X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/658f6aea7b968c7db3a1c2be58c62efb091c3984..ba1c3362c6dc0d65eb3d06368c47b75aa135456b:/grpsess.c diff --git a/grpsess.c b/grpsess.c index 7f897b3..5528453 100644 --- a/grpsess.c +++ b/grpsess.c @@ -9,7 +9,9 @@ #include #include #include +#include +#include "dhcp6.h" #include "l2tpns.h" #include "util.h" #include "cluster.h" @@ -25,6 +27,14 @@ union grp_iphash { groupidt gnextgrpid = 0; +typedef struct +{ + sessionidt sid_loaddist[0x10000]; +} +local_group; + +local_group *grp_local = NULL; // Array of local_group structures. + // Find gruop by IP, < 1 for not found // // Confusingly enough, this 'ip' must be @@ -447,6 +457,14 @@ void grp_initdata() { grpsession[i].state = GROUPEUNDEF; } + + if (!(grp_local = shared_malloc(sizeof(local_group) * MAXGROUPE))) + { + LOG(0, 0, 0, "Error doing malloc for grp_local: %s\n", strerror(errno)); + exit(1); + } + memset(grp_local, 0, sizeof(grp_local[0]) * MAXGROUPE); + } // Update time_changed of the group @@ -497,13 +515,14 @@ static void grp_uncache_ipsession(groupidt g, sessionidt s) } } +uint16_t guint16_index_loadlist; // return the next session can be used on the group -sessionidt grp_getnextsession(groupidt g, in_addr_t ip) +sessionidt grp_getnextsession(groupidt g, in_addr_t ip, in_addr_t ip_src) { sessionidt s = 0, s2 = 0, s3 = 0; int i; uint32_t ltime_changed = 0, mintxrate = 0xFFFFFFFF, maxtxrate = 0; - uint32_t txrate; + uint32_t txrate = 0; if (g >= MAXGROUPE) return 0; @@ -523,7 +542,8 @@ sessionidt grp_getnextsession(groupidt g, in_addr_t ip) coutgrp_delta = session[s2].cout - grpsession[g].sesslist[i].prev_coutgrp; grpsession[g].sesslist[i].prev_coutgrp = session[s2].cout; - grpsession[g].sesslist[i].tx_rate = coutgrp_delta/ltime_changed; + txrate = (txrate + (coutgrp_delta/ltime_changed)) >> 1; + grpsession[g].sesslist[i].tx_rate = txrate; txrate = grpsession[g].sesslist[i].tx_rate/grpsession[g].sesslist[i].weight; if (txrate < mintxrate) @@ -551,19 +571,36 @@ sessionidt grp_getnextsession(groupidt g, in_addr_t ip) if ((s = sessionbyip(ip))) { - if (s == grpsession[g].smax) + uint8_t *as = (uint8_t *) &ip_src; + uint8_t *ad = (uint8_t *) &ip; + uint16_t ai = ad[3]; + ai <<= 8; + ai |= as[3]; + + s = grp_local[g].sid_loaddist[ai]; + if (!s) { s = grpsession[g].smin; - grpsession[g].smax = 0; + grp_local[g].sid_loaddist[ai] = s; + } + + if (g != grp_groupbysession(s)) + { + // This session does not belong to this group + LOG(3, s, session[s].tunnel, "Warning, the session does not belong to group %d\n", g); + s = 0; + grp_local[g].sid_loaddist[ai] = 0; } else if ( (session[s].ppp.phase > Establish) && (time_now - session[s].last_packet <= (config->echo_timeout + 1)) ) { + grp_local[g].sid_loaddist[guint16_index_loadlist++] = 0; return s; } else { s = 0; + grp_local[g].sid_loaddist[ai] = 0; } }