2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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 .
/lib
/network
/header-zone
24 # TODO AC name, service name, sync?
26 HOOK_SETTINGS
="HOOK AUTH LINKNAME USER SECRET PEERDNS DEFAULTROUTE MTU"
27 HOOK_SETTINGS
="${HOOK_SETTINGS} DEVICE DEVICE_VID DEVICE_TYPE"
37 PPPOE_ALLOWED_AUTHS
="chap pap"
38 PPPOE_PLUGIN
="rp-pppoe.so"
40 function _pppoe_real_device
() {
42 if [ -n "${DEVICE_VID}" ]; then
43 device
="${DEVICE_MAC}"
55 assert isset DEFAULTROUTE
58 assert isset DEVICE_TYPE
60 assert isbool DEFAULTROUTE
63 assert isoneof DEVICE_TYPE real virtual
65 isset AUTH
&& assert isoneof AUTH
${PPPOE_ALLOWED_AUTHS}
66 isset DEVICE_ID
&& assert isinteger DEVICE_VID
69 function _parse_cmdline
() {
70 while [ $# -gt 0 ]; do
97 DEVICE_VID
=${1#--device-vid=}
100 echo "Unknown option: $1" >&2
107 if ! device_exists $
(devicify
${DEVICE}); then
108 error
"Device '${DEVICE}' does not exist."
112 DEVICE
=$
(macify
${DEVICE})
114 if isset DEVICE_VID
; then
115 DEVICE_TYPE
="virtual"
125 config_read
${ZONE_DIR}/${zone}/settings
127 # Creating necessary files
128 [ -d "${RED_RUN}/${LINKNAME}" ] || mkdir -p ${RED_RUN}/${LINKNAME}
130 # Setting up the device
131 if [ -n "${DEVICE_VID}" ]; then
132 device_create_virtual ${DEVICE} ${DEVICE_VID} ${DEVICE_MAC}
134 device_set_up ${DEVICE}
137 ppp_secret "${USER}" "${SECRET}"
139 cat <<EOF >${RED_RUN}/${LINKNAME}/options
145 plugin ${PPPOE_PLUGIN} $(_pppoe_real_device)
150 $(enabled PEERDNS && echo "usepeerdns
")
151 $(enabled DEFAULTROUTE && echo "defaultroute
")
154 $(isset AUTH && echo "require-
${AUTH}")
158 # Maximum transmission/receive unit
162 # Disable the compression
163 noccp noaccomp nodeflate nopcomp novj novjccomp nobsdcomp nomppe
168 pppd file ${RED_RUN}/${LINKNAME}/options >/dev/null
172 # Get exit code from ppp daemon and handle it:
175 log DEBUG "pppd detached successfully
"
180 error_log "pppd exited with unknown
exit code
'${ret}'"
189 config_read ${ZONE_DIR}/${zone}/settings
192 pid=$(cat /var/run/${zone}.pid 2>/dev/null)
193 if [ -n "${pid}" ]; then
194 kill ${pid} &>/dev/null
197 # Pull down device or remove virtual one
198 if [ -n "${DEVICE_VID}" ]; then
199 device_remove_virtual ${DEVICE_MAC}
201 device_set_down ${DEVICE}
207 function _discover() {
210 if [ "$
(device_get_type
${device})" != "real
" ]; then
215 output=$(pppoe-discovery -I ${device} -U $(uuid) 2>&1)
217 # Exit if there was not output
218 [ -z "${output}" ] && exit ${DISCOVER_ERROR}
220 # Exit if PADI timed out
221 grep -q "Timeout
" <<<${output} && exit ${DISCOVER_ERROR}
226 Access-Concentrator:*)
227 ac="${line#Access-Concentrator: }"
232 echo "ACCESS_CONCENTRATOR
=\"$ac\""