- close(tap_fd);
- destroy_conn_list();
-
- syslog(LOG_NOTICE, "Terminating.");
- return;
-}
-
-/*
- create a data (udp) socket
-*/
-int setup_vpn_connection(conn_list_t *cl)
-{
- int nfd, flags;
- struct sockaddr_in a;
-
- if(debug_lvl > 1)
- syslog(LOG_DEBUG, "Opening UDP socket to " IP_ADDR_S, IP_ADDR_V(cl->real_ip));
-
- nfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if(nfd == -1)
- {
- syslog(LOG_ERR, "Creating data socket failed: %m");
- return -1;
- }
-
- a.sin_family = AF_INET;
- a.sin_port = htons(cl->port);
- a.sin_addr.s_addr = htonl(cl->real_ip);
-
- if(connect(nfd, (struct sockaddr *)&a, sizeof(a)) == -1)
- {
- syslog(LOG_ERR, "Create connection to %08lx:%d failed: %m", ntohs(cl->real_ip),
- cl->port);
- return -1;
- }
-
- flags = fcntl(nfd, F_GETFL);
- if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0)
- {
- syslog(LOG_ERR, "This is a bug: %s:%d: %d:%m", __FILE__, __LINE__, nfd);
- return -1;
- }
-
- cl->socket = nfd;
- cl->status.dataopen = 1;
-
- return 0;
-}
-
-/*
- handle an incoming tcp connect call and open
- a connection to it.
-*/
-conn_list_t *create_new_connection(int sfd)
-{
- conn_list_t *p;
- struct sockaddr_in ci;
- int len = sizeof(ci);
-
- p = new_conn_list();
-
- if(getpeername(sfd, &ci, &len) < 0)
- {
- syslog(LOG_ERR, "Error: getpeername: %m");
- return NULL;
- }
-
- p->hostname = hostlookup(ci.sin_addr.s_addr);
- p->real_ip = ntohl(ci.sin_addr.s_addr);
- p->meta_socket = sfd;
- p->status.meta = 1;
-
- syslog(LOG_NOTICE, "Connection from %s:%d", p->hostname, htons(ci.sin_port));
-
- if(send_basic_info(p) < 0)
- {
- free(p);
- return NULL;
- }
-
- return p;
-}
-
-/*
- put all file descriptors in an fd_set array
-*/
-void build_fdset(fd_set *fs)
-{
- conn_list_t *p;
-
- FD_ZERO(fs);
-
- for(p = conn_list; p != NULL; p = p->next)
- {
- if(p->status.meta)
- FD_SET(p->meta_socket, fs);
- if(p->status.dataopen)
- FD_SET(p->socket, fs);
- }
-
- FD_SET(myself->meta_socket, fs);
- FD_SET(myself->socket, fs);
- FD_SET(tap_fd, fs);
-}
-
-/*
- receive incoming data from the listening
- udp socket and write it to the ethertap
- device after being decrypted
-*/
-int handle_incoming_vpn_data(conn_list_t *cl)
-{
- real_packet_t rp;
- int lenin;
- int x, l = sizeof(x);
- conn_list_t *f;
-
- if(getsockopt(cl->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
- {
- syslog(LOG_ERR, "This is a bug: %s:%d: %d:%m", __FILE__, __LINE__, cl->socket);
- return -1;
- }
- if(x)
- {
- syslog(LOG_ERR, "Incoming data socket error: %s", sys_errlist[x]);
- return -1;
- }
-
- rp.len = -1;
- lenin = recvfrom(cl->socket, &rp, MTU, 0, NULL, NULL);
- if(lenin <= 0)
- {
- syslog(LOG_ERR, "Receiving data failed: %m");
- return -1;
- }
- total_socket_in += lenin;
- if(rp.len >= 0)
- {
- f = lookup_conn(rp.from);
- if(debug_lvl > 2)
- syslog(LOG_DEBUG, "packet from " IP_ADDR_S " (len %d)",
- IP_ADDR_V(rp.from), rp.len);
- if(!f)
- {
- syslog(LOG_ERR, "Got packet from unknown source " IP_ADDR_S,
- IP_ADDR_V(rp.from));
- return -1;
+ read_config_options(config_tree, NULL);
+
+ xasprintf(&fname, "%s/hosts/%s", confbase, myself->name);
+ read_config_file(config_tree, fname);
+ free(fname);
+
+ /* Parse some options that are allowed to be changed while tinc is running */
+
+ setup_myself_reloadable();
+
+ /* Close connections to hosts that have a changed or deleted host config file */
+
+ for(node = connection_tree->head; node; node = next) {
+ c = node->data;
+ next = node->next;
+
+ if(c->status.control)
+ continue;
+
+ if(c->outgoing) {
+ free(c->outgoing->name);
+ if(c->outgoing->ai)
+ freeaddrinfo(c->outgoing->ai);
+ free(c->outgoing);
+ c->outgoing = NULL;
+ }
+
+ xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
+ if(stat(fname, &s) || s.st_mtime > last_config_check)
+ terminate_connection(c, c->status.active);
+ free(fname);