Lines Matching +full:config +full:- +full:complete +full:- +full:timeout +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0
3 * Automatic Configuration of IP -- use DHCP, BOOTP, RARP, or
4 * user-supplied information to configure own IP address and routes.
6 * Copyright (C) 1996-1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
12 * of misusing the IP layer. num_bugs_causing_wrong_arp_replies--;
13 * -- MJ, December 1998
17 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 08/11/1999
21 * -- Chip Salzenberg <chip@valinux.com>, May 2000
23 * Ported DHCP support from 2.2.16 to 2.4.0-test4
24 * -- Eric Biederman <ebiederman@lnxi.com>, 30 Aug 2000
27 * -- Eric Biederman <ebiederman@lnxi.com>, 22 April Aug 2001
30 * -- Josef Siemes <jsiemes@web.de>, Aug 2002
33 * -- Chris Novakovic <chris@chrisn.me.uk>, April 2018
88 /* Define the timeout for waiting for a DHCP/BOOTP/RARP reply */
91 #define CONF_BASE_TIMEOUT (HZ*2) /* Initial timeout: 2 seconds */
93 #define CONF_TIMEOUT_MULT *7/4 /* Rate of timeout growth */
94 #define CONF_TIMEOUT_MAX (HZ*30) /* Maximum allowed timeout */
96 - '3' from resolv.h */
102 /* Wait for carrier timeout default in seconds */
115 static int ic_enable __initdata; /* IP config enabled? */
130 static int ic_host_name_set __initdata; /* Host name set by us? */
167 /* Name of user-selected boot device */
202 if (dev->flags & IFF_LOOPBACK) in ic_is_init_dev()
204 return user_dev_name[0] ? !strcmp(dev->name, user_dev_name) : in ic_is_init_dev()
205 (!(dev->flags & IFF_LOOPBACK) && in ic_is_init_dev()
206 (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) && in ic_is_init_dev()
207 strncmp(dev->name, "dummy", 5)); in ic_is_init_dev()
222 if (!(dev->flags & IFF_LOOPBACK)) in ic_open_devs()
224 if (dev_change_flags(dev, dev->flags | IFF_UP, NULL) < 0) in ic_open_devs()
225 pr_err("IP-Config: Failed to open %s\n", dev->name); in ic_open_devs()
231 if (dev->mtu >= 364) in ic_open_devs()
235 dev->name, dev->mtu); in ic_open_devs()
236 if (!(dev->flags & IFF_NOARP)) in ic_open_devs()
241 oflags = dev->flags; in ic_open_devs()
243 pr_err("IP-Config: Failed to open %s\n", in ic_open_devs()
244 dev->name); in ic_open_devs()
249 return -ENOMEM; in ic_open_devs()
251 d->dev = dev; in ic_open_devs()
253 last = &d->next; in ic_open_devs()
254 d->flags = oflags; in ic_open_devs()
255 d->able = able; in ic_open_devs()
257 get_random_bytes(&d->xid, sizeof(__be32)); in ic_open_devs()
259 d->xid = 0; in ic_open_devs()
261 pr_debug("IP-Config: %s UP (able=%d, xid=%08x)\n", in ic_open_devs()
262 dev->name, able, d->xid); in ic_open_devs()
266 * the rtnl_lock at init. The carrier wait-loop must therefore run in ic_open_devs()
295 elapsed = jiffies_to_msecs(jiffies - start); in ic_open_devs()
296 wait = (carrier_timeout * 1000 - elapsed + 500) / 1000; in ic_open_devs()
306 pr_err("IP-Config: Device `%s' not found\n", in ic_open_devs()
309 pr_err("IP-Config: No network devices available\n"); in ic_open_devs()
310 return -ENODEV; in ic_open_devs()
320 struct net_device *selected_dev = ic_dev ? ic_dev->dev : NULL; in ic_close_devs()
331 next = d->next; in ic_close_devs()
332 dev = d->dev; in ic_close_devs()
343 pr_debug("IP-Config: Downing %s\n", dev->name); in ic_close_devs()
344 dev_change_flags(dev, d->flags, NULL); in ic_close_devs()
358 sin->sin_family = AF_INET; in set_sockaddr()
359 sin->sin_addr.s_addr = addr; in set_sockaddr()
360 sin->sin_port = port; in set_sockaddr()
374 strcpy(ir.ifr_ifrn.ifrn_name, ic_dev->dev->name); in ic_setup_if()
377 pr_err("IP-Config: Unable to set interface address (%d)\n", in ic_setup_if()
379 return -1; in ic_setup_if()
383 pr_err("IP-Config: Unable to set interface netmask (%d)\n", in ic_setup_if()
385 return -1; in ic_setup_if()
389 pr_err("IP-Config: Unable to set interface broadcast address (%d)\n", in ic_setup_if()
391 return -1; in ic_setup_if()
393 /* Handle the case where we need non-standard MTU on the boot link (a network in ic_setup_if()
399 if ((err = dev_set_mtu(ic_dev->dev, ic_dev_mtu)) < 0) in ic_setup_if()
400 pr_err("IP-Config: Unable to set interface mtu to %d (%d)\n", in ic_setup_if()
417 pr_err("IP-Config: Gateway not on directly connected network\n"); in ic_setup_routes()
418 return -1; in ic_setup_routes()
425 pr_err("IP-Config: Cannot add default route (%d)\n", in ic_setup_routes()
427 return -1; in ic_setup_routes()
446 sprintf(init_utsname()->nodename, "%pI4", &ic_myaddr); in ic_defaults()
461 pr_err("IP-Config: Unable to guess netmask for address %pI4\n", in ic_defaults()
463 return -1; in ic_defaults()
465 pr_notice("IP-Config: Guessing netmask %pI4\n", in ic_defaults()
523 if (rarp->ar_hln != dev->addr_len || dev->type != ntohs(rarp->ar_hrd)) in ic_rarp_recv()
527 if (rarp->ar_op != htons(ARPOP_RREPLY)) in ic_rarp_recv()
531 if (rarp->ar_pro != htons(ETH_P_IP)) in ic_rarp_recv()
550 while (d && d->dev != dev) in ic_rarp_recv()
551 d = d->next; in ic_rarp_recv()
555 /* Extract variable-width fields */ in ic_rarp_recv()
556 rarp_ptr += dev->addr_len; in ic_rarp_recv()
560 rarp_ptr += dev->addr_len; in ic_rarp_recv()
563 /* Discard packets which are not meant for us. */ in ic_rarp_recv()
564 if (memcmp(tha, dev->dev_addr, dev->addr_len)) in ic_rarp_recv()
595 struct net_device *dev = d->dev; in ic_rarp_send_if()
597 dev->dev_addr, dev->dev_addr); in ic_rarp_send_if()
687 pr_debug("DHCP: Sending message type %d (%s)\n", mt, d->dev->name); in ic_dhcp_init_options()
728 *e++ = 12; /* host-name */ in ic_dhcp_init_options()
729 len = strlen(utsname()->nodename); in ic_dhcp_init_options()
731 memcpy(e, utsname()->nodename, len); in ic_dhcp_init_options()
737 *e++ = 60; /* Class-identifier */ in ic_dhcp_init_options()
747 if (len >= 1 && len < 312 - (e - options) - 1) { in ic_dhcp_init_options()
799 /* Re-initialise all name servers and NTP servers to NONE, in case any in ic_bootp_init()
825 struct net_device *dev = d->dev; in ic_bootp_send_if()
830 int tlen = dev->needed_tailroom; in ic_bootp_send_if()
843 h->version = 4; in ic_bootp_send_if()
844 h->ihl = 5; in ic_bootp_send_if()
845 h->tot_len = htons(sizeof(struct bootp_pkt)); in ic_bootp_send_if()
846 h->frag_off = htons(IP_DF); in ic_bootp_send_if()
847 h->ttl = 64; in ic_bootp_send_if()
848 h->protocol = IPPROTO_UDP; in ic_bootp_send_if()
849 h->daddr = htonl(INADDR_BROADCAST); in ic_bootp_send_if()
850 h->check = ip_fast_csum((unsigned char *) h, h->ihl); in ic_bootp_send_if()
853 b->udph.source = htons(68); in ic_bootp_send_if()
854 b->udph.dest = htons(67); in ic_bootp_send_if()
855 b->udph.len = htons(sizeof(struct bootp_pkt) - sizeof(struct iphdr)); in ic_bootp_send_if()
856 /* UDP checksum not calculated -- explicitly allowed in BOOTP RFC */ in ic_bootp_send_if()
859 b->op = BOOTP_REQUEST; in ic_bootp_send_if()
860 if (dev->type < 256) /* check for false types */ in ic_bootp_send_if()
861 b->htype = dev->type; in ic_bootp_send_if()
862 else if (dev->type == ARPHRD_FDDI) in ic_bootp_send_if()
863 b->htype = ARPHRD_ETHER; in ic_bootp_send_if()
865 pr_warn("Unknown ARP type 0x%04x for device %s\n", dev->type, in ic_bootp_send_if()
866 dev->name); in ic_bootp_send_if()
867 b->htype = dev->type; /* can cause undefined behavior */ in ic_bootp_send_if()
871 b->hlen = dev->addr_len; in ic_bootp_send_if()
872 memcpy(b->hw_addr, dev->dev_addr, dev->addr_len); in ic_bootp_send_if()
873 b->secs = htons(jiffies_diff / HZ); in ic_bootp_send_if()
874 b->xid = d->xid; in ic_bootp_send_if()
879 ic_dhcp_init_options(b->exten, d); in ic_bootp_send_if()
882 ic_bootp_init_ext(b->exten); in ic_bootp_send_if()
885 skb->dev = dev; in ic_bootp_send_if()
886 skb->protocol = htons(ETH_P_IP); in ic_bootp_send_if()
887 if (dev_hard_header(skb, dev, ntohs(skb->protocol), in ic_bootp_send_if()
888 dev->broadcast, dev->dev_addr, skb->len) < 0) { in ic_bootp_send_if()
900 * Copy BOOTP-supplied string
906 if (len > max-1) in ic_bootp_string()
907 len = max-1; in ic_bootp_string()
951 ic_bootp_string(utsname()->nodename, ext+1, *ext, in ic_do_bootp_ext()
970 ic_bootp_string(utsname()->domainname, ext+1, *ext, in ic_do_bootp_ext()
1000 if (skb->pkt_type == PACKET_OTHERHOST) in ic_bootp_recv()
1013 h = &b->iph; in ic_bootp_recv()
1015 if (h->ihl != 5 || h->version != 4 || h->protocol != IPPROTO_UDP) in ic_bootp_recv()
1024 if (skb->len < ntohs(h->tot_len)) in ic_bootp_recv()
1027 if (ip_fast_csum((char *) h, h->ihl)) in ic_bootp_recv()
1030 if (b->udph.source != htons(67) || b->udph.dest != htons(68)) in ic_bootp_recv()
1033 if (ntohs(h->tot_len) < ntohs(b->udph.len) + sizeof(struct iphdr)) in ic_bootp_recv()
1036 len = ntohs(b->udph.len) - sizeof(struct udphdr); in ic_bootp_recv()
1037 ext_len = len - (sizeof(*b) - in ic_bootp_recv()
1038 sizeof(struct iphdr) - in ic_bootp_recv()
1039 sizeof(struct udphdr) - in ic_bootp_recv()
1040 sizeof(b->exten)); in ic_bootp_recv()
1045 if (!pskb_may_pull(skb, skb->len)) in ic_bootp_recv()
1049 h = &b->iph; in ic_bootp_recv()
1060 while (d && d->dev != dev) in ic_bootp_recv()
1061 d = d->next; in ic_bootp_recv()
1066 if (b->op != BOOTP_REPLY || in ic_bootp_recv()
1067 b->xid != d->xid) { in ic_bootp_recv()
1068 net_err_ratelimited("DHCP/BOOTP: Reply not for us on %s, op[%x] xid[%x]\n", in ic_bootp_recv()
1069 d->dev->name, b->op, b->xid); in ic_bootp_recv()
1075 !memcmp(b->exten, ic_bootp_cookie, 4)) { /* Check magic cookie */ in ic_bootp_recv()
1076 u8 *end = (u8 *) b + ntohs(b->iph.tot_len); in ic_bootp_recv()
1084 ext = &b->exten[4]; in ic_bootp_recv()
1104 pr_debug("DHCP: Got message type %d (%s)\n", mt, d->dev->name); in ic_bootp_recv()
1115 ic_myaddr = b->your_ip; in ic_bootp_recv()
1118 &ic_myaddr, &b->iph.saddr); in ic_bootp_recv()
1124 (b->server_ip != server_id)) in ic_bootp_recv()
1125 b->server_ip = ic_servaddr; in ic_bootp_recv()
1129 if (memcmp(dev->dev_addr, b->hw_addr, dev->addr_len) != 0) in ic_bootp_recv()
1147 ext = &b->exten[4]; in ic_bootp_recv()
1160 ic_myaddr = b->your_ip; in ic_bootp_recv()
1161 ic_servaddr = b->server_ip; in ic_bootp_recv()
1162 ic_addrservaddr = b->iph.saddr; in ic_bootp_recv()
1163 if (ic_gateway == NONE && b->relay_ip) in ic_bootp_recv()
1164 ic_gateway = b->relay_ip; in ic_bootp_recv()
1187 * Dynamic IP configuration -- DHCP, BOOTP, RARP.
1196 unsigned long start_jiffies, timeout, jiff; in ic_dynamic() local
1206 pr_err("IP-Config: Incomplete network configuration information\n"); in ic_dynamic()
1207 return -1; in ic_dynamic()
1221 return -1; in ic_dynamic()
1241 * applies.. - AC] in ic_dynamic()
1252 get_random_bytes(&timeout, sizeof(timeout)); in ic_dynamic()
1253 timeout = CONF_BASE_TIMEOUT + (timeout % (unsigned int) CONF_TIMEOUT_RANDOM); in ic_dynamic()
1256 if (do_bootp && (d->able & IC_BOOTP)) in ic_dynamic()
1257 ic_bootp_send_if(d, jiffies - start_jiffies); in ic_dynamic()
1260 if (do_rarp && (d->able & IC_RARP)) in ic_dynamic()
1264 if (!d->next) { in ic_dynamic()
1265 jiff = jiffies + timeout; in ic_dynamic()
1287 if ((d = d->next)) in ic_dynamic()
1290 if (! --retries) { in ic_dynamic()
1297 timeout = timeout CONF_TIMEOUT_MULT; in ic_dynamic()
1298 if (timeout > CONF_TIMEOUT_MAX) in ic_dynamic()
1299 timeout = CONF_TIMEOUT_MAX; in ic_dynamic()
1315 return -1; in ic_dynamic()
1318 pr_info("IP-Config: Got %s answer from %pI4, my address is %pI4\n", in ic_dynamic()
1363 return -ENOMEM; in ipconfig_proc_net_init()
1376 return -ENOMEM; in ipconfig_proc_net_create()
1380 return -ENOMEM; in ipconfig_proc_net_create()
1385 return -ENOMEM; in ipconfig_proc_net_create()
1419 if (cp == cq || cp - cq > 3) in root_nfs_parse_addr()
1469 return -ENODEV; in wait_for_devices()
1504 pr_debug("IP-Config: Entered.\n"); in ip_auto_config()
1522 * If the config information is insufficient (e.g., our IP address or in ip_auto_config()
1533 ic_first_dev->next) { in ip_auto_config()
1546 * Also, if the root will be NFS-mounted, we in ip_auto_config()
1550 * -- Chip in ip_auto_config()
1554 pr_err("IP-Config: Retrying forever (NFS root)...\n"); in ip_auto_config()
1560 pr_err("IP-Config: Retrying forever (CIFS root)...\n"); in ip_auto_config()
1565 if (--retries) { in ip_auto_config()
1566 pr_err("IP-Config: Reopening network devices...\n"); in ip_auto_config()
1571 pr_err("IP-Config: Auto-configuration of network failed\n"); in ip_auto_config()
1572 return -1; in ip_auto_config()
1575 pr_err("IP-Config: Incomplete network configuration information\n"); in ip_auto_config()
1577 return -1; in ip_auto_config()
1580 /* Device selected manually or only one device -> use it */ in ip_auto_config()
1592 return -1; in ip_auto_config()
1605 pr_info("IP-Config: Complete:\n"); in ip_auto_config()
1608 ic_dev->dev->name, ic_dev->dev->addr_len, ic_dev->dev->dev_addr, in ip_auto_config()
1610 pr_info(" host=%s, domain=%s, nis-domain=%s\n", in ip_auto_config()
1611 utsname()->nodename, ic_domain, utsname()->domainname); in ip_auto_config()
1653 err = -1; in ip_auto_config()
1667 * command line parameter. See Documentation/admin-guide/nfs/nfsroot.rst.
1713 ic_proto_enabled &= ~IC_USE_DHCP; /* backward compat :-( */ in ic_proto_name()
1753 pr_debug("IP-Config: Parameter #%d: `%s'\n", num, ip); in ip_auto_config_setup()
1774 strscpy(utsname()->domainname, dp, in ip_auto_config_setup()
1775 sizeof(utsname()->domainname)); in ip_auto_config_setup()
1777 strscpy(utsname()->nodename, ip, in ip_auto_config_setup()
1778 sizeof(utsname()->nodename)); in ip_auto_config_setup()