Skip to content

Instantly share code, notes, and snippets.

@peter-kolenic
Last active August 29, 2015 14:13
Show Gist options
  • Save peter-kolenic/2e20ce41f0d6e6f6eeb2 to your computer and use it in GitHub Desktop.
Save peter-kolenic/2e20ce41f0d6e6f6eeb2 to your computer and use it in GitHub Desktop.
busybox options -I IP, --server-filter IP for https://github.com/imincik/gis-lab/issues/333: patch against ubuntu precise package
diff --git a/debian/config/pkg/deb b/debian/config/pkg/deb
index 506256e..d9f989a 100644
--- a/debian/config/pkg/deb
+++ b/debian/config/pkg/deb
@@ -831,6 +831,7 @@ CONFIG_UDHCP_DEBUG=0
CONFIG_FEATURE_UDHCP_RFC3397=y
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
+CONFIG_FEATURE_UDHCPC_FILTER=y
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS=""
# CONFIG_UDPSVD is not set
# CONFIG_VCONFIG is not set
diff --git a/debian/config/pkg/initramfs b/debian/config/pkg/initramfs
index 37bef92..3875cb1 100644
--- a/debian/config/pkg/initramfs
+++ b/debian/config/pkg/initramfs
@@ -819,6 +819,7 @@ CONFIG_UDHCP_DEBUG=0
# CONFIG_FEATURE_UDHCP_RFC3397 is not set
CONFIG_UDHCPC_DEFAULT_SCRIPT=""
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=0
+CONFIG_FEATURE_UDHCPC_FILTER=y
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS=""
# CONFIG_UDPSVD is not set
# CONFIG_VCONFIG is not set
diff --git a/debian/config/pkg/static b/debian/config/pkg/static
index 76305c0..ddfb921 100644
--- a/debian/config/pkg/static
+++ b/debian/config/pkg/static
@@ -831,6 +831,7 @@ CONFIG_UDHCP_DEBUG=0
CONFIG_FEATURE_UDHCP_RFC3397=y
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
+CONFIG_FEATURE_UDHCPC_FILTER=y
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"
# CONFIG_UDPSVD is not set
CONFIG_VCONFIG=y
diff --git a/debian/config/pkg/udeb b/debian/config/pkg/udeb
index ce64299..8524aca 100644
--- a/debian/config/pkg/udeb
+++ b/debian/config/pkg/udeb
@@ -823,6 +823,7 @@ CONFIG_UDHCP_DEBUG=0
CONFIG_FEATURE_UDHCP_RFC3397=y
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
+CONFIG_FEATURE_UDHCPC_FILTER=y
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS=""
# CONFIG_UDPSVD is not set
CONFIG_VCONFIG=y
diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src
index dcd493f..f2db190 100644
--- a/networking/udhcp/Config.src
+++ b/networking/udhcp/Config.src
@@ -130,3 +130,11 @@ config UDHCPC_SLACK_FOR_BUGGY_SERVERS
maximum size of entire IP packet, and sends packets which are
28 bytes too large.
Seednet (ISP) VDSL: sends packets 2 bytes too large.
+
+config FEATURE_UDHCPC_FILTER
+ bool "Add udhcpc filter option ignoring all but one server"
+ default n
+ depends on UDHCPC
+ help
+ If selected, udhcpc will have option to ignore all DHCP responses not
+ comming from the server IP specified on command line.
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 5bc00f4..ca8ff14 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -894,6 +894,9 @@ static void client_background(void)
//usage: "\n -H,-h,--hostname NAME Send NAME as client hostname (default none)"
//usage: "\n -V,--vendorclass VENDOR Vendor identifier (default 'udhcp VERSION')"
//usage: "\n -C,--clientid-none Don't send MAC as client identifier"
+//usage: IF_FEATURE_UDHCPC_FILTER(
+//usage: "\n -I,--server-filter IP Ignore responses from servers other than given one"
+//usage: )
//usage: IF_UDHCP_VERBOSE(
//usage: "\n -v Verbose"
//usage: )
@@ -931,6 +934,9 @@ static void client_background(void)
//usage: "\n -H,-h NAME Send NAME as client hostname (default none)"
//usage: "\n -V VENDOR Vendor identifier (default 'udhcp VERSION')"
//usage: "\n -C Don't send MAC as client identifier"
+//usage: IF_FEATURE_UDHCPC_FILTER(
+//usage: "\n -I IP Ignore responses from servers other than given one"
+//usage: )
//usage: IF_UDHCP_VERBOSE(
//usage: "\n -v Verbose"
//usage: )
@@ -942,6 +948,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
uint8_t *temp, *message;
const char *str_V, *str_h, *str_F, *str_r;
IF_FEATURE_UDHCP_PORT(char *str_P;)
+ IF_FEATURE_UDHCPC_FILTER(const char *str_I;)
void *clientid_mac_ptr;
llist_t *list_O = NULL;
llist_t *list_x = NULL;
@@ -961,6 +968,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
struct timeval tv;
struct dhcp_packet packet;
fd_set rfds;
+ IF_FEATURE_UDHCPC_FILTER(uint32_t server_filter_addr;)
#if ENABLE_LONG_OPTS
static const char udhcpc_longopts[] ALIGN1 =
@@ -986,6 +994,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
"background\0" No_argument "b"
IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a")
IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P")
+ IF_FEATURE_UDHCPC_FILTER("server-filter\0" Required_argument "I")
;
#endif
enum {
@@ -1014,9 +1023,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
USE_FOR_MMU( OPTBIT_b,)
IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,)
IF_FEATURE_UDHCP_PORT( OPTBIT_P,)
+ IF_FEATURE_UDHCPC_FILTER(OPTBIT_I,)
USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,)
IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,)
IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,)
+ IF_FEATURE_UDHCPC_FILTER(OPT_I = 1 << OPTBIT_I,)
};
/* Default options */
@@ -1038,6 +1049,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
USE_FOR_MMU("b")
IF_FEATURE_UDHCPC_ARPING("a")
IF_FEATURE_UDHCP_PORT("P:")
+ IF_FEATURE_UDHCPC_FILTER("I:")
"v"
, &str_V, &str_h, &str_h, &str_F
, &client_config.interface, &client_config.pidfile, &str_r /* i,p */
@@ -1046,6 +1058,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
, &list_O
, &list_x
IF_FEATURE_UDHCP_PORT(, &str_P)
+ IF_FEATURE_UDHCPC_FILTER(, &str_I)
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
, &dhcp_verbose
#endif
@@ -1123,6 +1136,17 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
logmode |= LOGMODE_SYSLOG;
}
+#if ENABLE_FEATURE_UDHCPC_FILTER
+ if (opt & OPT_I) {
+ struct in_addr temp_addr;
+ if(inet_aton(str_I, &temp_addr)) {
+ server_filter_addr = temp_addr.s_addr;
+ } else {
+ bb_perror_msg_and_die("server filter address can't be parsed:%s",str_I);
+ }
+ }
+#endif
+
/* Make sure fd 0,1,2 are open */
bb_sanitize_stdio();
/* Equivalent of doing a fflush after every \n */
@@ -1369,6 +1393,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
continue;
}
+#if ENABLE_FEATURE_UDHCPC_FILTER
+ if (packet.siaddr_nip != server_filter_addr) {
+ log1("siaddr_nip %x does not match our server %x, ignoring packet",packet.siaddr_nip, server_filter_addr);
+ continue;
+ }
+#endif
message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE);
if (message == NULL) {
bb_error_msg("no message type option, ignoring packet");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment