]>
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 ports_get_all
() {
29 for port
in $
(port_dir
)/*; do
30 [ -f "${port}" ] ||
continue
36 function port_file
() {
41 echo "$(port_dir)/${port}"
44 function port_exists
() {
47 [ -f "${NETWORK_CONFIG_DIR}/ports/${port}" ]
50 function port_get_hook
() {
55 config_get_hook $
(port_file
${port})
58 function port_is_attached
() {
65 for zone
in $
(zones_get_all
); do
68 assert zone_exists
${zone}
70 if listmatch
${port} $
(zone_get_ports
${zone}); then
79 function port_create
() {
83 #if port_exists ${port}; then
84 # error "Port '${port}' does already exist."
85 # return ${EXIT_ERROR}
91 if ! hook_exists port
${hook}; then
92 error
"Port hook '${hook}' does not exist."
96 #port_edit ${port} ${hook} $@
98 #if [ $? -ne ${EXIT_OK} ]; then
99 # port_destroy ${port}
102 hook_exec port
${hook} create $@
105 function port_destroy
() {
110 port_exists
${port} ||
return ${EXIT_OK}
112 # Check if the port is attached to any zone and don't delete it.
115 local attached_zone
=$
(port_is_attached
${port})
116 if [ -n "${attached_zone}" ]; then
117 error_log
"Cannot destroy port '${port}' which is attached to zone '${attached_zone}'."
121 # Check if the port is linked to any other port and don't allow the user
124 for other_port
in $
(ports_get
); do
125 [ "${other_port}" = "${port}" ] && continue
127 if listmatch
${port} $
(port_get_parents
${other_port}); then
128 error_log
"Cannot destroy port '${port}' which is a parent port to '${other_port}'."
132 if listmatch
${port} $
(port_get_children
${other_port}); then
133 error_log
"Cannot destroy port '${port}' which is child of port '${other_port}'."
138 # If ok says we are not okay --> exit
139 if [ ${ok} -ne ${EXIT_OK} ]; then
145 rm -f $
(port_file
${port})
148 function port_remove
() {
152 function port_edit
() {
156 # XXX? Compatibility function
157 function port_show
() {
165 function port_down
() {
169 function port_status
() {
173 function port_info
() {
177 function port_cmd
() {
185 local hook
=$
(port_get_hook
${port})
189 hook_exec port
${hook} ${cmd} ${port} $@
192 function ports_get
() {
194 for port
in $
(port_dir
)/*; do
195 port
=$
(basename ${port})
196 if port_exists
${port}; then
202 function port_find_free
() {
210 while [ ${i} -lt 99 ]; do
211 port
=${pattern//N/${i}}
212 if ! port_exists
${port} && ! device_exists
${port}; then
222 function port_get_info
() {
227 assert port_exists
${port}
231 eval $
(port_info
${port})
236 function port_get_parents
() {
239 port_get_info
${port} PORT_PARENTS
242 function port_get_children
() {
245 port_get_info
${port} PORT_CHILDREN
248 function port_zone
() {
249 # Get name of the zones, this port is configured in.
256 for zone
in $
(zones_get_all
); do
257 if zone_has_port
${zone} ${port}; then