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 PPP_SUPPORTED_AUTH_METHODS
="chap pap"
24 function pppd_start
() {
26 assert isset interface
28 # This will block until the connection has been established or
30 service_start
"pppd@${interface}.service"
32 # Get the exit code of the ppp daemon and figure out
34 local ret
=$
(service_get_exitcode
"pppd@${interface}.service")
40 error
"pppd crashed for an unknown reason"
43 error
"pppd: Configuration error"
46 error
"pppd terminated"
49 error
"pppd: Link terminated by modem"
52 error
"pppd: Authentication failed"
55 error
"pppd: Unhandled exit code: ${ret}"
62 function pppd_stop
() {
64 assert isset interface
66 service_stop
"pppd@${interface}.service"
69 function pppd_status
() {
71 assert isset interface
73 service_status
"pppd@${interface}.service"
76 function ppp_common_ip_pre_up
() {
80 if ! zone_exists
${zone}; then
81 error
"Zone '${zone}' does not exist."
85 routing_db_from_ppp
${zone} ipv4
87 # Request firewall reload
88 event_emit firewall-reload
93 function ppp_common_ip_up
() {
97 if ! zone_exists
${zone}; then
98 error
"Zone '${zone}' does not exist."
102 routing_db_set
${zone} ipv4 active
1
103 routing_update
${zone} ipv4
104 routing_default_update
106 # Emit interface-up event
107 event_interface_up
${zone}
112 function ppp_common_ip_down
() {
116 if ! zone_exists
${zone}; then
117 error
"Zone '${zone}' does not exist."
121 # Remove the information about this zone from the routing database
122 # and update the routing table.
123 routing_db_remove
${zone} ipv4
124 routing_update
${zone} ipv4
125 routing_default_update
127 # Save accounting information
128 ppp_accounting
${zone}
130 # Emit interface-up event
131 event_interface_down
${zone}
136 function ppp_common_ipv6_up
() {
140 if ! zone_exists
${zone}; then
141 error
"Zone '${zone}' does not exist."
145 # Add information about this zone to the routing database.
146 routing_db_from_ppp
${zone} ipv6
148 routing_db_set
${zone} ipv6 active
1
149 routing_update
${zone} ipv6
150 routing_default_update
152 # Emit interface-up event
153 event_interface_up
${zone}
158 function ppp_common_ipv6_down
() {
162 if ! zone_exists
${zone}; then
163 error
"Zone '${zone}' does not exist."
167 # Remove the information about this zone from the routing database
168 # and update the routing table.
169 routing_db_remove
${zone} ipv6
170 routing_update
${zone} ipv6
171 routing_default_update
173 # Save accounting information
174 ppp_accounting
${zone}
176 # Emit interface-up event
177 event_interface_down
${zone}
182 function ppp_secret
() {
189 # Updateing secret file
191 while read user a secret
; do
192 if [ "'${USER}'" != "${user}" ]; then
193 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
195 done < ${PPP_SECRETS}
196 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
197 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
198 rm -f ${PPP_SECRETS}.tmp
201 function ppp_accounting() {
205 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
206 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
209 function pppd_exec() {
210 log DEBUG "Running pppd with parameters '$@
'."
215 function pppd_write_config() {
216 local file=${1}; shift
222 local default_asyncmap="true"
224 local lcp_echo_failure=3
225 local lcp_echo_interval=20
229 local plugin plugin_options
234 while [ $# -gt 0 ]; do
237 auth=$(cli_get_val ${1})
240 baudrate=$(cli_get_val ${1})
241 assert isoneof baudrate ${SERIAL_BAUDRATES}
244 connect_cmd=$(cli_get_val ${1})
246 # Enable or disable the use of the default asyncmap.
247 --default-asyncmap=*)
248 value=$(cli_get_val ${1})
249 if enabled value; then
250 default_asyncmap="true"
252 default_asyncmap="false"
255 # The name of the created ppp interface.
257 interface=$(cli_get_val ${1})
260 --lcr-echo-failure=*)
261 lcr_echo_failure=$(cli_get_val ${1})
263 if ! isinteger ${lcr_echo_failure}; then
264 error "--lcr-echo-failure= requires a number"
269 --lcr-echo-interval=*)
270 lcr_echo_interval=$(cli_get_val ${1})
272 if ! isinteger ${lcr_echo_failure}; then
273 error "--lcr-echo-interval= requires a number"
277 # Maximum Transmission Unit
279 mtu=$(cli_get_val ${1})
281 # Maximum Receive Unit
283 mru=$(cli_get_val ${1})
286 password=$(cli_get_val ${1})
289 plugin=$(cli_get_val ${1})
292 plugin_options=$(cli_get_val ${1})
294 # Sets if the modem is a serial device.
296 serial=$(cli_get_val ${1})
299 serial_device=$(cli_get_val ${1})
302 username=$(cli_get_val ${1})
305 log WARNING "Unhandled argument: ${1}"
311 if [ -z "${interface}" ]; then
312 log ERROR "You need to set the interface name: ${interface}"
315 linkname="${interface}"
318 if ! isoneof ${auth} ${PPP_SUPPORTED_AUTH_METHODS}; then
319 log ERROR "Unsupported auth method: ${auth}"
324 if enabled serial; then
325 assert isset serial_device
326 assert [ -c "${serial_device}" ]
329 # Set the user credentials.
330 ppp_secret "${username}" "${password}"
332 # Write the configuration header.
333 mkdir -p $(dirname ${file}) 2>/dev/null
334 config_header "PPP daemon configuration file" > ${file}
336 # At first, set the name of the link.
337 print "linkname ${linkname}\n" >> ${file}
339 # Configure the interface/zone name.
341 print "# Interface name"
342 print "ifname ${interface}"
347 if isset plugin; then
349 print "# Plugin settings"
350 print "plugin ${plugin} ${plugin_options}"
355 # User authentication
356 if isset username; then
358 print "# User authentication"
359 print "user ${username}"
363 print "require-${auth}"
371 isset mru || mru=${mtu}
374 print "# MTU/MRU settings"
381 if enabled serial; then
383 print "# Serial modem settings"
384 print "${serial_device} ${baudrate}"
392 if isset connect_cmd; then
394 print "# Connect command"
395 print "connect \"${connect_cmd}\""
402 if enabled default_asyncmap; then
404 print "# Use the default asyncmap."
405 print "default-asyncmap"
412 print "# LCP settings"
413 print "lcp-echo-failure ${lcp_echo_failure}"
414 print "lcp-echo-interval ${lcp_echo_interval}"
418 # Add the default settings.
420 print "# Disable the compression"
421 print "noccp noaccomp nodeflate nopcomp novj novjccomp nobsdcomp nomppe"
423 print "noipdefault updetach debug"