5 /* set up throttling based on RADIUS reply */
8 * lcp:interface-config#1=service-policy input N
9 * lcp:interface-config#2=service-policy output N
12 * throttle=yes (use throttle_rate from config)
16 char const *cvs_id
= "$Id: autothrottle.c,v 1.15 2005-10-11 07:59:09 bodea Exp $";
18 int plugin_api_version
= PLUGIN_API_VERSION
;
19 struct pluginfuncs
*p
;
21 #define THROTTLE_KEY "lcp:interface-config"
23 int plugin_radius_response(struct param_radius_response
*data
)
25 if (!strncmp(data
->key
, THROTTLE_KEY
, sizeof(THROTTLE_KEY
) - 1))
27 char *sp
= strchr(data
->value
, ' ');
31 if (!sp
|| sp
- data
->value
< 4 ||
32 strncmp("service-policy", data
->value
, sp
- data
->value
))
35 while (*sp
== ' ') sp
++;
38 if (!(sp
= strchr(data
->value
, ' ')) ||
39 (strncmp("input", data
->value
, sp
- data
->value
) &&
40 strncmp("output", data
->value
, sp
- data
->value
)))
42 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
43 " Not throttling user (invalid type %.*s)\n",
44 sp
- data
->value
, data
->value
);
51 while (*sp
== ' ') sp
++;
54 if ((rate
= strtol(data
->value
, &sp
, 10)) < 0 || *sp
)
56 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
57 " Not throttling user (invalid rate %s)\n",
65 data
->s
->throttle_in
= rate
;
66 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
67 " Throttling user input to %dkb/s\n",
72 data
->s
->throttle_out
= rate
;
73 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
74 " Throttling user output to %dkb/s\n",
79 if (!strcmp(data
->key
, "throttle"))
84 if ((rate
= strtol(data
->value
, &e
, 10)) < 0 || *e
)
87 if (!strcmp(data
->value
, "yes"))
89 unsigned long *ts
= p
->getconfig("throttle_speed", UNSIGNED_LONG
);
93 else if (!strcmp(data
->value
, "no"))
101 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
102 " Throttling user to %dkb/s\n", rate
);
104 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
105 " Not throttling user\n");
107 data
->s
->throttle_in
= data
->s
->throttle_out
= rate
;
110 return PLUGIN_RET_OK
;
113 int plugin_radius_reset(struct param_radius_reset
*data
)
115 p
->throttle(p
->get_id_by_session(data
->s
), 0, 0);
116 return PLUGIN_RET_OK
;
119 int plugin_init(struct pluginfuncs
*funcs
)
121 return ((p
= funcs
)) ? 1 : 0;