union grp_iphash *idx;
} grp_ip_hash[256]; // Mapping from IP address to group structures.
-static groupidt gnextgrpid = 0;
+groupidt gnextgrpid = 0;
// Find gruop by IP, < 1 for not found
//
// return the next session can be used on the group
sessionidt grp_getnextsession(groupidt g, in_addr_t ip)
{
- sessionidt s = 0, s2 = 0, s3 = 0, smax = 0;
+ sessionidt s = 0, s2 = 0, s3 = 0;
int i;
uint32_t ltime_changed = 0, mintxrate = 0xFFFFFFFF, maxtxrate = 0;
uint32_t txrate;
if (g >= MAXGROUPE)
return 0;
- if (grpsession[g].time_changed < config->grp_txrate_average_time)
- {
- if ((s = sessionbyip(ip)))
- {
- if ( (session[s].ppp.phase > Establish) &&
- (time_now - session[s].last_packet <= (config->echo_timeout + 1)) )
- {
- return s;
- }
- s = 0;
- }
- }
- else
+ if (grpsession[g].time_changed >= config->grp_txrate_average_time)
{
// recalculation txrate
ltime_changed = grpsession[g].time_changed;
grpsession[g].time_changed = 0;
- s = 0;
for (i = 0; i < grpsession[g].nbsession; i++)
{
if ((s2 = grpsession[g].sesslist[i].sid))
{
- s3 = s2;
-
grpsession[g].sesslist[i].tx_rate = session[s2].coutgrp_delta/ltime_changed;
session[s2].coutgrp_delta = 0;
- //LOG(3, s2, session[s2].tunnel, "TX Rate: %d session weight: %d\n",
- // grpsession[g].sesslist[i].tx_rate, grpsession[g].sesslist[i].weight);
-
txrate = grpsession[g].sesslist[i].tx_rate/grpsession[g].sesslist[i].weight;
if (txrate < mintxrate)
{
if ( session[s2].ppp.phase > Establish &&
(time_now - session[s2].last_packet <= (config->echo_timeout + 1)) )
{
- s = s2;
+ grpsession[g].smin = s2;
mintxrate = txrate;
}
}
if ( session[s2].ppp.phase > Establish &&
(time_now - session[s2].last_packet <= (config->echo_timeout + 1)) )
{
- smax = s2;
+ grpsession[g].smax = s2;
maxtxrate = txrate;
}
}
}
}
+ }
- if (smax && (maxtxrate != mintxrate))
+ if ((s = sessionbyip(ip)))
+ {
+ if (s == grpsession[g].smax)
+ {
+ s = grpsession[g].smin;
+ grpsession[g].smax = 0;
+ }
+ else if ( (session[s].ppp.phase > Establish) &&
+ (time_now - session[s].last_packet <= (config->echo_timeout + 1)) )
{
- grp_uncache_ipsession(g, smax);
+ return s;
+ }
+ else
+ {
+ s = 0;
}
}
(time_now - session[s2].last_packet <= (config->echo_timeout + 1)))
{
s = s2;
- //LOG(3, s, session[s].tunnel, "New random session\n");
}
else
{