📄 config.c
字号:
}intconfigure_global_option(void){ struct cf_list *cl; /* DNS servers */ if (cf_dns_list && dhcp6_mode != DHCP6_MODE_SERVER) { dprintf(LOG_INFO, "%s" "%s:%d server-only configuration", FNAME, configfilename, cf_dns_list->line); goto bad; } TAILQ_INIT(&dnslist0); for (cl = cf_dns_list; cl; cl = cl->next) { /* duplication check */ if (dhcp6_find_listval(&dnslist0, cl->ptr, DHCP6_LISTVAL_ADDR6)) { dprintf(LOG_INFO, "%s" "%s:%d duplicated DNS server: %s", FNAME, configfilename, cl->line, in6addr2str((struct in6_addr *)cl->ptr, 0)); goto bad; } if (dhcp6_add_listval(&dnslist0, cl->ptr, DHCP6_LISTVAL_ADDR6) == NULL) { dprintf(LOG_ERR, "%s" "failed to add a DNS server", FNAME); goto bad; } } return 0; bad: return -1;}#if 0/* we currently only construct EUI-64 based interface ID */static intget_default_ifid(pif) struct prefix_ifconf *pif;{ struct ifaddrs *ifa, *ifap; struct sockaddr *sdl; if (pif->ifid_len < 64) { dprintf(LOG_NOTICE, "%s" "ID length too short", FNAME); return -1; } if (getifaddrs(&ifap) < 0) { dprintf(LOG_ERR, "%s" "getifaddrs failed: %s", FNAME, strerror(errno)); return -1; } for (ifa = ifap; ifa; ifa = ifa->ifa_next) { char *cp; if (strcmp(ifa->ifa_name, pif->ifname) != 0) continue; sdl = ifa->ifa_addr; if (sizeof(*sdl) < 6) { dprintf(LOG_NOTICE, "%s" "link layer address is too short (%s)", FNAME, pif->ifname); goto fail; } memset(pif->ifid, 0, sizeof(pif->ifid)); cp = (char *)(sdl->sa_data + sizeof(*sdl)); pif->ifid[8] = cp[0]; pif->ifid[8] ^= 0x02; /* reverse the u/l bit*/ pif->ifid[9] = cp[1]; pif->ifid[10] = cp[2]; pif->ifid[11] = 0xff; pif->ifid[12] = 0xfe; pif->ifid[13] = cp[3]; pif->ifid[14] = cp[4]; pif->ifid[15] = cp[5]; break; } if (ifa == NULL) { dprintf(LOG_INFO, "%s" "cannot find interface information for %s", FNAME, pif->ifname); goto fail; } freeifaddrs(ifap); return (0); fail: freeifaddrs(ifap); return (-1);}#endifvoidconfigure_cleanup(void){ clear_ifconf(dhcp6_ifconflist); dhcp6_ifconflist = NULL; clear_hostconf(host_conflist0); host_conflist0 = NULL; dhcp6_clear_list(&dnslist0); TAILQ_INIT(&dnslist0);}voidconfigure_commit(void){ struct dhcp6_ifconf *ifc; struct dhcp6_if *ifp; /* commit interface configuration */ for (ifc = dhcp6_ifconflist; ifc; ifc = ifc->next) { if ((ifp = find_ifconfbyname(ifc->ifname)) != NULL) { ifp->send_flags = ifc->send_flags; ifp->allow_flags = ifc->allow_flags; clear_options(ifp->send_options); ifp->send_options = ifc->send_options; ifc->send_options = NULL; dhcp6_clear_list(&ifp->reqopt_list); ifp->reqopt_list = ifc->reqopt_list; TAILQ_INIT(&ifc->reqopt_list); dhcp6_clear_list(&ifp->addr_list); ifp->addr_list = ifc->addr_list; TAILQ_INIT(&ifc->addr_list); dhcp6_clear_list(&ifp->prefix_list); ifp->prefix_list = ifc->prefix_list; TAILQ_INIT(&ifc->prefix_list); ifp->server_pref = ifc->server_pref; memcpy(&ifp->iaidinfo, &ifc->iaidinfo, sizeof(ifp->iaidinfo)); } } clear_ifconf(dhcp6_ifconflist); /* commit prefix configuration */ if (host_conflist) { /* clear previous configuration. (need more work?) */ clear_hostconf(host_conflist); } host_conflist = host_conflist0; host_conflist0 = NULL;}static voidclear_ifconf(struct dhcp6_ifconf *iflist){ struct dhcp6_ifconf *ifc, *ifc_next; for (ifc = iflist; ifc; ifc = ifc_next) { ifc_next = ifc->next; free(ifc->ifname); clear_options(ifc->send_options); dhcp6_clear_list(&ifc->reqopt_list); free(ifc); }}static voidclear_hostconf(struct host_conf *hlist){ struct host_conf *host, *host_next; struct dhcp6_listval *p; for (host = hlist; host; host = host_next) { host_next = host->next; free(host->name); while ((p = TAILQ_FIRST(&host->prefix_list)) != NULL) { TAILQ_REMOVE(&host->prefix_list, p, link); free(p); } if (host->duid.duid_id) free(host->duid.duid_id); free(host); }}static voidclear_options(struct dhcp6_optconf *opt0){ struct dhcp6_optconf *opt, *opt_next; for (opt = opt0; opt; opt = opt_next) { opt_next = opt->next; free(opt->val); free(opt); }}static intadd_options(int opcode, struct dhcp6_ifconf *ifc, struct cf_list *cfl0){ struct dhcp6_listval *opt; struct cf_list *cfl; int opttype; for (cfl = cfl0; cfl; cfl = cfl->next) { if (opcode == DHCPOPTCODE_REQUEST) { for (opt = TAILQ_FIRST(&ifc->reqopt_list); opt; opt = TAILQ_NEXT(opt, link)) { if (opt->val_num == cfl->type) { dprintf(LOG_INFO, "%s" "duplicated requested" " option: %s", FNAME, dhcp6optstr(cfl->type)); goto next; /* ignore it */ } } } switch(cfl->type) { case DHCPOPT_RAPID_COMMIT: switch(opcode) { case DHCPOPTCODE_SEND: ifc->send_flags |= DHCIFF_RAPID_COMMIT; break; case DHCPOPTCODE_ALLOW: ifc->allow_flags |= DHCIFF_RAPID_COMMIT; break; default: dprintf(LOG_ERR, "%s" "invalid operation (%d) " "for option type (%d)", FNAME, opcode, cfl->type); return (-1); } break; case DHCPOPT_PREFIX_DELEGATION: switch(opcode) { case DHCPOPTCODE_REQUEST: ifc->send_flags |= DHCIFF_PREFIX_DELEGATION; break; default: dprintf(LOG_ERR, "%s" "invalid operation (%d) " "for option type (%d)", FNAME, opcode, cfl->type); return (-1); } break; case DHCPOPT_DNS: switch(opcode) { case DHCPOPTCODE_REQUEST: opttype = DH6OPT_DNS_RESOLVERS; if (dhcp6_add_listval(&ifc->reqopt_list, &opttype, DHCP6_LISTVAL_NUM) == NULL) { dprintf(LOG_ERR, "%s" "failed to " "configure an option", FNAME); return (-1); } break; default: dprintf(LOG_ERR, "%s" "invalid operation (%d) " "for option type (%d)", FNAME, opcode, cfl->type); break; } break; default: dprintf(LOG_ERR, "%s" "unknown option type: %d", FNAME, cfl->type); return (-1); } next:; } return (0);}static intadd_address(struct dhcp6_list *addr_list, struct dhcp6_addr *v6addr){ struct dhcp6_listval *lv, *val; /* avoid invalid addresses */ if (IN6_IS_ADDR_RESERVED(&v6addr->addr)) { dprintf(LOG_ERR, "%s" "invalid address: %s", FNAME, in6addr2str(&v6addr->addr, 0)); return (-1); } /* address duplication check */ for (lv = TAILQ_FIRST(addr_list); lv; lv = TAILQ_NEXT(lv, link)) { if (IN6_ARE_ADDR_EQUAL(&lv->val_dhcp6addr.addr, &v6addr->addr) && lv->val_dhcp6addr.plen == v6addr->plen) { dprintf(LOG_ERR, "%s" "duplicated address: %s/%d ", FNAME, in6addr2str(&v6addr->addr, 0), v6addr->plen); return (-1); } } if ((val = (struct dhcp6_listval *)malloc(sizeof(*val))) == NULL) dprintf(LOG_ERR, "%s" "memory allocation failed", FNAME); memset(val, 0, sizeof(*val)); memcpy(&val->val_dhcp6addr, v6addr, sizeof(val->val_dhcp6addr)); dprintf(LOG_DEBUG, "%s" "add address: %s", FNAME, in6addr2str(&v6addr->addr, 0)); TAILQ_INSERT_TAIL(addr_list, val, link); return (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -