/* Build a map from ra-names subnets to corresponding interfaces. This is used to go from DHCPv4 leases to SLAAC addresses, interface->IPv6-subnet, IPv6-subnet + MAC address -> SLAAC. */ static int add_subnet(struct in6_addr *local, int prefix, int scope, int if_index, int dad, void *vparam) { struct dhcp_context *context; (void)scope; (void)dad; (void)vparam; for (context = daemon->ra_contexts; context; context = context->next) if ((context->flags & CONTEXT_RA_NAME) && prefix == context->prefix && is_same_net6(local, &context->start6, prefix) && is_same_net6(local, &context->end6, prefix)) { context->if_index = if_index; context->local6 = *local; } return 1; }
static struct cond_domain *search_domain6(struct in6_addr *addr, struct cond_domain *c) { u64 addrpart = addr6part(addr); for (; c; c = c->next) if (c->is6 && is_same_net6(addr, &c->start6, 64) && addrpart >= addr6part(&c->start6) && addrpart <= addr6part(&c->end6)) return c; return NULL; }
int is_name_synthetic(int flags, char *name, struct all_addr *addr) { char *p; struct cond_domain *c = NULL; int prot = AF_INET; #ifdef HAVE_IPV6 if (flags & F_IPV6) prot = AF_INET6; #endif for (c = daemon->synth_domains; c; c = c->next) { int found = 0; char *tail, *pref; for (tail = name, pref = c->prefix; *tail != 0 && pref && *pref != 0; tail++, pref++) { unsigned int c1 = (unsigned char) *pref; unsigned int c2 = (unsigned char) *tail; if (c1 >= 'A' && c1 <= 'Z') c1 += 'a' - 'A'; if (c2 >= 'A' && c2 <= 'Z') c2 += 'a' - 'A'; if (c1 != c2) break; } if (pref && *pref != 0) continue; /* prefix match fail */ /* NB, must not alter name if we return zero */ for (p = tail; *p; p++) { char c = *p; if ((c >='0' && c <= '9') || c == '-') continue; #ifdef HAVE_IPV6 if (prot == AF_INET6 && ((c >='A' && c <= 'F') || (c >='a' && c <= 'f'))) continue; #endif break; } if (*p != '.') continue; *p = 0; #ifdef HAVE_IPV6 if (prot == AF_INET6 && strstr(tail, "--ffff-") == tail) { /* special hack for v4-mapped. */ memcpy(tail, "::ffff:", 7); for (p = tail + 7; *p; p++) if (*p == '-') *p = '.'; } else #endif { /* swap . or : for - */ for (p = tail; *p; p++) if (*p == '-') { if (prot == AF_INET) *p = '.'; #ifdef HAVE_IPV6 else *p = ':'; #endif } } if (hostname_isequal(c->domain, p+1) && inet_pton(prot, tail, addr)) { if (prot == AF_INET) { if (!c->is6 && ntohl(addr->addr.addr4.s_addr) >= ntohl(c->start.s_addr) && ntohl(addr->addr.addr4.s_addr) <= ntohl(c->end.s_addr)) found = 1; } #ifdef HAVE_IPV6 else { u64 addrpart = addr6part(&addr->addr.addr6); if (c->is6 && is_same_net6(&addr->addr.addr6, &c->start6, 64) && addrpart >= addr6part(&c->start6) && addrpart <= addr6part(&c->end6)) found = 1; } #endif } /* restore name */ for (p = tail; *p; p++) if (*p == '.' || *p == ':') *p = '-'; *p = '.'; if (found) return 1; } return 0; }