2 * ntp_peer.c - management of data maintained for peer associations
12 #include "ntp_lists.h"
13 #include "ntp_stdlib.h"
14 #include "ntp_control.h"
15 #include <ntp_random.h>
18 * Table of valid association combinations
19 * ---------------------------------------
22 * peer->mode | UNSPEC ACTIVE PASSIVE CLIENT SERVER BCAST
23 * ---------- | ---------------------------------------------
24 * NO_PEER | e 1 0 1 1 1
25 * ACTIVE | e 1 1 0 0 0
26 * PASSIVE | e 1 e 0 0 0
27 * CLIENT | e 0 0 0 1 0
28 * SERVER | e 0 0 0 0 0
30 * BCLIENT | e 0 0 0 e 1
32 * One point to note here: a packet in BCAST mode can potentially match
33 * a peer in CLIENT mode, but we that is a special case and we check for
34 * that early in the decision process. This avoids having to keep track
35 * of what kind of associations are possible etc... We actually
36 * circumvent that problem by requiring that the first b(m)roadcast
37 * received after the change back to BCLIENT mode sets the clock.
39 #define AM_MODES 7 /* number of rows and columns */
40 #define NO_PEER 0 /* action when no peer is found */
42 int AM[AM_MODES][AM_MODES] = {
44 /* peer { UNSPEC, ACTIVE, PASSIVE, CLIENT, SERVER, BCAST } */
46 /*NONE*/{ AM_ERR, AM_NEWPASS, AM_NOMATCH, AM_FXMIT, AM_MANYCAST, AM_NEWBCL},
48 /*A*/ { AM_ERR, AM_PROCPKT, AM_PROCPKT, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH},
50 /*P*/ { AM_ERR, AM_PROCPKT, AM_ERR, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH},
52 /*C*/ { AM_ERR, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH, AM_PROCPKT, AM_NOMATCH},
54 /*S*/ { AM_ERR, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH},
56 /*BCST*/{ AM_ERR, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH},
58 /*BCL*/ { AM_ERR, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH, AM_NOMATCH, AM_PROCPKT},
61 #define MATCH_ASSOC(x, y) AM[(x)][(y)]
64 * These routines manage the allocation of memory to peer structures
65 * and the maintenance of three data structures involving all peers:
67 * - peer_list is a single list with all peers, suitable for scanning
68 * operations over all peers.
69 * - peer_adr_hash is an array of lists indexed by hashed peer address.
70 * - peer_aid_hash is an array of lists indexed by hashed associd.
72 * They also maintain a free list of peer structures, peer_free.
74 * The three main entry points are findpeer(), which looks for matching
75 * peer structures in the peer list, newpeer(), which allocates a new
76 * peer structure and adds it to the list, and unpeer(), which
77 * demobilizes the association and deallocates the structure.
82 struct peer *peer_hash[NTP_HASH_SIZE]; /* peer hash table */
83 int peer_hash_count[NTP_HASH_SIZE]; /* peers in each bucket */
84 struct peer *assoc_hash[NTP_HASH_SIZE]; /* association ID hash table */
85 int assoc_hash_count[NTP_HASH_SIZE];/* peers in each bucket */
86 struct peer *peer_list; /* peer structures list */
87 static struct peer *peer_free; /* peer structures free list */
88 int peer_free_count; /* count of free structures */
91 * Association ID. We initialize this value randomly, then assign a new
92 * value every time an association is mobilized.
94 static associd_t current_association_ID; /* association ID */
95 static associd_t initial_association_ID; /* association ID */
98 * Memory allocation watermarks.
100 #define INIT_PEER_ALLOC 8 /* static preallocation */
101 #define INC_PEER_ALLOC 4 /* add N more when empty */
104 * Miscellaneous statistic counters which may be queried.
106 u_long peer_timereset; /* time stat counters zeroed */
107 u_long findpeer_calls; /* calls to findpeer */
108 u_long assocpeer_calls; /* calls to findpeerbyassoc */
109 u_long peer_allocations; /* allocations from free list */
110 u_long peer_demobilizations; /* structs freed to free list */
111 int total_peer_structs; /* peer structs */
112 int peer_associations; /* mobilized associations */
113 int peer_preempt; /* preemptable associations */
114 static struct peer init_peer_alloc[INIT_PEER_ALLOC]; /* init alloc */
116 static struct peer * findexistingpeer_name(const char *, u_short,
118 static struct peer * findexistingpeer_addr(sockaddr_u *,
121 static void free_peer(struct peer *, int);
122 static void getmorepeermem(void);
123 static int score(struct peer *);
127 * init_peer - initialize peer data structures and counters
129 * N.B. We use the random number routine in here. It had better be
130 * initialized prior to getting here.
138 * Initialize peer free list from static allocation.
140 for (i = COUNTOF(init_peer_alloc) - 1; i >= 0; i--)
141 LINK_SLIST(peer_free, &init_peer_alloc[i], p_link);
142 total_peer_structs = COUNTOF(init_peer_alloc);
143 peer_free_count = COUNTOF(init_peer_alloc);
146 * Initialize our first association ID
149 current_association_ID = ntp_random() & ASSOCID_MAX;
150 while (!current_association_ID);
151 initial_association_ID = current_association_ID;
156 * getmorepeermem - add more peer structures to the free list
164 peers = eallocarray(INC_PEER_ALLOC, sizeof(*peers));
166 for (i = INC_PEER_ALLOC - 1; i >= 0; i--)
167 LINK_SLIST(peer_free, &peers[i], p_link);
169 total_peer_structs += INC_PEER_ALLOC;
170 peer_free_count += INC_PEER_ALLOC;
175 findexistingpeer_name(
176 const char * hostname,
178 struct peer * start_peer,
184 if (NULL == start_peer)
187 p = start_peer->p_link;
188 for (; p != NULL; p = p->p_link)
189 if (p->hostname != NULL
190 && (-1 == mode || p->hmode == mode)
191 && (AF_UNSPEC == hname_fam
192 || AF_UNSPEC == AF(&p->srcadr)
193 || hname_fam == AF(&p->srcadr))
194 && !strcasecmp(p->hostname, hostname))
202 findexistingpeer_addr(
204 struct peer * start_peer,
212 DPRINTF(2, ("findexistingpeer_addr(%s, %s, %d, 0x%x, %p)\n",
215 ? sptoa(&start_peer->srcadr)
217 mode, (u_int)cast_flags, ip_count));
220 * start_peer is included so we can locate instances of the
221 * same peer through different interfaces in the hash table.
222 * Without MDF_BCLNT, a match requires the same mode and remote
223 * address. MDF_BCLNT associations start out as MODE_CLIENT
224 * if broadcastdelay is not specified, and switch to
225 * MODE_BCLIENT after estimating the one-way delay. Duplicate
226 * associations are expanded in definition to match any other
227 * MDF_BCLNT with the same srcadr (remote, unicast address).
229 if (NULL == start_peer)
230 peer = peer_hash[NTP_HASH_ADDR(addr)];
232 peer = start_peer->adr_link;
234 while (peer != NULL) {
235 DPRINTF(3, ("%s %s %d %d 0x%x 0x%x ", sptoa(addr),
236 sptoa(&peer->srcadr), mode, peer->hmode,
237 (u_int)cast_flags, (u_int)peer->cast_flags));
239 if (SOCK_EQ(addr, &peer->srcadr)) {
243 if ((-1 == mode || peer->hmode == mode ||
244 ((MDF_BCLNT & peer->cast_flags) &&
245 (MDF_BCLNT & cast_flags))) &&
246 ADDR_PORT_EQ(addr, &peer->srcadr)) {
247 DPRINTF(3, ("found.\n"));
251 peer = peer->adr_link;
259 * findexistingpeer - search by address and return a pointer to a peer.
264 const char * hostname,
265 struct peer * start_peer,
271 if (hostname != NULL)
272 return findexistingpeer_name(hostname, AF(addr),
275 return findexistingpeer_addr(addr, start_peer, mode,
276 cast_flags, ip_count);
281 * findpeer - find and return a peer match for a received datagram in
282 * the peer_hash table.
284 * [Bug 3072] To faciliate a faster reorganisation after routing changes
285 * the original code re-assigned the peer address to be the destination
286 * of the received packet and initiated another round on a mismatch.
287 * Unfortunately this leaves us wide open for a DoS attack where the
288 * attacker directs a packet with forged destination address to us --
289 * this results in a wrong interface assignment, actually creating a DoS
292 * This condition would persist until the next update of the interface
293 * list, but a continued attack would put us out of business again soon
294 * enough. Authentication alone does not help here, since it does not
295 * protect the UDP layer and leaves us open for a replay attack.
297 * So we do not update the adresses and wait until the next interface
298 * list update does the right thing for us.
302 struct recvbuf *rbufp,
314 srcadr = &rbufp->recv_srcadr;
315 hash = NTP_HASH_ADDR(srcadr);
316 for (p = peer_hash[hash]; p != NULL; p = p->adr_link) {
318 /* [Bug 3072] ensure interface of peer matches */
319 /* [Bug 3356] ... if NOT a broadcast peer! */
320 if (p->hmode != MODE_BCLIENT && p->dstadr != rbufp->dstadr)
323 /* ensure peer source address matches */
324 if ( ! ADDR_PORT_EQ(srcadr, &p->srcadr))
327 /* If the association matching rules determine that this
328 * is not a valid combination, then look for the next
329 * valid peer association.
331 *action = MATCH_ASSOC(p->hmode, pkt_mode);
333 /* A response to our manycastclient solicitation might
334 * be misassociated with an ephemeral peer already spun
335 * for the server. If the packet's org timestamp
336 * doesn't match the peer's, check if it matches the
337 * ACST prototype peer's. If so it is a redundant
338 * solicitation response, return AM_ERR to discard it.
341 if (MODE_SERVER == pkt_mode && AM_PROCPKT == *action) {
342 pkt = &rbufp->recv_pkt;
343 NTOHL_FP(&pkt->org, &pkt_org);
344 if (!L_ISEQU(&p->aorg, &pkt_org) &&
345 findmanycastpeer(rbufp))
349 /* if an error was returned, exit back right here. */
350 if (*action == AM_ERR)
353 /* if a match is found, we stop our search. */
354 if (*action != AM_NOMATCH)
358 /* If no matching association is found... */
360 *action = MATCH_ASSOC(NO_PEER, pkt_mode);
366 * findpeerbyassoc - find and return a peer using his association ID
377 hash = assoc & NTP_HASH_MASK;
378 for (p = assoc_hash[hash]; p != NULL; p = p->aid_link)
379 if (assoc == p->associd)
386 * clear_all - flush all time values for all associations
394 * This routine is called when the clock is stepped, and so all
395 * previously saved time values are untrusted.
397 for (p = peer_list; p != NULL; p = p->p_link)
398 if (!(MDF_TXONLY_MASK & p->cast_flags))
399 peer_clear(p, "STEP");
401 DPRINTF(1, ("clear_all: at %lu\n", current_time));
406 * score_all() - determine if an association can be demobilized
410 struct peer *peer /* peer structure pointer */
418 * This routine finds the minimum score for all preemptible
419 * associations and returns > 0 if the association can be
424 for (speer = peer_list; speer != NULL; speer = speer->p_link)
425 if (speer->flags & FLAG_PREEMPT) {
430 DPRINTF(1, ("score_all: at %lu score %d min %d\n",
431 current_time, tamp, temp));
441 * score() - calculate preemption score
445 struct peer *peer /* peer structure pointer */
451 * This routine calculates the premption score from the peer
452 * error bits and status. Increasing values are more cherished.
455 if (!(peer->flash & TEST10))
456 temp++; /* 1 good synch and stratum */
457 if (!(peer->flash & TEST13))
458 temp++; /* 2 reachable */
459 if (!(peer->flash & TEST12))
460 temp++; /* 3 no loop */
461 if (!(peer->flash & TEST11))
462 temp++; /* 4 good distance */
463 if (peer->status >= CTL_PST_SEL_SELCAND)
464 temp++; /* 5 in the hunt */
465 if (peer->status != CTL_PST_SEL_EXCESS)
466 temp++; /* 6 not spare tire */
467 return (temp); /* selection status */
472 * free_peer - internal routine to free memory referred to by a struct
473 * peer and return it to the peer free list. If unlink is
474 * nonzero, unlink from the various lists.
482 struct peer * unlinked;
486 hash = NTP_HASH_ADDR(&p->srcadr);
487 peer_hash_count[hash]--;
489 UNLINK_SLIST(unlinked, peer_hash[hash], p, adr_link,
491 if (NULL == unlinked) {
492 peer_hash_count[hash]++;
493 msyslog(LOG_ERR, "peer %s not in address table!",
498 * Remove him from the association hash as well.
500 hash = p->associd & NTP_HASH_MASK;
501 assoc_hash_count[hash]--;
503 UNLINK_SLIST(unlinked, assoc_hash[hash], p, aid_link,
505 if (NULL == unlinked) {
506 assoc_hash_count[hash]++;
508 "peer %s not in association ID table!",
512 /* Remove him from the overall list. */
513 UNLINK_SLIST(unlinked, peer_list, p, p_link,
515 if (NULL == unlinked)
516 msyslog(LOG_ERR, "%s not in peer list!",
520 if (p->hostname != NULL)
523 if (p->ident != NULL)
526 if (p->addrs != NULL)
527 free(p->addrs); /* from copy_addrinfo_list() */
529 /* Add his corporeal form to peer free list */
531 LINK_SLIST(peer_free, p, p_link);
537 * unpeer - remove peer structure from hash table and free structure
544 mprintf_event(PEVNT_DEMOBIL, peer, "assoc %u", peer->associd);
545 restrict_source(&peer->srcadr, 1, 0);
546 set_peerdstadr(peer, NULL);
547 peer_demobilizations++;
549 if (FLAG_PREEMPT & peer->flags)
553 * If this peer is actually a clock, shut it down first
555 if (FLAG_REFCLOCK & peer->flags)
556 refclock_unpeer(peer);
559 free_peer(peer, TRUE);
564 * peer_config - configure a new association
569 const char * hostname,
579 const char * ident /* autokey group */
585 * We do a dirty little jig to figure the cast flags. This is
586 * probably not the best place to do this, at least until the
587 * configure code is rebuilt. Note only one flag can be set.
591 if (IS_MCAST(srcadr))
592 cast_flags = MDF_MCAST;
594 cast_flags = MDF_BCAST;
598 if (hostname != NULL && SOCK_UNSPEC(srcadr))
599 cast_flags = MDF_POOL;
600 else if (IS_MCAST(srcadr))
601 cast_flags = MDF_ACAST;
603 cast_flags = MDF_UCAST;
607 cast_flags = MDF_UCAST;
611 * Mobilize the association and initialize its variables. If
612 * emulating ntpdate, force iburst. For pool and manycastclient
613 * strip FLAG_PREEMPT as the prototype associations are not
614 * themselves preemptible, though the resulting associations
617 flags |= FLAG_CONFIG;
619 flags |= FLAG_IBURST;
620 if ((MDF_ACAST | MDF_POOL) & cast_flags)
621 flags &= ~FLAG_PREEMPT;
622 return newpeer(srcadr, hostname, dstadr, ippeerlimit, hmode, version,
623 minpoll, maxpoll, flags, cast_flags, ttl, key, ident);
627 * setup peer dstadr field keeping it in sync with the interface
636 struct peer * unlinked;
638 DEBUG_INSIST(p != NULL);
643 /* check for impossible or identical assignment */
644 if (p->dstadr == dstadr)
648 * Don't accept updates to a separate multicast receive-only
649 * endpt while a BCLNT peer is running its unicast protocol.
651 if (dstadr != NULL && (FLAG_BC_VOL & p->flags) &&
652 (INT_MCASTIF & dstadr->flags) && MODE_CLIENT == p->hmode) {
656 /* unlink from list if we have an address prior to assignment */
657 if (p->dstadr != NULL) {
658 p->dstadr->peercnt--;
659 UNLINK_SLIST(unlinked, p->dstadr->peers, p, ilink,
661 msyslog(LOG_INFO, "%s local addr %s -> %s",
662 stoa(&p->srcadr), latoa(p->dstadr),
668 /* link to list if we have an address after assignment */
669 if (p->dstadr != NULL) {
670 LINK_SLIST(dstadr->peers, p, ilink);
676 * attempt to re-rebind interface if necessary
679 peer_refresh_interface(
686 niface = select_peerinterface(p, &p->srcadr, NULL);
689 "peer_refresh_interface: %s->%s mode %d vers %d poll %d %d flags 0x%x 0x%x ttl %u key %08x: new interface: ",
690 p->dstadr == NULL ? "<null>" :
691 stoa(&p->dstadr->sin), stoa(&p->srcadr), p->hmode,
692 p->version, p->minpoll, p->maxpoll, p->flags, p->cast_flags,
694 if (niface != NULL) {
696 "fd=%d, bfd=%d, name=%.16s, flags=0x%x, ifindex=%u, sin=%s",
697 niface->fd, niface->bfd, niface->name,
698 niface->flags, niface->ifindex,
699 stoa(&niface->sin)));
700 if (niface->flags & INT_BROADCAST)
701 DPRINTF(4, (", bcast=%s",
702 stoa(&niface->bcast)));
703 DPRINTF(4, (", mask=%s\n", stoa(&niface->mask)));
705 DPRINTF(4, ("<NONE>\n"));
709 set_peerdstadr(p, niface);
710 if (p->dstadr != NULL) {
712 * clear crypto if we change the local address
714 if (p->dstadr != piface && !(MDF_ACAST & p->cast_flags)
715 && MODE_BROADCAST != p->pmode)
716 peer_clear(p, "XFAC");
719 * Broadcast needs the socket enabled for broadcast
721 if (MDF_BCAST & p->cast_flags)
722 enable_broadcast(p->dstadr, &p->srcadr);
725 * Multicast needs the socket interface enabled for
728 if (MDF_MCAST & p->cast_flags)
729 enable_multicast_if(p->dstadr, &p->srcadr);
735 * refresh_all_peerinterfaces - see that all interface bindings are up
739 refresh_all_peerinterfaces(void)
744 * this is called when the interface list has changed
745 * give all peers a chance to find a better interface
746 * but only if either they don't have an address already
747 * or if the one they have hasn't worked for a while.
749 for (p = peer_list; p != NULL; p = p->p_link) {
750 if (!(p->dstadr && (p->reach & 0x3))) // Bug 2849 XOR 2043
751 peer_refresh_interface(p);
757 * newpeer - initialize a new peer association
762 const char * hostname,
781 DEBUG_REQUIRE(srcadr);
785 * If Autokey is requested but not configured, complain loudly.
788 if (key > NTP_MAXKEY) {
791 } else if (flags & FLAG_SKEY) {
792 msyslog(LOG_ERR, "Autokey not configured");
799 * For now only pool associations have a hostname.
801 INSIST(NULL == hostname || (MDF_POOL & cast_flags));
804 * First search from the beginning for an association with given
805 * remote address and mode. If an interface is given, search
806 * from there to find the association which matches that
807 * destination. If the given interface is "any", track down the
808 * actual interface, because that's what gets put into the peer
811 if (dstadr != NULL) {
812 peer = findexistingpeer(srcadr, hostname, NULL, hmode,
813 cast_flags, &ip_count);
814 while (peer != NULL) {
815 if ( peer->dstadr == dstadr
816 || ( (MDF_BCLNT & cast_flags)
817 && (MDF_BCLNT & peer->cast_flags)))
820 if (dstadr == ANY_INTERFACE_CHOOSE(srcadr) &&
821 peer->dstadr == findinterface(srcadr))
824 peer = findexistingpeer(srcadr, hostname, peer,
825 hmode, cast_flags, &ip_count);
828 /* no endpt address given */
829 peer = findexistingpeer(srcadr, hostname, NULL, hmode,
830 cast_flags, &ip_count);
834 * If a peer is found, this would be a duplicate and we don't
835 * allow that. This avoids duplicate ephemeral (broadcast/
836 * multicast) and preemptible (manycast and pool) client
840 DPRINTF(2, ("newpeer(%s) found existing association\n",
847 DPRINTF(1, ("newpeer(%s) found no existing and %d other associations\n",
853 /* Check ippeerlimit wrt ip_count */
854 if (ippeerlimit > -1) {
855 if (ip_count + 1 > ippeerlimit) {
856 DPRINTF(2, ("newpeer(%s) denied - ippeerlimit %d\n",
864 DPRINTF(1, ("newpeer(%s) - ippeerlimit %d ignored\n",
872 * Allocate a new peer structure. Some dirt here, since some of
873 * the initialization requires knowlege of our system state.
875 if (peer_free_count == 0)
877 UNLINK_HEAD_SLIST(peer, peer_free, p_link);
878 INSIST(peer != NULL);
881 if (FLAG_PREEMPT & flags)
885 * Assign an association ID and increment the system variable.
887 peer->associd = current_association_ID;
888 if (++current_association_ID == 0)
889 ++current_association_ID;
891 peer->srcadr = *srcadr;
892 if (hostname != NULL)
893 peer->hostname = estrdup(hostname);
895 peer->version = version;
897 peer->cast_flags = cast_flags;
899 select_peerinterface(peer, srcadr, dstadr));
902 * It is an error to set minpoll less than NTP_MINPOLL or to
903 * set maxpoll greater than NTP_MAXPOLL. However, minpoll is
904 * clamped not greater than NTP_MAXPOLL and maxpoll is clamped
905 * not less than NTP_MINPOLL without complaint. Finally,
906 * minpoll is clamped not greater than maxpoll.
909 peer->minpoll = NTP_MINDPOLL;
911 peer->minpoll = min(minpoll, NTP_MAXPOLL);
913 peer->maxpoll = NTP_MAXDPOLL;
915 peer->maxpoll = max(maxpoll, NTP_MINPOLL);
916 if (peer->minpoll > peer->maxpoll)
917 peer->minpoll = peer->maxpoll;
919 if (peer->dstadr != NULL)
920 DPRINTF(3, ("newpeer(%s): using fd %d and our addr %s\n",
921 stoa(srcadr), peer->dstadr->fd,
922 stoa(&peer->dstadr->sin)));
924 DPRINTF(3, ("newpeer(%s): local interface currently not bound\n",
928 * Broadcast needs the socket enabled for broadcast
930 if ((MDF_BCAST & cast_flags) && peer->dstadr != NULL)
931 enable_broadcast(peer->dstadr, srcadr);
934 * Multicast needs the socket interface enabled for multicast
936 if ((MDF_MCAST & cast_flags) && peer->dstadr != NULL)
937 enable_multicast_if(peer->dstadr, srcadr);
940 if (key > NTP_MAXKEY)
941 peer->flags |= FLAG_SKEY;
946 peer->ident = estrdup(ident);
947 peer->precision = sys_precision;
948 peer->hpoll = peer->minpoll;
949 if (cast_flags & MDF_ACAST)
950 peer_clear(peer, "ACST");
951 else if (cast_flags & MDF_POOL)
952 peer_clear(peer, "POOL");
953 else if (cast_flags & MDF_MCAST)
954 peer_clear(peer, "MCST");
955 else if (cast_flags & MDF_BCAST)
956 peer_clear(peer, "BCST");
958 peer_clear(peer, "INIT");
963 * Note time on statistics timers.
965 peer->timereset = current_time;
966 peer->timereachable = current_time;
967 peer->timereceived = current_time;
969 if (ISREFCLOCKADR(&peer->srcadr)) {
972 * We let the reference clock support do clock
973 * dependent initialization. This includes setting
974 * the peer timer, since the clock may have requirements
978 peer->maxpoll = peer->minpoll;
979 if (!refclock_newpeer(peer)) {
981 * Dump it, something screwed up
983 set_peerdstadr(peer, NULL);
988 msyslog(LOG_ERR, "refclock %s isn't supported. ntpd was compiled without refclock support.",
989 stoa(&peer->srcadr));
990 set_peerdstadr(peer, NULL);
993 #endif /* REFCLOCK */
997 * Put the new peer in the hash tables.
999 hash = NTP_HASH_ADDR(&peer->srcadr);
1000 LINK_SLIST(peer_hash[hash], peer, adr_link);
1001 peer_hash_count[hash]++;
1002 hash = peer->associd & NTP_HASH_MASK;
1003 LINK_SLIST(assoc_hash[hash], peer, aid_link);
1004 assoc_hash_count[hash]++;
1005 LINK_SLIST(peer_list, peer, p_link);
1007 restrict_source(&peer->srcadr, 0, 0);
1008 mprintf_event(PEVNT_MOBIL, peer, "assoc %d", peer->associd);
1009 DPRINTF(1, ("newpeer: %s->%s mode %u vers %u poll %u %u flags 0x%x 0x%x ttl %u key %08x\n",
1010 latoa(peer->dstadr), stoa(&peer->srcadr), peer->hmode,
1011 peer->version, peer->minpoll, peer->maxpoll, peer->flags,
1012 peer->cast_flags, peer->ttl, peer->keyid));
1018 * peer_clr_stats - clear peer module statistics counters
1021 peer_clr_stats(void)
1024 assocpeer_calls = 0;
1025 peer_allocations = 0;
1026 peer_demobilizations = 0;
1027 peer_timereset = current_time;
1032 * peer_reset - reset statistics counters
1042 peer->timereset = current_time;
1045 peer->processed = 0;
1049 peer->seldisptoolarge = 0;
1050 peer->selbroken = 0;
1055 * peer_all_reset - reset all peer statistics counters
1058 peer_all_reset(void)
1062 for (peer = peer_list; peer != NULL; peer = peer->p_link)
1068 * findmanycastpeer - find and return a manycastclient or pool
1069 * association matching a received response.
1073 struct recvbuf *rbufp /* receive buffer pointer */
1081 * This routine is called upon arrival of a server-mode response
1082 * to a manycastclient multicast solicitation, or to a pool
1083 * server unicast solicitation. Search the peer list for a
1084 * manycastclient association where the last transmit timestamp
1085 * matches the response packet's originate timestamp. There can
1086 * be multiple manycastclient associations, or multiple pool
1087 * solicitation assocations, so this assumes the transmit
1088 * timestamps are unique for such.
1090 pkt = &rbufp->recv_pkt;
1091 for (peer = peer_list; peer != NULL; peer = peer->p_link)
1092 if (MDF_SOLICIT_MASK & peer->cast_flags) {
1093 NTOHL_FP(&pkt->org, &p_org);
1094 if (L_ISEQU(&p_org, &peer->aorg))
1101 /* peer_cleanup - clean peer list prior to shutdown */
1102 void peer_cleanup(void)
1107 for (assoc = initial_association_ID; assoc != current_association_ID; assoc++) {
1109 peer = findpeerbyassoc(assoc);
1114 peer = findpeerbyassoc(current_association_ID);