rename layer_type to layer_proto
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -34,27 +34,24 @@ struct duplicated_packet_filter
|
||||
// reutrn -1: error
|
||||
static inline int duplicated_packet_key_get(const struct packet *packet, struct duplicated_packet_key *key)
|
||||
{
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(packet, LAYER_TYPE_IPV4);
|
||||
if (ipv4_layer == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
const struct packet_layer *l4_layer = packet_get_innermost_layer(packet, (enum layer_type)(LAYER_TYPE_TCP | LAYER_TYPE_UDP));
|
||||
if (l4_layer == NULL)
|
||||
const struct packet_layer *ip_layer = packet_get_innermost_layer(packet, LAYER_PROTO_IPV4);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(packet, LAYER_PROTO_TCP);
|
||||
const struct packet_layer *udp_layer = packet_get_innermost_layer(packet, LAYER_PROTO_UDP);
|
||||
if (ip_layer == NULL || (tcp_layer == NULL && udp_layer == NULL))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(key, 0, sizeof(struct duplicated_packet_key));
|
||||
|
||||
const struct ip *iphdr = (const struct ip *)ipv4_layer->hdr_ptr;
|
||||
const struct ip *iphdr = (const struct ip *)ip_layer->hdr_ptr;
|
||||
key->ip_id = ipv4_hdr_get_ipid(iphdr);
|
||||
key->src_addr = ipv4_hdr_get_src_addr(iphdr);
|
||||
key->dst_addr = ipv4_hdr_get_dst_addr(iphdr);
|
||||
|
||||
if (l4_layer->type == LAYER_TYPE_TCP)
|
||||
if (tcp_layer)
|
||||
{
|
||||
const struct tcphdr *tcphdr = (const struct tcphdr *)l4_layer->hdr_ptr;
|
||||
const struct tcphdr *tcphdr = (const struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
key->seq = tcp_hdr_get_seq(tcphdr);
|
||||
key->ack = tcp_hdr_get_ack(tcphdr);
|
||||
key->src_port = tcp_hdr_get_src_port(tcphdr);
|
||||
@@ -63,7 +60,7 @@ static inline int duplicated_packet_key_get(const struct packet *packet, struct
|
||||
}
|
||||
else
|
||||
{
|
||||
const struct udphdr *udphdr = (const struct udphdr *)l4_layer->hdr_ptr;
|
||||
const struct udphdr *udphdr = (const struct udphdr *)udp_layer->hdr_ptr;
|
||||
key->src_port = udp_hdr_get_src_port(udphdr);
|
||||
key->dst_port = udp_hdr_get_dst_port(udphdr);
|
||||
key->l4_checksum = udp_hdr_get_checksum(udphdr);
|
||||
|
||||
@@ -302,7 +302,7 @@ static inline void ip_frag_hdr_init(struct ip_frag_hdr *hdr, const struct packet
|
||||
{
|
||||
struct packet_layer *layer = pkt->frag_layer;
|
||||
|
||||
if (layer->type == LAYER_TYPE_IPV6)
|
||||
if (layer->type == 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;
|
||||
@@ -865,7 +865,7 @@ struct packet *ip_reassembly_packet(struct ip_reassembly *assy, const struct pac
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (layer->type == LAYER_TYPE_IPV4)
|
||||
if (layer->type == 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_TYPE_IPV6)
|
||||
else if (layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
pkt1 = ipv6_reassembly_packet(assy, pkt, now);
|
||||
if (pkt1 && pkt1->frag_layer)
|
||||
|
||||
@@ -243,7 +243,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
|
||||
EXPECT_TRUE(memcmp(new_pkt->data_ptr, expect, new_pkt->data_len) == 0);
|
||||
|
||||
// check IPv4
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_IPV4);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(layer);
|
||||
struct ip *hdr = (struct ip *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
|
||||
@@ -262,7 +262,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_data(hdr) == NULL);
|
||||
|
||||
// check TCP
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_TCP);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(layer);
|
||||
struct tcphdr *tcp_hdr = (struct tcphdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(tcp_hdr_get_src_port(tcp_hdr) == 62629);
|
||||
@@ -336,7 +336,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
|
||||
EXPECT_TRUE(memcmp(new_pkt->data_ptr, expect, new_pkt->data_len) == 0);
|
||||
|
||||
// check IPv4
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_IPV4);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(layer);
|
||||
struct ip *hdr = (struct ip *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
|
||||
@@ -355,7 +355,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_data(hdr) == NULL);
|
||||
|
||||
// check TCP
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_TCP);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(layer);
|
||||
struct tcphdr *tcp_hdr = (struct tcphdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(tcp_hdr_get_src_port(tcp_hdr) == 62629);
|
||||
@@ -491,7 +491,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
EXPECT_TRUE(memcmp(new_pkt->data_ptr, expect, new_pkt->data_len) == 0);
|
||||
|
||||
// check IPv4
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_IPV4);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(layer);
|
||||
struct ip *hdr = (struct ip *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
|
||||
@@ -510,7 +510,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_data(hdr) == NULL);
|
||||
|
||||
// check TCP
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_TCP);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(layer);
|
||||
struct tcphdr *tcp_hdr = (struct tcphdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(tcp_hdr_get_src_port(tcp_hdr) == 62629);
|
||||
@@ -595,7 +595,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
|
||||
EXPECT_TRUE(memcmp(new_pkt->data_ptr, expect, new_pkt->data_len) == 0);
|
||||
|
||||
// check IPv4
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_IPV4);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(layer);
|
||||
struct ip *hdr = (struct ip *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
|
||||
@@ -614,7 +614,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_data(hdr) == NULL);
|
||||
|
||||
// check TCP
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_TCP);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(layer);
|
||||
struct tcphdr *tcp_hdr = (struct tcphdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(tcp_hdr_get_src_port(tcp_hdr) == 62629);
|
||||
|
||||
@@ -676,7 +676,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
|
||||
EXPECT_TRUE(memcmp(new_pkt->data_ptr, expect, new_pkt->data_len) == 0);
|
||||
|
||||
// check IPv6
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_IPV6);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_IPV6);
|
||||
EXPECT_TRUE(layer);
|
||||
struct ip6_hdr *hdr = (struct ip6_hdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(ipv6_hdr_get_version(hdr) == 6);
|
||||
@@ -696,7 +696,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
|
||||
EXPECT_TRUE(ipv6_hdr_get_frag_ext(hdr) == NULL);
|
||||
|
||||
// check UDP
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_UDP);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_UDP);
|
||||
EXPECT_TRUE(layer);
|
||||
struct udphdr *udp_hdr = (struct udphdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(udp_hdr_get_src_port(udp_hdr) == 6363);
|
||||
@@ -847,7 +847,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
EXPECT_TRUE(memcmp(new_pkt->data_ptr, expect, new_pkt->data_len) == 0);
|
||||
|
||||
// check IPv6
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_IPV6);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_IPV6);
|
||||
EXPECT_TRUE(layer);
|
||||
struct ip6_hdr *hdr = (struct ip6_hdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(ipv6_hdr_get_version(hdr) == 6);
|
||||
@@ -867,7 +867,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
EXPECT_TRUE(ipv6_hdr_get_frag_ext(hdr) == NULL);
|
||||
|
||||
// check UDP
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_UDP);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_UDP);
|
||||
EXPECT_TRUE(layer);
|
||||
struct udphdr *udp_hdr = (struct udphdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(udp_hdr_get_src_port(udp_hdr) == 6363);
|
||||
@@ -967,7 +967,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
EXPECT_TRUE(memcmp(new_pkt->data_ptr, expect, new_pkt->data_len) == 0);
|
||||
|
||||
// check IPv6
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_IPV6);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_IPV6);
|
||||
EXPECT_TRUE(layer);
|
||||
struct ip6_hdr *hdr = (struct ip6_hdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(ipv6_hdr_get_version(hdr) == 6);
|
||||
@@ -987,7 +987,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
EXPECT_TRUE(ipv6_hdr_get_frag_ext(hdr) == NULL);
|
||||
|
||||
// check UDP
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_TYPE_UDP);
|
||||
layer = packet_get_innermost_layer(new_pkt, LAYER_PROTO_UDP);
|
||||
EXPECT_TRUE(layer);
|
||||
struct udphdr *udp_hdr = (struct udphdr *)layer->hdr_ptr;
|
||||
EXPECT_TRUE(udp_hdr_get_src_port(udp_hdr) == 6363);
|
||||
|
||||
@@ -17,7 +17,7 @@ extern "C"
|
||||
|
||||
static inline void packet_set_ipv4_src_addr(struct packet *pkt, uint32_t saddr)
|
||||
{
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_IPV4);
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(ipv4_layer);
|
||||
struct ip *hdr = (struct ip *)ipv4_layer->hdr_ptr;
|
||||
ipv4_hdr_set_src_addr(hdr, saddr);
|
||||
@@ -25,7 +25,7 @@ static inline void packet_set_ipv4_src_addr(struct packet *pkt, uint32_t saddr)
|
||||
|
||||
static inline void packet_set_ipv6_src_addr(struct packet *pkt, struct in6_addr saddr)
|
||||
{
|
||||
const struct packet_layer *ipv6_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_IPV6);
|
||||
const struct packet_layer *ipv6_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_IPV6);
|
||||
EXPECT_TRUE(ipv6_layer);
|
||||
struct ip6_hdr *hdr = (struct ip6_hdr *)ipv6_layer->hdr_ptr;
|
||||
ipv6_hdr_set_src_in6_addr(hdr, saddr);
|
||||
@@ -33,7 +33,7 @@ static inline void packet_set_ipv6_src_addr(struct packet *pkt, struct in6_addr
|
||||
|
||||
static inline void packet_set_ipv6_frag_offset(struct packet *pkt, uint16_t offset)
|
||||
{
|
||||
const struct packet_layer *ipv6_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_IPV6);
|
||||
const struct packet_layer *ipv6_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_IPV6);
|
||||
EXPECT_TRUE(ipv6_layer);
|
||||
struct ip6_hdr *hdr = (struct ip6_hdr *)ipv6_layer->hdr_ptr;
|
||||
struct ip6_frag *frag_hdr = ipv6_hdr_get_frag_ext(hdr);
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
#define PACKET_LOG_DATA_INSUFFICIENCY(pkt, layer) \
|
||||
{ \
|
||||
PACKET_LOG_WARN("pkt: %p, layer: %s, data insufficiency", \
|
||||
(pkt), layer_type_to_str(layer)); \
|
||||
(pkt), layer_proto_to_str(layer)); \
|
||||
}
|
||||
|
||||
#define PACKET_LOG_UNSUPPORT_PROTO(pkt, layer, next_proto) \
|
||||
{ \
|
||||
PACKET_LOG_WARN("pkt: %p, layer: %s, unsupport next proto %d", \
|
||||
(pkt), layer_type_to_str(layer), (next_proto)); \
|
||||
(pkt), layer_proto_to_str(layer), (next_proto)); \
|
||||
}
|
||||
|
||||
#define PACKET_LOG_UNSUPPORT_ETHPROTO(pkt, next_proto) \
|
||||
@@ -49,11 +49,11 @@
|
||||
******************************************************************************/
|
||||
|
||||
static inline const char *ldbc_method_to_str(enum ldbc_method method);
|
||||
static inline const char *layer_type_to_str(enum layer_type type);
|
||||
static inline const char *layer_proto_to_str(enum layer_proto type);
|
||||
|
||||
static inline void set_tuple2(const char *data, enum layer_type type, struct tuple2 *tuple);
|
||||
static inline void set_tuple4(const char *data, enum layer_type type, struct tuple4 *tuple);
|
||||
static inline void set_tuple6(const char *data, enum layer_type type, struct tuple6 *tuple, uint64_t domain);
|
||||
static inline void set_tuple2(const char *data, enum layer_proto type, struct tuple2 *tuple);
|
||||
static inline void set_tuple4(const char *data, enum layer_proto type, struct tuple4 *tuple);
|
||||
static inline void set_tuple6(const char *data, enum layer_proto type, struct tuple6 *tuple, uint64_t domain);
|
||||
|
||||
static inline struct packet_layer *get_free_layer(struct packet *pkt);
|
||||
|
||||
@@ -112,65 +112,63 @@ static inline const char *ldbc_method_to_str(enum ldbc_method method)
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char *layer_type_to_str(enum layer_type type)
|
||||
static inline const char *layer_proto_to_str(enum layer_proto type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case LAYER_TYPE_ETHER:
|
||||
case LAYER_PROTO_ETHER:
|
||||
return "ETH";
|
||||
case LAYER_TYPE_PWETH:
|
||||
case LAYER_PROTO_PWETH:
|
||||
return "PWETH";
|
||||
case LAYER_TYPE_PPP:
|
||||
case LAYER_PROTO_PPP:
|
||||
return "PPP";
|
||||
case LAYER_TYPE_HDLC:
|
||||
return "HDLC";
|
||||
case LAYER_TYPE_L2TP:
|
||||
case LAYER_PROTO_L2TP:
|
||||
return "L2TP";
|
||||
case LAYER_TYPE_VLAN:
|
||||
case LAYER_PROTO_VLAN:
|
||||
return "VLAN";
|
||||
case LAYER_TYPE_PPPOE:
|
||||
case LAYER_PROTO_PPPOE:
|
||||
return "PPPOE";
|
||||
case LAYER_TYPE_MPLS:
|
||||
case LAYER_PROTO_MPLS:
|
||||
return "MPLS";
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
return "IPV4";
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
return "IPV6";
|
||||
case LAYER_TYPE_IPAH:
|
||||
case LAYER_PROTO_IPAH:
|
||||
return "IPAH";
|
||||
case LAYER_TYPE_GRE:
|
||||
case LAYER_PROTO_GRE:
|
||||
return "GRE";
|
||||
case LAYER_TYPE_UDP:
|
||||
case LAYER_PROTO_UDP:
|
||||
return "UDP";
|
||||
case LAYER_TYPE_TCP:
|
||||
case LAYER_PROTO_TCP:
|
||||
return "TCP";
|
||||
case LAYER_TYPE_ICMP:
|
||||
case LAYER_PROTO_ICMP:
|
||||
return "ICMP";
|
||||
case LAYER_TYPE_ICMP6:
|
||||
case LAYER_PROTO_ICMP6:
|
||||
return "ICMP6";
|
||||
case LAYER_TYPE_VXLAN:
|
||||
case LAYER_PROTO_VXLAN:
|
||||
return "VXLAN";
|
||||
case LAYER_TYPE_GTPV1_U:
|
||||
case LAYER_PROTO_GTPV1_U:
|
||||
return "GTPV1";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
static inline void set_tuple2(const char *data, enum layer_type type, struct tuple2 *tuple)
|
||||
static inline void set_tuple2(const char *data, enum layer_proto type, struct tuple2 *tuple)
|
||||
{
|
||||
const struct ip *ipv4 = NULL;
|
||||
const struct ip6_hdr *ipv6 = NULL;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
ipv4 = (const struct ip *)data;
|
||||
tuple->ip_type = IP_TYPE_V4;
|
||||
tuple->src_addr.v4.s_addr = ipv4->ip_src.s_addr;
|
||||
tuple->dst_addr.v4.s_addr = ipv4->ip_dst.s_addr;
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
ipv6 = (const struct ip6_hdr *)data;
|
||||
tuple->ip_type = IP_TYPE_V6;
|
||||
tuple->src_addr.v6 = ipv6->ip6_src;
|
||||
@@ -181,7 +179,7 @@ static inline void set_tuple2(const char *data, enum layer_type type, struct tup
|
||||
}
|
||||
}
|
||||
|
||||
static inline void set_tuple4(const char *data, enum layer_type type, struct tuple4 *tuple)
|
||||
static inline void set_tuple4(const char *data, enum layer_proto type, struct tuple4 *tuple)
|
||||
{
|
||||
const struct ip *ipv4 = NULL;
|
||||
const struct ip6_hdr *ipv6 = NULL;
|
||||
@@ -190,23 +188,23 @@ static inline void set_tuple4(const char *data, enum layer_type type, struct tup
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LAYER_TYPE_TCP:
|
||||
case LAYER_PROTO_TCP:
|
||||
tcp = (const struct tcphdr *)data;
|
||||
tuple->src_port = tcp->th_sport;
|
||||
tuple->dst_port = tcp->th_dport;
|
||||
break;
|
||||
case LAYER_TYPE_UDP:
|
||||
case LAYER_PROTO_UDP:
|
||||
udp = (const struct udphdr *)data;
|
||||
tuple->src_port = udp->uh_sport;
|
||||
tuple->dst_port = udp->uh_dport;
|
||||
break;
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
ipv4 = (const struct ip *)data;
|
||||
tuple->ip_type = IP_TYPE_V4;
|
||||
tuple->src_addr.v4.s_addr = ipv4->ip_src.s_addr;
|
||||
tuple->dst_addr.v4.s_addr = ipv4->ip_dst.s_addr;
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
ipv6 = (const struct ip6_hdr *)data;
|
||||
tuple->ip_type = IP_TYPE_V6;
|
||||
tuple->src_addr.v6 = ipv6->ip6_src;
|
||||
@@ -217,7 +215,7 @@ static inline void set_tuple4(const char *data, enum layer_type type, struct tup
|
||||
}
|
||||
}
|
||||
|
||||
static inline void set_tuple6(const char *data, enum layer_type type, struct tuple6 *tuple, uint64_t domain)
|
||||
static inline void set_tuple6(const char *data, enum layer_proto type, struct tuple6 *tuple, uint64_t domain)
|
||||
{
|
||||
const struct ip *ipv4 = NULL;
|
||||
const struct ip6_hdr *ipv6 = NULL;
|
||||
@@ -228,25 +226,25 @@ static inline void set_tuple6(const char *data, enum layer_type type, struct tup
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LAYER_TYPE_TCP:
|
||||
case LAYER_PROTO_TCP:
|
||||
tcp = (const struct tcphdr *)data;
|
||||
tuple->ip_proto = IPPROTO_TCP;
|
||||
tuple->src_port = tcp->th_sport;
|
||||
tuple->dst_port = tcp->th_dport;
|
||||
break;
|
||||
case LAYER_TYPE_UDP:
|
||||
case LAYER_PROTO_UDP:
|
||||
udp = (const struct udphdr *)data;
|
||||
tuple->ip_proto = IPPROTO_UDP;
|
||||
tuple->src_port = udp->uh_sport;
|
||||
tuple->dst_port = udp->uh_dport;
|
||||
break;
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
ipv4 = (const struct ip *)data;
|
||||
tuple->ip_type = IP_TYPE_V4;
|
||||
tuple->src_addr.v4.s_addr = ipv4->ip_src.s_addr;
|
||||
tuple->dst_addr.v4.s_addr = ipv4->ip_dst.s_addr;
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
ipv6 = (const struct ip6_hdr *)data;
|
||||
tuple->ip_type = IP_TYPE_V6;
|
||||
tuple->src_addr.v6 = ipv6->ip6_src;
|
||||
@@ -278,7 +276,7 @@ static inline struct packet_layer *get_free_layer(struct packet *pkt)
|
||||
(_pkt)->trim_len += (_trim); \
|
||||
(_pkt)->layers_used++; \
|
||||
PACKET_LOG_DEBUG("layer[%d/%d]: %s, hdr_offset: %d, hdr_ptr: %p, hdr_len: %d, pld_ptr: %p, pld_len: %d", \
|
||||
(_pkt)->layers_used - 1, (_pkt)->layers_size, layer_type_to_str((_type)), \
|
||||
(_pkt)->layers_used - 1, (_pkt)->layers_size, layer_proto_to_str((_type)), \
|
||||
(_layer)->hdr_offset, (_layer)->hdr_ptr, (_layer)->hdr_len, (_layer)->pld_ptr, (_layer)->pld_len); \
|
||||
}
|
||||
|
||||
@@ -358,7 +356,7 @@ static inline const char *parse_ether(struct packet *pkt, const char *data, uint
|
||||
{
|
||||
if (unlikely(len < sizeof(struct ethhdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_ETHER);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_ETHER);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -368,7 +366,7 @@ static inline const char *parse_ether(struct packet *pkt, const char *data, uint
|
||||
return data;
|
||||
}
|
||||
uint16_t next_proto = eth_hdr_get_proto((const struct ethhdr *)data);
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_ETHER, sizeof(struct ethhdr), data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_ETHER, sizeof(struct ethhdr), data, len, 0);
|
||||
|
||||
return parse_l3(pkt, next_proto, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
@@ -386,7 +384,7 @@ static inline const char *parse_pweth(struct packet *pkt, const char *data, uint
|
||||
*/
|
||||
if (unlikely(len < 4))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_PWETH);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_PWETH);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -395,7 +393,7 @@ static inline const char *parse_pweth(struct packet *pkt, const char *data, uint
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_PWETH, 4, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_PWETH, 4, data, len, 0);
|
||||
|
||||
return parse_ether(pkt, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
@@ -455,7 +453,7 @@ static inline const char *parse_ppp(struct packet *pkt, const char *data, uint16
|
||||
*/
|
||||
if (unlikely(len < 4))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_PPP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_PPP);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -488,7 +486,7 @@ success:
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_PPP, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_PPP, hdr_len, data, len, 0);
|
||||
switch (next_proto)
|
||||
{
|
||||
case PPP_IP:
|
||||
@@ -496,7 +494,7 @@ success:
|
||||
case PPP_IPV6:
|
||||
return parse_ipv6(pkt, layer->pld_ptr, layer->pld_len);
|
||||
default:
|
||||
PACKET_LOG_UNSUPPORT_PROTO(pkt, LAYER_TYPE_PPP, next_proto);
|
||||
PACKET_LOG_UNSUPPORT_PROTO(pkt, LAYER_PROTO_PPP, next_proto);
|
||||
return layer->pld_ptr;
|
||||
}
|
||||
}
|
||||
@@ -506,7 +504,7 @@ static inline const char *parse_l2tpv2_over_udp(struct packet *pkt, const char *
|
||||
uint16_t hdr_len = calc_udp_l2tpv2_hdr_len(data, len);
|
||||
if (unlikely(hdr_len == 0 || hdr_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_L2TP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_L2TP);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -515,7 +513,7 @@ static inline const char *parse_l2tpv2_over_udp(struct packet *pkt, const char *
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_L2TP, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_L2TP, hdr_len, data, len, 0);
|
||||
|
||||
// control message
|
||||
if (l2tp_hdr_get_type((const struct l2tp_hdr *)data))
|
||||
@@ -534,7 +532,7 @@ static inline const char *parse_l2tpv3_over_udp(struct packet *pkt, const char *
|
||||
uint16_t hdr_len = calc_udp_l2tpv3_hdr_len(data, len);
|
||||
if (unlikely(hdr_len == 0 || hdr_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_L2TP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_L2TP);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -543,7 +541,7 @@ static inline const char *parse_l2tpv3_over_udp(struct packet *pkt, const char *
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_L2TP, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_L2TP, hdr_len, data, len, 0);
|
||||
|
||||
// control message
|
||||
if (l2tp_hdr_get_type((const struct l2tp_hdr *)data))
|
||||
@@ -563,7 +561,7 @@ static inline const char *parse_l2tpv3_over_ip(struct packet *pkt, const char *d
|
||||
uint16_t hdr_len = calc_ip_l2tpv3_hdr_len(data, len);
|
||||
if (unlikely(hdr_len == 0 || hdr_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_L2TP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_L2TP);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -572,7 +570,7 @@ static inline const char *parse_l2tpv3_over_ip(struct packet *pkt, const char *d
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_L2TP, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_L2TP, hdr_len, data, len, 0);
|
||||
|
||||
// data message
|
||||
if (ntohl(*((uint32_t *)data)))
|
||||
@@ -591,7 +589,7 @@ static inline const char *parse_vlan(struct packet *pkt, const char *data, uint1
|
||||
{
|
||||
if (unlikely(len < sizeof(struct vlan_hdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_VLAN);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_VLAN);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -601,7 +599,7 @@ static inline const char *parse_vlan(struct packet *pkt, const char *data, uint1
|
||||
return data;
|
||||
}
|
||||
uint16_t next_proto = vlan_hdr_get_ethertype((const struct vlan_hdr *)data);
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_VLAN, sizeof(struct vlan_hdr), data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_VLAN, sizeof(struct vlan_hdr), data, len, 0);
|
||||
|
||||
return parse_l3(pkt, next_proto, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
@@ -610,7 +608,7 @@ static inline const char *parse_pppoe_ses(struct packet *pkt, const char *data,
|
||||
{
|
||||
if (unlikely(len < 6))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_PPPOE);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_PPPOE);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -619,7 +617,7 @@ static inline const char *parse_pppoe_ses(struct packet *pkt, const char *data,
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_PPPOE, 6, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_PPPOE, 6, data, len, 0);
|
||||
|
||||
return parse_ppp(pkt, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
@@ -628,7 +626,7 @@ static inline const char *parse_mpls(struct packet *pkt, const char *data, uint1
|
||||
{
|
||||
if (unlikely(len < 4))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_MPLS);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_MPLS);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -640,7 +638,7 @@ static inline const char *parse_mpls(struct packet *pkt, const char *data, uint1
|
||||
|
||||
if (mpls_label_get_bos((const struct mpls_label *)data))
|
||||
{
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_MPLS, 4, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_MPLS, 4, data, len, 0);
|
||||
if (layer->pld_len == 0)
|
||||
{
|
||||
return layer->pld_ptr;
|
||||
@@ -668,7 +666,7 @@ static inline const char *parse_mpls(struct packet *pkt, const char *data, uint1
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_MPLS, 4, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_MPLS, 4, data, len, 0);
|
||||
return parse_mpls(pkt, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
}
|
||||
@@ -677,7 +675,7 @@ static inline const char *parse_ipv4(struct packet *pkt, const char *data, uint1
|
||||
{
|
||||
if (unlikely(len < sizeof(struct ip)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPV4);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPV4);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -690,14 +688,14 @@ static inline const char *parse_ipv4(struct packet *pkt, const char *data, uint1
|
||||
uint16_t hdr_len = ipv4_hdr_get_hdr_len(hdr);
|
||||
if (unlikely(hdr_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPV4);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPV4);
|
||||
return data;
|
||||
}
|
||||
|
||||
uint16_t total_len = ipv4_hdr_get_total_len(hdr);
|
||||
if (unlikely(total_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPV4);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPV4);
|
||||
return data;
|
||||
}
|
||||
if (unlikely(total_len < hdr_len))
|
||||
@@ -706,7 +704,7 @@ static inline const char *parse_ipv4(struct packet *pkt, const char *data, uint1
|
||||
return data;
|
||||
}
|
||||
uint16_t trim_len = len - total_len;
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_IPV4, hdr_len, data, len, trim_len);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_IPV4, hdr_len, data, len, trim_len);
|
||||
|
||||
// ip fragmented
|
||||
if (ipv4_hdr_get_mf_flag(hdr) || ipv4_hdr_get_frag_offset(hdr))
|
||||
@@ -743,7 +741,7 @@ static inline const char *parse_ipv6(struct packet *pkt, const char *data, uint1
|
||||
|
||||
if (unlikely(len < sizeof(struct ip6_hdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPV6);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPV6);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -756,7 +754,7 @@ static inline const char *parse_ipv6(struct packet *pkt, const char *data, uint1
|
||||
uint16_t pld_len = ipv6_hdr_get_payload_len(hdr);
|
||||
if (unlikely(pld_len + sizeof(struct ip6_hdr) > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPV6);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPV6);
|
||||
return data;
|
||||
}
|
||||
uint8_t next_proto = ipv6_hdr_get_next_header(hdr);
|
||||
@@ -767,7 +765,7 @@ static inline const char *parse_ipv6(struct packet *pkt, const char *data, uint1
|
||||
{
|
||||
if (unlikely(pld_len < 2))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPV6);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPV6);
|
||||
return data;
|
||||
}
|
||||
struct ip6_ext *ext = (struct ip6_ext *)next_hdr_ptr;
|
||||
@@ -788,7 +786,7 @@ static inline const char *parse_ipv6(struct packet *pkt, const char *data, uint1
|
||||
}
|
||||
if (unlikely(skip_len > pld_len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPV6);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPV6);
|
||||
return data;
|
||||
}
|
||||
hdr_len += skip_len;
|
||||
@@ -796,7 +794,7 @@ static inline const char *parse_ipv6(struct packet *pkt, const char *data, uint1
|
||||
next_hdr_ptr += skip_len;
|
||||
next_proto = ext->ip6e_nxt;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_IPV6, hdr_len, data, len, trim_len);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_IPV6, hdr_len, data, len, trim_len);
|
||||
|
||||
// ipv6 fragment
|
||||
if (next_proto == IPPROTO_FRAGMENT)
|
||||
@@ -835,7 +833,7 @@ static inline const char *parse_auth(struct packet *pkt, const char *data, uint1
|
||||
|
||||
if (unlikely(len < 12))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPAH);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPAH);
|
||||
return data;
|
||||
}
|
||||
/*
|
||||
@@ -848,7 +846,7 @@ static inline const char *parse_auth(struct packet *pkt, const char *data, uint1
|
||||
uint16_t hdr_len = ((const uint8_t *)data)[1] * 4 + 8;
|
||||
if (unlikely(len < hdr_len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_IPAH);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_IPAH);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -857,7 +855,7 @@ static inline const char *parse_auth(struct packet *pkt, const char *data, uint1
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_IPAH, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_IPAH, hdr_len, data, len, 0);
|
||||
|
||||
return parse_l4(pkt, next_proto, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
@@ -867,7 +865,7 @@ static inline const char *parse_gre(struct packet *pkt, const char *data, uint16
|
||||
uint16_t hdr_len = calc_gre_hdr_len(data, len);
|
||||
if (unlikely(hdr_len == 0 || hdr_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_GRE);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_GRE);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -877,7 +875,7 @@ static inline const char *parse_gre(struct packet *pkt, const char *data, uint16
|
||||
return data;
|
||||
}
|
||||
uint16_t next_proto = gre_hdr_get_proto((const struct gre_hdr *)data);
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_GRE, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_GRE, hdr_len, data, len, 0);
|
||||
|
||||
return parse_l3(pkt, next_proto, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
@@ -886,7 +884,7 @@ static inline const char *parse_udp(struct packet *pkt, const char *data, uint16
|
||||
{
|
||||
if (unlikely(len < sizeof(struct udphdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_UDP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_UDP);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -896,7 +894,7 @@ static inline const char *parse_udp(struct packet *pkt, const char *data, uint16
|
||||
return data;
|
||||
}
|
||||
const struct udphdr *hdr = (struct udphdr *)data;
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_UDP, sizeof(struct udphdr), data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_UDP, sizeof(struct udphdr), data, len, 0);
|
||||
|
||||
uint16_t src_port = udp_hdr_get_src_port(hdr);
|
||||
uint16_t dst_port = udp_hdr_get_dst_port(hdr);
|
||||
@@ -963,7 +961,7 @@ static inline const char *parse_tcp(struct packet *pkt, const char *data, uint16
|
||||
{
|
||||
if (unlikely(len < sizeof(struct tcphdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_TCP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_TCP);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -975,10 +973,10 @@ static inline const char *parse_tcp(struct packet *pkt, const char *data, uint16
|
||||
uint16_t hdr_len = tcp_hdr_get_hdr_len((const struct tcphdr *)data);
|
||||
if (unlikely(hdr_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_TCP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_TCP);
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_TCP, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_TCP, hdr_len, data, len, 0);
|
||||
|
||||
return layer->pld_ptr;
|
||||
}
|
||||
@@ -987,7 +985,7 @@ static inline const char *parse_icmp(struct packet *pkt, const char *data, uint1
|
||||
{
|
||||
if (unlikely(len < sizeof(struct icmphdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_ICMP);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_ICMP);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -996,7 +994,7 @@ static inline const char *parse_icmp(struct packet *pkt, const char *data, uint1
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_ICMP, sizeof(struct icmphdr), data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_ICMP, sizeof(struct icmphdr), data, len, 0);
|
||||
|
||||
return layer->pld_ptr;
|
||||
}
|
||||
@@ -1005,7 +1003,7 @@ static inline const char *parse_icmp6(struct packet *pkt, const char *data, uint
|
||||
{
|
||||
if (unlikely(len < sizeof(struct icmp6_hdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_ICMP6);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_ICMP6);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1014,7 +1012,7 @@ static inline const char *parse_icmp6(struct packet *pkt, const char *data, uint
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_ICMP6, sizeof(struct icmp6_hdr), data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_ICMP6, sizeof(struct icmp6_hdr), data, len, 0);
|
||||
|
||||
return layer->pld_ptr;
|
||||
}
|
||||
@@ -1023,7 +1021,7 @@ static inline const char *parse_vxlan(struct packet *pkt, const char *data, uint
|
||||
{
|
||||
if (unlikely(len < sizeof(struct vxlan_hdr)))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_VXLAN);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_VXLAN);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1032,7 +1030,7 @@ static inline const char *parse_vxlan(struct packet *pkt, const char *data, uint
|
||||
{
|
||||
return data;
|
||||
}
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_VXLAN, sizeof(struct vxlan_hdr), data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_VXLAN, sizeof(struct vxlan_hdr), data, len, 0);
|
||||
|
||||
return parse_ether(pkt, layer->pld_ptr, layer->pld_len);
|
||||
}
|
||||
@@ -1042,7 +1040,7 @@ static inline const char *parse_gtpv1_u(struct packet *pkt, const char *data, ui
|
||||
uint16_t hdr_len = get_gtp_hdr_len(data, len);
|
||||
if (unlikely(hdr_len == 0 || hdr_len > len))
|
||||
{
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_TYPE_GTPV1_U);
|
||||
PACKET_LOG_DATA_INSUFFICIENCY(pkt, LAYER_PROTO_GTPV1_U);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1052,7 +1050,7 @@ static inline const char *parse_gtpv1_u(struct packet *pkt, const char *data, ui
|
||||
return data;
|
||||
}
|
||||
uint8_t next_proto = (((const uint8_t *)(data + hdr_len))[0]) >> 4;
|
||||
SET_LAYER(pkt, layer, LAYER_TYPE_GTPV1_U, hdr_len, data, len, 0);
|
||||
SET_LAYER(pkt, layer, LAYER_PROTO_GTPV1_U, hdr_len, data, len, 0);
|
||||
|
||||
switch (next_proto)
|
||||
{
|
||||
@@ -1061,7 +1059,7 @@ static inline const char *parse_gtpv1_u(struct packet *pkt, const char *data, ui
|
||||
case 6:
|
||||
return parse_ipv6(pkt, layer->pld_ptr, layer->pld_len);
|
||||
default:
|
||||
PACKET_LOG_UNSUPPORT_PROTO(pkt, LAYER_TYPE_GTPV1_U, next_proto);
|
||||
PACKET_LOG_UNSUPPORT_PROTO(pkt, LAYER_PROTO_GTPV1_U, next_proto);
|
||||
return layer->pld_ptr;
|
||||
}
|
||||
}
|
||||
@@ -1151,56 +1149,54 @@ void packet_print_str(const struct packet *pkt)
|
||||
int used = 0;
|
||||
const struct packet_layer *layer = &pkt->layers[i];
|
||||
printf(" layer[%u]: %p, type: %s, hdr_offset: %u, hdr_ptr: %p, hdr_len: %u, pld_ptr: %p, pld_len: %u\n",
|
||||
i, layer, layer_type_to_str(layer->type), layer->hdr_offset,
|
||||
i, layer, layer_proto_to_str(layer->type), layer->hdr_offset,
|
||||
layer->hdr_ptr, layer->hdr_len, layer->pld_ptr, layer->pld_len);
|
||||
switch (layer->type)
|
||||
{
|
||||
case LAYER_TYPE_ETHER:
|
||||
case LAYER_PROTO_ETHER:
|
||||
used = eth_hdr_to_str((const struct ethhdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_PWETH:
|
||||
case LAYER_PROTO_PWETH:
|
||||
break;
|
||||
case LAYER_TYPE_PPP:
|
||||
case LAYER_PROTO_PPP:
|
||||
break;
|
||||
case LAYER_TYPE_HDLC:
|
||||
break;
|
||||
case LAYER_TYPE_L2TP:
|
||||
case LAYER_PROTO_L2TP:
|
||||
used = l2tp_hdr_to_str((const struct l2tp_hdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_VLAN:
|
||||
case LAYER_PROTO_VLAN:
|
||||
used = vlan_hdr_to_str((const struct vlan_hdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_PPPOE:
|
||||
case LAYER_PROTO_PPPOE:
|
||||
break;
|
||||
case LAYER_TYPE_MPLS:
|
||||
case LAYER_PROTO_MPLS:
|
||||
used = mpls_label_to_str((const struct mpls_label *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
break;
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
used = ipv4_hdr_to_str((const struct ip *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
used = ipv6_hdr_to_str((const struct ip6_hdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_IPAH:
|
||||
case LAYER_PROTO_IPAH:
|
||||
break;
|
||||
case LAYER_TYPE_GRE:
|
||||
case LAYER_PROTO_GRE:
|
||||
used = gre_hdr_to_str((const struct gre_hdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_UDP:
|
||||
case LAYER_PROTO_UDP:
|
||||
used = udp_hdr_to_str((const struct udphdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_TCP:
|
||||
case LAYER_PROTO_TCP:
|
||||
used = tcp_hdr_to_str((const struct tcphdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_ICMP:
|
||||
case LAYER_PROTO_ICMP:
|
||||
break;
|
||||
case LAYER_TYPE_ICMP6:
|
||||
case LAYER_PROTO_ICMP6:
|
||||
break;
|
||||
case LAYER_TYPE_VXLAN:
|
||||
case LAYER_PROTO_VXLAN:
|
||||
used = vxlan_hdr_to_str((const struct vxlan_hdr *)layer->hdr_ptr, buffer, sizeof(buffer));
|
||||
break;
|
||||
case LAYER_TYPE_GTPV1_U:
|
||||
case LAYER_PROTO_GTPV1_U:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1223,7 +1219,7 @@ int packet_get_innermost_tuple2(const struct packet *pkt, struct tuple2 *tuple)
|
||||
{
|
||||
layer = &pkt->layers[i];
|
||||
|
||||
if (layer->type & LAYER_TYPE_L3)
|
||||
if (layer->type == LAYER_PROTO_IPV4 || layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
set_tuple2((const char *)pkt->data_ptr + layer->hdr_offset, layer->type, tuple);
|
||||
return 0;
|
||||
@@ -1244,7 +1240,7 @@ int packet_get_outermost_tuple2(const struct packet *pkt, struct tuple2 *tuple)
|
||||
{
|
||||
layer = &pkt->layers[i];
|
||||
|
||||
if (layer->type & LAYER_TYPE_L3)
|
||||
if (layer->type == LAYER_PROTO_IPV4 || layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
set_tuple2((const char *)pkt->data_ptr + layer->hdr_offset, layer->type, tuple);
|
||||
return 0;
|
||||
@@ -1268,14 +1264,14 @@ int packet_get_innermost_tuple4(const struct packet *pkt, struct tuple4 *tuple)
|
||||
layer = &pkt->layers[i];
|
||||
|
||||
// first get L4 layer
|
||||
if (layer->type & (LAYER_TYPE_UDP | LAYER_TYPE_TCP))
|
||||
if (layer->type == LAYER_PROTO_UDP || layer->type == LAYER_PROTO_TCP)
|
||||
{
|
||||
layer_l4 = layer;
|
||||
continue;
|
||||
}
|
||||
|
||||
// second get L3 layer
|
||||
if (layer->type & LAYER_TYPE_L3)
|
||||
if (layer->type == LAYER_PROTO_IPV4 || layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
layer_l3 = layer;
|
||||
break;
|
||||
@@ -1308,14 +1304,14 @@ int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple)
|
||||
layer = &pkt->layers[i];
|
||||
|
||||
// first get L3 layer
|
||||
if (layer->type & LAYER_TYPE_L3)
|
||||
if (layer->type == LAYER_PROTO_IPV4 || layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
layer_l3 = layer;
|
||||
continue;
|
||||
}
|
||||
|
||||
// second get L4 layer
|
||||
if (layer->type & (LAYER_TYPE_UDP | LAYER_TYPE_TCP))
|
||||
if (layer->type == LAYER_PROTO_UDP || layer->type == LAYER_PROTO_TCP)
|
||||
{
|
||||
layer_l4 = layer;
|
||||
break;
|
||||
@@ -1349,14 +1345,14 @@ int packet_get_innermost_tuple6(const struct packet *pkt, struct tuple6 *tuple)
|
||||
layer = &pkt->layers[i];
|
||||
|
||||
// first get L4 layer
|
||||
if (layer->type & (LAYER_TYPE_UDP | LAYER_TYPE_TCP))
|
||||
if (layer->type == LAYER_PROTO_UDP || layer->type == LAYER_PROTO_TCP)
|
||||
{
|
||||
layer_l4 = layer;
|
||||
continue;
|
||||
}
|
||||
|
||||
// second get L3 layer
|
||||
if (layer->type & LAYER_TYPE_L3)
|
||||
if (layer->type == LAYER_PROTO_IPV4 || layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
layer_l3 = layer;
|
||||
break;
|
||||
@@ -1390,14 +1386,14 @@ int packet_get_outermost_tuple6(const struct packet *pkt, struct tuple6 *tuple)
|
||||
layer = &pkt->layers[i];
|
||||
|
||||
// first get L3 layer
|
||||
if (layer->type & LAYER_TYPE_L3)
|
||||
if (layer->type == LAYER_PROTO_IPV4 || layer->type == LAYER_PROTO_IPV6)
|
||||
{
|
||||
layer_l3 = layer;
|
||||
continue;
|
||||
}
|
||||
|
||||
// second get L4 layer
|
||||
if (layer->type & (LAYER_TYPE_UDP | LAYER_TYPE_TCP))
|
||||
if (layer->type == LAYER_PROTO_UDP || layer->type == LAYER_PROTO_TCP)
|
||||
{
|
||||
layer_l4 = layer;
|
||||
break;
|
||||
@@ -1416,14 +1412,14 @@ int packet_get_outermost_tuple6(const struct packet *pkt, struct tuple6 *tuple)
|
||||
}
|
||||
}
|
||||
|
||||
const struct packet_layer *packet_get_innermost_layer(const struct packet *pkt, enum layer_type type)
|
||||
const struct packet_layer *packet_get_innermost_layer(const struct packet *pkt, enum layer_proto type)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
|
||||
for (int8_t i = pkt->layers_used - 1; i >= 0; i--)
|
||||
{
|
||||
layer = &pkt->layers[i];
|
||||
if (layer->type & type)
|
||||
if (layer->type == type)
|
||||
{
|
||||
return layer;
|
||||
}
|
||||
@@ -1432,14 +1428,14 @@ const struct packet_layer *packet_get_innermost_layer(const struct packet *pkt,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct packet_layer *packet_get_outermost_layer(const struct packet *pkt, enum layer_type type)
|
||||
const struct packet_layer *packet_get_outermost_layer(const struct packet *pkt, enum layer_proto type)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
|
||||
for (int8_t i = 0; i < pkt->layers_used; i++)
|
||||
{
|
||||
layer = &pkt->layers[i];
|
||||
if (layer->type & type)
|
||||
if (layer->type == type)
|
||||
{
|
||||
return layer;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple);
|
||||
int packet_get_innermost_tuple6(const struct packet *pkt, struct tuple6 *tuple);
|
||||
int packet_get_outermost_tuple6(const struct packet *pkt, struct tuple6 *tuple);
|
||||
|
||||
const struct packet_layer *packet_get_innermost_layer(const struct packet *pkt, enum layer_type type);
|
||||
const struct packet_layer *packet_get_outermost_layer(const struct packet *pkt, enum layer_type type);
|
||||
const struct packet_layer *packet_get_innermost_layer(const struct packet *pkt, enum layer_proto type);
|
||||
const struct packet_layer *packet_get_outermost_layer(const struct packet *pkt, enum layer_proto type);
|
||||
|
||||
/******************************************************************************
|
||||
* Utils
|
||||
@@ -115,7 +115,6 @@ void packet_set_session_id(struct packet *pkt, uint64_t sess_id);
|
||||
void packet_set_direction(struct packet *pkt, enum packet_direction dir);
|
||||
|
||||
int packet_is_fragment(const struct packet *pkt);
|
||||
int packet_get_fingerprint(const struct packet *pkt, char *buff, int size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -405,65 +405,3 @@ 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;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -201,12 +201,8 @@ const char *session_get0_current_payload(const struct session *sess, size_t *pay
|
||||
const struct packet *pkt = session_get0_current_packet(sess);
|
||||
if (pkt)
|
||||
{
|
||||
const struct packet_layer *pkt_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_ALL);
|
||||
if (pkt_layer)
|
||||
{
|
||||
*payload_len = pkt_layer->pld_len;
|
||||
return pkt_layer->pld_ptr;
|
||||
}
|
||||
*payload_len = packet_get_payload_len(pkt);
|
||||
return packet_get_payload(pkt);
|
||||
}
|
||||
*payload_len = 0;
|
||||
return NULL;
|
||||
|
||||
@@ -650,7 +650,7 @@ static struct session *session_manager_lookup_tcp_session(struct session_manager
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_TCP);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_TCP);
|
||||
const struct tcphdr *hdr = (const struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
uint8_t flags = tcp_hdr_get_flags(hdr);
|
||||
if ((flags & TH_SYN) == 0)
|
||||
@@ -676,7 +676,7 @@ static struct session *session_manager_lookup_tcp_session(struct session_manager
|
||||
|
||||
static struct session *session_manager_new_tcp_session(struct session_manager *mgr, const struct packet *pkt, const struct tuple6 *key, uint64_t now)
|
||||
{
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_TCP);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_TCP);
|
||||
const struct tcphdr *hdr = (const struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
uint8_t flags = tcp_hdr_get_flags(hdr);
|
||||
if (!(flags & TH_SYN))
|
||||
@@ -767,7 +767,7 @@ static struct session *session_manager_new_udp_session(struct session_manager *m
|
||||
|
||||
static int session_manager_update_tcp_session(struct session_manager *mgr, struct session *sess, const struct packet *pkt, const struct tuple6 *key, uint64_t now)
|
||||
{
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_TCP);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_TCP);
|
||||
const struct tcphdr *hdr = (const struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
enum flow_direction dir = identify_direction_by_history(sess, key);
|
||||
uint8_t flags = tcp_hdr_get_flags(hdr);
|
||||
|
||||
@@ -47,7 +47,7 @@ struct session_manager_options opts = {
|
||||
|
||||
static void packet_set_ip_id(struct packet *pkt, uint16_t ip_id)
|
||||
{
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_IPV4);
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(ipv4_layer);
|
||||
struct ip *hdr = (struct ip *)ipv4_layer->hdr_ptr;
|
||||
ipv4_hdr_set_ipid(hdr, ip_id);
|
||||
|
||||
@@ -49,7 +49,7 @@ struct session_manager_options opts = {
|
||||
|
||||
static void packet_set_ip_src_addr(struct packet *pkt, uint32_t addr)
|
||||
{
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_IPV4);
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(ipv4_layer);
|
||||
struct ip *hdr = (struct ip *)ipv4_layer->hdr_ptr;
|
||||
ipv4_hdr_set_src_addr(hdr, addr);
|
||||
|
||||
@@ -49,7 +49,7 @@ struct session_manager_options opts = {
|
||||
|
||||
static void packet_set_ip_src_addr(struct packet *pkt, uint32_t addr)
|
||||
{
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_IPV4);
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(ipv4_layer);
|
||||
struct ip *hdr = (struct ip *)ipv4_layer->hdr_ptr;
|
||||
ipv4_hdr_set_src_addr(hdr, addr);
|
||||
|
||||
@@ -190,7 +190,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_RST)
|
||||
char tcp_pkt_c2s_rst[1500] = {0};
|
||||
memcpy(tcp_pkt_c2s_rst, tcp_pkt9_c2s_fin, sizeof(tcp_pkt9_c2s_fin));
|
||||
packet_parse(&pkt, (const char *)tcp_pkt_c2s_rst, sizeof(tcp_pkt9_c2s_fin));
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_TYPE_TCP);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(tcp_layer);
|
||||
struct tcphdr *hdr = (struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
tcp_hdr_set_flags(hdr, 0);
|
||||
@@ -277,7 +277,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_RST)
|
||||
char tcp_pkt_s2c_rst[1500] = {0};
|
||||
memcpy(tcp_pkt_s2c_rst, tcp_pkt10_s2c_fin, sizeof(tcp_pkt10_s2c_fin));
|
||||
packet_parse(&pkt, (const char *)tcp_pkt_s2c_rst, sizeof(tcp_pkt10_s2c_fin));
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_TYPE_TCP);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(tcp_layer);
|
||||
struct tcphdr *hdr = (struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
tcp_hdr_set_flags(hdr, 0);
|
||||
|
||||
@@ -427,7 +427,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_RETRANSMISSION)
|
||||
char syn_retransmission[1500] = {0};
|
||||
memcpy(syn_retransmission, tcp_pkt1_c2s_syn, sizeof(tcp_pkt1_c2s_syn));
|
||||
packet_parse(&pkt, (const char *)syn_retransmission, sizeof(tcp_pkt1_c2s_syn));
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(&pkt, LAYER_TYPE_IPV4);
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(&pkt, LAYER_PROTO_IPV4);
|
||||
struct ip *hdr = (struct ip *)ipv4_layer->hdr_ptr;
|
||||
ipv4_hdr_set_ipid(hdr, 0x1234);
|
||||
printf("<= Packet Parse: done\n\n");
|
||||
@@ -523,7 +523,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK_RETRANSMISSION)
|
||||
char tcp_pkt_s2c_synack_retransmission[1500] = {0};
|
||||
memcpy(tcp_pkt_s2c_synack_retransmission, tcp_pkt2_s2c_syn_ack, sizeof(tcp_pkt2_s2c_syn_ack));
|
||||
packet_parse(&pkt, (const char *)tcp_pkt_s2c_synack_retransmission, sizeof(tcp_pkt2_s2c_syn_ack));
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(&pkt, LAYER_TYPE_IPV4);
|
||||
const struct packet_layer *ipv4_layer = packet_get_innermost_layer(&pkt, LAYER_PROTO_IPV4);
|
||||
EXPECT_TRUE(ipv4_layer);
|
||||
struct ip *hdr = (struct ip *)ipv4_layer->hdr_ptr;
|
||||
ipv4_hdr_set_ipid(hdr, 0x1234);
|
||||
|
||||
@@ -179,7 +179,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_RST)
|
||||
char tcp_pkt_c2s_rst[1500] = {0};
|
||||
memcpy(tcp_pkt_c2s_rst, tcp_pkt9_c2s_fin, sizeof(tcp_pkt9_c2s_fin));
|
||||
packet_parse(&pkt, (const char *)tcp_pkt_c2s_rst, sizeof(tcp_pkt9_c2s_fin));
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_TYPE_TCP);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(tcp_layer);
|
||||
struct tcphdr *hdr = (struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
tcp_hdr_set_flags(hdr, 0);
|
||||
@@ -274,7 +274,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_RST)
|
||||
char tcp_pkt_s2c_rst[1500] = {0};
|
||||
memcpy(tcp_pkt_s2c_rst, tcp_pkt10_s2c_fin, sizeof(tcp_pkt10_s2c_fin));
|
||||
packet_parse(&pkt, (const char *)tcp_pkt_s2c_rst, sizeof(tcp_pkt10_s2c_fin));
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_TYPE_TCP);
|
||||
const struct packet_layer *tcp_layer = packet_get_innermost_layer(&pkt, LAYER_PROTO_TCP);
|
||||
EXPECT_TRUE(tcp_layer);
|
||||
struct tcphdr *hdr = (struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
tcp_hdr_set_flags(hdr, 0);
|
||||
|
||||
@@ -254,7 +254,7 @@ static int build_tcp_packet(const struct packet *first, uint16_t ip_id, uint8_t
|
||||
curr = (struct packet_layer *)packet_get_layer(first, i);
|
||||
switch (curr->type)
|
||||
{
|
||||
case LAYER_TYPE_TCP:
|
||||
case LAYER_PROTO_TCP:
|
||||
trim = curr->hdr_len + curr->pld_len - sizeof(struct tcphdr) - pld_len;
|
||||
if (len - trim > buff_size)
|
||||
{
|
||||
@@ -267,41 +267,41 @@ static int build_tcp_packet(const struct packet *first, uint16_t ip_id, uint8_t
|
||||
memcpy(pkt_buff + curr->hdr_offset + sizeof(struct tcphdr), tcp_pld, pld_len);
|
||||
}
|
||||
break;
|
||||
case LAYER_TYPE_UDP:
|
||||
case LAYER_PROTO_UDP:
|
||||
udphdr = (struct udphdr *)(pkt_buff + curr->hdr_offset);
|
||||
update_udp_hdr(udphdr, trim);
|
||||
break;
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
iphdr = (struct ip *)(pkt_buff + curr->hdr_offset);
|
||||
last = (struct packet_layer *)packet_get_layer(first, i + 1);
|
||||
if (last->type == LAYER_TYPE_TCP)
|
||||
if (last->type == LAYER_PROTO_TCP)
|
||||
{
|
||||
tcphdr = (struct tcphdr *)(pkt_buff + last->hdr_offset);
|
||||
tcphdr->th_sum = checksum_v4(tcphdr, len - trim - last->hdr_offset, IPPROTO_TCP, &iphdr->ip_src, &iphdr->ip_dst);
|
||||
}
|
||||
if (last->type == LAYER_TYPE_UDP)
|
||||
if (last->type == LAYER_PROTO_UDP)
|
||||
{
|
||||
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
|
||||
udphdr->uh_sum = checksum_v4(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &iphdr->ip_src, &iphdr->ip_dst);
|
||||
}
|
||||
update_ip4_hdr(iphdr, ip_id, ip_ttl, trim);
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
ip6hdr = (struct ip6_hdr *)(pkt_buff + curr->hdr_offset);
|
||||
last = (struct packet_layer *)packet_get_layer(first, i + 1);
|
||||
if (last->type == LAYER_TYPE_TCP)
|
||||
if (last->type == LAYER_PROTO_TCP)
|
||||
{
|
||||
tcphdr = (struct tcphdr *)(pkt_buff + last->hdr_offset);
|
||||
tcphdr->th_sum = checksum_v6(tcphdr, len - trim - last->hdr_offset, IPPROTO_TCP, &ip6hdr->ip6_src, &ip6hdr->ip6_dst);
|
||||
}
|
||||
if (last->type == LAYER_TYPE_UDP)
|
||||
if (last->type == LAYER_PROTO_UDP)
|
||||
{
|
||||
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
|
||||
udphdr->uh_sum = checksum_v6(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &ip6hdr->ip6_src, &ip6hdr->ip6_dst);
|
||||
}
|
||||
update_ip6_hdr(ip6hdr, trim);
|
||||
break;
|
||||
case LAYER_TYPE_GRE:
|
||||
case LAYER_PROTO_GRE:
|
||||
return -EPROTONOSUPPORT;
|
||||
// TODO
|
||||
break;
|
||||
@@ -341,7 +341,7 @@ static int build_udp_packet(const struct packet *first, const char *udp_pld, int
|
||||
curr = (struct packet_layer *)packet_get_layer(first, i);
|
||||
switch (curr->type)
|
||||
{
|
||||
case LAYER_TYPE_UDP:
|
||||
case LAYER_PROTO_UDP:
|
||||
trim = curr->hdr_len + curr->pld_len - sizeof(struct udphdr) - pld_len;
|
||||
if (len - trim > buff_size)
|
||||
{
|
||||
@@ -354,27 +354,27 @@ static int build_udp_packet(const struct packet *first, const char *udp_pld, int
|
||||
memcpy(pkt_buff + curr->hdr_offset + sizeof(struct udphdr), udp_pld, pld_len);
|
||||
}
|
||||
break;
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
iphdr = (struct ip *)(pkt_buff + curr->hdr_offset);
|
||||
last = (struct packet_layer *)packet_get_layer(first, i + 1);
|
||||
if (last->type == LAYER_TYPE_UDP)
|
||||
if (last->type == LAYER_PROTO_UDP)
|
||||
{
|
||||
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
|
||||
udphdr->uh_sum = checksum_v4(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &iphdr->ip_src, &iphdr->ip_dst);
|
||||
}
|
||||
update_ip4_hdr(iphdr, 0, 0, trim);
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
ip6hdr = (struct ip6_hdr *)(pkt_buff + curr->hdr_offset);
|
||||
last = (struct packet_layer *)packet_get_layer(first, i + 1);
|
||||
if (last->type == LAYER_TYPE_UDP)
|
||||
if (last->type == LAYER_PROTO_UDP)
|
||||
{
|
||||
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
|
||||
udphdr->uh_sum = checksum_v6(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &ip6hdr->ip6_src, &ip6hdr->ip6_dst);
|
||||
}
|
||||
update_ip6_hdr(ip6hdr, trim);
|
||||
break;
|
||||
case LAYER_TYPE_GRE:
|
||||
case LAYER_PROTO_GRE:
|
||||
return -EPROTONOSUPPORT;
|
||||
// TODO
|
||||
break;
|
||||
|
||||
@@ -97,7 +97,7 @@ static void packet_to_tshark_format(const struct packet *pkt, uint64_t idx)
|
||||
const struct packet_layer *layer = packet_get_layer(pkt, i);
|
||||
switch (layer->type)
|
||||
{
|
||||
case LAYER_TYPE_ETHER:
|
||||
case LAYER_PROTO_ETHER:
|
||||
buffer_push(&buff_proto, "eth:ethertype");
|
||||
eth_hdr = (const struct ethhdr *)layer->hdr_ptr;
|
||||
eth_hdr_get_source(eth_hdr, tmp_src_buff, sizeof(tmp_src_buff));
|
||||
@@ -105,32 +105,29 @@ static void packet_to_tshark_format(const struct packet *pkt, uint64_t idx)
|
||||
buffer_push(&buff_eth_src, tmp_src_buff);
|
||||
buffer_push(&buff_eth_dst, tmp_dst_buff);
|
||||
break;
|
||||
case LAYER_TYPE_PWETH:
|
||||
case LAYER_PROTO_PWETH:
|
||||
buffer_push(&buff_proto, "pwethheuristic:pwethcw");
|
||||
break;
|
||||
case LAYER_TYPE_PPP:
|
||||
case LAYER_PROTO_PPP:
|
||||
buffer_push(&buff_proto, "ppp");
|
||||
break;
|
||||
case LAYER_TYPE_HDLC:
|
||||
buffer_push(&buff_proto, "hdlc");
|
||||
break;
|
||||
case LAYER_TYPE_L2TP:
|
||||
case LAYER_PROTO_L2TP:
|
||||
buffer_push(&buff_proto, "l2tp");
|
||||
break;
|
||||
case LAYER_TYPE_VLAN:
|
||||
case LAYER_PROTO_VLAN:
|
||||
buffer_push(&buff_proto, "vlan:ethertype");
|
||||
vlan_hdr = (const struct vlan_hdr *)layer->hdr_ptr;
|
||||
vlan_id = vlan_hdr_get_vid(vlan_hdr);
|
||||
snprintf(tmp_src_buff, sizeof(tmp_src_buff), "%u", vlan_id);
|
||||
buffer_push(&buff_vlan_id, tmp_src_buff);
|
||||
break;
|
||||
case LAYER_TYPE_PPPOE:
|
||||
case LAYER_PROTO_PPPOE:
|
||||
buffer_push(&buff_proto, "pppoes");
|
||||
break;
|
||||
case LAYER_TYPE_MPLS:
|
||||
case LAYER_PROTO_MPLS:
|
||||
buffer_push(&buff_proto, "mpls");
|
||||
break;
|
||||
case LAYER_TYPE_IPV4:
|
||||
case LAYER_PROTO_IPV4:
|
||||
buffer_push(&buff_proto, "ip");
|
||||
ipv4_hdr = (const struct ip *)layer->hdr_ptr;
|
||||
src_addr_v4 = ipv4_hdr_get_src_in_addr(ipv4_hdr);
|
||||
@@ -140,7 +137,7 @@ static void packet_to_tshark_format(const struct packet *pkt, uint64_t idx)
|
||||
buffer_push(&buff_ipv4_src, tmp_src_buff);
|
||||
buffer_push(&buff_ipv4_dst, tmp_dst_buff);
|
||||
break;
|
||||
case LAYER_TYPE_IPV6:
|
||||
case LAYER_PROTO_IPV6:
|
||||
buffer_push(&buff_proto, "ipv6");
|
||||
ipv6_hdr = (const struct ip6_hdr *)layer->hdr_ptr;
|
||||
switch (ipv6_hdr_get_next_header(ipv6_hdr))
|
||||
@@ -170,13 +167,13 @@ static void packet_to_tshark_format(const struct packet *pkt, uint64_t idx)
|
||||
buffer_push(&buff_ipv6_src, tmp_src_buff);
|
||||
buffer_push(&buff_ipv6_dst, tmp_dst_buff);
|
||||
break;
|
||||
case LAYER_TYPE_IPAH:
|
||||
case LAYER_PROTO_IPAH:
|
||||
buffer_push(&buff_proto, "ah");
|
||||
break;
|
||||
case LAYER_TYPE_GRE:
|
||||
case LAYER_PROTO_GRE:
|
||||
buffer_push(&buff_proto, "gre");
|
||||
break;
|
||||
case LAYER_TYPE_UDP:
|
||||
case LAYER_PROTO_UDP:
|
||||
buffer_push(&buff_proto, "udp");
|
||||
udp_hdr = (const struct udphdr *)layer->hdr_ptr;
|
||||
src_port = udp_hdr_get_src_port(udp_hdr);
|
||||
@@ -186,7 +183,7 @@ static void packet_to_tshark_format(const struct packet *pkt, uint64_t idx)
|
||||
buffer_push(&buff_udp_src, tmp_src_buff);
|
||||
buffer_push(&buff_udp_dst, tmp_dst_buff);
|
||||
break;
|
||||
case LAYER_TYPE_TCP:
|
||||
case LAYER_PROTO_TCP:
|
||||
buffer_push(&buff_proto, "tcp");
|
||||
tcp_hdr = (const struct tcphdr *)layer->hdr_ptr;
|
||||
src_port = tcp_hdr_get_src_port(tcp_hdr);
|
||||
@@ -196,16 +193,16 @@ static void packet_to_tshark_format(const struct packet *pkt, uint64_t idx)
|
||||
buffer_push(&buff_tcp_src, tmp_src_buff);
|
||||
buffer_push(&buff_tcp_dst, tmp_dst_buff);
|
||||
break;
|
||||
case LAYER_TYPE_ICMP:
|
||||
case LAYER_PROTO_ICMP:
|
||||
buffer_push(&buff_proto, "icmp");
|
||||
break;
|
||||
case LAYER_TYPE_ICMP6:
|
||||
case LAYER_PROTO_ICMP6:
|
||||
buffer_push(&buff_proto, "icmpv6");
|
||||
break;
|
||||
case LAYER_TYPE_VXLAN:
|
||||
case LAYER_PROTO_VXLAN:
|
||||
buffer_push(&buff_proto, "vxlan");
|
||||
break;
|
||||
case LAYER_TYPE_GTPV1_U:
|
||||
case LAYER_PROTO_GTPV1_U:
|
||||
buffer_push(&buff_proto, "gtp");
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user