}
struct interface *
-read_interface (const char *ifname, _unused int metric)
+read_interface(const char *ifname, _unused int metric)
{
int s;
struct ifreq ifr;
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);
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;
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__
}
int
-get_mtu(const char *ifname)
+do_mtu(const char *ifname, short int mtu)
{
struct ifreq ifr;
int r;
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)
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);