]>
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" |
69e93b3c | 25 | HOOK_SETTINGS="${HOOK_SETTINGS} SERVICE_NAME MTU PORT IPV6" |
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 | ||
97cb552e MT |
54 | function _check() { |
55 | assert isset USERNAME | |
56 | assert isset PASSWORD | |
261132f9 | 57 | |
3a829636 | 58 | isset AUTH && assert isoneof AUTH ${PPPOE_SUPPORTED_AUTH_METHODS} |
261132f9 | 59 | |
97cb552e MT |
60 | # Check for a valid port setting. |
61 | assert isset PORT | |
62 | assert port_exists ${PORT} | |
69e93b3c MT |
63 | |
64 | assert isset IPV6 | |
1848564d MT |
65 | } |
66 | ||
67 | function _parse_cmdline() { | |
68 | while [ $# -gt 0 ]; do | |
97cb552e MT |
69 | case "${1}" in |
70 | --access-concentrator=*) | |
71 | ACCESS_CONCENTRATOR=$(cli_get_val ${1}) | |
1848564d | 72 | ;; |
97cb552e MT |
73 | --auth=*) |
74 | AUTH=$(cli_get_val ${1}) | |
1848564d | 75 | ;; |
69e93b3c MT |
76 | --ipv6=*) |
77 | local value="$(cli_get_val "${1}")" | |
78 | if enabled value; then | |
79 | IPV6="true" | |
80 | else | |
81 | IPV6="false" | |
82 | fi | |
83 | ;; | |
1848564d | 84 | --mtu=*) |
97cb552e | 85 | MTU=$(cli_get_val ${1}) |
1848564d | 86 | ;; |
97cb552e MT |
87 | --password=*) |
88 | PASSWORD=$(cli_get_val ${1}) | |
1848564d | 89 | ;; |
97cb552e MT |
90 | --port=*) |
91 | PORT=$(cli_get_val ${1}) | |
1848564d | 92 | ;; |
97cb552e MT |
93 | --service-name=*) |
94 | SERVICE_NAME=$(cli_get_val ${1}) | |
1848564d | 95 | ;; |
97cb552e MT |
96 | --username=*) |
97 | USERNAME=$(cli_get_val ${1}) | |
201b7dff | 98 | ;; |
1848564d | 99 | *) |
97cb552e | 100 | warning "Unknown argument: ${1}" >&2 |
1848564d MT |
101 | ;; |
102 | esac | |
103 | shift | |
104 | done | |
1848564d MT |
105 | } |
106 | ||
107 | function _up() { | |
108 | local zone=${1} | |
711ffac1 MT |
109 | assert isset zone |
110 | ||
2044f591 MT |
111 | zone_config_read ${zone} |
112 | ||
113 | # Bring up the port. | |
114 | log DEBUG "Bringing up port '${PORT}'." | |
115 | port_up ${PORT} | |
116 | ||
97cb552e MT |
117 | # Start the ppp daemon. |
118 | pppd_start ${zone} | |
da453c33 | 119 | |
97cb552e | 120 | exit ${EXIT_OK} |
1848564d MT |
121 | } |
122 | ||
123 | function _down() { | |
124 | local zone=${1} | |
97cb552e | 125 | assert isset zone |
1848564d | 126 | |
2044f591 MT |
127 | zone_config_read ${zone} |
128 | ||
97cb552e MT |
129 | # Stop the ppp daemon. |
130 | pppd_stop ${zone} | |
1848564d | 131 | |
2044f591 MT |
132 | # Bring down the port. |
133 | log DEBUG "Bringing down port '${PORT}'." | |
134 | port_down ${PORT} | |
135 | ||
1848564d MT |
136 | exit ${EXIT_OK} |
137 | } | |
138 | ||
139 | function _discover() { | |
140 | local device=${1} | |
141 | ||
142 | if [ "$(device_get_type ${device})" != "real" ]; then | |
5b20e43a | 143 | exit ${EXIT_ERROR} |
1848564d MT |
144 | fi |
145 | ||
146 | local output | |
147 | output=$(pppoe-discovery -I ${device} -U $(uuid) 2>&1) | |
148 | ||
149 | # Exit if there was not output | |
150 | [ -z "${output}" ] && exit ${DISCOVER_ERROR} | |
151 | ||
152 | # Exit if PADI timed out | |
153 | grep -q "Timeout" <<<${output} && exit ${DISCOVER_ERROR} | |
154 | ||
155 | local ac | |
156 | while read line; do | |
157 | case "${line}" in | |
158 | Access-Concentrator:*) | |
159 | ac="${line#Access-Concentrator: }" | |
160 | ;; | |
161 | esac | |
162 | done <<<"${output}" | |
163 | ||
164 | echo "ACCESS_CONCENTRATOR=\"$ac\"" | |
165 | ||
166 | exit ${DISCOVER_OK} | |
167 | } | |
5b20e43a | 168 | |
8eadf1da MT |
169 | function _status() { |
170 | local zone=${1} | |
711ffac1 MT |
171 | assert isset zone |
172 | ||
3cb2fc42 | 173 | cli_device_headline ${zone} |
8eadf1da | 174 | |
711ffac1 MT |
175 | zone_config_read ${zone} |
176 | ||
3cb2fc42 | 177 | cli_headline 2 "Configuration" |
97cb552e MT |
178 | cli_print_fmt1 2 "Username" "${USERNAME}" |
179 | cli_print_fmt1 2 "Password" "<hidden>" | |
180 | cli_print_fmt1 2 "Port" "${PORT}" | |
3cb2fc42 MT |
181 | cli_space |
182 | ||
8eadf1da MT |
183 | # Exit if zone is down |
184 | if ! zone_is_up ${zone}; then | |
185 | echo # Empty line | |
186 | exit ${EXIT_ERROR} | |
187 | fi | |
188 | ||
711ffac1 MT |
189 | # XXX display time since connection started |
190 | ||
3cb2fc42 | 191 | cli_headline 2 "Point-to-Point-over-Ethernet protocol" |
201b7dff MT |
192 | local proto |
193 | for proto in ${IP_SUPPORTED_PROTOCOLS}; do | |
194 | routing_db_exists ${zone} ${proto} || continue | |
3cb2fc42 MT |
195 | |
196 | local headline | |
197 | case "${proto}" in | |
198 | ipv6) | |
199 | headline="Internet Protocol Version 6" | |
200 | ;; | |
201 | ipv4) | |
202 | headline="Internet Protocol Version 4" | |
203 | ;; | |
204 | *) | |
205 | headline="Unkown protocol" | |
206 | ;; | |
207 | esac | |
208 | cli_headline 3 "${headline}" | |
209 | ||
210 | cli_print_fmt1 3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)" | |
211 | cli_print_fmt1 3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)" | |
212 | cli_print_fmt1 3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)" | |
213 | cli_space | |
214 | cli_print_fmt1 3 "MAC-Remote" "$(routing_db_get ${zone} ${proto} remote-address)" | |
215 | cli_space | |
201b7dff | 216 | done |
3cb2fc42 | 217 | |
8eadf1da MT |
218 | exit ${EXIT_OK} |
219 | } | |
220 | ||
97cb552e MT |
221 | function _ppp_write_config() { |
222 | local zone=${1} | |
223 | assert isset zone | |
224 | ||
225 | local file=${2} | |
226 | assert isset file | |
227 | ||
228 | # Read in the configuration files. | |
229 | zone_config_read ${zone} | |
230 | ||
97cb552e MT |
231 | # Prepare the command line options for the pppoe plugin. |
232 | local plugin_options | |
233 | ||
234 | # Add the access concentrator (if any). | |
235 | if isset ACCESS_CONCENTRATOR; then | |
236 | plugin_options="${plugin_options} rp_pppoe_ac '${ACCESS_CONCENTRATOR}'" | |
711ffac1 MT |
237 | fi |
238 | ||
97cb552e MT |
239 | # Add the service name (if any). |
240 | if isset SERVICE_NAME; then | |
241 | plugin_options="${plugin_options} rp_pppoe_service '${SERVICE_NAME}'" | |
242 | fi | |
711ffac1 | 243 | |
97cb552e MT |
244 | # The last argument must be the interface. |
245 | plugin_options="${plugin_options} ${PORT}" | |
246 | ||
247 | pppd_write_config ${file} \ | |
248 | --interface="${zone}" \ | |
6c74a64c MT |
249 | --username="${USERNAME}" \ |
250 | --password="${PASSWORD}" \ | |
97cb552e MT |
251 | --mtu="${MTU}" \ |
252 | --auth="${AUTH}" \ | |
69e93b3c | 253 | --ipv6="${IPV6}" \ |
97cb552e MT |
254 | \ |
255 | --plugin="${PPPOE_PLUGIN}" \ | |
256 | --plugin-options="${plugin_options}" | |
257 | ||
6c74a64c | 258 | exit ${EXIT_OK} |
711ffac1 | 259 | } |