Refactored packet API to support struct layer (using union to contain different types of encapsulation headers)

This commit is contained in:
luwenpeng
2024-06-14 19:24:27 +08:00
parent 1f78881cbb
commit de4c15f43c
47 changed files with 834 additions and 701 deletions

View File

@@ -4,6 +4,7 @@
#include <assert.h>
#include "packet_priv.h"
#include "packet_utils.h"
#include "crc32_hash.h"
#include "checksum.h"
#include "ipv4_utils.h"
@@ -302,7 +303,7 @@ static inline void ip_frag_hdr_init(struct ip_frag_hdr *hdr, const struct packet
{
struct raw_layer *layer = pkt->frag_layer;
if (layer->type == LAYER_PROTO_IPV6)
if (layer->proto == LAYER_PROTO_IPV6)
{
struct ip6_frag *frag_ext = ipv6_hdr_get_frag_ext((const struct ip6_hdr *)layer->hdr_ptr);
hdr->next_proto = frag_ext->ip6f_nxt;
@@ -639,8 +640,8 @@ static struct packet *ip_frag_reassemble(struct ip_reassembly *assy, struct ip_f
return NULL;
}
char *ptr = (char *)packet_get_data(pkt);
char *end = ptr + packet_get_len(pkt);
char *ptr = (char *)packet_get_raw_data(pkt);
char *end = ptr + packet_get_raw_len(pkt);
// copy last frag
if (last->len > end - ptr)
@@ -729,7 +730,6 @@ static struct packet *ip_frag_reassemble(struct ip_reassembly *assy, struct ip_f
// create a new packet
packet_parse(pkt, ptr, packet_len);
packet_set_origin_ctx(pkt, NULL);
return pkt;
@@ -865,7 +865,7 @@ struct packet *ip_reassembly_packet(struct ip_reassembly *assy, const struct pac
return NULL;
}
if (layer->type == LAYER_PROTO_IPV4)
if (layer->proto == LAYER_PROTO_IPV4)
{
pkt1 = ipv4_reassembly_packet(assy, pkt, now);
if (pkt1 && pkt1->frag_layer)
@@ -877,7 +877,7 @@ struct packet *ip_reassembly_packet(struct ip_reassembly *assy, const struct pac
return pkt1;
}
else if (layer->type == LAYER_PROTO_IPV6)
else if (layer->proto == LAYER_PROTO_IPV6)
{
pkt1 = ipv6_reassembly_packet(assy, pkt, now);
if (pkt1 && pkt1->frag_layer)