Introduction to Simple Local Peer Discovery Protocol (SLPD)
Full functionality of tinc mesh relays on having at least one node,
accessible, with known address to which all other nodes must connect
in order to exchange information about other peers.
Sometimes, however, in smaller networks or if two or more peers are
located in the same LAN segment without access to any of the nodes with
known address, there is no way of establishing a functional mesh
without manually changing the configuration.
SLPD addresses this problem utilizing multicast groups and autoconnect.
- Node sends periodically simple message to multicast group
(default 224.0.42.23 port 1655) in this format:
"sLPD 0 1 nodename port publickey"
"0 1" is the "major minior" version of the protocol
- Node listens to the multicast group for messages on all interfaces:
- if the nodename is known and the publickey matches the
node's public key the source address of the packet
will be stored as learned ip address
- at this point setup_outgoing_connection() will be able to
choose the learned ip for connect
Configarion example:
* Roadwarriors: SLPDInterval = 30
* Router on your home network or in your hackerspace:
- It should broadcast only in the direction of the LAN thus you should
set SLPDInterface = eth0 and SLPDInterval = 10
* Defaults:
SLPDGroup = "224.0.42.23"
SLPDPort = 1655
SLPDInterval = 0 (means SLPD is disabled)
The check of the publickey is not implemented yet. IPv6 support
must be implemented. This is the first commit - highly experimental.
This commit is contained in:
parent
4401c645ab
commit
cdd148204f
6 changed files with 211 additions and 1 deletions
|
|
@ -59,6 +59,7 @@
|
|||
|
||||
int keylifetime = 0;
|
||||
int edgeupdateinterval = 0;
|
||||
int slpdinterval = 0;
|
||||
#ifdef HAVE_LZO
|
||||
static char lzo_wrkmem[LZO1X_999_MEM_COMPRESS > LZO1X_1_MEM_COMPRESS ? LZO1X_999_MEM_COMPRESS : LZO1X_1_MEM_COMPRESS];
|
||||
#endif
|
||||
|
|
@ -1514,6 +1515,51 @@ skip_harder:
|
|||
send_mtu_info(myself, n, MTU);
|
||||
}
|
||||
|
||||
static void handle_incoming_slpd_packet(listen_socket_t *ls, void *pkt, sockaddr_t *addr) {
|
||||
|
||||
int mav, miv, port;
|
||||
char nodename[MAXSIZE], fng[MAXSIZE];
|
||||
|
||||
int i = sscanf(pkt, "sLPD %d %d %s %d %s", &mav, &miv, &nodename[0], &port, &fng[0]);
|
||||
if (i != 5) {
|
||||
logger(DEBUG_ALWAYS, LOG_ERR, "cant not parse packet... %d",i);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mav == 0 && miv == 1) {
|
||||
|
||||
logger(DEBUG_TRAFFIC, LOG_ERR, "Got SLPD packet node:%s port:%d %d.%d <%s> from %s", nodename, port, mav, miv, fng, inet_ntoa(addr->in.sin_addr));
|
||||
|
||||
node_t *n = lookup_node(nodename);
|
||||
if (!n) {
|
||||
logger(DEBUG_ALWAYS, LOG_ERR, "unknown node: %s", nodename);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strncmp(n->name, myself->name, strlen(myself->name))) {
|
||||
logger(DEBUG_SCARY_THINGS, LOG_NOTICE, "Ignore SLPD for myself: %s", nodename);
|
||||
return;
|
||||
}
|
||||
|
||||
config_t *cfg = NULL;
|
||||
if (!n->slpd_address) {
|
||||
cfg = new_config();
|
||||
cfg->variable = xstrdup("Address");
|
||||
cfg->value = xstrdup(inet_ntoa(addr->in.sin_addr));
|
||||
cfg->file = NULL;
|
||||
cfg->line = -1;
|
||||
|
||||
logger(DEBUG_ALWAYS, LOG_ERR, "Discovered %s on %s", nodename, inet_ntoa(addr->in.sin_addr));
|
||||
|
||||
n->slpd_address = cfg;
|
||||
n->status.has_address = true;
|
||||
}
|
||||
} else {
|
||||
logger(DEBUG_ALWAYS, LOG_ERR, "Got SLPD packet with wrong version %d.%d", mav, miv);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void handle_incoming_vpn_data(void *data, int flags) {
|
||||
listen_socket_t *ls = data;
|
||||
|
||||
|
|
@ -1575,6 +1621,27 @@ void handle_incoming_vpn_data(void *data, int flags) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void handle_incoming_slpd_data(void *data, int flags) {
|
||||
listen_socket_t *ls = data;
|
||||
|
||||
void *pkt;
|
||||
sockaddr_t addr = {};
|
||||
socklen_t addrlen = sizeof addr;
|
||||
|
||||
logger(DEBUG_SCARY_THINGS, LOG_INFO, "Receiving LPD packet");
|
||||
|
||||
int len = recvfrom(ls->udp.fd, (void *)&pkt, MAXSIZE, 0, &addr.sa, &addrlen);
|
||||
|
||||
if(len <= 0 || len > MAXSIZE) {
|
||||
if(!sockwouldblock(sockerrno))
|
||||
logger(DEBUG_ALWAYS, LOG_ERR, "Receiving SLPD packet failed: %s", sockstrerror(sockerrno));
|
||||
return;
|
||||
}
|
||||
|
||||
handle_incoming_slpd_packet(ls, &pkt, &addr);
|
||||
}
|
||||
|
||||
|
||||
void handle_device_data(void *data, int flags) {
|
||||
vpn_packet_t packet;
|
||||
UNUSED(data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue