From: pcarana Date: Thu, 28 Feb 2019 19:55:08 +0000 (-0600) Subject: Use timestamp as session ID X-Git-Tag: v0.0.2~52^2~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8de6aa212e555028974ce4e08ac0001c4a375a1f;p=thirdparty%2FFORT-validator.git Use timestamp as session ID --- diff --git a/src/rtr/pdu_handler.c b/src/rtr/pdu_handler.c index 0fec38e1..3f3d8c78 100644 --- a/src/rtr/pdu_handler.c +++ b/src/rtr/pdu_handler.c @@ -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, ¤t_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, ¤t_serial); diff --git a/src/vrps.c b/src/vrps.c index 5ab42de2..5ab1bf40 100644 --- a/src/vrps.c +++ b/src/vrps.c @@ -1,5 +1,6 @@ #include "vrps.h" +#include #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; +} diff --git a/src/vrps.h b/src/vrps.h index 445ba628..4a774960 100644 --- a/src/vrps.h +++ b/src/vrps.h @@ -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_ */