refactor: packet module (split to parse/build/layer/tunnel/utils)

This commit is contained in:
luwenpeng
2024-06-24 17:07:05 +08:00
parent d8963af5f8
commit 71422ebb36
36 changed files with 796 additions and 724 deletions

View File

@@ -1,6 +1,12 @@
#include "packet_priv.h"
#include "packet_def.h"
#include "packet_layer.h"
#include "packet_utils.h"
int packet_get_layer_count(const struct packet *pkt)
{
return pkt->layers_used;
}
int packet_get_layer_by_idx(const struct packet *pkt, int idx, struct layer *out)
{
const struct raw_layer *raw = packet_get_raw_layer(pkt, idx);
@@ -14,3 +20,44 @@ int packet_get_layer_by_idx(const struct packet *pkt, int idx, struct layer *out
return 0;
}
}
const struct raw_layer *packet_get_raw_layer(const struct packet *pkt, int idx)
{
if (idx < 0 || idx >= pkt->layers_used)
{
return NULL;
}
return &pkt->layers[idx];
}
const struct raw_layer *packet_get_innermost_raw_layer(const struct packet *pkt, enum layer_proto proto)
{
const struct raw_layer *layer = NULL;
for (int8_t i = pkt->layers_used - 1; i >= 0; i--)
{
layer = &pkt->layers[i];
if (layer->proto == proto)
{
return layer;
}
}
return NULL;
}
const struct raw_layer *packet_get_outermost_raw_layer(const struct packet *pkt, enum layer_proto proto)
{
const struct raw_layer *layer = NULL;
for (int8_t i = 0; i < pkt->layers_used; i++)
{
layer = &pkt->layers[i];
if (layer->proto == proto)
{
return layer;
}
}
return NULL;
}