-
Notifications
You must be signed in to change notification settings - Fork 35
6. IPv6 API Description
Structure to identify an IPv6 flow:
/** @brief Struct to generate the flow key **/
typedef struct
{
/// source IP address
unsigned char source[16];
/// destination IP address
unsigned char destination[16];
/// Transport layer protocol
unsigned char protocol;
/// Identification
unsigned int id;
} ntoh_ipv6_tuple4_t, *pntoh_ipv6_tuple4_t;
Structure to store an IPv6 fragment:
/** @brief Struct to store the information of each fragment */
typedef struct _ipv6_fragment_
{
/// pointer to the next fragment
struct _ipv6_fragment_ *next;
/// fragment offset
unsigned int offset;
/// fragment data length
unsigned int len;
/// fragment data
unsigned char *data;
} ntoh_ipv6_fragment_t , *pntoh_ipv6_fragment_t;
Structure to store all information of an IPv6 flow:
/** @brief Struct to store the information of each IPv6 flow */
typedef struct
{
/// flow identification data
ntoh_ipv6_tuple4_t ident;
/// flow key
ntoh_ipv6_key_t key;
/// fragments list
pntoh_ipv6_fragment_t fragments;
/// total amount of received data
size_t meat;
/// total amount of expected data
size_t total;
/// final fragment received?
struct ip6_hdr *final_iphdr;
/// user defined function to receive defragmented packets
void *function;
/// last activity
struct timeval last_activ;
/// user-defined data
void *udata;
ntoh_lock_t lock;
} ntoh_ipv6_flow_t, *pntoh_ipv6_flow_t;
Structure to store all information needed for an IPv6 session:
/** @brief Structure to store global parameters */
typedef struct _ipv6_session_
{
struct _ipv6_session_ *next;
/// max. number of IP flows
sem_t max_flows;
sem_t max_fragments;
/// hash table to store IP flows
pipv6_flows_table_t flows;
/// connection tables related
pthread_t tID;
ntoh_lock_t lock;
}ntoh_ipv6_session_t , *pntoh_ipv6_session_t;
Function to initialize IPv6 defragmentation
void ntoh_ipv6_init ( void );
Function to flush all IPv6 sessions and release all resources
void ntoh_ipv6_exit ( void );
Function to create a new session:
pntoh_ipv4_session_t ntoh_ipv6_new_session ( unsigned int max_flows , unsigned long max_mem , unsigned int *error );
- max_flows: Max. number of allowed flows in this session
- max_mem: Max. amount of memory to be used to store fragments
- *error: Returned error code
This function returns a pointer to the new session, or NULL on error.
Function to resize an existing session:
int ntoh_ipv6_resize_session ( pntoh_ipv6_session_t session , size_t size );
- session: Pointer to the IPv6 session to be resized
- size: New size
This function returns NTOH_OK on success and the error code when it fails.
Function to free a session:
void ntoh_ipv6_free_session ( pntoh_ipv6_session_t session );
- session: Session pointer to be released
Function to create a new flow:
pntoh_ipv6_flow_t ntoh_ipv6_new_flow ( pntoh_ipv6_session_t session , pntoh_ipv4_tuple4_t tuple4 , pipv6_dfcallback_t function , void *udata , unsigned int *error);
- session: IPv6 session
- tuple4: Tuple4 identifying the flow
- function: User defined callback function to receive the defragmented datagrams of this flow
- udata: User data linked to this flow
- *error: Returned error code
This function returns a pointer to the new created IPv6 flow, or NULL on error.
Function to find an IPv6 flow:
pntoh_ipv6_flow_t ntoh_ipv6_find_flow ( pntoh_ipv6_session_t session , pntoh_ipv6_tuple4_t tuple4 );
- session: IPv6 session
- tuple4: Tuple4 structure identifying the flow
This function returns a pointer to the flow if it was found, or NULL if it was not found.
Function to free an IPv6 flow:
void ntoh_ipv6_free_flow ( pntoh_ipv6_session_t session , pntoh_ipv6_flow_t flow , unsigned short reason );
- session: IPv6 session
- flow: Flow to be free'd
- reason: Value to be sent to the user-defined callback function
Function to add a fragment to a given IPv6 flow:
int ntoh_ipv6_add_fragment ( pntoh_ipv6_session_t session , pntoh_ipv6_flow_t flow , struct ip6_hdr *iphdr );
- session: IPv6 session
- flow: IPv6 flow where the new fragment will be added
- iphdr: IPv6 header
This function returns NTOH_OK on success and the error code on failure.
Function to get the number of stored IPv6 flows in a session:
unsigned int ntoh_ipv6_count_flows ( pntoh_ipv6_session_t session );
- session: IPv6 session
This function returns the number of IPv6 flows stored in the given session.
Function to get the size of the IPv6 sessions table (max allowed flows):
unsigned int *ntoh_ipv6_get_size ( pntoh_ipv6_session_t session );
- session: IPv6 session
This function returns the size of the IPv6 sessions table.
Function to get the tuple4:
unsigned int ntoh_ipv6_get_tuple4 ( struct ip6_hdr *ip , pntoh_ipv6_tuple4_t tuple );
- ip: IPv6 Header
- tuple: Pointer to the output tuple4 struct
This function returns NTOH_OK on success and the error code on failure.
Macro to check if an IPv4 datagram is part of a fragmented datagram:
#define NTOH_IPV6_IS_FRAGMENT(val) (((struct ip6_hdr*)val)->ip6_nxt==IPPROTO_FRAGMENT && \
( \
(ntohs(((struct ip6_frag *)((unsigned char*)val+sizeof(struct ip6_hdr)))->ip6f_offlg) & IP6F_OFF_MASK)>0 || \
(ntohs(((struct ip6_frag *)((unsigned char*)val+sizeof(struct ip6_hdr)))->ip6f_offlg & IP6F_MORE_FRAG)>0) \
))
- val: IPv6 header
Typedef defining the user defined callback function:
typedef void(*pipv6_dfcallback_t) ( pntoh_ipv6_flow_t flow , pntoh_ipv6_tuple4_t tuple4, unsigned char* data, size_t len, unsigned short reason);
- flow: IPv6 flow where the defragmented datagrams of the sent datagram where stored
- tuple4: Tuple4 identifying the flow
- data: Defragmented datagram
- len: Total length of the defragmented datagram (IPv6 header + payload)
- reason: Why the datagram is sent?
Unlike TCP reassembly, IPv6 defragmentation only store the information of the sender.
Possible values for "reason" parameter:
- NTOH_REASON_DEFRAGMENTED_DATAGRAM
- NTOH_REASON_TIMEDOUT_FRAGMENTS