]> git.ipfire.org Git - people/arne_f/network.git/blobdiff - functions.ppp
Fix weird device CLI command.
[people/arne_f/network.git] / functions.ppp
index 7598f0ba05ca9e88391846b68c1656b9f721b25e..c10e7e7cbbd3973e0a1bbfeb0068510cc90f620a 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2009  Michael Tremer & Christian Schmidt                      #
+# Copyright (C) 2010  Michael Tremer & Christian Schmidt                      #
 #                                                                             #
 # This program is free software: you can redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
 #                                                                             #
 ###############################################################################
 
-RED_RUN=/var/run/network/red
-PPP_SECRETS=/etc/ppp/secrets
+function ppp_init() {
+       mkdir -p /var/run/ppp 2>/dev/null
+}
 
-function ppp_pre_up() {
-       # Load the ppp_generic module if not already done
-       grep -q ^ppp_generic /proc/modules || modprobe ppp_generic
+init_register ppp_init
 
-       connection --starting --zone=${zone}
-}
+function ppp_common_ip_pre_up() {
+       local zone=${1}
+       shift
+
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               return ${EXIT_ERROR}
+       fi
+
+       red_db_from_ppp ${zone}
+
+       # Request firewall reload
+       event_firewall_reload
 
-function ppp_post_up() {
-       : #connection --up --zone=${zone}
+       return ${EXIT_OK}
 }
 
-function ppp_pre_down() {
-       connection --stopping --zone=${zone}
+function ppp_common_ip_up() {
+       local zone=${1}
+       shift
+
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               return ${EXIT_ERROR}
+       fi
+
+       red_db_set ${zone} active 1
+       red_routing_update ${zone}
+
+       # Emit interface-up event
+       event_interface_up ${zone}
+
+       return ${EXIT_OK}
 }
 
-function ppp_post_down() {
-       : #connection --down --zone=${zone}
+function ppp_common_ip_down() {
+       local zone=${1}
+       shift
+
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               return ${EXIT_ERROR}
+       fi
+
+       # Save accounting information
+       ppp_accounting ${zone}
+
+       # Emit interface-up event
+       event_interface_down ${zone}
+
+       return ${EXIT_OK}
 }
 
 function ppp_secret() {
@@ -60,51 +97,16 @@ function ppp_secret() {
        rm -f ${PPP_SECRETS}.tmp
 }
 
-function ppp_stat() {
-       local name=${1}
-       local time=${2}
-       local rcvd=${3}
-       local sent=${4}
-
-       local file="${LOG_DIR}/ppp_${name}.db"
-       if ! [ -e "${file}" ]; then
-       sqlite3 -batch ${file} <<EOF
-CREATE TABLE connections(date, duration, rcvd, sent);
-EOF
-       fi
-       ppp_stat_init ${file}
-
-       sqlite3 -batch ${file} <<EOF
-INSERT INTO connections(date, duration, rcvd, sent) VALUES('$(date -u '+%s')', '${time}', '${rcvd}', '${sent}');
-EOF
-}
+function ppp_accounting() {
+       local zone=${1}
+       shift
 
-function ppp_linkname_get() {
-       local config=${1}
-       (
-               . ${config}
-               echo "${LINKNAME}"
-       )
+       db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
+               --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
 }
 
-function red_defaultroute_update() {
-       local command="ip route replace default"
-
-       for uplink in ${RED_RUN}/*; do
-               [ -d "${uplink}" ] || continue
-
-               # Skip if no gateway given
-               [ -e "${uplink}/gateway" ] || continue
-
-               command="${command} nexthop via $(<${uplink}/gateway)"
-               if [ -e "${uplink}/weight" ]; then
-                       command="${command} weight $(<${uplink}/weight)"
-               fi
-       done
-       $command
-       ip route flush cache
-}
+function pppd_exec() {
+       log DEBUG "Running pppd with parameters '$@'."
 
-function red_dns_update() {
-       : # XXX todo
+       pppd $@ > /dev/null
 }