]> git.ipfire.org Git - people/stevee/network.git/blame - hooks/ports/virtual
bridge-stp: Move to helpers directory.
[people/stevee/network.git] / hooks / ports / virtual
CommitLineData
711ffac1
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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
987dfeb4 22. /usr/lib/network/header-port
711ffac1 23
95b96ee3 24HOOK_SETTINGS="HOOK ADDRESS PARENT TAG"
711ffac1 25
95b96ee3 26PORT_PARENTS_VAR="PARENT"
98f4dae6 27
95b96ee3 28ADDRESS=$(mac_generate)
711ffac1
MT
29
30function _check() {
95b96ee3
MT
31 assert isset PARENT
32 assert ismac ADDRESS
33 assert isinteger TAG
711ffac1 34
95b96ee3
MT
35 if [ ${TAG} -gt 4096 ]; then
36 error "TAG is greater than 4096."
711ffac1
MT
37 exit ${EXIT_ERROR}
38 fi
39
40 local reserved
41 for reserved in 0 4095; do
95b96ee3
MT
42 if [ "${TAG}" = "${reserved}" ]; then
43 error "TAG=${reserved} is reserved."
711ffac1
MT
44 exit ${EXIT_ERROR}
45 fi
46 done
47}
48
49function _create() {
50 while [ $# -gt 0 ]; do
51 case "${1}" in
52 --device=*)
95b96ee3 53 PARENT=${1#--device=}
711ffac1
MT
54 ;;
55 --mac=*)
95b96ee3 56 ADDRESS=${1#--mac=}
711ffac1
MT
57 ;;
58 --id=*)
95b96ee3 59 TAG=${1#--id=}
711ffac1
MT
60 ;;
61 *)
62 warning "Unknown argument '${1}'"
63 ;;
64 esac
65 shift
66 done
67
95b96ee3 68 local port="${PARENT}v${TAG}"
711ffac1
MT
69
70 config_write $(port_file ${port}) ${HOOK_SETTINGS}
71
72 exit ${EXIT_OK}
73}
74
75function _edit() {
76 local port=${1}
77 shift
78
79 assert isset port
80
81 config_read $(port_file ${port})
82
83 while [ $# -gt 0 ]; do
84 case "${1}" in
85 --mac=*)
95b96ee3 86 ADDRESS=${1#--mac=}
711ffac1
MT
87 ;;
88 *)
89 warning "Unknown argument '${1}'"
90 ;;
91 esac
92 shift
93 done
94
95 config_write $(port_file ${port}) ${HOOK_SETTINGS}
96
97 exit ${EXIT_OK}
98}
99
100function _up() {
101 local port=${1}
102
103 assert isset port
104
105 config_read $(port_file ${port})
106
107 if ! device_exists ${port}; then
95b96ee3 108 virtual_create ${PARENT} ${TAG} ${ADDRESS}
711ffac1
MT
109 fi
110
111 exit ${EXIT_OK}
112}
113
114function _down() {
115 local port=${1}
116
117 assert isset port
118
119 config_read $(port_file ${port})
120
121 if ! device_exists ${port}; then
122 exit ${EXIT_OK}
123 fi
124
8c6a8966 125 virtual_remove ${port}
711ffac1
MT
126
127 exit ${EXIT_OK}
128}