]> git.ipfire.org Git - people/ms/network.git/blame - functions.ppp
Fixed some issues with pppoe dial-in.
[people/ms/network.git] / functions.ppp
CommitLineData
5b20e43a
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
1848564d 5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
5b20e43a
MT
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
711ffac1
MT
22function ppp_init() {
23 mkdir -p /var/run/ppp 2>/dev/null
24}
25
b8357295 26init_register ppp_init
a63c45b9 27
c7ad7801
MT
28function ppp_common_ip_pre_up() {
29 local zone=${1}
30 shift
31
32 if ! zone_exists ${zone}; then
33 error "Zone '${zone}' does not exist."
34 return ${EXIT_ERROR}
35 fi
36
2c973348
MT
37 # XXX protocol hardcoded
38 routing_db_from_ppp ${zone} ipv4
ff8ec5ef 39
c7ad7801
MT
40 # Request firewall reload
41 event_firewall_reload
42
43 return ${EXIT_OK}
44}
45
46function ppp_common_ip_up() {
47 local zone=${1}
48 shift
49
50 if ! zone_exists ${zone}; then
51 error "Zone '${zone}' does not exist."
52 return ${EXIT_ERROR}
53 fi
54
2c973348
MT
55 # XXX protocol is hardcoded
56 routing_db_set ${zone} ipv4 active 1
57 routing_update ${zone} ipv4
ff8ec5ef 58
c7ad7801
MT
59 # Emit interface-up event
60 event_interface_up ${zone}
61
62 return ${EXIT_OK}
63}
64
65function ppp_common_ip_down() {
66 local zone=${1}
67 shift
68
69 if ! zone_exists ${zone}; then
70 error "Zone '${zone}' does not exist."
71 return ${EXIT_ERROR}
72 fi
73
059469a8
MT
74 # Save accounting information
75 ppp_accounting ${zone}
76
c7ad7801
MT
77 # Emit interface-up event
78 event_interface_down ${zone}
79
80 return ${EXIT_OK}
81}
82
5b20e43a
MT
83function ppp_secret() {
84 local USER=${1}
85 local SECRET=${2}
86 local a
87 local secret
88 local user
89
90 # Updateing secret file
91 > ${PPP_SECRETS}.tmp
92 while read user a secret; do
93 if [ "'${USER}'" != "${user}" ]; then
94 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
95 fi
96 done < ${PPP_SECRETS}
97 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
98 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
99 rm -f ${PPP_SECRETS}.tmp
100}
101
059469a8
MT
102function ppp_accounting() {
103 local zone=${1}
104 shift
5b20e43a 105
059469a8
MT
106 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
107 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
5b20e43a 108}
711ffac1
MT
109
110function pppd_exec() {
711ffac1
MT
111 log DEBUG "Running pppd with parameters '$@'."
112
113 pppd $@ > /dev/null
114}