diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2011-09-19 19:17:59 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2011-09-19 19:17:59 +0400 |
commit | d50058d08b3250761087ed4d77e279b0999c8ef5 (patch) | |
tree | d3be6ff0e83749aa7c0a3219cc9716db3658e618 /accel-pppd/extra | |
parent | cb6c09e7def0913c77b57ced8656e406176adfd4 (diff) | |
download | accel-ppp-xebd-d50058d08b3250761087ed4d77e279b0999c8ef5.tar.gz accel-ppp-xebd-d50058d08b3250761087ed4d77e279b0999c8ef5.zip |
shaper_tbf: fix temporary rate change functionality
Diffstat (limited to 'accel-pppd/extra')
-rw-r--r-- | accel-pppd/extra/shaper_tbf.c | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/accel-pppd/extra/shaper_tbf.c b/accel-pppd/extra/shaper_tbf.c index 6060027..52ba6a2 100644 --- a/accel-pppd/extra/shaper_tbf.c +++ b/accel-pppd/extra/shaper_tbf.c @@ -795,7 +795,8 @@ static void ev_shaper(struct ev_shaper_t *ev) struct shaper_pd_t *pd = find_pd(ev->ppp, 1); int down_speed = 0, down_burst = 0; int up_speed = 0, up_burst = 0; - int tr_id; + int tr_id = 0; + struct time_range_pd_t *tr_pd; if (!pd) return; @@ -803,9 +804,29 @@ static void ev_shaper(struct ev_shaper_t *ev) parse_string(ev->val, ATTR_DOWN, &down_speed, &down_burst, &tr_id); parse_string(ev->val, ATTR_UP, &up_speed, &up_burst, &tr_id); - if (down_speed > 0 && up_speed > 0) { + tr_pd = get_tr_pd(pd, tr_id); + tr_pd->down_speed = down_speed; + tr_pd->down_burst = down_burst; + tr_pd->up_speed = up_speed; + tr_pd->up_burst = up_burst; + + if (temp_down_speed || temp_up_speed) { + pd->temp_down_speed = temp_down_speed; + pd->temp_up_speed = temp_up_speed; + pd->down_speed = temp_down_speed; + pd->up_speed = temp_up_speed; + down_speed = temp_down_speed; + up_speed = temp_up_speed; + down_burst = 0; + up_burst = 0; + } else { + if (!pd->cur_tr) + return; pd->down_speed = down_speed; pd->up_speed = up_speed; + } + + if (pd->down_speed > 0 && pd->up_speed > 0) { if (!install_shaper(ev->ppp->ifname, down_speed, down_burst, up_speed, up_burst)) { if (conf_verbose) log_ppp_info2("tbf: installed shaper %i/%i (Kbit)\n", down_speed, up_speed); @@ -813,6 +834,24 @@ static void ev_shaper(struct ev_shaper_t *ev) } } +static void ev_ppp_started(struct ppp_t *ppp) +{ + struct shaper_pd_t *pd = find_pd(ppp, 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; + pd->down_speed = temp_down_speed; + pd->up_speed = temp_up_speed; + if (!install_shaper(ppp->ifname, temp_down_speed, 0, temp_up_speed, 0)) { + if (conf_verbose) + log_ppp_info2("tbf: installed shaper %i/%i (Kbit)\n", temp_down_speed, temp_up_speed); + } + } +} + static void ev_ctrl_finished(struct ppp_t *ppp) { struct shaper_pd_t *pd = find_pd(ppp, 0); @@ -835,14 +874,14 @@ static void shaper_change_help(char * const *f, int f_cnt, void *cli) static void shaper_change(struct shaper_pd_t *pd) { - if (pd->down_speed && pd->up_speed) + if (pd->down_speed || pd->up_speed) remove_shaper(pd->ppp->ifname); - if (pd->temp_down_speed && pd->temp_up_speed) { + if (pd->temp_down_speed || pd->temp_up_speed) { pd->down_speed = pd->temp_down_speed; pd->up_speed = pd->temp_up_speed; install_shaper(pd->ppp->ifname, pd->temp_down_speed, 0, pd->temp_up_speed, 0); - } else if (pd->cur_tr->down_speed && pd->cur_tr->up_speed) { + } else if (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; install_shaper(pd->ppp->ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); @@ -921,8 +960,14 @@ static void shaper_restore(struct shaper_pd_t *pd) { remove_shaper(pd->ppp->ifname); - if (pd->cur_tr) + if (pd->cur_tr) { + pd->down_speed = pd->cur_tr->down_speed; + pd->up_speed = pd->cur_tr->up_speed; install_shaper(pd->ppp->ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); + } else { + pd->down_speed = 0; + pd->up_speed = 0; + } } static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void *cli) @@ -1291,6 +1336,7 @@ static void init(void) triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa); } #endif + triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ev_ppp_started); triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished); triton_event_register_handler(EV_SHAPER, (triton_event_func)ev_shaper); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); |