refactor: rename struct raw_layer to struct layer_private

This commit is contained in:
luwenpeng
2024-08-21 11:17:25 +08:00
parent ee612d73c9
commit 1aece166cd
20 changed files with 268 additions and 268 deletions

View File

@@ -142,7 +142,7 @@ void *packet_get_user_data(struct packet *pkt)
int packet_get_innermost_tuple2(const struct packet *pkt, struct tuple2 *tuple)
{
memset(tuple, 0, sizeof(struct tuple2));
const struct raw_layer *layer = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = pkt->layers_used - 1; i >= 0; i--)
{
@@ -174,7 +174,7 @@ int packet_get_innermost_tuple2(const struct packet *pkt, struct tuple2 *tuple)
int packet_get_outermost_tuple2(const struct packet *pkt, struct tuple2 *tuple)
{
memset(tuple, 0, sizeof(struct tuple2));
const struct raw_layer *layer = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = 0; i < pkt->layers_used; i++)
{
@@ -206,9 +206,9 @@ int packet_get_outermost_tuple2(const struct packet *pkt, struct tuple2 *tuple)
int packet_get_innermost_tuple4(const struct packet *pkt, struct tuple4 *tuple)
{
memset(tuple, 0, sizeof(struct tuple4));
const struct raw_layer *layer_l3 = NULL;
const struct raw_layer *layer_l4 = NULL;
const struct raw_layer *layer = NULL;
const struct layer_private *layer_l3 = NULL;
const struct layer_private *layer_l4 = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = pkt->layers_used - 1; i >= 0; i--)
{
@@ -268,9 +268,9 @@ int packet_get_innermost_tuple4(const struct packet *pkt, struct tuple4 *tuple)
int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple)
{
memset(tuple, 0, sizeof(struct tuple4));
const struct raw_layer *layer_l3 = NULL;
const struct raw_layer *layer_l4 = NULL;
const struct raw_layer *layer = NULL;
const struct layer_private *layer_l3 = NULL;
const struct layer_private *layer_l4 = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = 0; i < pkt->layers_used; i++)
{
@@ -330,9 +330,9 @@ int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple)
int packet_get_innermost_tuple6(const struct packet *pkt, struct tuple6 *tuple)
{
memset(tuple, 0, sizeof(struct tuple6));
const struct raw_layer *layer_l3 = NULL;
const struct raw_layer *layer_l4 = NULL;
const struct raw_layer *layer = NULL;
const struct layer_private *layer_l3 = NULL;
const struct layer_private *layer_l4 = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = pkt->layers_used - 1; i >= 0; i--)
{
@@ -395,9 +395,9 @@ int packet_get_innermost_tuple6(const struct packet *pkt, struct tuple6 *tuple)
int packet_get_outermost_tuple6(const struct packet *pkt, struct tuple6 *tuple)
{
memset(tuple, 0, sizeof(struct tuple6));
const struct raw_layer *layer_l3 = NULL;
const struct raw_layer *layer_l4 = NULL;
const struct raw_layer *layer = NULL;
const struct layer_private *layer_l3 = NULL;
const struct layer_private *layer_l4 = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = 0; i < pkt->layers_used; i++)
{
@@ -466,7 +466,7 @@ int packet_get_layer_count(const struct packet *pkt)
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);
const struct layer_private *raw = packet_get_layer(pkt, idx);
if (raw == NULL)
{
return -1;
@@ -478,7 +478,7 @@ int packet_get_layer_by_idx(const struct packet *pkt, int idx, struct layer *out
}
}
const struct raw_layer *packet_get_raw_layer(const struct packet *pkt, int idx)
const struct layer_private *packet_get_layer(const struct packet *pkt, int idx)
{
if (idx < 0 || idx >= pkt->layers_used)
{
@@ -487,9 +487,9 @@ const struct raw_layer *packet_get_raw_layer(const struct packet *pkt, int idx)
return &pkt->layers[idx];
}
const struct raw_layer *packet_get_innermost_raw_layer(const struct packet *pkt, enum layer_proto proto)
const struct layer_private *packet_get_innermost_layer(const struct packet *pkt, enum layer_proto proto)
{
const struct raw_layer *layer = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = pkt->layers_used - 1; i >= 0; i--)
{
@@ -503,9 +503,9 @@ const struct raw_layer *packet_get_innermost_raw_layer(const struct packet *pkt,
return NULL;
}
const struct raw_layer *packet_get_outermost_raw_layer(const struct packet *pkt, enum layer_proto proto)
const struct layer_private *packet_get_outermost_layer(const struct packet *pkt, enum layer_proto proto)
{
const struct raw_layer *layer = NULL;
const struct layer_private *layer = NULL;
for (int8_t i = 0; i < pkt->layers_used; i++)
{
@@ -527,10 +527,10 @@ struct tunnel_detector
{
enum tunnel_type type;
int contain_layers;
int (*identify_func)(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2);
int (*identify_func)(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2);
};
static int is_ipv4_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2 __attribute__((unused)))
static int is_ipv4_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2 __attribute__((unused)))
{
if (curr && curr->proto == LAYER_PROTO_IPV4 &&
next1 && (next1->proto == LAYER_PROTO_IPV4 || next1->proto == LAYER_PROTO_IPV6))
@@ -541,7 +541,7 @@ static int is_ipv4_tunnel(const struct raw_layer *curr, const struct raw_layer *
return 0;
}
static int is_ipv6_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2 __attribute__((unused)))
static int is_ipv6_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2 __attribute__((unused)))
{
if (curr && curr->proto == LAYER_PROTO_IPV6 &&
next1 && (next1->proto == LAYER_PROTO_IPV4 || next1->proto == LAYER_PROTO_IPV6))
@@ -552,7 +552,7 @@ static int is_ipv6_tunnel(const struct raw_layer *curr, const struct raw_layer *
return 0;
}
static int is_gre_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2 __attribute__((unused)))
static int is_gre_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2 __attribute__((unused)))
{
if (curr && (curr->proto == LAYER_PROTO_IPV4 || curr->proto == LAYER_PROTO_IPV6) &&
next1 && next1->proto == LAYER_PROTO_GRE)
@@ -563,7 +563,7 @@ static int is_gre_tunnel(const struct raw_layer *curr, const struct raw_layer *n
return 0;
}
static int is_gtp_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2)
static int is_gtp_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2)
{
if (curr && (curr->proto == LAYER_PROTO_IPV4 || curr->proto == LAYER_PROTO_IPV6) &&
next1 && next1->proto == LAYER_PROTO_UDP &&
@@ -575,7 +575,7 @@ static int is_gtp_tunnel(const struct raw_layer *curr, const struct raw_layer *n
return 0;
}
static int is_vxlan_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2)
static int is_vxlan_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2)
{
if (curr && (curr->proto == LAYER_PROTO_IPV4 || curr->proto == LAYER_PROTO_IPV6) &&
next1 && next1->proto == LAYER_PROTO_UDP &&
@@ -587,7 +587,7 @@ static int is_vxlan_tunnel(const struct raw_layer *curr, const struct raw_layer
return 0;
}
static int is_l2tp_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2)
static int is_l2tp_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2)
{
if (curr && (curr->proto == LAYER_PROTO_IPV4 || curr->proto == LAYER_PROTO_IPV6) &&
next1 && next1->proto == LAYER_PROTO_UDP &&
@@ -599,7 +599,7 @@ static int is_l2tp_tunnel(const struct raw_layer *curr, const struct raw_layer *
return 0;
}
static int is_teredo_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2)
static int is_teredo_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2)
{
if (curr && curr->proto == LAYER_PROTO_IPV4 &&
next1 && next1->proto == LAYER_PROTO_UDP &&
@@ -622,7 +622,7 @@ static struct tunnel_detector detectors[] = {
};
// return index of detectors
static int detect_tunnel(const struct raw_layer *curr, const struct raw_layer *next1, const struct raw_layer *next2)
static int detect_tunnel(const struct layer_private *curr, const struct layer_private *next1, const struct layer_private *next2)
{
for (int i = 0; i < (int)(sizeof(detectors) / sizeof(detectors[0])); i++)
{
@@ -639,15 +639,15 @@ int packet_get_tunnel_count(const struct packet *pkt)
{
int count = 0;
int used = packet_get_layer_count(pkt);
const struct raw_layer *curr = NULL;
const struct raw_layer *next1 = NULL;
const struct raw_layer *next2 = NULL;
const struct layer_private *curr = NULL;
const struct layer_private *next1 = NULL;
const struct layer_private *next2 = NULL;
for (int i = 0; i < used; i++)
{
curr = packet_get_raw_layer(pkt, i);
next1 = packet_get_raw_layer(pkt, i + 1);
next2 = packet_get_raw_layer(pkt, i + 2);
curr = packet_get_layer(pkt, i);
next1 = packet_get_layer(pkt, i + 1);
next2 = packet_get_layer(pkt, i + 2);
if (detect_tunnel(curr, next1, next2) >= 0)
{
count++;
@@ -664,16 +664,16 @@ int packet_get_tunnel_by_idx(const struct packet *pkt, int idx, struct tunnel *o
int ret = -1;
int count = 0;
int used = packet_get_layer_count(pkt);
const struct raw_layer *curr = NULL;
const struct raw_layer *next1 = NULL;
const struct raw_layer *next2 = NULL;
const struct layer_private *curr = NULL;
const struct layer_private *next1 = NULL;
const struct layer_private *next2 = NULL;
memset(out, 0, sizeof(struct tunnel));
for (int i = 0; i < used; i++)
{
curr = packet_get_raw_layer(pkt, i);
next1 = packet_get_raw_layer(pkt, i + 1);
next2 = packet_get_raw_layer(pkt, i + 2);
curr = packet_get_layer(pkt, i);
next1 = packet_get_layer(pkt, i + 1);
next2 = packet_get_layer(pkt, i + 2);
ret = detect_tunnel(curr, next1, next2);
if (ret >= 0 && count++ == idx)
{
@@ -923,7 +923,7 @@ int packet_is_fragment(const struct packet *pkt)
return (pkt->frag_layer) ? 1 : 0;
}
void layer_convert(const struct raw_layer *in, struct layer *out)
void layer_convert(const struct layer_private *in, struct layer *out)
{
if (in == NULL || out == NULL)
{