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.

87 lines
1.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2013 Julius Schulz-Zander <julius@net.t-labs.tu-berlin.de>
  3. # Copyright (C) 2014-2017 OpenWrt.org
  4. # Copyright (C) 2018 Yousong Zhou <yszhou4tech@gmail.com>
  5. START=15
  6. ovs_ctl="/usr/share/openvswitch/scripts/ovs-ctl"; [ -x "$ovs_ctl" ] || ovs_ctl=:
  7. ovn_ctl="/usr/share/ovn/scripts/ovn-ctl"; [ -x "$ovn_ctl" ] || ovn_ctl=:
  8. extra_command "status" "Get status information"
  9. start() {
  10. ovs_action start "$@"
  11. }
  12. stop() {
  13. ovs_action stop "$@"
  14. }
  15. restart() {
  16. ovs_action restart "$@"
  17. }
  18. status() {
  19. ovs_action status "$@"
  20. }
  21. ovs_action_cfgs=
  22. ovs_action() {
  23. local action="$1"; shift
  24. local cfgtype
  25. ovs_action_cfgs="$*"
  26. config_load openvswitch
  27. for cfgtype in ovs ovn_northd ovn_controller; do
  28. config_foreach "ovs_xx" "$cfgtype" "$action" "$cfgtype"
  29. done
  30. config_foreach ovs_bridge_init "ovs_bridge"
  31. }
  32. ovs_xx() {
  33. local cfg="$1"
  34. local action="$2"
  35. local cfgtype="$3"
  36. local disabled
  37. if [ -n "$ovs_action_cfgs" ] && ! list_contains "ovs_action_cfgs" "$cfg"; then
  38. return
  39. fi
  40. case "$action" in
  41. status|stop) ;;
  42. *)
  43. config_get_bool disabled "$cfg" disabled 0
  44. [ "$disabled" == "0" ] || return
  45. ;;
  46. esac
  47. case "$cfgtype" in
  48. ovs)
  49. "$ovs_ctl" "$action" \
  50. --system-id=random
  51. ;;
  52. ovn_*)
  53. "$ovn_ctl" "${action}_${cfgtype#ovn_}"
  54. ;;
  55. esac
  56. }
  57. ovs_bridge_init() {
  58. local cfg="$1"
  59. local disabled
  60. local name
  61. local controller
  62. config_get_bool disabled "$cfg" disabled 0
  63. [ "$disabled" == "0" ] || return
  64. config_get name "$cfg" name $cfg
  65. ovs-vsctl --may-exist add-br "$name"
  66. config_get controller "$cfg" controller
  67. [ -n "$controller" ] && \
  68. ovs-vsctl set-controller "$name" "$controller"
  69. }