Add ip_reassemble & ip_fragment function define

This commit is contained in:
luwenpeng
2024-02-04 17:40:26 +08:00
parent 3bbb341280
commit c0514964f9
4 changed files with 129 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#include "ip_fragment.h"
/*
* Return the number of fragmented packets, stored in the pkts_out array
* Packets in the pkts_out array should be freed by calling the packet_free() function
*/
uint16_t ipv4_fragment_packet(struct packet *pkt_in, struct packet **pkts_out, uint16_t nb_pkts_out, uint16_t mtu_size)
{
if (pkt_in == NULL || pkts_out == NULL || nb_pkts_out == 0)
{
IP_FRAGMENT_LOG_ERROR("invalid input parameters");
return 0;
}
// TODO
return 0;
}
uint16_t ipv6_fragment_packet(struct packet *pkt_in, struct packet **pkts_out, uint16_t nb_pkts_out, uint16_t mtu_size)
{
if (pkt_in == NULL || pkts_out == NULL || nb_pkts_out == 0)
{
IP_FRAGMENT_LOG_ERROR("invalid input parameters");
return 0;
}
// TODO
return 0;
}

View File

@@ -0,0 +1,26 @@
#ifndef _IP_FRAGMENT_H
#define _IP_FRAGMENT_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include "packet.h"
#include "log.h"
#define IP_FRAGMENT_LOG_DEBUG(format, ...) LOG_DEBUG("ip_fragment", format, ##__VA_ARGS__)
#define IP_FRAGMENT_LOG_ERROR(format, ...) LOG_ERROR("ip_fragment", format, ##__VA_ARGS__)
/*
* Return the number of fragmented packets, stored in the pkts_out array
* Packets in the pkts_out array should be freed by calling the packet_free() function
*/
uint16_t ipv4_fragment_packet(struct packet *pkt_in, struct packet **pkts_out, uint16_t nb_pkts_out, uint16_t mtu_size);
uint16_t ipv6_fragment_packet(struct packet *pkt_in, struct packet **pkts_out, uint16_t nb_pkts_out, uint16_t mtu_size);
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -0,0 +1,31 @@
#include "ip_reassemble.h"
struct ip_reassemble_manager *ip_reassemble_manager_create(const struct ip_reassemble_config *config)
{
// TODO
}
void ip_reassemble_manager_destory(struct ip_reassemble_manager *mgr)
{
// TODO
}
void ip_reassemble_manager_stat(struct ip_reassemble_manager *mgr)
{
// TODO
}
/*
* Returns the reassembled packet, or NULL if the packet is not reassembled
* The returned packet should be freed by calling the packet_free() function
*/
struct packet *ipv4_reassemble_packet(struct ip_reassemble_manager *mgr, const struct packet *pkt)
{
// TODO
}
struct packet *ipv6_reassemble_packet(struct ip_reassemble_manager *mgr, const struct packet *pkt)
{
// TODO
}

View File

@@ -0,0 +1,40 @@
#ifndef _IP_REASSEMBLE_H
#define _IP_REASSEMBLE_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include "packet.h"
#include "log.h"
#define IP_REASSEMBLE_DEBUG(format, ...) LOG_DEBUG("ip_reassemble", format, ##__VA_ARGS__)
#define IP_REASSEMBLE_ERROR(format, ...) LOG_ERROR("ip_reassemble", format, ##__VA_ARGS__)
struct ip_reassemble_config
{
bool enable_reassemble;
uint32_t max_cycles;
uint32_t max_entries;
uint32_t bucket_entries;
uint32_t bucket_num;
};
struct ip_reassemble_manager *ip_reassemble_manager_create(const struct ip_reassemble_config *config);
void ip_reassemble_manager_destory(struct ip_reassemble_manager *mgr);
void ip_reassemble_manager_stat(struct ip_reassemble_manager *mgr);
/*
* Returns the reassembled packet, or NULL if the packet is not reassembled
* The returned packet should be freed by calling the packet_free() function
*/
struct packet *ipv4_reassemble_packet(struct ip_reassemble_manager *mgr, const struct packet *pkt);
struct packet *ipv6_reassemble_packet(struct ip_reassemble_manager *mgr, const struct packet *pkt);
#ifdef __cpluscplus
}
#endif
#endif