Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Automatic Configuration of IP -- use DHCP, BOOTP, RARP, or |
| 3 | * user-supplied information to configure own IP address and routes. |
| 4 | * |
| 5 | * Copyright (C) 1996-1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
| 6 | * |
| 7 | * Derived from network configuration code in fs/nfs/nfsroot.c, |
| 8 | * originally Copyright (C) 1995, 1996 Gero Kuhlmann and me. |
| 9 | * |
| 10 | * BOOTP rewritten to construct and analyse packets itself instead |
| 11 | * of misusing the IP layer. num_bugs_causing_wrong_arp_replies--; |
| 12 | * -- MJ, December 1998 |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * Fixed ip_auto_config_setup calling at startup in the new "Linker Magic" |
| 15 | * initialization scheme. |
| 16 | * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 08/11/1999 |
| 17 | * |
| 18 | * DHCP support added. To users this looks like a whole separate |
| 19 | * protocol, but we know it's just a bag on the side of BOOTP. |
| 20 | * -- Chip Salzenberg <chip@valinux.com>, May 2000 |
| 21 | * |
| 22 | * Ported DHCP support from 2.2.16 to 2.4.0-test4 |
| 23 | * -- Eric Biederman <ebiederman@lnxi.com>, 30 Aug 2000 |
| 24 | * |
| 25 | * Merged changes from 2.2.19 into 2.4.3 |
| 26 | * -- Eric Biederman <ebiederman@lnxi.com>, 22 April Aug 2001 |
| 27 | * |
| 28 | * Multiple Nameservers in /proc/net/pnp |
| 29 | * -- Josef Siemes <jsiemes@web.de>, Aug 2002 |
| 30 | */ |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/types.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/jiffies.h> |
| 36 | #include <linux/random.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/utsname.h> |
| 39 | #include <linux/in.h> |
| 40 | #include <linux/if.h> |
| 41 | #include <linux/inet.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 42 | #include <linux/inetdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/netdevice.h> |
| 44 | #include <linux/if_arp.h> |
| 45 | #include <linux/skbuff.h> |
| 46 | #include <linux/ip.h> |
| 47 | #include <linux/socket.h> |
| 48 | #include <linux/route.h> |
| 49 | #include <linux/udp.h> |
| 50 | #include <linux/proc_fs.h> |
| 51 | #include <linux/seq_file.h> |
| 52 | #include <linux/major.h> |
| 53 | #include <linux/root_dev.h> |
| 54 | #include <linux/delay.h> |
Adrian Bunk | 43d6066 | 2005-09-05 18:05:52 -0700 | [diff] [blame] | 55 | #include <linux/nfs_fs.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 56 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <net/arp.h> |
| 58 | #include <net/ip.h> |
| 59 | #include <net/ipconfig.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 60 | #include <net/route.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #include <asm/uaccess.h> |
| 63 | #include <net/checksum.h> |
| 64 | #include <asm/processor.h> |
| 65 | |
| 66 | /* Define this to allow debugging output */ |
| 67 | #undef IPCONFIG_DEBUG |
| 68 | |
| 69 | #ifdef IPCONFIG_DEBUG |
| 70 | #define DBG(x) printk x |
| 71 | #else |
| 72 | #define DBG(x) do { } while(0) |
| 73 | #endif |
| 74 | |
| 75 | #if defined(CONFIG_IP_PNP_DHCP) |
| 76 | #define IPCONFIG_DHCP |
| 77 | #endif |
| 78 | #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_DHCP) |
| 79 | #define IPCONFIG_BOOTP |
| 80 | #endif |
| 81 | #if defined(CONFIG_IP_PNP_RARP) |
| 82 | #define IPCONFIG_RARP |
| 83 | #endif |
| 84 | #if defined(IPCONFIG_BOOTP) || defined(IPCONFIG_RARP) |
| 85 | #define IPCONFIG_DYNAMIC |
| 86 | #endif |
| 87 | |
| 88 | /* Define the friendly delay before and after opening net devices */ |
| 89 | #define CONF_PRE_OPEN 500 /* Before opening: 1/2 second */ |
| 90 | #define CONF_POST_OPEN 1 /* After opening: 1 second */ |
| 91 | |
| 92 | /* Define the timeout for waiting for a DHCP/BOOTP/RARP reply */ |
| 93 | #define CONF_OPEN_RETRIES 2 /* (Re)open devices twice */ |
| 94 | #define CONF_SEND_RETRIES 6 /* Send six requests per open */ |
| 95 | #define CONF_INTER_TIMEOUT (HZ/2) /* Inter-device timeout: 1/2 second */ |
| 96 | #define CONF_BASE_TIMEOUT (HZ*2) /* Initial timeout: 2 seconds */ |
| 97 | #define CONF_TIMEOUT_RANDOM (HZ) /* Maximum amount of randomization */ |
| 98 | #define CONF_TIMEOUT_MULT *7/4 /* Rate of timeout growth */ |
| 99 | #define CONF_TIMEOUT_MAX (HZ*30) /* Maximum allowed timeout */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 100 | #define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers |
| 101 | - '3' from resolv.h */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 103 | #define NONE cpu_to_be32(INADDR_NONE) |
| 104 | #define ANY cpu_to_be32(INADDR_ANY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Public IP configuration |
| 108 | */ |
| 109 | |
| 110 | /* This is used by platforms which might be able to set the ipconfig |
| 111 | * variables using firmware environment vars. If this is set, it will |
| 112 | * ignore such firmware variables. |
| 113 | */ |
| 114 | int ic_set_manually __initdata = 0; /* IPconfig parameters set manually */ |
| 115 | |
| 116 | static int ic_enable __initdata = 0; /* IP config enabled? */ |
| 117 | |
| 118 | /* Protocol choice */ |
| 119 | int ic_proto_enabled __initdata = 0 |
| 120 | #ifdef IPCONFIG_BOOTP |
| 121 | | IC_BOOTP |
| 122 | #endif |
| 123 | #ifdef CONFIG_IP_PNP_DHCP |
| 124 | | IC_USE_DHCP |
| 125 | #endif |
| 126 | #ifdef IPCONFIG_RARP |
| 127 | | IC_RARP |
| 128 | #endif |
| 129 | ; |
| 130 | |
| 131 | static int ic_host_name_set __initdata = 0; /* Host name set by us? */ |
| 132 | |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 133 | __be32 ic_myaddr = NONE; /* My IP address */ |
| 134 | static __be32 ic_netmask = NONE; /* Netmask for local subnet */ |
| 135 | __be32 ic_gateway = NONE; /* Gateway IP address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 137 | __be32 ic_servaddr = NONE; /* Boot server IP address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 139 | __be32 root_server_addr = NONE; /* Address of NFS server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | u8 root_server_path[256] = { 0, }; /* Path to mount as root */ |
| 141 | |
Chris Friesen | 2513dfb | 2009-05-17 20:39:33 -0700 | [diff] [blame] | 142 | u32 ic_dev_xid; /* Device under configuration */ |
| 143 | |
David S. Miller | 1b0b04f | 2007-11-19 21:56:16 -0800 | [diff] [blame] | 144 | /* vendor class identifier */ |
| 145 | static char vendor_class_identifier[253] __initdata; |
Rainer Jochem | 62013db | 2007-11-14 02:18:39 -0800 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* Persistent data: */ |
| 148 | |
| 149 | static int ic_proto_used; /* Protocol used, if any */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 150 | static __be32 ic_nameservers[CONF_NAMESERVERS_MAX]; /* DNS Server IP addresses */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | static u8 ic_domain[64]; /* DNS (not NIS) domain name */ |
| 152 | |
| 153 | /* |
| 154 | * Private state. |
| 155 | */ |
| 156 | |
| 157 | /* Name of user-selected boot device */ |
| 158 | static char user_dev_name[IFNAMSIZ] __initdata = { 0, }; |
| 159 | |
| 160 | /* Protocols supported by available interfaces */ |
| 161 | static int ic_proto_have_if __initdata = 0; |
| 162 | |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 163 | /* MTU for boot device */ |
| 164 | static int ic_dev_mtu __initdata = 0; |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | #ifdef IPCONFIG_DYNAMIC |
| 167 | static DEFINE_SPINLOCK(ic_recv_lock); |
| 168 | static volatile int ic_got_reply __initdata = 0; /* Proto(s) that replied */ |
| 169 | #endif |
| 170 | #ifdef IPCONFIG_DHCP |
| 171 | static int ic_dhcp_msgtype __initdata = 0; /* DHCP msg type received */ |
| 172 | #endif |
| 173 | |
| 174 | |
| 175 | /* |
| 176 | * Network devices |
| 177 | */ |
| 178 | |
| 179 | struct ic_device { |
| 180 | struct ic_device *next; |
| 181 | struct net_device *dev; |
| 182 | unsigned short flags; |
| 183 | short able; |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 184 | __be32 xid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */ |
| 188 | static struct net_device *ic_dev __initdata = NULL; /* Selected device */ |
| 189 | |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 190 | static bool __init ic_device_match(struct net_device *dev) |
| 191 | { |
| 192 | if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) : |
| 193 | (!(dev->flags & IFF_LOOPBACK) && |
| 194 | (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) && |
| 195 | strncmp(dev->name, "dummy", 5))) |
| 196 | return true; |
| 197 | return false; |
| 198 | } |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | static int __init ic_open_devs(void) |
| 201 | { |
| 202 | struct ic_device *d, **last; |
| 203 | struct net_device *dev; |
| 204 | unsigned short oflags; |
| 205 | |
| 206 | last = &ic_first_dev; |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 207 | rtnl_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* bring loopback device up first */ |
Eric W. Biederman | 0cc217e | 2007-09-26 22:10:06 -0700 | [diff] [blame] | 210 | for_each_netdev(&init_net, dev) { |
| 211 | if (!(dev->flags & IFF_LOOPBACK)) |
| 212 | continue; |
| 213 | if (dev_change_flags(dev, dev->flags | IFF_UP) < 0) |
| 214 | printk(KERN_ERR "IP-Config: Failed to open %s\n", dev->name); |
| 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 217 | for_each_netdev(&init_net, dev) { |
Eric W. Biederman | 0cc217e | 2007-09-26 22:10:06 -0700 | [diff] [blame] | 218 | if (dev->flags & IFF_LOOPBACK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | continue; |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 220 | if (ic_device_match(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | int able = 0; |
| 222 | if (dev->mtu >= 364) |
| 223 | able |= IC_BOOTP; |
| 224 | else |
| 225 | printk(KERN_WARNING "DHCP/BOOTP: Ignoring device %s, MTU %d too small", dev->name, dev->mtu); |
| 226 | if (!(dev->flags & IFF_NOARP)) |
| 227 | able |= IC_RARP; |
| 228 | able &= ic_proto_enabled; |
| 229 | if (ic_proto_enabled && !able) |
| 230 | continue; |
| 231 | oflags = dev->flags; |
| 232 | if (dev_change_flags(dev, oflags | IFF_UP) < 0) { |
| 233 | printk(KERN_ERR "IP-Config: Failed to open %s\n", dev->name); |
| 234 | continue; |
| 235 | } |
| 236 | if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 237 | rtnl_unlock(); |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 238 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | d->dev = dev; |
| 241 | *last = d; |
| 242 | last = &d->next; |
| 243 | d->flags = oflags; |
| 244 | d->able = able; |
| 245 | if (able & IC_BOOTP) |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 246 | get_random_bytes(&d->xid, sizeof(__be32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | else |
| 248 | d->xid = 0; |
| 249 | ic_proto_have_if |= able; |
| 250 | DBG(("IP-Config: %s UP (able=%d, xid=%08x)\n", |
| 251 | dev->name, able, d->xid)); |
| 252 | } |
| 253 | } |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 254 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | *last = NULL; |
| 257 | |
| 258 | if (!ic_first_dev) { |
| 259 | if (user_dev_name[0]) |
| 260 | printk(KERN_ERR "IP-Config: Device `%s' not found.\n", user_dev_name); |
| 261 | else |
| 262 | printk(KERN_ERR "IP-Config: No network devices available.\n"); |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 263 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static void __init ic_close_devs(void) |
| 269 | { |
| 270 | struct ic_device *d, *next; |
| 271 | struct net_device *dev; |
| 272 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 273 | rtnl_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | next = ic_first_dev; |
| 275 | while ((d = next)) { |
| 276 | next = d->next; |
| 277 | dev = d->dev; |
| 278 | if (dev != ic_dev) { |
| 279 | DBG(("IP-Config: Downing %s\n", dev->name)); |
| 280 | dev_change_flags(dev, d->flags); |
| 281 | } |
| 282 | kfree(d); |
| 283 | } |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 284 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Interface to various network functions. |
| 289 | */ |
| 290 | |
| 291 | static inline void |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 292 | set_sockaddr(struct sockaddr_in *sin, __be32 addr, __be16 port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
| 294 | sin->sin_family = AF_INET; |
| 295 | sin->sin_addr.s_addr = addr; |
| 296 | sin->sin_port = port; |
| 297 | } |
| 298 | |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 299 | static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
| 301 | int res; |
| 302 | |
| 303 | mm_segment_t oldfs = get_fs(); |
| 304 | set_fs(get_ds()); |
Denis V. Lunev | e5b13cb | 2008-02-28 20:51:43 -0800 | [diff] [blame] | 305 | res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | set_fs(oldfs); |
| 307 | return res; |
| 308 | } |
| 309 | |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 310 | static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg) |
| 311 | { |
| 312 | int res; |
| 313 | |
| 314 | mm_segment_t oldfs = get_fs(); |
| 315 | set_fs(get_ds()); |
| 316 | res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg); |
| 317 | set_fs(oldfs); |
| 318 | return res; |
| 319 | } |
| 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg) |
| 322 | { |
| 323 | int res; |
| 324 | |
| 325 | mm_segment_t oldfs = get_fs(); |
| 326 | set_fs(get_ds()); |
Denis V. Lunev | 1bad118 | 2008-01-10 03:29:53 -0800 | [diff] [blame] | 327 | res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | set_fs(oldfs); |
| 329 | return res; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Set up interface addresses and routes. |
| 334 | */ |
| 335 | |
| 336 | static int __init ic_setup_if(void) |
| 337 | { |
| 338 | struct ifreq ir; |
| 339 | struct sockaddr_in *sin = (void *) &ir.ifr_ifru.ifru_addr; |
| 340 | int err; |
| 341 | |
| 342 | memset(&ir, 0, sizeof(ir)); |
| 343 | strcpy(ir.ifr_ifrn.ifrn_name, ic_dev->name); |
| 344 | set_sockaddr(sin, ic_myaddr, 0); |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 345 | if ((err = ic_devinet_ioctl(SIOCSIFADDR, &ir)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | printk(KERN_ERR "IP-Config: Unable to set interface address (%d).\n", err); |
| 347 | return -1; |
| 348 | } |
| 349 | set_sockaddr(sin, ic_netmask, 0); |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 350 | if ((err = ic_devinet_ioctl(SIOCSIFNETMASK, &ir)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | printk(KERN_ERR "IP-Config: Unable to set interface netmask (%d).\n", err); |
| 352 | return -1; |
| 353 | } |
| 354 | set_sockaddr(sin, ic_myaddr | ~ic_netmask, 0); |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 355 | if ((err = ic_devinet_ioctl(SIOCSIFBRDADDR, &ir)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | printk(KERN_ERR "IP-Config: Unable to set interface broadcast address (%d).\n", err); |
| 357 | return -1; |
| 358 | } |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 359 | /* Handle the case where we need non-standard MTU on the boot link (a network |
| 360 | * using jumbo frames, for instance). If we can't set the mtu, don't error |
| 361 | * out, we'll try to muddle along. |
| 362 | */ |
| 363 | if (ic_dev_mtu != 0) { |
| 364 | strcpy(ir.ifr_name, ic_dev->name); |
| 365 | ir.ifr_mtu = ic_dev_mtu; |
| 366 | if ((err = ic_dev_ioctl(SIOCSIFMTU, &ir)) < 0) |
| 367 | printk(KERN_ERR "IP-Config: Unable to set interface mtu to %d (%d).\n", |
| 368 | ic_dev_mtu, err); |
| 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static int __init ic_setup_routes(void) |
| 374 | { |
| 375 | /* No need to setup device routes, only the default route... */ |
| 376 | |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 377 | if (ic_gateway != NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | struct rtentry rm; |
| 379 | int err; |
| 380 | |
| 381 | memset(&rm, 0, sizeof(rm)); |
| 382 | if ((ic_gateway ^ ic_myaddr) & ic_netmask) { |
| 383 | printk(KERN_ERR "IP-Config: Gateway not on directly connected network.\n"); |
| 384 | return -1; |
| 385 | } |
| 386 | set_sockaddr((struct sockaddr_in *) &rm.rt_dst, 0, 0); |
| 387 | set_sockaddr((struct sockaddr_in *) &rm.rt_genmask, 0, 0); |
| 388 | set_sockaddr((struct sockaddr_in *) &rm.rt_gateway, ic_gateway, 0); |
| 389 | rm.rt_flags = RTF_UP | RTF_GATEWAY; |
| 390 | if ((err = ic_route_ioctl(SIOCADDRT, &rm)) < 0) { |
| 391 | printk(KERN_ERR "IP-Config: Cannot add default route (%d).\n", err); |
| 392 | return -1; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Fill in default values for all missing parameters. |
| 401 | */ |
| 402 | |
| 403 | static int __init ic_defaults(void) |
| 404 | { |
| 405 | /* |
| 406 | * At this point we have no userspace running so need not |
| 407 | * claim locks on system_utsname |
| 408 | */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | if (!ic_host_name_set) |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 411 | sprintf(init_utsname()->nodename, "%pI4", &ic_myaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 413 | if (root_server_addr == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | root_server_addr = ic_servaddr; |
| 415 | |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 416 | if (ic_netmask == NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | if (IN_CLASSA(ntohl(ic_myaddr))) |
| 418 | ic_netmask = htonl(IN_CLASSA_NET); |
| 419 | else if (IN_CLASSB(ntohl(ic_myaddr))) |
| 420 | ic_netmask = htonl(IN_CLASSB_NET); |
| 421 | else if (IN_CLASSC(ntohl(ic_myaddr))) |
| 422 | ic_netmask = htonl(IN_CLASSC_NET); |
| 423 | else { |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 424 | printk(KERN_ERR "IP-Config: Unable to guess netmask for address %pI4\n", |
| 425 | &ic_myaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return -1; |
| 427 | } |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 428 | printk("IP-Config: Guessing netmask %pI4\n", &ic_netmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | /* |
| 435 | * RARP support. |
| 436 | */ |
| 437 | |
| 438 | #ifdef IPCONFIG_RARP |
| 439 | |
David S. Miller | f2ccd8f | 2005-08-09 19:34:12 -0700 | [diff] [blame] | 440 | static int ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | static struct packet_type rarp_packet_type __initdata = { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 443 | .type = cpu_to_be16(ETH_P_RARP), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | .func = ic_rarp_recv, |
| 445 | }; |
| 446 | |
Sam Ravnborg | 45e741b | 2008-04-29 20:58:15 -0700 | [diff] [blame] | 447 | static inline void __init ic_rarp_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
| 449 | dev_add_pack(&rarp_packet_type); |
| 450 | } |
| 451 | |
Sam Ravnborg | 45e741b | 2008-04-29 20:58:15 -0700 | [diff] [blame] | 452 | static inline void __init ic_rarp_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
| 454 | dev_remove_pack(&rarp_packet_type); |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * Process received RARP packet. |
| 459 | */ |
| 460 | static int __init |
David S. Miller | f2ccd8f | 2005-08-09 19:34:12 -0700 | [diff] [blame] | 461 | ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
| 463 | struct arphdr *rarp; |
| 464 | unsigned char *rarp_ptr; |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 465 | __be32 sip, tip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | unsigned char *sha, *tha; /* s for "source", t for "target" */ |
| 467 | struct ic_device *d; |
| 468 | |
YOSHIFUJI Hideaki | 721499e | 2008-07-19 22:34:43 -0700 | [diff] [blame] | 469 | if (!net_eq(dev_net(dev), &init_net)) |
Eric W. Biederman | e730c15 | 2007-09-17 11:53:39 -0700 | [diff] [blame] | 470 | goto drop; |
| 471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) |
| 473 | return NET_RX_DROP; |
| 474 | |
| 475 | if (!pskb_may_pull(skb, sizeof(struct arphdr))) |
| 476 | goto drop; |
| 477 | |
| 478 | /* Basic sanity checks can be done without the lock. */ |
Arnaldo Carvalho de Melo | 9c70220 | 2007-04-25 18:04:18 -0700 | [diff] [blame] | 479 | rarp = (struct arphdr *)skb_transport_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | /* If this test doesn't pass, it's not IP, or we should |
| 482 | * ignore it anyway. |
| 483 | */ |
| 484 | if (rarp->ar_hln != dev->addr_len || dev->type != ntohs(rarp->ar_hrd)) |
| 485 | goto drop; |
| 486 | |
| 487 | /* If it's not a RARP reply, delete it. */ |
| 488 | if (rarp->ar_op != htons(ARPOP_RREPLY)) |
| 489 | goto drop; |
| 490 | |
| 491 | /* If it's not Ethernet, delete it. */ |
| 492 | if (rarp->ar_pro != htons(ETH_P_IP)) |
| 493 | goto drop; |
| 494 | |
Pavel Emelyanov | 988b705 | 2008-03-03 12:20:57 -0800 | [diff] [blame] | 495 | if (!pskb_may_pull(skb, arp_hdr_len(dev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | goto drop; |
| 497 | |
| 498 | /* OK, it is all there and looks valid, process... */ |
Arnaldo Carvalho de Melo | 9c70220 | 2007-04-25 18:04:18 -0700 | [diff] [blame] | 499 | rarp = (struct arphdr *)skb_transport_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | rarp_ptr = (unsigned char *) (rarp + 1); |
| 501 | |
| 502 | /* One reply at a time, please. */ |
| 503 | spin_lock(&ic_recv_lock); |
| 504 | |
| 505 | /* If we already have a reply, just drop the packet */ |
| 506 | if (ic_got_reply) |
| 507 | goto drop_unlock; |
| 508 | |
| 509 | /* Find the ic_device that the packet arrived on */ |
| 510 | d = ic_first_dev; |
| 511 | while (d && d->dev != dev) |
| 512 | d = d->next; |
| 513 | if (!d) |
| 514 | goto drop_unlock; /* should never happen */ |
| 515 | |
| 516 | /* Extract variable-width fields */ |
| 517 | sha = rarp_ptr; |
| 518 | rarp_ptr += dev->addr_len; |
| 519 | memcpy(&sip, rarp_ptr, 4); |
| 520 | rarp_ptr += 4; |
| 521 | tha = rarp_ptr; |
| 522 | rarp_ptr += dev->addr_len; |
| 523 | memcpy(&tip, rarp_ptr, 4); |
| 524 | |
| 525 | /* Discard packets which are not meant for us. */ |
| 526 | if (memcmp(tha, dev->dev_addr, dev->addr_len)) |
| 527 | goto drop_unlock; |
| 528 | |
| 529 | /* Discard packets which are not from specified server. */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 530 | if (ic_servaddr != NONE && ic_servaddr != sip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | goto drop_unlock; |
| 532 | |
| 533 | /* We have a winner! */ |
| 534 | ic_dev = dev; |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 535 | if (ic_myaddr == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | ic_myaddr = tip; |
| 537 | ic_servaddr = sip; |
| 538 | ic_got_reply = IC_RARP; |
| 539 | |
| 540 | drop_unlock: |
| 541 | /* Show's over. Nothing to see here. */ |
| 542 | spin_unlock(&ic_recv_lock); |
| 543 | |
| 544 | drop: |
| 545 | /* Throw the packet out. */ |
| 546 | kfree_skb(skb); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | |
| 551 | /* |
| 552 | * Send RARP request packet over a single interface. |
| 553 | */ |
| 554 | static void __init ic_rarp_send_if(struct ic_device *d) |
| 555 | { |
| 556 | struct net_device *dev = d->dev; |
| 557 | arp_send(ARPOP_RREQUEST, ETH_P_RARP, 0, dev, 0, NULL, |
| 558 | dev->dev_addr, dev->dev_addr); |
| 559 | } |
| 560 | #endif |
| 561 | |
| 562 | /* |
| 563 | * DHCP/BOOTP support. |
| 564 | */ |
| 565 | |
| 566 | #ifdef IPCONFIG_BOOTP |
| 567 | |
| 568 | struct bootp_pkt { /* BOOTP packet format */ |
| 569 | struct iphdr iph; /* IP header */ |
| 570 | struct udphdr udph; /* UDP header */ |
| 571 | u8 op; /* 1=request, 2=reply */ |
| 572 | u8 htype; /* HW address type */ |
| 573 | u8 hlen; /* HW address length */ |
| 574 | u8 hops; /* Used only by gateways */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 575 | __be32 xid; /* Transaction ID */ |
| 576 | __be16 secs; /* Seconds since we started */ |
| 577 | __be16 flags; /* Just what it says */ |
| 578 | __be32 client_ip; /* Client's IP address if known */ |
| 579 | __be32 your_ip; /* Assigned IP address */ |
| 580 | __be32 server_ip; /* (Next, e.g. NFS) Server's IP address */ |
| 581 | __be32 relay_ip; /* IP address of BOOTP relay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | u8 hw_addr[16]; /* Client's HW address */ |
| 583 | u8 serv_name[64]; /* Server host name */ |
| 584 | u8 boot_file[128]; /* Name of boot file */ |
| 585 | u8 exten[312]; /* DHCP options / BOOTP vendor extensions */ |
| 586 | }; |
| 587 | |
| 588 | /* packet ops */ |
| 589 | #define BOOTP_REQUEST 1 |
| 590 | #define BOOTP_REPLY 2 |
| 591 | |
| 592 | /* DHCP message types */ |
| 593 | #define DHCPDISCOVER 1 |
| 594 | #define DHCPOFFER 2 |
| 595 | #define DHCPREQUEST 3 |
| 596 | #define DHCPDECLINE 4 |
| 597 | #define DHCPACK 5 |
| 598 | #define DHCPNAK 6 |
| 599 | #define DHCPRELEASE 7 |
| 600 | #define DHCPINFORM 8 |
| 601 | |
David S. Miller | f2ccd8f | 2005-08-09 19:34:12 -0700 | [diff] [blame] | 602 | static int ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | static struct packet_type bootp_packet_type __initdata = { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 605 | .type = cpu_to_be16(ETH_P_IP), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | .func = ic_bootp_recv, |
| 607 | }; |
| 608 | |
| 609 | |
| 610 | /* |
| 611 | * Initialize DHCP/BOOTP extension fields in the request. |
| 612 | */ |
| 613 | |
| 614 | static const u8 ic_bootp_cookie[4] = { 99, 130, 83, 99 }; |
| 615 | |
| 616 | #ifdef IPCONFIG_DHCP |
| 617 | |
| 618 | static void __init |
| 619 | ic_dhcp_init_options(u8 *options) |
| 620 | { |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 621 | u8 mt = ((ic_servaddr == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | ? DHCPDISCOVER : DHCPREQUEST); |
| 623 | u8 *e = options; |
Rainer Jochem | 62013db | 2007-11-14 02:18:39 -0800 | [diff] [blame] | 624 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | #ifdef IPCONFIG_DEBUG |
| 627 | printk("DHCP: Sending message type %d\n", mt); |
| 628 | #endif |
| 629 | |
| 630 | memcpy(e, ic_bootp_cookie, 4); /* RFC1048 Magic Cookie */ |
| 631 | e += 4; |
| 632 | |
| 633 | *e++ = 53; /* DHCP message type */ |
| 634 | *e++ = 1; |
| 635 | *e++ = mt; |
| 636 | |
| 637 | if (mt == DHCPREQUEST) { |
| 638 | *e++ = 54; /* Server ID (IP address) */ |
| 639 | *e++ = 4; |
| 640 | memcpy(e, &ic_servaddr, 4); |
| 641 | e += 4; |
| 642 | |
| 643 | *e++ = 50; /* Requested IP address */ |
| 644 | *e++ = 4; |
| 645 | memcpy(e, &ic_myaddr, 4); |
| 646 | e += 4; |
| 647 | } |
| 648 | |
| 649 | /* always? */ |
| 650 | { |
| 651 | static const u8 ic_req_params[] = { |
| 652 | 1, /* Subnet mask */ |
| 653 | 3, /* Default gateway */ |
| 654 | 6, /* DNS server */ |
| 655 | 12, /* Host name */ |
| 656 | 15, /* Domain name */ |
| 657 | 17, /* Boot path */ |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 658 | 26, /* MTU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | 40, /* NIS domain name */ |
| 660 | }; |
| 661 | |
| 662 | *e++ = 55; /* Parameter request list */ |
| 663 | *e++ = sizeof(ic_req_params); |
| 664 | memcpy(e, ic_req_params, sizeof(ic_req_params)); |
| 665 | e += sizeof(ic_req_params); |
Rainer Jochem | 62013db | 2007-11-14 02:18:39 -0800 | [diff] [blame] | 666 | |
| 667 | if (*vendor_class_identifier) { |
| 668 | printk(KERN_INFO "DHCP: sending class identifier \"%s\"\n", |
| 669 | vendor_class_identifier); |
| 670 | *e++ = 60; /* Class-identifier */ |
| 671 | len = strlen(vendor_class_identifier); |
| 672 | *e++ = len; |
| 673 | memcpy(e, vendor_class_identifier, len); |
| 674 | e += len; |
| 675 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | *e++ = 255; /* End of the list */ |
| 679 | } |
| 680 | |
| 681 | #endif /* IPCONFIG_DHCP */ |
| 682 | |
| 683 | static void __init ic_bootp_init_ext(u8 *e) |
| 684 | { |
| 685 | memcpy(e, ic_bootp_cookie, 4); /* RFC1048 Magic Cookie */ |
| 686 | e += 4; |
| 687 | *e++ = 1; /* Subnet mask request */ |
| 688 | *e++ = 4; |
| 689 | e += 4; |
| 690 | *e++ = 3; /* Default gateway request */ |
| 691 | *e++ = 4; |
| 692 | e += 4; |
| 693 | *e++ = 5; /* Name server request */ |
| 694 | *e++ = 8; |
| 695 | e += 8; |
| 696 | *e++ = 12; /* Host name request */ |
| 697 | *e++ = 32; |
| 698 | e += 32; |
| 699 | *e++ = 40; /* NIS Domain name request */ |
| 700 | *e++ = 32; |
| 701 | e += 32; |
| 702 | *e++ = 17; /* Boot path */ |
| 703 | *e++ = 40; |
| 704 | e += 40; |
| 705 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 706 | *e++ = 57; /* set extension buffer size for reply */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | *e++ = 2; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 708 | *e++ = 1; /* 128+236+8+20+14, see dhcpd sources */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | *e++ = 150; |
| 710 | |
| 711 | *e++ = 255; /* End of the list */ |
| 712 | } |
| 713 | |
| 714 | |
| 715 | /* |
| 716 | * Initialize the DHCP/BOOTP mechanism. |
| 717 | */ |
Sam Ravnborg | 45e741b | 2008-04-29 20:58:15 -0700 | [diff] [blame] | 718 | static inline void __init ic_bootp_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
| 720 | int i; |
| 721 | |
| 722 | for (i = 0; i < CONF_NAMESERVERS_MAX; i++) |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 723 | ic_nameservers[i] = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
| 725 | dev_add_pack(&bootp_packet_type); |
| 726 | } |
| 727 | |
| 728 | |
| 729 | /* |
| 730 | * DHCP/BOOTP cleanup. |
| 731 | */ |
Sam Ravnborg | 45e741b | 2008-04-29 20:58:15 -0700 | [diff] [blame] | 732 | static inline void __init ic_bootp_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | { |
| 734 | dev_remove_pack(&bootp_packet_type); |
| 735 | } |
| 736 | |
| 737 | |
| 738 | /* |
| 739 | * Send DHCP/BOOTP request to single interface. |
| 740 | */ |
| 741 | static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_diff) |
| 742 | { |
| 743 | struct net_device *dev = d->dev; |
| 744 | struct sk_buff *skb; |
| 745 | struct bootp_pkt *b; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | struct iphdr *h; |
| 747 | |
| 748 | /* Allocate packet */ |
Johannes Berg | f5184d2 | 2008-05-12 20:48:31 -0700 | [diff] [blame] | 749 | skb = alloc_skb(sizeof(struct bootp_pkt) + LL_ALLOCATED_SPACE(dev) + 15, |
| 750 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | if (!skb) |
| 752 | return; |
Johannes Berg | f5184d2 | 2008-05-12 20:48:31 -0700 | [diff] [blame] | 753 | skb_reserve(skb, LL_RESERVED_SPACE(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | b = (struct bootp_pkt *) skb_put(skb, sizeof(struct bootp_pkt)); |
| 755 | memset(b, 0, sizeof(struct bootp_pkt)); |
| 756 | |
| 757 | /* Construct IP header */ |
Arnaldo Carvalho de Melo | 04b964d | 2007-03-10 19:27:27 -0300 | [diff] [blame] | 758 | skb_reset_network_header(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 759 | h = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | h->version = 4; |
| 761 | h->ihl = 5; |
| 762 | h->tot_len = htons(sizeof(struct bootp_pkt)); |
| 763 | h->frag_off = htons(IP_DF); |
| 764 | h->ttl = 64; |
| 765 | h->protocol = IPPROTO_UDP; |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 766 | h->daddr = htonl(INADDR_BROADCAST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | h->check = ip_fast_csum((unsigned char *) h, h->ihl); |
| 768 | |
| 769 | /* Construct UDP header */ |
| 770 | b->udph.source = htons(68); |
| 771 | b->udph.dest = htons(67); |
| 772 | b->udph.len = htons(sizeof(struct bootp_pkt) - sizeof(struct iphdr)); |
| 773 | /* UDP checksum not calculated -- explicitly allowed in BOOTP RFC */ |
| 774 | |
| 775 | /* Construct DHCP/BOOTP header */ |
| 776 | b->op = BOOTP_REQUEST; |
| 777 | if (dev->type < 256) /* check for false types */ |
| 778 | b->htype = dev->type; |
| 779 | else if (dev->type == ARPHRD_IEEE802_TR) /* fix for token ring */ |
| 780 | b->htype = ARPHRD_IEEE802; |
| 781 | else if (dev->type == ARPHRD_FDDI) |
| 782 | b->htype = ARPHRD_ETHER; |
| 783 | else { |
| 784 | printk("Unknown ARP type 0x%04x for device %s\n", dev->type, dev->name); |
| 785 | b->htype = dev->type; /* can cause undefined behavior */ |
| 786 | } |
Stephen Hemminger | dea75bd | 2008-03-04 17:03:49 -0800 | [diff] [blame] | 787 | |
| 788 | /* server_ip and your_ip address are both already zero per RFC2131 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | b->hlen = dev->addr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | memcpy(b->hw_addr, dev->dev_addr, dev->addr_len); |
| 791 | b->secs = htons(jiffies_diff / HZ); |
| 792 | b->xid = d->xid; |
| 793 | |
| 794 | /* add DHCP options or BOOTP extensions */ |
| 795 | #ifdef IPCONFIG_DHCP |
| 796 | if (ic_proto_enabled & IC_USE_DHCP) |
| 797 | ic_dhcp_init_options(b->exten); |
| 798 | else |
| 799 | #endif |
| 800 | ic_bootp_init_ext(b->exten); |
| 801 | |
| 802 | /* Chain packet down the line... */ |
| 803 | skb->dev = dev; |
| 804 | skb->protocol = htons(ETH_P_IP); |
Stephen Hemminger | 0c4e858 | 2007-10-09 01:36:32 -0700 | [diff] [blame] | 805 | if (dev_hard_header(skb, dev, ntohs(skb->protocol), |
| 806 | dev->broadcast, dev->dev_addr, skb->len) < 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | dev_queue_xmit(skb) < 0) |
| 808 | printk("E"); |
| 809 | } |
| 810 | |
| 811 | |
| 812 | /* |
| 813 | * Copy BOOTP-supplied string if not already set. |
| 814 | */ |
| 815 | static int __init ic_bootp_string(char *dest, char *src, int len, int max) |
| 816 | { |
| 817 | if (!len) |
| 818 | return 0; |
| 819 | if (len > max-1) |
| 820 | len = max-1; |
| 821 | memcpy(dest, src, len); |
| 822 | dest[len] = '\0'; |
| 823 | return 1; |
| 824 | } |
| 825 | |
| 826 | |
| 827 | /* |
| 828 | * Process BOOTP extensions. |
| 829 | */ |
| 830 | static void __init ic_do_bootp_ext(u8 *ext) |
| 831 | { |
| 832 | u8 servers; |
| 833 | int i; |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 834 | u16 mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | #ifdef IPCONFIG_DEBUG |
| 837 | u8 *c; |
| 838 | |
| 839 | printk("DHCP/BOOTP: Got extension %d:",*ext); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 840 | for (c=ext+2; c<ext+2+ext[1]; c++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | printk(" %02x", *c); |
| 842 | printk("\n"); |
| 843 | #endif |
| 844 | |
| 845 | switch (*ext++) { |
| 846 | case 1: /* Subnet mask */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 847 | if (ic_netmask == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | memcpy(&ic_netmask, ext+1, 4); |
| 849 | break; |
| 850 | case 3: /* Default gateway */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 851 | if (ic_gateway == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | memcpy(&ic_gateway, ext+1, 4); |
| 853 | break; |
| 854 | case 6: /* DNS server */ |
| 855 | servers= *ext/4; |
| 856 | if (servers > CONF_NAMESERVERS_MAX) |
| 857 | servers = CONF_NAMESERVERS_MAX; |
| 858 | for (i = 0; i < servers; i++) { |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 859 | if (ic_nameservers[i] == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | memcpy(&ic_nameservers[i], ext+1+4*i, 4); |
| 861 | } |
| 862 | break; |
| 863 | case 12: /* Host name */ |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 864 | ic_bootp_string(utsname()->nodename, ext+1, *ext, __NEW_UTS_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | ic_host_name_set = 1; |
| 866 | break; |
| 867 | case 15: /* Domain name (DNS) */ |
| 868 | ic_bootp_string(ic_domain, ext+1, *ext, sizeof(ic_domain)); |
| 869 | break; |
| 870 | case 17: /* Root path */ |
| 871 | if (!root_server_path[0]) |
| 872 | ic_bootp_string(root_server_path, ext+1, *ext, sizeof(root_server_path)); |
| 873 | break; |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 874 | case 26: /* Interface MTU */ |
| 875 | memcpy(&mtu, ext+1, sizeof(mtu)); |
| 876 | ic_dev_mtu = ntohs(mtu); |
| 877 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | case 40: /* NIS Domain name (_not_ DNS) */ |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 879 | ic_bootp_string(utsname()->domainname, ext+1, *ext, __NEW_UTS_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | break; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | |
| 885 | /* |
| 886 | * Receive BOOTP reply. |
| 887 | */ |
David S. Miller | f2ccd8f | 2005-08-09 19:34:12 -0700 | [diff] [blame] | 888 | static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | { |
| 890 | struct bootp_pkt *b; |
| 891 | struct iphdr *h; |
| 892 | struct ic_device *d; |
| 893 | int len, ext_len; |
| 894 | |
YOSHIFUJI Hideaki | 721499e | 2008-07-19 22:34:43 -0700 | [diff] [blame] | 895 | if (!net_eq(dev_net(dev), &init_net)) |
Eric W. Biederman | e730c15 | 2007-09-17 11:53:39 -0700 | [diff] [blame] | 896 | goto drop; |
| 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | /* Perform verifications before taking the lock. */ |
| 899 | if (skb->pkt_type == PACKET_OTHERHOST) |
| 900 | goto drop; |
| 901 | |
| 902 | if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) |
| 903 | return NET_RX_DROP; |
| 904 | |
| 905 | if (!pskb_may_pull(skb, |
| 906 | sizeof(struct iphdr) + |
| 907 | sizeof(struct udphdr))) |
| 908 | goto drop; |
| 909 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 910 | b = (struct bootp_pkt *)skb_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | h = &b->iph; |
| 912 | |
| 913 | if (h->ihl != 5 || h->version != 4 || h->protocol != IPPROTO_UDP) |
| 914 | goto drop; |
| 915 | |
| 916 | /* Fragments are not supported */ |
| 917 | if (h->frag_off & htons(IP_OFFSET | IP_MF)) { |
| 918 | if (net_ratelimit()) |
| 919 | printk(KERN_ERR "DHCP/BOOTP: Ignoring fragmented " |
| 920 | "reply.\n"); |
| 921 | goto drop; |
| 922 | } |
| 923 | |
| 924 | if (skb->len < ntohs(h->tot_len)) |
| 925 | goto drop; |
| 926 | |
| 927 | if (ip_fast_csum((char *) h, h->ihl)) |
| 928 | goto drop; |
| 929 | |
| 930 | if (b->udph.source != htons(67) || b->udph.dest != htons(68)) |
| 931 | goto drop; |
| 932 | |
| 933 | if (ntohs(h->tot_len) < ntohs(b->udph.len) + sizeof(struct iphdr)) |
| 934 | goto drop; |
| 935 | |
| 936 | len = ntohs(b->udph.len) - sizeof(struct udphdr); |
| 937 | ext_len = len - (sizeof(*b) - |
| 938 | sizeof(struct iphdr) - |
| 939 | sizeof(struct udphdr) - |
| 940 | sizeof(b->exten)); |
| 941 | if (ext_len < 0) |
| 942 | goto drop; |
| 943 | |
| 944 | /* Ok the front looks good, make sure we can get at the rest. */ |
| 945 | if (!pskb_may_pull(skb, skb->len)) |
| 946 | goto drop; |
| 947 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 948 | b = (struct bootp_pkt *)skb_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | h = &b->iph; |
| 950 | |
| 951 | /* One reply at a time, please. */ |
| 952 | spin_lock(&ic_recv_lock); |
| 953 | |
| 954 | /* If we already have a reply, just drop the packet */ |
| 955 | if (ic_got_reply) |
| 956 | goto drop_unlock; |
| 957 | |
| 958 | /* Find the ic_device that the packet arrived on */ |
| 959 | d = ic_first_dev; |
| 960 | while (d && d->dev != dev) |
| 961 | d = d->next; |
| 962 | if (!d) |
| 963 | goto drop_unlock; /* should never happen */ |
| 964 | |
| 965 | /* Is it a reply to our BOOTP request? */ |
| 966 | if (b->op != BOOTP_REPLY || |
| 967 | b->xid != d->xid) { |
| 968 | if (net_ratelimit()) |
| 969 | printk(KERN_ERR "DHCP/BOOTP: Reply not for us, " |
| 970 | "op[%x] xid[%x]\n", |
| 971 | b->op, b->xid); |
| 972 | goto drop_unlock; |
| 973 | } |
| 974 | |
Chris Friesen | 2513dfb | 2009-05-17 20:39:33 -0700 | [diff] [blame] | 975 | /* Is it a reply for the device we are configuring? */ |
| 976 | if (b->xid != ic_dev_xid) { |
| 977 | if (net_ratelimit()) |
| 978 | printk(KERN_ERR "DHCP/BOOTP: Ignoring delayed packet \n"); |
| 979 | goto drop_unlock; |
| 980 | } |
| 981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | /* Parse extensions */ |
| 983 | if (ext_len >= 4 && |
| 984 | !memcmp(b->exten, ic_bootp_cookie, 4)) { /* Check magic cookie */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 985 | u8 *end = (u8 *) b + ntohs(b->iph.tot_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | u8 *ext; |
| 987 | |
| 988 | #ifdef IPCONFIG_DHCP |
| 989 | if (ic_proto_enabled & IC_USE_DHCP) { |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 990 | __be32 server_id = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | int mt = 0; |
| 992 | |
| 993 | ext = &b->exten[4]; |
| 994 | while (ext < end && *ext != 0xff) { |
| 995 | u8 *opt = ext++; |
| 996 | if (*opt == 0) /* Padding */ |
| 997 | continue; |
| 998 | ext += *ext + 1; |
| 999 | if (ext >= end) |
| 1000 | break; |
| 1001 | switch (*opt) { |
| 1002 | case 53: /* Message type */ |
| 1003 | if (opt[1]) |
| 1004 | mt = opt[2]; |
| 1005 | break; |
| 1006 | case 54: /* Server ID (IP address) */ |
| 1007 | if (opt[1] >= 4) |
| 1008 | memcpy(&server_id, opt + 2, 4); |
| 1009 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | #ifdef IPCONFIG_DEBUG |
| 1014 | printk("DHCP: Got message type %d\n", mt); |
| 1015 | #endif |
| 1016 | |
| 1017 | switch (mt) { |
| 1018 | case DHCPOFFER: |
| 1019 | /* While in the process of accepting one offer, |
| 1020 | * ignore all others. |
| 1021 | */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1022 | if (ic_myaddr != NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | goto drop_unlock; |
| 1024 | |
| 1025 | /* Let's accept that offer. */ |
| 1026 | ic_myaddr = b->your_ip; |
| 1027 | ic_servaddr = server_id; |
| 1028 | #ifdef IPCONFIG_DEBUG |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 1029 | printk("DHCP: Offered address %pI4 by server %pI4\n", |
| 1030 | &ic_myaddr, &ic_servaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | #endif |
| 1032 | /* The DHCP indicated server address takes |
| 1033 | * precedence over the bootp header one if |
| 1034 | * they are different. |
| 1035 | */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1036 | if ((server_id != NONE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | (b->server_ip != server_id)) |
| 1038 | b->server_ip = ic_servaddr; |
| 1039 | break; |
| 1040 | |
| 1041 | case DHCPACK: |
| 1042 | if (memcmp(dev->dev_addr, b->hw_addr, dev->addr_len) != 0) |
| 1043 | goto drop_unlock; |
| 1044 | |
| 1045 | /* Yeah! */ |
| 1046 | break; |
| 1047 | |
| 1048 | default: |
| 1049 | /* Urque. Forget it*/ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1050 | ic_myaddr = NONE; |
| 1051 | ic_servaddr = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | goto drop_unlock; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
| 1055 | ic_dhcp_msgtype = mt; |
| 1056 | |
| 1057 | } |
| 1058 | #endif /* IPCONFIG_DHCP */ |
| 1059 | |
| 1060 | ext = &b->exten[4]; |
| 1061 | while (ext < end && *ext != 0xff) { |
| 1062 | u8 *opt = ext++; |
| 1063 | if (*opt == 0) /* Padding */ |
| 1064 | continue; |
| 1065 | ext += *ext + 1; |
| 1066 | if (ext < end) |
| 1067 | ic_do_bootp_ext(opt); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | /* We have a winner! */ |
| 1072 | ic_dev = dev; |
| 1073 | ic_myaddr = b->your_ip; |
| 1074 | ic_servaddr = b->server_ip; |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1075 | if (ic_gateway == NONE && b->relay_ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | ic_gateway = b->relay_ip; |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1077 | if (ic_nameservers[0] == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | ic_nameservers[0] = ic_servaddr; |
| 1079 | ic_got_reply = IC_BOOTP; |
| 1080 | |
| 1081 | drop_unlock: |
| 1082 | /* Show's over. Nothing to see here. */ |
| 1083 | spin_unlock(&ic_recv_lock); |
| 1084 | |
| 1085 | drop: |
| 1086 | /* Throw the packet out. */ |
| 1087 | kfree_skb(skb); |
| 1088 | |
| 1089 | return 0; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1090 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
| 1092 | |
| 1093 | #endif |
| 1094 | |
| 1095 | |
| 1096 | /* |
| 1097 | * Dynamic IP configuration -- DHCP, BOOTP, RARP. |
| 1098 | */ |
| 1099 | |
| 1100 | #ifdef IPCONFIG_DYNAMIC |
| 1101 | |
| 1102 | static int __init ic_dynamic(void) |
| 1103 | { |
| 1104 | int retries; |
| 1105 | struct ic_device *d; |
| 1106 | unsigned long start_jiffies, timeout, jiff; |
| 1107 | int do_bootp = ic_proto_have_if & IC_BOOTP; |
| 1108 | int do_rarp = ic_proto_have_if & IC_RARP; |
| 1109 | |
| 1110 | /* |
| 1111 | * If none of DHCP/BOOTP/RARP was selected, return with an error. |
| 1112 | * This routine gets only called when some pieces of information |
| 1113 | * are missing, and without DHCP/BOOTP/RARP we are unable to get it. |
| 1114 | */ |
| 1115 | if (!ic_proto_enabled) { |
| 1116 | printk(KERN_ERR "IP-Config: Incomplete network configuration information.\n"); |
| 1117 | return -1; |
| 1118 | } |
| 1119 | |
| 1120 | #ifdef IPCONFIG_BOOTP |
| 1121 | if ((ic_proto_enabled ^ ic_proto_have_if) & IC_BOOTP) |
| 1122 | printk(KERN_ERR "DHCP/BOOTP: No suitable device found.\n"); |
| 1123 | #endif |
| 1124 | #ifdef IPCONFIG_RARP |
| 1125 | if ((ic_proto_enabled ^ ic_proto_have_if) & IC_RARP) |
| 1126 | printk(KERN_ERR "RARP: No suitable device found.\n"); |
| 1127 | #endif |
| 1128 | |
| 1129 | if (!ic_proto_have_if) |
| 1130 | /* Error message already printed */ |
| 1131 | return -1; |
| 1132 | |
| 1133 | /* |
| 1134 | * Setup protocols |
| 1135 | */ |
| 1136 | #ifdef IPCONFIG_BOOTP |
| 1137 | if (do_bootp) |
| 1138 | ic_bootp_init(); |
| 1139 | #endif |
| 1140 | #ifdef IPCONFIG_RARP |
| 1141 | if (do_rarp) |
| 1142 | ic_rarp_init(); |
| 1143 | #endif |
| 1144 | |
| 1145 | /* |
| 1146 | * Send requests and wait, until we get an answer. This loop |
| 1147 | * seems to be a terrible waste of CPU time, but actually there is |
| 1148 | * only one process running at all, so we don't need to use any |
| 1149 | * scheduler functions. |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1150 | * [Actually we could now, but the nothing else running note still |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | * applies.. - AC] |
| 1152 | */ |
| 1153 | printk(KERN_NOTICE "Sending %s%s%s requests .", |
| 1154 | do_bootp |
| 1155 | ? ((ic_proto_enabled & IC_USE_DHCP) ? "DHCP" : "BOOTP") : "", |
| 1156 | (do_bootp && do_rarp) ? " and " : "", |
| 1157 | do_rarp ? "RARP" : ""); |
| 1158 | |
| 1159 | start_jiffies = jiffies; |
| 1160 | d = ic_first_dev; |
| 1161 | retries = CONF_SEND_RETRIES; |
| 1162 | get_random_bytes(&timeout, sizeof(timeout)); |
| 1163 | timeout = CONF_BASE_TIMEOUT + (timeout % (unsigned) CONF_TIMEOUT_RANDOM); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1164 | for (;;) { |
Chris Friesen | 2513dfb | 2009-05-17 20:39:33 -0700 | [diff] [blame] | 1165 | /* Track the device we are configuring */ |
| 1166 | ic_dev_xid = d->xid; |
| 1167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | #ifdef IPCONFIG_BOOTP |
| 1169 | if (do_bootp && (d->able & IC_BOOTP)) |
| 1170 | ic_bootp_send_if(d, jiffies - start_jiffies); |
| 1171 | #endif |
| 1172 | #ifdef IPCONFIG_RARP |
| 1173 | if (do_rarp && (d->able & IC_RARP)) |
| 1174 | ic_rarp_send_if(d); |
| 1175 | #endif |
| 1176 | |
| 1177 | jiff = jiffies + (d->next ? CONF_INTER_TIMEOUT : timeout); |
Nishanth Aravamudan | 121caf5 | 2005-09-12 14:15:34 -0700 | [diff] [blame] | 1178 | while (time_before(jiffies, jiff) && !ic_got_reply) |
| 1179 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | #ifdef IPCONFIG_DHCP |
| 1181 | /* DHCP isn't done until we get a DHCPACK. */ |
Joe Perches | 9d4fb27 | 2009-11-23 10:41:23 -0800 | [diff] [blame] | 1182 | if ((ic_got_reply & IC_BOOTP) && |
| 1183 | (ic_proto_enabled & IC_USE_DHCP) && |
| 1184 | ic_dhcp_msgtype != DHCPACK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | ic_got_reply = 0; |
| 1186 | printk(","); |
| 1187 | continue; |
| 1188 | } |
| 1189 | #endif /* IPCONFIG_DHCP */ |
| 1190 | |
| 1191 | if (ic_got_reply) { |
| 1192 | printk(" OK\n"); |
| 1193 | break; |
| 1194 | } |
| 1195 | |
| 1196 | if ((d = d->next)) |
| 1197 | continue; |
| 1198 | |
| 1199 | if (! --retries) { |
| 1200 | printk(" timed out!\n"); |
| 1201 | break; |
| 1202 | } |
| 1203 | |
| 1204 | d = ic_first_dev; |
| 1205 | |
| 1206 | timeout = timeout CONF_TIMEOUT_MULT; |
| 1207 | if (timeout > CONF_TIMEOUT_MAX) |
| 1208 | timeout = CONF_TIMEOUT_MAX; |
| 1209 | |
| 1210 | printk("."); |
| 1211 | } |
| 1212 | |
| 1213 | #ifdef IPCONFIG_BOOTP |
| 1214 | if (do_bootp) |
| 1215 | ic_bootp_cleanup(); |
| 1216 | #endif |
| 1217 | #ifdef IPCONFIG_RARP |
| 1218 | if (do_rarp) |
| 1219 | ic_rarp_cleanup(); |
| 1220 | #endif |
| 1221 | |
Maxime Bizon | 7a1af5d | 2005-06-28 13:21:12 -0700 | [diff] [blame] | 1222 | if (!ic_got_reply) { |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1223 | ic_myaddr = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | return -1; |
Maxime Bizon | 7a1af5d | 2005-06-28 13:21:12 -0700 | [diff] [blame] | 1225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 1227 | printk("IP-Config: Got %s answer from %pI4, ", |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1228 | ((ic_got_reply & IC_RARP) ? "RARP" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | : (ic_proto_enabled & IC_USE_DHCP) ? "DHCP" : "BOOTP"), |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 1230 | &ic_servaddr); |
| 1231 | printk("my address is %pI4\n", &ic_myaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | #endif /* IPCONFIG_DYNAMIC */ |
| 1237 | |
| 1238 | #ifdef CONFIG_PROC_FS |
| 1239 | |
| 1240 | static int pnp_seq_show(struct seq_file *seq, void *v) |
| 1241 | { |
| 1242 | int i; |
| 1243 | |
| 1244 | if (ic_proto_used & IC_PROTO) |
| 1245 | seq_printf(seq, "#PROTO: %s\n", |
| 1246 | (ic_proto_used & IC_RARP) ? "RARP" |
| 1247 | : (ic_proto_used & IC_USE_DHCP) ? "DHCP" : "BOOTP"); |
| 1248 | else |
| 1249 | seq_puts(seq, "#MANUAL\n"); |
| 1250 | |
| 1251 | if (ic_domain[0]) |
| 1252 | seq_printf(seq, |
| 1253 | "domain %s\n", ic_domain); |
| 1254 | for (i = 0; i < CONF_NAMESERVERS_MAX; i++) { |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1255 | if (ic_nameservers[i] != NONE) |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 1256 | seq_printf(seq, "nameserver %pI4\n", |
| 1257 | &ic_nameservers[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | } |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1259 | if (ic_servaddr != NONE) |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 1260 | seq_printf(seq, "bootserver %pI4\n", |
| 1261 | &ic_servaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | return 0; |
| 1263 | } |
| 1264 | |
| 1265 | static int pnp_seq_open(struct inode *indoe, struct file *file) |
| 1266 | { |
| 1267 | return single_open(file, pnp_seq_show, NULL); |
| 1268 | } |
| 1269 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 1270 | static const struct file_operations pnp_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | .owner = THIS_MODULE, |
| 1272 | .open = pnp_seq_open, |
| 1273 | .read = seq_read, |
| 1274 | .llseek = seq_lseek, |
| 1275 | .release = single_release, |
| 1276 | }; |
| 1277 | #endif /* CONFIG_PROC_FS */ |
| 1278 | |
| 1279 | /* |
| 1280 | * Extract IP address from the parameter string if needed. Note that we |
| 1281 | * need to have root_server_addr set _before_ IPConfig gets called as it |
| 1282 | * can override it. |
| 1283 | */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1284 | __be32 __init root_nfs_parse_addr(char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | { |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1286 | __be32 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | int octets = 0; |
| 1288 | char *cp, *cq; |
| 1289 | |
| 1290 | cp = cq = name; |
| 1291 | while (octets < 4) { |
| 1292 | while (*cp >= '0' && *cp <= '9') |
| 1293 | cp++; |
| 1294 | if (cp == cq || cp - cq > 3) |
| 1295 | break; |
| 1296 | if (*cp == '.' || octets == 3) |
| 1297 | octets++; |
| 1298 | if (octets < 4) |
| 1299 | cp++; |
| 1300 | cq = cp; |
| 1301 | } |
| 1302 | if (octets == 4 && (*cp == ':' || *cp == '\0')) { |
| 1303 | if (*cp == ':') |
| 1304 | *cp++ = '\0'; |
| 1305 | addr = in_aton(name); |
| 1306 | memmove(name, cp, strlen(cp) + 1); |
| 1307 | } else |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1308 | addr = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
| 1310 | return addr; |
| 1311 | } |
| 1312 | |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 1313 | #define DEVICE_WAIT_MAX 12 /* 12 seconds */ |
| 1314 | |
| 1315 | static int __init wait_for_devices(void) |
| 1316 | { |
| 1317 | int i; |
| 1318 | |
| 1319 | msleep(CONF_PRE_OPEN); |
| 1320 | for (i = 0; i < DEVICE_WAIT_MAX; i++) { |
| 1321 | struct net_device *dev; |
| 1322 | int found = 0; |
| 1323 | |
| 1324 | rtnl_lock(); |
| 1325 | for_each_netdev(&init_net, dev) { |
| 1326 | if (ic_device_match(dev)) { |
| 1327 | found = 1; |
| 1328 | break; |
| 1329 | } |
| 1330 | } |
| 1331 | rtnl_unlock(); |
| 1332 | if (found) |
| 1333 | return 0; |
| 1334 | ssleep(1); |
| 1335 | } |
| 1336 | return -ENODEV; |
| 1337 | } |
| 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | /* |
| 1340 | * IP Autoconfig dispatcher. |
| 1341 | */ |
| 1342 | |
| 1343 | static int __init ip_auto_config(void) |
| 1344 | { |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1345 | __be32 addr; |
Benjamin Zores | 9d8dba6 | 2009-01-29 16:19:13 -0800 | [diff] [blame] | 1346 | #ifdef IPCONFIG_DYNAMIC |
| 1347 | int retries = CONF_OPEN_RETRIES; |
| 1348 | #endif |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 1349 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
| 1351 | #ifdef CONFIG_PROC_FS |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 1352 | proc_net_fops_create(&init_net, "pnp", S_IRUGO, &pnp_seq_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | #endif /* CONFIG_PROC_FS */ |
| 1354 | |
| 1355 | if (!ic_enable) |
| 1356 | return 0; |
| 1357 | |
| 1358 | DBG(("IP-Config: Entered.\n")); |
| 1359 | #ifdef IPCONFIG_DYNAMIC |
| 1360 | try_try_again: |
| 1361 | #endif |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 1362 | /* Wait for devices to appear */ |
| 1363 | err = wait_for_devices(); |
| 1364 | if (err) |
| 1365 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
| 1367 | /* Setup all network devices */ |
David S. Miller | 964ad81 | 2010-03-12 00:00:17 -0800 | [diff] [blame^] | 1368 | err = ic_open_devs(); |
| 1369 | if (err) |
| 1370 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
| 1372 | /* Give drivers a chance to settle */ |
| 1373 | ssleep(CONF_POST_OPEN); |
| 1374 | |
| 1375 | /* |
| 1376 | * If the config information is insufficient (e.g., our IP address or |
| 1377 | * IP address of the boot server is missing or we have multiple network |
| 1378 | * interfaces and no default was set), use BOOTP or RARP to get the |
| 1379 | * missing values. |
| 1380 | */ |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1381 | if (ic_myaddr == NONE || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | #ifdef CONFIG_ROOT_NFS |
Joe Perches | 9d4fb27 | 2009-11-23 10:41:23 -0800 | [diff] [blame] | 1383 | (root_server_addr == NONE && |
| 1384 | ic_servaddr == NONE && |
| 1385 | ROOT_DEV == Root_NFS) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | #endif |
| 1387 | ic_first_dev->next) { |
| 1388 | #ifdef IPCONFIG_DYNAMIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | if (ic_dynamic() < 0) { |
| 1390 | ic_close_devs(); |
| 1391 | |
| 1392 | /* |
| 1393 | * I don't know why, but sometimes the |
| 1394 | * eepro100 driver (at least) gets upset and |
| 1395 | * doesn't work the first time it's opened. |
| 1396 | * But then if you close it and reopen it, it |
| 1397 | * works just fine. So we need to try that at |
| 1398 | * least once before giving up. |
| 1399 | * |
| 1400 | * Also, if the root will be NFS-mounted, we |
| 1401 | * have nowhere to go if DHCP fails. So we |
| 1402 | * just have to keep trying forever. |
| 1403 | * |
| 1404 | * -- Chip |
| 1405 | */ |
| 1406 | #ifdef CONFIG_ROOT_NFS |
| 1407 | if (ROOT_DEV == Root_NFS) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1408 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | "IP-Config: Retrying forever (NFS root)...\n"); |
| 1410 | goto try_try_again; |
| 1411 | } |
| 1412 | #endif |
| 1413 | |
| 1414 | if (--retries) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1415 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | "IP-Config: Reopening network devices...\n"); |
| 1417 | goto try_try_again; |
| 1418 | } |
| 1419 | |
| 1420 | /* Oh, well. At least we tried. */ |
| 1421 | printk(KERN_ERR "IP-Config: Auto-configuration of network failed.\n"); |
| 1422 | return -1; |
| 1423 | } |
| 1424 | #else /* !DYNAMIC */ |
| 1425 | printk(KERN_ERR "IP-Config: Incomplete network configuration information.\n"); |
| 1426 | ic_close_devs(); |
| 1427 | return -1; |
| 1428 | #endif /* IPCONFIG_DYNAMIC */ |
| 1429 | } else { |
| 1430 | /* Device selected manually or only one device -> use it */ |
| 1431 | ic_dev = ic_first_dev->dev; |
| 1432 | } |
| 1433 | |
| 1434 | addr = root_nfs_parse_addr(root_server_path); |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1435 | if (root_server_addr == NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | root_server_addr = addr; |
| 1437 | |
| 1438 | /* |
| 1439 | * Use defaults whereever applicable. |
| 1440 | */ |
| 1441 | if (ic_defaults() < 0) |
| 1442 | return -1; |
| 1443 | |
| 1444 | /* |
| 1445 | * Close all network devices except the device we've |
| 1446 | * autoconfigured and set up routes. |
| 1447 | */ |
| 1448 | ic_close_devs(); |
| 1449 | if (ic_setup_if() < 0 || ic_setup_routes() < 0) |
| 1450 | return -1; |
| 1451 | |
| 1452 | /* |
| 1453 | * Record which protocol was actually used. |
| 1454 | */ |
| 1455 | #ifdef IPCONFIG_DYNAMIC |
| 1456 | ic_proto_used = ic_got_reply | (ic_proto_enabled & IC_USE_DHCP); |
| 1457 | #endif |
| 1458 | |
| 1459 | #ifndef IPCONFIG_SILENT |
| 1460 | /* |
| 1461 | * Clue in the operator. |
| 1462 | */ |
| 1463 | printk("IP-Config: Complete:"); |
Uwe Kleine-Koenig | 9c00409 | 2008-02-17 22:28:32 -0800 | [diff] [blame] | 1464 | printk("\n device=%s", ic_dev->name); |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 1465 | printk(", addr=%pI4", &ic_myaddr); |
| 1466 | printk(", mask=%pI4", &ic_netmask); |
| 1467 | printk(", gw=%pI4", &ic_gateway); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | printk(",\n host=%s, domain=%s, nis-domain=%s", |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 1469 | utsname()->nodename, ic_domain, utsname()->domainname); |
Harvey Harrison | 673d57e | 2008-10-31 00:53:57 -0700 | [diff] [blame] | 1470 | printk(",\n bootserver=%pI4", &ic_servaddr); |
| 1471 | printk(", rootserver=%pI4", &root_server_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | printk(", rootpath=%s", root_server_path); |
Chris Friesen | 9643f45 | 2009-05-19 15:31:50 -0700 | [diff] [blame] | 1473 | if (ic_dev_mtu) |
| 1474 | printk(", mtu=%d", ic_dev_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | printk("\n"); |
| 1476 | #endif /* !SILENT */ |
| 1477 | |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
| 1481 | late_initcall(ip_auto_config); |
| 1482 | |
| 1483 | |
| 1484 | /* |
| 1485 | * Decode any IP configuration options in the "ip=" or "nfsaddrs=" kernel |
J. Bruce Fields | dc7a081 | 2009-10-27 14:41:35 -0400 | [diff] [blame] | 1486 | * command line parameter. See Documentation/filesystems/nfs/nfsroot.txt. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | */ |
| 1488 | static int __init ic_proto_name(char *name) |
| 1489 | { |
| 1490 | if (!strcmp(name, "on") || !strcmp(name, "any")) { |
| 1491 | return 1; |
| 1492 | } |
Simon Horman | a6c05c3 | 2007-12-25 20:54:42 -0800 | [diff] [blame] | 1493 | if (!strcmp(name, "off") || !strcmp(name, "none")) { |
Amos Waterland | 92ffb85 | 2008-01-05 23:23:06 -0800 | [diff] [blame] | 1494 | return 0; |
Simon Horman | a6c05c3 | 2007-12-25 20:54:42 -0800 | [diff] [blame] | 1495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | #ifdef CONFIG_IP_PNP_DHCP |
| 1497 | else if (!strcmp(name, "dhcp")) { |
| 1498 | ic_proto_enabled &= ~IC_RARP; |
| 1499 | return 1; |
| 1500 | } |
| 1501 | #endif |
| 1502 | #ifdef CONFIG_IP_PNP_BOOTP |
| 1503 | else if (!strcmp(name, "bootp")) { |
| 1504 | ic_proto_enabled &= ~(IC_RARP | IC_USE_DHCP); |
| 1505 | return 1; |
| 1506 | } |
| 1507 | #endif |
| 1508 | #ifdef CONFIG_IP_PNP_RARP |
| 1509 | else if (!strcmp(name, "rarp")) { |
| 1510 | ic_proto_enabled &= ~(IC_BOOTP | IC_USE_DHCP); |
| 1511 | return 1; |
| 1512 | } |
| 1513 | #endif |
| 1514 | #ifdef IPCONFIG_DYNAMIC |
| 1515 | else if (!strcmp(name, "both")) { |
| 1516 | ic_proto_enabled &= ~IC_USE_DHCP; /* backward compat :-( */ |
| 1517 | return 1; |
| 1518 | } |
| 1519 | #endif |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
| 1523 | static int __init ip_auto_config_setup(char *addrs) |
| 1524 | { |
| 1525 | char *cp, *ip, *dp; |
| 1526 | int num = 0; |
| 1527 | |
| 1528 | ic_set_manually = 1; |
Simon Horman | 9cecd07 | 2007-12-27 21:19:10 -0800 | [diff] [blame] | 1529 | ic_enable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | |
Amos Waterland | 92ffb85 | 2008-01-05 23:23:06 -0800 | [diff] [blame] | 1531 | /* |
| 1532 | * If any dhcp, bootp etc options are set, leave autoconfig on |
| 1533 | * and skip the below static IP processing. |
| 1534 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | if (ic_proto_name(addrs)) |
| 1536 | return 1; |
| 1537 | |
Amos Waterland | 92ffb85 | 2008-01-05 23:23:06 -0800 | [diff] [blame] | 1538 | /* If no static IP is given, turn off autoconfig and bail. */ |
| 1539 | if (*addrs == 0 || |
| 1540 | strcmp(addrs, "off") == 0 || |
| 1541 | strcmp(addrs, "none") == 0) { |
| 1542 | ic_enable = 0; |
| 1543 | return 1; |
| 1544 | } |
| 1545 | |
| 1546 | /* Parse string for static IP assignment. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | ip = addrs; |
| 1548 | while (ip && *ip) { |
| 1549 | if ((cp = strchr(ip, ':'))) |
| 1550 | *cp++ = '\0'; |
| 1551 | if (strlen(ip) > 0) { |
| 1552 | DBG(("IP-Config: Parameter #%d: `%s'\n", num, ip)); |
| 1553 | switch (num) { |
| 1554 | case 0: |
Al Viro | e6f1ceb | 2008-03-17 22:44:53 -0700 | [diff] [blame] | 1555 | if ((ic_myaddr = in_aton(ip)) == ANY) |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1556 | ic_myaddr = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | break; |
| 1558 | case 1: |
Al Viro | e6f1ceb | 2008-03-17 22:44:53 -0700 | [diff] [blame] | 1559 | if ((ic_servaddr = in_aton(ip)) == ANY) |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1560 | ic_servaddr = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | break; |
| 1562 | case 2: |
Al Viro | e6f1ceb | 2008-03-17 22:44:53 -0700 | [diff] [blame] | 1563 | if ((ic_gateway = in_aton(ip)) == ANY) |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1564 | ic_gateway = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | break; |
| 1566 | case 3: |
Al Viro | e6f1ceb | 2008-03-17 22:44:53 -0700 | [diff] [blame] | 1567 | if ((ic_netmask = in_aton(ip)) == ANY) |
Al Viro | 5a874db | 2006-11-08 00:19:38 -0800 | [diff] [blame] | 1568 | ic_netmask = NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | break; |
| 1570 | case 4: |
| 1571 | if ((dp = strchr(ip, '.'))) { |
| 1572 | *dp++ = '\0'; |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 1573 | strlcpy(utsname()->domainname, dp, |
| 1574 | sizeof(utsname()->domainname)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 1576 | strlcpy(utsname()->nodename, ip, |
| 1577 | sizeof(utsname()->nodename)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | ic_host_name_set = 1; |
| 1579 | break; |
| 1580 | case 5: |
| 1581 | strlcpy(user_dev_name, ip, sizeof(user_dev_name)); |
| 1582 | break; |
| 1583 | case 6: |
Amos Waterland | 92ffb85 | 2008-01-05 23:23:06 -0800 | [diff] [blame] | 1584 | if (ic_proto_name(ip) == 0 && |
| 1585 | ic_myaddr == NONE) { |
| 1586 | ic_enable = 0; |
| 1587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | ip = cp; |
| 1592 | num++; |
| 1593 | } |
| 1594 | |
| 1595 | return 1; |
| 1596 | } |
| 1597 | |
| 1598 | static int __init nfsaddrs_config_setup(char *addrs) |
| 1599 | { |
| 1600 | return ip_auto_config_setup(addrs); |
| 1601 | } |
| 1602 | |
Rainer Jochem | 62013db | 2007-11-14 02:18:39 -0800 | [diff] [blame] | 1603 | static int __init vendor_class_identifier_setup(char *addrs) |
| 1604 | { |
| 1605 | if (strlcpy(vendor_class_identifier, addrs, |
| 1606 | sizeof(vendor_class_identifier)) |
| 1607 | >= sizeof(vendor_class_identifier)) |
| 1608 | printk(KERN_WARNING "DHCP: vendorclass too long, truncated to \"%s\"", |
| 1609 | vendor_class_identifier); |
| 1610 | return 1; |
| 1611 | } |
| 1612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | __setup("ip=", ip_auto_config_setup); |
| 1614 | __setup("nfsaddrs=", nfsaddrs_config_setup); |
Rainer Jochem | 62013db | 2007-11-14 02:18:39 -0800 | [diff] [blame] | 1615 | __setup("dhcpclass=", vendor_class_identifier_setup); |