[ntp:bk-ntp-dev-send] BitKeeper diffs

Harlan Stenn stenn at deacon.udel.edu
Fri Jun 15 16:33:59 PDT 2007


#### ChangeSet ####
2007-06-15 07:48:47-04:00, mayer at pogo.udel.edu 
  Remove unused variable

==== ntpd/ntp_io.c ====
2007-06-15 07:48:30-04:00, mayer at pogo.udel.edu +0 -1
  Remove unused variable

--- 1.252/ntpd/ntp_io.c	2007-06-14 23:05:45 -04:00
+++ 1.253/ntpd/ntp_io.c	2007-06-15 07:48:30 -04:00
@@ -3208,7 +3208,6 @@ findlocalinterface(
 	struct sockaddr_storage saddr;
 	GETSOCKNAME_SOCKLEN_TYPE saddrlen = SOCKLEN(addr);
 	struct interface *iface;
-	int on = 1;
 
 	DPRINTF(4, ("Finding interface for addr %s in list of addresses\n",
 		    stoa(addr));)

#### ChangeSet ####
2007-06-14 23:22:06-04:00, mayer at pogo.udel.edu 
  Bug #629 changes to ensure broadcast works including on wildcard addresses

==== ChangeLog ====
2007-06-14 23:21:42-04:00, mayer at pogo.udel.edu +1 -0
  Bug #629 changes to ensure broadcast works including on wildcard addresses

--- 1.69/ChangeLog	2007-06-14 18:41:59 -04:00
+++ 1.70/ChangeLog	2007-06-14 23:21:42 -04:00
@@ -1,3 +1,4 @@
+* [Bug #629] changes to ensure broadcast works including on wildcard addresses
 * [Bug 853] get_node() must return a pointer to maximally-aligned memory.
 * Leap file fixes from Dave Mills.
 * [Bug 858] Recent leapfile changes broke without OPENSSL.

#### ChangeSet ####
2007-06-14 23:06:42-04:00, mayer at pogo.udel.edu 
  Bug #629 changes to ensure broadcast works including on wildcard addresses

==== ntpd/ntp_io.c ====
2007-06-14 23:05:45-04:00, mayer at pogo.udel.edu +22 -17
  Bug #629 changes to ensure broadcast works including on wildcard addresses

--- 1.251/ntpd/ntp_io.c	2007-06-02 18:32:04 -04:00
+++ 1.252/ntpd/ntp_io.c	2007-06-14 23:05:45 -04:00
@@ -265,7 +265,7 @@ static void	delete_interface_from_list	(
 static struct interface *find_addr_in_list	(struct sockaddr_storage *);
 static struct interface *find_flagged_addr_in_list (struct sockaddr_storage *, int);
 static void	create_wildcards	(u_short);
-static isc_boolean_t	address_okay	(struct interface *);
+static isc_boolean_t	address_okay	(isc_interface_t *);
 static void		convert_isc_if		(isc_interface_t *, struct interface *, u_short);
 static struct interface *getinterface	(struct sockaddr_storage *, int);
 static struct interface *findlocalinterface	(struct sockaddr_storage *, int);
@@ -853,7 +853,7 @@ create_wildcards(u_short port) {
 		((struct sockaddr_in*)&interface->bcast)->sin_addr.s_addr = htonl(INADDR_ANY);
 #endif /* MCAST */
 		interface->fd = open_socket(&interface->sin,
-				 interface->flags, 1, interface);
+				 0, 1, interface);
 
 		if (interface->fd != INVALID_SOCKET) {
 			wildipv4 = interface;
@@ -867,6 +867,7 @@ create_wildcards(u_short port) {
 				stoa((&interface->sin)));
 			exit(1);
 		}
+	DPRINT_INTERFACE(2, (interface, "created ", "\n"));
 	}
 
 #ifdef INCLUDE_IPV6_SUPPORT
@@ -890,7 +891,7 @@ create_wildcards(u_short port) {
 		interface->ignore_packets = ISC_TRUE;
 
 		interface->fd = open_socket(&interface->sin,
-				 interface->flags, 1, interface);
+				 0, 1, interface);
 
 		if (interface->fd != INVALID_SOCKET) {
 			wildipv6 = interface;
@@ -903,21 +904,22 @@ create_wildcards(u_short port) {
 				stoa((&interface->sin)));
 			exit(1);
 		}
+	DPRINT_INTERFACE(2, (interface, "created ", "\n"));
 	}
 #endif
 }
 
 
 static isc_boolean_t
-address_okay(struct interface *iface) {
+address_okay(isc_interface_t *isc_if) {
 
 	DPRINTF(4, ("address_okay: listen Virtual: %d, IF name: %s\n", 
-		    listen_to_virtual_ips, iface->name));
+		    listen_to_virtual_ips, isc_if->name));
 
 	/*
 	 * Always allow the loopback
 	 */
-	if((iface->flags & INT_LOOPBACK) != 0) {
+	if((isc_if->flags & INTERFACE_F_LOOPBACK) != 0) {
 		DPRINTF(4, ("address_okay: loopback - OK\n"));
 		return (ISC_TRUE);
 	}
@@ -926,7 +928,7 @@ address_okay(struct interface *iface) {
 	 * Check if the interface is specified
 	 */
 	if (specific_interface != NULL) {
-		if (strcasecmp(iface->name, specific_interface) == 0) {
+		if (strcasecmp(isc_if->name, specific_interface) == 0) {
 			DPRINTF(4, ("address_okay: specific interface name matched - OK\n"));
 			return (ISC_TRUE);
 		} else {
@@ -936,7 +938,7 @@ address_okay(struct interface *iface) {
 	}
 	else {
 		if (listen_to_virtual_ips == 0  && 
-		    (strchr(iface->name, (int)':') != NULL)) {
+		    (strchr(isc_if->name, (int)':') != NULL)) {
 			DPRINTF(4, ("address_okay: virtual ip/alias - FAIL\n"));
 			return (ISC_FALSE);
 		}
@@ -947,8 +949,7 @@ address_okay(struct interface *iface) {
 }
 
 static void
-convert_isc_if(isc_interface_t *isc_if, struct interface *itf, u_short port)
-{
+convert_isc_if(isc_interface_t *isc_if, struct interface *itf, u_short port) {
 	itf->scopeid = 0;
 	itf->family = (short) isc_if->af;
 	strcpy(itf->name, isc_if->name);
@@ -1028,7 +1029,7 @@ refresh_interface(struct interface * int
 	{
 		close_and_delete_fd_from_list(interface->fd);
 		interface->fd = open_socket(&interface->sin,
-					    interface->flags, 0, interface);
+					    0, 0, interface);
 		 /*
 		  * reset TTL indication so TTL is is set again 
 		  * next time around
@@ -1238,7 +1239,7 @@ update_interfaces(
 		 * and potentially causing problems with more than one
 		 * process fiddling with the clock
 		 */
-		if (address_okay(&interface) == ISC_TRUE) {
+		if (address_okay(&isc_if) == ISC_TRUE) {
 			interface.ignore_packets = ISC_FALSE;
 		}
 		else {
@@ -1431,7 +1432,7 @@ create_interface(
 	 * create socket
 	 */
 	interface->fd = open_socket(&interface->sin,
-				 interface->flags, 0, interface);
+				 0, 0, interface);
 
 	if (interface->fd != INVALID_SOCKET)
 		list_if_listening(interface, port);
@@ -1914,13 +1915,14 @@ io_setbclient(void)
 		 */
 		if (interf->bfd == INVALID_SOCKET) {
 			fd = interf->fd;
+			jstatus = socket_broadcast_enable(interf, fd, &interf->sin);
 		}
 		else {
 			fd = interf->bfd;
+			jstatus = ISC_TRUE;
 		}
 
 		/* Enable Broadcast on socket */
-		jstatus = socket_broadcast_enable(interf, fd, &interf->sin);
 		if (jstatus == ISC_TRUE)
 		{
 			nif++;
@@ -2335,6 +2337,8 @@ open_socket(
 				stoa(addr));
 		}
 #endif /* IPTOS_LOWDELAY && IPPROTO_IP && IP_TOS */
+	if ((flags & INT_BROADCAST))
+		socket_broadcast_enable(interf, fd, addr);
 	}
 
 	/*
@@ -2401,7 +2405,7 @@ open_socket(
 					  "bind() fd %d, family %d, port %d, addr %s, in_classd=%d flags=0x%x fails: %m",
 					  fd, addr->ss_family, (int)ntohs(((struct sockaddr_in*)addr)->sin_port),
 					  stoa(addr),
-					  IN_CLASSD(ntohl(((struct sockaddr_in*)addr)->sin_addr.s_addr)), flags);
+					  IN_CLASSD(ntohl(((struct sockaddr_in*)addr)->sin_addr.s_addr)), interf->flags);
 #ifdef INCLUDE_IPV6_SUPPORT
 			else if (addr->ss_family == AF_INET6)
 		                netsyslog(LOG_ERR,
@@ -2413,7 +2417,7 @@ open_socket(
 					  -1
 # endif
 					  , stoa(addr),
-					  IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)addr)->sin6_addr), flags);
+					  IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)addr)->sin6_addr), interf->flags);
 #endif
 		}
 
@@ -2444,7 +2448,7 @@ open_socket(
 		   addr->ss_family,
 		   (int)ntohs(((struct sockaddr_in*)addr)->sin_port),
 		   stoa(addr),
-		    flags));
+		    interf->flags));
 
 	init_nonblocking_io(fd);
 	
@@ -3204,6 +3208,7 @@ findlocalinterface(
 	struct sockaddr_storage saddr;
 	GETSOCKNAME_SOCKLEN_TYPE saddrlen = SOCKLEN(addr);
 	struct interface *iface;
+	int on = 1;
 
 	DPRINTF(4, ("Finding interface for addr %s in list of addresses\n",
 		    stoa(addr));)

==== ports/winnt/ntpd/ntp_iocompletionport.c ====
2007-06-14 23:06:16-04:00, mayer at pogo.udel.edu +12 -3
  Bug #629 changes to ensure broadcast works including on wildcard addresses

--- 1.26/ports/winnt/ntpd/ntp_iocompletionport.c	2007-06-02 18:28:47 -04:00
+++ 1.27/ports/winnt/ntpd/ntp_iocompletionport.c	2007-06-14 23:06:16 -04:00
@@ -511,13 +511,22 @@ OnSocketRecv(DWORD i, IoCompletionInfo *
 		 * we carve out an exception but only if the client has requested
 		 * to receive wildcard sockets
 		 */
+#ifdef DEBUG
+		if(debug > 3 && get_packet_mode(buff) == MODE_BROADCAST)
+			printf("****Accepting Broadcast packet on fd %d from %s\n", buff->fd, stoa(&buff->recv_srcadr));
+#endif
 		ignore_this = inter->ignore_packets;
 		if (ignore_this == ISC_TRUE && inter->family == AF_INET &&
 		    inter->flags == (INT_BROADCAST | INT_WILDCARD) &&
 		    get_packet_mode(buff) == MODE_BROADCAST &&
 		    get_broadcastclient_flag() == ISC_TRUE
-		    )
+		    ) {
 			ignore_this = ISC_FALSE;
+#ifdef DEBUG
+			if (debug > 3)
+  				printf("****Accepting ignored packet on fd %d from %s\n", buff->fd, stoa(&buff->recv_srcadr));
+#endif
+		}
 
 		/*
 		 * If we keep it add some info to the structure
@@ -528,8 +537,8 @@ OnSocketRecv(DWORD i, IoCompletionInfo *
 			buff->receiver = receive; 
 			buff->dstadr = inter;
 #ifdef DEBUG
-			if (debug > 3)
-  				printf("Received %d bytes in buffer %x from %s\n", Bytes, buff, stoa(&buff->recv_srcadr));
+			if (debug > 1)
+  				printf("Received %d bytes of fd %d in buffer %x from %s\n", Bytes, buff->fd, buff, stoa(&buff->recv_srcadr));
 #endif
 			add_full_recv_buffer(buff);
 			/*

#### ChangeSet ####
2007-06-02 18:30:39-04:00, mayer at pogo.udel.edu 
  Bug #629 Allow certain broadcast packets to be received on the wildcard socket

==== include/ntp_io.h ====
2007-06-02 18:28:47-04:00, mayer at pogo.udel.edu +3 -0
  Bug #629 Allow certain broadcast packets to be received on the wildcard socket

--- 1.5/include/ntp_io.h	2001-11-10 02:00:29 -05:00
+++ 1.6/include/ntp_io.h	2007-06-02 18:28:47 -04:00
@@ -30,6 +30,7 @@
 # include "win32_io.h"
 #endif
 
+#include <isc/boolean.h>
 /*
  * Define FNDELAY and FASYNC using O_NONBLOCK and O_ASYNC if we need
  * to (and can).  This is here initially for QNX, but may help for
@@ -46,5 +47,7 @@
 #  define FASYNC O_ASYNC
 # endif
 #endif
+
+isc_boolean_t get_broadcastclient_flag(void); /* Get the status of client broadcast */
 
 #endif

==== include/ntp_request.h ====
2007-06-02 18:28:47-04:00, mayer at pogo.udel.edu +7 -0
  Bug #629 Allow certain broadcast packets to be received on the wildcard socket

--- 1.31/include/ntp_request.h	2007-05-26 11:05:50 -04:00
+++ 1.32/include/ntp_request.h	2007-06-02 18:28:47 -04:00
@@ -6,6 +6,7 @@
 #define _NTP_REQUEST_H
 
 #include "ntp_types.h"
+#include "recvbuff.h"
 
 /*
  * A mode 7 packet is used exchanging data between an NTP server
@@ -923,4 +924,10 @@ struct info_dns_assoc {
 	associd_t associd;	/* association ID */
 	char hostname[NTP_MAXHOSTNAME];	/* hostname */
 };
+
+/*
+ * function declarations
+ */
+int get_packet_mode(struct recvbuf *rbufp); /* Return packet mode */
+
 #endif /* NTP_REQUEST_H */

==== ntpd/ntp_io.c ====
2007-06-02 18:28:46-04:00, mayer at pogo.udel.edu +27 -2
  Bug #629 Allow certain broadcast packets to be received on the wildcard socket

--- 1.249/ntpd/ntp_io.c	2007-05-26 04:09:54 -04:00
+++ 1.249.1.1/ntpd/ntp_io.c	2007-06-02 18:28:46 -04:00
@@ -133,6 +133,7 @@ struct interface *any_interface;	/* defa
 struct interface *any6_interface;	/* default ipv6 interface */
 struct interface *loopback_interface;	/* loopback ipv4 interface */
 
+isc_boolean_t	broadcast_client_enabled = ISC_FALSE;	/* is broadcast client enabled */
 int ninterfaces;			/* Total number of interfaces */
 
 volatile int disable_dynamic_updates;   /* when set to != 0 dynamic updates won't happen */
@@ -758,7 +759,7 @@ add_interface(struct interface *interfac
 }
 
 /*
- * remove interface from known interface list and clean up
+ * remove interface from knoen interface list and clean up
  * associated resources
  */
 static void
@@ -1548,6 +1549,7 @@ socket_broadcast_enable(struct interface
 #endif
 	}
 	iface->flags |= INT_BCASTOPEN;
+	broadcast_client_enabled = ISC_TRUE;
 	return ISC_TRUE;
 #else
 	return ISC_FALSE;
@@ -1575,6 +1577,7 @@ socket_broadcast_disable(struct interfac
 		}
 	}
 	iface->flags &= ~INT_BCASTOPEN;
+	broadcast_client_enabled = ISC_FALSE;
 	return ISC_TRUE;
 #else
 	return ISC_FALSE;
@@ -1582,6 +1585,15 @@ socket_broadcast_disable(struct interfac
 }
 
 #endif /* OPEN_BCAST_SOCKET */
+
+/*
+ * return the broadcast client flag value
+ */
+isc_boolean_t
+get_broadcastclient_flag(void)
+{
+	return (broadcast_client_enabled);
+}
 /*
  * Check to see if the address is a multicast address
  */
@@ -2833,6 +2845,7 @@ read_network_packet(SOCKET fd, struct in
 {
 	GETSOCKNAME_SOCKLEN_TYPE fromlen;
 	int buflen;
+	isc_boolean_t ignore_this;
 	register struct recvbuf *rb;
 #ifdef HAVE_TIMESTAMP
 	struct msghdr msghdr;
@@ -2849,7 +2862,19 @@ read_network_packet(SOCKET fd, struct in
 
 	rb = get_free_recv_buffer();
 
-	if (rb == NULL || itf->ignore_packets == ISC_TRUE)
+	/* For broadcast packet received on the IPv4 wildcard socket
+	 * we carve out an exception but only if the client has requested
+	 * to receive wildcard sockets
+	 */
+	ignore_this = itf->ignore_packets;
+	if (ignore_this == ISC_TRUE && itf->family == AF_INET &&
+	    itf->flags == (INT_BROADCAST | INT_WILDCARD) &&
+	    get_packet_mode(rb) == MODE_BROADCAST &&
+	    get_broadcastclient_flag() == ISC_TRUE
+	    )
+	    ignore_this = ISC_FALSE;
+
+	if (rb == NULL || ignore_this == ISC_TRUE)
 	{
 		char buf[RX_BUFF_SIZE];
 		struct sockaddr_storage from;

==== ntpd/ntp_request.c ====
2007-06-02 18:28:46-04:00, mayer at pogo.udel.edu +9 -0
  Bug #629 Allow certain broadcast packets to be received on the wildcard socket

--- 1.67/ntpd/ntp_request.c	2007-05-26 11:06:08 -04:00
+++ 1.68/ntpd/ntp_request.c	2007-06-02 18:28:46 -04:00
@@ -401,6 +401,15 @@ flush_pkt(void)
 
 
 /*
+ * Given a buffer, return the packet mode
+ */
+int
+get_packet_mode(struct recvbuf *rbufp)
+{
+	struct req_pkt *inpkt = (struct req_pkt *)&rbufp->recv_pkt;
+	return (INFO_MODE(inpkt->rm_vn_mode));
+}
+/*
  * process_private - process private mode (7) packets
  */
 void

==== ports/winnt/ntpd/ntp_iocompletionport.c ====
2007-06-02 18:28:47-04:00, mayer at pogo.udel.edu +20 -2
  Bug #629 Allow certain broadcast packets to be received on the wildcard socket

--- 1.25/ports/winnt/ntpd/ntp_iocompletionport.c	2007-05-27 20:10:47 -04:00
+++ 1.26/ports/winnt/ntpd/ntp_iocompletionport.c	2007-06-02 18:28:47 -04:00
@@ -16,6 +16,8 @@
 #include "ntp_refclock.h"
 #include "ntp_iocompletionport.h"
 #include "transmitbuff.h"
+#include "ntp_request.h"
+#include "ntp_io.h"
 
 /*
  * Request types
@@ -456,8 +458,12 @@ OnSocketRecv(DWORD i, IoCompletionInfo *
 {
 	struct recvbuf *buff = NULL;
 	recvbuf_t *newbuff;
+	isc_boolean_t ignore_this;
+	l_fp arrival_time;
 	struct interface * inter = (struct interface *) i;
 	
+	get_systime(&arrival_time);	
+
 	/*  Convert the overlapped pointer back to a recvbuf pointer.
 	*/
 	
@@ -501,11 +507,23 @@ OnSocketRecv(DWORD i, IoCompletionInfo *
 	}
 	else 
 	{
+		/* For broadcast packet received on the IPv4 wildcard socket
+		 * we carve out an exception but only if the client has requested
+		 * to receive wildcard sockets
+		 */
+		ignore_this = inter->ignore_packets;
+		if (ignore_this == ISC_TRUE && inter->family == AF_INET &&
+		    inter->flags == (INT_BROADCAST | INT_WILDCARD) &&
+		    get_packet_mode(buff) == MODE_BROADCAST &&
+		    get_broadcastclient_flag() == ISC_TRUE
+		    )
+			ignore_this = ISC_FALSE;
+
 		/*
 		 * If we keep it add some info to the structure
 		 */
-		if (Bytes > 0 && inter->ignore_packets == ISC_FALSE) {
-			get_systime(&buff->recv_time);	
+		if (Bytes > 0 && ignore_this == ISC_FALSE) {
+			memcpy(&buff->recv_time, &arrival_time, sizeof(arrival_time));	
 			buff->recv_length = (int) Bytes;
 			buff->receiver = receive; 
 			buff->dstadr = inter;


More information about the bk-ntp-dev-send mailing list