diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index 769e6a2753..9539fefd3d 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -870,7 +870,8 @@ static_stage3_ip4_done (NMModemBroadband *self) address.peer_address = address_network; address.plen = mm_bearer_ip_config_get_prefix (self->priv->ipv4_config); address.source = NM_IP_CONFIG_SOURCE_WWAN; - nm_ip4_config_add_address (config, &address); + if (address.plen <= 32) + nm_ip4_config_add_address (config, &address); nm_log_info (LOGD_MB, " address %s/%d", address_string, address.plen); @@ -960,7 +961,8 @@ stage3_ip6_done (NMModemBroadband *self) config = nm_ip6_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port)); address.plen = mm_bearer_ip_config_get_prefix (self->priv->ipv6_config); - nm_ip6_config_add_address (config, &address); + if (address.plen <= 128) + nm_ip6_config_add_address (config, &address); nm_log_info (LOGD_MB, " address %s/%d", address_string, address.plen); diff --git a/src/dhcp-manager/nm-dhcp-utils.c b/src/dhcp-manager/nm-dhcp-utils.c index 571b1c2213..a88a7e6d51 100644 --- a/src/dhcp-manager/nm-dhcp-utils.c +++ b/src/dhcp-manager/nm-dhcp-utils.c @@ -382,7 +382,8 @@ nm_dhcp_utils_ip4_config_from_options (int ifindex, in_addr_t addr; NMPlatformIP4Address address; char *str = NULL; - guint32 gwaddr = 0, plen = 0; + guint32 gwaddr = 0; + guint8 plen = 0; g_return_val_if_fail (options != NULL, NULL); diff --git a/src/dnsmasq-manager/nm-dnsmasq-utils.c b/src/dnsmasq-manager/nm-dnsmasq-utils.c index bf8faecd52..3786f37d44 100644 --- a/src/dnsmasq-manager/nm-dnsmasq-utils.c +++ b/src/dnsmasq-manager/nm-dnsmasq-utils.c @@ -34,7 +34,7 @@ nm_dnsmasq_utils_get_range (const NMPlatformIP4Address *addr, char **out_error_desc) { guint32 host = addr->address; - guint32 prefix = addr->plen; + guint8 prefix = addr->plen; guint32 netmask = nm_utils_ip4_prefix_to_netmask (prefix); guint32 first, last, reserved; diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 78c3f94f4f..d6f6a9b3fc 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -365,6 +365,8 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_fu if (addr->plen == 0) continue; + nm_assert (addr->plen <= 32); + route.ifindex = ifindex; route.source = NM_IP_CONFIG_SOURCE_KERNEL; @@ -466,6 +468,7 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, gu nm_ip_address_get_address_binary (s_addr, &address.address); address.peer_address = address.address; address.plen = nm_ip_address_get_prefix (s_addr); + nm_assert (address.plen <= 32); address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT; address.preferred = NM_PLATFORM_LIFETIME_PERMANENT; address.source = NM_IP_CONFIG_SOURCE_USER; @@ -564,6 +567,10 @@ nm_ip4_config_create_setting (const NMIP4Config *config) continue; } + /* FIXME: NMIPAddress doesn't support zero prefixes. */ + if (address->plen == 0) + continue; + /* Static address found. */ if (!method) method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index ab0b67d842..0b32901bf1 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -454,6 +454,7 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, gu memset (&address, 0, sizeof (address)); nm_ip_address_get_address_binary (s_addr, &address.address); address.plen = nm_ip_address_get_prefix (s_addr); + nm_assert (address.plen <= 128); address.lifetime = NM_PLATFORM_LIFETIME_PERMANENT; address.preferred = NM_PLATFORM_LIFETIME_PERMANENT; address.source = NM_IP_CONFIG_SOURCE_USER; @@ -555,6 +556,10 @@ nm_ip6_config_create_setting (const NMIP6Config *config) continue; } + /* FIXME: NMIPAddress does not support zero prefixes. */ + if (address->plen == 0) + continue; + /* Static address found. */ if (!method || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index fc3875c724..15d9c54301 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -91,17 +91,17 @@ static void link_changed (NMPlatform *platform, NMFakePlatformLink *device, gboo static gboolean ip6_address_add (NMPlatform *platform, int ifindex, struct in6_addr addr, - int plen, + guint8 plen, struct in6_addr peer_addr, guint32 lifetime, guint32 preferred, guint flags); -static gboolean ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, int plen); +static gboolean ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, guint8 plen); /******************************************************************/ static gboolean -_ip4_address_equal_peer_net (in_addr_t peer1, in_addr_t peer2, int plen) +_ip4_address_equal_peer_net (in_addr_t peer1, in_addr_t peer2, guint8 plen) { return ((peer1 ^ peer2) & nm_utils_ip4_prefix_to_netmask (plen)) == 0; } @@ -886,7 +886,7 @@ static gboolean ip4_address_add (NMPlatform *platform, int ifindex, in_addr_t addr, - int plen, + guint8 plen, in_addr_t peer_addr, guint32 lifetime, guint32 preferred, @@ -938,7 +938,7 @@ static gboolean ip6_address_add (NMPlatform *platform, int ifindex, struct in6_addr addr, - int plen, + guint8 plen, struct in6_addr peer_addr, guint32 lifetime, guint32 preferred, @@ -982,7 +982,7 @@ ip6_address_add (NMPlatform *platform, } static gboolean -ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in_addr_t peer_address) +ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, guint8 plen, in_addr_t peer_address) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform); int i; @@ -1007,7 +1007,7 @@ ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, } static gboolean -ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, int plen) +ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, guint8 plen) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform); int i; @@ -1031,7 +1031,7 @@ ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, int } static const NMPlatformIP4Address * -ip4_address_get (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in_addr_t peer_address) +ip4_address_get (NMPlatform *platform, int ifindex, in_addr_t addr, guint8 plen, in_addr_t peer_address) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform); int i; @@ -1050,7 +1050,7 @@ ip4_address_get (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in } static const NMPlatformIP6Address * -ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr, int plen) +ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr, guint8 plen) { NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform); int i; @@ -1058,8 +1058,9 @@ ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr, int pl for (i = 0; i < priv->ip6_addresses->len; i++) { NMPlatformIP6Address *address = &g_array_index (priv->ip6_addresses, NMPlatformIP6Address, i); - if (address->ifindex == ifindex && address->plen == plen && - IN6_ARE_ADDR_EQUAL (&address->address, &addr)) + if ( address->ifindex == ifindex + && address->plen == plen + && IN6_ARE_ADDR_EQUAL (&address->address, &addr)) return address; } diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index e8d75c0837..668f0f5a1f 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -1640,6 +1640,9 @@ _new_from_nl_addr (struct nlmsghdr *nlh, gboolean id_only) ? sizeof (in_addr_t) : sizeof (struct in6_addr); + if (ifa->ifa_prefixlen > (is_v4 ? 32 : 128)) + goto errout; + /*****************************************************************/ obj = nmp_object_new (is_v4 ? NMP_OBJECT_TYPE_IP4_ADDRESS : NMP_OBJECT_TYPE_IP6_ADDRESS, NULL); @@ -2160,7 +2163,7 @@ _nl_msg_new_address (int nlmsg_type, int family, int ifindex, gconstpointer address, - int plen, + guint8 plen, gconstpointer peer_address, guint32 flags, int scope, @@ -5268,7 +5271,7 @@ static gboolean ip4_address_add (NMPlatform *platform, int ifindex, in_addr_t addr, - int plen, + guint8 plen, in_addr_t peer_addr, guint32 lifetime, guint32 preferred, @@ -5299,7 +5302,7 @@ static gboolean ip6_address_add (NMPlatform *platform, int ifindex, struct in6_addr addr, - int plen, + guint8 plen, struct in6_addr peer_addr, guint32 lifetime, guint32 preferred, @@ -5326,7 +5329,7 @@ ip6_address_add (NMPlatform *platform, } static gboolean -ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in_addr_t peer_address) +ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, guint8 plen, in_addr_t peer_address) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; NMPObject obj_id; @@ -5351,7 +5354,7 @@ ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, } static gboolean -ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, int plen) +ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, guint8 plen) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; NMPObject obj_id; @@ -5376,7 +5379,7 @@ ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, int } static const NMPlatformIP4Address * -ip4_address_get (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in_addr_t peer_address) +ip4_address_get (NMPlatform *platform, int ifindex, in_addr_t addr, guint8 plen, in_addr_t peer_address) { NMPObject obj_id; const NMPObject *obj; @@ -5389,7 +5392,7 @@ ip4_address_get (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in } static const NMPlatformIP6Address * -ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr, int plen) +ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr, guint8 plen) { NMPObject obj_id; const NMPObject *obj; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 744363b123..07ec4cf0b3 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -2459,8 +2459,10 @@ nm_platform_ethtool_get_link_speed (NMPlatform *self, const char *ifname, guint3 /******************************************************************/ void -nm_platform_ip4_address_set_addr (NMPlatformIP4Address *addr, in_addr_t address, int plen) +nm_platform_ip4_address_set_addr (NMPlatformIP4Address *addr, in_addr_t address, guint8 plen) { + nm_assert (plen <= 32); + addr->address = address; addr->peer_address = address; addr->plen = plen; @@ -2499,7 +2501,7 @@ gboolean nm_platform_ip4_address_add (NMPlatform *self, int ifindex, in_addr_t address, - int plen, + guint8 plen, in_addr_t peer_address, guint32 lifetime, guint32 preferred, @@ -2509,7 +2511,7 @@ nm_platform_ip4_address_add (NMPlatform *self, _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (plen > 0, FALSE); + g_return_val_if_fail (plen <= 32, FALSE); g_return_val_if_fail (lifetime > 0, FALSE); g_return_val_if_fail (preferred <= lifetime, FALSE); g_return_val_if_fail (!label || strlen (label) < sizeof (((NMPlatformIP4Address *) NULL)->label), FALSE); @@ -2537,7 +2539,7 @@ gboolean nm_platform_ip6_address_add (NMPlatform *self, int ifindex, struct in6_addr address, - int plen, + guint8 plen, struct in6_addr peer_address, guint32 lifetime, guint32 preferred, @@ -2546,7 +2548,7 @@ nm_platform_ip6_address_add (NMPlatform *self, _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (plen > 0, FALSE); + g_return_val_if_fail (plen <= 128, FALSE); g_return_val_if_fail (lifetime > 0, FALSE); g_return_val_if_fail (preferred <= lifetime, FALSE); @@ -2568,7 +2570,7 @@ nm_platform_ip6_address_add (NMPlatform *self, } gboolean -nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address) +nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address) { char str_dev[TO_STRING_DEV_BUF_SIZE]; char str_peer2[NM_UTILS_INET_ADDRSTRLEN]; @@ -2577,7 +2579,7 @@ nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (plen > 0, FALSE); + g_return_val_if_fail (plen <= 32, FALSE); _LOGD ("address: deleting IPv4 address %s/%d, %sifindex %d%s", nm_utils_inet4_ntop (address, NULL), plen, @@ -2589,14 +2591,14 @@ nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address } gboolean -nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, int plen) +nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen) { char str_dev[TO_STRING_DEV_BUF_SIZE]; _CHECK_SELF (self, klass, FALSE); g_return_val_if_fail (ifindex > 0, FALSE); - g_return_val_if_fail (plen > 0, FALSE); + g_return_val_if_fail (plen <= 128, FALSE); _LOGD ("address: deleting IPv6 address %s/%d, ifindex %d%s", nm_utils_inet6_ntop (&address, NULL), plen, ifindex, @@ -2605,21 +2607,21 @@ nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr a } const NMPlatformIP4Address * -nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, int plen, guint32 peer_address) +nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, guint32 peer_address) { _CHECK_SELF (self, klass, NULL); - g_return_val_if_fail (plen > 0, NULL); + g_return_val_if_fail (plen <= 32, NULL); return klass->ip4_address_get (self, ifindex, address, plen, peer_address); } const NMPlatformIP6Address * -nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, int plen) +nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen) { _CHECK_SELF (self, klass, NULL); - g_return_val_if_fail (plen > 0, NULL); + g_return_val_if_fail (plen <= 128, NULL); return klass->ip6_address_get (self, ifindex, address, plen); } diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index fbfa470174..10fe282db0 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -226,7 +226,7 @@ typedef struct { * IFA_FLAGS attribute. */ \ guint32 n_ifa_flags; \ \ - int plen; \ + guint8 plen; \ ; /** @@ -593,7 +593,7 @@ typedef struct { gboolean (*ip4_address_add) (NMPlatform *, int ifindex, in_addr_t address, - int plen, + guint8 plen, in_addr_t peer_address, guint32 lifetime, guint32 preferred_lft, @@ -602,15 +602,15 @@ typedef struct { gboolean (*ip6_address_add) (NMPlatform *, int ifindex, struct in6_addr address, - int plen, + guint8 plen, struct in6_addr peer_address, guint32 lifetime, guint32 preferred_lft, guint32 flags); - gboolean (*ip4_address_delete) (NMPlatform *, int ifindex, in_addr_t address, int plen, in_addr_t peer_address); - gboolean (*ip6_address_delete) (NMPlatform *, int ifindex, struct in6_addr address, int plen); - const NMPlatformIP4Address *(*ip4_address_get) (NMPlatform *, int ifindex, in_addr_t address, int plen, in_addr_t peer_address); - const NMPlatformIP6Address *(*ip6_address_get) (NMPlatform *, int ifindex, struct in6_addr address, int plen); + gboolean (*ip4_address_delete) (NMPlatform *, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address); + gboolean (*ip6_address_delete) (NMPlatform *, int ifindex, struct in6_addr address, guint8 plen); + const NMPlatformIP4Address *(*ip4_address_get) (NMPlatform *, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address); + const NMPlatformIP6Address *(*ip6_address_get) (NMPlatform *, int ifindex, struct in6_addr address, guint8 plen); GArray * (*ip4_route_get_all) (NMPlatform *, int ifindex, NMPlatformGetRouteFlags flags); GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex, NMPlatformGetRouteFlags flags); @@ -835,10 +835,10 @@ guint32 nm_platform_mesh_get_channel (NMPlatform *self, int ifindex); gboolean nm_platform_mesh_set_channel (NMPlatform *self, int ifindex, guint32 channel); gboolean nm_platform_mesh_set_ssid (NMPlatform *self, int ifindex, const guint8 *ssid, gsize len); -void nm_platform_ip4_address_set_addr (NMPlatformIP4Address *addr, in_addr_t address, int plen); +void nm_platform_ip4_address_set_addr (NMPlatformIP4Address *addr, in_addr_t address, guint8 plen); const struct in6_addr *nm_platform_ip6_address_get_peer (const NMPlatformIP6Address *addr); -const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address); +const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address); NMPlatformError nm_platform_link_gre_add (NMPlatform *self, const char *name, @@ -862,13 +862,13 @@ NMPlatformError nm_platform_link_sit_add (NMPlatform *self, const NMPlatformLnkSit *props, const NMPlatformLink **out_link); -const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, int plen); +const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen); GArray *nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex); GArray *nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex); gboolean nm_platform_ip4_address_add (NMPlatform *self, int ifindex, in_addr_t address, - int plen, + guint8 plen, in_addr_t peer_address, guint32 lifetime, guint32 preferred_lft, @@ -877,13 +877,13 @@ gboolean nm_platform_ip4_address_add (NMPlatform *self, gboolean nm_platform_ip6_address_add (NMPlatform *self, int ifindex, struct in6_addr address, - int plen, + guint8 plen, struct in6_addr peer_address, guint32 lifetime, guint32 preferred_lft, guint32 flags); -gboolean nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address); -gboolean nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, int plen); +gboolean nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address); +gboolean nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen); gboolean nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, GPtrArray **out_added_addresses); gboolean nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, gboolean keep_link_local); gboolean nm_platform_address_flush (NMPlatform *self, int ifindex); diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index fcd4894487..07ea9fe1d5 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -343,7 +343,7 @@ _vt_cmd_obj_stackinit_id_link (NMPObject *obj, const NMPObject *src) } const NMPObject * -nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifindex, guint32 address, int plen, guint32 peer_address) +nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifindex, guint32 address, guint8 plen, guint32 peer_address) { nmp_object_stackinit (obj, NMP_OBJECT_TYPE_IP4_ADDRESS, NULL); obj->ip4_address.ifindex = ifindex; @@ -360,7 +360,7 @@ _vt_cmd_obj_stackinit_id_ip4_address (NMPObject *obj, const NMPObject *src) } const NMPObject * -nmp_object_stackinit_id_ip6_address (NMPObject *obj, int ifindex, const struct in6_addr *address, int plen) +nmp_object_stackinit_id_ip6_address (NMPObject *obj, int ifindex, const struct in6_addr *address, guint8 plen) { nmp_object_stackinit (obj, NMP_OBJECT_TYPE_IP6_ADDRESS, NULL); obj->ip4_address.ifindex = ifindex; diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 71e6e876ad..72d6270814 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -345,8 +345,8 @@ NMPObject *nmp_object_new_link (int ifindex); const NMPObject *nmp_object_stackinit (NMPObject *obj, NMPObjectType obj_type, const NMPlatformObject *plobj); const NMPObject *nmp_object_stackinit_id (NMPObject *obj, const NMPObject *src); const NMPObject *nmp_object_stackinit_id_link (NMPObject *obj, int ifindex); -const NMPObject *nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifindex, guint32 address, int plen, guint32 peer_address); -const NMPObject *nmp_object_stackinit_id_ip6_address (NMPObject *obj, int ifindex, const struct in6_addr *address, int plen); +const NMPObject *nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifindex, guint32 address, guint8 plen, guint32 peer_address); +const NMPObject *nmp_object_stackinit_id_ip6_address (NMPObject *obj, int ifindex, const struct in6_addr *address, guint8 plen); const NMPObject *nmp_object_stackinit_id_ip4_route (NMPObject *obj, int ifindex, guint32 network, guint8 plen, guint32 metric); const NMPObject *nmp_object_stackinit_id_ip6_route (NMPObject *obj, int ifindex, const struct in6_addr *network, guint8 plen, guint32 metric); diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c index 83a0bfd3c2..15b00203a6 100644 --- a/src/platform/tests/test-address.c +++ b/src/platform/tests/test-address.c @@ -308,7 +308,7 @@ test_ip4_address_peer_zero (void) in_addr_t addr, addr_peer; guint32 lifetime = 2000; guint32 preferred = 1000; - const int plen = 24; + const gint8 plen = 24; const char *label = NULL; in_addr_t peers[3], r_peers[3]; int i; diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index 18a28690e0..89a7addf84 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -481,7 +481,7 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32)) address.plen = u32; - if (address.address && address.plen) { + if (address.address && address.plen && address.plen <= 32) { address.source = NM_IP_CONFIG_SOURCE_PPP; nm_ip4_config_add_address (config, &address); } else { @@ -554,6 +554,7 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, NMPlatformIP6Address addr; struct in6_addr a; NMUtilsIPv6IfaceId iid = NM_UTILS_IPV6_IFACE_ID_INIT; + gboolean has_peer = FALSE; _LOGI ("(IPv6 Config Get) reply received."); @@ -567,9 +568,12 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { nm_ip6_config_set_gateway (config, &a); addr.peer_address = a; + has_peer = TRUE; } if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { + if (!has_peer) + addr.peer_address = addr.address; nm_ip6_config_add_address (config, &addr); if (set_ip_config_common (manager, config_dict, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 7efcc7829b..2945ad34ad 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -1387,11 +1387,11 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, "u", &u32)) address.plen = u32; - if (address.address && address.plen) { + if (address.address && address.plen && address.plen <= 32) { address.source = NM_IP_CONFIG_SOURCE_VPN; nm_ip4_config_add_address (config, &address); } else { - _LOGE ("invalid IP4 config received!"); + _LOGW ("invalid IP4 config received!"); g_object_unref (config); nm_vpn_connection_config_maybe_complete (self, FALSE); return; @@ -1524,11 +1524,11 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_PREFIX, "u", &u32)) address.plen = u32; - if (!IN6_IS_ADDR_UNSPECIFIED (&address.address) && address.plen) { + if (!IN6_IS_ADDR_UNSPECIFIED (&address.address) && address.plen && address.plen <= 128) { address.source = NM_IP_CONFIG_SOURCE_VPN; nm_ip6_config_add_address (config, &address); } else { - _LOGE ("invalid IP6 config received!"); + _LOGW ("invalid IP6 config received!"); g_object_unref (config); nm_vpn_connection_config_maybe_complete (self, FALSE); return;