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 .
/usr
/lib
/network
/header-zone
24 # TODO XXX AC name, service name, sync?
26 HOOK_SETTINGS
="HOOK AUTH LINKNAME USER SECRET PEERDNS DEFAULTROUTE MTU"
37 PPPOE_ALLOWED_AUTHS
="chap pap"
38 PPPOE_PLUGIN
="rp-pppoe.so"
44 cat /var
/run
/${zone}.pid
2>/dev
/null
51 assert isset DEFAULTROUTE
54 #assert isset DEVICE_TYPE
56 assert isbool DEFAULTROUTE
60 #assert isoneof DEVICE_TYPE real virtual
62 local ports_num
=$
(listlength
${PORTS})
63 assert isoneof ports_num
0 1
65 isset AUTH
&& assert isoneof AUTH
${PPPOE_ALLOWED_AUTHS}
66 isset DEVICE_ID
&& assert isinteger DEVICE_VID
69 function _parse_cmdline
() {
72 while [ $# -gt 0 ]; do
87 value
=${1#--defaultroute=}
88 if enabled value
; then
96 if enabled value
; then
109 echo "Unknown option: $1" >&2
123 zone_config_read
${zone}
125 local port
=$
(zone_get_ports
${zone})
129 if ! port_exists
${port}; then
130 error_log
"Parent device '${port}' does not exist. Cannot bring up zone '${zone}'."
134 # Creating necessary files
135 # XXX must be PPP_RUN
136 [ -d "${RED_RUN}/${LINKNAME}" ] || mkdir -p ${RED_RUN}/${LINKNAME}
138 # Setting up the device
139 zone_ports_up ${zone}
141 ppp_secret "${USER}" "${SECRET}"
143 # XXX AC and service on plugin command line
145 cat <<EOF >${RED_RUN}/${LINKNAME}/options
151 plugin ${PPPOE_PLUGIN} ${port}
153 # Enable/disable IPv6
154 $(enabled IPV6 && echo "+" || echo "-")ipv6
159 $(enabled PEERDNS && echo "usepeerdns
")
160 $(enabled DEFAULTROUTE && echo "defaultroute
")
163 $(isset AUTH && echo "require-
${AUTH}")
167 # Maximum transmission/receive unit
171 # Disable the compression
172 noccp noaccomp nodeflate nopcomp novj novjccomp nobsdcomp nomppe
177 pppd_exec file ${RED_RUN}/${LINKNAME}/options
181 # Get exit code from ppp daemon and handle it:
184 log DEBUG "pppd detached successfully
"
188 log ERROR "Authentication failed. Maybe user and
/or secret is
/are incorrect.
"
193 error_log "pppd exited with unknown
exit code
'${ret}'"
204 kill $(pppd_pid ${zone}) &>/dev/null
206 zone_ports_down ${zone}
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\""
245 cli_device_headline ${zone}
247 zone_config_read ${zone}
249 cli_headline 2 "Configuration
"
250 cli_print_fmt1 2 "User
" "${USER}"
251 cli_print_fmt1 2 "Secret
" "<hidden
>"
254 enabled IPV6 &>/dev/null
255 local ipv6_enabled=$?
256 cli_print_fmt1 2 "IPv6?
" "$
(cli_print_bool
${ipv6_enabled})"
258 cli_headline 2 "Ports
"
259 zone_ports_status ${zone}
260 if [ -z "$
(zone_get_ports
${zone})" ]; then
261 cli_print_warning "No ports attached. Won
't be able to start."
265 # Exit if zone is down
266 if ! zone_is_up ${zone}; then
271 # XXX display time since connection started
273 cli_headline 2 "Point-to-Point-over-Ethernet protocol"
275 for proto in ${IP_SUPPORTED_PROTOCOLS}; do
276 routing_db_exists ${zone} ${proto} || continue
281 headline="Internet Protocol Version 6"
284 headline="Internet Protocol Version 4"
287 headline="Unkown protocol"
290 cli_headline 3 "${headline}"
292 cli_print_fmt1 3 "IP address" "$(routing_db_get ${zone} ${proto} local-ip-address)"
293 cli_print_fmt1 3 "Gateway" "$(routing_db_get ${zone} ${proto} remote-ip-address)"
294 cli_print_fmt1 3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)"
296 cli_print_fmt1 3 "MAC-Remote" "$(routing_db_get ${zone} ${proto} remote-address)"
303 function _port_add() {
308 if [ $(listlength $(zone_get_ports ${zone})) -ge 1 ]; then
309 error "This hook only supports one port at a time."
310 error "Please remove any existant port(s) and try again."
314 _port_cmd add ${zone} ${port} $@