netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] ipconfig: send Client-identifier in DHCP requests
@ 2015-10-15  8:54 roy.qing.li
  2015-10-15 14:56 ` Florian Fainelli
  2015-10-19  2:24 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: roy.qing.li @ 2015-10-15  8:54 UTC (permalink / raw)
  To: netdev

From: Li RongQing <roy.qing.li@gmail.com>

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>
---
 Documentation/filesystems/nfs/nfsroot.txt |  3 +++
 net/ipv4/ipconfig.c                       | 32 ++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/Documentation/filesystems/nfs/nfsroot.txt b/Documentation/filesystems/nfs/nfsroot.txt
index 2d66ed6..bb5ab6d 100644
--- a/Documentation/filesystems/nfs/nfsroot.txt
+++ b/Documentation/filesystems/nfs/nfsroot.txt
@@ -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.
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index ed4ef09..0bc7412 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -146,6 +146,10 @@ u8 root_server_path[256] = { 0, };	/* 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: */
 
 static int ic_proto_used;			/* Protocol used, if any */
@@ -728,6 +732,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 +1571,24 @@ 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;
+			if (kstrtou8(client_id, 0, dhcp_client_identifier))
+				DBG("DHCP: Invalid client identifier type\n");
+			strncpy(dhcp_client_identifier + 1, v + 1, 251);
+			*v = ',';
+		}
 		return 1;
 	}
 #endif
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] ipconfig: send Client-identifier in DHCP requests
  2015-10-15  8:54 [PATCH net-next v2] ipconfig: send Client-identifier in DHCP requests roy.qing.li
@ 2015-10-15 14:56 ` Florian Fainelli
  2015-10-15 23:54   ` Li RongQing
  2015-10-19  2:24 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2015-10-15 14:56 UTC (permalink / raw)
  To: roy.qing.li; +Cc: netdev

2015-10-15 1:54 GMT-07:00  <roy.qing.li@gmail.com>:
> From: Li RongQing <roy.qing.li@gmail.com>
>
> 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>
> ---
>  Documentation/filesystems/nfs/nfsroot.txt |  3 +++
>  net/ipv4/ipconfig.c                       | 32 ++++++++++++++++++++++++++++++-
>  2 files changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/filesystems/nfs/nfsroot.txt b/Documentation/filesystems/nfs/nfsroot.txt
> index 2d66ed6..bb5ab6d 100644
> --- a/Documentation/filesystems/nfs/nfsroot.txt
> +++ b/Documentation/filesystems/nfs/nfsroot.txt
> @@ -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.
> diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
> index ed4ef09..0bc7412 100644
> --- a/net/ipv4/ipconfig.c
> +++ b/net/ipv4/ipconfig.c
> @@ -146,6 +146,10 @@ u8 root_server_path[256] = { 0, }; /* 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: */
>
>  static int ic_proto_used;                      /* Protocol used, if any */
> @@ -728,6 +732,16 @@ ic_dhcp_init_options(u8 *options)
>                         memcpy(e, vendor_class_identifier, len);
>                         e += len;
>                 }
> +               len = strlen(dhcp_client_identifier + 1);

Did not you mean strlen(dhcp_client_identifer) + 1 instead?
-- 
Florian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] ipconfig: send Client-identifier in DHCP requests
  2015-10-15 14:56 ` Florian Fainelli
@ 2015-10-15 23:54   ` Li RongQing
  0 siblings, 0 replies; 4+ messages in thread
From: Li RongQing @ 2015-10-15 23:54 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: netdev

On Thu, Oct 15, 2015 at 10:56 PM, Florian Fainelli <f.fainelli@gmail.com> wrote:
> Did not you mean strlen(dhcp_client_identifer) + 1 instead?


no;
dhcp_client_identifer[0] is client identifier type, and it maybe 0;
dhcp_client_identifer+1 is the start address of client identifier value;

-Roy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] ipconfig: send Client-identifier in DHCP requests
  2015-10-15  8:54 [PATCH net-next v2] ipconfig: send Client-identifier in DHCP requests roy.qing.li
  2015-10-15 14:56 ` Florian Fainelli
@ 2015-10-19  2:24 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2015-10-19  2:24 UTC (permalink / raw)
  To: roy.qing.li; +Cc: netdev

From: roy.qing.li@gmail.com
Date: Thu, 15 Oct 2015 16:54:36 +0800

> From: Li RongQing <roy.qing.li@gmail.com>
> 
> 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>

Looks good, applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-19  2:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-15  8:54 [PATCH net-next v2] ipconfig: send Client-identifier in DHCP requests roy.qing.li
2015-10-15 14:56 ` Florian Fainelli
2015-10-15 23:54   ` Li RongQing
2015-10-19  2:24 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).