📄 net.c
字号:
setMethodSensitivity(&v6Method, 3); /* run the form */ do { answer = newtRunForm(f); if (answer == back) { newtFormDestroy(f); newtPopWindow(); return LOADER_BACK; } /* need at least one stack */ if (opts->ipv4Choice == ' ' && opts->ipv6Choice == ' ') { newtWinMessage(_("Missing Protocol"), _("Retry"), _("You must select at least one protocol (IPv4 " "or IPv6).")); continue; } /* NFS only works over IPv4 */ if (opts->ipv4Choice == ' ' && methodNum == METHOD_NFS) { newtWinMessage(_("IPv4 Needed for NFS"), _("Retry"), _("NFS installation method requires IPv4 support.")); continue; } /* what TCP/IP stacks do we use? what conf methods? */ if (opts->ipv4Choice == '*') { newCfg->noipv4 = 0; for (z = 0; z < 2; z++) if (newtRadioGetCurrent(v4Method[0]) == v4Method[z]) newCfg->ipv4method = z; } else { newCfg->noipv4 = 1; } if (opts->ipv6Choice == '*') { newCfg->noipv6 = 0; for (z = 0; z < 3; z++) if (newtRadioGetCurrent(v6Method[0]) == v6Method[z]) newCfg->ipv6method = z; } else { newCfg->noipv6 = 1; } /* do interface configuration (call DHCP here, or return for manual) */ if ((!newCfg->noipv4 && newCfg->ipv4method == IPV4_DHCP_METHOD) || (!newCfg->noipv6 && (newCfg->ipv6method == IPV6_AUTO_METHOD || newCfg->ipv6method == IPV6_DHCP_METHOD))) { /* do DHCP if selected */ if (!FL_TESTING(flags)) { winStatus(55, 3, NULL, _("Sending request for IP information for %s..."), device, 0); waitForLink(device); dret = doDhcp(newCfg); newtPopWindow(); } if (dret == NULL) { newCfg->isDynamic = 1; if (!(newCfg->dev.set & PUMP_NETINFO_HAS_DNS)) { logMessage(WARNING, "dhcp worked, but did not return a DNS server"); /* * prompt for a nameserver IP address when: * - DHCP for IPv4, DHCP/AUTO for IPv6 and both enabled * - IPv4 disabled and DHCP/AUTO for IPv6 * - IPv6 disabled and DHCP for IPv4 */ if ((newCfg->ipv4method == IPV4_DHCP_METHOD && (newCfg->ipv6method == IPV6_AUTO_METHOD || newCfg->ipv6method == IPV6_DHCP_METHOD)) || (newCfg->ipv4method == IPV4_DHCP_METHOD && newCfg->noipv6) || (newCfg->noipv4 && (newCfg->ipv6method == IPV6_AUTO_METHOD || newCfg->ipv6method == IPV6_DHCP_METHOD))) { i = getDnsServers(newCfg); i = i ? 0 : 1; } else { i = 1; } } else { i = 1; } } else { logMessage(DEBUGLVL, "dhcp: %s", dret); i = 0; } } else { /* manual IP configuration for IPv4 and IPv6 */ newtFormDestroy(f); newtPopWindow(); return LOADER_OK; } } while (i != 1); newtFormDestroy(f); newtPopWindow(); if ((!newCfg->noipv4 && newCfg->ipv4method == IPV4_MANUAL_METHOD) || (!newCfg->noipv6 && newCfg->ipv6method == IPV6_MANUAL_METHOD)) return LOADER_OK; else return LOADER_NOOP;}int manualNetConfig(char * device, struct networkDeviceConfig * cfg, struct networkDeviceConfig * newCfg, struct intfconfig_s * ipcomps, struct netconfopts * opts) { int i, rows, pos, primary, prefix, cidr, q, have[2], stack[2]; char *buf = NULL; char ret[48]; ip_addr_t *tip; struct in_addr addr; struct in6_addr addr6; newtComponent f, okay, back, answer; newtGrid egrid = NULL; newtGrid qgrid = NULL; newtGrid rgrid = NULL; newtGrid buttons, grid; newtComponent text = NULL; /* so we don't perform this test over and over */ stack[IPV4] = opts->ipv4Choice == '*' && newCfg->ipv4method == IPV4_MANUAL_METHOD; stack[IPV6] = opts->ipv6Choice == '*' && newCfg->ipv6method == IPV6_MANUAL_METHOD; /* UI WINDOW 2 (optional): manual IP config for non-DHCP installs */ rows = 2; for (i = 0; i < 2; i++) if (stack[i]) rows++; egrid = newtCreateGrid(4, rows); pos = 0; /* IPv4 entry items */ if (stack[IPV4]) { newtGridSetField(egrid, 0, pos, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("IPv4 address:")), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); ipcomps->ipv4Entry = newtEntry(-1, -1, NULL, 16, &ipcomps->ipv4, 0); ipcomps->cidr4Entry = newtEntry(-1, -1, NULL, 16, &ipcomps->cidr4, 0); /* use a nested grid for ipv4 addr & netmask */ qgrid = newtCreateGrid(3, 1); newtGridSetField(qgrid, 0, 0, NEWT_GRID_COMPONENT, ipcomps->ipv4Entry, 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(qgrid, 1, 0, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("/")), 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(qgrid, 2, 0, NEWT_GRID_COMPONENT, ipcomps->cidr4Entry, 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(egrid, 1, pos, NEWT_GRID_SUBGRID, qgrid, 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtComponentAddCallback(ipcomps->ipv4Entry, ipCallback, ipcomps); newtComponentAddCallback(ipcomps->cidr4Entry, cidrCallback, ipcomps); /* populate fields if we have data already */ tip = NULL; if (cfg->dev.set & PUMP_INTFINFO_HAS_IPV4_IP) tip = &(cfg->dev.ipv4); else if (newCfg->dev.set & PUMP_INTFINFO_HAS_IPV4_IP) tip = &(newCfg->dev.ipv4); if (tip) { inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); newtEntrySet(ipcomps->ipv4Entry, ret, 1); } tip = NULL; if (cfg->dev.set & PUMP_INTFINFO_HAS_NETMASK) tip = &(cfg->dev.netmask); else if (newCfg->dev.set & PUMP_INTFINFO_HAS_NETMASK) tip = &(newCfg->dev.netmask); if (tip) { inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); newtEntrySet(ipcomps->cidr4Entry, ret, 1); } pos++; } /* IPv6 entry items */ if (stack[IPV6]) { newtGridSetField(egrid, 0, pos, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("IPv6 address:")), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); ipcomps->ipv6Entry = newtEntry(-1, -1, NULL, 41, &ipcomps->ipv6, 0); ipcomps->cidr6Entry = newtEntry(-1, -1, NULL, 4, &ipcomps->cidr6, 0); /* use a nested grid for ipv6 addr & netmask */ rgrid = newtCreateGrid(3, 1); newtGridSetField(rgrid, 0, 0, NEWT_GRID_COMPONENT, ipcomps->ipv6Entry, 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(rgrid, 1, 0, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("/")), 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(rgrid, 2, 0, NEWT_GRID_COMPONENT, ipcomps->cidr6Entry, 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(egrid, 1, pos, NEWT_GRID_SUBGRID, rgrid, 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtComponentAddCallback(ipcomps->ipv6Entry, ipCallback, ipcomps); newtComponentAddCallback(ipcomps->cidr6Entry, cidrCallback, ipcomps); /* populate fields if we have data already */ tip = NULL; if (cfg->dev.set & PUMP_INTFINFO_HAS_IPV6_IP) tip = &(cfg->dev.ipv6); else if (newCfg->dev.set & PUMP_INTFINFO_HAS_IPV6_IP) tip = &(newCfg->dev.ipv6); if (tip) { inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); newtEntrySet(ipcomps->ipv6Entry, ret, 1); } if (cfg->dev.set & PUMP_INTFINFO_HAS_IPV6_PREFIX) q = asprintf(&buf, "%d", cfg->dev.ipv6_prefixlen); else if (newCfg->dev.set & PUMP_INTFINFO_HAS_IPV6_PREFIX) q = asprintf(&buf, "%d", newCfg->dev.ipv6_prefixlen); if (buf) { newtEntrySet(ipcomps->cidr6Entry, buf, 1); free(buf); } pos++; } /* common entry items */ ipcomps->gwEntry = newtEntry(-1, -1, NULL, 41, &ipcomps->gw, 0); ipcomps->nsEntry = newtEntry(-1, -1, NULL, 41, &ipcomps->ns, 0); newtGridSetField(egrid, 0, pos, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("Gateway:")), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(egrid, 1, pos, NEWT_GRID_COMPONENT, ipcomps->gwEntry, 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); pos++; newtGridSetField(egrid, 0, pos, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("Name Server:")), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(egrid, 1, pos, NEWT_GRID_COMPONENT, ipcomps->nsEntry, 1, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); tip = NULL; if (cfg->dev.set & PUMP_NETINFO_HAS_GATEWAY) tip = &(cfg->dev.gateway); else if (newCfg->dev.set & PUMP_NETINFO_HAS_GATEWAY) tip = &(newCfg->dev.gateway); if (tip) { inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); newtEntrySet(ipcomps->gwEntry, ret, 1); } tip = NULL; if (cfg->dev.numDns) tip = &(cfg->dev.dnsServers[0]); else if (newCfg->dev.numDns) tip = &(newCfg->dev.dnsServers[0]); if (tip) { inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); newtEntrySet(ipcomps->nsEntry, ret, 1); } newtComponentAddCallback(ipcomps->gwEntry, ipCallback, ipcomps); newtComponentAddCallback(ipcomps->nsEntry, ipCallback, ipcomps); /* button bar at the bottom of the window */ buttons = newtButtonBar(_("OK"), &okay, _("Back"), &back, NULL); /* main window layout */ grid = newtCreateGrid(1, 3); buf = sdupprintf(_("Enter the IPv4 and/or the IPv6 address and prefix " "(address / prefix). For IPv4, the dotted-quad " "netmask or the CIDR-style prefix are acceptable. " "The gateway and name server fields must be valid IPv4 " "or IPv6 addresses.")); text = newtTextboxReflowed(-1, -1, buf, 52, 0, 10, 0); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 1, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, egrid, 0, 0, 0, 1, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); f = newtForm(NULL, NULL, 0); newtGridAddComponentsToForm(grid, f, 1); newtGridWrappedWindow(grid, _("Manual TCP/IP Configuration")); newtGridFree(grid, 1); /* run the form */ while ((have[IPV4] != 2) || (have[IPV6] != 2)) { have[IPV4] = 0; have[IPV6] = 0; for (i = 0; i < 2; i++) if (!stack[i]) have[i] = 2; answer = newtRunForm(f); /* memset(newCfg, 0, sizeof(*newCfg)); */ /* collect IPv4 data */ if (stack[IPV4]) { if (ipcomps->ipv4) { if (inet_pton(AF_INET, ipcomps->ipv4, &addr) >= 1) { newCfg->dev.ipv4 = ip_addr_in(&addr); newCfg->dev.set |= PUMP_INTFINFO_HAS_IPV4_IP; have[IPV4]++; } } if (ipcomps->cidr4) { if (inet_pton(AF_INET, ipcomps->cidr4, &addr) >= 1) { newCfg->dev.netmask = ip_addr_in(&addr); newCfg->dev.set |= PUMP_INTFINFO_HAS_NETMASK; have[IPV4]++; } else { cidr = atoi(ipcomps->cidr4); if (cidr >= 1 && cidr <= 32) { if (inet_pton(AF_INET, "255.255.255.255", &addr) >= 1) { addr.s_addr = htonl(ntohl(addr.s_addr) << (32 - cidr)); newCfg->dev.netmask = ip_addr_in(&addr); newCfg->dev.set |= PUMP_INTFINFO_HAS_NETMASK; have[IPV4]++; } } } } } /* collect IPv6 data */ if (stack[IPV6]) { if (ipcomps->ipv6) { if (inet_pton(AF_INET6, ipcomps->ipv6, &addr6) >= 1) { newCfg->dev.ipv6 = ip_addr_in6(&addr6); newCfg->dev.set |= PUMP_INTFINFO_HAS_IPV6_IP; have[IPV6]++; } } if (ipcomps->cidr6) { prefix = atoi(ipcomps->cidr6); if (prefix > 0 || prefix <= 128) { newCfg->dev.ipv6_prefixlen = prefix; newCfg->dev.set |= PUMP_INTFINFO_HAS_IPV6_PREFIX; have[IPV6]++; } } } /* collect common network settings */ if (ipcomps->gw) { primary = 0; if (inet_pton(AF_INET, ipcomps->gw, &addr) >= 1) { newCfg->dev.gateway = ip_addr_in(&addr); newCfg->dev.set |= PUMP_NETINFO_HAS_GATEWAY; primary = AF_INET; } else if (inet_pton(AF_INET6, ipcomps->gw, &addr6) >= 1) { newCfg->dev.gateway = ip_addr_in6(&addr6); newCfg->dev.set |= PUMP_NETINFO_HAS_GATEWAY; primary = AF_INET6; } /* We set cfg->dev.ip to the IP address of the dominant * network. Determine that by the address family of the * gateway.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -