1 // L2TPNS Rate Limiting Stuff
2 // $Id: rl.c,v 1.3 2004-04-05 05:29:13 fred_nerk Exp $
14 extern radiust
*radius
;
15 extern sessiont
*session
;
18 extern tbft
*filter_buckets
;
19 extern struct configt
*config
;
28 "tc qdisc add dev " DEVICE
" root handle 1: htb",
29 "tc class add dev " DEVICE
" parent 1: classid 1:1 htb rate 100mbit burst 300k",
30 "tc filter del dev " DEVICE
" protocol ip pref 1 fw",
31 "iptables -t mangle -N throttle 2>&1 >/dev/null",
32 "iptables -t mangle -F throttle 2>&1 >/dev/null",
33 "iptables -t mangle -A l2tpns -j throttle 2>&1 >/dev/null",
38 log(2, 0, 0, 0, "Initializing HTB\n");
39 for (i
= 0; commands
[i
] && *commands
[i
]; i
++)
41 log(3, 0, 0, 0, "Running \"%s\"\n", commands
[i
]);
44 log(2, 0, 0, 0, "Done initializing HTB\n");
51 if (!config
->rl_rate
) return 0;
53 if (next_tbf
>= MAXSESSION
) return 0;
55 snprintf(filter_buckets
[t
].handle
, 9, "1:%d0", t
);
57 log(2, 0, 0, 0, "Creating new htb %s\n", filter_buckets
[t
].handle
);
58 snprintf(cmd
, 2048, "tc class add dev " DEVICE
" parent 1: classid %s htb rate %lukbit burst 15k",
59 filter_buckets
[t
].handle
, config
->rl_rate
);
60 log(3, 0, 0, 0, "%s\n", cmd
);
63 snprintf(cmd
, 2048, "tc filter add dev " DEVICE
" protocol ip parent 1:0 prio 1 handle %d fw flowid %s",
64 t
, filter_buckets
[t
].handle
);
65 log(3, 0, 0, 0, "%s\n", cmd
);
75 if (!config
->rl_rate
) return 0;
77 for (i
= 1; i
< MAXSESSION
; i
++)
79 if (!filter_buckets
[i
].in_use
&& *filter_buckets
[i
].handle
)
81 filter_buckets
[i
].in_use
= 1;
82 log(2, 0, 0, 0, "Returning tbf %s\n", filter_buckets
[i
].handle
);
87 if (i
) filter_buckets
[i
].in_use
= 1;
91 void rl_done_tbf(u16 t
)
94 if (!config
->rl_rate
) return;
95 log(2, 0, 0, 0, "Freeing up HTB %s\n", filter_buckets
[t
].handle
);
96 filter_buckets
[t
].in_use
= 0;
99 void rl_destroy_tbf(u16 t
)
102 if (!config
->rl_rate
) return;
103 if (filter_buckets
[t
].in_use
)
105 log(0, 0, 0, 0, "Trying to destroy an in-use HTB %s\n", filter_buckets
[t
].handle
);
108 snprintf(cmd
, 2048, "tc qdisc del dev " DEVICE
" handle %s", filter_buckets
[t
].handle
);
110 system("iptables -t mangle -D l2tpns -j throttle 2>&1 >/dev/null");
111 system("iptables -t mangle -X throttle 2>&1 >/dev/null");
112 memset(filter_buckets
[t
].handle
, 0, sizeof(filter_buckets
[t
].handle
));