diff --git a/usr/bin/NETMODE b/usr/bin/NETMODE index d365d7a..30ea955 100755 --- a/usr/bin/NETMODE +++ b/usr/bin/NETMODE @@ -5,12 +5,22 @@ function show_usage() { echo "" } -function configure_client() { +function shut_it_all_down() { + #we are restarting, possibly with new config, or reversing dhcp roles + #kill 'em all, let the user sort them out /etc/init.d/odhcpd stop + pkill -9 dnsmasq #odhcpd starts dnsmasq but fails to stop it + pkill -9 udhcpc #this is the observed dhcp client + pkill -9 odhcpcd #just in case +} + +function configure_client() { + shut_it_all_down uci set network.lan.proto='dhcp' } function configure_server() { + shut_it_all_down uci set network.lan.proto='static' uci set network.lan.ipaddr='172.16.24.1' uci set network.lan.netmask='255.255.255.0' @@ -38,8 +48,7 @@ case $1 in ;; "AUTO") #make sure nothing interferes - /etc/init.d/odhcpd stop - pkill -9 odhcpcd + shut_it_all_down #this will exit 0 if a dhcp discovery/request packet is seen, and 124 if not sniffed="$(timeout 15 tcpdump -Z nobody -i eth0 -c 3 udp src port 68 and udp dst port 67 -v 2>&1)" if echo "${sniffed}" | grep -q 'DHCP-Message Option 53, length 1: Discover' && \