]>
Commit | Line | Data |
---|---|---|
1848564d MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
97cb552e | 5 | # Copyright (C) 2012 IPFire Network Development Team # |
1848564d MT |
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 | ||
f41fa3d7 | 22 | . /usr/lib/network/header-zone |
1848564d | 23 | |
97cb552e | 24 | HOOK_SETTINGS="HOOK ACCESS_CONCENTRATOR AUTH USERNAME PASSWORD" |
08e40c8c | 25 | HOOK_SETTINGS="${HOOK_SETTINGS} SERVICE_NAME MTU PORT IPV6 PREFIX_DELEGATION" |
1848564d | 26 | |
97cb552e MT |
27 | # User credentials for the dialin. |
28 | USERNAME="" | |
29 | PASSWORD="" | |
1848564d | 30 | |
97cb552e | 31 | # Set the authentication mechanism. |
1848564d | 32 | AUTH= |
97cb552e MT |
33 | |
34 | # The physical ethernet port the modem is connected to. | |
35 | PORT="" | |
36 | ||
37 | # Access Concentrator. | |
38 | ACCESS_CONCENTRATOR="" | |
39 | ||
40 | # Service name. | |
41 | SERVICE_NAME="" | |
42 | ||
43 | # Maximum Transmission Unit. | |
44 | # 1492 is a very common value for that. | |
1848564d | 45 | MTU=1492 |
1848564d | 46 | |
97cb552e | 47 | # This hook can work with all authentication methods supported by pppd. |
3a829636 | 48 | PPPOE_SUPPORTED_AUTH_METHODS="${PPP_SUPPORTED_AUTH_METHODS}" |
1848564d MT |
49 | PPPOE_PLUGIN="rp-pppoe.so" |
50 | ||
69e93b3c MT |
51 | # Request an IPv6 address. |
52 | IPV6="true" | |
53 | ||
08e40c8c MT |
54 | # Use IPv6 prefix delegation. |
55 | PREFIX_DELEGATION="false" | |
56 | ||
2181765d | 57 | function hook_check() { |
97cb552e MT |
58 | assert isset USERNAME |
59 | assert isset PASSWORD | |
261132f9 | 60 | |
3a829636 | 61 | isset AUTH && assert isoneof AUTH ${PPPOE_SUPPORTED_AUTH_METHODS} |
261132f9 | 62 | |
97cb552e MT |
63 | # Check for a valid port setting. |
64 | assert isset PORT | |
65 | assert port_exists ${PORT} | |
69e93b3c MT |
66 | |
67 | assert isset IPV6 | |
08e40c8c | 68 | assert isset PREFIX_DELEGATION |
1848564d MT |
69 | } |
70 | ||
2181765d | 71 | function hook_parse_cmdline() { |
1848564d | 72 | while [ $# -gt 0 ]; do |
97cb552e MT |
73 | case "${1}" in |
74 | --access-concentrator=*) | |
75 | ACCESS_CONCENTRATOR=$(cli_get_val ${1}) | |
1848564d | 76 | ;; |
97cb552e MT |
77 | --auth=*) |
78 | AUTH=$(cli_get_val ${1}) | |
1848564d | 79 | ;; |
69e93b3c MT |
80 | --ipv6=*) |
81 | local value="$(cli_get_val "${1}")" | |
82 | if enabled value; then | |
83 | IPV6="true" | |
84 | else | |
85 | IPV6="false" | |
86 | fi | |
87 | ;; | |
1848564d | 88 | --mtu=*) |
97cb552e | 89 | MTU=$(cli_get_val ${1}) |
1848564d | 90 | ;; |
97cb552e MT |
91 | --password=*) |
92 | PASSWORD=$(cli_get_val ${1}) | |
1848564d | 93 | ;; |
97cb552e MT |
94 | --port=*) |
95 | PORT=$(cli_get_val ${1}) | |
1848564d | 96 | ;; |
08e40c8c MT |
97 | --prefix-delegation=*) |
98 | PREFIX_DELEGATION="$(cli_get_bool "${1}")" | |
99 | ;; | |
97cb552e MT |
100 | --service-name=*) |
101 | SERVICE_NAME=$(cli_get_val ${1}) | |
1848564d | 102 | ;; |
97cb552e MT |
103 | --username=*) |
104 | USERNAME=$(cli_get_val ${1}) | |
201b7dff | 105 | ;; |
1848564d | 106 | *) |
97cb552e | 107 | warning "Unknown argument: ${1}" >&2 |
1848564d MT |
108 | ;; |
109 | esac | |
110 | shift | |
111 | done | |
1848564d MT |
112 | } |
113 | ||
2181765d | 114 | function hook_up() { |
1848564d | 115 | local zone=${1} |
711ffac1 MT |
116 | assert isset zone |
117 | ||
2044f591 MT |
118 | zone_config_read ${zone} |
119 | ||
120 | # Bring up the port. | |
121 | log DEBUG "Bringing up port '${PORT}'." | |
122 | port_up ${PORT} | |
123 | ||
97cb552e MT |
124 | # Start the ppp daemon. |
125 | pppd_start ${zone} | |
da453c33 | 126 | |
97cb552e | 127 | exit ${EXIT_OK} |
1848564d MT |
128 | } |
129 | ||
2181765d | 130 | function hook_down() { |
1848564d | 131 | local zone=${1} |
97cb552e | 132 | assert isset zone |
1848564d | 133 | |
2044f591 MT |
134 | zone_config_read ${zone} |
135 | ||
97cb552e MT |
136 | # Stop the ppp daemon. |
137 | pppd_stop ${zone} | |
1848564d | 138 | |
2044f591 MT |
139 | # Bring down the port. |
140 | log DEBUG "Bringing down port '${PORT}'." | |
141 | port_down ${PORT} | |
142 | ||
1848564d MT |
143 | exit ${EXIT_OK} |
144 | } | |
145 | ||
2181765d | 146 | function hook_discover() { |
1848564d MT |
147 | local device=${1} |
148 | ||
149 | if [ "$(device_get_type ${device})" != "real" ]; then | |
5b20e43a | 150 | exit ${EXIT_ERROR} |
1848564d MT |
151 | fi |
152 | ||
153 | local output | |
154 | output=$(pppoe-discovery -I ${device} -U $(uuid) 2>&1) | |
155 | ||
156 | # Exit if there was not output | |
157 | [ -z "${output}" ] && exit ${DISCOVER_ERROR} | |
158 | ||
159 | # Exit if PADI timed out | |
160 | grep -q "Timeout" <<<${output} && exit ${DISCOVER_ERROR} | |
161 | ||
162 | local ac | |
163 | while read line; do | |
164 | case "${line}" in | |
165 | Access-Concentrator:*) | |
166 | ac="${line#Access-Concentrator: }" | |
167 | ;; | |
168 | esac | |
169 | done <<<"${output}" | |
170 | ||
171 | echo "ACCESS_CONCENTRATOR=\"$ac\"" | |
172 | ||
173 | exit ${DISCOVER_OK} | |
174 | } | |
5b20e43a | 175 | |
2181765d | 176 | function hook_status() { |
8eadf1da | 177 | local zone=${1} |
711ffac1 MT |
178 | assert isset zone |
179 | ||
3cb2fc42 | 180 | cli_device_headline ${zone} |
8eadf1da | 181 | |
711ffac1 MT |
182 | zone_config_read ${zone} |
183 | ||
3cb2fc42 | 184 | cli_headline 2 "Configuration" |
97cb552e MT |
185 | cli_print_fmt1 2 "Username" "${USERNAME}" |
186 | cli_print_fmt1 2 "Password" "<hidden>" | |
187 | cli_print_fmt1 2 "Port" "${PORT}" | |
3cb2fc42 MT |
188 | cli_space |
189 | ||
8eadf1da MT |
190 | # Exit if zone is down |
191 | if ! zone_is_up ${zone}; then | |
192 | echo # Empty line | |
193 | exit ${EXIT_ERROR} | |
194 | fi | |
195 | ||
711ffac1 MT |
196 | # XXX display time since connection started |
197 | ||
3cb2fc42 | 198 | cli_headline 2 "Point-to-Point-over-Ethernet protocol" |
201b7dff MT |
199 | local proto |
200 | for proto in ${IP_SUPPORTED_PROTOCOLS}; do | |
201 | routing_db_exists ${zone} ${proto} || continue | |
3cb2fc42 MT |
202 | |
203 | local headline | |
204 | case "${proto}" in | |
205 | ipv6) | |
206 | headline="Internet Protocol Version 6" | |
207 | ;; | |
208 | ipv4) | |
209 | headline="Internet Protocol Version 4" | |
210 | ;; | |
211 | *) | |
212 | headline="Unkown protocol" | |
213 | ;; | |
214 | esac | |
215 | cli_headline 3 "${headline}" | |
216 | ||
217 | cli_print_fmt1 3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)" | |
218 | cli_print_fmt1 3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)" | |
219 | cli_print_fmt1 3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)" | |
220 | cli_space | |
221 | cli_print_fmt1 3 "MAC-Remote" "$(routing_db_get ${zone} ${proto} remote-address)" | |
222 | cli_space | |
201b7dff | 223 | done |
3cb2fc42 | 224 | |
8eadf1da MT |
225 | exit ${EXIT_OK} |
226 | } | |
227 | ||
2181765d | 228 | function hook_ppp_write_config() { |
97cb552e MT |
229 | local zone=${1} |
230 | assert isset zone | |
231 | ||
232 | local file=${2} | |
233 | assert isset file | |
234 | ||
235 | # Read in the configuration files. | |
236 | zone_config_read ${zone} | |
237 | ||
97cb552e MT |
238 | # Prepare the command line options for the pppoe plugin. |
239 | local plugin_options | |
240 | ||
241 | # Add the access concentrator (if any). | |
242 | if isset ACCESS_CONCENTRATOR; then | |
243 | plugin_options="${plugin_options} rp_pppoe_ac '${ACCESS_CONCENTRATOR}'" | |
711ffac1 MT |
244 | fi |
245 | ||
97cb552e MT |
246 | # Add the service name (if any). |
247 | if isset SERVICE_NAME; then | |
248 | plugin_options="${plugin_options} rp_pppoe_service '${SERVICE_NAME}'" | |
249 | fi | |
711ffac1 | 250 | |
97cb552e MT |
251 | # The last argument must be the interface. |
252 | plugin_options="${plugin_options} ${PORT}" | |
253 | ||
254 | pppd_write_config ${file} \ | |
255 | --interface="${zone}" \ | |
6c74a64c MT |
256 | --username="${USERNAME}" \ |
257 | --password="${PASSWORD}" \ | |
97cb552e MT |
258 | --mtu="${MTU}" \ |
259 | --auth="${AUTH}" \ | |
69e93b3c | 260 | --ipv6="${IPV6}" \ |
97cb552e MT |
261 | \ |
262 | --plugin="${PPPOE_PLUGIN}" \ | |
263 | --plugin-options="${plugin_options}" | |
264 | ||
6c74a64c | 265 | exit ${EXIT_OK} |
711ffac1 | 266 | } |