remove tuple.h from include/stellar
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
install(FILES stellar/utils.h DESTINATION include/stellar/ COMPONENT LIBRARIES)
|
||||
install(FILES stellar/tuple.h DESTINATION include/stellar/ COMPONENT LIBRARIES)
|
||||
install(FILES stellar/packet.h DESTINATION include/stellar/ COMPONENT LIBRARIES)
|
||||
install(FILES stellar/session.h DESTINATION include/stellar/ COMPONENT LIBRARIES)
|
||||
install(FILES stellar/stellar.h DESTINATION include/stellar/ COMPONENT LIBRARIES)
|
||||
|
||||
@@ -6,7 +6,13 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "stellar/tuple.h"
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#define __FAVOR_BSD 1
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip6.h>
|
||||
|
||||
enum layer_type
|
||||
{
|
||||
@@ -59,28 +65,6 @@ struct packet_layer
|
||||
uint16_t pld_len; // payload length
|
||||
};
|
||||
|
||||
// return 0: found
|
||||
// return -1: not found
|
||||
int packet_get_innermost_tuple2(const struct packet *pkt, struct tuple2 *tuple);
|
||||
int packet_get_outermost_tuple2(const struct packet *pkt, struct tuple2 *tuple);
|
||||
|
||||
// return 0: found
|
||||
// return -1: not found
|
||||
int packet_get_innermost_tuple4(const struct packet *pkt, struct tuple4 *tuple);
|
||||
int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple);
|
||||
|
||||
// return 0: found
|
||||
// return -1: not found
|
||||
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);
|
||||
|
||||
/******************************************************************************
|
||||
* Utils
|
||||
******************************************************************************/
|
||||
|
||||
#define MAX_SID_NUM 8
|
||||
struct sid_list
|
||||
{
|
||||
@@ -117,29 +101,6 @@ void packet_set_action(struct packet *pkt, enum packet_action action);
|
||||
enum packet_action packet_get_action(const struct packet *pkt);
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
* Example: getting the innermost TCP layer
|
||||
******************************************************************************
|
||||
*
|
||||
* |<--------------------------- pkt->data_len -------------------------->|
|
||||
* +----------+------+-----+-------+------+---------------+---------------+
|
||||
* | Ethernet | IPv4 | UDP | GTP-U | IPv4 | TCP | Payload |
|
||||
* +----------+------+-----+-------+------+---------------+---------------+
|
||||
* ^ ^ ^
|
||||
* | | |
|
||||
* |<------------ hdr_offset ------------>|<-- hdr_len -->|<-- pld_len -->|
|
||||
* | | |
|
||||
* | | +-- pld_ptr
|
||||
* | +-- hdr_ptr
|
||||
* +-- data_ptr
|
||||
*
|
||||
* const struct packet_layer *tcp_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_TCP);
|
||||
* const struct tcphdr *hdr = (const struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
* uint16_t src_port = ntohs(hdr->th_sport);
|
||||
* uint16_t dst_port = ntohs(hdr->th_dport);
|
||||
* uint32_t seq = ntohl(hdr->th_seq);
|
||||
* uint32_t ack = ntohl(hdr->th_ack);
|
||||
*
|
||||
******************************************************************************
|
||||
* Example: foreach layer in packet
|
||||
******************************************************************************
|
||||
@@ -160,6 +121,168 @@ enum packet_action packet_get_action(const struct packet *pkt);
|
||||
* }
|
||||
*/
|
||||
|
||||
struct address
|
||||
{
|
||||
uint8_t family; // AF_INET or AF_INET6
|
||||
union
|
||||
{
|
||||
struct in_addr v4; /* network order */
|
||||
struct in6_addr v6; /* network order */
|
||||
} data;
|
||||
};
|
||||
|
||||
static inline int packet_get_addr(const struct packet *pkt, struct address *src_addr, struct address *dst_addr)
|
||||
{
|
||||
const struct ip *ip4_hdr = NULL;
|
||||
const struct ip6_hdr *ip6_hdr = NULL;
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type & LAYER_TYPE_IPV4)
|
||||
{
|
||||
ip4_hdr = (const struct ip *)layer->hdr_ptr;
|
||||
if (src_addr != NULL)
|
||||
{
|
||||
src_addr->family = AF_INET;
|
||||
src_addr->data.v4.s_addr = ip4_hdr->ip_src.s_addr;
|
||||
}
|
||||
if (dst_addr != NULL)
|
||||
{
|
||||
dst_addr->family = AF_INET;
|
||||
dst_addr->data.v4.s_addr = ip4_hdr->ip_dst.s_addr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (layer->type & LAYER_TYPE_IPV6)
|
||||
{
|
||||
ip6_hdr = (const struct ip6_hdr *)layer->hdr_ptr;
|
||||
if (src_addr != NULL)
|
||||
{
|
||||
src_addr->family = AF_INET6;
|
||||
src_addr->data.v6 = ip6_hdr->ip6_src;
|
||||
}
|
||||
if (dst_addr != NULL)
|
||||
{
|
||||
dst_addr->family = AF_INET6;
|
||||
dst_addr->data.v6 = ip6_hdr->ip6_dst;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_port(const struct packet *pkt, uint16_t *src_port, uint16_t *dst_port)
|
||||
{
|
||||
const struct tcphdr *tcp_hdr = NULL;
|
||||
const struct udphdr *udp_hdr = NULL;
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type & LAYER_TYPE_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)
|
||||
{
|
||||
udp_hdr = (const struct udphdr *)layer->hdr_ptr;
|
||||
src_port != NULL ? *src_port = udp_hdr->uh_sport : 0;
|
||||
dst_port != NULL ? *dst_port = udp_hdr->uh_dport : 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_ip_hdr(const struct packet *pkt, struct ip *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type & LAYER_TYPE_IPV4)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct ip));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_ip6_hdr(const struct packet *pkt, struct ip6_hdr *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type & LAYER_TYPE_IPV6)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct ip6_hdr));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_tcp_hdr(const struct packet *pkt, struct tcphdr *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type & LAYER_TYPE_TCP)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct tcphdr));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int packet_get_udp_hdr(const struct packet *pkt, struct udphdr *hdr)
|
||||
{
|
||||
const struct packet_layer *layer = NULL;
|
||||
int8_t num = packet_get_layers_number(pkt);
|
||||
for (int8_t i = num - 1; i >= 0; i--)
|
||||
{
|
||||
layer = packet_get_layer(pkt, i);
|
||||
if (layer->type & LAYER_TYPE_UDP)
|
||||
{
|
||||
if (hdr != NULL)
|
||||
{
|
||||
memcpy(hdr, layer->hdr_ptr, sizeof(struct udphdr));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -139,10 +139,6 @@ enum closing_reason session_get_closing_reason(const struct session *sess);
|
||||
enum session_direction session_get_direction(const struct session *sess);
|
||||
enum flow_direction session_get_current_flow_direction(const struct session *sess);
|
||||
const struct packet *session_get_first_packet(const struct session *sess, enum flow_direction dir);
|
||||
|
||||
const struct tuple6 *session_get_tuple6(const struct session *sess);
|
||||
enum flow_direction session_get_tuple6_direction(const struct session *sess);
|
||||
|
||||
uint64_t session_get_id(const struct session *sess);
|
||||
uint64_t session_get_timestamp(const struct session *sess, enum session_timestamp type);
|
||||
uint64_t session_get_stat(const struct session *sess, enum flow_direction dir, enum session_stat stat);
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
#ifndef _TUPLE_PUB_H
|
||||
#define _TUPLE_PUB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
enum ip_type
|
||||
{
|
||||
IP_TYPE_V4,
|
||||
IP_TYPE_V6,
|
||||
};
|
||||
|
||||
union ip_address
|
||||
{
|
||||
struct in_addr v4; /* network order */
|
||||
struct in6_addr v6; /* network order */
|
||||
};
|
||||
|
||||
struct tuple2
|
||||
{
|
||||
enum ip_type ip_type;
|
||||
union ip_address src_addr; /* network order */
|
||||
union ip_address dst_addr; /* network order */
|
||||
};
|
||||
|
||||
struct tuple4
|
||||
{
|
||||
enum ip_type ip_type;
|
||||
union ip_address src_addr; /* network order */
|
||||
union ip_address dst_addr; /* network order */
|
||||
|
||||
in_port_t src_port; /* network order */
|
||||
in_port_t dst_port; /* network order */
|
||||
};
|
||||
|
||||
struct tuple5
|
||||
{
|
||||
enum ip_type ip_type;
|
||||
union ip_address src_addr; /* network order */
|
||||
union ip_address dst_addr; /* network order */
|
||||
|
||||
in_port_t src_port; /* network order */
|
||||
in_port_t dst_port; /* network order */
|
||||
|
||||
uint16_t ip_proto; /* network order */
|
||||
};
|
||||
|
||||
struct tuple6
|
||||
{
|
||||
enum ip_type ip_type;
|
||||
union ip_address src_addr; /* network order */
|
||||
union ip_address dst_addr; /* network order */
|
||||
|
||||
uint16_t src_port; /* network order */
|
||||
uint16_t dst_port; /* network order */
|
||||
|
||||
uint16_t ip_proto; /* network order */
|
||||
uint64_t domain;
|
||||
};
|
||||
|
||||
uint32_t tuple2_hash(const struct tuple2 *tuple);
|
||||
uint32_t tuple4_hash(const struct tuple4 *tuple);
|
||||
uint32_t tuple5_hash(const struct tuple5 *tuple);
|
||||
uint32_t tuple6_hash(const struct tuple6 *tuple);
|
||||
|
||||
int tuple2_cmp(const struct tuple2 *tuple_a, const struct tuple2 *tuple_b);
|
||||
int tuple4_cmp(const struct tuple4 *tuple_a, const struct tuple4 *tuple_b);
|
||||
int tuple5_cmp(const struct tuple5 *tuple_a, const struct tuple5 *tuple_b);
|
||||
int tuple6_cmp(const struct tuple6 *tuple_a, const struct tuple6 *tuple_b);
|
||||
|
||||
void tuple2_reverse(const struct tuple2 *in, struct tuple2 *out);
|
||||
void tuple4_reverse(const struct tuple4 *in, struct tuple4 *out);
|
||||
void tuple5_reverse(const struct tuple5 *in, struct tuple5 *out);
|
||||
void tuple6_reverse(const struct tuple6 *in, struct tuple6 *out);
|
||||
|
||||
void tuple2_to_str(const struct tuple2 *tuple, char *buf, uint32_t size);
|
||||
void tuple4_to_str(const struct tuple4 *tuple, char *buf, uint32_t size);
|
||||
void tuple5_to_str(const struct tuple5 *tuple, char *buf, uint32_t size);
|
||||
void tuple6_to_str(const struct tuple6 *tuple, char *buf, uint32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user