]> git.pld-linux.org Git - packages/ntp.git/blob - ntp-4.2.4p7-bcast.patch
- release 9
[packages/ntp.git] / ntp-4.2.4p7-bcast.patch
1 diff -up ntp-4.2.4p7/ntpd/ntp_io.c.bcast ntp-4.2.4p7/ntpd/ntp_io.c
2 --- ntp-4.2.4p7/ntpd/ntp_io.c.bcast     2009-05-18 16:53:05.000000000 +0200
3 +++ ntp-4.2.4p7/ntpd/ntp_io.c   2009-05-18 16:54:19.000000000 +0200
4 @@ -150,6 +150,8 @@ int ninterfaces;                    /* Total number of in
5  
6  volatile int disable_dynamic_updates;   /* when set to != 0 dynamic updates won't happen */
7  
8 +static int pktinfo_status = 0;         /* is IP_PKTINFO on wildipv4 iface enabled? */
9 +
10  #ifdef REFCLOCK
11  /*
12   * Refclock stuff.     We keep a chain of structures with data concerning
13 @@ -1611,6 +1613,18 @@ set_reuseaddr(int flag) {
14  #endif /* ! SO_EXCLUSIVEADDRUSE */
15  }
16  
17 +static void
18 +set_pktinfo(int flag)
19 +{
20 +       if (wildipv4 == NULL)
21 +               return;
22 +       if (setsockopt(wildipv4->fd, SOL_IP, IP_PKTINFO, &flag, sizeof (flag))) {
23 +               if (debug > 1)
24 +                       printf("setsockopt(IP_PKTINFO) failed: %s\n", strerror(errno));
25 +       } else
26 +               pktinfo_status = flag;
27 +}
28 +
29  /*
30   * This is just a wrapper around an internal function so we can
31   * make other changes as necessary later on
32 @@ -2027,6 +2041,7 @@ io_setbclient(void)
33  #else
34         netsyslog(LOG_ERR, "io_setbclient: Broadcast Client disabled by build");
35  #endif
36 +       set_pktinfo(1);
37  }
38  
39  /*
40 @@ -2049,6 +2064,7 @@ io_unsetbclient(void)
41                     continue;
42                 lstatus = socket_broadcast_disable(interf, &interf->sin);
43         }
44 +       set_pktinfo(0);
45  }
46  
47  /*
48 @@ -2957,7 +2973,8 @@ read_network_packet(SOCKET fd, struct in
49  #ifdef HAVE_TIMESTAMP
50         struct msghdr msghdr;
51         struct iovec iovec;
52 -       char control[TIMESTAMP_CTLMSGBUF_SIZE]; /* pick up control messages */
53 +       char control[sizeof (struct cmsghdr) * 2 + sizeof (struct timeval) +
54 +               sizeof (struct in_pktinfo) + 32];       /* pick up control messages */
55  #endif
56  
57         /*
58 @@ -2969,7 +2986,7 @@ read_network_packet(SOCKET fd, struct in
59  
60         rb = get_free_recv_buffer();
61  
62 -       if (rb == NULL || itf->ignore_packets == ISC_TRUE)
63 +       if (rb == NULL || (itf->ignore_packets == ISC_TRUE && !(pktinfo_status && itf == wildipv4)))
64         {
65                 char buf[RX_BUFF_SIZE];
66                 struct sockaddr_storage from;
67 @@ -3031,6 +3048,34 @@ read_network_packet(SOCKET fd, struct in
68                 return (buflen);
69         }
70  
71 +       if (pktinfo_status && itf->ignore_packets == ISC_TRUE && itf == wildipv4) {
72 +               /* check for broadcast on 255.255.255.255, exception allowed on wildipv4 */
73 +               struct cmsghdr *cmsg;
74 +               struct in_pktinfo *pktinfo = NULL;
75 +
76 +               if ((cmsg = CMSG_FIRSTHDR(&msghdr)))
77 +                       do {
78 +                               if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_PKTINFO)
79 +                                       pktinfo = (struct in_pktinfo *) CMSG_DATA(cmsg);
80 +                       } while ((cmsg = CMSG_NXTHDR(&msghdr, cmsg)));
81 +               if (pktinfo && pktinfo->ipi_addr.s_addr == INADDR_BROADCAST) {
82 +#ifdef DEBUG
83 +                       if (debug > 3) {
84 +                               printf("INADDR_BROADCAST\n");
85 +                       }
86 +#endif
87 +               } else {
88 +#ifdef DEBUG
89 +                       if (debug > 3)
90 +                               printf("%s on (%lu) fd=%d from %s\n", "ignore",
91 +                                               free_recvbuffs(), fd, stoa(&rb->recv_srcadr));
92 +#endif
93 +                       packets_ignored++;
94 +                       freerecvbuf(rb);
95 +                       return (buflen);
96 +               }
97 +       }
98 +
99  #ifdef DEBUG
100         if (debug > 2) {
101                 if(rb->recv_srcadr.ss_family == AF_INET)
102 diff -up ntp-4.2.4p7/ntpd/ntp_peer.c.bcast ntp-4.2.4p7/ntpd/ntp_peer.c
103 --- ntp-4.2.4p7/ntpd/ntp_peer.c.bcast   2008-08-10 13:02:40.000000000 +0200
104 +++ ntp-4.2.4p7/ntpd/ntp_peer.c 2009-05-18 16:53:05.000000000 +0200
105 @@ -709,7 +709,8 @@ select_peerinterface(struct peer *peer, 
106          * as our (network) source address would be undefined and
107          * crypto will not work without knowing the own transmit address
108          */
109 -       if (interface != NULL && interface->flags & INT_WILDCARD)
110 +       if (interface != NULL && interface->flags & INT_WILDCARD &&
111 +                       !(cast_flags & MDF_BCAST))
112  #ifdef SYS_WINNT
113                 if ( !accept_wildcard_if_for_winnt )  
114  #endif
This page took 0.031413 seconds and 3 git commands to generate.