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 ###############################################################################
24 echo "${NETWORK_CONFIG_DIR}/ports/${port}"
29 for port
in $
(port_dir
)/*; do
30 port
="$(basename "${port}")"
31 if port_exists
"${port}"; then
40 # Collect all ports that are attached to a zone
42 for zone
in $
(zones_get_all
); do
43 list_append ports_in_use $
(zone_get_ports
"${zone}")
46 # Collect all ports that are enslaved by an other port
48 for port
in $
(port_list
); do
49 list_append ports_in_use $
(port_get_slaves
"${port}")
52 list_sort
${ports_in_use}
56 local ports_in_use
="$(port_list_in_use)"
59 for port
in $
(port_list
); do
60 if ! list_match
"${port}" ${ports_in_use}; then
72 config_get_hook $
(port_file
${port})
78 print
"${RUN_DIR}/ports/${port}"
82 port_settings_read
() {
86 # Save the HOOK variable.
89 settings_read
"$(port_file "${port}")" ${HOOK_SETTINGS}
95 port_settings_write
() {
101 if function_exists
"hook_check_settings"; then
102 list_append args
"--check=\"hook_check_settings\""
104 list_append args
${HOOK_SETTINGS}
106 settings_write
"$(port_file "${port}")" ${args}
117 echo "$(port_dir ${port})/settings"
123 [ -d "${NETWORK_CONFIG_DIR}/ports/${port}" ]
131 config_get_hook $
(port_file
${port})
141 for zone
in $
(zones_get_all
); do
144 assert zone_exists
${zone}
146 if list_match
${port} $
(zone_get_ports
${zone}); then
163 if ! hook_exists port
"${hook}"; then
164 error
"Port hook '${hook}' does not exist."
168 hook_exec port
"${hook}" new $@
175 # Cannot delete a port that does not exist
176 if ! port_exists
${port}; then
177 error
"No such port: ${port}"
181 # Check if the port is attached to any zone and don't delete it.
184 local attached_zone
=$
(port_is_attached
${port})
185 if [ -n "${attached_zone}" ]; then
186 error_log
"Cannot destroy port '${port}' which is attached to zone '${attached_zone}'."
190 # Check if the port is linked to any other port and don't allow the user
193 for other_port
in $
(ports_get
); do
194 [ "${other_port}" = "${port}" ] && continue
196 if list_match
${port} $
(port_get_parents
${other_port}); then
197 error_log
"Cannot destroy port '${port}' which is a parent port to '${other_port}'."
201 if list_match
${port} $
(port_get_children
${other_port}); then
202 error_log
"Cannot destroy port '${port}' which is child of port '${other_port}'."
207 # If ok says we are not okay --> exit
208 if [ ${ok} -ne ${EXIT_OK} ]; then
212 port_remove
"${port}"
214 rm -rf $
(port_dir
${port})
225 if ! port_exists
"${port}"; then
226 log ERROR
"Port ${port} does not exist"
230 # If the device is still up, we need to bring it down first.
231 if device_is_up
"${port}"; then
235 port_cmd
"remove" "${port}"
238 # Restarts the port by removing it and then re-creating it
243 port_remove
"${port}"
245 port_create
"${port}"
276 local hook
=$
(port_get_hook
${port})
278 # Abort if we could not find a hook
279 if ! isset hook
; then
280 log CRITICAL
"Port ${port} does not have a hook associated with it"
284 hook_exec port
${hook} ${cmd} ${port} $@
289 for port
in $
(port_dir
)/*; do
290 port
=$
(basename ${port})
291 if port_exists
${port}; then
305 while [ ${i} -lt 99 ]; do
306 port
=${pattern//N/${i}}
307 if ! port_exists
${port} && ! device_exists
${port}; then
322 assert port_exists
${port}
326 eval $
(port_info
${port})
334 port_get_info
${port} PORT_PARENTS
337 port_get_children
() {
340 port_get_info
${port} PORT_CHILDREN
344 # Get name of the zones, this port is configured in.
351 for zone
in $
(zones_get_all
); do
352 if zone_has_port
${zone} ${port}; then
361 port_hotplug_event
() {
365 hotplug_assert_in_hotplug_event
367 port_cmd
"hotplug" "${port}"
373 port_settings_read
"${port}" \
374 --ignore-superfluous-settings SLAVES
378 port_device_is_slave
() {
385 local slaves
="$(port_get_slaves "${port}")"
387 # Returns true if device is in slaves
388 list_match
"${device}" ${slaves}
394 port_settings_read
"${port}" \
395 --ignore-superfluous-settings PHY
405 # Nothing to do if an empty argument is given
410 phy
="$(phy_get_address "${phy}")"
412 local port_phy
="$(port_get_phy "${port}")"
413 [ "${port_phy}" = "${phy}" ]
416 ports_lowest_address
() {
421 for port
in $
(port_list
); do
422 # Skip all ports that do not exist
423 # any more or are not plugged in
424 device_exists
"${port}" ||
continue
426 # Skip all ports that are not proper ethernet devices
427 device_is_wireless
"${port}" && continue
428 device_is_ethernet
"${port}" ||
continue
430 list_append addresses
"$(device_get_address "${port}")"
434 addresses
="$(list_sort ${addresses})"
436 # Get the first element which is the lowest MAC address
437 list_head
${addresses}
445 # This function return the color of a port
449 color_read
"port" ${name}
452 port_get_description_title
() {
456 description_title_read $
(description_format_filename
"port" "${name}")