FreeBSD kernel IPv4 code
SCTP Packet Parsing

Macros

#define SN_SCTP_FIRSTCHUNK(sctphead)   (struct sctp_chunkhdr *)(((char *)sctphead) + sizeof(struct sctphdr))
 
#define SN_SCTP_NEXTCHUNK(chunkhead)   (struct sctp_chunkhdr *)(((char *)chunkhead) + SCTP_SIZE32(ntohs(chunkhead->chunk_length)))
 
#define SN_SCTP_NEXTPARAM(param)   (struct sctp_paramhdr *)(((char *)param) + SCTP_SIZE32(ntohs(param->param_length)))
 
#define SN_MIN_CHUNK_SIZE   4
 
#define SN_MIN_PARAM_SIZE   4
 
#define SN_VTAG_PARAM_SIZE   12
 
#define SN_ASCONFACK_PARAM_SIZE   8
 
#define SN_PARSE_OK   0
 
#define SN_PARSE_ERROR_IPSHL   1
 
#define SN_PARSE_ERROR_AS_MALLOC   2
 
#define SN_PARSE_ERROR_CHHL   3
 
#define SN_PARSE_ERROR_DIR   4
 
#define SN_PARSE_ERROR_VTAG   5
 
#define SN_PARSE_ERROR_CHUNK   6
 
#define SN_PARSE_ERROR_PORT   7
 
#define SN_PARSE_ERROR_LOOKUP   8
 
#define SN_PARSE_ERROR_PARTIALLOOKUP   9
 
#define SN_PARSE_ERROR_LOOKUP_ABORT   10
 
#define SN_SCTP_ABORT   0x0000
 
#define SN_SCTP_INIT   0x0001
 
#define SN_SCTP_INITACK   0x0002
 
#define SN_SCTP_SHUTCOMP   0x0010
 
#define SN_SCTP_SHUTACK   0x0020
 
#define SN_SCTP_ASCONF   0x0100
 
#define SN_SCTP_ASCONFACK   0x0200
 
#define SN_SCTP_OTHER   0xFFFF
 

Functions

static int sctp_PktParser (struct libalias *la, int direction, struct ip *pip, struct sctp_nat_msg *sm, struct sctp_nat_assoc **passoc)
 Parses SCTP packets for the key SCTP chunk that will be processed. More...
 
static int GetAsconfVtags (struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, uint32_t *g_vtag, int direction)
 Extract Vtags from Asconf Chunk. More...
 
static void AddGlobalIPAddresses (struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction)
 AddGlobalIPAddresses from Init,InitAck,or AddIP packets. More...
 
static void RmGlobalIPAddresses (struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction)
 RmGlobalIPAddresses from DelIP packets. More...
 
static int IsASCONFack (struct libalias *la, struct sctp_nat_msg *sm, int direction)
 Check that ASCONF was successful. More...
 
static int IsADDorDEL (struct libalias *la, struct sctp_nat_msg *sm, int direction)
 Check to see if ASCONF contains an Add IP or Del IP parameter. More...
 

Detailed Description

Macros to:

These functions parse the SCTP packet and fill a sctp_nat_msg structure with the parsed contents.

Macro Definition Documentation

◆ SN_ASCONFACK_PARAM_SIZE

#define SN_ASCONFACK_PARAM_SIZE   8

Size of SCTP ASCONF ACK param in bytes

Definition at line 224 of file alias_sctp.c.

◆ SN_MIN_CHUNK_SIZE

#define SN_MIN_CHUNK_SIZE   4

Smallest possible SCTP chunk size in bytes

Definition at line 221 of file alias_sctp.c.

◆ SN_MIN_PARAM_SIZE

#define SN_MIN_PARAM_SIZE   4

Smallest possible SCTP param size in bytes

Definition at line 222 of file alias_sctp.c.

◆ SN_PARSE_ERROR_AS_MALLOC

#define SN_PARSE_ERROR_AS_MALLOC   2

Packet parsing error - assoc malloc

Definition at line 229 of file alias_sctp.c.

◆ SN_PARSE_ERROR_CHHL

#define SN_PARSE_ERROR_CHHL   3

Packet parsing error - Chunk header len

Definition at line 230 of file alias_sctp.c.

◆ SN_PARSE_ERROR_CHUNK

#define SN_PARSE_ERROR_CHUNK   6

Packet parsing error - Chunk

Definition at line 233 of file alias_sctp.c.

◆ SN_PARSE_ERROR_DIR

#define SN_PARSE_ERROR_DIR   4

Packet parsing error - Direction

Definition at line 231 of file alias_sctp.c.

◆ SN_PARSE_ERROR_IPSHL

#define SN_PARSE_ERROR_IPSHL   1

Packet parsing error - IP and SCTP common header len

Definition at line 228 of file alias_sctp.c.

◆ SN_PARSE_ERROR_LOOKUP

#define SN_PARSE_ERROR_LOOKUP   8

Packet parsing error - Lookup

Definition at line 235 of file alias_sctp.c.

◆ SN_PARSE_ERROR_LOOKUP_ABORT

#define SN_PARSE_ERROR_LOOKUP_ABORT   10

Packet parsing error - Lookup - but abort packet

Definition at line 237 of file alias_sctp.c.

◆ SN_PARSE_ERROR_PARTIALLOOKUP

#define SN_PARSE_ERROR_PARTIALLOOKUP   9

Packet parsing error - partial lookup only found

Definition at line 236 of file alias_sctp.c.

◆ SN_PARSE_ERROR_PORT

#define SN_PARSE_ERROR_PORT   7

Packet parsing error - Port=0

Definition at line 234 of file alias_sctp.c.

◆ SN_PARSE_ERROR_VTAG

#define SN_PARSE_ERROR_VTAG   5

Packet parsing error - Vtag

Definition at line 232 of file alias_sctp.c.

◆ SN_PARSE_OK

#define SN_PARSE_OK   0

Packet parsed for SCTP messages

Definition at line 227 of file alias_sctp.c.

◆ SN_SCTP_ABORT

#define SN_SCTP_ABORT   0x0000

a packet containing an ABORT chunk

Definition at line 240 of file alias_sctp.c.

◆ SN_SCTP_ASCONF

#define SN_SCTP_ASCONF   0x0100

a packet containing an ASCONF chunk

Definition at line 245 of file alias_sctp.c.

◆ SN_SCTP_ASCONFACK

#define SN_SCTP_ASCONFACK   0x0200

a packet containing an ASCONF-ACK chunk

Definition at line 246 of file alias_sctp.c.

◆ SN_SCTP_FIRSTCHUNK

#define SN_SCTP_FIRSTCHUNK (   sctphead)    (struct sctp_chunkhdr *)(((char *)sctphead) + sizeof(struct sctphdr))

Returns a pointer to the first chunk in an SCTP packet given a pointer to the SCTP header

Definition at line 211 of file alias_sctp.c.

◆ SN_SCTP_INIT

#define SN_SCTP_INIT   0x0001

a packet containing an INIT chunk

Definition at line 241 of file alias_sctp.c.

◆ SN_SCTP_INITACK

#define SN_SCTP_INITACK   0x0002

a packet containing an INIT-ACK chunk

Definition at line 242 of file alias_sctp.c.

◆ SN_SCTP_NEXTCHUNK

#define SN_SCTP_NEXTCHUNK (   chunkhead)    (struct sctp_chunkhdr *)(((char *)chunkhead) + SCTP_SIZE32(ntohs(chunkhead->chunk_length)))

Returns a pointer to the next chunk in an SCTP packet given a pointer to the current chunk

Definition at line 215 of file alias_sctp.c.

◆ SN_SCTP_NEXTPARAM

#define SN_SCTP_NEXTPARAM (   param)    (struct sctp_paramhdr *)(((char *)param) + SCTP_SIZE32(ntohs(param->param_length)))

Returns a pointer to the next parameter in an SCTP packet given a pointer to the current parameter

Definition at line 219 of file alias_sctp.c.

◆ SN_SCTP_OTHER

#define SN_SCTP_OTHER   0xFFFF

a packet containing a chunk that is not of interest

Definition at line 247 of file alias_sctp.c.

◆ SN_SCTP_SHUTACK

#define SN_SCTP_SHUTACK   0x0020

a packet containing a SHUTDOWN-ACK chunk

Definition at line 244 of file alias_sctp.c.

◆ SN_SCTP_SHUTCOMP

#define SN_SCTP_SHUTCOMP   0x0010

a packet containing a SHUTDOWN-COMPLETE chunk

Definition at line 243 of file alias_sctp.c.

◆ SN_VTAG_PARAM_SIZE

#define SN_VTAG_PARAM_SIZE   12

Size of SCTP ASCONF vtag param in bytes

Definition at line 223 of file alias_sctp.c.

Function Documentation

◆ AddGlobalIPAddresses()

static void AddGlobalIPAddresses ( struct sctp_nat_msg sm,
struct sctp_nat_assoc assoc,
int  direction 
)
static

AddGlobalIPAddresses from Init,InitAck,or AddIP packets.

AddGlobalIPAddresses scans an SCTP chunk (in sm) for Global IP addresses, and adds them.

Parameters
smPointer to sctp message information
assocPointer to the association this SCTP Message belongs to
directionSN_TO_LOCAL | SN_TO_GLOBAL

Definition at line 1342 of file alias_sctp.c.

◆ GetAsconfVtags()

static int GetAsconfVtags ( struct libalias la,
struct sctp_nat_msg sm,
uint32_t l_vtag,
uint32_t g_vtag,
int  direction 
)
static

Extract Vtags from Asconf Chunk.

GetAsconfVtags scans an Asconf Chunk for the vtags parameter, and then extracts the vtags.

GetAsconfVtags is not called from within sctp_PktParser. It is called only from within ID_process when an AddIP has been received.

Parameters
laPointer to the relevant libalias instance
smPointer to sctp message information
l_vtagPointer to the local vtag in the association this SCTP Message belongs to
g_vtagPointer to the local vtag in the association this SCTP Message belongs to
directionSN_TO_LOCAL | SN_TO_GLOBAL
Returns
1 - success | 0 - fail

Definition at line 1274 of file alias_sctp.c.

◆ IsADDorDEL()

static int IsADDorDEL ( struct libalias la,
struct sctp_nat_msg sm,
int  direction 
)
static

Check to see if ASCONF contains an Add IP or Del IP parameter.

IsADDorDEL scans an ASCONF packet to see if it contains an AddIP or DelIP parameter

Parameters
laPointer to the relevant libalias instance
smPointer to sctp message information
directionSN_TO_LOCAL | SN_TO_GLOBAL
Returns
SCTP_ADD_IP_ADDRESS | SCTP_DEL_IP_ADDRESS | 0 - fail

Definition at line 1666 of file alias_sctp.c.

◆ IsASCONFack()

static int IsASCONFack ( struct libalias la,
struct sctp_nat_msg sm,
int  direction 
)
static

Check that ASCONF was successful.

Each ASCONF configuration parameter carries a correlation ID which should be matched with an ASCONFack. This is difficult for a NAT, since every association could potentially have a number of outstanding ASCONF configuration parameters, which should only be activated on receipt of the ACK.

Currently we only look for an ACK when the NAT is setting up a new association (ie AddIP for a connection that the NAT does not know about because the original Init went through a public interface or another NAT) Since there is currently no connection on this path, there should be no other ASCONF configuration parameters outstanding, so we presume that if there is an ACK that it is responding to the AddIP and activate the new association.

Parameters
laPointer to the relevant libalias instance
smPointer to sctp message information
directionSN_TO_LOCAL | SN_TO_GLOBAL
Returns
1 - success | 0 - fail

Definition at line 1612 of file alias_sctp.c.

◆ RmGlobalIPAddresses()

static void RmGlobalIPAddresses ( struct sctp_nat_msg sm,
struct sctp_nat_assoc assoc,
int  direction 
)
static

RmGlobalIPAddresses from DelIP packets.

RmGlobalIPAddresses scans an ASCONF chunk for DelIP parameters to remove the given Global IP addresses from the association. It will not delete the the address if it is a list of one address.

Parameters
smPointer to sctp message information
assocPointer to the association this SCTP Message belongs to
directionSN_TO_LOCAL | SN_TO_GLOBAL

Definition at line 1505 of file alias_sctp.c.

◆ sctp_PktParser()

static int sctp_PktParser ( struct libalias la,
int  direction,
struct ip pip,
struct sctp_nat_msg sm,
struct sctp_nat_assoc **  passoc 
)
static

Parses SCTP packets for the key SCTP chunk that will be processed.

This module parses SCTP packets for the key SCTP chunk that will be processed The module completes the sctp_nat_msg structure and either retrieves the relevant (existing) stored association from the Hash Tables or creates a new association entity with state SN_ID

Parameters
laPointer to the relevant libalias instance
directionSN_TO_LOCAL | SN_TO_GLOBAL
pip
smPointer to sctp message information
passocPointer to the association this SCTP Message belongs to
Returns
SN_PARSE_OK | SN_PARSE_ERROR_*

Definition at line 1050 of file alias_sctp.c.

References sctpChunkOfInt::Asconf, sctp_chunkhdr::chunk_flags, sctp_nat_msg::chunk_length, sctp_chunkhdr::chunk_length, sctp_chunkhdr::chunk_type, sctphdr::dest_port, FindSctpGlobal(), FindSctpGlobalT(), FindSctpLocal(), FindSctpLocalT(), sctpChunkOfInt::Init, sctpChunkOfInt::InitAck, ip::ip_dst, sctp_nat_msg::ip_hdr, ip::ip_hl, ip::ip_len, IS_SCTP_CONTROL, sctp_nat_msg::msg, sctp_paramhdr::param_type, in_addr::s_addr, SCTP_ABORT_ASSOCIATION, SCTP_ASCONF, SCTP_ASCONF_ACK, SCTP_HAD_NO_TCB, sctp_nat_msg::sctp_hdr, sctp_init_ack, sctp_init_ack_chunk, SCTP_INITIATION, SCTP_INITIATION_ACK, SCTP_IPV4_ADDRESS, SCTP_SHUTDOWN_ACK, SCTP_SHUTDOWN_COMPLETE, SCTP_SIZE32, sctp_nat_msg::sctpchnk, SN_ID, SN_MIN_CHUNK_SIZE, SN_NULL_TBL, SN_PARSE_ERROR_AS_MALLOC, SN_PARSE_ERROR_CHHL, SN_PARSE_ERROR_IPSHL, SN_PARSE_ERROR_LOOKUP, SN_PARSE_ERROR_LOOKUP_ABORT, SN_PARSE_ERROR_PARTIALLOOKUP, SN_PARSE_ERROR_PORT, SN_PARSE_ERROR_VTAG, SN_PARSE_OK, SN_SCTP_ABORT, SN_SCTP_ASCONF, SN_SCTP_ASCONFACK, SN_SCTP_FIRSTCHUNK, SN_SCTP_INIT, SN_SCTP_INITACK, SN_SCTP_NEXTCHUNK, SN_SCTP_OTHER, SN_SCTP_SHUTACK, SN_SCTP_SHUTCOMP, SN_TO_LOCAL, sctphdr::src_port, sctp_nat_assoc::state, sysctl_chunk_proc_limit, sysctl_initialising_chunk_proc_limit, and sctphdr::v_tag.

Here is the call graph for this function: