]> git.ipfire.org Git - people/stevee/network.git/blame - hooks/zones/isdn-server
doc: Confused STP standards.
[people/stevee/network.git] / 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
22. /lib/network/header-zone
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
42function _check() {
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
55function _parse_cmdline() {
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
115function _up() {
116 local zone=${1}
117 shift
118
119 assert isset zone
120
121 zone_config_read ${zone}
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
172function _down() {
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
188function _status() {
189 local zone=${1}
190
191 assert isset zone
192
193 cli_status_headline ${zone}
194
195 zone_config_read ${zone}
196
197 cli_headline " Configuration:"
198 printf "${DEVICE_PRINT_LINE1}" "User:" "${USER}"
199 printf "${DEVICE_PRINT_LINE1}" "Secret:" "<hidden>"
200 echo
201 printf "${DEVICE_PRINT_LINE1}" "MTU:" "${MTU}"
202 printf "${DEVICE_PRINT_LINE1}" "Use default route?" "$(enabled DEFAULTROUTE && echo "enabled" || echo "disabled")"
203 printf "${DEVICE_PRINT_LINE1}" "Use peer DNS?" "$(enabled PEERDNS && echo "enabled" || echo "disabled")"
204 echo
205
206 if device_exists ${zone}; then
207 cli_headline " ISDN information:"
208 printf "${DEVICE_PRINT_LINE1}" "L2 protocol:" "$(isdn_get_l2proto ${zone})"
209 printf "${DEVICE_PRINT_LINE1}" "L3 protocol:" "$(isdn_get_l3proto ${zone})"
210 printf "${DEVICE_PRINT_LINE1}" "Encapsulation:" "$(isdn_get_encap ${zone})"
211 echo
212 fi
213
214 # Exit if zone is down
215 if ! zone_is_up ${zone}; then
216 echo # Empty line
217 exit ${EXIT_ERROR}
218 fi
219
220 # XXX display time since connection started
221
222 cli_headline " Point-to-Point-over-Ethernet protocol:"
223 echo " IP-Address : $(routing_db_get ${zone} local-ip-address)"
224 echo " Gateway : $(routing_db_get ${zone} remote-ip-address)"
225 echo " DNS-Server : $(routing_db_get ${zone} dns)"
226 echo
227 echo " MAC-Remote : $(routing_db_get ${zone} remote-address)"
228 echo
229 echo " MTU : $(device_get_mtu ${zone})"
230 echo # Empty line
231 exit ${EXIT_OK}
232}
233
234run $@