]>
Commit | Line | Data |
---|---|---|
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 |
25 | DEFAULT_MTU=1500 | |
26 | ||
3a0e1dda MT |
27 | # Selectable speeds in MBit/s |
28 | VALID_SPEEDS="10000 1000 100 10" | |
29 | ||
178aabc0 MT |
30 | # We can run in full or half duplex |
31 | VALID_DUPLEXES="full half" | |
32 | ||
64b7bffd MT |
33 | # DEVICE equals the actual MAC address of the device. |
34 | # If ADDRESS is set, the device will get ADDRESS set for its MAC address. | |
35 | ||
178aabc0 | 36 | HOOK_SETTINGS="HOOK ADDRESS DEVICE DUPLEX MTU SPEED" |
711ffac1 | 37 | |
1c6a4e30 | 38 | hook_check_settings() { |
64b7bffd MT |
39 | assert ismac DEVICE |
40 | ||
41 | if isset ADDRESS; then | |
42 | assert ismac ADDRESS | |
43 | fi | |
ef53293c MT |
44 | |
45 | if isset MTU; then | |
46 | assert mtu_is_valid "ethernet" "${MTU}" | |
47 | fi | |
3a0e1dda | 48 | |
178aabc0 MT |
49 | if isset DUPLEX; then |
50 | assert isoneof DUPLEX ${VALID_DUPLEXES} | |
51 | fi | |
52 | ||
3a0e1dda MT |
53 | if isset SPEED; then |
54 | assert isoneof SPEED ${VALID_SPEEDS} | |
55 | fi | |
711ffac1 MT |
56 | } |
57 | ||
c1c6a024 MT |
58 | hook_parse_cmdline() { |
59 | while [ $# -gt 0 ]; do | |
60 | case "${1}" in | |
61 | --address=*) | |
62 | ADDRESS="$(cli_get_val "${1}")" | |
63 | ||
64 | if ! mac_is_valid "${ADDRESS}"; then | |
65 | error "Invalid MAC address: ${ADDRESS}" | |
66 | return ${EXIT_ERROR} | |
67 | fi | |
68 | ;; | |
ef53293c | 69 | |
178aabc0 MT |
70 | --duplex=*) |
71 | DUPLEX="$(cli_get_val "${1}")" | |
72 | ||
73 | if ! isoneof DUPLEX ${VALID_DUPLEXES}; then | |
74 | error "Invalid duplex mode: ${DUPLEX}" | |
75 | return ${EXIT_ERROR} | |
76 | fi | |
77 | ;; | |
78 | ||
ef53293c MT |
79 | --mtu=*) |
80 | MTU="$(cli_get_val "${1}")" | |
81 | ||
82 | if ! mtu_is_valid "ethernet" "${MTU}"; then | |
83 | error "Invalid MTU: ${MTU}" | |
84 | return ${EXIT_ERROR} | |
85 | fi | |
86 | ;; | |
3a0e1dda MT |
87 | |
88 | --speed=*) | |
89 | SPEED="$(cli_get_val "${1}")" | |
90 | ||
91 | if ! isoneof SPEED ${VALID_SPEEDS}; then | |
92 | error "Invalid speed: ${SPEED}" | |
93 | return ${EXIT_ERROR} | |
94 | fi | |
95 | ;; | |
96 | ||
c1c6a024 MT |
97 | *) |
98 | error "Unknown argument: ${1}" | |
99 | return ${EXIT_ERROR} | |
100 | ;; | |
101 | esac | |
102 | shift | |
103 | done | |
104 | } | |
105 | ||
3d007f4c MT |
106 | hook_create() { |
107 | return ${EXIT_OK} | |
108 | } | |
109 | ||
ef53293c | 110 | hook_up() { |
79271f35 MT |
111 | local port="${1}" |
112 | ||
ef53293c MT |
113 | local ${HOOK_SETTINGS} |
114 | if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then | |
115 | log ERROR "Could not read settings for port ${port}" | |
116 | return ${EXIT_ERROR} | |
117 | fi | |
118 | ||
79271f35 MT |
119 | # Set MAC address, if needed |
120 | if isset ADDRESS; then | |
121 | device_set_address "${port}" "${ADDRESS}" | |
122 | fi | |
123 | ||
ef53293c MT |
124 | # Set MTU |
125 | if isset MTU; then | |
126 | device_set_mtu "${port}" "${MTU}" | |
127 | else | |
128 | device_set_mtu "${port}" "${DEFAULT_MTU}" | |
129 | fi | |
130 | ||
178aabc0 MT |
131 | # Set duplex mode |
132 | if isset DUPLEX; then | |
133 | device_set_duplex "${port}" "${DUPLEX}" | |
134 | fi | |
135 | ||
3a0e1dda MT |
136 | # Set speed |
137 | if isset SPEED; then | |
138 | device_set_speed "${port}" "${SPEED}" | |
139 | fi | |
140 | ||
ef53293c MT |
141 | # Bring up the device |
142 | device_set_up "${port}" | |
143 | ||
711ffac1 MT |
144 | exit ${EXIT_OK} |
145 | } | |
146 | ||
1c6a4e30 | 147 | hook_remove() { |
711ffac1 MT |
148 | exit ${EXIT_OK} |
149 | } | |
150 | ||
1c6a4e30 | 151 | hook_hotplug_rename() { |
8895cf8f | 152 | local port=${1} |
8895cf8f | 153 | assert isset port |
64b7bffd MT |
154 | |
155 | local device=${2} | |
8895cf8f MT |
156 | assert isset device |
157 | ||
64b7bffd | 158 | # Read in the conifguration file. |
e9df08ad | 159 | port_settings_read "${port}" ${HOOK_SETTINGS} |
64b7bffd MT |
160 | |
161 | # Get the current MAC address of the device. | |
162 | local address=$(device_get_address ${device}) | |
163 | assert isset address | |
8895cf8f | 164 | |
64b7bffd MT |
165 | # Check if the address matches with the configuration. |
166 | if list_match "${address}" ${DEVICE} ${ADDRESS}; then | |
8c63fa13 | 167 | log DEBUG "Device '${device}' equals port '${port}'." |
2f7adf2c | 168 | exit ${EXIT_OK} |
8895cf8f MT |
169 | fi |
170 | ||
8c63fa13 | 171 | log DEBUG "Device '${device}' does not equal port '${port}'." |
8895cf8f MT |
172 | exit ${EXIT_ERROR} |
173 | } |