p2p-action.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. IFNAME=$1
  3. CMD=$2
  4. kill_daemon() {
  5. NAME=$1
  6. PF=$2
  7. if [ ! -r $PF ]; then
  8. return
  9. fi
  10. PID=`cat $PF`
  11. if [ $PID -gt 0 ]; then
  12. if ps $PID | grep -q $NAME; then
  13. kill $PID
  14. fi
  15. fi
  16. rm $PF
  17. }
  18. if [ "$CMD" = "P2P-GROUP-STARTED" ]; then
  19. GIFNAME=$3
  20. if [ "$4" = "GO" ]; then
  21. kill_daemon dhclient /var/run/dhclient-$GIFNAME.pid
  22. rm /var/run/dhclient.leases-$GIFNAME
  23. kill_daemon dnsmasq /var/run/dnsmasq.pid-$GIFNAME
  24. ifconfig $GIFNAME 192.168.42.1 up
  25. dnsmasq -x /var/run/dnsmasq.pid-$GIFNAME \
  26. -i $GIFNAME \
  27. -F192.168.42.11,192.168.42.99
  28. fi
  29. if [ "$4" = "client" ]; then
  30. kill_daemon dhclient /var/run/dhclient-$GIFNAME.pid
  31. rm /var/run/dhclient.leases-$GIFNAME
  32. kill_daemon dnsmasq /var/run/dnsmasq.pid-$GIFNAME
  33. dhclient -pf /var/run/dhclient-$GIFNAME.pid \
  34. -lf /var/run/dhclient.leases-$GIFNAME \
  35. -nw \
  36. $GIFNAME
  37. fi
  38. fi
  39. if [ "$CMD" = "P2P-GROUP-REMOVED" ]; then
  40. GIFNAME=$3
  41. if [ "$4" = "GO" ]; then
  42. kill_daemon dnsmasq /var/run/dnsmasq.pid-$GIFNAME
  43. ifconfig $GIFNAME 0.0.0.0
  44. fi
  45. if [ "$4" = "client" ]; then
  46. kill_daemon dhclient /var/run/dhclient-$GIFNAME.pid
  47. rm /var/run/dhclient.leases-$GIFNAME
  48. ifconfig $GIFNAME 0.0.0.0
  49. fi
  50. fi