diff --git a/l2tplac.c b/l2tplac.c index 8be2261..0cec975 100644 --- a/l2tplac.c +++ b/l2tplac.c @@ -532,20 +532,8 @@ int lac_session_forward(uint8_t *buf, int len, sessionidt sess, uint16_t proto, if ((proto == PPPIP) || (proto == PPPMP) ||(proto == PPPIPV6 && config->ipv6_prefix.s6_addr[0])) { session[sess].last_packet = session[sess].last_data = time_now; - // Update STAT IN - increment_counter(&session[sess].cin, &session[sess].cin_wrap, len); - session[sess].cin_delta += len; - session[sess].pin++; - sess_local[sess].cin += len; - sess_local[sess].pin++; - - session[s].last_data = time_now; - // Update STAT OUT - increment_counter(&session[s].cout, &session[s].cout_wrap, len); // byte count - session[s].cout_delta += len; - session[s].pout++; - sess_local[s].cout += len; - sess_local[s].pout++; + update_session_in_stat(sess, 1, len); + update_session_out_stat(s, 1, len); } else session[sess].last_packet = time_now; diff --git a/l2tpns.c b/l2tpns.c index 4cd1a28..3e6d846 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -2276,15 +2276,34 @@ void processmpframe(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l, uint8_t e } } -static void update_session_out_stat(sessionidt s, sessiont *sp, int len) +// +// Account for some incoming packets in the session statistics +void update_session_in_stat(sessionidt s, int packets, size_t len) { + sessiont *sp = &session[s]; + + increment_counter(&sp->cin, &sp->cin_wrap, len); // byte count + sp->cin_delta += len; + sp->pin += packets; + sp->last_data = time_now; + + sess_local[s].cin += len; // To send to master.. + sess_local[s].pin += packets; +} + +// +// Account for some outgoing packets in the session statistics +void update_session_out_stat(sessionidt s, int packets, size_t len) +{ + sessiont *sp = &session[s]; + increment_counter(&sp->cout, &sp->cout_wrap, len); // byte count sp->cout_delta += len; - sp->pout++; + sp->pout += packets; sp->last_data = time_now; sess_local[s].cout += len; // To send to master.. - sess_local[s].pout++; + sess_local[s].pout += packets; } // process outgoing (to tunnel) IP @@ -2493,7 +2512,7 @@ void processipout(uint8_t *buf, int len) tunnelsend(fragbuf, fraglen + (p-fragbuf), t); // send it... // statistics - update_session_out_stat(s, sp, fraglen); + update_session_out_stat(s, 1, fraglen); remain -= fraglen; while (remain > last_fraglen) @@ -2506,7 +2525,7 @@ void processipout(uint8_t *buf, int len) p = makeppp(fragbuf, sizeof(fragbuf), buf+(len - remain), fraglen, s, t, PPPIP, 0, bid, 0); if (!p) return; tunnelsend(fragbuf, fraglen + (p-fragbuf), t); // send it... - update_session_out_stat(s, sp, fraglen); + update_session_out_stat(s, 1, fraglen); remain -= fraglen; } // send the last fragment @@ -2518,7 +2537,7 @@ void processipout(uint8_t *buf, int len) p = makeppp(fragbuf, sizeof(fragbuf), buf+(len - remain), remain, s, t, PPPIP, 0, bid, MP_END); if (!p) return; tunnelsend(fragbuf, remain + (p-fragbuf), t); // send it... - update_session_out_stat(s, sp, remain); + update_session_out_stat(s, 1, remain); if (remain != last_fraglen) LOG(3, s, t, "PROCESSIPOUT ERROR REMAIN != LAST_FRAGLEN, %d != %d\n", remain, last_fraglen); } @@ -2529,7 +2548,7 @@ void processipout(uint8_t *buf, int len) if (!p) return; tunnelsend(fragbuf, len + (p-fragbuf), t); // send it... LOG(4, s, t, "MPPP: packet sent as one frame\n"); - update_session_out_stat(s, sp, len); + update_session_out_stat(s, 1, len); } } else @@ -2537,14 +2556,14 @@ void processipout(uint8_t *buf, int len) // Send it as one frame (NO MPPP Frame) uint8_t *p = opt_makeppp(buf, len, s, t, PPPIP, 0, 0, 0); tunnelsend(p, len + (buf-p), t); // send it... - update_session_out_stat(s, sp, len); + update_session_out_stat(s, 1, len); } } else { uint8_t *p = opt_makeppp(buf, len, s, t, PPPIP, 0, 0, 0); tunnelsend(p, len + (buf-p), t); // send it... - update_session_out_stat(s, sp, len); + update_session_out_stat(s, 1, len); } // Snooping this session, send it to intercept box diff --git a/l2tpns.h b/l2tpns.h index 8b1f121..c28eccc 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -979,6 +979,8 @@ void adjust_tcp6_mss(sessionidt s, tunnelidt t, uint8_t *buf, int len, uint8_t * void sendipcp(sessionidt s, tunnelidt t); void sendipv6cp(sessionidt s, tunnelidt t); void processudp(uint8_t *buf, int len, struct sockaddr_in *addr, uint16_t indexudpfd); +void update_session_in_stat(sessionidt s, int packets, size_t len); +void update_session_out_stat(sessionidt s, int packets, size_t len); void processipout(uint8_t *buf, int len); void snoop_send_packet(uint8_t *packet, uint16_t size, in_addr_t destination, uint16_t port); int find_filter(char const *name, size_t len); diff --git a/ppp.c b/ppp.c index 08c2ef0..36645e0 100644 --- a/ppp.c +++ b/ppp.c @@ -1722,12 +1722,7 @@ static void update_sessions_in_stat(sessionidt s, uint16_t l) bundleidt b = session[s].bundle; if (!b) { - increment_counter(&session[s].cin, &session[s].cin_wrap, l); - session[s].cin_delta += l; - session[s].pin++; - - sess_local[s].cin += l; - sess_local[s].pin++; + update_session_in_stat(s, 1, l); } else { @@ -1737,12 +1732,8 @@ static void update_sessions_in_stat(sessionidt s, uint16_t l) { l = frag[b].fragment[i].length; s = frag[b].fragment[i].sid; - increment_counter(&session[s].cin, &session[s].cin_wrap, l); - session[s].cin_delta += l; - session[s].pin++; + update_session_in_stat(s, 1, l); - sess_local[s].cin += l; - sess_local[s].pin++; if (i == end) return; i = (i + 1) & MAXFRAGNUM_MASK; @@ -2383,12 +2374,7 @@ void send_ipin(sessionidt s, uint8_t *buf, int len) } // Increment packet counters - increment_counter(&session[s].cin, &session[s].cin_wrap, len); - session[s].cin_delta += len; - session[s].pin++; - - sess_local[s].cin += len; - sess_local[s].pin++; + update_session_in_stat(s, 1, len); eth_tx += len; diff --git a/pppoe.c b/pppoe.c index 935bd0f..c60f4fb 100644 --- a/pppoe.c +++ b/pppoe.c @@ -955,21 +955,9 @@ static void pppoe_forwardto_session_rmlns(uint8_t *pack, int size, sessionidt se if ((proto == PPPIP) || (proto == PPPMP) ||(proto == PPPIPV6 && config->ipv6_prefix.s6_addr[0])) { - session[sess].last_packet = session[sess].last_data = time_now; - // Update STAT IN - increment_counter(&session[sess].cin, &session[sess].cin_wrap, ll2tp); - session[sess].cin_delta += ll2tp; - session[sess].pin++; - sess_local[sess].cin += ll2tp; - sess_local[sess].pin++; - - session[s].last_data = time_now; - // Update STAT OUT - increment_counter(&session[s].cout, &session[s].cout_wrap, ll2tp); // byte count - session[s].cout_delta += ll2tp; - session[s].pout++; - sess_local[s].cout += ll2tp; - sess_local[s].pout++; + session[sess].last_packet = time_now; + update_session_in_stat(s, 1, ll2tp); + update_session_out_stat(s, 1, ll2tp); } else session[sess].last_packet = time_now; @@ -1026,21 +1014,9 @@ void pppoe_forwardto_session_pppoe(uint8_t *pack, int size, sessionidt sess, uin if ((proto == PPPIP) || (proto == PPPMP) ||(proto == PPPIPV6 && config->ipv6_prefix.s6_addr[0])) { - session[sess].last_packet = session[sess].last_data = time_now; - // Update STAT IN - increment_counter(&session[sess].cin, &session[sess].cin_wrap, lpppoe); - session[sess].cin_delta += lpppoe; - session[sess].pin++; - sess_local[sess].cin += lpppoe; - sess_local[sess].pin++; - - session[s].last_data = time_now; - // Update STAT OUT - increment_counter(&session[s].cout, &session[s].cout_wrap, lpppoe); // byte count - session[s].cout_delta += lpppoe; - session[s].pout++; - sess_local[s].cout += lpppoe; - sess_local[s].pout++; + session[sess].last_packet = time_now; + update_session_in_stat(s, 1, lpppoe); + update_session_out_stat(s, 1, lpppoe); } else session[sess].last_packet = time_now;