// 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);
if (len < 0)
return -1;
-
buf[len] = 0;
return atoi(buf);
-
}
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);
// 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;
.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;