1 /** 2 * @file re_natbd.h NAT Behavior Discovery Using STUN (RFC 5780) 3 * 4 * Copyright (C) 2010 Creytiv.com 5 */ 6 7 8 /** NAT Mapping/Filtering types - See RFC 4787 for definitions */ 9 enum nat_type { 10 NAT_TYPE_UNKNOWN = 0, /**< Unknown type */ 11 NAT_TYPE_ENDP_INDEP = 1, /**< Endpoint-Independent */ 12 NAT_TYPE_ADDR_DEP = 2, /**< Address-Dependent */ 13 NAT_TYPE_ADDR_PORT_DEP = 3 /**< Address and Port-Dependent */ 14 }; 15 16 17 /* Strings */ 18 const char *nat_type_str(enum nat_type type); 19 20 21 /* 22 * Diagnosing NAT Hairpinning 23 */ 24 struct nat_hairpinning; 25 /** 26 * Defines the NAT Hairpinning handler 27 */ 28 typedef void (nat_hairpinning_h)(int err, bool supported, void *arg); 29 30 int nat_hairpinning_alloc(struct nat_hairpinning **nhp, 31 const struct sa *srv, int proto, 32 const struct stun_conf *conf, 33 nat_hairpinning_h *hph, void *arg); 34 int nat_hairpinning_start(struct nat_hairpinning *nh); 35 36 37 /* 38 * Determining NAT Mapping Behavior 39 */ 40 struct nat_mapping; 41 42 /** 43 * Defines the NAT Mapping handler 44 * 45 * @param err Errorcode 46 * @param type NAT Mapping type 47 * @param arg Handler argument 48 */ 49 typedef void (nat_mapping_h)(int err, enum nat_type map, void *arg); 50 51 int nat_mapping_alloc(struct nat_mapping **nmp, const struct sa *laddr, 52 const struct sa *srv, int proto, 53 const struct stun_conf *conf, 54 nat_mapping_h *mh, void *arg); 55 int nat_mapping_start(struct nat_mapping *nm); 56 57 58 /* 59 * Determining NAT Filtering Behavior 60 */ 61 struct nat_filtering; 62 63 /** 64 * Defines the NAT Filtering handler 65 * 66 * @param err Errorcode 67 * @param type NAT Filtering type 68 * @param arg Handler argument 69 */ 70 typedef void (nat_filtering_h)(int err, enum nat_type filt, void *arg); 71 72 int nat_filtering_alloc(struct nat_filtering **nfp, const struct sa *srv, 73 const struct stun_conf *conf, 74 nat_filtering_h *fh, void *arg); 75 int nat_filtering_start(struct nat_filtering *nf); 76 77 78 /* 79 * Binding Lifetime Discovery 80 */ 81 82 struct nat_lifetime; 83 84 /** Defines the NAT lifetime interval */ 85 struct nat_lifetime_interval { 86 uint32_t min; /**< Minimum lifetime interval in [seconds] */ 87 uint32_t cur; /**< Current lifetime interval in [seconds] */ 88 uint32_t max; /**< Maximum lifetime interval in [seconds] */ 89 }; 90 91 92 /** 93 * Defines the NAT Lifetime handler 94 * 95 * @param err Errorcode 96 * @param i NAT Lifetime intervals 97 * @param arg Handler argument 98 */ 99 typedef void (nat_lifetime_h)(int err, const struct nat_lifetime_interval *i, 100 void *arg); 101 102 int nat_lifetime_alloc(struct nat_lifetime **nlp, const struct sa *srv, 103 uint32_t interval, const struct stun_conf *conf, 104 nat_lifetime_h *lh, void *arg); 105 int nat_lifetime_start(struct nat_lifetime *nl); 106 107 108 /* 109 * Detecting Generic ALGs 110 */ 111 struct nat_genalg; 112 113 /** 114 * Defines the NAT Generic ALG handler 115 * 116 * @param err Errorcode 117 * @param errcode STUN Error code (if set) 118 * @param status Generic ALG status (-1=not detected, 1=detected) 119 * @param map Mapped network address 120 * @param arg Handler argument 121 */ 122 typedef void (nat_genalg_h)(int err, uint16_t scode, const char *reason, 123 int status, const struct sa *map, void *arg); 124 125 int nat_genalg_alloc(struct nat_genalg **ngp, const struct sa *srv, int proto, 126 const struct stun_conf *conf, 127 nat_genalg_h *gh, void *arg); 128 int nat_genalg_start(struct nat_genalg *ng); 129