linux/net/ipv4/ipconfig.c

// SPDX-License-Identifier: GPL-2.0
/*
 *  Automatic Configuration of IP -- use DHCP, BOOTP, RARP, or
 *  user-supplied information to configure own IP address and routes.
 *
 *  Copyright (C) 1996-1998 Martin Mares <[email protected]>
 *
 *  Derived from network configuration code in fs/nfs/nfsroot.c,
 *  originally Copyright (C) 1995, 1996 Gero Kuhlmann and me.
 *
 *  BOOTP rewritten to construct and analyse packets itself instead
 *  of misusing the IP layer. num_bugs_causing_wrong_arp_replies--;
 *					     -- MJ, December 1998
 *
 *  Fixed ip_auto_config_setup calling at startup in the new "Linker Magic"
 *  initialization scheme.
 *	- Arnaldo Carvalho de Melo <[email protected]>, 08/11/1999
 *
 *  DHCP support added.  To users this looks like a whole separate
 *  protocol, but we know it's just a bag on the side of BOOTP.
 *		-- Chip Salzenberg <[email protected]>, May 2000
 *
 *  Ported DHCP support from 2.2.16 to 2.4.0-test4
 *              -- Eric Biederman <[email protected]>, 30 Aug 2000
 *
 *  Merged changes from 2.2.19 into 2.4.3
 *              -- Eric Biederman <[email protected]>, 22 April Aug 2001
 *
 *  Multiple Nameservers in /proc/net/pnp
 *              --  Josef Siemes <[email protected]>, Aug 2002
 *
 *  NTP servers in /proc/net/ipconfig/ntp_servers
 *              --  Chris Novakovic <[email protected]>, April 2018
 */

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

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

#if defined(CONFIG_IP_PNP_DHCP)
#define IPCONFIG_DHCP
#endif
#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_DHCP)
#define IPCONFIG_BOOTP
#endif
#if defined(CONFIG_IP_PNP_RARP)
#define IPCONFIG_RARP
#endif
#if defined(IPCONFIG_BOOTP) || defined(IPCONFIG_RARP)
#define IPCONFIG_DYNAMIC
#endif

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

/* Define the timeout for waiting for a DHCP/BOOTP/RARP reply */
#define CONF_OPEN_RETRIES
#define CONF_SEND_RETRIES
#define CONF_BASE_TIMEOUT
#define CONF_TIMEOUT_RANDOM
#define CONF_TIMEOUT_MULT
#define CONF_TIMEOUT_MAX
#define CONF_NAMESERVERS_MAX
#define CONF_NTP_SERVERS_MAX

#define NONE
#define ANY

/* Wait for carrier timeout default in seconds */
static unsigned int carrier_timeout =;

/*
 * Public IP configuration
 */

/* This is used by platforms which might be able to set the ipconfig
 * variables using firmware environment vars.  If this is set, it will
 * ignore such firmware variables.
 */
int ic_set_manually __initdata =;		/* IPconfig parameters set manually */

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

/* Protocol choice */
int ic_proto_enabled __initdata =
#endif
			;

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

__be32 ic_myaddr =;		/* My IP address */
static __be32 ic_netmask =;	/* Netmask for local subnet */
__be32 ic_gateway =;	/* Gateway IP address */

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

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

__be32 root_server_addr =;	/* Address of NFS server */
u8 root_server_path[256] =;	/* Path to mount as root */

/* vendor class identifier */
static char vendor_class_identifier[253] __initdata;

#if defined(CONFIG_IP_PNP_DHCP)
static char dhcp_client_identifier[253] __initdata;
#endif

/* Persistent data: */

#ifdef IPCONFIG_DYNAMIC
static int ic_proto_used;			/* Protocol used, if any */
#else
#define ic_proto_used
#endif
static __be32 ic_nameservers[CONF_NAMESERVERS_MAX]; /* DNS Server IP addresses */
static __be32 ic_ntp_servers[CONF_NTP_SERVERS_MAX]; /* NTP server IP addresses */
static u8 ic_domain[64];		/* DNS (not NIS) domain name */

/*
 * Private state.
 */

/* Name of user-selected boot device */
static char user_dev_name[IFNAMSIZ] __initdata =;

/* Protocols supported by available interfaces */
static int ic_proto_have_if __initdata;

/* MTU for boot device */
static int ic_dev_mtu __initdata;

#ifdef IPCONFIG_DYNAMIC
static DEFINE_SPINLOCK(ic_recv_lock);
static volatile int ic_got_reply __initdata;    /* Proto(s) that replied */
#endif
#ifdef IPCONFIG_DHCP
static int ic_dhcp_msgtype __initdata;	/* DHCP msg type received */
#endif


/*
 *	Network devices
 */

struct ic_device {};

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

static bool __init ic_is_init_dev(struct net_device *dev)
{}

static int __init ic_open_devs(void)
{}

/* Close all network interfaces except the one we've autoconfigured, and its
 * lowers, in case it's a stacked virtual interface.
 */
static void __init ic_close_devs(void)
{}

/*
 *	Interface to various network functions.
 */

static inline void
set_sockaddr(struct sockaddr_in *sin, __be32 addr, __be16 port)
{}

/*
 *	Set up interface addresses and routes.
 */

static int __init ic_setup_if(void)
{}

static int __init ic_setup_routes(void)
{}

/*
 *	Fill in default values for all missing parameters.
 */

static int __init ic_defaults(void)
{}

/*
 *	RARP support.
 */

#ifdef IPCONFIG_RARP

static int ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev);

static struct packet_type rarp_packet_type __initdata =;

static inline void __init ic_rarp_init(void)
{}

static inline void __init ic_rarp_cleanup(void)
{}

/*
 *  Process received RARP packet.
 */
static int __init
ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
{}


/*
 *  Send RARP request packet over a single interface.
 */
static void __init ic_rarp_send_if(struct ic_device *d)
{}
#endif

/*
 *  Predefine Nameservers
 */
static inline void __init ic_nameservers_predef(void)
{}

/* Predefine NTP servers */
static inline void __init ic_ntp_servers_predef(void)
{}

/*
 *	DHCP/BOOTP support.
 */

#ifdef IPCONFIG_BOOTP

struct bootp_pkt {};

/* packet ops */
#define BOOTP_REQUEST
#define BOOTP_REPLY

/* DHCP message types */
#define DHCPDISCOVER
#define DHCPOFFER
#define DHCPREQUEST
#define DHCPDECLINE
#define DHCPACK
#define DHCPNAK
#define DHCPRELEASE
#define DHCPINFORM

static int ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev);

static struct packet_type bootp_packet_type __initdata =;

/* DHCPACK can overwrite DNS if fallback was set upon first BOOTP reply */
static int ic_nameservers_fallback __initdata;

/*
 *  Initialize DHCP/BOOTP extension fields in the request.
 */

static const u8 ic_bootp_cookie[4] =;

#ifdef IPCONFIG_DHCP

static void __init
ic_dhcp_init_options(u8 *options, struct ic_device *d)
{}

#endif /* IPCONFIG_DHCP */

static void __init ic_bootp_init_ext(u8 *e)
{}


/*
 *  Initialize the DHCP/BOOTP mechanism.
 */
static inline void __init ic_bootp_init(void)
{}


/*
 *  DHCP/BOOTP cleanup.
 */
static inline void __init ic_bootp_cleanup(void)
{}


/*
 *  Send DHCP/BOOTP request to single interface.
 */
static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_diff)
{}


/*
 *  Copy BOOTP-supplied string
 */
static int __init ic_bootp_string(char *dest, char *src, int len, int max)
{}


/*
 *  Process BOOTP extensions.
 */
static void __init ic_do_bootp_ext(u8 *ext)
{}


/*
 *  Receive BOOTP reply.
 */
static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
{}


#endif


/*
 *	Dynamic IP configuration -- DHCP, BOOTP, RARP.
 */

#ifdef IPCONFIG_DYNAMIC

static int __init ic_dynamic(void)
{}

#endif /* IPCONFIG_DYNAMIC */

#ifdef CONFIG_PROC_FS
/* proc_dir_entry for /proc/net/ipconfig */
static struct proc_dir_entry *ipconfig_dir;

/* Name servers: */
static int pnp_seq_show(struct seq_file *seq, void *v)
{}

/* Create the /proc/net/ipconfig directory */
static int __init ipconfig_proc_net_init(void)
{}

/* Create a new file under /proc/net/ipconfig */
static int ipconfig_proc_net_create(const char *name,
				    const struct proc_ops *proc_ops)
{}

/* Write NTP server IP addresses to /proc/net/ipconfig/ntp_servers */
static int ntp_servers_show(struct seq_file *seq, void *v)
{}
DEFINE_PROC_SHOW_ATTRIBUTE();
#endif /* CONFIG_PROC_FS */

/*
 *  Extract IP address from the parameter string if needed. Note that we
 *  need to have root_server_addr set _before_ IPConfig gets called as it
 *  can override it.
 */
__be32 __init root_nfs_parse_addr(char *name)
{}

#define DEVICE_WAIT_MAX

static int __init wait_for_devices(void)
{}

/*
 *	IP Autoconfig dispatcher.
 */

static int __init ip_auto_config(void)
{}

late_initcall(ip_auto_config);


/*
 *  Decode any IP configuration options in the "ip=" or "nfsaddrs=" kernel
 *  command line parameter.  See Documentation/admin-guide/nfs/nfsroot.rst.
 */
static int __init ic_proto_name(char *name)
{}

static int __init ip_auto_config_setup(char *addrs)
{}
__setup();

static int __init nfsaddrs_config_setup(char *addrs)
{}
__setup();

static int __init vendor_class_identifier_setup(char *addrs)
{}
__setup();

static int __init set_carrier_timeout(char *str)
{}
__setup();