[oe-commits] org.oe.dreambox busybox-1.01: add zeroconf support
tmbinc commit
oe at amethyst.openembedded.net
Wed May 21 23:32:18 UTC 2008
busybox-1.01: add zeroconf support
Author: tmbinc at openembedded.org
Branch: org.openembedded.dreambox
Revision: e63a9e517cb10924d2b788d339328d6313bcbf57
ViewMTN: http://monotone.openembedded.org/revision/info/e63a9e517cb10924d2b788d339328d6313bcbf57
Files:
1
packages/busybox/busybox-1.01/zeroconf.patch
packages/busybox/busybox_1.01.bb
Diffs:
#
# mt diff -r530a04cb8d7e7753457eee0876fd0d6b95b76f3d -re63a9e517cb10924d2b788d339328d6313bcbf57
#
#
#
# add_file "packages/busybox/busybox-1.01/zeroconf.patch"
# content [a1c8e0caa3d0bd1bdedfea6b167236a94ef15dbd]
#
# patch "packages/busybox/busybox_1.01.bb"
# from [eebf4a596fa27252fbbcbd924115c2698247a5b0]
# to [dbb48d4893367d86e0f3db393be2f146b4e37846]
#
============================================================
--- packages/busybox/busybox-1.01/zeroconf.patch a1c8e0caa3d0bd1bdedfea6b167236a94ef15dbd
+++ packages/busybox/busybox-1.01/zeroconf.patch a1c8e0caa3d0bd1bdedfea6b167236a94ef15dbd
@@ -0,0 +1,1184 @@
+Index: busybox-1.01/include/usage.h
+===================================================================
+--- busybox-1.01.orig/include/usage.h 2008-05-21 22:31:10.000000000 +0200
++++ busybox-1.01/include/usage.h 2008-05-21 22:31:24.000000000 +0200
+@@ -2625,7 +2625,7 @@
+ "/dev/tty2\n"
+
+ #define udhcpc_trivial_usage \
+- "[-Cfbnqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]"
++ "[-Cfbznqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]"
+ #define udhcpc_full_usage \
+ "\t-c,\t--clientid=CLIENTID\tSet client identifier\n" \
+ "\t-C,\t--clientid-none\tSuppress default client identifier\n" \
+@@ -2634,6 +2634,7 @@
+ "\t-f,\t--foreground\tDo not fork after getting lease\n" \
+ "\t-b,\t--background\tFork to background if lease cannot be immediately negotiated.\n" \
+ "\t-i,\t--interface=INTERFACE\tInterface to use (default: eth0)\n" \
++ "\t-z,\t--zeroconf\tWith Zeroconf address attibution support\n" \
+ "\t-n,\t--now\tExit with failure if lease cannot be immediately negotiated.\n" \
+ "\t-p,\t--pidfile=file\tStore process ID of daemon in file\n" \
+ "\t-q,\t--quit\tQuit after obtaining lease\n" \
+Index: busybox-1.01/networking/udhcp/Config.in
+===================================================================
+--- busybox-1.01.orig/networking/udhcp/Config.in 2008-05-21 22:31:10.000000000 +0200
++++ busybox-1.01/networking/udhcp/Config.in 2008-05-21 22:31:24.000000000 +0200
+@@ -26,6 +26,18 @@
+
+ See http://udhcp.busybox.net for further details.
+
++config CONFIG_UDHCPC_ZEROCONF
++ bool "udhcp Client with zeroconf support"
++ default n
++ depends on CONFIG_UDHCPC
++ help
++ Zeroconf support allows udhcpc to assign static address on dhcp
++ server less network.
++
++ Take a look to busybox/networking/udhcp/samples/ for udhcpc script
++
++ http://udhcp.busybox.net/lists/udhcp/2005-May/000124.html
++
+ config CONFIG_DUMPLEASES
+ bool "Lease display utility (dumpleases)"
+ default n
+Index: busybox-1.01/networking/udhcp/Makefile.in
+===================================================================
+--- busybox-1.01.orig/networking/udhcp/Makefile.in 2008-05-21 22:31:10.000000000 +0200
++++ busybox-1.01/networking/udhcp/Makefile.in 2008-05-21 22:31:24.000000000 +0200
+@@ -34,11 +34,25 @@
+ endif
+ endif
+
++ifeq ($(CONFIG_UDHCPC_ZEROCONF), y)
++# this if you want to include Zeroconf support directly in DHCP client
++ZEROCONF=1
++endif
++
++
++ifdef ZEROCONF
++CFLAGS += -DUDHCP_ZEROCONF
++endif
++
+ UDHCP-y:=
+ UDHCP-$(CONFIG_UDHCP_SHARED) += common.c options.c packet.c pidfile.c \
+ signalpipe.c socket.c
+ UDHCP-$(CONFIG_UDHCPC) += dhcpc.c clientpacket.c clientsocket.c \
+ script.c
++ifdef ZEROCONF
++UDHCP-$(CONFIG_UDHCPC) += zeroconf.c
++endif
++
+ UDHCP-$(CONFIG_UDHCPD) += dhcpd.c arpping.c files.c leases.c \
+ serverpacket.c static_leases.c
+ UDHCP-$(CONFIG_DUMPLEASES) += dumpleases.c
+Index: busybox-1.01/networking/udhcp/dhcpc.c
+===================================================================
+--- busybox-1.01.orig/networking/udhcp/dhcpc.c 2008-05-21 22:31:10.000000000 +0200
++++ busybox-1.01/networking/udhcp/dhcpc.c 2008-05-21 22:31:24.000000000 +0200
+@@ -43,6 +43,9 @@
+ #include "socket.h"
+ #include "common.h"
+ #include "signalpipe.h"
++#ifdef UDHCP_ZEROCONF
++#include "zeroconf.h"
++#endif
+
+ static int state;
+ static unsigned long requested_ip; /* = 0 */
+@@ -57,6 +60,10 @@
+ #define LISTEN_RAW 2
+ static int listen_mode;
+
++/* Warning: 2k038 bug :P */
++
++#define TIMEOUT_INFINITE 0x7fffffff
++
+ struct client_config_t client_config = {
+ /* Default options. */
+ abort_if_no_lease: 0,
+@@ -85,6 +92,7 @@
+ " -b, --background Fork to background if lease cannot be\n"
+ " immediately negotiated.\n"
+ " -i, --interface=INTERFACE Interface to use (default: eth0)\n"
++" -z, --zeroconf With Zeroconf address attibution support\n"
+ " -n, --now Exit with failure if lease cannot be\n"
+ " immediately negotiated.\n"
+ " -p, --pidfile=file Store process ID of daemon in file\n"
+@@ -127,6 +135,9 @@
+ break;
+ case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
+ run_script(NULL, "deconfig");
++#ifdef UDHCP_ZEROCONF
++ zeroconf_event(ZEROCONF_EVENT_DHCPOUT);
++#endif
+ case REQUESTING:
+ case RELEASED:
+ change_mode(LISTEN_RAW);
+@@ -157,6 +168,9 @@
+ temp_addr.s_addr = requested_ip;
+ LOG(LOG_INFO, "Unicasting a release of %s to %s",
+ inet_ntoa(temp_addr), buffer);
++#ifdef UDHCP_ZEROCONF
++ zeroconf_event(ZEROCONF_EVENT_DHCPOUT);
++#endif
+ send_release(server_addr, requested_ip); /* unicast */
+ run_script(NULL, "deconfig");
+ }
+@@ -164,7 +178,7 @@
+
+ change_mode(LISTEN_NONE);
+ state = RELEASED;
+- timeout = 0x7fffffff;
++ timeout = TIMEOUT_INFINITE;
+ }
+
+
+@@ -191,9 +205,12 @@
+ int c, len;
+ struct dhcpMessage packet;
+ struct in_addr temp_addr;
+- long now;
++ unsigned long now;
+ int max_fd;
+ int sig;
++#ifdef UDHCP_ZEROCONF
++ int with_zeroconf = 0;
++#endif
+ int no_clientid = 0;
+ char hostbuf[256]; /* SUSv2: hostnames are <= 255 bytes */
+
+@@ -205,6 +222,7 @@
+ {"hostname", required_argument, 0, 'H'},
+ {"hostname", required_argument, 0, 'h'},
+ {"interface", required_argument, 0, 'i'},
++ {"zeroconf", no_argument, 0, 'z'},
+ {"now", no_argument, 0, 'n'},
+ {"pidfile", required_argument, 0, 'p'},
+ {"quit", no_argument, 0, 'q'},
+@@ -226,7 +244,7 @@
+ /* get options */
+ while (1) {
+ int option_index = 0;
+- c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:t:v", arg_options, &option_index);
++ c = getopt_long(argc, argv, "c:fbH:h:i:znp:qr:s:t:v", arg_options, &option_index);
+ if (c == -1) break;
+
+ switch (c) {
+@@ -262,6 +280,13 @@
+ case 'i':
+ client_config.interface = optarg;
+ break;
++ case 'z':
++#ifdef UDHCP_ZEROCONF
++ with_zeroconf = 1;
++#else
++ printf("Zeroconf support not included in this build.\n");
++#endif
++ break;
+ case 'n':
+ client_config.abort_if_no_lease = 1;
+ break;
+@@ -296,6 +321,11 @@
+ NULL, client_config.arp) < 0)
+ return 1;
+
++#ifdef UDHCP_ZEROCONF
++ zeroconf_init(with_zeroconf, client_config.arp, client_config.interface,
++ client_config.ifindex);
++#endif
++
+ /* if not set, and not suppressed, setup the default client ID */
+ if (!client_config.clientid && !no_clientid) {
+ client_config.clientid = xmalloc(6 + 3);
+@@ -310,12 +340,25 @@
+
+ state = INIT_SELECTING;
+ run_script(NULL, "deconfig");
++
++#ifdef UDHCP_ZEROCONF
++ zeroconf_event(ZEROCONF_EVENT_DHCPOUT);
++#endif
++
+ change_mode(LISTEN_RAW);
+
+ for (;;) {
+
+- tv.tv_sec = timeout - uptime();
++ /* configures timeout for select(), the smaller between DHCP and Zeroconf timeouts */
++#ifdef UDHCP_ZEROCONF
++ zeroconf_set_smallest_timeout(&tv, timeout);
++#else
++ tv.tv_sec = timeout - time(NULL);
++ if (tv.tv_sec < 0) {
++ tv.tv_sec = 0;
++ }
+ tv.tv_usec = 0;
++#endif
+
+ if (listen_mode != LISTEN_NONE && fd < 0) {
+ if (listen_mode == LISTEN_KERNEL)
+@@ -327,16 +370,38 @@
+ return 0;
+ }
+ }
+- max_fd = udhcp_sp_fd_set(&rfds, fd);
+
+- if (tv.tv_sec > 0) {
++#ifdef UDHCP_ZEROCONF
++ if (zeroconf_fd > -1) {
++ max_fd = udhcp_sp_fd_set2(&rfds, fd, zeroconf_fd);
++ } else {
++ max_fd = udhcp_sp_fd_set(&rfds, fd);
++ }
++#else
++ max_fd = udhcp_sp_fd_set(&rfds, fd);
++#endif
++ if (tv.tv_sec > 0 || tv.tv_usec > 0) {
+ DEBUG(LOG_INFO, "Waiting on select...");
+ retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
+ } else retval = 0; /* If we already timed out, fall through */
+
+- now = uptime();
++ now = time(NULL);
+ if (retval == 0) {
+- /* timeout dropped to zero */
++ /* timeout, must be forwarded to Zeroconf and DHCP state machines */
++
++#ifdef UDHCP_ZEROCONF
++ /* Zeroconf has its own timeout tests, just tick it */
++ zeroconf_event(ZEROCONF_EVENT_TICK);
++#endif
++
++ if (timeout > now) {
++ /* it is not DHCP's timeout */
++ continue;
++ }
++
++ DEBUG(LOG_INFO, "DHCP timeout");
++
++ /* DHCP timeout dropped to zero */
+ switch (state) {
+ case INIT_SELECTING:
+ if (packet_num < 3) {
+@@ -375,6 +440,9 @@
+ } else {
+ /* timed out, go back to init state */
+ if (state == RENEW_REQUESTED) run_script(NULL, "deconfig");
++#ifdef UDHCP_ZEROCONF
++ zeroconf_event(ZEROCONF_EVENT_DHCPOUT);
++#endif
+ state = INIT_SELECTING;
+ timeout = now;
+ packet_num = 0;
+@@ -409,6 +477,9 @@
+ state = INIT_SELECTING;
+ LOG(LOG_INFO, "Lease lost, entering init state");
+ run_script(NULL, "deconfig");
++#ifdef UDHCP_ZEROCONF
++ zeroconf_event(ZEROCONF_EVENT_DHCPOUT);
++#endif
+ timeout = now;
+ packet_num = 0;
+ change_mode(LISTEN_RAW);
+@@ -422,10 +493,21 @@
+ break;
+ case RELEASED:
+ /* yah, I know, *you* say it would never happen */
+- timeout = 0x7fffffff;
++ timeout = TIMEOUT_INFINITE;
+ break;
+ }
++#ifdef UDHCP_ZEROCONF
++ } else if (retval > 0 && zeroconf_fd > -1 && FD_ISSET(zeroconf_fd, &rfds)) {
++ /* zeroconf packet is ready, process */
++
++ DEBUG(LOG_INFO, "Socket data for Zeroconf");
++
++ zeroconf_event(ZEROCONF_EVENT_SOCKETREADY);
++#endif
+ } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) {
++
++ DEBUG(LOG_INFO, "Socket data for DHCP");
++
+ /* a packet is ready, read it */
+
+ if (listen_mode == LISTEN_KERNEL)
+@@ -496,6 +578,9 @@
+ start = now;
+ timeout = t1 + start;
+ requested_ip = packet.yiaddr;
++#ifdef UDHCP_ZEROCONF
++ zeroconf_event(ZEROCONF_EVENT_DHCPIN);
++#endif
+ run_script(&packet,
+ ((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
+
+@@ -510,8 +595,12 @@
+ /* return to init state */
+ LOG(LOG_INFO, "Received DHCP NAK");
+ run_script(&packet, "nak");
+- if (state != REQUESTING)
++ if (state != REQUESTING) {
+ run_script(NULL, "deconfig");
++#ifdef UDHCP_ZEROCONF
++ zeroconf_event(ZEROCONF_EVENT_DHCPOUT);
++#endif
++ }
+ state = INIT_SELECTING;
+ timeout = now;
+ requested_ip = 0;
+Index: busybox-1.01/networking/udhcp/options.c
+===================================================================
+--- busybox-1.01.orig/networking/udhcp/options.c 2008-05-21 22:31:10.000000000 +0200
++++ busybox-1.01/networking/udhcp/options.c 2008-05-21 22:31:24.000000000 +0200
+@@ -70,7 +70,8 @@
+ length = 308;
+ while (!done) {
+ if (i >= length) {
+- LOG(LOG_WARNING, "bogus packet, option fields too long.");
++ if (length > 0)
++ LOG(LOG_WARNING, "bogus packet, option fields too long.");
+ return NULL;
+ }
+ if (optionptr[i + OPT_CODE] == code) {
+Index: busybox-1.01/networking/udhcp/samples/WARNING_LEASEFAIL
+===================================================================
+--- /dev/null 1970-01-01 00:00:00.000000000 +0000
++++ busybox-1.01/networking/udhcp/samples/WARNING_LEASEFAIL 2008-05-21 22:31:24.000000000 +0200
+@@ -0,0 +1,7 @@
++WARNING ABOUT leasefail SCRIPT IN ZEROCONF-ENABLED CONFIGURATIONS
++
++if your UDHCP compilation flags are set to support Zeroconf, you
++should not do any network configuration in 'leasefail' script, since
++it would damage the configurations that 'zeroconf' script may have
++done just before 'leasefail' is run.
++
+Index: busybox-1.01/networking/udhcp/samples/sample.zeroconf
+===================================================================
+--- /dev/null 1970-01-01 00:00:00.000000000 +0000
++++ busybox-1.01/networking/udhcp/samples/sample.zeroconf 2008-05-21 22:31:24.000000000 +0200
+@@ -0,0 +1,53 @@
++#!/bin/sh
++# udhcpc script edited by Tim Riker <Tim at Rikers.org> with zerconf support
++
++[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
++
++RESOLV_CONF="/etc/resolv.conf"
++[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
++[ -n "$subnet" ] && NETMASK="netmask $subnet"
++
++case "$1" in
++ deconfig)
++ /sbin/ifconfig $interface 0.0.0.0
++ ;;
++
++ renew|bound)
++ /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
++
++ if [ -n "$router" ] ; then
++ echo "deleting routers"
++ while route del default gw 0.0.0.0 dev $interface ; do
++ :
++ done
++
++ for i in $router ; do
++ route add default gw $i dev $interface
++ done
++ fi
++
++ echo -n > $RESOLV_CONF
++ [ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF
++
++ for i in $dns ; do
++ echo "adding dns $i"
++ echo "nameserver $i" >> $RESOLV_CONF
++ done
++ ;;
++
++ zeroconf)
++ /sbin/ifconfig $interface $ip broadcast 169.254.255.255 netmask 255.255.0.0
++
++ echo "deleting routers"
++
++ while /sbin/route del default gw 0.0.0.0 dev $interface ; do
++ :
++ done
++
++ echo -n > $RESOLV_CONF
++ ;;
++
++esac
++
++exit 0
++
+Index: busybox-1.01/networking/udhcp/signalpipe.c
+===================================================================
+--- busybox-1.01.orig/networking/udhcp/signalpipe.c 2008-05-21 22:31:10.000000000 +0200
++++ busybox-1.01/networking/udhcp/signalpipe.c 2008-05-21 22:31:24.000000000 +0200
+@@ -60,6 +60,13 @@
+ return signal_pipe[0] > extra_fd ? signal_pipe[0] : extra_fd;
+ }
+
++int udhcp_sp_fd_set2(fd_set *rfds, int extra_fd, int extra_fd2)
++{
++ int max_fd = udhcp_sp_fd_set(rfds, extra_fd);
++ if (extra_fd2 >= 0) FD_SET(extra_fd2, rfds);
++ return (max_fd > extra_fd2 ? max_fd : extra_fd2);
++}
++
+
+ /* Read a signal from the signal pipe. Returns 0 if there is
+ * no signal, -1 on error (and sets errno appropriately), and
+Index: busybox-1.01/networking/udhcp/signalpipe.h
+===================================================================
+--- busybox-1.01.orig/networking/udhcp/signalpipe.h 2008-05-21 22:31:10.000000000 +0200
++++ busybox-1.01/networking/udhcp/signalpipe.h 2008-05-21 22:31:24.000000000 +0200
+@@ -19,4 +19,5 @@
+
+ void udhcp_sp_setup(void);
+ int udhcp_sp_fd_set(fd_set *rfds, int extra_fd);
++int udhcp_sp_fd_set2(fd_set *rfds, int extra_fd, int extra_fd2);
+ int udhcp_sp_read(fd_set *rfds);
+Index: busybox-1.01/networking/udhcp/zeroconf.c
+===================================================================
+--- /dev/null 1970-01-01 00:00:00.000000000 +0000
++++ busybox-1.01/networking/udhcp/zeroconf.c 2008-05-21 22:31:24.000000000 +0200
+@@ -0,0 +1,604 @@
++/* zeroconf.c
++ *
++ * Zeroconf handling
++ * Based on draft-ietf-zeroconf-ipv4-linklocal.txt (July 2004)
++ *
++ * Elvis Pfützenreuter <elvis at indt.org> May 2005
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++ */
++
++/* TODO (future): Excess traffic in DHCP socket (while DHCP lease has not been granted)
++ * TODO: Tests with autoimmune response (two network interfaces in the same net, with/wo 2 udhcpc)
++ * TODO (future): ARP "is-at" in broadcast mode if using link-local address - move to kernel ?
++ */
++
++#include <sys/time.h>
++#include <sys/file.h>
++#include <unistd.h>
++#include <getopt.h>
++#include <s%s
>>> DIFF TRUNCATED @ 16K
More information about the Openembedded-commits
mailing list