1 // L2TPNS Throttle Stuff
2 // $Id: throttle.c,v 1.1 2003-12-16 07:07:39 fred_nerk Exp $
13 #include <arpa/inet.h>
19 extern char *radiussecret
;
20 extern radiust
*radius
;
21 extern sessiont
*session
;
22 extern ipt radiusserver
[MAXRADSERVER
]; // radius servers
26 extern u8 numradiusservers
;
28 extern unsigned long rl_rate
;
29 extern tbft
*filter_buckets
;
31 // Throttle or Unthrottle a session
32 int throttle_session(sessionidt s
, int throttle
)
34 if (!rl_rate
) return 0;
36 if (!*session
[s
].user
)
37 return 0; // User not logged in
43 log(2, 0, s
, session
[s
].tunnel
, "Throttling session %d for user %s\n", s
, session
[s
].user
);
44 if (!session
[s
].tbf
) session
[s
].tbf
= rl_get_tbf();
45 snprintf(cmd
, 2048, "iptables -t mangle -A throttle -d %s -j MARK --set-mark %d", inet_toa(ntohl(session
[s
].ip
)),
47 log(4, 0, s
, session
[s
].tunnel
, "Running %s\n", cmd
);
53 log(2, 0, s
, session
[s
].tunnel
, "Unthrottling session %d for user %s\n", s
, session
[s
].user
);
57 snprintf(cmd
, 2048, "iptables -t mangle -D throttle -d %s -j MARK --set-mark %d", inet_toa(ntohl(session
[s
].ip
)), session
[s
].tbf
);
58 log(4, 0, s
, session
[s
].tunnel
, "Running %s\n", cmd
);
61 int status
= system(cmd
);
62 if (WEXITSTATUS(status
) != 0) break;
66 rl_done_tbf(session
[s
].tbf
);
70 session
[s
].throttle
= throttle
;