Usefull for VPN with per megabyte billing.
(Works for me)
#
# pppd makefile for Linux
-# $Id: Makefile.linux,v 1.50 2002/06/10 13:46:28 dfs Exp $
+# $Id: Makefile.linux,v 1.51 2002/07/13 06:24:36 kad Exp $
#
# Default installation locations
#CBCP=y
+MAXOCTETS=y
+
INCLUDE_DIRS= -I../include
COMPILE_FLAGS= -D_linux_=1 -DHAVE_PATHS_H -DIPX_CHANGE -DHAVE_MMAP
CFLAGS += -DCBCP_SUPPORT
endif
+ifdef MAXOCTETS
+ CFLAGS += -DMAXOCTETS
+endif
+
INSTALL= install -o root
install: pppd
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#define RCSID "$Id: auth.c,v 1.77 2002/05/21 17:26:49 dfs Exp $"
+#define RCSID "$Id: auth.c,v 1.78 2002/07/13 06:24:36 kad Exp $"
#include <stdio.h>
#include <stddef.h>
static void check_access __P((FILE *, char *));
static int wordlist_count __P((struct wordlist *));
+#ifdef MAXOCTETS
+static void check_maxoctets __P((void *));
+#endif
+
/*
* Authentication-related options.
*/
if (maxconnect > 0)
TIMEOUT(connect_time_expired, 0, maxconnect);
+#ifdef MAXOCTETS
+ if (maxoctets > 0)
+ TIMEOUT(check_maxoctets, NULL, maxoctets_timeout);
+#endif
+
/*
* Detach now, if the updetach option was given.
*/
if (--num_np_up == 0) {
UNTIMEOUT(check_idle, NULL);
UNTIMEOUT(connect_time_expired, NULL);
+#ifdef MAXOCTETS
+ UNTIMEOUT(check_maxoctets, NULL);
+#endif
new_phase(PHASE_NETWORK);
}
}
}
}
+#ifdef MAXOCTETS
+static void
+check_maxoctets(arg)
+ void *arg;
+{
+ int diff;
+ unsigned int used;
+
+ update_link_stats(ifunit);
+ link_stats_valid=0;
+
+ switch(maxoctets_dir) {
+ case PPP_OCTETS_DIRECTION_IN:
+ used = link_stats.bytes_in;
+ break;
+ case PPP_OCTETS_DIRECTION_OUT:
+ used = link_stats.bytes_out;
+ break;
+ case PPP_OCTETS_DIRECTION_MAX:
+ used = (link_stats.bytes_in > link_stats.bytes_out) ? link_stats.bytes_in : link_stats.bytes_out;
+ break;
+ default:
+ used = link_stats.bytes_in+link_stats.bytes_out;
+ break;
+ }
+ diff = maxoctets - used;
+ if(diff < 0) {
+ notice("Traffic limit reached. Limit: %u Used: %u", maxoctets, used);
+ lcp_close(0, "Traffic limit");
+ need_holdoff = 0;
+ status = EXIT_TRAFFIC_LIMIT;
+ } else {
+ TIMEOUT(check_maxoctets, NULL, maxoctets_timeout);
+ }
+}
+#endif
+
/*
* check_idle - check whether the link has been idle for long
* enough that we can shut it down.
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#define RCSID "$Id: options.c,v 1.83 2002/04/02 13:54:59 dfs Exp $"
+#define RCSID "$Id: options.c,v 1.84 2002/07/13 06:24:36 kad Exp $"
#include <ctype.h>
#include <stdio.h>
bool dryrun; /* print out option values and exit */
char *domain; /* domain name set by domain option */
+#ifdef MAXOCTETS
+unsigned int maxoctets = 0; /* default - no limit */
+int maxoctets_dir = 0; /* default - sum of traffic */
+int maxoctets_timeout = 1; /* default 1 second */
+#endif
+
+
extern option_t auth_options[];
extern struct stat devstat;
static int setactivefilter __P((char **));
#endif
+#ifdef MAXOCTETS
+static int setmodir __P((char **));
+#endif
+
static option_t *find_option __P((const char *name));
static int process_option __P((option_t *, char *, char **));
static int n_arguments __P((option_t *));
"set filter for active pkts", OPT_PRIO },
#endif
+#ifdef MAXOCTETS
+ { "maxoctets", o_int, &maxoctets,
+ "Set connection traffic limit",
+ OPT_PRIO | OPT_LLIMIT | OPT_NOINCR | OPT_ZEROINF },
+ { "mo", o_int, &maxoctets,
+ "Set connection traffic limit",
+ OPT_ALIAS | OPT_PRIO | OPT_LLIMIT | OPT_NOINCR | OPT_ZEROINF },
+ { "mo-direction", o_special, setmodir,
+ "Set direction for limit traffic (sum,in,out,max)" },
+ { "mo-timeout", o_int, &maxoctets_timeout,
+ "Check for traffic limit every N seconds", OPT_PRIO | OPT_LLIMIT | 1 },
+#endif
+
{ NULL }
};
break;
default:
- printer(arg, "# %s value (type %d??)", opt->name, opt->type);
+ printer(arg, "# %s value (type %d\?\?)", opt->name, opt->type);
break;
}
printer(arg, "\t\t# (from %s)\n", mainopt->source);
log_default = 0;
return 1;
}
+#ifdef MAXOCTETS
+static int
+setmodir(argv)
+ char **argv;
+{
+ if(*argv == NULL)
+ return 0;
+ if(!strcmp(*argv,"in")) {
+ maxoctets_dir = PPP_OCTETS_DIRECTION_IN;
+ } else if (!strcmp(*argv,"out")) {
+ maxoctets_dir = PPP_OCTETS_DIRECTION_OUT;
+ } else if (!strcmp(*argv,"max")) {
+ maxoctets_dir = PPP_OCTETS_DIRECTION_MAX;
+ } else {
+ maxoctets_dir = PPP_OCTETS_DIRECTION_SUM;
+ }
+ return 1;
+}
+#endif
#ifdef PLUGIN
static int
CHAPMS=y
# Uncomment the next line to include support for MPPE.
MPPE=y
+# Uncomment the next lint to include support for traffic limiting
+MAXOCTETS=y
ifdef CHAPMS
CFLAGS += -DCHAPMS=1
CFLAGS += -DMPPE=1
endif
endif
+ifdef MAXOCTETS
+CFLAGS += -DMAXOCTETS=1
+endif
all: $(PLUGIN)
*
***********************************************************************/
static char const RCSID[] =
-"$Id: radius.c,v 1.9 2002/04/02 14:09:34 dfs Exp $";
+"$Id: radius.c,v 1.10 2002/07/13 06:24:36 kad Exp $";
#include "pppd.h"
#include "chap.h"
/* Session timeout */
maxconnect = vp->lvalue;
break;
-
+#ifdef MAXOCTETS
+ case PW_SESSION_OCTETS_LIMIT:
+ /* Session traffic limit */
+ maxoctets = vp->lvalue;
+ break;
+ case PW_OCTETS_DIRECTION:
+ /* Session traffic limit direction check */
+ maxoctets_dir = vp->lvalue & 3;
+ break;
+#endif
case PW_FRAMED_IP_ADDRESS:
/* seting up remote IP addresses */
remote = vp->lvalue;
ATTRIBUTE Crypt-Password 1006 string
ATTRIBUTE Connect-Rate 1007 integer
+#
+# Experimental, implementation specific attributes
+#
+# Limit session traffic
+ATTRIBUTE Session-Octets-Limit 227 integer
+# What to assume as limit - 0 in+out, 1 in, 2 out, 3 max(in,out)
+ATTRIBUTE Octets-Direction 228 integer
+
#
# Integer Translations
#
#VALUE Server-Config Password-Expiration 30
#VALUE Server-Config Password-Warning 5
+# Octets-Direction
+VALUE Octets-Direction Sum 0
+VALUE Octets-Direction Input 1
+VALUE Octets-Direction Output 2
+VALUE Octets-Direction Maximum 3
+
INCLUDE /etc/radiusclient/dictionary.microsoft
/*
- * $Id: radiusclient.h,v 1.6 2002/04/02 14:09:34 dfs Exp $
+ * $Id: radiusclient.h,v 1.7 2002/07/13 06:24:36 kad Exp $
*
* Copyright (C) 1995,1996,1997,1998 Lars Fenneberg
*
#define PW_USER_ID 222 /* string */
#define PW_USER_REALM 223 /* string */
+
+/* Session limits */
+#define PW_SESSION_OCTETS_LIMIT 227 /* integer */
+#define PW_OCTETS_DIRECTION 228 /* integer */
+
/* Integer Translations */
/* SERVICE TYPES */
#define PW_LOCAL 2
#define PW_REMOTE 3
+/* Session-Octets-Limit */
+#define PW_OCTETS_DIRECTION_SUM 0
+#define PW_OCTETS_DIRECTION_IN 1
+#define PW_OCTETS_DIRECTION_OUT 2
+#define PW_OCTETS_DIRECTION_MAX 3
+
+
/* Vendor codes */
#define VENDOR_NONE (-1)
#define VENDOR_MICROSOFT 311
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: pppd.h,v 1.68 2002/05/21 17:26:49 dfs Exp $
+ * $Id: pppd.h,v 1.69 2002/07/13 06:24:36 kad Exp $
*/
/*
extern bool dump_options; /* print out option values */
extern bool dryrun; /* check everything, print options, exit */
+#ifdef MAXOCTETS
+extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */
+extern int maxoctets_dir; /* Direction :
+ 0 - in+out (default)
+ 1 - in
+ 2 - out
+ 3 - max(in,out) */
+extern int maxoctets_timeout; /* Timeout for check of octets limit */
+#define PPP_OCTETS_DIRECTION_SUM 0
+#define PPP_OCTETS_DIRECTION_IN 1
+#define PPP_OCTETS_DIRECTION_OUT 2
+#define PPP_OCTETS_DIRECTION_MAX 3
+#endif
+
#ifdef PPP_FILTER
extern struct bpf_program pass_filter; /* Filter for pkts to pass */
extern struct bpf_program active_filter; /* Filter for link-active pkts */
#define EXIT_LOOPBACK 17
#define EXIT_INIT_FAILED 18
#define EXIT_AUTH_TOPEER_FAILED 19
+#ifdef MAXOCTETS
+#define EXIT_TRAFFIC_LIMIT 20
+#endif
/*
* Debug macros. Slightly useful for finding bugs in pppd, not particularly