2024-04-22 20:01:15 +08:00
|
|
|
#ifndef _PACKET_PRIV_H
|
|
|
|
|
#define _PACKET_PRIV_H
|
2023-12-11 16:22:46 +08:00
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2023-12-11 16:22:46 +08:00
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-12-15 18:57:13 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
2024-04-10 11:40:26 +08:00
|
|
|
|
2024-01-26 14:41:40 +08:00
|
|
|
#include "log.h"
|
2024-04-22 20:01:15 +08:00
|
|
|
#include "stellar/tuple.h"
|
|
|
|
|
#include "stellar/packet.h"
|
2023-12-15 18:57:13 +08:00
|
|
|
|
2024-03-09 19:28:14 +08:00
|
|
|
#define PACKET_MAX_LAYERS 32
|
2024-01-26 14:41:40 +08:00
|
|
|
#define PACKET_LOG_ERROR(format, ...) LOG_ERROR("packet", format, ##__VA_ARGS__)
|
2024-05-16 11:52:14 +08:00
|
|
|
#define PACKET_LOG_WARN(format, ...) LOG_WARN("packet", format, ##__VA_ARGS__)
|
2024-04-11 19:44:02 +08:00
|
|
|
#define PACKET_LOG_DEBUG(format, ...) void(0)
|
2024-05-08 18:24:26 +08:00
|
|
|
// #define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
|
2023-12-15 18:57:13 +08:00
|
|
|
|
|
|
|
|
enum ldbc_method
|
|
|
|
|
{
|
|
|
|
|
LDBC_METHOD_HASH_INT_IP = 1,
|
|
|
|
|
LDBC_METHOD_HASH_EXT_IP = 2,
|
|
|
|
|
LDBC_METHOD_HASH_INT_IP_AND_EXT_IP = 3,
|
|
|
|
|
LDBC_METHOD_HASH_INNERMOST_INT_IP = 4,
|
|
|
|
|
LDBC_METHOD_HASH_INNERMOST_EXT_IP = 5,
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-11 19:44:02 +08:00
|
|
|
enum packet_origin
|
2024-03-09 19:28:14 +08:00
|
|
|
{
|
2024-05-08 18:24:26 +08:00
|
|
|
PACKET_ORIGIN_MARSIO = 0x1, // packet data in mbuff (eg: packet I/O mrzcpd mode)
|
|
|
|
|
PACKET_ORIGIN_DUMPFILE = 0x2, // packet data in pcap (eg: packet I/O dumpfile mode)
|
|
|
|
|
PACKET_ORIGIN_USERSTACK = 0x3, // packet data in user stack (eg: inject packet)
|
|
|
|
|
PACKET_ORIGIN_USERHEAP = 0x4, // packet data in user heap (eg: ip reassembly)
|
2024-03-09 19:28:14 +08:00
|
|
|
};
|
|
|
|
|
|
2023-12-15 18:57:13 +08:00
|
|
|
struct packet
|
|
|
|
|
{
|
2024-04-10 11:40:26 +08:00
|
|
|
struct packet_layer layers[PACKET_MAX_LAYERS];
|
|
|
|
|
struct packet_layer *frag_layer; // fragment layer
|
2023-12-15 18:57:13 +08:00
|
|
|
int8_t layers_used;
|
|
|
|
|
int8_t layers_size;
|
|
|
|
|
|
|
|
|
|
const char *data_ptr;
|
|
|
|
|
uint16_t data_len;
|
2024-05-24 19:10:33 +08:00
|
|
|
uint16_t trim_len; // trim eth padding
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-05-08 18:24:26 +08:00
|
|
|
void *origin_ctx; // mbuff or pcap pointer
|
2024-05-09 14:57:12 +08:00
|
|
|
enum packet_action action;
|
2024-04-11 19:44:02 +08:00
|
|
|
enum packet_origin origin;
|
2023-12-15 18:57:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// return innermost payload
|
2024-03-09 19:28:14 +08:00
|
|
|
const char *packet_parse(struct packet *pkt, const char *data, uint16_t len);
|
2024-05-24 19:10:33 +08:00
|
|
|
void packet_print_str(const struct packet *pkt);
|
2023-12-15 18:57:13 +08:00
|
|
|
|
|
|
|
|
// direction 1: E2I
|
|
|
|
|
// direction 0: I2E
|
2024-03-09 19:28:14 +08:00
|
|
|
uint64_t packet_get_hash(const struct packet *pkt, enum ldbc_method method, int direction);
|
|
|
|
|
|
2024-04-11 19:44:02 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Utils
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2024-05-09 14:57:12 +08:00
|
|
|
#define MAX_ROUTE_CTX 64
|
|
|
|
|
struct route_ctx
|
|
|
|
|
{
|
|
|
|
|
char data[MAX_ROUTE_CTX];
|
|
|
|
|
int used;
|
|
|
|
|
};
|
|
|
|
|
void packet_set_route_ctx(struct packet *pkt, const struct route_ctx *ctx);
|
|
|
|
|
void packet_get_route_ctx(const struct packet *pkt, struct route_ctx *ctx);
|
|
|
|
|
|
2024-04-11 19:44:02 +08:00
|
|
|
void packet_set_origin(struct packet *pkt, enum packet_origin origin);
|
|
|
|
|
enum packet_origin packet_get_origin(const struct packet *pkt);
|
2024-03-09 19:28:14 +08:00
|
|
|
|
2024-05-08 18:24:26 +08:00
|
|
|
void packet_set_origin_ctx(struct packet *pkt, void *ctx);
|
|
|
|
|
void *packet_get_origin_ctx(const struct packet *pkt);
|
2024-03-09 19:28:14 +08:00
|
|
|
|
2024-05-09 14:57:12 +08:00
|
|
|
void packet_set_domain(struct packet *pkt, uint64_t domain);
|
|
|
|
|
uint64_t packet_get_domain(const struct packet *pkt);
|
2024-03-09 19:28:14 +08:00
|
|
|
|
2024-04-25 16:48:50 +08:00
|
|
|
void packet_set_ctrl(struct packet *pkt);
|
2024-05-09 14:57:12 +08:00
|
|
|
int packet_is_ctrl(const struct packet *pkt);
|
|
|
|
|
|
|
|
|
|
void packet_set_sid_list(struct packet *pkt, const struct sid_list *list);
|
|
|
|
|
void packet_get_sid_list(const struct packet *pkt, struct sid_list *list);
|
|
|
|
|
void packet_append_sid_list(struct packet *pkt, const struct sid_list *list);
|
2024-04-25 16:48:50 +08:00
|
|
|
|
2024-03-09 19:28:14 +08:00
|
|
|
struct packet *packet_new(uint16_t pkt_len);
|
|
|
|
|
void packet_free(struct packet *pkt);
|
|
|
|
|
struct packet *packet_dup(const struct packet *pkt);
|
|
|
|
|
|
2024-05-09 14:57:12 +08:00
|
|
|
void packet_set_session_id(struct packet *pkt, uint64_t sess_id);
|
|
|
|
|
void packet_set_direction(struct packet *pkt, enum packet_direction dir);
|
2024-03-09 19:28:14 +08:00
|
|
|
|
2024-05-09 14:57:12 +08:00
|
|
|
int packet_is_fragment(const struct packet *pkt);
|
2024-05-21 17:39:16 +08:00
|
|
|
int packet_get_fingerprint(const struct packet *pkt, char *buff, int size);
|
2023-12-11 16:22:46 +08:00
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2023-12-11 16:22:46 +08:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|