-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
udp-notifier mechanism #1445
base: master
Are you sure you want to change the base?
udp-notifier mechanism #1445
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,9 @@ turn_params_t turn_params = { | |
0, /* no_auth_pings */ | ||
0, /* no_dynamic_ip_list */ | ||
0, /* no_dynamic_realms */ | ||
|
||
///// UDP NOTIFIER ///// | ||
0, | ||
"", | ||
0, /* log_binding */ | ||
0, /* no_stun_backward_compatibility */ | ||
0, /* response_origin_only_with_rfc5780 */ | ||
|
@@ -1217,9 +1219,7 @@ static char Usage[] = | |
" name will be constructed as-is, without PID and date appendage.\n" | ||
" This option can be used, for example, together with the logrotate " | ||
"tool.\n" | ||
" --new-log-timestamp Enable full ISO-8601 timestamp in all logs.\n" | ||
" --new-log-timestamp-format <format> Set timestamp format (in strftime(1) format). Depends on " | ||
"--new-log-timestamp to be enabled.\n" | ||
" --new-log-timestamp Enable timestamp in all logs.\n" | ||
" --log-binding Log STUN binding request. It is now disabled by default to " | ||
"avoid DoS attacks.\n" | ||
" --stale-nonce[=<value>] Use extra security with nonce value having limited lifetime (default " | ||
|
@@ -1308,6 +1308,7 @@ static char Usage[] = | |
" when we want to run server applications on the relay endpoints.\n" | ||
" This option eliminates the IP permissions check on the packets\n" | ||
" incoming to the relay endpoints.\n" | ||
" --udp-notifier Send notification messages to target device via UDP interface.\n" | ||
" --cli-max-output-sessions Maximum number of output sessions in ps CLI command.\n" | ||
" This value can be changed on-the-fly in CLI. The default value is " | ||
"256.\n" | ||
|
@@ -1435,7 +1436,6 @@ enum EXTRA_OPTS { | |
SYSLOG_FACILITY_OPT, | ||
SIMPLE_LOG_OPT, | ||
NEW_LOG_TIMESTAMP_OPT, | ||
NEW_LOG_TIMESTAMP_FORMAT_OPT, | ||
AUX_SERVER_OPT, | ||
UDP_SELF_BALANCE_OPT, | ||
ALTERNATE_SERVER_OPT, | ||
|
@@ -1483,6 +1483,7 @@ enum EXTRA_OPTS { | |
NO_HTTP_OPT, | ||
SECRET_KEY_OPT, | ||
ACME_REDIRECT_OPT, | ||
UDP_NOTIFIER_OPT, | ||
LOG_BINDING_OPT, | ||
NO_RFC5780, | ||
NO_STUN_BACKWARD_COMPATIBILITY_OPT, | ||
|
@@ -1584,7 +1585,6 @@ static const struct myoption long_options[] = { | |
{"syslog", optional_argument, NULL, SYSLOG_OPT}, | ||
{"simple-log", optional_argument, NULL, SIMPLE_LOG_OPT}, | ||
{"new-log-timestamp", optional_argument, NULL, NEW_LOG_TIMESTAMP_OPT}, | ||
{"new-log-timestamp-format", required_argument, NULL, NEW_LOG_TIMESTAMP_FORMAT_OPT}, | ||
{"aux-server", required_argument, NULL, AUX_SERVER_OPT}, | ||
{"udp-self-balance", optional_argument, NULL, UDP_SELF_BALANCE_OPT}, | ||
{"alternate-server", required_argument, NULL, ALTERNATE_SERVER_OPT}, | ||
|
@@ -1626,6 +1626,7 @@ static const struct myoption long_options[] = { | |
{"keep-address-family", optional_argument, NULL, 'K'}, | ||
{"allocation-default-address-family", required_argument, NULL, 'A'}, | ||
{"acme-redirect", required_argument, NULL, ACME_REDIRECT_OPT}, | ||
{"udp-notifier", required_argument, NULL, UDP_NOTIFIER_OPT }, | ||
{"log-binding", optional_argument, NULL, LOG_BINDING_OPT}, | ||
{"no-rfc5780", optional_argument, NULL, NO_RFC5780}, | ||
{"no-stun-backward-compatibility", optional_argument, NULL, NO_STUN_BACKWARD_COMPATIBILITY_OPT}, | ||
|
@@ -2328,6 +2329,10 @@ static void set_option(int c, char *value) { | |
turn_params.rest_api_separator = *value; | ||
} | ||
break; | ||
case UDP_NOTIFIER_OPT: | ||
turn_params.udp_notifier = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use the C99 "stdbool" header, and the true/false keywords (sometimes implemented as macros by C99) over '1' and '0' and 'int'. |
||
STRCPY(turn_params.udp_notifier_params, value); | ||
break; | ||
case LOG_BINDING_OPT: | ||
turn_params.log_binding = get_bool_value(value); | ||
break; | ||
|
@@ -2350,7 +2355,6 @@ static void set_option(int c, char *value) { | |
case SYSLOG_OPT: | ||
case SIMPLE_LOG_OPT: | ||
case NEW_LOG_TIMESTAMP_OPT: | ||
case NEW_LOG_TIMESTAMP_FORMAT_OPT: | ||
case SYSLOG_FACILITY_OPT: | ||
case 'c': | ||
case 'n': | ||
|
@@ -2491,8 +2495,6 @@ static void read_config_file(int argc, char **argv, int pass) { | |
set_simple_log(get_bool_value(value)); | ||
} else if ((pass == 0) && (c == NEW_LOG_TIMESTAMP_OPT)) { | ||
use_new_log_timestamp_format = 1; | ||
} else if ((pass == 0) && (c == NEW_LOG_TIMESTAMP_FORMAT_OPT)) { | ||
set_turn_log_timestamp_format(value); | ||
} else if ((pass == 0) && (c == SYSLOG_FACILITY_OPT)) { | ||
set_syslog_facility(value); | ||
} else if ((pass == 1) && (c != 'u')) { | ||
|
@@ -2982,9 +2984,6 @@ int main(int argc, char **argv) { | |
case NEW_LOG_TIMESTAMP_OPT: | ||
use_new_log_timestamp_format = 1; | ||
break; | ||
case NEW_LOG_TIMESTAMP_FORMAT_OPT: | ||
set_turn_log_timestamp_format(optarg); | ||
break; | ||
case SYSLOG_FACILITY_OPT: | ||
set_syslog_facility(optarg); | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,6 +326,10 @@ typedef struct _turn_params_ { | |
int no_auth_pings; | ||
int no_dynamic_ip_list; | ||
int no_dynamic_realms; | ||
|
||
//// UDP Notifier //// | ||
int udp_notifier; | ||
char udp_notifier_params[1025]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1025 is a magic number. Additionally, does this need to be a flat buffer of characters? can't it be parsed into a struct that has meaningful variable names for whatever the fields are? |
||
|
||
vint log_binding; | ||
vint no_stun_backward_compatibility; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include "ntfy_driver.h" | ||
#include "../mainrelay.h" | ||
#include "../../common/apputils.h" | ||
#include "udp_subscriber.h" | ||
#include "apps/relay/mainrelay.h" | ||
typedef struct _turn_notifier_t{ | ||
turn_ntfy_subscriber_if_t** subscribers; | ||
size_t subscriber_count; | ||
}turn_notifier_t; | ||
|
||
|
||
pthread_key_t notifier_key; | ||
pthread_once_t notifier_key_once = PTHREAD_ONCE_INIT; | ||
|
||
static void notifier_interface_remove(void*notifier_p); | ||
|
||
|
||
static void make_notifier_key(void) | ||
{ | ||
(void) pthread_key_create(¬ifier_key, notifier_interface_remove); | ||
} | ||
|
||
static void subscriber_add(turn_notifier_t* notifier, turn_ntfy_subscriber_if_t* subscriber) | ||
{ | ||
if(notifier && subscriber) { | ||
notifier->subscribers = (turn_ntfy_subscriber_if_t**)realloc(notifier->subscribers,(sizeof(turn_ntfy_subscriber_if_t*)*(notifier->subscriber_count+1))); | ||
notifier->subscribers[notifier->subscriber_count] = subscriber; | ||
notifier->subscriber_count += 1; | ||
} | ||
} | ||
|
||
static void subscribers_init(turn_notifier_t *notifier){ | ||
|
||
size_t i; | ||
|
||
for(i=0; i<(notifier->subscriber_count); i++){ | ||
if(notifier->subscribers[i]->init) { | ||
notifier->subscribers[i]->long_term_data = notifier->subscribers[i]->init(); | ||
} | ||
} | ||
} | ||
|
||
static void subscribers_notify(turn_notifier_t *notifier, TURN_NTFY_LEVEL level, const char* string){ | ||
|
||
size_t i; | ||
|
||
for(i=0; i<(notifier->subscriber_count); i++){ | ||
if(notifier->subscribers[i]->notify) { | ||
notifier->subscribers[i]->notify(notifier->subscribers[i]->long_term_data, level, string); | ||
} | ||
} | ||
} | ||
|
||
static void subscribers_remove(turn_notifier_t *notifier){ | ||
|
||
size_t i; | ||
|
||
for(i=0; i<(notifier->subscriber_count); i++){ | ||
if(notifier->subscribers[i]->remove) { | ||
notifier->subscribers[i]->remove(notifier->subscribers[i]->long_term_data); | ||
} | ||
} | ||
} | ||
|
||
static turn_notifier_t* notifier_interface_get(void){ | ||
|
||
(void) pthread_once(¬ifier_key_once, make_notifier_key); | ||
|
||
turn_notifier_t *notifier = (turn_notifier_t *)pthread_getspecific(notifier_key); | ||
|
||
if(!notifier){ | ||
|
||
turn_notifier_t* notifier=(turn_notifier_t*)malloc(sizeof(turn_notifier_t)); | ||
if(!notifier) return notifier; | ||
|
||
bzero(notifier,sizeof(turn_notifier_t)); | ||
|
||
subscriber_add(notifier,udp_subscriber_inferface_get()); | ||
|
||
subscribers_init(notifier); | ||
|
||
pthread_setspecific(notifier_key, notifier); | ||
} | ||
return notifier; | ||
} | ||
|
||
static void notifier_interface_remove(void*notifier_p){ | ||
|
||
turn_notifier_t *notifier = (turn_notifier_t *)notifier_p; | ||
|
||
if(notifier){ | ||
|
||
subscribers_remove(notifier); | ||
|
||
free(notifier); | ||
} | ||
} | ||
|
||
int turn_ntfy_check(){ | ||
|
||
turn_notifier_t* notifier = notifier_interface_get(); | ||
|
||
if(notifier){ | ||
if(notifier->subscriber_count>0) | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
void turn_ntfy_func_default(TURN_NTFY_LEVEL level, const char* format, ...){ | ||
|
||
#define MAX_RTPPRINTF_BUFFER_SIZE (1024) | ||
char string[MAX_RTPPRINTF_BUFFER_SIZE+1]; | ||
#undef MAX_RTPPRINTF_BUFFER_SIZE | ||
|
||
va_list args; | ||
|
||
turn_notifier_t* notifier = notifier_interface_get(); | ||
|
||
if(notifier){ | ||
va_start(args,format); | ||
|
||
vsnprintf(string, sizeof(string)-1, format, args); | ||
string[sizeof(string)-1]=0; | ||
|
||
va_end(args); | ||
|
||
subscribers_notify(notifier, level, string); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like you may need to rebase against the latest master/main branch?
Unless your PR is intending to remove the --new-log-timestamp-format option?