#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2012 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### function switch_start() { local service="openvswitch.service" if ! service_is_active "${service}"; then service_start "${service}" fi return ${EXIT_OK} } function switch_create() { local device=${1} assert isset device # Make sure that the openvswitch service is running. switch_start log DEBUG "Creating virtual switch: ${device}" ovs-vsctl -- --may-exist add-br ${device} assert device_exists ${device} return ${EXIT_OK} } function switch_remove() { local device=${1} assert isset device # Set device down. device_set_down ${device} log DEBUG "Removing virtual switch: ${device}" ovs-vsctl -- --if-exists del-br ${device} return ${EXIT_OK} } function switch_exists() { local device=${1} assert isset device ovs-vsctl -- br-exists ${device} case "$?" in 0) return ${EXIT_TRUE} ;; 2) return ${EXIT_FALSE} ;; esac return ${EXIT_ERROR} } function switch_get_members() { local device=${1} assert isset device ovs-vsctl -- list-ports ${device} return ${EXIT_OK} } function switch_attach_port() { local device=${1} assert isset device local port=${2} assert isset port log DEBUG "Attaching port '${port}' to switch '${device}'" ovs-vsctl -- --may-exist add-port "${device}" "${port}" return ${EXIT_OK} } function switch_detach_port() { local device=${1} assert isset device local port=${2} assert isset port log DEBUG "Detaching port '${port}' from switch '${device}'" ovs-vsctl -- --if-exists del-port "${device}" "${port}" return ${EXIT_OK} } function switch_stp_enable() { local device=${1} assert isset device log DEBUG "Enable STP on switch ${device}" ovs-vsctl set Bridge ${device} "stp_enable=true" return ${EXIT_OK} } function switch_stp_disable() { local device=${1} assert isset device log DEBUG "Disable STP on switch ${device}" ovs-vsctl set Bridge ${device} "stp_enable=false" return ${EXIT_OK} } function switch_stp_is_enabled() { local device=${1} assert isset device local output=$(ovs-vsctl -- --if-exists get Bridge ${device} stp_enable) if enabled output; then return ${EXIT_TRUE} fi return ${EXIT_FALSE} }