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 function hook_check_settings
() {
58 isset AUTH
&& assert isoneof AUTH
${PPPOE_SUPPORTED_AUTH_METHODS}
61 assert isset PREFIX_DELEGATION
64 function 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}"
122 # Start the ppp daemon.
128 function hook_down
() {
132 zone_settings_read
"${zone}"
134 # Stop the ppp daemon.
137 # Bring down the port.
138 log DEBUG
"Bringing down port '${PORT}'."
144 function hook_hotplug
() {
147 case "$(hotplug_action)" in
149 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
150 # Bring up the zone if it is enabled but not active, yet.
151 zone_start_auto
"${zone}"
157 # PPPoE cannot work if the ethernet device has been removed
158 if hotplug_event_interface_is_port_of_zone
"${zone}"; then
159 if zone_is_active
"${zone}"; then
168 exit ${EXIT_NOT_HANDLED}
171 function hook_discover
() {
174 # This obviously only works on ethernet (or compatible) devices
175 if ! device_is_ethernet_compatible
"${device}"; then
180 output
=$
(pppoe-discovery
-I ${device} -U $
(uuid
) 2>&1)
182 # Exit if there was not output
183 [ -z "${output}" ] && exit ${DISCOVER_ERROR}
185 # Exit if PADI timed out
186 grep -q "Timeout" <<<${output} && exit ${DISCOVER_ERROR}
191 Access-Concentrator
:*)
192 ac
="${line#Access-Concentrator: }"
197 echo "ACCESS_CONCENTRATOR=\"$ac\""
202 function hook_status
() {
206 cli_device_headline
${zone}
208 zone_settings_read
"${zone}"
210 cli_headline
2 "Configuration"
211 cli_print_fmt1
2 "Username" "${USERNAME}"
212 cli_print_fmt1
2 "Password" "<hidden>"
214 local port
=$
(__hook_get_port
"${zone}")
216 cli_print_fmt1
2 "Port" "${port}"
220 # Exit if zone is down
221 if ! zone_is_up
${zone}; then
226 # XXX display time since connection started
228 cli_headline
2 "Point-to-Point-over-Ethernet protocol"
230 for proto
in ${IP_SUPPORTED_PROTOCOLS}; do
231 routing_db_exists
${zone} ${proto} ||
continue
236 headline
="Internet Protocol Version 6"
239 headline
="Internet Protocol Version 4"
242 headline
="Unkown protocol"
245 cli_headline
3 "${headline}"
247 cli_print_fmt1
3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)"
248 cli_print_fmt1
3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)"
249 cli_print_fmt1
3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)"
251 cli_print_fmt1
3 "MAC-Remote" "$(routing_db_get ${zone} ${proto} remote-address)"
258 function hook_ppp_write_config
() {
265 # Read in the configuration files.
266 zone_settings_read
"${zone}"
268 # A port has to be assigned for this action
269 local port
=$
(__hook_get_port
"${zone}")
270 if ! isset port
; then
271 error
"No port assigned to pppoe hook of zone '${zone}'"
275 # Prepare the command line options for the pppoe plugin.
278 # Add the access concentrator (if any).
279 if isset ACCESS_CONCENTRATOR
; then
280 plugin_options
="${plugin_options} rp_pppoe_ac '${ACCESS_CONCENTRATOR}'"
283 # Add the service name (if any).
284 if isset SERVICE_NAME
; then
285 plugin_options
="${plugin_options} rp_pppoe_service '${SERVICE_NAME}'"
288 # The last argument must be the interface.
289 plugin_options
="${plugin_options} ${port}"
291 pppd_write_config
${file} \
292 --interface="${zone}" \
293 --username="${USERNAME}" \
294 --password="${PASSWORD}" \
299 --plugin="${PPPOE_PLUGIN}" \
300 --plugin-options="${plugin_options}"
305 function __hook_get_port
() {
309 for port
in $
(zone_get_ports
"${zone}"); do
317 function hook_port_attach
() {
318 # Excepting at least two arguments here
325 # PPPoE can only use one port
326 local ports_num
="$(zone_get_ports_num "${zone}")"
327 if [ ${ports_num} -ge 1 ]; then
328 local ports
="$(zone_get_ports "${zone}")"
329 error
"The pppoe zone hook only supports assigning one port"
330 error
" port '${ports}' has already been assigned to zone '${zone}'"
334 if ! zone_port_settings_write
"${zone}" "${port}"; then
341 function hook_port_detach
() {
347 # Shut down the entire zone here, because it cannot
348 # run without a port any way and removing the port would
349 # create a hotplug event which will be processed after the
350 # port has already been detached...
353 if ! zone_port_settings_remove
"${zone}" "${port}"; then
360 function hook_ppp_ipv6_up
() {
363 ppp_common_ipv6_up
"${zone}"
366 zone_settings_read
"${zone}"
368 if enabled PREFIX_DELEGATION
; then
369 dhclient_start
"${zone}" ipv6
375 function hook_ppp_ipv6_down
() {
378 ppp_common_ipv6_down
"${zone}"
381 zone_settings_read
"${zone}"
383 if enabled PREFIX_DELEGATION
; then
384 dhclient_stop
"${zone}" ipv6