diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index f3b7f556f9..731c4c5928 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -3724,6 +3724,8 @@ _l3cfg_update_combined_config(NML3Cfg *self, } if (self->priv.ifindex == NM_LOOPBACK_IFINDEX) { + NMPlatformIPXRoute rx; + if (!nm_l3_config_data_lookup_address_4(l3cd, NM_IPV4LO_NETWORK, 8, @@ -3743,6 +3745,21 @@ _l3cfg_update_combined_config(NML3Cfg *self, }; nm_l3_config_data_add_address_6(l3cd, &ip6_address); } + + rx.r4 = (NMPlatformIP4Route){ + .ifindex = 1, + .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, + .network = NM_IPV4LO_NETWORK, + .plen = 8, + .table_coerced = nm_platform_route_table_coerce(RT_TABLE_LOCAL), + .scope_inv = nm_platform_route_scope_inv(RT_SCOPE_HOST), + .type_coerced = nm_platform_route_type_coerce(RTN_LOCAL), + }; + nm_platform_ip_route_normalize(AF_INET, &rx.rx); + if (!nm_l3_config_data_lookup_route(l3cd, AF_INET, &rx.rx)) { + _LOGE("---- adding loopback route"); + nm_l3_config_data_add_route_4(l3cd, &rx.r4); + } } for (i = 0; i < l3_config_datas_len; i++) { const L3ConfigData *l3cd_data = l3_config_datas_arr[i]; diff --git a/src/libnm-glib-aux/nm-inet-utils.h b/src/libnm-glib-aux/nm-inet-utils.h index 2c1bd4126e..3532401b74 100644 --- a/src/libnm-glib-aux/nm-inet-utils.h +++ b/src/libnm-glib-aux/nm-inet-utils.h @@ -230,9 +230,10 @@ gboolean nm_ip6_addr_is_ula(const struct in6_addr *address); /*****************************************************************************/ -#define NM_IPV4LL_NETWORK ((in_addr_t) htonl(0xA9FE0000lu)) -#define NM_IPV4LL_NETMASK ((in_addr_t) htonl(0xFFFF0000lu)) -#define NM_IPV4LO_NETWORK ((in_addr_t) htonl(0x7F000001lu)) +#define NM_IPV4LL_NETWORK ((in_addr_t) htonl(0xA9FE0000lu)) +#define NM_IPV4LL_NETMASK ((in_addr_t) htonl(0xFFFF0000lu)) +#define NM_IPV4LO_NETWORK ((in_addr_t) htonl(0x7F000001lu)) +#define NM_IPV4LO_RT_NETWORK ((in_addr_t) htonl(0x7F000000lu)) static inline gboolean nm_ip4_addr_is_loopback(in_addr_t addr) diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index 33a2f103bb..d5620446da 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -4770,6 +4770,44 @@ nm_platform_ip_route_get_prune_list(NMPlatform *self, * pruning them. */ if (NM_IS_IPv4(addr_family)) { + _LOGD("*************drop route start**************"); + if (rt->r4.network == NM_IPV4LO_NETWORK) { + _LOGD("*************drop route1**************"); + rt_local4 = (NMPlatformIP4Route){ + .ifindex = ifindex, + .type_coerced = nm_platform_route_type_coerce(RTN_LOCAL), + .plen = 32, + .rt_source = NM_IPV4LO_NETWORK, + .metric = 0, + .table_coerced = nm_platform_route_table_coerce(local_table), + .scope_inv = nm_platform_route_scope_inv(RT_SCOPE_HOST), + .network = NM_IPV4LO_NETWORK, + .pref_src = NM_IPV4LO_NETWORK, + }; + } else if (rt->r4.network == NM_IPV4LO_RT_NETWORK) { + _LOGD("*************drop route2**************"); + rt_local4 = (NMPlatformIP4Route){ + .ifindex = ifindex, + .type_coerced = nm_platform_route_type_coerce(RTN_LOCAL), + .plen = 8, + .rt_source = NM_IPV4LO_NETWORK, + .metric = 0, + .table_coerced = nm_platform_route_table_coerce(local_table), + .scope_inv = nm_platform_route_scope_inv(RT_SCOPE_HOST), + .network = NM_IPV4LO_RT_NETWORK, + .pref_src = NM_IPV4LO_NETWORK, + }; + } + if (nm_platform_ip4_route_cmp(&rt->r4, + &rt_local4, + NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) + == 0) { + _LOGD("*************drop route**************"); + continue; + } + } + if (NM_IS_IPv4(addr_family)) { + _LOGD("++++++++++++drop route general++++++++++++++"); /* for each IPv4 address kernel adds a route like * * local $ADDR dev $IFACE table local proto kernel scope host src $PRIMARY_ADDR