Fix: inverted delete/add routes in cluster mode
authorfendo <fendo@bi12info.com>
Sun, 13 Jan 2013 22:08:38 +0000 (23:08 +0100)
committerfendo <fendo@bi12info.com>
Sun, 13 Jan 2013 22:08:38 +0000 (23:08 +0100)
cluster.c
cluster.h
l2tpns.c
pppoe.c

index cf65972..78de01b 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -1018,54 +1018,27 @@ static int type_changed(int type, int id)
 {
        int i;
 
-       for (i = 0 ; i < config->cluster_num_changes ; ++i)
-               if ( cluster_changes[i].id == id &&
-                       cluster_changes[i].type == type)
-                       return 0;       // Already marked for change.
-
-       cluster_changes[i].type = type;
-       cluster_changes[i].id = id;
-       ++config->cluster_num_changes;
-
-       if (config->cluster_num_changes > MAX_CHANGES)
-               cluster_heartbeat(); // flush now
-
-       return 1;
-}
-
-// The deleted session, must be before the new session
-int cluster_listinvert_session(int sidnew, int sidtodel)
-{
-       int i, inew = 0;
-
        for (i = 0 ; i < config->cluster_num_changes ; ++i)
        {
-               if ( cluster_changes[i].id == sidtodel && cluster_changes[i].type == C_CSESSION)
-                       return 0;       // Deleted session already before the new session.
-
-               if ( cluster_changes[i].id == sidnew && cluster_changes[i].type == C_CSESSION)
+               if ( cluster_changes[i].id == id && cluster_changes[i].type == type)
                {
-                       if (session[i].tunnel != T_FREE)
-                               inew = i;
-                       else
-                               return 0;       // This a free session no invert.
-
+                       // Already marked for change, remove it
+                       --config->cluster_num_changes;
+                       memmove(&cluster_changes[i],
+                                       &cluster_changes[i+1],
+                                       (config->cluster_num_changes - i) * sizeof(cluster_changes[i]));
                        break;
                }
        }
 
-       for ( ; i < config->cluster_num_changes ; ++i)
-       {
-               if ( cluster_changes[i].id == sidtodel && cluster_changes[i].type == C_CSESSION)
-               {
-                       // Reverse position
-                       cluster_changes[i].id = sidnew;
-                       cluster_changes[inew].id = sidtodel;
-                       return 1;
-               }
-       }
+       cluster_changes[config->cluster_num_changes].type = type;
+       cluster_changes[config->cluster_num_changes].id = id;
+       ++config->cluster_num_changes;
 
-       return 0;
+       if (config->cluster_num_changes > MAX_CHANGES)
+               cluster_heartbeat(); // flush now
+
+       return 1;
 }
 
 // A particular session has been changed!
index 59a6aa6..6a769e4 100644 (file)
--- a/cluster.h
+++ b/cluster.h
@@ -83,7 +83,6 @@ typedef struct {
 
 int cluster_init(void);
 int processcluster(uint8_t *buf, int size, in_addr_t addr);
-int cluster_listinvert_session(int sidnew, int sidtodel);
 int cluster_send_session(int sid);
 int cluster_send_bundle(int bid);
 int cluster_send_tunnel(int tid);
index 0da9a24..850cd76 100644 (file)
--- a/l2tpns.c
+++ b/l2tpns.c
@@ -5548,8 +5548,7 @@ int sessionsetup(sessionidt s, tunnelidt t)
 
                        if (ip == session[i].ip)
                        {
-                               sessionkill(i, "Duplicate IP address");
-                               cluster_listinvert_session(s, i);
+                               sessionshutdown(i, "Duplicate IP address", CDN_ADMIN_DISC, TERM_ADMIN_RESET);  // close radius/routes, etc.
                                continue;
                        }
 
@@ -5570,7 +5569,7 @@ int sessionsetup(sessionidt s, tunnelidt t)
 
                        // Drop the new session in case of duplicate sessionss, not the old one.
                        if (!strcasecmp(user, session[i].user))
-                               sessionkill(i, "Duplicate session for users");
+                               sessionshutdown(i, "Duplicate session for users", CDN_ADMIN_DISC, TERM_ADMIN_RESET);  // close radius/routes, etc.
                }
        }
 
diff --git a/pppoe.c b/pppoe.c
index 52b554e..882e0c1 100644 (file)
--- a/pppoe.c
+++ b/pppoe.c
@@ -1,6 +1,7 @@
 /*
  * Fernando ALVES 2013
  * Add functionality "server pppoe" to l2tpns.
+ * inspiration pppoe.c of accel-ppp
  * GPL licenced
  */