]> git.ipfire.org Git - people/stevee/network.git/blame - functions.switch
wireless: Add function to find DFS channels.
[people/stevee/network.git] / functions.switch
CommitLineData
607d9345
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 IPFire Network Development Team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
fc603a2b
MT
22function switch_start() {
23 local service="openvswitch.service"
24
25 if ! service_is_active "${service}"; then
26 service_start "${service}"
27 fi
28
29 return ${EXIT_OK}
30}
31
607d9345
MT
32function switch_create() {
33 local device=${1}
34 assert isset device
35
fc603a2b
MT
36 # Make sure that the openvswitch service is running.
37 switch_start
38
607d9345
MT
39 log DEBUG "Creating virtual switch: ${device}"
40 ovs-vsctl -- --may-exist add-br ${device}
41
42 assert device_exists ${device}
43
44 return ${EXIT_OK}
45}
46
47function switch_remove() {
48 local device=${1}
49 assert isset device
50
51 # Set device down.
52 device_set_down ${device}
53
54 log DEBUG "Removing virtual switch: ${device}"
55 ovs-vsctl -- --if-exists del-br ${device}
56
57 return ${EXIT_OK}
58}
59
60function switch_exists() {
61 local device=${1}
62 assert isset device
63
64 ovs-vsctl -- br-exists ${device}
65 case "$?" in
66 0)
67 return ${EXIT_TRUE}
68 ;;
69 2)
70 return ${EXIT_FALSE}
71 ;;
72 esac
73
74 return ${EXIT_ERROR}
75}
76
77function switch_get_members() {
78 local device=${1}
79 assert isset device
80
81 ovs-vsctl -- list-ports ${device}
82 return ${EXIT_OK}
83}
84
85function switch_attach_port() {
86 local device=${1}
87 assert isset device
88
89 local port=${2}
90 assert isset port
91
92 log DEBUG "Attaching port '${port}' to switch '${device}'"
0152cbb0 93 ovs-vsctl -- --may-exist add-port "${device}" "${port}"
607d9345
MT
94
95 return ${EXIT_OK}
96}
97
98function switch_detach_port() {
99 local device=${1}
100 assert isset device
101
102 local port=${2}
103 assert isset port
104
105 log DEBUG "Detaching port '${port}' from switch '${device}'"
0152cbb0 106 ovs-vsctl -- --if-exists del-port "${device}" "${port}"
607d9345
MT
107
108 return ${EXIT_OK}
109}
110
111function switch_stp_enable() {
112 local device=${1}
113 assert isset device
114
115 log DEBUG "Enable STP on switch ${device}"
116 ovs-vsctl set Bridge ${device} "stp_enable=true"
117
118 return ${EXIT_OK}
119}
120
121function switch_stp_disable() {
122 local device=${1}
123 assert isset device
124
125 log DEBUG "Disable STP on switch ${device}"
126 ovs-vsctl set Bridge ${device} "stp_enable=false"
127
128 return ${EXIT_OK}
129}
130
131function switch_stp_is_enabled() {
132 local device=${1}
133 assert isset device
134
135 local output=$(ovs-vsctl -- --if-exists get Bridge ${device} stp_enable)
136
137 if enabled output; then
138 return ${EXIT_TRUE}
139 fi
140
141 return ${EXIT_FALSE}
142}