/* 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;
/* *PublicIPconfiguration
*/
/* This is used by platforms which might be able to set the ipconfig *variablesusingfirmwareenvironmentvars.Ifthisisset,itwill *ignoresuchfirmwarevariables.
*/ 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 */
/* *Privatestate.
*/
/* 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 *thertnl_lockatinit.Thecarrierwait-loopmustthereforerun *withoutholdingit.
*/
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;
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 *usingjumboframes,forinstance).Ifwecan'tsetthemtu,don'terror *out,we'lltrytomuddlealong.
*/ 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();
} return0;
}
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;
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 *ignoreitanyway.
*/ 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, *andcannotbelargerthanthelengthofoptions
*/ 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 */
}
/* *InitializetheDHCP/BOOTPmechanism.
*/ staticinlinevoid __init ic_bootp_init(void)
{ /* Re-initialise all name servers and NTP servers to NONE, in case any *weresetviathe"ip="or"nfsaddrs="kernelcommandlineparameters: *anyIPaddressesspecifiedtherewillalreadyhavebeendecodedbut *arenolongerneeded
*/
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;
}
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) return0; 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;
}
/* *IPAutoconfigdispatcher.
*/
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="kernelcommandlineparametersweren'tdecoded, *otherwisewe'lloverwritetheIPaddressesspecifiedthere)
*/ if (ic_set_manually == 0) {
ic_nameservers_predef();
ic_ntp_servers_predef();
}
staticint __init ip_auto_config_setup(char *addrs)
{ char *cp, *ip, *dp; int num = 0;
ic_set_manually = 1;
ic_enable = 1;
/* *Ifanydhcp,bootpetcoptionsareset,leaveautoconfigon *andskipthebelowstaticIPprocessing.
*/ if (ic_proto_name(addrs)) return1;
/* 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; return1;
}
/* 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) { case0: if ((ic_myaddr = in_aton(ip)) == ANY)
ic_myaddr = NONE; break; case1: if ((ic_servaddr = in_aton(ip)) == ANY)
ic_servaddr = NONE; break; case2: if ((ic_gateway = in_aton(ip)) == ANY)
ic_gateway = NONE; break; case3: if ((ic_netmask = in_aton(ip)) == ANY)
ic_netmask = NONE; break; case4: 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; case5:
strscpy(user_dev_name, ip, sizeof(user_dev_name)); break; case6: if (ic_proto_name(ip) == 0 &&
ic_myaddr == NONE) {
ic_enable = 0;
} break; case7: if (CONF_NAMESERVERS_MAX >= 1) {
ic_nameservers[0] = in_aton(ip); if (ic_nameservers[0] == ANY)
ic_nameservers[0] = NONE;
} break; case8: if (CONF_NAMESERVERS_MAX >= 2) {
ic_nameservers[1] = in_aton(ip); if (ic_nameservers[1] == ANY)
ic_nameservers[1] = NONE;
} break; case9: 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.