]>
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 | ||
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 | ||
ef53293c | 30 | HOOK_SETTINGS="HOOK ADDRESS DEVICE MTU" |
711ffac1 | 31 | |
1c6a4e30 | 32 | hook_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 | |
711ffac1 MT |
42 | } |
43 | ||
c1c6a024 MT |
44 | hook_parse_cmdline() { |
45 | while [ $# -gt 0 ]; do | |
46 | case "${1}" in | |
47 | --address=*) | |
48 | ADDRESS="$(cli_get_val "${1}")" | |
49 | ||
50 | if ! mac_is_valid "${ADDRESS}"; then | |
51 | error "Invalid MAC address: ${ADDRESS}" | |
52 | return ${EXIT_ERROR} | |
53 | fi | |
54 | ;; | |
ef53293c MT |
55 | |
56 | --mtu=*) | |
57 | MTU="$(cli_get_val "${1}")" | |
58 | ||
59 | if ! mtu_is_valid "ethernet" "${MTU}"; then | |
60 | error "Invalid MTU: ${MTU}" | |
61 | return ${EXIT_ERROR} | |
62 | fi | |
63 | ;; | |
c1c6a024 MT |
64 | *) |
65 | error "Unknown argument: ${1}" | |
66 | return ${EXIT_ERROR} | |
67 | ;; | |
68 | esac | |
69 | shift | |
70 | done | |
71 | } | |
72 | ||
3d007f4c MT |
73 | hook_create() { |
74 | return ${EXIT_OK} | |
75 | } | |
76 | ||
ef53293c | 77 | hook_up() { |
79271f35 MT |
78 | local port="${1}" |
79 | ||
ef53293c MT |
80 | local ${HOOK_SETTINGS} |
81 | if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then | |
82 | log ERROR "Could not read settings for port ${port}" | |
83 | return ${EXIT_ERROR} | |
84 | fi | |
85 | ||
79271f35 MT |
86 | # Set MAC address, if needed |
87 | if isset ADDRESS; then | |
88 | device_set_address "${port}" "${ADDRESS}" | |
89 | fi | |
90 | ||
ef53293c MT |
91 | # Set MTU |
92 | if isset MTU; then | |
93 | device_set_mtu "${port}" "${MTU}" | |
94 | else | |
95 | device_set_mtu "${port}" "${DEFAULT_MTU}" | |
96 | fi | |
97 | ||
98 | # Bring up the device | |
99 | device_set_up "${port}" | |
100 | ||
711ffac1 MT |
101 | exit ${EXIT_OK} |
102 | } | |
103 | ||
1c6a4e30 | 104 | hook_remove() { |
711ffac1 MT |
105 | exit ${EXIT_OK} |
106 | } | |
107 | ||
1c6a4e30 | 108 | hook_hotplug_rename() { |
8895cf8f | 109 | local port=${1} |
8895cf8f | 110 | assert isset port |
64b7bffd MT |
111 | |
112 | local device=${2} | |
8895cf8f MT |
113 | assert isset device |
114 | ||
64b7bffd | 115 | # Read in the conifguration file. |
e9df08ad | 116 | port_settings_read "${port}" ${HOOK_SETTINGS} |
64b7bffd MT |
117 | |
118 | # Get the current MAC address of the device. | |
119 | local address=$(device_get_address ${device}) | |
120 | assert isset address | |
8895cf8f | 121 | |
64b7bffd MT |
122 | # Check if the address matches with the configuration. |
123 | if list_match "${address}" ${DEVICE} ${ADDRESS}; then | |
8c63fa13 | 124 | log DEBUG "Device '${device}' equals port '${port}'." |
2f7adf2c | 125 | exit ${EXIT_OK} |
8895cf8f MT |
126 | fi |
127 | ||
8c63fa13 | 128 | log DEBUG "Device '${device}' does not equal port '${port}'." |
8895cf8f MT |
129 | exit ${EXIT_ERROR} |
130 | } |