]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Only set maximum message size if we can get the MTU of the interface.
authorRoy Marples <roy@marples.name>
Tue, 11 Aug 2015 09:23:26 +0000 (09:23 +0000)
committerRoy Marples <roy@marples.name>
Tue, 11 Aug 2015 09:23:26 +0000 (09:23 +0000)
dhcp.c

diff --git a/dhcp.c b/dhcp.c
index 2714d4129aa04fa9ca02d79c78e5cf8353f6cb56..a77e4424cea95da1ad4dd5cbcb40f7d902564c29 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -900,21 +900,27 @@ make_message(struct dhcp_message **message,
                if (!(ifo->options & DHCPCD_BOOTP)) {
                        int mtu;
 
-                       *p++ = DHO_MAXMESSAGESIZE;
-                       *p++ = 2;
-                       mtu = if_getmtu(ifp);
-                       if (mtu < MTU_MIN) {
-                               if (if_setmtu(ifp, MTU_MIN) == 0)
-                                       sz = MTU_MIN;
+                       if ((mtu = if_getmtu(ifp)) == -1)
+                               logger(ifp->ctx, LOG_ERR,
+                                   "%s: if_getmtu: %m", ifp->name);
+                       else if (mtu < MTU_MIN) {
+                               if (if_setmtu(ifp, MTU_MIN) == -1)
+                                       logger(ifp->ctx, LOG_ERR,
+                                           "%s: if_setmtu: %m", ifp->name);
+                               mtu = MTU_MIN;
                        } else if (mtu > MTU_MAX) {
                                /* Even though our MTU could be greater than
                                 * MTU_MAX (1500) dhcpcd does not presently
                                 * handle DHCP packets any bigger. */
                                mtu = MTU_MAX;
                        }
-                       sz = htons((uint16_t)mtu);
-                       memcpy(p, &sz, 2);
-                       p += 2;
+                       if (mtu != -1) {
+                               *p++ = DHO_MAXMESSAGESIZE;
+                               *p++ = 2;
+                               sz = htons((uint16_t)mtu);
+                               memcpy(p, &sz, 2);
+                               p += 2;
+                       }
                }
 
                if (ifo->userclass[0]) {