After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 721767 - NetworkManager does not add route for dhcp server when needed
NetworkManager does not add route for dhcp server when needed
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: IP and DNS config
0.9.x
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-01-08 03:53 UTC by Scott Shambarger
Modified: 2014-01-24 12:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add route for dhcp4-server if needed (1.60 KB, patch)
2014-01-08 05:11 UTC, Scott Shambarger
none Details | Review
Updated patch with comment, requested patch format (2.67 KB, patch)
2014-01-09 00:07 UTC, Scott Shambarger
none Details | Review
Updated patch to add device route if no gateway. (2.73 KB, patch)
2014-01-09 14:10 UTC, Scott Shambarger
none Details | Review
style !fixup for previous patch (2.27 KB, patch)
2014-01-09 14:39 UTC, Thomas Haller
none Details | Review
Patch including fixups and updated commit message (2.93 KB, patch)
2014-01-09 22:32 UTC, Scott Shambarger
none Details | Review

Description Scott Shambarger 2014-01-08 03:53:15 UTC
I'm filing this as an upstream version of redhat bug 983325

When using a NetworkManager with a dhcp server, a routing entry is not added for the server if the server is not within the assigned network mask.  In this case, a host routing entry for the dhcp_server_identifier should be created, so that if the interface is not the default route, the dhcp server can be contacted.

To clarify, this bug will only be visible if the interface is NOT the default route.  The bug will cause the address on the interface to eventually expire, and cause the connection to reset (killing all open connections).
Comment 1 Scott Shambarger 2014-01-08 05:11:31 UTC
Created attachment 265638 [details] [review]
add route for dhcp4-server if needed

I've created a patch to add a host routing entry for the dhcp4 server if it's not on the local subnet.  I've tested this on my server, and it works as expected on my Fedora rpm build.
Comment 2 Pavel Simerda 2014-01-08 09:47:11 UTC
(In reply to comment #1)
> Created an attachment (id=265638) [details] [review]
> add route for dhcp4-server if needed

What is the purpose of the first hunk? 

Also, could you please describe the actual problem, specifically the reason why the DHCP server/relay which is typically in the same subnet, should be unreachable at all. Preferebly in a comment, so it doesn't get lost.

The magic of adding various routes is already more complicated than necessary, it would be nice to have all new additions properly documented in comments.
Comment 3 Thomas Haller 2014-01-08 13:25:34 UTC
(In reply to comment #1)
> Created an attachment (id=265638) [details] [review]
> add route for dhcp4-server if needed
> 
> I've created a patch to add a host routing entry for the dhcp4 server if it's
> not on the local subnet.  I've tested this on my server, and it works as
> expected on my Fedora rpm build.

Just a minor side note: you could create the patch with
$ git format-patch -n1
which contains the author and your commit message. We can then apply it conveniently with `git am`.

Anyway, thank you for your effort!!
Comment 4 Scott Shambarger 2014-01-09 00:07:51 UTC
Created attachment 265805 [details] [review]
Updated patch with comment, requested patch format

The first hunk is to save the gwaddr in the second code path to retrieve it.

I've updated the code with a comment referring to the RFC and the rationale for the route (and also when it's needed).  In my case it's a dhcp server with Comcast in the US, but I didn't think that needed to be specified in the comment -- although the ISP is large enough to affect many users.

Let me know if you need any more updates :)
Comment 5 Thomas Haller 2014-01-09 10:22:44 UTC
Referring to your original bug report https://bugzilla.redhat.com/show_bug.cgi?id=983325#c0 ...

I think that is_router_reachable() in /usr/sbin/dhclient-script does something different: it ensures, that there is a device route for all the routers. You want to have a route to the DHCP server.

In your original report, you got the DHCP offer from 96.147.132.1, but then you want to set the route for 69.252.97.6 (you explain that the former "is actually the relay agent"...). But in another setup without new_dhcp_server_identifier, wouldn't we have to ensure, that there is a route to the IP where the DHCP offer came from?

Also, you only add the route, if the interface has a gateway. Why this restriction? Wouldn't we want to add a device route to the DHCP server in this case?
Comment 6 Pavel Simerda 2014-01-09 11:34:21 UTC
(In reply to comment #3)
> Just a minor side note: you could create the patch with
> $ git format-patch -n1
> which contains the author and your commit message. We can then apply it
> conveniently with `git am`.

Isn't 'git show' easier and better?
Comment 7 Pavel Simerda 2014-01-09 11:36:22 UTC
(In reply to comment #5)
> Referring to your original bug report
> https://bugzilla.redhat.com/show_bug.cgi?id=983325#c0 ...
> 
> I think that is_router_reachable() in /usr/sbin/dhclient-script does something
> different: it ensures, that there is a device route for all the routers. You
> want to have a route to the DHCP server.
> 
> In your original report, you got the DHCP offer from 96.147.132.1, but then you
> want to set the route for 69.252.97.6 (you explain that the former "is actually
> the relay agent"...).

Aha, I missed that. You should AFAIK never talk to the DHCP server directly and should always use the relay agent. Please check and CLOSE/WONTFIX.
Comment 8 Thomas Haller 2014-01-09 11:52:37 UTC
(In reply to comment #6)
> Isn't 'git show' easier and better?

AFAIK the output of git-show cannot be applied as conveniently as doing git-format-patch + git-am -- in the latter case, you already have the commit ready, not just the patch applied.


(In reply to comment #7)
> Aha, I missed that. You should AFAIK never talk to the DHCP server directly and
> should always use the relay agent. Please check and CLOSE/WONTFIX.

In the original bug report, the relay-agent is also not on the same network. So, maybe, we need to add the route for the IP that sent the DHCPOFFER?
Comment 9 Scott Shambarger 2014-01-09 13:14:47 UTC
(In reply to comment #5)
> I think that is_router_reachable() in /usr/sbin/dhclient-script does something
> different: it ensures, that there is a device route for all the routers. You
> want to have a route to the DHCP server.

My comment there was noting how is_router_reachable is specifically checking if the router address is on a different subnet than the assigned one, and adding a route for it before pinging it in that case...

> In your original report, you got the DHCP offer from 96.147.132.1, but then you
> want to set the route for 69.252.97.6 (you explain that the former "is actually
> the relay agent"...). But in another setup without new_dhcp_server_identifier,
> wouldn't we have to ensure, that there is a route to the IP where the DHCP
> offer came from?

When server_identifier is present, dhclient unicasts directly to it; if none is supplied, then it broadcasts on the device (no route needed).

I looked at the isc dhclient.c code (see state_bound) as I couldn't test this directly... my dhcpd always sends a server_identifier option, and I can't find how to suppress it (just change it :)

> Also, you only add the route, if the interface has a gateway. Why this
> restriction? Wouldn't we want to add a device route to the DHCP server in this
> case?

I suppose a device route could be used as a fallback... I'm just not sure how to create one using the NMPlatformIP4Route (would setting the gateway to zero do it?).
Comment 10 Scott Shambarger 2014-01-09 13:18:40 UTC
(In reply to comment #7)
> Aha, I missed that. You should AFAIK never talk to the DHCP server directly and
> should always use the relay agent. Please check and CLOSE/WONTFIX.

As I referenced in the patch comment, rfc2132 says dhclient should use the server_identifier to unicast to the dhcp server when it's supplied, so dhclient is expected to talk to it directly (and it tries to :)
Comment 11 Thomas Haller 2014-01-09 13:34:43 UTC
(In reply to comment #9)

> I suppose a device route could be used as a fallback... I'm just not sure how
> to create one using the NMPlatformIP4Route (would setting the gateway to zero
> do it?).

Yes, a device route has 0.0.0.0 as gateway. So, I think, you could just omit the check "if (gwaddr) {" ...
Comment 12 Scott Shambarger 2014-01-09 14:10:58 UTC
Created attachment 265843 [details] [review]
Updated patch to add device route if no gateway.

Also added a info log if the route is added... so it's clear where it's going to.
Comment 13 Thomas Haller 2014-01-09 14:39:16 UTC
Created attachment 265845 [details] [review]
style !fixup for previous patch

(In reply to comment #12)

I would suggest this !fixup for style/logging, but overall I think it's good.

IMO we should reference the full bz URLs in the commit message:
https://bugzilla.gnome.org/show_bug.cgi?id=721767
https://bugzilla.redhat.com/show_bug.cgi?id=983325
Comment 14 Scott Shambarger 2014-01-09 14:49:19 UTC
Style updates look fine. If it's ok to put links in the commit messages, it sounds like a good idea.  Thanks for all the feedback... still getting my sea legs on the "gnome way" of things :)
Comment 15 Scott Shambarger 2014-01-09 16:18:28 UTC
BTW, should I submit an updated patch combining the changes and updating the commit message, or is the plan to submit both patches together?
Comment 16 Thomas Haller 2014-01-09 21:07:12 UTC
(In reply to comment #15)
> BTW, should I submit an updated patch combining the changes and updating the
> commit message, or is the plan to submit both patches together?

yes, if you agree, just take !fixup from comment 13, update the commit message and repost the patch :) Thank you!!
Comment 17 Scott Shambarger 2014-01-09 22:32:58 UTC
Created attachment 265882 [details] [review]
Patch including fixups and updated commit message

Updated patch. Thanks again for all the assistance!
Comment 18 Thomas Haller 2014-01-09 22:40:17 UTC
ACK, looks good to me!
Comment 19 Thomas Haller 2014-01-21 20:22:21 UTC
Pushed to master as http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=31fe84e467732463eabc8f70c2a419008e7a227c

(After adjusting commit message and fixed whitespace)

Thanks!!

Closing bug now.
Comment 20 Pavel Simerda 2014-01-24 12:38:23 UTC
For reference...

9.7. Server Identifier

   This option is used in DHCPOFFER and DHCPREQUEST messages, and may
   optionally be included in the DHCPACK and DHCPNAK messages.  DHCP
   servers include this option in the DHCPOFFER in order to allow the
   client to distinguish between lease offers.  DHCP clients use the
   contents of the 'server identifier' field as the destination address
   for any DHCP messages unicast to the DHCP server.  DHCP clients also
   indicate which of several lease offers is being accepted by including
   this option in a DHCPREQUEST message.

   The identifier is the IP address of the selected server.

   The code for this option is 54, and its length is 4.

This RFC unfortunately doesn't specify the behavior with regard to DHCP relay agent, though.