]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Save a few more bytes.
authorRoy Marples <roy@marples.name>
Sat, 29 Mar 2008 11:41:00 +0000 (11:41 +0000)
committerRoy Marples <roy@marples.name>
Sat, 29 Mar 2008 11:41:00 +0000 (11:41 +0000)
client.c
if.c
if.h

index 6636c3167e93ea5e5c09d3d5b4890a5d2c1cc53b..bec74ec09fb203113420d69cef3d7364c1548c77 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1089,6 +1089,9 @@ dhcp_run(const struct options *options, int *pidfd)
                goto eexit;
        }
 
+       logger(LOG_INFO, "hardware address = %s",
+              hwaddr_ntoa(iface->hwaddr, iface->hwlen));
+
        state = xzalloc(sizeof(*state));
        state->dhcp = xzalloc(sizeof(*state->dhcp));
        state->pidfd = pidfd;
diff --git a/if.c b/if.c
index 97ed3cf9d926099fed7034eb437d34da8a63b64b..d08fa046f7c636c64825049c51cb02a0710d843b 100644 (file)
--- a/if.c
+++ b/if.c
@@ -258,7 +258,7 @@ do_interface(const char *ifname,
 }
 
 struct interface *
-read_interface (const char *ifname, _unused int metric)
+read_interface(const char *ifname, _unused int metric)
 {
        int s;
        struct ifreq ifr;
@@ -292,11 +292,6 @@ read_interface (const char *ifname, _unused int metric)
        case ARPHRD_INFINIBAND:
                hwlen = INFINIBAND_ADDR_LEN;
                break;
-       default:
-               logger (LOG_ERR,
-                       "interface is not Ethernet, FireWire, " \
-                       "InfiniBand or Token Ring");
-               goto eexit;
        }
 
        hwaddr = xmalloc(sizeof(unsigned char) * HWADDR_LEN);
@@ -319,14 +314,12 @@ read_interface (const char *ifname, _unused int metric)
        if (ioctl(s, SIOCGIFMTU, &ifr) == -1)
                goto eexit;
 
+       /* Ensure that the MTU is big enough for DHCP */
        if (ifr.ifr_mtu < MTU_MIN) {
-               logger(LOG_DEBUG, "MTU of %d is too low, setting to %d",
-                      ifr.ifr_mtu, MTU_MIN);
                ifr.ifr_mtu = MTU_MIN;
                strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-               if (ioctl(s, SIOCSIFMTU, &ifr) == -1) {
+               if (ioctl(s, SIOCSIFMTU, &ifr) == -1)
                        goto eexit;
-               }
        }
        mtu = ifr.ifr_mtu;
 
@@ -357,9 +350,6 @@ read_interface (const char *ifname, _unused int metric)
        iface->arpable = !(ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK));
        iface->mtu = iface->previous_mtu = mtu;
 
-       logger(LOG_INFO, "hardware address = %s",
-              hwaddr_ntoa(iface->hwaddr, iface->hwlen));
-
        /* 0 is a valid fd, so init to -1 */
        iface->fd = -1;
 #ifdef __linux__
@@ -373,7 +363,7 @@ eexit:
 }
 
 int
-get_mtu(const char *ifname)
+do_mtu(const char *ifname, short int mtu)
 {
        struct ifreq ifr;
        int r;
@@ -384,33 +374,14 @@ get_mtu(const char *ifname)
 
        memset(&ifr, 0, sizeof(ifr));
        strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-       r = ioctl(s, SIOCGIFMTU, &ifr);
+       ifr.ifr_mtu = mtu;
+       r = ioctl(s, mtu ? SIOCSIFMTU : SIOCGIFMTU, &ifr);
        close(s);
-
        if (r == -1)
                return -1;
        return ifr.ifr_mtu;
 }
 
-int
-set_mtu(const char *ifname, short int mtu)
-{
-       struct ifreq ifr;
-       int r;
-       int s;
-
-       if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
-               return -1;
-
-       memset(&ifr, 0, sizeof(ifr));
-       logger(LOG_DEBUG, "setting MTU to %d", mtu);
-       strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-       ifr.ifr_mtu = mtu;
-       r = ioctl(s, SIOCSIFMTU, &ifr);
-       close(s);
-       return r == 0 ? 0 : -1;
-}
-
 static void
 log_route(struct in_addr destination, struct in_addr netmask,
          struct in_addr gateway, _unused int metric, int del)
diff --git a/if.h b/if.h
index 311c30b1915afef5da42dbd9d5d744f2bebaa334..06e73001019d555541c81eed474302d1df7a6535 100644 (file)
--- a/if.h
+++ b/if.h
@@ -127,8 +127,9 @@ char *hwaddr_ntoa(const unsigned char *, size_t);
 size_t hwaddr_aton(unsigned char *, const char *);
 
 struct interface *read_interface(const char *, int);
-int get_mtu(const char *);
-int set_mtu(const char *, short int);
+int do_mtu(const char *, short int);
+#define get_mtu(iface) do_mtu(iface, 0)
+#define set_mtu(iface, mtu) do_mtu(iface, mtu)
 
 int add_address(const char *, struct in_addr, struct in_addr, struct in_addr);
 int del_address(const char *, struct in_addr, struct in_addr);