Update changelog (LAC functionnality)
[l2tpns.git] / cluster.c
index c6f7eee..b2a244e 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -363,6 +363,28 @@ int master_garden_packet(sessionidt s, uint8_t *data, int size)
 
 }
 
+//
+// Forward a MPPP packet to the master for handling.
+//
+// (Note that this must be called with the tun header
+// as the start of the data).
+// (i.e. this routine writes to data[-8]).
+int master_forward_mppp_packet(sessionidt s, uint8_t *data, int size)
+{
+       uint8_t *p = data - (2 * sizeof(uint32_t));
+       uint8_t *psave = p;
+
+       if (!config->cluster_master_address) // No election has been held yet. Just skip it.
+               return -1;
+
+       LOG(4, 0, 0, "Forward MPPP packet to master (size %d)\n", size);
+
+       add_type(&p, C_MPPP_FORWARD, s, NULL, 0);
+
+       return peer_send_data(config->cluster_master_address, psave, size + (2 * sizeof(uint32_t)));
+
+}
+
 //
 // Send a chunk of data as a heartbeat..
 // We save it in the history buffer as we do so.
@@ -945,7 +967,7 @@ void cluster_heartbeat()
                exit(1);
        }
 
-       LOG(3, 0, 0, "Sending v%d heartbeat #%d, change #%" PRIu64 " with %d changes "
+       LOG(4, 0, 0, "Sending v%d heartbeat #%d, change #%" PRIu64 " with %d changes "
                     "(%d x-sess, %d x-bundles, %d x-tunnels, %d highsess, %d highbund, %d hightun, size %d)\n",
            HB_VERSION, h.seq, h.table_version, config->cluster_num_changes,
            count, bcount, tcount, config->cluster_highest_sessionid, config->cluster_highest_bundleid,
@@ -980,6 +1002,36 @@ static int type_changed(int type, int id)
        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)
+               {
+                       inew = 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;
+               }
+       }
+
+       return 0;
+}
 
 // A particular session has been changed!
 int cluster_send_session(int sid)
@@ -1351,10 +1403,10 @@ struct oldsession {
        uint32_t tx_connect_speed;
        uint32_t rx_connect_speed;
        clockt timeout;
-        uint32_t mrru;
-        uint8_t mssf;
-        epdist epdis;
-        bundleidt bundle;
+       uint32_t mrru;
+       uint8_t mssf;
+       epdist epdis;
+       bundleidt bundle;
        in_addr_t snoop_ip;
        uint16_t snoop_port;
        uint8_t walled_garden;
@@ -1435,6 +1487,7 @@ static uint8_t *convert_session(struct oldsession *old)
 // Process a heartbeat..
 //
 // v6: added RADIUS class attribute, re-ordered session structure
+// v7: added tunnelt attribute at the end of struct (tunnelt size change)
 static int cluster_process_heartbeat(uint8_t *data, int size, int more, uint8_t *p, in_addr_t addr)
 {
        heartt *h;
@@ -1442,11 +1495,18 @@ static int cluster_process_heartbeat(uint8_t *data, int size, int more, uint8_t
        int i, type;
        int hb_ver = more;
 
+#ifdef LAC
+#if HB_VERSION != 7
+# error "need to update cluster_process_heartbeat()"
+#endif
+#else
 #if HB_VERSION != 6
 # error "need to update cluster_process_heartbeat()"
 #endif
+#endif
+
 
-       // we handle versions 5 through 6
+       // we handle versions 5 through 7
        if (hb_ver < 5 || hb_ver > HB_VERSION) {
                LOG(0, 0, 0, "Received a heartbeat version that I don't support (%d)!\n", hb_ver);
                return -1; // Ignore it??
@@ -1658,7 +1718,13 @@ static int cluster_process_heartbeat(uint8_t *data, int size, int more, uint8_t
                                size = rle_decompress((uint8_t **) &p, s, c, sizeof(c));
                                s -= (p - orig_p);
 
-                               if (size != sizeof(tunnelt) ) { // Ouch! Very very bad!
+#ifdef LAC
+                               if ( ((hb_ver >= HB_VERSION) && (size != sizeof(tunnelt))) ||
+                                        ((hb_ver < HB_VERSION) && (size > sizeof(tunnelt))) )
+#else
+                               if (size != sizeof(tunnelt) )
+#endif
+                               { // Ouch! Very very bad!
                                        LOG(0, 0, 0, "DANGER: Received a CTUNNEL that didn't decompress correctly!\n");
                                                // Now what? Should exit! No-longer up to date!
                                        break;
@@ -1802,6 +1868,16 @@ int processcluster(uint8_t *data, int size, in_addr_t addr)
                        return 0;
                }
 
+       case C_MPPP_FORWARD:
+               // Receive a MPPP packet from a slave.
+               if (!config->cluster_iam_master) {
+                       LOG(0, 0, 0, "I'm not the master, but I got a C_MPPP_FORWARD from %s?\n", fmtaddr(addr, 0));
+                       return -1;
+               }
+
+               processipout(p, s);
+               return 0;
+
        case C_THROTTLE: {      // Receive a forwarded packet from a slave.
                if (!config->cluster_iam_master) {
                        LOG(0, 0, 0, "I'm not the master, but I got a C_THROTTLE from %s?\n", fmtaddr(addr, 0));