From: Frank Kardel Date: Sat, 15 Jul 2006 09:35:45 +0000 (+0000) Subject: ntp_io.c: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4d24dbcc0fe1ed23a4d33db2be355a4b6c29b4a;p=thirdparty%2Fntp.git ntp_io.c: cleanup debug messages add RTM_REDIRECT, RTM_CHANGE as additional interface list scan routing message triggers ntpd.h: select_peerinterface() is comletely private to ntp_peer.c ntp_peer.c: - clear peer crypto when disconnecting from a bound interface - re-arrange initialization for more usable debug output - only bind to non wildcard interfaces even if the OS would offer to send via such an interface bk: 44b8b6f1so90wnn80ANkLw0p4YZ7tA --- diff --git a/include/ntpd.h b/include/ntpd.h index 13a08d2cb0..3c8d442111 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -140,7 +140,6 @@ extern struct peer *findexistingpeer P((struct sockaddr_storage *, struct peer * extern struct peer *findpeer P((struct sockaddr_storage *, struct interface *, int, int *)); extern struct peer *findpeerbyassoc P((u_int)); extern void set_peerdstadr P((struct peer *peer, struct interface *interface)); -extern struct interface *select_peerinterface P((struct peer *, struct sockaddr_storage *, struct interface *, u_char)); extern struct peer *newpeer P((struct sockaddr_storage *, struct interface *, int, int, int, int, u_int, u_char, int, keyid_t)); extern void peer_all_reset P((void)); extern void peer_clr_stats P((void)); diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 17f3607e4d..bdd496eb7c 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -1123,10 +1123,10 @@ update_interfaces( */ init_interface(&interface); - DPRINT_INTERFACE(1, (&interface, "examining", "\n")); - convert_isc_if(&isc_if, &interface, port); + DPRINT_INTERFACE(1, (&interface, "examining ", "\n")); + if (!(interface.flags & INT_UP)) { /* interfaces must be UP to be usable */ DPRINTF(1, ("skipping interface %s (%s) - DOWN\n", interface.name, stoa(&interface.sin))); continue; @@ -3634,6 +3634,12 @@ process_routing_msgs(struct asyncio_reader *reader) #ifdef RTM_DELETE case RTM_DELETE: #endif +#ifdef RTM_REDIRECT + case RTM_REDIRECT: +#endif +#ifdef RTM_CHANGE + case RTM_CHANGE: +#endif #ifdef RTM_LOSING case RTM_LOSING: #endif @@ -3647,7 +3653,7 @@ process_routing_msgs(struct asyncio_reader *reader) * we are keen on new and deleted addresses and if an interface goes up and down or routing changes */ DPRINTF(1, ("routing message op = %d: scheduling interface update\n", rtm->rtm_type)); - timer_interfacetimeout(current_time + 2); + timer_interfacetimeout(current_time); break; default: /* diff --git a/ntpd/ntp_peer.c b/ntpd/ntp_peer.c index 4688d8e0c8..b5015ad6a1 100644 --- a/ntpd/ntp_peer.c +++ b/ntpd/ntp_peer.c @@ -104,6 +104,7 @@ int peer_preempt; /* preemptable associations */ static struct peer init_peer_alloc[INIT_PEER_ALLOC]; /* init alloc */ static void getmorepeermem P((void)); +static struct interface *select_peerinterface P((struct peer *, struct sockaddr_storage *, struct interface *, u_char)); /* * init_peer - initialize peer data structures and counters @@ -529,31 +530,31 @@ void set_peerdstadr(struct peer *peer, struct interface *interface) { if (peer->dstadr != interface) { + struct interface *prev_dstadr = peer->dstadr; + if (peer->dstadr != NULL) { peer->dstadr->peercnt--; ISC_LIST_UNLINK_TYPE(peer->dstadr->peers, peer, ilink, struct peer); } - if (interface == NULL) - { + DPRINTF(1, ("set_peerdstadr(%s): change interface from %s to %s\n", + stoa(&peer->srcadr), + (peer->dstadr != NULL) ? stoa(&peer->dstadr->sin) : "", + (interface != NULL) ? stoa(&interface->sin) : "")); + + peer->dstadr = interface; + + if (prev_dstadr != NULL) { /* - * reset crypto information if we disconnect from - * an interface - other crypto updates are handled - * by the crypto machinery + * reset crypto information if we change from an + * active interface + * all other crypto updates are handled by the crypto + * machinery */ -#ifdef DEBUG - msyslog(LOG_INFO, "set_peerdstadr: disconnecting peer from interface - clearing crypto"); -#endif peer_crypto_clear(peer); } - DPRINTF(1, ("set_peerdstadr: at %ld next %ld assoc ID %d\n", - current_time, peer->nextdate, peer->associd)); - - - peer->dstadr = interface; - if (peer->dstadr != NULL) { ISC_LIST_APPEND(peer->dstadr->peers, peer, ilink); @@ -633,7 +634,7 @@ refresh_all_peerinterfaces(void) int n; /* - * this is called when te interfac list has changed + * this is called when the interface list has changed * give all peers a chance to find a better interface */ for (n = 0; n < NTP_HASH_SIZE; n++) { @@ -648,7 +649,7 @@ refresh_all_peerinterfaces(void) /* * find an interface suitable for the src address */ -struct interface * +static struct interface * select_peerinterface(struct peer *peer, struct sockaddr_storage *srcadr, struct interface *dstadr, u_char cast_flags) { struct interface *interface; @@ -687,6 +688,15 @@ select_peerinterface(struct peer *peer, struct sockaddr_storage *srcadr, struct interface = dstadr; else interface = findinterface(srcadr); + + /* + * we do not bind to the wildcard interfaces for output + * as our (network) source address would be undefined and + * crypto will not work without knowing the own transmit address + */ + if (interface != NULL && interface->flags & INT_WILDCARD) + interface = NULL; + return interface; } @@ -758,7 +768,24 @@ newpeer( return (NULL); } + peer->srcadr = *srcadr; + peer->hmode = (u_char)hmode; + peer->version = (u_char)version; + peer->minpoll = (u_char)max(NTP_MINPOLL, minpoll); + peer->maxpoll = (u_char)min(NTP_MAXPOLL, maxpoll); + peer->flags = flags; + set_peerdstadr(peer, dstadr); + +#ifdef DEBUG + if (debug>2) { + if (peer->dstadr) + printf("newpeer: using fd %d and our addr %s\n", + peer->dstadr->fd, stoa(&peer->dstadr->sin)); + else + printf("newpeer: local interface currently not bound\n"); + } +#endif /* * Broadcast needs the socket enabled for broadcast @@ -772,21 +799,6 @@ newpeer( if (cast_flags & MDF_MCAST && peer->dstadr) { enable_multicast_if(peer->dstadr, srcadr); } -#ifdef DEBUG - if (debug>2) { - if (peer->dstadr) - printf("newpeer: using fd %d and our addr %s\n", - peer->dstadr->fd, stoa(&peer->dstadr->sin)); - else - printf("newpeer: local interface currently not bound\n"); - } -#endif - peer->srcadr = *srcadr; - peer->hmode = (u_char)hmode; - peer->version = (u_char)version; - peer->minpoll = (u_char)max(NTP_MINPOLL, minpoll); - peer->maxpoll = (u_char)min(NTP_MAXPOLL, maxpoll); - peer->flags = flags; if (key != 0) peer->flags |= FLAG_AUTHENABLE; if (key > NTP_MAXKEY)