- Lots of small changes.
[tinc] / src / protocol.c
1 /*
2     protocol.c -- handle the meta-protocol
3     Copyright (C) 1999,2000 Ivo Timmermans <itimmermans@bigfoot.com>,
4                        2000 Guus Sliepen <guus@sliepen.warande.net>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id: protocol.c,v 1.28.4.30 2000/09/14 11:54:51 guus Exp $
21 */
22
23 #include "config.h"
24
25 #include <sys/types.h>
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include <syslog.h>
30 #include <sys/socket.h>
31 #include <unistd.h>
32 #include <stdio.h>
33
34 #include <utils.h>
35 #include <xalloc.h>
36
37 #include <netinet/in.h>
38
39 #include "conf.h"
40 #include "encr.h"
41 #include "net.h"
42 #include "netutl.h"
43 #include "protocol.h"
44
45 #include "system.h"
46
47 /* Generic outgoing request routine - takes care of logging and error detection as well */
48
49 int send_request(conn_list_t *cl, const char *format, int request, /*args*/ ...)
50 {
51   va_list args;
52   char *buffer = NULL;
53 cp
54   if(debug_lvl >= DEBUG_PROTOCOL)
55     syslog(LOG_DEBUG, _("Sending %s to %s (%s)"), requestname[request], cl->id, cl->hostname);
56
57   va_start(args, format);
58   len = vasprintf(&buffer, format, args);
59   va_end(args);
60
61   if(len < 0 || !buffer)
62     {
63       syslog(LOG_ERR, _("Error during vasprintf(): %m"));
64       return -1;
65     }
66
67   if(debug_lvl >= DEBUG_META)
68     syslog(LOG_DEBUG, _("Sending meta data to %s (%s): %s"), cl->id, cl->hostname, buffer);
69
70   if(cl->status.encrypted)
71     {
72       /* FIXME: Do encryption */
73     }
74
75   if((write(cl->meta_socket, buffer, buflen)) < 0)
76     {
77       syslog(LOG_ERR, _("Sending meta data failed:  %m"));
78       return -1;
79     }
80 cp  
81 }
82
83 /* Connection protocol:
84
85    Client               Server
86    send_id(u)
87                         send_challenge(R)
88    send_chal_reply(BH)                   
89                         send_id(B)
90    send_challenge(BR)
91                         send_chal_reply(BH)
92    send_ack(B)
93                         send_ack(B)
94
95    (u) Unencrypted,
96    (R) RSA,
97    (H) SHA1,
98    (B) Blowfish.
99
100    Part of the challenge is directly used to set the blowfish key and the initial vector.
101    (Twee vliegen in één klap!)
102 */      
103
104 int send_id(conn_list_t *cl)
105 {
106 cp
107   return send_request(cl, "%d %s %d %s", ID, myself->id, myself->version, opt2str(myself->options));
108 }
109
110 int id_h(conn_list_t *cl)
111 {
112   conn_list_t *old;
113   char *options;
114 cp
115   if(sscanf(cl->buffer, "%*d %as %d %as", &cl->id, &cl->version, &options) != 3)
116     {
117        syslog(LOG_ERR, _("Got bad ID from %s"), cl->hostname);
118        return -1;
119     }
120     
121   /* Check if version matches */
122   
123   if(cl->version != myself->version)
124     {
125       syslog(LOG_ERR, _("Peer %s uses incompatible version %d"), cl->hostname, cl->min_version, cl->max_version);
126       return -1;
127     }
128
129   /* Check if option string is valid */
130   
131   if((cl->options = str2opt(options)) == -1)
132     {
133       syslog(LOG_ERR, _("Peer %s uses invalid option string"), cl->hostname);
134       return -1;
135     }
136     
137   /* Check if identity is a valid name */
138   
139   if(!check_id(cl->id))
140     {
141       syslog(LOG_ERR, _("Peer %s uses invalid identity name"), cl->hostname);
142       return -1;
143     }
144     
145   /* Load information about peer */
146   
147   if(!read_id(cl))
148     {
149       syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), cl->hostname, cl->id);
150       return -1;
151     }
152
153
154   /* First check if the host we connected to is already in our
155      connection list. If so, we are probably making a loop, which
156      is not desirable.
157    */
158
159   if(cl->status.outgoing)
160     {
161       if((old=lookup_id(cl->id)))
162         {
163           if(debug_lvl > DEBUG_CONNECTIONS)
164             syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"), cl->id, cl->hostname);
165           cl->status.outgoing = 0;
166           old->status.outgoing = 1;
167           terminate_connection(cl);
168           return 0;
169         }
170     }
171
172   /* Send a challenge to verify the identity */
173
174   cl->allow_request = CHAL_REPLY;
175 cp
176   return send_challenge(cl);
177 }
178
179 int send_challenge(conn_list_t *cl)
180 {
181   char *buffer;
182   int keylength;
183   int x;
184 cp
185   if(cl->chal_hash)
186     free(cl->chal_hash);
187   
188   /* Allocate buffers for the challenge and the hash */
189   
190   cl->chal_hash = xmalloc(SHA_DIGEST_LEN);
191   keylength = BN_num_bytes(cl->rsakey.n);
192   buffer = xmalloc(keylength*2);
193
194   /* Copy random data and the public key to the buffer */
195   
196   RAND_bytes(buffer, keylength);
197   BN_bn2bin(cl->rsakey.n, buffer+keylength);
198
199   /* If we don't have a blowfish key set yet, use the random data from the challenge to do so. */
200   
201   if(!cl->status.encrypted)
202     {
203       set_metakey(cl, buffer, keylength);
204     }
205
206   /* Calculate the hash from that */
207
208   SHA1(buffer, keylength*2, cl->chal_hash);
209
210   /* Convert the random data to a hexadecimal formatted string */
211
212   bin2hex(buffer,buffer,keylength);
213   buffer[keylength*2] = '\0';
214
215   /* Send the challenge */
216   
217   cl->allow_request = CHAL_REPLY;
218   x = send_request(cl, "%d %s", CHALLENGE, buffer);
219   free(buffer);
220   cl->status.encrypted = 1;
221 cp
222   return x;
223 }
224
225 int challenge_h(conn_list_t *cl)
226 {
227   char *challenge;
228 cp
229   if(sscanf(cl->buffer, "%*d %as", &cl->id, &challenge) != 1)
230     {
231        syslog(LOG_ERR, _("Got bad CHALLENGE from %s (%s)"), cl->id, cl->hostname);
232        return -1;
233     }
234
235   /* Rest is done by send_chal_reply() */
236   
237   x = send_chal_reply(cl, challenge);
238   free(challenge);
239 cp
240   return x;
241 }
242
243 int send_chal_reply(conn_list_t *cl, char *challenge)
244 {
245   char *buffer;
246   int keylength;
247   char *hash;
248   int x;
249 cp
250   keylength = BN_num_bytes(myself->rsakey.n);
251
252   /* Check if the length of the challenge is all right */
253
254   if(strlen(challenge) != keylength*2)
255     {
256       syslog(LOG_ERROR, _("Intruder: wrong challenge length from %s (%s)"), cl->id, cl->hostname);
257       return -1;
258     }
259
260   /* Allocate buffers for the challenge and the hash */
261   
262   buffer = xmalloc(keylength*2);
263   hash = xmalloc(SHA_DIGEST_LEN*2+1);
264
265   /* Copy the incoming random data and our public key to the buffer */
266
267   hex2bin(challenge, buffer, keylength); 
268   BN_bn2bin(myself->rsakey.n, buffer+keylength);
269
270   /* Calculate the hash from that */
271   
272   SHA1(buffer, keylength*2, hash);
273
274   /* If we don't have a blowfish key set yet, use the random data from the challenge to do so. */
275   
276   if(!cl->status.encrypted)
277     {
278       set_metakey(cl, buffer, keylength);
279       cl->status.encrypted = 1;
280     }
281
282   free(buffer);
283
284   /* Convert the hash to a hexadecimal formatted string */
285
286   bin2hex(hash,hash,SHA_DIGEST_LEN);
287   hash[SHA_DIGEST_LEN*2] = '\0';
288
289   /* Send the reply */
290
291   if(cl->status.outgoing)
292     cl->allow_resuest = ID;
293   else
294     cl->allow_request = ACK;
295
296   x = send_request(cl, "%d %s", CHAL_REPLY, hash);
297   free(hash);
298 cp
299   return x;
300
301
302 int chal_reply_h(conn_list_t *cl)
303 {
304   char *hash;
305 cp
306   if(sscanf(cl->buffer, "%*d %as", &cl->id, &hash) != 2)
307     {
308        syslog(LOG_ERR, _("Got bad CHAL_REPLY from %s (%s)"), cl->id, cl->hostname);
309        return -1;
310     }
311
312   /* Check if the length of the hash is all right */
313   
314   if(strlen(hash) != SHA_DIGEST_LEN*2)
315     {
316       syslog(LOG_ERROR, _("Intruder: wrong challenge reply length from %s (%s)"), cl->id, cl->hostname);
317       return -1;
318     }
319     
320   /* Convert the hash to binary format */
321   
322   hex2bin(hash, hash, SHA_DIGEST_LEN);
323   
324   /* Verify the incoming hash with the calculated hash */
325   
326   if{!memcmp(hash, cl->chal_hash, SHA_DIGEST_LEN)}
327     {
328       syslog(LOG_ERROR, _("Intruder: wrong challenge reply from %s (%s)"), cl->id, cl->hostname);
329       return -1;
330     }
331
332   /* Identity has now been positively verified.
333      If we are accepting this new connection, then send our identity,
334      if we are making this connecting, acknowledge.
335    */
336    
337   free(hash);
338   free(cl->chal_hash);
339
340 cp
341   if(cl->status.outgoing)
342     {
343       cl->allow_request = ACK;
344       return send_ack(cl);
345     }
346   else
347     {
348       cl->allow_request = CHALLENGE;
349       return send_id(cl);
350     }
351 }
352
353 int send_ack(conn_list_t *cl)
354 {
355 cp
356   return send_request(cl, "%d", ACK);
357 }
358
359 int ack_h(conn_list_t *cl)
360 {
361   conn_list_t old;
362 cp
363   /* Okay, before we active the connection, we check if there is another entry
364      in the connection list with the same vpn_ip. If so, it presumably is an
365      old connection that has timed out but we don't know it yet.
366    */
367
368   while((old = lookup_id(cl->id))) 
369     {
370       if(debug_lvl > DEBUG_CONNECTIONS)
371         syslog(LOG_NOTICE, _("Removing old entry for %s at %s in favour of new connection from %s"),
372         cl->id, old->hostname, cl->hostname);
373       old->status.active = 0;
374       terminate_connection(old);
375     }
376
377   /* Activate this connection */
378
379   cl->allow_request = ALL;
380   cl->status.active = 1;
381
382   if(debug_lvl > DEBUG_CONNECTIONS)
383     syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), cl->id, cl->hostname);
384
385   /* Exchange information about other tinc daemons */
386
387   notify_others(cl, NULL, send_add_host);
388   notify_one(cl);
389
390   upstreamindex = 0;
391
392 cp
393   if(cl->status.outgoing)
394     return 0;
395   else
396     return send_ack(cl);
397 }
398
399 /* Address and subnet information exchange */
400
401 int send_add_subnet(conn_list_t *cl, conn_list_t *other, subnet_t *subnet)
402 {
403 cp
404   return send_request(cl, "%d %s %d %s", ADD_SUBNET, other->id, subnet->type, net2str(subnet));
405 }
406
407 int add_subnet_h(conn_list_t *cl)
408 {
409 }
410
411 int send_del_subnet(conn_list_t *cl, conn_list_t *other, subnet_t *subnet)
412 {
413 cp
414   return send_request(cl, "%d %s %d %s", DEL_SUBNET, other->id, subnet->type, net2str(subnet));
415 }
416
417 int del_subnet_h(conn_list_t *cl)
418 {
419 }
420
421 /* New and closed connections notification */
422
423 int send_add_host(conn_list_t *cl, conn_list_t *other)
424 {
425 cp
426   return send_request(cl, "%d %s %lx:%d %s", ADD_HOST, other->id, other->address, other->port, opt2str(other->options));
427 }
428
429 int add_host_h(conn_list_t *cl)
430 {
431   char *options;
432   conn_list_t *old, *new;
433 cp
434   new = new_conn_list();
435
436   if(sscanf(cl->buffer, "%*d %as %lx:%d %as", &new->id, &new->address, &new->port, &options) != 4)
437     {
438        syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s)"), cl->id, cl->hostname);
439        return -1;
440     }  
441
442   /* Check if option string is valid */
443   
444   if((new->options = str2opt(options) == -1)
445     {
446       syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid option string"), cl->hostname);
447       return -1;
448     }
449
450   /* Check if identity is a valid name */
451   
452   if(!check_id(new->id))
453     {
454       syslog(LOG_ERR, _("Got bad ADD_HOST from %s (%s): invalid identity name"), cl->id, cl->hostname);
455       return -1;
456     }
457     
458   /* Check if somebody tries to add ourself */
459   
460   if(!strcmp(new->id, myself->id))
461     {
462       syslog(LOG_ERR, _("Warning: got ADD_HOST from %s (%s) for ourself, restarting"), cl->id, cl->hostname);
463       sighup = 1;
464       return 0;
465     }
466
467   /* Fill in more of the new conn_list structure */
468
469   new->hostname = hostlookup(htonl(new->address));
470   
471   /* Check if the new host already exists in the connnection list */
472
473   if((old = lookup_id(id))
474     {
475       if((new->address == old->address) && (new->port == old->port))
476         {
477           if(debug_lvl > DEBUG_CONNECTIONS)
478             syslog(LOG_NOTICE, _("Got duplicate ADD_HOST for %s (%s) from %s (%s)"), old->id, old->hostname, new->id, new->hostname);
479           return 0;
480         }
481       else
482         {
483           if(debug_lvl > DEBUG_CONNECTIONS)
484             syslog(LOG_NOTICE, _("Removing old entry for %s (%s)"), old->id, old->hostname);
485           old->status.active = 0;
486           terminate_connection(old);
487         }
488     }
489
490   /* Fill in rest of conn_list structure */
491
492   new->nexthop = cl;
493   new->status.active = 1;
494   
495   /* Hook it up into the conn_list */
496
497   conn_list_add(conn_list, new);
498
499   /* Tell the rest about the new host */
500   
501   notify_others(new, cl, send_add_host);
502   
503 cp
504   return 0;
505 }
506
507 int send_del_host(conn_list_t *cl, conn_list_t *other)
508 {
509 cp
510   return send_request(cl, "%d %s %lx:%d", DEL_HOST, other->id, other->address, other->port);
511 }
512
513 int del_host_h(conn_list_t *cl)
514 {
515   char *id;
516   ip_t address;
517   port_t port;
518   conn_list_t *old;
519 cp
520   if(sscanf(cl->buffer, "%*d %as %lx:%d", &id, &address, &port) != 3)
521     {
522        syslog(LOG_ERR, _("Got bad DEL_HOST from %s (%s)"), cl->id, cl->hostname);
523        return -1;
524     }  
525
526   /* Check if somebody tries to delete ourself */
527   
528   if(!strcmp(id, myself->id))
529     {
530       syslog(LOG_ERR, _("Warning: got DEL_HOST from %s (%s) for ourself, restarting"), cl->id, cl->hostname);
531       sighup = 1;
532       return 0;
533     }
534
535   /* Check if the new host already exists in the connnection list */
536
537   if((old = lookup_id(id))
538     {
539       if((address == old->address) && (port == old->port))
540         {
541           notify_others(old, cl, send_del_host);
542
543           fw->status.termreq = 1;
544           fw->status.active = 0;
545
546           terminate_connection(fw);
547 cp
548           return 0;
549         }
550     }
551
552   if(debug_lvl > DEBUG_CONNECTIONS)
553     {
554       syslog(LOG_NOTICE, _("Got DEL_HOST for %s from %s (%s) which is not in our connection list"), id, cl->id, cl->hostname);
555     }
556 cp
557   return 0;
558 }
559
560 /* Status and error notification routines */
561
562 int send_status(conn_list_t *cl, int statusno, char *statusstring)
563 {
564 cp
565   if(!statusstring)
566     statusstring = status_text[statusno];
567 cp
568   return send_request(cl, "%d %d %s", STATUS, statusno, statusstring);
569 }
570
571 int status_h(conn_list_t *cl)
572 {
573   int statusno;
574   char *statusstring;
575 cp
576   if(sscanf(cl->buffer, "%*d %d %as", &statusno, &statusstring) != 2)
577     {
578        syslog(LOG_ERR, _("Got bad STATUS from %s (%s)"), cl->id, cl->hostname);
579        return -1;
580     }
581
582   if(debug_lvl > DEBUG_STATUS)
583     {
584       syslog(LOG_NOTICE, _("Status message from %s (%s): %s: %s"), cl->id, cl->hostname, status_text[statusno], statusstring);
585     }
586
587 cp
588   free(statusstring);
589   return 0;
590 }
591
592 int send_error(conn_list_t *cl, int errno, char *errstring)
593 {
594 cp
595   if(!errorstring)
596     errorstring = error_text[errno];
597   return send_request(cl, "%d %d %s", ERROR, errno, errstring);
598 }
599
600 int error_h(conn_list_t *cl)
601 {
602   int errno;
603   char *errorstring;
604 cp
605   if(sscanf(cl->buffer, "%*d %d %as", &errno, &errorstring) != 2)
606     {
607        syslog(LOG_ERR, _("Got bad error from %s (%s)"), cl->id, cl->hostname);
608        return -1;
609     }
610
611   if(debug_lvl > DEBUG_error)
612     {
613       syslog(LOG_NOTICE, _("Error message from %s (%s): %s: %s"), cl->id, cl->hostname, error_text[errno], errorstring);
614     }
615
616   free(errorstring);
617   cl->status.termreq = 1;
618   terminate_connection(cl);
619 cp
620   return 0;
621 }
622
623 int send_termreq(conn_list_t *cl)
624 {
625 cp
626   return send_request(cl, "%d", TERMREQ);
627 }
628
629 int termreq_h(conn_list_t *cl)
630 {
631 cp
632   cl->status.termreq = 1;
633   terminate_connection(cl);
634 cp
635   return 0;
636 }
637
638 /* Keepalive routines - FIXME: needs a closer look */
639
640 int send_ping(conn_list_t *cl)
641 {
642   cl->status.pinged = 1;
643 cp
644   return send_request(cl, "%d", PING);
645 }
646
647 int ping_h(conn_list_t *cl)
648 {
649 cp
650   return send_pong(cl);
651 }
652
653 int send_pong(conn_list_t *cl)
654 {
655 cp
656   return send_request(cl, "%d", PONG);
657 }
658
659 int pong_h(conn_list_t *cl)
660 {
661 cp
662   cl->status.got_pong = 1;
663 cp
664   return 0;
665 }
666
667 /* Key exchange */
668
669 int send_key_changed(conn_list_t *from, conn_list_t *cl)
670 {
671   conn_list_t *p;
672 cp
673   for(p = conn_list; p != NULL; p = p->next)
674     {
675       if(p!=cl && p->status.meta && p->status.active)
676         send_request(p, "%d %s", KEY_CHANGED, from->id);
677     }
678 cp
679   return 0;
680 }
681
682 int key_changed_h(conn_list_t *cl)
683 {
684   char *from_id;
685   conn_list_t *from;
686 cp
687   if(sscanf(cl->buffer, "%*d %as", &from_id) != 1)
688     {
689        syslog(LOG_ERR, _("Got bad KEY_CHANGED from %s (%s)"), cl->id, cl->hostname);
690        return -1;
691     }  
692
693   if(!(from = lookup_id(from_id)))
694     {
695       syslog(LOG_ERR, _("Got KEY_CHANGED from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
696       free(from_id);
697       return -1;
698     }
699
700   free(from_id);
701     
702   from->status.validkey = 0;
703   from->status.waitingforkey = 0;
704   
705   send_key_changed(from, cl);
706 cp
707   return 0;
708 }
709   
710 int send_req_key(conn_list_t *from, conn_list_t *to)
711 {
712 cp
713   return send_request(to->nexthop, "%d %s %s", REQ_KEY, from->id, to->id);
714 }
715
716 int req_key_h(conn_list_t *cl)
717 {
718   char *from_id, *to_id;
719   conn_list_t *from, *to;
720 cp
721   if(sscanf(cl->buffer, "%*d %as %as", &from_id, &to_id) != 2)
722     {
723        syslog(LOG_ERR, _("Got bad REQ_KEY from %s (%s)"), cl->id, cl->hostname);
724        return -1;
725     }  
726
727   if(!(from = lookup_id(from_id)))
728     {
729       syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
730       free(from_id); free(to_id);
731       return -1;
732     }
733
734   /* Check if this key request is for us */
735
736   if(!strcmp(id, myself->strcmp))
737     {
738       send_ans_key(myself, from, myself->datakey);
739     }
740   else
741     {
742       if(!(to = lookup_id(to_id)))
743         {
744           syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) destination %s which does not exist in our connection list"), cl->id, cl->hostname, to_id);
745           free(from_id); free(to_id);
746           return -1;
747         }
748       send_req_key(from, to);
749     }
750
751   free(from_id); free(to_id);
752 cp
753   return 0;
754 }
755
756 int send_ans_key(conn_list_t *from, conn_list_t *to, char *datakey)
757 {
758 cp
759   return send_request(to->nexthop, "%d %s %s %s", ANS_KEY, from->id, to->id, datakey);
760 }
761
762 int ans_key_h(conn_list_t *cl)
763 {
764   char *from_id, *to_id, *datakey;
765   int keylength;
766   conn_list_t *from, *to;
767 cp
768   if(sscanf(cl->buffer, "%*d %as %as %as", &from_id, &to_id, &datakey) != 3)
769     {
770        syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s)"), cl->id, cl->hostname);
771        return -1;
772     }  
773
774   if(!(from = lookup_id(from_id)))
775     {
776       syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
777       free(from_id); free(to_id); free(datakey);
778       return -1;
779     }
780
781   /* Check if this key request is for us */
782
783   if(!strcmp(id, myself->strcmp))
784     {
785       /* It is for us, convert it to binary and set the key with it. */
786       
787       keylength = strlen(datakey);
788       
789       if((keylength%2) || (keylength <= 0))
790         {
791           syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s) origin %s: invalid key"), cl->id, cl->hostname, from->id);
792           free(from_id); free(to_id); free(datakey);
793           return -1;
794         }
795       keylength /= 2;
796       hex2bin(datakey, datakey, keylength);
797       BF_set_key(cl->datakey, keylength, datakey);
798     }
799   else
800     {
801       if(!(to = lookup_id(to_id)))
802         {
803           syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) destination %s which does not exist in our connection list"), cl->id, cl->hostname, to_id);
804           free(from_id); free(to_id); free(datakey);
805           return -1;
806         }
807       send_ans_key(from, to, datakey);
808     }
809
810   free(from_id); free(to_id); free(datakey);
811 cp
812   return 0;
813 }
814
815 /* Old routines */
816
817 /*
818   Notify all my direct connections of a new host
819   that was added to the vpn, with the exception
820   of the source of the announcement.
821 */
822
823 int notify_others(conn_list_t *new, conn_list_t *source,
824                   int (*function)(conn_list_t*, conn_list_t*))
825 {
826   conn_list_t *p;
827 cp
828   for(p = conn_list; p != NULL; p = p->next)
829     if(p != new && p != source && p->status.meta && p->status.active)
830       function(p, new);
831 cp
832   return 0;
833 }
834
835 /*
836   Notify one connection of everything
837   I have connected
838 */
839
840 int notify_one(conn_list_t *new)
841 {
842   conn_list_t *p;
843 cp
844   for(p = conn_list; p != NULL; p = p->next)
845     if(p != new && p->status.active)
846       send_add_host(new, p);
847 cp
848   return 0;
849 }
850
851 /* "Complete overhaul". */
852
853 int (*request_handlers[])(conn_list_t*) = {
854   id_h, challenge_h, chal_reply_h, ack_h,
855   status_h, error_h, termreq_h,
856   ping_h, pong_h,
857   add_host_h, del_host_h,
858   add_subnet_h, del_subnet_h,
859   key_changed_h, req_key_h, ans_key_h,
860 };
861
862 char (*request_name[]) = {
863   "ID", "CHALLENGE", "CHAL_REPLY", "ACK",
864   "STATUS", "ERROR", "TERMREQ",
865   "PING", "PONG",
866   "ADD_HOST", "DEL_HOST",
867   "ADD_SUBNET", "DEL_SUBNET",
868   "KEY_CHANGED", "REQ_KEY", "ANS_KEY",
869 };