// SPDX-License-Identifier: GPL-2.0 /* * Automatic Configuration of IP -- use DHCP, BOOTP, RARP, or * user-supplied information to configure own IP address and routes. * * Copyright (C) 1996-1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz> * * Derived from network configuration code in fs/nfs/nfsroot.c, * originally Copyright (C) 1995, 1996 Gero Kuhlmann and me. * * BOOTP rewritten to construct and analyse packets itself instead * of misusing the IP layer. num_bugs_causing_wrong_arp_replies--; * -- MJ, December 1998 * * Fixed ip_auto_config_setup calling at startup in the new "Linker Magic" * initialization scheme. * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 08/11/1999 * * DHCP support added. To users this looks like a whole separate * protocol, but we know it's just a bag on the side of BOOTP. * -- Chip Salzenberg <chip@valinux.com>, May 2000 * * Ported DHCP support from 2.2.16 to 2.4.0-test4 * -- Eric Biederman <ebiederman@lnxi.com>, 30 Aug 2000 * * Merged changes from 2.2.19 into 2.4.3 * -- Eric Biederman <ebiederman@lnxi.com>, 22 April Aug 2001 * * Multiple Nameservers in /proc/net/pnp * -- Josef Siemes <jsiemes@web.de>, Aug 2002 * * NTP servers in /proc/net/ipconfig/ntp_servers * -- Chris Novakovic <chris@chrisn.me.uk>, April 2018
*/
/* Define the friendly delay before and after opening net devices */ #define CONF_POST_OPEN 10 /* After opening: 10 msecs */
/* Define the timeout for waiting for a DHCP/BOOTP/RARP reply */ #define CONF_OPEN_RETRIES 2 /* (Re)open devices twice */ #define CONF_SEND_RETRIES 6 /* Send six requests per open */ #define CONF_BASE_TIMEOUT (HZ*2) /* Initial timeout: 2 seconds */ #define CONF_TIMEOUT_RANDOM (HZ) /* Maximum amount of randomization */ #define CONF_TIMEOUT_MULT *7/4 /* Rate of timeout growth */ #define CONF_TIMEOUT_MAX (HZ*30) /* Maximum allowed timeout */ #define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers
- '3' from resolv.h */ #define CONF_NTP_SERVERS_MAX 3 /* Maximum number of NTP servers */
#define NONE cpu_to_be32(INADDR_NONE) #define ANY cpu_to_be32(INADDR_ANY)
/* Wait for carrier timeout default in seconds */ staticunsignedint carrier_timeout = 120;
/* * Public IP configuration
*/
/* This is used by platforms which might be able to set the ipconfig * variables using firmware environment vars. If this is set, it will * ignore such firmware variables.
*/ int ic_set_manually __initdata = 0; /* IPconfig parameters set manually */
staticint ic_enable __initdata; /* IP config enabled? */
#ifdef IPCONFIG_DYNAMIC staticint ic_proto_used; /* Protocol used, if any */ #else #define ic_proto_used 0 #endif static __be32 ic_nameservers[CONF_NAMESERVERS_MAX]; /* DNS Server IP addresses */ static __be32 ic_ntp_servers[CONF_NTP_SERVERS_MAX]; /* NTP server IP addresses */ static u8 ic_domain[64]; /* DNS (not NIS) domain name */
/* * Private state.
*/
/* Name of user-selected boot device */ staticchar user_dev_name[IFNAMSIZ] __initdata = { 0, };
/* Protocols supported by available interfaces */ staticint ic_proto_have_if __initdata;
/* MTU for boot device */ staticint ic_dev_mtu __initdata;
#ifdef IPCONFIG_DYNAMIC static DEFINE_SPINLOCK(ic_recv_lock); staticvolatileint ic_got_reply __initdata; /* Proto(s) that replied */ #endif #ifdef IPCONFIG_DHCP staticint ic_dhcp_msgtype __initdata; /* DHCP msg type received */ #endif
/* bring loopback device up first */
for_each_netdev(&init_net, dev) { if (!(dev->flags & IFF_LOOPBACK)) continue; if (dev_change_flags(dev, dev->flags | IFF_UP, NULL) < 0)
pr_err("IP-Config: Failed to open %s\n", dev->name);
}
for_each_netdev(&init_net, dev) { if (ic_is_init_dev(dev)) { int able = 0; if (dev->mtu >= 364)
able |= IC_BOOTP; else
pr_warn("DHCP/BOOTP: Ignoring device %s, MTU %d too small\n",
dev->name, dev->mtu); if (!(dev->flags & IFF_NOARP))
able |= IC_RARP;
able &= ic_proto_enabled; if (ic_proto_enabled && !able) continue;
oflags = dev->flags; if (dev_change_flags(dev, oflags | IFF_UP, NULL) < 0) {
pr_err("IP-Config: Failed to open %s\n",
dev->name); continue;
} if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) {
rtnl_unlock(); return -ENOMEM;
}
d->dev = dev;
*last = d;
last = &d->next;
d->flags = oflags;
d->able = able; if (able & IC_BOOTP)
get_random_bytes(&d->xid, sizeof(__be32)); else
d->xid = 0;
ic_proto_have_if |= able;
pr_debug("IP-Config: %s UP (able=%d, xid=%08x)\n",
dev->name, able, d->xid);
}
} /* Devices with a complex topology like SFP ethernet interfaces needs * the rtnl_lock at init. The carrier wait-loop must therefore run * without holding it.
*/
rtnl_unlock();
/* no point in waiting if we could not bring up at least one device */ if (!ic_first_dev) goto have_carrier;
/* wait for a carrier on at least one device */
start = jiffies;
next_msg = start + secs_to_jiffies(20); while (time_before(jiffies, start +
secs_to_jiffies(carrier_timeout))) { int wait, elapsed;
elapsed = jiffies_to_msecs(jiffies - start);
wait = (carrier_timeout * 1000 - elapsed + 500) / 1000;
pr_info("Waiting up to %d more seconds for network.\n", wait);
next_msg = jiffies + secs_to_jiffies(20);
}
have_carrier:
*last = NULL;
if (!ic_first_dev) { if (user_dev_name[0])
pr_err("IP-Config: Device `%s' not found\n",
user_dev_name); else
pr_err("IP-Config: No network devices available\n"); return -ENODEV;
} return 0;
}
/* Close all network interfaces except the one we've autoconfigured, and its * lowers, in case it's a stacked virtual interface.
*/ staticvoid __init ic_close_devs(void)
{ struct net_device *selected_dev = ic_dev ? ic_dev->dev : NULL; struct ic_device *d, *next; struct net_device *dev;
memset(&ir, 0, sizeof(ir));
strcpy(ir.ifr_ifrn.ifrn_name, ic_dev->dev->name);
set_sockaddr(sin, ic_myaddr, 0); if ((err = devinet_ioctl(&init_net, SIOCSIFADDR, &ir)) < 0) {
pr_err("IP-Config: Unable to set interface address (%d)\n",
err); return -1;
}
set_sockaddr(sin, ic_netmask, 0); if ((err = devinet_ioctl(&init_net, SIOCSIFNETMASK, &ir)) < 0) {
pr_err("IP-Config: Unable to set interface netmask (%d)\n",
err); return -1;
}
set_sockaddr(sin, ic_myaddr | ~ic_netmask, 0); if ((err = devinet_ioctl(&init_net, SIOCSIFBRDADDR, &ir)) < 0) {
pr_err("IP-Config: Unable to set interface broadcast address (%d)\n",
err); return -1;
} /* Handle the case where we need non-standard MTU on the boot link (a network * using jumbo frames, for instance). If we can't set the mtu, don't error * out, we'll try to muddle along.
*/ if (ic_dev_mtu != 0) {
rtnl_lock(); if ((err = dev_set_mtu(ic_dev->dev, ic_dev_mtu)) < 0)
pr_err("IP-Config: Unable to set interface mtu to %d (%d)\n",
ic_dev_mtu, err);
rtnl_unlock();
} return 0;
}
staticint __init ic_setup_routes(void)
{ /* No need to setup device routes, only the default route... */
if (ic_gateway != NONE) { struct rtentry rm; int err;
/* * Process received RARP packet.
*/ staticint __init
ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
{ struct arphdr *rarp; unsignedchar *rarp_ptr;
__be32 sip, tip; unsignedchar *tha; /* t for "target" */ struct ic_device *d;
if (!net_eq(dev_net(dev), &init_net)) goto drop;
skb = skb_share_check(skb, GFP_ATOMIC); if (!skb) return NET_RX_DROP;
if (!pskb_may_pull(skb, sizeof(struct arphdr))) goto drop;
/* Basic sanity checks can be done without the lock. */
rarp = (struct arphdr *)skb_transport_header(skb);
/* If this test doesn't pass, it's not IP, or we should * ignore it anyway.
*/ if (rarp->ar_hln != dev->addr_len || dev->type != ntohs(rarp->ar_hrd)) goto drop;
/* If it's not a RARP reply, delete it. */ if (rarp->ar_op != htons(ARPOP_RREPLY)) goto drop;
/* If it's not Ethernet, delete it. */ if (rarp->ar_pro != htons(ETH_P_IP)) goto drop;
if (!pskb_may_pull(skb, arp_hdr_len(dev))) goto drop;
/* OK, it is all there and looks valid, process... */
rarp = (struct arphdr *)skb_transport_header(skb);
rarp_ptr = (unsignedchar *) (rarp + 1);
/* One reply at a time, please. */
spin_lock(&ic_recv_lock);
/* If we already have a reply, just drop the packet */ if (ic_got_reply) goto drop_unlock;
/* Find the ic_device that the packet arrived on */
d = ic_first_dev; while (d && d->dev != dev)
d = d->next; if (!d) goto drop_unlock; /* should never happen */
if (mt == DHCPREQUEST) {
*e++ = 54; /* Server ID (IP address) */
*e++ = 4;
memcpy(e, &ic_servaddr, 4);
e += 4;
*e++ = 50; /* Requested IP address */
*e++ = 4;
memcpy(e, &ic_myaddr, 4);
e += 4;
}
/* always? */
{ staticconst u8 ic_req_params[] = {
1, /* Subnet mask */
3, /* Default gateway */
6, /* DNS server */
12, /* Host name */
15, /* Domain name */
17, /* Boot path */
26, /* MTU */
40, /* NIS domain name */
42, /* NTP servers */
};
*e++ = 55; /* Parameter request list */
*e++ = sizeof(ic_req_params);
memcpy(e, ic_req_params, sizeof(ic_req_params));
e += sizeof(ic_req_params);
if (ic_host_name_set) {
*e++ = 12; /* host-name */
len = strlen(utsname()->nodename);
*e++ = len;
memcpy(e, utsname()->nodename, len);
e += len;
} if (*vendor_class_identifier) {
pr_info("DHCP: sending class identifier \"%s\"\n",
vendor_class_identifier);
*e++ = 60; /* Class-identifier */
len = strlen(vendor_class_identifier);
*e++ = len;
memcpy(e, vendor_class_identifier, len);
e += len;
}
len = strlen(dhcp_client_identifier + 1); /* the minimum length of identifier is 2, include 1 byte type, * and can not be larger than the length of options
*/ if (len >= 1 && len < 312 - (e - options) - 1) {
*e++ = 61;
*e++ = len + 1;
memcpy(e, dhcp_client_identifier, len + 1);
e += len + 1;
}
}
*e++ = 255; /* End of the list */
}
#endif/* IPCONFIG_DHCP */
staticvoid __init ic_bootp_init_ext(u8 *e)
{
memcpy(e, ic_bootp_cookie, 4); /* RFC1048 Magic Cookie */
e += 4;
*e++ = 1; /* Subnet mask request */
*e++ = 4;
e += 4;
*e++ = 3; /* Default gateway request */
*e++ = 4;
e += 4; #if CONF_NAMESERVERS_MAX > 0
*e++ = 6; /* (DNS) name server request */
*e++ = 4 * CONF_NAMESERVERS_MAX;
e += 4 * CONF_NAMESERVERS_MAX; #endif
*e++ = 12; /* Host name request */
*e++ = 32;
e += 32;
*e++ = 40; /* NIS Domain name request */
*e++ = 32;
e += 32;
*e++ = 17; /* Boot path */
*e++ = 40;
e += 40;
*e++ = 57; /* set extension buffer size for reply */
*e++ = 2;
*e++ = 1; /* 128+236+8+20+14, see dhcpd sources */
*e++ = 150;
*e++ = 255; /* End of the list */
}
/* * Initialize the DHCP/BOOTP mechanism.
*/ staticinlinevoid __init ic_bootp_init(void)
{ /* Re-initialise all name servers and NTP servers to NONE, in case any * were set via the "ip=" or "nfsaddrs=" kernel command line parameters: * any IP addresses specified there will already have been decoded but * are no longer needed
*/
ic_nameservers_predef();
ic_ntp_servers_predef();
/* Fragments are not supported */ if (ip_is_fragment(h)) {
net_err_ratelimited("DHCP/BOOTP: Ignoring fragmented reply\n"); goto drop;
}
if (skb->len < ntohs(h->tot_len)) goto drop;
if (ip_fast_csum((char *) h, h->ihl)) goto drop;
if (b->udph.source != htons(67) || b->udph.dest != htons(68)) goto drop;
if (ntohs(h->tot_len) < ntohs(b->udph.len) + sizeof(struct iphdr)) goto drop;
len = ntohs(b->udph.len) - sizeof(struct udphdr);
ext_len = len - (sizeof(*b) - sizeof(struct iphdr) - sizeof(struct udphdr) - sizeof(b->exten)); if (ext_len < 0) goto drop;
/* Ok the front looks good, make sure we can get at the rest. */ if (!pskb_may_pull(skb, skb->len)) goto drop;
b = (struct bootp_pkt *)skb_network_header(skb);
h = &b->iph;
/* One reply at a time, please. */
spin_lock(&ic_recv_lock);
/* If we already have a reply, just drop the packet */ if (ic_got_reply) goto drop_unlock;
/* Find the ic_device that the packet arrived on */
d = ic_first_dev; while (d && d->dev != dev)
d = d->next; if (!d) goto drop_unlock; /* should never happen */
/* Is it a reply to our BOOTP request? */ if (b->op != BOOTP_REPLY ||
b->xid != d->xid) {
net_err_ratelimited("DHCP/BOOTP: Reply not for us on %s, op[%x] xid[%x]\n",
d->dev->name, b->op, b->xid); goto drop_unlock;
}
#ifdef IPCONFIG_DHCP if (ic_proto_enabled & IC_USE_DHCP) {
__be32 server_id = NONE; int mt = 0;
ext = &b->exten[4]; while (ext < end && *ext != 0xff) {
u8 *opt = ext++; if (*opt == 0) /* Padding */ continue;
ext += *ext + 1; if (ext >= end) break; switch (*opt) { case 53: /* Message type */ if (opt[1])
mt = opt[2]; break; case 54: /* Server ID (IP address) */ if (opt[1] >= 4)
memcpy(&server_id, opt + 2, 4); break;
}
}
pr_debug("DHCP: Got message type %d (%s)\n", mt, d->dev->name);
switch (mt) { case DHCPOFFER: /* While in the process of accepting one offer, * ignore all others.
*/ if (ic_myaddr != NONE) goto drop_unlock;
/* Let's accept that offer. */
ic_myaddr = b->your_ip;
ic_servaddr = server_id;
pr_debug("DHCP: Offered address %pI4 by server %pI4\n",
&ic_myaddr, &b->iph.saddr); /* The DHCP indicated server address takes * precedence over the bootp header one if * they are different.
*/ if ((server_id != NONE) &&
(b->server_ip != server_id))
b->server_ip = ic_servaddr; break;
case DHCPACK: if (memcmp(dev->dev_addr, b->hw_addr, dev->addr_len) != 0) goto drop_unlock;
ext = &b->exten[4]; while (ext < end && *ext != 0xff) {
u8 *opt = ext++; if (*opt == 0) /* Padding */ continue;
ext += *ext + 1; if (ext < end)
ic_do_bootp_ext(opt);
}
}
/* We have a winner! */
ic_dev = d;
ic_myaddr = b->your_ip;
ic_servaddr = b->server_ip;
ic_addrservaddr = b->iph.saddr; if (ic_gateway == NONE && b->relay_ip)
ic_gateway = b->relay_ip; if (ic_nameservers[0] == NONE) {
ic_nameservers[0] = ic_servaddr;
ic_nameservers_fallback = 1;
}
ic_got_reply = IC_BOOTP;
drop_unlock: /* Show's over. Nothing to see here. */
spin_unlock(&ic_recv_lock);
drop: /* Throw the packet out. */
kfree_skb(skb);
return 0;
}
#endif
/* * Dynamic IP configuration -- DHCP, BOOTP, RARP.
*/
#ifdef IPCONFIG_DYNAMIC
staticint __init ic_dynamic(void)
{ int retries; struct ic_device *d; unsignedlong start_jiffies, timeout, jiff; int do_bootp = ic_proto_have_if & IC_BOOTP; int do_rarp = ic_proto_have_if & IC_RARP;
/* * If none of DHCP/BOOTP/RARP was selected, return with an error. * This routine gets only called when some pieces of information * are missing, and without DHCP/BOOTP/RARP we are unable to get it.
*/ if (!ic_proto_enabled) {
pr_err("IP-Config: Incomplete network configuration information\n"); return -1;
}
#ifdef IPCONFIG_BOOTP if ((ic_proto_enabled ^ ic_proto_have_if) & IC_BOOTP)
pr_err("DHCP/BOOTP: No suitable device found\n"); #endif #ifdef IPCONFIG_RARP if ((ic_proto_enabled ^ ic_proto_have_if) & IC_RARP)
pr_err("RARP: No suitable device found\n"); #endif
if (!ic_proto_have_if) /* Error message already printed */ return -1;
/* * Setup protocols
*/ #ifdef IPCONFIG_BOOTP if (do_bootp)
ic_bootp_init(); #endif #ifdef IPCONFIG_RARP if (do_rarp)
ic_rarp_init(); #endif
/* * Send requests and wait, until we get an answer. This loop * seems to be a terrible waste of CPU time, but actually there is * only one process running at all, so we don't need to use any * scheduler functions. * [Actually we could now, but the nothing else running note still * applies.. - AC]
*/
pr_notice("Sending %s%s%s requests .",
do_bootp
? ((ic_proto_enabled & IC_USE_DHCP) ? "DHCP" : "BOOTP") : "",
(do_bootp && do_rarp) ? " and " : "",
do_rarp ? "RARP" : "");
if (ic_domain[0])
seq_printf(seq, "domain %s\n", ic_domain); for (i = 0; i < CONF_NAMESERVERS_MAX; i++) { if (ic_nameservers[i] != NONE)
seq_printf(seq, "nameserver %pI4\n",
&ic_nameservers[i]);
} if (ic_servaddr != NONE)
seq_printf(seq, "bootserver %pI4\n",
&ic_servaddr); return 0;
}
/* Create the /proc/net/ipconfig directory */ staticint __init ipconfig_proc_net_init(void)
{
ipconfig_dir = proc_net_mkdir(&init_net, "ipconfig", init_net.proc_net); if (!ipconfig_dir) return -ENOMEM;
return 0;
}
/* Create a new file under /proc/net/ipconfig */ staticint ipconfig_proc_net_create(constchar *name, conststruct proc_ops *proc_ops)
{ char *pname; struct proc_dir_entry *p;
if (!ipconfig_dir) return -ENOMEM;
pname = kasprintf(GFP_KERNEL, "%s%s", "ipconfig/", name); if (!pname) return -ENOMEM;
p = proc_create(pname, 0444, init_net.proc_net, proc_ops);
kfree(pname); if (!p) return -ENOMEM;
return 0;
}
/* Write NTP server IP addresses to /proc/net/ipconfig/ntp_servers */ staticint ntp_servers_show(struct seq_file *seq, void *v)
{ int i;
for (i = 0; i < CONF_NTP_SERVERS_MAX; i++) { if (ic_ntp_servers[i] != NONE)
seq_printf(seq, "%pI4\n", &ic_ntp_servers[i]);
} return 0;
}
DEFINE_PROC_SHOW_ATTRIBUTE(ntp_servers); #endif/* CONFIG_PROC_FS */
/* * Extract IP address from the parameter string if needed. Note that we * need to have root_server_addr set _before_ IPConfig gets called as it * can override it.
*/
__be32 __init root_nfs_parse_addr(char *name)
{
__be32 addr; int octets = 0; char *cp, *cq;
staticint __init wait_for_devices(void)
{ int i; bool try_init_devs = true;
for (i = 0; i < DEVICE_WAIT_MAX; i++) { struct net_device *dev; int found = 0;
/* make sure deferred device probes are finished */
wait_for_device_probe();
rtnl_lock();
for_each_netdev(&init_net, dev) { if (ic_is_init_dev(dev)) {
found = 1; break;
}
}
rtnl_unlock(); if (found) return 0; if (try_init_devs &&
(ROOT_DEV == Root_NFS || ROOT_DEV == Root_CIFS)) {
try_init_devs = false;
wait_for_init_devices_probe();
}
ssleep(1);
} return -ENODEV;
}
/* * IP Autoconfig dispatcher.
*/
staticint __init ip_auto_config(void)
{
__be32 addr; #ifdef IPCONFIG_DYNAMIC int retries = CONF_OPEN_RETRIES; #endif int err; unsignedint i, count;
/* Initialise all name servers and NTP servers to NONE (but only if the * "ip=" or "nfsaddrs=" kernel command line parameters weren't decoded, * otherwise we'll overwrite the IP addresses specified there)
*/ if (ic_set_manually == 0) {
ic_nameservers_predef();
ic_ntp_servers_predef();
}
if (ipconfig_proc_net_init() == 0)
ipconfig_proc_net_create("ntp_servers", &ntp_servers_proc_ops); #endif/* CONFIG_PROC_FS */
if (!ic_enable) return 0;
pr_debug("IP-Config: Entered.\n"); #ifdef IPCONFIG_DYNAMIC
try_try_again: #endif /* Wait for devices to appear */
err = wait_for_devices(); if (err) return err;
/* Setup all network devices */
err = ic_open_devs(); if (err) return err;
/* Give drivers a chance to settle */
msleep(CONF_POST_OPEN);
/* * If the config information is insufficient (e.g., our IP address or * IP address of the boot server is missing or we have multiple network * interfaces and no default was set), use BOOTP or RARP to get the * missing values.
*/ if (ic_myaddr == NONE || #ifdefined(CONFIG_ROOT_NFS) || defined(CONFIG_CIFS_ROOT)
(root_server_addr == NONE &&
ic_servaddr == NONE &&
(ROOT_DEV == Root_NFS || ROOT_DEV == Root_CIFS)) || #endif
ic_first_dev->next) { #ifdef IPCONFIG_DYNAMIC if (ic_dynamic() < 0) {
ic_close_devs();
/* * I don't know why, but sometimes the * eepro100 driver (at least) gets upset and * doesn't work the first time it's opened. * But then if you close it and reopen it, it * works just fine. So we need to try that at * least once before giving up. * * Also, if the root will be NFS-mounted, we * have nowhere to go if DHCP fails. So we * just have to keep trying forever. * * -- Chip
*/ #ifdef CONFIG_ROOT_NFS if (ROOT_DEV == Root_NFS) {
pr_err("IP-Config: Retrying forever (NFS root)...\n"); goto try_try_again;
} #endif #ifdef CONFIG_CIFS_ROOT if (ROOT_DEV == Root_CIFS) {
pr_err("IP-Config: Retrying forever (CIFS root)...\n"); goto try_try_again;
} #endif
if (--retries) {
pr_err("IP-Config: Reopening network devices...\n"); goto try_try_again;
}
/* Oh, well. At least we tried. */
pr_err("IP-Config: Auto-configuration of network failed\n"); return -1;
} #else/* !DYNAMIC */
pr_err("IP-Config: Incomplete network configuration information\n");
ic_close_devs(); return -1; #endif/* IPCONFIG_DYNAMIC */
} else { /* Device selected manually or only one device -> use it */
ic_dev = ic_first_dev;
}
addr = root_nfs_parse_addr(root_server_path); if (root_server_addr == NONE)
root_server_addr = addr;
/* * Use defaults wherever applicable.
*/ if (ic_defaults() < 0) return -1;
/* * Record which protocol was actually used.
*/ #ifdef IPCONFIG_DYNAMIC
ic_proto_used = ic_got_reply | (ic_proto_enabled & IC_USE_DHCP); #endif
#ifndef IPCONFIG_SILENT /* * Clue in the operator.
*/
pr_info("IP-Config: Complete:\n");
pr_info(" device=%s, hwaddr=%*phC, ipaddr=%pI4, mask=%pI4, gw=%pI4\n",
ic_dev->dev->name, ic_dev->dev->addr_len, ic_dev->dev->dev_addr,
&ic_myaddr, &ic_netmask, &ic_gateway);
pr_info(" host=%s, domain=%s, nis-domain=%s\n",
utsname()->nodename, ic_domain, utsname()->domainname);
pr_info(" bootserver=%pI4, rootserver=%pI4, rootpath=%s",
&ic_servaddr, &root_server_addr, root_server_path); if (ic_dev_mtu)
pr_cont(", mtu=%d", ic_dev_mtu); /* Name servers (if any): */ for (i = 0, count = 0; i < CONF_NAMESERVERS_MAX; i++) { if (ic_nameservers[i] != NONE) { if (i == 0)
pr_info(" nameserver%u=%pI4",
i, &ic_nameservers[i]); else
pr_cont(", nameserver%u=%pI4",
i, &ic_nameservers[i]);
count++;
} if ((i + 1 == CONF_NAMESERVERS_MAX) && count > 0)
pr_cont("\n");
} /* NTP servers (if any): */ for (i = 0, count = 0; i < CONF_NTP_SERVERS_MAX; i++) { if (ic_ntp_servers[i] != NONE) { if (i == 0)
pr_info(" ntpserver%u=%pI4",
i, &ic_ntp_servers[i]); else
pr_cont(", ntpserver%u=%pI4",
i, &ic_ntp_servers[i]);
/* * Close all network devices except the device we've * autoconfigured and set up routes.
*/ if (ic_setup_if() < 0 || ic_setup_routes() < 0)
err = -1; else
err = 0;
ic_close_devs();
return err;
}
late_initcall(ip_auto_config);
/* * Decode any IP configuration options in the "ip=" or "nfsaddrs=" kernel * command line parameter. See Documentation/admin-guide/nfs/nfsroot.rst.
*/ staticint __init ic_proto_name(char *name)
{ if (!strcmp(name, "on") || !strcmp(name, "any")) { return 1;
} if (!strcmp(name, "off") || !strcmp(name, "none")) { return 0;
} #ifdef CONFIG_IP_PNP_DHCP elseif (!strncmp(name, "dhcp", 4)) { char *client_id;
staticint __init ip_auto_config_setup(char *addrs)
{ char *cp, *ip, *dp; int num = 0;
ic_set_manually = 1;
ic_enable = 1;
/* * If any dhcp, bootp etc options are set, leave autoconfig on * and skip the below static IP processing.
*/ if (ic_proto_name(addrs)) return 1;
/* If no static IP is given, turn off autoconfig and bail. */ if (*addrs == 0 ||
strcmp(addrs, "off") == 0 ||
strcmp(addrs, "none") == 0) {
ic_enable = 0; return 1;
}
/* Initialise all name servers and NTP servers to NONE */
ic_nameservers_predef();
ic_ntp_servers_predef();
/* Parse string for static IP assignment. */
ip = addrs; while (ip && *ip) { if ((cp = strchr(ip, ':')))
*cp++ = '\0'; if (strlen(ip) > 0) {
pr_debug("IP-Config: Parameter #%d: `%s'\n", num, ip); switch (num) { case 0: if ((ic_myaddr = in_aton(ip)) == ANY)
ic_myaddr = NONE; break; case 1: if ((ic_servaddr = in_aton(ip)) == ANY)
ic_servaddr = NONE; break; case 2: if ((ic_gateway = in_aton(ip)) == ANY)
ic_gateway = NONE; break; case 3: if ((ic_netmask = in_aton(ip)) == ANY)
ic_netmask = NONE; break; case 4: if ((dp = strchr(ip, '.'))) {
*dp++ = '\0';
strscpy(utsname()->domainname, dp, sizeof(utsname()->domainname));
}
strscpy(utsname()->nodename, ip, sizeof(utsname()->nodename));
ic_host_name_set = 1; break; case 5:
strscpy(user_dev_name, ip, sizeof(user_dev_name)); break; case 6: if (ic_proto_name(ip) == 0 &&
ic_myaddr == NONE) {
ic_enable = 0;
} break; case 7: if (CONF_NAMESERVERS_MAX >= 1) {
ic_nameservers[0] = in_aton(ip); if (ic_nameservers[0] == ANY)
ic_nameservers[0] = NONE;
} break; case 8: if (CONF_NAMESERVERS_MAX >= 2) {
ic_nameservers[1] = in_aton(ip); if (ic_nameservers[1] == ANY)
ic_nameservers[1] = NONE;
} break; case 9: if (CONF_NTP_SERVERS_MAX >= 1) {
ic_ntp_servers[0] = in_aton(ip); if (ic_ntp_servers[0] == ANY)
ic_ntp_servers[0] = NONE;
} break;
}
}
ip = cp;
num++;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.