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_speed from config)
16 char const *cvs_id
= "$Id: autothrottle.c,v 1.17 2006-05-18 14:40:31 bodea Exp $";
18 int plugin_api_version
= PLUGIN_API_VERSION
;
19 static struct pluginfuncs
*f
= 0;
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 f
->log(3, f
->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 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
57 " Not throttling user (invalid rate %s)\n",
65 data
->s
->throttle_in
= rate
;
66 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
67 " Throttling user input to %dkb/s\n", rate
);
71 data
->s
->throttle_out
= rate
;
72 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
73 " Throttling user output to %dkb/s\n", rate
);
76 else if (!strcmp(data
->key
, "throttle"))
81 if ((rate
= strtol(data
->value
, &e
, 10)) < 0 || *e
)
84 if (!strcmp(data
->value
, "yes"))
86 unsigned long *ts
= f
->getconfig("throttle_speed", UNSIGNED_LONG
);
90 else if (!strcmp(data
->value
, "no"))
98 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
99 " Throttling user to %dkb/s\n", rate
);
101 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
102 " Not throttling user\n");
104 data
->s
->throttle_in
= data
->s
->throttle_out
= rate
;
107 return PLUGIN_RET_OK
;
110 int plugin_radius_reset(struct param_radius_reset
*data
)
112 f
->throttle(f
->get_id_by_session(data
->s
), 0, 0);
113 return PLUGIN_RET_OK
;
116 int plugin_radius_account(struct param_radius_account
*data
)
118 if (data
->s
->throttle_in
|| data
->s
->throttle_out
)
120 uint8_t *p
= *data
->packet
;
123 if (data
->s
->throttle_in
)
125 *p
= 26; // vendor-specific
126 *(uint32_t *) (p
+ 2) = htonl(9); // Cisco
127 p
[6] = 1; // Cisco-AVPair
128 p
[7] = 2 + sprintf((char *) p
+ 8,
129 "lcp:interface-config#%d=service-policy input %d", i
++,
130 data
->s
->throttle_in
);
136 if (data
->s
->throttle_out
)
138 *p
= 26; // vendor-specific
139 *(uint32_t *) (p
+ 2) = htonl(9); // Cisco
140 p
[6] = 1; // Cisco-AVPair
141 p
[7] = 2 + sprintf((char *) p
+ 8,
142 "lcp:interface-config#%d=service-policy output %d", i
++,
143 data
->s
->throttle_out
);
152 return PLUGIN_RET_OK
;
155 int plugin_init(struct pluginfuncs
*funcs
)
157 return ((f
= funcs
)) ? 1 : 0;