2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
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. #
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. #
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/>. #
20 ###############################################################################
22 .
/usr
/lib
/network
/header-zone
24 HOOK_SETTINGS
="HOOK ACCESS_CONCENTRATOR AUTH USERNAME PASSWORD"
25 HOOK_SETTINGS
="${HOOK_SETTINGS} SERVICE_NAME MTU PORT IPV6 PREFIX_DELEGATION"
27 # User credentials for the dialin.
31 # Set the authentication mechanism.
34 # The physical ethernet port the modem is connected to.
37 # Access Concentrator.
38 ACCESS_CONCENTRATOR
=""
43 # Maximum Transmission Unit.
44 # 1492 is a very common value for that.
47 # This hook can work with all authentication methods supported by pppd.
48 PPPOE_SUPPORTED_AUTH_METHODS
="${PPP_SUPPORTED_AUTH_METHODS}"
49 PPPOE_PLUGIN
="rp-pppoe.so"
51 # Request an IPv6 address.
54 # Use IPv6 prefix delegation.
55 PREFIX_DELEGATION
="false"
57 function hook_check
() {
61 isset AUTH
&& assert isoneof AUTH
${PPPOE_SUPPORTED_AUTH_METHODS}
63 # Check for a valid port setting.
65 assert port_exists
${PORT}
68 assert isset PREFIX_DELEGATION
71 function hook_parse_cmdline
() {
72 while [ $# -gt 0 ]; do
74 --access-concentrator=*)
75 ACCESS_CONCENTRATOR
=$
(cli_get_val
${1})
78 AUTH
=$
(cli_get_val
${1})
81 local value
="$(cli_get_val "${1}")"
82 if enabled value
; then
89 MTU
=$
(cli_get_val
${1})
92 PASSWORD
=$
(cli_get_val
${1})
95 PORT
=$
(cli_get_val
${1})
97 --prefix-delegation=*)
98 PREFIX_DELEGATION
="$(cli_get_bool "${1}")"
101 SERVICE_NAME
=$
(cli_get_val
${1})
104 USERNAME
=$
(cli_get_val
${1})
107 warning
"Unknown argument: ${1}" >&2
118 zone_config_read
${zone}
121 log DEBUG
"Bringing up port '${PORT}'."
124 # Start the ppp daemon.
130 function hook_down
() {
134 zone_config_read
${zone}
136 # Stop the ppp daemon.
139 # Bring down the port.
140 log DEBUG
"Bringing down port '${PORT}'."
146 function hook_discover
() {
149 if [ "$(device_get_type ${device})" != "real" ]; then
154 output
=$
(pppoe-discovery
-I ${device} -U $
(uuid
) 2>&1)
156 # Exit if there was not output
157 [ -z "${output}" ] && exit ${DISCOVER_ERROR}
159 # Exit if PADI timed out
160 grep -q "Timeout" <<<${output} && exit ${DISCOVER_ERROR}
165 Access-Concentrator
:*)
166 ac
="${line#Access-Concentrator: }"
171 echo "ACCESS_CONCENTRATOR=\"$ac\""
176 function hook_status
() {
180 cli_device_headline
${zone}
182 zone_config_read
${zone}
184 cli_headline
2 "Configuration"
185 cli_print_fmt1
2 "Username" "${USERNAME}"
186 cli_print_fmt1
2 "Password" "<hidden>"
187 cli_print_fmt1
2 "Port" "${PORT}"
190 # Exit if zone is down
191 if ! zone_is_up
${zone}; then
196 # XXX display time since connection started
198 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
200 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
201 routing_db_exists
${zone} ${proto} ||
continue
206 headline
="Internet Protocol Version 6"
209 headline
="Internet Protocol Version 4"
212 headline
="Unkown protocol"
215 cli_headline
3 "${headline}"
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)"
221 cli_print_fmt1
3 "MAC-Remote" "$(routing_db_get ${zone} ${proto} remote-address)"
228 function hook_ppp_write_config
() {
235 # Read in the configuration files.
236 zone_config_read
${zone}
238 # Prepare the command line options for the pppoe plugin.
241 # Add the access concentrator (if any).
242 if isset ACCESS_CONCENTRATOR
; then
243 plugin_options
="${plugin_options} rp_pppoe_ac '${ACCESS_CONCENTRATOR}'"
246 # Add the service name (if any).
247 if isset SERVICE_NAME
; then
248 plugin_options
="${plugin_options} rp_pppoe_service '${SERVICE_NAME}'"
251 # The last argument must be the interface.
252 plugin_options
="${plugin_options} ${PORT}"
254 pppd_write_config
${file} \
255 --interface="${zone}" \
256 --username="${USERNAME}" \
257 --password="${PASSWORD}" \
262 --plugin="${PPPOE_PLUGIN}" \
263 --plugin-options="${plugin_options}"