]> git.ipfire.org Git - people/arne_f/network.git/blame - functions.ports
network: STP: Make protocol version configureable.
[people/arne_f/network.git] / functions.ports
CommitLineData
711ffac1
MT
1#!/bin/bash
2# XXX header missing
3
4function port_dir() {
5 echo "${CONFIG_DIR}/ports"
6}
7
8function port_file() {
9 local port=${1}
10
11 assert isset port
12
13 echo "$(port_dir)/${port}"
14}
15
16function port_exists() {
17 local port=${1}
18
19 [ -f "${CONFIG_DIR}/ports/${port}" ]
20}
21
22function port_get_hook() {
23 local port=${1}
24
25 assert isset port
26
27 config_get_hook $(port_file ${port})
28}
29
30function port_is_attached() {
31 local port=${1}
32 shift
33
34 assert isset port
35
36 local zone
37 for zone in $(zones_get_all); do
38
39 assert isset zone
40 assert zone_exists ${zone}
41
42 if listmatch ${port} $(zone_get_ports ${zone}); then
43 echo "${zone}"
44 return ${EXIT_OK}
45 fi
46 done
47
48 return ${EXIT_ERROR}
49}
50
51function port_create() {
52 #local port=${1}
53 #shift
54 #
55 #if port_exists ${port}; then
56 # error "Port '${port}' does already exist."
57 # return ${EXIT_ERROR}
58 #fi
59
60 local hook=${1}
61 shift
62
63 if ! hook_exists port ${hook}; then
64 error "Port hook '${hook}' does not exist."
65 return ${EXIT_ERROR}
66 fi
67
68 #port_edit ${port} ${hook} $@
69 #
70 #if [ $? -ne ${EXIT_OK} ]; then
71 # port_destroy ${port}
72 #fi
73
74 hook_exec port ${hook} create $@
75}
76
77function port_destroy() {
78 local port=${1}
79
80 assert isset port
81
82 port_exists ${port} || return ${EXIT_OK}
83
84 local attached_zone=$(port_is_attached ${port})
85
86 if [ -n "${attached_zone}" ]; then
87 error "Cannot destroy port '${port}' which is attached to zone '${attached_zone}'."
88 return ${EXIT_ERROR}
89 fi
90
91 port_down ${port}
92
93 rm -f $(port_file ${port})
94}
95
f90e550b
MT
96function port_remove() {
97 port_destroy $@
98}
99
711ffac1
MT
100function port_edit() {
101 port_cmd edit $@
102}
103
104# XXX? Compatibility function
105function port_show() {
106 port_status $@
107}
108
109function port_up() {
110 port_cmd up $@
111}
112
113function port_down() {
114 port_cmd down $@
115}
116
117function port_status() {
118 port_cmd status $@
119}
120
121function port_cmd() {
122 local cmd=${1}
123 local port=${2}
124 shift 2
125
126 assert isset cmd
127 assert isset port
128
129 local hook=$(port_get_hook ${port})
130
131 assert isset hook
132
133 hook_exec port ${hook} ${cmd} ${port} $@
134}
f90e550b
MT
135
136function ports_get() {
137 local port
138 for port in $(port_dir)/*; do
139 port=$(basename ${port})
140 if port_exists ${port}; then
141 echo "${port}"
142 fi
143 done
144}
2ae0fb8d
MT
145
146# This function automatically creates the real ethernet devices
147# that do not exists in the configuration.
148# Saves some work for the administrator.
149function ports_init() {
150 local device
151 for device in $(devices_get_all); do
152 if device_is_real ${device}; then
153 if ! port_exists ${device}; then
154 port_create ethernet ${device}
155 fi
156 fi
157 done
158}
159
160init_register ports_init