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