[OpenWrt-Devel] [PATCH 2/3] busybox: allow own class B range to be used for zeroconf
Michel Stam
m.stam at fugro.nl
Thu Oct 2 09:41:35 EDT 2014
169.254 may be used by local networks. This patch allows specifying
your own IP range.
Signed-off-by: Michel Stam <m.stam at fugro.nl>
---
.../busybox/patches/450-zcip-own-ip-range.patch | 110 +++++++++++++++++++++
1 file changed, 110 insertions(+)
create mode 100644 package/utils/busybox/patches/450-zcip-own-ip-range.patch
diff --git a/package/utils/busybox/patches/450-zcip-own-ip-range.patch b/package/utils/busybox/patches/450-zcip-own-ip-range.patch
new file mode 100644
index 0000000..7193402
--- /dev/null
+++ b/package/utils/busybox/patches/450-zcip-own-ip-range.patch
@@ -0,0 +1,110 @@
+From bddeb00a36df927c8372fc40b96e6e8dd13e6609 Mon Sep 17 00:00:00 2001
+From: Michel Stam <m.stam at fugro.nl>
+Date: Thu, 25 Sep 2014 13:43:33 +0200
+Subject: [PATCH] zcip: allow our own class B range to be used for ZeroConf
+
+169.254 may already be used by a local network. This patch allows
+specifying your own IP range.
+
+Signed-off-by: Michel Stam <m.stam at fugro.nl>
+---
+ networking/zcip.c | 21 ++++++++++++++++++---
+ 1 file changed, 18 insertions(+), 3 deletions(-)
+
+diff --git a/networking/zcip.c b/networking/zcip.c
+index 45d1f7c..2a57543 100644
+--- a/networking/zcip.c
++++ b/networking/zcip.c
+@@ -30,6 +30,7 @@
+ //usage: "\n -f Run in foreground"
+ //usage: "\n -q Quit after obtaining address"
+ //usage: "\n -r 169.254.x.x Request this address first"
++//usage: "\n -l w.x.0.0 Use this class B range instead of 169.254"
+ //usage: "\n -v Verbose"
+ //usage: "\n"
+ //usage: "\nWith no -q, runs continuously monitoring for ARP conflicts,"
+@@ -87,10 +88,12 @@ enum {
+ struct globals {
+ struct sockaddr saddr;
+ struct ether_addr eth_addr;
++ uint32_t localnet_addr;
+ } FIX_ALIASING;
+ #define G (*(struct globals*)&bb_common_bufsiz1)
+ #define saddr (G.saddr )
+ #define eth_addr (G.eth_addr)
++#define localnet_addr (G.localnet_addr)
+ #define INIT_G() do { } while (0)
+
+
+@@ -105,7 +108,7 @@ static uint32_t pick(void)
+ do {
+ tmp = rand() & IN_CLASSB_HOST;
+ } while (tmp > (IN_CLASSB_HOST - 0x0200));
+- return htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
++ return htonl((localnet_addr + 0x0100) + tmp);
+ }
+
+ /**
+@@ -197,6 +200,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
+ {
+ int state;
+ char *r_opt;
++ char *l_opt;
+ unsigned opts;
+
+ // ugly trick, but I want these zeroed in one go
+@@ -204,6 +208,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
+ const struct in_addr null_ip;
+ const struct ether_addr null_addr;
+ struct in_addr ip;
++ struct in_addr net;
+ struct ifreq ifr;
+ int timeout_ms; /* must be signed */
+ unsigned conflicts;
+@@ -215,6 +220,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
+ #define null_ip (L.null_ip )
+ #define null_addr (L.null_addr )
+ #define ip (L.ip )
++#define net (L.net )
+ #define ifr (L.ifr )
+ #define timeout_ms (L.timeout_ms)
+ #define conflicts (L.conflicts )
+@@ -224,6 +230,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
+ #define verbose (L.verbose )
+
+ memset(&L, 0, sizeof(L));
++ localnet_addr = LINKLOCAL_ADDR; // Assume default 169.254.x.x
+ INIT_G();
+
+ #define FOREGROUND (opts & 1)
+@@ -231,7 +238,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
+ // parse commandline: prog [options] ifname script
+ // exactly 2 args; -v accumulates and implies -f
+ opt_complementary = "=2:vv:vf";
+- opts = getopt32(argv, "fqr:v", &r_opt, &verbose);
++ opts = getopt32(argv, "fqr:l:v", &r_opt, &l_opt, &verbose);
+ #if !BB_MMU
+ // on NOMMU reexec early (or else we will rerun things twice)
+ if (!FOREGROUND)
+@@ -246,9 +253,17 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
+ openlog(applet_name, 0, LOG_DAEMON);
+ logmode |= LOGMODE_SYSLOG;
+ }
++ if (opts & 8) { // -l n.n.n.n
++ if (inet_aton(l_opt, &net) == 0
++ || (net.s_addr & htonl(IN_CLASSB_NET)) != net.s_addr
++ ) {
++ bb_error_msg_and_die("invalid network address");
++ }
++ localnet_addr = ntohl(net.s_addr);
++ }
+ if (opts & 4) { // -r n.n.n.n
+ if (inet_aton(r_opt, &ip) == 0
+- || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR
++ || (ntohl(ip.s_addr) & IN_CLASSB_NET) != localnet_addr
+ ) {
+ bb_error_msg_and_die("invalid link address");
+ }
+--
+1.7.12.1
+
--
1.7.12.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list