From 1d490769d87875bbc03de1c1c7b198e4f9f42b91 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Sun, 27 Jul 2014 22:11:42 +0200 Subject: Add a connection type for openvswitch interfaces Open vSwitch support code contributed by: Jonathan Hudson --- docs/examples/openvswitch | 5 +++++ docs/netctl.profile.5.txt | 9 +++++++++ src/lib/connections/openvswitch | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 docs/examples/openvswitch create mode 100644 src/lib/connections/openvswitch diff --git a/docs/examples/openvswitch b/docs/examples/openvswitch new file mode 100644 index 0000000..c2069b3 --- /dev/null +++ b/docs/examples/openvswitch @@ -0,0 +1,5 @@ +Description="Example Open vSwitch connection" +Interface=ovs-br0 +Connection=openvswitch +BindsToInterfaces=(eth0 eth1) +IP=dhcp diff --git a/docs/netctl.profile.5.txt b/docs/netctl.profile.5.txt index 29a679f..9956c24 100644 --- a/docs/netctl.profile.5.txt +++ b/docs/netctl.profile.5.txt @@ -48,6 +48,8 @@ AVAILABLE CONNECTION TYPES For PPPoE connections. +mobile_ppp+:: For mobile broadband PPP connections that use a USB modem. ++openvswitch+:: + For Open vSwitch bridge interfaces. +tunnel+:: For tunnel interfaces. +tuntap+:: @@ -426,6 +428,13 @@ type: A file to read additional pppd options from. +OPTIONS FOR `openvswitch' CONNECTIONS +------------------------------------- +The interfaces of 'BindsToInterfaces' take part in the bridge named by +'Interface'. Only the *ip options* are understood for connections of +the `openvswitch' type. + + OPTIONS FOR `tunnel' CONNECTIONS -------------------------------- The name of the tunnel interface is specified in 'Interface'. Next to diff --git a/src/lib/connections/openvswitch b/src/lib/connections/openvswitch new file mode 100644 index 0000000..b9b9cfc --- /dev/null +++ b/src/lib/connections/openvswitch @@ -0,0 +1,39 @@ +# Contributed by: Jonathan Hudson + +. "$SUBR_DIR/ip" + +: ${OVSCTL:=ovs-vsctl} + +# Make sure BindsToInterfaces is set +BindsToInterfaces=("${BindsToInterfaces[@]}") + +openvswitch_up() { + systemctl start ovs-vswitchd.service + if ! $OVSCTL br-exists "$Interface" && ! $OVSCTL add-br "$Interface"; then + report_error "Could not create a bridge named '$Interface'" + return 1 + fi + + for port in "${BindsToInterfaces[@]}"; do + ip link set dev "$port" promisc on up + ip addr flush dev "$port" scope host &>/dev/null + ip addr flush dev "$port" scope site &>/dev/null + ip addr flush dev "$port" scope global &>/dev/null + $OVSCTL --may-exist add-port "$Interface" "$port" + done + + bring_interface_up "$Interface" + ip_set +} + +openvswitch_down() { + for port in "${BindsToInterfaces[@]}"; do + ip link set dev "$port" promisc off down + done + + ip_unset + $OVSCTL del-br "$Interface" +} + + +# vim: ft=sh ts=4 et sw=4: -- cgit v1.2.3-24-g4f1b