diff options
Diffstat (limited to 'src/radv.c')
-rw-r--r-- | src/radv.c | 71 |
1 files changed, 46 insertions, 25 deletions
@@ -1,4 +1,4 @@ -/* dnsmasq is Copyright (c) 2000-2015 Simon Kelley +/* dnsmasq is Copyright (c) 2000-2018 Simon Kelley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,11 +28,12 @@ struct ra_param { time_t now; - int ind, managed, other, found_context, first, adv_router; + int ind, managed, other, first, adv_router; char *if_name; struct dhcp_netid *tags; struct in6_addr link_local, link_global, ula; unsigned int glob_pref_time, link_pref_time, ula_pref_time, adv_interval, prio; + struct dhcp_context *found_context; }; struct search_param { @@ -81,7 +82,7 @@ void ra_init(time_t now) /* ensure this is around even if we're not doing DHCPv6 */ expand_buf(&daemon->outpacket, sizeof(struct dhcp_packet)); - /* See if we're guessing SLAAC addresses, if so we need to recieve ping replies */ + /* See if we're guessing SLAAC addresses, if so we need to receive ping replies */ for (context = daemon->dhcp6; context; context = context->next) if ((context->flags & CONTEXT_RA_NAME)) break; @@ -111,10 +112,10 @@ void ra_init(time_t now) daemon->icmp6fd = fd; if (daemon->doing_ra) - ra_start_unsolicted(now, NULL); + ra_start_unsolicited(now, NULL); } -void ra_start_unsolicted(time_t now, struct dhcp_context *context) +void ra_start_unsolicited(time_t now, struct dhcp_context *context) { /* init timers so that we do ra's for some/all soon. some ra_times will end up zeroed if it's not appropriate to advertise those contexts. @@ -245,7 +246,7 @@ static void send_ra_alias(time_t now, int iface, char *iface_name, struct in6_ad struct dhcp_netid iface_id; struct dhcp_opt *opt_cfg; struct ra_interface *ra_param = find_iface_param(iface_name); - int done_dns = 0, old_prefix = 0; + int done_dns = 0, old_prefix = 0, mtu = 0; unsigned int min_pref_time; #ifdef HAVE_LINUX_NETWORK FILE *f; @@ -254,7 +255,7 @@ static void send_ra_alias(time_t now, int iface, char *iface_name, struct in6_ad parm.ind = iface; parm.managed = 0; parm.other = 0; - parm.found_context = 0; + parm.found_context = NULL; parm.adv_router = 0; parm.if_name = iface_name; parm.first = 1; @@ -263,8 +264,10 @@ static void send_ra_alias(time_t now, int iface, char *iface_name, struct in6_ad parm.adv_interval = calc_interval(ra_param); parm.prio = calc_prio(ra_param); - save_counter(0); - ra = expand(sizeof(struct ra_packet)); + reset_counter(); + + if (!(ra = expand(sizeof(struct ra_packet)))) + return; ra->type = ND_ROUTER_ADVERT; ra->code = 0; @@ -311,8 +314,14 @@ static void send_ra_alias(time_t now, int iface, char *iface_name, struct in6_ad unsigned int old = difftime(now, context->address_lost_time); if (old > context->saved_valid) - { + { /* We've advertised this enough, time to go */ + + /* If this context held the timeout, and there's another context in use + transfer the timeout there. */ + if (context->ra_time != 0 && parm.found_context && parm.found_context->ra_time == 0) + new_timeout(parm.found_context, iface_name, now); + *up = context->next; free(context); } @@ -393,22 +402,32 @@ static void send_ra_alias(time_t now, int iface, char *iface_name, struct in6_ad put_opt6_long(1000 * calc_interval(find_iface_param(iface_name))); } + /* Set the MTU from ra_param if any, an MTU of 0 mean automatic for linux, */ + /* an MTU of -1 prevents the option from being sent. */ + if (ra_param) + mtu = ra_param->mtu; #ifdef HAVE_LINUX_NETWORK - /* Note that IPv6 MTU is not necessarilly the same as the IPv4 MTU + /* Note that IPv6 MTU is not necessarily the same as the IPv4 MTU available from SIOCGIFMTU */ - sprintf(daemon->namebuff, "/proc/sys/net/ipv6/conf/%s/mtu", iface_name); - if ((f = fopen(daemon->namebuff, "r"))) + if (mtu == 0) { - if (fgets(daemon->namebuff, MAXDNAME, f)) - { - put_opt6_char(ICMP6_OPT_MTU); - put_opt6_char(1); - put_opt6_short(0); - put_opt6_long(atoi(daemon->namebuff)); - } - fclose(f); + char *mtu_name = ra_param ? ra_param->mtu_name : NULL; + sprintf(daemon->namebuff, "/proc/sys/net/ipv6/conf/%s/mtu", mtu_name ? : iface_name); + if ((f = fopen(daemon->namebuff, "r"))) + { + if (fgets(daemon->namebuff, MAXDNAME, f)) + mtu = atoi(daemon->namebuff); + fclose(f); + } } #endif + if (mtu > 0) + { + put_opt6_char(ICMP6_OPT_MTU); + put_opt6_char(1); + put_opt6_short(0); + put_opt6_long(mtu); + } iface_enumerate(AF_LOCAL, &send_iface, add_lla); @@ -522,7 +541,7 @@ static void send_ra_alias(time_t now, int iface, char *iface_name, struct in6_ad } while (retry_send(sendto(daemon->icmp6fd, daemon->outpacket.iov_base, - save_counter(0), 0, (struct sockaddr *)&addr, + save_counter(-1), 0, (struct sockaddr *)&addr, sizeof(addr)))); } @@ -639,8 +658,10 @@ static int add_prefixes(struct in6_addr *local, int prefix, off_link = (context->flags & CONTEXT_RA_OFF_LINK); } - param->first = 0; - param->found_context = 1; + param->first = 0; + /* found_context is the _last_ one we found, so if there's + more than one, it's not the first. */ + param->found_context = context; } /* configured time is ceiling */ @@ -772,7 +793,7 @@ time_t periodic_ra(time_t now) associated with it, because it's for a subnet we dont have an interface on. Probably we're doing DHCP on a remote subnet via a relay. Zero the timer, since we won't - ever be able to send ra's and satistfy it. */ + ever be able to send ra's and satisfy it. */ context->ra_time = 0; if (param.iface != 0 && |