e0731f05585028173f587b804ca745b6ca8f3460
1 // L2TPNS Throttle Stuff
2 // $Id: throttle.c,v 1.2 2004-03-05 00:09:03 fred_nerk Exp $
13 #include <arpa/inet.h>
19 extern radiust
*radius
;
20 extern sessiont
*session
;
23 extern tbft
*filter_buckets
;
24 extern struct configt
*config
;
26 // Throttle or Unthrottle a session
27 int throttle_session(sessionidt s
, int throttle
)
29 if (!config
->rl_rate
) return 0;
31 if (!*session
[s
].user
)
32 return 0; // User not logged in
38 if (!session
[s
].tbf
) session
[s
].tbf
= rl_get_tbf();
41 log(1, 0, s
, session
[s
].tunnel
, "Error creating a filtering bucket for user %s\n", session
[s
].user
);
44 log(2, 0, s
, session
[s
].tunnel
, "Throttling session %d for user %s\n", s
, session
[s
].user
);
45 snprintf(cmd
, 2048, "iptables -t mangle -A throttle -d %s -j MARK --set-mark %d",
46 inet_toa(ntohl(session
[s
].ip
)),
48 log(4, 0, s
, session
[s
].tunnel
, "Running %s\n", cmd
);
54 log(2, 0, s
, session
[s
].tunnel
, "Unthrottling session %d for user %s\n", s
, session
[s
].user
);
58 snprintf(cmd
, 2048, "iptables -t mangle -D throttle -d %s -j MARK --set-mark %d", inet_toa(ntohl(session
[s
].ip
)), session
[s
].tbf
);
59 log(4, 0, s
, session
[s
].tunnel
, "Running %s\n", cmd
);
62 int status
= system(cmd
);
63 if (WEXITSTATUS(status
) != 0) break;
67 rl_done_tbf(session
[s
].tbf
);
71 session
[s
].throttle
= throttle
;