ra: always send current hop limit
authorSteven Barth <steven@midlink.org>
Fri, 10 Apr 2015 11:52:00 +0000 (13:52 +0200)
committerSteven Barth <steven@midlink.org>
Fri, 10 Apr 2015 11:52:00 +0000 (13:52 +0200)
src/odhcpd.c
src/odhcpd.h
src/router.c

index 52bca13c4db7019a2ccbaee44c6ed88fa30ae022..aad5b37b2e5b831c9c910660bcc453659060e5ce 100644 (file)
@@ -113,11 +113,11 @@ int odhcpd_open_rtnl(void)
 
 
 // Read IPv6 MTU for interface
-int odhcpd_get_interface_mtu(const char *ifname)
+int odhcpd_get_interface_config(const char *ifname, const char *what)
 {
        char buf[64];
-       const char *sysctl_pattern = "/proc/sys/net/ipv6/conf/%s/mtu";
-       snprintf(buf, sizeof(buf), sysctl_pattern, ifname);
+       const char *sysctl_pattern = "/proc/sys/net/ipv6/conf/%s/%s";
+       snprintf(buf, sizeof(buf), sysctl_pattern, ifname, what);
 
        int fd = open(buf, O_RDONLY);
        ssize_t len = read(fd, buf, sizeof(buf) - 1);
@@ -126,10 +126,8 @@ int odhcpd_get_interface_mtu(const char *ifname)
        if (len < 0)
                return -1;
 
-
        buf[len] = 0;
        return atoi(buf);
-
 }
 
 
index 21dc99fb4301fd26064f15f01e0c22f9b01d8ba4..5944661d67db1483a2565edccabc0ebc265ce8fd 100644 (file)
@@ -186,7 +186,7 @@ ssize_t odhcpd_get_interface_addresses(int ifindex,
                struct odhcpd_ipaddr *addrs, size_t cnt);
 int odhcpd_get_preferred_interface_address(int ifindex, struct in6_addr *addr);
 struct interface* odhcpd_get_interface_by_name(const char *name);
-int odhcpd_get_interface_mtu(const char *ifname);
+int odhcpd_get_interface_config(const char *ifname, const char *what);
 int odhcpd_get_mac(const struct interface *iface, uint8_t mac[6]);
 struct interface* odhcpd_get_interface_by_index(int ifindex);
 struct interface* odhcpd_get_master_interface(void);
index 60d6b3f3b39d39575b7bbc9f69ab3ac9ecde7bc7..f942d8f851639c039faff54cf985ef0a80ba8fbc 100644 (file)
@@ -209,9 +209,11 @@ static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len)
 // Router Advert server mode
 static uint64_t send_router_advert(struct interface *iface, const struct in6_addr *from)
 {
-       int mtu = odhcpd_get_interface_mtu(iface->ifname);
-       if (mtu < 0)
-               mtu = 1500;
+       int mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
+       int hlim = odhcpd_get_interface_config(iface->ifname, "hop_limit");
+
+       if (mtu < 1280)
+               mtu = 1280;
 
        struct {
                struct nd_router_advert h;
@@ -224,6 +226,9 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
                .mtu = {ND_OPT_MTU, 1, 0, htonl(mtu)},
        };
 
+       if (hlim > 0)
+               adv.h.nd_ra_curhoplimit = hlim;
+
        if (iface->dhcpv6)
                adv.h.nd_ra_flags_reserved = ND_RA_FLAG_OTHER;