5 /* set up throttling based on RADIUS reply */
7 char const *cvs_id
= "$Id: autothrottle.c,v 1.13 2004/11/30 07:14:45 bodea Exp $";
9 int plugin_api_version
= PLUGIN_API_VERSION
;
10 struct pluginfuncs
*p
;
12 #define THROTTLE_KEY "lcp:interface-config"
14 int plugin_radius_response(struct param_radius_response
*data
)
16 if (!strncmp(data
->key
, THROTTLE_KEY
, sizeof(THROTTLE_KEY
) - 1))
18 char *sp
= strchr(data
->value
, ' ');
22 if (!sp
|| sp
- data
->value
< 4 ||
23 strncmp("service-policy", data
->value
, sp
- data
->value
))
26 while (*sp
== ' ') sp
++;
29 if (!(sp
= strchr(data
->value
, ' ')) ||
30 (strncmp("input", data
->value
, sp
- data
->value
) &&
31 strncmp("output", data
->value
, sp
- data
->value
)))
33 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
34 " Not throttling user (invalid type %.*s)\n",
35 sp
- data
->value
, data
->value
);
42 while (*sp
== ' ') sp
++;
45 if ((rate
= strtol(data
->value
, &sp
, 10)) < 0 || *sp
)
47 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
48 " Not throttling user (invalid rate %s)\n",
56 data
->s
->throttle_in
= rate
;
57 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
58 " Throttling user input to %dkb/s\n",
63 data
->s
->throttle_out
= rate
;
64 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
65 " Throttling user output to %dkb/s\n",
70 if (!strcmp(data
->key
, "throttle"))
72 if (!strcmp(data
->value
, "yes"))
74 unsigned long *rate
= p
->getconfig("throttle_speed", UNSIGNED_LONG
);
78 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
79 " Throttling user to %dkb/s\n", *rate
);
81 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
82 " Not throttling user (throttle_speed=0)\n");
84 data
->s
->throttle_in
= data
->s
->throttle_out
= *rate
;
87 p
->log(1, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
88 " Not throttling user (can't get throttle_speed)\n");
90 else if (!strcmp(data
->value
, "no"))
92 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
93 " Not throttling user\n");
95 data
->s
->throttle_in
= data
->s
->throttle_out
= 0;
102 int plugin_init(struct pluginfuncs
*funcs
)
104 return ((p
= funcs
)) ? 1 : 0;