Add injected packets to duplicate packet filter
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user