2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2011 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 function isdn_config_dir
() {
24 local dir
="${RUN_DIR}/isdn/${device}"
26 [ -d "${dir}" ] || mkdir
-p ${dir}
31 function isdn_create_device
() {
34 if device_exists
${device}; then
38 log INFO
"Creating ISDN interface ${device}."
39 isdnctrl addif
${device} >/dev
/null
42 function isdn_remove_device
() {
45 if ! device_exists
${device}; then
49 log INFO
"Removing ISDN interface ${device}."
50 isdnctrl delif
${device} >/dev
/null
53 function isdn_add_slave
() {
57 assert device_exists
${device}
60 log INFO
"Creating ISDN slave interface ${slave} for device ${device}."
61 isdnctrl addslave
${device} ${slave}
69 log ERROR
"Could not create slave device for ${device}."
76 function isdn_rem_slave
() {
80 assert device_exists
${device}
83 log INFO
"Removing ISDN slave interface ${slave}."
84 isdnctrl delslave
${device} ${slave} >/dev
/null
87 function isdn_addlink
() {
90 assert device_exists
${device}
92 log INFO
"Adding link to ISDN interface ${device}."
93 isdnctrl addlink
${device} >/dev
/null
96 function isdn_get_encap
() {
99 assert device_exists
${device}
101 isdnctrl encap
${device} |
awk '{ print $NF }'
104 function isdn_set_encap
() {
108 assert device_exists
${device}
114 log ERROR
"Cannot set unknown encapsulation: ${encap}"
119 isdnctrl encap
${device} ${encap} >/dev
/null
122 function isdn_get_l2proto
() {
125 assert device_exists
${device}
127 isdnctrl l2_prot
${device} |
awk '{ print $NF }'
130 function isdn_set_l2proto
() {
134 assert device_exists
${device}
140 log ERROR
"Cannot set unknown l2 proto: ${proto}"
145 isdnctrl l2_prot
${device} ${proto} >/dev
/null
148 function isdn_get_l3proto
() {
151 assert device_exists
${device}
153 isdnctrl l3_prot
${device} |
awk '{ print $NF }'
156 function isdn_set_l3proto
() {
160 assert device_exists
${device}
166 log ERROR
"Cannot set unknown l3 proto: ${proto}"
171 isdnctrl l3_prot
${device} ${proto} >/dev
/null
174 function isdn_set_dialmax
() {
178 assert device_exists
${device}
179 assert
[ ${dialmax} -gt 0 ]
181 isdnctrl dialmax
${device} ${dialmax} >/dev
/null
184 function isdn_set_eaz
() {
188 assert device_exists
${device}
191 isdnctrl eaz
${device} ${eaz} >/dev
/null
194 function isdn_set_dialmode
() {
198 assert device_exists
${device}
203 log ERROR
"Cannot set unknown dialmode: ${mode}"
208 isdnctrl dialmode
${device} ${mode} >/dev
/null
211 function isdn_set_huptimeout
() {
215 assert device_exists
${device}
216 assert isinteger timeout
218 isdnctrl huptimeout
${device} ${mode} >/dev
/null
221 function isdn_addphone
() {
226 assert device_exists
${device}
227 assert isoneof
type in out
230 isdnctrl addphone
${device} ${type} ${number} >/dev
/null
233 function isdn_dial
() {
237 assert device_exists
${device}
239 local mode
="persistent"
240 local channels
="auto"
243 while [ $# -gt 0 ]; do
249 channels
=${1#--channels=}
252 ipppd_args
="${ipppd_args} ${1}"
258 assert isset channels
260 assert isoneof channels
1 2 auto
263 ipppd_start
${ipppd_args}
267 isdn_set_dialmode
${device} auto
270 case "${channels}" in
278 isdn_addlink
${device}
282 # Establish the connection immediately.
283 isdnctrl dial
${device} >/dev
/null
286 log ERROR
"Unknown dial mode given: ${mode}."
292 function isdn_hangup
() {
295 assert device_exists
${device}
297 # Bring isdn device down.
298 ip link
set ${device} down
304 function ipppd_start
() {
308 assert device_exists
${device}
310 ipppd_write_config
${device} $@
312 # Actually run the service.
313 service_start
"ipppd@${device}.service"
316 function ipppd_write_config
() {
331 # mode tells us if we are running in server or
332 # client mode. The collection of variables to
333 # be set depends on this.
336 while [ $# -gt 0 ]; do
354 value
=${1#--proxyarp=}
355 if enabled value
; then
362 netmask
=${1#--netmask=}
365 local_address
=${1#--local-address=}
368 remote_address
=${1#--remote-address=}
371 value
=${1#--dns-server=}
372 # XXX check if this is actually an IP address
374 dns_servers
="${dns_servers} ${value}"
377 log WARN
"Unknown argument given: ${1}"
383 # Check if all common variables are correctly set.
389 # Check if all variables for client mode are set.
394 assert isset local_address
395 assert isset remote_address
399 log CRITICAL
"Invalid mode given: ${mode}"
404 # Make a configuration file.
405 local config
="$(isdn_config_dir ${device})/config"
410 # XXX find a solution for this
413 # Never change the default route
423 # Disable compression
432 cat >>${config} <<EOF
439 # Get remote DNS servers
447 cat >>${config} <<EOF
450 ${local_address}:${remote_address}
454 $(for value in ${dns_servers}; do echo "ms-dns ${value}"; done)
461 function ipppd_stop
() {
465 service_stop
"ipppd@${device}.service"
467 # Remove configuration file.
468 rm -f $
(isdn_config_dir
${device})/config
471 function ibod_start
() {
474 assert device_exists
${device}
476 # Create ibod configuration file first.
480 log INFO
"Starting ibod service on device ${device}."
481 service_start
"ibod@${device}.service"
484 function ibod_config_file
() {
487 echo "$(isdn_config_dir $@)/ibod.cf"
490 function ibod_write_config
() {
493 log DEBUG
"Writing ibod.cf for device ${device}."
495 # Create path to configuration file.
496 local config
=$
(ibod_config_file
${device})
498 # Empty configuration file.
501 # Set the device to watch.
502 echo "DEVICE ${device}" >> ${config}
504 # We could set some more options here to
505 # configure when ibod is bringing the second
506 # channel up and down. I guess that is not
507 # required at the moment.
511 function ibod_stop
() {
514 log INFO
"Stopping ibod on device ${device}..."
515 service_stop
"ibod@${device}.service"
517 # Remove ibod configuration file.
518 rm -f $
(ibod_config_file
${device})