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 IPV6 PREFIX_DELEGATION"
27 # User credentials for the dialin.
31 # Set the authentication mechanism.
34 # Access Concentrator.
35 ACCESS_CONCENTRATOR
=""
40 # Maximum Transmission Unit.
43 # This hook can work with all authentication methods supported by pppd.
44 PPPOE_SUPPORTED_AUTH_METHODS
="${PPP_SUPPORTED_AUTH_METHODS}"
45 PPPOE_PLUGIN
="rp-pppoe.so"
47 # Request an IPv6 address.
50 # Use IPv6 prefix delegation.
51 PREFIX_DELEGATION
="true"
53 hook_check_settings
() {
57 isset AUTH
&& assert isoneof AUTH
${PPPOE_SUPPORTED_AUTH_METHODS}
60 assert isset PREFIX_DELEGATION
63 hook_parse_cmdline
() {
64 while [ $# -gt 0 ]; do
66 --access-concentrator=*)
67 ACCESS_CONCENTRATOR
=$
(cli_get_val
"${1}")
70 AUTH
=$
(cli_get_val
"${1}")
73 local value
="$(cli_get_val "${1}")"
74 if enabled value
; then
81 MTU
=$
(cli_get_val
"${1}")
84 PASSWORD
=$
(cli_get_val
"${1}")
86 --prefix-delegation=*)
87 PREFIX_DELEGATION
="$(cli_get_bool "${1}")"
90 SERVICE_NAME
=$
(cli_get_val
"${1}")
93 USERNAME
=$
(cli_get_val
"${1}")
96 warning
"Unknown argument: ${1}" >&2
107 # If this zone's port is not set, we will return
108 # with EXIT_OK so that this zone will remain active,
109 # but we cannot start pppd.
110 local port
=$
(__hook_get_port
"${zone}")
111 if ! isset port ||
! port_exists
"${port}"; then
112 log WARNING
"Could not bring up zone '${zone}' because no port is attached"
116 zone_settings_read
"${zone}"
118 # Load the pppoe kernel module
124 # Start the ppp daemon.
134 zone_settings_read
"${zone}"
136 # Stop the ppp daemon.
139 # Bring down the port.
140 local port
=$
(__hook_get_port
"${zone}")
142 log DEBUG
"Bringing down port '${port}'"
152 case "$(hotplug_action)" in
154 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
155 # Bring up the zone if it is enabled but not active, yet.
156 zone_start_auto
"${zone}"
162 # PPPoE cannot work if the ethernet device has been removed
163 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
164 if zone_is_active
"${zone}"; then
173 exit ${EXIT_NOT_HANDLED}
179 # This obviously only works on ethernet (or compatible) devices
180 if ! device_is_ethernet_compatible
"${device}"; then
185 output
=$
(pppoe-discovery
-I ${device} -U $
(uuid
) 2>&1)
187 # Exit if there was not output
188 [ -z "${output}" ] && exit ${DISCOVER_ERROR}
190 # Exit if PADI timed out
191 grep -q "Timeout" <<<${output} && exit ${DISCOVER_ERROR}
196 Access-Concentrator
:*)
197 ac
="${line#Access-Concentrator: }"
202 echo "ACCESS_CONCENTRATOR=\"$ac\""
211 cli_device_headline
${zone}
213 zone_settings_read
"${zone}"
215 cli_headline
2 "Configuration"
216 cli_print_fmt1
2 "Username" "${USERNAME}"
217 cli_print_fmt1
2 "Password" "<hidden>"
219 local port
=$
(__hook_get_port
"${zone}")
221 cli_print_fmt1
2 "Port" "${port}"
225 # Exit if zone is down
226 if ! zone_is_up
${zone}; then
231 # XXX display time since connection started
233 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
234 cli_print_fmt1
2 "MAC-Remote" "$(db_get "${zone}/remote-address
")"
238 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
239 db_exists
"${zone}/${proto}" ||
continue
244 headline
="Internet Protocol Version 6"
247 headline
="Internet Protocol Version 4"
250 headline
="Unkown protocol"
253 cli_headline
3 "${headline}"
255 cli_print_fmt1
3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address
")"
256 cli_print_fmt1
3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address
")"
257 cli_print_fmt1
3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers
")"
264 hook_ppp_write_config
() {
271 # Read in the configuration files.
272 zone_settings_read
"${zone}"
274 # A port has to be assigned for this action
275 local port
=$
(__hook_get_port
"${zone}")
276 if ! isset port
; then
277 error
"No port assigned to pppoe hook of zone '${zone}'"
281 # Prepare the command line options for the pppoe plugin.
284 # Add the access concentrator (if any).
285 if isset ACCESS_CONCENTRATOR
; then
286 plugin_options
="${plugin_options} rp_pppoe_ac '${ACCESS_CONCENTRATOR}'"
289 # Add the service name (if any).
290 if isset SERVICE_NAME
; then
291 plugin_options
="${plugin_options} rp_pppoe_service '${SERVICE_NAME}'"
294 # The last argument must be the interface.
295 plugin_options
="${plugin_options} ${port}"
297 pppd_write_config
${file} \
298 --interface="${zone}" \
299 --username="${USERNAME}" \
300 --password="${PASSWORD}" \
305 --plugin="${PPPOE_PLUGIN}" \
306 --plugin-options="${plugin_options}"
315 for port
in $
(zone_get_ports
"${zone}"); do
324 # Excepting at least two arguments here
331 # PPPoE can only use one port
332 local ports_num
="$(zone_get_ports_num "${zone}")"
333 if [ ${ports_num} -ge 1 ]; then
334 local ports
="$(zone_get_ports "${zone}")"
335 error
"The pppoe zone hook only supports assigning one port"
336 error
" port '${ports}' has already been assigned to zone '${zone}'"
340 if ! zone_port_settings_write
"${zone}" "${port}"; then
353 # Shut down the entire zone here, because it cannot
354 # run without a port any way and removing the port would
355 # create a hotplug event which will be processed after the
356 # port has already been detached...
359 if ! zone_port_settings_remove
"${zone}" "${port}"; then
372 # Try bringing up the port if it has not been brought up before
373 if ! device_exists
"${port}"; then
374 port_create
"${port}"
377 # Make sure that the port is up
389 if device_exists
"${port}"; then
399 ppp_common_ipv6_up
"${zone}"
402 zone_settings_read
"${zone}"
404 if enabled PREFIX_DELEGATION
; then
405 dhclient_start
"${zone}" ipv6
411 hook_ppp_ipv6_down
() {
414 ppp_common_ipv6_down
"${zone}"
417 zone_settings_read
"${zone}"
419 if enabled PREFIX_DELEGATION
; then
420 dhclient_stop
"${zone}" ipv6