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 cat /var
/run
/${zone}.pid
2>/dev
/null
62 assert isset DEFAULTROUTE
65 assert isset DEVICE_TYPE
67 assert isbool DEFAULTROUTE
70 assert isoneof DEVICE_TYPE real virtual
72 isset AUTH
&& assert isoneof AUTH
${PPPOE_ALLOWED_AUTHS}
73 isset DEVICE_ID
&& assert isinteger DEVICE_VID
76 function _parse_cmdline
() {
77 while [ $# -gt 0 ]; do
101 DEVICE
=${1#--device=}
104 DEVICE_VID
=${1#--device-vid=}
107 echo "Unknown option: $1" >&2
114 if ! device_exists $
(devicify
${DEVICE}); then
115 error
"Device '${DEVICE}' does not exist."
119 DEVICE
=$
(macify
${DEVICE})
121 if isset DEVICE_VID
; then
122 DEVICE_TYPE
="virtual"
132 config_read
${ZONE_DIR}/${zone}/settings
134 # Creating necessary files
135 [ -d "${RED_RUN}/${LINKNAME}" ] || mkdir -p ${RED_RUN}/${LINKNAME}
137 # Setting up the device
138 if [ -n "${DEVICE_VID}" ]; then
139 device_create_virtual ${DEVICE} ${DEVICE_VID} ${DEVICE_MAC}
141 device_set_up ${DEVICE}
144 ppp_secret "${USER}" "${SECRET}"
146 cat <<EOF >${RED_RUN}/${LINKNAME}/options
152 plugin ${PPPOE_PLUGIN} $(_pppoe_real_device)
157 $(enabled PEERDNS && echo "usepeerdns
")
158 $(enabled DEFAULTROUTE && echo "defaultroute
")
161 $(isset AUTH && echo "require-
${AUTH}")
165 # Maximum transmission/receive unit
169 # Disable the compression
170 noccp noaccomp nodeflate nopcomp novj novjccomp nobsdcomp nomppe
175 pppd file ${RED_RUN}/${LINKNAME}/options >/dev/null
179 # Get exit code from ppp daemon and handle it:
182 log DEBUG "pppd detached successfully
"
187 error_log "pppd exited with unknown
exit code
'${ret}'"
196 config_read ${ZONE_DIR}/${zone}/settings
199 kill $(pppd_pid ${zone}) &>/dev/null
201 # Pull down device or remove virtual one
202 if [ -n "${DEVICE_VID}" ]; then
203 device_remove_virtual ${DEVICE_MAC}
205 device_set_down ${DEVICE}
211 function _discover() {
214 if [ "$
(device_get_type
${device})" != "real
" ]; then
219 output=$(pppoe-discovery -I ${device} -U $(uuid) 2>&1)
221 # Exit if there was not output
222 [ -z "${output}" ] && exit ${DISCOVER_ERROR}
224 # Exit if PADI timed out
225 grep -q "Timeout
" <<<${output} && exit ${DISCOVER_ERROR}
230 Access-Concentrator:*)
231 ac="${line#Access-Concentrator: }"
236 echo "ACCESS_CONCENTRATOR
=\"$ac\""
244 cli_status_headline ${zone}
246 # Exit if zone is down
247 if ! zone_is_up ${zone}; then
252 cli_headline " Point-to-Point-over-Ethernet protocol
:"
253 echo " IP-Address
: $
(red_db_get
${zone} local-ip-address
)"
254 echo " Gateway
: $
(red_db_get
${zone} remote-ip-address
)"
255 echo " DNS-Server
: $
(red_db_get
${zone} dns
)"
257 echo " MAC-Remote
: $
(red_db_get
${zone} remote-address
)"
259 echo " MTU
: $
(device_get_mtu
${zone})"