introduce netmode auto

who wouldn't want a sweet feature like this?
pull/4/head
Rick Farina (Zero_Chaos) 2019-12-12 14:14:31 -05:00
parent 52f3349406
commit 60cc5d98f5
No known key found for this signature in database
GPG Key ID: A29433C0AA431DDC
1 changed files with 25 additions and 4 deletions

View File

@ -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