On Tuesday 01 April 2008 23:09, L. Gabriel Somlo wrote:
> Denys & All,
> 
> I noticed that udhcpc sends a default list of options in its request
> (i.e., all options listed with flag OPTION_REQ in options.c)
> 
> That's bad, at least when used with some versions of isc dhcpd, which
> will only include the requested options in a reply.
> 
> I know about the -O flag that can get udhcpc to request extra options,
> but what if I want to see options I didn't think about asking for ?
> Including a default option list in the request will always preclude me
> from seeing options I didn't know to ask for.

        USE_FEATURE_UDHCPC_ARPING( \
      "\n       -a,--arping     Use arping to validate offered address" \
        ) \
+     "\n       -o,--no-default-options Do not request options by default" \
        ) \
        SKIP_GETOPT_LONG( \

SKIP_GETOPT_LONG case also needs -o covered.


-               "O:"
+               "O:o:"

-o does not take a param, should be "O:o".

        packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
        for (i = 0; (c = dhcp_options[i].code) != 0; i++) {
-               if ((dhcp_options[i].flags & OPTION_REQ)
+               if (((dhcp_options[i].flags & OPTION_REQ) && 
!client_config.no_default_options) //vda
                 || (client_config.opt_mask[c >> 3] & (1 << (c & 7)))
                ) {
                        packet->options[end + OPT_DATA + len] = c;
                        len++;
                }

so, you create "empty" DHCP_PARAM_REQ. Why not just omitting it
at all like this?

-       add_param_req_option(&packet);
+       if (!client_config.no_default_options)
+               add_param_req_option(&packet);

> I've added the '-o' command line flag to udhcpc, which inhibits
> inclusion of default options in the request. Options can still be
> explicitly requested with -O.

I am thinking - maybe we should just junk the idea of "default"
options to ask for? We can ask user to always provide explicit
list of -O OPTs to ask. What do you think?

> I have also added a mechanism to request '-o' (actually, its long form
> --no-default-options) from ifupdown's /etc/network/interfaces:
> 
>       auto eth0
>       iface eth0 inet dhcp
>         nodefaultopts --no-default-options

Please take a look at attached patch - will this work for you?
--
vda
diff -d -urpN busybox.3/include/usage.h busybox.4/include/usage.h
--- busybox.3/include/usage.h	2008-03-31 21:26:17.000000000 +0200
+++ busybox.4/include/usage.h	2008-04-02 01:36:14.000000000 +0200
@@ -4116,7 +4116,7 @@
        "Adjust filesystem options on ext[23] filesystems"
 
 #define udhcpc_trivial_usage \
-       "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \
+       "[-Cfbnqtvo] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \
        "	[-p pidfile] [-r IP] [-s script] [-O dhcp-option]..." USE_FEATURE_UDHCP_PORT(" [-P N]")
 #define udhcpc_full_usage \
 	USE_GETOPT_LONG( \
@@ -4131,13 +4131,14 @@
      "\n	-t,--retries=N		Send up to N request packets" \
      "\n	-T,--timeout=N		Try to get a lease for N seconds (default 3)" \
      "\n	-A,--tryagain=N		Wait N seconds (default 20) after failure" \
+     "\n	-O,--request-option=OPT	Request DHCP option OPT from server" \
+     "\n	-o,--no-default-options	Do not request options by default" \
      "\n	-f,--foreground	Run in foreground" \
      "\n	-b,--background	Background if lease is not immediately obtained" \
      "\n	-S,--syslog	Log to syslog too" \
      "\n	-n,--now	Exit with failure if lease is not immediately obtained" \
      "\n	-q,--quit	Quit after obtaining lease" \
      "\n	-R,--release	Release IP on quit" \
-     "\n	-O,--request-option=OPT	Request DHCP option OPT from server" \
 	USE_FEATURE_UDHCP_PORT( \
      "\n	-P,--client-port N  Use port N instead of default 68" \
 	) \
@@ -4157,13 +4158,14 @@
      "\n	-t N		Send up to N request packets" \
      "\n	-T N		Try to get a lease for N seconds (default 3)" \
      "\n	-A N		Wait N seconds (default 20) after failure" \
+     "\n	-O OPT		Request DHCP option OPT from server" \
+     "\n	-o		Do not request options by default" \
      "\n	-f		Run in foreground" \
      "\n	-b		Background if lease is not immediately obtained" \
      "\n	-S		Log to syslog too" \
      "\n	-n		Exit with failure if lease is not immediately obtained" \
      "\n	-q		Quit after obtaining lease" \
      "\n	-R		Release IP on quit" \
-     "\n	-O OPT		Request DHCP option OPT from server" \
 	USE_FEATURE_UDHCP_PORT( \
      "\n	-P N		Use port N instead of default 68" \
 	) \
diff -d -urpN busybox.3/networking/ifupdown.c busybox.4/networking/ifupdown.c
--- busybox.3/networking/ifupdown.c	2008-03-31 21:26:06.000000000 +0200
+++ busybox.4/networking/ifupdown.c	2008-04-02 01:47:14.000000000 +0200
@@ -476,7 +476,8 @@ static const struct dhcp_client_t ext_dh
 		"pump -i %iface% -k",
 	},
 	{ "udhcpc",
-		"udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ -t %retries%]]",
+		"udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]]"
+				"[[ -s %script%]][[ %udhcpc_opts%]]",
 		"kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
 	},
 };
@@ -507,7 +508,7 @@ static int dhcp_up(struct interface_defn
 		return 0;
 #endif
 	return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
-			"-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ -t %retries%]]",
+			"-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ %udhcpc_opts%]]",
 			ifd, exec);
 }
 #else
diff -d -urpN busybox.3/networking/udhcp/clientpacket.c busybox.4/networking/udhcp/clientpacket.c
--- busybox.3/networking/udhcp/clientpacket.c	2008-03-31 21:26:05.000000000 +0200
+++ busybox.4/networking/udhcp/clientpacket.c	2008-04-02 01:49:01.000000000 +0200
@@ -62,6 +62,9 @@ static void add_param_req_option(struct 
 	int end = end_option(packet->options);
 	int i, len = 0;
 
+	if (client_config.no_default_options)
+		return;
+
 	packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
 	for (i = 0; (c = dhcp_options[i].code) != 0; i++) {
 		if ((dhcp_options[i].flags & OPTION_REQ)
@@ -107,7 +110,9 @@ int send_discover(uint32_t xid, uint32_t
 	/* Explicitly saying that we want RFC-compliant packets helps
 	 * some buggy DHCP servers to NOT send bigger packets */
 	add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576));
+
 	add_param_req_option(&packet);
+
 	bb_info_msg("Sending discover...");
 	return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
 			SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
@@ -125,8 +130,8 @@ int send_selecting(uint32_t xid, uint32_
 
 	add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
 	add_simple_option(packet.options, DHCP_SERVER_ID, server);
-
 	add_param_req_option(&packet);
+
 	addr.s_addr = requested;
 	bb_info_msg("Sending select for %s...", inet_ntoa(addr));
 	return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
diff -d -urpN busybox.3/networking/udhcp/dhcpc.c busybox.4/networking/udhcp/dhcpc.c
--- busybox.3/networking/udhcp/dhcpc.c	2008-03-31 21:26:05.000000000 +0200
+++ busybox.4/networking/udhcp/dhcpc.c	2008-04-02 01:36:34.000000000 +0200
@@ -182,6 +182,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSE
 		OPT_W = 1 << 21,
 #endif
 		OPT_P = 1 << 22,
+		OPT_o = 1 << 23,
 	};
 #if ENABLE_GETOPT_LONG
 	static const char udhcpc_longopts[] ALIGN1 =
@@ -211,6 +212,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSE
 #if ENABLE_FEATURE_UDHCP_PORT
 		"client-port\0"	   Required_argument "P"
 #endif
+		"no-default-options\0" No_argument   "o"
 		;
 #endif
 	/* Default options. */
@@ -230,7 +232,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSE
 	opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:"
 		USE_FEATURE_UDHCPC_ARPING("aW:")
 		USE_FEATURE_UDHCP_PORT("P:")
-		"O:"
+		"O:o"
 		, &str_c, &str_V, &str_h, &str_h, &str_F
 		, &client_config.interface, &client_config.pidfile, &str_r
 		, &client_config.script
@@ -291,6 +293,8 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSE
 		SERVER_PORT = CLIENT_PORT - 1;
 	}
 #endif
+	if (opt & OPT_o)
+		client_config.no_default_options = 1;
 	while (list_O) {
 		int n = index_in_strings(dhcp_option_strings, list_O->data);
 		if (n < 0)
diff -d -urpN busybox.3/networking/udhcp/dhcpc.h busybox.4/networking/udhcp/dhcpc.h
--- busybox.3/networking/udhcp/dhcpc.h	2008-03-31 21:26:05.000000000 +0200
+++ busybox.4/networking/udhcp/dhcpc.h	2008-04-02 01:36:48.000000000 +0200
@@ -21,6 +21,7 @@ struct client_config_t {
 	char release_on_quit;           /* Perform release on quit */
 	char abort_if_no_lease;         /* Abort if no lease */
 	char background_if_no_lease;    /* Fork to background if no lease */
+	char no_default_options;        /* Do not include default optins in request */
 	const char *interface;          /* The name of the interface to use */
 	char *pidfile;                  /* Optionally store the process ID */
 	const char *script;             /* User script to run at dhcp events */
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to