p2p-action-udhcp.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 udhcpc /var/run/udhcpc-$GIFNAME.pid
  22. ifconfig $GIFNAME 192.168.42.1 up
  23. udhcpd /etc/udhcpd-p2p.conf
  24. fi
  25. if [ "$4" = "client" ]; then
  26. kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
  27. kill_daemon udhcpd /var/run/udhcpd-$GIFNAME.pid
  28. udhcpc -i $GIFNAME -p /var/run/udhcpc-$GIFNAME.pid \
  29. -s /etc/udhcpc.script
  30. fi
  31. fi
  32. if [ "$CMD" = "P2P-GROUP-REMOVED" ]; then
  33. GIFNAME=$3
  34. if [ "$4" = "GO" ]; then
  35. kill_daemon udhcpd /var/run/udhcpd-$GIFNAME.pid
  36. ifconfig $GIFNAME 0.0.0.0
  37. fi
  38. if [ "$4" = "client" ]; then
  39. kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
  40. ifconfig $GIFNAME 0.0.0.0
  41. fi
  42. fi
  43. if [ "$CMD" = "P2P-CROSS-CONNECT-ENABLE" ]; then
  44. GIFNAME=$3
  45. UPLINK=$4
  46. # enable NAT/masquarade $GIFNAME -> $UPLINK
  47. iptables -P FORWARD DROP
  48. iptables -t nat -A POSTROUTING -o $UPLINK -j MASQUERADE
  49. iptables -A FORWARD -i $UPLINK -o $GIFNAME -m state --state RELATED,ESTABLISHED -j ACCEPT
  50. iptables -A FORWARD -i $GIFNAME -o $UPLINK -j ACCEPT
  51. sysctl net.ipv4.ip_forward=1
  52. fi
  53. if [ "$CMD" = "P2P-CROSS-CONNECT-DISABLE" ]; then
  54. GIFNAME=$3
  55. UPLINK=$4
  56. # disable NAT/masquarade $GIFNAME -> $UPLINK
  57. sysctl net.ipv4.ip_forward=0
  58. iptables -t nat -D POSTROUTING -o $UPLINK -j MASQUERADE
  59. iptables -D FORWARD -i $UPLINK -o $GIFNAME -m state --state RELATED,ESTABLISHED -j ACCEPT
  60. iptables -D FORWARD -i $GIFNAME -o $UPLINK -j ACCEPT
  61. fi