]> git.ipfire.org Git - people/stevee/network.git/blob - hooks/zones/isdn
hostapd: Enable WMM by default.
[people/stevee/network.git] / hooks / zones / isdn
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 . /usr/lib/network/header-zone
23
24 HOOK_SETTINGS="HOOK AUTH LINKNAME USER SECRET PEERDNS DEFAULTROUTE MSN MTU"
25 HOOK_SETTINGS="${HOOK_SETTINGS} L2PROTO L3PROTO ENCAP PHONE"
26
27 AUTH=
28 CHANNELS="auto"
29 DEFAULTROUTE=1
30 ENCAP="syncppp"
31 L2PROTO="hdlc"
32 L3PROTO="trans"
33 LINKNAME="$(uuid)"
34 MSN=
35 MTU=1500
36 PEERDNS=1
37 TIMEOUT=10
38 SECRET=
39 USER=
40 PHONE=
41
42 MODE="persistent"
43
44 ISDN_ALLOWED_AUTHS="chap pap"
45
46 function hook_check() {
47 assert isset USER
48 assert isset SECRET
49 assert isset LINKNAME
50 assert isset DEFAULTROUTE
51 assert isset PEERDNS
52 assert isset TIMEOUT
53 assert isset PHONE
54
55 assert isbool DEFAULTROUTE
56 assert isbool PEERDNS
57 assert isinteger MSN
58 assert isinteger TIMEOUT
59
60 isset AUTH && assert isoneof AUTH ${ISDN_ALLOWED_AUTHS}
61 }
62
63 function hook_parse_cmdline() {
64 local value
65
66 while [ $# -gt 0 ]; do
67 case "$1" in
68 --user=*)
69 USER=${1#--user=}
70 ;;
71 --secret=*)
72 SECRET=${1#--secret=}
73 ;;
74 --linkname=*)
75 LINKNAME=${1#--name=}
76 ;;
77 --mtu=*)
78 MTU=${1#--mtu=}
79 ;;
80 --defaultroute=*)
81 value=${1#--defaultroute=}
82 if enabled value; then
83 DEFAULTROUTE=1
84 else
85 DEFAULTROUTE=0
86 fi
87 ;;
88 --dns=*)
89 value=${1#--dns=}
90 if enabled value; then
91 PEERDNS=1
92 else
93 PEERDNS=0
94 fi
95 ;;
96 --auth=*)
97 AUTH=${1#--auth=}
98 ;;
99 --device=*)
100 DEVICE=${1#--device=}
101 ;;
102 --msn=*)
103 MSN=${1#--msn=}
104 ;;
105 --timeout=*)
106 TIMEOUT=${1#--timeout=}
107 ;;
108 --phone=*)
109 PHONE="${PHONE} ${1#--phone=}"
110 ;;
111 *)
112 echo "Unknown option: $1" >&2
113 exit ${EXIT_ERROR}
114 ;;
115 esac
116 shift
117 done
118 }
119
120 function hook_up() {
121 local zone=${1}
122 shift
123
124 assert isset zone
125
126 zone_config_read ${zone}
127
128 assert [ -e "/dev/${DEVICE}" ]
129
130 # Creating necessary files
131 # XXX must be PPP_RUN
132 [ -d "${RED_RUN}/${LINKNAME}" ] || mkdir -p ${RED_RUN}/${LINKNAME}
133
134 # Create device node.
135 isdn_create_device ${zone}
136
137 # Apply configuration to the ISDN stack.
138 isdn_set_l2proto ${zone} ${L2PROTO}
139 isdn_set_l3proto ${zone} ${L3PROTO}
140 isdn_set_encap ${zone} ${ENCAP}
141
142 isdn_set_eaz ${zone} ${MSN}
143 isdn_set_huptimeout ${zone} $(( ${TIMEOUT} * 60 ))
144 isdn_addphone ${zone} out ${PHONE}
145
146 # Updating PPP credentials.
147 ppp_secret "${USER}" "${SECRET}"
148
149 # Bring up connection.
150 isdn_dial ${zone} \
151 --mode=${MODE} \
152 --channels=${CHANNELS} \
153 --user=${USER} \
154 --mtu=${MTU}
155
156 exit ${EXIT_OK}
157 }
158
159 function hook_down() {
160 local zone=${1}
161 shift
162
163 # Bring down ISDN interface.
164 isdn_hangup ${zone}
165
166 # Remove ISDN device.
167 isdn_remove_device ${zone}
168
169 exit ${EXIT_OK}
170 }
171
172 function hook_status() {
173 local zone=${1}
174 assert isset zone
175
176 cli_device_headline ${zone}
177
178 zone_config_read ${zone}
179
180 cli_headline 2 "Configuration:"
181 cli_print_fmt1 2 "User" "${USER}"
182 cli_print_fmt1 2 "Secret" "<hidden>"
183 cli_space
184
185 if device_exists ${zone}; then
186 cli_headline 3 "ISDN information:"
187 cli_print_fmt1 3 "L2 protocol" "$(isdn_get_l2proto ${zone})"
188 cli_print_fmt1 3 "L3 protocol" "$(isdn_get_l3proto ${zone})"
189 cli_print_fmt1 3 "Encapsulation" "$(isdn_get_encap ${zone})"
190 cli_space
191 fi
192
193 # Exit if zone is down
194 zone_is_up ${zone} || exit ${EXIT_ERROR}
195
196 # XXX display time since connection started
197
198 cli_headline 2 "Point-to-Point protocol"
199 cli_print_fmt1 2 "IP address" "$(routing_db_get ${zone} local-ip-address)"
200 cli_print_fmt1 2 "Gateway" "$(routing_db_get ${zone} remote-ip-address)"
201 cli_print_fmt1 2 "DNS servers" "$(routing_db_get ${zone} dns)"
202 cli_space
203
204 exit ${EXIT_OK}
205 }