]> git.ipfire.org Git - people/ms/network.git/blame - src/hooks/ports/ethernet
port: ethernet: Use combined setting for advertised link speeds
[people/ms/network.git] / src / hooks / ports / ethernet
CommitLineData
711ffac1
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
8c63fa13 22. /usr/lib/network/header-port
711ffac1 23
ef53293c
MT
24# Default MTU
25DEFAULT_MTU=1500
26
64b7bffd
MT
27# DEVICE equals the actual MAC address of the device.
28# If ADDRESS is set, the device will get ADDRESS set for its MAC address.
29
5b1fd814 30HOOK_SETTINGS="HOOK ADDRESS ADVERTISED_LINK_SPEEDS DEVICE MTU"
711ffac1 31
1c6a4e30 32hook_check_settings() {
64b7bffd
MT
33 assert ismac DEVICE
34
35 if isset ADDRESS; then
36 assert ismac ADDRESS
37 fi
ef53293c
MT
38
39 if isset MTU; then
40 assert mtu_is_valid "ethernet" "${MTU}"
41 fi
3a0e1dda 42
5b1fd814
MT
43 if isset MODES; then
44 local mode
45 for mode in ${MODES}; do
46 assert [ -n "${DEVICE_LINK_SPEEDS[${mode}]}" ]
47 done
3a0e1dda 48 fi
711ffac1
MT
49}
50
c1c6a024
MT
51hook_parse_cmdline() {
52 while [ $# -gt 0 ]; do
53 case "${1}" in
54 --address=*)
55 ADDRESS="$(cli_get_val "${1}")"
56
57 if ! mac_is_valid "${ADDRESS}"; then
58 error "Invalid MAC address: ${ADDRESS}"
59 return ${EXIT_ERROR}
60 fi
61 ;;
ef53293c 62
5b1fd814
MT
63 --advertised-link-speeds=*)
64 ADVERTISED_LINK_SPEEDS="$(cli_get_val "${1}")"
178aabc0 65
5b1fd814
MT
66 local speed
67 for speed in ${ADVERTISED_LINK_SPEEDS}; do
68 if [ -z "${DEVICE_LINK_SPEEDS[${speed}]}" ]; then
69 error "Unsupported link speed: ${speed}"
70 return ${EXIT_ERROR}
71 fi
72 done
178aabc0
MT
73 ;;
74
ef53293c
MT
75 --mtu=*)
76 MTU="$(cli_get_val "${1}")"
77
78 if ! mtu_is_valid "ethernet" "${MTU}"; then
79 error "Invalid MTU: ${MTU}"
80 return ${EXIT_ERROR}
81 fi
82 ;;
3a0e1dda 83
c1c6a024
MT
84 *)
85 error "Unknown argument: ${1}"
86 return ${EXIT_ERROR}
87 ;;
88 esac
89 shift
90 done
91}
92
3d007f4c
MT
93hook_create() {
94 return ${EXIT_OK}
95}
96
ef53293c 97hook_up() {
79271f35
MT
98 local port="${1}"
99
ef53293c
MT
100 local ${HOOK_SETTINGS}
101 if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
102 log ERROR "Could not read settings for port ${port}"
103 return ${EXIT_ERROR}
104 fi
105
79271f35
MT
106 # Set MAC address, if needed
107 if isset ADDRESS; then
108 device_set_address "${port}" "${ADDRESS}"
109 fi
110
ef53293c
MT
111 # Set MTU
112 if isset MTU; then
113 device_set_mtu "${port}" "${MTU}"
114 else
115 device_set_mtu "${port}" "${DEFAULT_MTU}"
116 fi
117
5b1fd814
MT
118 # Set link speeds
119 if isset ADVERTISED_LINK_SPEEDS; then
120 device_advertise_link_speeds "${port}" ${ADVERTISED_LINK_SPEEDS}
3a0e1dda
MT
121 fi
122
ef53293c
MT
123 # Bring up the device
124 device_set_up "${port}"
125
711ffac1
MT
126 exit ${EXIT_OK}
127}
128
1c6a4e30 129hook_remove() {
711ffac1
MT
130 exit ${EXIT_OK}
131}
132
1c6a4e30 133hook_hotplug_rename() {
8895cf8f 134 local port=${1}
8895cf8f 135 assert isset port
64b7bffd
MT
136
137 local device=${2}
8895cf8f
MT
138 assert isset device
139
64b7bffd 140 # Read in the conifguration file.
e9df08ad 141 port_settings_read "${port}" ${HOOK_SETTINGS}
64b7bffd
MT
142
143 # Get the current MAC address of the device.
144 local address=$(device_get_address ${device})
145 assert isset address
8895cf8f 146
64b7bffd
MT
147 # Check if the address matches with the configuration.
148 if list_match "${address}" ${DEVICE} ${ADDRESS}; then
8c63fa13 149 log DEBUG "Device '${device}' equals port '${port}'."
2f7adf2c 150 exit ${EXIT_OK}
8895cf8f
MT
151 fi
152
8c63fa13 153 log DEBUG "Device '${device}' does not equal port '${port}'."
8895cf8f
MT
154 exit ${EXIT_ERROR}
155}