reassembler_packet.c File Reference

Relating to processing packets in the fast path. More...

#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#include <sys/limits.h>
#include <isc/eventlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <jnx/aux_types.h>
#include <jnx/bits.h>
#include <jnx/mpsdk.h>
#include <jnx/msp_objcache.h>
#include <jnx/atomic.h>
#include <jnx/msp_locks.h>
#include <sys/jnx/jbuf.h>
#include "reassembler_logging.h"
#include "reassembler_packet.h"

Go to the source code of this file.

Data Structures

struct  fragment_hole_s
struct  fragment_entry_s
struct  hashtable_s

Defines

#define SHARED_MEM_NAME   "reassembler arena"
 shared mem name
#define HASHTABLE_NAME   "reassembler hash table"
 table o.c. name
#define TABLE_ENTRY_NAME   "reassembler table entry"
 entry o.c. name
#define FRAGMENT_ENTRY_NAME   "reassembler fragment entry"
 frag o.c. name
#define ENTRY_AGE_CHECK_INTERVAL   5
 run aging routine interval in seconds
#define MAX_MSP_SEND_RETRIES   100
 Max msp_data_send retries before panic.
#define MIN_FIFO_DEPTH   1023
 Minimum FIFO depth (used with max # of dCPUs).
#define BYTES_PER_FRAG_BLOCK   8
 Bytes in a fragment block (for frag offset).
#define WORDS_PER_FRAG_BLOCK   2
 Words in a fragment block (for frag offset).
#define FLOW_BUCKET_COUNT   (1024 * 64)

Typedefs

typedef fragment_hole_s fragment_hole_t
typedef fragment_entry_s fragment_entry_t
typedef hashtable_s hashtable_t

Functions

typedef TAILQ_HEAD (fragment_list_s, fragment_entry_s)
typedef TAILQ_HEAD (ht_bucket_list_s, table_entry_s)
static void aging_cleanup (evContext ctx UNUSED, void *uap UNUSED, struct timespec due UNUSED, struct timespec inter UNUSED)
static void checksum_adjust (unsigned char *chksum, unsigned char *optr, int olen, unsigned char *nptr, int nlen)
static void send_packet (struct jbuf *pkt_buf, const msp_data_handle_t const *handle)
static status_t pullup_bytes (struct jbuf **pkt_buf, uint16_t num_bytes)
static void send_fragment_list (table_entry_t *entry, const int cpu, const msp_data_handle_t const *handle)
static status_t process_fragment (struct jbuf *pkt_buf, const int cpu, const msp_data_handle_t const *handle)
static void * reassembler_process_packet (msp_dataloop_args_t *params)
status_t init_packet_loops (evContext ctx)
void stop_packet_loops (evContext ctx)

Variables

const uint32_t HASH_MASK = FLOW_BUCKET_COUNT - 1
 table_entry_t
 hash_bucket_t
uint16_t reassembler_mtu
 the configured MTU
static evTimerID aging_timer
 timer set to do aging and cleanup
static msp_shm_handle_t shm_handle
 handle for shared memory allocator
static msp_oc_handle_t table_handle
 handle for OC table allocator
static msp_oc_handle_t entry_handle
 handle for OC table entry allocator
static msp_oc_handle_t frag_handle
 handle for OC frag entry allocator
static hashtable_tflows_table
 pointer to the hashtable of flows
static atomic_uint_t loops_running
 # of data loops running
static volatile uint8_t do_shutdown
 do the data loops need to shutdown
static uint32_t obj_cache_id
 ID for OC memory tracking.


Detailed Description

Relating to processing packets in the fast path.

These functions and types will manage the packet processing in the data path

Definition in file reassembler_packet.c.


Define Documentation

#define FLOW_BUCKET_COUNT   (1024 * 64)

The number of buckets; must be a power of 2, currently 2^16

Definition at line 70 of file reassembler_packet.c.

Referenced by aging_cleanup(), and init_packet_loops().


Typedef Documentation

typedef struct fragment_entry_s fragment_entry_t

fragment entry list item information structure

typedef struct fragment_hole_s fragment_hole_t

fragment hole information structure

Note:
fragment blocks are 8 bytes

typedef struct hashtable_s hashtable_t

A hashtable for the flows_table

In the hashtable the KEY fields are hashed to lookup a bucket, then within the bucket list an input search KEY must match exactly with an existing entry's KEY (i.e. all KEY fields).

The hashtable value is the whole table entry (in which the key info is also stored).


Function Documentation

static void aging_cleanup ( evContext ctx  UNUSED,
void *uap  UNUSED,
struct timespec due  UNUSED,
struct timespec inter  UNUSED 
) [static]

Callback to periodically age out entries in our flows_table and cleanup shared memory

Parameters:
[in] ctx The event context for this application
[in] uap The user data for this callback
[in] due The absolute time when the event is due (now)
[in] inter The period; when this will next be called

Definition at line 196 of file reassembler_packet.c.

References entry_handle, FLOW_BUCKET_COUNT, flows_table, hashtable_s::hash_bucket, hash_bucket_t, obj_cache_id, and table_entry_t.

Referenced by init_packet_loops().

static void checksum_adjust ( unsigned char *  chksum,
unsigned char *  optr,
int  olen,
unsigned char *  nptr,
int  nlen 
) [static]

This function will adjust a checksum. It is taken directly from the NAT RFC 3022. The algorithm below is applicable only for even offsets (i.e. optr below must be at an even offset from start of header) and even lengths (i.e. olen and nlen below must be even).

Parameters:
[in,out] chksum Checksum
[in] optr Pointer to old data to scan
[in] olen Length of old data to scan
[in] nptr Pointer to old data to scan
[in] nlen Length of new data to scan

Definition at line 279 of file reassembler_packet.c.

Referenced by send_fragment_list().

status_t init_packet_loops ( evContext  ctx  ) 

Start packet loops, one per available data core

Parameters:
[in] ctx event context from master thread used for cleanup timer

Definition at line 1182 of file reassembler_packet.c.

References aging_cleanup(), aging_timer, do_shutdown, ENTRY_AGE_CHECK_INTERVAL, entry_handle, FLOW_BUCKET_COUNT, flows_table, frag_handle, FRAGMENT_ENTRY_NAME, hashtable_s::hash_bucket, HASHTABLE_NAME, loops_running, MIN_FIFO_DEPTH, obj_cache_id, reassembler_process_packet(), SHARED_MEM_NAME, shm_handle, TABLE_ENTRY_NAME, table_entry_t, and table_handle.

Referenced by reassembler_init().

static status_t process_fragment ( struct jbuf *  pkt_buf,
const int  cpu,
const msp_data_handle_t const *  handle 
) [static]

Process an IP fragment and do reassembly as necessary. The input packet must be a fragment. The more fragment bit or the fragment offset must be set. If the packet overlaps with something already seen, we keep the older data. Frees the input jbuf. Sends the reassembled packet according to the send_fragment_list function on reassembly completion.

Parameters:
[in] pkt_buf The current jbuf that we received; will be sent or dropped in here
[in] cpu The current CPU; used in objcache operations
[in] handle The data handle for the current dCPU/FIFO; used to send packet
Returns:
SUCCESS reassembly succeeded; EFAIL failure occured with a log msg

Definition at line 622 of file reassembler_packet.c.

References BYTES_PER_FRAG_BLOCK, entry_handle, flows_table, frag_handle, hashtable_s::hash_bucket, hash_bucket_t, HASH_MASK, obj_cache_id, send_fragment_list(), and table_entry_t.

Referenced by reassembler_process_packet().

static status_t pullup_bytes ( struct jbuf **  pkt_buf,
uint16_t  num_bytes 
) [static]

Ensure or pullup enough data into the first jbuf of the chain in order to analyze it better where the bytes are contiguous

Parameters:
[in] pkt_buf The packet in jbuf format (chain of jbufs)
[in] num_bytes The number of contiguous bytes of data required in the first jbuf
Returns:
Returns the result of the jbuf_pullup on the pkt_buf upon SUCCESS; otherwise pkt_buf remains unchanged and EFAIL is returned

Definition at line 366 of file reassembler_packet.c.

Referenced by reassembler_process_packet(), and send_fragment_list().

static void* reassembler_process_packet ( msp_dataloop_args_t *  params  )  [static]

Entry point for packet processing threads (function passed to msp_data_create_loop_on_cpu)

Parameters:
[in] params dataloop parameters with user data, loop identifier, and loop number

Definition at line 1107 of file reassembler_packet.c.

References do_shutdown, loops_running, process_fragment(), pullup_bytes(), and send_packet().

Referenced by init_packet_loops().

static void send_fragment_list ( table_entry_t entry,
const int  cpu,
const msp_data_handle_t const *  handle 
) [static]

Process a fragment list in the given table entry and send out the reassembled packet held in the list. If the total length exceeds the configured MTU (reassembler_mtu), then re-fragment at nearest 8-byte boundary <= reassembler_mtu. The fragment list is emptied and freed. Any errors are logged, but list is freed regardless.

Parameters:
[in] entry The table entry with the fragment list to use
[in] handle The data handle for the current dCPU/FIFO; used to send packet

Definition at line 397 of file reassembler_packet.c.

References BYTES_PER_FRAG_BLOCK, checksum_adjust(), frag_handle, fragment_entry_s::jb, obj_cache_id, pullup_bytes(), reassembler_mtu, and send_packet().

Referenced by process_fragment().

static void send_packet ( struct jbuf *  pkt_buf,
const msp_data_handle_t const *  handle 
) [static]

Send the packet or other message; frees the packet upon failure

Parameters:
[in] pkt_buf The packet in jbuf format as we received it
[in] handle The handle for the data loop

Definition at line 318 of file reassembler_packet.c.

References MAX_MSP_SEND_RETRIES.

Referenced by reassembler_process_packet(), and send_fragment_list().

void stop_packet_loops ( evContext  ctx  ) 

Cleanup data loops for shutdown

Parameters:
[in] ctx event context from master thread used for cleanup timer

Definition at line 1362 of file reassembler_packet.c.

References aging_timer, do_shutdown, entry_handle, flows_table, loops_running, obj_cache_id, and table_handle.

Referenced by reassembler_quit().

typedef TAILQ_HEAD ( ht_bucket_list_s  ,
table_entry_s   
)

A bucket in a hashtable_t

< lock for this bucket

< list of entries in bucket

Definition at line 136 of file reassembler_packet.c.

typedef TAILQ_HEAD ( fragment_list_s  ,
fragment_entry_s   
)

table entry information structure

< entry lock

< entry age timestamp

< src IP address (HT KEY field)

< dest IP address (HT KEY field)

< frag group (ID) (HT KEY field)

< protocol (ID) (HT KEY field)

< flag to free entry

< total length of bytes in flist

< list of fragments and holes

< next and prev list entries

Definition at line 109 of file reassembler_packet.c.


Variable Documentation

const uint32_t HASH_MASK = FLOW_BUCKET_COUNT - 1

Our mask defining the width of our hash function

Definition at line 75 of file reassembler_packet.c.

Referenced by process_fragment().


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:27:07 2010 for SDK Your Net Corporation IP Fragment Reassembly Example: reassembler 1.0 by Doxygen 1.5.1