2018-04-08 16:48:13 +02:00
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include "dbg.h"
|
|
|
|
#include "cw.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Detect NAT after a join/discovery request
|
|
|
|
* @param conn Connection object
|
|
|
|
* @retval 1 NAT detected
|
|
|
|
* @retval 0 no NAT was detected
|
|
|
|
*/
|
2022-08-13 09:47:12 +02:00
|
|
|
int cw_detect_nat(struct cw_ElemHandlerParams *params)
|
2018-04-08 16:48:13 +02:00
|
|
|
{
|
2022-08-13 09:47:12 +02:00
|
|
|
const char * remote_str;
|
2018-04-08 16:48:13 +02:00
|
|
|
char local_str[128];
|
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
remote_str = cw_cfg_get(params->cfg,"capwap-local-ip-address",NULL);
|
|
|
|
if (remote_str == NULL){
|
2018-04-08 16:48:13 +02:00
|
|
|
cw_dbg(DBG_WARN,"Can't detect NAT. No local IP from peer received.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert remote connected and sent ip addresse to
|
|
|
|
* strings */
|
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
sock_addrtostr((struct sockaddr*)&(params->conn->addr),local_str,128,0);
|
2018-04-08 16:48:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* if connected and sent address is the same, there is
|
|
|
|
* no NAT */
|
|
|
|
if (strcmp(remote_str,local_str)==0)
|
|
|
|
return 0;
|
|
|
|
/* otherwise ther must be something between AC and WTP */
|
|
|
|
return 1;
|
|
|
|
}
|
2022-08-13 09:47:12 +02:00
|
|
|
|