1
/* $Id: nat_detect.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJNATH_NAT_DETECT_H__
21
#define __PJNATH_NAT_DETECT_H__
25
* @brief ICE session management
27
#include <pjnath/stun_session.h>
34
* @defgroup PJNATH_NAT_DETECT NAT Classification/Detection Tool
35
* @brief NAT Classification/Detection Tool
39
* This module provides one function to perform NAT classification and
40
* detection. NAT type detection is performed by calling
41
* #pj_stun_detect_nat_type() function.
46
* This enumeration describes the NAT types, as specified by RFC 3489
47
* Section 5, NAT Variations.
49
typedef enum pj_stun_nat_type
52
* NAT type is unknown because the detection has not been performed.
54
PJ_STUN_NAT_TYPE_UNKNOWN,
57
* NAT type is unknown because there is failure in the detection
58
* process, possibly because server does not support RFC 3489.
60
PJ_STUN_NAT_TYPE_ERR_UNKNOWN,
63
* This specifies that the client has open access to Internet (or
64
* at least, its behind a firewall that behaves like a full-cone NAT,
65
* but without the translation)
67
PJ_STUN_NAT_TYPE_OPEN,
70
* This specifies that communication with server has failed, probably
71
* because UDP packets are blocked.
73
PJ_STUN_NAT_TYPE_BLOCKED,
76
* Firewall that allows UDP out, and responses have to come back to
77
* the source of the request (like a symmetric NAT, but no
80
PJ_STUN_NAT_TYPE_SYMMETRIC_UDP,
83
* A full cone NAT is one where all requests from the same internal
84
* IP address and port are mapped to the same external IP address and
85
* port. Furthermore, any external host can send a packet to the
86
* internal host, by sending a packet to the mapped external address.
88
PJ_STUN_NAT_TYPE_FULL_CONE,
91
* A symmetric NAT is one where all requests from the same internal
92
* IP address and port, to a specific destination IP address and port,
93
* are mapped to the same external IP address and port. If the same
94
* host sends a packet with the same source address and port, but to
95
* a different destination, a different mapping is used. Furthermore,
96
* only the external host that receives a packet can send a UDP packet
97
* back to the internal host.
99
PJ_STUN_NAT_TYPE_SYMMETRIC,
102
* A restricted cone NAT is one where all requests from the same
103
* internal IP address and port are mapped to the same external IP
104
* address and port. Unlike a full cone NAT, an external host (with
105
* IP address X) can send a packet to the internal host only if the
106
* internal host had previously sent a packet to IP address X.
108
PJ_STUN_NAT_TYPE_RESTRICTED,
111
* A port restricted cone NAT is like a restricted cone NAT, but the
112
* restriction includes port numbers. Specifically, an external host
113
* can send a packet, with source IP address X and source port P,
114
* to the internal host only if the internal host had previously sent
115
* a packet to IP address X and port P.
117
PJ_STUN_NAT_TYPE_PORT_RESTRICTED
123
* This structure contains the result of NAT classification function.
125
typedef struct pj_stun_nat_detect_result
128
* Status of the detection process. If this value is not PJ_SUCCESS,
129
* the detection has failed and \a nat_type field will contain
130
* PJ_STUN_NAT_TYPE_UNKNOWN.
135
* The text describing the status, if the status is not PJ_SUCCESS.
137
const char *status_text;
140
* This contains the NAT type as detected by the detection procedure.
141
* This value is only valid when the \a status is PJ_SUCCESS.
143
pj_stun_nat_type nat_type;
146
* Text describing that NAT type.
148
const char *nat_type_name;
150
} pj_stun_nat_detect_result;
154
* Type of callback to be called when the NAT detection function has
157
typedef void pj_stun_nat_detect_cb(void *user_data,
158
const pj_stun_nat_detect_result *res);
162
* Get the NAT name from the specified NAT type.
164
* @param type NAT type.
168
PJ_DECL(const char*) pj_stun_get_nat_name(pj_stun_nat_type type);
172
* Perform NAT classification function according to the procedures
173
* specified in RFC 3489. Once this function returns successfully,
174
* the procedure will run in the "background" and will complete
175
* asynchronously. Application can register a callback to be notified
176
* when such detection has completed.
178
* @param server STUN server address.
179
* @param stun_cfg A structure containing various STUN configurations,
180
* such as the ioqueue and timer heap instance used
181
* to receive network I/O and timer events.
182
* @param user_data Application data, which will be returned back
184
* @param cb Callback to be registered to receive notification
185
* about detection result.
187
* @return If this function returns PJ_SUCCESS, the procedure
188
* will complete asynchronously and callback will be
189
* called when it completes. For other return
190
* values, it means that an error has occured and
191
* the procedure did not start.
193
PJ_DECL(pj_status_t) pj_stun_detect_nat_type(const pj_sockaddr_in *server,
194
pj_stun_config *stun_cfg,
196
pj_stun_nat_detect_cb *cb);
207
#endif /* __PJNATH_NAT_DETECT_H__ */