]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Use timestamp as session ID
authorpcarana <pc.moreno2099@gmail.com>
Thu, 28 Feb 2019 19:55:08 +0000 (13:55 -0600)
committerpcarana <pc.moreno2099@gmail.com>
Thu, 28 Feb 2019 19:55:08 +0000 (13:55 -0600)
src/rtr/pdu_handler.c
src/vrps.c
src/vrps.h

index 0fec38e1a40dd9b16915b9d93c7f73218fb05a3b..3f3d8c786e5173fa8e77dc44e549afeb80d1918b 100644 (file)
@@ -50,9 +50,20 @@ handle_serial_query_pdu(int fd, void *pdu)
        struct sender_common common;
        int error, updates;
        u_int32_t current_serial;
+       u_int16_t session_id;
+
+       /*
+        * RFC 6810 and 8210:
+        * "If [...] either the router or the cache finds that the value of the
+        * Session ID is not the same as the other's, the party which detects the
+        * mismatch MUST immediately terminate the session with an Error Report PDU
+        * with code 0 ("Corrupt Data")"
+        */
+       session_id = current_session_id();
+       if (received->header.session_id != session_id)
+               return send_error_report_pdu(&common, ERR_CORRUPT_DATA, NULL, NULL);
 
        current_serial = last_serial_number();
-       /* TODO Handle sessions and its ID */
        init_sender_common(&common, fd, received->header.protocol_version,
            &received->header.session_id, &received->serial_number,
            &current_serial);
@@ -91,8 +102,7 @@ handle_reset_query_pdu(int fd, void *pdu)
        int error, updates;
 
        current_serial = last_serial_number();
-       /* TODO Handle sessions and its ID */
-       session_id = 1;
+       session_id = current_session_id();
        init_sender_common(&common, fd, received->header.protocol_version,
            &session_id, NULL, &current_serial);
 
index 5ab42de21a436f91004bcf7ff2049188b42f3a91..5ab1bf408e5396e07b442db772f2ebee90ee455d 100644 (file)
@@ -1,5 +1,6 @@
 #include "vrps.h"
 
+#include <time.h>
 #include "array_list.h"
 
 #define FLAG_WITHDRAWAL                0
@@ -16,6 +17,7 @@ ARRAY_LIST(deltasdb, struct delta)
 
 struct deltasdb db;
 u_int32_t current_serial;
+u_int16_t session_id;
 
 int
 deltas_db_init(void)
@@ -28,6 +30,8 @@ deltas_db_init(void)
                return error;
        }
        current_serial = 0;
+       /* The downcast takes the LSBs */
+       session_id = time(NULL);
 
        return 0;
 }
@@ -230,3 +234,9 @@ last_serial_number(void)
 {
        return current_serial;
 }
+
+u_int16_t
+current_session_id(void)
+{
+       return session_id;
+}
index 445ba62801c1f86a1eb6258dabeb9860abd6082d..4a7749601e5e4eeb7dcec8d3d77c8895df42ec75 100644 (file)
@@ -39,5 +39,6 @@ void delta_destroy(struct delta *);
 void deltas_db_destroy(void);
 
 u_int32_t last_serial_number(void);
+u_int16_t current_session_id(void);
 
 #endif /* SRC_VRPS_H_ */