radv.c tidying.

This commit is contained in:
Simon Kelley
2012-03-29 11:07:25 +01:00
parent 0e88d53faa
commit 1e02a85970

View File

@@ -276,7 +276,6 @@ static void send_ra(int iface, char *iface_name, struct in6_addr *dest)
static int add_prefixes(struct in6_addr *local, int prefix, static int add_prefixes(struct in6_addr *local, int prefix,
int scope, int if_index, int dad, void *vparam) int scope, int if_index, int dad, void *vparam)
{ {
struct dhcp_context *context;
struct ra_param *param = vparam; struct ra_param *param = vparam;
(void)scope; /* warning */ (void)scope; /* warning */
@@ -290,11 +289,11 @@ static int add_prefixes(struct in6_addr *local, int prefix,
!IN6_IS_ADDR_LINKLOCAL(local) && !IN6_IS_ADDR_LINKLOCAL(local) &&
!IN6_IS_ADDR_MULTICAST(local)) !IN6_IS_ADDR_MULTICAST(local))
{ {
int do_prefix = 0;
int do_slaac = 0; int do_slaac = 0;
int deprecate = 0; int deprecate = 0;
unsigned int time = 0xffffffff; unsigned int time = 0xffffffff;
struct in6_addr *addr = NULL; struct dhcp_context *context;
struct prefix_opt *opt;
for (context = daemon->ra_contexts; context; context = context->next) for (context = daemon->ra_contexts; context; context = context->next)
if (prefix == context->prefix && if (prefix == context->prefix &&
@@ -331,36 +330,41 @@ static int add_prefixes(struct in6_addr *local, int prefix,
param->first = 0; param->first = 0;
param->found_context = 1; param->found_context = 1;
if (context->flags & CONTEXT_RA_DONE) if (!(context->flags & CONTEXT_RA_DONE))
continue; {
context->flags |= CONTEXT_RA_DONE;
context->flags |= CONTEXT_RA_DONE; do_prefix = 1;
addr = &context->start6; }
} }
if (addr && (opt = expand(sizeof(struct prefix_opt)))) if (do_prefix)
{ {
u64 addrpart = addr6part(addr); struct prefix_opt *opt;
u64 mask = (prefix == 64) ? (u64)-1LL : (1LLU << (128 - prefix)) - 1LLU;
/* lifetimes must be min 2 hrs, by RFC 2462 */ if ((opt = expand(sizeof(struct prefix_opt))))
if (time < 7200) {
time = 7200; u64 addrpart = addr6part(local);
u64 mask = (prefix == 64) ? (u64)-1LL : (1LLU << (128 - prefix)) - 1LLU;
opt->type = ICMP6_OPT_PREFIX; /* lifetimes must be min 2 hrs, by RFC 2462 */
opt->len = 4; if (time < 7200)
opt->prefix_len = prefix; time = 7200;
/* autonomous only is we're not doing dhcp */
opt->flags = do_slaac ? 0x40 : 0x00;
opt->valid_lifetime = htonl(time);
opt->preferred_lifetime = htonl(deprecate ? 0 : time);
opt->reserved = 0;
opt->prefix = *addr; opt->type = ICMP6_OPT_PREFIX;
setaddr6part(&opt->prefix, addrpart & ~mask); opt->len = 4;
opt->prefix_len = prefix;
/* autonomous only is we're not doing dhcp */
opt->flags = do_slaac ? 0x40 : 0x00;
opt->valid_lifetime = htonl(time);
opt->preferred_lifetime = htonl(deprecate ? 0 : time);
opt->reserved = 0;
inet_ntop(AF_INET6, &opt->prefix, daemon->addrbuff, ADDRSTRLEN); opt->prefix = *local;
my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s", param->if_name, daemon->addrbuff); setaddr6part(&opt->prefix, addrpart & ~mask);
inet_ntop(AF_INET6, &opt->prefix, daemon->addrbuff, ADDRSTRLEN);
my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s", param->if_name, daemon->addrbuff);
}
} }
} }
} }