Lines Matching refs:peer

2  * ntp_peer.c - management of data maintained for peer associations
22 * peer->mode | UNSPEC ACTIVE PASSIVE CLIENT SERVER BCAST
33 * a peer in CLIENT mode, but we that is a special case and we check for
40 #define NO_PEER 0 /* action when no peer is found */
44 /* peer { UNSPEC, ACTIVE, PASSIVE, CLIENT, SERVER, BCAST } */
64 * These routines manage the allocation of memory to peer structures
69 * - peer_adr_hash is an array of lists indexed by hashed peer address.
72 * They also maintain a free list of peer structures, peer_free.
75 * peer structures in the peer list, newpeer(), which allocates a new
76 * peer structure and adds it to the list, and unpeer(), which
82 struct peer *peer_hash[NTP_HASH_SIZE]; /* peer hash table */
84 struct peer *assoc_hash[NTP_HASH_SIZE]; /* association ID hash table */
86 struct peer *peer_list; /* peer structures list */
87 static struct peer *peer_free; /* peer structures free list */
111 int total_peer_structs; /* peer structs */
114 static struct peer init_peer_alloc[INIT_PEER_ALLOC]; /* init alloc */
116 static struct peer * findexistingpeer_name(const char *, u_short,
117 struct peer *, int);
118 static struct peer * findexistingpeer_addr(sockaddr_u *,
119 struct peer *, int,
121 static void free_peer(struct peer *, int);
123 static int score(struct peer *);
127 * init_peer - initialize peer data structures and counters
138 * Initialize peer free list from static allocation.
156 * getmorepeermem - add more peer structures to the free list
162 struct peer *peers;
174 static struct peer *
178 struct peer * start_peer,
182 struct peer *p;
201 struct peer *
204 struct peer * start_peer,
210 struct peer *peer;
221 * same peer through different interfaces in the hash table.
230 peer = peer_hash[NTP_HASH_ADDR(addr)];
232 peer = start_peer->adr_link;
234 while (peer != NULL) {
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) &&
246 ADDR_PORT_EQ(addr, &peer->srcadr)) {
251 peer = peer->adr_link;
254 return peer;
259 * findexistingpeer - search by address and return a pointer to a peer.
261 struct peer *
265 struct peer * start_peer,
281 * findpeer - find and return a peer match for a received datagram in
285 * the original code re-assigned the peer address to be the destination
300 struct peer *
307 struct peer * p;
318 /* [Bug 3072] ensure interface of peer matches */
319 /* [Bug 3356] ... if NOT a broadcast peer! */
323 /* ensure peer source address matches */
329 * valid peer association.
334 * be misassociated with an ephemeral peer already spun
336 * doesn't match the peer's, check if it matches the
337 * ACST prototype peer's. If so it is a redundant
366 * findpeerbyassoc - find and return a peer using his association ID
368 struct peer *
373 struct peer *p;
391 struct peer *p;
410 struct peer *peer /* peer structure pointer */
413 struct peer *speer;
422 tamp = score(peer);
445 struct peer *peer /* peer structure pointer */
451 * This routine calculates the premption score from the peer
455 if (!(peer->flash & TEST10))
457 if (!(peer->flash & TEST13))
459 if (!(peer->flash & TEST12))
461 if (!(peer->flash & TEST11))
463 if (peer->status >= CTL_PST_SEL_SELCAND)
465 if (peer->status != CTL_PST_SEL_EXCESS)
473 * peer and return it to the peer free list. If unlink is
478 struct peer * p,
482 struct peer * unlinked;
490 struct peer);
493 msyslog(LOG_ERR, "peer %s not in address table!",
504 struct peer);
508 "peer %s not in association ID table!",
514 struct peer);
516 msyslog(LOG_ERR, "%s not in peer list!",
529 /* Add his corporeal form to peer free list */
537 * unpeer - remove peer structure from hash table and free structure
541 struct peer *peer
544 mprintf_event(PEVNT_DEMOBIL, peer, "assoc %u", peer->associd);
545 restrict_source(&peer->srcadr, 1, 0);
546 set_peerdstadr(peer, NULL);
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);
566 struct peer *
627 * setup peer dstadr field keeping it in sync with the interface
632 struct peer * p,
636 struct peer * unlinked;
649 * endpt while a BCLNT peer is running its unicast protocol.
660 struct peer);
680 struct peer *p
741 struct peer *p;
757 * newpeer - initialize a new peer association
759 struct peer *
776 struct peer * peer;
808 * actual interface, because that's what gets put into the peer
812 peer = findexistingpeer(srcadr, hostname, NULL, hmode,
814 while (peer != NULL) {
815 if ( peer->dstadr == dstadr
817 && (MDF_BCLNT & peer->cast_flags)))
821 peer->dstadr == findinterface(srcadr))
824 peer = findexistingpeer(srcadr, hostname, peer,
829 peer = findexistingpeer(srcadr, hostname, NULL, hmode,
834 * If a peer is found, this would be a duplicate and we don't
839 if (peer != NULL) {
874 * Allocate a new peer structure. Some dirt here, since some of
879 UNLINK_HEAD_SLIST(peer, peer_free, p_link);
880 INSIST(peer != NULL);
889 peer->associd = current_association_ID;
893 peer->srcadr = *srcadr;
895 peer->hostname = estrdup(hostname);
896 peer->hmode = hmode;
897 peer->version = version;
898 peer->flags = flags;
899 peer->cast_flags = cast_flags;
900 set_peerdstadr(peer,
901 select_peerinterface(peer, srcadr, dstadr));
911 peer->minpoll = NTP_MINDPOLL;
913 peer->minpoll = min(minpoll, NTP_MAXPOLL);
915 peer->maxpoll = NTP_MAXDPOLL;
917 peer->maxpoll = max(maxpoll, NTP_MINPOLL);
918 if (peer->minpoll > peer->maxpoll)
919 peer->minpoll = peer->maxpoll;
921 if (peer->dstadr != NULL)
923 stoa(srcadr), peer->dstadr->fd,
924 stoa(&peer->dstadr->sin)));
932 if ((MDF_BCAST & cast_flags) && peer->dstadr != NULL)
933 enable_broadcast(peer->dstadr, srcadr);
938 if ((MDF_MCAST & cast_flags) && peer->dstadr != NULL)
939 enable_multicast_if(peer->dstadr, srcadr);
943 peer->flags |= FLAG_SKEY;
945 peer->ttl = ttl;
946 peer->keyid = key;
948 peer->ident = estrdup(ident);
949 peer->precision = sys_precision;
950 peer->hpoll = peer->minpoll;
952 peer_clear(peer, "ACST");
954 peer_clear(peer, "POOL");
956 peer_clear(peer, "MCST");
958 peer_clear(peer, "BCST");
960 peer_clear(peer, "INIT");
967 peer->timereset = current_time;
968 peer->timereachable = current_time;
969 peer->timereceived = current_time;
971 if (ISREFCLOCKADR(&peer->srcadr)) {
976 * the peer timer, since the clock may have requirements
980 peer->maxpoll = peer->minpoll;
981 if (!refclock_newpeer(peer)) {
985 set_peerdstadr(peer, NULL);
986 free_peer(peer, 0);
991 stoa(&peer->srcadr));
992 set_peerdstadr(peer, NULL);
993 free_peer(peer, 0);
999 * Put the new peer in the hash tables.
1001 hash = NTP_HASH_ADDR(&peer->srcadr);
1002 LINK_SLIST(peer_hash[hash], peer, adr_link);
1004 hash = peer->associd & NTP_HASH_MASK;
1005 LINK_SLIST(assoc_hash[hash], peer, aid_link);
1007 LINK_SLIST(peer_list, peer, p_link);
1009 restrict_source(&peer->srcadr, 0, 0);
1010 mprintf_event(PEVNT_MOBIL, peer, "assoc %d", peer->associd);
1012 latoa(peer->dstadr), stoa(&peer->srcadr), peer->hmode,
1013 peer->version, peer->minpoll, peer->maxpoll, peer->flags,
1014 peer->cast_flags, peer->ttl, peer->keyid));
1015 return peer;
1020 * peer_clr_stats - clear peer module statistics counters
1038 struct peer *peer
1041 if (peer == NULL)
1044 peer->timereset = current_time;
1045 peer->sent = 0;
1046 peer->received = 0;
1047 peer->processed = 0;
1048 peer->badauth = 0;
1049 peer->bogusorg = 0;
1050 peer->oldpkt = 0;
1051 peer->seldisptoolarge = 0;
1052 peer->selbroken = 0;
1057 * peer_all_reset - reset all peer statistics counters
1062 struct peer *peer;
1064 for (peer = peer_list; peer != NULL; peer = peer->p_link)
1065 peer_reset(peer);
1073 struct peer *
1078 struct peer *peer;
1085 * server unicast solicitation. Search the peer list for a
1093 for (peer = peer_list; peer != NULL; peer = peer->p_link)
1094 if (MDF_SOLICIT_MASK & peer->cast_flags) {
1096 if (L_ISEQU(&p_org, &peer->aorg))
1100 return peer;
1103 /* peer_cleanup - clean peer list prior to shutdown */
1106 struct peer *peer;
1111 peer = findpeerbyassoc(assoc);
1112 if (peer != NULL)
1113 unpeer(peer);
1116 peer = findpeerbyassoc(current_association_ID);
1117 if (peer != NULL)
1118 unpeer(peer);