This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/src/packet_io/packet_io_util.h

110 lines
2.5 KiB
C
Raw Normal View History

/*
**********************************************************************************************
2022-08-11 11:18:14 +08:00
* File: packet_io_util.h
* Description: packet_io internal utils
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-07-15
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
2022-08-11 11:18:14 +08:00
#ifndef _PACKET_IO_UTIL_H_
#define _PACKET_IO_UTIL_H_
2022-08-11 10:50:41 +08:00
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
2022-08-11 11:18:14 +08:00
#include <pthread.h>
2022-08-18 16:26:00 +08:00
#define STR_MAX_LEN 1024
2022-08-11 21:25:29 +08:00
#ifndef DLT_EN10MB
#define DLT_EN10MB 1
#endif
#define LINKTYPE_ETHERNET DLT_EN10MB
#define ETHERNET_TYPE_IP 0x0800
#define ETHERNET_TYPE_IPV6 0x86dd
#define PKT_QUEUE_MAX_NUM 256
#define CUSTOM_ZONE_LEN 64
#define ETHERNET_HEADER_LEN 14
#define DEFAULT_MTU 1500
#define DEFAULT_PACKET_SIZE (CUSTOM_ZONE_LEN + DEFAULT_MTU + ETHERNET_HEADER_LEN)
#define COMMON_SIZE_OF_PIO_PACKET (DEFAULT_PACKET_SIZE + sizeof(struct pio_packet))
#define MAX_SIZE_OF_PIO_PACKET (65535 + sizeof(struct pio_packet))
/**
* @brief pcap_live/pcap_file mode packet structure
*
* |<-pkt_hdr |<-pkt_payload
* | |
* | struct pio_packet | custom zone | L2 header | ...... |
* 64bytes 14bytes 1500bytes
*
* custom zone: user can set custom field
* pkt_payload: received packet data
2022-08-10 10:21:07 +08:00
*/
struct pio_packet {
/* pkt header pointer */
void *pkt_hdr;
/* pkt length */
uint32_t pkt_len;
/* pkt payload pointer */
void *pkt_payload;
2022-08-11 21:25:29 +08:00
/* data link type */
uint32_t data_link;
/* reference counts */
uint32_t ref_cnt;
struct pio_packet *prev;
struct pio_packet *next;
};
struct pio_packet_queue {
struct pio_packet *top;
struct pio_packet *bot;
uint32_t len;
pthread_mutex_t mutex_q;
};
2022-08-11 21:25:29 +08:00
/**
* @brief string copy safely,
*
* @retval -1(failed), 0(success)
*/
2022-08-18 16:26:00 +08:00
ssize_t strncpy_safe(char *dst, const char *src, size_t dst_size);
2022-08-11 21:25:29 +08:00
2022-08-18 16:26:00 +08:00
ssize_t packet_copy_data(uint8_t *ptr, const uint8_t *pkt_data, uint32_t pkt_len);
2022-08-11 21:25:29 +08:00
/**
* @brief ip hash function for struct pio_packet, 2 tuple(sip/dip) hash
*
* @retval hash value
*/
uint64_t pio_packet_hash(struct pio_packet *p);
void pio_packet_queue_init(struct pio_packet_queue *);
void pio_packet_enqueue(struct pio_packet_queue *, struct pio_packet *);
2022-08-11 11:18:14 +08:00
struct pio_packet *pio_packet_dequeue(struct pio_packet_queue *);
2022-08-11 11:18:14 +08:00
2022-08-11 10:50:41 +08:00
void release_pio_packet_queue(struct pio_packet_queue *);
#ifdef __cpluscplus
}
#endif
2022-08-11 11:18:14 +08:00
#endif /* _PACKET_IO_UTIL_H_ */