10-net 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2006 OpenWrt.org
  2. include /lib/network
  3. addif() {
  4. # Ensure that ipv6 is loaded, autoloading happens later but ipv6 might be
  5. # required now for interface setup.
  6. [ -d /proc/sys/net/ipv6 ] || {
  7. grep -q '^ipv6' /etc/modules.d/* && insmod ipv6
  8. }
  9. # PPP devices are configured by pppd, no need to run setup_interface here
  10. case "$INTERFACE" in
  11. ppp*) return 0;;
  12. esac
  13. scan_interfaces
  14. local cfg="$(find_config "$INTERFACE")"
  15. # check the autoload setting
  16. config_get auto "$cfg" auto
  17. case "$auto" in
  18. 1|on|enabled) setup_interface "$INTERFACE";;
  19. esac
  20. # find all vlan configurations for this interface and set them up as well
  21. for ifc in $interfaces; do
  22. config_get iftype "$ifc" type
  23. config_get ifs "$ifc" device
  24. for dev in $ifs; do
  25. [ "${dev%%\.*}" = "$INTERFACE" -a "$dev" != "$INTERFACE" ] && {
  26. add_vlan "$dev"
  27. }
  28. done
  29. done
  30. }
  31. delif() {
  32. scan_interfaces
  33. # find all vlan configurations for this interface and nuke 'em
  34. for ifc in $interfaces; do
  35. config_get iftype "$ifc" type
  36. config_get ifs "$ifc" device
  37. confdevs="$(uci get network.$ifc.ifname)"
  38. for dev in $ifs; do
  39. [ "${dev%%\.*}" = "$INTERFACE" ] && {
  40. list_contains confdevs "$dev" || list_remove ifs "$dev"
  41. }
  42. done
  43. uci_set_state "network" "$ifc" device "$ifs"
  44. done
  45. }
  46. case "$ACTION" in
  47. add|register)
  48. case "$PHYSDEVDRIVER" in
  49. natsemi) sleep 1;;
  50. esac
  51. addif
  52. ;;
  53. remove|unregister)
  54. delif
  55. ;;
  56. esac