network.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # udevd does clearenv(). Export shell PATH to children.
  3. export PATH
  4. # Do not run when pcmcia-cs is installed
  5. test -x /sbin/cardctl && exit 0
  6. # We get two "add" events for hostap cards due to wifi0
  7. echo "$INTERFACE" | grep -q wifi && exit 0
  8. # Check if /etc/init.d/network has been run yet to see if we are
  9. # called by starting /etc/rcS.d/S03udev and not by hotplugging a device
  10. #
  11. # At this stage, network interfaces should not be brought up
  12. # automatically because:
  13. # a) /etc/init.d/network has not been run yet (security issue)
  14. # b) /var has not been populated yet so /etc/resolv,conf points to
  15. # oblivion, making the network unusable
  16. #
  17. spoofp="`grep ^spoofprotect /etc/network/options`"
  18. if test -z "$spoofp"
  19. then
  20. # This is the default from /etc/init.d/network
  21. spoofp_val=yes
  22. else
  23. spoofp_val=${spoofp#spoofprotect=}
  24. fi
  25. test "$spoofp_val" = yes && spoofp_val=1 || spoofp_val=0
  26. # I think it is safe to assume that "lo" will always be there ;)
  27. if test "`cat /proc/sys/net/ipv4/conf/lo/rp_filter`" != "$spoofp_val" -a -n "$spoofp_val"
  28. then
  29. echo "$INTERFACE" >> /dev/udev_network_queue
  30. exit 0
  31. fi
  32. #
  33. # Code taken from pcmcia-cs:/etc/pcmcia/network
  34. #
  35. # if this interface has an entry in /etc/network/interfaces, let ifupdown
  36. # handle it
  37. if grep -q "iface \+$INTERFACE" /etc/network/interfaces; then
  38. case $ACTION in
  39. add)
  40. ifconfig | grep -q "^$INTERFACE" || ifup $INTERFACE
  41. ;;
  42. remove)
  43. ifdown $INTERFACE
  44. ;;
  45. esac
  46. exit 0
  47. fi