embedded IPsec source code documentation


util.c File Reference


Detailed Description

A collection of common helper functions and macros used everywhere in the IPsec library.

Author:
Niklaus Schild <n.schild@gmx.ch>
OUTLINE: The following functions are implemented in this module:
  • logging

IMPLEMENTATION:

There are no implementation hints to be mentioned.

NOTES:

This document is part of embedded IPsec
Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne
All rights reserved.
This file contains code from the lwIP project by Adam Dunkels and others
Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
All rights reserved.


Definition in file util.c.

#include <string.h>
#include <ctype.h>
#include "ipsec/ipsec.h"
#include "ipsec/util.h"
#include "ipsec/debug.h"

Go to the source code of this file.

Functions

void ipsec_print_ip (ipsec_ip_header *header)
__u32 ipsec_inet_addr (const char *cp)
int ipsec_inet_aton (const char *cp, struct ipsec_in_addr *addr)
__u8ipsec_inet_ntoa (__u32 addr)
__u16 ipsec_htons (__u16 n)
__u16 ipsec_ntohs (__u16 n)
__u32 ipsec_htonl (__u32 n)
__u32 ipsec_ntohl (__u32 n)
__u16 chksum (void *dataptr, int len)
__u16 ipsec_ip_chksum (void *dataptr, __u16 len)
void ipsec_dump_buffer (char *prefix, unsigned char *data, int offs, int length)
ipsec_audit ipsec_check_replay_window (__u32 seq, __u32 lastSeq, __u32 bitField)
ipsec_audit ipsec_update_replay_window (__u32 seq, __u32 *lastSeq, __u32 *bitField)


Function Documentation

__u16 chksum void *  dataptr,
int  len
[static]
 

helper function to calculate the IP header checksum

Parameters:
len length of the buffer
dataptr pointer the buffer
Returns:
16-bit value of the checksum

Definition at line 322 of file util.c.

ipsec_audit ipsec_check_replay_window __u32  seq,
__u32  lastSeq,
__u32  bitField
 

Verify the sequence number of the AH packet is inside the window (defined as IPSEC_SEQ_MAX_WINDOW) Note: this function does NOT update the lastSeq variable and may safely be called prior to IVC check.

Parameters:
seq sequence number of the current packet
lastSeq sequence number of the last known packet
bitField field used to verify resent data within the window
Returns:
IPSEC_AUDIT_SUCCESS if check passed (packet allowed)

IPSEC_AUDIT_SEQ_MISMATCH if check failed (packet disallowed)

Definition at line 431 of file util.c.

void ipsec_dump_buffer char *  prefix,
unsigned char *  data,
int  offs,
int  length
 

Dump (print) a memory location

Parameters:
prefix print this text at the beginning of each line
data pointer the buffer which should be printed
offs offset from the buffer's start address
length number of bytes to be printed initialized with IP, netmask and gateway address.
Returns:
void

Definition at line 381 of file util.c.

__u32 ipsec_htonl __u32  n  ) 
 

Converts long types from host to network order

Parameters:
n long value in host order
Returns:
long value in network order

Definition at line 296 of file util.c.

__u16 ipsec_htons __u16  n  ) 
 

Converts short types from host to network order

Parameters:
n short value in host order
Returns:
short value in network order

Definition at line 274 of file util.c.

__u32 ipsec_inet_addr const char *  cp  ) 
 

Converts an IP address from the dotted notation into a 32-bit network order

Parameters:
cp IP address in dotted notation
Returns:
address in network order

IP_ADDR_NONE on failure the return value has all bits set to 1

Definition at line 117 of file util.c.

int ipsec_inet_aton const char *  cp,
struct ipsec_in_addr addr
 

Converts an IP address from dotted notation into a 32-bit value. This function is used by inet_addr().

Parameters:
cp IP address in dotted notation
addr binary IP address
Returns:
1 Address is valid

0 Address is not valid

Definition at line 136 of file util.c.

__u8* ipsec_inet_ntoa __u32  addr  ) 
 

Converts an binary IP address to a dotted notation Beware that this function is not reentrant.

Parameters:
addr binary IP address
Returns:
pointer to the character string representing the dotted notation

Definition at line 240 of file util.c.

__u16 ipsec_ip_chksum void *  dataptr,
__u16  len
 

calculates the checksum of the IP header

Parameters:
dataptr pointer to the buffer
len length of the buffer
Returns:
16-bit value of the checksum

Definition at line 354 of file util.c.

__u32 ipsec_ntohl __u32  n  ) 
 

Converts long types from network to host order

Parameters:
n long value in network order
Returns:
long value in host order

Definition at line 310 of file util.c.

__u16 ipsec_ntohs __u16  n  ) 
 

Converts short types from network to host order

Parameters:
n short value in network order
Returns:
short value in host order

Definition at line 285 of file util.c.

void ipsec_print_ip ipsec_ip_header header  ) 
 

Prints the header of an IP packet

Parameters:
header pointer to an IP header
Returns:
void

Definition at line 69 of file util.c.

ipsec_audit ipsec_update_replay_window __u32  seq,
__u32 lastSeq,
__u32 bitField
 

Verify and update the sequence number. Note: this function is UPDATING the lastSeq variable and must be called only AFTER checking the IVC.

This code is based on RFC2401, Appendix C -- Sequence Space Window Code Example

Parameters:
seq sequence number of the current packet
lastSeq pointer to sequence number of the last known packet
bitField pointer to field used to verify resent data within the window
Returns:
IPSEC_AUDIT_SUCCESS if check passed (packet allowed)

IPSEC_AUDIT_SEQ_MISMATCH if check failed (packet disallowed)

Definition at line 468 of file util.c.


Copyright 2003 by Christian Scheurer and Niklaus Schild