From 60cc5d98f595aa932576a42c1cd249d68ab493dc Mon Sep 17 00:00:00 2001 From: "Rick Farina (Zero_Chaos)" Date: Thu, 12 Dec 2019 14:14:31 -0500 Subject: [PATCH] introduce netmode auto who wouldn't want a sweet feature like this? --- usr/bin/NETMODE | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/usr/bin/NETMODE b/usr/bin/NETMODE index a056b41..1a83f51 100755 --- a/usr/bin/NETMODE +++ b/usr/bin/NETMODE @@ -5,14 +5,35 @@ function show_usage() { echo "" } +function configure_client() { + /etc/init.d/odhcpd stop + uci set network.lan.proto='dhcp' +} + +function configure_server() { + uci set network.lan.proto='none' + /etc/init.d/odhcpd start +} + case $1 in "DHCP_CLIENT") - uci set network.lan.proto='dhcp' - /etc/init.d/odhcpd stop + configure_client ;; "DHCP_SERVER") - uci set network.lan.proto='none' - /etc/init.d/odhcpd start + configure_server + ;; + "AUTO") + #make sure nothing interferes + /etc/init.d/odhcpd stop + /etc/init.d/network stop + #this will exit 0 if a dhcp related packet is seen, and 124 if not + #todo: this only looks for a dhcp request/discover and doesn't check that there was no reply... + if timeout 10 tcpdump -Z nobody -i eth0 -c 1 -q udp src port 68 > /dev/null 2>&1; then + #we saw someone looking for a dhcp server + configure_server + else + configure_client + fi ;; *) show_usage