Suggested patch: Sending the FQDN when booting via DHCP
Subsystems (3)
[re-sent without HTML encoding, and to the right aliases ...]
Hi all,
the following patch can be useful, in order to let the DHCP server accordingly update the DNS, when booting via DHCP.
This can be useful for 2 reasons:
1) on small systems, the embedded filesystem may even not have udhcpd
2) when booting nfsroot, the nfs server does not like when udhcpd in invoked, even when requested the same IP address.
Here is the patch, for 2.6.27-rc5. (Notice that it is the very first time I deliver a patch for Linux, and I may have missed some points on the procedure, if it is the case I apologize for that). What do you think about it ?
Any ideas or comments are welcome.
Thanks,
Thierry
net/ipv4/Kconfig +10 -0
@@ -162,6 +162,16 @@ config IP_PNP_DHCP must be operating on your network. Read for details. +config IP_PNP_DHCP_FQDN + bool "IP: DHCP FQDN" + default y + depends on IP_PNP_DHCP + ---help--- + If you want your Linux box to send its FQDN in the DHCP request, + in order to let the DHCP server know how to update the DNS, you + can say Y here. + +
config IP_PNP_BOOTP
bool "IP: BOOTP support"
depends on IP_PNP
net/ipv4/ipconfig.c +0 -0
@@ -565,6 +565,19 @@ struct bootp_pkt { /* BOOTP packet format */
#define DHCPRELEASE 7
#define DHCPINFORM 8
+/* DHCP options */
+
+#define DHCP_OPT_REQUESTED_IP 50
+#define DHCP_OPT_MESSAGE_TYPE 53
+#define DHCP_OPT_SERVER_ID 54
+#define DHCP_OPT_VEND_CLASS_ID 60
+#define DHCP_OPT_FQDN 81
+
+#define DHCP_FQDN_FLAGS_S 0x1 /* Server update */ +#define DHCP_FQDN_FLAGS_O 0x2 +#define DHCP_FQDN_FLAGS_E 0x4 +#define DHCP_FQDN_FLAGS_N 0x8
+
static int ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev);
static struct packet_type bootp_packet_type __initdata = { @@ -596,20 +609,35 @@ ic_dhcp_init_options(u8 *options)
memcpy(e, ic_bootp_cookie, 4); /* RFC1048 Magic Cookie */
e += 4;
- *e++ = 53; /* DHCP message type */
+ *e++ = DHCP_OPT_MESSAGE_TYPE; /* DHCP message type */
*e++ = 1;
*e++ = mt;
if (mt == DHCPREQUEST) {
- *e++ = 54; /* Server ID (IP address) */
- *e++ = 4;
+#ifdef CONFIG_IP_PNP_DHCP_FQDN
+ char * hostname = utsname()->nodename; + int len = strlen(hostname); + + *e++ = DHCP_OPT_FQDN; + *e++ = len + 3; /* Len with flags and R1+R2 */ + *e++ = DHCP_FQDN_FLAGS_S; + e += 2; + memcpy(e,hostname,len); + e += len;
+#endif /* CONFIG_IP_PNP_DHCP_FQDN */
+
+ *e++ = DHCP_OPT_SERVER_ID; /* Server ID (IP address) */
+ *e++ = 4; /* Len */
memcpy(e, &ic_servaddr, 4);
e += 4;- *e++ = 50; /* Requested IP address */
+ *e++ = DHCP_OPT_REQUESTED_IP; /* Requested IP address */
*e++ = 4;
memcpy(e, &ic_myaddr, 4);
e += 4;+
}
/* always? */
@@ -632,7 +660,7 @@ ic_dhcp_init_options(u8 *options)
if (*vendor_class_identifier) {
printk(KERN_INFO "DHCP: sending class identifier \"%s\"\n",
vendor_class_identifier);
- *e++ = 60; /* Class-identifier */
+ *e++ = DHCP_OPT_VEND_CLASS_ID; /* Class-identifier */
len = strlen(vendor_class_identifier);
*e++ = len;
memcpy(e, vendor_class_identifier, len);Quoted 6 lines · Thierry
[re-sent without HTML encoding, and to the right aliases ...]
Hi all,
the following patch can be useful, in order to let the DHCP server accordingly update the DNS, when booting via DHCP.
Quoted 8 lines
This can be useful for 2 reasons:
1) on small systems, the embedded filesystem may even not have udhcpd
2) when booting nfsroot, the nfs server does not like when udhcpd in invoked, even when requested the same IP address.Here is the patch, for 2.6.27-rc5. (Notice that it is the very first time I deliver a patch for Linux, and I may have missed some points on the procedure, if it is the case I apologize for that). What do you think about it ?
Any ideas or comments are welcome.
This should probably be a kernel command-line option, rather than a static config option.
-- Chris
David Miller
maintainerFrom: Chris Snook <[email protected]>
Date: Tue, 09 Sep 2008 23:16:37 -0400
Quoted 11 lines
Quoted 9 lines · Thierry
[re-sent without HTML encoding, and to the right aliases ...]
Hi all,
the following patch can be useful, in order to let the DHCP server accordingly update the DNS, when booting via DHCP. This can be useful for 2 reasons:
1) on small systems, the embedded filesystem may even not have udhcpd
2) when booting nfsroot, the nfs server does not like when udhcpd in invoked, even when requested the same IP address. Here is the patch, for 2.6.27-rc5. (Notice that it is the very first time I deliver a patch for Linux, and I may have missed some points on the procedure, if it is the case I apologize for that). What do you think about it ? Any ideas or comments are welcome.
Quoted 1 line
This should probably be a kernel command-line option, rather than a static config option.
Also:
1) The submitter's email client corrupted the patch making it unusable anyways, it munged tabs into spaces etc.
2) At this point in time ->nodename is going to be something like "(none)" and therefore not very useful. This only gets set after userland has started up.
So really, the nodename would need to be specified as well as a command line option for this to really be useful.