summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2010-11-07 00:43:36 +0300
committerDmitry Kozlov <xeb@mail.ru>2010-11-07 00:43:36 +0300
commit91df4499ccb1642c449c632ebc5a74ba7d5c7fd2 (patch)
treec066ec2ae80b7e550103f96407c5a6d5fb0d99e9
parentab309f4568da0b6b64952e082a0f7d4cb1b028f8 (diff)
downloadaccel-ppp-91df4499ccb1642c449c632ebc5a74ba7d5c7fd2.tar.gz
accel-ppp-91df4499ccb1642c449c632ebc5a74ba7d5c7fd2.zip
chap-secrets: support the rate limit of session (in kilobits) at fifth column
-rw-r--r--accel-pptpd/accel-pptp.conf5
-rw-r--r--accel-pptpd/accel-pptp.conf.56
-rw-r--r--accel-pptpd/extra/chap-secrets.c31
-rw-r--r--accel-pptpd/extra/shaper_tbf.c89
-rw-r--r--accel-pptpd/include/events.h8
-rw-r--r--accel-pptpd/ppp/ccp_mppe.c2
6 files changed, 104 insertions, 37 deletions
diff --git a/accel-pptpd/accel-pptp.conf b/accel-pptpd/accel-pptp.conf
index 466e7da..d918aca 100644
--- a/accel-pptpd/accel-pptp.conf
+++ b/accel-pptpd/accel-pptp.conf
@@ -36,14 +36,17 @@ verbose=1
[pppoe]
interface=eth0
+#ac-name=xxx
+#service-name=yyy
verbose=1
[l2tp]
#dictionary=/usr/local/share/accel-pptp/l2tp/dictionary
-#hello_interval=60
+#hello-interval=60
#timeout=60
#rtimeout=5
#retransmit=5
+#host-name=accel-pptp
verbose=1
[dns]
diff --git a/accel-pptpd/accel-pptp.conf.5 b/accel-pptpd/accel-pptp.conf.5
index 4b32b6e..c422d10 100644
--- a/accel-pptpd/accel-pptp.conf.5
+++ b/accel-pptpd/accel-pptp.conf.5
@@ -152,6 +152,12 @@ Specifies interface name to listen/send discovery packets. You may specify multi
.B interface
options.
.TP
+.BI "ac-name=" ac-name
+Specifies AC-Name tag value. If absent tag will not be sent.
+.TP
+.BI "service-name=" service-name
+Specifies Service-Name to respond. If absent any Service-Name is acceptable.
+.TP
.BI "verbose=" n
If this option is given and
.B n
diff --git a/accel-pptpd/extra/chap-secrets.c b/accel-pptpd/extra/chap-secrets.c
index d60ceb7..410b4e8 100644
--- a/accel-pptpd/extra/chap-secrets.c
+++ b/accel-pptpd/extra/chap-secrets.c
@@ -24,6 +24,7 @@ struct cs_pd_t
struct ppp_pd_t pd;
struct ipdb_item_t ip;
char *passwd;
+ char *rate;
};
static char *skip_word(char *ptr)
@@ -44,7 +45,7 @@ static int split(char *buf, char **ptr)
{
int i;
- for (i = 0; i < 3; i++) {
+ for (i = 0; i < 4; i++) {
buf = skip_word(buf);
if (!*buf)
return i;
@@ -72,7 +73,7 @@ static struct cs_pd_t *create_pd(struct ppp_t *ppp, const char *username)
{
FILE *f;
char *buf;
- char *ptr[4];
+ char *ptr[5];
int n;
struct cs_pd_t *pd;
@@ -122,10 +123,13 @@ found:
}
pd->ip.addr = conf_gw_ip_address;
- if (n == 3)
+ if (n >= 3)
pd->ip.peer_addr = inet_addr(ptr[2]);
pd->ip.owner = &ipdb;
-
+
+ if (n == 4)
+ pd->rate = _strdup(ptr[3]);
+
list_add_tail(&pd->pd.entry, &ppp->pd_list);
fclose(f);
@@ -156,9 +160,27 @@ static void ev_ppp_finished(struct ppp_t *ppp)
list_del(&pd->pd.entry);
_free(pd->passwd);
+ if (pd->rate)
+ _free(pd->rate);
_free(pd);
}
+static void ev_ppp_pre_up(struct ppp_t *ppp)
+{
+ struct cs_pd_t *pd = find_pd(ppp);
+ struct ev_shaper_t ev = {
+ .ppp = ppp,
+ };
+
+ if (!pd)
+ return;
+
+ if (pd->rate) {
+ ev.val = pd->rate;
+ triton_event_fire(EV_SHAPER, &ev);
+ }
+}
+
static struct ipdb_item_t *get_ip(struct ppp_t *ppp)
{
struct cs_pd_t *pd;
@@ -214,4 +236,5 @@ static void __init init(void)
ipdb_register(&ipdb);
triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ev_ppp_finished);
+ triton_event_register_handler(EV_PPP_PRE_UP, (triton_event_func)ev_ppp_pre_up);
}
diff --git a/accel-pptpd/extra/shaper_tbf.c b/accel-pptpd/extra/shaper_tbf.c
index 1404b21..970a72b 100644
--- a/accel-pptpd/extra/shaper_tbf.c
+++ b/accel-pptpd/extra/shaper_tbf.c
@@ -33,12 +33,14 @@
#define ATTR_DOWN 2
static int conf_verbose = 0;
+#ifdef RADIUS
static int conf_attr_down = 11; //Filter-Id
static int conf_attr_up = 11; //Filter-Id
+static int conf_vendor = 0;
+#endif
static double conf_burst_factor = 0.1;
static int conf_latency = 50;
static int conf_mpu = 0;
-static int conf_vendor = 0;
static double tick_in_usec = 1;
static double clock_factor = 1;
@@ -491,47 +493,51 @@ out_err:
return -1;
}
-#ifdef RADIUS
-static void parse_attr(struct rad_attr_t *attr, int dir, int *speed, int *burst)
+static void parse_string(const char *str, int dir, int *speed, int *burst)
{
char *endptr;
long int val;
unsigned int n1, n2, n3;
- if (attr->attr->type == ATTR_TYPE_STRING) {
- if (strstr(attr->val.string, "lcp:interface-config#1=rate-limit output") == attr->val.string) {
- if (dir == ATTR_DOWN) {
- val = sscanf(attr->val.string, "lcp:interface-config#1=rate-limit output %u %u %u conform-action transmit exceed-action drop", &n1, &n2, &n3);
- if (val == 3) {
- *speed = n1/1000;
- *burst = n2;
- }
+ if (strstr(str, "lcp:interface-config#1=rate-limit output") == str) {
+ if (dir == ATTR_DOWN) {
+ val = sscanf(str, "lcp:interface-config#1=rate-limit output %u %u %u conform-action transmit exceed-action drop", &n1, &n2, &n3);
+ if (val == 3) {
+ *speed = n1/1000;
+ *burst = n2;
}
- return;
}
- else if (strstr(attr->val.string, "lcp:interface-config#1=rate-limit input") == attr->val.string) {
- if (dir == ATTR_UP) {
- val = sscanf(attr->val.string, "lcp:interface-config#1=rate-limit input %u %u %u conform-action transmit exceed-action drop", &n1, &n2, &n3);
- if (val == 3) {
- *speed = n1/1000;
- *burst = n2;
- }
+ return;
+ }
+ else if (strstr(str, "lcp:interface-config#1=rate-limit input") == str) {
+ if (dir == ATTR_UP) {
+ val = sscanf(str, "lcp:interface-config#1=rate-limit input %u %u %u conform-action transmit exceed-action drop", &n1, &n2, &n3);
+ if (val == 3) {
+ *speed = n1/1000;
+ *burst = n2;
}
- return;
}
+ return;
+ }
- val = strtol(attr->val.string, &endptr, 10);
- if (*endptr == 0)
- *speed = val;
- else {
- if (*endptr == '/' || *endptr == '\\' || *endptr == ':') {
- if (dir == ATTR_DOWN)
- *speed = val;
- else
- *speed = strtol(endptr + 1, &endptr, 10);
- }
+ val = strtol(str, &endptr, 10);
+ if (*endptr == 0)
+ *speed = val;
+ else {
+ if (*endptr == '/' || *endptr == '\\' || *endptr == ':') {
+ if (dir == ATTR_DOWN)
+ *speed = val;
+ else
+ *speed = strtol(endptr + 1, &endptr, 10);
}
}
+}
+
+#ifdef RADIUS
+static void parse_attr(struct rad_attr_t *attr, int dir, int *speed, int *burst)
+{
+ if (attr->attr->type == ATTR_TYPE_STRING)
+ parse_string(attr->val.string, dir, speed, burst);
else if (attr->attr->type == ATTR_TYPE_INTEGER)
*speed = attr->val.integer;
}
@@ -615,6 +621,28 @@ static void ev_radius_coa(struct ev_radius_t *ev)
}
#endif
+static void ev_shaper(struct ev_shaper_t *ev)
+{
+ struct shaper_pd_t *pd = find_pd(ev->ppp, 1);
+ int down_speed = 0, down_burst = 0;
+ int up_speed = 0, up_burst = 0;
+
+ if (!pd)
+ return;
+
+ parse_string(ev->val, ATTR_DOWN, &down_speed, &down_burst);
+ parse_string(ev->val, ATTR_UP, &up_speed, &up_burst);
+
+ if (down_speed > 0 && up_speed > 0) {
+ pd->down_speed = down_speed;
+ pd->up_speed = up_speed;
+ if (!install_shaper(ev->ppp->ifname, down_speed, down_burst, up_speed, up_burst)) {
+ if (conf_verbose)
+ log_ppp_info("tbf: installed shaper %i/%i (Kbit)\n", down_speed, up_speed);
+ }
+ }
+}
+
static void ev_ctrl_finished(struct ppp_t *ppp)
{
struct shaper_pd_t *pd = find_pd(ppp, 0);
@@ -750,5 +778,6 @@ static void __init init(void)
triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
#endif
triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished);
+ triton_event_register_handler(EV_SHAPER, (triton_event_func)ev_shaper);
}
diff --git a/accel-pptpd/include/events.h b/accel-pptpd/include/events.h
index f0b1b8c..5958f27 100644
--- a/accel-pptpd/include/events.h
+++ b/accel-pptpd/include/events.h
@@ -14,7 +14,7 @@
#define EV_PPP_PRE_UP 9
#define EV_PPP_ACCT_START 10
#define EV_IP_CHANGED 100
-#define EV_SHAPE_CHANGED 101
+#define EV_SHAPER 101
#define EV_MPPE_KEYS 102
#define EV_RADIUS_ACCESS_ACCEPT 200
#define EV_RADIUS_COA 201
@@ -38,5 +38,11 @@ struct ev_mppe_keys_t
int type;
};
+struct ev_shaper_t
+{
+ struct ppp_t *ppp;
+ const char *val;
+};
+
#endif
diff --git a/accel-pptpd/ppp/ccp_mppe.c b/accel-pptpd/ppp/ccp_mppe.c
index 9235d85..0952aa0 100644
--- a/accel-pptpd/ppp/ccp_mppe.c
+++ b/accel-pptpd/ppp/ccp_mppe.c
@@ -198,7 +198,7 @@ static int mppe_recv_conf_nak(struct ppp_ccp_t *ccp, struct ccp_option_t *opt, u
if (ntohl(opt32->val) == (MPPE_S | MPPE_H))
return -1;
} else if (mppe_opt->policy == 1) {
- if (ntohl(opt32->val) & (MPPE_S | MPPE_H) == (MPPE_S | MPPE_H))
+ if ((ntohl(opt32->val) & (MPPE_S | MPPE_H)) == (MPPE_S | MPPE_H))
mppe_opt->mppe = 0;
else
mppe_opt->mppe = 1;