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 # This hook can work with all authentication methods supported by pppd.
28 PPPOE_SUPPORTED_AUTH_METHODS
="${PPP_SUPPORTED_AUTH_METHODS}"
29 PPPOE_PLUGIN
="rp-pppoe.so"
31 # Request an IPv6 address.
34 # Use IPv6 prefix delegation.
35 DEFAULT_PREFIX_DELEGATION
="true"
37 hook_check_settings
() {
41 isset AUTH
&& assert isoneof AUTH
${PPPOE_SUPPORTED_AUTH_METHODS}
44 assert isset PREFIX_DELEGATION
47 hook_parse_cmdline
() {
48 while [ $# -gt 0 ]; do
50 --access-concentrator=*)
51 ACCESS_CONCENTRATOR
=$
(cli_get_val
"${1}")
54 AUTH
=$
(cli_get_val
"${1}")
57 local value
="$(cli_get_val "${1}")"
58 if enabled value
; then
65 MTU
=$
(cli_get_val
"${1}")
68 PASSWORD
=$
(cli_get_val
"${1}")
70 --prefix-delegation=*)
71 PREFIX_DELEGATION
="$(cli_get_bool "${1}")"
74 SERVICE_NAME
=$
(cli_get_val
"${1}")
77 USERNAME
=$
(cli_get_val
"${1}")
80 warning
"Unknown argument: ${1}" >&2
91 # If this zone's port is not set, we will return
92 # with EXIT_OK so that this zone will remain active,
93 # but we cannot start pppd.
94 local port
=$
(__hook_get_port
"${zone}")
95 if ! isset port ||
! port_exists
"${port}"; then
96 log WARNING
"Could not bring up zone '${zone}' because no port is attached"
100 zone_settings_read
"${zone}"
102 # Load the pppoe kernel module
108 # Start the ppp daemon.
118 zone_settings_read
"${zone}"
120 # Stop the ppp daemon.
123 # Bring down the port.
124 local port
=$
(__hook_get_port
"${zone}")
126 log DEBUG
"Bringing down port '${port}'"
136 case "$(hotplug_action)" in
138 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
139 # Bring up the zone if it is enabled but not active, yet.
140 zone_start_auto
"${zone}"
146 # PPPoE cannot work if the ethernet device has been removed
147 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
148 if zone_is_active
"${zone}"; then
157 exit ${EXIT_NOT_HANDLED}
163 # This obviously only works on ethernet (or compatible) devices
164 if ! device_is_ethernet_compatible
"${device}"; then
169 output
=$
(pppoe-discovery
-I ${device} -U $
(uuid
) 2>&1)
171 # Exit if there was not output
172 [ -z "${output}" ] && exit ${DISCOVER_ERROR}
174 # Exit if PADI timed out
175 grep -q "Timeout" <<<${output} && exit ${DISCOVER_ERROR}
180 Access-Concentrator
:*)
181 ac
="${line#Access-Concentrator: }"
186 echo "ACCESS_CONCENTRATOR=\"$ac\""
195 cli_device_headline
${zone}
197 zone_settings_read
"${zone}"
199 cli_headline
2 "Configuration"
200 cli_print_fmt1
2 "Username" "${USERNAME}"
201 cli_print_fmt1
2 "Password" "<hidden>"
203 local port
=$
(__hook_get_port
"${zone}")
205 cli_print_fmt1
2 "Port" "${port}"
209 # Exit if zone is down
210 if ! zone_is_up
${zone}; then
215 # XXX display time since connection started
217 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
218 cli_print_fmt1
2 "MAC-Remote" "$(db_get "${zone}/remote-address
")"
222 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
223 db_exists
"${zone}/${proto}" ||
continue
228 headline
="Internet Protocol Version 6"
231 headline
="Internet Protocol Version 4"
234 headline
="Unkown protocol"
237 cli_headline
3 "${headline}"
239 cli_print_fmt1
3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address
")"
240 cli_print_fmt1
3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address
")"
241 cli_print_fmt1
3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers
")"
248 hook_ppp_write_config
() {
255 # Read in the configuration files.
256 zone_settings_read
"${zone}"
258 # A port has to be assigned for this action
259 local port
=$
(__hook_get_port
"${zone}")
260 if ! isset port
; then
261 error
"No port assigned to pppoe hook of zone '${zone}'"
265 # Prepare the command line options for the pppoe plugin.
268 # Add the access concentrator (if any).
269 if isset ACCESS_CONCENTRATOR
; then
270 plugin_options
="${plugin_options} rp_pppoe_ac '${ACCESS_CONCENTRATOR}'"
273 # Add the service name (if any).
274 if isset SERVICE_NAME
; then
275 plugin_options
="${plugin_options} rp_pppoe_service '${SERVICE_NAME}'"
278 # The last argument must be the interface.
279 plugin_options
="${plugin_options} ${port}"
281 pppd_write_config
${file} \
282 --interface="${zone}" \
283 --username="${USERNAME}" \
284 --password="${PASSWORD}" \
289 --plugin="${PPPOE_PLUGIN}" \
290 --plugin-options="${plugin_options}"
299 for port
in $
(zone_get_ports
"${zone}"); do
308 # Excepting at least two arguments here
315 # PPPoE can only use one port
316 local ports_num
="$(zone_get_ports_num "${zone}")"
317 if [ ${ports_num} -ge 1 ]; then
318 local ports
="$(zone_get_ports "${zone}")"
319 error
"The pppoe zone hook only supports assigning one port"
320 error
" port '${ports}' has already been assigned to zone '${zone}'"
324 if ! zone_port_settings_write
"${zone}" "${port}"; then
337 # Shut down the entire zone here, because it cannot
338 # run without a port any way and removing the port would
339 # create a hotplug event which will be processed after the
340 # port has already been detached...
343 if ! zone_port_settings_remove
"${zone}" "${port}"; then
356 # Try bringing up the port if it has not been brought up before
357 if ! device_exists
"${port}"; then
358 port_create
"${port}"
361 # Make sure that the port is up
373 if device_exists
"${port}"; then
383 ppp_common_ipv6_up
"${zone}"
386 zone_settings_read
"${zone}"
388 if enabled PREFIX_DELEGATION
; then
389 dhclient_start
"${zone}" ipv6
395 hook_ppp_ipv6_down
() {
398 ppp_common_ipv6_down
"${zone}"
401 zone_settings_read
"${zone}"
403 if enabled PREFIX_DELEGATION
; then
404 dhclient_stop
"${zone}" ipv6