diff --git a/src/session/session_manager.cpp b/src/session/session_manager.cpp index cf4749e..9bf66ee 100644 --- a/src/session/session_manager.cpp +++ b/src/session/session_manager.cpp @@ -918,6 +918,14 @@ void session_manager_free(struct session_manager *mgr) } } +void session_manager_record_duplicated_packet(struct session_manager *mgr, const struct packet *pkt, uint64_t now) +{ + if (mgr->opts.duplicated_packet_filter_enable) + { + duplicated_packet_filter_add(mgr->dup_pkt_filter, pkt, now); + } +} + struct session *session_manager_new_session(struct session_manager *mgr, const struct packet *pkt, uint64_t now) { struct tuple6 key; diff --git a/src/session/session_manager.h b/src/session/session_manager.h index d86dfae..36ce1e7 100644 --- a/src/session/session_manager.h +++ b/src/session/session_manager.h @@ -99,6 +99,7 @@ struct session_manager_stat struct session_manager; struct session_manager *session_manager_new(struct session_manager_options *opts, uint64_t now); void session_manager_free(struct session_manager *mgr); +void session_manager_record_duplicated_packet(struct session_manager *mgr, const struct packet *pkt, uint64_t now); struct session *session_manager_new_session(struct session_manager *mgr, const struct packet *pkt, uint64_t now); void session_manager_free_session(struct session_manager *mgr, struct session *sess); diff --git a/src/stellar/inject.cpp b/src/stellar/inject.cpp index 0e09fcf..39cc889 100644 --- a/src/stellar/inject.cpp +++ b/src/stellar/inject.cpp @@ -1,7 +1,7 @@ -#include #include #include +#include "times.h" #include "tcp_utils.h" #include "udp_utils.h" #include "ipv4_utils.h" @@ -205,9 +205,7 @@ static inline void calc_tcp_fingerprint(struct tcp_fingerprint *finger) { #define RANGE(rand, start, end) (start + rand % (end - start + 1)) // [start, end] - struct timespec curtime; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &curtime); - uint64_t random = (0x013579ABCDEF ^ (uint64_t)curtime.tv_nsec); + uint64_t random = 0x013579ABCDEF ^ stellar_get_monotonic_time_msec(); finger->ipid = (uint16_t)(RANGE(random, 32767, 65535)); finger->ttl = (uint8_t)(RANGE(random, 48, 120)); finger->win = (uint16_t)(RANGE(random, 1000, 1460)); @@ -385,6 +383,7 @@ int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir (((flags) & TH_SYN) ? 1 : 0), (((flags) & TH_FIN) ? 1 : 0) uint16_t thr_idx = stellar_get_current_thread_index(); + uint64_t time_ms = stellar_get_monotonic_time_msec(); if (session_get_type(sess) != SESSION_TYPE_TCP) { @@ -428,6 +427,7 @@ int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir packet_parse(&inj_pkt, buff, pkt_len); packet_set_origin(&inj_pkt, PACKET_ORIGIN_USERSTACK); packet_set_origin_ctx(&inj_pkt, &meta); + session_manager_record_duplicated_packet(runtime->threads[thr_idx].sess_mgr, &inj_pkt, time_ms); if (packet_io_inject(runtime->packet_io, thr_idx, &inj_pkt, 1) == 1) { session_inc_stat((struct session *)sess, inject_dir, STAT_INJECTED_PACKETS_SUCCESS, 1); @@ -448,6 +448,7 @@ int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir int inject_udp_packet(const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len) { uint16_t thr_idx = stellar_get_current_thread_index(); + uint64_t time_ms = stellar_get_monotonic_time_msec(); if (session_get_type(sess) != SESSION_TYPE_UDP) { @@ -485,6 +486,7 @@ int inject_udp_packet(const struct session *sess, enum flow_direction inject_dir packet_parse(&inj_pkt, buff, pkt_len); packet_set_origin(&inj_pkt, PACKET_ORIGIN_USERSTACK); packet_set_origin_ctx(&inj_pkt, &meta); + session_manager_record_duplicated_packet(runtime->threads[thr_idx].sess_mgr, &inj_pkt, time_ms); if (packet_io_inject(runtime->packet_io, thr_idx, &inj_pkt, 1) == 1) { session_inc_stat((struct session *)sess, inject_dir, STAT_INJECTED_PACKETS_SUCCESS, 1);