From: Roy Marples Date: Sat, 29 Mar 2008 11:41:00 +0000 (+0000) Subject: Save a few more bytes. X-Git-Tag: v4.0.2~521 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75e802f3d49ad0bc85bd7c0faa6038eb2f98124c;p=thirdparty%2Fdhcpcd.git Save a few more bytes. --- diff --git a/client.c b/client.c index 6636c316..bec74ec0 100644 --- 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 97ed3cf9..d08fa046 100644 --- 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 311c30b1..06e73001 100644 --- 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);