Implemented SLPD information expiration and added support for port
This commit is contained in:
parent
e567374a5d
commit
ff8f57c130
4 changed files with 25 additions and 3 deletions
|
@ -25,8 +25,9 @@
|
|||
#include "splay_tree.h"
|
||||
#include "subnet.h"
|
||||
|
||||
#define DEFAULT_SLPD_GROUP "ff02::42:1"
|
||||
#define DEFAULT_SLPD_PORT "1655"
|
||||
#define DEFAULT_SLPD_GROUP "ff02::42:1"
|
||||
#define DEFAULT_SLPD_PORT "1655"
|
||||
#define DEFAULT_SLPD_EXPIRE 300
|
||||
|
||||
typedef struct config_t {
|
||||
char *variable;
|
||||
|
|
|
@ -72,6 +72,7 @@ bool udp_discovery = true;
|
|||
int udp_discovery_keepalive_interval = 10;
|
||||
int udp_discovery_interval = 2;
|
||||
int udp_discovery_timeout = 30;
|
||||
extern int my_slpd_expire;
|
||||
|
||||
#define MAX_SEQNO 1073741824
|
||||
|
||||
|
@ -1540,6 +1541,16 @@ static void handle_incoming_slpd_packet(listen_socket_t *ls, void *pkt, struct s
|
|||
return;
|
||||
}
|
||||
|
||||
if (n->slpd_address != NULL) {
|
||||
if (now.tv_sec - n->slpd_active_since.tv_sec < my_slpd_expire) {
|
||||
return;
|
||||
} else {
|
||||
logger(DEBUG_ALWAYS, LOG_ERR, "Expire SLPD for %s", n->name);
|
||||
free_config(n->slpd_address);
|
||||
n->slpd_address = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!n->ecdsa)
|
||||
node_read_ecdsa_public_key(n);
|
||||
|
||||
|
@ -1564,6 +1575,7 @@ static void handle_incoming_slpd_packet(listen_socket_t *ls, void *pkt, struct s
|
|||
}
|
||||
|
||||
config_t *cfg = NULL;
|
||||
|
||||
if (!n->slpd_address) {
|
||||
char iface_name[255] = { 0 };
|
||||
char fullhost[255] = { 0 };
|
||||
|
@ -1572,13 +1584,14 @@ static void handle_incoming_slpd_packet(listen_socket_t *ls, void *pkt, struct s
|
|||
|
||||
cfg = new_config();
|
||||
cfg->variable = xstrdup("Address");
|
||||
snprintf(fullhost, 254, "%s%%%s", addrstr, iface_name);
|
||||
snprintf(fullhost, 254, "%s%%%s %d", addrstr, iface_name, port);
|
||||
cfg->value = xstrdup(fullhost);
|
||||
cfg->file = NULL;
|
||||
cfg->line = -1;
|
||||
|
||||
logger(DEBUG_ALWAYS, LOG_ERR, "Discovered %s on %s", nodename , fullhost);
|
||||
n->slpd_address = cfg;
|
||||
n->slpd_active_since = now;
|
||||
n->status.has_address = true;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
char *myport;
|
||||
char *my_slpd_port;
|
||||
char *my_slpd_group;
|
||||
int my_slpd_expire;
|
||||
static char *myname;
|
||||
static io_t device_io;
|
||||
devops_t devops;
|
||||
|
@ -928,6 +929,12 @@ static bool setup_myself(void) {
|
|||
if(!get_config_string(lookup_config(config_tree, "SLPDGroup"), &my_slpd_group))
|
||||
my_slpd_group = xstrdup(DEFAULT_SLPD_GROUP);
|
||||
|
||||
char *tmp_expire;
|
||||
if(!get_config_string(lookup_config(config_tree, "SLPDExpire"), &tmp_expire))
|
||||
my_slpd_expire = DEFAULT_SLPD_EXPIRE;
|
||||
else
|
||||
my_slpd_expire = atoi(tmp_expire);
|
||||
|
||||
myself->connection->options = 0;
|
||||
myself->connection->protocol_major = PROT_MAJOR;
|
||||
myself->connection->protocol_minor = PROT_MINOR;
|
||||
|
|
|
@ -83,6 +83,7 @@ typedef struct node_t {
|
|||
|
||||
struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
|
||||
struct config_t *slpd_address; /* Address we learned via SLPD */
|
||||
struct timeval slpd_active_since; /* Last time a (gratuitous) UDP probe reply was sent */
|
||||
uint32_t sent_seqno; /* Sequence number last sent to this node */
|
||||
uint32_t received_seqno; /* Sequence number last received from this node */
|
||||
uint32_t received; /* Total valid packets received from this node */
|
||||
|
|
Loading…
Reference in a new issue