]>
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 | ||
64b7bffd MT |
30 | # DEVICE equals the actual MAC address of the device. |
31 | # If ADDRESS is set, the device will get ADDRESS set for its MAC address. | |
32 | ||
3a0e1dda | 33 | HOOK_SETTINGS="HOOK ADDRESS DEVICE MTU SPEED" |
711ffac1 | 34 | |
1c6a4e30 | 35 | hook_check_settings() { |
64b7bffd MT |
36 | assert ismac DEVICE |
37 | ||
38 | if isset ADDRESS; then | |
39 | assert ismac ADDRESS | |
40 | fi | |
ef53293c MT |
41 | |
42 | if isset MTU; then | |
43 | assert mtu_is_valid "ethernet" "${MTU}" | |
44 | fi | |
3a0e1dda MT |
45 | |
46 | if isset SPEED; then | |
47 | assert isoneof SPEED ${VALID_SPEEDS} | |
48 | fi | |
711ffac1 MT |
49 | } |
50 | ||
c1c6a024 MT |
51 | hook_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 MT |
62 | |
63 | --mtu=*) | |
64 | MTU="$(cli_get_val "${1}")" | |
65 | ||
66 | if ! mtu_is_valid "ethernet" "${MTU}"; then | |
67 | error "Invalid MTU: ${MTU}" | |
68 | return ${EXIT_ERROR} | |
69 | fi | |
70 | ;; | |
3a0e1dda MT |
71 | |
72 | --speed=*) | |
73 | SPEED="$(cli_get_val "${1}")" | |
74 | ||
75 | if ! isoneof SPEED ${VALID_SPEEDS}; then | |
76 | error "Invalid speed: ${SPEED}" | |
77 | return ${EXIT_ERROR} | |
78 | fi | |
79 | ;; | |
80 | ||
c1c6a024 MT |
81 | *) |
82 | error "Unknown argument: ${1}" | |
83 | return ${EXIT_ERROR} | |
84 | ;; | |
85 | esac | |
86 | shift | |
87 | done | |
88 | } | |
89 | ||
3d007f4c MT |
90 | hook_create() { |
91 | return ${EXIT_OK} | |
92 | } | |
93 | ||
ef53293c | 94 | hook_up() { |
79271f35 MT |
95 | local port="${1}" |
96 | ||
ef53293c MT |
97 | local ${HOOK_SETTINGS} |
98 | if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then | |
99 | log ERROR "Could not read settings for port ${port}" | |
100 | return ${EXIT_ERROR} | |
101 | fi | |
102 | ||
79271f35 MT |
103 | # Set MAC address, if needed |
104 | if isset ADDRESS; then | |
105 | device_set_address "${port}" "${ADDRESS}" | |
106 | fi | |
107 | ||
ef53293c MT |
108 | # Set MTU |
109 | if isset MTU; then | |
110 | device_set_mtu "${port}" "${MTU}" | |
111 | else | |
112 | device_set_mtu "${port}" "${DEFAULT_MTU}" | |
113 | fi | |
114 | ||
3a0e1dda MT |
115 | # Set speed |
116 | if isset SPEED; then | |
117 | device_set_speed "${port}" "${SPEED}" | |
118 | fi | |
119 | ||
ef53293c MT |
120 | # Bring up the device |
121 | device_set_up "${port}" | |
122 | ||
711ffac1 MT |
123 | exit ${EXIT_OK} |
124 | } | |
125 | ||
1c6a4e30 | 126 | hook_remove() { |
711ffac1 MT |
127 | exit ${EXIT_OK} |
128 | } | |
129 | ||
1c6a4e30 | 130 | hook_hotplug_rename() { |
8895cf8f | 131 | local port=${1} |
8895cf8f | 132 | assert isset port |
64b7bffd MT |
133 | |
134 | local device=${2} | |
8895cf8f MT |
135 | assert isset device |
136 | ||
64b7bffd | 137 | # Read in the conifguration file. |
e9df08ad | 138 | port_settings_read "${port}" ${HOOK_SETTINGS} |
64b7bffd MT |
139 | |
140 | # Get the current MAC address of the device. | |
141 | local address=$(device_get_address ${device}) | |
142 | assert isset address | |
8895cf8f | 143 | |
64b7bffd MT |
144 | # Check if the address matches with the configuration. |
145 | if list_match "${address}" ${DEVICE} ${ADDRESS}; then | |
8c63fa13 | 146 | log DEBUG "Device '${device}' equals port '${port}'." |
2f7adf2c | 147 | exit ${EXIT_OK} |
8895cf8f MT |
148 | fi |
149 | ||
8c63fa13 | 150 | log DEBUG "Device '${device}' does not equal port '${port}'." |
8895cf8f MT |
151 | exit ${EXIT_ERROR} |
152 | } |