Skip to contentSkip to conversation

ipconfig: send Client-identifier in DHCP requests

PATCH Superseded [email protected] 2 participants 4 messages Oct 15, 2015

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipconfig: send Client-identifier in DHCP requests

From: Li RongQing <[email protected]>

A dhcp server may provide parameters to a client from a pool of IP addresses and using a shared rootfs, or provide a specific set of parameters for a specific client, usually using the MAC address to identify each client individually. The dhcp protocol also specifies a client-id field which can be used to determine the correct parameters to supply when no MAC address is available. There is currently no way to tell the kernel to supply a specific client-id, only the userspace dhcp clients support this feature, but this can not be used when the network is needed before userspace is available such as when the root filesystem is on NFS.

This patch is to be able to do something like "ip=dhcp,client_id_type, client_id_value", as a kernel parameter to enable the kernel to identify itself to the server.

---
 Documentation/filesystems/nfs/nfsroot.txt |  3 +++
 net/ipv4/ipconfig.c                       | 28 +++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
Documentation/filesystems/nfs/nfsroot.txt +3 -0
index 2d66ed6..bb5ab6d 100644
@@ -157,6 +157,9 @@ ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:
 		  both:        use both BOOTP and RARP but not DHCP
 		               (old option kept for backwards compatibility)
 
+		if dhcp is used, the client identifier can be used by following
+		format "ip=dhcp,client-id-type,client-id-value"
+
                 Default: any
 
   <dns0-ip>	IP address of first nameserver.
net/ipv4/ipconfig.c +27 -1
index ed4ef09..57c4fd4 100644
@@ -145,6 +145,7 @@ u8 root_server_path[256] = { 0, };	/* Path to mount as root */
 
 /* vendor class identifier */
 static char vendor_class_identifier[253] __initdata;
+static char dhcp_client_identifier[253] __initdata;
 
 /* Persistent data: */
 
@@ -728,6 +729,16 @@ ic_dhcp_init_options(u8 *options)
 			memcpy(e, vendor_class_identifier, len);
 			e += len;
 		}
+		len = strlen(dhcp_client_identifier + 1);
+		/* the minimum length of identifier is 2, include 1 byte type,
+		 * and can not be larger than the length of options
+		 */
+		if (len >= 1 && len < 312 - (e - options) - 1) {
+			*e++ = 61;
+			*e++ = len + 1;
+			memcpy(e, dhcp_client_identifier, len + 1);
+			e += len + 1;
+		}
 	}
 
 	*e++ = 255;	/* End of the list */
@@ -1557,8 +1568,23 @@ static int __init ic_proto_name(char *name)
 		return 0;
 	}
 #ifdef CONFIG_IP_PNP_DHCP
-	else if (!strcmp(name, "dhcp")) {
+	else if (!strncmp(name, "dhcp", 4)) {
+		char *client_id;
+
 		ic_proto_enabled &= ~IC_RARP;
+		client_id = strstr(name, "dhcp,");
+		if (client_id) {
+			char *v;
+
+			client_id = client_id + 5;
+			v = strchr(client_id, ',');
+			if (!v)
+				return 1;
+			*v = 0;
+			kstrtou8(client_id, 0, dhcp_client_identifier);
+			strncpy(dhcp_client_identifier + 1, v + 1, 251);
+			*v = ',';
+		}
 		return 1;
 	}
 #endif
Signature · 1 line
2.1.4
#1 lore raw
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Li,

[auto build test WARNING on net/master -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/roy-qing-li-gmail-com/ipconfig-send-Client-identifier-in-DHCP-requests/20151015-105553
config: parisc-defconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=parisc

All warnings (new ones prefixed by >>):

net/ipv4/ipconfig.c: In function 'ic_proto_name':

>> net/ipv4/ipconfig.c:1584:4: warning: ignoring return value of 'kstrtou8', declared with attribute warn_unused_result [-Wunused-result]
       kstrtou8(client_id, 0, dhcp_client_identifier);
       ^

vim +/kstrtou8 +1584 net/ipv4/ipconfig.c

1568 return 0;
1569 }
1570 #ifdef CONFIG_IP_PNP_DHCP
1571 else if (!strncmp(name, "dhcp", 4)) {
1572 char *client_id;
1573
1574 ic_proto_enabled &= ~IC_RARP;
1575 client_id = strstr(name, "dhcp,");
1576 if (client_id) {
1577 char *v;
1578
1579 client_id = client_id + 5;
1580 v = strchr(client_id, ',');
1581 if (!v)
1582 return 1;
1583 *v = 0;

> 1584				kstrtou8(client_id, 0, dhcp_client_identifier);

1585 strncpy(dhcp_client_identifier + 1, v + 1, 251);
1586 *v = ',';
1587 }
1588 return 1;
1589 }
1590 #endif
1591 #ifdef CONFIG_IP_PNP_BOOTP
1592 else if (!strcmp(name, "bootp")) {

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
In reply to [email protected]
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Li,

[auto build test WARNING on net/master -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/roy-qing-li-gmail-com/ipconfig-send-Client-identifier-in-DHCP-requests/20151015-105553
config: parisc-c3000_defconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=parisc

All warnings (new ones prefixed by >>):

>> net/ipv4/ipconfig.c:148:13: warning: 'dhcp_client_identifier' defined but not used [-Wunused-variable]
    static char dhcp_client_identifier[253] __initdata;
                ^

vim +/dhcp_client_identifier +148 net/ipv4/ipconfig.c

132
133 static int ic_host_name_set __initdata; /* Host name set by us? */
134
135 __be32 ic_myaddr = NONE; /* My IP address */
136 static __be32 ic_netmask = NONE; /* Netmask for local subnet */
137 __be32 ic_gateway = NONE; /* Gateway IP address */
138
139 __be32 ic_addrservaddr = NONE; /* IP Address of the IP addresses'server */
140
141 __be32 ic_servaddr = NONE; /* Boot server IP address */
142
143 __be32 root_server_addr = NONE; /* Address of NFS server */
144 u8 root_server_path[256] = { 0, }; /* Path to mount as root */
145
146 /* vendor class identifier */
147 static char vendor_class_identifier[253] __initdata;

 > 148	static char dhcp_client_identifier[253] __initdata;

149
150 /* Persistent data: */
151
152 static int ic_proto_used; /* Protocol used, if any */
153 static __be32 ic_nameservers[CONF_NAMESERVERS_MAX]; /* DNS Server IP addresses */
154 static u8 ic_domain[64]; /* DNS (not NIS) domain name */
155
156 /*

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw
Quoted 12 lines · kbuild test robot

Hi Li,

[auto build test WARNING on net/master -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/roy-qing-li-gmail-com/ipconfig-send-Client-identifier-in-DHCP-requests/20151015-105553
config: parisc-c3000_defconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=parisc

Quoted 5 lines

All warnings (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

net/ipv4/ipconfig.c:148:13: warning: 'dhcp_client_identifier' defined but not used [-Wunused-variable]

    static char dhcp_client_identifier[253] __initdata;
                ^

Thanks, I will fix it

-Roy