diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2014-11-17 18:45:29 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2014-11-17 18:45:29 +0300 |
commit | ca13dfe2c774835c3aed9567747c9b8b989446ba (patch) | |
tree | aba9f272cae35c38ca24319460e5f55df3022d9a /accel-pppd/shaper | |
parent | be476ff24258d1c3a043c69040ab147e6ed59c5a (diff) | |
download | accel-ppp-ca13dfe2c774835c3aed9567747c9b8b989446ba.tar.gz accel-ppp-ca13dfe2c774835c3aed9567747c9b8b989446ba.zip |
shaper: introduce "fwmark" option
If specified then fwmark filters will be installed to bypass shaper
Diffstat (limited to 'accel-pppd/shaper')
-rw-r--r-- | accel-pppd/shaper/limiter.c | 41 | ||||
-rw-r--r-- | accel-pppd/shaper/shaper.c | 11 | ||||
-rw-r--r-- | accel-pppd/shaper/shaper.h | 4 |
3 files changed, 50 insertions, 6 deletions
diff --git a/accel-pppd/shaper/limiter.c b/accel-pppd/shaper/limiter.c index 954a1169..2398bfea 100644 --- a/accel-pppd/shaper/limiter.c +++ b/accel-pppd/shaper/limiter.c @@ -246,7 +246,8 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu req.t.tcm_ifindex = ifindex; req.t.tcm_handle = 1; req.t.tcm_parent = 0xffff0000; - req.t.tcm_info = TC_H_MAKE(1 << 16, ntohs(ETH_P_IP)); + + req.t.tcm_info = TC_H_MAKE(100 << 16, ntohs(ETH_P_IP)); addattr_l(&req.n, sizeof(req), TCA_KIND, "u32", 4); @@ -340,7 +341,9 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, req.t.tcm_ifindex = ifindex; req.t.tcm_handle = 1; req.t.tcm_parent = 0xffff0000; - req.t.tcm_info = TC_H_MAKE(1 << 16, ntohs(ETH_P_IP)); + + req.t.tcm_info = TC_H_MAKE(100 << 16, ntohs(ETH_P_IP)); + addattr_l(&req.n, sizeof(req), TCA_KIND, "u32", 4); @@ -390,6 +393,35 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, return 0; } +static int install_fwmark(struct rtnl_handle *rth, int ifindex, int parent) +{ + struct rtattr *tail; + + struct { + struct nlmsghdr n; + struct tcmsg t; + char buf[1024]; + } req; + + memset(&req, 0, sizeof(req) - 1024); + + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)); + req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_EXCL|NLM_F_CREATE; + req.n.nlmsg_type = RTM_NEWTFILTER; + req.t.tcm_family = AF_UNSPEC; + req.t.tcm_ifindex = ifindex; + req.t.tcm_handle = 1; + req.t.tcm_parent = parent; + req.t.tcm_info = TC_H_MAKE(90 << 16, ntohs(ETH_P_IP)); + + addattr_l(&req.n, sizeof(req), TCA_KIND, "fw", 3); + tail = NLMSG_TAIL(&req.n); + addattr_l(&req.n, TCA_BUF_MAX, TCA_OPTIONS, NULL, 0); + addattr32(&req.n, TCA_BUF_MAX, TCA_FW_CLASSID, TC_H_MAKE(conf_fwmark << 16, 0)); + tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail; + return rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0); +} + static int remove_root(struct rtnl_handle *rth, int ifindex) { struct qdisc_opt opt = { @@ -450,6 +482,11 @@ int install_limiter(struct ap_session *ses, int down_speed, int down_burst, int if (r == 0) r = install_leaf_qdisc(&rth, conf_ifb_ifindex, 0x00010001 + ses->unit_idx + 1, (1 + ses->unit_idx + 1) << 16); } + + if (conf_fwmark) { + install_fwmark(&rth, ses->ifindex, 0x00010000); + install_fwmark(&rth, ses->ifindex, TC_H_INGRESS); + } rtnl_close(&rth); diff --git a/accel-pppd/shaper/shaper.c b/accel-pppd/shaper/shaper.c index 14388eda..85b0edd7 100644 --- a/accel-pppd/shaper/shaper.c +++ b/accel-pppd/shaper/shaper.c @@ -43,6 +43,7 @@ int conf_r2q = 10; int conf_cburst = 1534; int conf_ifb_ifindex; static double conf_multiplier = 1; +int conf_fwmark; int conf_up_limiter = LIM_POLICE; int conf_down_limiter = LIM_TBF; @@ -972,7 +973,13 @@ static void load_config(void) conf_multiplier = atof(opt); else conf_multiplier = 1; - + + opt = conf_get_opt("shaper", "fwmark"); + if (opt) + conf_fwmark = atof(opt); + else + conf_fwmark = 0; + triton_context_call(&shaper_ctx, (triton_event_func)load_time_ranges, NULL); } @@ -981,7 +988,7 @@ static void init(void) const char *opt; tc_core_init(); - + opt = conf_get_opt("shaper", "ifb"); if (opt && init_ifb(opt)) _exit(0); diff --git a/accel-pppd/shaper/shaper.h b/accel-pppd/shaper/shaper.h index f3ba8d99..4864b86f 100644 --- a/accel-pppd/shaper/shaper.h +++ b/accel-pppd/shaper/shaper.h @@ -11,8 +11,7 @@ struct rtnl_handle; struct nlmsghdr; -struct qdisc_opt -{ +struct qdisc_opt { char *kind; int handle; int parent; @@ -37,6 +36,7 @@ extern int conf_moderate_quantum; extern int conf_r2q; extern int conf_cburst; extern int conf_ifb_ifindex; +extern int conf_fwmark; extern int conf_leaf_qdisc; extern int conf_lq_arg1; extern int conf_lq_arg2; |