nat_traversal.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include "../../sr_module.h"
#include "../../mem/shm_mem.h"
#include "../../mem/mem.h"
#include "../../lock_ops.h"
#include "../../dprint.h"
#include "../../str.h"
#include "../../pvar.h"
#include "../../error.h"
#include "../../timer.h"
#include "../../resolve.h"
#include "../../data_lump.h"
#include "../../mod_fix.h"
#include "../../script_cb.h"
#include "../../parser/msg_parser.h"
#include "../../parser/parse_from.h"
#include "../../parser/parse_uri.h"
#include "../../parser/parse_expires.h"
#include "../../parser/contact/parse_contact.h"
#include "../dialog/dlg_load.h"
#include "../tm/tm_load.h"
#include "../sl/sl_cb.h"

Include dependency graph for nat_traversal.c:

Go to the source code of this file.

Data Structures

struct  Dialog_Param
struct  HashSlot
struct  HashTable
struct  Keepalive_Params
struct  NAT_Contact
struct  NatTest
struct  NetInfo
struct  SIP_Dialog

Defines

#define False   0
#define FROM_PREFIX   "sip:keepalive@"
#define HASH(table, key)   (hash_string(key) % (table)->size)
#define HASH_SIZE   512
#define INLINE   inline
#define is_private_address(x)   (rfc1918address(x)==1 ? 1 : 0)
#define max(a, b)   ((a)>(b) ? (a) : (b))
#define min(a, b)   ((a)<(b) ? (a) : (b))
#define STATE_FILE_HEADER   "# Automatically generated file from internal keepalive state. Do NOT modify!\n"
#define STR_HAS_IPREFIX(str, prefix)   ((str).len>(prefix).len && strncasecmp((prefix).s, (str).s, (prefix).len)==0)
#define STR_HAS_PREFIX(str, prefix)   ((str).len>(prefix).len && memcmp((prefix).s, (str).s, (prefix).len)==0)
#define STR_IMATCH(str, buf)   ((str).len==strlen(buf) && strncasecmp(buf, (str).s, (str).len)==0)
#define STR_IMATCH_STR(str, str2)   ((str).len==(str2).len && strncasecmp((str).s, (str2).s, (str).len)==0)
#define STR_MATCH(str, buf)   ((str).len==strlen(buf) && memcmp(buf, (str).s, (str).len)==0)
#define STR_MATCH_STR(str, str2)   ((str).len==(str2).len && memcmp((str).s, (str2).s, (str).len)==0)
#define True   1
#define URI_LIST_INITIAL_SIZE   8
#define URI_LIST_RESIZE_INCREMENT   8

Typedefs

typedef int Bool
typedef Bool(* NatTestFunction )(struct sip_msg *msg)

Enumerations

enum  NatTestType { NTNone = 0, NTPrivateContact = 1, NTSourceAddress = 2, NTPrivateVia = 4 }

Functions

static void __dialog_confirmed (struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
static void __dialog_created (struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
static void __dialog_destroy (struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
static void __dialog_early (struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
static void __sl_reply_out (unsigned int types, struct sip_msg *request, struct sl_cb_param *param)
static void __tm_reply_in (struct cell *trans, int type, struct tmcb_params *param)
static int ClientNatTest (struct sip_msg *msg, unsigned int tests)
static Bool Dialog_Param_add_candidate (Dialog_Param *param, char *candidate)
static void Dialog_Param_del (Dialog_Param *param)
static Bool Dialog_Param_has_candidate (Dialog_Param *param, char *candidate)
static Dialog_ParamDialog_Param_new (void)
static int FixContact (struct sip_msg *msg)
static Bool get_contact_uri (struct sip_msg *msg, struct sip_uri *uri, contact_t **_c)
static int get_expires (struct sip_msg *msg)
static time_t get_register_expire (struct sip_msg *request, struct sip_msg *reply)
static char * get_source_uri (struct sip_msg *msg)
static INLINE unsigned hash_string (const char *key)
static void HashTable_del (HashTable *table)
static HashTableHashTable_new (void)
static NAT_ContactHashTable_search (HashTable *table, char *uri, unsigned slot)
static void keepalive_registration (struct sip_msg *request, time_t expire)
static void keepalive_subscription (struct sip_msg *request, time_t expire)
static void keepalive_timer (unsigned int ticks, void *data)
static INLINE void ltrim (str *string)
static void mod_destroy (void)
static int mod_init (void)
static void NAT_Contact_del (NAT_Contact *contact)
static SIP_DialogNAT_Contact_get_dialog (NAT_Contact *contact, struct dlg_cell *dlg)
static Bool NAT_Contact_match (NAT_Contact *contact, const char *uri)
static NAT_ContactNAT_Contact_new (char *uri, struct socket_info *socket)
static NAT_ContactNAT_Contact_purge_expired (NAT_Contact *contact, time_t now)
static int NAT_Keepalive (struct sip_msg *msg)
static int preprocess_request (struct sip_msg *msg, void *param)
static int pv_get_keepalive_socket (struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
static int pv_get_source_uri (struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
static int pv_parse_nat_contact_name (pv_spec_p sp, str *in)
static int reply_filter (struct sip_msg *reply)
static void restore_keepalive_state (void)
static INLINE int rfc1918address (str *address)
static INLINE void rtrim (str *string)
static void save_keepalive_state (void)
static void send_keepalive (NAT_Contact *contact)
static INLINE char * shm_strdup (char *source)
static void SIP_Dialog_del (SIP_Dialog *dialog)
static INLINE void SIP_Dialog_end (SIP_Dialog *dialog)
static SIP_DialogSIP_Dialog_new (struct dlg_cell *dlg, time_t expire)
static SIP_DialogSIP_Dialog_purge_expired (SIP_Dialog *dialog, time_t now)
static INLINE void SIP_Registration_expire (NAT_Contact *contact, time_t now)
static INLINE void SIP_Registration_update (NAT_Contact *contact, time_t expire)
static INLINE void SIP_Subscription_expire (NAT_Contact *contact, time_t now)
static INLINE void SIP_Subscription_update (NAT_Contact *contact, time_t expire)
static Bool test_private_contact (struct sip_msg *msg)
static Bool test_private_via (struct sip_msg *msg)
static Bool test_source_address (struct sip_msg *msg)
static INLINE void trim (str *string)

Variables

static cmd_export_t commands []
static unsigned dialog_default_timeout = 12*3600
stat_vardialog_endpoints = 0
static int dialog_flag = -1
struct dlg_binds dlg_api
struct module_exports exports
Bool have_dlg_api = False
static Bool keepalive_disabled = False
stat_varkeepalive_endpoints = 0
static unsigned int keepalive_interval = 60
static Keepalive_Params keepalive_params = {"NOTIFY", NULL, "", "", 0, 0, ""}
static char * keepalive_state_file = "keepalive_state"
static HashTablenat_table = NULL
static NatTest NAT_Tests []
static param_export_t parameters []
static pv_export_t pvars []
stat_varregistered_endpoints = 0
static NetInfo rfc1918nets []
static stat_export_t statistics []
stat_varsubscribed_endpoints = 0
struct tm_binds tm_api


Define Documentation

#define False   0

Definition at line 84 of file nat_traversal.c.

#define FROM_PREFIX   "sip:keepalive@"

Definition at line 1483 of file nat_traversal.c.

#define HASH ( table,
key   )     (hash_string(key) % (table)->size)

#define HASH_SIZE   512

#define INLINE   inline

Definition at line 60 of file nat_traversal.c.

#define is_private_address (  )     (rfc1918address(x)==1 ? 1 : 0)

Definition at line 779 of file nat_traversal.c.

Referenced by test_private_contact(), and test_private_via().

#define max ( a,
 )     ((a)>(b) ? (a) : (b))

#define min ( a,
 )     ((a)<(b) ? (a) : (b))

Definition at line 70 of file nat_traversal.c.

Referenced by xj_wlist_get().

#define STATE_FILE_HEADER   "# Automatically generated file from internal keepalive state. Do NOT modify!\n"

Definition at line 1584 of file nat_traversal.c.

#define STR_HAS_IPREFIX ( str,
prefix   )     ((str).len>(prefix).len && strncasecmp((prefix).s, (str).s, (prefix).len)==0)

Definition at line 79 of file nat_traversal.c.

#define STR_HAS_PREFIX ( str,
prefix   )     ((str).len>(prefix).len && memcmp((prefix).s, (str).s, (prefix).len)==0)

Definition at line 78 of file nat_traversal.c.

#define STR_IMATCH ( str,
buf   )     ((str).len==strlen(buf) && strncasecmp(buf, (str).s, (str).len)==0)

Definition at line 73 of file nat_traversal.c.

#define STR_IMATCH_STR ( str,
str2   )     ((str).len==(str2).len && strncasecmp((str).s, (str2).s, (str).len)==0)

Definition at line 76 of file nat_traversal.c.

#define STR_MATCH ( str,
buf   )     ((str).len==strlen(buf) && memcmp(buf, (str).s, (str).len)==0)

Definition at line 72 of file nat_traversal.c.

#define STR_MATCH_STR ( str,
str2   )     ((str).len==(str2).len && memcmp((str).s, (str2).s, (str).len)==0)

Definition at line 75 of file nat_traversal.c.

Referenced by get_register_expire().

#define True   1

Definition at line 83 of file nat_traversal.c.

#define URI_LIST_INITIAL_SIZE   8

Definition at line 139 of file nat_traversal.c.

Referenced by Dialog_Param_new().

#define URI_LIST_RESIZE_INCREMENT   8

Definition at line 140 of file nat_traversal.c.

Referenced by Dialog_Param_add_candidate().


Typedef Documentation

typedef int Bool

Definition at line 82 of file nat_traversal.c.

typedef Bool(* NatTestFunction)(struct sip_msg *msg)

Definition at line 87 of file nat_traversal.c.


Enumeration Type Documentation

Enumerator:
NTNone 
NTPrivateContact 
NTSourceAddress 
NTPrivateVia 

Definition at line 89 of file nat_traversal.c.


Function Documentation

static void __dialog_confirmed ( struct dlg_cell dlg,
int  type,
struct dlg_cb_params _params 
) [static]

static void __dialog_created ( struct dlg_cell dlg,
int  type,
struct dlg_cb_params _params 
) [static]

static void __dialog_destroy ( struct dlg_cell dlg,
int  type,
struct dlg_cb_params _params 
) [static]

static void __dialog_early ( struct dlg_cell dlg,
int  type,
struct dlg_cb_params _params 
) [static]

static void __sl_reply_out ( unsigned int  types,
struct sip_msg request,
struct sl_cb_param param 
) [static]

static void __tm_reply_in ( struct cell trans,
int  type,
struct tmcb_params param 
) [static]

static int ClientNatTest ( struct sip_msg msg,
unsigned int  tests 
) [static]

Definition at line 1469 of file nat_traversal.c.

References NTNone, and NatTest::test.

static Bool Dialog_Param_add_candidate ( Dialog_Param param,
char *  candidate 
) [static]

static void Dialog_Param_del ( Dialog_Param param  )  [static]

static Bool Dialog_Param_has_candidate ( Dialog_Param param,
char *  candidate 
) [static]

static Dialog_Param* Dialog_Param_new ( void   )  [static]

static int FixContact ( struct sip_msg msg  )  [static]

static Bool get_contact_uri ( struct sip_msg msg,
struct sip_uri uri,
contact_t **  _c 
) [static]

static int get_expires ( struct sip_msg msg  )  [static]

static time_t get_register_expire ( struct sip_msg request,
struct sip_msg reply 
) [static]

static char* get_source_uri ( struct sip_msg msg  )  [static]

static INLINE unsigned hash_string ( const char *  key  )  [static]

Definition at line 498 of file nat_traversal.c.

static void HashTable_del ( HashTable table  )  [static]

static HashTable* HashTable_new ( void   )  [static]

static NAT_Contact* HashTable_search ( HashTable table,
char *  uri,
unsigned  slot 
) [static]

static void keepalive_registration ( struct sip_msg request,
time_t  expire 
) [static]

static void keepalive_subscription ( struct sip_msg request,
time_t  expire 
) [static]

static void keepalive_timer ( unsigned int  ticks,
void *  data 
) [static]

Definition at line 1546 of file nat_traversal.c.

static INLINE void ltrim ( str string  )  [static]

Definition at line 705 of file nat_traversal.c.

References _str::len, and _str::s.

static void mod_destroy ( void   )  [static]

Definition at line 1795 of file nat_traversal.c.

References LM_ERR.

static int mod_init ( void   )  [static]

Definition at line 1691 of file nat_traversal.c.

static void NAT_Contact_del ( NAT_Contact contact  )  [static]

static SIP_Dialog* NAT_Contact_get_dialog ( NAT_Contact contact,
struct dlg_cell dlg 
) [static]

static Bool NAT_Contact_match ( NAT_Contact contact,
const char *  uri 
) [static]

Definition at line 445 of file nat_traversal.c.

References NAT_Contact::uri.

Referenced by HashTable_search().

static NAT_Contact* NAT_Contact_new ( char *  uri,
struct socket_info socket 
) [static]

static NAT_Contact* NAT_Contact_purge_expired ( NAT_Contact contact,
time_t  now 
) [static]

static int NAT_Keepalive ( struct sip_msg msg  )  [static]

static int preprocess_request ( struct sip_msg msg,
void *  param 
) [static]

static int pv_get_keepalive_socket ( struct sip_msg msg,
pv_param_t param,
pv_value_t res 
) [static]

Definition at line 1925 of file nat_traversal.c.

static int pv_get_source_uri ( struct sip_msg msg,
pv_param_t param,
pv_value_t res 
) [static]

Definition at line 1967 of file nat_traversal.c.

static int pv_parse_nat_contact_name ( pv_spec_p  sp,
str in 
) [static]

Definition at line 1890 of file nat_traversal.c.

static int reply_filter ( struct sip_msg reply  )  [static]

Definition at line 1842 of file nat_traversal.c.

static void restore_keepalive_state ( void   )  [static]

Definition at line 1624 of file nat_traversal.c.

static INLINE int rfc1918address ( str address  )  [static]

Definition at line 783 of file nat_traversal.c.

References ip_addr::addr32, mask, NetInfo::name, netaddr, NULL, str2ip(), and ip_addr::u.

static INLINE void rtrim ( str string  )  [static]

Definition at line 715 of file nat_traversal.c.

References _str::len.

static void save_keepalive_state ( void   )  [static]

Definition at line 1587 of file nat_traversal.c.

static void send_keepalive ( NAT_Contact contact  )  [static]

Definition at line 1486 of file nat_traversal.c.

References LM_ERR.

static INLINE char * shm_strdup ( char *  source  )  [static]

static void SIP_Dialog_del ( SIP_Dialog dialog  )  [static]

Definition at line 305 of file nat_traversal.c.

References SIP_Dialog::expire, shm_free, and update_stat.

Referenced by NAT_Contact_del(), and SIP_Dialog_purge_expired().

static INLINE void SIP_Dialog_end ( SIP_Dialog dialog  )  [static]

Definition at line 339 of file nat_traversal.c.

References SIP_Dialog::expire, and update_stat.

Referenced by __dialog_confirmed(), and __dialog_destroy().

static SIP_Dialog* SIP_Dialog_new ( struct dlg_cell dlg,
time_t  expire 
) [static]

static SIP_Dialog* SIP_Dialog_purge_expired ( SIP_Dialog dialog,
time_t  now 
) [static]

Definition at line 319 of file nat_traversal.c.

References SIP_Dialog::expire, SIP_Dialog::next, NULL, and SIP_Dialog_del().

Referenced by NAT_Contact_purge_expired().

static INLINE void SIP_Registration_expire ( NAT_Contact contact,
time_t  now 
) [static]

Definition at line 361 of file nat_traversal.c.

References NAT_Contact::registration_expire, and update_stat.

Referenced by NAT_Contact_purge_expired().

static INLINE void SIP_Registration_update ( NAT_Contact contact,
time_t  expire 
) [static]

Definition at line 351 of file nat_traversal.c.

References NAT_Contact::registration_expire, and update_stat.

Referenced by keepalive_registration().

static INLINE void SIP_Subscription_expire ( NAT_Contact contact,
time_t  now 
) [static]

Definition at line 380 of file nat_traversal.c.

References NAT_Contact::subscription_expire, and update_stat.

Referenced by NAT_Contact_purge_expired().

static INLINE void SIP_Subscription_update ( NAT_Contact contact,
time_t  expire 
) [static]

Definition at line 370 of file nat_traversal.c.

References NAT_Contact::subscription_expire, and update_stat.

Referenced by keepalive_subscription().

static Bool test_private_contact ( struct sip_msg msg  )  [static]

Definition at line 822 of file nat_traversal.c.

References False, get_contact_uri(), sip_uri::host, and is_private_address.

static Bool test_private_via ( struct sip_msg msg  )  [static]

Definition at line 836 of file nat_traversal.c.

References via_body::host, is_private_address, and sip_msg::via1.

static Bool test_source_address ( struct sip_msg msg  )  [static]

static INLINE void trim ( str string  )  [static]

Definition at line 728 of file nat_traversal.c.

References ltrim(), and rtrim().


Variable Documentation

cmd_export_t commands[] [static]

Definition at line 233 of file nat_traversal.c.

unsigned dialog_default_timeout = 12*3600 [static]

Definition at line 211 of file nat_traversal.c.

Referenced by Dialog_Param_new().

Definition at line 216 of file nat_traversal.c.

int dialog_flag = -1 [static]

Definition at line 210 of file nat_traversal.c.

Definition at line 207 of file nat_traversal.c.

Definition at line 263 of file nat_traversal.c.

Bool have_dlg_api = False

Definition at line 208 of file nat_traversal.c.

Bool keepalive_disabled = False [static]

Definition at line 198 of file nat_traversal.c.

Referenced by NAT_Keepalive().

Definition at line 213 of file nat_traversal.c.

unsigned int keepalive_interval = 60 [static]

Definition at line 200 of file nat_traversal.c.

Keepalive_Params keepalive_params = {"NOTIFY", NULL, "", "", 0, 0, ""} [static]

Definition at line 204 of file nat_traversal.c.

char* keepalive_state_file = "keepalive_state" [static]

Definition at line 202 of file nat_traversal.c.

HashTable* nat_table = NULL [static]

Definition at line 196 of file nat_traversal.c.

NatTest NAT_Tests[] [static]

Definition at line 225 of file nat_traversal.c.

Definition at line 240 of file nat_traversal.c.

pv_export_t pvars[] [static]

Initial value:

 {
    {str_init("keepalive.socket"), PVT_OTHER, pv_get_keepalive_socket, NULL, pv_parse_nat_contact_name, NULL, NULL, 0},
    {str_init("source_uri"), PVT_OTHER, pv_get_source_uri, NULL, NULL, NULL, NULL, 0},
    {{0, 0}, 0, 0, 0, 0, 0, 0, 0}
}

Definition at line 249 of file nat_traversal.c.

Definition at line 214 of file nat_traversal.c.

NetInfo rfc1918nets[] [static]

Definition at line 218 of file nat_traversal.c.

Definition at line 255 of file nat_traversal.c.

Definition at line 215 of file nat_traversal.c.

struct tm_binds tm_api

Definition at line 206 of file nat_traversal.c.

Referenced by NAT_Keepalive().


Generated on Wed May 23 20:00:41 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6