Commit bc0fbc66 authored by David S. Miller's avatar David S. Miller

Merge branch 'ipconfig-NTP-server-support-bug-fixes-documentation-improvements'

Chris Novakovic says:

====================
ipconfig: NTP server support, bug fixes, documentation improvements

This series (against net-next) makes various improvements to ipconfig:

 - Patch #1 correctly documents the behaviour of parameter 4 in the
   "ip=" and "nfsaddrs=" command line parameter.
 - Patch #2 tidies up the printk()s for reporting configured name
   servers.
 - Patch #3 fixes a bug in autoconfiguration via BOOTP whereby the IP
   addresses of IEN-116 name servers are requested from the BOOTP
   server, rather than those of DNS name servers.
 - Patch #4 requests the number of DNS servers specified by
   CONF_NAMESERVERS_MAX when autoconfiguring via BOOTP, rather than
   hardcoding it to 2.
 - Patch #5 fully documents the contents and format of /proc/net/pnp in
   Documentation/filesystems/nfs/nfsroot.txt.
 - Patch #6 fixes a bug whereby bogus information is written to
   /proc/net/pnp when ipconfig is not used.
 - Patch #7 creates a new procfs directory for ipconfig-related
   configuration reports at /proc/net/ipconfig.
 - Patch #8 allows for NTP servers to be configured (manually on the
   kernel command line or automatically via DHCP), enabling systems with
   an NFS root filesystem to synchronise their clock before mounting
   their root filesystem. NTP server IP addresses are written to
   /proc/net/ipconfig/ntp_servers.

Changes from v1:

 - David requested that a new directory /proc/net/ipconfig be created to
   contain ipconfig-related configuration reports, which is implemented
   in the new patch #7. NTP server IPs are now written to this directory
   instead of /proc/net/ntp in the new patch #8.
 - Cong and David both requested that the modification to CREDITS be
   dropped. This patch has been removed from the series.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5cb5ce33 c04d2cb2
...@@ -5,6 +5,7 @@ Written 1996 by Gero Kuhlmann <gero@gkminix.han.de> ...@@ -5,6 +5,7 @@ Written 1996 by Gero Kuhlmann <gero@gkminix.han.de>
Updated 1997 by Martin Mares <mj@atrey.karlin.mff.cuni.cz> Updated 1997 by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
Updated 2006 by Nico Schottelius <nico-kernel-nfsroot@schottelius.org> Updated 2006 by Nico Schottelius <nico-kernel-nfsroot@schottelius.org>
Updated 2006 by Horms <horms@verge.net.au> Updated 2006 by Horms <horms@verge.net.au>
Updated 2018 by Chris Novakovic <chris@chrisn.me.uk>
...@@ -79,7 +80,7 @@ nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>] ...@@ -79,7 +80,7 @@ nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>: ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:
<dns0-ip>:<dns1-ip> <dns0-ip>:<dns1-ip>:<ntp0-ip>
This parameter tells the kernel how to configure IP addresses of devices This parameter tells the kernel how to configure IP addresses of devices
and also how to set up the IP routing table. It was originally called and also how to set up the IP routing table. It was originally called
...@@ -110,6 +111,9 @@ ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>: ...@@ -110,6 +111,9 @@ ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:
will not be triggered if it is missing and NFS root is not will not be triggered if it is missing and NFS root is not
in operation. in operation.
Value is exported to /proc/net/pnp with the prefix "bootserver "
(see below).
Default: Determined using autoconfiguration. Default: Determined using autoconfiguration.
The address of the autoconfiguration server is used. The address of the autoconfiguration server is used.
...@@ -123,10 +127,13 @@ ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>: ...@@ -123,10 +127,13 @@ ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:
Default: Determined using autoconfiguration. Default: Determined using autoconfiguration.
<hostname> Name of the client. May be supplied by autoconfiguration, <hostname> Name of the client. If a '.' character is present, anything
but its absence will not trigger autoconfiguration. before the first '.' is used as the client's hostname, and anything
If specified and DHCP is used, the user provided hostname will after it is used as its NIS domain name. May be supplied by
be carried in the DHCP request to hopefully update DNS record. autoconfiguration, but its absence will not trigger autoconfiguration.
If specified and DHCP is used, the user-provided hostname (and NIS
domain name, if present) will be carried in the DHCP request; this
may cause a DNS record to be created or updated for the client.
Default: Client IP address is used in ASCII notation. Default: Client IP address is used in ASCII notation.
...@@ -162,12 +169,55 @@ ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>: ...@@ -162,12 +169,55 @@ ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:
Default: any Default: any
<dns0-ip> IP address of first nameserver. <dns0-ip> IP address of primary nameserver.
Value gets exported by /proc/net/pnp which is often linked Value is exported to /proc/net/pnp with the prefix "nameserver "
on embedded systems by /etc/resolv.conf. (see below).
Default: None if not using autoconfiguration; determined
automatically if using autoconfiguration.
<dns1-ip> IP address of secondary nameserver.
See <dns0-ip>.
<ntp0-ip> IP address of a Network Time Protocol (NTP) server.
Value is exported to /proc/net/ipconfig/ntp_servers, but is
otherwise unused (see below).
Default: None if not using autoconfiguration; determined
automatically if using autoconfiguration.
After configuration (whether manual or automatic) is complete, two files
are created in the following format; lines are omitted if their respective
value is empty following configuration:
- /proc/net/pnp:
#PROTO: <DHCP|BOOTP|RARP|MANUAL> (depending on configuration method)
domain <dns-domain> (if autoconfigured, the DNS domain)
nameserver <dns0-ip> (primary name server IP)
nameserver <dns1-ip> (secondary name server IP)
nameserver <dns2-ip> (tertiary name server IP)
bootserver <server-ip> (NFS server IP)
- /proc/net/ipconfig/ntp_servers:
<ntp0-ip> (NTP server IP)
<ntp1-ip> (NTP server IP)
<ntp2-ip> (NTP server IP)
<dns-domain> and <dns2-ip> (in /proc/net/pnp) and <ntp1-ip> and <ntp2-ip>
(in /proc/net/ipconfig/ntp_servers) are requested during autoconfiguration;
they cannot be specified as part of the "ip=" kernel command line parameter.
Because the "domain" and "nameserver" options are recognised by DNS
resolvers, /etc/resolv.conf is often linked to /proc/net/pnp on systems
that use an NFS root filesystem.
<dns1-ip> IP address of second nameserver. Note that the kernel will not synchronise the system time with any NTP
Same as above. servers it discovers; this is the responsibility of a user space process
(e.g. an initrd/initramfs script that passes the IP addresses listed in
/proc/net/ipconfig/ntp_servers to an NTP client before mounting the real
root filesystem if it is on NFS).
nfsrootdebug nfsrootdebug
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
* *
* Multiple Nameservers in /proc/net/pnp * Multiple Nameservers in /proc/net/pnp
* -- Josef Siemes <jsiemes@web.de>, Aug 2002 * -- Josef Siemes <jsiemes@web.de>, Aug 2002
*
* NTP servers in /proc/net/ipconfig/ntp_servers
* -- Chris Novakovic <chris@chrisn.me.uk>, April 2018
*/ */
#include <linux/types.h> #include <linux/types.h>
...@@ -93,6 +96,7 @@ ...@@ -93,6 +96,7 @@
#define CONF_TIMEOUT_MAX (HZ*30) /* Maximum allowed timeout */ #define CONF_TIMEOUT_MAX (HZ*30) /* Maximum allowed timeout */
#define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers #define CONF_NAMESERVERS_MAX 3 /* Maximum number of nameservers
- '3' from resolv.h */ - '3' from resolv.h */
#define CONF_NTP_SERVERS_MAX 3 /* Maximum number of NTP servers */
#define NONE cpu_to_be32(INADDR_NONE) #define NONE cpu_to_be32(INADDR_NONE)
#define ANY cpu_to_be32(INADDR_ANY) #define ANY cpu_to_be32(INADDR_ANY)
...@@ -152,12 +156,16 @@ static int ic_proto_used; /* Protocol used, if any */ ...@@ -152,12 +156,16 @@ static int ic_proto_used; /* Protocol used, if any */
#define ic_proto_used 0 #define ic_proto_used 0
#endif #endif
static __be32 ic_nameservers[CONF_NAMESERVERS_MAX]; /* DNS Server IP addresses */ 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 */ static u8 ic_domain[64]; /* DNS (not NIS) domain name */
/* /*
* Private state. * Private state.
*/ */
/* proc_dir_entry for /proc/net/ipconfig */
static struct proc_dir_entry *ipconfig_dir;
/* Name of user-selected boot device */ /* Name of user-selected boot device */
static char user_dev_name[IFNAMSIZ] __initdata = { 0, }; static char user_dev_name[IFNAMSIZ] __initdata = { 0, };
...@@ -576,6 +584,15 @@ static inline void __init ic_nameservers_predef(void) ...@@ -576,6 +584,15 @@ static inline void __init ic_nameservers_predef(void)
ic_nameservers[i] = NONE; ic_nameservers[i] = NONE;
} }
/* Predefine NTP servers */
static inline void __init ic_ntp_servers_predef(void)
{
int i;
for (i = 0; i < CONF_NTP_SERVERS_MAX; i++)
ic_ntp_servers[i] = NONE;
}
/* /*
* DHCP/BOOTP support. * DHCP/BOOTP support.
*/ */
...@@ -671,6 +688,7 @@ ic_dhcp_init_options(u8 *options, struct ic_device *d) ...@@ -671,6 +688,7 @@ ic_dhcp_init_options(u8 *options, struct ic_device *d)
17, /* Boot path */ 17, /* Boot path */
26, /* MTU */ 26, /* MTU */
40, /* NIS domain name */ 40, /* NIS domain name */
42, /* NTP servers */
}; };
*e++ = 55; /* Parameter request list */ *e++ = 55; /* Parameter request list */
...@@ -721,9 +739,11 @@ static void __init ic_bootp_init_ext(u8 *e) ...@@ -721,9 +739,11 @@ static void __init ic_bootp_init_ext(u8 *e)
*e++ = 3; /* Default gateway request */ *e++ = 3; /* Default gateway request */
*e++ = 4; *e++ = 4;
e += 4; e += 4;
*e++ = 5; /* Name server request */ #if CONF_NAMESERVERS_MAX > 0
*e++ = 8; *e++ = 6; /* (DNS) name server request */
e += 8; *e++ = 4 * CONF_NAMESERVERS_MAX;
e += 4 * CONF_NAMESERVERS_MAX;
#endif
*e++ = 12; /* Host name request */ *e++ = 12; /* Host name request */
*e++ = 32; *e++ = 32;
e += 32; e += 32;
...@@ -748,7 +768,13 @@ static void __init ic_bootp_init_ext(u8 *e) ...@@ -748,7 +768,13 @@ static void __init ic_bootp_init_ext(u8 *e)
*/ */
static inline void __init ic_bootp_init(void) static inline void __init ic_bootp_init(void)
{ {
/* Re-initialise all name servers and NTP servers to NONE, in case any
* were set via the "ip=" or "nfsaddrs=" kernel command line parameters:
* any IP addresses specified there will already have been decoded but
* are no longer needed
*/
ic_nameservers_predef(); ic_nameservers_predef();
ic_ntp_servers_predef();
dev_add_pack(&bootp_packet_type); dev_add_pack(&bootp_packet_type);
} }
...@@ -912,6 +938,15 @@ static void __init ic_do_bootp_ext(u8 *ext) ...@@ -912,6 +938,15 @@ static void __init ic_do_bootp_ext(u8 *ext)
ic_bootp_string(utsname()->domainname, ext+1, *ext, ic_bootp_string(utsname()->domainname, ext+1, *ext,
__NEW_UTS_LEN); __NEW_UTS_LEN);
break; break;
case 42: /* NTP servers */
servers = *ext / 4;
if (servers > CONF_NTP_SERVERS_MAX)
servers = CONF_NTP_SERVERS_MAX;
for (i = 0; i < servers; i++) {
if (ic_ntp_servers[i] == NONE)
memcpy(&ic_ntp_servers[i], ext+1+4*i, 4);
}
break;
} }
} }
...@@ -1258,6 +1293,7 @@ static int __init ic_dynamic(void) ...@@ -1258,6 +1293,7 @@ static int __init ic_dynamic(void)
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
/* Name servers: */
static int pnp_seq_show(struct seq_file *seq, void *v) static int pnp_seq_show(struct seq_file *seq, void *v)
{ {
int i; int i;
...@@ -1294,6 +1330,62 @@ static const struct file_operations pnp_seq_fops = { ...@@ -1294,6 +1330,62 @@ static const struct file_operations pnp_seq_fops = {
.llseek = seq_lseek, .llseek = seq_lseek,
.release = single_release, .release = single_release,
}; };
/* Create the /proc/net/ipconfig directory */
static int __init ipconfig_proc_net_init(void)
{
ipconfig_dir = proc_net_mkdir(&init_net, "ipconfig", init_net.proc_net);
if (!ipconfig_dir)
return -ENOMEM;
return 0;
}
/* Create a new file under /proc/net/ipconfig */
static int ipconfig_proc_net_create(const char *name,
const struct file_operations *fops)
{
char *pname;
struct proc_dir_entry *p;
if (!ipconfig_dir)
return -ENOMEM;
pname = kasprintf(GFP_KERNEL, "%s%s", "ipconfig/", name);
if (!pname)
return -ENOMEM;
p = proc_create(pname, 0444, init_net.proc_net, fops);
kfree(pname);
if (!p)
return -ENOMEM;
return 0;
}
/* Write NTP server IP addresses to /proc/net/ipconfig/ntp_servers */
static int ntp_servers_seq_show(struct seq_file *seq, void *v)
{
int i;
for (i = 0; i < CONF_NTP_SERVERS_MAX; i++) {
if (ic_ntp_servers[i] != NONE)
seq_printf(seq, "%pI4\n", &ic_ntp_servers[i]);
}
return 0;
}
static int ntp_servers_seq_open(struct inode *inode, struct file *file)
{
return single_open(file, ntp_servers_seq_show, NULL);
}
static const struct file_operations ntp_servers_seq_fops = {
.open = ntp_servers_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
/* /*
...@@ -1368,8 +1460,20 @@ static int __init ip_auto_config(void) ...@@ -1368,8 +1460,20 @@ static int __init ip_auto_config(void)
int err; int err;
unsigned int i; unsigned int i;
/* Initialise all name servers and NTP servers to NONE (but only if the
* "ip=" or "nfsaddrs=" kernel command line parameters weren't decoded,
* otherwise we'll overwrite the IP addresses specified there)
*/
if (ic_set_manually == 0) {
ic_nameservers_predef();
ic_ntp_servers_predef();
}
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
proc_create("pnp", 0444, init_net.proc_net, &pnp_seq_fops); proc_create("pnp", 0444, init_net.proc_net, &pnp_seq_fops);
if (ipconfig_proc_net_init() == 0)
ipconfig_proc_net_create("ntp_servers", &ntp_servers_seq_fops);
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
if (!ic_enable) if (!ic_enable)
...@@ -1481,16 +1585,32 @@ static int __init ip_auto_config(void) ...@@ -1481,16 +1585,32 @@ static int __init ip_auto_config(void)
&ic_servaddr, &root_server_addr, root_server_path); &ic_servaddr, &root_server_addr, root_server_path);
if (ic_dev_mtu) if (ic_dev_mtu)
pr_cont(", mtu=%d", ic_dev_mtu); pr_cont(", mtu=%d", ic_dev_mtu);
for (i = 0; i < CONF_NAMESERVERS_MAX; i++) /* Name servers (if any): */
for (i = 0; i < CONF_NAMESERVERS_MAX; i++) {
if (ic_nameservers[i] != NONE) { if (ic_nameservers[i] != NONE) {
pr_cont(" nameserver%u=%pI4", if (i == 0)
i, &ic_nameservers[i]); pr_info(" nameserver%u=%pI4",
break; i, &ic_nameservers[i]);
else
pr_cont(", nameserver%u=%pI4",
i, &ic_nameservers[i]);
} }
for (i++; i < CONF_NAMESERVERS_MAX; i++) if (i + 1 == CONF_NAMESERVERS_MAX)
if (ic_nameservers[i] != NONE) pr_cont("\n");
pr_cont(", nameserver%u=%pI4", i, &ic_nameservers[i]); }
pr_cont("\n"); /* NTP servers (if any): */
for (i = 0; i < CONF_NTP_SERVERS_MAX; i++) {
if (ic_ntp_servers[i] != NONE) {
if (i == 0)
pr_info(" ntpserver%u=%pI4",
i, &ic_ntp_servers[i]);
else
pr_cont(", ntpserver%u=%pI4",
i, &ic_ntp_servers[i]);
}
if (i + 1 == CONF_NTP_SERVERS_MAX)
pr_cont("\n");
}
#endif /* !SILENT */ #endif /* !SILENT */
/* /*
...@@ -1588,7 +1708,9 @@ static int __init ip_auto_config_setup(char *addrs) ...@@ -1588,7 +1708,9 @@ static int __init ip_auto_config_setup(char *addrs)
return 1; return 1;
} }
/* Initialise all name servers and NTP servers to NONE */
ic_nameservers_predef(); ic_nameservers_predef();
ic_ntp_servers_predef();
/* Parse string for static IP assignment. */ /* Parse string for static IP assignment. */
ip = addrs; ip = addrs;
...@@ -1647,6 +1769,13 @@ static int __init ip_auto_config_setup(char *addrs) ...@@ -1647,6 +1769,13 @@ static int __init ip_auto_config_setup(char *addrs)
ic_nameservers[1] = NONE; ic_nameservers[1] = NONE;
} }
break; break;
case 9:
if (CONF_NTP_SERVERS_MAX >= 1) {
ic_ntp_servers[0] = in_aton(ip);
if (ic_ntp_servers[0] == ANY)
ic_ntp_servers[0] = NONE;
}
break;
} }
} }
ip = cp; ip = cp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment