Consolidate stat update code

into
update_session_in_stat
update_session_out_stat
This commit is contained in:
Samuel Thibault 2023-04-23 16:47:26 +02:00
parent 1db43fc51d
commit c7853de428
5 changed files with 41 additions and 70 deletions

View file

@ -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