aoe-interfaces.in 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /bin/sh
  2. # aoe-interfaces - set or list the allowed AoE network interfaces
  3. # Copyright 2008, Coraid, Inc., and licensed under GPL v.2.
  4. zero="`basename $0`"
  5. devf=@devdir@/interfaces
  6. sysf=/sys/module/aoe/parameters/aoe_iflist
  7. if test -z "$*"; then
  8. if test -r "$sysf"; then
  9. cat "$sysf"
  10. else
  11. # can't read from interfaces device
  12. false
  13. fi
  14. exit
  15. fi
  16. if test "$1" = "-c"; then
  17. shift
  18. if test "$#" != "0"; then
  19. echo "$zero Error: -c flag takes no arguments" 1>&2
  20. exit 1
  21. fi
  22. fi
  23. netifs="$*"
  24. err=no
  25. for i in $netifs; do
  26. test -d "/sys/class/net/$i" || {
  27. echo "$zero Error: \"$i\" is not a network interface" 1>&2
  28. err=yes
  29. }
  30. done
  31. if test "$err" = "yes"; then
  32. exit 1
  33. fi
  34. if test -w "$sysf"; then
  35. printf '%s\0' "$netifs" > "$sysf"
  36. else
  37. if test ! -w "$devf"; then
  38. echo 1>&2 "$zero: $devf does not exist or is not writeable."
  39. exit 1
  40. fi
  41. if test ! -c "$devf"; then
  42. exec 1>&2
  43. echo "$zero: $devf is not a character device file"
  44. echo "$zero: use udev or aoe-mkdevs to create it"
  45. exit 1
  46. fi
  47. printf '%s\0' "$netifs" > "$devf"
  48. fi