diff options
-rw-r--r-- | anaconda.spec | 1 | ||||
-rw-r--r-- | isys/Makefile | 2 | ||||
-rw-r--r-- | isys/isys.c | 80 | ||||
-rw-r--r-- | loader2/Makefile | 7 | ||||
-rw-r--r-- | loader2/net.c | 419 | ||||
-rw-r--r-- | loader2/net.h | 20 | ||||
-rw-r--r-- | loader2/nfsinstall.c | 17 | ||||
-rw-r--r-- | loader2/telnetd.c | 6 | ||||
-rw-r--r-- | loader2/urlinstall.c | 6 |
9 files changed, 390 insertions, 168 deletions
diff --git a/anaconda.spec b/anaconda.spec index e65ae3777..a91d52f94 100644 --- a/anaconda.spec +++ b/anaconda.spec @@ -14,6 +14,7 @@ BuildPreReq: libXxf86misc-devel, intltool >= 0.31.2-3, python-urlgrabber BuildPreReq: pykickstart, yum, device-mapper >= 1.01.05-3, libsepol-devel BuildPreReq: pango-devel, pirut, libXt-devel, slang-devel >= 2.0.6-2 BuildPreReq: glib2-devel >= 2.11.1-5 +BuildPreReq: libdhcp-devel, libdhcp4client-devel, libdhcp6client-devel Requires: rpm-python >= 4.2-0.61, rhpl >= 0.170, parted >= 1.6.3-7, booty Requires: kudzu > 1.2.0, yum >= 2.5.1-3, pirut Requires: pyparted, libxml2-python, python-urlgrabber diff --git a/isys/Makefile b/isys/Makefile index f3fe7766f..21ef7eb66 100644 --- a/isys/Makefile +++ b/isys/Makefile @@ -8,7 +8,7 @@ OBJECTS = nfsmount.o nfsmount_clnt.o nfsmount_xdr.o imount.o \ ethtool.o wireless.o eddsupport.o nl.o SOBJECTS = $(patsubst %.o,%.lo,$(OBJECTS)) SOURCES = $(patsubst %.o,%.c,$(OBJECTS)) isys.c -LOADLIBES = -lresolv -lpci -lpopt -lpump -lext2fs -lz -lkudzu -lpci -ldevmapper +LOADLIBES = -lresolv -lpci -lpopt -lext2fs -lz -lkudzu -lpci -ldevmapper LOADLIBES += $(SELINUXLIBES) PYMODULES = _isys.so SUBDIRS = gzlib diff --git a/isys/isys.c b/isys/isys.c index 64394c84e..87727eeef 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -32,7 +32,6 @@ #include <sys/vfs.h> #include <unistd.h> #include <resolv.h> -#include <pump.h> #include <scsi/scsi.h> #include <scsi/scsi_ioctl.h> #include <sys/vt.h> @@ -84,8 +83,6 @@ static PyObject * doGetRaidChunkSize(PyObject * s, PyObject * args); static PyObject * doDevSpaceFree(PyObject * s, PyObject * args); static PyObject * doRaidStart(PyObject * s, PyObject * args); static PyObject * doRaidStop(PyObject * s, PyObject * args); -static PyObject * doConfigNetDevice(PyObject * s, PyObject * args); -static PyObject * doPumpNetDevice(PyObject * s, PyObject * args); static PyObject * doResetResolv(PyObject * s, PyObject * args); static PyObject * doSetResolvRetry(PyObject * s, PyObject * args); static PyObject * doLoadFont(PyObject * s, PyObject * args); @@ -141,8 +138,6 @@ static PyMethodDef isysModuleMethods[] = { { "smpavailable", (PyCFunction) smpAvailable, METH_VARARGS, NULL }, { "htavailable", (PyCFunction) htAvailable, METH_VARARGS, NULL }, { "umount", (PyCFunction) doUMount, METH_VARARGS, NULL }, - { "confignetdevice", (PyCFunction) doConfigNetDevice, METH_VARARGS, NULL }, - { "pumpnetdevice", (PyCFunction) doPumpNetDevice, METH_VARARGS, NULL }, { "checkBoot", (PyCFunction) doCheckBoot, METH_VARARGS, NULL }, { "swapon", (PyCFunction) doSwapon, METH_VARARGS, NULL }, { "swapoff", (PyCFunction) doSwapoff, METH_VARARGS, NULL }, @@ -552,81 +547,6 @@ void init_isys(void) { PyDict_SetItemString(d, "EARLY_SWAP_RAM", PyInt_FromLong(EARLY_SWAP_RAM)); } -static PyObject * doConfigNetDevice(PyObject * s, PyObject * args) { - char * dev, * ip, * netmask; - char * gateway; - struct pumpNetIntf device; - typedef int int32; - - if (!PyArg_ParseTuple(args, "ssss", &dev, &ip, &netmask, &gateway)) - return NULL; - - memset(&device,'\0',sizeof(struct pumpNetIntf)); - strncpy(device.device, dev, sizeof(device.device) - 1); - device.ip.s_addr = inet_addr(ip); - device.netmask.s_addr = inet_addr(netmask); - - *((int32 *) &device.broadcast) = (*((int32 *) &device.ip) & - *((int32 *) &device.netmask)) | - ~(*((int32 *) &device.netmask)); - - *((int32 *) &device.network) = - *((int32 *) &device.ip) & *((int32 *) &device.netmask); - - device.set = PUMP_INTFINFO_HAS_IP | PUMP_INTFINFO_HAS_NETMASK | - PUMP_INTFINFO_HAS_BROADCAST | PUMP_INTFINFO_HAS_NETWORK; - - if (pumpSetupInterface(&device)) { - PyErr_SetFromErrno(PyExc_SystemError); - return NULL; - } - - if (strlen(gateway)) { - device.gateway.s_addr = inet_addr(gateway); - if (pumpSetupDefaultGateway(&device.gateway)) { - PyErr_SetFromErrno(PyExc_SystemError); - return NULL; - } - } - - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * doPumpNetDevice(PyObject * s, PyObject * args) { - char * device; - char * dhcpclass = NULL; - char * chptr; - struct pumpNetIntf cfg; - PyObject * rc; - - if (!PyArg_ParseTuple(args, "s|s", &device, &dhcpclass)) - return NULL; - - chptr = pumpDhcpClassRun(device, 0, 0, NULL, dhcpclass, &cfg, NULL); - if (chptr) { - Py_INCREF(Py_None); - return Py_None; - } - - if (pumpSetupInterface(&cfg)) { - PyErr_SetFromErrno(PyExc_SystemError); - return NULL; - } - - if (pumpSetupDefaultGateway(&cfg.gateway)) { - PyErr_SetFromErrno(PyExc_SystemError); - return NULL; - } - - if (cfg.numDns) - rc = PyString_FromString(inet_ntoa(cfg.dnsServers[0])); - else - rc = PyString_FromString(""); - - return rc; -} - #include <linux/fb.h> static PyObject * doFbconProbe (PyObject * s, PyObject * args) { diff --git a/loader2/Makefile b/loader2/Makefile index 60b58eef8..973282174 100644 --- a/loader2/Makefile +++ b/loader2/Makefile @@ -7,9 +7,14 @@ else TARGET=depend $(PROGS) endif +# glib - for utility stuff GLIB = $(shell pkg-config --libs glib-2.0) CFLAGS += $(shell pkg-config --cflags glib-2.0) +# dhcp library flags +DHCP = $(shell pkg-config --libs libdhcp) +CFLAGS += $(shell pkg-config --cflags libdhcp) + SLANGLIB = -lslang NEWTLIB = -lnewt ISYSLIB = ../isys/libisys.a @@ -121,7 +126,7 @@ loader-net.o: loader.c loader: loader.o $(OBJS) $(NETOBJS) $(CC) -g $(STATIC) -o $@ $^ -lpopt \ $(HWLIBS) $(ISYSLIB) $(GUNZIP) $(UNICODELIB) \ - -lpump -lresolv $(NEWTLIB) $(SLANGLIB) $(DMLIB) $(GLIB) + -lresolv $(NEWTLIB) $(SLANGLIB) $(DMLIB) $(GLIB) $(DHCP) -lm clean: rm -f *.o *~ .depend init ctype.c mkctype \ diff --git a/loader2/net.c b/loader2/net.c index fc0d0ba68..e06baa990 100644 --- a/loader2/net.c +++ b/loader2/net.c @@ -68,6 +68,7 @@ static void ipCallback(newtComponent co, void * dptr) { char * ascii; int broadcast, network; int af = AF_INET; /* accept as a parameter */ + int l = 0; if (co == data->ipEntry) { if (strlen(data->ip) && !strlen(data->nm)) { @@ -91,18 +92,24 @@ static void ipCallback(newtComponent co, void * dptr) { if (!inet_pton(af, data->nm, &nmaddr)) return; if (af == AF_INET) { + l = INET_ADDRSTRLEN; + } else if (af == AF_INET6) { + l = INET6_ADDRSTRLEN; + } + + if (af == AF_INET || af == AF_INET6) { network = ipaddr.s_addr & nmaddr.s_addr; broadcast = (ipaddr.s_addr & nmaddr.s_addr) | (~nmaddr.s_addr) ; if (!strlen(data->gw)) { - char gw[INET_ADDRSTRLEN]; + char gw[l]; addr.s_addr = htonl(ntohl(broadcast) - 1); inet_ntop(af, &addr, gw, sizeof(gw)); newtEntrySet(data->gwEntry, gw, 1); } if (!strlen(data->ns)) { - char ns[INET_ADDRSTRLEN]; + char ns[l]; naddr.s_addr = network; naddr.s_addr |= htonl(1); inet_ntop(af, &naddr, ns, sizeof(ns)); @@ -201,16 +208,8 @@ static void parseEthtoolSettings(struct loaderData_s * loaderData) { } void initLoopback(void) { - struct pumpNetIntf dev; - - strcpy(dev.device, "lo"); - inet_pton(AF_INET, "127.0.0.1", &dev.ip); - inet_pton(AF_INET, "255.0.0.0", &dev.netmask); - inet_pton(AF_INET, "127.0.0.0", &dev.network); - dev.set = PUMP_INTFINFO_HAS_NETMASK | PUMP_INTFINFO_HAS_IP - | PUMP_INTFINFO_HAS_NETWORK; - - pumpSetupInterface(&dev); + /* this function needs to configure IPv4 and IPv6 localhost using Netlink */ + return; } static void dhcpBoxCallback(newtComponent co, void * ptr) { @@ -323,6 +322,7 @@ void setupNetworkDeviceConfig(struct networkDeviceConfig * cfg, struct loaderData_s * loaderData, int flags) { struct in_addr addr; + struct in6_addr addr6; char * c; /* set to 1 to get ks network struct logged */ @@ -352,7 +352,7 @@ void setupNetworkDeviceConfig(struct networkDeviceConfig * cfg, /* this is how we specify dhcp */ if (!strncmp(loaderData->ip, "dhcp", 4)) { - char * chptr; + int ret = -1; /* JKFIXME: this soooo doesn't belong here. and it needs to * be broken out into a function too */ @@ -371,23 +371,28 @@ void setupNetworkDeviceConfig(struct networkDeviceConfig * cfg, if (!FL_TESTING(flags)) { waitForLink(loaderData->netDev); - chptr = doDhcp(loaderData->netDev, cfg, loaderData->netCls); - } else { - chptr = NULL; + ret = doDhcp(loaderData->netDev, cfg, loaderData->netCls); } if (!FL_CMDLINE(flags)) newtPopWindow(); - if (chptr) { - logMessage(DEBUGLVL, "pump told us: %s", chptr); + if (ret) { + logMessage(DEBUGLVL, "dhcp: %s", + (ret==DO_DHCP_OUT_OF_MEMORY) ? "out of memory" : + (ret==DO_DHCP_FAILURE) ? "failure" : "unknown error"); return; } cfg->isDynamic = 1; cfg->preset = 1; } else if (inet_pton(AF_INET, loaderData->ip, &addr)) { - cfg->dev.ip = addr; + cfg->dev.ip = ip_addr_in(&addr); + cfg->dev.set |= PUMP_INTFINFO_HAS_IP; + cfg->isDynamic = 0; + cfg->preset = 1; + } else if (inet_pton(AF_INET6, loaderData->ip, &addr6)) { + cfg->dev.ip = ip_addr_in6(&addr6); cfg->dev.set |= PUMP_INTFINFO_HAS_IP; cfg->isDynamic = 0; cfg->preset = 1; @@ -398,12 +403,22 @@ void setupNetworkDeviceConfig(struct networkDeviceConfig * cfg, } if (loaderData->netmask && (inet_pton(AF_INET, loaderData->netmask, &addr))) { - cfg->dev.netmask = addr; + cfg->dev.netmask = ip_addr_in(&addr); + cfg->dev.set |= PUMP_INTFINFO_HAS_NETMASK; + } + + if (loaderData->netmask && (inet_pton(AF_INET6, loaderData->netmask, &addr6))) { + cfg->dev.netmask = ip_addr_in6(&addr6); cfg->dev.set |= PUMP_INTFINFO_HAS_NETMASK; } if (loaderData->gateway && (inet_pton(AF_INET, loaderData->gateway, &addr))) { - cfg->dev.gateway = addr; + cfg->dev.gateway = ip_addr_in(&addr); + cfg->dev.set |= PUMP_NETINFO_HAS_GATEWAY; + } + + if (loaderData->gateway && (inet_pton(AF_INET6, loaderData->gateway, &addr6))) { + cfg->dev.gateway = ip_addr_in6(&addr6); cfg->dev.set |= PUMP_NETINFO_HAS_GATEWAY; } @@ -413,12 +428,18 @@ void setupNetworkDeviceConfig(struct networkDeviceConfig * cfg, /* Scan the dns parameter for multiple comma-separated IP addresses */ c = strtok(buf, ","); - while ((cfg->dev.numDns < MAX_DNS_SERVERS) && (c != NULL) && - (inet_pton(AF_INET, c, &addr))) { - cfg->dev.dnsServers[cfg->dev.numDns] = addr; - cfg->dev.numDns++; - logMessage(DEBUGLVL, "adding %s", inet_ntoa(addr)); - c = strtok(NULL, ","); + while ((cfg->dev.numDns < MAX_DNS_SERVERS) && (c != NULL)) { + if (inet_pton(AF_INET, c, &addr)) { + cfg->dev.dnsServers[cfg->dev.numDns] = ip_addr_in(&addr); + cfg->dev.numDns++; + logMessage(DEBUGLVL, "adding %s", inet_ntoa(addr)); + c = strtok(NULL, ","); + } else if (inet_pton(AF_INET6, c, &addr6)) { + cfg->dev.dnsServers[cfg->dev.numDns] = ip_addr_in6(&addr6); + cfg->dev.numDns++; + logMessage(DEBUGLVL, "adding %s", inet_ntoa(addr)); + c = strtok(NULL, ","); + } } logMessage(INFO, "dnsservers is %s", loaderData->dns); if (cfg->dev.numDns) @@ -473,8 +494,11 @@ int readNetConfig(char * device, struct networkDeviceConfig * cfg, struct intfconfig_s c; int i; struct in_addr addr; + struct in6_addr addr6; char dhcpChoice; - char * chptr; + int dret = -1; + char ret[47]; + ip_addr_t *tip; memset(&c, 0, sizeof(c)); @@ -526,17 +550,29 @@ int readNetConfig(char * device, struct networkDeviceConfig * cfg, c.gwEntry = newtEntry(-1, -1, NULL, 16, &c.gw, 0); c.nsEntry = newtEntry(-1, -1, NULL, 16, &c.ns, 0); - if (cfg->dev.set & PUMP_INTFINFO_HAS_IP) - newtEntrySet(c.ipEntry, inet_ntoa(cfg->dev.ip), 1); + if (cfg->dev.set & PUMP_INTFINFO_HAS_IP) { + tip = &(cfg->dev.ip); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + newtEntrySet(c.ipEntry, ret, 1); + } - if (cfg->dev.set & PUMP_INTFINFO_HAS_NETMASK) - newtEntrySet(c.nmEntry, inet_ntoa(cfg->dev.netmask), 1); + if (cfg->dev.set & PUMP_INTFINFO_HAS_NETMASK) { + tip = &(cfg->dev.netmask); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + newtEntrySet(c.nmEntry, ret, 1); + } - if (cfg->dev.set & PUMP_NETINFO_HAS_GATEWAY) - newtEntrySet(c.gwEntry, inet_ntoa(cfg->dev.gateway), 1); + if (cfg->dev.set & PUMP_NETINFO_HAS_GATEWAY) { + tip = &(cfg->dev.gateway); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + newtEntrySet(c.gwEntry, ret, 1); + } - if (cfg->dev.numDns) - newtEntrySet(c.nsEntry, inet_ntoa(cfg->dev.dnsServers[0]), 1); + if (cfg->dev.numDns) { + tip = &(cfg->dev.dnsServers[0]); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + newtEntrySet(c.nsEntry, ret, 1); + } if (!cfg->isDynamic) { dhcpChoice = ' '; @@ -591,22 +627,40 @@ int readNetConfig(char * device, struct networkDeviceConfig * cfg, if (dhcpChoice == ' ') { i = 0; memset(&newCfg, 0, sizeof(newCfg)); - if (*c.ip && inet_pton(AF_INET, c.ip, &addr)) { - i++; - newCfg.dev.ip = addr; - newCfg.dev.set |= PUMP_INTFINFO_HAS_IP; + if (*c.ip) { + if (inet_pton(AF_INET, c.ip, &addr)) { + i++; + newCfg.dev.ip = ip_addr_in(&addr); + newCfg.dev.set |= PUMP_INTFINFO_HAS_IP; + } else if (inet_pton(AF_INET6, c.ip, &addr6)) { + i++; + newCfg.dev.ip = ip_addr_in6(&addr6); + newCfg.dev.set |= PUMP_INTFINFO_HAS_IP; + } } - if (*c.nm && inet_pton(AF_INET, c.nm, &addr)) { - i++; - newCfg.dev.netmask = addr; - newCfg.dev.set |= PUMP_INTFINFO_HAS_NETMASK; + if (*c.nm) { + if (inet_pton(AF_INET, c.nm, &addr)) { + i++; + newCfg.dev.netmask = ip_addr_in(&addr); + newCfg.dev.set |= PUMP_INTFINFO_HAS_NETMASK; + } else if (inet_pton(AF_INET6, c.nm, &addr6)) { + i++; + newCfg.dev.netmask = ip_addr_in6(&addr6); + newCfg.dev.set |= PUMP_INTFINFO_HAS_NETMASK; + } } - if (c.ns && *c.ns && inet_pton(AF_INET, c.ns, &addr)) { - cfg->dev.dnsServers[0] = addr; - if (cfg->dev.numDns < 1) - cfg->dev.numDns = 1; + if (c.ns && *c.ns) { + if (inet_pton(AF_INET, c.ns, &addr)) { + cfg->dev.dnsServers[0] = ip_addr_in(&addr); + if (cfg->dev.numDns < 1) + cfg->dev.numDns = 1; + } else if (inet_pton(AF_INET6, c.ns, &addr6)) { + cfg->dev.dnsServers[0] = ip_addr_in6(&addr6); + if (cfg->dev.numDns < 1) + cfg->dev.numDns = 1; + } } if (i != 2) { @@ -623,13 +677,11 @@ int readNetConfig(char * device, struct networkDeviceConfig * cfg, _("Sending request for IP information for %s..."), device, 0); waitForLink(device); - chptr = doDhcp(device, &newCfg, dhcpclass); + dret = doDhcp(device, &newCfg, dhcpclass); newtPopWindow(); - } else { - chptr = NULL; } - if (!chptr) { + if (dret==DO_DHCP_SUCCESS) { newCfg.isDynamic = 1; if (!(newCfg.dev.set & PUMP_NETINFO_HAS_DNS)) { logMessage(WARNING, "pump worked, but didn't return a DNS server"); @@ -639,7 +691,9 @@ int readNetConfig(char * device, struct networkDeviceConfig * cfg, i = 2; } } else { - logMessage(DEBUGLVL, "pump told us: %s", chptr); + logMessage(DEBUGLVL, "dhcp: %s", + (dret==DO_DHCP_OUT_OF_MEMORY) ? "out of memory" : + (dret==DO_DHCP_FAILURE) ? "failure" : "unknown error"); i = 0; } } @@ -659,9 +713,14 @@ int readNetConfig(char * device, struct networkDeviceConfig * cfg, fillInIpInfo(cfg); if (!(cfg->dev.set & PUMP_NETINFO_HAS_GATEWAY)) { - if (c.gw && *c.gw && inet_pton(AF_INET, c.gw, &addr)) { - cfg->dev.gateway = addr; - cfg->dev.set |= PUMP_NETINFO_HAS_GATEWAY; + if (c.gw && *c.gw) { + if (inet_pton(AF_INET, c.gw, &addr)) { + cfg->dev.gateway = ip_addr_in(&addr); + cfg->dev.set |= PUMP_NETINFO_HAS_GATEWAY; + } else if (inet_pton(AF_INET6, c.gw, &addr6)) { + cfg->dev.gateway = ip_addr_in6(&addr6); + cfg->dev.set |= PUMP_NETINFO_HAS_GATEWAY; + } } } @@ -705,16 +764,206 @@ char * setupInterface(struct networkDeviceConfig *dev) { return pumpSetupInterface(&dev->dev); } -char * doDhcp(char * ifname, +void ifxDHCPv6(struct pumpNetIntf *ifx) { + IPaddr_t addr = STAILQ_FIRST( &(ifx->dhcp_nic->dhcpv6->address_list) )->addr; + + if( ifx->set & PUMP_INTFINFO_HAS_IP ) { + ifx->ipv6 = nic_ip_addr( addr ); + if( (ifx->ipv6_prefixlen = nic_addr_get_prefix( addr )) > 0 ) + ifx->set |= PUMP_INTFINFO_HAS_IPV6_PREFIX; + ifx->set |= PUMP_INTFINFO_HAS_IPV6_IP; + } else { + ifx->ip = nic_ip_addr( addr ); + ifx->set |= PUMP_INTFINFO_HAS_IP; + ifx->ipv6_prefixlen = nic_addr_get_prefix( addr ); + if ( ifx->ipv6_prefixlen ) { + ifx->network = ip_mask(&ifx->ip, ifx->ipv6_prefixlen); + ifx->set |= PUMP_INTFINFO_HAS_NETWORK; + } + } + + if( !STAILQ_EMPTY(&(ifx->dhcp_nic->dhcpv6->dns_list)) ) { + IPaddr_list_node_t *n=0; + STAILQ_FOREACH(n, &(ifx->dhcp_nic->dhcpv6->dns_list), link) { + if( ifx->numDns >= MAX_DNS_SERVERS ) + break; + ifx->dnsServers[ ifx->numDns++ ] = nic_ip_addr( n->addr ); + ifx->set |= PUMP_NETINFO_HAS_DNS; + } + } + + if( (ifx->set & PUMP_NETINFO_HAS_DNS) && ifx->dhcp_nic->dhcpv6->search_list) { + char *s=ifx->domain; + asprintf(&(ifx->domain), "%s%s%s", s ? s : "", s ? " " : "" , ifx->dhcp_nic->dhcpv6->search_list); + if( s ) + free(s); + ifx->set |= PUMP_NETINFO_HAS_DOMAIN; + } +} + +void ifxDHCPv4( struct pumpNetIntf *ifx ) +{ + IPaddr_t addr = STAILQ_FIRST( &(ifx->dhcp_nic->dhcpv4->address_list) )->addr; + if( ifx->set & PUMP_INTFINFO_HAS_IP ) + { + ifx->ipv4 = nic_ip_addr( addr ); + ifx->set |= PUMP_INTFINFO_HAS_IPV4_IP; + }else + { + ifx->ip = nic_ip_addr( addr ); + ifx->set |= PUMP_INTFINFO_HAS_IP; + if ( nic_addr_get_prefix( addr ) ) + { + ifx->network = ip_mask(&ifx->ip, nic_addr_get_prefix( addr ) ); + ifx->set |= PUMP_INTFINFO_HAS_NETWORK; + } + } + if ( nic_addr_get_prefix( addr ) ) + { + ifx->netmask = ip_v4_prefix_to_netmask( nic_addr_get_prefix( addr ) ); + ifx->set |= PUMP_INTFINFO_HAS_NETMASK; + + ip_addr_t broadcast = nic_addr_get_broadcast( addr ); + if( broadcast.sa_family ) + { + ifx->broadcast = broadcast; + ifx->set |= PUMP_INTFINFO_HAS_BROADCAST; + } + } + if( ifx->dhcp_nic->dhcpv4 + &&( !STAILQ_EMPTY( &( ifx->dhcp_nic->dhcpv4->route_list )) ) + ) + { + IProute_list_node_t *n; + STAILQ_FOREACH( n, &( ifx->dhcp_nic->dhcpv4->route_list ), link ) + { + ip_addr_t dst = nic_route_get_dst( n->route ); + ip_addr_t gw = nic_route_get_gateway( n->route ); + uint8_t dst_len = nic_route_get_dst_len( n->route ); + if( (dst.sa_family == 0) + &&(dst_len == 0) + &&(gw.sa_family == AF_INET) + ) + { + ifx->gateway = gw; + ifx->set |= PUMP_NETINFO_HAS_GATEWAY; + break; + } + } + } + if( ifx->dhcp_nic->dhc4ctl + && dhcpv4_mtu_option( ifx->dhcp_nic->dhc4ctl ) + ) + { + ifx->mtu = dhcpv4_mtu_option( ifx->dhcp_nic->dhc4ctl ); + ifx->set |= PUMP_INTFINFO_HAS_MTU; + } + if( ifx->dhcp_nic->dhcpv4->lease.dhcp4_lease ) + { + DHCPv4_lease *lease=ifx->dhcp_nic->dhcpv4->lease.dhcp4_lease; + if ( lease->server_address.s_addr != 0 ) + { + ifx->nextServer = ip_addr_in(&(lease->server_address)); + ifx->set |= PUMP_INTFINFO_HAS_NEXTSERVER; + } + if ( lease->filename ) + { + ifx->bootFile = strdup( lease->filename ); + ifx->set |= PUMP_INTFINFO_HAS_BOOTFILE; + } + } + + if( !STAILQ_EMPTY(&(ifx->dhcp_nic->dhcpv4->dns_list)) ) + { + IPaddr_list_node_t *n=0; + STAILQ_FOREACH(n, &(ifx->dhcp_nic->dhcpv4->dns_list), link) + { + if( ifx->numDns >= MAX_DNS_SERVERS ) + break; + ifx->dnsServers[ ifx->numDns++ ] = nic_ip_addr( n->addr ); + ifx->set |= PUMP_NETINFO_HAS_DNS; + } + } + if( (ifx->set & PUMP_NETINFO_HAS_DNS) + && ifx->dhcp_nic->dhcpv4->search_list + ) + { + char *s=ifx->domain; + asprintf + ( &(ifx->domain), + "%s%s%s", + s ? s : "", + s ? " " : "" , + ifx->dhcp_nic->dhcpv4->search_list + ); + if( s ) + free(s); + ifx->set |= PUMP_NETINFO_HAS_DOMAIN; + } + if( ifx->dhcp_nic->dhcpv4->host_name ) + { + ifx->set |= PUMP_NETINFO_HAS_HOSTNAME; + if(ifx->hostname) + free(ifx->hostname); + ifx->hostname = strdup( ifx->dhcp_nic->dhcpv4->host_name ); + } +} + +int doDhcp(char * ifname, struct networkDeviceConfig *dev, char * dhcpclass) { + struct pumpNetIntf *ifx = &dev->dev; + LIBDHCP_Capability cap = DHCP_CONFIGURE_INTERFACES; + +/* no work yet + DHCP_Preference dhcp_preference = IPv6_PREFERENCE; +*/ + DHCP_Preference dhcp_preference = DHCPv6_DISABLE; + setupWireless(dev); logMessage(INFO, "running dhcp for %s", ifname); - return pumpDhcpClassRun(ifname, 0, 0, NULL, - dhcpclass ? dhcpclass : "anaconda", - &dev->dev, NULL); - -} + cap |= DHCP_CONFIGURE_ADDRESSES|DHCP_CONFIGURE_RADVD; + cap |= DHCP_CONFIGURE_ROUTES|DHCP_CONFIGURE_RESOLVER; + + if (ifx->nh == 0) { + ifx->nh = nic_open(0); + if (ifx->nh == 0L) + return DO_DHCP_OUT_OF_MEMORY; + } + + ifx->dhcp_nic = dhcp_nic(ifx->nh, dhcp_preference, ifx->device, + cap, 20, NULL, 0, + "-V", dhcpclass, + 0L, 0L, 0L); + + if (ifx->dhcp_nic) { + /* fill in the pumpNetIntf structure. + * We'll just use the FIRST configured address as ifx->ip - + * users should realize that a list of addresses may have + * been configured. + */ + if ((ifx->dhcp_nic->dhcpv4 && ifx->dhcp_nic->dhcpv6 ) + &&(!STAILQ_EMPTY(&(ifx->dhcp_nic->dhcpv4->address_list))) + &&(!STAILQ_EMPTY(&(ifx->dhcp_nic->dhcpv6->address_list)))) { + if (dhcp_preference & IPv6_PREFERENCE) { + ifxDHCPv6 (ifx); + ifxDHCPv4 (ifx); + } else { + ifxDHCPv4 (ifx); + ifxDHCPv6 (ifx); + } + } else if (ifx->dhcp_nic->dhcpv4 + &&(!STAILQ_EMPTY(&(ifx->dhcp_nic->dhcpv4->address_list)))) { + ifxDHCPv4 (ifx); + } else if (ifx->dhcp_nic->dhcpv6 + &&(!STAILQ_EMPTY(&(ifx->dhcp_nic->dhcpv6->address_list)))) { + ifxDHCPv6 (ifx); + } + } else { + return DO_DHCP_FAILURE; + } + return DO_DHCP_SUCCESS; +} int configureNetwork(struct networkDeviceConfig * dev) { char *rc; @@ -723,9 +972,6 @@ int configureNetwork(struct networkDeviceConfig * dev) { if (rc) logMessage(INFO, "result of pumpSetupInterface is %s", rc); - if (dev->dev.set & PUMP_NETINFO_HAS_GATEWAY) - pumpSetupDefaultGateway(&dev->dev.gateway); - /* we need to wait for a link after setting up the interface as some * switches decide to reconfigure themselves after that (#115825) */ @@ -737,6 +983,8 @@ int writeNetInfo(const char * fn, struct networkDeviceConfig * dev) { FILE * f; int i; struct device ** devices; + char ret[47]; + ip_addr_t *tip; devices = probeDevices(CLASS_NETWORK, BUS_UNSPEC, PROBE_LOADED); if (!devices) @@ -755,12 +1003,26 @@ int writeNetInfo(const char * fn, struct networkDeviceConfig * dev) { fprintf(f, "BOOTPROTO=dhcp\n"); } else { fprintf(f, "BOOTPROTO=static\n"); - fprintf(f, "IPADDR=%s\n", inet_ntoa(dev->dev.ip)); - fprintf(f, "NETMASK=%s\n", inet_ntoa(dev->dev.netmask)); - if (dev->dev.set & PUMP_NETINFO_HAS_GATEWAY) - fprintf(f, "GATEWAY=%s\n", inet_ntoa(dev->dev.gateway)); - if (dev->dev.set & PUMP_INTFINFO_HAS_BROADCAST) - fprintf(f, "BROADCAST=%s\n", inet_ntoa(dev->dev.broadcast)); + + tip = &(dev->dev.ip); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + fprintf(f, "IPADDR=%s\n", ret); + + tip = &(dev->dev.netmask); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + fprintf(f, "NETMASK=%s\n", ret); + + if (dev->dev.set & PUMP_NETINFO_HAS_GATEWAY) { + tip = &(dev->dev.gateway); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + fprintf(f, "GATEWAY=%s\n", ret); + } + + if (dev->dev.set & PUMP_INTFINFO_HAS_BROADCAST) { + tip = &(dev->dev.broadcast); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + fprintf(f, "BROADCAST=%s\n", ret); + } } if (dev->dev.set & PUMP_NETINFO_HAS_HOSTNAME) @@ -794,6 +1056,8 @@ int writeResolvConf(struct networkDeviceConfig * net) { char * filename = "/etc/resolv.conf"; FILE * f; int i; + char ret[47]; + ip_addr_t *tip; #if defined(__s390__) || defined(__s390x__) return 0; #endif @@ -810,8 +1074,11 @@ int writeResolvConf(struct networkDeviceConfig * net) { if (net->dev.set & PUMP_NETINFO_HAS_DOMAIN) fprintf(f, "search %s\n", net->dev.domain); - for (i = 0; i < net->dev.numDns; i++) - fprintf(f, "nameserver %s\n", inet_ntoa(net->dev.dnsServers[i])); + for (i = 0; i < net->dev.numDns; i++) { + tip = &(net->dev.dnsServers[i]); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + fprintf(f, "nameserver %s\n", ret); + } fclose(f); @@ -822,6 +1089,8 @@ int writeResolvConf(struct networkDeviceConfig * net) { int findHostAndDomain(struct networkDeviceConfig * dev, int flags) { char * name, * chptr; + char ret[47]; + ip_addr_t *tip; if (!FL_TESTING(flags)) { writeResolvConf(dev); @@ -839,7 +1108,9 @@ int findHostAndDomain(struct networkDeviceConfig * dev, int flags) { else printf("Determining host name and domain...\n"); - name = mygethostbyaddr(inet_ntoa(dev->dev.ip)); + tip = &(dev->dev.ip); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + name = mygethostbyaddr(ret); if (!FL_CMDLINE(flags)) newtPopWindow(); diff --git a/loader2/net.h b/loader2/net.h index 57cdd13b8..0910b9ae7 100644 --- a/loader2/net.h +++ b/loader2/net.h @@ -2,8 +2,20 @@ #define H_LOADER_NET #include "loader.h" -#include "pump.h" - +#include <ip_addr.h> +#include <libdhcp.h> +#include <pump.h> + +#define IP_STRLEN( ip ) \ + ( ((ip)->sa_family == AF_INET) ? INET_ADDRSTRLEN : \ + ((ip)->sa_family == AF_INET6) ? INET6_ADDRSTRLEN : 0 ) + +/* return values for doDhcp in net.c */ +enum { + DO_DHCP_SUCCESS, + DO_DHCP_OUT_OF_MEMORY, + DO_DHCP_FAILURE +}; struct networkDeviceConfig { struct pumpNetIntf dev; @@ -45,7 +57,7 @@ int kickstartNetworkUp(struct loaderData_s * loaderData, int flags); char * setupInterface(struct networkDeviceConfig *dev); -char * doDhcp(char * ifname, - struct networkDeviceConfig *dev, char * dhcpclass); +int doDhcp(char * ifname, + struct networkDeviceConfig *dev, char * dhcpclass); #endif diff --git a/loader2/nfsinstall.c b/loader2/nfsinstall.c index fc0125b36..16c0b54dc 100644 --- a/loader2/nfsinstall.c +++ b/loader2/nfsinstall.c @@ -287,9 +287,11 @@ void setKickstartNfs(struct loaderData_s * loaderData, int argc, int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData, int flags) { + char ret[47]; char * host = NULL, *path = NULL, * file = NULL, * opts = NULL; int failed = 0; struct networkDeviceConfig netCfg; + ip_addr_t *tip; if (kickstartNetworkUp(loaderData, &netCfg, flags)) { logMessage(ERROR, "unable to bring up network"); @@ -304,20 +306,23 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData, logMessage(ERROR, "no bootserver was found"); return 1; } - + + tip = &(netCfg.dev.nextServer); if (!(netCfg.dev.set & PUMP_INTFINFO_HAS_BOOTFILE)) { - url = sdupprintf("%s:%s", inet_ntoa(netCfg.dev.nextServer), - "/kickstart/"); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + url = sdupprintf("%s:%s", ret, "/kickstart/"); logMessage(ERROR, "bootp: no bootfile received"); } else { - url = sdupprintf("%s:%s", inet_ntoa(netCfg.dev.nextServer), - netCfg.dev.bootFile); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + url = sdupprintf("%s:%s", ret, netCfg.dev.bootFile); + logMessage(INFO, "foo bar"); } } logMessage(INFO, "url is %s", url); - getHostandPath(url, &host, &path, inet_ntoa(netCfg.dev.ip)); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + getHostandPath(url, &host, &path, ret); opts = strchr(host, ':'); if (opts && (strlen(opts) > 1)) { diff --git a/loader2/telnetd.c b/loader2/telnetd.c index e5610e409..6c3bfef66 100644 --- a/loader2/telnetd.c +++ b/loader2/telnetd.c @@ -228,14 +228,18 @@ int beTelnet(int flags) { void startTelnetd(struct loaderData_s * loaderData, moduleInfoSet modInfo, moduleList modLoaded, moduleDeps modDeps, int flags) { + char ret[47]; struct networkDeviceConfig netCfg; + ip_addr_t *tip; if (kickstartNetworkUp(loaderData, &netCfg, flags)) { logMessage(ERROR, "unable to bring up network"); return; } - logMessage(INFO, "going to beTelnet for %s", inet_ntoa(netCfg.dev.ip)); + tip = &(netCfg.dev.ip); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); + logMessage(INFO, "going to beTelnet for %s", ret); if (!beTelnet(flags)) flags |= LOADER_FLAGS_TEXT | LOADER_FLAGS_NOSHELL; diff --git a/loader2/urlinstall.c b/loader2/urlinstall.c index beb81e408..f799bd74c 100644 --- a/loader2/urlinstall.c +++ b/loader2/urlinstall.c @@ -352,6 +352,7 @@ char * mountUrlImage(struct installMethod * method, int getFileFromUrl(char * url, char * dest, struct loaderData_s * loaderData, int flags) { + char ret[47]; struct iurlinfo ui; enum urlprotocol_t proto = !strncmp(url, "ftp://", 6) ? URL_METHOD_FTP : URL_METHOD_HTTP; @@ -359,6 +360,7 @@ int getFileFromUrl(char * url, char * dest, int fd, rc; struct networkDeviceConfig netCfg; char * ehdrs = NULL; + ip_addr_t *tip; if (kickstartNetworkUp(loaderData, &netCfg, flags)) { logMessage(ERROR, "unable to bring up network"); @@ -368,8 +370,10 @@ int getFileFromUrl(char * url, char * dest, memset(&ui, 0, sizeof(ui)); ui.protocol = proto; + tip = &(netCfg.dev.ip); + inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip)); getHostandPath((proto == URL_METHOD_FTP ? url + 6 : url + 7), - &host, &file, inet_ntoa(netCfg.dev.ip)); + &host, &file, ret); logMessage(INFO, "ks location: %s://%s/%s", (proto == URL_METHOD_FTP ? "ftp" : "http"), host, file); |