Add test case: inject IPv4 based TCP payload packet after recv C2S first payload

This commit is contained in:
luwenpeng
2024-05-21 17:39:16 +08:00
parent 3701fc7361
commit e8c61a1752
24 changed files with 580 additions and 410 deletions

View File

@@ -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;
}