9973a4fca7e9b193dadc60518573e681e2bcfab7
5 /* set up throttling based on RADIUS reply */
7 char const *cvs_id
= "$Id: autothrottle.c,v 1.9 2004-11-17 08:23:34 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
)
20 if (strncmp(data
->key
, THROTTLE_KEY
, strlen(THROTTLE_KEY
)) == 0)
22 char *pt
= strdup(data
->value
);
23 while ((t
= strsep(&pt
, " ")) != NULL
)
25 if (strcmp(t
, "serv") == 0)
27 else if (strcmp(t
, "o") && i
== 1)
29 else if (strcmp(t
, "i") && i
== 1)
31 else if (i
> 1 && (rate
= atoi(t
)) > 0)
36 data
->s
->throttle_out
= rate
;
38 p
->log(3, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, " Set output throttle rate %dkb/s\n", rate
);
42 data
->s
->throttle_in
= rate
;
44 p
->log(3, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, " Set input throttle rate %dkb/s\n", rate
);
48 p
->log(1, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, "Syntax error in rate limit AV pair: %s=%s\n", data
->key
, data
->value
);
56 p
->log(1, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, "Syntax error in rate limit AV pair: %s=%s\n",
57 data
->key
, data
->value
);
63 else if (strcmp(data
->key
, "throttle") == 0)
65 if (strcmp(data
->value
, "yes") == 0)
67 unsigned long *rate
= p
->getconfig("throttle_speed", UNSIGNED_LONG
);
71 p
->log(3, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, " Throttling user to %dkb/s\n", *rate
);
73 p
->log(3, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, " Not throttling user (throttle_speed=0)\n");
75 data
->s
->throttle_in
= data
->s
->throttle_out
= *rate
;
78 p
->log(1, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, "Not throttling user (can't get throttle_speed)\n");
80 else if (strcmp(data
->value
, "no") == 0)
82 p
->log(3, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, " Not throttling user\n");
83 data
->s
->throttle_in
= data
->s
->throttle_out
= 0;
87 p
->log(4, 0, p
->get_id_by_session(data
->s
), data
->s
->tunnel
, "autothrottle module ignoring AV pair %s=%s\n",
88 data
->key
, data
->value
);
93 int plugin_init(struct pluginfuncs
*funcs
)
95 return ((p
= funcs
)) ? 1 : 0;