summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2024-06-12 18:21:45 +0800
committerluwenpeng <[email protected]>2024-06-12 18:21:45 +0800
commit01958b56c5fe4b13566fb601954035bfee17c8b6 (patch)
treec5cc3deeeef0b18c0ba8ab9bc1eb8bd5da80c752 /include
parent10528bcfd3b6cce87fd4c913899ee41b39f1b943 (diff)
rename layer_type to layer_proto
Diffstat (limited to 'include')
-rw-r--r--include/stellar/packet.h65
1 files changed, 29 insertions, 36 deletions
diff --git a/include/stellar/packet.h b/include/stellar/packet.h
index 02060d0..91639e4 100644
--- a/include/stellar/packet.h
+++ b/include/stellar/packet.h
@@ -14,50 +14,43 @@ extern "C"
#include <netinet/ip.h>
#include <netinet/ip6.h>
-enum layer_type
+enum layer_proto
{
+ LAYER_PROTO_NONE = 0,
+
// L2 -- data link layer
- LAYER_TYPE_ETHER = 1 << 0,
- LAYER_TYPE_PWETH = 1 << 1,
- LAYER_TYPE_PPP = 1 << 2,
- LAYER_TYPE_HDLC = 1 << 3,
- LAYER_TYPE_L2TP = 1 << 4,
- LAYER_TYPE_L2 = (LAYER_TYPE_ETHER | LAYER_TYPE_PWETH | LAYER_TYPE_PPP | LAYER_TYPE_HDLC | LAYER_TYPE_L2TP),
+ LAYER_PROTO_ETHER = 1,
+ LAYER_PROTO_PWETH = 2,
+ LAYER_PROTO_PPP = 3,
+ LAYER_PROTO_L2TP = 4,
// L2 -- tunnel
- LAYER_TYPE_VLAN = 1 << 5,
- LAYER_TYPE_PPPOE = 1 << 6,
- LAYER_TYPE_MPLS = 1 << 7,
- LAYER_TYPE_L2_TUN = (LAYER_TYPE_VLAN | LAYER_TYPE_PPPOE | LAYER_TYPE_MPLS),
+ LAYER_PROTO_VLAN = 21,
+ LAYER_PROTO_PPPOE = 22,
+ LAYER_PROTO_MPLS = 23,
// L3 -- network layer
- LAYER_TYPE_IPV4 = 1 << 8,
- LAYER_TYPE_IPV6 = 1 << 9,
- LAYER_TYPE_IPAH = 1 << 10,
- LAYER_TYPE_L3 = (LAYER_TYPE_IPV4 | LAYER_TYPE_IPV6 | LAYER_TYPE_IPAH),
+ LAYER_PROTO_IPV4 = 31,
+ LAYER_PROTO_IPV6 = 32,
+ LAYER_PROTO_IPAH = 33,
// L3 -- tunnel
- LAYER_TYPE_GRE = 1 << 11,
- LAYER_TYPE_L3_TUN = (LAYER_TYPE_GRE),
+ LAYER_PROTO_GRE = 41,
// L4 -- transport layer
- LAYER_TYPE_UDP = 1 << 12,
- LAYER_TYPE_TCP = 1 << 13,
- LAYER_TYPE_ICMP = 1 << 14,
- LAYER_TYPE_ICMP6 = 1 << 15,
- LAYER_TYPE_L4 = (LAYER_TYPE_UDP | LAYER_TYPE_TCP | LAYER_TYPE_ICMP | LAYER_TYPE_ICMP6),
+ LAYER_PROTO_UDP = 51,
+ LAYER_PROTO_TCP = 52,
+ LAYER_PROTO_ICMP = 53,
+ LAYER_PROTO_ICMP6 = 54,
// L4 -- tunnel
- LAYER_TYPE_VXLAN = 1 << 16,
- LAYER_TYPE_GTPV1_U = 1 << 17,
-
- // ALL
- LAYER_TYPE_ALL = (LAYER_TYPE_L2 | LAYER_TYPE_L2_TUN | LAYER_TYPE_L3 | LAYER_TYPE_L3_TUN | LAYER_TYPE_L4 | LAYER_TYPE_VXLAN | LAYER_TYPE_GTPV1_U),
+ LAYER_PROTO_VXLAN = 61,
+ LAYER_PROTO_GTPV1_U = 62,
};
struct packet_layer
{
- enum layer_type type;
+ enum layer_proto type;
const char *hdr_ptr; // header pointer
const char *pld_ptr; // payload pointer
uint16_t hdr_offset; // header offset from data_ptr
@@ -140,7 +133,7 @@ static inline int packet_get_addr(const struct packet *pkt, struct address *src_
for (int8_t i = num - 1; i >= 0; i--)
{
layer = packet_get_layer(pkt, i);
- if (layer->type & LAYER_TYPE_IPV4)
+ if (layer->type == LAYER_PROTO_IPV4)
{
ip4_hdr = (const struct ip *)layer->hdr_ptr;
if (src_addr != NULL)
@@ -155,7 +148,7 @@ static inline int packet_get_addr(const struct packet *pkt, struct address *src_
}
return 0;
}
- if (layer->type & LAYER_TYPE_IPV6)
+ if (layer->type == LAYER_PROTO_IPV6)
{
ip6_hdr = (const struct ip6_hdr *)layer->hdr_ptr;
if (src_addr != NULL)
@@ -184,14 +177,14 @@ static inline int packet_get_port(const struct packet *pkt, uint16_t *src_port,
for (int8_t i = num - 1; i >= 0; i--)
{
layer = packet_get_layer(pkt, i);
- if (layer->type & LAYER_TYPE_TCP)
+ if (layer->type == LAYER_PROTO_TCP)
{
tcp_hdr = (const struct tcphdr *)layer->hdr_ptr;
src_port != NULL ? *src_port = tcp_hdr->th_sport : 0;
dst_port != NULL ? *dst_port = tcp_hdr->th_dport : 0;
return 0;
}
- if (layer->type & LAYER_TYPE_UDP)
+ if (layer->type == LAYER_PROTO_UDP)
{
udp_hdr = (const struct udphdr *)layer->hdr_ptr;
src_port != NULL ? *src_port = udp_hdr->uh_sport : 0;
@@ -210,7 +203,7 @@ static inline int packet_get_ip_hdr(const struct packet *pkt, struct ip *hdr)
for (int8_t i = num - 1; i >= 0; i--)
{
layer = packet_get_layer(pkt, i);
- if (layer->type & LAYER_TYPE_IPV4)
+ if (layer->type == LAYER_PROTO_IPV4)
{
if (hdr != NULL)
{
@@ -230,7 +223,7 @@ static inline int packet_get_ip6_hdr(const struct packet *pkt, struct ip6_hdr *h
for (int8_t i = num - 1; i >= 0; i--)
{
layer = packet_get_layer(pkt, i);
- if (layer->type & LAYER_TYPE_IPV6)
+ if (layer->type == LAYER_PROTO_IPV6)
{
if (hdr != NULL)
{
@@ -250,7 +243,7 @@ static inline int packet_get_tcp_hdr(const struct packet *pkt, struct tcphdr *hd
for (int8_t i = num - 1; i >= 0; i--)
{
layer = packet_get_layer(pkt, i);
- if (layer->type & LAYER_TYPE_TCP)
+ if (layer->type == LAYER_PROTO_TCP)
{
if (hdr != NULL)
{
@@ -270,7 +263,7 @@ static inline int packet_get_udp_hdr(const struct packet *pkt, struct udphdr *hd
for (int8_t i = num - 1; i >= 0; i--)
{
layer = packet_get_layer(pkt, i);
- if (layer->type & LAYER_TYPE_UDP)
+ if (layer->type == LAYER_PROTO_UDP)
{
if (hdr != NULL)
{