You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
2.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. # shellcheck disable=SC2034 # foo appears unused. Verify it or export it.
  3. START=25
  4. STOP=99
  5. MSTPCTL="/usr/sbin/mstpctl"
  6. MSTPD="/usr/sbin/mstpd"
  7. USE_PROCD=1
  8. mstpd_get_bridges() {
  9. "$MSTPCTL" showbridge | grep -v "^ " | cut -d " " -f 1 2>/dev/null
  10. }
  11. # mstpd log levels
  12. # LOG_LEVEL_NONE 0
  13. # LOG_LEVEL_ERROR 1
  14. # LOG_LEVEL_INFO 2
  15. # LOG_LEVEL_DEBUG 3
  16. # LOG_LEVEL_STATE_MACHINE_TRANSITION 4
  17. # LOG_LEVEL_MAX 100
  18. config_bridge_port_mstpd() {
  19. local config="$1"
  20. local index=$2 # FIXME: maybe remove index later
  21. local name=$3
  22. [ -n "$index" -a -n "$name" ] || return 0
  23. config_get br_index "$config" br_index
  24. [ -n "$br_index" ] || return 0
  25. [ "$index" = "$br_index" ] || return 0
  26. config_get port_name "$config" name
  27. [ -n "$port_name" ] || return 0
  28. for opt in bpduguard; do
  29. config_get $opt "$config" $opt
  30. eval optval=\$$opt
  31. [ -z "$optval" ] || "$MSTPCTL" "set$opt" "$name" "$port_name" "$optval"
  32. done
  33. }
  34. config_bridge_mstpd() {
  35. local config="$1"
  36. local optval=
  37. local name=
  38. local enable=
  39. local mstid=0 # for the moment, using only MSTID
  40. config_get index "$config" index
  41. [ -n "$index" ] || return 1
  42. # Get bridge name
  43. config_get name "$config" name
  44. [ -n "$name" ] || return 0
  45. config_get enable "$config" enable
  46. if [ "$enable" != "1" ] ; then
  47. return 0
  48. fi
  49. list_contains MSTPD_PREINSTALLED_BRIDGES "$name" || \
  50. "$MSTPCTL" addbridge "$name"
  51. # All options here have 'set$opt' equivalent calls in mstpd,
  52. # hence this trick with the loop
  53. for opt in maxage fdelay maxhops hello ageing forcevers txholdcount; do
  54. config_get $opt "$config" "$opt"
  55. eval optval=\$$opt
  56. [ -z "$optval" ] || "$MSTPCTL" set$opt "$name" "$optval"
  57. done
  58. config_get treeprio "$config" treeprio
  59. [ -z "$treeprio" ] || $MSTPCTL settreeprio "$name" "$mstid" "$treeprio"
  60. config_foreach config_bridge_port_mstpd bridge_port "$index" "$name"
  61. CONFIGURED_BRIDGES="$CONFIGURED_BRIDGES $name"
  62. export CONFIGURED_BRIDGES
  63. }
  64. start_service() {
  65. procd_open_instance
  66. procd_set_param command $MSTPD
  67. procd_append_param command -v 2
  68. procd_append_param command -d # don't daemonize, procd will handle that for us
  69. procd_append_param command -s # print to syslog
  70. # set auto respawn behavior
  71. procd_set_param respawn
  72. # reload config on respawn
  73. procd_open_trigger
  74. procd_add_raw_trigger "instance.start" 2000 "/etc/init.d/mstpd" "reload"
  75. procd_close_trigger
  76. procd_close_instance
  77. }
  78. service_running() {
  79. pgrep mstpd >/dev/null 2>&1
  80. }
  81. reload_service() {
  82. if ! running ; then
  83. start
  84. return
  85. fi
  86. unset CONFIGURED_BRIDGES
  87. MSTPD_PREINSTALLED_BRIDGES="$(mstpd_get_bridges)"
  88. export MSTPD_PREINSTALLED_BRIDGES
  89. config_load 'mstpd'
  90. config_foreach config_bridge_mstpd bridge
  91. for bridge in $(mstpd_get_bridges) ; do
  92. list_contains CONFIGURED_BRIDGES "$bridge" || \
  93. $MSTPCTL delbridge "$bridge"
  94. done
  95. # return 0 (success) here, otherwise, and endless restart loop will occur from procd
  96. # because the last return code may be mstpctl failing
  97. return 0
  98. }