From 2b461bfa19f7862081522c64e90399dc1f30b59a Mon Sep 17 00:00:00 2001 From: Scott Shambarger Date: Thu, 9 Jan 2014 14:56:39 -0800 Subject: [PATCH] core: set classful prefix length for DHCP4 static routes (bgo #721771) Follow RFC 3442 to set network prefix based on address class. However, still uses host routing if the target address is not a network address (ie host part not zero). https://bugzilla.gnome.org/show_bug.cgi?id=721771 Signed-off-by: Thomas Haller --- src/dhcp-manager/nm-dhcp-client.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index 4bbcdeb173..edea8f84a2 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -1073,15 +1073,24 @@ process_classful_routes (GHashTable *options, NMIP4Config *ip4_config) continue; } - // FIXME: ensure the IP addresse and route are sane + // FIXME: ensure the IP address and route are sane memset (&route, 0, sizeof (route)); route.network = rt_addr; - route.plen = 32; + /* RFC 2132, updated by RFC 3442: + The Static Routes option (option 33) does not provide a subnet mask + for each route - it is assumed that the subnet mask is implicit in + whatever network number is specified in each route entry */ + route.plen = nm_utils_ip4_get_default_prefix (rt_addr); + if (rt_addr & ~nm_utils_ip4_prefix_to_netmask (route.plen)) { + /* RFC 943: target not "this network"; using host routing */ + route.plen = 32; + } route.gateway = rt_route; nm_ip4_config_add_route (ip4_config, &route); - nm_log_info (LOGD_DHCP, " static route %s gw %s", *s, *(s + 1)); + nm_log_info (LOGD_DHCP, " static route %s", + nm_platform_ip4_route_to_string (&route)); } out: