cregit-Linux how code gets into the kernel

Release 4.8 net/ipv4/ipconfig.c

Directory: net/ipv4
/*
 *  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
 */

#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/random.h>
#include <linux/init.h>
#include <linux/utsname.h>
#include <linux/in.h>
#include <linux/if.h>
#include <linux/inet.h>
#include <linux/inetdevice.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/socket.h>
#include <linux/route.h>
#include <linux/udp.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/major.h>
#include <linux/root_dev.h>
#include <linux/delay.h>
#include <linux/nfs_fs.h>
#include <linux/slab.h>
#include <linux/export.h>
#include <net/net_namespace.h>
#include <net/arp.h>
#include <net/ip.h>
#include <net/ipconfig.h>
#include <net/route.h>

#include <asm/uaccess.h>
#include <net/checksum.h>
#include <asm/processor.h>

#if defined(CONFIG_IP_PNP_DHCP)

#define IPCONFIG_DHCP
#endif
#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_DHCP)

#define IPCONFIG_BOOTP
#endif
#if defined(CONFIG_IP_PNP_RARP)

#define IPCONFIG_RARP
#endif
#if defined(IPCONFIG_BOOTP) || defined(IPCONFIG_RARP)

#define IPCONFIG_DYNAMIC
#endif

/* Define the friendly delay before and after opening net devices */

#define CONF_POST_OPEN		10	
/* After opening: 10 msecs */

#define CONF_CARRIER_TIMEOUT	120000	
/* Wait for carrier timeout */

/* 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_INTER_TIMEOUT	(HZ)	
/* Inter-device timeout: 1 second */

#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 NONE cpu_to_be32(INADDR_NONE)

#define ANY cpu_to_be32(INADDR_ANY)

/*
 * 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 */


static int ic_enable __initdata;		
/* IP config enabled? */

/* Protocol choice */

int ic_proto_enabled __initdata = 0
#ifdef IPCONFIG_BOOTP
			| IC_BOOTP
#endif
#ifdef CONFIG_IP_PNP_DHCP
			| IC_USE_DHCP
#endif
#ifdef IPCONFIG_RARP
			| IC_RARP
#endif
			;


static int ic_host_name_set __initdata;	
/* Host name set by us? */


__be32 ic_myaddr = NONE;		
/* My IP address */

static __be32 ic_netmask = NONE;	
/* Netmask for local subnet */

__be32 ic_gateway = NONE;	
/* Gateway IP address */

#ifdef IPCONFIG_DYNAMIC

static __be32 ic_addrservaddr = NONE;	
/* IP Address of the IP addresses'server */
#endif


__be32 ic_servaddr = NONE;	
/* Boot server IP address */


__be32 root_server_addr = NONE;	
/* Address of NFS server */

u8 root_server_path[256] = { 0, };	
/* Path to mount as root */

/* vendor class identifier */

static char vendor_class_identifier[253] __initdata;

#if defined(CONFIG_IP_PNP_DHCP)

static char dhcp_client_identifier[253] __initdata;
#endif

/* Persistent data: */

#ifdef IPCONFIG_DYNAMIC

static int 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 u8 ic_domain[64];		
/* DNS (not NIS) domain name */

/*
 * Private state.
 */

/* Name of user-selected boot device */

static char user_dev_name[IFNAMSIZ] __initdata = { 0, };

/* Protocols supported by available interfaces */

static int ic_proto_have_if __initdata;

/* MTU for boot device */

static int ic_dev_mtu __initdata;

#ifdef IPCONFIG_DYNAMIC
static DEFINE_SPINLOCK(ic_recv_lock);

static volatile int ic_got_reply __initdata;    
/* Proto(s) that replied */
#endif
#ifdef IPCONFIG_DHCP

static int ic_dhcp_msgtype __initdata;	
/* DHCP msg type received */
#endif


/*
 *      Network devices
 */


struct ic_device {
	
struct ic_device *next;
	
struct net_device *dev;
	
unsigned short flags;
	
short able;
	
__be32 xid;
};


static struct ic_device *ic_first_dev __initdata;	
/* List of open device */

static struct net_device *ic_dev __initdata;		
/* Selected device */


static bool __init ic_is_init_dev(struct net_device *dev) { if (dev->flags & IFF_LOOPBACK) return false; return user_dev_name[0] ? !strcmp(dev->name, user_dev_name) : (!(dev->flags & IFF_LOOPBACK) && (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) && strncmp(dev->name, "dummy", 5)); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller6284.93%150.00%
micha nelissenmicha nelissen1115.07%150.00%
Total73100.00%2100.00%


static int __init ic_open_devs(void) { struct ic_device *d, **last; struct net_device *dev; unsigned short oflags; unsigned long start, next_msg; last = &ic_first_dev; rtnl_lock(); /* bring loopback and DSA master network devices up first */ for_each_netdev(&init_net, dev) { if (!(dev->flags & IFF_LOOPBACK) && !netdev_uses_dsa(dev)) continue; if (dev_change_flags(dev, dev->flags | IFF_UP) < 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) < 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); } } /* 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 + msecs_to_jiffies(CONF_CARRIER_TIMEOUT/12); while (time_before(jiffies, start + msecs_to_jiffies(CONF_CARRIER_TIMEOUT))) { int wait, elapsed; for_each_netdev(&init_net, dev) if (ic_is_init_dev(dev) && netif_carrier_ok(dev)) goto have_carrier; msleep(1); if (time_before(jiffies, next_msg)) continue; elapsed = jiffies_to_msecs(jiffies - start); wait = (CONF_CARRIER_TIMEOUT - elapsed + 500)/1000; pr_info("Waiting up to %d more seconds for network.\n", wait); next_msg = jiffies + msecs_to_jiffies(CONF_CARRIER_TIMEOUT/12); } have_carrier: rtnl_unlock(); *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; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git22849.03%521.74%
paul gortmakerpaul gortmaker6213.33%14.35%
micha nelissenmicha nelissen4910.54%14.35%
linus torvaldslinus torvalds337.10%28.70%
eric w. biedermaneric w. biederman255.38%28.70%
hideaki yoshifujihideaki yoshifuji183.87%14.35%
gerlando falautogerlando falauto91.94%14.35%
joe perchesjoe perches71.51%14.35%
florian fainelliflorian fainelli71.51%14.35%
francois-xavier le bailfrancois-xavier le bail51.08%14.35%
bastian stenderbastian stender51.08%14.35%
himangi saraogihimangi saraogi51.08%14.35%
pavel emelianovpavel emelianov40.86%14.35%
stephen hemmingerstephen hemminger30.65%14.35%
daniel lezcanodaniel lezcano20.43%14.35%
david s. millerdavid s. miller20.43%14.35%
al viroal viro10.22%14.35%
Total465100.00%23100.00%


static void __init ic_close_devs(void) { struct ic_device *d, *next; struct net_device *dev; rtnl_lock(); next = ic_first_dev; while ((d = next)) { next = d->next; dev = d->dev; if (dev != ic_dev && !netdev_uses_dsa(dev)) { pr_debug("IP-Config: Downing %s\n", dev->name); dev_change_flags(dev, d->flags); } kfree(d); } rtnl_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git8189.01%562.50%
florian fainelliflorian fainelli66.59%112.50%
stephen hemmingerstephen hemminger22.20%112.50%
bastian stenderbastian stender22.20%112.50%
Total91100.00%8100.00%

/* * Interface to various network functions. */
static inline void set_sockaddr(struct sockaddr_in *sin, __be32 addr, __be16 port) { sin->sin_family = AF_INET; sin->sin_addr.s_addr = addr; sin->sin_port = port; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git3694.74%150.00%
al viroal viro25.26%150.00%
Total38100.00%2100.00%


static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg) { int res; mm_segment_t oldfs = get_fs(); set_fs(get_ds()); res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg); set_fs(oldfs); return res; }

Contributors

PersonTokensPropCommitsCommitProp
chris friesenchris friesen57100.00%1100.00%
Total57100.00%1100.00%


static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg) { int res; mm_segment_t oldfs = get_fs(); set_fs(get_ds()); res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg); set_fs(oldfs); return res; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4782.46%240.00%
stephen hemmingerstephen hemminger610.53%120.00%
denis v. lunevdenis v. lunev35.26%120.00%
chris friesenchris friesen11.75%120.00%
Total57100.00%5100.00%


static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg) { int res; mm_segment_t oldfs = get_fs(); set_fs(get_ds()); res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg); set_fs(oldfs); return res; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4885.71%250.00%
stephen hemmingerstephen hemminger58.93%125.00%
denis v. lunevdenis v. lunev35.36%125.00%
Total56100.00%4100.00%

/* * Set up interface addresses and routes. */
static int __init ic_setup_if(void) { struct ifreq ir; struct sockaddr_in *sin = (void *) &ir.ifr_ifru.ifru_addr; int err; memset(&ir, 0, sizeof(ir)); strcpy(ir.ifr_ifrn.ifrn_name, ic_dev->name); set_sockaddr(sin, ic_myaddr, 0); if ((err = ic_devinet_ioctl(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 = ic_devinet_ioctl(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 = ic_devinet_ioctl(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) { strcpy(ir.ifr_name, ic_dev->name); ir.ifr_mtu = ic_dev_mtu; if ((err = ic_dev_ioctl(SIOCSIFMTU, &ir)) < 0) pr_err("IP-Config: Unable to set interface mtu to %d (%d)\n", ic_dev_mtu, err); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git16973.80%250.00%
chris friesenchris friesen5222.71%125.00%
joe perchesjoe perches83.49%125.00%
Total229100.00%4100.00%


static int __init ic_setup_routes(void) { /* No need to setup device routes, only the default route... */ if (ic_gateway != NONE) { struct rtentry rm; int err; memset(&rm, 0, sizeof(rm)); if ((ic_gateway ^ ic_myaddr) & ic_netmask) { pr_err("IP-Config: Gateway not on directly connected network\n"); return -1; } set_sockaddr((struct sockaddr_in *) &rm.rt_dst, 0, 0); set_sockaddr((struct sockaddr_in *) &rm.rt_genmask, 0, 0); set_sockaddr((struct sockaddr_in *) &rm.rt_gateway, ic_gateway, 0); rm.rt_flags = RTF_UP | RTF_GATEWAY; if ((err = ic_route_ioctl(SIOCADDRT, &rm)) < 0) { pr_err("IP-Config: Cannot add default route (%d)\n", err); return -1; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git14596.67%250.00%
joe perchesjoe perches42.67%125.00%
al viroal viro10.67%125.00%
Total150100.00%4100.00%

/* * Fill in default values for all missing parameters. */
static int __init ic_defaults(void) { /* * At this point we have no userspace running so need not * claim locks on system_utsname */ if (!ic_host_name_set) sprintf(init_utsname()->nodename, "%pI4", &ic_myaddr); if (root_server_addr == NONE) root_server_addr = ic_servaddr; if (ic_netmask == NONE) { if (IN_CLASSA(ntohl(ic_myaddr))) ic_netmask = htonl(IN_CLASSA_NET); else if (IN_CLASSB(ntohl(ic_myaddr))) ic_netmask = htonl(IN_CLASSB_NET); else if (IN_CLASSC(ntohl(ic_myaddr))) ic_netmask = htonl(IN_CLASSC_NET); else { pr_err("IP-Config: Unable to guess netmask for address %pI4\n", &ic_myaddr); return -1; } pr_notice("IP-Config: Guessing netmask %pI4\n", &ic_netmask); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git10785.60%436.36%
harvey harrisonharvey harrison64.80%19.09%
hideaki yoshifujihideaki yoshifuji32.40%19.09%
serge hallynserge hallyn32.40%19.09%
al viroal viro21.60%19.09%
linus torvaldslinus torvalds21.60%19.09%
bastian stenderbastian stender10.80%19.09%
joe perchesjoe perches10.80%19.09%
Total125100.00%11100.00%

/* * RARP support. */ #ifdef IPCONFIG_RARP static int ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev); static struct packet_type rarp_packet_type __initdata = { .type = cpu_to_be16(ETH_P_RARP), .func = ic_rarp_recv, };
static inline void __init ic_rarp_init(void) { dev_add_pack(&rarp_packet_type); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1593.75%266.67%
sam ravnborgsam ravnborg16.25%133.33%
Total16100.00%3100.00%


static inline void __init ic_rarp_cleanup(void) { dev_remove_pack(&rarp_packet_type); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1593.75%266.67%
sam ravnborgsam ravnborg16.25%133.33%
Total16100.00%3100.00%

/* * Process received RARP packet. */
static int __init ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { struct arphdr *rarp; unsigned char *rarp_ptr; __be32 sip, tip; unsigned char *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 = (unsigned char *) (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 */ /* Extract variable-width fields */ rarp_ptr += dev->addr_len; memcpy(&sip, rarp_ptr, 4); rarp_ptr += 4; tha = rarp_ptr; rarp_ptr += dev->addr_len; memcpy(&tip, rarp_ptr, 4); /* Discard packets which are not meant for us. */ if (memcmp(tha, dev->dev_addr, dev->addr_len)) goto drop_unlock; /* Discard packets which are not from specified server. */ if (ic_servaddr != NONE && ic_servaddr != sip) goto drop_unlock; /* We have a winner! */ ic_dev = dev; if (ic_myaddr == NONE) ic_myaddr = tip; ic_servaddr = sip; ic_addrservaddr = sip; ic_got_reply = IC_RARP; drop_unlock: /* Show's over. Nothing to see here. */ spin_unlock(&ic_recv_lock); drop: /* Throw the packet out. */ kfree_skb(skb); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git19651.58%421.05%
david s. millerdavid s. miller12532.89%315.79%
linus torvaldslinus torvalds215.53%210.53%
hideaki yoshifujihideaki yoshifuji102.63%315.79%
eric w. biedermaneric w. biederman71.84%15.26%
arnaldo carvalho de meloarnaldo carvalho de melo61.58%15.26%
ian morrisian morris51.32%15.26%
philippe de muyterphilippe de muyter41.05%15.26%
al viroal viro30.79%15.26%
pavel emelianovpavel emelianov20.53%15.26%
fabian frederickfabian frederick10.26%15.26%
Total380100.00%19100.00%

/* * Send RARP request packet over a single interface. */
static void __init ic_rarp_send_if(struct ic_device *d) { struct net_device *dev = d->dev; arp_send(ARPOP_RREQUEST, ETH_P_RARP, 0, dev, 0, NULL, dev->dev_addr, dev->dev_addr); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4295.45%375.00%
linus torvaldslinus torvalds24.55%125.00%
Total44100.00%4100.00%

#endif /* * Predefine Nameservers */
static inline void __init ic_nameservers_predef(void) { int i; for (i = 0; i < CONF_NAMESERVERS_MAX; i++) ic_nameservers[i] = NONE; }

Contributors

PersonTokensPropCommitsCommitProp
andy shevchenkoandy shevchenko33100.00%1100.00%
Total33100.00%1100.00%

/* * DHCP/BOOTP support. */ #ifdef IPCONFIG_BOOTP struct bootp_pkt { /* BOOTP packet format */ struct iphdr iph; /* IP header */ struct udphdr udph; /* UDP header */ u8 op; /* 1=request, 2=reply */ u8 htype; /* HW address type */ u8 hlen; /* HW address length */ u8 hops; /* Used only by gateways */ __be32 xid; /* Transaction ID */ __be16 secs; /* Seconds since we started */ __be16 flags; /* Just what it says */ __be32 client_ip; /* Client's IP address if known */ __be32 your_ip; /* Assigned IP address */ __be32 server_ip; /* (Next, e.g. NFS) Server's IP address */ __be32 relay_ip; /* IP address of BOOTP relay */ u8 hw_addr[16]; /* Client's HW address */ u8 serv_name[64]; /* Server host name */ u8 boot_file[128]; /* Name of boot file */ u8 exten[312]; /* DHCP options / BOOTP vendor extensions */ }; /* packet ops */ #define BOOTP_REQUEST 1 #define BOOTP_REPLY 2 /* DHCP message types */ #define DHCPDISCOVER 1 #define DHCPOFFER 2 #define DHCPREQUEST 3 #define DHCPDECLINE 4 #define DHCPACK 5 #define DHCPNAK 6 #define DHCPRELEASE 7 #define DHCPINFORM 8 static int ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev); static struct packet_type bootp_packet_type __initdata = { .type = cpu_to_be16(ETH_P_IP), .func = ic_bootp_recv, }; static __be32 ic_dev_xid; /* Device under configuration */ /* * Initialize DHCP/BOOTP extension fields in the request. */ static const u8 ic_bootp_cookie[4] = { 99, 130, 83, 99 }; #ifdef IPCONFIG_DHCP
static void __init ic_dhcp_init_options(u8 *options) { u8 mt = ((ic_servaddr == NONE) ? DHCPDISCOVER : DHCPREQUEST); u8 *e = options; int len; pr_debug("DHCP: Sending message type %d\n", mt); memcpy(e, ic_bootp_cookie, 4); /* RFC1048 Magic Cookie */ e += 4; *e++ = 53; /* DHCP message type */ *e++ = 1; *e++ = mt; 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? */ { static const 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 */ }; *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 */ }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds18048.91%110.00%
li rongqingli rongqing6116.58%110.00%
rainer jochemrainer jochem4913.32%110.00%
fengguang wufengguang wu4512.23%110.00%
pre-gitpre-git277.34%220.00%
chris friesenchris friesen30.82%110.00%
bastian stenderbastian stender10.27%110.00%
joe perchesjoe perches10.27%110.00%
al viroal viro10.27%110.00%
Total368100.00%10100.00%

#endif /* IPCONFIG_DHCP */
static void __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; *e++ = 5; /* Name server request */ *e++ = 8; e += 8; *e++ = 12; /* Host name request */ *