/* ****************************************************************************** * HEADER FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipike_payload_nat.h,v $ $Revision: 1.6.16.2 $ * $Source: /home/interpeak/CVSRoot/ipike/src/ipike_payload_nat.h,v $ * $Author: svc-cmnet $ $Date: 2013-03-13 07:45:26 $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Magnus Alstrom ****************************************************************************** */ #ifndef IPIKE_PAYLOAD_NAT_H #define IPIKE_PAYLOAD_NAT_H #include "ipike.h" #include "ipike_sadb.h" /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* NAT Discovery payload * NAT Original Address payload * * Payloads for discovering and handling of NAT traversal (RFC 3947) */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include "ipike_config.h" #include "ipike_payload.h" #ifdef __cplusplus extern "C" { #endif /* **************************************************************************** * 4 DEFINES **************************************************************************** */ #define IPIKE_NAT_DISCOVERY_HEADER_LENGTH sizeof(Ipike_nat_discovery_payload) #define IPIKE_NAT_DISCOVERY_MIN_LEN MD5_DIGEST_LENGTH #define IPIKE_NAT_DISCOVERY_MAX_LEN SHA512_DIGEST_LENGTH #define IPIKE_NAT_ORG_ADDR_HEADER_LENGTH sizeof(Ipike_nat_org_addr_payload) #define IPIKE_NAT_ORG_ADDR_MIN_LEN 4 #define IPIKE_NAT_ORG_ADDR_MAX_LEN 16 /* **************************************************************************** * 5 TYPES **************************************************************************** */ /* NAT Discovery Payload Format 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ! Next Payload ! RESERVED ! Payload Length ! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ! ! ~ HASH of the address and port ~ ! ! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ typedef struct Ipike_payload_nat_discovery_struct { /* The generic ISAKMP payload header, the length includes the length of all transforms associated with the proposal */ Ipike_payload_header header; /* NAT discovery follows. Contains the NAT discovery data. */ } Ipike_nat_discovery_payload; /* NAT Orginal Address Format 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 +---------------+---------------+---------------+---------------+ | Next Payload | RESERVED | Payload length | +---------------+---------------+---------------+---------------+ | ID Type | RESERVED | RESERVED | +---------------+---------------+---------------+---------------+ | IPv4 (4 octets) or IPv6 address (16 octets) | +---------------+---------------+---------------+---------------+ */ typedef struct Ipike_payload_nat_org_addr_struct { /* The generic ISAKMP payload header, the length includes the length of all transforms associated with the proposal */ Ipike_payload_header header; Ip_u8 type; Ip_u8 reserved1; Ip_u16 reserved2; /* NAT original address follows. Contains the NAT origial address data. */ } Ipike_nat_org_addr_payload; /* **************************************************************************** * 6 FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipike_nat_discovery_new *=========================================================================== * Description: Creates a new nat_discovery payload. * Parameters: nat_discovery_data - nat discovery data. * nat_discovery_len - the length of the nat discovery. * Returns: A new nat discovery payload or IP_NULL if out of memory. * * */ IP_GLOBAL Ipike_nat_discovery_payload* ipike_nat_discovery_new( const Ip_u8* nat_discovery_data, Ip_u16 nat_discovery_len); /* *=========================================================================== * ipike_nat_discovery_create *=========================================================================== * Description: Creates a new nat discovery payload from the information * created in the exchange. * Parameters: nat_discovery - will point to a new nat discovery payload if * the call was successful. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_discovery_create( union Ip_sockaddr_union* address, Ip_u8* i_cookie, Ip_u8* r_cookie, Ip_u16 hash_alg, Ipike_nat_discovery_payload** nat_discovery); /* *=========================================================================== * ipike_nat_discovery_check_payload *=========================================================================== * Description: Verifies that the nat discovery payload is sane. * Parameters: nat_discovery - a pointer to a nat discovery payload. * Returns: IPIKE_SUCCESS * * */ IP_GLOBAL Ipike_error ipike_nat_discovery_check_payload(Ipike_nat_discovery_payload* nat_discovery); /* *=========================================================================== * ipike_nat_discovery_generate_pair *=========================================================================== * Description: Generate nat discovery data for source and destination. * Parameters: ike_sa - SA to initialize NAT discovery data. * hash_alg - Algorithm uses for generating data. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY */ IP_GLOBAL Ipike_error ipike_nat_discovery_generate_pair(Ipike_sadb_entry* ike_sa, Ip_u16 hash_alg); /* *=========================================================================== * ipike_nat_discovery_start *=========================================================================== * Description: Extracts the nat discovery data from the payload. * Parameters: ike_sa - SA to initialize for NAT discovery. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_discovery_start(Ipike_sadb_entry* ike_sa, Ip_u16 hash_alg); /* *=========================================================================== * ipike_nat_discovery_end *=========================================================================== * Description: Extracts the nat discovery data from the payload. * Parameters: ie - the exchange. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_discovery_end(Ipike_isakmp_exchange* ie); /* *=========================================================================== * ipike_nat_discovery_process *=========================================================================== * Description: Extracts the nat discovery data from the payload. * Parameters: ike_sa - SA to discover NAT for. * hash_alg - the used hash algorithm. * payload - a nat discovery payload. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_discovery_process( Ipike_sadb_entry* ike_sa, Ipike_nat_discovery_payload* payload); /* *=========================================================================== * ipike_nat_discovery_extract *=========================================================================== * Description: Extracts the nat discovery data from the payload. * Parameters: payload - a nat discovery payload. * nat_discovery - the nat discovery data will be added here if * the call was successful. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_discovery_extract( Ipike_nat_discovery_payload* payload, Ipike_value* nat_discovery); /* *=========================================================================== * ipike_nat_discovery_generate *=========================================================================== * Description: Generates the digest of the cookies, ip address and port. * nat_discovery - pointer to where the nat_discovery data * should be stored. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_discovery_generate( union Ip_sockaddr_union* address, Ip_u8* i_cookie, Ip_u8* r_cookie, Ip_u16 hash_alg, Ipike_value* nat_discovery); /* *=========================================================================== * ipike_nat_discovery_print_payload *=========================================================================== * Description: Prints the content of the nat discovery payload to the system * log. * Parameters: nat_discovery - a pointer to a nat discovery payload. * Returns: */ IP_GLOBAL void ipike_nat_discovery_print_payload(Ipike_nat_discovery_payload* nat_discovery); /* *=========================================================================== * ipike_nat_original_address_create *=========================================================================== * Description: Creates a new nat original address payload from the * information created in the exchange. * Parameters: nat_org_addr - will point to a new nat original address * payload if the call was successful. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_original_address_create( union Ip_sockaddr_union* address, Ipike_nat_org_addr_payload** nat_org_addr); /* *=========================================================================== * ipike_nat_original_address_check_payload *=========================================================================== * Description: Verifies that the nat original address payload is sane. * Parameters: nat_org_addr - a pointer to a nat original address payload. * Returns: IPIKE_SUCCESS * * */ IP_GLOBAL Ipike_error ipike_nat_original_address_check_payload( Ipike_nat_org_addr_payload* nat_org_addr); /* *=========================================================================== * ipike_nat_original_address_extract *=========================================================================== * Description: Extracts the nat original address data from the payload. * Parameters: payload - a nat original address payload. * nat_org_addr - the nat original address will be added * here if the call was successful. * Returns: IPIKE_SUCCESS * IPIKE_OUT_OF_MEMORY * */ IP_GLOBAL Ipike_error ipike_nat_original_address_extract( Ipike_nat_org_addr_payload* payload, union Ip_sockaddr_union* nat_org_addr); /* *=========================================================================== * ipike_nat_original_address_print_payload *=========================================================================== * Description: Prints the content of the nat original address payload to the * system log. * Parameters: nat_org_addr - a pointer to a nat original address payload. * Returns: * * */ IP_GLOBAL void ipike_nat_original_address_print_payload( Ipike_nat_org_addr_payload* nat_org_addr); #ifdef __cplusplus } #endif #endif /* **************************************************************************** * END OF FILE **************************************************************************** */