]>
git.ipfire.org Git - people/stevee/network.git/blob - src/functions/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_settings_read
() {
45 # Save the HOOK variable.
48 settings_read
"$(port_file "${port}")" "$@"
54 function port_settings_write
() {
59 settings_write
"$(port_file "${port}")" "$@"
62 function ports_get_all
() {
65 for port
in $
(port_dir
)/*; do
66 [ -f "${port}" ] ||
continue
72 function port_file
() {
76 echo "$(port_dir)/${port}"
79 function port_exists
() {
82 [ -f "${NETWORK_CONFIG_DIR}/ports/${port}" ]
85 function port_get_hook
() {
90 config_get_hook $
(port_file
${port})
93 function port_is_attached
() {
100 for zone
in $
(zones_get_all
); do
103 assert zone_exists
${zone}
105 if listmatch
${port} $
(zone_get_ports
${zone}); then
114 function port_create
() {
118 #if port_exists ${port}; then
119 # error "Port '${port}' does already exist."
120 # return ${EXIT_ERROR}
126 if ! hook_exists port
${hook}; then
127 error
"Port hook '${hook}' does not exist."
131 #port_edit ${port} ${hook} $@
133 #if [ $? -ne ${EXIT_OK} ]; then
134 # port_destroy ${port}
137 hook_exec port
${hook} create $@
140 function port_destroy
() {
145 port_exists
${port} ||
return ${EXIT_OK}
147 # Check if the port is attached to any zone and don't delete it.
150 local attached_zone
=$
(port_is_attached
${port})
151 if [ -n "${attached_zone}" ]; then
152 error_log
"Cannot destroy port '${port}' which is attached to zone '${attached_zone}'."
156 # Check if the port is linked to any other port and don't allow the user
159 for other_port
in $
(ports_get
); do
160 [ "${other_port}" = "${port}" ] && continue
162 if listmatch
${port} $
(port_get_parents
${other_port}); then
163 error_log
"Cannot destroy port '${port}' which is a parent port to '${other_port}'."
167 if listmatch
${port} $
(port_get_children
${other_port}); then
168 error_log
"Cannot destroy port '${port}' which is child of port '${other_port}'."
173 # If ok says we are not okay --> exit
174 if [ ${ok} -ne ${EXIT_OK} ]; then
180 rm -f $
(port_file
${port})
183 function port_remove
() {
187 function port_edit
() {
191 # XXX? Compatibility function
192 function port_show
() {
200 function port_down
() {
204 function port_status
() {
208 function port_info
() {
212 function port_cmd
() {
220 local hook
=$
(port_get_hook
${port})
224 hook_exec port
${hook} ${cmd} ${port} $@
227 function ports_get
() {
229 for port
in $
(port_dir
)/*; do
230 port
=$
(basename ${port})
231 if port_exists
${port}; then
237 function port_find_free
() {
245 while [ ${i} -lt 99 ]; do
246 port
=${pattern//N/${i}}
247 if ! port_exists
${port} && ! device_exists
${port}; then
257 function port_get_info
() {
262 assert port_exists
${port}
266 eval $
(port_info
${port})
271 function port_get_parents
() {
274 port_get_info
${port} PORT_PARENTS
277 function port_get_children
() {
280 port_get_info
${port} PORT_CHILDREN
283 function port_zone
() {
284 # Get name of the zones, this port is configured in.
291 for zone
in $
(zones_get_all
); do
292 if zone_has_port
${zone} ${port}; then