From 53626cd06a3ef05ed847daea802ef0aa9661caa7 Mon Sep 17 00:00:00 2001
From: Anders Darander <anders@chargestorm.se>
Date: Thu, 3 Nov 2011 08:51:31 +0100
Subject: [PATCH] busybox-udhcpc-no_deconfig.patch

Upstream-Status: Pending

Add a new option -D to the udhcpc client that allows for
dhcp renewal to occur without having to down the interface
in the process.

Signed-off-by: Greg Moffatt <greg.moffatt@windriver.com>

Updated to latest Busybox 1.17.3

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>

Updated to Busybox 1.18.4
option spec is changed

Signed-off-by: Qing He <qing.he@intel.com>

Updated to Busybox 1.19.3

Signed-off-by: Anders Darander <anders@chargestorm.se>

Fixed options -b, -a and -P.

Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
---
 networking/udhcp/dhcpc.c                       | 29 ++++++++++++++++------
 1 file changed, 21 insertions(+), 8 deletions(-)

Index: busybox-1.31.0/networking/udhcp/dhcpc.c
===================================================================
--- busybox-1.31.0.orig/networking/udhcp/dhcpc.c
+++ busybox-1.31.0/networking/udhcp/dhcpc.c
@@ -48,6 +48,8 @@
 };
 #endif
 
+/* option whether to down the interface when reconfiguring */
+static int allow_deconfig = 1;
 
 /* "struct client_data_t client_data" is in bb_common_bufsiz1 */
 
@@ -103,8 +105,10 @@
 	OPT_x = 1 << 18,
 	OPT_f = 1 << 19,
 	OPT_B = 1 << 20,
+	OPT_D = 1 << 21,
 /* The rest has variable bit positions, need to be clever */
 	OPTBIT_B = 20,
+	OPTBIT_D = 21,
 	USE_FOR_MMU(             OPTBIT_b,)
 	IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,)
 	IF_FEATURE_UDHCP_PORT(   OPTBIT_P,)
@@ -1124,7 +1128,8 @@
 		client_data.state = RENEW_REQUESTED;
 		break;
 	case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
-		udhcp_run_script(NULL, "deconfig");
+		if (allow_deconfig)
+			udhcp_run_script(NULL, "deconfig");
 	case REQUESTING:
 	case RELEASED:
 		change_listen_mode(LISTEN_RAW);
@@ -1160,7 +1165,8 @@
  * Users requested to be notified in all cases, even if not in one
  * of the states above.
  */
-	udhcp_run_script(NULL, "deconfig");
+	if (allow_deconfig)
+		udhcp_run_script(NULL, "deconfig");
 
 	change_listen_mode(LISTEN_NONE);
 	client_data.state = RELEASED;
@@ -1278,7 +1284,7 @@
 	/* Parse command line */
 	opt = getopt32long(argv, "^"
 		/* O,x: list; -T,-t,-A take numeric param */
-		"CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB"
+		"CV:H:h:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fBD"
 		USE_FOR_MMU("b")
 		IF_FEATURE_UDHCPC_ARPING("a::")
 		IF_FEATURE_UDHCP_PORT("P:")
@@ -1389,6 +1395,10 @@
 		logmode |= LOGMODE_SYSLOG;
 	}
 
+	if (opt & OPT_D) {
+		allow_deconfig = 0;
+	}
+
 	/* Create pidfile */
 	write_pidfile(client_data.pidfile);
 	/* Goes to stdout (unless NOMMU) and possibly syslog */
@@ -1397,7 +1407,8 @@
 	srand(monotonic_us());
 
 	client_data.state = INIT_SELECTING;
-	udhcp_run_script(NULL, "deconfig");
+	if (allow_deconfig)
+		udhcp_run_script(NULL, "deconfig");
 	change_listen_mode(LISTEN_RAW);
 	packet_num = 0;
 	timeout = 0;
@@ -1570,7 +1581,8 @@
 				}
 				/* Timed out, enter init state */
 				bb_info_msg("lease lost, entering init state");
-				udhcp_run_script(NULL, "deconfig");
+				if (allow_deconfig)
+					udhcp_run_script(NULL, "deconfig");
 				client_data.state = INIT_SELECTING;
 				client_data.first_secs = 0; /* make secs field count from 0 */
 				/*timeout = 0; - already is */
@@ -1762,8 +1774,10 @@
 							"(got ARP reply), declining");
 						send_decline(/*xid,*/ server_addr, packet.yiaddr);
 
-						if (client_data.state != REQUESTING)
-							udhcp_run_script(NULL, "deconfig");
+						if (client_data.state != REQUESTING) {
+							if (allow_deconfig)
+								udhcp_run_script(NULL, "deconfig");
+						}
 						change_listen_mode(LISTEN_RAW);
 						client_data.state = INIT_SELECTING;
 						client_data.first_secs = 0; /* make secs field count from 0 */
@@ -1832,8 +1846,10 @@
 				/* return to init state */
 				bb_info_msg("received %s", "DHCP NAK");
 				udhcp_run_script(&packet, "nak");
-				if (client_data.state != REQUESTING)
-					udhcp_run_script(NULL, "deconfig");
+				if (client_data.state != REQUESTING) {
+					if (allow_deconfig)
+						udhcp_run_script(NULL, "deconfig");
+				}
 				change_listen_mode(LISTEN_RAW);
 				sleep(3); /* avoid excessive network traffic */
 				client_data.state = INIT_SELECTING;
