Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipconfig: send Client-identifier in DHCP requests

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.

Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Li RongQing and committed by
David S. Miller
26fb342c 4be3158a

+34 -1
+3
Documentation/filesystems/nfs/nfsroot.txt
··· 157 157 both: use both BOOTP and RARP but not DHCP 158 158 (old option kept for backwards compatibility) 159 159 160 + if dhcp is used, the client identifier can be used by following 161 + format "ip=dhcp,client-id-type,client-id-value" 162 + 160 163 Default: any 161 164 162 165 <dns0-ip> IP address of first nameserver.
+31 -1
net/ipv4/ipconfig.c
··· 146 146 /* vendor class identifier */ 147 147 static char vendor_class_identifier[253] __initdata; 148 148 149 + #if defined(CONFIG_IP_PNP_DHCP) 150 + static char dhcp_client_identifier[253] __initdata; 151 + #endif 152 + 149 153 /* Persistent data: */ 150 154 151 155 static int ic_proto_used; /* Protocol used, if any */ ··· 731 727 *e++ = len; 732 728 memcpy(e, vendor_class_identifier, len); 733 729 e += len; 730 + } 731 + len = strlen(dhcp_client_identifier + 1); 732 + /* the minimum length of identifier is 2, include 1 byte type, 733 + * and can not be larger than the length of options 734 + */ 735 + if (len >= 1 && len < 312 - (e - options) - 1) { 736 + *e++ = 61; 737 + *e++ = len + 1; 738 + memcpy(e, dhcp_client_identifier, len + 1); 739 + e += len + 1; 734 740 } 735 741 } 736 742 ··· 1571 1557 return 0; 1572 1558 } 1573 1559 #ifdef CONFIG_IP_PNP_DHCP 1574 - else if (!strcmp(name, "dhcp")) { 1560 + else if (!strncmp(name, "dhcp", 4)) { 1561 + char *client_id; 1562 + 1575 1563 ic_proto_enabled &= ~IC_RARP; 1564 + client_id = strstr(name, "dhcp,"); 1565 + if (client_id) { 1566 + char *v; 1567 + 1568 + client_id = client_id + 5; 1569 + v = strchr(client_id, ','); 1570 + if (!v) 1571 + return 1; 1572 + *v = 0; 1573 + if (kstrtou8(client_id, 0, dhcp_client_identifier)) 1574 + DBG("DHCP: Invalid client identifier type\n"); 1575 + strncpy(dhcp_client_identifier + 1, v + 1, 251); 1576 + *v = ','; 1577 + } 1576 1578 return 1; 1577 1579 } 1578 1580 #endif