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/common/pio_packet_queue.h

64 lines
1.7 KiB
C
Raw Normal View History

/*
**********************************************************************************************
* File: pio_packet_queue.h
* Description: pio packet queue structure and api
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-07-15
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
#pragma once
#include <stdint.h>
#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 SIZE_OF_PIO_PACKET (DEFAULT_PACKET_SIZE + 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;
/* 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;
};
int packet_copy_data(uint8_t *ptr, const uint8_t *pkt_data, uint32_t pkt_len);
void pio_packet_enqueue(struct pio_packet_queue *, struct pio_packet *);
struct pio_packet *pio_packet_dequeue(struct pio_packet_queue *);
void release_pio_packet_queue(struct pio_packet_queue *);