From cfa92d28d87a3e012ed192e1e9e3699f3e436a1f Mon Sep 17 00:00:00 2001 From: randomize00 <53703968+randomize00@users.noreply.github.com> Date: Wed, 14 Apr 2021 13:46:50 +0800 Subject: [PATCH] add callback function for hin2n to protect socket (#684) --- include/n2n_typedefs.h | 3 +++ src/edge_utils.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/n2n_typedefs.h b/include/n2n_typedefs.h index 306d338..a4ea1d4 100644 --- a/include/n2n_typedefs.h +++ b/include/n2n_typedefs.h @@ -516,6 +516,9 @@ typedef struct n2n_edge_callbacks { /* Called periodically in the main loop. */ void (*main_loop_period)(n2n_edge_t *eee, time_t now); + + /* Called when a new socket to supernode is created. */ + void (*sock_opened)(n2n_edge_t *eee); } n2n_edge_callbacks_t; typedef struct n2n_tuntap_priv_config { diff --git a/src/edge_utils.c b/src/edge_utils.c index 342c8a0..2c379a5 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -219,6 +219,9 @@ int supernode_connect(n2n_edge_t *eee) { return -1; } + if(eee->cb.sock_opened) + eee->cb.sock_opened(eee); + struct sockaddr_in sock; sock.sin_family = AF_INET; sock.sin_port = htons(eee->curr_sn->sock.port);