dhcpc does not handle local subnet routes correctly

Bug #1369367 reported by Stephen Pierce
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
CirrOS
Confirmed
Medium
Unassigned

Bug Description

Long summary:
When Cirros gets a local subnet route from the dhcp server, it does not properly add the route to the route table.

To reproduce:

1. Add option 121 (classless-static-route),169.254.0.0/16,0.0.0.0 to dhcpd server
2. Run udhcpc within cirros
3. Profit

Output:

$ /sbin/ifdown -a; /sbin/ifup -a
udhcpc (v1.20.1) started
Sending discover...
Sending select for 10.29.103.106...
Lease of 10.29.103.106 obtained, lease time 1200
deleting routers
adding dns 171.70.168.183
adding dns 173.36.131.10
adding dns 173.37.87.157
adding net 169.254.0.0/16 with router 0.0.0.0
route: SIOCADDRT: Invalid argument
WARN: failed: route add -net "169.254.0.0/16" gw "0.0.0.0"

Proposed patch to /usr/share/udhcpc/default.script is attached.

References:

RFC 3442
Classless Static Route Option for DHCPv4
December 2002
Page 3-4

Local Subnet Routes

   In some cases more than one IP subnet may be configured on a link.
   In such cases, a host whose IP address is in one IP subnet in the
   link could communicate directly with a host whose IP address is in a
   different IP subnet on the same link. In cases where a client is
   being assigned an IP address on an IP subnet on such a link, for each
   IP subnet in the link other than the IP subnet on which the client
   has been assigned the DHCP server MAY be configured to specify a
   router IP address of 0.0.0.0.

   For example, consider the case where there are three IP subnets
   configured on a link: 10.0.0/24, 192.168.0/24, 10.0.21/24. If the
   client is assigned an IP address of 10.0.21.17, then the server could
   include a route with a destination of 10.0.0/24 and a router address
   of 0.0.0.0, and also a route with a destination of 192.168.0/24 and a
   router address of 0.0.0.0.

   A DHCP client whose underlying TCP/IP stack does not provide this
   capability MUST ignore routes in the Classless Static Routes option
   whose router IP address is 0.0.0.0. Please note that the behavior
   described here only applies to the Classless Static Routes option,
   not to the Static Routes option nor the Router option.

Related branches

Revision history for this message
Stephen Pierce (pierce-stephen) wrote :
Download full text (3.7 KiB)

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: stevpier@vm-stevpier-20141208033149-h5g3ylznt0y1p9wv
# target_branch: bzr+ssh://bazaar.launchpad.net/%2Bbranch/cirros/
# testament_sha1: 4c3a9c8dfd4accb6b8f5d119c8320b569e6c7140
# timestamp: 2014-12-07 21:34:26 -0600
# base_revision_id: <email address hidden>
#
# Begin patch
=== modified file 'src/sbin/cirros-dhcpc'
--- src/sbin/cirros-dhcpc 2014-09-05 16:51:59 +0000
+++ src/sbin/cirros-dhcpc 2014-12-08 03:31:49 +0000
@@ -20,15 +20,25 @@
        # routes are pairs of network and gateway
        # 169.254.169.254/32 10.65.0.128
        local net="" router="" err=0
+ local_interface="$1"
+ shift 1
        while [ $# -ne 0 ]; do
                net="$1"
                router="$2"
- [ -n "$net" ] || continue
- debug 1 "adding net $net with router $router"
- route add -net "$net" gw "$router" || {
- error "WARN: failed: route add -net \"$net\" gw \"$router\""
- err=$(($err+1));
- }
+ if [ "$router" == "0.0.0.0" ] ; then
+ debug 1 "adding net $net to $interface"
+ route add -net "$net" dev "$interface" || {
+ error "WARN: failed: route add -net \"$net\" dev \"$interface\""
+ err=$(($err+1));
+ }
+ else
+ debug 1 "adding net $net with router $router"
+ route add -net "$net" gw "$router" || {
+ [ -n "$net" ] || continue
+ error "WARN: failed: route add -net \"$net\" gw \"$router\""
+ err=$(($err+1));
+ }
+ fi
                shift 2 || {
                        error "apply_static_routes: failed shift 2. odd number of args?"
                        return 1;
@@ -128,7 +138,7 @@
                done
        } > "$RESOLV_CONF"

- apply_static_routes $staticroutes
+ apply_static_routes $interface $staticroutes
 }

 case "$1" in

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWdvIGj0AAe3fgEAwVGv//3IB
EI6////+UAR9cSe7eXme3t3Y0OCUQmk9U9MUepp6I2Qm1MaJkAAbSGgyiMjEyp7Qp7UZIDNJoaBo
AAAlBCBMTQ0p71SD1GaA0mBHqep6CMCRSU9pJ5RtR7UJhPSAaG1NAAGgAkkTCCmZMIU3k1JspoAA
AaBowRBIY0wbQ2Nn5OO7xcxlP4wywT++LgIT9/uy4yQac1WFWCHRky5HTwyvdFPLTvO3houKC9gj
HY4pYegT/V6oql07FNw0axdCwjBXIOv0dzwvs3Y2GMDMGf3c6HzR2keHsxXpko+JPK6VHCks8yJz
wILlNEQtrx5G+VJvvZpWTlqamug17GVFFFVkkwMBb+RxhRUFVFYbhlspaSDsZEZ+BwB4nZQ/SlOw
SGFl9CvrvonIEX6D6YR4tUbwPLogwxOdtKLNuuR6gi7HiLf5sySEdONwoikXR0fmMIvCfqTEwNqo
maxV/EPExyY223m3XDDJCNziKc5g6UZ2pkbyxpCeqMwmpLtAmy6OTBaqs+BXt6RLJTL5dZPGwbga
ivlALIITCyM32koM9tkEwwxKyTVlEQqWOy9TURhIWzUlGdZHqE6q4uTUCvSyBBdfzJOJxAo5m2Ox
YUU52vZ3zxrIJN8qWvgF4CLBfWDlvNi9MnozIZrstNCMSsOcBEC0I4KA4NSUht4eyQkHLIQQJ3Xv
hVQ/DRKkFrrkEpdWPNbTiyVAtJSv2E8isqqpYy5arlmstLFDIslgSBt5CNq2k/iL24dCwWctVlhH
0+7QS4keqopvqbcXEDk+5x8jhGNmraGnV2PNLUwK4ZUVV8VvRWIZ50KCaaICw4PPTZUuv42QIXuN
Am2VBcboMGqtfcNFoSAs8ILxahxp15BUB6FRDdRcvPBc20CbHObFWNAQhFk8J1VG...

Read more...

Revision history for this message
Stephen Pierce (pierce-stephen) wrote :
Changed in cirros:
status: New → Confirmed
Scott Moser (smoser)
Changed in cirros:
importance: Undecided → Medium
Revision history for this message
Scott Moser (smoser) wrote :

thanks for the bug and the patch. sorry its taken so long.
I wonder if you could test the attached patch with one of the daily builds at http://download.cirros-cloud.net/daily/

Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Dr. Jens Harbott (j-harbott) wrote :

Even with the daily build, I'm getting warning messages. It seems that cirros is not confirming to RFC3442 here, which states:

If the DHCP server returns both a Classless Static Routes option and
a Router option, the DHCP client MUST ignore the Router option.

But if I look at the boot log with added verbosity, there is first the router option being handled:

Starting network...
Starting udhcpc on eth0, asking for options {staticroutes mtu}
udhcpc (v1.23.2) started
Sending discover...
Sending select for 10.11.0.6...
Lease of 10.11.0.6 obtained, lease time 86400
ifconfig eth0 10.11.0.6 broadcast 10.11.255.255 netmask 255.255.0.0 mtu 1450
deleting routers
route add default gw 10.11.0.1 dev eth0
configuring /etc/resolv.conf for eth0. domain=openstacklocal nameservers: 10.11.0.2 10.11.0.3
adding net 169.254.169.254/32 via gw 10.11.0.1
adding net 0.0.0.0/0 via gw 10.11.0.1
route: SIOCADDRT: File exists
WARN: failed: route add -net "0.0.0.0/0" gw "10.11.0.1"

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.