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.
41 # 1492 is a very common value for that.
44 # This hook can work with all authentication methods supported by pppd.
45 PPPOE_SUPPORTED_AUTH_METHODS
="${PPP_SUPPORTED_AUTH_METHODS}"
46 PPPOE_PLUGIN
="rp-pppoe.so"
48 # Request an IPv6 address.
51 # Use IPv6 prefix delegation.
52 PREFIX_DELEGATION
="true"
54 hook_check_settings
() {
58 isset AUTH
&& assert isoneof AUTH
${PPPOE_SUPPORTED_AUTH_METHODS}
61 assert isset PREFIX_DELEGATION
64 hook_parse_cmdline
() {
65 while [ $# -gt 0 ]; do
67 --access-concentrator=*)
68 ACCESS_CONCENTRATOR
=$
(cli_get_val
${1})
71 AUTH
=$
(cli_get_val
${1})
74 local value
="$(cli_get_val "${1}")"
75 if enabled value
; then
82 MTU
=$
(cli_get_val
${1})
85 PASSWORD
=$
(cli_get_val
${1})
87 --prefix-delegation=*)
88 PREFIX_DELEGATION
="$(cli_get_bool "${1}")"
91 SERVICE_NAME
=$
(cli_get_val
${1})
94 USERNAME
=$
(cli_get_val
${1})
97 warning
"Unknown argument: ${1}" >&2
108 # If this zone's port is not set, we will return
109 # with EXIT_OK so that this zone will remain active,
110 # but we cannot start pppd.
111 local port
=$
(__hook_get_port
"${zone}")
112 if ! isset port ||
! port_exists
"${port}"; then
113 log WARNING
"Could not bring up zone '${zone}' because no port is attached"
117 zone_settings_read
"${zone}"
119 # Load the pppoe kernel module
125 # Start the ppp daemon.
135 zone_settings_read
"${zone}"
137 # Stop the ppp daemon.
140 # Bring down the port.
141 local port
=$
(__hook_get_port
"${zone}")
143 log DEBUG
"Bringing down port '${port}'"
153 case "$(hotplug_action)" in
155 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
156 # Bring up the zone if it is enabled but not active, yet.
157 zone_start_auto
"${zone}"
163 # PPPoE cannot work if the ethernet device has been removed
164 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
165 if zone_is_active
"${zone}"; then
174 exit ${EXIT_NOT_HANDLED}
180 # This obviously only works on ethernet (or compatible) devices
181 if ! device_is_ethernet_compatible
"${device}"; then
186 output
=$
(pppoe-discovery
-I ${device} -U $
(uuid
) 2>&1)
188 # Exit if there was not output
189 [ -z "${output}" ] && exit ${DISCOVER_ERROR}
191 # Exit if PADI timed out
192 grep -q "Timeout" <<<${output} && exit ${DISCOVER_ERROR}
197 Access-Concentrator
:*)
198 ac
="${line#Access-Concentrator: }"
203 echo "ACCESS_CONCENTRATOR=\"$ac\""
212 cli_device_headline
${zone}
214 zone_settings_read
"${zone}"
216 cli_headline
2 "Configuration"
217 cli_print_fmt1
2 "Username" "${USERNAME}"
218 cli_print_fmt1
2 "Password" "<hidden>"
220 local port
=$
(__hook_get_port
"${zone}")
222 cli_print_fmt1
2 "Port" "${port}"
226 # Exit if zone is down
227 if ! zone_is_up
${zone}; then
232 # XXX display time since connection started
234 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
235 cli_print_fmt1
2 "MAC-Remote" "$(db_get "${zone}/remote-address
")"
239 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
240 db_exists
"${zone}/${proto}" ||
continue
245 headline
="Internet Protocol Version 6"
248 headline
="Internet Protocol Version 4"
251 headline
="Unkown protocol"
254 cli_headline
3 "${headline}"
256 cli_print_fmt1
3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address
")"
257 cli_print_fmt1
3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address
")"
258 cli_print_fmt1
3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers
")"
265 hook_ppp_write_config
() {
272 # Read in the configuration files.
273 zone_settings_read
"${zone}"
275 # A port has to be assigned for this action
276 local port
=$
(__hook_get_port
"${zone}")
277 if ! isset port
; then
278 error
"No port assigned to pppoe hook of zone '${zone}'"
282 # Prepare the command line options for the pppoe plugin.
285 # Add the access concentrator (if any).
286 if isset ACCESS_CONCENTRATOR
; then
287 plugin_options
="${plugin_options} rp_pppoe_ac '${ACCESS_CONCENTRATOR}'"
290 # Add the service name (if any).
291 if isset SERVICE_NAME
; then
292 plugin_options
="${plugin_options} rp_pppoe_service '${SERVICE_NAME}'"
295 # The last argument must be the interface.
296 plugin_options
="${plugin_options} ${port}"
298 pppd_write_config
${file} \
299 --interface="${zone}" \
300 --username="${USERNAME}" \
301 --password="${PASSWORD}" \
306 --plugin="${PPPOE_PLUGIN}" \
307 --plugin-options="${plugin_options}"
316 for port
in $
(zone_get_ports
"${zone}"); do
325 # Excepting at least two arguments here
332 # PPPoE can only use one port
333 local ports_num
="$(zone_get_ports_num "${zone}")"
334 if [ ${ports_num} -ge 1 ]; then
335 local ports
="$(zone_get_ports "${zone}")"
336 error
"The pppoe zone hook only supports assigning one port"
337 error
" port '${ports}' has already been assigned to zone '${zone}'"
341 if ! zone_port_settings_write
"${zone}" "${port}"; then
354 # Shut down the entire zone here, because it cannot
355 # run without a port any way and removing the port would
356 # create a hotplug event which will be processed after the
357 # port has already been detached...
360 if ! zone_port_settings_remove
"${zone}" "${port}"; then
370 ppp_common_ipv6_up
"${zone}"
373 zone_settings_read
"${zone}"
375 if enabled PREFIX_DELEGATION
; then
376 dhclient_start
"${zone}" ipv6
382 hook_ppp_ipv6_down
() {
385 ppp_common_ipv6_down
"${zone}"
388 zone_settings_read
"${zone}"
390 if enabled PREFIX_DELEGATION
; then
391 dhclient_stop
"${zone}" ipv6