LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] ipconfig.c : implement DHCP Class-identifier
@ 2007-11-08 14:32 Rainer Jochem
  2007-11-08 15:45 ` Patrick McHardy
  2007-11-08 20:27 ` Ilpo Järvinen
  0 siblings, 2 replies; 10+ messages in thread
From: Rainer Jochem @ 2007-11-08 14:32 UTC (permalink / raw)
  To: davem, kuznet, jmorris, kaber; +Cc: linux-kernel, netdev, pcernko


This patch implements the DHCP Class identifier (see rfc1533) which is
used by DHCP clients to optionally identify the type and configuration of 
a DHCP client which is send as a string to the server. For example, the
identifier may encode the client's hardware configuration. If the newly 
introduced kernel-parameter 'dhcpclass' is set, then the kernel sends 
the given string in its DHCP-request to the server.
If the option is omitted, the behaviour is as before without this patch.


Patch applies to:
Version:	2.6.23.1
File:		net/ipv4/ipconfig.c


Signed-off-by: Rainer Jochem <rainer.jochem@mpi-sb.mpg.de>

---

--- net/ipv4/ipconfig.c.orig	2007-11-08 14:54:11.001662860 +0100
+++ net/ipv4/ipconfig.c	2007-11-08 14:54:15.961480524 +0100
@@ -139,6 +139,8 @@ __be32 ic_servaddr = NONE;	/* Boot serve
 __be32 root_server_addr = NONE;	/* Address of NFS server */
 u8 root_server_path[256] = { 0, };	/* Path to mount as root */
 
+char vendor_class_identifier[256] = { 0, }; /* vendor class identifier */
+
 /* Persistent data: */
 
 static int ic_proto_used;			/* Protocol used, if any */
@@ -620,6 +622,17 @@ ic_dhcp_init_options(u8 *options)
 		*e++ = sizeof(ic_req_params);
 		memcpy(e, ic_req_params, sizeof(ic_req_params));
 		e += sizeof(ic_req_params);
+
+		// Send it only if the according kernel parameter was set
+		if (*vendor_class_identifier) {
+			printk(KERN_INFO "Sending class identifier \"%s\"\n",
+			       vendor_class_identifier);
+			*e++ = 60;	/* Class-identifier */
+			*e++ = strlen(vendor_class_identifier);
+			memcpy(e, vendor_class_identifier,
+			       strlen(vendor_class_identifier));
+			e += strlen(vendor_class_identifier);
+		}
 	}
 
 	*e++ = 255;	/* End of the list */
@@ -1507,5 +1520,14 @@ static int __init nfsaddrs_config_setup(
 	return ip_auto_config_setup(addrs);
 }
 
+static int __init vendor_class_identifier_setup(char *addrs)
+{
+	if (strlcpy(vendor_class_identifier, addrs, 250) > 250)
+		printk(KERN_WARNING "vendorclass too long, truncated to \"%s\"",
+		       vendor_class_identifier);
+	return 1;
+}
+
 __setup("ip=", ip_auto_config_setup);
 __setup("nfsaddrs=", nfsaddrs_config_setup);
+__setup("dhcpclass=", vendor_class_identifier_setup);



--- ../linux-2.6.23.1/Documentation/kernel-parameters.txt	2007-10-12 18:43:44.000000000 +0200
+++ Documentation/kernel-parameters.txt	2007-10-24 17:02:22.441454955 +0200
@@ -533,6 +533,10 @@ and is between 256 and 4096 characters. 
 	dhash_entries=	[KNL]
 			Set number of hash buckets for dentry cache.
 
+	dhcpclass=	[KNL]
+			Set DHCP Vendor Class Identifier to be sent
+			by the client.
+
 	digi=		[HW,SERIAL]
 			IO parameters + enable/disable command.



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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-08 14:32 [PATCH] ipconfig.c : implement DHCP Class-identifier Rainer Jochem
@ 2007-11-08 15:45 ` Patrick McHardy
  2007-11-14  8:44   ` Rainer Jochem
  2007-11-08 20:27 ` Ilpo Järvinen
  1 sibling, 1 reply; 10+ messages in thread
From: Patrick McHardy @ 2007-11-08 15:45 UTC (permalink / raw)
  To: Rainer Jochem; +Cc: davem, kuznet, jmorris, linux-kernel, netdev, pcernko

Rainer Jochem wrote:
> --- net/ipv4/ipconfig.c.orig	2007-11-08 14:54:11.001662860 +0100
> +++ net/ipv4/ipconfig.c	2007-11-08 14:54:15.961480524 +0100
> @@ -139,6 +139,8 @@ __be32 ic_servaddr = NONE;	/* Boot serve
>  __be32 root_server_addr = NONE;	/* Address of NFS server */
>  u8 root_server_path[256] = { 0, };	/* Path to mount as root */
>  
> +char vendor_class_identifier[256] = { 0, }; /* vendor class identifier */

static please, no need to initialize.

> +
>  /* Persistent data: */
>  
>  static int ic_proto_used;			/* Protocol used, if any */
> @@ -620,6 +622,17 @@ ic_dhcp_init_options(u8 *options)
>  		*e++ = sizeof(ic_req_params);
>  		memcpy(e, ic_req_params, sizeof(ic_req_params));
>  		e += sizeof(ic_req_params);
> +
> +		// Send it only if the according kernel parameter was set
> +		if (*vendor_class_identifier) {
> +			printk(KERN_INFO "Sending class identifier \"%s\"\n",
> +			       vendor_class_identifier);

Seems like useless noise.

> +			*e++ = 60;	/* Class-identifier */
> +			*e++ = strlen(vendor_class_identifier);
> +			memcpy(e, vendor_class_identifier,
> +			       strlen(vendor_class_identifier));
> +			e += strlen(vendor_class_identifier);

You could avoid these three strlen calls by using a temporary
variable to hold the length.

> +		}
>  	}
>  
>  	*e++ = 255;	/* End of the list */
> @@ -1507,5 +1520,14 @@ static int __init nfsaddrs_config_setup(
>  	return ip_auto_config_setup(addrs);
>  }
>  
> +static int __init vendor_class_identifier_setup(char *addrs)
> +{
> +	if (strlcpy(vendor_class_identifier, addrs, 250) > 250)

sizeof(vendor_class_identifier). Why are you using 250 but the
array is 256 bytes large?

> +		printk(KERN_WARNING "vendorclass too long, truncated to \"%s\"",
> +		       vendor_class_identifier);
> +	return 1;
> +}
> +
>  __setup("ip=", ip_auto_config_setup);
>  __setup("nfsaddrs=", nfsaddrs_config_setup);
> +__setup("dhcpclass=", vendor_class_identifier_setup);
> 
> 
> 
> --- ../linux-2.6.23.1/Documentation/kernel-parameters.txt	2007-10-12 18:43:44.000000000 +0200
> +++ Documentation/kernel-parameters.txt	2007-10-24 17:02:22.441454955 +0200
> @@ -533,6 +533,10 @@ and is between 256 and 4096 characters. 
>  	dhash_entries=	[KNL]
>  			Set number of hash buckets for dentry cache.
>  
> +	dhcpclass=	[KNL]

[IP_PNP]

> +			Set DHCP Vendor Class Identifier to be sent
> +			by the client.
> +
>  	digi=		[HW,SERIAL]
>  			IO parameters + enable/disable command.
> 
> 


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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-08 14:32 [PATCH] ipconfig.c : implement DHCP Class-identifier Rainer Jochem
  2007-11-08 15:45 ` Patrick McHardy
@ 2007-11-08 20:27 ` Ilpo Järvinen
  1 sibling, 0 replies; 10+ messages in thread
From: Ilpo Järvinen @ 2007-11-08 20:27 UTC (permalink / raw)
  To: Rainer Jochem
  Cc: davem, kuznet, jmorris, kaber, linux-kernel, netdev, pcernko

On Thu, 8 Nov 2007, Rainer Jochem wrote:

> @@ -620,6 +622,17 @@ ic_dhcp_init_options(u8 *options)
>  		*e++ = sizeof(ic_req_params);
>  		memcpy(e, ic_req_params, sizeof(ic_req_params));
>  		e += sizeof(ic_req_params);
> +
> +		// Send it only if the according kernel parameter was set

No C99 comments please. Though I'm not sure if this comment is that 
necessary anyway...

> +		if (*vendor_class_identifier) {
> +			printk(KERN_INFO "Sending class identifier \"%s\"\n",
> +			       vendor_class_identifier);
> +			*e++ = 60;	/* Class-identifier */
> +			*e++ = strlen(vendor_class_identifier);
> +			memcpy(e, vendor_class_identifier,
> +			       strlen(vendor_class_identifier));
> +			e += strlen(vendor_class_identifier);
> +		}
>  	}
>  
>  	*e++ = 255;	/* End of the list */

-- 
 i.

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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-08 15:45 ` Patrick McHardy
@ 2007-11-14  8:44   ` Rainer Jochem
  2007-11-14  8:56     ` Patrick McHardy
  0 siblings, 1 reply; 10+ messages in thread
From: Rainer Jochem @ 2007-11-14  8:44 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: davem, kuznet, jmorris, linux-kernel, netdev, pcernko


Corrected version below.

> >+			printk(KERN_INFO "Sending class identifier \"%s\"\n",
> >+			       vendor_class_identifier);
> 
> Seems like useless noise.

This information is only sent in the case that the option is actually used.
And in this case it might be useful for the user to see to which string the 
option was set.


--- net/ipv4/ipconfig.c.orig	2007-11-14 09:16:15.800566536 +0100
+++ net/ipv4/ipconfig.c	2007-11-14 09:16:20.200403710 +0100
@@ -139,6 +139,8 @@ __be32 ic_servaddr = NONE;	/* Boot serve
 __be32 root_server_addr = NONE;	/* Address of NFS server */
 u8 root_server_path[256] = { 0, };	/* Path to mount as root */
 
+static char vendor_class_identifier[253]; /* vendor class identifier */
+
 /* Persistent data: */
 
 static int ic_proto_used;			/* Protocol used, if any */
@@ -580,6 +582,7 @@ ic_dhcp_init_options(u8 *options)
 	u8 mt = ((ic_servaddr == NONE)
 		 ? DHCPDISCOVER : DHCPREQUEST);
 	u8 *e = options;
+	int len = 0;
 
 #ifdef IPCONFIG_DEBUG
 	printk("DHCP: Sending message type %d\n", mt);
@@ -620,6 +623,16 @@ ic_dhcp_init_options(u8 *options)
 		*e++ = sizeof(ic_req_params);
 		memcpy(e, ic_req_params, sizeof(ic_req_params));
 		e += sizeof(ic_req_params);
+
+		if (*vendor_class_identifier) {
+			printk(KERN_INFO "Sending class identifier \"%s\"\n",
+			       vendor_class_identifier);
+			*e++ = 60;	/* Class-identifier */
+			len = strlen(vendor_class_identifier);
+			*e++ = len;
+			memcpy(e, vendor_class_identifier, len);
+			e += len;
+		}
 	}
 
 	*e++ = 255;	/* End of the list */
@@ -1507,5 +1520,16 @@ static int __init nfsaddrs_config_setup(
 	return ip_auto_config_setup(addrs);
 }
 
+static int __init vendor_class_identifier_setup(char *addrs)
+{
+	if (strlcpy(vendor_class_identifier, addrs,
+		    sizeof(vendor_class_identifier))
+	    > sizeof(vendor_class_identifier))
+		printk(KERN_WARNING "vendorclass too long, truncated to \"%s\"",
+		       vendor_class_identifier);
+	return 1;
+}
+
 __setup("ip=", ip_auto_config_setup);
 __setup("nfsaddrs=", nfsaddrs_config_setup);
+__setup("dhcpclass=", vendor_class_identifier_setup);




----



--- ../linux-2.6.23.1/Documentation/kernel-parameters.txt	2007-10-12 18:43:44.000000000 +0200
+++ Documentation/kernel-parameters.txt	2007-10-24 17:02:22.441454955 +0200
@@ -533,6 +533,10 @@ and is between 256 and 4096 characters. 
 	dhash_entries=	[KNL]
 			Set number of hash buckets for dentry cache.
 
+	dhcpclass=	[IP_PNP]
+			Set DHCP Vendor Class Identifier to be sent
+			by the client.
+
 	digi=		[HW,SERIAL]
 			IO parameters + enable/disable command.

Signed-off-by: Rainer Jochem <rainer.jochem@mpi-sb.mpg.de>

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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-14  8:44   ` Rainer Jochem
@ 2007-11-14  8:56     ` Patrick McHardy
  2007-11-14  9:45       ` Rainer Jochem
  0 siblings, 1 reply; 10+ messages in thread
From: Patrick McHardy @ 2007-11-14  8:56 UTC (permalink / raw)
  To: Rainer Jochem; +Cc: davem, kuznet, jmorris, linux-kernel, netdev, pcernko

Rainer Jochem wrote:
> Corrected version below.
> 
>>> +			printk(KERN_INFO "Sending class identifier \"%s\"\n",
>>> +			       vendor_class_identifier);
>> Seems like useless noise.
> 
> This information is only sent in the case that the option is actually used.
> And in this case it might be useful for the user to see to which string the 
> option was set.


I don't think its very useful since you can simply get this information
from /proc/cmdline in case something goes wrong, but if you insist at
least give it a meaningful prefix.

> @@ -580,6 +582,7 @@ ic_dhcp_init_options(u8 *options)
>  	u8 mt = ((ic_servaddr == NONE)
>  		 ? DHCPDISCOVER : DHCPREQUEST);
>  	u8 *e = options;
> +	int len = 0;

The initialization is unnecessary.

>  #ifdef IPCONFIG_DEBUG
>  	printk("DHCP: Sending message type %d\n", mt);
> @@ -620,6 +623,16 @@ ic_dhcp_init_options(u8 *options)
>  		*e++ = sizeof(ic_req_params);
>  		memcpy(e, ic_req_params, sizeof(ic_req_params));
>  		e += sizeof(ic_req_params);
> +
> +		if (*vendor_class_identifier) {
> +			printk(KERN_INFO "Sending class identifier \"%s\"\n",
> +			       vendor_class_identifier);
> +			*e++ = 60;	/* Class-identifier */
> +			len = strlen(vendor_class_identifier);
> +			*e++ = len;
> +			memcpy(e, vendor_class_identifier, len);
> +			e += len;
> +		}
>  	}
>  
>  	*e++ = 255;	/* End of the list */
> @@ -1507,5 +1520,16 @@ static int __init nfsaddrs_config_setup(
>  	return ip_auto_config_setup(addrs);
>  }
>  
> +static int __init vendor_class_identifier_setup(char *addrs)
> +{
> +	if (strlcpy(vendor_class_identifier, addrs,
> +		    sizeof(vendor_class_identifier))
> +	    > sizeof(vendor_class_identifier))
> +		printk(KERN_WARNING "vendorclass too long, truncated to \"%s\"",
> +		       vendor_class_identifier);

Should be >= I think.

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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-14  8:56     ` Patrick McHardy
@ 2007-11-14  9:45       ` Rainer Jochem
  2007-11-14  9:48         ` Patrick McHardy
  2007-11-14 22:11         ` Francois Romieu
  0 siblings, 2 replies; 10+ messages in thread
From: Rainer Jochem @ 2007-11-14  9:45 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: davem, kuznet, jmorris, linux-kernel, netdev, pcernko



> I don't think its very useful since you can simply get this information
> from /proc/cmdline in case something goes wrong, but if you insist at
> least give it a meaningful prefix.

Added.

> The initialization is unnecessary.

Removed.

> Should be >= I think.

Fixed.


Regards,
 Rainer

----

--- net/ipv4/ipconfig.c.orig	2007-11-14 09:16:15.800566536 +0100
+++ net/ipv4/ipconfig.c	2007-11-14 10:34:22.471219274 +0100
@@ -139,6 +139,8 @@ __be32 ic_servaddr = NONE;	/* Boot serve
 __be32 root_server_addr = NONE;	/* Address of NFS server */
 u8 root_server_path[256] = { 0, };	/* Path to mount as root */
 
+static char vendor_class_identifier[253]; /* vendor class identifier */
+
 /* Persistent data: */
 
 static int ic_proto_used;			/* Protocol used, if any */
@@ -580,6 +582,7 @@ ic_dhcp_init_options(u8 *options)
 	u8 mt = ((ic_servaddr == NONE)
 		 ? DHCPDISCOVER : DHCPREQUEST);
 	u8 *e = options;
+	int len;
 
 #ifdef IPCONFIG_DEBUG
 	printk("DHCP: Sending message type %d\n", mt);
@@ -620,6 +623,16 @@ ic_dhcp_init_options(u8 *options)
 		*e++ = sizeof(ic_req_params);
 		memcpy(e, ic_req_params, sizeof(ic_req_params));
 		e += sizeof(ic_req_params);
+
+		if (*vendor_class_identifier) {
+			printk(KERN_INFO "DHCP: sending class identifier \"%s\"\n",
+			       vendor_class_identifier);
+			*e++ = 60;	/* Class-identifier */
+			len = strlen(vendor_class_identifier);
+			*e++ = len;
+			memcpy(e, vendor_class_identifier, len);
+			e += len;
+		}
 	}
 
 	*e++ = 255;	/* End of the list */
@@ -1507,5 +1520,16 @@ static int __init nfsaddrs_config_setup(
 	return ip_auto_config_setup(addrs);
 }
 
+static int __init vendor_class_identifier_setup(char *addrs)
+{
+	if (strlcpy(vendor_class_identifier, addrs,
+		    sizeof(vendor_class_identifier))
+	    >= sizeof(vendor_class_identifier))
+		printk(KERN_WARNING "DHCP: vendorclass too long, truncated to \"%s\"",
+		       vendor_class_identifier);
+	return 1;
+}
+
 __setup("ip=", ip_auto_config_setup);
 __setup("nfsaddrs=", nfsaddrs_config_setup);
+__setup("dhcpclass=", vendor_class_identifier_setup);

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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-14  9:45       ` Rainer Jochem
@ 2007-11-14  9:48         ` Patrick McHardy
  2007-11-14 10:18           ` David Miller
  2007-11-14 22:11         ` Francois Romieu
  1 sibling, 1 reply; 10+ messages in thread
From: Patrick McHardy @ 2007-11-14  9:48 UTC (permalink / raw)
  To: Rainer Jochem; +Cc: davem, kuznet, jmorris, linux-kernel, netdev, pcernko

Rainer Jochem wrote:
> 
>> I don't think its very useful since you can simply get this information
>> from /proc/cmdline in case something goes wrong, but if you insist at
>> least give it a meaningful prefix.
> 
> Added.
> 
>> The initialization is unnecessary.
> 
> Removed.
> 
>> Should be >= I think.
> 
> Fixed.


Looks fine, thanks.



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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-14  9:48         ` Patrick McHardy
@ 2007-11-14 10:18           ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2007-11-14 10:18 UTC (permalink / raw)
  To: kaber; +Cc: rainer.jochem, kuznet, jmorris, linux-kernel, netdev, pcernko

From: Patrick McHardy <kaber@trash.net>
Date: Wed, 14 Nov 2007 10:48:43 +0100

> Rainer Jochem wrote:
> > 
> >> I don't think its very useful since you can simply get this information
> >> from /proc/cmdline in case something goes wrong, but if you insist at
> >> least give it a meaningful prefix.
> > 
> > Added.
> > 
> >> The initialization is unnecessary.
> > 
> > Removed.
> > 
> >> Should be >= I think.
> > 
> > Fixed.
> 
> Looks fine, thanks.

Applied to net-2.6.25, thanks everyone.

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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-14  9:45       ` Rainer Jochem
  2007-11-14  9:48         ` Patrick McHardy
@ 2007-11-14 22:11         ` Francois Romieu
  2007-11-20  5:56           ` David Miller
  1 sibling, 1 reply; 10+ messages in thread
From: Francois Romieu @ 2007-11-14 22:11 UTC (permalink / raw)
  To: Rainer Jochem
  Cc: Patrick McHardy, davem, kuznet, jmorris, linux-kernel, netdev, pcernko

Rainer Jochem <rainer.jochem@mpi-sb.mpg.de> :
[...]
> --- net/ipv4/ipconfig.c.orig	2007-11-14 09:16:15.800566536 +0100
> +++ net/ipv4/ipconfig.c	2007-11-14 10:34:22.471219274 +0100
> @@ -139,6 +139,8 @@ __be32 ic_servaddr = NONE;	/* Boot serve
>  __be32 root_server_addr = NONE;	/* Address of NFS server */
>  u8 root_server_path[256] = { 0, };	/* Path to mount as root */
>  
> +static char vendor_class_identifier[253]; /* vendor class identifier */
> +

ic_dhcp_init_options is __init. Should it not be __initdata ?

-- 
Ueimor

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

* Re: [PATCH] ipconfig.c : implement DHCP Class-identifier
  2007-11-14 22:11         ` Francois Romieu
@ 2007-11-20  5:56           ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2007-11-20  5:56 UTC (permalink / raw)
  To: romieu
  Cc: rainer.jochem, kaber, kuznet, jmorris, linux-kernel, netdev, pcernko

From: Francois Romieu <romieu@fr.zoreil.com>
Date: Wed, 14 Nov 2007 23:11:19 +0100

> Rainer Jochem <rainer.jochem@mpi-sb.mpg.de> :
> [...]
> > --- net/ipv4/ipconfig.c.orig	2007-11-14 09:16:15.800566536 +0100
> > +++ net/ipv4/ipconfig.c	2007-11-14 10:34:22.471219274 +0100
> > @@ -139,6 +139,8 @@ __be32 ic_servaddr = NONE;	/* Boot serve
> >  __be32 root_server_addr = NONE;	/* Address of NFS server */
> >  u8 root_server_path[256] = { 0, };	/* Path to mount as root */
> >  
> > +static char vendor_class_identifier[253]; /* vendor class identifier */
> > +
> 
> ic_dhcp_init_options is __init. Should it not be __initdata ?

I think so and I've made that change in net-2.6.25, thanks.

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

end of thread, other threads:[~2007-11-20  5:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-08 14:32 [PATCH] ipconfig.c : implement DHCP Class-identifier Rainer Jochem
2007-11-08 15:45 ` Patrick McHardy
2007-11-14  8:44   ` Rainer Jochem
2007-11-14  8:56     ` Patrick McHardy
2007-11-14  9:45       ` Rainer Jochem
2007-11-14  9:48         ` Patrick McHardy
2007-11-14 10:18           ` David Miller
2007-11-14 22:11         ` Francois Romieu
2007-11-20  5:56           ` David Miller
2007-11-08 20:27 ` Ilpo Järvinen

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).