]> git.ipfire.org Git - people/stevee/network.git/blob - functions.ppp
Fixed some issues with pppoe dial-in.
[people/stevee/network.git] / functions.ppp
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 function ppp_init() {
23 mkdir -p /var/run/ppp 2>/dev/null
24 }
25
26 init_register ppp_init
27
28 function 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
37 # XXX protocol hardcoded
38 routing_db_from_ppp ${zone} ipv4
39
40 # Request firewall reload
41 event_firewall_reload
42
43 return ${EXIT_OK}
44 }
45
46 function 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
55 # XXX protocol is hardcoded
56 routing_db_set ${zone} ipv4 active 1
57 routing_update ${zone} ipv4
58
59 # Emit interface-up event
60 event_interface_up ${zone}
61
62 return ${EXIT_OK}
63 }
64
65 function 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
74 # Save accounting information
75 ppp_accounting ${zone}
76
77 # Emit interface-up event
78 event_interface_down ${zone}
79
80 return ${EXIT_OK}
81 }
82
83 function 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
102 function ppp_accounting() {
103 local zone=${1}
104 shift
105
106 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
107 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
108 }
109
110 function pppd_exec() {
111 log DEBUG "Running pppd with parameters '$@'."
112
113 pppd $@ > /dev/null
114 }