Pārlūkot izejas kodu

feat: Add option to disable error reasons in STUN responses

This commit introduces a new configuration option, `no-error-reason`.
When enabled, the TURN server will send STUN error responses with an
empty reason phrase. This can be useful in environments where minimizing
response size is critical, at the cost of slightly harder debugging.

Changes include:
- Added `no_error_reason` to the `turn_params_t` struct.
- Modified `mainrelay.c` to parse the `--no-error-reason` command-line
  option and corresponding configuration file setting.
- Updated `ns_turn_server.c` to check this flag and conditionally
  omit the reason phrase when constructing error responses.
- Added the new option to the example `turnserver.conf` file.
- Conceptually outlined test cases for this new functionality.
google-labs-jules[bot] 5 mēneši atpakaļ
vecāks
revīzija
06034663d3

+ 3 - 0
examples/etc/turnserver.conf

@@ -819,6 +819,9 @@
 #
 # stun-backward-compatibility
 
+# Uncomment to disable error reason phrases in STUN error responses.
+# This can reduce response size slightly but makes debugging harder.
+#no-error-reason
 
 # Return an HTTP/S response when an HTTP/S connection is made to a TCP port
 # otherwise only supporting STUN/TURN. This may be useful for debugging and

+ 8 - 1
src/apps/relay/mainrelay.c

@@ -228,7 +228,8 @@ turn_params_t turn_params = {
 
     false, /* log_binding */
     false, /* stun_backward_compatibility */
-    false  /* respond_http_unsupported */
+    false, /* respond_http_unsupported */
+    false  /* no_error_reason */
 };
 
 //////////////// OpenSSL Init //////////////////////
@@ -1340,6 +1341,7 @@ static char Usage[] =
     "connections made to ports not\n"
     "						supporting HTTP. The default behaviour is to immediately "
     "close the connection.\n"
+    " --no-error-reason				Do not send error reason phrase in STUN error responses.\n"
     " --version					Print version (and exit).\n"
     " -h						Help\n"
     "\n";
@@ -1498,6 +1500,7 @@ enum EXTRA_OPTS {
   STUN_BACKWARD_COMPATIBILITY_OPT,
   RESPONSE_ORIGIN_ONLY_WITH_RFC5780_OPT,
   RESPOND_HTTP_UNSUPPORTED_OPT,
+  NO_ERROR_REASON_OPT,
   VERSION_OPT
 };
 
@@ -1642,6 +1645,7 @@ static const struct myoption long_options[] = {
     {"stun-backward-compatibility", optional_argument, NULL, STUN_BACKWARD_COMPATIBILITY_OPT},
     {"response-origin-only-with-rfc5780", optional_argument, NULL, RESPONSE_ORIGIN_ONLY_WITH_RFC5780_OPT},
     {"respond-http-unsupported", optional_argument, NULL, RESPOND_HTTP_UNSUPPORTED_OPT},
+    {"no-error-reason", optional_argument, NULL, NO_ERROR_REASON_OPT},
     {"version", optional_argument, NULL, VERSION_OPT},
     {"syslog-facility", required_argument, NULL, SYSLOG_FACILITY_OPT},
     {NULL, no_argument, NULL, 0}};
@@ -2359,6 +2363,9 @@ static void set_option(int c, char *value) {
   case RESPOND_HTTP_UNSUPPORTED_OPT:
     turn_params.respond_http_unsupported = get_bool_value(value);
     break;
+  case NO_ERROR_REASON_OPT:
+    turn_params.no_error_reason = get_bool_value(value);
+    break;
 
   /* these options have been already taken care of before: */
   case 'l':

+ 1 - 0
src/apps/relay/mainrelay.h

@@ -338,6 +338,7 @@ typedef struct _turn_params_ {
   bool log_binding;
   bool stun_backward_compatibility;
   bool respond_http_unsupported;
+  bool no_error_reason;
 } turn_params_t;
 
 extern turn_params_t turn_params;