Fix building documentation when using OpenBSD's make.
[tinc] / src / net_socket.c
1 /*
2     net_socket.c -- Handle various kinds of sockets.
3     Copyright (C) 1998-2005 Ivo Timmermans,
4                   2000-2017 Guus Sliepen <guus@tinc-vpn.org>
5                   2006      Scott Lamb <slamb@slamb.org>
6                   2009      Florian Forster <octo@verplant.org>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License along
19     with this program; if not, write to the Free Software Foundation, Inc.,
20     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include "system.h"
24
25 #include "avl_tree.h"
26 #include "conf.h"
27 #include "connection.h"
28 #include "event.h"
29 #include "logger.h"
30 #include "meta.h"
31 #include "net.h"
32 #include "netutl.h"
33 #include "protocol.h"
34 #include "proxy.h"
35 #include "utils.h"
36 #include "xalloc.h"
37
38 /* Needed on Mac OS/X */
39 #ifndef SOL_TCP
40 #define SOL_TCP IPPROTO_TCP
41 #endif
42
43 int addressfamily = AF_UNSPEC;
44 int mintimeout = 0;
45 int maxtimeout = 900;
46 int seconds_till_retry = 5;
47 int udp_rcvbuf = 0;
48 int udp_sndbuf = 0;
49
50 listen_socket_t listen_socket[MAXSOCKETS];
51 int listen_sockets;
52 list_t *outgoing_list = NULL;
53
54 /* Setup sockets */
55
56 static void configure_tcp(connection_t *c) {
57         int option;
58
59 #ifdef O_NONBLOCK
60         int flags = fcntl(c->socket, F_GETFL);
61
62         if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
63                 logger(LOG_ERR, "fcntl for %s: %s", c->hostname, strerror(errno));
64         }
65
66 #elif defined(WIN32)
67         unsigned long arg = 1;
68
69         if(ioctlsocket(c->socket, FIONBIO, &arg) != 0) {
70                 logger(LOG_ERR, "ioctlsocket for %s: %s", c->hostname, sockstrerror(sockerrno));
71         }
72
73 #endif
74
75 #if defined(SOL_TCP) && defined(TCP_NODELAY)
76         option = 1;
77         setsockopt(c->socket, SOL_TCP, TCP_NODELAY, (void *)&option, sizeof(option));
78 #endif
79
80 #if defined(SOL_IP) && defined(IP_TOS) && defined(IPTOS_LOWDELAY)
81         option = IPTOS_LOWDELAY;
82         setsockopt(c->socket, SOL_IP, IP_TOS, (void *)&option, sizeof(option));
83 #endif
84
85 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) && defined(IPTOS_LOWDELAY)
86         option = IPTOS_LOWDELAY;
87         setsockopt(c->socket, IPPROTO_IPV6, IPV6_TCLASS, (void *)&option, sizeof(option));
88 #endif
89 }
90
91 static bool bind_to_interface(int sd) {
92         char *iface;
93
94 #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
95         struct ifreq ifr;
96         int status;
97 #endif /* defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) */
98
99         if(!get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) {
100                 return true;
101         }
102
103 #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
104         memset(&ifr, 0, sizeof(ifr));
105         strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
106         ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0;
107         free(iface);
108
109         status = setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr));
110
111         if(status) {
112                 logger(LOG_ERR, "Can't bind to interface %s: %s", ifr.ifr_ifrn.ifrn_name, strerror(errno));
113                 return false;
114         }
115
116 #else /* if !defined(SOL_SOCKET) || !defined(SO_BINDTODEVICE) */
117         logger(LOG_WARNING, "%s not supported on this platform", "BindToInterface");
118 #endif
119
120         return true;
121 }
122
123 int setup_listen_socket(const sockaddr_t *sa) {
124         int nfd;
125         char *addrstr;
126         int option;
127         char *iface;
128
129         nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
130
131         if(nfd < 0) {
132                 ifdebug(STATUS) logger(LOG_ERR, "Creating metasocket failed: %s", sockstrerror(sockerrno));
133                 return -1;
134         }
135
136 #ifdef FD_CLOEXEC
137         fcntl(nfd, F_SETFD, FD_CLOEXEC);
138 #endif
139
140         /* Optimize TCP settings */
141
142         option = 1;
143         setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option));
144
145 #if defined(SOL_IPV6) && defined(IPV6_V6ONLY)
146
147         if(sa->sa.sa_family == AF_INET6) {
148                 setsockopt(nfd, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
149         }
150
151 #endif
152
153         if(get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) {
154 #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
155                 struct ifreq ifr;
156
157                 memset(&ifr, 0, sizeof(ifr));
158                 strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
159                 ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0;
160                 free(iface);
161
162                 if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr))) {
163                         closesocket(nfd);
164                         logger(LOG_ERR, "Can't bind to interface %s: %s", ifr.ifr_ifrn.ifrn_name, strerror(sockerrno));
165                         return -1;
166                 }
167
168 #else
169                 logger(LOG_WARNING, "%s not supported on this platform", "BindToInterface");
170 #endif
171         }
172
173         if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
174                 closesocket(nfd);
175                 addrstr = sockaddr2hostname(sa);
176                 logger(LOG_ERR, "Can't bind to %s/tcp: %s", addrstr, sockstrerror(sockerrno));
177                 free(addrstr);
178                 return -1;
179         }
180
181         if(listen(nfd, 3)) {
182                 closesocket(nfd);
183                 logger(LOG_ERR, "System call `%s' failed: %s", "listen", sockstrerror(sockerrno));
184                 return -1;
185         }
186
187         return nfd;
188 }
189
190 int setup_vpn_in_socket(const sockaddr_t *sa) {
191         int nfd;
192         char *addrstr;
193         int option;
194
195         nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
196
197         if(nfd < 0) {
198                 logger(LOG_ERR, "Creating UDP socket failed: %s", sockstrerror(sockerrno));
199                 return -1;
200         }
201
202 #ifdef FD_CLOEXEC
203         fcntl(nfd, F_SETFD, FD_CLOEXEC);
204 #endif
205
206 #ifdef O_NONBLOCK
207         {
208                 int flags = fcntl(nfd, F_GETFL);
209
210                 if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
211                         closesocket(nfd);
212                         logger(LOG_ERR, "System call `%s' failed: %s", "fcntl",
213                                strerror(errno));
214                         return -1;
215                 }
216         }
217 #elif defined(WIN32)
218         {
219                 unsigned long arg = 1;
220
221                 if(ioctlsocket(nfd, FIONBIO, &arg) != 0) {
222                         closesocket(nfd);
223                         logger(LOG_ERR, "Call to `%s' failed: %s", "ioctlsocket", sockstrerror(sockerrno));
224                         return -1;
225                 }
226         }
227 #endif
228
229         option = 1;
230         setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option));
231         setsockopt(nfd, SOL_SOCKET, SO_BROADCAST, (void *)&option, sizeof(option));
232
233         if(udp_rcvbuf && setsockopt(nfd, SOL_SOCKET, SO_RCVBUF, (void *)&udp_rcvbuf, sizeof(udp_rcvbuf))) {
234                 logger(LOG_WARNING, "Can't set UDP SO_RCVBUF to %i: %s", udp_rcvbuf, strerror(errno));
235         }
236
237         if(udp_sndbuf && setsockopt(nfd, SOL_SOCKET, SO_SNDBUF, (void *)&udp_sndbuf, sizeof(udp_sndbuf))) {
238                 logger(LOG_WARNING, "Can't set UDP SO_SNDBUF to %i: %s", udp_sndbuf, strerror(errno));
239         }
240
241 #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
242
243         if(sa->sa.sa_family == AF_INET6) {
244                 setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
245         }
246
247 #endif
248
249 #if defined(IP_DONTFRAG) && !defined(IP_DONTFRAGMENT)
250 #define IP_DONTFRAGMENT IP_DONTFRAG
251 #endif
252
253 #if defined(SOL_IP) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
254
255         if(myself->options & OPTION_PMTU_DISCOVERY) {
256                 option = IP_PMTUDISC_DO;
257                 setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, (void *)&option, sizeof(option));
258         }
259
260 #elif defined(IPPROTO_IP) && defined(IP_DONTFRAGMENT)
261
262         if(myself->options & OPTION_PMTU_DISCOVERY) {
263                 option = 1;
264                 setsockopt(nfd, IPPROTO_IP, IP_DONTFRAGMENT, (void *)&option, sizeof(option));
265         }
266
267 #endif
268
269 #if defined(SOL_IPV6) && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
270
271         if(myself->options & OPTION_PMTU_DISCOVERY) {
272                 option = IPV6_PMTUDISC_DO;
273                 setsockopt(nfd, SOL_IPV6, IPV6_MTU_DISCOVER, (void *)&option, sizeof(option));
274         }
275
276 #elif defined(IPPROTO_IPV6) && defined(IPV6_DONTFRAG)
277
278         if(myself->options & OPTION_PMTU_DISCOVERY) {
279                 option = 1;
280                 setsockopt(nfd, IPPROTO_IPV6, IPV6_DONTFRAG, (void *)&option, sizeof(option));
281         }
282
283 #endif
284
285         if(!bind_to_interface(nfd)) {
286                 closesocket(nfd);
287                 return -1;
288         }
289
290         if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
291                 closesocket(nfd);
292                 addrstr = sockaddr2hostname(sa);
293                 logger(LOG_ERR, "Can't bind to %s/udp: %s", addrstr, sockstrerror(sockerrno));
294                 free(addrstr);
295                 return -1;
296         }
297
298         return nfd;
299 } /* int setup_vpn_in_socket */
300
301 void retry_outgoing(outgoing_t *outgoing) {
302         outgoing->timeout += 5;
303
304         if(outgoing->timeout < mintimeout) {
305                 outgoing->timeout = mintimeout;
306         }
307
308         if(outgoing->timeout > maxtimeout) {
309                 outgoing->timeout = maxtimeout;
310         }
311
312         if(outgoing->event) {
313                 event_del(outgoing->event);
314         }
315
316         outgoing->event = new_event();
317         outgoing->event->handler = (event_handler_t) setup_outgoing_connection;
318         outgoing->event->time = now + outgoing->timeout;
319         outgoing->event->data = outgoing;
320         event_add(outgoing->event);
321
322         ifdebug(CONNECTIONS) logger(LOG_NOTICE,
323                                     "Trying to re-establish outgoing connection in %d seconds",
324                                     outgoing->timeout);
325 }
326
327 void finish_connecting(connection_t *c) {
328         ifdebug(CONNECTIONS) logger(LOG_INFO, "Connected to %s (%s)", c->name, c->hostname);
329
330         c->last_ping_time = now;
331
332         send_id(c);
333 }
334
335 static void do_outgoing_pipe(connection_t *c, char *command) {
336 #ifndef HAVE_MINGW
337         int fd[2];
338
339         if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
340                 logger(LOG_ERR, "Could not create socketpair: %s\n", strerror(errno));
341                 return;
342         }
343
344         if(fork()) {
345                 c->socket = fd[0];
346                 close(fd[1]);
347                 ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Using proxy %s", command);
348                 return;
349         }
350
351         close(0);
352         close(1);
353         close(fd[0]);
354         dup2(fd[1], 0);
355         dup2(fd[1], 1);
356         close(fd[1]);
357
358         // Other filedescriptors should be closed automatically by CLOEXEC
359
360         char *host = NULL;
361         char *port = NULL;
362
363         sockaddr2str(&c->address, &host, &port);
364         setenv("REMOTEADDRESS", host, true);
365         setenv("REMOTEPORT", port, true);
366         setenv("NODE", c->name, true);
367         setenv("NAME", myself->name, true);
368
369         if(netname) {
370                 setenv("NETNAME", netname, true);
371         }
372
373         int result = system(command);
374
375         if(result < 0) {
376                 logger(LOG_ERR, "Could not execute %s: %s\n", command, strerror(errno));
377         } else if(result) {
378                 logger(LOG_ERR, "%s exited with non-zero status %d", command, result);
379         }
380
381         exit(result);
382 #else
383         logger(LOG_ERR, "Proxy type exec not supported on this platform!");
384         return;
385 #endif
386 }
387
388 static bool is_valid_host_port(const char *host, const char *port) {
389         for(const char *p = host; *p; p++)
390                 if(!isalnum(*p) && *p != '-' && *p != '.') {
391                         return false;
392                 }
393
394         for(const char *p = port; *p; p++)
395                 if(!isalnum(*p)) {
396                         return false;
397                 }
398
399         return true;
400 }
401
402 void do_outgoing_connection(connection_t *c) {
403         struct addrinfo *proxyai = NULL;
404         int result;
405
406         if(!c->outgoing) {
407                 logger(LOG_ERR, "do_outgoing_connection() for %s called without c->outgoing", c->name);
408                 abort();
409         }
410
411 begin:
412
413         if(!c->outgoing->ai) {
414                 if(!c->outgoing->cfg) {
415                         ifdebug(CONNECTIONS) logger(LOG_ERR, "Could not set up a meta connection to %s",
416                                                     c->name);
417                         c->status.remove = true;
418                         retry_outgoing(c->outgoing);
419                         c->outgoing = NULL;
420                         return;
421                 }
422
423                 char *address, *port, *space;
424
425                 get_config_string(c->outgoing->cfg, &address);
426
427                 space = strchr(address, ' ');
428
429                 if(space) {
430                         port = xstrdup(space + 1);
431                         *space = 0;
432                 } else {
433                         if(!get_config_string(lookup_config(c->config_tree, "Port"), &port)) {
434                                 port = xstrdup("655");
435                         }
436                 }
437
438                 c->outgoing->ai = str2addrinfo(address, port, SOCK_STREAM);
439
440                 // If we cannot resolve the address, maybe we are using a proxy that can?
441                 if(!c->outgoing->ai && proxytype != PROXY_NONE && is_valid_host_port(address, port)) {
442                         memset(&c->address, 0, sizeof(c->address));
443                         c->address.sa.sa_family = AF_UNKNOWN;
444                         c->address.unknown.address = address;
445                         c->address.unknown.port = port;
446                 } else {
447                         free(address);
448                         free(port);
449                 }
450
451                 c->outgoing->aip = c->outgoing->ai;
452                 c->outgoing->cfg = lookup_config_next(c->config_tree, c->outgoing->cfg);
453
454                 if(!c->outgoing->ai && proxytype != PROXY_NONE) {
455                         goto connect;
456                 }
457         }
458
459         if(!c->outgoing->aip) {
460                 if(c->outgoing->ai) {
461                         freeaddrinfo(c->outgoing->ai);
462                 }
463
464                 c->outgoing->ai = NULL;
465                 goto begin;
466         }
467
468         memcpy(&c->address, c->outgoing->aip->ai_addr, c->outgoing->aip->ai_addrlen);
469         c->outgoing->aip = c->outgoing->aip->ai_next;
470
471 connect:
472
473         if(c->hostname) {
474                 free(c->hostname);
475         }
476
477         c->hostname = sockaddr2hostname(&c->address);
478
479         ifdebug(CONNECTIONS) logger(LOG_INFO, "Trying to connect to %s (%s)", c->name,
480                                     c->hostname);
481
482         if(!proxytype) {
483                 c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
484         } else if(proxytype == PROXY_EXEC) {
485                 c->status.proxy_passed = true;
486                 do_outgoing_pipe(c, proxyhost);
487         } else {
488                 proxyai = str2addrinfo(proxyhost, proxyport, SOCK_STREAM);
489
490                 if(!proxyai) {
491                         goto begin;
492                 }
493
494                 ifdebug(CONNECTIONS) logger(LOG_INFO, "Using proxy at %s port %s", proxyhost, proxyport);
495                 c->socket = socket(proxyai->ai_family, SOCK_STREAM, IPPROTO_TCP);
496         }
497
498         if(c->socket == -1) {
499                 ifdebug(CONNECTIONS) logger(LOG_ERR, "Creating socket for %s failed: %s", c->hostname, sockstrerror(sockerrno));
500                 goto begin;
501         }
502
503         if(proxytype != PROXY_EXEC) {
504                 configure_tcp(c);
505         }
506
507 #ifdef FD_CLOEXEC
508         fcntl(c->socket, F_SETFD, FD_CLOEXEC);
509 #endif
510
511         if(proxytype != PROXY_EXEC) {
512 #if defined(SOL_IPV6) && defined(IPV6_V6ONLY)
513                 int option = 1;
514
515                 if(c->address.sa.sa_family == AF_INET6) {
516                         setsockopt(c->socket, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option));
517                 }
518
519 #endif
520
521                 bind_to_interface(c->socket);
522
523                 int b = -1;
524
525                 for(int i = 0; i < listen_sockets; i++) {
526                         if(listen_socket[i].sa.sa.sa_family == c->address.sa.sa_family) {
527                                 if(b == -1) {
528                                         b = i;
529                                 } else  {
530                                         b = -1;
531                                         break;
532                                 }
533                         }
534                 }
535
536                 if(b != -1) {
537                         sockaddr_t sa = listen_socket[b].sa;
538
539                         if(sa.sa.sa_family == AF_INET) {
540                                 sa.in.sin_port = 0;
541                         } else if(sa.sa.sa_family == AF_INET6) {
542                                 sa.in6.sin6_port = 0;
543                         }
544
545                         if(bind(c->socket, &sa.sa, SALEN(sa.sa))) {
546                                 char *addrstr = sockaddr2hostname(&sa);
547                                 logger(LOG_ERR, "Can't bind to %s/tcp: %s", addrstr, sockstrerror(sockerrno));
548                                 free(addrstr);
549                         }
550                 }
551         }
552
553         /* Connect */
554
555         if(!proxytype) {
556                 result = connect(c->socket, &c->address.sa, SALEN(c->address.sa));
557         } else if(proxytype == PROXY_EXEC) {
558                 result = 0;
559         } else {
560                 result = connect(c->socket, proxyai->ai_addr, proxyai->ai_addrlen);
561                 freeaddrinfo(proxyai);
562         }
563
564         now = time(NULL);
565
566         if(result == -1) {
567                 if(sockinprogress(sockerrno)) {
568                         c->last_ping_time = now;
569                         c->status.connecting = true;
570                         return;
571                 }
572
573                 closesocket(c->socket);
574
575                 ifdebug(CONNECTIONS) logger(LOG_ERR, "%s: %s", c->hostname, sockstrerror(sockerrno));
576
577                 goto begin;
578         }
579
580         finish_connecting(c);
581
582         return;
583 }
584
585 void setup_outgoing_connection(outgoing_t *outgoing) {
586         connection_t *c;
587         node_t *n;
588
589         outgoing->event = NULL;
590
591         n = lookup_node(outgoing->name);
592
593         if(n)
594                 if(n->connection) {
595                         ifdebug(CONNECTIONS) logger(LOG_INFO, "Already connected to %s", outgoing->name);
596
597                         n->connection->outgoing = outgoing;
598                         return;
599                 }
600
601         c = new_connection();
602         c->name = xstrdup(outgoing->name);
603         c->outcipher = myself->connection->outcipher;
604         c->outdigest = myself->connection->outdigest;
605         c->outmaclength = myself->connection->outmaclength;
606         c->outcompression = myself->connection->outcompression;
607
608         init_configuration(&c->config_tree);
609
610         if(!read_connection_config(c)) {
611                 free_connection(c);
612                 outgoing->timeout = maxtimeout;
613                 retry_outgoing(outgoing);
614                 return;
615         }
616
617         outgoing->cfg = lookup_config(c->config_tree, "Address");
618
619         if(!outgoing->cfg) {
620                 logger(LOG_ERR, "No address specified for %s", c->name);
621                 free_connection(c);
622                 outgoing->timeout = maxtimeout;
623                 retry_outgoing(outgoing);
624                 return;
625         }
626
627         c->outgoing = outgoing;
628         c->last_ping_time = now;
629
630         connection_add(c);
631
632         do_outgoing_connection(c);
633 }
634
635 /*
636   accept a new tcp connect and create a
637   new connection
638 */
639 bool handle_new_meta_connection(int sock) {
640         connection_t *c;
641         sockaddr_t sa;
642         int fd;
643         socklen_t len = sizeof(sa);
644
645         fd = accept(sock, &sa.sa, &len);
646
647         if(fd < 0) {
648                 logger(LOG_ERR, "Accepting a new connection failed: %s", sockstrerror(sockerrno));
649                 return false;
650         }
651
652         sockaddrunmap(&sa);
653
654         c = new_connection();
655         c->name = xstrdup("<unknown>");
656         c->outcipher = myself->connection->outcipher;
657         c->outdigest = myself->connection->outdigest;
658         c->outmaclength = myself->connection->outmaclength;
659         c->outcompression = myself->connection->outcompression;
660
661         c->address = sa;
662         c->hostname = sockaddr2hostname(&sa);
663         c->socket = fd;
664         c->last_ping_time = now;
665
666         ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection from %s", c->hostname);
667
668         configure_tcp(c);
669
670         connection_add(c);
671
672         c->allow_request = ID;
673         send_id(c);
674
675         return true;
676 }
677
678 static void free_outgoing(outgoing_t *outgoing) {
679         if(outgoing->ai) {
680                 freeaddrinfo(outgoing->ai);
681         }
682
683         if(outgoing->name) {
684                 free(outgoing->name);
685         }
686
687         free(outgoing);
688 }
689
690 void try_outgoing_connections(void) {
691         static config_t *cfg = NULL;
692         char *name;
693         outgoing_t *outgoing;
694
695         outgoing_list = list_alloc((list_action_t)free_outgoing);
696
697         for(cfg = lookup_config(config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
698                 get_config_string(cfg, &name);
699
700                 if(!check_id(name)) {
701                         logger(LOG_ERR,
702                                "Invalid name for outgoing connection in %s line %d",
703                                cfg->file, cfg->line);
704                         free(name);
705                         continue;
706                 }
707
708                 outgoing = xmalloc_and_zero(sizeof(*outgoing));
709                 outgoing->name = name;
710                 list_insert_tail(outgoing_list, outgoing);
711                 setup_outgoing_connection(outgoing);
712         }
713 }