X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/916c13c6039bd189873ee094e9c0ebd010899792..bb40243c71b99c8bbb08deb95c68b7af9b7bb0d4:/grpsess.c?ds=sidebyside diff --git a/grpsess.c b/grpsess.c index 73c729a..f38ab1a 100644 --- a/grpsess.c +++ b/grpsess.c @@ -42,6 +42,14 @@ static groupidt grp_lookup_ipmap(in_addr_t ip) return h[*a].grp; } +typedef struct +{ + sessionidt sid_loaddist[0x10000]; +} +local_group; + +local_group *grp_local = NULL; // Array of local_group structures. + // // Take an IP address in HOST byte order and // add it to the grouid by IP cache. @@ -129,7 +137,7 @@ static void grp_routeset(groupidt g, in_addr_t ip, int prefixlen, int add) n_ip = htonl(ip); netlink_addattr(&req.nh, RTA_DST, &n_ip, sizeof(n_ip)); - LOG(1, 0, 0, "Route (Group) %s %s/%d\n", add ? "add" : "del", fmtaddr(htonl(ip), 0), prefixlen); + LOG(3, 0, 0, "Route (Group) %s %s/%d\n", add ? "add" : "del", fmtaddr(htonl(ip), 0), prefixlen); if (netlink_send(&req.nh) < 0) LOG(0, 0, 0, "grp_routeset() error in sending netlink message: %s\n", strerror(errno)); @@ -447,6 +455,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 @@ -498,7 +514,7 @@ static void grp_uncache_ipsession(groupidt g, sessionidt s) } // 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; @@ -551,9 +567,30 @@ 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; + grp_local[g].sid_loaddist[ai] = s; + } + + if (g != grp_groupbysession(s)) + { + // This session does not belong to this group + LOG(2, 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 (s == grpsession[g].smax) { s = grpsession[g].smin; + grp_local[g].sid_loaddist[ai] = s; grpsession[g].smax = 0; } else if ( (session[s].ppp.phase > Establish) && @@ -564,6 +601,7 @@ sessionidt grp_getnextsession(groupidt g, in_addr_t ip) else { s = 0; + grp_local[g].sid_loaddist[ai] = 0; } } @@ -633,7 +671,7 @@ int grp_cluster_load_groupe(groupidt g, groupsesst *new) // Check session list for (i = 0; i < grpsession[g].nbsession; i++) { - if (grpsession[g].sesslist[i].sid == new->sesslist[i].sid) + if (grpsession[g].sesslist[i].sid != new->sesslist[i].sid) { updategroup = 1; break;