aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2021-06-23 15:46:34 +0200
committerFelix Fietkau <nbd@nbd.name>2021-06-23 15:49:28 +0200
commit1038ac123558b960e7b661f1133b5a920173345e (patch)
tree0bbc55cefe20607ade8f89c294f32c21a52ffee0
parent238046303d3408c622a2c2c2fc25fbc26cdd20e4 (diff)
openvswitch: add support for definining bridge ports in the config
Add limited procd support to handle config reload Option drop_unknown_ports can be used to ensure that only configured ports are part of the bridge Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rwxr-xr-xnet/openvswitch/files/openvswitch.init61
1 files changed, 61 insertions, 0 deletions
diff --git a/net/openvswitch/files/openvswitch.init b/net/openvswitch/files/openvswitch.init
index 10cbfdffb..0789021c3 100755
--- a/net/openvswitch/files/openvswitch.init
+++ b/net/openvswitch/files/openvswitch.init
@@ -2,7 +2,9 @@
# Copyright (C) 2013 Julius Schulz-Zander <julius@net.t-labs.tu-berlin.de>
# Copyright (C) 2014-2017 OpenWrt.org
# Copyright (C) 2018 Yousong Zhou <yszhou4tech@gmail.com>
+# Copyright (C) 2021 Felix Fietkau <nbd@nbd.name>
+. /lib/functions/procd.sh
START=15
ovs_ctl="/usr/share/openvswitch/scripts/ovs-ctl"; [ -x "$ovs_ctl" ] || ovs_ctl=:
@@ -10,15 +12,35 @@ ovn_ctl="/usr/share/ovn/scripts/ovn-ctl"; [ -x "$ovn_ctl" ] || ovn_ctl=:
extra_command "status" "Get status information"
+service_triggers() {
+ procd_add_reload_trigger openvswitch
+}
+
+init_triggers() {
+ procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
+ procd_close_service set
+}
+
start() {
+ init_triggers
ovs_action start "$@"
}
+reload() {
+ start
+}
+
+running() {
+ return 0
+}
+
stop() {
+ procd_kill "$(basename ${basescript:-$initscript})"
ovs_action stop "$@"
}
restart() {
+ init_triggers
ovs_action restart "$@"
}
@@ -68,6 +90,41 @@ ovs_xx() {
esac
}
+ovs_bridge_parse_port() {
+ case "$1" in
+ *:*)
+ port="${1%%:*}"
+ type="${1#*:}"
+ ;;
+ *)
+ port="$1"
+ type=""
+ ;;
+ esac
+}
+
+ovs_bridge_port_add() {
+ [ -n "$1" ] || return
+
+ ovs_bridge_parse_port "$1"
+ cur_type="$(ovs-vsctl get interface "$port" type 2>/dev/null)"
+ [ "$?" = 0 ] && {
+ [ "$type" = "$cur_type" ] || ovs-vsctl del-port "$port"
+ }
+
+ ovs-vsctl --may-exist add-port "$name" "$port" ${type:+ -- set interface "$port" type="$type"}
+ __port_list="$__port_list ${port} "
+}
+
+ovs_bridge_port_cleanup() {
+ for port in `ovs-vsctl list-ports "$name"`; do
+ case "$__port_list" in
+ *" $port "*);;
+ *) ovs-vsctl del-port "$port";;
+ esac
+ done
+}
+
ovs_bridge_init() {
local cfg="$1"
@@ -81,6 +138,10 @@ ovs_bridge_init() {
config_get name "$cfg" name $cfg
ovs-vsctl --may-exist add-br "$name"
+ config_list_foreach "$cfg" "ports" ovs_bridge_port_add
+ config_get_bool drop "$cfg" "drop_unknown_ports" 0
+ [ "$drop" == 1 ] && ovs_bridge_port_cleanup
+
config_get controller "$cfg" controller
[ -n "$controller" ] && \
ovs-vsctl set-controller "$name" "$controller"