5 /* set up throttling based on RADIUS reply */
7 char const *cvs_id
= "$Id: autothrottle.c,v 1.11 2004-11-30 00:46:36 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
, sizeof(THROTTLE_KEY
) - 1) == 0)
24 if (strncmp(data
->value
, "serv", 4))
27 pt
= strdup(data
->value
);
28 while ((t
= strsep(&pt
, " ")) != NULL
)
30 if (strcmp(t
, "serv") == 0)
32 else if (strcmp(t
, "o") == 0 && i
== 1)
34 else if (strcmp(t
, "i") == 0 && i
== 1)
38 if ((rate
= strtol(t
, (char **)NULL
, 10)) < 0 )
40 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
41 "Syntax Error: rate is not a number %s\n", t
);
49 data
->s
->throttle_out
= rate
;
51 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
52 " Set output throttle rate %dkb/s\n", rate
);
57 data
->s
->throttle_in
= rate
;
59 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
60 " Set input throttle rate %dkb/s\n", rate
);
65 p
->log(1, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
66 "Syntax error in rate limit AV pair: %s=%s\n", data
->key
, data
->value
);
74 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
75 "Unknown lcp:interface-config AV pair %s=%s\n",data
->key
, data
->value
);
79 else if (strcmp(data
->key
, "throttle") == 0)
81 if (strcmp(data
->value
, "yes") == 0)
83 unsigned long *rate
= p
->getconfig("throttle_speed", UNSIGNED_LONG
);
87 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
88 " Throttling user to %dkb/s\n", *rate
);
90 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
91 " Not throttling user (throttle_speed=0)\n");
93 data
->s
->throttle_in
= data
->s
->throttle_out
= *rate
;
96 p
->log(1, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
97 "Not throttling user (can't get throttle_speed)\n");
99 else if (strcmp(data
->value
, "no") == 0)
101 p
->log(3, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
102 " Not throttling user\n");
104 data
->s
->throttle_in
= data
->s
->throttle_out
= 0;
108 p
->log(4, p
->get_id_by_session(data
->s
), data
->s
->tunnel
,
109 "autothrottle module ignoring AV pair %s=%s\n",
110 data
->key
, data
->value
);
112 return PLUGIN_RET_OK
;
115 int plugin_init(struct pluginfuncs
*funcs
)
117 return ((p
= funcs
)) ? 1 : 0;