7244cfafd2340f66ce192239c0b8eb08fb13a9ce
1 // L2TPNS Throttle Stuff
2 // $Id: throttle.c,v 1.3 2004/05/24 04:29:21 fred_nerk Exp $
13 #include <arpa/inet.h>
19 extern radiust
*radius
;
20 extern sessiont
*session
;
22 extern tbft
*filter_buckets
;
23 extern struct configt
*config
;
25 // Throttle or Unthrottle a session
26 int throttle_session(sessionidt s
, int throttle
)
28 if (!config
->rl_rate
) return 0;
30 if (!*session
[s
].user
)
31 return 0; // User not logged in
37 if (!session
[s
].tbf
) session
[s
].tbf
= rl_get_tbf();
40 log(1, 0, s
, session
[s
].tunnel
, "Error creating a filtering bucket for user %s\n", session
[s
].user
);
43 log(2, 0, s
, session
[s
].tunnel
, "Throttling session %d for user %s (bucket %s)\n", s
, session
[s
].user
, filter_buckets
[session
[s
].tbf
].handle
);
44 snprintf(cmd
, 2048, "iptables -t mangle -A throttle -d %s -j MARK --set-mark %d",
45 inet_toa(ntohl(session
[s
].ip
)),
47 log(4, 0, s
, session
[s
].tunnel
, "Running %s\n", cmd
);
48 if (WEXITSTATUS(system(cmd
)) != 0)
50 log(2, 0, s
, session
[s
].tunnel
, "iptables returned an error. Session is not throttled\n");
57 log(2, 0, s
, session
[s
].tunnel
, "Unthrottling session %d for user %s\n", s
, session
[s
].user
);
61 snprintf(cmd
, 2048, "iptables -t mangle -D throttle -d %s -j MARK --set-mark %d", inet_toa(ntohl(session
[s
].ip
)), session
[s
].tbf
);
62 log(4, 0, s
, session
[s
].tunnel
, "Running %s\n", cmd
);
65 int status
= system(cmd
);
66 if (WEXITSTATUS(status
) != 0) break;
70 rl_done_tbf(session
[s
].tbf
);
74 session
[s
].throttle
= throttle
;
75 return session
[s
].throttle
;