1 diff -up ntp-4.2.6p3/ntpd/ntp_io.c.bcast ntp-4.2.6p3/ntpd/ntp_io.c
2 --- ntp-4.2.6p3/ntpd/ntp_io.c.bcast 2010-12-25 10:40:36.000000000 +0100
3 +++ ntp-4.2.6p3/ntpd/ntp_io.c 2011-01-05 17:46:13.820049150 +0100
4 @@ -151,6 +151,8 @@ int ninterfaces; /* Total number of in
6 int disable_dynamic_updates; /* scan interfaces once only */
8 +static int pktinfo_status = 0; /* is IP_PKTINFO on wildipv4 iface enabled? */
12 * Refclock stuff. We keep a chain of structures with data concerning
13 @@ -2254,6 +2256,17 @@ set_reuseaddr(
14 #endif /* ! SO_EXCLUSIVEADDRUSE */
18 +set_pktinfo(int flag)
20 + if (wildipv4 == NULL)
22 + if (setsockopt(wildipv4->fd, SOL_IP, IP_PKTINFO, &flag, sizeof (flag))) {
23 + msyslog(LOG_ERR, "set_pktinfo: setsockopt(IP_PKTINFO, %s) failed: %m", flag ? "on" : "off");
25 + pktinfo_status = flag;
29 * This is just a wrapper around an internal function so we can
30 * make other changes as necessary later on
31 @@ -2659,6 +2672,7 @@ io_setbclient(void)
37 DPRINTF(1, ("io_setbclient: Opened broadcast clients\n"));
39 @@ -2685,6 +2699,7 @@ io_unsetbclient(void)
41 socket_broadcast_disable(ep, &ep->sin);
47 @@ -3392,7 +3407,8 @@ read_network_packet(
51 - char control[TIMESTAMP_CTLMSGBUF_SIZE];
52 + char control[sizeof (struct cmsghdr) * 2 + sizeof (struct timeval) +
53 + sizeof (struct in_pktinfo) + 32];
57 @@ -3403,7 +3419,7 @@ read_network_packet(
60 rb = get_free_recv_buffer();
61 - if (NULL == rb || itf->ignore_packets) {
62 + if (NULL == rb || (itf->ignore_packets && !(pktinfo_status && itf == wildipv4))) {
63 char buf[RX_BUFF_SIZE];
66 @@ -3463,6 +3479,27 @@ read_network_packet(
70 + if (pktinfo_status && itf->ignore_packets && itf == wildipv4) {
71 + /* check for broadcast on 255.255.255.255, exception allowed on wildipv4 */
72 + struct cmsghdr *cmsg;
73 + struct in_pktinfo *pktinfo = NULL;
75 + if ((cmsg = CMSG_FIRSTHDR(&msghdr)))
77 + if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_PKTINFO)
78 + pktinfo = (struct in_pktinfo *) CMSG_DATA(cmsg);
79 + } while ((cmsg = CMSG_NXTHDR(&msghdr, cmsg)));
80 + if (pktinfo && pktinfo->ipi_addr.s_addr == INADDR_BROADCAST) {
81 + DPRINTF(4, ("INADDR_BROADCAST\n"));
83 + DPRINTF(4, ("%s on (%lu) fd=%d from %s\n", "ignore",
84 + free_recvbuffs(), fd, stoa(&rb->recv_srcadr)));
91 DPRINTF(3, ("read_network_packet: fd=%d length %d from %s\n",
92 fd, buflen, stoa(&rb->recv_srcadr)));