From ca13dfe2c774835c3aed9567747c9b8b989446ba Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Mon, 17 Nov 2014 18:45:29 +0300 Subject: shaper: introduce "fwmark" option If specified then fwmark filters will be installed to bypass shaper --- accel-pppd/shaper/limiter.c | 41 +++++++++++++++++++++++++++++++++++++++-- accel-pppd/shaper/shaper.c | 11 +++++++++-- accel-pppd/shaper/shaper.h | 4 ++-- 3 files changed, 50 insertions(+), 6 deletions(-) (limited to 'accel-pppd/shaper') diff --git a/accel-pppd/shaper/limiter.c b/accel-pppd/shaper/limiter.c index 954a116..2398bfe 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 14388ed..85b0edd 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 f3ba8d9..4864b86 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; -- cgit v1.2.3