diff options
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/shaper/limiter.c | 86 | ||||
-rw-r--r-- | accel-pppd/shaper/shaper.c | 68 |
2 files changed, 76 insertions, 78 deletions
diff --git a/accel-pppd/shaper/limiter.c b/accel-pppd/shaper/limiter.c index 2398bfe..b0525cb 100644 --- a/accel-pppd/shaper/limiter.c +++ b/accel-pppd/shaper/limiter.c @@ -59,7 +59,7 @@ static int qdisc_htb_root(struct qdisc_opt *qopt, struct nlmsghdr *n) opt.rate2quantum = qopt->quantum; opt.version = 3; opt.defcls = qopt->defcls; - + tail = NLMSG_TAIL(n); addattr_l(n, TCA_BUF_MAX, TCA_OPTIONS, NULL, 0); addattr_l(n, TCA_BUF_MAX, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt))); @@ -131,9 +131,9 @@ int tc_qdisc_modify(struct rtnl_handle *rth, int ifindex, int cmd, unsigned flag if (opt->handle) req.t.tcm_handle = opt->handle; - + req.t.tcm_parent = opt->parent; - + if (opt->kind) addattr_l(&req.n, sizeof(req), TCA_KIND, opt->kind, strlen(opt->kind) + 1); @@ -171,7 +171,7 @@ static int install_htb(struct rtnl_handle *rth, int ifindex, int rate, int burst .defcls = 1, .qdisc = qdisc_htb_root, }; - + struct qdisc_opt opt2 = { .kind = "htb", .handle = 0x00010001, @@ -185,10 +185,10 @@ static int install_htb(struct rtnl_handle *rth, int ifindex, int rate, int burst if (tc_qdisc_modify(rth, ifindex, RTM_NEWQDISC, NLM_F_EXCL|NLM_F_CREATE, &opt1)) return -1; - + if (tc_qdisc_modify(rth, ifindex, RTM_NEWTCLASS, NLM_F_EXCL|NLM_F_CREATE, &opt2)) return -1; - + return 0; } @@ -211,7 +211,7 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu .handle = 0xffff0000, .parent = TC_H_INGRESS, }; - + struct sel { struct tc_u32_sel sel; struct tc_u32_key key; @@ -220,7 +220,7 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu .sel.flags = TC_U32_TERMINAL, .key.off = 12, }; - + struct tc_police police = { .action = TC_POLICE_SHOT, .rate.rate = rate, @@ -231,7 +231,7 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu if (tc_qdisc_modify(rth, ifindex, RTM_NEWQDISC, NLM_F_EXCL|NLM_F_CREATE, &opt1)) return -1; - + if (tc_calc_rtable(&police.rate, rtab, Rcell_log, mtu, linklayer) < 0) { log_ppp_error("shaper: failed to calculate ceil rate table.\n"); return -1; @@ -246,9 +246,9 @@ 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(100 << 16, ntohs(ETH_P_IP)); - + addattr_l(&req.n, sizeof(req), TCA_KIND, "u32", 4); tail = NLMSG_TAIL(&req.n); @@ -266,15 +266,15 @@ static int install_police(struct rtnl_handle *rth, int ifindex, int rate, int bu addattr_l(&req.n, MAX_MSG, TCA_POLICE_TBF, &police, sizeof(police)); addattr_l(&req.n, MAX_MSG, TCA_POLICE_RATE, rtab, 1024); tail3->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail3; - + tail2->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail2; - + tail1->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail1; addattr_l(&req.n, MAX_MSG, TCA_U32_CLASSID, &flowid, 4); addattr_l(&req.n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel)); tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail; - + if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; @@ -300,13 +300,13 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, .quantum = conf_quantum, .qdisc = qdisc_htb_class, }; - + struct qdisc_opt opt2 = { .kind = "ingress", .handle = 0xffff0000, .parent = TC_H_INGRESS, }; - + struct sel { struct tc_u32_sel sel; struct tc_u32_key key; @@ -315,11 +315,11 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, .sel.flags = TC_U32_TERMINAL, .key.off = 0, }; - + struct tc_skbedit p1 = { .action = TC_ACT_PIPE, }; - + struct tc_mirred p2 = { .eaction = TCA_EGRESS_REDIR, .action = TC_ACT_STOLEN, @@ -328,10 +328,10 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, if (tc_qdisc_modify(rth, conf_ifb_ifindex, RTM_NEWTCLASS, NLM_F_EXCL|NLM_F_CREATE, &opt1)) return -1; - + if (tc_qdisc_modify(rth, ifindex, RTM_NEWQDISC, NLM_F_EXCL|NLM_F_CREATE, &opt2)) return -1; - + memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)); @@ -341,10 +341,10 @@ 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(100 << 16, ntohs(ETH_P_IP)); - + addattr_l(&req.n, sizeof(req), TCA_KIND, "u32", 4); tail = NLMSG_TAIL(&req.n); @@ -353,7 +353,7 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, tail1 = NLMSG_TAIL(&req.n); addattr_l(&req.n, MAX_MSG, TCA_U32_ACT, NULL, 0); - // action skbedit priority X pipe + // action skbedit priority X pipe tail2 = NLMSG_TAIL(&req.n); addattr_l(&req.n, MAX_MSG, 1, NULL, 0); addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, "skbedit", 8); @@ -363,9 +363,9 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, addattr_l(&req.n, MAX_MSG, TCA_SKBEDIT_PARMS, &p1, sizeof(p1)); addattr_l(&req.n, MAX_MSG, TCA_SKBEDIT_PRIORITY, &priority, sizeof(priority)); tail3->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail3; - + tail2->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail2; - + tail1->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail1; // action mirred egress redirect dev ifb0 @@ -377,16 +377,16 @@ static int install_htb_ifb(struct rtnl_handle *rth, int ifindex, __u32 priority, addattr_l(&req.n, MAX_MSG, TCA_ACT_OPTIONS, NULL, 0); addattr_l(&req.n, MAX_MSG, TCA_MIRRED_PARMS, &p2, sizeof(p2)); tail3->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail3; - + tail2->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail2; - + tail1->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail1; // addattr32(&req.n, TCA_BUF_MAX, TCA_U32_CLASSID, 1); addattr_l(&req.n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel)); tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail; - + if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; @@ -410,14 +410,14 @@ static int install_fwmark(struct rtnl_handle *rth, int ifindex, int parent) 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_handle = conf_fwmark; 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)); + addattr32(&req.n, TCA_BUF_MAX, TCA_FW_CLASSID, TC_H_MAKE(1 << 16, 0)); tail->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)tail; return rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0); } @@ -428,7 +428,7 @@ static int remove_root(struct rtnl_handle *rth, int ifindex) .handle = 0x00010000, .parent = TC_H_ROOT, }; - + return tc_qdisc_modify(rth, ifindex, RTM_DELQDISC, 0, &opt); } @@ -438,7 +438,7 @@ static int remove_ingress(struct rtnl_handle *rth, int ifindex) .handle = 0xffff0000, .parent = TC_H_INGRESS, }; - + return tc_qdisc_modify(rth, ifindex, RTM_DELQDISC, 0, &opt); } @@ -448,7 +448,7 @@ static int remove_htb_ifb(struct rtnl_handle *rth, int ifindex, int priority) .handle = 0x00010001 + priority, .parent = 0x00010000, }; - + return tc_qdisc_modify(rth, conf_ifb_ifindex, RTM_DELTCLASS, 0, &opt); } @@ -456,7 +456,7 @@ int install_limiter(struct ap_session *ses, int down_speed, int down_burst, int { struct rtnl_handle rth; int r; - + if (rtnl_open(&rth, 0)) { log_ppp_error("shaper: cannot open rtnetlink\n"); return -1; @@ -483,11 +483,9 @@ int install_limiter(struct ap_session *ses, int down_speed, int down_burst, int r = install_leaf_qdisc(&rth, conf_ifb_ifindex, 0x00010001 + ses->unit_idx + 1, (1 + ses->unit_idx + 1) << 16); } - if (conf_fwmark) { + if (conf_fwmark) install_fwmark(&rth, ses->ifindex, 0x00010000); - install_fwmark(&rth, ses->ifindex, TC_H_INGRESS); - } - + rtnl_close(&rth); return r; @@ -504,7 +502,7 @@ int remove_limiter(struct ap_session *ses) remove_root(&rth, ses->ifindex); remove_ingress(&rth, ses->ifindex); - + if (conf_up_limiter == LIM_HTB) remove_htb_ifb(&rth, ses->ifindex, ses->unit_idx + 1); @@ -525,7 +523,7 @@ int init_ifb(const char *name) struct tcmsg t; char buf[TCA_BUF_MAX]; } req; - + struct qdisc_opt opt = { .kind = "htb", .handle = 0x00010000, @@ -536,7 +534,7 @@ int init_ifb(const char *name) if (system("modprobe -q ifb")) log_warn("failed to load ifb kernel module\n"); - + memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, name); @@ -546,7 +544,7 @@ int init_ifb(const char *name) } conf_ifb_ifindex = ifr.ifr_ifindex; - + ifr.ifr_flags |= IFF_UP; if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr)) { @@ -575,7 +573,7 @@ int init_ifb(const char *name) req.t.tcm_handle = 1; req.t.tcm_parent = 0x00010000; req.t.tcm_info = TC_H_MAKE(100 << 16, ntohs(ETH_P_IP)); - + addattr_l(&req.n, sizeof(req), TCA_KIND, "flow", 5); tail = NLMSG_TAIL(&req.n); diff --git a/accel-pppd/shaper/shaper.c b/accel-pppd/shaper/shaper.c index fa89e62..862267a 100644 --- a/accel-pppd/shaper/shaper.c +++ b/accel-pppd/shaper/shaper.c @@ -155,7 +155,7 @@ static void parse_string(const char *str, int dir, int *speed, int *burst, int * } return; } - + str1 = strstr(str, "rate-limit output"); if (str1) { val = sscanf(str1, "rate-limit output %u %u %u", &n1, &n2, &n3); @@ -175,7 +175,7 @@ static void parse_string(const char *str, int dir, int *speed, int *burst, int * } return; } - + str1 = strstr(str, "rate-limit input"); if (str1) { val = sscanf(str1, "rate-limit input %u %u %u", &n1, &n2, &n3); @@ -212,7 +212,7 @@ static void parse_string(const char *str, int dir, int *speed, int *burst, int * static struct time_range_pd_t *get_tr_pd(struct shaper_pd_t *pd, int id) { struct time_range_pd_t *tr_pd; - + list_for_each_entry(tr_pd, &pd->tr_list, entry) { if (tr_pd->id == id) return tr_pd; @@ -224,7 +224,7 @@ static struct time_range_pd_t *get_tr_pd(struct shaper_pd_t *pd, int id) if (id == time_range_id || id == 0) pd->cur_tr = tr_pd; - + list_add_tail(&tr_pd->entry, &pd->tr_list); return tr_pd; @@ -304,13 +304,13 @@ static void ev_radius_coa(struct ev_radius_t *ev) ev->res = -1; return; } - + clear_tr_pd(pd); check_radius_attrs(pd, ev->request); - + if (pd->temp_down_speed || pd->temp_up_speed) return; - + if (!pd->cur_tr) { if (pd->down_speed || pd->up_speed) { pd->down_speed = 0; @@ -330,7 +330,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) ev->res = -1; return; } - + if (pd->down_speed > 0 || pd->up_speed > 0) { if (install_limiter(ev->ses, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { ev->res= -1; @@ -396,10 +396,10 @@ static void ev_ppp_pre_up(struct ap_session *ses) int down_speed, down_burst; int up_speed, up_burst; struct shaper_pd_t *pd = find_pd(ses, 1); - + if (!pd) return; - + if (temp_down_speed || temp_up_speed) { pd->temp_down_speed = temp_down_speed; pd->temp_up_speed = temp_up_speed; @@ -476,7 +476,7 @@ static void shaper_change(struct shaper_pd_t *pd) pd->down_speed = 0; pd->up_speed = 0; } - + out: if (__sync_sub_and_fetch(&pd->refs, 1) == 0) { clear_tr_pd(pd); @@ -499,10 +499,10 @@ static int shaper_change_exec(const char *cmd, char * const *f, int f_cnt, void //if (down_speed == 0 || up_speed == 0) // return CLI_CMD_INVAL; - + if (!strcmp(f[2], "all")) all = 1; - + if (f_cnt == 5) { if (strcmp(f[4], "temp")) return CLI_CMD_SYNTAX; @@ -583,12 +583,12 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void if (f_cnt != 3) return CLI_CMD_SYNTAX; - + if (strcmp(f[2], "all")) all = 0; else all = 1; - + pthread_rwlock_rdlock(&shaper_lock); if (all) { temp_down_speed = 0; @@ -612,7 +612,7 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void if (!all && !found) cli_send(cli, "not found\r\n"); - + return CLI_CMD_OK; } @@ -665,7 +665,7 @@ static void update_shaper_tr(struct shaper_pd_t *pd) goto out; remove_limiter(pd->ses); } - + if (pd->cur_tr && (pd->cur_tr->down_speed || pd->cur_tr->up_speed)) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; @@ -707,7 +707,7 @@ static void time_range_end_timer(struct triton_timer_t *t) struct shaper_pd_t *pd; time_range_id = 0; - + log_debug("shaper: time_range_end_timer\n"); pthread_rwlock_rdlock(&shaper_lock); @@ -730,7 +730,7 @@ static struct time_range_t *parse_range(time_t t, const char *val) return NULL; if (id <= 0) return NULL; - + localtime_r(&t, &begin_tm); begin_tm.tm_sec = 0; end_tm = begin_tm; @@ -738,11 +738,11 @@ static struct time_range_t *parse_range(time_t t, const char *val) endptr = strptime(endptr + 1, "%H:%M", &begin_tm); if (*endptr != '-') return NULL; - + endptr = strptime(endptr + 1, "%H:%M", &end_tm); if (*endptr) return NULL; - + r = _malloc(sizeof(*r)); memset(r, 0, sizeof(*r)); @@ -766,7 +766,7 @@ static void load_time_ranges(void) if (!s) return; - + time(&ts); while (!list_empty(&time_range_list)) { @@ -813,7 +813,7 @@ static void load_time_ranges(void) r->end.expire_tv.tv_sec += 24 * 60 * 60; triton_timer_add(&shaper_ctx, &r->begin, 1); - + if (r->end.period) triton_timer_add(&shaper_ctx, &r->end, 1); } @@ -851,7 +851,7 @@ static int parse_vendor_opt(const char *opt) vendor = rad_dict_find_vendor_name(opt); if (vendor) return vendor->id; - + return atoi(opt); } #endif @@ -875,7 +875,7 @@ static void load_config(void) opt = conf_get_opt("shaper", "attr-down"); if (opt) conf_attr_down = parse_attr_opt(opt); - + opt = conf_get_opt("shaper", "attr-up"); if (opt) conf_attr_up = parse_attr_opt(opt); @@ -886,13 +886,13 @@ static void load_config(void) } } #endif - + opt = conf_get_opt("shaper", "burst-factor"); if (opt) { conf_down_burst_factor = strtod(opt, NULL); conf_up_burst_factor = conf_down_burst_factor * 10; } - + opt = conf_get_opt("shaper", "down-burst-factor"); if (opt) conf_down_burst_factor = strtod(opt, NULL); @@ -926,13 +926,13 @@ static void load_config(void) conf_quantum = atoi(opt); else conf_quantum = 0; - + opt = conf_get_opt("shaper", "moderate-quantum"); if (opt) conf_moderate_quantum = atoi(opt); else conf_moderate_quantum = 0; - + opt = conf_get_opt("shaper", "cburst"); if (opt && atoi(opt) >= 0) conf_cburst = atoi(opt); @@ -972,19 +972,19 @@ static void load_config(void) opt = conf_get_opt("shaper", "verbose"); if (opt && atoi(opt) >= 0) conf_verbose = atoi(opt) > 0; - + opt = conf_get_opt("shaper", "rate-multiplier"); if (opt && atof(opt) > 0) conf_multiplier = atof(opt); else conf_multiplier = 1; - + opt = conf_get_opt("shaper", "fwmark"); if (opt) - conf_fwmark = atof(opt); + conf_fwmark = atoi(opt); else conf_fwmark = 0; - + triton_context_call(&shaper_ctx, (triton_event_func)load_time_ranges, NULL); } @@ -993,7 +993,7 @@ static void init(void) const char *opt; tc_core_init(); - + opt = conf_get_opt("shaper", "ifb"); if (opt && init_ifb(opt)) _exit(0); |