]>
git.ipfire.org Git - people/stevee/network.git/blob - functions.ports
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
23 echo "${NETWORK_CONFIG_DIR}/ports"
26 function port_get_hook
() {
30 config_get_hook $
(port_file
${port})
33 function port_config_dir
() {
36 print
"${RUN_DIR}/ports/${port}"
40 function port_config_read
() {
44 # Save the HOOK variable.
47 config_read $
(port_file
${port})
53 function port_config_write
() {
57 config_write $
(port_file
${port})
60 function ports_get_all
() {
63 for port
in $
(port_dir
)/*; do
64 [ -f "${port}" ] ||
continue
70 function port_file
() {
74 echo "$(port_dir)/${port}"
77 function port_exists
() {
80 [ -f "${NETWORK_CONFIG_DIR}/ports/${port}" ]
83 function port_get_hook
() {
88 config_get_hook $
(port_file
${port})
91 function port_is_attached
() {
98 for zone
in $
(zones_get_all
); do
101 assert zone_exists
${zone}
103 if listmatch
${port} $
(zone_get_ports
${zone}); then
112 function port_create
() {
116 #if port_exists ${port}; then
117 # error "Port '${port}' does already exist."
118 # return ${EXIT_ERROR}
124 if ! hook_exists port
${hook}; then
125 error
"Port hook '${hook}' does not exist."
129 #port_edit ${port} ${hook} $@
131 #if [ $? -ne ${EXIT_OK} ]; then
132 # port_destroy ${port}
135 hook_exec port
${hook} create $@
138 function port_destroy
() {
143 port_exists
${port} ||
return ${EXIT_OK}
145 # Check if the port is attached to any zone and don't delete it.
148 local attached_zone
=$
(port_is_attached
${port})
149 if [ -n "${attached_zone}" ]; then
150 error_log
"Cannot destroy port '${port}' which is attached to zone '${attached_zone}'."
154 # Check if the port is linked to any other port and don't allow the user
157 for other_port
in $
(ports_get
); do
158 [ "${other_port}" = "${port}" ] && continue
160 if listmatch
${port} $
(port_get_parents
${other_port}); then
161 error_log
"Cannot destroy port '${port}' which is a parent port to '${other_port}'."
165 if listmatch
${port} $
(port_get_children
${other_port}); then
166 error_log
"Cannot destroy port '${port}' which is child of port '${other_port}'."
171 # If ok says we are not okay --> exit
172 if [ ${ok} -ne ${EXIT_OK} ]; then
178 rm -f $
(port_file
${port})
181 function port_remove
() {
185 function port_edit
() {
189 # XXX? Compatibility function
190 function port_show
() {
198 function port_down
() {
202 function port_status
() {
206 function port_info
() {
210 function port_cmd
() {
218 local hook
=$
(port_get_hook
${port})
222 hook_exec port
${hook} ${cmd} ${port} $@
225 function ports_get
() {
227 for port
in $
(port_dir
)/*; do
228 port
=$
(basename ${port})
229 if port_exists
${port}; then
235 function port_find_free
() {
243 while [ ${i} -lt 99 ]; do
244 port
=${pattern//N/${i}}
245 if ! port_exists
${port} && ! device_exists
${port}; then
255 function port_get_info
() {
260 assert port_exists
${port}
264 eval $
(port_info
${port})
269 function port_get_parents
() {
272 port_get_info
${port} PORT_PARENTS
275 function port_get_children
() {
278 port_get_info
${port} PORT_CHILDREN
281 function port_zone
() {
282 # Get name of the zones, this port is configured in.
289 for zone
in $
(zones_get_all
); do
290 if zone_has_port
${zone} ${port}; then