Microchip® Advanced Software Framework

ip6_frag.c File Reference

IPv6 fragmentation and reassembly.

#include "lwip/opt.h"
#include "lwip/ip6_frag.h"
#include "lwip/ip6.h"
#include "lwip/icmp6.h"
#include "lwip/nd6.h"
#include "lwip/ip.h"
#include "lwip/pbuf.h"
#include "lwip/memp.h"
#include "lwip/stats.h"
#include <string.h>

Data Structures

struct  ip6_reass_helper
 This is a helper struct which holds the starting offset and the ending offset of this fragment to easily chain the fragments. More...
 

Macros

#define IP_REASS_CHECK_OVERLAP   1
 Setting this to 0, you can turn off checking the fragments for overlapping regions. More...
 
#define IP_REASS_FLAG_LASTFRAG   0x01
 
#define IP_REASS_FREE_OLDEST   1
 Set to 0 to prevent freeing the oldest datagram when the reassembly buffer is full (IP_REASS_MAX_PBUFS pbufs are enqueued). More...
 

Functions

struct pbufip6_reass (struct pbuf *p)
 Reassembles incoming IPv6 fragments into an IPv6 datagram. More...
 
static void ip6_reass_free_complete_datagram (struct ip6_reassdata *ipr)
 Free a datagram (struct ip6_reassdata) and all its pbufs. More...
 
static void ip6_reass_remove_oldest_datagram (struct ip6_reassdata *ipr, int pbufs_needed)
 Free the oldest datagram to make room for enqueueing new fragments. More...
 
void ip6_reass_tmr (void)
 

Variables

static u16_t ip6_reass_pbufcount
 
PACK_STRUCT_BEGIN struct
ip6_reass_helper 
PACK_STRUCT_STRUCT
 
static PACK_STRUCT_END struct
ip6_reassdata
reassdatagrams
 

#define IP_REASS_CHECK_OVERLAP   1

Setting this to 0, you can turn off checking the fragments for overlapping regions.

The code gets a little smaller. Only use this if you know that overlapping won't occur on your network!

#define IP_REASS_FLAG_LASTFRAG   0x01
#define IP_REASS_FREE_OLDEST   1

Set to 0 to prevent freeing the oldest datagram when the reassembly buffer is full (IP_REASS_MAX_PBUFS pbufs are enqueued).

The code gets a little smaller. Datagrams will be freed by timeout only. Especially useful when MEMP_NUM_REASSDATA is set to 1, so one datagram can be reassembled at a time, only.

struct pbuf* ip6_reass ( struct pbuf p)

Reassembles incoming IPv6 fragments into an IPv6 datagram.

Parameters
ppoints to the IPv6 Fragment Header
lenthe length of the payload (after Fragment Header)
Returns
NULL if reassembly is incomplete, pbuf pointing to IPv6 Header if reassembly is complete

References ip6_reassdata::datagram_len, htons, ip6_reassdata::identification, if(), ip6_addr_cmp, ip6_current_dest_addr, ip6_current_header, ip6_current_src_addr, IP6_FRAG_HLEN, IP6_FRAG_MORE_FLAG, IP6_FRAG_OFFSET_MASK, IP6_FRAG_STATS_INC, IP6_HLEN, ip6_reass_pbufcount, ip6_reass_remove_oldest_datagram(), ip6_reassdata::iphdr, LWIP_ASSERT, memp_free(), memp_malloc(), ip6_reassdata::next, ip6_reassdata::nexth, ntohs, NULL, ip6_reassdata::p, pbuf::payload, pbuf_cat(), pbuf_clen(), pbuf_free(), pbuf_header(), reassdatagrams, and ip6_reassdata::timer.

Referenced by ip6_input().

static void ip6_reass_free_complete_datagram ( struct ip6_reassdata ipr)
static

Free a datagram (struct ip6_reassdata) and all its pbufs.

Updates the total count of enqueued pbufs (ip6_reass_pbufcount), sends an ICMP time exceeded packet.

Parameters
iprdatagram to free

References ICMP6_TE_FRAG, icmp6_time_exceeded(), if(), ip6_reass_pbufcount, ip6_reassdata::iphdr, LWIP_ASSERT, memp_free(), ip6_reassdata::next, NULL, ip6_reassdata::p, pbuf::payload, pbuf_clen(), pbuf_free(), pbuf_header(), and reassdatagrams.

Referenced by ip6_reass_remove_oldest_datagram(), and ip6_reass_tmr().

static void ip6_reass_remove_oldest_datagram ( struct ip6_reassdata ipr,
int  pbufs_needed 
)
static

Free the oldest datagram to make room for enqueueing new fragments.

The datagram ipr is not freed!

Parameters
iprip6_reassdata for the current fragment
pbufs_needednumber of pbufs needed to enqueue (used for freeing other datagrams if not enough space)

References ip6_reass_free_complete_datagram(), ip6_reass_pbufcount, ip6_reassdata::next, NULL, reassdatagrams, and ip6_reassdata::timer.

Referenced by ip6_reass().

PACK_STRUCT_BEGIN struct ip6_reass_helper PACK_STRUCT_STRUCT