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"
28 for port
in $
(port_dir
)/*; do
29 port
="$(basename "${port}")"
30 if port_exists
"${port}"; then
39 # Collect all ports that are attached to a zone
41 for zone
in $
(zones_get_all
); do
42 list_append ports_in_use $
(zone_get_ports
"${zone}")
45 # Collect all ports that are enslaved by an other port
47 for port
in $
(port_list
); do
48 list_append ports_in_use $
(port_get_slaves
"${port}")
51 list_sort
${ports_in_use}
55 local ports_in_use
="$(port_list_in_use)"
58 for port
in $
(port_list
); do
59 if ! list_match
"${port}" ${ports_in_use}; then
71 config_get_hook $
(port_file
${port})
77 print
"${RUN_DIR}/ports/${port}"
81 port_settings_read
() {
85 # Save the HOOK variable.
88 settings_read
"$(port_file "${port}")" ${HOOK_SETTINGS}
94 port_settings_write
() {
100 if function_exists
"hook_check_settings"; then
101 list_append args
"--check=\"hook_check_settings\""
103 list_append args
${HOOK_SETTINGS}
105 settings_write
"$(port_file "${port}")" ${args}
116 echo "$(port_dir)/${port}"
122 [ -f "${NETWORK_CONFIG_DIR}/ports/${port}" ]
130 config_get_hook $
(port_file
${port})
140 for zone
in $
(zones_get_all
); do
143 assert zone_exists
${zone}
145 if listmatch
${port} $
(zone_get_ports
${zone}); then
162 #if port_exists ${port}; then
163 # error "Port '${port}' does already exist."
164 # return ${EXIT_ERROR}
170 if ! hook_exists port
${hook}; then
171 error
"Port hook '${hook}' does not exist."
175 #port_edit ${port} ${hook} $@
177 #if [ $? -ne ${EXIT_OK} ]; then
178 # port_destroy ${port}
181 hook_exec port
${hook} new $@
189 port_exists
${port} ||
return ${EXIT_OK}
191 # Check if the port is attached to any zone and don't delete it.
194 local attached_zone
=$
(port_is_attached
${port})
195 if [ -n "${attached_zone}" ]; then
196 error_log
"Cannot destroy port '${port}' which is attached to zone '${attached_zone}'."
200 # Check if the port is linked to any other port and don't allow the user
203 for other_port
in $
(ports_get
); do
204 [ "${other_port}" = "${port}" ] && continue
206 if listmatch
${port} $
(port_get_parents
${other_port}); then
207 error_log
"Cannot destroy port '${port}' which is a parent port to '${other_port}'."
211 if listmatch
${port} $
(port_get_children
${other_port}); then
212 error_log
"Cannot destroy port '${port}' which is child of port '${other_port}'."
217 # If ok says we are not okay --> exit
218 if [ ${ok} -ne ${EXIT_OK} ]; then
222 port_remove
"${port}"
224 rm -f $
(port_file
${port})
235 # If the device is still up, we need to bring it down first.
236 if device_is_up
"${port}"; then
240 port_cmd
"remove" "${port}"
271 local hook
=$
(port_get_hook
${port})
275 hook_exec port
${hook} ${cmd} ${port} $@
280 for port
in $
(port_dir
)/*; do
281 port
=$
(basename ${port})
282 if port_exists
${port}; then
296 while [ ${i} -lt 99 ]; do
297 port
=${pattern//N/${i}}
298 if ! port_exists
${port} && ! device_exists
${port}; then
313 assert port_exists
${port}
317 eval $
(port_info
${port})
325 port_get_info
${port} PORT_PARENTS
328 port_get_children
() {
331 port_get_info
${port} PORT_CHILDREN
335 # Get name of the zones, this port is configured in.
342 for zone
in $
(zones_get_all
); do
343 if zone_has_port
${zone} ${port}; then
352 port_hotplug_event
() {
356 hotplug_assert_in_hotplug_event
358 port_cmd
"hotplug" "${port}"
364 port_settings_read
"${port}" \
365 --ignore-superfluous-settings SLAVES
369 port_device_is_slave
() {
376 local slaves
="$(port_get_slaves "${port}")"
378 # Returns true if device is in slaves
379 list_match
"${device}" ${slaves}
385 port_settings_read
"${port}" \
386 --ignore-superfluous-settings PHY
396 # Nothing to do if an empty argument is given
401 phy
="$(phy_get_address "${phy}")"
403 local port_phy
="$(port_get_phy "${port}")"
404 [ "${port_phy}" = "${phy}" ]
407 ports_lowest_address
() {
412 for port
in $
(port_list
); do
413 # Skip all ports that do not exist
414 # any more or are not plugged in
415 device_exists
"${port}" ||
continue
417 # Skip all ports that are not proper ethernet devices
418 device_is_wireless
"${port}" && continue
419 device_is_ethernet
"${port}" ||
continue
421 list_append addresses
"$(device_get_address "${port}")"
425 addresses
="$(list_sort ${addresses})"
427 # Get the first element which is the lowest MAC address
428 list_head
${addresses}