]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | . /usr/lib/network/header-port | |
23 | ||
24 | HOOK_SETTINGS=( | |
25 | "ADDRESS" | |
26 | "ADVERTISED_LINK_SPEEDS" | |
27 | "DEVICE" | |
28 | "OFFLOADING" | |
29 | "MTU" | |
30 | ) | |
31 | ||
32 | hook_check_settings() { | |
33 | assert ismac DEVICE | |
34 | ||
35 | # Invalid MAC addresses are not allowed | |
36 | assert not isoneof DEVICE 00:00:00:00:00:00 ff:ff:ff:ff:ff:ff | |
37 | ||
38 | if isset ADDRESS; then | |
39 | assert ismac ADDRESS | |
40 | fi | |
41 | ||
42 | if isset MTU; then | |
43 | assert mtu_is_valid "ethernet" "${MTU}" | |
44 | fi | |
45 | ||
46 | if isset MODES; then | |
47 | local mode | |
48 | for mode in ${MODES}; do | |
49 | assert [ -n "${DEVICE_LINK_SPEEDS[${mode}]}" ] | |
50 | done | |
51 | fi | |
52 | } | |
53 | ||
54 | hook_parse_cmdline() { | |
55 | while [ $# -gt 0 ]; do | |
56 | case "${1}" in | |
57 | --address=*) | |
58 | ADDRESS="$(cli_get_val "${1}")" | |
59 | ||
60 | if ! mac_is_valid "${ADDRESS}"; then | |
61 | error "Invalid MAC address: ${ADDRESS}" | |
62 | return ${EXIT_ERROR} | |
63 | fi | |
64 | ;; | |
65 | ||
66 | --advertised-link-speeds=*) | |
67 | ADVERTISED_LINK_SPEEDS="$(cli_get_val "${1}")" | |
68 | ||
69 | local speed | |
70 | for speed in ${ADVERTISED_LINK_SPEEDS}; do | |
71 | if [ -z "${DEVICE_LINK_SPEEDS[${speed}]}" ]; then | |
72 | error "Unsupported link speed: ${speed}" | |
73 | return ${EXIT_ERROR} | |
74 | fi | |
75 | done | |
76 | ;; | |
77 | ||
78 | --mtu=*) | |
79 | MTU="$(cli_get_val "${1}")" | |
80 | ||
81 | if ! mtu_is_valid "ethernet" "${MTU}"; then | |
82 | error "Invalid MTU: ${MTU}" | |
83 | return ${EXIT_ERROR} | |
84 | fi | |
85 | ;; | |
86 | ||
87 | --offloading=*) | |
88 | OFFLOADING="$(cli_get_bool "${1}")" | |
89 | ;; | |
90 | ||
91 | *) | |
92 | error "Unknown argument: ${1}" | |
93 | return ${EXIT_ERROR} | |
94 | ;; | |
95 | esac | |
96 | shift | |
97 | done | |
98 | } | |
99 | ||
100 | # This function is only called automatically by hotplug to create | |
101 | # a new ethernet port. | |
102 | hook_new() { | |
103 | local port="${1}" | |
104 | assert isset port | |
105 | ||
106 | local device="${2}" | |
107 | assert isset device | |
108 | ||
109 | local DEVICE="$(device_get_address "${device}")" | |
110 | ||
111 | if ! port_settings_write "${port}"; then | |
112 | log ERROR "Could not write settings for port ${port}" | |
113 | return ${EXIT_ERROR} | |
114 | fi | |
115 | ||
116 | return ${EXIT_OK} | |
117 | } | |
118 | ||
119 | hook_create() { | |
120 | return ${EXIT_OK} | |
121 | } | |
122 | ||
123 | hook_up() { | |
124 | local port="${1}" | |
125 | ||
126 | local ${HOOK_SETTINGS[*]} | |
127 | if ! port_settings_read "${port}"; then | |
128 | log ERROR "Could not read settings for port ${port}" | |
129 | return ${EXIT_ERROR} | |
130 | fi | |
131 | ||
132 | # Set MAC address, if needed | |
133 | if isset ADDRESS; then | |
134 | device_set_address "${port}" "${ADDRESS}" | |
135 | fi | |
136 | ||
137 | # Set MTU | |
138 | if isset MTU; then | |
139 | device_set_mtu "${port}" "${MTU}" | |
140 | else | |
141 | device_set_mtu "${port}" "${DEFAULT_MTU}" | |
142 | fi | |
143 | ||
144 | # Set link speeds | |
145 | if isset ADVERTISED_LINK_SPEEDS; then | |
146 | device_advertise_link_speeds "${port}" ${ADVERTISED_LINK_SPEEDS} | |
147 | fi | |
148 | ||
149 | # Auto-enable or disable hardware offloading | |
150 | if ! isset OFFLOADING || enabled OFFLOADING; then | |
151 | offloading_auto "${port}" | |
152 | else | |
153 | offloading_disable_all "${port}" | |
154 | fi | |
155 | ||
156 | # Bring up the device | |
157 | device_set_up "${port}" | |
158 | ||
159 | exit ${EXIT_OK} | |
160 | } | |
161 | ||
162 | hook_remove() { | |
163 | exit ${EXIT_OK} | |
164 | } | |
165 | ||
166 | hook_hotplug_rename() { | |
167 | hook_hotplug_rename_by_address "$@" | |
168 | } |