feature: packet manager support build packet
This commit is contained in:
@@ -136,21 +136,6 @@ int packet_get_tunnel_count(const struct packet *pkt);
|
|||||||
// return -1: failed
|
// return -1: failed
|
||||||
int packet_get_tunnel_by_idx(const struct packet *pkt, int idx, struct tunnel *out);
|
int packet_get_tunnel_by_idx(const struct packet *pkt, int idx, struct tunnel *out);
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* build
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* tcp_seq: the sequence number of the new TCP packet (in host byte order)
|
|
||||||
* tcp_ack: the acknowledgment number of the new TCP packet (in host byte order)
|
|
||||||
* tcp_options_len: the length of the options (must be a multiple of 4)
|
|
||||||
*/
|
|
||||||
struct packet *packet_build_tcp(const struct packet *origin_pkt, uint32_t tcp_seq, uint32_t tcp_ack, uint8_t tcp_flags,
|
|
||||||
const char *tcp_options, uint16_t tcp_options_len,
|
|
||||||
const char *tcp_payload, uint16_t tcp_payload_len);
|
|
||||||
struct packet *packet_build_udp(const struct packet *origin_pkt, const char *udp_payload, uint16_t udp_payload_len);
|
|
||||||
struct packet *packet_build_l3(const struct packet *origin_pkt, uint8_t ip_proto, const char *l3_payload, uint16_t l3_payload_len);
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* utils
|
* utils
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
@@ -183,6 +168,7 @@ enum packet_type
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum packet_type packet_get_type(const struct packet *pkt);
|
enum packet_type packet_get_type(const struct packet *pkt);
|
||||||
|
void packet_set_type(struct packet *pkt, enum packet_type type);
|
||||||
|
|
||||||
void packet_set_action(struct packet *pkt, enum packet_action action);
|
void packet_set_action(struct packet *pkt, enum packet_action action);
|
||||||
enum packet_action packet_get_action(const struct packet *pkt);
|
enum packet_action packet_get_action(const struct packet *pkt);
|
||||||
@@ -228,6 +214,20 @@ typedef void on_packet_claimed_callback(struct packet *pkt, void *arg);
|
|||||||
int packet_manager_claim_packet(struct packet_manager *pkt_mgr, uint16_t thread_id, struct packet *pkt, on_packet_claimed_callback cb, void *arg);
|
int packet_manager_claim_packet(struct packet_manager *pkt_mgr, uint16_t thread_id, struct packet *pkt, on_packet_claimed_callback cb, void *arg);
|
||||||
void packet_manager_schedule_packet(struct packet_manager *pkt_mgr, uint16_t thread_id, struct packet *pkt, enum packet_stage stage);
|
void packet_manager_schedule_packet(struct packet_manager *pkt_mgr, uint16_t thread_id, struct packet *pkt, enum packet_stage stage);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tcp_seq: the sequence number of the new TCP packet (in host byte order)
|
||||||
|
* tcp_ack: the acknowledgment number of the new TCP packet (in host byte order)
|
||||||
|
* tcp_options_len: the length of the options (must be a multiple of 4)
|
||||||
|
*/
|
||||||
|
struct packet *packet_manager_build_tcp_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt,
|
||||||
|
uint32_t tcp_seq, uint32_t tcp_ack, uint8_t tcp_flags,
|
||||||
|
const char *tcp_options, uint16_t tcp_options_len,
|
||||||
|
const char *tcp_payload, uint16_t tcp_payload_len);
|
||||||
|
struct packet *packet_manager_build_udp_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt,
|
||||||
|
const char *udp_payload, uint16_t udp_payload_len);
|
||||||
|
struct packet *packet_manager_build_l3_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt,
|
||||||
|
uint8_t ip_proto, const char *l3_payload, uint16_t l3_payload_len);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
23
infra/packet_manager/packet_builder.h
Normal file
23
infra/packet_manager/packet_builder.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "stellar/packet.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tcp_seq: the sequence number of the new TCP packet (in host byte order)
|
||||||
|
* tcp_ack: the acknowledgment number of the new TCP packet (in host byte order)
|
||||||
|
* tcp_options_len: the length of the options (must be a multiple of 4)
|
||||||
|
*/
|
||||||
|
struct packet *packet_build_tcp(const struct packet *origin_pkt, uint32_t tcp_seq, uint32_t tcp_ack, uint8_t tcp_flags,
|
||||||
|
const char *tcp_options, uint16_t tcp_options_len,
|
||||||
|
const char *tcp_payload, uint16_t tcp_payload_len);
|
||||||
|
struct packet *packet_build_udp(const struct packet *origin_pkt, const char *udp_payload, uint16_t udp_payload_len);
|
||||||
|
struct packet *packet_build_l3(const struct packet *origin_pkt, uint8_t ip_proto, const char *l3_payload, uint16_t l3_payload_len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -5,7 +5,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct packet;
|
#include "stellar/packet.h"
|
||||||
|
|
||||||
// Duplicated Packet Filter for IPv4 Packet
|
// Duplicated Packet Filter for IPv4 Packet
|
||||||
struct packet_dabloom;
|
struct packet_dabloom;
|
||||||
|
|||||||
@@ -127,7 +127,6 @@ uint16_t packet_get_link_id(const struct packet *pkt);
|
|||||||
void packet_set_claim(struct packet *pkt, bool claim);
|
void packet_set_claim(struct packet *pkt, bool claim);
|
||||||
bool packet_is_claim(const struct packet *pkt);
|
bool packet_is_claim(const struct packet *pkt);
|
||||||
|
|
||||||
void packet_set_type(struct packet *pkt, enum packet_type type);
|
|
||||||
void packet_set_direction(struct packet *pkt, enum packet_direction dir);
|
void packet_set_direction(struct packet *pkt, enum packet_direction dir);
|
||||||
|
|
||||||
void *packet_get_user_data(struct packet *pkt);
|
void *packet_get_user_data(struct packet *pkt);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "utils_internal.h"
|
#include "utils_internal.h"
|
||||||
#include "packet_internal.h"
|
#include "packet_internal.h"
|
||||||
#include "packet_manager.h"
|
#include "packet_manager.h"
|
||||||
|
#include "packet_builder.h"
|
||||||
#include "fieldstat/fieldstat_easy.h"
|
#include "fieldstat/fieldstat_easy.h"
|
||||||
|
|
||||||
#define PACKET_MANAGER_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "packet manager", format, ##__VA_ARGS__)
|
#define PACKET_MANAGER_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "packet manager", format, ##__VA_ARGS__)
|
||||||
@@ -430,6 +431,60 @@ void packet_manager_print_stat(struct packet_manager *pkt_mgr, uint16_t thread_i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct packet *packet_manager_build_tcp_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt, uint32_t tcp_seq, uint32_t tcp_ack, uint8_t tcp_flags,
|
||||||
|
const char *tcp_options, uint16_t tcp_options_len, const char *tcp_payload, uint16_t tcp_payload_len)
|
||||||
|
{
|
||||||
|
struct packet *pkt = packet_build_tcp(origin_pkt, tcp_seq, tcp_ack, tcp_flags, tcp_options, tcp_options_len, tcp_payload, tcp_payload_len);
|
||||||
|
if (pkt == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct exdata_runtime *ex_rte = exdata_runtime_new(pkt_mgr->sche->ex_sche);
|
||||||
|
packet_set_user_data(pkt, ex_rte);
|
||||||
|
|
||||||
|
return pkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct packet *packet_manager_build_udp_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt, const char *udp_payload, uint16_t udp_payload_len)
|
||||||
|
{
|
||||||
|
struct packet *pkt = packet_build_udp(origin_pkt, udp_payload, udp_payload_len);
|
||||||
|
if (pkt == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct exdata_runtime *ex_rte = exdata_runtime_new(pkt_mgr->sche->ex_sche);
|
||||||
|
packet_set_user_data(pkt, ex_rte);
|
||||||
|
|
||||||
|
return pkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct packet *packet_manager_build_l3_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt, uint8_t ip_proto, const char *l3_payload, uint16_t l3_payload_len)
|
||||||
|
{
|
||||||
|
struct packet *pkt = packet_build_l3(origin_pkt, ip_proto, l3_payload, l3_payload_len);
|
||||||
|
if (pkt == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct exdata_runtime *ex_rte = exdata_runtime_new(pkt_mgr->sche->ex_sche);
|
||||||
|
packet_set_user_data(pkt, ex_rte);
|
||||||
|
|
||||||
|
return pkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void packet_manager_free_packet(struct packet_manager *pkt_mgr __attribute__((unused)), struct packet *pkt)
|
||||||
|
{
|
||||||
|
if (pkt)
|
||||||
|
{
|
||||||
|
struct exdata_runtime *ex_rte = packet_get_user_data(pkt);
|
||||||
|
exdata_runtime_free(ex_rte);
|
||||||
|
|
||||||
|
packet_free(pkt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* packet manager module
|
* packet manager module
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "stellar/packet.h"
|
||||||
|
|
||||||
struct packet_pool;
|
struct packet_pool;
|
||||||
struct packet_pool *packet_pool_new(uint64_t capacity);
|
struct packet_pool *packet_pool_new(uint64_t capacity);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "packet_internal.h"
|
#include "packet_internal.h"
|
||||||
#include "packet_dump.h"
|
#include "packet_dump.h"
|
||||||
#include "packet_parser.h"
|
#include "packet_parser.h"
|
||||||
|
#include "packet_builder.h"
|
||||||
|
|
||||||
#define PRINT_GREEN(fmt, ...) printf("\033[0;32m" fmt "\033[0m\n", ##__VA_ARGS__)
|
#define PRINT_GREEN(fmt, ...) printf("\033[0;32m" fmt "\033[0m\n", ##__VA_ARGS__)
|
||||||
#define PRINT_RED(fmt, ...) printf("\033[0;31m" fmt "\033[0m\n", ##__VA_ARGS__)
|
#define PRINT_RED(fmt, ...) printf("\033[0;31m" fmt "\033[0m\n", ##__VA_ARGS__)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ global:
|
|||||||
packet_get_tunnel_count;
|
packet_get_tunnel_count;
|
||||||
packet_get_tunnel_by_idx;
|
packet_get_tunnel_by_idx;
|
||||||
packet_prepend_sids;
|
packet_prepend_sids;
|
||||||
|
packet_set_type;
|
||||||
|
packet_get_type;
|
||||||
packet_get_direction;
|
packet_get_direction;
|
||||||
packet_set_action;
|
packet_set_action;
|
||||||
packet_get_action;
|
packet_get_action;
|
||||||
@@ -12,9 +14,6 @@ global:
|
|||||||
packet_get_raw_len;
|
packet_get_raw_len;
|
||||||
packet_get_payload_data;
|
packet_get_payload_data;
|
||||||
packet_get_payload_len;
|
packet_get_payload_len;
|
||||||
packet_build_tcp;
|
|
||||||
packet_build_udp;
|
|
||||||
packet_build_l3;
|
|
||||||
packet_manager_on_init;
|
packet_manager_on_init;
|
||||||
packet_manager_on_exit;
|
packet_manager_on_exit;
|
||||||
packet_manager_on_thread_init;
|
packet_manager_on_thread_init;
|
||||||
@@ -23,6 +22,9 @@ global:
|
|||||||
packet_manager_subscribe;
|
packet_manager_subscribe;
|
||||||
packet_manager_claim_packet;
|
packet_manager_claim_packet;
|
||||||
packet_manager_schedule_packet;
|
packet_manager_schedule_packet;
|
||||||
|
packet_manager_build_tcp_packet;
|
||||||
|
packet_manager_build_udp_packet;
|
||||||
|
packet_manager_build_l3_packet;
|
||||||
|
|
||||||
session_is_symmetric;
|
session_is_symmetric;
|
||||||
session_has_duplicate_traffic;
|
session_has_duplicate_traffic;
|
||||||
|
|||||||
Reference in New Issue
Block a user