📄 netconf.c
字号:
break; } case PPP_UPEVT_CHAP_CLIENT_SUCCESS: case PPP_UPEVT_CHAP_CLIENT_FAILURE: { ppp_auth_string_t *msg = arg; BUG(BUG_SNARK_PPP_AUTH_STATUS, BUG_CONTINUABLE, net, (BUG_OUT, "PPP(%s): CHAP client: %s: \"%.*s\"", net->s_name, (event == PPP_UPEVT_CHAP_CLIENT_SUCCESS ? "Success" : "Failure"), (int) ppp_auth_string_len(msg), ppp_auth_string_str(msg))); result = PPP_UPRET_CONTINUE; break; } case PPP_UPEVT_CHAP_CLIENT_DONE: case PPP_UPEVT_CHAP_SERVER_DONE: BUG(BUG_SNARK_PPP_AUTH_STATUS, BUG_CONTINUABLE, net, (BUG_OUT, "PPP(%s): Auth done: %s %s", net->s_name, (event == PPP_UPEVT_CHAP_CLIENT_DONE ? "CHAP client" : "CHAP server"), ((* (ppp_auth_status_t *) arg) == PPP_AUTH_FAILURE ? "lost" : "won"))); result = PPP_UPRET_CONTINUE; break;#endif /* INSTALL_ATTACHE_PPP_CHAP */#if INSTALL_ATTACHE_PPP_PAP case PPP_UPEVT_PAP_SERVER_STARTING: result = PPP_UPRET_CONTINUE; break; case PPP_UPEVT_PAP_CLIENT_STARTING: if ((s = INI_LOOKUP(attache_section, "ppp-pap-client-info")) != 0 && parse_line(s, av, sizeof(av)/sizeof(*av)) == 2) { ppp_auth_string_cons(ptr_ppp_pap_client_username(net), (bits8_t *) av[0], STRLEN(av[0])); ppp_auth_string_cons(ptr_ppp_pap_client_secret(net), (bits8_t *) av[1], STRLEN(av[1])); result = PPP_UPRET_CONTINUE; } break; case PPP_UPEVT_PAP_SERVER_GET_VERDICT: { ppp_auth_status_t status = PPP_AUTH_FAILURE; ppp_pap_info_t *info = arg; ppp_auth_string_t *username = ppp_pap_info_username(info); ppp_auth_string_t *secret = ppp_pap_info_secret(info); BUG_ASSERT(ppp_auth_string_str(username) && ppp_auth_string_str(secret)); for (s = INI_ITER_START(attache_section, "ppp-pap-server-info"); s; s = INI_ITER_NEXT()) { if (parse_line(s, av, sizeof(av)/sizeof(*av)) == 2 || STRNCMP(av[0], ppp_auth_string_str(username), ppp_auth_string_len(username)) == 0 || STRNCMP(av[1], ppp_auth_string_str(secret), ppp_auth_string_len(secret)) == 0) { status = PPP_AUTH_SUCCESS; break; } } ppp_pap_server_set_verdict(net, status); result = PPP_UPRET_CONTINUE; break; } case PPP_UPEVT_PAP_CLIENT_SUCCESS: case PPP_UPEVT_PAP_CLIENT_FAILURE: BUG(BUG_SNARK_PPP_AUTH_STATUS, BUG_CONTINUABLE, net, (BUG_OUT, "PPP(%s): PAP client: %s: \"%.*s\"", net->s_name, (event == PPP_UPEVT_PAP_CLIENT_SUCCESS ? "Success" : "Failure"), (int) ppp_auth_string_len((ppp_auth_string_t *) arg), ppp_auth_string_str((ppp_auth_string_t *) arg))); result = PPP_UPRET_CONTINUE; break; case PPP_UPEVT_PAP_CLIENT_DONE: case PPP_UPEVT_PAP_SERVER_DONE: BUG(BUG_SNARK_PPP_AUTH_STATUS, BUG_CONTINUABLE, net, (BUG_OUT, "PPP(%s): Auth done: %s %s", net->s_name, (event == PPP_UPEVT_PAP_CLIENT_DONE ? "PAP client" : "PAP server"), ((* (ppp_auth_status_t *) arg) == PPP_AUTH_FAILURE ? "lost" : "won"))); result = PPP_UPRET_CONTINUE; break;#endif /* INSTALL_ATTACHE_PPP_PAP */ case PPP_UPEVT_NO_CLIENT_AUTH: case PPP_UPEVT_NO_SERVER_AUTH: BUG(BUG_SNARK_PPP_AUTH_STATUS, BUG_CONTINUABLE, net, (BUG_OUT, "PPP(%s): No %s authentication available", net->s_name, (event == PPP_UPEVT_NO_CLIENT_AUTH ? "client" : "server"))); result = PPP_UPRET_CONTINUE; break; default: result = PPP_UPRET_UNKNOWN_CODE; break; } if (close_ini_when_done) { ini_close(ini_handle); ini_handle = 0; } return result;}#endif /* INSTALL_ATTACHE_PPP */#if SNARK_GRATUITOUS_ARP/* * Send an ARP for our own address. This is an ugly thing to do, but * if we make up a new ethernet address every time, it's the best * way to avoid confusing everyone else on the wire. * * Ignore return values, because there isn't anything we could do on * an error anyway. */void snark_gratuitous_arp(net_if * net, ipaddr_t *from){ if (net->arp && from) arp_send_request(net, from, from);}#endif /* SNARK_GRATUITOUS_ARP */#if INSTALL_ATTACHE_LOOPBACK/* * Here's where we configure the loopback interface. It's subject * to the same restrictions as any other interface, if it's not * configured we don't attach it. */static void netconfig_loop(void){ struct net *net; static char name[] = "lp0"; if ((net = GLUE_ALLOC(sizeof(*net) + sizeof(name))) == 0) return; MEMSET(net, 0, sizeof(*net)); net->s_name = (char *) (net + 1); net->driver = &loopdriver; net->mtu = LOOP_MTU; net->speed = 0x7FFFFFFFL; /* Some SNMPs don't like 0xFFFFFFFF here */ STRCPY(net->s_name, name);#if 1 net->flags = NF_DOWN;#endif#if 0/*INSTALL_ATTACHE_12_NF_DOWN_COMPAT*/ if (netconfig_if(net)) if_attach(net); else GLUE_FREE(net);#else if (netconfig_if(net)) { if (if_attach(net) == 0) if_up(net); } else GLUE_FREE(net);#endif}#endif /* INSTALL_ATTACHE_LOOPBACK */#if INSTALL_ATTACHE_DNS/* * DNS configuration. This is hairy, mostly because we're trying to * be nice and completely general. Don't look at this too hard. */static void netconfig_dns(void){ static char ns[] = "nameserver"; static char suffix[] = "dns-suffix"; static char pref[] = "dns-preference"; unsigned char *p, *eob; int n; size_t len; char *s; /* * DNS transport dispatch vector, resource limits. */ MEMSET(&domain_config, 0, sizeof(domain_config)); domain_config.transport = &dns_udp_dispatch; domain_config.max_tries_per_server = 5; domain_config.wait_for_buf_alloc = 10; domain_config.max_buf_alloc_failures = 10; /* * Read DNS nameserver addresses. * usage: nameserver=addr */ n = 0; for (s = INI_ITER_START(attache_section, ns); s; s = INI_ITER_NEXT()) n++; if ((len = n * sizeof(struct dns_server)) == 0) { printf(" -- No DNS nameservers --\n"); } else if ((domain_config.servers = GLUE_ALLOC(len)) == 0) { fprintf(stderr, "Not enough space for %d nameservers, ignoring\n", n); } else { for (s = INI_ITER_START(attache_section, ns); s; s = INI_ITER_NEXT()) if ((domain_config.servers[domain_config.n_servers].addr = atoinet(s)) == 0) fprintf(stderr, "Error parsing nameserver address: %s\n", s); else domain_config.n_servers++; } /* * Read DNS search path. Gotta convert to internal form too, fun city. * usage: dns-suffix=dnsname */ len = sizeof(unsigned char *); n = 0; for (s = INI_ITER_START(attache_section, suffix); s; s = INI_ITER_NEXT()) { int encoded = dns_encode_name(0, DNS_MAX_DOMAIN_NAME, s); if (encoded > 0) { n++; len += sizeof(unsigned char *) + encoded; } } if (n == 0) { printf(" -- No DNS search path --\n"); } else if ((domain_config.search_path = GLUE_ALLOC(len)) == 0) { fprintf(stderr, "Not enough space for %d DNS suffixes, ignoring\n", n); } else { eob = ((unsigned char *) domain_config.search_path) + len; p = (unsigned char *) (domain_config.search_path + n + 1); n = 0; for (s = INI_ITER_START(attache_section, suffix); s; s = INI_ITER_NEXT()) { int res = dns_encode_name(p, (unsigned) (eob - p), s); if (res > 0) { domain_config.search_path[n++] = p; p += res; } else { fprintf(stderr, "Couldn't parse DNS suffix \"%s\", err=%d, ignoring\n", s, res); } } domain_config.search_path[n] = 0; } /* * Read DNS address sorting preference list. * usage: dns-preference=addr mask */ n = 0; for (s = INI_ITER_START(attache_section, pref); s; s = INI_ITER_NEXT()) n++; if ((len = (n + 1) * sizeof(struct dns_preference_list)) == 0) { printf(" -- No DNS address sort list --\n"); } else if ((domain_config.preferences = GLUE_ALLOC(len)) == 0) { fprintf(stderr, "Not enough space for %d preferences, ignoring\n", n); } else { n = 0; for (s = INI_ITER_START(attache_section, pref); s; s = INI_ITER_NEXT()) { char *argv[3], line[80]; strncpy(line, s, sizeof(line) - 1); if (parse_line(s, argv, sizeof(argv)/sizeof(*argv)) != 2 || (domain_config.preferences[n].addr = atoinet(argv[0])) == 0 || (domain_config.preferences[n].mask = atoinet(argv[1])) == 0) { fprintf(stderr, "Couldn't parse preference \"%s\", ignoring\n", s); } else { n++; } } domain_config.preferences[n].addr = DNS_PREFERENCE_END_OF_LIST; } /* * Random control parameters that nobody but me will ever set. */ if ((s = INI_LOOKUP(attache_section, "max-tries-per-server")) != 0) domain_config.max_tries_per_server = atoi(s); if ((s = INI_LOOKUP(attache_section, "wait-for-buf-alloc")) != 0) domain_config.wait_for_buf_alloc = atol(s); if ((s = INI_LOOKUP(attache_section, "max-buf-alloc-failures")) != 0) domain_config.max_buf_alloc_failures = atoi(s); if ((s = INI_LOOKUP(attache_section, "max-ttl")) != 0) domain_config.max_ttl = atol(s);}#endif/* * pick up my ip addresses the new way * usage: ip-address=address mask net [broadcast-address] * address, mask, and broadcast-address are IP addresses in decimal * dotted notation, and net is an interface name (net->s_name field) */static void netconfig_addresses(void){ char *addr_string, *addr_argv[7]; int error_code, addr_argc; ipaddr_t addr, mask, brd; bits8_t pfxlen; struct net *net; SET_IPADDR_TYPE(&brd, IPV4); IPADDR_ALL_ONES(&brd); for (addr_string = INI_ITER_START(attache_section, "ip-address"); addr_string; addr_string = INI_ITER_NEXT()) { addr_argc = parse_line(addr_string, addr_argv, 7); if ((addr_argc != 3) && (addr_argc != 4)) fprintf(stderr, "Error in argument count to `ip-address' command: %s\n", addr_string); else if (string_to_ipaddr(addr_argv[0], &addr), GET_IPADDR_TYPE(&addr) != IPV4) fprintf(stderr, "Bad address `%s' in `ip-address' command\n", addr_argv[0]); else if ((string_to_ipaddr(addr_argv[1], &mask), GET_IPADDR_TYPE(&mask) != IPV4) || ((pfxlen = ipv4_mask_to_pfxlen(&mask)) == 0)) fprintf(stderr, "Bad mask `%s' in `ip-address' command\n", addr_argv[1]); else if ((net = if_lookup(addr_argv[2])) == 0) fprintf(stderr, "No network interface named `%s' for ip-address %s\n", addr_argv[2], addr_argv[0]); else if ((addr_argc == 4) && ((string_to_ipaddr(addr_argv[3], &brd), GET_IPADDR_TYPE(&brd) != IPV4))) fprintf(stderr, "Bad broadcast address `%s' in `ip-address' command\n", addr_argv[3]); else { char brd_str[3*4+3+1]; /* WWW.XXX.YYY.ZZZ */ ipaddr_to_string(&brd, brd_str, sizeof(brd_str)); error_code = route_add_address(&addr, pfxlen, &brd, net); switch (error_code) { case RCERR_NONE: printf(" -- IP address: %s/", addr_argv[0]); printf("%s on %s", addr_argv[1], net->s_name); printf(" broadcast: %s --\n", brd_str); break; case RCERR_BADBRD: fprintf(stderr, "Bad broadcast address `%s' for ip-address `%s'\n" "either it's not a legal broadcast address or it doesn't\n" "match a previous broadcast address for this subnet\n", brd_str, addr_argv[0]); default: fprintf(stderr, "route_add_address() error %d for ip-address `%s'\n", error_code, addr_argv[0]); break; } } }#if INSTALL_ATTACHE_IPV6 SET_IPADDR_TYPE(&brd, IPV6); IPADDR_ZERO(&brd); for (addr_string = INI_ITER_START(attache_section, "ipv6-address"); addr_string; addr_string = INI_ITER_NEXT()) { addr_argc = parse_line(addr_string, addr_argv, 7); if (addr_argc != 3) fprintf(stderr, "Error in arg count to `ipv6-address' command: %s\n", addr_string); else if (string_to_ipaddr(addr_argv[0], &addr), GET_IPADDR_TYPE(&addr) != IPV6) fprintf(stderr, "Bad address `%s' in `ip-address' command\n", addr_argv[0]); else if ((pfxlen = atoi(addr_argv[1])) > 128) fprintf(stderr, "Bad prefix length `%d' in `ip-address' command\n", pfxlen); else if ((net = if_lookup(addr_argv[2])) == 0) fprintf(stderr, "No network interface named `%s' for ip-address %s\n", addr_argv[2], addr_argv[0]); else { error_code = route_add_address(&addr, pfxlen, &brd, net); switch (error_code) { case RCERR_NONE: printf(" -- IPv6 address: %s/", addr_argv[0]); printf("%s on %s\n", addr_argv[1], net->s_name); break; default: fprintf(stderr, "route_add_address() error %d for ip-address `%s'\n", error_code, addr_argv[0]); break; } } }#endif /* INSTALL_ATTACHE_IPV6 */}/* * Configure all the static routing stuff, default router, etcetera. * This is hairy. Don't look at it too hard. *//* * If the following routine gives trouble, try replacing the calls to * route_host_looup() with calls to route_best_lookup(). They do * aproximately the same thing, but route_best_lookup() doesn't worry
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -