Преглед изворни кода

core: removed STUN from core

- Added hooks so that STUN messages can be passed to a module
- Removed STUN configuration file parameters
Peter Dunkley пре 12 година
родитељ
комит
c573aa70bb
12 измењених фајлова са 159 додато и 115 уклоњено
  1. 0 11
      Makefile.defs
  2. 0 9
      cfg.lex
  3. 0 16
      cfg.y
  4. 13 0
      events.c
  5. 3 1
      events.h
  6. 0 6
      globals.h
  7. 0 9
      main.c
  8. 46 0
      stun.c
  9. 64 0
      stun.h
  10. 15 29
      tcp_read.c
  11. 17 27
      udp_server.c
  12. 1 7
      ver_defs.h

+ 0 - 11
Makefile.defs

@@ -647,8 +647,6 @@ data_target = $(prefix)/$(data_dir)
 # -DPROFILING
 # -DPROFILING
 #		if enabled profiling will be enabled for child processes
 #		if enabled profiling will be enabled for child processes
 #		Don't forget to set PROFILE (see below)
 #		Don't forget to set PROFILE (see below)
-# -DUSE_STUN
-#		compiles in stun support
 # -DNO_SIG_DEBUG
 # -DNO_SIG_DEBUG
 #        turns off debugging messages in signal handlers (which might be 
 #        turns off debugging messages in signal handlers (which might be 
 #         unsafe)
 #         unsafe)
@@ -752,10 +750,6 @@ ifeq ($(WITHAS), 1)
 	C_DEFS+= -DWITH_AS_SUPPORT
 	C_DEFS+= -DWITH_AS_SUPPORT
 endif
 endif
 
 
-ifneq ($(STUN),)
-	C_DEFS+= -DUSE_STUN
-endif
-
 ifeq ($(mode),)
 ifeq ($(mode),)
 	mode = release
 	mode = release
 endif
 endif
@@ -2100,11 +2094,6 @@ LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lssl -lcrypto \
 #       E.g.: make CORE_TLS=1 EXTRA_TLS_LIBS="-lz -lkrb5"
 #       E.g.: make CORE_TLS=1 EXTRA_TLS_LIBS="-lz -lkrb5"
 endif
 endif
 
 
-ifneq ($(STUN),)
-C_INCLUDES+= -I$(LOCALBASE)/ssl/include
-LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lcrypto
-endif
-
 ifneq ($(found_lock_method), yes)
 ifneq ($(found_lock_method), yes)
 $(warning	No locking method found so far, trying SYS V sems)
 $(warning	No locking method found so far, trying SYS V sems)
 		C_DEFS+= -DUSE_SYSV_SEM  # try sys v sems
 		C_DEFS+= -DUSE_SYSV_SEM  # try sys v sems

+ 0 - 9
cfg.lex

@@ -498,11 +498,6 @@ PVBUFSLOTS		"pv_buffer_slots"
 HTTP_REPLY_HACK		"http_reply_hack"
 HTTP_REPLY_HACK		"http_reply_hack"
 VERSION_TABLE_CFG		"version_table"
 VERSION_TABLE_CFG		"version_table"
 
 
-/* stun config variables */
-STUN_REFRESH_INTERVAL "stun_refresh_interval"
-STUN_ALLOW_STUN "stun_allow_stun"
-STUN_ALLOW_FP "stun_allow_fp"
-
 SERVER_ID     "server_id"
 SERVER_ID     "server_id"
 
 
 LATENCY_LOG				latency_log
 LATENCY_LOG				latency_log
@@ -985,10 +980,6 @@ IMPORTFILE      "import_file"
 <INITIAL>{LOADPATH}		{ count(); yylval.strval=yytext; return LOADPATH; }
 <INITIAL>{LOADPATH}		{ count(); yylval.strval=yytext; return LOADPATH; }
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
 
 
-<INITIAL>{STUN_REFRESH_INTERVAL} { count(); yylval.strval=yytext; return STUN_REFRESH_INTERVAL;}
-<INITIAL>{STUN_ALLOW_STUN} { count(); yylval.strval=yytext; return STUN_ALLOW_STUN;}
-<INITIAL>{STUN_ALLOW_FP} { count(); yylval.strval=yytext; return STUN_ALLOW_FP;}
-
 <INITIAL>{EQUAL}	{ count(); return EQUAL; }
 <INITIAL>{EQUAL}	{ count(); return EQUAL; }
 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
 <INITIAL>{EQUAL_T}	{ count(); return EQUAL_T; }
 <INITIAL>{EQUAL_T}	{ count(); return EQUAL_T; }

+ 0 - 16
cfg.y

@@ -195,12 +195,6 @@
 	#define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
 	#define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
 #endif
 #endif
 
 
-#ifdef USE_STUN
-	#define IF_STUN(x) x
-#else 
-	#define IF_STUN(x) warn("stun support not compiled in")
-#endif
-
 #ifdef USE_SCTP
 #ifdef USE_SCTP
 	#define IF_SCTP(x) x
 	#define IF_SCTP(x) x
 #else
 #else
@@ -586,10 +580,6 @@ extern char *finame;
 %token ADDEQ
 %token ADDEQ
 
 
 
 
-%token STUN_REFRESH_INTERVAL
-%token STUN_ALLOW_STUN
-%token STUN_ALLOW_FP
-
 /*pre-processor*/
 /*pre-processor*/
 %token SUBST
 %token SUBST
 %token SUBSTDEF
 %token SUBSTDEF
@@ -1708,12 +1698,6 @@ assign_stm:
 	| PVBUFSLOTS EQUAL error { yyerror("number expected"); }
 	| PVBUFSLOTS EQUAL error { yyerror("number expected"); }
 	| HTTP_REPLY_HACK EQUAL NUMBER { http_reply_hack=$3; }
 	| HTTP_REPLY_HACK EQUAL NUMBER { http_reply_hack=$3; }
 	| HTTP_REPLY_HACK EQUAL error { yyerror("boolean value expected"); }
 	| HTTP_REPLY_HACK EQUAL error { yyerror("boolean value expected"); }
-	| STUN_REFRESH_INTERVAL EQUAL NUMBER { IF_STUN(stun_refresh_interval=$3); }
-	| STUN_REFRESH_INTERVAL EQUAL error{ yyerror("number expected"); }
-	| STUN_ALLOW_STUN EQUAL NUMBER { IF_STUN(stun_allow_stun=$3); }
-	| STUN_ALLOW_STUN EQUAL error{ yyerror("number expected"); }
-	| STUN_ALLOW_FP EQUAL NUMBER { IF_STUN(stun_allow_fp=$3) ; }
-	| STUN_ALLOW_FP EQUAL error{ yyerror("number expected"); }
     | SERVER_ID EQUAL NUMBER { server_id=$3; }
     | SERVER_ID EQUAL NUMBER { server_id=$3; }
     | LATENCY_LOG EQUAL NUMBER { default_core_cfg.latency_log=$3; }
     | LATENCY_LOG EQUAL NUMBER { default_core_cfg.latency_log=$3; }
 	| LATENCY_LOG EQUAL error  { yyerror("number  expected"); }
 	| LATENCY_LOG EQUAL error  { yyerror("number  expected"); }

+ 13 - 0
events.c

@@ -106,6 +106,11 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
 					_sr_events_list.tcp_ws_frame_out = f;
 					_sr_events_list.tcp_ws_frame_out = f;
 				else return -1;
 				else return -1;
 			break;
 			break;
+		case SREV_STUN_IN:
+				if(_sr_events_list.stun_in==0)
+					_sr_events_list.stun_in = f;
+				else return -1;
+			break;
 		default:
 		default:
 			return -1;
 			return -1;
 	}
 	}
@@ -209,6 +214,12 @@ int sr_event_exec(int type, void *data)
 					ret = _sr_events_list.tcp_ws_frame_out(data);
 					ret = _sr_events_list.tcp_ws_frame_out(data);
 					return ret;
 					return ret;
 				} else return 1;
 				} else return 1;
+		case SREV_STUN_IN:
+				if(unlikely(_sr_events_list.stun_in!=0))
+				{
+					ret = _sr_events_list.stun_in(data);
+					return ret;
+				} else return 1;
 		default:
 		default:
 			return -1;
 			return -1;
 	}
 	}
@@ -242,6 +253,8 @@ int sr_event_enabled(int type)
 				return (_sr_events_list.tcp_ws_frame_in!=0)?1:0;
 				return (_sr_events_list.tcp_ws_frame_in!=0)?1:0;
 		case SREV_TCP_WS_FRAME_OUT:
 		case SREV_TCP_WS_FRAME_OUT:
 				return (_sr_events_list.tcp_ws_frame_out!=0)?1:0;
 				return (_sr_events_list.tcp_ws_frame_out!=0)?1:0;
+		case SREV_STUN_IN:
+				return (_sr_events_list.stun_in!=0)?1:0;
 	}
 	}
 	return 0;
 	return 0;
 }
 }

+ 3 - 1
events.h

@@ -28,12 +28,13 @@
 #define SREV_CORE_STATS			3
 #define SREV_CORE_STATS			3
 #define SREV_CFG_RUN_ACTION		4
 #define SREV_CFG_RUN_ACTION		4
 #define SREV_PKG_SET_USED		5
 #define SREV_PKG_SET_USED		5
-#define SREV_PKG_SET_REAL_USED	6
+#define SREV_PKG_SET_REAL_USED		6
 #define SREV_NET_DGRAM_IN		7
 #define SREV_NET_DGRAM_IN		7
 #define SREV_TCP_HTTP_100C		8
 #define SREV_TCP_HTTP_100C		8
 #define SREV_TCP_MSRP_FRAME		9
 #define SREV_TCP_MSRP_FRAME		9
 #define SREV_TCP_WS_FRAME_IN		10
 #define SREV_TCP_WS_FRAME_IN		10
 #define SREV_TCP_WS_FRAME_OUT		11
 #define SREV_TCP_WS_FRAME_OUT		11
+#define SREV_STUN_IN			12
 
 
 
 
 typedef int (*sr_event_cb_f)(void *data);
 typedef int (*sr_event_cb_f)(void *data);
@@ -50,6 +51,7 @@ typedef struct sr_event_cb {
 	sr_event_cb_f tcp_msrp_frame;
 	sr_event_cb_f tcp_msrp_frame;
 	sr_event_cb_f tcp_ws_frame_in;
 	sr_event_cb_f tcp_ws_frame_in;
 	sr_event_cb_f tcp_ws_frame_out;
 	sr_event_cb_f tcp_ws_frame_out;
+	sr_event_cb_f stun_in;
 } sr_event_cb_t;
 } sr_event_cb_t;
 
 
 void sr_event_cb_init(void);
 void sr_event_cb_init(void);

+ 0 - 6
globals.h

@@ -136,12 +136,6 @@ extern int mcast_loopback;
 extern int mcast_ttl;
 extern int mcast_ttl;
 #endif /* USE_MCAST */
 #endif /* USE_MCAST */
 
 
-#ifdef USE_STUN
-extern unsigned int stun_refresh_interval;
-extern int stun_allow_stun;
-extern int stun_allow_fp;
-#endif
-
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 extern int auto_bind_ipv6;
 extern int auto_bind_ipv6;
 #endif
 #endif

+ 0 - 9
main.c

@@ -504,15 +504,6 @@ unsigned short port_no=0; /* default port*/
 unsigned short tls_port_no=0; /* default port */
 unsigned short tls_port_no=0; /* default port */
 #endif
 #endif
 
 
-#ifdef USE_STUN
-/* refresh interval in miliseconds */
-unsigned int stun_refresh_interval=0;
-/* stun can be switch off even if it is compiled */
-int stun_allow_stun=1;
-/* use or don't use fingerprint */
-int stun_allow_fp=1;
-#endif
-
 struct host_alias* aliases=0; /* name aliases list */
 struct host_alias* aliases=0; /* name aliases list */
 
 
 /* Parameter to child_init */
 /* Parameter to child_init */

+ 46 - 0
stun.c

@@ -0,0 +1,46 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2013 Crocodile RCS Ltd
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "events.h"
+#include "ip_addr.h"
+#include "stun.h"
+
+int stun_process_msg(char* buf, unsigned int len, struct receive_info* ri)
+{
+        int ret;
+	stun_event_info_t sev;
+
+        ret = 0;
+        LM_DBG("STUN Message: [[>>>\n%.*s<<<]]\n", len, buf);
+        if(likely(sr_event_enabled(SREV_STUN_IN))) {
+		memset(&sev, 0, sizeof(stun_event_info_t));
+		sev.buf = buf;
+		sev.len = len;
+		sev.rcv = ri;
+                ret = sr_event_exec(SREV_STUN_IN, (void *) &sev);
+        } else {
+                LM_DBG("no callback registering for handling STUN -"
+			" dropping!\n");
+        }
+        return ret;
+}

+ 64 - 0
stun.h

@@ -0,0 +1,64 @@
+/*
+ * $Id$
+ *
+ * Portions Copyright (C) 2013 Crocodile RCS Ltd
+ *
+ * Based on "ser_stun.h". Copyright (C) 2001-2003 FhG Fokus
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef _STUN_H
+#define _STUN_H
+
+#include "ip_addr.h"
+
+/* type redefinition */
+typedef unsigned char UCHAR_T;
+typedef unsigned short USHORT_T;
+typedef unsigned int UINT_T;
+typedef unsigned long ULONG_T;
+
+#define MAGIC_COOKIE	0x2112A442
+#define TRANSACTION_ID	12
+
+struct transaction_id {
+        UINT_T magic_cookie;
+        UCHAR_T id[TRANSACTION_ID];
+};
+
+struct stun_hdr {
+        USHORT_T type;
+        USHORT_T len;
+        struct transaction_id id;
+};
+
+struct stun_attr {
+        USHORT_T type;
+        USHORT_T len;
+};
+
+typedef struct stun_event_info {
+	char *buf;
+	unsigned int len;
+	struct receive_info *rcv;
+} stun_event_info_t;
+
+int stun_process_msg(char* buf, unsigned int len, struct receive_info* ri);
+
+#endif /* _STUN_H */

+ 15 - 29
tcp_read.c

@@ -97,13 +97,7 @@
 #include "tsend.h"
 #include "tsend.h"
 #include "forward.h"
 #include "forward.h"
 #include "events.h"
 #include "events.h"
-
-#ifdef USE_STUN
-#include "ser_stun.h"
-
-int is_msg_complete(struct tcp_req* r);
-
-#endif /* USE_STUN */
+#include "stun.h"
 
 
 #ifdef READ_HTTP11
 #ifdef READ_HTTP11
 #define HTTP11CONTINUE	"HTTP/1.1 100 Continue\r\nContent-Length: 0\r\n\r\n"
 #define HTTP11CONTINUE	"HTTP/1.1 100 Continue\r\nContent-Length: 0\r\n\r\n"
@@ -123,6 +117,8 @@ static int tcpmain_sock=-1;
 static struct local_timer tcp_reader_ltimer;
 static struct local_timer tcp_reader_ltimer;
 static ticks_t tcp_reader_prev_ticks;
 static ticks_t tcp_reader_prev_ticks;
 
 
+int is_msg_complete(struct tcp_req* r);
+
 /**
 /**
  * control cloning of TCP receive buffer
  * control cloning of TCP receive buffer
  * - needed for operations working directly inside the buffer
  * - needed for operations working directly inside the buffer
@@ -373,11 +369,8 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 	int bytes, remaining;
 	int bytes, remaining;
 	char *p;
 	char *p;
 	struct tcp_req* r;
 	struct tcp_req* r;
-
-#ifdef USE_STUN
 	unsigned int mc;   /* magic cookie */
 	unsigned int mc;   /* magic cookie */
 	unsigned short body_len;
 	unsigned short body_len;
-#endif
 
 
 #ifdef READ_MSRP
 #ifdef READ_MSRP
 	char *mfline;
 	char *mfline;
@@ -610,18 +603,16 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 						r->start=p;
 						r->start=p;
 						break;
 						break;
 					default:
 					default:
-#ifdef USE_STUN
-						/* STUN support can be switched off even if it's compiled */
 						/* stun test */						
 						/* stun test */						
-						if (stun_allow_stun && (unsigned char)*p == 0x00) {
+						if (unlikely(sr_event_enabled(SREV_STUN_IN)) && (unsigned char)*p == 0x00) {
 							r->state=H_STUN_MSG;
 							r->state=H_STUN_MSG;
 						/* body will used as pointer to the last used byte */
 						/* body will used as pointer to the last used byte */
 							r->body=p;
 							r->body=p;
 							r->content_len = 0;
 							r->content_len = 0;
 							DBG("stun msg detected\n");
 							DBG("stun msg detected\n");
-						}else
-#endif
-						r->state=H_SKIP;
+						} else {
+							r->state=H_SKIP;
+						}
 						r->start=p;
 						r->start=p;
 				};
 				};
 				p++;
 				p++;
@@ -656,7 +647,7 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 					r->state = H_SKIP_EMPTY;
 					r->state = H_SKIP_EMPTY;
 				}
 				}
 				break;
 				break;
-#ifdef USE_STUN
+
 			case H_STUN_MSG:
 			case H_STUN_MSG:
 				if ((r->pos - r->body) >= sizeof(struct stun_hdr)) {
 				if ((r->pos - r->body) >= sizeof(struct stun_hdr)) {
 					/* copy second short from buffer where should be body 
 					/* copy second short from buffer where should be body 
@@ -688,8 +679,8 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 						}
 						}
 						else {
 						else {
 							/* set content_len to length of fingerprint */
 							/* set content_len to length of fingerprint */
-							body_len = sizeof(struct stun_attr) + 
-									   SHA_DIGEST_LENGTH;
+							body_len = sizeof(struct stun_attr) + 20;
+							/* 20 is SHA_DIGEST_LENGTH from openssl/sha.h */
 						}
 						}
 					}
 					}
 					r->content_len=body_len;
 					r->content_len=body_len;
@@ -711,7 +702,8 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 					}
 					}
 					else {
 					else {
 						/* set content_len to length of fingerprint */
 						/* set content_len to length of fingerprint */
-						body_len = sizeof(struct stun_attr)+SHA_DIGEST_LENGTH;
+						body_len = sizeof(struct stun_attr) + 20;
+						/* 20 is SHA_DIGEST_LENGTH from openssl/sha.h */
 						r->content_len=body_len;
 						r->content_len=body_len;
 					}
 					}
 				}
 				}
@@ -736,7 +728,7 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 					p = r->pos;
 					p = r->pos;
 				}
 				}
 				break;
 				break;
-#endif /* USE_STUN */
+
 			change_state_case(H_CONT_LEN1,  'O', 'o', H_CONT_LEN2);
 			change_state_case(H_CONT_LEN1,  'O', 'o', H_CONT_LEN2);
 			change_state_case(H_CONT_LEN2,  'N', 'n', H_CONT_LEN3);
 			change_state_case(H_CONT_LEN2,  'N', 'n', H_CONT_LEN3);
 			change_state_case(H_CONT_LEN3,  'T', 't', H_CONT_LEN4);
 			change_state_case(H_CONT_LEN3,  'T', 't', H_CONT_LEN4);
@@ -1350,14 +1342,11 @@ again:
 					LOG(L_ERR, "CRLF ping: tcp_send() failed\n");
 					LOG(L_ERR, "CRLF ping: tcp_send() failed\n");
 				}
 				}
 				ret = 0;
 				ret = 0;
-			}else
-#ifdef USE_STUN
-			if (unlikely(req->state==H_STUN_END)){
+			} else if (unlikely(req->state==H_STUN_END)) {
 				/* stun request */
 				/* stun request */
 				ret = stun_process_msg(req->start, req->parsed-req->start,
 				ret = stun_process_msg(req->start, req->parsed-req->start,
 									 &con->rcv);
 									 &con->rcv);
-			}else
-#endif
+			} else
 #ifdef READ_MSRP
 #ifdef READ_MSRP
 			// if (unlikely(req->flags&F_TCP_REQ_MSRP_FRAME)){
 			// if (unlikely(req->flags&F_TCP_REQ_MSRP_FRAME)){
 			if (unlikely(req->state==H_MSRP_FINISH)){
 			if (unlikely(req->state==H_MSRP_FINISH)){
@@ -1762,8 +1751,6 @@ error:
 }
 }
 
 
 
 
-
-#ifdef USE_STUN
 int is_msg_complete(struct tcp_req* r)
 int is_msg_complete(struct tcp_req* r)
 {
 {
 	if (TCP_REQ_HAS_CLEN(r)) {
 	if (TCP_REQ_HAS_CLEN(r)) {
@@ -1778,6 +1765,5 @@ int is_msg_complete(struct tcp_req* r)
 		return 1;
 		return 1;
 	}
 	}
 }
 }
-#endif
 
 
 #endif /* USE_TCP */
 #endif /* USE_TCP */

+ 17 - 27
udp_server.c

@@ -76,15 +76,12 @@
 #include "ip_addr.h"
 #include "ip_addr.h"
 #include "cfg/cfg_struct.h"
 #include "cfg/cfg_struct.h"
 #include "events.h"
 #include "events.h"
+#include "stun.h"
 #ifdef USE_RAW_SOCKS
 #ifdef USE_RAW_SOCKS
 #include "raw_sock.h"
 #include "raw_sock.h"
 #endif /* USE_RAW_SOCKS */
 #endif /* USE_RAW_SOCKS */
 
 
 
 
-#ifdef USE_STUN
-  #include "ser_stun.h"
-#endif
-
 #ifdef DBG_MSG_QA
 #ifdef DBG_MSG_QA
 /* message quality assurance -- frequently, bugs in ser have
 /* message quality assurance -- frequently, bugs in ser have
    been indicated by zero characters or long whitespaces
    been indicated by zero characters or long whitespaces
@@ -501,19 +498,14 @@ int udp_rcv_loop()
 			}
 			}
 		}
 		}
 #ifndef NO_ZERO_CHECKS
 #ifndef NO_ZERO_CHECKS
-#ifdef USE_STUN
-		/* STUN support can be switched off even if it's compiled */
-		if (stun_allow_stun == 0 || (unsigned char)*buf != 0x00) {
-#endif
-		  if (len<MIN_UDP_PACKET) {
-			  tmp=ip_addr2a(&ri.src_ip);
-			  DBG("udp_rcv_loop: probing packet received from %s %d\n",
-				  	tmp, htons(ri.src_port));
-			  continue;
-		  }
-#ifdef USE_STUN
+		if (!unlikely(sr_event_enabled(SREV_STUN_IN)) || (unsigned char)*buf != 0x00) {
+			if (len<MIN_UDP_PACKET) {
+				tmp=ip_addr2a(&ri.src_ip);
+				DBG("udp_rcv_loop: probing packet received from %s %d\n",
+					tmp, htons(ri.src_port));
+				continue;
+			}
 		}
 		}
-#endif
 /* historically, zero-terminated packets indicated a bug in clients
 /* historically, zero-terminated packets indicated a bug in clients
  * that calculated wrongly packet length and included string-terminating
  * that calculated wrongly packet length and included string-terminating
  * zero; today clients exist with legitimate binary payloads and we
  * zero; today clients exist with legitimate binary payloads and we
@@ -544,17 +536,15 @@ int udp_rcv_loop()
 		
 		
 		/* update the local config */
 		/* update the local config */
 		cfg_update();
 		cfg_update();
-#ifdef USE_STUN
-			/* STUN support can be switched off even if it's compiled */
-			if (stun_allow_stun && (unsigned char)*buf == 0x00) {
-			    /* stun_process_msg releases buf memory if necessary */
-				if ((stun_process_msg(buf, len, &ri)) != 0) {
-					continue; /* some error occurred */
-				}
-			} else
-#endif
-		/* receive_msg must free buf too!*/
-		receive_msg(buf, len, &ri);
+		if (unlikely(sr_event_enabled(SREV_STUN_IN)) && (unsigned char)*buf == 0x00) {
+			/* stun_process_msg releases buf memory if necessary */
+			if ((stun_process_msg(buf, len, &ri)) != 0) {
+				continue; /* some error occurred */
+			}
+		} else {
+			/* receive_msg must free buf too!*/
+			receive_msg(buf, len, &ri);
+		}
 		
 		
 	/* skip: do other stuff */
 	/* skip: do other stuff */
 		
 		

+ 1 - 7
ver_defs.h

@@ -291,12 +291,6 @@
 #define NO_SIG_DEBUG_STR ""
 #define NO_SIG_DEBUG_STR ""
 #endif
 #endif
 
 
-#ifdef USE_STUN
-#define USE_STUN_STR ", USE_STUN"
-#else
-#define USE_STUN_STR ""
-#endif
-
 #ifdef HAVE_RESOLV_RES 
 #ifdef HAVE_RESOLV_RES 
 #define HAVE_RESOLV_RES_STR ", HAVE_RESOLV_RES"
 #define HAVE_RESOLV_RES_STR ", HAVE_RESOLV_RES"
 #else
 #else
@@ -336,7 +330,7 @@
 #define SER_COMPILE_FLAGS \
 #define SER_COMPILE_FLAGS \
 	STATS_STR EXTRA_DEBUG_STR USE_IPV6_STR USE_TCP_STR USE_TLS_STR \
 	STATS_STR EXTRA_DEBUG_STR USE_IPV6_STR USE_TCP_STR USE_TLS_STR \
 	USE_SCTP_STR CORE_TLS_STR TLS_HOOKS_STR  USE_RAW_SOCKS_STR \
 	USE_SCTP_STR CORE_TLS_STR TLS_HOOKS_STR  USE_RAW_SOCKS_STR \
-	USE_STUN_STR DISABLE_NAGLE_STR USE_MCAST_STR NO_DEBUG_STR NO_LOG_STR \
+	DISABLE_NAGLE_STR USE_MCAST_STR NO_DEBUG_STR NO_LOG_STR \
 	NO_SIG_DEBUG_STR DNS_IP_HACK_STR  SHM_MEM_STR SHM_MMAP_STR PKG_MALLOC_STR \
 	NO_SIG_DEBUG_STR DNS_IP_HACK_STR  SHM_MEM_STR SHM_MMAP_STR PKG_MALLOC_STR \
 	F_MALLOC_STR DL_MALLOC_STR SF_MALLOC_STR  LL_MALLOC_STR \
 	F_MALLOC_STR DL_MALLOC_STR SF_MALLOC_STR  LL_MALLOC_STR \
 	USE_SHM_MEM_STR \
 	USE_SHM_MEM_STR \