]> git.ipfire.org Git - people/stevee/network.git/blame - functions.ppp
network: New function device_is_promisc.
[people/stevee/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
c7ad7801
MT
22function ppp_common_ip_pre_up() {
23 local zone=${1}
24 shift
25
26 if ! zone_exists ${zone}; then
27 error "Zone '${zone}' does not exist."
28 return ${EXIT_ERROR}
29 fi
30
31 # Request firewall reload
32 event_firewall_reload
33
34 return ${EXIT_OK}
35}
36
37function ppp_common_ip_up() {
38 local zone=${1}
39 shift
40
41 if ! zone_exists ${zone}; then
42 error "Zone '${zone}' does not exist."
43 return ${EXIT_ERROR}
44 fi
45
46 # Emit interface-up event
47 event_interface_up ${zone}
48
49 return ${EXIT_OK}
50}
51
52function ppp_common_ip_down() {
53 local zone=${1}
54 shift
55
56 if ! zone_exists ${zone}; then
57 error "Zone '${zone}' does not exist."
58 return ${EXIT_ERROR}
59 fi
60
059469a8
MT
61 # Save accounting information
62 ppp_accounting ${zone}
63
c7ad7801
MT
64 # Emit interface-up event
65 event_interface_down ${zone}
66
67 return ${EXIT_OK}
68}
69
5b20e43a
MT
70function ppp_secret() {
71 local USER=${1}
72 local SECRET=${2}
73 local a
74 local secret
75 local user
76
77 # Updateing secret file
78 > ${PPP_SECRETS}.tmp
79 while read user a secret; do
80 if [ "'${USER}'" != "${user}" ]; then
81 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
82 fi
83 done < ${PPP_SECRETS}
84 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
85 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
86 rm -f ${PPP_SECRETS}.tmp
87}
88
059469a8
MT
89function ppp_accounting() {
90 local zone=${1}
91 shift
5b20e43a 92
059469a8
MT
93 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
94 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
5b20e43a
MT
95}
96
97function red_defaultroute_update() {
98 local command="ip route replace default"
99
1848564d 100 local uplink
5b20e43a
MT
101 for uplink in ${RED_RUN}/*; do
102 [ -d "${uplink}" ] || continue
103
104 # Skip if no gateway given
105 [ -e "${uplink}/gateway" ] || continue
106
107 command="${command} nexthop via $(<${uplink}/gateway)"
108 if [ -e "${uplink}/weight" ]; then
109 command="${command} weight $(<${uplink}/weight)"
110 fi
111 done
112 $command
1848564d 113 #ip route flush cache
5b20e43a
MT
114}
115
116function red_dns_update() {
117 : # XXX todo
118}