]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/zones/isdn-server
Rename all "config" to "settings"
[people/stevee/network.git] / src / hooks / zones / isdn-server
CommitLineData
785afa13
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
f41fa3d7 22. /usr/lib/network/header-zone
785afa13
MT
23
24HOOK_SETTINGS="HOOK LOCAL_ADDRESS REMOTE_ADDRESS MSN MTU MRU"
25HOOK_SETTINGS="${HOOK_SETTINGS} L2PROTO L3PROTO ENCAP"
26
27# The peer address of the ISDN server.
28LOCAL_ADDRESS=
29REMOTE_ADDRESS=
30
31AUTH=
32ENCAP="syncppp"
33L2PROTO="hdlc"
34L3PROTO="trans"
35LINKNAME="$(uuid)"
36MSN=
37MTU=1500
38TIMEOUT=10
39
40MODE="persistent"
41
2181765d 42function hook_check() {
785afa13
MT
43 assert isset LOCAL_ADDRESS
44 assert isset REMOTE_ADDRESS
45
46 assert isset LINKNAME
47 assert isset TIMEOUT
48
49 assert isinteger MSN
50 assert isinteger TIMEOUT
51
52 isset AUTH && assert isoneof AUTH ${ISDN_ALLOWED_AUTHS}
53}
54
2181765d 55function hook_parse_cmdline() {
785afa13
MT
56 local value
57
58 while [ $# -gt 0 ]; do
59 case "$1" in
60 --local-address=*)
61 LOCAL_ADDRESS=${1#--local-address=}
62 ;;
63 --remote-address=*)
64 REMOTE_ADDRESS=${1#--remote-address=}
65 ;;
66 --subnet=*)
67 SUBNET=${1#--subnet=}
68 ;;
69 --linkname=*)
70 LINKNAME=${1#--name=}
71 ;;
72 --mtu=*)
73 MTU=${1#--mtu=}
74 ;;
75 --defaultroute=*)
76 value=${1#--defaultroute=}
77 if enabled value; then
78 DEFAULTROUTE=1
79 else
80 DEFAULTROUTE=0
81 fi
82 ;;
83 --dns=*)
84 value=${1#--dns=}
85 if enabled value; then
86 PEERDNS=1
87 else
88 PEERDNS=0
89 fi
90 ;;
91 --auth=*)
92 AUTH=${1#--auth=}
93 ;;
94 --device=*)
95 DEVICE=${1#--device=}
96 ;;
97 --msn=*)
98 MSN=${1#--msn=}
99 ;;
100 --timeout=*)
101 TIMEOUT=${1#--timeout=}
102 ;;
103 --phone=*)
104 PHONE="${PHONE} ${1#--phone=}"
105 ;;
106 *)
107 echo "Unknown option: $1" >&2
108 exit ${EXIT_ERROR}
109 ;;
110 esac
111 shift
112 done
113}
114
2181765d 115function hook_up() {
785afa13
MT
116 local zone=${1}
117 shift
118
119 assert isset zone
120
e9df08ad 121 zone_settings_read "${zone}" ${HOOK_SETTINGS}
785afa13
MT
122
123 assert [ -e "/dev/${DEVICE}" ]
124
125 # Creating necessary files
126 # XXX must be PPP_RUN
127 [ -d "${RED_RUN}/${LINKNAME}" ] || mkdir -p ${RED_RUN}/${LINKNAME}
128
129 # Create device node.
130 isdn_create_device ${zone}
131
132 # Apply configuration to the ISDN stack.
133 isdn_set_l2proto ${zone} ${L2PROTO}
134 isdn_set_l3proto ${zone} ${L3PROTO}
135 isdn_set_encap ${zone} ${ENCAP}
136
137 isdn_set_eaz ${zone} ${MSN}
138 isdn_set_huptimeout ${zone} $(( ${TIMEOUT} * 60 ))
139
140 # Set our ip address.
141 ip_address_add ${zone} ${LOCAL_ADDRESS}
142 device_set_up ${zone}
143
144 # Start ipppd in server mode and make it listening for
145 # incoming connections:
146 local options
147
148 # Get a list of all DNS servers.
149 local dns_server
150 for dns_server in ${dns_servers}; do
151 options="${options} --dns-server=${dns_server}"
152 done
153
154 # Convert netmask.
155 local prefix=$(ip_get_prefix ${LOCAL_ADDRESS})
156 local netmask=$(ipv4_prefix2netmask ${prefix})
157
158 # Split prefix from LOCAL_ADDRESS.
159 local local_address=$(ip_split_prefix ${LOCAL_ADDRESS})
160
161 ipppd_start ${zone} \
162 --mode="server" \
163 --local-address="${local_address}" \
164 --remote-address="${REMOTE_ADDRESS}" \
165 --netmask="${netmask}" \
166 --mtu=${MTU} \
167 ${options}
168
169 exit ${EXIT_OK}
170}
171
2181765d 172function hook_down() {
785afa13
MT
173 local zone=${1}
174 shift
175
176 # Kill ipppd service.
177 ipppd_stop ${zone}
178
179 # Bring down ISDN interface.
180 device_set_down ${zone}
181
182 # Remove ISDN device.
183 isdn_remove_device ${zone}
184
185 exit ${EXIT_OK}
186}
187
2181765d 188function hook_status() {
785afa13 189 local zone=${1}
785afa13
MT
190 assert isset zone
191
3cb2fc42 192 cli_device_headline ${zone}
785afa13 193
e9df08ad 194 zone_settings_read "${zone}" ${HOOK_SETTINGS}
785afa13
MT
195
196 cli_headline " Configuration:"
197 printf "${DEVICE_PRINT_LINE1}" "User:" "${USER}"
198 printf "${DEVICE_PRINT_LINE1}" "Secret:" "<hidden>"
199 echo
200 printf "${DEVICE_PRINT_LINE1}" "MTU:" "${MTU}"
201 printf "${DEVICE_PRINT_LINE1}" "Use default route?" "$(enabled DEFAULTROUTE && echo "enabled" || echo "disabled")"
202 printf "${DEVICE_PRINT_LINE1}" "Use peer DNS?" "$(enabled PEERDNS && echo "enabled" || echo "disabled")"
203 echo
204
205 if device_exists ${zone}; then
206 cli_headline " ISDN information:"
207 printf "${DEVICE_PRINT_LINE1}" "L2 protocol:" "$(isdn_get_l2proto ${zone})"
208 printf "${DEVICE_PRINT_LINE1}" "L3 protocol:" "$(isdn_get_l3proto ${zone})"
209 printf "${DEVICE_PRINT_LINE1}" "Encapsulation:" "$(isdn_get_encap ${zone})"
210 echo
211 fi
212
213 # Exit if zone is down
214 if ! zone_is_up ${zone}; then
215 echo # Empty line
216 exit ${EXIT_ERROR}
217 fi
218
219 # XXX display time since connection started
220
221 cli_headline " Point-to-Point-over-Ethernet protocol:"
222 echo " IP-Address : $(routing_db_get ${zone} local-ip-address)"
223 echo " Gateway : $(routing_db_get ${zone} remote-ip-address)"
224 echo " DNS-Server : $(routing_db_get ${zone} dns)"
225 echo
226 echo " MAC-Remote : $(routing_db_get ${zone} remote-address)"
227 echo
228 echo " MTU : $(device_get_mtu ${zone})"
229 echo # Empty line
230 exit ${EXIT_OK}
231}