From: Frank Kardel Date: Mon, 22 Aug 2005 16:19:29 +0000 (+0000) Subject: ntpdc_ops.c: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e196efb9d9c94ea0ac72f531aba39b2a499bb5f8;p=thirdparty%2Fntp.git ntpdc_ops.c: cleanup output format add enable/disable output ntp_proto.c: as we are re-binding all interfaces on interface list changes a refresh on transmit is not needed ntp_peer.c: re-bind all interfaces when the interface list changes unbind interface when refclock configuration fails correct setting of a new interface for a peer ntp_io.c: re-bind all interfaces when the interface list changes bk: 4309fb11u2qf8AsDQnSk57JW3Pdzeg --- diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 5aecf35174..d395d57cc8 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -766,6 +766,7 @@ update_interfaces( ) { interface_info_t ifi; + int need_refresh = 0; isc_mem_t *mctx = NULL; isc_interfaceiter_t *iter = NULL; isc_boolean_t scan_ipv4 = ISC_FALSE; @@ -819,7 +820,7 @@ update_interfaces( unsigned int family; interface_t interface; interface_t *iface; - + result = isc_interfaceiter_current(iter, &isc_if); if (result != ISC_R_SUCCESS) @@ -886,6 +887,8 @@ update_interfaces( if (loopback_interface == &interface) loopback_interface = iface; + need_refresh = 1; + ifi.action = IFS_CREATED; ifi.interface = iface; if (receiver && iface) @@ -930,7 +933,7 @@ update_interfaces( peer = ISC_LIST_HEAD(interf->peers); /* - * re-assign all peers interface bindings + * disconnect peer from deleted interface */ while (peer != NULL) { struct peer *npeer = ISC_LIST_NEXT(peer, ilink); @@ -938,12 +941,9 @@ update_interfaces( /* * this one just lost it's interface */ + need_refresh = 1; set_peerdstadr(peer, NULL); - /* - * see whether we can get a new one for him right now - */ - peer_refresh_interface(peer); peer = npeer; } delete_interface(interf); @@ -952,6 +952,12 @@ update_interfaces( interf = next; } } + + /* + * now re-configure as the world has changed + */ + if (need_refresh) + refresh_all_peerinterfaces(); } diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index f369a28b17..5f5ca6544b 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -342,6 +342,8 @@ unpeer( printf("demobilize %u %d %d\n", peer_to_remove->associd, peer_associations, peer_preempt); #endif + set_peerdstadr(peer_to_remove, NULL); + peer_clear(peer_to_remove, "KILL"); hash = NTP_HASH_ADDR(&peer_to_remove->srcadr); peer_hash_count[hash]--; @@ -519,37 +521,32 @@ peer_config( void set_peerdstadr(struct peer *peer, struct interface *interface) { - if (peer->dstadr != NULL) - { - peer->dstadr->peercnt--; - ISC_LIST_UNLINK_TYPE(peer->dstadr->peers, peer, ilink, struct peer); - } - - if (peer->dstadr != interface) - { - peer->dstadr = interface; - /* reset crypto information */ - peer_crypto_clear(peer); - } + if (peer->dstadr != interface) { + if (peer->dstadr != NULL) + { + peer->dstadr->peercnt--; + ISC_LIST_UNLINK_TYPE(peer->dstadr->peers, peer, ilink, struct peer); + } + peer->dstadr = interface; + /* reset crypto information */ + peer_crypto_clear(peer); - if (peer->dstadr != NULL) - { - ISC_LIST_APPEND(peer->dstadr->peers, peer, ilink); - peer->dstadr->peercnt++; - } + if (peer->dstadr != NULL) + { + ISC_LIST_APPEND(peer->dstadr->peers, peer, ilink); + peer->dstadr->peercnt++; + } + } } /* * attempt to re-rebind interface if necessary */ -void +static void peer_refresh_interface(struct peer *peer) { interface_t *niface; - if (peer->dstadr) /* we only work for citizens that got lost */ - return; - niface = select_peerinterface(peer, &peer->srcadr, NULL, peer->cast_flags); #ifdef DEBUG @@ -585,6 +582,7 @@ peer_refresh_interface(struct peer *peer) } } #endif + if (niface != NULL) { set_peerdstadr(peer, niface); } else { @@ -602,6 +600,27 @@ peer_refresh_interface(struct peer *peer) } } +/* + * refresh_all_peerinterfaces - see that all interface bindings are up to date + */ +void +refresh_all_peerinterfaces(void) +{ + struct peer *peer, *next_peer; + int n; + + /* + * this is called when te interfac list has changed + * give all peers a chance to find a better interface + */ + for (n = 0; n < NTP_HASH_SIZE; n++) { + for (peer = peer_hash[n]; peer != 0; peer = next_peer) { + next_peer = peer->next; + peer_refresh_interface(peer); + } + } +} + /* * find an interface suitable for the src address */ @@ -783,6 +802,8 @@ newpeer( /* * Dump it, something screwed up */ + set_peerdstadr(peer, NULL); + peer->next = peer_free; peer_free = peer; peer_free_count++; diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index a9dfe88112..42d46e4d05 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -2267,20 +2267,6 @@ peer_xmit( if (peer->flash & TEST9) return; - /* - * freshen up interfaces if needbe - */ - peer_refresh_interface(peer); - - if (!peer->dstadr) { - /* - * still no luck - keep on waiting - */ - DPRINTF(1, ("peer_xmit: peer %s has no interface - IGNORED\n", stoa(&peer->srcadr))); - - return; /* no use in attempting to send on a peer without an interface */ - } - xpkt.li_vn_mode = PKT_LI_VN_MODE(sys_leap, peer->version, peer->hmode); xpkt.stratum = STRATUM_TO_PKT(sys_stratum); diff --git a/ntpdc/ntpdc_ops.c b/ntpdc/ntpdc_ops.c index 1bc9b8cf7f..98df96ab24 100644 --- a/ntpdc/ntpdc_ops.c +++ b/ntpdc/ntpdc_ops.c @@ -3036,10 +3036,10 @@ again: (u_long)ntohl(ik->errcnt)); } -#define IF_LIST_FMT "%2d %c %48s %c %12.12s %03x %3d %2d %5d %5d %5d %1d %2d\n" -#define IF_LIST_FMT_STR "%2s %c %48s %c %12.12s %3s %3s %2s %5s %5s %5s %1s %2s\n" +#define IF_LIST_FMT "%2d %c %48s %c %c %12.12s %03x %3d %2d %5d %5d %5d %2d %3d\n" +#define IF_LIST_FMT_STR "%2s %c %48s %c %c %12.12s %3s %3s %2s %5s %5s %5s %2s %3s\n" #define IF_LIST_AFMT_STR " %48s %c\n" -#define IF_LIST_LABELS "#", 'A', "Address/Mask/Broadcast", 'T', "IF name", "Flg", "TL", "#M", "recv", "sent", "drop", "S", "PC" +#define IF_LIST_LABELS "#", 'A', "Address/Mask/Broadcast", 'T', 'E', "IF name", "Flg", "TL", "#M", "recv", "sent", "drop", "S", "PC" #define IF_LIST_LINE "==========================================================================================================\n" static void @@ -3081,6 +3081,7 @@ iflist( ntohl(ifs->ifindex), actions[(ifs->action >= 1 && ifs->action < 4) ? ifs->action : 0], stoa((&saddr)), 'A', + ifs->ignore_packets ? 'D' : 'E', ifs->name, ntohl(ifs->flags), ntohl(ifs->last_ttl),