Add test case: inject IPv4 based TCP payload packet after recv C2S first payload
This commit is contained in:
@@ -96,6 +96,7 @@ void packet_set_session_id(struct packet *pkt, uint64_t sess_id);
|
||||
void packet_set_direction(struct packet *pkt, enum packet_direction dir);
|
||||
|
||||
int packet_is_fragment(const struct packet *pkt);
|
||||
int packet_get_fingerprint(const struct packet *pkt, char *buff, int size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "udp_utils.h"
|
||||
#include "tcp_utils.h"
|
||||
#include "ipv4_utils.h"
|
||||
#include "ipv6_utils.h"
|
||||
#include "packet_priv.h"
|
||||
#include "marsio.h"
|
||||
|
||||
@@ -401,3 +405,65 @@ void packet_append_sid_list(struct packet *pkt, const struct sid_list *list)
|
||||
PACKET_LOG_WARN("packet origin is not marsio, failed to append sid list");
|
||||
}
|
||||
}
|
||||
|
||||
int packet_get_fingerprint(const struct packet *pkt, char *buff, int size)
|
||||
{
|
||||
int used = 0;
|
||||
char tuple_str[256] = {0};
|
||||
|
||||
struct tuple6 tuple;
|
||||
const struct tcphdr *tcp_hdr = NULL;
|
||||
const struct udphdr *udp_hdr = NULL;
|
||||
const struct ip *ipv4_hdr = NULL;
|
||||
const struct ip6_hdr *ipv6_hdr = NULL;
|
||||
const struct packet_layer *l3_layer = NULL;
|
||||
const struct packet_layer *l4_layer = NULL;
|
||||
memset(buff, 0, size);
|
||||
|
||||
if (packet_get_innermost_tuple6(pkt, &tuple) != 0)
|
||||
{
|
||||
return used;
|
||||
}
|
||||
tuple6_to_str(&tuple, tuple_str, sizeof(tuple_str));
|
||||
used += snprintf(buff + used, size - used, "tuple6: %s, ", tuple_str);
|
||||
|
||||
l3_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_L3);
|
||||
if (l3_layer == NULL || l3_layer->hdr_ptr == NULL)
|
||||
{
|
||||
return used;
|
||||
}
|
||||
switch (l3_layer->type)
|
||||
{
|
||||
case LAYER_TYPE_IPV4:
|
||||
ipv4_hdr = (const struct ip *)l3_layer->hdr_ptr;
|
||||
used += snprintf(buff + used, size - used, "ip_ttl: %u, ip_id: %u, ", ipv4_hdr_get_ttl(ipv4_hdr), ipv4_hdr_get_ipid(ipv4_hdr));
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
ipv6_hdr = (const struct ip6_hdr *)l3_layer->hdr_ptr;
|
||||
used += snprintf(buff + used, size - used, "ip6_hlim: %u, ", ipv6_hdr_get_hop_limit(ipv6_hdr));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
l4_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_L4);
|
||||
if (l4_layer == NULL || l4_layer->hdr_ptr == NULL)
|
||||
{
|
||||
return used;
|
||||
}
|
||||
switch (l4_layer->type)
|
||||
{
|
||||
case LAYER_TYPE_TCP:
|
||||
tcp_hdr = (const struct tcphdr *)l4_layer->hdr_ptr;
|
||||
used += snprintf(buff + used, size - used, "tcp_seq: %u, tcp_ack: %u, tcp_checksum: %u, ", tcp_hdr_get_seq(tcp_hdr), tcp_hdr_get_ack(tcp_hdr), tcp_hdr_get_checksum(tcp_hdr));
|
||||
break;
|
||||
case LAYER_TYPE_UDP:
|
||||
udp_hdr = (const struct udphdr *)l4_layer->hdr_ptr;
|
||||
used += snprintf(buff + used, size - used, "udp_checksum: %u, ", udp_hdr_get_checksum(udp_hdr));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ static void save_packet(const char *work_dir, struct packet *pkt, uint64_t idx)
|
||||
fwrite(packet_get_data(pkt), 1, len, fp);
|
||||
fflush(fp);
|
||||
fclose(fp);
|
||||
PACKET_IO_LOG_DEBUG("save packet to %s", file);
|
||||
PACKET_IO_LOG_STATE("save packet to %s", file);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -491,7 +491,7 @@ void stellar_print_config(struct stellar_config *config)
|
||||
CONFIG_LOG_DEBUG("packet_io->nr_threads : %d", io_opts->nr_threads);
|
||||
for (uint16_t i = 0; i < io_opts->nr_threads; i++)
|
||||
{
|
||||
CONFIG_LOG_DEBUG("packet_io->cpu_mask[%03d] : %d", i, io_opts->cpu_mask[i]);
|
||||
CONFIG_LOG_DEBUG("packet_io->cpu_mask[%3d] : %d", i, io_opts->cpu_mask[i]);
|
||||
}
|
||||
|
||||
// ip reassemble config
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -209,7 +210,10 @@ static inline void calc_tcp_fingerprint(struct tcp_fingerprint *finger)
|
||||
{
|
||||
#define RANGE(rand, start, end) (start + rand % (end - start + 1)) // [start, end]
|
||||
|
||||
uint64_t random = 0x013579ABCDEF ^ stellar_get_monotonic_time_msec();
|
||||
struct timespec time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||
|
||||
uint64_t random = 0x013579ABCDEF ^ time.tv_nsec;
|
||||
finger->ipid = (uint16_t)(RANGE(random, 32767, 65535));
|
||||
finger->ttl = (uint8_t)(RANGE(random, 48, 120));
|
||||
finger->win = (uint16_t)(RANGE(random, 1000, 1460));
|
||||
|
||||
Reference in New Issue
Block a user