2024-06-19 15:06:14 +08:00
|
|
|
#pragma once
|
2024-04-10 11:40:26 +08:00
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2024-04-10 11:40:26 +08:00
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-06-14 19:24:27 +08:00
|
|
|
#include <stdint.h>
|
2024-04-10 11:40:26 +08:00
|
|
|
|
2024-06-14 19:24:27 +08:00
|
|
|
#define MAX_SIDS 8
|
|
|
|
|
struct sids
|
2024-04-10 11:40:26 +08:00
|
|
|
{
|
2024-06-14 19:24:27 +08:00
|
|
|
uint16_t sid[MAX_SIDS];
|
2024-05-09 14:57:12 +08:00
|
|
|
int used;
|
|
|
|
|
};
|
2024-06-14 19:24:27 +08:00
|
|
|
void packet_prepend_sids(struct packet *pkt, const struct sids *sids);
|
2024-05-09 14:57:12 +08:00
|
|
|
|
|
|
|
|
enum packet_direction
|
|
|
|
|
{
|
|
|
|
|
PACKET_DIRECTION_OUTGOING = 0, // Internal -> External: 0
|
|
|
|
|
PACKET_DIRECTION_INCOMING = 1, // External -> Internal: 1
|
|
|
|
|
};
|
2024-06-14 19:24:27 +08:00
|
|
|
enum packet_direction packet_get_direction(const struct packet *pkt);
|
2024-05-09 14:57:12 +08:00
|
|
|
|
|
|
|
|
enum packet_action
|
|
|
|
|
{
|
2024-04-24 11:40:00 +08:00
|
|
|
PACKET_ACTION_FORWARD = 0,
|
2024-05-09 14:57:12 +08:00
|
|
|
PACKET_ACTION_DROP = 1,
|
|
|
|
|
};
|
2024-06-14 19:24:27 +08:00
|
|
|
void packet_set_action(struct packet *pkt, enum packet_action action);
|
|
|
|
|
enum packet_action packet_get_action(const struct packet *pkt);
|
2024-05-09 14:57:12 +08:00
|
|
|
|
2024-06-14 19:24:27 +08:00
|
|
|
const char *packet_get_raw_data(const struct packet *pkt);
|
|
|
|
|
uint16_t packet_get_raw_len(const struct packet *pkt);
|
2024-04-11 19:44:02 +08:00
|
|
|
|
|
|
|
|
const char *packet_get_payload(const struct packet *pkt);
|
|
|
|
|
uint16_t packet_get_payload_len(const struct packet *pkt);
|
|
|
|
|
|
2024-07-02 17:55:55 +08:00
|
|
|
/*
|
|
|
|
|
* 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)
|
|
|
|
|
*/
|
2024-07-15 15:07:38 +08:00
|
|
|
struct packet *craft_tcp_packet(const struct packet *origin_pkt, uint32_t tcp_seq, uint32_t tcp_ack, uint8_t tcp_flags,
|
2024-07-02 17:55:55 +08:00
|
|
|
const char *tcp_options, uint16_t tcp_options_len,
|
|
|
|
|
const char *tcp_payload, uint16_t tcp_payload_len);
|
2024-07-15 15:07:38 +08:00
|
|
|
struct packet *craft_udp_packet(const struct packet *origin_pkt, const char *udp_payload, uint16_t udp_payload_len);
|
2024-06-28 16:08:40 +08:00
|
|
|
struct packet *craft_packet_from_scratch(const struct layer larers[], uint16_t layer_count, const char *payload, uint16_t payload_len);
|
2024-06-27 15:07:54 +08:00
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2024-04-10 11:40:26 +08:00
|
|
|
}
|
|
|
|
|
#endif
|