ipconfig.c : implement DHCP Class-identifier
Subsystems (2)
PATCH 1/1 ipconfig.c : implement DHCP Class-identifier
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
---
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +22 -0
@@ -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);
kernel-parameters.txt renamed from linux-2.6.23.1/Documentation/kernel-parameters.txt +4 -0
@@ -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.
ipv4/ipconfig.c __be32 ic_servaddr = NONE; /* Boot serve · line 142
Quoted 7 lines · Rainer Jochem
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +1
-0@@ -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.
ipv4/ipconfig.c ic_dhcp_init_options(u8 *options) · line 629
Quoted 13 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +6
-0+/* 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.
ipv4/ipconfig.c ic_dhcp_init_options(u8 *options) · line 634
Quoted 5 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +5
-0+ *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.
ipv4/ipconfig.c static int __init nfsaddrs_config_setup( · line 1525
Quoted 11 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +4
-0+ } } *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?
Quoted 14 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +6
-0+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);
kernel-parameters.txt and is between 256 and 4096 characters. · line 536
Quoted 4 lines
kernel-parameters.txt renamed from linux-2.6.23.1/Documentation/kernel-parameters.txt +1
-0@@ -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]
Quoted 7 lines
kernel-parameters.txt renamed from linux-2.6.23.1/Documentation/kernel-parameters.txt +3
-0+ Set DHCP Vendor Class Identifier to be sent + by the client. + digi= [HW,SERIAL] IO parameters + enable/disable command.
ipv4/ipconfig.c ic_dhcp_init_options(u8 *options) · line 626
Quoted 6 lines · Rainer Jochem
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +2
-0@@ -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...
Quoted 12 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +9
-0+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 */
Signature · 1 line
i.
Corrected version below.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ 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.
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +24 -0
@@ -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);
----
kernel-parameters.txt renamed from linux-2.6.23.1/Documentation/kernel-parameters.txt +4 -0
@@ -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.
Quoted 8 lines · Rainer Jochem
Corrected version below.
Quoted 3 lines
ipv4/ipconfig.c ic_dhcp_init_options(u8 *options) · line 629
Quoted 2 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +2
-0+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.
ipv4/ipconfig.c ic_dhcp_init_options(u8 *options) · line 585
Quoted 5 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +1
-0@@ -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.
Quoted 20 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +10
-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 */
ipv4/ipconfig.c static int __init nfsaddrs_config_setup( · line 1529
Quoted 10 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +7
-0@@ -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.
Quoted 5 lines
I don't think its very useful since you can simply get this information from
/proc/cmdlinein case something goes wrong, but if you insist at least give it a meaningful prefix.
Added.
Quoted 1 line
The initialization is unnecessary.
Removed.
Quoted 1 line
Should be >= I think.
Fixed.
Regards,
Rainer
----
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +24 -0
@@ -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);
Quoted 7 lines · Rainer Jochem
Quoted 4 lines
I don't think its very useful since you can simply get this information from
/proc/cmdlinein case something goes wrong, but if you insist at least give it a meaningful prefix.Added.
Quoted 7 lines
Quoted 1 line
The initialization is unnecessary.
Removed.
Quoted 1 line
Should be >= I think.
Fixed.
Looks fine, thanks.
From: Patrick McHardy <[email protected]>
Date: Wed, 14 Nov 2007 10:48:43 +0100
Quoted 10 lines
Quoted 9 lines · Rainer Jochem
Quoted 4 lines
I don't think its very useful since you can simply get this information from
/proc/cmdlinein case something goes wrong, but if you insist at least give it a meaningful prefix.Added.
Quoted 1 line
The initialization is unnecessary.
Quoted 7 lines
Quoted 5 lines
Removed.
Quoted 1 line
Should be >= I think.
Fixed.
Looks fine, thanks.
Applied to net-2.6.25, thanks everyone.
Rainer Jochem <[email protected]> :
[...]
ipv4/ipconfig.c __be32 ic_servaddr = NONE; /* Boot serve · line 143
Quoted 8 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +2
-0@@ -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 ?
Signature · 1 line
Ueimor
David Miller
maintainerFrom: Francois Romieu <[email protected]>
Date: Wed, 14 Nov 2007 23:11:19 +0100
Quoted 8 lines
Rainer Jochem <[email protected]> :
[...]Quoted 6 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +0
-0@@ -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 */
Quoted 4 lines
ipv4/ipconfig.c __be32 ic_servaddr = NONE; /* Boot serve · line 143
Quoted 2 lines
ipv4/ipconfig.c renamed from ipv4/ipconfig.c.orig +2
-0+static char vendor_class_identifier[253 ];/* vendor class identifier */ +
ic_dhcp_init_optionsis__init. Should it not be__initdata?
I think so and I've made that change in net-2.6.25, thanks.