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 int plugin_api_version
= PLUGIN_API_VERSION
;
17 static struct pluginfuncs
*f
= 0;
19 #define THROTTLE_KEY "lcp:interface-config"
21 int plugin_radius_response(struct param_radius_response
*data
)
23 if (!strncmp(data
->key
, THROTTLE_KEY
, sizeof(THROTTLE_KEY
) - 1))
25 char *sp
= strchr(data
->value
, ' ');
29 if (!sp
|| sp
- data
->value
< 4 ||
30 strncmp("service-policy", data
->value
, sp
- data
->value
))
33 while (*sp
== ' ') sp
++;
36 if (!(sp
= strchr(data
->value
, ' ')) ||
37 (strncmp("input", data
->value
, sp
- data
->value
) &&
38 strncmp("output", data
->value
, sp
- data
->value
)))
40 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
41 " Not throttling user (invalid type %.*s)\n",
42 sp
- data
->value
, data
->value
);
49 while (*sp
== ' ') sp
++;
52 if ((rate
= strtol(data
->value
, &sp
, 10)) < 0 || *sp
)
54 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
55 " Not throttling user (invalid rate %s)\n",
63 data
->s
->throttle_in
= rate
;
64 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
65 " Throttling user input to %dkb/s\n", rate
);
69 data
->s
->throttle_out
= rate
;
70 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
71 " Throttling user output to %dkb/s\n", rate
);
74 else if (!strcmp(data
->key
, "throttle"))
79 if ((rate
= strtol(data
->value
, &e
, 10)) < 0 || *e
)
82 if (!strcmp(data
->value
, "yes"))
84 unsigned long *ts
= f
->getconfig("throttle_speed", UNSIGNED_LONG
);
88 else if (!strcmp(data
->value
, "no"))
96 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
97 " Throttling user to %dkb/s\n", rate
);
99 f
->log(3, f
->get_id_by_session(data
->s
), data
->s
->tunnel
,
100 " Not throttling user\n");
102 data
->s
->throttle_in
= data
->s
->throttle_out
= rate
;
105 return PLUGIN_RET_OK
;
108 int plugin_radius_reset(struct param_radius_reset
*data
)
110 f
->throttle(f
->get_id_by_session(data
->s
), 0, 0);
111 return PLUGIN_RET_OK
;
114 int plugin_radius_account(struct param_radius_account
*data
)
116 if (data
->s
->throttle_in
|| data
->s
->throttle_out
)
118 uint8_t *p
= *data
->packet
;
121 if (data
->s
->throttle_in
)
123 *p
= 26; // vendor-specific
124 *(uint32_t *) (p
+ 2) = htonl(9); // Cisco
125 p
[6] = 1; // Cisco-AVPair
126 p
[7] = 2 + sprintf((char *) p
+ 8,
127 "lcp:interface-config#%d=service-policy input %d", i
++,
128 data
->s
->throttle_in
);
134 if (data
->s
->throttle_out
)
136 *p
= 26; // vendor-specific
137 *(uint32_t *) (p
+ 2) = htonl(9); // Cisco
138 p
[6] = 1; // Cisco-AVPair
139 p
[7] = 2 + sprintf((char *) p
+ 8,
140 "lcp:interface-config#%d=service-policy output %d", i
++,
141 data
->s
->throttle_out
);
150 return PLUGIN_RET_OK
;
153 int plugin_init(struct pluginfuncs
*funcs
)
155 return ((f
= funcs
)) ? 1 : 0;