From 49b7d963372f963c2eab9435fa69aa1f61326111 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Mon, 26 Oct 2015 15:40:47 +0000 Subject: [PATCH 01/68] Remove svn:keywords from contributed files. From 2332dd949202c2e8f97a20f870bc7d177f6e1302 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 6 Jan 2016 21:47:49 +0000 Subject: [PATCH 02/68] Use standard name for ASCII LF and FF control codes PR: 205778 MFC after: 2 weeks --- share/man/man7/ascii.7 | 8 ++++---- share/misc/ascii | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/share/man/man7/ascii.7 b/share/man/man7/ascii.7 index a9c75ad9031b..aa02af9a2832 100644 --- a/share/man/man7/ascii.7 +++ b/share/man/man7/ascii.7 @@ -28,7 +28,7 @@ .\" @(#)ascii.7 8.1 (Berkeley) 6/5/93 .\" $FreeBSD$ .\" -.Dd June 5, 1993 +.Dd January 6, 2016 .Dt ASCII 7 .Os .Sh NAME @@ -42,7 +42,7 @@ The set: .Bd -literal -offset left 000 NUL 001 SOH 002 STX 003 ETX 004 EOT 005 ENQ 006 ACK 007 BEL -010 BS 011 HT 012 NL 013 VT 014 NP 015 CR 016 SO 017 SI +010 BS 011 HT 012 LF 013 VT 014 FF 015 CR 016 SO 017 SI 020 DLE 021 DC1 022 DC2 023 DC3 024 DC4 025 NAK 026 SYN 027 ETB 030 CAN 031 EM 032 SUB 033 ESC 034 FS 035 GS 036 RS 037 US 040 SP 041 ! 042 " 043 # 044 $ 045 % 046 & 047 ' @@ -64,7 +64,7 @@ The set: .Bd -literal -offset left 00 NUL 01 SOH 02 STX 03 ETX 04 EOT 05 ENQ 06 ACK 07 BEL -08 BS 09 HT 0A NL 0B VT 0C NP 0D CR 0E SO 0F SI +08 BS 09 HT 0A LF 0B VT 0C FF 0D CR 0E SO 0F SI 10 DLE 11 DC1 12 DC2 13 DC3 14 DC4 15 NAK 16 SYN 17 ETB 18 CAN 19 EM 1A SUB 1B ESC 1C FS 1D GS 1E RS 1F US 20 SP 21 ! 22 " 23 # 24 $ 25 % 26 & 27 ' @@ -86,7 +86,7 @@ The set: .Bd -literal -offset left 0 NUL 1 SOH 2 STX 3 ETX 4 EOT 5 ENQ 6 ACK 7 BEL - 8 BS 9 HT 10 NL 11 VT 12 NP 13 CR 14 SO 15 SI + 8 BS 9 HT 10 LF 11 VT 12 FF 13 CR 14 SO 15 SI 16 DLE 17 DC1 18 DC2 19 DC3 20 DC4 21 NAK 22 SYN 23 ETB 24 CAN 25 EM 26 SUB 27 ESC 28 FS 29 GS 30 RS 31 US 32 SP 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' diff --git a/share/misc/ascii b/share/misc/ascii index b7bcef5c467a..2a71a4305dd8 100644 --- a/share/misc/ascii +++ b/share/misc/ascii @@ -1,5 +1,5 @@ |000 nul|001 soh|002 stx|003 etx|004 eot|005 enq|006 ack|007 bel| -|010 bs |011 ht |012 nl |013 vt |014 np |015 cr |016 so |017 si | +|010 bs |011 ht |012 lf |013 vt |014 ff |015 cr |016 so |017 si | |020 dle|021 dc1|022 dc2|023 dc3|024 dc4|025 nak|026 syn|027 etb| |030 can|031 em |032 sub|033 esc|034 fs |035 gs |036 rs |037 us | |040 sp |041 ! |042 " |043 # |044 $ |045 % |046 & |047 ' | @@ -16,7 +16,7 @@ |170 x |171 y |172 z |173 { |174 | |175 } |176 ~ |177 del| | 00 nul| 01 soh| 02 stx| 03 etx| 04 eot| 05 enq| 06 ack| 07 bel| -| 08 bs | 09 ht | 0a nl | 0b vt | 0c np | 0d cr | 0e so | 0f si | +| 08 bs | 09 ht | 0a lf | 0b vt | 0c ff | 0d cr | 0e so | 0f si | | 10 dle| 11 dc1| 12 dc2| 13 dc3| 14 dc4| 15 nak| 16 syn| 17 etb| | 18 can| 19 em | 1a sub| 1b esc| 1c fs | 1d gs | 1e rs | 1f us | | 20 sp | 21 ! | 22 " | 23 # | 24 $ | 25 % | 26 & | 27 ' | @@ -33,7 +33,7 @@ | 78 x | 79 y | 7a z | 7b { | 7c | | 7d } | 7e ~ | 7f del| | 0 nul| 1 soh| 2 stx| 3 etx| 4 eot| 5 enq| 6 ack| 7 bel| -| 8 bs | 9 ht | 10 nl | 11 vt | 12 np | 13 cr | 14 so | 15 si | +| 8 bs | 9 ht | 10 lf | 11 vt | 12 ff | 13 cr | 14 so | 15 si | | 16 dle| 17 dc1| 18 dc2| 19 dc3| 20 dc4| 21 nak| 22 syn| 23 etb| | 24 can| 25 em | 26 sub| 27 esc| 28 fs | 29 gs | 30 rs | 31 us | | 32 sp | 33 ! | 34 " | 35 # | 36 $ | 37 % | 38 & | 39 ' | From b46e917554ee224fb1035c66bf4f7bbfccb3a922 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Wed, 6 Jan 2016 21:58:45 +0000 Subject: [PATCH 03/68] Provide knob NO_INSTALLEXTRAKERNELS. If defined, extra kernels in KERNCONF won't be installed, only the first one would. --- Makefile.inc1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 5102f9d0ec3f..f56fc71ddcf5 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -1230,7 +1230,7 @@ reinstallkernel reinstallkernel.debug: _installcheck_kernel ${CROSSENV} PATH=${TMPPATH} \ ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//} .endif -.if ${BUILDKERNELS:[#]} > 1 +.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS) .for _kernel in ${BUILDKERNELS:[2..-1]} @echo "--------------------------------------------------------------" @echo ">>> Installing kernel ${_kernel}" @@ -1261,7 +1261,7 @@ distributekernel distributekernel.debug: ${DESTDIR}/${DISTDIR}/kernel.meta .endif .endif -.if ${BUILDKERNELS:[#]} > 1 +.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS) .for _kernel in ${BUILDKERNELS:[2..-1]} .if defined(NO_ROOT) echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta @@ -1292,7 +1292,7 @@ packagekernel: tar cvf - --include '*/*/*.debug' \ @${DESTDIR}/${DISTDIR}/kernel.meta | \ ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz -.if ${BUILDKERNELS:[#]} > 1 +.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS) .for _kernel in ${BUILDKERNELS:[2..-1]} cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \ tar cvf - --exclude '*.debug' \ @@ -1313,7 +1313,7 @@ packagekernel: cd ${DESTDIR}/${DISTDIR}/kernel; \ tar cvf - --include '*/*/*.debug' $$(eval find .) | \ ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz -.if ${BUILDKERNELS:[#]} > 1 +.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS) .for _kernel in ${BUILDKERNELS:[2..-1]} cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \ tar cvf - --exclude '*.debug' . | \ From 0c39d38d215df8423974f87134838fafc0170552 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Thu, 7 Jan 2016 00:14:42 +0000 Subject: [PATCH 04/68] Historically we have two fields in tcpcb to describe sender MSS: t_maxopd, and t_maxseg. This dualism emerged with T/TCP, but was not properly cleaned up after T/TCP removal. After all permutations over the years the result is that t_maxopd stores a minimum of peer offered MSS and MTU reduced by minimum protocol header. And t_maxseg stores (t_maxopd - TCPOLEN_TSTAMP_APPA) if timestamps are in action, or is equal to t_maxopd otherwise. That's a very rough estimate of MSS reduced by options length. Throughout the code it was used in places, where preciseness was not important, like cwnd or ssthresh calculations. With this change: - t_maxopd goes away. - t_maxseg now stores MSS not adjusted by options. - new function tcp_maxseg() is provided, that calculates MSS reduced by options length. The functions gives a better estimate, since it takes into account SACK state as well. Reviewed by: jtl Differential Revision: https://reviews.freebsd.org/D3593 --- sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c | 3 +- sys/dev/cxgbe/tom/t4_cpl_io.c | 3 +- sys/netinet/tcp_input.c | 102 +++++++++++++---------------- sys/netinet/tcp_output.c | 16 ++--- sys/netinet/tcp_subr.c | 57 +++++++++++++++- sys/netinet/tcp_timer.c | 21 +++--- sys/netinet/tcp_usrreq.c | 10 ++- sys/netinet/tcp_var.h | 5 +- 8 files changed, 123 insertions(+), 94 deletions(-) diff --git a/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c b/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c index 985306c3c6e8..d896020abf39 100644 --- a/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c +++ b/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c @@ -1536,14 +1536,13 @@ assign_rxopt(struct tcpcb *tp, uint16_t tcpopt) struct toepcb *toep = tp->t_toe; struct adapter *sc = toep->tp_tod->tod_softc; - tp->t_maxseg = tp->t_maxopd = sc->params.mtus[G_TCPOPT_MSS(tcpopt)] - 40; + tp->t_maxseg = sc->params.mtus[G_TCPOPT_MSS(tcpopt)] - 40; if (G_TCPOPT_TSTAMP(tcpopt)) { tp->t_flags |= TF_RCVD_TSTMP; tp->t_flags |= TF_REQ_TSTMP; /* forcibly set */ tp->ts_recent = 0; /* XXX */ tp->ts_recent_age = tcp_ts_getticks(); - tp->t_maxseg -= TCPOLEN_TSTAMP_APPA; } if (G_TCPOPT_SACK(tcpopt)) diff --git a/sys/dev/cxgbe/tom/t4_cpl_io.c b/sys/dev/cxgbe/tom/t4_cpl_io.c index d58592e85b49..f18f115c3202 100644 --- a/sys/dev/cxgbe/tom/t4_cpl_io.c +++ b/sys/dev/cxgbe/tom/t4_cpl_io.c @@ -221,7 +221,7 @@ assign_rxopt(struct tcpcb *tp, unsigned int opt) n = sizeof(struct ip6_hdr) + sizeof(struct tcphdr); else n = sizeof(struct ip) + sizeof(struct tcphdr); - tp->t_maxseg = tp->t_maxopd = sc->params.mtus[G_TCPOPT_MSS(opt)] - n; + tp->t_maxseg = sc->params.mtus[G_TCPOPT_MSS(opt)] - n; CTR4(KTR_CXGBE, "%s: tid %d, mtu_idx %u (%u)", __func__, toep->tid, G_TCPOPT_MSS(opt), sc->params.mtus[G_TCPOPT_MSS(opt)]); @@ -230,7 +230,6 @@ assign_rxopt(struct tcpcb *tp, unsigned int opt) tp->t_flags |= TF_RCVD_TSTMP; /* timestamps ok */ tp->ts_recent = 0; /* hmmm */ tp->ts_recent_age = tcp_ts_getticks(); - tp->t_maxseg -= TCPOLEN_TSTAMP_APPA; } if (G_TCPOPT_SACK(opt)) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index a763e464ba48..3a979a0c42d7 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -290,7 +290,7 @@ cc_ack_received(struct tcpcb *tp, struct tcphdr *th, uint16_t type) if (type == CC_ACK) { if (tp->snd_cwnd > tp->snd_ssthresh) { tp->t_bytes_acked += min(tp->ccv->bytes_this_ack, - V_tcp_abc_l_var * tp->t_maxseg); + V_tcp_abc_l_var * tcp_maxseg(tp)); if (tp->t_bytes_acked >= tp->snd_cwnd) { tp->t_bytes_acked -= tp->snd_cwnd; tp->ccv->flags |= CCF_ABC_SENTAWND; @@ -313,11 +313,13 @@ cc_conn_init(struct tcpcb *tp) { struct hc_metrics_lite metrics; struct inpcb *inp = tp->t_inpcb; + u_int maxseg; int rtt; INP_WLOCK_ASSERT(tp->t_inpcb); tcp_hc_get(&inp->inp_inc, &metrics); + maxseg = tcp_maxseg(tp); if (tp->t_srtt == 0 && (rtt = metrics.rmx_rtt)) { tp->t_srtt = rtt; @@ -342,7 +344,7 @@ cc_conn_init(struct tcpcb *tp) * the slow start threshhold, but set the * threshold to no less than 2*mss. */ - tp->snd_ssthresh = max(2 * tp->t_maxseg, metrics.rmx_ssthresh); + tp->snd_ssthresh = max(2 * maxseg, metrics.rmx_ssthresh); TCPSTAT_INC(tcps_usedssthresh); } @@ -359,21 +361,20 @@ cc_conn_init(struct tcpcb *tp) * requiring us to be cautious. */ if (tp->snd_cwnd == 1) - tp->snd_cwnd = tp->t_maxseg; /* SYN(-ACK) lost */ + tp->snd_cwnd = maxseg; /* SYN(-ACK) lost */ else if (V_tcp_initcwnd_segments) - tp->snd_cwnd = min(V_tcp_initcwnd_segments * tp->t_maxseg, - max(2 * tp->t_maxseg, V_tcp_initcwnd_segments * 1460)); + tp->snd_cwnd = min(V_tcp_initcwnd_segments * maxseg, + max(2 * maxseg, V_tcp_initcwnd_segments * 1460)); else if (V_tcp_do_rfc3390) - tp->snd_cwnd = min(4 * tp->t_maxseg, - max(2 * tp->t_maxseg, 4380)); + tp->snd_cwnd = min(4 * maxseg, max(2 * maxseg, 4380)); else { /* Per RFC5681 Section 3.1 */ - if (tp->t_maxseg > 2190) - tp->snd_cwnd = 2 * tp->t_maxseg; - else if (tp->t_maxseg > 1095) - tp->snd_cwnd = 3 * tp->t_maxseg; + if (maxseg > 2190) + tp->snd_cwnd = 2 * maxseg; + else if (maxseg > 1095) + tp->snd_cwnd = 3 * maxseg; else - tp->snd_cwnd = 4 * tp->t_maxseg; + tp->snd_cwnd = 4 * maxseg; } if (CC_ALGO(tp)->conn_init != NULL) @@ -383,6 +384,8 @@ cc_conn_init(struct tcpcb *tp) void inline cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type) { + u_int maxseg; + INP_WLOCK_ASSERT(tp->t_inpcb); switch(type) { @@ -402,12 +405,13 @@ cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type) } break; case CC_RTO: + maxseg = tcp_maxseg(tp); tp->t_dupacks = 0; tp->t_bytes_acked = 0; EXIT_RECOVERY(tp->t_flags); tp->snd_ssthresh = max(2, min(tp->snd_wnd, tp->snd_cwnd) / 2 / - tp->t_maxseg) * tp->t_maxseg; - tp->snd_cwnd = tp->t_maxseg; + maxseg) * maxseg; + tp->snd_cwnd = maxseg; break; case CC_RTO_ERR: TCPSTAT_INC(tcps_sndrexmitbad); @@ -469,13 +473,11 @@ tcp_signature_verify_input(struct mbuf *m, int off0, int tlen, int optlen, * the ack that opens up a 0-sized window. * - LRO wasn't used for this segment. We make sure by checking that the * segment size is not larger than the MSS. - * - Delayed acks are enabled or this is a half-synchronized T/TCP - * connection. */ #define DELAY_ACK(tp, tlen) \ ((!tcp_timer_active(tp, TT_DELACK) && \ (tp->t_flags & TF_RXWIN0SENT) == 0) && \ - (tlen <= tp->t_maxopd) && \ + (tlen <= tp->t_maxseg) && \ (V_tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN))) static void inline @@ -2481,6 +2483,9 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, hhook_run_tcp_est_in(tp, th, &to); if (SEQ_LEQ(th->th_ack, tp->snd_una)) { + u_int maxseg; + + maxseg = tcp_maxseg(tp); if (tlen == 0 && (tiwin == tp->snd_wnd || (tp->t_flags & TF_SACK_PERMIT))) { @@ -2560,12 +2565,12 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, tp->sackhint.sack_bytes_rexmit; if (awnd < tp->snd_ssthresh) { - tp->snd_cwnd += tp->t_maxseg; + tp->snd_cwnd += maxseg; if (tp->snd_cwnd > tp->snd_ssthresh) tp->snd_cwnd = tp->snd_ssthresh; } } else - tp->snd_cwnd += tp->t_maxseg; + tp->snd_cwnd += maxseg; (void) tp->t_fb->tfb_tcp_output(tp); goto drop; } else if (tp->t_dupacks == tcprexmtthresh) { @@ -2599,18 +2604,18 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, TCPSTAT_INC( tcps_sack_recovery_episode); tp->sack_newdata = tp->snd_nxt; - tp->snd_cwnd = tp->t_maxseg; + tp->snd_cwnd = maxseg; (void) tp->t_fb->tfb_tcp_output(tp); goto drop; } tp->snd_nxt = th->th_ack; - tp->snd_cwnd = tp->t_maxseg; + tp->snd_cwnd = maxseg; (void) tp->t_fb->tfb_tcp_output(tp); KASSERT(tp->snd_limited <= 2, ("%s: tp->snd_limited too big", __func__)); tp->snd_cwnd = tp->snd_ssthresh + - tp->t_maxseg * + maxseg * (tp->t_dupacks - tp->snd_limited); if (SEQ_GT(onxt, tp->snd_nxt)) tp->snd_nxt = onxt; @@ -2641,7 +2646,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, tp->snd_cwnd = (tp->snd_nxt - tp->snd_una) + (tp->t_dupacks - tp->snd_limited) * - tp->t_maxseg; + maxseg; /* * Only call tcp_output when there * is new data available to be sent. @@ -2654,10 +2659,10 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, if (avail > 0) (void) tp->t_fb->tfb_tcp_output(tp); sent = tp->snd_max - oldsndmax; - if (sent > tp->t_maxseg) { + if (sent > maxseg) { KASSERT((tp->t_dupacks == 2 && tp->snd_limited == 0) || - (sent == tp->t_maxseg + 1 && + (sent == maxseg + 1 && tp->t_flags & TF_SENTFIN), ("%s: sent too much", __func__)); @@ -3510,11 +3515,9 @@ tcp_xmit_timer(struct tcpcb *tp, int rtt) * While looking at the routing entry, we also initialize other path-dependent * parameters from pre-set or cached values in the routing entry. * - * Also take into account the space needed for options that we - * send regularly. Make maxseg shorter by that amount to assure - * that we can send maxseg amount of data even when the options - * are present. Store the upper limit of the length of options plus - * data in maxopd. + * NOTE that resulting t_maxseg doesn't include space for TCP options or + * IP options, e.g. IPSEC data, since length of this data may vary, and + * thus it is calculated for every segment separately in tcp_output(). * * NOTE that this routine is only called when we process an incoming * segment, or an ICMP need fragmentation datagram. Outgoing SYN/ACK MSS @@ -3528,7 +3531,6 @@ tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer, u_long maxmtu = 0; struct inpcb *inp = tp->t_inpcb; struct hc_metrics_lite metrics; - int origoffer; #ifdef INET6 int isipv6 = ((inp->inp_vflag & INP_IPV6) != 0) ? 1 : 0; size_t min_protoh = isipv6 ? @@ -3544,13 +3546,12 @@ tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer, KASSERT(offer == -1, ("%s: conflict", __func__)); offer = mtuoffer - min_protoh; } - origoffer = offer; /* Initialize. */ #ifdef INET6 if (isipv6) { maxmtu = tcp_maxmtu6(&inp->inp_inc, cap); - tp->t_maxopd = tp->t_maxseg = V_tcp_v6mssdflt; + tp->t_maxseg = V_tcp_v6mssdflt; } #endif #if defined(INET) && defined(INET6) @@ -3559,7 +3560,7 @@ tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer, #ifdef INET { maxmtu = tcp_maxmtu(&inp->inp_inc, cap); - tp->t_maxopd = tp->t_maxseg = V_tcp_mssdflt; + tp->t_maxseg = V_tcp_mssdflt; } #endif @@ -3583,9 +3584,9 @@ tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer, /* * Offer == 0 means that there was no MSS on the SYN * segment, in this case we use tcp_mssdflt as - * already assigned to t_maxopd above. + * already assigned to t_maxseg above. */ - offer = tp->t_maxopd; + offer = tp->t_maxseg; break; case -1: @@ -3657,31 +3658,15 @@ tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer, mss = min(mss, offer); /* - * Sanity check: make sure that maxopd will be large + * Sanity check: make sure that maxseg will be large * enough to allow some data on segments even if the * all the option space is used (40bytes). Otherwise * funny things may happen in tcp_output. + * + * XXXGL: shouldn't we reserve space for IP/IPv6 options? */ mss = max(mss, 64); - /* - * maxopd stores the maximum length of data AND options - * in a segment; maxseg is the amount of data in a normal - * segment. We need to store this value (maxopd) apart - * from maxseg, because now every segment carries options - * and thus we normally have somewhat less data in segments. - */ - tp->t_maxopd = mss; - - /* - * origoffer==-1 indicates that no segments were received yet. - * In this case we just guess. - */ - if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP && - (origoffer == -1 || - (tp->t_flags & TF_RCVD_TSTMP) == TF_RCVD_TSTMP)) - mss -= TCPOLEN_TSTAMP_APPA; - tp->t_maxseg = mss; } @@ -3804,7 +3789,8 @@ void tcp_newreno_partial_ack(struct tcpcb *tp, struct tcphdr *th) { tcp_seq onxt = tp->snd_nxt; - u_long ocwnd = tp->snd_cwnd; + u_long ocwnd = tp->snd_cwnd; + u_int maxseg = tcp_maxseg(tp); INP_WLOCK_ASSERT(tp->t_inpcb); @@ -3815,7 +3801,7 @@ tcp_newreno_partial_ack(struct tcpcb *tp, struct tcphdr *th) * Set snd_cwnd to one segment beyond acknowledged offset. * (tp->snd_una has not yet been updated when this function is called.) */ - tp->snd_cwnd = tp->t_maxseg + BYTES_THIS_ACK(tp, th); + tp->snd_cwnd = maxseg + BYTES_THIS_ACK(tp, th); tp->t_flags |= TF_ACKNOW; (void) tp->t_fb->tfb_tcp_output(tp); tp->snd_cwnd = ocwnd; @@ -3829,7 +3815,7 @@ tcp_newreno_partial_ack(struct tcpcb *tp, struct tcphdr *th) tp->snd_cwnd -= BYTES_THIS_ACK(tp, th); else tp->snd_cwnd = 0; - tp->snd_cwnd += tp->t_maxseg; + tp->snd_cwnd += maxseg; } int diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 482ead5a329b..3c32d77c377e 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -830,11 +830,11 @@ tcp_output(struct tcpcb *tp) /* * Adjust data length if insertion of options will - * bump the packet length beyond the t_maxopd length. + * bump the packet length beyond the t_maxseg length. * Clear the FIN bit because we cut off the tail of * the segment. */ - if (len + optlen + ipoptlen > tp->t_maxopd) { + if (len + optlen + ipoptlen > tp->t_maxseg) { flags &= ~TH_FIN; if (tso) { @@ -937,7 +937,7 @@ tcp_output(struct tcpcb *tp) * fractional unless the send sockbuf can be * emptied: */ - max_len = (tp->t_maxopd - optlen); + max_len = (tp->t_maxseg - optlen); if ((off + len) < sbavail(&so->so_snd)) { moff = len % max_len; if (moff != 0) { @@ -967,7 +967,7 @@ tcp_output(struct tcpcb *tp) sendalot = 1; } else { - len = tp->t_maxopd - optlen - ipoptlen; + len = tp->t_maxseg - optlen - ipoptlen; sendalot = 1; } } else @@ -1277,10 +1277,10 @@ tcp_output(struct tcpcb *tp) * The TCP pseudo header checksum is always provided. */ if (tso) { - KASSERT(len > tp->t_maxopd - optlen, + KASSERT(len > tp->t_maxseg - optlen, ("%s: len <= tso_segsz", __func__)); m->m_pkthdr.csum_flags |= CSUM_TSO; - m->m_pkthdr.tso_segsz = tp->t_maxopd - optlen; + m->m_pkthdr.tso_segsz = tp->t_maxseg - optlen; } #ifdef IPSEC @@ -1348,7 +1348,7 @@ tcp_output(struct tcpcb *tp) */ ip6->ip6_plen = htons(m->m_pkthdr.len - sizeof(*ip6)); - if (V_path_mtu_discovery && tp->t_maxopd > V_tcp_minmss) + if (V_path_mtu_discovery && tp->t_maxseg > V_tcp_minmss) tp->t_flags2 |= TF2_PLPMTU_PMTUD; else tp->t_flags2 &= ~TF2_PLPMTU_PMTUD; @@ -1394,7 +1394,7 @@ tcp_output(struct tcpcb *tp) * * NB: Don't set DF on small MTU/MSS to have a safe fallback. */ - if (V_path_mtu_discovery && tp->t_maxopd > V_tcp_minmss) { + if (V_path_mtu_discovery && tp->t_maxseg > V_tcp_minmss) { ip->ip_off |= htons(IP_DF); tp->t_flags2 |= TF2_PLPMTU_PMTUD; } else { diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index c2e0696394a5..9f21f116f164 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1087,7 +1087,7 @@ tcp_newtcpcb(struct inpcb *inp) #endif tp->t_timers = &tm->tt; /* LIST_INIT(&tp->t_segq); */ /* XXX covered by M_ZERO */ - tp->t_maxseg = tp->t_maxopd = + tp->t_maxseg = #ifdef INET6 isipv6 ? V_tcp_v6mssdflt : #endif /* INET6 */ @@ -1901,7 +1901,7 @@ tcp_ctlinput(int cmd, struct sockaddr *sa, void *vip) * Only process the offered MTU if it * is smaller than the current one. */ - if (mtu < tp->t_maxopd + + if (mtu < tp->t_maxseg + sizeof(struct tcpiphdr)) { bzero(&inc, sizeof(inc)); inc.inc_faddr = faddr; @@ -2283,6 +2283,59 @@ tcp_maxmtu6(struct in_conninfo *inc, struct tcp_ifcap *cap) } #endif /* INET6 */ +/* + * Calculate effective SMSS per RFC5681 definition for a given TCP + * connection at its current state, taking into account SACK and etc. + */ +u_int +tcp_maxseg(const struct tcpcb *tp) +{ + u_int optlen; + + if (tp->t_flags & TF_NOOPT) + return (tp->t_maxseg); + + /* + * Here we have a simplified code from tcp_addoptions(), + * without a proper loop, and having most of paddings hardcoded. + * We might make mistakes with padding here in some edge cases, + * but this is harmless, since result of tcp_maxseg() is used + * only in cwnd and ssthresh estimations. + */ +#define PAD(len) ((((len) / 4) + !!((len) % 4)) * 4) + if (TCPS_HAVEESTABLISHED(tp->t_state)) { + if (tp->t_flags & TF_RCVD_TSTMP) + optlen = TCPOLEN_TSTAMP_APPA; + else + optlen = 0; +#ifdef TCP_SIGNATURE + if (tp->t_flags & TF_SIGNATURE) + optlen += PAD(TCPOLEN_SIGNATURE); +#endif + if ((tp->t_flags & TF_SACK_PERMIT) && tp->rcv_numsacks > 0) { + optlen += TCPOLEN_SACKHDR; + optlen += tp->rcv_numsacks * TCPOLEN_SACK; + optlen = PAD(optlen); + } + } else { + if (tp->t_flags & TF_REQ_TSTMP) + optlen = TCPOLEN_TSTAMP_APPA; + else + optlen = PAD(TCPOLEN_MAXSEG); + if (tp->t_flags & TF_REQ_SCALE) + optlen += PAD(TCPOLEN_WINDOW); +#ifdef TCP_SIGNATURE + if (tp->t_flags & TF_SIGNATURE) + optlen += PAD(TCPOLEN_SIGNATURE); +#endif + if (tp->t_flags & TF_SACK_PERMIT) + optlen += PAD(TCPOLEN_SACK_PERMITTED); + } +#undef PAD + optlen = min(optlen, TCP_MAXOLEN); + return (tp->t_maxseg - optlen); +} + #ifdef IPSEC /* compute ESP/AH header size for TCP, including outer IP header. */ size_t diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 9767eb709056..fb4ff11a4a72 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -660,7 +660,6 @@ tcp_timer_rexmt(void * xtp) */ if (V_tcp_pmtud_blackhole_detect && (((tp->t_state == TCPS_ESTABLISHED)) || (tp->t_state == TCPS_FIN_WAIT_1))) { - int optlen; #ifdef INET6 int isipv6; #endif @@ -684,8 +683,7 @@ tcp_timer_rexmt(void * xtp) tp->t_flags2 |= TF2_PLPMTU_BLACKHOLE; /* Keep track of previous MSS. */ - optlen = tp->t_maxopd - tp->t_maxseg; - tp->t_pmtud_saved_maxopd = tp->t_maxopd; + tp->t_pmtud_saved_maxseg = tp->t_maxseg; /* * Reduce the MSS to blackhole value or to the default @@ -694,13 +692,13 @@ tcp_timer_rexmt(void * xtp) #ifdef INET6 isipv6 = (tp->t_inpcb->inp_vflag & INP_IPV6) ? 1 : 0; if (isipv6 && - tp->t_maxopd > V_tcp_v6pmtud_blackhole_mss) { + tp->t_maxseg > V_tcp_v6pmtud_blackhole_mss) { /* Use the sysctl tuneable blackhole MSS. */ - tp->t_maxopd = V_tcp_v6pmtud_blackhole_mss; + tp->t_maxseg = V_tcp_v6pmtud_blackhole_mss; V_tcp_pmtud_blackhole_activated++; } else if (isipv6) { /* Use the default MSS. */ - tp->t_maxopd = V_tcp_v6mssdflt; + tp->t_maxseg = V_tcp_v6mssdflt; /* * Disable Path MTU Discovery when we switch to * minmss. @@ -713,13 +711,13 @@ tcp_timer_rexmt(void * xtp) else #endif #ifdef INET - if (tp->t_maxopd > V_tcp_pmtud_blackhole_mss) { + if (tp->t_maxseg > V_tcp_pmtud_blackhole_mss) { /* Use the sysctl tuneable blackhole MSS. */ - tp->t_maxopd = V_tcp_pmtud_blackhole_mss; + tp->t_maxseg = V_tcp_pmtud_blackhole_mss; V_tcp_pmtud_blackhole_activated++; } else { /* Use the default MSS. */ - tp->t_maxopd = V_tcp_mssdflt; + tp->t_maxseg = V_tcp_mssdflt; /* * Disable Path MTU Discovery when we switch to * minmss. @@ -728,7 +726,6 @@ tcp_timer_rexmt(void * xtp) V_tcp_pmtud_blackhole_activated_min_mss++; } #endif - tp->t_maxseg = tp->t_maxopd - optlen; /* * Reset the slow-start flight size * as it may depend on the new MSS. @@ -748,9 +745,7 @@ tcp_timer_rexmt(void * xtp) (tp->t_rxtshift > 6)) { tp->t_flags2 |= TF2_PLPMTU_PMTUD; tp->t_flags2 &= ~TF2_PLPMTU_BLACKHOLE; - optlen = tp->t_maxopd - tp->t_maxseg; - tp->t_maxopd = tp->t_pmtud_saved_maxopd; - tp->t_maxseg = tp->t_maxopd - optlen; + tp->t_maxseg = tp->t_pmtud_saved_maxseg; V_tcp_pmtud_blackhole_failed++; /* * Reset the slow-start flight size as it diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 3435668dd8cb..76bc8aac0d99 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -904,8 +904,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, /* * Do implied connect if not yet connected, * initialize window to default value, and - * initialize maxseg/maxopd using peer's cached - * MSS. + * initialize maxseg using peer's cached MSS. */ #ifdef INET6 if (isipv6) @@ -964,8 +963,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, /* * Do implied connect if not yet connected, * initialize window to default value, and - * initialize maxseg/maxopd using peer's cached - * MSS. + * initialize maxseg using peer's cached MSS. */ #ifdef INET6 if (isipv6) @@ -2208,8 +2206,8 @@ db_print_tcpcb(struct tcpcb *tp, const char *name, int indent) "0x%08x\n", tp->snd_ssthresh, tp->snd_recover); db_print_indent(indent); - db_printf("t_maxopd: %u t_rcvtime: %u t_startime: %u\n", - tp->t_maxopd, tp->t_rcvtime, tp->t_starttime); + db_printf("t_rcvtime: %u t_startime: %u\n", + tp->t_rcvtime, tp->t_starttime); db_print_indent(indent); db_printf("t_rttime: %u t_rtsq: 0x%08x\n", diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 8d76912275a1..6cd4cf05874a 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -180,8 +180,6 @@ struct tcpcb { u_long snd_spare2; /* unused */ tcp_seq snd_recover; /* for use in NewReno Fast Recovery */ - u_int t_maxopd; /* mss plus options */ - u_int t_rcvtime; /* inactivity time */ u_int t_starttime; /* time connection was established */ u_int t_rtttime; /* RTT measurement start time */ @@ -192,6 +190,7 @@ struct tcpcb { int t_rxtcur; /* current retransmit value (ticks) */ u_int t_maxseg; /* maximum segment size */ + u_int t_pmtud_saved_maxseg; /* pre-blackhole MSS */ int t_srtt; /* smoothed round-trip time */ int t_rttvar; /* variance in round-trip time */ @@ -251,7 +250,6 @@ struct tcpcb { u_int t_tsomax; /* TSO total burst length limit in bytes */ u_int t_tsomaxsegcount; /* TSO maximum segment count */ u_int t_tsomaxsegsize; /* TSO maximum segment size in bytes */ - u_int t_pmtud_saved_maxopd; /* pre-blackhole MSS */ u_int t_flags2; /* More tcpcb flags storage */ #if defined(_KERNEL) && defined(TCP_RFC7413) uint32_t t_ispare[6]; /* 5 UTO, 1 TBD */ @@ -775,6 +773,7 @@ int tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb u_long tcp_maxmtu(struct in_conninfo *, struct tcp_ifcap *); u_long tcp_maxmtu6(struct in_conninfo *, struct tcp_ifcap *); +u_int tcp_maxseg(const struct tcpcb *); void tcp_mss_update(struct tcpcb *, int, int, struct hc_metrics_lite *, struct tcp_ifcap *); void tcp_mss(struct tcpcb *, int); From dbecd1bfdf736d7fff457b6f6e28f43365cb1dfa Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 7 Jan 2016 00:15:02 +0000 Subject: [PATCH 05/68] Switch GNU ld to be installed as ld.bfd and linked as ld We intend to replace GNU ld with LLVM's lld, and on the path to there we'll experiment with having lld installed or linked as /usr/bin/ld. Thus, make ld.bfd the primary install target for GNU ld, to later facilitate making the ld link optional. Reviewed by: davide, dim Differential Revision: https://reviews.freebsd.org/D4790 --- gnu/usr.bin/binutils/ld/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gnu/usr.bin/binutils/ld/Makefile b/gnu/usr.bin/binutils/ld/Makefile index 5058c0a8e3e8..5bc3846a1434 100644 --- a/gnu/usr.bin/binutils/ld/Makefile +++ b/gnu/usr.bin/binutils/ld/Makefile @@ -6,7 +6,8 @@ ELF_SCR_EXT= x xbn xc xd xdc xdw xn xr xs xsc xsw xu xw .PATH: ${SRCDIR}/ld -PROG= ld +PROG= ld.bfd +MAN= ld.1 SCRIPTDIR= /usr/libdata/ldscripts SRCS+= ldcref.c \ ldctor.c \ @@ -48,7 +49,7 @@ CLEANFILES+= ldemul-list.h stringify.sed FILES= ${LDSCRIPTS:S|^|ldscripts/|} FILESDIR= ${SCRIPTDIR} -LINKS= ${BINDIR}/ld ${BINDIR}/ld.bfd +LINKS= ${BINDIR}/ld.bfd ${BINDIR}/ld HOST= ${TARGET_TUPLE} LIBSEARCHPATH= \"=/lib\":\"=/usr/lib\" From 3ba0785a742f0a29c3869f52bd99e6b5b8b9c0e0 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 00:19:03 +0000 Subject: [PATCH 06/68] Move the MAKEOBJDIRPREFIX value guard to sys.mk and expand to MAKEOBJDIR. This will ensure that the variable was not set as a make override, in make.conf, src.conf or src-env.conf. It allows setting the value in src-env.conf when using WITH_AUTO_OBJ since that case properly handles changing .OBJDIR (except if MAKEOBJDIRPREFIX does not yet exist which is being discussed to be changed). This change allows setting a default MAKEOBJDIRPREFIX via local.sys.env.mk. Sponsored by: EMC / Isilon Storage Division --- Makefile | 7 ------- share/mk/sys.mk | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 836097b42389..c9b8a0a11bc0 100644 --- a/Makefile +++ b/Makefile @@ -143,13 +143,6 @@ TGTS+= ${BITGTS} PATH= /sbin:/bin:/usr/sbin:/usr/bin MAKEOBJDIRPREFIX?= /usr/obj -_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \ - ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \ - -f /dev/null -V MAKEOBJDIRPREFIX dummy -.if !empty(_MAKEOBJDIRPREFIX) -.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\ - (in make.conf(5)) or command-line variable. -.endif # We often need to use the tree's version of make to build it. # Choices add to complexity though. diff --git a/share/mk/sys.mk b/share/mk/sys.mk index 51f2818480d7..d8fc057b12db 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -33,6 +33,13 @@ __ENV_ONLY_OPTIONS:= \ ${__DEFAULT_YES_OPTIONS} \ ${__DEFAULT_DEPENDENT_OPTIONS:H} +__ENV_ONLY_VARS= \ + MAKEOBJDIR \ + MAKEOBJDIRPREFIX +.for _var in ${__ENV_ONLY_VARS} +_pre_includes_${_var:tl}:= ${${_var}:U__null} +.endfor + # early include for customization # see local.sys.mk below # Not included when building in fmake compatibility mode (still needed @@ -50,6 +57,9 @@ __ENV_ONLY_OPTIONS:= \ .endif .endif .if ${MK_AUTO_OBJ} == "yes" +# Reset, since it is allowed to be set from src-env.conf included before this. +_pre_includes_makeobjdirprefix:= ${MAKEOBJDIRPREFIX:U__null} +_pre_includes_makeobjdir:= ${MAKEOBJDIR:U__null} # This needs to be done early - before .PATH is computed # Don't do this for 'make showconfig' as it enables all options where meta mode # is not expected. @@ -410,6 +420,15 @@ __MAKE_SHELL?=/bin/sh path=${__MAKE_SHELL} .endif +# Ensure MAKEOBJDIRPREFIX was not incorrectly set. +.for _var in ${__ENV_ONLY_VARS} +.if ${.MAKEOVERRIDES:M${_var}} || (defined(${_var}) && \ + ${${_var}} != ${_pre_includes_${_var:tl}}) +.error ${_var} can only be set in environment, not as a global (in make.conf(5)) or command-line variable. +.endif +.undef _pre_includes_${_var:tl} +.endfor + # Hack for ports compatibility. Historically, ports makefiles have # assumed they can examine MACHINE_CPU without including anything # because this was automatically included in sys.mk. For /usr/src, From f99c0d1382b3a1ec51248c04d2bc19ddaac93221 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 00:19:30 +0000 Subject: [PATCH 07/68] Add in DIRDEPS_BUILD support. Sponsored by: EMC / Isilon Storage Division --- lib/libsysdecode/Makefile.depend | 22 +++++++++++++++++++++ targets/pseudo/userland/lib/Makefile.depend | 1 + 2 files changed, 23 insertions(+) create mode 100644 lib/libsysdecode/Makefile.depend diff --git a/lib/libsysdecode/Makefile.depend b/lib/libsysdecode/Makefile.depend new file mode 100644 index 000000000000..653f52664dc0 --- /dev/null +++ b/lib/libsysdecode/Makefile.depend @@ -0,0 +1,22 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + gnu/lib/csu \ + gnu/lib/libgcc \ + include \ + include/rpc \ + include/xlocale \ + lib/${CSU_DIR} \ + lib/libc \ + lib/libcompiler_rt \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +ioctl.So: ioctl.c +ioctl.o: ioctl.c +ioctl.po: ioctl.c +.endif diff --git a/targets/pseudo/userland/lib/Makefile.depend b/targets/pseudo/userland/lib/Makefile.depend index c5e2407ddc18..e57164a7d917 100644 --- a/targets/pseudo/userland/lib/Makefile.depend +++ b/targets/pseudo/userland/lib/Makefile.depend @@ -136,6 +136,7 @@ DIRDEPS = \ lib/libstand \ lib/libstdbuf \ lib/libstdthreads \ + lib/libsysdecode \ lib/libtacplus \ lib/libtelnet \ lib/libthr \ From 0e87e3cb6fc5d22df0d6cd87bc9cd90d65d811f3 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 00:20:47 +0000 Subject: [PATCH 08/68] Revert r293286. It was not intended to come in yet. --- Makefile | 7 +++++++ share/mk/sys.mk | 19 ------------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index c9b8a0a11bc0..836097b42389 100644 --- a/Makefile +++ b/Makefile @@ -143,6 +143,13 @@ TGTS+= ${BITGTS} PATH= /sbin:/bin:/usr/sbin:/usr/bin MAKEOBJDIRPREFIX?= /usr/obj +_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \ + ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \ + -f /dev/null -V MAKEOBJDIRPREFIX dummy +.if !empty(_MAKEOBJDIRPREFIX) +.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\ + (in make.conf(5)) or command-line variable. +.endif # We often need to use the tree's version of make to build it. # Choices add to complexity though. diff --git a/share/mk/sys.mk b/share/mk/sys.mk index d8fc057b12db..51f2818480d7 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -33,13 +33,6 @@ __ENV_ONLY_OPTIONS:= \ ${__DEFAULT_YES_OPTIONS} \ ${__DEFAULT_DEPENDENT_OPTIONS:H} -__ENV_ONLY_VARS= \ - MAKEOBJDIR \ - MAKEOBJDIRPREFIX -.for _var in ${__ENV_ONLY_VARS} -_pre_includes_${_var:tl}:= ${${_var}:U__null} -.endfor - # early include for customization # see local.sys.mk below # Not included when building in fmake compatibility mode (still needed @@ -57,9 +50,6 @@ _pre_includes_${_var:tl}:= ${${_var}:U__null} .endif .endif .if ${MK_AUTO_OBJ} == "yes" -# Reset, since it is allowed to be set from src-env.conf included before this. -_pre_includes_makeobjdirprefix:= ${MAKEOBJDIRPREFIX:U__null} -_pre_includes_makeobjdir:= ${MAKEOBJDIR:U__null} # This needs to be done early - before .PATH is computed # Don't do this for 'make showconfig' as it enables all options where meta mode # is not expected. @@ -420,15 +410,6 @@ __MAKE_SHELL?=/bin/sh path=${__MAKE_SHELL} .endif -# Ensure MAKEOBJDIRPREFIX was not incorrectly set. -.for _var in ${__ENV_ONLY_VARS} -.if ${.MAKEOVERRIDES:M${_var}} || (defined(${_var}) && \ - ${${_var}} != ${_pre_includes_${_var:tl}}) -.error ${_var} can only be set in environment, not as a global (in make.conf(5)) or command-line variable. -.endif -.undef _pre_includes_${_var:tl} -.endfor - # Hack for ports compatibility. Historically, ports makefiles have # assumed they can examine MACHINE_CPU without including anything # because this was automatically included in sys.mk. For /usr/src, From b8e3d9cc79f70c21c09717b75766498d208577e3 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 00:32:40 +0000 Subject: [PATCH 09/68] Update dependencies after r292622 moved the ioctl script. Sponsored by: EMC / Isilon Storage Division --- usr.bin/truss/Makefile.depend.amd64 | 3 --- 1 file changed, 3 deletions(-) diff --git a/usr.bin/truss/Makefile.depend.amd64 b/usr.bin/truss/Makefile.depend.amd64 index ad9c8b3d5906..334bb3a8d446 100644 --- a/usr.bin/truss/Makefile.depend.amd64 +++ b/usr.bin/truss/Makefile.depend.amd64 @@ -6,7 +6,6 @@ DIRDEPS = \ gnu/lib/libgcc \ include \ include/arpa \ - include/rpc \ include/xlocale \ lib/${CSU_DIR} \ lib/libc \ @@ -26,6 +25,4 @@ amd64-freebsd32.o: freebsd32_syscalls.h amd64-freebsd32.po: freebsd32_syscalls.h amd64-linux32.o: amd64-linux32_syscalls.h amd64-linux32.po: amd64-linux32_syscalls.h -ioctl.o: ioctl.c -ioctl.po: ioctl.c .endif From 6b53d1bc6f718a2c7b45cf992dfeaeb940f63d9c Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 7 Jan 2016 02:04:17 +0000 Subject: [PATCH 10/68] cache: ansify functions and fix some style issues No functional changes. --- sys/kern/vfs_cache.c | 55 ++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index ff3736d2dffa..f1bd82122372 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -288,7 +288,7 @@ static u_long nummiss; STATNODE(CTLFLAG_RD, nummiss, &nummiss, "Number of cache misses"); static u_long nummisszap; STATNODE(CTLFLAG_RD, nummisszap, &nummisszap, "Number of cache misses we do not want to cache"); -static u_long numposzaps; STATNODE(CTLFLAG_RD, numposzaps, &numposzaps, +static u_long numposzaps; STATNODE(CTLFLAG_RD, numposzaps, &numposzaps, "Number of cache hits (positive) we do not want to cache"); static u_long numposhits; STATNODE(CTLFLAG_RD, numposhits, &numposhits, "Number of cache hits (positive)"); @@ -303,8 +303,6 @@ SYSCTL_OPAQUE(_vfs_cache, OID_AUTO, nchstats, CTLFLAG_RD | CTLFLAG_MPSAFE, &nchstats, sizeof(nchstats), "LU", "VFS cache effectiveness statistics"); - - static void cache_zap(struct namecache *ncp); static int vn_vptocnp_locked(struct vnode **vp, struct ucred *cred, char *buf, u_int *buflen); @@ -410,8 +408,7 @@ SYSCTL_PROC(_debug_hashstat, OID_AUTO, nchash, CTLTYPE_INT|CTLFLAG_RD| * pointer to a vnode or if it is just a negative cache entry. */ static void -cache_zap(ncp) - struct namecache *ncp; +cache_zap(struct namecache *ncp) { struct vnode *vp; @@ -446,7 +443,7 @@ cache_zap(ncp) } numcache--; cache_free(ncp); - if (vp) + if (vp != NULL) vdrop(vp); } @@ -468,12 +465,8 @@ cache_zap(ncp) */ int -cache_lookup(dvp, vpp, cnp, tsp, ticksp) - struct vnode *dvp; - struct vnode **vpp; - struct componentname *cnp; - struct timespec *tsp; - int *ticksp; +cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, + struct timespec *tsp, int *ticksp) { struct namecache *ncp; uint32_t hash; @@ -701,12 +694,8 @@ cache_lookup(dvp, vpp, cnp, tsp, ticksp) * Add an entry to the cache. */ void -cache_enter_time(dvp, vp, cnp, tsp, dtsp) - struct vnode *dvp; - struct vnode *vp; - struct componentname *cnp; - struct timespec *tsp; - struct timespec *dtsp; +cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, + struct timespec *tsp, struct timespec *dtsp) { struct namecache *ncp, *n2; struct namecache_ts *n3; @@ -836,9 +825,9 @@ cache_enter_time(dvp, vp, cnp, tsp, dtsp) * has populated v_cache_dd pointer already. */ if (dvp->v_cache_dd != NULL) { - CACHE_WUNLOCK(); - cache_free(ncp); - return; + CACHE_WUNLOCK(); + cache_free(ncp); + return; } KASSERT(vp == NULL || vp->v_type == VDIR, ("wrong vnode type %p", vp)); @@ -846,7 +835,7 @@ cache_enter_time(dvp, vp, cnp, tsp, dtsp) } numcache++; - if (!vp) { + if (vp == NULL) { numneg++; if (cnp->cn_flags & ISWHITEOUT) ncp->nc_flag |= NCF_WHITE; @@ -884,7 +873,7 @@ cache_enter_time(dvp, vp, cnp, tsp, dtsp) * "negative" cache queue, otherwise, we place it into the * destination vnode's cache entries queue. */ - if (vp) { + if (vp != NULL) { TAILQ_INSERT_HEAD(&vp->v_cache_dst, ncp, nc_dst); SDT_PROBE3(vfs, namecache, enter, done, dvp, nc_get_name(ncp), vp); @@ -975,8 +964,7 @@ cache_changesize(int newmaxvnodes) * Invalidate all entries to a particular vnode. */ void -cache_purge(vp) - struct vnode *vp; +cache_purge(struct vnode *vp) { CTR1(KTR_VFS, "cache_purge(%p)", vp); @@ -999,8 +987,7 @@ cache_purge(vp) * Invalidate all negative entries for a particular directory vnode. */ void -cache_purge_negative(vp) - struct vnode *vp; +cache_purge_negative(struct vnode *vp) { struct namecache *cp, *ncp; @@ -1018,8 +1005,7 @@ cache_purge_negative(vp) * Flush all entries referencing a particular filesystem. */ void -cache_purgevfs(mp) - struct mount *mp; +cache_purgevfs(struct mount *mp) { struct nchashhead *ncpp; struct namecache *ncp, *nnp; @@ -1042,12 +1028,7 @@ cache_purgevfs(mp) */ int -vfs_cache_lookup(ap) - struct vop_lookup_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - } */ *ap; +vfs_cache_lookup(struct vop_lookup_args *ap) { struct vnode *dvp; int error; @@ -1088,9 +1069,7 @@ SYSCTL_INT(_debug, OID_AUTO, disablecwd, CTLFLAG_RW, &disablecwd, 0, /* Implementation of the getcwd syscall. */ int -sys___getcwd(td, uap) - struct thread *td; - struct __getcwd_args *uap; +sys___getcwd(struct thread *td, struct __getcwd_args *uap) { return (kern___getcwd(td, uap->buf, UIO_USERSPACE, uap->buflen, From b875c2e96d79d6174c20232829d7b84c0c3c8ca0 Mon Sep 17 00:00:00 2001 From: Josh Paetzel Date: Thu, 7 Jan 2016 05:34:39 +0000 Subject: [PATCH 11/68] Allow /etc/exports to contain usernames/groups with spaces in them. If you are getting your users/groups from a directory service such as LDAP or AD it's possible for those usernames or groupnames to contain spaces. Submitted by: Sean E. Fagan Reviewed by: rmacklem MFC after: 1 week Sponsored by: iXsystems --- usr.sbin/mountd/exports.5 | 2 ++ usr.sbin/mountd/mountd.c | 71 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/usr.sbin/mountd/exports.5 b/usr.sbin/mountd/exports.5 index 88e2219ab46d..018a865015ab 100644 --- a/usr.sbin/mountd/exports.5 +++ b/usr.sbin/mountd/exports.5 @@ -131,6 +131,7 @@ The credential includes all the groups to which the user is a member on the local machine (see .Xr id 1 ) . The user may be specified by name or number. +The user string may be quoted, or use backslash escaping. .Pp .Sm off .Fl maproot Li = Sy user:group1:group2:... @@ -140,6 +141,7 @@ to be used for remote access by root. The elements of the list may be either names or numbers. Note that user: should be used to distinguish a credential containing no groups from a complete credential for that user. +The group names may be quoted, or use backslash escaping. .Pp .Sm off .Fl mapall Li = Sy user diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index 535a3f718197..d6da2bc9c24c 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -174,6 +174,7 @@ static int check_options(struct dirlist *); static int checkmask(struct sockaddr *sa); static int chk_host(struct dirlist *, struct sockaddr *, int *, int *, int *, int **); +static char *strsep_quote(char **stringp, const char *delim); static int create_service(struct netconfig *nconf); static void complete_service(struct netconfig *nconf, char *port_str); static void clearout_service(void); @@ -277,6 +278,73 @@ static void SYSLOG(int, const char *, ...) __printflike(2, 3); static int debug = 0; #endif +/* + * Similar to strsep(), but it allows for quoted strings + * and escaped characters. + * + * It returns the string (or NULL, if *stringp is NULL), + * which is a de-quoted version of the string if necessary. + * + * It modifies *stringp in place. + */ +static char * +strsep_quote(char **stringp, const char *delim) +{ + char *srcptr, *dstptr, *retval; + char quot = 0; + + if (stringp == NULL || *stringp == NULL) + return (NULL); + + srcptr = dstptr = retval = *stringp; + + while (*srcptr) { + /* + * We're looking for several edge cases here. + * First: if we're in quote state (quot != 0), + * then we ignore the delim characters, but otherwise + * process as normal, unless it is the quote character. + * Second: if the current character is a backslash, + * we take the next character as-is, without checking + * for delim, quote, or backslash. Exception: if the + * next character is a NUL, that's the end of the string. + * Third: if the character is a quote character, we toggle + * quote state. + * Otherwise: check the current character for NUL, or + * being in delim, and end the string if either is true. + */ + if (*srcptr == '\\') { + srcptr++; + /* + * The edge case here is if the next character + * is NUL, we want to stop processing. But if + * it's not NUL, then we simply want to copy it. + */ + if (*srcptr) { + *dstptr++ = *srcptr++; + } + continue; + } + if (quot == 0 && (*srcptr == '\'' || *srcptr == '"')) { + quot = *srcptr++; + continue; + } + if (quot && *srcptr == quot) { + /* End of the quoted part */ + quot = 0; + srcptr++; + continue; + } + if (!quot && strchr(delim, *srcptr)) + break; + *dstptr++ = *srcptr++; + } + + *dstptr = 0; /* Terminate the string */ + *stringp = (*srcptr == '\0') ? NULL : srcptr + 1; + return (retval); +} + /* * Mountd server for NFS mount protocol as described in: * NFS: Network File System Protocol Specification, RFC1094, Appendix A @@ -2831,8 +2899,9 @@ parsecred(char *namelist, struct xucred *cr) /* * Get the user's password table entry. */ - names = strsep(&namelist, " \t\n"); + names = strsep_quote(&namelist, " \t\n"); name = strsep(&names, ":"); + /* Bug? name could be NULL here */ if (isdigit(*name) || *name == '-') pw = getpwuid(atoi(name)); else From 4332feca4b8144d1842c7ecf98ac4f17bac3c1c6 Mon Sep 17 00:00:00 2001 From: Allan Jude Date: Thu, 7 Jan 2016 05:47:34 +0000 Subject: [PATCH 12/68] Make additional parts of sys/geom/eli more usable in userspace The upcoming GELI support in the loader reuses parts of this code Some ifdefs are added, and some code is moved outside of existing ifdefs The HMAC parts of GELI are broken out into their own file, to separate them from the kernel crypto/openssl dependant parts that are replaced in the boot code. Passed the GELI regression suite (tools/regression/geom/eli) Files=20 Tests=14996 Result: PASS Reviewed by: pjd, delphij MFC after: 1 week Sponsored by: ScaleEngine Inc. Differential Revision: https://reviews.freebsd.org/D4699 --- sbin/geom/class/eli/Makefile | 1 + sys/conf/files | 1 + sys/geom/eli/g_eli.c | 83 +--------------- sys/geom/eli/g_eli.h | 96 ++++++++++++++++-- sys/geom/eli/g_eli_crypto.c | 72 -------------- sys/geom/eli/g_eli_hmac.c | 150 +++++++++++++++++++++++++++++ sys/geom/eli/g_eli_key_cache.c | 32 +++--- sys/geom/eli/pkcs5v2.c | 2 + sys/modules/geom/geom_eli/Makefile | 1 + 9 files changed, 254 insertions(+), 184 deletions(-) create mode 100644 sys/geom/eli/g_eli_hmac.c diff --git a/sbin/geom/class/eli/Makefile b/sbin/geom/class/eli/Makefile index 50de65117c62..5eff32c50689 100644 --- a/sbin/geom/class/eli/Makefile +++ b/sbin/geom/class/eli/Makefile @@ -4,6 +4,7 @@ GEOM_CLASS= eli SRCS= g_eli_crypto.c +SRCS+= g_eli_hmac.c SRCS+= g_eli_key.c SRCS+= pkcs5v2.c SRCS+= sha256c.c diff --git a/sys/conf/files b/sys/conf/files index feac6c0e1de9..3652b3b9f7d9 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2994,6 +2994,7 @@ geom/concat/g_concat.c optional geom_concat geom/eli/g_eli.c optional geom_eli geom/eli/g_eli_crypto.c optional geom_eli geom/eli/g_eli_ctl.c optional geom_eli +geom/eli/g_eli_hmac.c optional geom_eli geom/eli/g_eli_integrity.c optional geom_eli geom/eli/g_eli_key.c optional geom_eli geom/eli/g_eli_key_cache.c optional geom_eli diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c index 57adc40addc8..a2b4e6517ee4 100644 --- a/sys/geom/eli/g_eli.c +++ b/sys/geom/eli/g_eli.c @@ -571,40 +571,6 @@ g_eli_worker(void *arg) } } -/* - * Here we generate IV. It is unique for every sector. - */ -void -g_eli_crypto_ivgen(struct g_eli_softc *sc, off_t offset, u_char *iv, - size_t size) -{ - uint8_t off[8]; - - if ((sc->sc_flags & G_ELI_FLAG_NATIVE_BYTE_ORDER) != 0) - bcopy(&offset, off, sizeof(off)); - else - le64enc(off, (uint64_t)offset); - - switch (sc->sc_ealgo) { - case CRYPTO_AES_XTS: - bcopy(off, iv, sizeof(off)); - bzero(iv + sizeof(off), size - sizeof(off)); - break; - default: - { - u_char hash[SHA256_DIGEST_LENGTH]; - SHA256_CTX ctx; - - /* Copy precalculated SHA256 context for IV-Key. */ - bcopy(&sc->sc_ivctx, &ctx, sizeof(ctx)); - SHA256_Update(&ctx, off, sizeof(off)); - SHA256_Final(hash, &ctx); - bcopy(hash, iv, MIN(sizeof(hash), size)); - break; - } - } -} - int g_eli_read_metadata(struct g_class *mp, struct g_provider *pp, struct g_eli_metadata *md) @@ -751,44 +717,9 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp, else gp->access = g_std_access; - sc->sc_version = md->md_version; - sc->sc_inflight = 0; - sc->sc_crypto = G_ELI_CRYPTO_UNKNOWN; - sc->sc_flags = md->md_flags; - /* Backward compatibility. */ - if (md->md_version < G_ELI_VERSION_04) - sc->sc_flags |= G_ELI_FLAG_NATIVE_BYTE_ORDER; - if (md->md_version < G_ELI_VERSION_05) - sc->sc_flags |= G_ELI_FLAG_SINGLE_KEY; - if (md->md_version < G_ELI_VERSION_06 && - (sc->sc_flags & G_ELI_FLAG_AUTH) != 0) { - sc->sc_flags |= G_ELI_FLAG_FIRST_KEY; - } - if (md->md_version < G_ELI_VERSION_07) - sc->sc_flags |= G_ELI_FLAG_ENC_IVKEY; - sc->sc_ealgo = md->md_ealgo; + eli_metadata_softc(sc, md, bpp->sectorsize, bpp->mediasize); sc->sc_nkey = nkey; - if (sc->sc_flags & G_ELI_FLAG_AUTH) { - sc->sc_akeylen = sizeof(sc->sc_akey) * 8; - sc->sc_aalgo = md->md_aalgo; - sc->sc_alen = g_eli_hashlen(sc->sc_aalgo); - - sc->sc_data_per_sector = bpp->sectorsize - sc->sc_alen; - /* - * Some hash functions (like SHA1 and RIPEMD160) generates hash - * which length is not multiple of 128 bits, but we want data - * length to be multiple of 128, so we can encrypt without - * padding. The line below rounds down data length to multiple - * of 128 bits. - */ - sc->sc_data_per_sector -= sc->sc_data_per_sector % 16; - - sc->sc_bytes_per_sector = - (md->md_sectorsize - 1) / sc->sc_data_per_sector + 1; - sc->sc_bytes_per_sector *= bpp->sectorsize; - } - gp->softc = sc; sc->sc_geom = gp; @@ -831,22 +762,10 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp, goto failed; } - sc->sc_sectorsize = md->md_sectorsize; - sc->sc_mediasize = bpp->mediasize; - if (!(sc->sc_flags & G_ELI_FLAG_ONETIME)) - sc->sc_mediasize -= bpp->sectorsize; - if (!(sc->sc_flags & G_ELI_FLAG_AUTH)) - sc->sc_mediasize -= (sc->sc_mediasize % sc->sc_sectorsize); - else { - sc->sc_mediasize /= sc->sc_bytes_per_sector; - sc->sc_mediasize *= sc->sc_sectorsize; - } - /* * Remember the keys in our softc structure. */ g_eli_mkey_propagate(sc, mkey); - sc->sc_ekeylen = md->md_keylen; LIST_INIT(&sc->sc_workers); diff --git a/sys/geom/eli/g_eli.h b/sys/geom/eli/g_eli.h index e4dbee6819ab..3deb865c4af7 100644 --- a/sys/geom/eli/g_eli.h +++ b/sys/geom/eli/g_eli.h @@ -40,8 +40,6 @@ #include #include #include -#include -#include #include #else #include @@ -49,6 +47,8 @@ #include #include #endif +#include +#include #ifndef _OpenSSL_ #include #endif @@ -132,15 +132,15 @@ /* Switch data encryption key every 2^20 blocks. */ #define G_ELI_KEY_SHIFT 20 +#define G_ELI_CRYPTO_UNKNOWN 0 +#define G_ELI_CRYPTO_HW 1 +#define G_ELI_CRYPTO_SW 2 + #ifdef _KERNEL extern int g_eli_debug; extern u_int g_eli_overwrites; extern u_int g_eli_batch; -#define G_ELI_CRYPTO_UNKNOWN 0 -#define G_ELI_CRYPTO_HW 1 -#define G_ELI_CRYPTO_SW 2 - #define G_ELI_DEBUG(lvl, ...) do { \ if (g_eli_debug >= (lvl)) { \ printf("GEOM_ELI"); \ @@ -173,6 +173,8 @@ struct g_eli_worker { LIST_ENTRY(g_eli_worker) w_next; }; +#endif /* _KERNEL */ + struct g_eli_softc { struct g_geom *sc_geom; u_int sc_version; @@ -200,15 +202,35 @@ struct g_eli_softc { size_t sc_sectorsize; u_int sc_bytes_per_sector; u_int sc_data_per_sector; +#ifndef _KERNEL + int sc_cpubind; +#else /* _KERNEL */ boolean_t sc_cpubind; /* Only for software cryptography. */ struct bio_queue_head sc_queue; struct mtx sc_queue_mtx; LIST_HEAD(, g_eli_worker) sc_workers; +#endif /* _KERNEL */ }; #define sc_name sc_geom->name -#endif /* _KERNEL */ + +#define G_ELI_KEY_MAGIC 0xe11341c + +struct g_eli_key { + /* Key value, must be first in the structure. */ + uint8_t gek_key[G_ELI_DATAKEYLEN]; + /* Magic. */ + int gek_magic; + /* Key number. */ + uint64_t gek_keyno; + /* Reference counter. */ + int gek_count; + /* Keeps keys sorted by most recent use. */ + TAILQ_ENTRY(g_eli_key) gek_next; + /* Keeps keys sorted by number. */ + RB_ENTRY(g_eli_key) gek_link; +}; struct g_eli_metadata { char md_magic[16]; /* Magic value. */ @@ -569,6 +591,60 @@ g_eli_hashlen(u_int algo) return (0); } +static __inline void +eli_metadata_softc(struct g_eli_softc *sc, const struct g_eli_metadata *md, + u_int sectorsize, off_t mediasize) +{ + + sc->sc_version = md->md_version; + sc->sc_inflight = 0; + sc->sc_crypto = G_ELI_CRYPTO_UNKNOWN; + sc->sc_flags = md->md_flags; + /* Backward compatibility. */ + if (md->md_version < G_ELI_VERSION_04) + sc->sc_flags |= G_ELI_FLAG_NATIVE_BYTE_ORDER; + if (md->md_version < G_ELI_VERSION_05) + sc->sc_flags |= G_ELI_FLAG_SINGLE_KEY; + if (md->md_version < G_ELI_VERSION_06 && + (sc->sc_flags & G_ELI_FLAG_AUTH) != 0) { + sc->sc_flags |= G_ELI_FLAG_FIRST_KEY; + } + if (md->md_version < G_ELI_VERSION_07) + sc->sc_flags |= G_ELI_FLAG_ENC_IVKEY; + sc->sc_ealgo = md->md_ealgo; + + if (sc->sc_flags & G_ELI_FLAG_AUTH) { + sc->sc_akeylen = sizeof(sc->sc_akey) * 8; + sc->sc_aalgo = md->md_aalgo; + sc->sc_alen = g_eli_hashlen(sc->sc_aalgo); + + sc->sc_data_per_sector = sectorsize - sc->sc_alen; + /* + * Some hash functions (like SHA1 and RIPEMD160) generates hash + * which length is not multiple of 128 bits, but we want data + * length to be multiple of 128, so we can encrypt without + * padding. The line below rounds down data length to multiple + * of 128 bits. + */ + sc->sc_data_per_sector -= sc->sc_data_per_sector % 16; + + sc->sc_bytes_per_sector = + (md->md_sectorsize - 1) / sc->sc_data_per_sector + 1; + sc->sc_bytes_per_sector *= sectorsize; + } + sc->sc_sectorsize = md->md_sectorsize; + sc->sc_mediasize = mediasize; + if (!(sc->sc_flags & G_ELI_FLAG_ONETIME)) + sc->sc_mediasize -= sectorsize; + if (!(sc->sc_flags & G_ELI_FLAG_AUTH)) + sc->sc_mediasize -= (sc->sc_mediasize % sc->sc_sectorsize); + else { + sc->sc_mediasize /= sc->sc_bytes_per_sector; + sc->sc_mediasize *= sc->sc_sectorsize; + } + sc->sc_ekeylen = md->md_keylen; +} + #ifdef _KERNEL int g_eli_read_metadata(struct g_class *mp, struct g_provider *pp, struct g_eli_metadata *md); @@ -583,8 +659,6 @@ void g_eli_config(struct gctl_req *req, struct g_class *mp, const char *verb); void g_eli_read_done(struct bio *bp); void g_eli_write_done(struct bio *bp); int g_eli_crypto_rerun(struct cryptop *crp); -void g_eli_crypto_ivgen(struct g_eli_softc *sc, off_t offset, u_char *iv, - size_t size); void g_eli_crypto_read(struct g_eli_softc *sc, struct bio *bp, boolean_t fromworker); void g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp); @@ -592,6 +666,8 @@ void g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp); void g_eli_auth_read(struct g_eli_softc *sc, struct bio *bp); void g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp); #endif +void g_eli_crypto_ivgen(struct g_eli_softc *sc, off_t offset, u_char *iv, + size_t size); void g_eli_mkey_hmac(unsigned char *mkey, const unsigned char *key); int g_eli_mkey_decrypt(const struct g_eli_metadata *md, @@ -620,6 +696,8 @@ void g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize); void g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize, const uint8_t *data, size_t datasize, uint8_t *md, size_t mdsize); +void g_eli_key_fill(struct g_eli_softc *sc, struct g_eli_key *key, + uint64_t keyno); #ifdef _KERNEL void g_eli_key_init(struct g_eli_softc *sc); void g_eli_key_destroy(struct g_eli_softc *sc); diff --git a/sys/geom/eli/g_eli_crypto.c b/sys/geom/eli/g_eli_crypto.c index 43eabf49e3db..2d145fd80c5a 100644 --- a/sys/geom/eli/g_eli_crypto.c +++ b/sys/geom/eli/g_eli_crypto.c @@ -221,75 +221,3 @@ g_eli_crypto_decrypt(u_int algo, u_char *data, size_t datasize, return (g_eli_crypto_cipher(algo, 0, data, datasize, key, keysize)); } - -void -g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey, - size_t hkeylen) -{ - u_char k_ipad[128], key[128]; - SHA512_CTX lctx; - u_int i; - - bzero(key, sizeof(key)); - if (hkeylen == 0) - ; /* do nothing */ - else if (hkeylen <= 128) - bcopy(hkey, key, hkeylen); - else { - /* If key is longer than 128 bytes reset it to key = SHA512(key). */ - SHA512_Init(&lctx); - SHA512_Update(&lctx, hkey, hkeylen); - SHA512_Final(key, &lctx); - } - - /* XOR key with ipad and opad values. */ - for (i = 0; i < sizeof(key); i++) { - k_ipad[i] = key[i] ^ 0x36; - ctx->k_opad[i] = key[i] ^ 0x5c; - } - bzero(key, sizeof(key)); - /* Perform inner SHA512. */ - SHA512_Init(&ctx->shactx); - SHA512_Update(&ctx->shactx, k_ipad, sizeof(k_ipad)); - bzero(k_ipad, sizeof(k_ipad)); -} - -void -g_eli_crypto_hmac_update(struct hmac_ctx *ctx, const uint8_t *data, - size_t datasize) -{ - - SHA512_Update(&ctx->shactx, data, datasize); -} - -void -g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize) -{ - u_char digest[SHA512_MDLEN]; - SHA512_CTX lctx; - - SHA512_Final(digest, &ctx->shactx); - /* Perform outer SHA512. */ - SHA512_Init(&lctx); - SHA512_Update(&lctx, ctx->k_opad, sizeof(ctx->k_opad)); - bzero(ctx, sizeof(*ctx)); - SHA512_Update(&lctx, digest, sizeof(digest)); - SHA512_Final(digest, &lctx); - bzero(&lctx, sizeof(lctx)); - /* mdsize == 0 means "Give me the whole hash!" */ - if (mdsize == 0) - mdsize = SHA512_MDLEN; - bcopy(digest, md, mdsize); - bzero(digest, sizeof(digest)); -} - -void -g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize, const uint8_t *data, - size_t datasize, uint8_t *md, size_t mdsize) -{ - struct hmac_ctx ctx; - - g_eli_crypto_hmac_init(&ctx, hkey, hkeysize); - g_eli_crypto_hmac_update(&ctx, data, datasize); - g_eli_crypto_hmac_final(&ctx, md, mdsize); -} diff --git a/sys/geom/eli/g_eli_hmac.c b/sys/geom/eli/g_eli_hmac.c new file mode 100644 index 000000000000..36b76deb9fda --- /dev/null +++ b/sys/geom/eli/g_eli_hmac.c @@ -0,0 +1,150 @@ +/*- + * Copyright (c) 2005-2010 Pawel Jakub Dawidek + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#ifdef _KERNEL +#include +#include +#include +#else +#include +#include +#include +#include +#include +#include +#define _OpenSSL_ +#endif +#include + +void +g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey, + size_t hkeylen) +{ + u_char k_ipad[128], key[128]; + SHA512_CTX lctx; + u_int i; + + bzero(key, sizeof(key)); + if (hkeylen == 0) + ; /* do nothing */ + else if (hkeylen <= 128) + bcopy(hkey, key, hkeylen); + else { + /* If key is longer than 128 bytes reset it to key = SHA512(key). */ + SHA512_Init(&lctx); + SHA512_Update(&lctx, hkey, hkeylen); + SHA512_Final(key, &lctx); + } + + /* XOR key with ipad and opad values. */ + for (i = 0; i < sizeof(key); i++) { + k_ipad[i] = key[i] ^ 0x36; + ctx->k_opad[i] = key[i] ^ 0x5c; + } + bzero(key, sizeof(key)); + /* Perform inner SHA512. */ + SHA512_Init(&ctx->shactx); + SHA512_Update(&ctx->shactx, k_ipad, sizeof(k_ipad)); + bzero(k_ipad, sizeof(k_ipad)); +} + +void +g_eli_crypto_hmac_update(struct hmac_ctx *ctx, const uint8_t *data, + size_t datasize) +{ + + SHA512_Update(&ctx->shactx, data, datasize); +} + +void +g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize) +{ + u_char digest[SHA512_MDLEN]; + SHA512_CTX lctx; + + SHA512_Final(digest, &ctx->shactx); + /* Perform outer SHA512. */ + SHA512_Init(&lctx); + SHA512_Update(&lctx, ctx->k_opad, sizeof(ctx->k_opad)); + bzero(ctx, sizeof(*ctx)); + SHA512_Update(&lctx, digest, sizeof(digest)); + SHA512_Final(digest, &lctx); + bzero(&lctx, sizeof(lctx)); + /* mdsize == 0 means "Give me the whole hash!" */ + if (mdsize == 0) + mdsize = SHA512_MDLEN; + bcopy(digest, md, mdsize); + bzero(digest, sizeof(digest)); +} + +void +g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize, const uint8_t *data, + size_t datasize, uint8_t *md, size_t mdsize) +{ + struct hmac_ctx ctx; + + g_eli_crypto_hmac_init(&ctx, hkey, hkeysize); + g_eli_crypto_hmac_update(&ctx, data, datasize); + g_eli_crypto_hmac_final(&ctx, md, mdsize); +} + +/* + * Here we generate IV. It is unique for every sector. + */ +void +g_eli_crypto_ivgen(struct g_eli_softc *sc, off_t offset, u_char *iv, + size_t size) +{ + uint8_t off[8]; + + if ((sc->sc_flags & G_ELI_FLAG_NATIVE_BYTE_ORDER) != 0) + bcopy(&offset, off, sizeof(off)); + else + le64enc(off, (uint64_t)offset); + + switch (sc->sc_ealgo) { + case CRYPTO_AES_XTS: + bcopy(off, iv, sizeof(off)); + bzero(iv + sizeof(off), size - sizeof(off)); + break; + default: + { + u_char hash[SHA256_DIGEST_LENGTH]; + SHA256_CTX ctx; + + /* Copy precalculated SHA256 context for IV-Key. */ + bcopy(&sc->sc_ivctx, &ctx, sizeof(ctx)); + SHA256_Update(&ctx, off, sizeof(off)); + SHA256_Final(hash, &ctx); + bcopy(hash, iv, MIN(sizeof(hash), size)); + break; + } + } +} diff --git a/sys/geom/eli/g_eli_key_cache.c b/sys/geom/eli/g_eli_key_cache.c index cb867166cee3..0b909bef55ee 100644 --- a/sys/geom/eli/g_eli_key_cache.c +++ b/sys/geom/eli/g_eli_key_cache.c @@ -28,17 +28,20 @@ __FBSDID("$FreeBSD$"); #include +#ifdef _KERNEL #include #include -#include #include #include +#endif /* _KERNEL */ +#include #include #include #include +#ifdef _KERNEL MALLOC_DECLARE(M_ELI); SYSCTL_DECL(_kern_geom_eli); @@ -56,22 +59,7 @@ static uint64_t g_eli_key_cache_misses; SYSCTL_UQUAD(_kern_geom_eli, OID_AUTO, key_cache_misses, CTLFLAG_RW, &g_eli_key_cache_misses, 0, "Key cache misses"); -#define G_ELI_KEY_MAGIC 0xe11341c - -struct g_eli_key { - /* Key value, must be first in the structure. */ - uint8_t gek_key[G_ELI_DATAKEYLEN]; - /* Magic. */ - int gek_magic; - /* Key number. */ - uint64_t gek_keyno; - /* Reference counter. */ - int gek_count; - /* Keeps keys sorted by most recent use. */ - TAILQ_ENTRY(g_eli_key) gek_next; - /* Keeps keys sorted by number. */ - RB_ENTRY(g_eli_key) gek_link; -}; +#endif /* _KERNEL */ static int g_eli_key_cmp(const struct g_eli_key *a, const struct g_eli_key *b) @@ -84,10 +72,7 @@ g_eli_key_cmp(const struct g_eli_key *a, const struct g_eli_key *b) return (0); } -RB_PROTOTYPE(g_eli_key_tree, g_eli_key, gek_link, g_eli_key_cmp); -RB_GENERATE(g_eli_key_tree, g_eli_key, gek_link, g_eli_key_cmp); - -static void +void g_eli_key_fill(struct g_eli_softc *sc, struct g_eli_key *key, uint64_t keyno) { const uint8_t *ekey; @@ -110,6 +95,10 @@ g_eli_key_fill(struct g_eli_softc *sc, struct g_eli_key *key, uint64_t keyno) key->gek_magic = G_ELI_KEY_MAGIC; } +#ifdef _KERNEL +RB_PROTOTYPE(g_eli_key_tree, g_eli_key, gek_link, g_eli_key_cmp); +RB_GENERATE(g_eli_key_tree, g_eli_key, gek_link, g_eli_key_cmp); + static struct g_eli_key * g_eli_key_allocate(struct g_eli_softc *sc, uint64_t keyno) { @@ -350,3 +339,4 @@ g_eli_key_drop(struct g_eli_softc *sc, uint8_t *rawkey) } mtx_unlock(&sc->sc_ekeys_lock); } +#endif /* _KERNEL */ diff --git a/sys/geom/eli/pkcs5v2.c b/sys/geom/eli/pkcs5v2.c index 05677c1b76f1..6992801958ce 100644 --- a/sys/geom/eli/pkcs5v2.c +++ b/sys/geom/eli/pkcs5v2.c @@ -83,6 +83,7 @@ pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt, } #ifndef _KERNEL +#ifndef _STAND /* * Return the number of microseconds needed for 'interations' iterations. */ @@ -120,4 +121,5 @@ pkcs5v2_calculate(int usecs) } return (((intmax_t)iterations * (intmax_t)usecs) / v); } +#endif /* !_STAND */ #endif /* !_KERNEL */ diff --git a/sys/modules/geom/geom_eli/Makefile b/sys/modules/geom/geom_eli/Makefile index 51d821a64f62..c42ccf19f737 100644 --- a/sys/modules/geom/geom_eli/Makefile +++ b/sys/modules/geom/geom_eli/Makefile @@ -6,6 +6,7 @@ KMOD= geom_eli SRCS= g_eli.c SRCS+= g_eli_crypto.c SRCS+= g_eli_ctl.c +SRCS+= g_eli_hmac.c SRCS+= g_eli_integrity.c SRCS+= g_eli_key.c SRCS+= g_eli_key_cache.c From 8a9f7532b0742c8f48985f2d546795d833524bcd Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Thu, 7 Jan 2016 08:07:17 +0000 Subject: [PATCH 13/68] Convert cxgb/cxgbe to the new routing API. Discussed with: np --- sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c | 37 ++++++++++------------ sys/dev/cxgb/ulp/tom/cxgb_listen.c | 17 ++++------- sys/dev/cxgbe/iw_cxgbe/cm.c | 41 ++++++++++++------------- sys/dev/cxgbe/tom/t4_listen.c | 44 +++++++++++++-------------- 4 files changed, 64 insertions(+), 75 deletions(-) diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c index 7b435607df0c..b98caaedf21f 100644 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c +++ b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -264,20 +265,14 @@ void __free_ep(struct iwch_ep_common *epc) free(epc, M_DEVBUF); } -static struct rtentry * +static int find_route(__be32 local_ip, __be32 peer_ip, __be16 local_port, - __be16 peer_port, u8 tos) + __be16 peer_port, u8 tos, struct nhop4_extended *pnh4) { - struct route iproute; - struct sockaddr_in *dst = (struct sockaddr_in *)&iproute.ro_dst; - - bzero(&iproute, sizeof iproute); - dst->sin_family = AF_INET; - dst->sin_len = sizeof *dst; - dst->sin_addr.s_addr = peer_ip; - - rtalloc(&iproute); - return iproute.ro_rt; + struct in_addr addr; + + addr.s_addr = peer_ip; + return (fib4_lookup_nh_ext(RT_DEFAULT_FIB, addr, NHR_REF, 0, pnh4)); } static void @@ -1293,7 +1288,7 @@ iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) int err = 0; struct iwch_dev *h = to_iwch_dev(cm_id->device); struct iwch_ep *ep; - struct rtentry *rt; + struct nhop4_extended nh4; struct toedev *tdev; if (is_loopback_dst(cm_id)) { @@ -1329,28 +1324,28 @@ iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) goto fail2; /* find a route */ - rt = find_route(cm_id->local_addr.sin_addr.s_addr, + err = find_route(cm_id->local_addr.sin_addr.s_addr, cm_id->remote_addr.sin_addr.s_addr, cm_id->local_addr.sin_port, - cm_id->remote_addr.sin_port, IPTOS_LOWDELAY); - if (!rt) { + cm_id->remote_addr.sin_port, IPTOS_LOWDELAY, &nh4); + if (err) { printf("%s - cannot find route.\n", __FUNCTION__); err = EHOSTUNREACH; goto fail2; } - if (!(rt->rt_ifp->if_flags & IFCAP_TOE)) { + if (!(nh4.nh_ifp->if_flags & IFCAP_TOE)) { printf("%s - interface not TOE capable.\n", __FUNCTION__); - RTFREE(rt); + fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); goto fail2; } - tdev = TOEDEV(rt->rt_ifp); + tdev = TOEDEV(nh4.nh_ifp); if (tdev == NULL) { printf("%s - No toedev for interface.\n", __FUNCTION__); - RTFREE(rt); + fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); goto fail2; } - RTFREE(rt); + fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); state_set(&ep->com, CONNECTING); ep->com.local_addr = cm_id->local_addr; diff --git a/sys/dev/cxgb/ulp/tom/cxgb_listen.c b/sys/dev/cxgb/ulp/tom/cxgb_listen.c index 933a83c2aaa7..b7d69df6cd21 100644 --- a/sys/dev/cxgb/ulp/tom/cxgb_listen.c +++ b/sys/dev/cxgb/ulp/tom/cxgb_listen.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -480,8 +481,8 @@ do_pass_accept_req(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) unsigned int tid = GET_TID(req); struct listen_ctx *lctx = lookup_stid(&td->tid_maps, stid); struct l2t_entry *e = NULL; + struct nhop4_basic nh4; struct sockaddr_in nam; - struct rtentry *rt; struct inpcb *inp; struct socket *so; struct port_info *pi; @@ -525,18 +526,12 @@ do_pass_accept_req(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) nam.sin_len = sizeof(nam); nam.sin_family = AF_INET; nam.sin_addr = inc.inc_faddr; - rt = rtalloc1((struct sockaddr *)&nam, 0, 0); - if (rt == NULL) + if (fib4_lookup_nh_basic(RT_DEFAULT_FIB, nam.sin_addr, 0, 0, &nh4) != 0) REJECT_PASS_ACCEPT(); else { - struct sockaddr *nexthop; - - RT_UNLOCK(rt); - nexthop = rt->rt_flags & RTF_GATEWAY ? rt->rt_gateway : - (struct sockaddr *)&nam; - if (rt->rt_ifp == ifp) - e = t3_l2t_get(pi, rt->rt_ifp, nexthop); - RTFREE(rt); + nam.sin_addr = nh4.nh_addr; + if (nh4.nh_ifp == ifp) + e = t3_l2t_get(pi, ifp, (struct sockaddr *)&nam); if (e == NULL) REJECT_PASS_ACCEPT(); /* no l2te, or ifp mismatch */ } diff --git a/sys/dev/cxgbe/iw_cxgbe/cm.c b/sys/dev/cxgbe/iw_cxgbe/cm.c index cb4be71e5615..8af7df5f4ebd 100644 --- a/sys/dev/cxgbe/iw_cxgbe/cm.c +++ b/sys/dev/cxgbe/iw_cxgbe/cm.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -86,8 +87,8 @@ static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state tostate); static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state tostate); static void *alloc_ep(int size, gfp_t flags); void __free_ep(struct c4iw_ep_common *epc); -static struct rtentry * find_route(__be32 local_ip, __be32 peer_ip, __be16 local_port, - __be16 peer_port, u8 tos); +static int find_route(__be32 local_ip, __be32 peer_ip, __be16 local_port, + __be16 peer_port, u8 tos, struct nhop4_extended *pnh4); static int close_socket(struct c4iw_ep_common *epc, int close); static int shutdown_socket(struct c4iw_ep_common *epc); static void abort_socket(struct c4iw_ep *ep); @@ -201,23 +202,21 @@ set_tcpinfo(struct c4iw_ep *ep) } -static struct rtentry * +static int find_route(__be32 local_ip, __be32 peer_ip, __be16 local_port, - __be16 peer_port, u8 tos) + __be16 peer_port, u8 tos, struct nhop4_extended *pnh4) { - struct route iproute; - struct sockaddr_in *dst = (struct sockaddr_in *)&iproute.ro_dst; + struct in_addr addr; + int err; CTR5(KTR_IW_CXGBE, "%s:frtB %x, %x, %d, %d", __func__, local_ip, peer_ip, ntohs(local_port), ntohs(peer_port)); - bzero(&iproute, sizeof iproute); - dst->sin_family = AF_INET; - dst->sin_len = sizeof *dst; - dst->sin_addr.s_addr = peer_ip; - rtalloc(&iproute); - CTR2(KTR_IW_CXGBE, "%s:frtE %p", __func__, (uint64_t)iproute.ro_rt); - return iproute.ro_rt; + addr.s_addr = peer_ip; + err = fib4_lookup_nh_ext(RT_DEFAULT_FIB, addr, NHR_REF, 0, pnh4); + + CTR2(KTR_IW_CXGBE, "%s:frtE %d", __func__, err); + return err; } static int @@ -2012,7 +2011,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) int err = 0; struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); struct c4iw_ep *ep = NULL; - struct rtentry *rt; + struct nhop4_extended nh4; struct toedev *tdev; CTR2(KTR_IW_CXGBE, "%s:ccB %p", __func__, cm_id); @@ -2068,13 +2067,13 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) init_sock(&ep->com); /* find a route */ - rt = find_route( + err = find_route( cm_id->local_addr.sin_addr.s_addr, cm_id->remote_addr.sin_addr.s_addr, cm_id->local_addr.sin_port, - cm_id->remote_addr.sin_port, 0); + cm_id->remote_addr.sin_port, 0, &nh4); - if (!rt) { + if (err) { CTR2(KTR_IW_CXGBE, "%s:cc7 %p", __func__, ep); printk(KERN_ERR MOD "%s - cannot find route.\n", __func__); @@ -2082,7 +2081,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) goto fail2; } - if (!(rt->rt_ifp->if_capenable & IFCAP_TOE)) { + if (!(nh4.nh_ifp->if_capenable & IFCAP_TOE)) { CTR2(KTR_IW_CXGBE, "%s:cc8 %p", __func__, ep); printf("%s - interface not TOE capable.\n", __func__); @@ -2090,7 +2089,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) err = -ENOPROTOOPT; goto fail3; } - tdev = TOEDEV(rt->rt_ifp); + tdev = TOEDEV(nh4.nh_ifp); if (tdev == NULL) { @@ -2098,7 +2097,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) printf("%s - No toedev for interface.\n", __func__); goto fail3; } - RTFREE(rt); + fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); state_set(&ep->com, CONNECTING); ep->tos = 0; @@ -2117,7 +2116,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) fail3: CTR2(KTR_IW_CXGBE, "%s:ccb %p", __func__, ep); - RTFREE(rt); + fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); fail2: cm_id->rem_ref(cm_id); c4iw_put_ep(&ep->com); diff --git a/sys/dev/cxgbe/tom/t4_listen.c b/sys/dev/cxgbe/tom/t4_listen.c index 187a9f879f22..5af9260371f8 100644 --- a/sys/dev/cxgbe/tom/t4_listen.c +++ b/sys/dev/cxgbe/tom/t4_listen.c @@ -49,9 +49,11 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include +#include #include #include #include @@ -1095,46 +1097,44 @@ static struct l2t_entry * get_l2te_for_nexthop(struct port_info *pi, struct ifnet *ifp, struct in_conninfo *inc) { - struct rtentry *rt; struct l2t_entry *e; struct sockaddr_in6 sin6; struct sockaddr *dst = (void *)&sin6; if (inc->inc_flags & INC_ISIPV6) { + struct nhop6_basic nh6; + + bzero(dst, sizeof(struct sockaddr_in6)); dst->sa_len = sizeof(struct sockaddr_in6); dst->sa_family = AF_INET6; - ((struct sockaddr_in6 *)dst)->sin6_addr = inc->inc6_faddr; if (IN6_IS_ADDR_LINKLOCAL(&inc->inc6_laddr)) { /* no need for route lookup */ e = t4_l2t_get(pi, ifp, dst); return (e); } + + if (fib6_lookup_nh_basic(RT_DEFAULT_FIB, &inc->inc6_faddr, + 0, 0, 0, &nh6) != 0) + return (NULL); + if (nh6.nh_ifp != ifp) + return (NULL); + ((struct sockaddr_in6 *)dst)->sin6_addr = nh6.nh_addr; } else { + struct nhop4_basic nh4; + dst->sa_len = sizeof(struct sockaddr_in); dst->sa_family = AF_INET; - ((struct sockaddr_in *)dst)->sin_addr = inc->inc_faddr; - } - - rt = rtalloc1(dst, 0, 0); - if (rt == NULL) - return (NULL); - else { - struct sockaddr *nexthop; - - RT_UNLOCK(rt); - if (rt->rt_ifp != ifp) - e = NULL; - else { - if (rt->rt_flags & RTF_GATEWAY) - nexthop = rt->rt_gateway; - else - nexthop = dst; - e = t4_l2t_get(pi, ifp, nexthop); - } - RTFREE(rt); + + if (fib4_lookup_nh_basic(RT_DEFAULT_FIB, inc->inc_faddr, 0, 0, + &nh4) != 0) + return (NULL); + if (nh4.nh_ifp != ifp) + return (NULL); + ((struct sockaddr_in *)dst)->sin_addr = nh4.nh_addr; } + e = t4_l2t_get(pi, ifp, dst); return (e); } From b9320e2a6a17b3d22b107fb0b968f94952ff33b3 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Thu, 7 Jan 2016 09:40:19 +0000 Subject: [PATCH 14/68] Remove unused file. --- sys/ofed/include/rdma/Kbuild | 1 - 1 file changed, 1 deletion(-) delete mode 100644 sys/ofed/include/rdma/Kbuild diff --git a/sys/ofed/include/rdma/Kbuild b/sys/ofed/include/rdma/Kbuild deleted file mode 100644 index e7c043216558..000000000000 --- a/sys/ofed/include/rdma/Kbuild +++ /dev/null @@ -1 +0,0 @@ -header-y += ib_user_mad.h From 460a5b502f0f3cac5f48f1328144fdedca6dd415 Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Thu, 7 Jan 2016 10:20:03 +0000 Subject: [PATCH 15/68] Convert pf(4) to the new routing API. Differential Revision: https://reviews.freebsd.org/D4763 --- sys/netpfil/pf/pf.c | 131 ++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 42 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 57e78e8498d6..1b7715309ba7 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -94,6 +95,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #endif /* INET6 */ #include @@ -2985,49 +2988,35 @@ static u_int16_t pf_calc_mss(struct pf_addr *addr, sa_family_t af, int rtableid, u_int16_t offer) { #ifdef INET - struct sockaddr_in *dst; - struct route ro; + struct nhop4_basic nh4; #endif /* INET */ #ifdef INET6 - struct sockaddr_in6 *dst6; - struct route_in6 ro6; + struct nhop6_basic nh6; + struct in6_addr dst6; + uint32_t scopeid; #endif /* INET6 */ - struct rtentry *rt = NULL; int hlen = 0; - u_int16_t mss = V_tcp_mssdflt; + uint16_t mss = 0; switch (af) { #ifdef INET case AF_INET: hlen = sizeof(struct ip); - bzero(&ro, sizeof(ro)); - dst = (struct sockaddr_in *)&ro.ro_dst; - dst->sin_family = AF_INET; - dst->sin_len = sizeof(*dst); - dst->sin_addr = addr->v4; - in_rtalloc_ign(&ro, 0, rtableid); - rt = ro.ro_rt; + if (fib4_lookup_nh_basic(rtableid, addr->v4, 0, 0, &nh4) == 0) + mss = nh4.nh_mtu - hlen - sizeof(struct tcphdr); break; #endif /* INET */ #ifdef INET6 case AF_INET6: hlen = sizeof(struct ip6_hdr); - bzero(&ro6, sizeof(ro6)); - dst6 = (struct sockaddr_in6 *)&ro6.ro_dst; - dst6->sin6_family = AF_INET6; - dst6->sin6_len = sizeof(*dst6); - dst6->sin6_addr = addr->v6; - in6_rtalloc_ign(&ro6, 0, rtableid); - rt = ro6.ro_rt; + in6_splitscope(&addr->v6, &dst6, &scopeid); + if (fib6_lookup_nh_basic(rtableid, &dst6, scopeid, 0,0,&nh6)==0) + mss = nh6.nh_mtu - hlen - sizeof(struct tcphdr); break; #endif /* INET6 */ } - if (rt && rt->rt_ifp) { - mss = rt->rt_ifp->if_mtu - hlen - sizeof(struct tcphdr); - mss = max(V_tcp_mssdflt, mss); - RTFREE(rt); - } + mss = max(V_tcp_mssdflt, mss); mss = min(mss, offer); mss = max(mss, 64); /* sanity - at least max opt space */ return (mss); @@ -5194,13 +5183,12 @@ pf_pull_hdr(struct mbuf *m, int off, void *p, int len, return (p); } -int -pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif, +#ifdef RADIX_MPATH +static int +pf_routable_oldmpath(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif, int rtableid) { -#ifdef RADIX_MPATH struct radix_node_head *rnh; -#endif struct sockaddr_in *dst; int ret = 1; int check_mpath; @@ -5215,12 +5203,10 @@ pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif, struct ifnet *ifp; check_mpath = 0; -#ifdef RADIX_MPATH /* XXX: stick to table 0 for now */ rnh = rt_tables_get_rnh(0, af); if (rnh != NULL && rn_mpath_capable(rnh)) check_mpath = 1; -#endif bzero(&ro, sizeof(ro)); switch (af) { case AF_INET: @@ -5283,9 +5269,7 @@ pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif, if (kif->pfik_ifp == ifp) ret = 1; -#ifdef RADIX_MPATH rn = rn_mpath_next(rn); -#endif } while (check_mpath == 1 && rn != NULL && ret == 0); } else ret = 0; @@ -5294,6 +5278,72 @@ pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif, RTFREE(ro.ro_rt); return (ret); } +#endif + +int +pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif, + int rtableid) +{ +#ifdef INET + struct nhop4_basic nh4; +#endif +#ifdef INET6 + struct nhop6_basic nh6; +#endif + struct ifnet *ifp; +#ifdef RADIX_MPATH + struct radix_node_head *rnh; + + /* XXX: stick to table 0 for now */ + rnh = rt_tables_get_rnh(0, af); + if (rnh != NULL && rn_mpath_capable(rnh)) + return (pf_routable_oldmpath(addr, af, kif, rtableid)); +#endif + /* + * Skip check for addresses with embedded interface scope, + * as they would always match anyway. + */ + if (af == AF_INET6 && IN6_IS_SCOPE_EMBED(&addr->v6)) + return (1); + + if (af != AF_INET && af != AF_INET6) + return (0); + + /* Skip checks for ipsec interfaces */ + if (kif != NULL && kif->pfik_ifp->if_type == IFT_ENC) + return (1); + + ifp = NULL; + + switch (af) { +#ifdef INET6 + case AF_INET6: + if (fib6_lookup_nh_basic(rtableid, &addr->v6, 0, 0, 0, &nh6)!=0) + return (0); + ifp = nh6.nh_ifp; + break; +#endif +#ifdef INET + case AF_INET: + if (fib4_lookup_nh_basic(rtableid, addr->v4, 0, 0, &nh4) != 0) + return (0); + ifp = nh4.nh_ifp; + break; +#endif + } + + /* No interface given, this is a no-route check */ + if (kif == NULL) + return (1); + + if (kif->pfik_ifp == NULL) + return (0); + + /* Perform uRPF check if passed input interface */ + if (kif->pfik_ifp == ifp) + return (1); + return (0); +} #ifdef INET static void @@ -5344,23 +5394,20 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, dst.sin_addr = ip->ip_dst; if (r->rt == PF_FASTROUTE) { - struct rtentry *rt; + struct nhop4_basic nh4; if (s) PF_STATE_UNLOCK(s); - rt = rtalloc1_fib(sintosa(&dst), 0, 0, M_GETFIB(m0)); - if (rt == NULL) { + + if (fib4_lookup_nh_basic(M_GETFIB(m0), ip->ip_dst, 0, + m0->m_pkthdr.flowid, &nh4) != 0) { KMOD_IPSTAT_INC(ips_noroute); error = EHOSTUNREACH; goto bad; } - ifp = rt->rt_ifp; - counter_u64_add(rt->rt_pksent, 1); - - if (rt->rt_flags & RTF_GATEWAY) - bcopy(satosin(rt->rt_gateway), &dst, sizeof(dst)); - RTFREE_LOCKED(rt); + ifp = nh4.nh_ifp; + dst.sin_addr = nh4.nh_addr; } else { if (TAILQ_EMPTY(&r->rpool.list)) { DPFPRINTF(PF_DEBUG_URGENT, From 3aefe8928aaa4b3d670344de6b2e77fc958254c7 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Thu, 7 Jan 2016 10:39:13 +0000 Subject: [PATCH 16/68] Make cap_mkdb and services_mkdb file operations sync Similar fix was done for passwd and group operations in r285050. When a temporary file is created and then renamed to replace official file there are no checks to make sure data was written to disk and if a power cycle happens at this time, system can end up with a 0 length file Approved by: bapt MFC after: 1 week Sponsored by: Netgate Differential Revision: https://reviews.freebsd.org/D2982 --- usr.bin/cap_mkdb/cap_mkdb.c | 2 +- usr.sbin/services_mkdb/services_mkdb.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/usr.bin/cap_mkdb/cap_mkdb.c b/usr.bin/cap_mkdb/cap_mkdb.c index 2f8bd96f16af..bbcedd5a8d54 100644 --- a/usr.bin/cap_mkdb/cap_mkdb.c +++ b/usr.bin/cap_mkdb/cap_mkdb.c @@ -119,7 +119,7 @@ main(int argc, char *argv[]) (void)snprintf(buf, sizeof(buf), "%s.db", capname ? capname : *argv); if ((capname = strdup(buf)) == NULL) errx(1, "strdup failed"); - if ((capdbp = dbopen(capname, O_CREAT | O_TRUNC | O_RDWR, + if ((capdbp = dbopen(capname, O_CREAT | O_TRUNC | O_RDWR | O_SYNC, DEFFILEMODE, DB_HASH, &openinfo)) == NULL) err(1, "%s", buf); diff --git a/usr.sbin/services_mkdb/services_mkdb.c b/usr.sbin/services_mkdb/services_mkdb.c index a91340e7d7d2..9ea66deed689 100644 --- a/usr.sbin/services_mkdb/services_mkdb.c +++ b/usr.sbin/services_mkdb/services_mkdb.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -91,6 +92,8 @@ main(int argc, char *argv[]) size_t cnt = 0; StringList *sl, ***svc; size_t port, proto; + char *dbname_dir; + int dbname_dir_fd = -1; setprogname(argv[0]); @@ -138,7 +141,7 @@ main(int argc, char *argv[]) err(1, "Cannot install exit handler"); (void)snprintf(tname, sizeof(tname), "%s.tmp", dbname); - db = dbopen(tname, O_RDWR | O_CREAT | O_EXCL, + db = dbopen(tname, O_RDWR | O_CREAT | O_EXCL | O_SYNC, (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), DB_HASH, &hinfo); if (!db) err(1, "Error opening temporary database `%s'", tname); @@ -164,8 +167,21 @@ main(int argc, char *argv[]) if ((db->close)(db)) err(1, "Error closing temporary database `%s'", tname); - if (rename(tname, dbname) == -1) + /* + * Make sure file is safe on disk. To improve performance we will call + * fsync() to the directory where file lies + */ + if (rename(tname, dbname) == -1 || + (dbname_dir = dirname(dbname)) == NULL || + (dbname_dir_fd = open(dbname_dir, O_RDONLY|O_DIRECTORY)) == -1 || + fsync(dbname_dir_fd) != 0) { + if (dbname_dir_fd != -1) + close(dbname_dir_fd); err(1, "Cannot rename `%s' to `%s'", tname, dbname); + } + + if (dbname_dir_fd != -1) + close(dbname_dir_fd); return 0; } From 49b375e74b9813477d95292cd321dde141cfe1c3 Mon Sep 17 00:00:00 2001 From: "Jonathan T. Looney" Date: Thu, 7 Jan 2016 11:54:20 +0000 Subject: [PATCH 17/68] Apply the changes from r293284 to one additional file. Discussed with: glebius --- sys/netinet/tcp_stacks/fastpath.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sys/netinet/tcp_stacks/fastpath.c b/sys/netinet/tcp_stacks/fastpath.c index 85b24f67c7a3..a49f85bbaa06 100644 --- a/sys/netinet/tcp_stacks/fastpath.c +++ b/sys/netinet/tcp_stacks/fastpath.c @@ -158,13 +158,11 @@ static void tcp_do_segment_fastack(struct mbuf *, struct tcphdr *, * the ack that opens up a 0-sized window. * - LRO wasn't used for this segment. We make sure by checking that the * segment size is not larger than the MSS. - * - Delayed acks are enabled or this is a half-synchronized T/TCP - * connection. */ #define DELAY_ACK(tp, tlen) \ ((!tcp_timer_active(tp, TT_DELACK) && \ (tp->t_flags & TF_RXWIN0SENT) == 0) && \ - (tlen <= tp->t_maxopd) && \ + (tlen <= tp->t_maxseg) && \ (V_tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN))) /* From a72d531f3563245375a44e834e184d00a207a5e1 Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Thu, 7 Jan 2016 12:22:29 +0000 Subject: [PATCH 18/68] Do not use 'struct route_in6' inside hash6_insert(). rin6 was used only as sockaddr_in6 storage. Make rtalloc1_fib() use on-stack sin6 and return rtenry directly, instead of doing useless work with 'struct route_in6'. --- sys/netgraph/netflow/netflow.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/sys/netgraph/netflow/netflow.c b/sys/netgraph/netflow/netflow.c index 9b3f7d839ce5..644d46f7a712 100644 --- a/sys/netgraph/netflow/netflow.c +++ b/sys/netgraph/netflow/netflow.c @@ -395,9 +395,8 @@ hash6_insert(priv_p priv, struct flow_hash_entry *hsh6, struct flow6_rec *r, int plen, uint8_t flags, uint8_t tcp_flags) { struct flow6_entry *fle6; - struct sockaddr_in6 *src, *dst; + struct sockaddr_in6 sin6; struct rtentry *rt; - struct route_in6 rin6; mtx_assert(&hsh6->mtx, MA_OWNED); @@ -425,16 +424,14 @@ hash6_insert(priv_p priv, struct flow_hash_entry *hsh6, struct flow6_rec *r, * fill in out_ifx, dst_mask, nexthop, and dst_as in future releases. */ if ((flags & NG_NETFLOW_CONF_NODSTLOOKUP) == 0) { - bzero(&rin6, sizeof(struct route_in6)); - dst = (struct sockaddr_in6 *)&rin6.ro_dst; - dst->sin6_len = sizeof(struct sockaddr_in6); - dst->sin6_family = AF_INET6; - dst->sin6_addr = r->dst.r_dst6; + bzero(&sin6, sizeof(struct sockaddr_in6)); + sin6.sin6_len = sizeof(struct sockaddr_in6); + sin6.sin6_family = AF_INET6; + sin6.sin6_addr = r->dst.r_dst6; - rin6.ro_rt = rtalloc1_fib((struct sockaddr *)dst, 0, 0, r->fib); + rt = rtalloc1_fib((struct sockaddr *)&sin6, 0, 0, r->fib); - if (rin6.ro_rt != NULL) { - rt = rin6.ro_rt; + if (rt != NULL) { fle6->f.fle_o_ifx = rt->rt_ifp->if_index; if (rt->rt_flags & RTF_GATEWAY && @@ -453,17 +450,14 @@ hash6_insert(priv_p priv, struct flow_hash_entry *hsh6, struct flow6_rec *r, if ((flags & NG_NETFLOW_CONF_NOSRCLOOKUP) == 0) { /* Do route lookup on source address, to fill in src_mask. */ - bzero(&rin6, sizeof(struct route_in6)); - src = (struct sockaddr_in6 *)&rin6.ro_dst; - src->sin6_len = sizeof(struct sockaddr_in6); - src->sin6_family = AF_INET6; - src->sin6_addr = r->src.r_src6; + bzero(&sin6, sizeof(struct sockaddr_in6)); + sin6.sin6_len = sizeof(struct sockaddr_in6); + sin6.sin6_family = AF_INET6; + sin6.sin6_addr = r->src.r_src6; - rin6.ro_rt = rtalloc1_fib((struct sockaddr *)src, 0, 0, r->fib); - - if (rin6.ro_rt != NULL) { - rt = rin6.ro_rt; + rt = rtalloc1_fib((struct sockaddr *)&sin6, 0, 0, r->fib); + if (rt != NULL) { if (rt_mask(rt)) fle6->f.src_mask = RT_MASK6(rt); else From 514ba65500d01b433c2faa6d7132af4804eb0865 Mon Sep 17 00:00:00 2001 From: Svatopluk Kraus Date: Thu, 7 Jan 2016 12:31:49 +0000 Subject: [PATCH 19/68] Print curpmap in "show pcpu" command. Approved by: kib (mentor) --- sys/arm/arm/db_interface.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/arm/arm/db_interface.c b/sys/arm/arm/db_interface.c index 25d1706c8ff1..43831462d896 100644 --- a/sys/arm/arm/db_interface.c +++ b/sys/arm/arm/db_interface.c @@ -152,6 +152,10 @@ int db_frame(struct db_variable *vp, db_expr_t *valp, int rw) void db_show_mdpcpu(struct pcpu *pc) { + +#if __ARM_ARCH >= 6 + db_printf("curpmap = %p\n", pc->pc_curpmap); +#endif } int db_validate_address(vm_offset_t addr) From 454f163b9fcf0e871b35e1d36874d519561f64be Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 15:55:41 +0000 Subject: [PATCH 20/68] nvd: set DISKFLAG_DIRECT_COMPLETION Submitted by: gallatin MFC after: 3 days --- sys/dev/nvd/nvd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c index f459e06b2ab4..a890686ebc6e 100644 --- a/sys/dev/nvd/nvd.c +++ b/sys/dev/nvd/nvd.c @@ -287,7 +287,7 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg) disk->d_unit = TAILQ_LAST(&disk_head, disk_list)->disk->d_unit + 1; - disk->d_flags = 0; + disk->d_flags = DISKFLAG_DIRECT_COMPLETION; if (nvme_ns_get_flags(ns) & NVME_NS_DEALLOCATE_SUPPORTED) disk->d_flags |= DISKFLAG_CANDELETE; From 8fe5c0d2867653bb073062361cd954a64798167b Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 15:57:17 +0000 Subject: [PATCH 21/68] nvd: do not wait for previous bios before submitting ordered bio Still wait until all in-flight bios (including the ordered bio) complete before processing more bios from the queue. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvd/nvd.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c index a890686ebc6e..e6d4c0cb3be1 100644 --- a/sys/dev/nvd/nvd.c +++ b/sys/dev/nvd/nvd.c @@ -204,19 +204,6 @@ nvd_bioq_process(void *arg, int pending) if (bp == NULL) break; -#ifdef BIO_ORDERED - /* - * BIO_ORDERED flag dictates that all outstanding bios - * must be completed before processing the bio with - * BIO_ORDERED flag set. - */ - if (bp->bio_flags & BIO_ORDERED) { - while (ndisk->cur_depth > 0) { - pause("nvd flush", 1); - } - } -#endif - bp->bio_driver1 = NULL; atomic_add_int(&ndisk->cur_depth, 1); From 26ca317aef1ba366f08136da9342e99e525383fa Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 15:58:44 +0000 Subject: [PATCH 22/68] nvd: skip BIO_ORDERED logic when bio fails submission This ensures the bio flags are not read after biodone(). The ordering will still be enforced, after the bio is submitted successfully. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvd/nvd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c index e6d4c0cb3be1..7d78a8ca52c7 100644 --- a/sys/dev/nvd/nvd.c +++ b/sys/dev/nvd/nvd.c @@ -215,6 +215,7 @@ nvd_bioq_process(void *arg, int pending) bp->bio_flags |= BIO_ERROR; bp->bio_resid = bp->bio_bcount; biodone(bp); + continue; } #ifdef BIO_ORDERED From 47ef4244f580eb12dc49a8aa7ef3d581b66c4219 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 15:59:51 +0000 Subject: [PATCH 23/68] nvd: break out submission logic into separate function This enables a future patch using this same logic to submit I/O directly bypassing the taskqueue. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvd/nvd.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c index 7d78a8ca52c7..710b04bd7ddc 100644 --- a/sys/dev/nvd/nvd.c +++ b/sys/dev/nvd/nvd.c @@ -47,6 +47,8 @@ struct nvd_disk; static disk_ioctl_t nvd_ioctl; static disk_strategy_t nvd_strategy; +static void nvd_done(void *arg, const struct nvme_completion *cpl); + static void *nvd_new_disk(struct nvme_namespace *ns, void *ctrlr); static void destroy_geom_disk(struct nvd_disk *ndisk); @@ -148,6 +150,26 @@ nvd_unload() nvme_unregister_consumer(consumer_handle); } +static int +nvd_bio_submit(struct nvd_disk *ndisk, struct bio *bp) +{ + int err; + + bp->bio_driver1 = NULL; + atomic_add_int(&ndisk->cur_depth, 1); + err = nvme_ns_bio_process(ndisk->ns, bp, nvd_done); + if (err) { + atomic_add_int(&ndisk->cur_depth, -1); + bp->bio_error = err; + bp->bio_flags |= BIO_ERROR; + bp->bio_resid = bp->bio_bcount; + biodone(bp); + return (-1); + } + + return (0); +} + static void nvd_strategy(struct bio *bp) { @@ -195,7 +217,6 @@ nvd_bioq_process(void *arg, int pending) { struct nvd_disk *ndisk = arg; struct bio *bp; - int err; for (;;) { mtx_lock(&ndisk->bioqlock); @@ -204,17 +225,7 @@ nvd_bioq_process(void *arg, int pending) if (bp == NULL) break; - bp->bio_driver1 = NULL; - atomic_add_int(&ndisk->cur_depth, 1); - - err = nvme_ns_bio_process(ndisk->ns, bp, nvd_done); - - if (err) { - atomic_add_int(&ndisk->cur_depth, -1); - bp->bio_error = err; - bp->bio_flags |= BIO_ERROR; - bp->bio_resid = bp->bio_bcount; - biodone(bp); + if (nvd_bio_submit(ndisk, bp) != 0) { continue; } From 58d0b8f3c3e2b5441ea4c2323feccc1b9454fed6 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 16:06:23 +0000 Subject: [PATCH 24/68] nvd: submit bios directly when BIO_ORDERED not set or in flight This significantly improves parallelism in the most common case. The taskqueue is still used whenever BIO_ORDERED bios are in flight. This patch is based heavily on a patch from gallatin@. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvd/nvd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c index 710b04bd7ddc..24ee07583034 100644 --- a/sys/dev/nvd/nvd.c +++ b/sys/dev/nvd/nvd.c @@ -73,6 +73,7 @@ struct nvd_disk { struct nvme_namespace *ns; uint32_t cur_depth; + uint32_t ordered_in_flight; TAILQ_ENTRY(nvd_disk) global_tailq; TAILQ_ENTRY(nvd_disk) ctrlr_tailq; @@ -160,6 +161,8 @@ nvd_bio_submit(struct nvd_disk *ndisk, struct bio *bp) err = nvme_ns_bio_process(ndisk->ns, bp, nvd_done); if (err) { atomic_add_int(&ndisk->cur_depth, -1); + if (__predict_false(bp->bio_flags & BIO_ORDERED)) + atomic_add_int(&ndisk->ordered_in_flight, -1); bp->bio_error = err; bp->bio_flags |= BIO_ERROR; bp->bio_resid = bp->bio_bcount; @@ -177,6 +180,18 @@ nvd_strategy(struct bio *bp) ndisk = (struct nvd_disk *)bp->bio_disk->d_drv1; + if (__predict_false(bp->bio_flags & BIO_ORDERED)) + atomic_add_int(&ndisk->ordered_in_flight, 1); + + if (__predict_true(ndisk->ordered_in_flight == 0)) { + nvd_bio_submit(ndisk, bp); + return; + } + + /* + * There are ordered bios in flight, so we need to submit + * bios through the task queue to enforce ordering. + */ mtx_lock(&ndisk->bioqlock); bioq_insert_tail(&ndisk->bioq, bp); mtx_unlock(&ndisk->bioqlock); @@ -208,6 +223,8 @@ nvd_done(void *arg, const struct nvme_completion *cpl) ndisk = bp->bio_disk->d_drv1; atomic_add_int(&ndisk->cur_depth, -1); + if (__predict_false(bp->bio_flags & BIO_ORDERED)) + atomic_add_int(&ndisk->ordered_in_flight, -1); biodone(bp); } @@ -316,6 +333,7 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg) ndisk->ns = ns; ndisk->disk = disk; ndisk->cur_depth = 0; + ndisk->ordered_in_flight = 0; mtx_init(&ndisk->bioqlock, "NVD bioq lock", NULL, MTX_DEF); bioq_init(&ndisk->bioq); From d85f84abb80933c07138584631bb91283e2c0952 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 16:08:04 +0000 Subject: [PATCH 25/68] nvme: simplify some of the nested ifs in interrupt setup code This prepares for some follow-up commits which do more work in this area. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvme/nvme_ctrlr.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index ee4b901a9c75..c0117fe0442b 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -999,7 +999,9 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) if (pci_msix_count(dev) < 2) { ctrlr->msix_enabled = 0; goto intx; - } else if (pci_msix_count(dev) < num_vectors_requested) { + } + + if (pci_msix_count(dev) < num_vectors_requested) { ctrlr->per_cpu_io_queues = FALSE; ctrlr->num_io_queues = 1; num_vectors_requested = 2; /* one for admin, one for I/O */ @@ -1009,26 +1011,28 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) { ctrlr->msix_enabled = 0; goto intx; - } else if (num_vectors_allocated < num_vectors_requested) { + } + + if (num_vectors_allocated < num_vectors_requested) { if (num_vectors_allocated < 2) { pci_release_msi(dev); ctrlr->msix_enabled = 0; goto intx; - } else { - ctrlr->per_cpu_io_queues = FALSE; - ctrlr->num_io_queues = 1; - /* - * Release whatever vectors were allocated, and just - * reallocate the two needed for the admin and single - * I/O qpair. - */ - num_vectors_allocated = 2; - pci_release_msi(dev); - if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) - panic("could not reallocate any vectors\n"); - if (num_vectors_allocated != 2) - panic("could not reallocate 2 vectors\n"); } + + ctrlr->per_cpu_io_queues = FALSE; + ctrlr->num_io_queues = 1; + /* + * Release whatever vectors were allocated, and just + * reallocate the two needed for the admin and single + * I/O qpair. + */ + num_vectors_allocated = 2; + pci_release_msi(dev); + if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) + panic("could not reallocate any vectors\n"); + if (num_vectors_allocated != 2) + panic("could not reallocate 2 vectors\n"); } /* From c75ad8ce5a37c30e5a0507211c472b3b2bb20e75 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 16:09:56 +0000 Subject: [PATCH 26/68] nvme: remove per_cpu_io_queues from struct nvme_controller Instead just use num_io_queues to make this determination. This prepares for some future changes enabling use of multiple queues when we do not have enough queues or MSI-X vectors for one queue per CPU. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvme/nvme_ctrlr.c | 11 +++-------- sys/dev/nvme/nvme_private.h | 1 - 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index c0117fe0442b..d5c7373aa260 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -160,7 +160,7 @@ nvme_ctrlr_construct_io_qpairs(struct nvme_controller *ctrlr) num_trackers, ctrlr); - if (ctrlr->per_cpu_io_queues) + if (ctrlr->num_io_queues > 1) bus_bind_intr(ctrlr->dev, qpair->res, i); } @@ -402,7 +402,6 @@ nvme_ctrlr_set_num_qpairs(struct nvme_controller *ctrlr) nvme_io_qpair_destroy(&ctrlr->ioq[i]); ctrlr->num_io_queues = 1; - ctrlr->per_cpu_io_queues = 0; } return (0); @@ -779,7 +778,6 @@ nvme_ctrlr_configure_intx(struct nvme_controller *ctrlr) { ctrlr->num_io_queues = 1; - ctrlr->per_cpu_io_queues = 0; ctrlr->rid = 0; ctrlr->res = bus_alloc_resource_any(ctrlr->dev, SYS_RES_IRQ, &ctrlr->rid, RF_SHAREABLE | RF_ACTIVE); @@ -969,9 +967,8 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) per_cpu_io_queues = 1; TUNABLE_INT_FETCH("hw.nvme.per_cpu_io_queues", &per_cpu_io_queues); - ctrlr->per_cpu_io_queues = per_cpu_io_queues ? TRUE : FALSE; - if (ctrlr->per_cpu_io_queues) + if (per_cpu_io_queues) ctrlr->num_io_queues = mp_ncpus; else ctrlr->num_io_queues = 1; @@ -1002,7 +999,6 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) } if (pci_msix_count(dev) < num_vectors_requested) { - ctrlr->per_cpu_io_queues = FALSE; ctrlr->num_io_queues = 1; num_vectors_requested = 2; /* one for admin, one for I/O */ } @@ -1020,7 +1016,6 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) goto intx; } - ctrlr->per_cpu_io_queues = FALSE; ctrlr->num_io_queues = 1; /* * Release whatever vectors were allocated, and just @@ -1192,7 +1187,7 @@ nvme_ctrlr_submit_io_request(struct nvme_controller *ctrlr, { struct nvme_qpair *qpair; - if (ctrlr->per_cpu_io_queues) + if (ctrlr->num_io_queues > 1) qpair = &ctrlr->ioq[curcpu]; else qpair = &ctrlr->ioq[0]; diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h index 6137b41e6425..a6d3eff51b37 100644 --- a/sys/dev/nvme/nvme_private.h +++ b/sys/dev/nvme/nvme_private.h @@ -265,7 +265,6 @@ struct nvme_controller { uint32_t enable_aborts; uint32_t num_io_queues; - boolean_t per_cpu_io_queues; /* Fields for tracking progress during controller initialization. */ struct intr_config_hook config_hook; From e5af5854ff3b396ed514c3231463b7ef654ca0bb Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 16:11:31 +0000 Subject: [PATCH 27/68] nvme: do not pre-allocate MSI-X IRQ resources The issue referenced here was resolved by other changes in recent commits, so this code is no longer needed. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvme/nvme_ctrlr.c | 37 +------------------------------------ sys/dev/nvme/nvme_private.h | 2 -- sys/dev/nvme/nvme_qpair.c | 3 ++- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index d5c7373aa260..35ee07b2b7e4 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -929,7 +929,7 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) { union cap_lo_register cap_lo; union cap_hi_register cap_hi; - int i, per_cpu_io_queues, rid; + int per_cpu_io_queues; int num_vectors_requested, num_vectors_allocated; int status, timeout_period; @@ -1030,41 +1030,6 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) panic("could not reallocate 2 vectors\n"); } - /* - * On earlier FreeBSD releases, there are reports that - * pci_alloc_msix() can return successfully with all vectors - * requested, but a subsequent bus_alloc_resource_any() - * for one of those vectors fails. This issue occurs more - * readily with multiple devices using per-CPU vectors. - * To workaround this issue, try to allocate the resources now, - * and fall back to INTx if we cannot allocate all of them. - * This issue cannot be reproduced on more recent versions of - * FreeBSD which have increased the maximum number of MSI-X - * vectors, but adding the workaround makes it easier for - * vendors wishing to import this driver into kernels based on - * older versions of FreeBSD. - */ - for (i = 0; i < num_vectors_allocated; i++) { - rid = i + 1; - ctrlr->msi_res[i] = bus_alloc_resource_any(ctrlr->dev, - SYS_RES_IRQ, &rid, RF_ACTIVE); - - if (ctrlr->msi_res[i] == NULL) { - ctrlr->msix_enabled = 0; - while (i > 0) { - i--; - bus_release_resource(ctrlr->dev, - SYS_RES_IRQ, - rman_get_rid(ctrlr->msi_res[i]), - ctrlr->msi_res[i]); - } - pci_release_msi(dev); - nvme_printf(ctrlr, "could not obtain all MSI-X " - "resources, reverting to intx\n"); - break; - } - } - intx: if (!ctrlr->msix_enabled) diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h index a6d3eff51b37..7e049eef0adf 100644 --- a/sys/dev/nvme/nvme_private.h +++ b/sys/dev/nvme/nvme_private.h @@ -275,8 +275,6 @@ struct nvme_controller { struct task fail_req_task; struct taskqueue *taskqueue; - struct resource *msi_res[MAXCPU + 1]; - /* For shared legacy interrupt. */ int rid; struct resource *res; diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c index d0cb8c6212c7..92fe6722e4f4 100644 --- a/sys/dev/nvme/nvme_qpair.c +++ b/sys/dev/nvme/nvme_qpair.c @@ -479,8 +479,9 @@ nvme_qpair_construct(struct nvme_qpair *qpair, uint32_t id, * the queue's vector to get the corresponding rid to use. */ qpair->rid = vector + 1; - qpair->res = ctrlr->msi_res[vector]; + qpair->res = bus_alloc_resource_any(ctrlr->dev, SYS_RES_IRQ, + &qpair->rid, RF_ACTIVE); bus_setup_intr(ctrlr->dev, qpair->res, INTR_TYPE_MISC | INTR_MPSAFE, NULL, nvme_qpair_msix_handler, qpair, &qpair->tag); From d400f790b12fc5a8b945b6dfbde3b90e723a5632 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 16:12:42 +0000 Subject: [PATCH 28/68] nvme: break out interrupt setup code into a separate function MFC after: 3 days Sponsored by: Intel --- sys/dev/nvme/nvme_ctrlr.c | 133 +++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 68 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 35ee07b2b7e4..76f9fb3ec996 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); static void nvme_ctrlr_construct_and_submit_aer(struct nvme_controller *ctrlr, struct nvme_async_event_request *aer); +static void nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr); static int nvme_ctrlr_allocate_bar(struct nvme_controller *ctrlr) @@ -777,6 +778,7 @@ static int nvme_ctrlr_configure_intx(struct nvme_controller *ctrlr) { + ctrlr->msix_enabled = 0; ctrlr->num_io_queues = 1; ctrlr->rid = 0; ctrlr->res = bus_alloc_resource_any(ctrlr->dev, SYS_RES_IRQ, @@ -924,13 +926,73 @@ static struct cdevsw nvme_ctrlr_cdevsw = { .d_ioctl = nvme_ctrlr_ioctl }; +static void +nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr) +{ + device_t dev; + int per_cpu_io_queues; + int num_vectors_requested, num_vectors_allocated; + + dev = ctrlr->dev; + per_cpu_io_queues = 1; + TUNABLE_INT_FETCH("hw.nvme.per_cpu_io_queues", &per_cpu_io_queues); + + ctrlr->force_intx = 0; + TUNABLE_INT_FETCH("hw.nvme.force_intx", &ctrlr->force_intx); + + if (ctrlr->force_intx || pci_msix_count(dev) < 2) { + nvme_ctrlr_configure_intx(ctrlr); + return; + } + + ctrlr->msix_enabled = 1; + + if (per_cpu_io_queues) + ctrlr->num_io_queues = mp_ncpus; + else + ctrlr->num_io_queues = 1; + + /* One vector per IO queue, plus one vector for admin queue. */ + num_vectors_requested = ctrlr->num_io_queues + 1; + + if (pci_msix_count(dev) < num_vectors_requested) { + ctrlr->num_io_queues = 1; + num_vectors_requested = 2; /* one for admin, one for I/O */ + } + + num_vectors_allocated = num_vectors_requested; + if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) { + nvme_ctrlr_configure_intx(ctrlr); + return; + } + + if (num_vectors_allocated < num_vectors_requested) { + if (num_vectors_allocated < 2) { + pci_release_msi(dev); + nvme_ctrlr_configure_intx(ctrlr); + return; + } + + ctrlr->num_io_queues = 1; + /* + * Release whatever vectors were allocated, and just + * reallocate the two needed for the admin and single + * I/O qpair. + */ + num_vectors_allocated = 2; + pci_release_msi(dev); + if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) + panic("could not reallocate any vectors\n"); + if (num_vectors_allocated != 2) + panic("could not reallocate 2 vectors\n"); + } +} + int nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) { union cap_lo_register cap_lo; union cap_hi_register cap_hi; - int per_cpu_io_queues; - int num_vectors_requested, num_vectors_allocated; int status, timeout_period; ctrlr->dev = dev; @@ -965,75 +1027,10 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) nvme_retry_count = NVME_DEFAULT_RETRY_COUNT; TUNABLE_INT_FETCH("hw.nvme.retry_count", &nvme_retry_count); - per_cpu_io_queues = 1; - TUNABLE_INT_FETCH("hw.nvme.per_cpu_io_queues", &per_cpu_io_queues); - - if (per_cpu_io_queues) - ctrlr->num_io_queues = mp_ncpus; - else - ctrlr->num_io_queues = 1; - - ctrlr->force_intx = 0; - TUNABLE_INT_FETCH("hw.nvme.force_intx", &ctrlr->force_intx); - ctrlr->enable_aborts = 0; TUNABLE_INT_FETCH("hw.nvme.enable_aborts", &ctrlr->enable_aborts); - ctrlr->msix_enabled = 1; - - if (ctrlr->force_intx) { - ctrlr->msix_enabled = 0; - goto intx; - } - - /* One vector per IO queue, plus one vector for admin queue. */ - num_vectors_requested = ctrlr->num_io_queues + 1; - - /* - * If we cannot even allocate 2 vectors (one for admin, one for - * I/O), then revert to INTx. - */ - if (pci_msix_count(dev) < 2) { - ctrlr->msix_enabled = 0; - goto intx; - } - - if (pci_msix_count(dev) < num_vectors_requested) { - ctrlr->num_io_queues = 1; - num_vectors_requested = 2; /* one for admin, one for I/O */ - } - - num_vectors_allocated = num_vectors_requested; - if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) { - ctrlr->msix_enabled = 0; - goto intx; - } - - if (num_vectors_allocated < num_vectors_requested) { - if (num_vectors_allocated < 2) { - pci_release_msi(dev); - ctrlr->msix_enabled = 0; - goto intx; - } - - ctrlr->num_io_queues = 1; - /* - * Release whatever vectors were allocated, and just - * reallocate the two needed for the admin and single - * I/O qpair. - */ - num_vectors_allocated = 2; - pci_release_msi(dev); - if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) - panic("could not reallocate any vectors\n"); - if (num_vectors_allocated != 2) - panic("could not reallocate 2 vectors\n"); - } - -intx: - - if (!ctrlr->msix_enabled) - nvme_ctrlr_configure_intx(ctrlr); + nvme_ctrlr_setup_interrupts(ctrlr); ctrlr->max_xfer_size = NVME_MAX_XFER_SIZE; nvme_ctrlr_construct_admin_qpair(ctrlr); From 2b647da7a0e7239bff2b30bda457bda3dd82a691 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 16:18:32 +0000 Subject: [PATCH 29/68] nvme: do not revert o single I/O queue when per-CPU queues not possible Previously nvme(4) would revert to a signle I/O queue if it could not allocate enought interrupt vectors or NVMe submission/completion queues to have one I/O queue per core. This patch determines how to utilize a smaller number of available interrupt vectors, and assigns (as closely as possible) an equal number of cores to each associated I/O queue. MFC after: 3 days Sponsored by: Intel --- sys/dev/nvme/nvme.c | 2 - sys/dev/nvme/nvme_ctrlr.c | 167 +++++++++++++++++++++++------------- sys/dev/nvme/nvme_private.h | 1 + 3 files changed, 106 insertions(+), 64 deletions(-) diff --git a/sys/dev/nvme/nvme.c b/sys/dev/nvme/nvme.c index cc14d34afbc4..9db2b14d13d0 100644 --- a/sys/dev/nvme/nvme.c +++ b/sys/dev/nvme/nvme.c @@ -270,8 +270,6 @@ nvme_attach(device_t dev) return (status); } - nvme_sysctl_initialize_ctrlr(ctrlr); - pci_enable_busmaster(dev); ctrlr->config_hook.ich_func = nvme_ctrlr_start_config_hook; diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 76f9fb3ec996..151f02542626 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -42,6 +42,12 @@ __FBSDID("$FreeBSD$"); #include "nvme_private.h" +/* + * Used for calculating number of CPUs to assign to each core and number of I/O + * queues to allocate per controller. + */ +#define NVME_CEILING(num, div) ((((num) - 1) / (div)) + 1) + static void nvme_ctrlr_construct_and_submit_aer(struct nvme_controller *ctrlr, struct nvme_async_event_request *aer); static void nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr); @@ -141,6 +147,13 @@ nvme_ctrlr_construct_io_qpairs(struct nvme_controller *ctrlr) */ num_trackers = min(num_trackers, (num_entries-1)); + /* + * This was calculated previously when setting up interrupts, but + * a controller could theoretically support fewer I/O queues than + * MSI-X vectors. So calculate again here just to be safe. + */ + ctrlr->num_cpus_per_ioq = NVME_CEILING(mp_ncpus, ctrlr->num_io_queues); + ctrlr->ioq = malloc(ctrlr->num_io_queues * sizeof(struct nvme_qpair), M_NVME, M_ZERO | M_WAITOK); @@ -161,8 +174,13 @@ nvme_ctrlr_construct_io_qpairs(struct nvme_controller *ctrlr) num_trackers, ctrlr); + /* + * Do not bother binding interrupts if we only have one I/O + * interrupt thread for this controller. + */ if (ctrlr->num_io_queues > 1) - bus_bind_intr(ctrlr->dev, qpair->res, i); + bus_bind_intr(ctrlr->dev, qpair->res, + i * ctrlr->num_cpus_per_ioq); } return (0); @@ -307,8 +325,15 @@ nvme_ctrlr_hw_reset(struct nvme_controller *ctrlr) int i; nvme_admin_qpair_disable(&ctrlr->adminq); - for (i = 0; i < ctrlr->num_io_queues; i++) - nvme_io_qpair_disable(&ctrlr->ioq[i]); + /* + * I/O queues are not allocated before the initial HW + * reset, so do not try to disable them. Use is_initialized + * to determine if this is the initial HW reset. + */ + if (ctrlr->is_initialized) { + for (i = 0; i < ctrlr->num_io_queues; i++) + nvme_io_qpair_disable(&ctrlr->ioq[i]); + } DELAY(100*1000); @@ -364,7 +389,7 @@ static int nvme_ctrlr_set_num_qpairs(struct nvme_controller *ctrlr) { struct nvme_completion_poll_status status; - int cq_allocated, i, sq_allocated; + int cq_allocated, sq_allocated; status.done = FALSE; nvme_ctrlr_cmd_set_num_queues(ctrlr, ctrlr->num_io_queues, @@ -385,25 +410,12 @@ nvme_ctrlr_set_num_qpairs(struct nvme_controller *ctrlr) cq_allocated = (status.cpl.cdw0 >> 16) + 1; /* - * Check that the controller was able to allocate the number of - * queues we requested. If not, revert to one IO queue pair. + * Controller may allocate more queues than we requested, + * so use the minimum of the number requested and what was + * actually allocated. */ - if (sq_allocated < ctrlr->num_io_queues || - cq_allocated < ctrlr->num_io_queues) { - - /* - * Destroy extra IO queue pairs that were created at - * controller construction time but are no longer - * needed. This will only happen when a controller - * supports fewer queues than MSI-X vectors. This - * is not the normal case, but does occur with the - * Chatham prototype board. - */ - for (i = 1; i < ctrlr->num_io_queues; i++) - nvme_io_qpair_destroy(&ctrlr->ioq[i]); - - ctrlr->num_io_queues = 1; - } + ctrlr->num_io_queues = min(ctrlr->num_io_queues, sq_allocated); + ctrlr->num_io_queues = min(ctrlr->num_io_queues, cq_allocated); return (0); } @@ -687,9 +699,20 @@ static void nvme_ctrlr_start(void *ctrlr_arg) { struct nvme_controller *ctrlr = ctrlr_arg; + uint32_t old_num_io_queues; int i; - nvme_qpair_reset(&ctrlr->adminq); + /* + * Only reset adminq here when we are restarting the + * controller after a reset. During initialization, + * we have already submitted admin commands to get + * the number of I/O queues supported, so cannot reset + * the adminq again here. + */ + if (ctrlr->is_resetting) { + nvme_qpair_reset(&ctrlr->adminq); + } + for (i = 0; i < ctrlr->num_io_queues; i++) nvme_qpair_reset(&ctrlr->ioq[i]); @@ -700,11 +723,25 @@ nvme_ctrlr_start(void *ctrlr_arg) return; } + /* + * The number of qpairs are determined during controller initialization, + * including using NVMe SET_FEATURES/NUMBER_OF_QUEUES to determine the + * HW limit. We call SET_FEATURES again here so that it gets called + * after any reset for controllers that depend on the driver to + * explicit specify how many queues it will use. This value should + * never change between resets, so panic if somehow that does happen. + */ + old_num_io_queues = ctrlr->num_io_queues; if (nvme_ctrlr_set_num_qpairs(ctrlr) != 0) { nvme_ctrlr_fail(ctrlr); return; } + if (old_num_io_queues != ctrlr->num_io_queues) { + panic("num_io_queues changed from %u to %u", old_num_io_queues, + ctrlr->num_io_queues); + } + if (nvme_ctrlr_create_qpairs(ctrlr) != 0) { nvme_ctrlr_fail(ctrlr); return; @@ -727,7 +764,16 @@ nvme_ctrlr_start_config_hook(void *arg) { struct nvme_controller *ctrlr = arg; - nvme_ctrlr_start(ctrlr); + nvme_qpair_reset(&ctrlr->adminq); + nvme_admin_qpair_enable(&ctrlr->adminq); + + if (nvme_ctrlr_set_num_qpairs(ctrlr) == 0 && + nvme_ctrlr_construct_io_qpairs(ctrlr) == 0) + nvme_ctrlr_start(ctrlr); + else + nvme_ctrlr_fail(ctrlr); + + nvme_sysctl_initialize_ctrlr(ctrlr); config_intrhook_disestablish(&ctrlr->config_hook); ctrlr->is_initialized = 1; @@ -780,6 +826,7 @@ nvme_ctrlr_configure_intx(struct nvme_controller *ctrlr) ctrlr->msix_enabled = 0; ctrlr->num_io_queues = 1; + ctrlr->num_cpus_per_ioq = mp_ncpus; ctrlr->rid = 0; ctrlr->res = bus_alloc_resource_any(ctrlr->dev, SYS_RES_IRQ, &ctrlr->rid, RF_SHAREABLE | RF_ACTIVE); @@ -932,6 +979,7 @@ nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr) device_t dev; int per_cpu_io_queues; int num_vectors_requested, num_vectors_allocated; + int num_vectors_available; dev = ctrlr->dev; per_cpu_io_queues = 1; @@ -940,52 +988,55 @@ nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr) ctrlr->force_intx = 0; TUNABLE_INT_FETCH("hw.nvme.force_intx", &ctrlr->force_intx); - if (ctrlr->force_intx || pci_msix_count(dev) < 2) { + /* + * FreeBSD currently cannot allocate more than about 190 vectors at + * boot, meaning that systems with high core count and many devices + * requesting per-CPU interrupt vectors will not get their full + * allotment. So first, try to allocate as many as we may need to + * understand what is available, then immediately release them. + * Then figure out how many of those we will actually use, based on + * assigning an equal number of cores to each I/O queue. + */ + + /* One vector for per core I/O queue, plus one vector for admin queue. */ + num_vectors_available = min(pci_msix_count(dev), mp_ncpus + 1); + if (pci_alloc_msix(dev, &num_vectors_available) != 0) { + num_vectors_available = 0; + } + pci_release_msi(dev); + + if (ctrlr->force_intx || num_vectors_available < 2) { nvme_ctrlr_configure_intx(ctrlr); return; } - ctrlr->msix_enabled = 1; - if (per_cpu_io_queues) - ctrlr->num_io_queues = mp_ncpus; + ctrlr->num_cpus_per_ioq = NVME_CEILING(mp_ncpus, num_vectors_available + 1); else - ctrlr->num_io_queues = 1; + ctrlr->num_cpus_per_ioq = mp_ncpus; - /* One vector per IO queue, plus one vector for admin queue. */ + ctrlr->num_io_queues = NVME_CEILING(mp_ncpus, ctrlr->num_cpus_per_ioq); num_vectors_requested = ctrlr->num_io_queues + 1; - - if (pci_msix_count(dev) < num_vectors_requested) { - ctrlr->num_io_queues = 1; - num_vectors_requested = 2; /* one for admin, one for I/O */ - } - num_vectors_allocated = num_vectors_requested; + + /* + * Now just allocate the number of vectors we need. This should + * succeed, since we previously called pci_alloc_msix() + * successfully returning at least this many vectors, but just to + * be safe, if something goes wrong just revert to INTx. + */ if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) { nvme_ctrlr_configure_intx(ctrlr); return; } if (num_vectors_allocated < num_vectors_requested) { - if (num_vectors_allocated < 2) { - pci_release_msi(dev); - nvme_ctrlr_configure_intx(ctrlr); - return; - } - - ctrlr->num_io_queues = 1; - /* - * Release whatever vectors were allocated, and just - * reallocate the two needed for the admin and single - * I/O qpair. - */ - num_vectors_allocated = 2; pci_release_msi(dev); - if (pci_alloc_msix(dev, &num_vectors_allocated) != 0) - panic("could not reallocate any vectors\n"); - if (num_vectors_allocated != 2) - panic("could not reallocate 2 vectors\n"); + nvme_ctrlr_configure_intx(ctrlr); + return; } + + ctrlr->msix_enabled = 1; } int @@ -1034,10 +1085,6 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) ctrlr->max_xfer_size = NVME_MAX_XFER_SIZE; nvme_ctrlr_construct_admin_qpair(ctrlr); - status = nvme_ctrlr_construct_io_qpairs(ctrlr); - - if (status != 0) - return (status); ctrlr->cdev = make_dev(&nvme_ctrlr_cdevsw, device_get_unit(dev), UID_ROOT, GID_WHEEL, 0600, "nvme%d", device_get_unit(dev)); @@ -1149,11 +1196,7 @@ nvme_ctrlr_submit_io_request(struct nvme_controller *ctrlr, { struct nvme_qpair *qpair; - if (ctrlr->num_io_queues > 1) - qpair = &ctrlr->ioq[curcpu]; - else - qpair = &ctrlr->ioq[0]; - + qpair = &ctrlr->ioq[curcpu / ctrlr->num_cpus_per_ioq]; nvme_qpair_submit_request(qpair, req); } diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h index 7e049eef0adf..33307117b5be 100644 --- a/sys/dev/nvme/nvme_private.h +++ b/sys/dev/nvme/nvme_private.h @@ -265,6 +265,7 @@ struct nvme_controller { uint32_t enable_aborts; uint32_t num_io_queues; + uint32_t num_cpus_per_ioq; /* Fields for tracking progress during controller initialization. */ struct intr_config_hook config_hook; From 712b97a63019863268edb2fe9067dc26ee1faf4a Mon Sep 17 00:00:00 2001 From: Sean Bruno Date: Thu, 7 Jan 2016 16:20:55 +0000 Subject: [PATCH 30/68] Switch em(4) to the extended RX descriptor format. This matches the e1000/e1000e split in linux. MFC after: 2 weeks Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D3447 --- sys/dev/e1000/if_em.c | 108 ++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c index d9b3ca559d6e..9fa5ee40898b 100644 --- a/sys/dev/e1000/if_em.c +++ b/sys/dev/e1000/if_em.c @@ -3733,29 +3733,38 @@ em_transmit_checksum_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, offload |= CSUM_TCP; tucss = hdr_len; tucso = hdr_len + offsetof(struct tcphdr, th_sum); - /* - * Setting up new checksum offload context for every frames - * takes a lot of processing time for hardware. This also - * reduces performance a lot for small sized frames so avoid - * it if driver can use previously configured checksum - * offload context. - */ - if (txr->last_hw_offload == offload) { - if (offload & CSUM_IP) { - if (txr->last_hw_ipcss == ipcss && - txr->last_hw_ipcso == ipcso && - txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } else { - if (txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } - } - txr->last_hw_offload = offload; - txr->last_hw_tucss = tucss; - txr->last_hw_tucso = tucso; + /* + * The 82574L can only remember the *last* context used + * regardless of queue that it was use for. We cannot reuse + * contexts on this hardware platform and must generate a new + * context every time. 82574L hardware spec, section 7.2.6, + * second note. + */ + if (adapter->num_queues < 2) { + /* + * Setting up new checksum offload context for every + * frames takes a lot of processing time for hardware. + * This also reduces performance a lot for small sized + * frames so avoid it if driver can use previously + * configured checksum offload context. + */ + if (txr->last_hw_offload == offload) { + if (offload & CSUM_IP) { + if (txr->last_hw_ipcss == ipcss && + txr->last_hw_ipcso == ipcso && + txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } else { + if (txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } + } + txr->last_hw_offload = offload; + txr->last_hw_tucss = tucss; + txr->last_hw_tucso = tucso; + } /* * Start offset for payload checksum calculation. * End offset for payload checksum calculation. @@ -3771,29 +3780,38 @@ em_transmit_checksum_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, *txd_upper |= E1000_TXD_POPTS_TXSM << 8; tucss = hdr_len; tucso = hdr_len + offsetof(struct udphdr, uh_sum); - /* - * Setting up new checksum offload context for every frames - * takes a lot of processing time for hardware. This also - * reduces performance a lot for small sized frames so avoid - * it if driver can use previously configured checksum - * offload context. - */ - if (txr->last_hw_offload == offload) { - if (offload & CSUM_IP) { - if (txr->last_hw_ipcss == ipcss && - txr->last_hw_ipcso == ipcso && - txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } else { - if (txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; + /* + * The 82574L can only remember the *last* context used + * regardless of queue that it was use for. We cannot reuse + * contexts on this hardware platform and must generate a new + * context every time. 82574L hardware spec, section 7.2.6, + * second note. + */ + if (adapter->num_queues < 2) { + /* + * Setting up new checksum offload context for every + * frames takes a lot of processing time for hardware. + * This also reduces performance a lot for small sized + * frames so avoid it if driver can use previously + * configured checksum offload context. + */ + if (txr->last_hw_offload == offload) { + if (offload & CSUM_IP) { + if (txr->last_hw_ipcss == ipcss && + txr->last_hw_ipcso == ipcso && + txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } else { + if (txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } } - } - txr->last_hw_offload = offload; - txr->last_hw_tucss = tucss; - txr->last_hw_tucso = tucso; + txr->last_hw_offload = offload; + txr->last_hw_tucss = tucss; + txr->last_hw_tucso = tucso; + } /* * Start offset for header checksum calculation. * End offset for header checksum calculation. From 8061e8bb1e379c9bbe7305423c387ea6523484bc Mon Sep 17 00:00:00 2001 From: Sean Bruno Date: Thu, 7 Jan 2016 16:24:18 +0000 Subject: [PATCH 31/68] Wow, um ... sorry about that. The commit log for this code should have read that it was for EM_MULTIQUEUE. Revert this and try again. --- sys/dev/e1000/if_em.c | 108 ++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 63 deletions(-) diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c index 9fa5ee40898b..d9b3ca559d6e 100644 --- a/sys/dev/e1000/if_em.c +++ b/sys/dev/e1000/if_em.c @@ -3733,38 +3733,29 @@ em_transmit_checksum_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, offload |= CSUM_TCP; tucss = hdr_len; tucso = hdr_len + offsetof(struct tcphdr, th_sum); - /* - * The 82574L can only remember the *last* context used - * regardless of queue that it was use for. We cannot reuse - * contexts on this hardware platform and must generate a new - * context every time. 82574L hardware spec, section 7.2.6, - * second note. - */ - if (adapter->num_queues < 2) { - /* - * Setting up new checksum offload context for every - * frames takes a lot of processing time for hardware. - * This also reduces performance a lot for small sized - * frames so avoid it if driver can use previously - * configured checksum offload context. - */ - if (txr->last_hw_offload == offload) { - if (offload & CSUM_IP) { - if (txr->last_hw_ipcss == ipcss && - txr->last_hw_ipcso == ipcso && - txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } else { - if (txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } - } - txr->last_hw_offload = offload; - txr->last_hw_tucss = tucss; - txr->last_hw_tucso = tucso; - } + /* + * Setting up new checksum offload context for every frames + * takes a lot of processing time for hardware. This also + * reduces performance a lot for small sized frames so avoid + * it if driver can use previously configured checksum + * offload context. + */ + if (txr->last_hw_offload == offload) { + if (offload & CSUM_IP) { + if (txr->last_hw_ipcss == ipcss && + txr->last_hw_ipcso == ipcso && + txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } else { + if (txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } + } + txr->last_hw_offload = offload; + txr->last_hw_tucss = tucss; + txr->last_hw_tucso = tucso; /* * Start offset for payload checksum calculation. * End offset for payload checksum calculation. @@ -3780,38 +3771,29 @@ em_transmit_checksum_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, *txd_upper |= E1000_TXD_POPTS_TXSM << 8; tucss = hdr_len; tucso = hdr_len + offsetof(struct udphdr, uh_sum); - /* - * The 82574L can only remember the *last* context used - * regardless of queue that it was use for. We cannot reuse - * contexts on this hardware platform and must generate a new - * context every time. 82574L hardware spec, section 7.2.6, - * second note. - */ - if (adapter->num_queues < 2) { - /* - * Setting up new checksum offload context for every - * frames takes a lot of processing time for hardware. - * This also reduces performance a lot for small sized - * frames so avoid it if driver can use previously - * configured checksum offload context. - */ - if (txr->last_hw_offload == offload) { - if (offload & CSUM_IP) { - if (txr->last_hw_ipcss == ipcss && - txr->last_hw_ipcso == ipcso && - txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } else { - if (txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } + /* + * Setting up new checksum offload context for every frames + * takes a lot of processing time for hardware. This also + * reduces performance a lot for small sized frames so avoid + * it if driver can use previously configured checksum + * offload context. + */ + if (txr->last_hw_offload == offload) { + if (offload & CSUM_IP) { + if (txr->last_hw_ipcss == ipcss && + txr->last_hw_ipcso == ipcso && + txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } else { + if (txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; } - txr->last_hw_offload = offload; - txr->last_hw_tucss = tucss; - txr->last_hw_tucso = tucso; - } + } + txr->last_hw_offload = offload; + txr->last_hw_tucss = tucss; + txr->last_hw_tucso = tucso; /* * Start offset for header checksum calculation. * End offset for header checksum calculation. From b834dcea9a55500a0aa8e79443a398810b3bfdbe Mon Sep 17 00:00:00 2001 From: Sean Bruno Date: Thu, 7 Jan 2016 16:42:48 +0000 Subject: [PATCH 32/68] Switch em(4) to the extended RX descriptor format. This matches the e1000/e1000e split in linux. Split rxbuffer and txbuffer apart to support the new RX descriptor format structures. Move rxbuffer manipulation to em_setup_rxdesc() to unify the new behavior changes. Add a RSSKEYLEN macro for help in generating the RSSKEY data structures in the card. Change em_receive_checksum() to process the new rxdescriptor format status bit. MFC after: 2 weeks Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D3447 --- sys/dev/e1000/if_em.c | 188 +++++++++++++++++++--------------- sys/dev/e1000/if_em.h | 20 +++- sys/dev/netmap/if_em_netmap.h | 16 +-- 3 files changed, 129 insertions(+), 95 deletions(-) diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c index d9b3ca559d6e..de53d8b9f229 100644 --- a/sys/dev/e1000/if_em.c +++ b/sys/dev/e1000/if_em.c @@ -260,7 +260,9 @@ static bool em_rxeof(struct rx_ring *, int, int *); #ifndef __NO_STRICT_ALIGNMENT static int em_fixup_rx(struct rx_ring *); #endif -static void em_receive_checksum(struct e1000_rx_desc *, struct mbuf *); +static void em_setup_rxdesc(union e1000_rx_desc_extended *, + const struct em_rxbuffer *rxbuf); +static void em_receive_checksum(uint32_t status, struct mbuf *); static void em_transmit_checksum_setup(struct tx_ring *, struct mbuf *, int, struct ip *, u32 *, u32 *); static void em_tso_setup(struct tx_ring *, struct mbuf *, int, struct ip *, @@ -631,7 +633,7 @@ em_attach(device_t dev) } else adapter->num_tx_desc = em_txd; - if (((em_rxd * sizeof(struct e1000_rx_desc)) % EM_DBA_ALIGN) != 0 || + if (((em_rxd * sizeof(union e1000_rx_desc_extended)) % EM_DBA_ALIGN) != 0 || (em_rxd > EM_MAX_RXD) || (em_rxd < EM_MIN_RXD)) { device_printf(dev, "Using %d RX descriptors instead of %d!\n", EM_DEFAULT_RXD, em_rxd); @@ -1872,7 +1874,7 @@ em_xmit(struct tx_ring *txr, struct mbuf **m_headp) struct adapter *adapter = txr->adapter; bus_dma_segment_t segs[EM_MAX_SCATTER]; bus_dmamap_t map; - struct em_buffer *tx_buffer, *tx_buffer_mapped; + struct em_txbuffer *tx_buffer, *tx_buffer_mapped; struct e1000_tx_desc *ctxd = NULL; struct mbuf *m_head; struct ether_header *eh; @@ -3296,7 +3298,7 @@ em_allocate_queues(struct adapter *adapter) * Next the RX queues... */ rsize = roundup2(adapter->num_rx_desc * - sizeof(struct e1000_rx_desc), EM_DBA_ALIGN); + sizeof(union e1000_rx_desc_extended), EM_DBA_ALIGN); for (int i = 0; i < adapter->num_queues; i++, rxconf++) { rxr = &adapter->rx_rings[i]; rxr->adapter = adapter; @@ -3314,7 +3316,7 @@ em_allocate_queues(struct adapter *adapter) error = ENOMEM; goto err_rx_desc; } - rxr->rx_base = (struct e1000_rx_desc *)rxr->rxdma.dma_vaddr; + rxr->rx_base = (union e1000_rx_desc_extended *)rxr->rxdma.dma_vaddr; bzero((void *)rxr->rx_base, rsize); /* Allocate receive buffers for the ring*/ @@ -3357,7 +3359,7 @@ em_allocate_transmit_buffers(struct tx_ring *txr) { struct adapter *adapter = txr->adapter; device_t dev = adapter->dev; - struct em_buffer *txbuf; + struct em_txbuffer *txbuf; int error, i; /* @@ -3380,7 +3382,7 @@ em_allocate_transmit_buffers(struct tx_ring *txr) } if (!(txr->tx_buffers = - (struct em_buffer *) malloc(sizeof(struct em_buffer) * + (struct em_txbuffer *) malloc(sizeof(struct em_txbuffer) * adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) { device_printf(dev, "Unable to allocate tx_buffer memory\n"); error = ENOMEM; @@ -3413,7 +3415,7 @@ static void em_setup_transmit_ring(struct tx_ring *txr) { struct adapter *adapter = txr->adapter; - struct em_buffer *txbuf; + struct em_txbuffer *txbuf; int i; #ifdef DEV_NETMAP struct netmap_slot *slot; @@ -3632,7 +3634,7 @@ static void em_free_transmit_buffers(struct tx_ring *txr) { struct adapter *adapter = txr->adapter; - struct em_buffer *txbuf; + struct em_txbuffer *txbuf; INIT_DEBUGOUT("free_transmit_ring: begin"); @@ -3699,7 +3701,7 @@ em_transmit_checksum_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, { struct adapter *adapter = txr->adapter; struct e1000_context_desc *TXD = NULL; - struct em_buffer *tx_buffer; + struct em_txbuffer *tx_buffer; int cur, hdr_len; u32 cmd = 0; u16 offload = 0; @@ -3836,7 +3838,7 @@ em_tso_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, { struct adapter *adapter = txr->adapter; struct e1000_context_desc *TXD; - struct em_buffer *tx_buffer; + struct em_txbuffer *tx_buffer; int cur, hdr_len; /* @@ -3914,7 +3916,7 @@ em_txeof(struct tx_ring *txr) { struct adapter *adapter = txr->adapter; int first, last, done, processed; - struct em_buffer *tx_buffer; + struct em_txbuffer *tx_buffer; struct e1000_tx_desc *tx_desc, *eop_desc; if_t ifp = adapter->ifp; @@ -4020,7 +4022,6 @@ em_txeof(struct tx_ring *txr) txr->busy = EM_TX_IDLE; } - /********************************************************************* * * Refresh RX descriptor mbufs from system mbuf buffer pool. @@ -4031,8 +4032,8 @@ em_refresh_mbufs(struct rx_ring *rxr, int limit) { struct adapter *adapter = rxr->adapter; struct mbuf *m; - bus_dma_segment_t segs[1]; - struct em_buffer *rxbuf; + bus_dma_segment_t segs; + struct em_rxbuffer *rxbuf; int i, j, error, nsegs; bool cleaned = FALSE; @@ -4067,7 +4068,7 @@ em_refresh_mbufs(struct rx_ring *rxr, int limit) /* Use bus_dma machinery to setup the memory mapping */ error = bus_dmamap_load_mbuf_sg(rxr->rxtag, rxbuf->map, - m, segs, &nsegs, BUS_DMA_NOWAIT); + m, &segs, &nsegs, BUS_DMA_NOWAIT); if (error != 0) { printf("Refresh mbufs: hdr dmamap load" " failure - %d\n", error); @@ -4076,9 +4077,10 @@ em_refresh_mbufs(struct rx_ring *rxr, int limit) goto update; } rxbuf->m_head = m; + rxbuf->paddr = segs.ds_addr; bus_dmamap_sync(rxr->rxtag, rxbuf->map, BUS_DMASYNC_PREREAD); - rxr->rx_base[i].buffer_addr = htole64(segs[0].ds_addr); + em_setup_rxdesc(&rxr->rx_base[i], rxbuf); cleaned = TRUE; i = j; /* Next is precalulated for us */ @@ -4113,10 +4115,10 @@ em_allocate_receive_buffers(struct rx_ring *rxr) { struct adapter *adapter = rxr->adapter; device_t dev = adapter->dev; - struct em_buffer *rxbuf; + struct em_rxbuffer *rxbuf; int error; - rxr->rx_buffers = malloc(sizeof(struct em_buffer) * + rxr->rx_buffers = malloc(sizeof(struct em_rxbuffer) * adapter->num_rx_desc, M_DEVBUF, M_NOWAIT | M_ZERO); if (rxr->rx_buffers == NULL) { device_printf(dev, "Unable to allocate rx_buffer memory\n"); @@ -4169,7 +4171,7 @@ static int em_setup_receive_ring(struct rx_ring *rxr) { struct adapter *adapter = rxr->adapter; - struct em_buffer *rxbuf; + struct em_rxbuffer *rxbuf; bus_dma_segment_t seg[1]; int rsize, nsegs, error = 0; #ifdef DEV_NETMAP @@ -4181,7 +4183,7 @@ em_setup_receive_ring(struct rx_ring *rxr) /* Clear the ring contents */ EM_RX_LOCK(rxr); rsize = roundup2(adapter->num_rx_desc * - sizeof(struct e1000_rx_desc), EM_DBA_ALIGN); + sizeof(union e1000_rx_desc_extended), EM_DBA_ALIGN); bzero((void *)rxr->rx_base, rsize); #ifdef DEV_NETMAP slot = netmap_reset(na, NR_RX, rxr->me, 0); @@ -4212,8 +4214,7 @@ em_setup_receive_ring(struct rx_ring *rxr) addr = PNMB(na, slot + si, &paddr); netmap_load_map(na, rxr->rxtag, rxbuf->map, addr); - /* Update descriptor */ - rxr->rx_base[j].buffer_addr = htole64(paddr); + em_setup_rxdesc(&rxr->rx_base[j], rxbuf); continue; } #endif /* DEV_NETMAP */ @@ -4239,8 +4240,8 @@ em_setup_receive_ring(struct rx_ring *rxr) bus_dmamap_sync(rxr->rxtag, rxbuf->map, BUS_DMASYNC_PREREAD); - /* Update descriptor */ - rxr->rx_base[j].buffer_addr = htole64(seg[0].ds_addr); + rxbuf->paddr = seg[0].ds_addr; + em_setup_rxdesc(&rxr->rx_base[j], rxbuf); } rxr->next_to_check = 0; rxr->next_to_refresh = 0; @@ -4277,7 +4278,7 @@ em_setup_receive_structures(struct adapter *adapter) for (int i = 0; i < q; ++i) { rxr = &adapter->rx_rings[i]; for (int n = 0; n < adapter->num_rx_desc; n++) { - struct em_buffer *rxbuf; + struct em_rxbuffer *rxbuf; rxbuf = &rxr->rx_buffers[n]; if (rxbuf->m_head != NULL) { bus_dmamap_sync(rxr->rxtag, rxbuf->map, @@ -4324,7 +4325,7 @@ static void em_free_receive_buffers(struct rx_ring *rxr) { struct adapter *adapter = rxr->adapter; - struct em_buffer *rxbuf = NULL; + struct em_rxbuffer *rxbuf = NULL; INIT_DEBUGOUT("free_receive_buffers: begin"); @@ -4366,11 +4367,10 @@ em_free_receive_buffers(struct rx_ring *rxr) static void em_initialize_receive_unit(struct adapter *adapter) { - struct rx_ring *rxr = adapter->rx_rings; + struct rx_ring *rxr = adapter->rx_rings; if_t ifp = adapter->ifp; struct e1000_hw *hw = &adapter->hw; - u64 bus_addr; - u32 rctl, rxcsum; + u32 rctl, rxcsum, rfctl; INIT_DEBUGOUT("em_initialize_receive_units: begin"); @@ -4383,6 +4383,25 @@ em_initialize_receive_unit(struct adapter *adapter) if ((hw->mac.type != e1000_82574) && (hw->mac.type != e1000_82583)) E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN); + /* Setup the Receive Control Register */ + rctl &= ~(3 << E1000_RCTL_MO_SHIFT); + rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | + E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | + (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT); + + /* Do not store bad packets */ + rctl &= ~E1000_RCTL_SBP; + + /* Enable Long Packet receive */ + if (if_getmtu(ifp) > ETHERMTU) + rctl |= E1000_RCTL_LPE; + else + rctl &= ~E1000_RCTL_LPE; + + /* Strip the CRC */ + if (!em_disable_crc_stripping) + rctl |= E1000_RCTL_SECRC; + E1000_WRITE_REG(&adapter->hw, E1000_RADV, adapter->rx_abs_int_delay.value); @@ -4394,20 +4413,21 @@ em_initialize_receive_unit(struct adapter *adapter) */ E1000_WRITE_REG(hw, E1000_ITR, DEFAULT_ITR); + /* Use extended rx descriptor formats */ + rfctl = E1000_READ_REG(hw, E1000_RFCTL); + rfctl |= E1000_RFCTL_EXTEN; /* ** When using MSIX interrupts we need to throttle ** using the EITR register (82574 only) */ if (hw->mac.type == e1000_82574) { - u32 rfctl; for (int i = 0; i < 4; i++) E1000_WRITE_REG(hw, E1000_EITR_82574(i), DEFAULT_ITR); /* Disable accelerated acknowledge */ - rfctl = E1000_READ_REG(hw, E1000_RFCTL); rfctl |= E1000_RFCTL_ACK_DIS; - E1000_WRITE_REG(hw, E1000_RFCTL, rfctl); } + E1000_WRITE_REG(hw, E1000_RFCTL, rfctl); rxcsum = E1000_READ_REG(hw, E1000_RXCSUM); if (if_getcapenable(ifp) & IFCAP_RXCSUM) { @@ -4424,38 +4444,44 @@ em_initialize_receive_unit(struct adapter *adapter) E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum); #ifdef EM_MULTIQUEUE +#define RSSKEYLEN 10 if (adapter->num_queues > 1) { - uint32_t rss_key[10]; - uint32_t reta; + uint8_t rss_key[4 * RSSKEYLEN]; + uint32_t reta = 0; int i; /* * Configure RSS key */ arc4rand(rss_key, sizeof(rss_key), 0); - for (i = 0; i < 10; ++i) - E1000_WRITE_REG_ARRAY(hw,E1000_RSSRK(0), i, rss_key[i]); + for (i = 0; i < RSSKEYLEN; ++i) { + uint32_t rssrk = 0; + + rssrk = EM_RSSRK_VAL(rss_key, i); + E1000_WRITE_REG(hw,E1000_RSSRK(i), rssrk); + } /* * Configure RSS redirect table in following fashion: * (hash & ring_cnt_mask) == rdr_table[(hash & rdr_table_mask)] */ - reta = 0; - for (i = 0; i < 4; ++i) { + for (i = 0; i < sizeof(reta); ++i) { uint32_t q; + q = (i % adapter->num_queues) << 7; reta |= q << (8 * i); } - for (i = 0; i < 32; ++i) + + for (i = 0; i < 32; ++i) { E1000_WRITE_REG(hw, E1000_RETA(i), reta); + } E1000_WRITE_REG(hw, E1000_MRQC, E1000_MRQC_RSS_ENABLE_2Q | E1000_MRQC_RSS_FIELD_IPV4_TCP | E1000_MRQC_RSS_FIELD_IPV4 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX | E1000_MRQC_RSS_FIELD_IPV6_EX | - E1000_MRQC_RSS_FIELD_IPV6 | - E1000_MRQC_RSS_FIELD_IPV6_TCP); + E1000_MRQC_RSS_FIELD_IPV6); } #endif /* @@ -4470,11 +4496,11 @@ em_initialize_receive_unit(struct adapter *adapter) for (int i = 0; i < adapter->num_queues; i++, rxr++) { /* Setup the Base and Length of the Rx Descriptor Ring */ + u64 bus_addr = rxr->rxdma.dma_paddr; u32 rdt = adapter->num_rx_desc - 1; /* default */ - bus_addr = rxr->rxdma.dma_paddr; E1000_WRITE_REG(hw, E1000_RDLEN(i), - adapter->num_rx_desc * sizeof(struct e1000_rx_desc)); + adapter->num_rx_desc * sizeof(union e1000_rx_desc_extended)); E1000_WRITE_REG(hw, E1000_RDBAH(i), (u32)(bus_addr >> 32)); E1000_WRITE_REG(hw, E1000_RDBAL(i), (u32)bus_addr); /* Setup the Head and Tail Descriptor Pointers */ @@ -4505,14 +4531,13 @@ em_initialize_receive_unit(struct adapter *adapter) (if_getmtu(ifp) > ETHERMTU)) { u32 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(0)); E1000_WRITE_REG(hw, E1000_RXDCTL(0), rxdctl | 3); - } else if ((adapter->hw.mac.type == e1000_82574) && - (if_getmtu(ifp) > ETHERMTU)) { + } else if (adapter->hw.mac.type == e1000_82574) { for (int i = 0; i < adapter->num_queues; i++) { u32 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i)); - rxdctl |= 0x20; /* PTHRESH */ - rxdctl |= 4 << 8; /* HTHRESH */ - rxdctl |= 4 << 16;/* WTHRESH */ + rxdctl |= 0x20; /* PTHRESH */ + rxdctl |= 4 << 8; /* HTHRESH */ + rxdctl |= 4 << 16;/* WTHRESH */ rxdctl |= 1 << 24; /* Switch to granularity */ E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl); } @@ -4525,19 +4550,8 @@ em_initialize_receive_unit(struct adapter *adapter) e1000_lv_jumbo_workaround_ich8lan(hw, FALSE); } - /* Setup the Receive Control Register */ - rctl &= ~(3 << E1000_RCTL_MO_SHIFT); - rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | - E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | - (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT); - - /* Strip the CRC */ - if (!em_disable_crc_stripping) - rctl |= E1000_RCTL_SECRC; - /* Make sure VLAN Filters are off */ rctl &= ~E1000_RCTL_VFE; - rctl &= ~E1000_RCTL_SBP; if (adapter->rx_mbuf_sz == MCLBYTES) rctl |= E1000_RCTL_SZ_2048; @@ -4546,11 +4560,8 @@ em_initialize_receive_unit(struct adapter *adapter) else if (adapter->rx_mbuf_sz > MJUMPAGESIZE) rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX; - if (if_getmtu(ifp) > ETHERMTU) - rctl |= E1000_RCTL_LPE; - else - rctl &= ~E1000_RCTL_LPE; - + /* ensure we clear use DTYPE of 00 here */ + rctl &= ~0x00000C00; /* Write out the settings */ E1000_WRITE_REG(hw, E1000_RCTL, rctl); @@ -4575,11 +4586,11 @@ em_rxeof(struct rx_ring *rxr, int count, int *done) struct adapter *adapter = rxr->adapter; if_t ifp = adapter->ifp; struct mbuf *mp, *sendmp; - u8 status = 0; + u32 status = 0; u16 len; int i, processed, rxdone = 0; bool eop; - struct e1000_rx_desc *cur; + union e1000_rx_desc_extended *cur; EM_RX_LOCK(rxr); @@ -4596,21 +4607,20 @@ em_rxeof(struct rx_ring *rxr, int count, int *done) #endif /* DEV_NETMAP */ for (i = rxr->next_to_check, processed = 0; count != 0;) { - if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) break; cur = &rxr->rx_base[i]; - status = cur->status; + status = le32toh(cur->wb.upper.status_error); mp = sendmp = NULL; if ((status & E1000_RXD_STAT_DD) == 0) break; - len = le16toh(cur->length); + len = le16toh(cur->wb.upper.length); eop = (status & E1000_RXD_STAT_EOP) != 0; - if ((cur->errors & E1000_RXD_ERR_FRAME_ERR_MASK) || + if ((status & E1000_RXDEXT_ERR_FRAME_ERR_MASK) || (rxr->discard == TRUE)) { adapter->dropped_pkts++; ++rxr->rx_discarded; @@ -4647,7 +4657,7 @@ em_rxeof(struct rx_ring *rxr, int count, int *done) sendmp = rxr->fmp; if_setrcvif(sendmp, ifp); if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); - em_receive_checksum(cur, sendmp); + em_receive_checksum(status, sendmp); #ifndef __NO_STRICT_ALIGNMENT if (adapter->hw.mac.max_frame_size > (MCLBYTES - ETHER_ALIGN) && @@ -4656,7 +4666,7 @@ em_rxeof(struct rx_ring *rxr, int count, int *done) #endif if (status & E1000_RXD_STAT_VP) { if_setvtag(sendmp, - le16toh(cur->special)); + le16toh(cur->wb.upper.vlan)); sendmp->m_flags |= M_VLANTAG; } #ifndef __NO_STRICT_ALIGNMENT @@ -4670,7 +4680,7 @@ em_rxeof(struct rx_ring *rxr, int count, int *done) BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); /* Zero out the receive descriptors status. */ - cur->status = 0; + cur->wb.upper.status_error &= htole32(~0xFF); ++rxdone; /* cumulative for POLL */ ++processed; @@ -4709,7 +4719,7 @@ em_rxeof(struct rx_ring *rxr, int count, int *done) static __inline void em_rx_discard(struct rx_ring *rxr, int i) { - struct em_buffer *rbuf; + struct em_rxbuffer *rbuf; rbuf = &rxr->rx_buffers[i]; bus_dmamap_unload(rxr->rxtag, rbuf->map); @@ -4781,6 +4791,14 @@ em_fixup_rx(struct rx_ring *rxr) } #endif +static void +em_setup_rxdesc(union e1000_rx_desc_extended *rxd, const struct em_rxbuffer *rxbuf) +{ + rxd->read.buffer_addr = htole64(rxbuf->paddr); + /* DD bits must be cleared */ + rxd->wb.upper.status_error= 0; +} + /********************************************************************* * * Verify that the hardware indicated that the checksum is valid. @@ -4789,23 +4807,27 @@ em_fixup_rx(struct rx_ring *rxr) * *********************************************************************/ static void -em_receive_checksum(struct e1000_rx_desc *rx_desc, struct mbuf *mp) +em_receive_checksum(uint32_t status, struct mbuf *mp) { mp->m_pkthdr.csum_flags = 0; /* Ignore Checksum bit is set */ - if (rx_desc->status & E1000_RXD_STAT_IXSM) + if (status & E1000_RXD_STAT_IXSM) return; - if (rx_desc->errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) - return; - - /* IP Checksum Good? */ - if (rx_desc->status & E1000_RXD_STAT_IPCS) + /* If the IP checksum exists and there is no IP Checksum error */ + if ((status & (E1000_RXD_STAT_IPCS | E1000_RXDEXT_STATERR_IPE)) == + E1000_RXD_STAT_IPCS) { mp->m_pkthdr.csum_flags = (CSUM_IP_CHECKED | CSUM_IP_VALID); + } /* TCP or UDP checksum */ - if (rx_desc->status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)) { + if ((status & (E1000_RXD_STAT_TCPCS | E1000_RXDEXT_STATERR_TCPE)) == + E1000_RXD_STAT_TCPCS) { + mp->m_pkthdr.csum_flags |= (CSUM_DATA_VALID | CSUM_PSEUDO_HDR); + mp->m_pkthdr.csum_data = htons(0xffff); + } + if (status & E1000_RXD_STAT_UDPCS) { mp->m_pkthdr.csum_flags |= (CSUM_DATA_VALID | CSUM_PSEUDO_HDR); mp->m_pkthdr.csum_data = htons(0xffff); } diff --git a/sys/dev/e1000/if_em.h b/sys/dev/e1000/if_em.h index 8725de35e81d..be9fdc96e6d3 100644 --- a/sys/dev/e1000/if_em.h +++ b/sys/dev/e1000/if_em.h @@ -330,7 +330,7 @@ struct tx_ring { struct taskqueue *tq; u32 next_avail_desc; u32 next_to_clean; - struct em_buffer *tx_buffers; + struct em_txbuffer *tx_buffers; volatile u16 tx_avail; u32 tx_tso; /* last tx was tso */ u16 last_hw_offload; @@ -362,11 +362,11 @@ struct rx_ring { u32 payload; struct task rx_task; struct taskqueue *tq; - struct e1000_rx_desc *rx_base; + union e1000_rx_desc_extended *rx_base; struct em_dma_alloc rxdma; u32 next_to_refresh; u32 next_to_check; - struct em_buffer *rx_buffers; + struct em_rxbuffer *rx_buffers; struct mbuf *fmp; struct mbuf *lmp; @@ -499,12 +499,19 @@ typedef struct _em_vendor_info_t { unsigned int index; } em_vendor_info_t; -struct em_buffer { +struct em_txbuffer { int next_eop; /* Index of the desc to watch */ struct mbuf *m_head; bus_dmamap_t map; /* bus_dma map for packet */ }; +struct em_rxbuffer { + int next_eop; /* Index of the desc to watch */ + struct mbuf *m_head; + bus_dmamap_t map; /* bus_dma map for packet */ + bus_addr_t paddr; +}; + /* ** Find the number of unrefreshed RX descriptors @@ -541,4 +548,9 @@ e1000_rx_unrefreshed(struct rx_ring *rxr) #define EM_TX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->tx_mtx, MA_OWNED) #define EM_RX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->rx_mtx, MA_OWNED) +#define EM_RSSRK_SIZE 4 +#define EM_RSSRK_VAL(key, i) (key[(i) * EM_RSSRK_SIZE] | \ + key[(i) * EM_RSSRK_SIZE + 1] << 8 | \ + key[(i) * EM_RSSRK_SIZE + 2] << 16 | \ + key[(i) * EM_RSSRK_SIZE + 3] << 24) #endif /* _EM_H_DEFINED_ */ diff --git a/sys/dev/netmap/if_em_netmap.h b/sys/dev/netmap/if_em_netmap.h index eae4f8c18ca0..28f2dd4bbc64 100644 --- a/sys/dev/netmap/if_em_netmap.h +++ b/sys/dev/netmap/if_em_netmap.h @@ -148,7 +148,7 @@ em_netmap_txsync(struct netmap_kring *kring, int flags) /* device-specific */ struct e1000_tx_desc *curr = &txr->tx_base[nic_i]; - struct em_buffer *txbuf = &txr->tx_buffers[nic_i]; + struct em_txbuffer *txbuf = &txr->tx_buffers[nic_i]; int flags = (slot->flags & NS_REPORT || nic_i == 0 || nic_i == report_frequency) ? E1000_TXD_CMD_RS : 0; @@ -239,12 +239,12 @@ em_netmap_rxsync(struct netmap_kring *kring, int flags) nm_i = netmap_idx_n2k(kring, nic_i); for (n = 0; ; n++) { // XXX no need to count - struct e1000_rx_desc *curr = &rxr->rx_base[nic_i]; - uint32_t staterr = le32toh(curr->status); + union e1000_rx_desc_extended *curr = &rxr->rx_base[nic_i]; + uint32_t staterr = le32toh(curr->wb.upper.status_error); if ((staterr & E1000_RXD_STAT_DD) == 0) break; - ring->slot[nm_i].len = le16toh(curr->length); + ring->slot[nm_i].len = le16toh(curr->wb.upper.length); ring->slot[nm_i].flags = slot_flags; bus_dmamap_sync(rxr->rxtag, rxr->rx_buffers[nic_i].map, BUS_DMASYNC_POSTREAD); @@ -271,19 +271,19 @@ em_netmap_rxsync(struct netmap_kring *kring, int flags) uint64_t paddr; void *addr = PNMB(na, slot, &paddr); - struct e1000_rx_desc *curr = &rxr->rx_base[nic_i]; - struct em_buffer *rxbuf = &rxr->rx_buffers[nic_i]; + union e1000_rx_desc_extended *curr = &rxr->rx_base[nic_i]; + struct em_rxbuffer *rxbuf = &rxr->rx_buffers[nic_i]; if (addr == NETMAP_BUF_BASE(na)) /* bad buf */ goto ring_reset; if (slot->flags & NS_BUF_CHANGED) { /* buffer has changed, reload map */ - curr->buffer_addr = htole64(paddr); + curr->read.buffer_addr = htole64(paddr); netmap_reload_map(na, rxr->rxtag, rxbuf->map, addr); slot->flags &= ~NS_BUF_CHANGED; } - curr->status = 0; + curr->wb.upper.status_error = 0; bus_dmamap_sync(rxr->rxtag, rxbuf->map, BUS_DMASYNC_PREREAD); nm_i = nm_next(nm_i, lim); From 676822acb5d3da091aed044b47b8c8cbcb0aa815 Mon Sep 17 00:00:00 2001 From: Sean Bruno Date: Thu, 7 Jan 2016 16:48:47 +0000 Subject: [PATCH 33/68] Disable the reuse of checksum offload context descriptors in the case of multiple queues in em(4). Document errata in the code. MFC after: 2 weeks Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D3995 --- sys/dev/e1000/if_em.c | 108 ++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c index de53d8b9f229..f586d399822f 100644 --- a/sys/dev/e1000/if_em.c +++ b/sys/dev/e1000/if_em.c @@ -3735,29 +3735,38 @@ em_transmit_checksum_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, offload |= CSUM_TCP; tucss = hdr_len; tucso = hdr_len + offsetof(struct tcphdr, th_sum); - /* - * Setting up new checksum offload context for every frames - * takes a lot of processing time for hardware. This also - * reduces performance a lot for small sized frames so avoid - * it if driver can use previously configured checksum - * offload context. - */ - if (txr->last_hw_offload == offload) { - if (offload & CSUM_IP) { - if (txr->last_hw_ipcss == ipcss && - txr->last_hw_ipcso == ipcso && - txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } else { - if (txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } - } - txr->last_hw_offload = offload; - txr->last_hw_tucss = tucss; - txr->last_hw_tucso = tucso; + /* + * The 82574L can only remember the *last* context used + * regardless of queue that it was use for. We cannot reuse + * contexts on this hardware platform and must generate a new + * context every time. 82574L hardware spec, section 7.2.6, + * second note. + */ + if (adapter->num_queues < 2) { + /* + * Setting up new checksum offload context for every + * frames takes a lot of processing time for hardware. + * This also reduces performance a lot for small sized + * frames so avoid it if driver can use previously + * configured checksum offload context. + */ + if (txr->last_hw_offload == offload) { + if (offload & CSUM_IP) { + if (txr->last_hw_ipcss == ipcss && + txr->last_hw_ipcso == ipcso && + txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } else { + if (txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } + } + txr->last_hw_offload = offload; + txr->last_hw_tucss = tucss; + txr->last_hw_tucso = tucso; + } /* * Start offset for payload checksum calculation. * End offset for payload checksum calculation. @@ -3773,29 +3782,38 @@ em_transmit_checksum_setup(struct tx_ring *txr, struct mbuf *mp, int ip_off, *txd_upper |= E1000_TXD_POPTS_TXSM << 8; tucss = hdr_len; tucso = hdr_len + offsetof(struct udphdr, uh_sum); - /* - * Setting up new checksum offload context for every frames - * takes a lot of processing time for hardware. This also - * reduces performance a lot for small sized frames so avoid - * it if driver can use previously configured checksum - * offload context. - */ - if (txr->last_hw_offload == offload) { - if (offload & CSUM_IP) { - if (txr->last_hw_ipcss == ipcss && - txr->last_hw_ipcso == ipcso && - txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; - } else { - if (txr->last_hw_tucss == tucss && - txr->last_hw_tucso == tucso) - return; + /* + * The 82574L can only remember the *last* context used + * regardless of queue that it was use for. We cannot reuse + * contexts on this hardware platform and must generate a new + * context every time. 82574L hardware spec, section 7.2.6, + * second note. + */ + if (adapter->num_queues < 2) { + /* + * Setting up new checksum offload context for every + * frames takes a lot of processing time for hardware. + * This also reduces performance a lot for small sized + * frames so avoid it if driver can use previously + * configured checksum offload context. + */ + if (txr->last_hw_offload == offload) { + if (offload & CSUM_IP) { + if (txr->last_hw_ipcss == ipcss && + txr->last_hw_ipcso == ipcso && + txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } else { + if (txr->last_hw_tucss == tucss && + txr->last_hw_tucso == tucso) + return; + } } - } - txr->last_hw_offload = offload; - txr->last_hw_tucss = tucss; - txr->last_hw_tucso = tucso; + txr->last_hw_offload = offload; + txr->last_hw_tucss = tucss; + txr->last_hw_tucso = tucso; + } /* * Start offset for header checksum calculation. * End offset for header checksum calculation. From 97f9586e97f7a4b1e1b4b5dab6dba6ec12a36f38 Mon Sep 17 00:00:00 2001 From: Sean Bruno Date: Thu, 7 Jan 2016 17:02:34 +0000 Subject: [PATCH 34/68] Fixup SFP module insertion on the 82599 when insertion happens after the system is booted and running. Add PHY detection logic to ixgbe_handle_mod() and add locking to ixgbe_handle_msf() as well. PR: 150251 Submitted by: aboyer@averesystems.com MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D3188 --- sys/dev/ixgbe/if_ix.c | 58 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/sys/dev/ixgbe/if_ix.c b/sys/dev/ixgbe/if_ix.c index c7ac59399ad2..90d70d98a464 100644 --- a/sys/dev/ixgbe/if_ix.c +++ b/sys/dev/ixgbe/if_ix.c @@ -2947,12 +2947,7 @@ ixgbe_config_link(struct adapter *adapter) sfp = ixgbe_is_sfp(hw); if (sfp) { - if (hw->phy.multispeed_fiber) { - hw->mac.ops.setup_sfp(hw); - ixgbe_enable_tx_laser(hw); - taskqueue_enqueue(adapter->tq, &adapter->msf_task); - } else - taskqueue_enqueue(adapter->tq, &adapter->mod_task); + taskqueue_enqueue(adapter->tq, &adapter->mod_task); } else { if (hw->mac.ops.check_link) err = ixgbe_check_link(hw, &adapter->link_speed, @@ -3758,23 +3753,66 @@ ixgbe_handle_mod(void *context, int pending) { struct adapter *adapter = context; struct ixgbe_hw *hw = &adapter->hw; + enum ixgbe_phy_type orig_type = hw->phy.type; device_t dev = adapter->dev; u32 err; + IXGBE_CORE_LOCK(adapter); + + /* Check to see if the PHY type changed */ + if (hw->phy.ops.identify) { + hw->phy.type = ixgbe_phy_unknown; + hw->phy.ops.identify(hw); + } + + if (hw->phy.type != orig_type) { + device_printf(dev, "Detected phy_type %d\n", hw->phy.type); + + if (hw->phy.type == ixgbe_phy_none) { + hw->phy.sfp_type = ixgbe_sfp_type_unknown; + goto out; + } + + /* Try to do the initialization that was skipped before */ + if (hw->phy.ops.init) + hw->phy.ops.init(hw); + if (hw->phy.ops.reset) + hw->phy.ops.reset(hw); + } + err = hw->phy.ops.identify_sfp(hw); if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { device_printf(dev, "Unsupported SFP+ module type was detected.\n"); - return; + goto out; } err = hw->mac.ops.setup_sfp(hw); if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { device_printf(dev, "Setup failure - unsupported SFP+ module type.\n"); - return; + goto out; } - taskqueue_enqueue(adapter->tq, &adapter->msf_task); + if (hw->phy.multispeed_fiber) + taskqueue_enqueue(adapter->tq, &adapter->msf_task); +out: + /* Update media type */ + switch (hw->mac.ops.get_media_type(hw)) { + case ixgbe_media_type_fiber: + adapter->optics = IFM_10G_SR; + break; + case ixgbe_media_type_copper: + adapter->optics = IFM_10G_TWINAX; + break; + case ixgbe_media_type_cx4: + adapter->optics = IFM_10G_CX4; + break; + default: + adapter->optics = 0; + break; + } + + IXGBE_CORE_UNLOCK(adapter); return; } @@ -3790,6 +3828,7 @@ ixgbe_handle_msf(void *context, int pending) u32 autoneg; bool negotiate; + IXGBE_CORE_LOCK(adapter); /* get_supported_phy_layer will call hw->phy.ops.identify_sfp() */ adapter->phy_layer = ixgbe_get_supported_physical_layer(hw); @@ -3802,6 +3841,7 @@ ixgbe_handle_msf(void *context, int pending) /* Adjust media types shown in ifconfig */ ifmedia_removeall(&adapter->media); ixgbe_add_media_types(adapter); + IXGBE_CORE_UNLOCK(adapter); return; } From 9030be4bad005c75a8a2df81f7e4b1a33913876e Mon Sep 17 00:00:00 2001 From: Sean Bruno Date: Thu, 7 Jan 2016 18:34:56 +0000 Subject: [PATCH 35/68] Fix VF handling of VLANs. This helps immensily with our ability to operate in the Amazon Cloud. Discussed on Intel Networking Community call this morning. Submitted by: Jarrod Petz(petz@nisshoko.net) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D4788 --- sys/dev/ixgbe/if_ixv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sys/dev/ixgbe/if_ixv.c b/sys/dev/ixgbe/if_ixv.c index 0b147d476b99..20358ad1a9b0 100644 --- a/sys/dev/ixgbe/if_ixv.c +++ b/sys/dev/ixgbe/if_ixv.c @@ -1664,7 +1664,7 @@ ixv_initialize_receive_units(struct adapter *adapter) /* Disable the queue */ rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)); - rxdctl &= ~(IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME); + rxdctl &= ~IXGBE_RXDCTL_ENABLE; IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl); for (int j = 0; j < 10; j++) { if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)) & @@ -1698,8 +1698,7 @@ ixv_initialize_receive_units(struct adapter *adapter) rxr->tail = IXGBE_VFRDT(rxr->me); /* Do the queue enabling last */ - rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)); - rxdctl |= IXGBE_RXDCTL_ENABLE; + rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME; IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl); for (int k = 0; k < 10; k++) { if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)) & From 0046e1868fb0f7704f0ba2fd9ec63321adbf0a8e Mon Sep 17 00:00:00 2001 From: Andriy Voskoboinyk Date: Thu, 7 Jan 2016 18:41:03 +0000 Subject: [PATCH 36/68] net80211 drivers: fix ieee80211_init_channels() usage Fix out-of-bounds read (all) / write (11n capable) for drivers that are using ieee80211_init_channels() to initialize channel list. Tested with: * RTL8188EU, STA mode. * RTL8188CUS, STA mode. * WUSB54GC, HOSTAP mode. Approved by: adrian (mentor) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D4818 --- sys/dev/bwi/if_bwi.c | 12 ++++++------ sys/dev/if_ndis/if_ndis.c | 13 +++++++------ sys/dev/iwi/if_iwi.c | 14 +++++++------- sys/dev/malo/if_malo.c | 10 +++++----- sys/dev/otus/if_otus.c | 14 +++++++------- sys/dev/ral/rt2560.c | 12 ++++++------ sys/dev/ral/rt2661.c | 12 ++++++------ sys/dev/ral/rt2860.c | 12 ++++++------ sys/dev/rtwn/if_rtwn.c | 10 +++++----- sys/dev/usb/wlan/if_rsu.c | 13 +++++++------ sys/dev/usb/wlan/if_rum.c | 13 +++++++------ sys/dev/usb/wlan/if_run.c | 13 +++++++------ sys/dev/usb/wlan/if_uath.c | 13 +++++++------ sys/dev/usb/wlan/if_upgt.c | 11 ++++++----- sys/dev/usb/wlan/if_ural.c | 13 +++++++------ sys/dev/usb/wlan/if_urtw.c | 11 ++++++----- sys/dev/usb/wlan/if_urtwn.c | 10 +++++----- sys/dev/usb/wlan/if_zyd.c | 11 ++++++----- 18 files changed, 113 insertions(+), 104 deletions(-) diff --git a/sys/dev/bwi/if_bwi.c b/sys/dev/bwi/if_bwi.c index ebed09c8ac0c..00e89f37e814 100644 --- a/sys/dev/bwi/if_bwi.c +++ b/sys/dev/bwi/if_bwi.c @@ -356,8 +356,8 @@ bwi_attach(struct bwi_softc *sc) device_t dev = sc->sc_dev; struct bwi_mac *mac; struct bwi_phy *phy; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int i, error; - uint8_t bands; BWI_LOCK_INIT(sc); @@ -453,15 +453,15 @@ bwi_attach(struct bwi_softc *sc) /* * Setup ratesets, phytype, channels and get MAC address */ - bands = 0; + memset(bands, 0, sizeof(bands)); if (phy->phy_mode == IEEE80211_MODE_11B || phy->phy_mode == IEEE80211_MODE_11G) { - setbit(&bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11B); if (phy->phy_mode == IEEE80211_MODE_11B) { ic->ic_phytype = IEEE80211_T_DS; } else { ic->ic_phytype = IEEE80211_T_OFDM; - setbit(&bands, IEEE80211_MODE_11G); + setbit(bands, IEEE80211_MODE_11G); } bwi_get_eaddr(sc, BWI_SPROM_11BG_EADDR, ic->ic_macaddr); @@ -475,7 +475,7 @@ bwi_attach(struct bwi_softc *sc) } } else if (phy->phy_mode == IEEE80211_MODE_11A) { /* TODO:11A */ - setbit(&bands, IEEE80211_MODE_11A); + setbit(bands, IEEE80211_MODE_11A); error = ENXIO; goto fail; } else { @@ -487,7 +487,7 @@ bwi_attach(struct bwi_softc *sc) BWI_SPROM_CARD_INFO_LOCALE); DPRINTF(sc, BWI_DBG_ATTACH, "locale: %d\n", sc->sc_locale); /* XXX use locale */ - ieee80211_init_channels(ic, NULL, &bands); + ieee80211_init_channels(ic, NULL, bands); ic->ic_softc = sc; ic->ic_name = device_get_nameunit(dev); diff --git a/sys/dev/if_ndis/if_ndis.c b/sys/dev/if_ndis/if_ndis.c index bb1f19ecfabf..47594fc60224 100644 --- a/sys/dev/if_ndis/if_ndis.c +++ b/sys/dev/if_ndis/if_ndis.c @@ -724,8 +724,8 @@ ndis_80211attach(struct ndis_softc *sc) ndis_80211_rates_ex rates; struct ndis_80211_nettype_list *ntl; uint32_t arg; - int mode, i, r, len; - uint8_t bands = 0; + int mode, i, r, len, nonettypes = 1; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)] = { 0 }; callout_init(&sc->ndis_scan_callout, 1); @@ -751,8 +751,9 @@ ndis_80211attach(struct ndis_softc *sc) for (i = 0; i < ntl->ntl_items; i++) { mode = ndis_nettype_mode(ntl->ntl_type[i]); if (mode) { + nonettypes = 0; setbit(ic->ic_modecaps, mode); - setbit(&bands, mode); + setbit(bands, mode); } else device_printf(sc->ndis_dev, "Unknown nettype %d\n", ntl->ntl_type[i]); @@ -760,9 +761,9 @@ ndis_80211attach(struct ndis_softc *sc) free(ntl, M_DEVBUF); nonettypes: /* Default to 11b channels if the card did not supply any */ - if (bands == 0) { + if (nonettypes) { setbit(ic->ic_modecaps, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11B); } len = sizeof(rates); bzero((char *)&rates, len); @@ -859,7 +860,7 @@ ndis_80211attach(struct ndis_softc *sc) #undef INCRATE #undef TESTSETRATE - ieee80211_init_channels(ic, NULL, &bands); + ieee80211_init_channels(ic, NULL, bands); /* * To test for WPA support, we need to see if we can diff --git a/sys/dev/iwi/if_iwi.c b/sys/dev/iwi/if_iwi.c index 53141e1e4495..55004f69e0f6 100644 --- a/sys/dev/iwi/if_iwi.c +++ b/sys/dev/iwi/if_iwi.c @@ -271,8 +271,8 @@ iwi_attach(device_t dev) struct iwi_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; uint16_t val; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int i, error; - uint8_t bands; sc->sc_dev = dev; @@ -373,13 +373,13 @@ iwi_attach(device_t dev) val = iwi_read_prom_word(sc, IWI_EEPROM_MAC + 2); ic->ic_macaddr[4] = val & 0xff; ic->ic_macaddr[5] = val >> 8; - - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (pci_get_device(dev) >= 0x4223) - setbit(&bands, IEEE80211_MODE_11A); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11A); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); /* override default methods */ diff --git a/sys/dev/malo/if_malo.c b/sys/dev/malo/if_malo.c index d02b6d5e2475..ff487082e708 100644 --- a/sys/dev/malo/if_malo.c +++ b/sys/dev/malo/if_malo.c @@ -173,7 +173,7 @@ malo_attach(uint16_t devid, struct malo_softc *sc) struct ieee80211com *ic = &sc->malo_ic; struct malo_hal *mh; int error; - uint8_t bands; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; MALO_LOCK_INIT(sc); callout_init_mtx(&sc->malo_watchdog_timer, &sc->malo_mtx, 0); @@ -222,10 +222,10 @@ malo_attach(uint16_t devid, struct malo_softc *sc) sc->malo_hwspecs.wcbbase[2], sc->malo_hwspecs.wcbbase[3]); /* NB: firmware looks that it does not export regdomain info API. */ - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); - ieee80211_init_channels(ic, NULL, &bands); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); + ieee80211_init_channels(ic, NULL, bands); sc->malo_txantenna = 0x2; /* h/w default */ sc->malo_rxantenna = 0xffff; /* h/w default */ diff --git a/sys/dev/otus/if_otus.c b/sys/dev/otus/if_otus.c index 160b05e7abb7..daa96266353a 100644 --- a/sys/dev/otus/if_otus.c +++ b/sys/dev/otus/if_otus.c @@ -624,8 +624,8 @@ otus_attachhook(struct otus_softc *sc) struct ieee80211com *ic = &sc->sc_ic; usb_device_request_t req; uint32_t in, out; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int error; - uint8_t bands; /* Not locked */ error = otus_load_firmware(sc, "otusfw_init", AR_FW_INIT_ADDR); @@ -743,19 +743,19 @@ otus_attachhook(struct otus_softc *sc) otus_get_chanlist(sc); #else /* Set supported .11b and .11g rates. */ - bands = 0; + memset(bands, 0, sizeof(bands)); if (sc->eeprom.baseEepHeader.opCapFlags & AR5416_OPFLAGS_11G) { - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); } if (sc->eeprom.baseEepHeader.opCapFlags & AR5416_OPFLAGS_11A) { - setbit(&bands, IEEE80211_MODE_11A); + setbit(bands, IEEE80211_MODE_11A); } #if 0 if (sc->sc_ht) - setbit(&bands, IEEE80211_MODE_11NG); + setbit(bands, IEEE80211_MODE_11NG); #endif - ieee80211_init_channels(ic, NULL, &bands); + ieee80211_init_channels(ic, NULL, bands); #endif ieee80211_ifattach(ic); diff --git a/sys/dev/ral/rt2560.c b/sys/dev/ral/rt2560.c index d62c470c82fe..1ba2791a9c21 100644 --- a/sys/dev/ral/rt2560.c +++ b/sys/dev/ral/rt2560.c @@ -199,7 +199,7 @@ rt2560_attach(device_t dev, int id) { struct rt2560_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; - uint8_t bands; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int error; sc->sc_dev = dev; @@ -278,12 +278,12 @@ rt2560_attach(device_t dev, int id) #endif ; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (sc->rf_rev == RT2560_RF_5222) - setbit(&bands, IEEE80211_MODE_11A); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11A); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_raw_xmit = rt2560_raw_xmit; diff --git a/sys/dev/ral/rt2661.c b/sys/dev/ral/rt2661.c index a2e955ced04b..a53d509bcf3d 100644 --- a/sys/dev/ral/rt2661.c +++ b/sys/dev/ral/rt2661.c @@ -199,8 +199,8 @@ rt2661_attach(device_t dev, int id) struct rt2661_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; uint32_t val; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int error, ac, ntries; - uint8_t bands; sc->sc_id = id; sc->sc_dev = dev; @@ -279,12 +279,12 @@ rt2661_attach(device_t dev, int id) #endif ; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) - setbit(&bands, IEEE80211_MODE_11A); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11A); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); #if 0 diff --git a/sys/dev/ral/rt2860.c b/sys/dev/ral/rt2860.c index 944797612a2f..8bfb00d81622 100644 --- a/sys/dev/ral/rt2860.c +++ b/sys/dev/ral/rt2860.c @@ -232,8 +232,8 @@ rt2860_attach(device_t dev, int id) struct rt2860_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; uint32_t tmp; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int error, ntries, qid; - uint8_t bands; sc->sc_dev = dev; sc->sc_debug = 0; @@ -319,12 +319,12 @@ rt2860_attach(device_t dev, int id) | IEEE80211_C_WME /* 802.11e */ ; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850) - setbit(&bands, IEEE80211_MODE_11A); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11A); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); diff --git a/sys/dev/rtwn/if_rtwn.c b/sys/dev/rtwn/if_rtwn.c index 6fedf7dd7bb7..ec17cdc6572f 100644 --- a/sys/dev/rtwn/if_rtwn.c +++ b/sys/dev/rtwn/if_rtwn.c @@ -251,7 +251,7 @@ rtwn_attach(device_t dev) struct rtwn_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; uint32_t lcsr; - uint8_t bands; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int i, count, error, rid; sc->sc_dev = dev; @@ -353,10 +353,10 @@ rtwn_attach(device_t dev) | IEEE80211_C_WME /* 802.11e */ ; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); - ieee80211_init_channels(ic, NULL, &bands); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); diff --git a/sys/dev/usb/wlan/if_rsu.c b/sys/dev/usb/wlan/if_rsu.c index ea89bff79e53..0dcde19add44 100644 --- a/sys/dev/usb/wlan/if_rsu.c +++ b/sys/dev/usb/wlan/if_rsu.c @@ -403,7 +403,8 @@ rsu_attach(device_t self) struct rsu_softc *sc = device_get_softc(self); struct ieee80211com *ic = &sc->sc_ic; int error; - uint8_t iface_index, bands; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index; struct usb_interface *iface; const char *rft; @@ -531,12 +532,12 @@ rsu_attach(device_t self) } /* Set supported .11b and .11g rates. */ - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (sc->sc_ht) - setbit(&bands, IEEE80211_MODE_11NG); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11NG); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_raw_xmit = rsu_raw_xmit; diff --git a/sys/dev/usb/wlan/if_rum.c b/sys/dev/usb/wlan/if_rum.c index 02b82ef55923..3fada69ec189 100644 --- a/sys/dev/usb/wlan/if_rum.c +++ b/sys/dev/usb/wlan/if_rum.c @@ -468,8 +468,9 @@ rum_attach(device_t self) struct usb_attach_arg *uaa = device_get_ivars(self); struct rum_softc *sc = device_get_softc(self); struct ieee80211com *ic = &sc->sc_ic; - uint8_t iface_index, bands; uint32_t tmp; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index; int error, ntries; device_set_usb_desc(self); @@ -537,12 +538,12 @@ rum_attach(device_t self) IEEE80211_CRYPTO_TKIPMIC | IEEE80211_CRYPTO_TKIP; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_5226) - setbit(&bands, IEEE80211_MODE_11A); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11A); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_update_promisc = rum_update_promisc; diff --git a/sys/dev/usb/wlan/if_run.c b/sys/dev/usb/wlan/if_run.c index 1ad9f608fd82..7a10d2c0aef8 100644 --- a/sys/dev/usb/wlan/if_run.c +++ b/sys/dev/usb/wlan/if_run.c @@ -704,8 +704,9 @@ run_attach(device_t self) struct usb_attach_arg *uaa = device_get_ivars(self); struct ieee80211com *ic = &sc->sc_ic; uint32_t ver; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index; int ntries, error; - uint8_t iface_index, bands; device_set_usb_desc(self); sc->sc_udev = uaa->device; @@ -785,14 +786,14 @@ run_attach(device_t self) ic->ic_flags |= IEEE80211_F_DATAPAD; ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850 || sc->rf_rev == RT3070_RF_3052 || sc->rf_rev == RT3593_RF_3053 || sc->rf_rev == RT5592_RF_5592) - setbit(&bands, IEEE80211_MODE_11A); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11A); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); diff --git a/sys/dev/usb/wlan/if_uath.c b/sys/dev/usb/wlan/if_uath.c index 747d49dc2efc..404fdd831778 100644 --- a/sys/dev/usb/wlan/if_uath.c +++ b/sys/dev/usb/wlan/if_uath.c @@ -328,7 +328,8 @@ uath_attach(device_t dev) struct uath_softc *sc = device_get_softc(dev); struct usb_attach_arg *uaa = device_get_ivars(dev); struct ieee80211com *ic = &sc->sc_ic; - uint8_t bands, iface_index = UATH_IFACE_INDEX; /* XXX */ + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index = UATH_IFACE_INDEX; /* XXX */ usb_error_t error; sc->sc_dev = dev; @@ -431,13 +432,13 @@ uath_attach(device_t dev) /* put a regulatory domain to reveal informations. */ uath_regdomain = sc->sc_devcap.regDomain; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if ((sc->sc_devcap.analog5GhzRevision & 0xf0) == 0x30) - setbit(&bands, IEEE80211_MODE_11A); + setbit(bands, IEEE80211_MODE_11A); /* XXX turbo */ - ieee80211_init_channels(ic, NULL, &bands); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_raw_xmit = uath_raw_xmit; diff --git a/sys/dev/usb/wlan/if_upgt.c b/sys/dev/usb/wlan/if_upgt.c index 8030c6f9391b..7f1e8adb694b 100644 --- a/sys/dev/usb/wlan/if_upgt.c +++ b/sys/dev/usb/wlan/if_upgt.c @@ -243,7 +243,8 @@ upgt_attach(device_t dev) struct upgt_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; struct usb_attach_arg *uaa = device_get_ivars(dev); - uint8_t bands, iface_index = UPGT_IFACE_INDEX; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index = UPGT_IFACE_INDEX; int error; sc->sc_dev = dev; @@ -337,10 +338,10 @@ upgt_attach(device_t dev) | IEEE80211_C_WPA /* 802.11i */ ; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); - ieee80211_init_channels(ic, NULL, &bands); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_raw_xmit = upgt_raw_xmit; diff --git a/sys/dev/usb/wlan/if_ural.c b/sys/dev/usb/wlan/if_ural.c index 4d84e5acb7c7..328b0a2df251 100644 --- a/sys/dev/usb/wlan/if_ural.c +++ b/sys/dev/usb/wlan/if_ural.c @@ -424,7 +424,8 @@ ural_attach(device_t self) struct usb_attach_arg *uaa = device_get_ivars(self); struct ural_softc *sc = device_get_softc(self); struct ieee80211com *ic = &sc->sc_ic; - uint8_t iface_index, bands; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index; int error; device_set_usb_desc(self); @@ -473,12 +474,12 @@ ural_attach(device_t self) | IEEE80211_C_WPA /* 802.11i */ ; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); if (sc->rf_rev == RAL_RF_5222) - setbit(&bands, IEEE80211_MODE_11A); - ieee80211_init_channels(ic, NULL, &bands); + setbit(bands, IEEE80211_MODE_11A); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_update_promisc = ural_update_promisc; diff --git a/sys/dev/usb/wlan/if_urtw.c b/sys/dev/usb/wlan/if_urtw.c index 105fd9daf72d..0f7b4d95b477 100644 --- a/sys/dev/usb/wlan/if_urtw.c +++ b/sys/dev/usb/wlan/if_urtw.c @@ -785,7 +785,8 @@ urtw_attach(device_t dev) struct urtw_softc *sc = device_get_softc(dev); struct usb_attach_arg *uaa = device_get_ivars(dev); struct ieee80211com *ic = &sc->sc_ic; - uint8_t bands, iface_index = URTW_IFACE_INDEX; /* XXX */ + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index = URTW_IFACE_INDEX; /* XXX */ uint16_t n_setup; uint32_t data; usb_error_t error; @@ -876,10 +877,10 @@ urtw_attach(device_t dev) IEEE80211_C_BGSCAN | /* capable of bg scanning */ IEEE80211_C_WPA; /* 802.11i */ - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); - ieee80211_init_channels(ic, NULL, &bands); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_raw_xmit = urtw_raw_xmit; diff --git a/sys/dev/usb/wlan/if_urtwn.c b/sys/dev/usb/wlan/if_urtwn.c index 73eda59dbac6..13f3926b2ee2 100644 --- a/sys/dev/usb/wlan/if_urtwn.c +++ b/sys/dev/usb/wlan/if_urtwn.c @@ -439,7 +439,7 @@ urtwn_attach(device_t self) struct usb_attach_arg *uaa = device_get_ivars(self); struct urtwn_softc *sc = device_get_softc(self); struct ieee80211com *ic = &sc->sc_ic; - uint8_t bands; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; int error; device_set_usb_desc(self); @@ -525,10 +525,10 @@ urtwn_attach(device_t self) IEEE80211_CRYPTO_TKIP | IEEE80211_CRYPTO_AES_CCM; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); - ieee80211_init_channels(ic, NULL, &bands); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_raw_xmit = urtwn_raw_xmit; diff --git a/sys/dev/usb/wlan/if_zyd.c b/sys/dev/usb/wlan/if_zyd.c index d23f306dc373..4463fc6777cd 100644 --- a/sys/dev/usb/wlan/if_zyd.c +++ b/sys/dev/usb/wlan/if_zyd.c @@ -334,7 +334,8 @@ zyd_attach(device_t dev) struct usb_attach_arg *uaa = device_get_ivars(dev); struct zyd_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; - uint8_t iface_index, bands; + uint8_t bands[howmany(IEEE80211_MODE_MAX, 8)]; + uint8_t iface_index; int error; if (uaa->info.bcdDevice < 0x4330) { @@ -387,10 +388,10 @@ zyd_attach(device_t dev) | IEEE80211_C_WPA /* 802.11i */ ; - bands = 0; - setbit(&bands, IEEE80211_MODE_11B); - setbit(&bands, IEEE80211_MODE_11G); - ieee80211_init_channels(ic, NULL, &bands); + memset(bands, 0, sizeof(bands)); + setbit(bands, IEEE80211_MODE_11B); + setbit(bands, IEEE80211_MODE_11G); + ieee80211_init_channels(ic, NULL, bands); ieee80211_ifattach(ic); ic->ic_raw_xmit = zyd_raw_xmit; From ca1c0252225af6f3c38c6ae23ca9580216cfc4e9 Mon Sep 17 00:00:00 2001 From: Devin Teske Date: Thu, 7 Jan 2016 18:50:02 +0000 Subject: [PATCH 37/68] Increase maximum buffer size for `-x cmd' value MFC after: 3 days X-MFC-to: stable/10 --- lib/libdpv/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libdpv/util.h b/lib/libdpv/util.h index 7bb3b189039b..5f646a63fc14 100644 --- a/lib/libdpv/util.h +++ b/lib/libdpv/util.h @@ -41,7 +41,7 @@ #define PATH_SHELL "/bin/sh" #endif -#define CMDBUFMAX 4096 +#define CMDBUFMAX 65536 __BEGIN_DECLS int shell_spawn_pipecmd(const char *_cmd, const char *_label, pid_t *_pid); From 25e85b1fbcfdd9c10c2a1c32bbbdd9cb33139e4b Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 19:19:23 +0000 Subject: [PATCH 38/68] Don't install /usr/include/stand.h twice after r293040. Only install it from lib/libstand. Sponsored by: EMC / Isilon Storage Division --- lib/libstand/Makefile | 2 +- sys/boot/libstand32/Makefile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile index ee8087be3ea6..c85b694f3e7e 100644 --- a/lib/libstand/Makefile +++ b/lib/libstand/Makefile @@ -17,7 +17,7 @@ LIBC_SRC= ${LIBSTAND_SRC}/../libc LIB= stand NO_PIC= -INCS= stand.h +INCS?= stand.h MAN?= libstand.3 WARNS?= 0 diff --git a/sys/boot/libstand32/Makefile b/sys/boot/libstand32/Makefile index d1c9ba2f6d85..66798d75e44f 100644 --- a/sys/boot/libstand32/Makefile +++ b/sys/boot/libstand32/Makefile @@ -10,6 +10,7 @@ LIBSTAND_CPUARCH=${MACHINE_CPUARCH} .endif LIBC_SRC= ${LIBSTAND_SRC}/../libc INTERNALLIB= +INCS= MAN= .PATH: ${LIBSTAND_SRC} From 63c612de72ce8f4e4d9dfb2bf47143ede1ad144a Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 19:37:11 +0000 Subject: [PATCH 39/68] Always try to upgrade to bmake if not already using it. This is mostly targetting stable/10 which requires bmake to build and has issues upgrading from <10. MFC after: 1 week Sponsored by: EMC / Isilon Storage Division PR: 198062 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 836097b42389..acb061bf8a74 100644 --- a/Makefile +++ b/Makefile @@ -205,7 +205,7 @@ _TARGET_ARCH?= ${MACHINE_ARCH} # The user can define ALWAYS_CHECK_MAKE to have this check performed # for all targets. # -.if defined(ALWAYS_CHECK_MAKE) +.if defined(ALWAYS_CHECK_MAKE) || !defined(.PARSEDIR) ${TGTS}: upgrade_checks .else buildworld: upgrade_checks From 0e42ee5dd8c2a9938415c1225fba0c383547d9a5 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 7 Jan 2016 19:47:26 +0000 Subject: [PATCH 40/68] Move amd64 metadata.h to x86 and share with i386 MFC after: 1 week --- sys/amd64/include/metadata.h | 57 ++---------------------------------- sys/i386/include/metadata.h | 37 ++--------------------- sys/x86/include/metadata.h | 57 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 88 deletions(-) create mode 100644 sys/x86/include/metadata.h diff --git a/sys/amd64/include/metadata.h b/sys/amd64/include/metadata.h index e13eba0c7e48..98d0272fd4cc 100644 --- a/sys/amd64/include/metadata.h +++ b/sys/amd64/include/metadata.h @@ -1,57 +1,6 @@ /*- - * Copyright (c) 2003 Peter Wemm - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ + * This file is in the public domain. */ +/* $FreeBSD$ */ -#ifndef _MACHINE_METADATA_H_ -#define _MACHINE_METADATA_H_ - -#define MODINFOMD_SMAP 0x1001 -#define MODINFOMD_SMAP_XATTR 0x1002 -#define MODINFOMD_DTBP 0x1003 -#define MODINFOMD_EFI_MAP 0x1004 -#define MODINFOMD_EFI_FB 0x1005 -#define MODINFOMD_MODULEP 0x1006 - -struct efi_map_header { - uint64_t memory_size; - uint64_t descriptor_size; - uint32_t descriptor_version; -}; - -struct efi_fb { - uint64_t fb_addr; - uint64_t fb_size; - uint32_t fb_height; - uint32_t fb_width; - uint32_t fb_stride; - uint32_t fb_mask_red; - uint32_t fb_mask_green; - uint32_t fb_mask_blue; - uint32_t fb_mask_reserved; -}; - -#endif /* !_MACHINE_METADATA_H_ */ +#include diff --git a/sys/i386/include/metadata.h b/sys/i386/include/metadata.h index 9003c15c3f81..98d0272fd4cc 100644 --- a/sys/i386/include/metadata.h +++ b/sys/i386/include/metadata.h @@ -1,37 +1,6 @@ /*- - * Copyright (c) 2003 Peter Wemm - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ + * This file is in the public domain. */ +/* $FreeBSD$ */ -#ifndef _MACHINE_METADATA_H_ -#define _MACHINE_METADATA_H_ - -#define MODINFOMD_SMAP 0x1001 -#define MODINFOMD_SMAP_XATTR 0x1002 -#define MODINFOMD_DTBP 0x1003 -#define MODINFOMD_MODULEP 0x1006 - -#endif /* !_MACHINE_METADATA_H_ */ +#include diff --git a/sys/x86/include/metadata.h b/sys/x86/include/metadata.h new file mode 100644 index 000000000000..e13eba0c7e48 --- /dev/null +++ b/sys/x86/include/metadata.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2003 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_METADATA_H_ +#define _MACHINE_METADATA_H_ + +#define MODINFOMD_SMAP 0x1001 +#define MODINFOMD_SMAP_XATTR 0x1002 +#define MODINFOMD_DTBP 0x1003 +#define MODINFOMD_EFI_MAP 0x1004 +#define MODINFOMD_EFI_FB 0x1005 +#define MODINFOMD_MODULEP 0x1006 + +struct efi_map_header { + uint64_t memory_size; + uint64_t descriptor_size; + uint32_t descriptor_version; +}; + +struct efi_fb { + uint64_t fb_addr; + uint64_t fb_size; + uint32_t fb_height; + uint32_t fb_width; + uint32_t fb_stride; + uint32_t fb_mask_red; + uint32_t fb_mask_green; + uint32_t fb_mask_blue; + uint32_t fb_mask_reserved; +}; + +#endif /* !_MACHINE_METADATA_H_ */ From e3ebb821185cbb08e0bb4329eaa12325ae4ea058 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 19:58:23 +0000 Subject: [PATCH 41/68] DIRDEPS_BUILD: Update dependencies. Sponsored by: EMC / Isilon Storage Division --- lib/libmd/Makefile.depend | 3 +++ sys/boot/libstand32/Makefile.depend | 1 - sys/boot/userboot/test/Makefile.depend | 1 - usr.bin/kdump/Makefile.depend | 3 --- usr.bin/nfsstat/Makefile.depend | 2 -- usr.sbin/jls/Makefile.depend | 2 ++ usr.sbin/sesutil/Makefile.depend | 1 + 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/libmd/Makefile.depend b/lib/libmd/Makefile.depend index 00038a0b92d0..e3acaaf0f445 100644 --- a/lib/libmd/Makefile.depend +++ b/lib/libmd/Makefile.depend @@ -33,6 +33,9 @@ sha1hl.po: sha1hl.c sha256hl.So: sha256hl.c sha256hl.o: sha256hl.c sha256hl.po: sha256hl.c +sha384hl.So: sha384hl.c +sha384hl.o: sha384hl.c +sha384hl.po: sha384hl.c sha512hl.So: sha512hl.c sha512hl.o: sha512hl.c sha512hl.po: sha512hl.c diff --git a/sys/boot/libstand32/Makefile.depend b/sys/boot/libstand32/Makefile.depend index dae5bcdc5da3..57cd80c479e6 100644 --- a/sys/boot/libstand32/Makefile.depend +++ b/sys/boot/libstand32/Makefile.depend @@ -6,7 +6,6 @@ DIRDEPS = \ include/arpa \ include/xlocale \ lib/libbz2 \ - lib/libstand \ .include diff --git a/sys/boot/userboot/test/Makefile.depend b/sys/boot/userboot/test/Makefile.depend index a5da8fda10c4..3646e2e2b1af 100644 --- a/sys/boot/userboot/test/Makefile.depend +++ b/sys/boot/userboot/test/Makefile.depend @@ -8,7 +8,6 @@ DIRDEPS = \ include/xlocale \ lib/${CSU_DIR} \ lib/libc \ - lib/libc_nonshared \ lib/libcompiler_rt \ diff --git a/usr.bin/kdump/Makefile.depend b/usr.bin/kdump/Makefile.depend index f86656e4c92b..83a2492bdfb9 100644 --- a/usr.bin/kdump/Makefile.depend +++ b/usr.bin/kdump/Makefile.depend @@ -6,7 +6,6 @@ DIRDEPS = \ gnu/lib/libgcc \ include \ include/arpa \ - include/rpc \ include/xlocale \ lib/${CSU_DIR} \ lib/libc \ @@ -20,8 +19,6 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -ioctl.o: ioctl.c -ioctl.po: ioctl.c kdump.o: kdump_subr.h kdump.o: linux32_syscalls.c kdump.o: linux_syscalls.c diff --git a/usr.bin/nfsstat/Makefile.depend b/usr.bin/nfsstat/Makefile.depend index 34582cd083a2..3646e2e2b1af 100644 --- a/usr.bin/nfsstat/Makefile.depend +++ b/usr.bin/nfsstat/Makefile.depend @@ -9,8 +9,6 @@ DIRDEPS = \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ - lib/libelf \ - lib/libkvm \ .include diff --git a/usr.sbin/jls/Makefile.depend b/usr.sbin/jls/Makefile.depend index 4131fa752579..50e6f23c947a 100644 --- a/usr.sbin/jls/Makefile.depend +++ b/usr.sbin/jls/Makefile.depend @@ -11,6 +11,8 @@ DIRDEPS = \ lib/libc \ lib/libcompiler_rt \ lib/libjail \ + lib/libutil \ + lib/libxo \ .include diff --git a/usr.sbin/sesutil/Makefile.depend b/usr.sbin/sesutil/Makefile.depend index 3646e2e2b1af..6002005509a1 100644 --- a/usr.sbin/sesutil/Makefile.depend +++ b/usr.sbin/sesutil/Makefile.depend @@ -9,6 +9,7 @@ DIRDEPS = \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ + lib/libsbuf \ .include From 48ce5d4cac7dc3c2160ea69dc550e218fbc0e697 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 7 Jan 2016 20:08:02 +0000 Subject: [PATCH 42/68] Provide yet another KPI for cdev creation, make_dev_s(9). Immediate problem fixed by the new KPI is the long-standing race between device creation and assignments to cdev->si_drv1 and cdev->si_drv2, which allows the window where cdevsw methods might be called with si_drv1,2 fields not yet set. Devices typically checked for NULL and returned spurious errors to usermode, and often left some methods unchecked. The new function interface is designed to be extensible, which should allow to add more features to make_dev_s(9) without inventing yet another name for function to create devices, while maintaining KPI and even KBI backward-compatibility. Reviewed by: hps, jhb Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D4746 --- share/man/man9/Makefile | 3 +- share/man/man9/make_dev.9 | 180 ++++++++++++++++++++++++++++---------- sys/kern/kern_conf.c | 98 ++++++++++++++++----- sys/sys/conf.h | 30 +++++-- 4 files changed, 235 insertions(+), 76 deletions(-) diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 3cd6f7f70585..def293651b41 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1013,7 +1013,8 @@ MLINKS+=make_dev.9 destroy_dev.9 \ make_dev.9 make_dev_alias_p.9 \ make_dev.9 make_dev_cred.9 \ make_dev.9 make_dev_credf.9 \ - make_dev.9 make_dev_p.9 + make_dev.9 make_dev_p.9 \ + make_dev.9 make_dev_s.9 MLINKS+=malloc.9 free.9 \ malloc.9 MALLOC_DECLARE.9 \ malloc.9 MALLOC_DEFINE.9 \ diff --git a/share/man/man9/make_dev.9 b/share/man/man9/make_dev.9 index 78345fab4a1d..0c53e8d3916b 100644 --- a/share/man/man9/make_dev.9 +++ b/share/man/man9/make_dev.9 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd Dec 22, 2012 +.Dd Jan 3, 2016 .Dt MAKE_DEV 9 .Os .Sh NAME @@ -32,6 +32,7 @@ .Nm make_dev_cred , .Nm make_dev_credf , .Nm make_dev_p , +.Nm make_dev_s , .Nm make_dev_alias , .Nm make_dev_alias_p , .Nm destroy_dev , @@ -45,16 +46,10 @@ and DEVFS registration for devices .Sh SYNOPSIS .In sys/param.h .In sys/conf.h -.Ft struct cdev * -.Fn make_dev "struct cdevsw *cdevsw" "int unit" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... -.Ft struct cdev * -.Fn make_dev_cred "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... -.Ft struct cdev * -.Fn make_dev_credf "int flags" "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... +.Ft void +.Fn make_dev_args_init "struct make_dev_args *args" .Ft int -.Fn make_dev_p "int flags" "struct cdev **cdev" "struct cdevsw *devsw" "struct ucred *cr" "uid_t uid" "gid_t gid" "int mode" "const char *fmt" ... -.Ft struct cdev * -.Fn make_dev_alias "struct cdev *pdev" "const char *fmt" ... +.Fn make_dev_s "struct make_dev_args *args" "struct cdev **cdev" "const char *fmt" ... .Ft int .Fn make_dev_alias_p "int flags" "struct cdev **cdev" "struct cdev *pdev" "const char *fmt" ... .Ft void @@ -67,12 +62,26 @@ and DEVFS registration for devices .Fn destroy_dev_drain "struct cdevsw *csw" .Ft void .Fn dev_depends "struct cdev *pdev" "struct cdev *cdev" +.Pp +LEGACY INTERFACES +.Ft struct cdev * +.Fn make_dev "struct cdevsw *cdevsw" "int unit" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... +.Ft struct cdev * +.Fn make_dev_cred "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... +.Ft struct cdev * +.Fn make_dev_credf "int flags" "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ... +.Ft int +.Fn make_dev_p "int flags" "struct cdev **cdev" "struct cdevsw *devsw" "struct ucred *cr" "uid_t uid" "gid_t gid" "int mode" "const char *fmt" ... +.Ft struct cdev * +.Fn make_dev_alias "struct cdev *pdev" "const char *fmt" ... .Sh DESCRIPTION The -.Fn make_dev_credf +.Fn make_dev_s function creates a .Fa cdev -structure for a new device. +structure for a new device, which is returned into the +.Fa cdev +argument. It also notifies .Xr devfs 5 of the presence of the new device, that causes corresponding nodes @@ -80,10 +89,34 @@ to be created. Besides this, a .Xr devctl 4 notification is sent. -The device will be owned by -.Va uid , +The function takes the structure +.Va struct make_dev_args args , +which specifies the parameters for the device creation: +.Pp +.Bd -literal -offset indent -compact +struct make_dev_args { + size_t mda_size; + int mda_flags; + struct cdevsw *mda_devsw; + struct ucred *mda_cr; + uid_t mda_uid; + gid_t mda_gid; + int mda_mode; + int mda_unit; + void *mda_si_drv1; + void *mda_si_drv2; +}; +.Ed +Before use and filling with the desired values, the structure must be +initialized by the +.Fn make_dev_args_init +function, which ensures that future kernel interface expansion does +not affect driver source code or binary interface. +.Pp +The created device will be owned by +.Va args.mda_uid , with the group ownership as -.Va gid . +.Va args.mda_gid . The name is the expansion of .Va fmt and following arguments as @@ -97,7 +130,7 @@ mount point and may contain slash .Ql / characters to denote subdirectories. The permissions of the file specified in -.Va perms +.Va args.mda_mode are defined in .In sys/stat.h : .Pp @@ -126,29 +159,28 @@ are defined in .Ed .Pp The -.Va cr +.Va args.mda_cr argument specifies credentials that will be stored in the .Fa si_cred member of the initialized .Fa struct cdev . +.Pp The -.Va flags +.Va args.mda_flags argument alters the operation of -.Fn make_dev_credf -or -.Fn make_dev_p . +.Fn make_dev_s. The following values are currently accepted: .Pp -.Bl -tag -width "MAKEDEV_CHECKNAME" -compact -offset indent -.It MAKEDEV_REF +.Bl -tag -width "It Dv MAKEDEV_CHECKNAME" -compact -offset indent +.It Dv MAKEDEV_REF reference the created device -.It MAKEDEV_NOWAIT +.It Dv MAKEDEV_NOWAIT do not sleep, the call may fail -.It MAKEDEV_WAITOK +.It Dv MAKEDEV_WAITOK allow the function to sleep to satisfy malloc -.It MAKEDEV_ETERNAL +.It Dv MAKEDEV_ETERNAL created device will be never destroyed -.It MAKEDEV_CHECKNAME +.It Dv MAKEDEV_CHECKNAME return an error if the device name is invalid or already exists .El .Pp @@ -189,10 +221,49 @@ For the convenience, use the flag for the code that can be compiled into kernel or loaded (and unloaded) as loadable module. .Pp -A panic will occur if the MAKEDEV_CHECKNAME flag is not specified +A panic will occur if the +.Dv MAKEDEV_CHECKNAME +flag is not specified and the device name is invalid or already exists. .Pp The +.Fn make_dev_p +use of the form +.Bd -literal -offset indent +struct cdev *dev; +int res; +res = make_dev_p(flags, &dev, cdevsw, cred, uid, gid, perms, name); +.Ed +is equivalent to the code +.Bd -literal -offset indent +struct cdev *dev; +struct make_dev_args args; +int res; + +make_dev_args_init(&args); +args.mda_flags = flags; +args.mda_devsw = cdevsw; +args.mda_cred = cred; +args.mda_uid = uid; +args.mda_gid = gid; +args.mda_mode = perms; +res = make_dev_s(&args, &dev, name); +.Ed +.Pp +Similarly, the +.Fn make_dev_credf +function call is equivalent to +.Bd -literal -offset indent + (void) make_dev_s(&args, &dev, name); +.Ed +In other words, +.Fn make_dev_credf +does not allow the caller to obtain the return value, and in +kernels compiled with the +.Va INVARIANTS +options, the function asserts that the device creation succeeded. +.Pp +The .Fn make_dev_cred function is equivalent to the call .Bd -literal -offset indent @@ -207,45 +278,55 @@ make_dev_credf(0, cdevsw, unit, NULL, uid, gid, perms, fmt, ...); .Ed .Pp The -.Fn make_dev_p -function is similar to -.Fn make_dev_credf -but it may return an error number and takes a pointer to the resulting -.Ft *cdev -as an argument. -.Pp -The -.Fn make_dev_alias +.Fn make_dev_alias_p function takes the returned .Ft cdev from .Fn make_dev and makes another (aliased) name for this device. It is an error to call -.Fn make_dev_alias +.Fn make_dev_alias_p prior to calling .Fn make_dev . .Pp -.Fn make_dev_alias_p +The +.Fn make_dev_alias function is similar to .Fn make_dev_alias -but it takes a pointer to the resulting +but it returns the resulting aliasing .Ft *cdev -as an argument and may return an error. +and may not return an error. .Pp The .Fa cdev returned by -.Fn make_dev +.Fn make_dev_s and -.Fn make_dev_alias +.Fn make_dev_alias_p has two fields, .Fa si_drv1 and .Fa si_drv2 , that are available to store state. Both fields are of type -.Ft void * . +.Ft void * , +and can be initialized simultaneously with the +.Va cdev +allocation by filling +.Va args.mda_si_drv1 +and +.Va args.mda_si_drv2 +members of the +.Fn make_dev_s +argument structure, or filled after the +.Va cdev +is allocated, if using legacy interfaces. +In the latter case, the driver should handle the race of +accessing uninitialized +.Va si_drv1 +and +.Va si_drv2 +itself. These are designed to replace the .Fa unit argument to @@ -331,8 +412,10 @@ unload until is actually finished for all of them. .Sh RETURN VALUES If successful, +.Fn make_dev_s +and .Fn make_dev_p -will return 0, otherwise it will return an error. +will return 0, otherwise they will return an error. If successful, .Fn make_dev_credf will return a valid @@ -341,10 +424,11 @@ pointer, otherwise it will return .Dv NULL . .Sh ERRORS The +.Fn make_dev_s , .Fn make_dev_p and .Fn make_dev_alias_p -call will fail and the device will be not registered if: +calls will fail and the device will be not registered if: .Bl -tag -width Er .It Bq Er ENOMEM The @@ -403,3 +487,7 @@ The function .Fn make_dev_p first appeared in .Fx 8.2 . +The function +.Fn make_dev_s +first appeared in +.Fx 11.0 . diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index 20565420704d..ea68a6dea9a8 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -566,22 +566,26 @@ notify_destroy(struct cdev *dev) } static struct cdev * -newdev(struct cdevsw *csw, int unit, struct cdev *si) +newdev(struct make_dev_args *args, struct cdev *si) { struct cdev *si2; + struct cdevsw *csw; mtx_assert(&devmtx, MA_OWNED); + csw = args->mda_devsw; if (csw->d_flags & D_NEEDMINOR) { /* We may want to return an existing device */ LIST_FOREACH(si2, &csw->d_devs, si_list) { - if (dev2unit(si2) == unit) { + if (dev2unit(si2) == args->mda_unit) { dev_free_devlocked(si); return (si2); } } } - si->si_drv0 = unit; + si->si_drv0 = args->mda_unit; si->si_devsw = csw; + si->si_drv1 = args->mda_si_drv1; + si->si_drv2 = args->mda_si_drv2; LIST_INSERT_HEAD(&csw->d_devs, si, si_list); return (si); } @@ -737,33 +741,46 @@ prep_devname(struct cdev *dev, const char *fmt, va_list ap) return (0); } +void +make_dev_args_init_impl(struct make_dev_args *args, size_t sz) +{ + + bzero(args, sz); + args->mda_size = sz; +} + static int -make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit, - struct ucred *cr, uid_t uid, gid_t gid, int mode, const char *fmt, - va_list ap) +make_dev_sv(struct make_dev_args *args1, struct cdev **dres, + const char *fmt, va_list ap) { struct cdev *dev, *dev_new; + struct make_dev_args args; int res; - KASSERT((flags & MAKEDEV_WAITOK) == 0 || (flags & MAKEDEV_NOWAIT) == 0, - ("make_dev_credv: both WAITOK and NOWAIT specified")); - dev_new = devfs_alloc(flags); + bzero(&args, sizeof(args)); + if (sizeof(args) < args1->mda_size) + return (EINVAL); + bcopy(args1, &args, args1->mda_size); + KASSERT((args.mda_flags & MAKEDEV_WAITOK) == 0 || + (args.mda_flags & MAKEDEV_NOWAIT) == 0, + ("make_dev_sv: both WAITOK and NOWAIT specified")); + dev_new = devfs_alloc(args.mda_flags); if (dev_new == NULL) return (ENOMEM); dev_lock(); - res = prep_cdevsw(devsw, flags); + res = prep_cdevsw(args.mda_devsw, args.mda_flags); if (res != 0) { dev_unlock(); devfs_free(dev_new); return (res); } - dev = newdev(devsw, unit, dev_new); + dev = newdev(&args, dev_new); if ((dev->si_flags & SI_NAMED) == 0) { res = prep_devname(dev, fmt, ap); if (res != 0) { - if ((flags & MAKEDEV_CHECKNAME) == 0) { + if ((args.mda_flags & MAKEDEV_CHECKNAME) == 0) { panic( - "make_dev_credv: bad si_name (error=%d, si_name=%s)", + "make_dev_sv: bad si_name (error=%d, si_name=%s)", res, dev->si_name); } if (dev == dev_new) { @@ -775,9 +792,9 @@ make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit, return (res); } } - if (flags & MAKEDEV_REF) + if ((args.mda_flags & MAKEDEV_REF) != 0) dev_refl(dev); - if (flags & MAKEDEV_ETERNAL) + if ((args.mda_flags & MAKEDEV_ETERNAL) != 0) dev->si_flags |= SI_ETERNAL; if (dev->si_flags & SI_CHEAPCLONE && dev->si_flags & SI_NAMED) { @@ -792,24 +809,55 @@ make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit, } KASSERT(!(dev->si_flags & SI_NAMED), ("make_dev() by driver %s on pre-existing device (min=%x, name=%s)", - devsw->d_name, dev2unit(dev), devtoname(dev))); + args.mda_devsw->d_name, dev2unit(dev), devtoname(dev))); dev->si_flags |= SI_NAMED; - if (cr != NULL) - dev->si_cred = crhold(cr); - dev->si_uid = uid; - dev->si_gid = gid; - dev->si_mode = mode; + if (args.mda_cr != NULL) + dev->si_cred = crhold(args.mda_cr); + dev->si_uid = args.mda_uid; + dev->si_gid = args.mda_gid; + dev->si_mode = args.mda_mode; devfs_create(dev); clean_unrhdrl(devfs_inos); dev_unlock_and_free(); - notify_create(dev, flags); + notify_create(dev, args.mda_flags); *dres = dev; return (0); } +int +make_dev_s(struct make_dev_args *args, struct cdev **dres, + const char *fmt, ...) +{ + va_list ap; + int res; + + va_start(ap, fmt); + res = make_dev_sv(args, dres, fmt, ap); + va_end(ap); + return (res); +} + +static int +make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit, + struct ucred *cr, uid_t uid, gid_t gid, int mode, const char *fmt, + va_list ap) +{ + struct make_dev_args args; + + make_dev_args_init(&args); + args.mda_flags = flags; + args.mda_devsw = devsw; + args.mda_cr = cr; + args.mda_uid = uid; + args.mda_gid = gid; + args.mda_mode = mode; + args.mda_unit = unit; + return (make_dev_sv(&args, dres, fmt, ap)); +} + struct cdev * make_dev(struct cdevsw *devsw, int unit, uid_t uid, gid_t gid, int mode, const char *fmt, ...) @@ -1247,6 +1295,7 @@ clone_create(struct clonedevs **cdp, struct cdevsw *csw, int *up, { struct clonedevs *cd; struct cdev *dev, *ndev, *dl, *de; + struct make_dev_args args; int unit, low, u; KASSERT(*cdp != NULL, @@ -1298,7 +1347,10 @@ clone_create(struct clonedevs **cdp, struct cdevsw *csw, int *up, } if (unit == -1) unit = low & CLONE_UNITMASK; - dev = newdev(csw, unit | extra, ndev); + make_dev_args_init(&args); + args.mda_unit = unit | extra; + args.mda_devsw = csw; + dev = newdev(&args, ndev); if (dev->si_flags & SI_CLONELIST) { printf("dev %p (%s) is on clonelist\n", dev, dev->si_name); printf("unit=%d, low=%d, extra=0x%x\n", unit, low, extra); diff --git a/sys/sys/conf.h b/sys/sys/conf.h index 4681acd192f6..a0dbc724fc5e 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -226,6 +226,28 @@ void clone_cleanup(struct clonedevs **); #define CLONE_FLAG0 (CLONE_UNITMASK + 1) int clone_create(struct clonedevs **, struct cdevsw *, int *unit, struct cdev **dev, int extra); +#define MAKEDEV_REF 0x01 +#define MAKEDEV_WHTOUT 0x02 +#define MAKEDEV_NOWAIT 0x04 +#define MAKEDEV_WAITOK 0x08 +#define MAKEDEV_ETERNAL 0x10 +#define MAKEDEV_CHECKNAME 0x20 +struct make_dev_args { + size_t mda_size; + int mda_flags; + struct cdevsw *mda_devsw; + struct ucred *mda_cr; + uid_t mda_uid; + gid_t mda_gid; + int mda_mode; + int mda_unit; + void *mda_si_drv1; + void *mda_si_drv2; +}; +void make_dev_args_init_impl(struct make_dev_args *_args, size_t _sz); +#define make_dev_args_init(a) \ + make_dev_args_init_impl((a), sizeof(struct make_dev_args)) + int count_dev(struct cdev *_dev); void delist_dev(struct cdev *_dev); void destroy_dev(struct cdev *_dev); @@ -245,12 +267,6 @@ struct cdev *make_dev(struct cdevsw *_devsw, int _unit, uid_t _uid, gid_t _gid, struct cdev *make_dev_cred(struct cdevsw *_devsw, int _unit, struct ucred *_cr, uid_t _uid, gid_t _gid, int _perms, const char *_fmt, ...) __printflike(7, 8); -#define MAKEDEV_REF 0x01 -#define MAKEDEV_WHTOUT 0x02 -#define MAKEDEV_NOWAIT 0x04 -#define MAKEDEV_WAITOK 0x08 -#define MAKEDEV_ETERNAL 0x10 -#define MAKEDEV_CHECKNAME 0x20 struct cdev *make_dev_credf(int _flags, struct cdevsw *_devsw, int _unit, struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode, @@ -258,6 +274,8 @@ struct cdev *make_dev_credf(int _flags, int make_dev_p(int _flags, struct cdev **_cdev, struct cdevsw *_devsw, struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode, const char *_fmt, ...) __printflike(8, 9); +int make_dev_s(struct make_dev_args *_args, struct cdev **_cdev, + const char *_fmt, ...) __printflike(3, 4); struct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...) __printflike(2, 3); int make_dev_alias_p(int _flags, struct cdev **_cdev, struct cdev *_pdev, From 0de14554627f9847d19bb5cddd8f85ebee792b1b Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 7 Jan 2016 20:15:09 +0000 Subject: [PATCH 43/68] Convert tty common code to use make_dev_s(). Tty.c was untypical in that it handled the si_drv1 issue consistently and correctly, by always checking for si_drv1 being non-NULL and sleeping if NULL. The removed code also illustrated unneeded complications in drivers which are eliminated by the use of new KPI. Reviewed by: hps, jhb Discussed with: bde Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D4746 --- sys/kern/tty.c | 99 ++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index d9d0ccea288a..9695312a5f75 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -237,14 +237,10 @@ static int ttydev_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { struct tty *tp; - int error = 0; - - while ((tp = dev->si_drv1) == NULL) { - error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1); - if (error != EWOULDBLOCK) - return (error); - } + int error; + tp = dev->si_drv1; + error = 0; tty_lock(tp); if (tty_gone(tp)) { /* Device is already gone. */ @@ -755,13 +751,10 @@ static int ttyil_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { struct tty *tp; - int error = 0; + int error; - while ((tp = dev->si_drv1) == NULL) { - error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1); - if (error != EWOULDBLOCK) - return (error); - } + tp = dev->si_drv1; + error = 0; tty_lock(tp); if (tty_gone(tp)) error = ENODEV; @@ -1189,6 +1182,7 @@ tty_makedevf(struct tty *tp, struct ucred *cred, int flags, const char *fmt, ...) { va_list ap; + struct make_dev_args args; struct cdev *dev, *init, *lock, *cua, *cinit, *clock; const char *prefix = "tty"; char name[SPECNAMELEN - 3]; /* for "tty" and "cua". */ @@ -1221,71 +1215,72 @@ tty_makedevf(struct tty *tp, struct ucred *cred, int flags, flags |= MAKEDEV_CHECKNAME; /* Master call-in device. */ - error = make_dev_p(flags, &dev, &ttydev_cdevsw, cred, uid, gid, mode, - "%s%s", prefix, name); - if (error) + make_dev_args_init(&args); + args.mda_flags = flags; + args.mda_devsw = &ttydev_cdevsw; + args.mda_cr = cred; + args.mda_uid = uid; + args.mda_gid = gid; + args.mda_mode = mode; + args.mda_si_drv1 = tp; + error = make_dev_s(&args, &dev, "%s%s", prefix, name); + if (error != 0) return (error); - dev->si_drv1 = tp; - wakeup(&dev->si_drv1); tp->t_dev = dev; init = lock = cua = cinit = clock = NULL; /* Slave call-in devices. */ if (tp->t_flags & TF_INITLOCK) { - error = make_dev_p(flags, &init, &ttyil_cdevsw, cred, uid, - gid, mode, "%s%s.init", prefix, name); - if (error) + args.mda_devsw = &ttyil_cdevsw; + args.mda_unit = TTYUNIT_INIT; + args.mda_si_drv1 = tp; + args.mda_si_drv2 = &tp->t_termios_init_in; + error = make_dev_s(&args, &init, "%s%s.init", prefix, name); + if (error != 0) goto fail; dev_depends(dev, init); - dev2unit(init) = TTYUNIT_INIT; - init->si_drv1 = tp; - wakeup(&init->si_drv1); - init->si_drv2 = &tp->t_termios_init_in; - error = make_dev_p(flags, &lock, &ttyil_cdevsw, cred, uid, - gid, mode, "%s%s.lock", prefix, name); - if (error) + args.mda_unit = TTYUNIT_LOCK; + args.mda_si_drv2 = &tp->t_termios_lock_in; + error = make_dev_s(&args, &lock, "%s%s.lock", prefix, name); + if (error != 0) goto fail; dev_depends(dev, lock); - dev2unit(lock) = TTYUNIT_LOCK; - lock->si_drv1 = tp; - wakeup(&lock->si_drv1); - lock->si_drv2 = &tp->t_termios_lock_in; } /* Call-out devices. */ if (tp->t_flags & TF_CALLOUT) { - error = make_dev_p(flags, &cua, &ttydev_cdevsw, cred, - UID_UUCP, GID_DIALER, 0660, "cua%s", name); - if (error) + make_dev_args_init(&args); + args.mda_flags = flags; + args.mda_devsw = &ttydev_cdevsw; + args.mda_cr = cred; + args.mda_uid = UID_UUCP; + args.mda_gid = GID_DIALER; + args.mda_mode = 0660; + args.mda_unit = TTYUNIT_CALLOUT; + args.mda_si_drv1 = tp; + error = make_dev_s(&args, &cua, "cua%s", name); + if (error != 0) goto fail; dev_depends(dev, cua); - dev2unit(cua) = TTYUNIT_CALLOUT; - cua->si_drv1 = tp; - wakeup(&cua->si_drv1); /* Slave call-out devices. */ if (tp->t_flags & TF_INITLOCK) { - error = make_dev_p(flags, &cinit, &ttyil_cdevsw, cred, - UID_UUCP, GID_DIALER, 0660, "cua%s.init", name); - if (error) + args.mda_devsw = &ttyil_cdevsw; + args.mda_unit = TTYUNIT_CALLOUT | TTYUNIT_INIT; + args.mda_si_drv2 = &tp->t_termios_init_out; + error = make_dev_s(&args, &cinit, "cua%s.init", name); + if (error != 0) goto fail; dev_depends(dev, cinit); - dev2unit(cinit) = TTYUNIT_CALLOUT | TTYUNIT_INIT; - cinit->si_drv1 = tp; - wakeup(&cinit->si_drv1); - cinit->si_drv2 = &tp->t_termios_init_out; - error = make_dev_p(flags, &clock, &ttyil_cdevsw, cred, - UID_UUCP, GID_DIALER, 0660, "cua%s.lock", name); - if (error) + args.mda_unit = TTYUNIT_CALLOUT | TTYUNIT_LOCK; + args.mda_si_drv2 = &tp->t_termios_lock_out; + error = make_dev_s(&args, &clock, "cua%s.lock", name); + if (error != 0) goto fail; dev_depends(dev, clock); - dev2unit(clock) = TTYUNIT_CALLOUT | TTYUNIT_LOCK; - clock->si_drv1 = tp; - wakeup(&clock->si_drv1); - clock->si_drv2 = &tp->t_termios_lock_out; } } From ee1988938c413b3173b5d537f5d8f2021c7fbd24 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 7 Jan 2016 20:22:55 +0000 Subject: [PATCH 44/68] Convert sys/cam to use make_dev_s(). Reviewed by: hps, jhb Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D4746 --- sys/cam/ctl/ctl.c | 15 ++++++++-- sys/cam/scsi/scsi_ch.c | 24 +++++++++------ sys/cam/scsi/scsi_enc.c | 28 +++++++++--------- sys/cam/scsi/scsi_pass.c | 32 ++++++++++---------- sys/cam/scsi/scsi_pt.c | 27 ++++++++++------- sys/cam/scsi/scsi_sa.c | 63 +++++++++++++++++++++++++--------------- sys/cam/scsi/scsi_sg.c | 29 +++++++++--------- 7 files changed, 129 insertions(+), 89 deletions(-) diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index ac886cae200b..4fdaa05d2e5b 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -1778,6 +1778,7 @@ ctl_ha_role_sysctl(SYSCTL_HANDLER_ARGS) static int ctl_init(void) { + struct make_dev_args args; struct ctl_softc *softc; void *other_pool; int i, error; @@ -1785,9 +1786,17 @@ ctl_init(void) softc = control_softc = malloc(sizeof(*control_softc), M_DEVBUF, M_WAITOK | M_ZERO); - softc->dev = make_dev(&ctl_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, - "cam/ctl"); - softc->dev->si_drv1 = softc; + make_dev_args_init(&args); + args.mda_devsw = &ctl_cdevsw; + args.mda_uid = UID_ROOT; + args.mda_gid = GID_OPERATOR; + args.mda_mode = 0600; + args.mda_si_drv1 = softc; + error = make_dev_s(&args, &softc->dev, "cam/ctl"); + if (error != 0) { + free(control_softc, M_DEVBUF); + return (error); + } sysctl_ctx_init(&softc->sysctl_ctx); softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx, diff --git a/sys/cam/scsi/scsi_ch.c b/sys/cam/scsi/scsi_ch.c index bc398e7f924f..137128dfd1a3 100644 --- a/sys/cam/scsi/scsi_ch.c +++ b/sys/cam/scsi/scsi_ch.c @@ -372,6 +372,8 @@ chregister(struct cam_periph *periph, void *arg) struct ch_softc *softc; struct ccb_getdev *cgd; struct ccb_pathinq cpi; + struct make_dev_args args; + int error; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -431,11 +433,20 @@ chregister(struct cam_periph *periph, void *arg) /* Register the device */ - softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT, - GID_OPERATOR, 0600, "%s%d", periph->periph_name, - periph->unit_number); + make_dev_args_init(&args); + args.mda_devsw = &ch_cdevsw; + args.mda_unit = periph->unit_number; + args.mda_uid = UID_ROOT; + args.mda_gid = GID_OPERATOR; + args.mda_mode = 0600; + args.mda_si_drv1 = periph; + error = make_dev_s(&args, &softc->dev, "%s%d", periph->periph_name, + periph->unit_number); cam_periph_lock(periph); - softc->dev->si_drv1 = periph; + if (error != 0) { + cam_periph_release_locked(periph); + return (CAM_REQ_CMP_ERR); + } /* * Add an async callback so that we get @@ -507,8 +518,6 @@ chclose(struct cdev *dev, int flag, int fmt, struct thread *td) struct mtx *mtx; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return(ENXIO); mtx = cam_periph_mtx(periph); mtx_lock(mtx); @@ -754,9 +763,6 @@ chioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td) int error; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return(ENXIO); - cam_periph_lock(periph); CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n")); diff --git a/sys/cam/scsi/scsi_enc.c b/sys/cam/scsi/scsi_enc.c index 844f25aef572..a450cd077156 100644 --- a/sys/cam/scsi/scsi_enc.c +++ b/sys/cam/scsi/scsi_enc.c @@ -264,10 +264,6 @@ enc_open(struct cdev *dev, int flags, int fmt, struct thread *td) int error = 0; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) { - return (ENXIO); - } - if (cam_periph_acquire(periph) != CAM_REQ_CMP) return (ENXIO); @@ -302,8 +298,6 @@ enc_close(struct cdev *dev, int flag, int fmt, struct thread *td) struct mtx *mtx; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); mtx = cam_periph_mtx(periph); mtx_lock(mtx); @@ -364,9 +358,6 @@ enc_ioctl(struct cdev *dev, u_long cmd, caddr_t arg_addr, int flag, addr = NULL; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering encioctl\n")); cam_periph_lock(periph); @@ -905,6 +896,7 @@ enc_ctor(struct cam_periph *periph, void *arg) enc_softc_t *enc; struct ccb_getdev *cgd; char *tname; + struct make_dev_args args; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -987,12 +979,20 @@ enc_ctor(struct cam_periph *periph, void *arg) return (CAM_REQ_CMP_ERR); } - enc->enc_dev = make_dev(&enc_cdevsw, periph->unit_number, - UID_ROOT, GID_OPERATOR, 0600, "%s%d", - periph->periph_name, periph->unit_number); - + make_dev_args_init(&args); + args.mda_devsw = &enc_cdevsw; + args.mda_unit = periph->unit_number; + args.mda_uid = UID_ROOT; + args.mda_gid = GID_OPERATOR; + args.mda_mode = 0600; + args.mda_si_drv1 = periph; + err = make_dev_s(&args, &enc->enc_dev, "%s%d", periph->periph_name, + periph->unit_number); cam_periph_lock(periph); - enc->enc_dev->si_drv1 = periph; + if (err != 0) { + cam_periph_release_locked(periph); + return (CAM_REQ_CMP_ERR); + } enc->enc_flags |= ENC_FLAG_INITIALIZED; diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c index 09cda5b85690..c0c313e82bd8 100644 --- a/sys/cam/scsi/scsi_pass.c +++ b/sys/cam/scsi/scsi_pass.c @@ -548,7 +548,8 @@ passregister(struct cam_periph *periph, void *arg) struct pass_softc *softc; struct ccb_getdev *cgd; struct ccb_pathinq cpi; - int no_tags; + struct make_dev_args args; + int error, no_tags; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -648,9 +649,20 @@ passregister(struct cam_periph *periph, void *arg) } /* Register the device */ - softc->dev = make_dev(&pass_cdevsw, periph->unit_number, - UID_ROOT, GID_OPERATOR, 0600, "%s%d", - periph->periph_name, periph->unit_number); + make_dev_args_init(&args); + args.mda_devsw = &pass_cdevsw; + args.mda_unit = periph->unit_number; + args.mda_uid = UID_ROOT; + args.mda_gid = GID_OPERATOR; + args.mda_mode = 0600; + args.mda_si_drv1 = periph; + error = make_dev_s(&args, &softc->dev, "%s%d", periph->periph_name, + periph->unit_number); + if (error != 0) { + cam_periph_lock(periph); + cam_periph_release_locked(periph); + return (CAM_REQ_CMP_ERR); + } /* * Hold a reference to the periph before we create the physical @@ -664,7 +676,6 @@ passregister(struct cam_periph *periph, void *arg) } cam_periph_lock(periph); - softc->dev->si_drv1 = periph; TASK_INIT(&softc->add_physpath_task, /*priority*/0, pass_add_physpath, periph); @@ -754,8 +765,6 @@ passclose(struct cdev *dev, int flag, int fmt, struct thread *td) struct mtx *mtx; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); mtx = cam_periph_mtx(periph); mtx_lock(mtx); @@ -1759,9 +1768,6 @@ passdoioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread uint32_t priority; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return(ENXIO); - cam_periph_lock(periph); softc = (struct pass_softc *)periph->softc; @@ -2068,9 +2074,6 @@ passpoll(struct cdev *dev, int poll_events, struct thread *td) int revents; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - softc = (struct pass_softc *)periph->softc; revents = poll_events & (POLLOUT | POLLWRNORM); @@ -2095,9 +2098,6 @@ passkqfilter(struct cdev *dev, struct knote *kn) struct pass_softc *softc; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - softc = (struct pass_softc *)periph->softc; kn->kn_hook = (caddr_t)periph; diff --git a/sys/cam/scsi/scsi_pt.c b/sys/cam/scsi/scsi_pt.c index 15240da32784..e9d24377c920 100644 --- a/sys/cam/scsi/scsi_pt.c +++ b/sys/cam/scsi/scsi_pt.c @@ -173,9 +173,6 @@ ptclose(struct cdev *dev, int flag, int fmt, struct thread *td) struct pt_softc *softc; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - softc = (struct pt_softc *)periph->softc; cam_periph_lock(periph); @@ -252,6 +249,8 @@ ptctor(struct cam_periph *periph, void *arg) struct pt_softc *softc; struct ccb_getdev *cgd; struct ccb_pathinq cpi; + struct make_dev_args args; + int error; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -282,6 +281,21 @@ ptctor(struct cam_periph *periph, void *arg) xpt_action((union ccb *)&cpi); cam_periph_unlock(periph); + + make_dev_args_init(&args); + args.mda_devsw = &pt_cdevsw; + args.mda_unit = periph->unit_number; + args.mda_uid = UID_ROOT; + args.mda_gid = GID_OPERATOR; + args.mda_mode = 0600; + args.mda_si_drv1 = periph; + error = make_dev_s(&args, &softc->dev, "%s%d", periph->periph_name, + periph->unit_number); + if (error != 0) { + cam_periph_lock(periph); + return (CAM_REQ_CMP_ERR); + } + softc->device_stats = devstat_new_entry("pt", periph->unit_number, 0, DEVSTAT_NO_BLOCKSIZE, @@ -289,11 +303,7 @@ ptctor(struct cam_periph *periph, void *arg) XPORT_DEVSTAT_TYPE(cpi.transport), DEVSTAT_PRIORITY_OTHER); - softc->dev = make_dev(&pt_cdevsw, periph->unit_number, UID_ROOT, - GID_OPERATOR, 0600, "%s%d", periph->periph_name, - periph->unit_number); cam_periph_lock(periph); - softc->dev->si_drv1 = periph; /* * Add async callbacks for bus reset and @@ -571,9 +581,6 @@ ptioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td) int error = 0; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return(ENXIO); - softc = (struct pt_softc *)periph->softc; cam_periph_lock(periph); diff --git a/sys/cam/scsi/scsi_sa.c b/sys/cam/scsi/scsi_sa.c index 6110b3d7adc3..149d06228455 100644 --- a/sys/cam/scsi/scsi_sa.c +++ b/sys/cam/scsi/scsi_sa.c @@ -731,9 +731,6 @@ saclose(struct cdev *dev, int flag, int fmt, struct thread *td) mode = SAMODE(dev); periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - cam_periph_lock(periph); softc = (struct sa_softc *)periph->softc; @@ -906,10 +903,6 @@ sastrategy(struct bio *bp) return; } periph = (struct cam_periph *)bp->bio_dev->si_drv1; - if (periph == NULL) { - biofinish(bp, NULL, ENXIO); - return; - } cam_periph_lock(periph); softc = (struct sa_softc *)periph->softc; @@ -1517,9 +1510,6 @@ saioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) spaceop = 0; /* shut up gcc */ periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - cam_periph_lock(periph); softc = (struct sa_softc *)periph->softc; @@ -2285,7 +2275,7 @@ saasync(void *callback_arg, u_int32_t code, static void sasetupdev(struct sa_softc *softc, struct cdev *dev) { - dev->si_drv1 = softc->periph; + dev->si_iosize_max = softc->maxio; dev->si_flags |= softc->si_flags; /* @@ -2347,8 +2337,10 @@ saregister(struct cam_periph *periph, void *arg) struct sa_softc *softc; struct ccb_getdev *cgd; struct ccb_pathinq cpi; + struct make_dev_args args; caddr_t match; char tmpstr[80]; + int error; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -2506,25 +2498,48 @@ saregister(struct cam_periph *periph, void *arg) return (CAM_REQ_CMP_ERR); } - softc->devs.ctl_dev = make_dev(&sa_cdevsw, SAMINOR(SA_CTLDEV, - SA_ATYPE_R), UID_ROOT, GID_OPERATOR, - 0660, "%s%d.ctl", periph->periph_name, periph->unit_number); + make_dev_args_init(&args); + args.mda_devsw = &sa_cdevsw; + args.mda_si_drv1 = softc->periph; + args.mda_uid = UID_ROOT; + args.mda_gid = GID_OPERATOR; + args.mda_mode = 0660; + + args.mda_unit = SAMINOR(SA_CTLDEV, SA_ATYPE_R); + error = make_dev_s(&args, &softc->devs.ctl_dev, "%s%d.ctl", + periph->periph_name, periph->unit_number); + if (error != 0) { + cam_periph_lock(periph); + return (CAM_REQ_CMP_ERR); + } sasetupdev(softc, softc->devs.ctl_dev); - softc->devs.r_dev = make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, - SA_ATYPE_R), UID_ROOT, GID_OPERATOR, - 0660, "%s%d", periph->periph_name, periph->unit_number); + args.mda_unit = SAMINOR(SA_NOT_CTLDEV, SA_ATYPE_R); + error = make_dev_s(&args, &softc->devs.r_dev, "%s%d", + periph->periph_name, periph->unit_number); + if (error != 0) { + cam_periph_lock(periph); + return (CAM_REQ_CMP_ERR); + } sasetupdev(softc, softc->devs.r_dev); - softc->devs.nr_dev = make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, - SA_ATYPE_NR), UID_ROOT, GID_OPERATOR, - 0660, "n%s%d", periph->periph_name, periph->unit_number); + args.mda_unit = SAMINOR(SA_NOT_CTLDEV, SA_ATYPE_NR); + error = make_dev_s(&args, &softc->devs.nr_dev, "n%s%d", + periph->periph_name, periph->unit_number); + if (error != 0) { + cam_periph_lock(periph); + return (CAM_REQ_CMP_ERR); + } sasetupdev(softc, softc->devs.nr_dev); - softc->devs.er_dev = make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, - SA_ATYPE_ER), UID_ROOT, GID_OPERATOR, - 0660, "e%s%d", periph->periph_name, periph->unit_number); - sasetupdev(softc, softc->devs.er_dev); + args.mda_unit = SAMINOR(SA_NOT_CTLDEV, SA_ATYPE_ER); + error = make_dev_s(&args, &softc->devs.er_dev, "e%s%d", + periph->periph_name, periph->unit_number); + if (error != 0) { + cam_periph_lock(periph); + return (CAM_REQ_CMP_ERR); + } + sasetupdev(softc, softc->devs.er_dev); cam_periph_lock(periph); diff --git a/sys/cam/scsi/scsi_sg.c b/sys/cam/scsi/scsi_sg.c index 3e130036ec02..ef83fc7c3cf1 100644 --- a/sys/cam/scsi/scsi_sg.c +++ b/sys/cam/scsi/scsi_sg.c @@ -300,7 +300,8 @@ sgregister(struct cam_periph *periph, void *arg) struct sg_softc *softc; struct ccb_getdev *cgd; struct ccb_pathinq cpi; - int no_tags; + struct make_dev_args args; + int no_tags, error; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -361,9 +362,20 @@ sgregister(struct cam_periph *periph, void *arg) } /* Register the device */ - softc->dev = make_dev(&sg_cdevsw, periph->unit_number, - UID_ROOT, GID_OPERATOR, 0600, "%s%d", - periph->periph_name, periph->unit_number); + make_dev_args_init(&args); + args.mda_devsw = &sg_cdevsw; + args.mda_unit = periph->unit_number; + args.mda_uid = UID_ROOT; + args.mda_gid = GID_OPERATOR; + args.mda_mode = 0600; + args.mda_si_drv1 = periph; + error = make_dev_s(&args, &softc->dev, "%s%d", + periph->periph_name, periph->unit_number); + if (error != 0) { + cam_periph_lock(periph); + cam_periph_release_locked(periph); + return (CAM_REQ_CMP_ERR); + } if (periph->unit_number < 26) { (void)make_dev_alias(softc->dev, "sg%c", periph->unit_number + 'a'); @@ -373,7 +385,6 @@ sgregister(struct cam_periph *periph, void *arg) (periph->unit_number % 26) + 'a'); } cam_periph_lock(periph); - softc->dev->si_drv1 = periph; /* * Add as async callback so that we get @@ -429,9 +440,6 @@ sgopen(struct cdev *dev, int flags, int fmt, struct thread *td) int error = 0; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - if (cam_periph_acquire(periph) != CAM_REQ_CMP) return (ENXIO); @@ -468,8 +476,6 @@ sgclose(struct cdev *dev, int flag, int fmt, struct thread *td) struct mtx *mtx; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); mtx = cam_periph_mtx(periph); mtx_lock(mtx); @@ -506,9 +512,6 @@ sgioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) int dir, error; periph = (struct cam_periph *)dev->si_drv1; - if (periph == NULL) - return (ENXIO); - cam_periph_lock(periph); softc = (struct sg_softc *)periph->softc; From 50dea2da1220badfc10a36d6850f03cb6506ad59 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 20:32:04 +0000 Subject: [PATCH 45/68] nvme: add hw.nvme.min_cpus_per_ioq tunable Due to FreeBSD system-wide limits on number of MSI-X vectors (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=199321), it may be desirable to allocate fewer than the maximum number of vectors for an NVMe device, in order to save vectors for other devices (usually Ethernet) that can take better advantage of them and may be probed after NVMe. This tunable is expressed in terms of minimum number of CPUs per I/O queue instead of max number of queues per controller, to allow for a more even distribution of CPUs per queue. This avoids cases where some number of CPUs have a dedicated queue, but other CPUs need to share queues. Ideally the PR referenced above will eventually be fixed and the mechanism implemented here becomes obsolete anyways. While here, fix a bug in the CPUs per I/O queue calculation to properly account for the admin queue's MSI-X vector. Reviewed by: gallatin MFC after: 3 days Sponsored by: Intel --- share/man/man4/nvme.4 | 18 +++++++++++++++--- sys/dev/nvme/nvme_ctrlr.c | 26 +++++++++++++++++++++----- sys/dev/nvme/nvme_sysctl.c | 6 +++++- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/share/man/man4/nvme.4 b/share/man/man4/nvme.4 index 068b006b954a..83ca8ae0066e 100644 --- a/share/man/man4/nvme.4 +++ b/share/man/man4/nvme.4 @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2012-2014 Intel Corporation +.\" Copyright (c) 2012-2016 Intel Corporation .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -33,7 +33,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 18, 2014 +.Dd January 7, 2016 .Dt NVME 4 .Os .Sh NAME @@ -89,7 +89,10 @@ not 0, and this driver follows that convention. By default, .Nm will create an I/O queue pair for each CPU, provided enough MSI-X vectors -can be allocated. +and NVMe queue pairs can be allocated. If not enough vectors or queue +pairs are available, nvme(4) will use a smaller number of queue pairs and +assign multiple CPUs per queue pair. +.Pp To force a single I/O queue pair shared by all CPUs, set the following tunable value in .Xr loader.conf 5 : @@ -97,6 +100,13 @@ tunable value in hw.nvme.per_cpu_io_queues=0 .Ed .Pp +To assign more than one CPU per I/O queue pair, thereby reducing the number +of MSI-X vectors consumed by the device, set the following tunable value in +.Xr loader.conf 5 : +.Bd -literal -offset indent +hw.nvme.min_cpus_per_ioq=X +.Ed +.Pp To force legacy interrupts for all .Nm driver instances, set the following tunable value in @@ -109,6 +119,8 @@ Note that use of INTx implies disabling of per-CPU I/O queue pairs. .Sh SYSCTL VARIABLES The following controller-level sysctls are currently implemented: .Bl -tag -width indent +.It Va dev.nvme.0.num_cpus_per_ioq +(R) Number of CPUs associated with each I/O queue pair. .It Va dev.nvme.0.int_coal_time (R/W) Interrupt coalescing timer period in microseconds. Set to 0 to disable. diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 151f02542626..6125894655f9 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -1,5 +1,5 @@ /*- - * Copyright (C) 2012-2015 Intel Corporation + * Copyright (C) 2012-2016 Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -978,13 +978,27 @@ nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr) { device_t dev; int per_cpu_io_queues; + int min_cpus_per_ioq; int num_vectors_requested, num_vectors_allocated; int num_vectors_available; dev = ctrlr->dev; + min_cpus_per_ioq = 1; + TUNABLE_INT_FETCH("hw.nvme.min_cpus_per_ioq", &min_cpus_per_ioq); + + if (min_cpus_per_ioq < 1) { + min_cpus_per_ioq = 1; + } else if (min_cpus_per_ioq > mp_ncpus) { + min_cpus_per_ioq = mp_ncpus; + } + per_cpu_io_queues = 1; TUNABLE_INT_FETCH("hw.nvme.per_cpu_io_queues", &per_cpu_io_queues); + if (per_cpu_io_queues == 0) { + min_cpus_per_ioq = mp_ncpus; + } + ctrlr->force_intx = 0; TUNABLE_INT_FETCH("hw.nvme.force_intx", &ctrlr->force_intx); @@ -1010,10 +1024,12 @@ nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr) return; } - if (per_cpu_io_queues) - ctrlr->num_cpus_per_ioq = NVME_CEILING(mp_ncpus, num_vectors_available + 1); - else - ctrlr->num_cpus_per_ioq = mp_ncpus; + /* + * Do not use all vectors for I/O queues - one must be saved for the + * admin queue. + */ + ctrlr->num_cpus_per_ioq = max(min_cpus_per_ioq, + NVME_CEILING(mp_ncpus, num_vectors_available - 1)); ctrlr->num_io_queues = NVME_CEILING(mp_ncpus, ctrlr->num_cpus_per_ioq); num_vectors_requested = ctrlr->num_io_queues + 1; diff --git a/sys/dev/nvme/nvme_sysctl.c b/sys/dev/nvme/nvme_sysctl.c index 8b991113fe40..08cd15e22570 100644 --- a/sys/dev/nvme/nvme_sysctl.c +++ b/sys/dev/nvme/nvme_sysctl.c @@ -1,5 +1,5 @@ /*- - * Copyright (C) 2012-2013 Intel Corporation + * Copyright (C) 2012-2016 Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -267,6 +267,10 @@ nvme_sysctl_initialize_ctrlr(struct nvme_controller *ctrlr) ctrlr_tree = device_get_sysctl_tree(ctrlr->dev); ctrlr_list = SYSCTL_CHILDREN(ctrlr_tree); + SYSCTL_ADD_UINT(ctrlr_ctx, ctrlr_list, OID_AUTO, "num_cpus_per_ioq", + CTLFLAG_RD, &ctrlr->num_cpus_per_ioq, 0, + "Number of CPUs assigned per I/O queue pair"); + SYSCTL_ADD_PROC(ctrlr_ctx, ctrlr_list, OID_AUTO, "int_coal_time", CTLTYPE_UINT | CTLFLAG_RW, ctrlr, 0, nvme_sysctl_int_coal_time, "IU", From 9c6b5d40eb0121ff354f454f83470f72131c14fa Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 20:35:26 +0000 Subject: [PATCH 46/68] nvme: replace NVME_CEILING macro with howmany() Suggested by: rpokala MFC after: 3 days --- sys/dev/nvme/nvme_ctrlr.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 6125894655f9..e400f52d84c3 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -42,12 +42,6 @@ __FBSDID("$FreeBSD$"); #include "nvme_private.h" -/* - * Used for calculating number of CPUs to assign to each core and number of I/O - * queues to allocate per controller. - */ -#define NVME_CEILING(num, div) ((((num) - 1) / (div)) + 1) - static void nvme_ctrlr_construct_and_submit_aer(struct nvme_controller *ctrlr, struct nvme_async_event_request *aer); static void nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr); @@ -152,7 +146,7 @@ nvme_ctrlr_construct_io_qpairs(struct nvme_controller *ctrlr) * a controller could theoretically support fewer I/O queues than * MSI-X vectors. So calculate again here just to be safe. */ - ctrlr->num_cpus_per_ioq = NVME_CEILING(mp_ncpus, ctrlr->num_io_queues); + ctrlr->num_cpus_per_ioq = howmany(mp_ncpus, ctrlr->num_io_queues); ctrlr->ioq = malloc(ctrlr->num_io_queues * sizeof(struct nvme_qpair), M_NVME, M_ZERO | M_WAITOK); @@ -1029,9 +1023,9 @@ nvme_ctrlr_setup_interrupts(struct nvme_controller *ctrlr) * admin queue. */ ctrlr->num_cpus_per_ioq = max(min_cpus_per_ioq, - NVME_CEILING(mp_ncpus, num_vectors_available - 1)); + howmany(mp_ncpus, num_vectors_available - 1)); - ctrlr->num_io_queues = NVME_CEILING(mp_ncpus, ctrlr->num_cpus_per_ioq); + ctrlr->num_io_queues = howmany(mp_ncpus, ctrlr->num_cpus_per_ioq); num_vectors_requested = ctrlr->num_io_queues + 1; num_vectors_allocated = num_vectors_requested; From f5b4d341044bd2c29fe13765adda01350d037703 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Thu, 7 Jan 2016 20:37:18 +0000 Subject: [PATCH 47/68] Obsolete inetd related files when WITHOUT_INETD is set Reviewed by: bapt Approved by: gnn MFC after: 1 week Sponsored by: Rubiconn Communications (Netgate) Differential Revision: https://reviews.freebsd.org/D4742 --- tools/build/mk/OptionalObsoleteFiles.inc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc index cb51987e1a6c..37f624efb952 100644 --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -2834,6 +2834,13 @@ OLD_FILES+=usr/share/man/man8/traceroute6.8.gz OLD_FILES+=rescue/ping6 .endif +.if ${MK_INETD} == no +OLD_FILES+=etc/rc.d/inetd +OLD_FILES+=usr/sbin/inetd +OLD_FILES+=usr/share/man/man5/inetd.conf.5.gz +OLD_FILES+=usr/share/man/man8/inetd.8.gz +.endif + .if ${MK_IPFILTER} == no OLD_FILES+=etc/periodic/security/510.ipfdenied OLD_FILES+=etc/periodic/security/610.ipf6denied From adba77a62e7254b58df4e32a5142e1ee3a062aa7 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 7 Jan 2016 20:48:24 +0000 Subject: [PATCH 48/68] sh: Ensure OPTIND=1 in subshell without forking does not affect outer env. Command substitutions containing a single simple command and here-document expansion are performed in a subshell environment, but may not fork. Any modified state of the shell environment should be restored afterward. The state that OPTIND=1 had been done was not saved and restored here. Note that the other parts of shellparam need not be saved and restored, since they are not modified in these situations (a fork is done before such modifications). --- bin/sh/eval.c | 7 +++++++ bin/sh/tests/builtins/Makefile | 1 + bin/sh/tests/builtins/getopts10.0 | 11 +++++++++++ 3 files changed, 19 insertions(+) create mode 100644 bin/sh/tests/builtins/getopts10.0 diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 46c00de75b99..5a3f8e71883b 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -496,10 +496,12 @@ exphere(union node *redir, struct arglist *fn) struct jmploc *savehandler; struct localvar *savelocalvars; int need_longjmp = 0; + unsigned char saveoptreset; redir->nhere.expdoc = ""; savelocalvars = localvars; localvars = NULL; + saveoptreset = shellparam.reset; forcelocal++; savehandler = handler; if (setjmp(jmploc.loc)) @@ -514,6 +516,7 @@ exphere(union node *redir, struct arglist *fn) forcelocal--; poplocalvars(); localvars = savelocalvars; + shellparam.reset = saveoptreset; if (need_longjmp) longjmp(handler->loc, 1); INTON; @@ -647,6 +650,7 @@ evalbackcmd(union node *n, struct backcmd *result) struct jmploc jmploc; struct jmploc *savehandler; struct localvar *savelocalvars; + unsigned char saveoptreset; result->fd = -1; result->buf = NULL; @@ -661,6 +665,7 @@ evalbackcmd(union node *n, struct backcmd *result) if (is_valid_fast_cmdsubst(n)) { savelocalvars = localvars; localvars = NULL; + saveoptreset = shellparam.reset; forcelocal++; savehandler = handler; if (setjmp(jmploc.loc)) { @@ -671,6 +676,7 @@ evalbackcmd(union node *n, struct backcmd *result) forcelocal--; poplocalvars(); localvars = savelocalvars; + shellparam.reset = saveoptreset; longjmp(handler->loc, 1); } } else { @@ -681,6 +687,7 @@ evalbackcmd(union node *n, struct backcmd *result) forcelocal--; poplocalvars(); localvars = savelocalvars; + shellparam.reset = saveoptreset; } else { if (pipe(pip) < 0) error("Pipe call failed: %s", strerror(errno)); diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index 63e6ab56514d..750e61569de0 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -95,6 +95,7 @@ FILES+= getopts6.0 FILES+= getopts7.0 FILES+= getopts8.0 getopts8.0.stdout FILES+= getopts9.0 getopts9.0.stdout +FILES+= getopts10.0 FILES+= hash1.0 hash1.0.stdout FILES+= hash2.0 hash2.0.stdout FILES+= hash3.0 hash3.0.stdout diff --git a/bin/sh/tests/builtins/getopts10.0 b/bin/sh/tests/builtins/getopts10.0 new file mode 100644 index 000000000000..a88e6ca3e85e --- /dev/null +++ b/bin/sh/tests/builtins/getopts10.0 @@ -0,0 +1,11 @@ +# $FreeBSD$ + +set -- -x arg +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +: $(: $((OPTIND = 1))) +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] From 1f2c92640755d4b95b7785b098b898e5e58db9ee Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Thu, 7 Jan 2016 20:52:35 +0000 Subject: [PATCH 49/68] Allow libnv to be built externally using GCC. GCC does not define _VA_LIST_DECLARED. It defines _VA_LIST_ and others. This was causing the prototype to not be defined and leading to an error later due to using nvlist_add_stringv(3) without a prototype in nvlist_add_stringf(3). This uses the same check as other va_list prototypes in the original change in r279438. --- sys/sys/nv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/sys/nv.h b/sys/sys/nv.h index a985b6d71121..fcea2b3ed966 100644 --- a/sys/sys/nv.h +++ b/sys/sys/nv.h @@ -146,7 +146,7 @@ void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value); void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value); void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value); void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4); -#ifdef _VA_LIST_DECLARED +#if !defined(_KERNEL) || defined(_VA_LIST_DECLARED) void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0); #endif void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value); From 042231951b17bd4b7f7fc00d0091066676a534b6 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 7 Jan 2016 21:16:44 +0000 Subject: [PATCH 50/68] ismt: fix ISMT_DESC_ADDR_RW macro Submitted by: Masanobu SAITOH MFC after: 3 days --- sys/dev/ismt/ismt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/dev/ismt/ismt.c b/sys/dev/ismt/ismt.c index dc90e3f07d41..3fbcfed0af62 100644 --- a/sys/dev/ismt/ismt.c +++ b/sys/dev/ismt/ismt.c @@ -72,7 +72,7 @@ __FBSDID("$FreeBSD$"); #define ISMT_DESC_LPR 0x80 /* Large Packet Received */ /* Macros */ -#define ISMT_DESC_ADDR_RW(addr, is_read) ((addr) | (is_read)) +#define ISMT_DESC_ADDR_RW(addr, is_read) ((addr << 1) | (is_read)) /* iSMT General Register address offsets (SMBBAR + ) */ #define ISMT_GR_GCTRL 0x000 /* General Control */ From 7135ca50c149b59b6490063d97ade66fe7b5bfef Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Thu, 7 Jan 2016 21:43:43 +0000 Subject: [PATCH 51/68] ext2fs: reading mmaped file in Ext4 causes panic Always call brelse(path.ep_bp), fixing reading EXT4 files using mmap(). Patch by Damjan Jovanovic. PR: 205938 MFC after: 1 week --- sys/fs/ext2fs/ext2_bmap.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sys/fs/ext2fs/ext2_bmap.c b/sys/fs/ext2fs/ext2_bmap.c index d144e926f0ba..7d4a88007a81 100644 --- a/sys/fs/ext2fs/ext2_bmap.c +++ b/sys/fs/ext2fs/ext2_bmap.c @@ -96,6 +96,7 @@ ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bnp, int *runp, int *runb) struct ext4_extent *ep; struct ext4_extent_path path = { .ep_bp = NULL }; daddr_t lbn; + int ret = 0; ip = VTOI(vp); fs = ip->i_e2fs; @@ -113,15 +114,21 @@ ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bnp, int *runp, int *runb) ext4_ext_find_extent(fs, ip, lbn, &path); ep = path.ep_ext; if (ep == NULL) - return (EIO); + ret = EIO; + else { + *bnp = fsbtodb(fs, lbn - ep->e_blk + + (ep->e_start_lo | (daddr_t)ep->e_start_hi << 32)); - *bnp = fsbtodb(fs, lbn - ep->e_blk + - (ep->e_start_lo | (daddr_t)ep->e_start_hi << 32)); + if (*bnp == 0) + *bnp = -1; + } - if (*bnp == 0) - *bnp = -1; + if (path.ep_bp != NULL) { + brelse(path.ep_bp); + path.ep_bp = NULL; + } - return (0); + return (ret); } /* From 0e50eefbd53961b0c25620cf7d09deaa02adb752 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 7 Jan 2016 21:46:07 +0000 Subject: [PATCH 52/68] sh: Add a test for 'cd -'. Redirect 'cd -' output to /dev/null since POSIX requires it to write the new directory name even if not interactive, but we currently only write it if interactive. --- bin/sh/tests/builtins/Makefile | 1 + bin/sh/tests/builtins/cd9.0 | 8 ++++++++ bin/sh/tests/builtins/cd9.0.stdout | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 bin/sh/tests/builtins/cd9.0 create mode 100644 bin/sh/tests/builtins/cd9.0.stdout diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index 750e61569de0..11240ca7dda8 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -48,6 +48,7 @@ FILES+= cd5.0 FILES+= cd6.0 FILES+= cd7.0 FILES+= cd8.0 +FILES+= cd9.0 cd9.0.stdout FILES+= command1.0 FILES+= command2.0 FILES+= command3.0 diff --git a/bin/sh/tests/builtins/cd9.0 b/bin/sh/tests/builtins/cd9.0 new file mode 100644 index 000000000000..78bcdff9a933 --- /dev/null +++ b/bin/sh/tests/builtins/cd9.0 @@ -0,0 +1,8 @@ +# $FreeBSD$ + +cd /dev +cd /bin +cd - >/dev/null +pwd +cd - >/dev/null +pwd diff --git a/bin/sh/tests/builtins/cd9.0.stdout b/bin/sh/tests/builtins/cd9.0.stdout new file mode 100644 index 000000000000..dac16a768d5e --- /dev/null +++ b/bin/sh/tests/builtins/cd9.0.stdout @@ -0,0 +1,2 @@ +/dev +/bin From eb581ab54a97527c04f0c7fe186d48b80b4a04ca Mon Sep 17 00:00:00 2001 From: Devin Teske Date: Thu, 7 Jan 2016 22:13:17 +0000 Subject: [PATCH 53/68] Bump copyright (forgotten part of r293340) MFC after: 3 days X-MFC-to: stable/10 X-MFC-with: r293340 --- lib/libdpv/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libdpv/util.h b/lib/libdpv/util.h index 5f646a63fc14..d746cb6cc401 100644 --- a/lib/libdpv/util.h +++ b/lib/libdpv/util.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2013-2014 Devin Teske + * Copyright (c) 2013-2016 Devin Teske * All rights reserved. * * Redistribution and use in source and binary forms, with or without From 1502e36346e5a499b67f0de80338f65b9877841a Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Thu, 7 Jan 2016 23:02:15 +0000 Subject: [PATCH 54/68] ioat(4): Add ioat_acquire_reserve() KPI ioat_acquire_reserve() is an extended version of ioat_acquire(). It allows users to reserve space in the channel for some number of descriptors. If this succeeds, it guarantees that at least submission of N valid descriptors will succeed. Sponsored by: EMC / Isilon Storage Division --- share/man/man4/ioat.4 | 12 +++++++++++- sys/dev/ioat/ioat.c | 15 +++++++++++++++ sys/dev/ioat/ioat.h | 15 ++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/share/man/man4/ioat.4 b/share/man/man4/ioat.4 index 59e17e6e0e99..10f2663ed8f0 100644 --- a/share/man/man4/ioat.4 +++ b/share/man/man4/ioat.4 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 5, 2016 +.Dd January 7, 2016 .Dt IOAT 4 .Os .Sh NAME @@ -73,6 +73,8 @@ In .Fn ioat_get_max_coalesce_period "bus_dmaengine_t dmaengine" .Ft void .Fn ioat_acquire "bus_dmaengine_t dmaengine" +.Ft int +.Fn ioat_acquire_reserve "bus_dmaengine_t dmaengine" "uint32_t n" "int mflags" .Ft void .Fn ioat_release "bus_dmaengine_t dmaengine" .Ft struct bus_dmadesc * @@ -178,6 +180,14 @@ When the user wants to offload a copy, they will first the .Ar bus_dmaengine_t object for exclusive access to enqueue operations on that channel. +Optionally, the user can reserve space by using +.Fn ioat_acquire_reserve +instead. +If +.Fn ioat_acquire_reserve +succeeds, there is guaranteed to be room for +.Fa N +new operations in the internal ring buffer. Then, they will submit one or more operations using .Fn ioat_blockfill , .Fn ioat_copy , diff --git a/sys/dev/ioat/ioat.c b/sys/dev/ioat/ioat.c index c93d1b594185..7f14c3ff40ec 100644 --- a/sys/dev/ioat/ioat.c +++ b/sys/dev/ioat/ioat.c @@ -789,6 +789,21 @@ ioat_acquire(bus_dmaengine_t dmaengine) CTR0(KTR_IOAT, __func__); } +int +ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags) +{ + struct ioat_softc *ioat; + int error; + + ioat = to_ioat_softc(dmaengine); + ioat_acquire(dmaengine); + + error = ioat_reserve_space(ioat, n, mflags); + if (error != 0) + ioat_release(dmaengine); + return (error); +} + void ioat_release(bus_dmaengine_t dmaengine) { diff --git a/sys/dev/ioat/ioat.h b/sys/dev/ioat/ioat.h index f5d5fada7045..64f97830a2d6 100644 --- a/sys/dev/ioat/ioat.h +++ b/sys/dev/ioat/ioat.h @@ -96,12 +96,25 @@ uint16_t ioat_get_max_coalesce_period(bus_dmaengine_t dmaengine); /* * Acquire must be called before issuing an operation to perform. Release is - * called after. Multiple operations can be issued within the context of one + * called after. Multiple operations can be issued within the context of one * acquire and release */ void ioat_acquire(bus_dmaengine_t dmaengine); void ioat_release(bus_dmaengine_t dmaengine); +/* + * Acquire_reserve can be called to ensure there is room for N descriptors. If + * it succeeds, the next N valid operations will successfully enqueue. + * + * It may fail with: + * - ENXIO if the channel is in an errored state, or the driver is being + * unloaded + * - EAGAIN if mflags included M_NOWAIT + * + * On failure, the caller does not hold the dmaengine. + */ +int ioat_acquire_reserve(bus_dmaengine_t dmaengine, unsigned n, int mflags); + /* * Issue a blockfill operation. The 64-bit pattern 'fillpattern' is written to * 'len' physically contiguous bytes at 'dst'. From 3da40d4a6b80386c9fe890bb2f6577bca834c17e Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 7 Jan 2016 23:13:20 +0000 Subject: [PATCH 55/68] sh: Reduce size of options table. --- bin/sh/expand.c | 4 +- bin/sh/options.c | 37 ++++++++++--------- bin/sh/options.h | 95 +++++++++++++++++++++++------------------------- bin/sh/var.c | 6 +-- 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 59ba5490f7fe..c661541d4918 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -951,8 +951,8 @@ varvalue(const char *name, int quoted, int subtype, int flag, case '-': p = buf; for (i = 0 ; i < NSHORTOPTS ; i++) { - if (optlist[i].val) - *p++ = optlist[i].letter; + if (optval[i]) + *p++ = optletter[i]; } *p = '\0'; strtodest(buf, flag, subtype, quoted, dst); diff --git a/bin/sh/options.c b/bin/sh/options.c index d1312005371c..606ccfb88efd 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -91,7 +91,7 @@ procargs(int argc, char **argv) if (argc > 0) argptr++; for (i = 0; i < NOPTS; i++) - optlist[i].val = 2; + optval[i] = 2; privileged = (getuid() != geteuid() || getgid() != getegid()); options(1); if (*argptr == NULL && minusc == NULL) @@ -104,8 +104,8 @@ procargs(int argc, char **argv) if (mflag == 2) mflag = iflag; for (i = 0; i < NOPTS; i++) - if (optlist[i].val == 2) - optlist[i].val = 0; + if (optval[i] == 2) + optval[i] = 0; arg0 = argv[0]; if (sflag == 0 && minusc == NULL) { scriptname = *argptr++; @@ -250,26 +250,29 @@ static void minus_o(char *name, int val) { int i; + const unsigned char *on; + size_t len; if (name == NULL) { if (val) { /* "Pretty" output. */ out1str("Current option settings\n"); - for (i = 0; i < NOPTS; i++) - out1fmt("%-16s%s\n", optlist[i].name, - optlist[i].val ? "on" : "off"); + for (i = 0, on = optname; i < NOPTS; i++, on += *on + 1) + out1fmt("%-16.*s%s\n", *on, on + 1, + optval[i] ? "on" : "off"); } else { /* Output suitable for re-input to shell. */ - for (i = 0; i < NOPTS; i++) - out1fmt("%s %co %s%s", + for (i = 0, on = optname; i < NOPTS; i++, on += *on + 1) + out1fmt("%s %co %.*s%s", i % 6 == 0 ? "set" : "", - optlist[i].val ? '-' : '+', - optlist[i].name, + optval[i] ? '-' : '+', + *on, on + 1, i % 6 == 5 || i == NOPTS - 1 ? "\n" : ""); } } else { - for (i = 0; i < NOPTS; i++) - if (equal(name, optlist[i].name)) { + len = strlen(name); + for (i = 0, on = optname; i < NOPTS; i++, on += *on + 1) + if (*on == len && memcmp(on + 1, name, len) == 0) { setoptionbyindex(i, val); return; } @@ -281,18 +284,18 @@ minus_o(char *name, int val) static void setoptionbyindex(int idx, int val) { - if (optlist[idx].letter == 'p' && !val && privileged) { + if (optletter[idx] == 'p' && !val && privileged) { if (setgid(getgid()) == -1) error("setgid"); if (setuid(getuid()) == -1) error("setuid"); } - optlist[idx].val = val; + optval[idx] = val; if (val) { /* #%$ hack for ksh semantics */ - if (optlist[idx].letter == 'V') + if (optletter[idx] == 'V') Eflag = 0; - else if (optlist[idx].letter == 'E') + else if (optletter[idx] == 'E') Vflag = 0; } } @@ -303,7 +306,7 @@ setoption(int flag, int val) int i; for (i = 0; i < NSHORTOPTS; i++) - if (optlist[i].letter == flag) { + if (optletter[i] == flag) { setoptionbyindex(i, val); return; } diff --git a/bin/sh/options.h b/bin/sh/options.h index b5cd67f4dea6..d997e6f50146 100644 --- a/bin/sh/options.h +++ b/bin/sh/options.h @@ -45,60 +45,57 @@ struct shparam { -#define eflag optlist[0].val -#define fflag optlist[1].val -#define Iflag optlist[2].val -#define iflag optlist[3].val -#define mflag optlist[4].val -#define nflag optlist[5].val -#define sflag optlist[6].val -#define xflag optlist[7].val -#define vflag optlist[8].val -#define Vflag optlist[9].val -#define Eflag optlist[10].val -#define Cflag optlist[11].val -#define aflag optlist[12].val -#define bflag optlist[13].val -#define uflag optlist[14].val -#define privileged optlist[15].val -#define Tflag optlist[16].val -#define Pflag optlist[17].val -#define hflag optlist[18].val -#define nologflag optlist[19].val +#define eflag optval[0] +#define fflag optval[1] +#define Iflag optval[2] +#define iflag optval[3] +#define mflag optval[4] +#define nflag optval[5] +#define sflag optval[6] +#define xflag optval[7] +#define vflag optval[8] +#define Vflag optval[9] +#define Eflag optval[10] +#define Cflag optval[11] +#define aflag optval[12] +#define bflag optval[13] +#define uflag optval[14] +#define privileged optval[15] +#define Tflag optval[16] +#define Pflag optval[17] +#define hflag optval[18] +#define nologflag optval[19] #define NSHORTOPTS 19 #define NOPTS 20 -struct optent { - const char *name; - const char letter; - char val; -}; - -extern struct optent optlist[NOPTS]; +extern char optval[NOPTS]; +extern const char optletter[NSHORTOPTS]; #ifdef DEFINE_OPTIONS -struct optent optlist[NOPTS] = { - { "errexit", 'e', 0 }, - { "noglob", 'f', 0 }, - { "ignoreeof", 'I', 0 }, - { "interactive",'i', 0 }, - { "monitor", 'm', 0 }, - { "noexec", 'n', 0 }, - { "stdin", 's', 0 }, - { "xtrace", 'x', 0 }, - { "verbose", 'v', 0 }, - { "vi", 'V', 0 }, - { "emacs", 'E', 0 }, - { "noclobber", 'C', 0 }, - { "allexport", 'a', 0 }, - { "notify", 'b', 0 }, - { "nounset", 'u', 0 }, - { "privileged", 'p', 0 }, - { "trapsasync", 'T', 0 }, - { "physical", 'P', 0 }, - { "trackall", 'h', 0 }, - { "nolog", '\0', 0 }, -}; +char optval[NOPTS]; +const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh"; +static const unsigned char optname[] = + "\007errexit" + "\006noglob" + "\011ignoreeof" + "\013interactive" + "\007monitor" + "\006noexec" + "\005stdin" + "\006xtrace" + "\007verbose" + "\002vi" + "\005emacs" + "\011noclobber" + "\011allexport" + "\006notify" + "\007nounset" + "\012privileged" + "\012trapsasync" + "\010physical" + "\010trackall" + "\005nolog" +; #endif diff --git a/bin/sh/var.c b/bin/sh/var.c index c124a5d51acf..d4013618ccd9 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -754,8 +754,8 @@ mklocal(char *name) INTOFF; lvp = ckmalloc(sizeof (struct localvar)); if (name[0] == '-' && name[1] == '\0') { - lvp->text = ckmalloc(sizeof optlist); - memcpy(lvp->text, optlist, sizeof optlist); + lvp->text = ckmalloc(sizeof optval); + memcpy(lvp->text, optval, sizeof optval); vp = NULL; } else { vp = find_var(name, &vpp, NULL); @@ -797,7 +797,7 @@ poplocalvars(void) localvars = lvp->next; vp = lvp->vp; if (vp == NULL) { /* $- saved */ - memcpy(optlist, lvp->text, sizeof optlist); + memcpy(optval, lvp->text, sizeof optval); ckfree(lvp->text); optschanged(); } else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) { From d83ed77082732928a4ca100773341d342a0d8bcf Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 8 Jan 2016 00:05:28 +0000 Subject: [PATCH 56/68] Setup /pkg as a spot for pkg to operate. This is for testing purposes only. You need to remount / rw and export TMPDIR=/pkg/tmp. pkg will then work. It's slow though: 15 minutes to pkg install git on an RPi 2 with a decently fast SD card. Since this is for testing, we set DEFAULT_ALWAYS_YES and ASSUME_ALWAYS_YES to YES. --- tools/tools/nanobsd/embedded/common | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/tools/nanobsd/embedded/common b/tools/tools/nanobsd/embedded/common index 63479117adf4..a1d401a03782 100644 --- a/tools/tools/nanobsd/embedded/common +++ b/tools/tools/nanobsd/embedded/common @@ -449,6 +449,28 @@ typical_embedded ( ) ( ) customize_cmd typical_embedded +fix_pkg ( ) ( + chdir ${NANO_WORLDDIR} + mkdir -p pkg + mkdir -p pkg/db + mkdir -p pkg/cache + mkdir -p pkg/tmp # Needed for pkg bootstrap + mkdir -p usr/local/etc # Will get moved to local/etc + ( + echo 'PKG_DBDIR = "/pkg/db"' + echo 'PKG_CACHEDIR = "/pkg/cache"' + echo 'DEFAULT_ALWAYS_YES = "yes"' + echo 'ASSUME_ALWAYS_YES = "yes"' + ) >> usr/local/etc/pkg.conf + [ -z ${NANO_NOPRIV_BUILD} ] || ( + echo "./pkg type=dir uname=root gname=wheel mode=0755" + echo "./pkg/cache type=dir uname=root gname=wheel mode=0755" + echo "./pkg/db type=dir uname=root gname=wheel mode=0755" + echo "./pkg/tmp type=dir uname=root gname=wheel mode=0755" + ) >> ${NANO_METALOG} +) +customize_cmd fix_pkg + save_build ( ) ( VERSION_FILE=${NANO_WORLDDIR}/etc/version if [ "${SVNREVISION}" = "${REVISION}" ]; then From 45b2ffd09e172d07515e9dd34fac120df815dfe8 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 8 Jan 2016 00:05:47 +0000 Subject: [PATCH 57/68] Make sure that the /set directive gets put at the top of the file, instead of in sort order. Slash sorts after period. --- tools/tools/nanobsd/defaults.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/tools/nanobsd/defaults.sh b/tools/tools/nanobsd/defaults.sh index 9bc177910230..3534ba248244 100755 --- a/tools/tools/nanobsd/defaults.sh +++ b/tools/tools/nanobsd/defaults.sh @@ -500,10 +500,9 @@ fixup_before_diskimage ( ) ( if [ -n "${NANO_METALOG}" ]; then pprint 2 "Fixing metalog" cp ${NANO_METALOG} ${NANO_METALOG}.pre - (echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" && - cat ${NANO_METALOG}.pre) | \ - ${NANO_TOOLS}/mtree-dedup.awk | \ - sed -e 's/ size=[0-9][0-9]*//' | sort > ${NANO_METALOG} + echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" > ${NANO_METALOG} + cat ${NANO_METALOG}.pre | ${NANO_TOOLS}/mtree-dedup.awk | \ + sed -e 's/ size=[0-9][0-9]*//' | sort >> ${NANO_METALOG} fi ) From b873436a30729e357a67082260439172fa2a0b50 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 8 Jan 2016 00:56:41 +0000 Subject: [PATCH 58/68] Revert r293201, r293202 (rtld: populate DT_DEBUG iff DYNAMIC segment is writable) It turns out MIPS binaries may have other oddities that can trigger a fault at startup. PR: 206017 Reported by: ray --- libexec/rtld-elf/rtld.c | 6 ++---- libexec/rtld-elf/rtld.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 424f2eafd7ce..ad5d359452d4 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -1144,13 +1144,13 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath, * is mapped read-only. DT_MIPS_RLD_MAP is used instead. */ +#ifndef __mips__ case DT_DEBUG: - if (!obj->writable_dynamic) - break; if (!early) dbg("Filling in DT_DEBUG entry"); ((Elf_Dyn*)dynp)->d_un.d_ptr = (Elf_Addr) &r_debug; break; +#endif case DT_FLAGS: if (dynp->d_un.d_val & DF_ORIGIN) @@ -1331,8 +1331,6 @@ digest_phdr(const Elf_Phdr *phdr, int phnum, caddr_t entry, const char *path) break; case PT_DYNAMIC: - if (ph->p_flags & PROT_WRITE) - obj->writable_dynamic = true; obj->dynamic = (const Elf_Dyn *)(ph->p_vaddr + obj->relocbase); break; diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index f151db0d1c7b..72a632e912e6 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -264,7 +264,6 @@ typedef struct Struct_Obj_Entry { bool valid_hash_sysv : 1; /* A valid System V hash hash tag is available */ bool valid_hash_gnu : 1; /* A valid GNU hash tag is available */ bool dlopened : 1; /* dlopen()-ed (vs. load statically) */ - bool writable_dynamic : 1; /* PT_DYNAMIC is writable */ struct link_map linkmap; /* For GDB and dlinfo() */ Objlist dldags; /* Object belongs to these dlopened DAGs (%) */ From 2f2edf0a088f94a70a15bfb4bb73bc910b22d727 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 8 Jan 2016 01:16:03 +0000 Subject: [PATCH 59/68] For SOCK_STREAM socket use sbappendstream() instead of sbappend(). --- sys/kern/uipc_usrreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index efed37b8affb..225a20471382 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -981,7 +981,7 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, control)) control = NULL; } else - sbappend_locked(&so2->so_rcv, m); + sbappendstream_locked(&so2->so_rcv, m, flags); break; case SOCK_SEQPACKET: { From adff67c988f8918bab7f820fd5deaffa73f284f3 Mon Sep 17 00:00:00 2001 From: Allan Jude Date: Fri, 8 Jan 2016 05:09:55 +0000 Subject: [PATCH 60/68] Add support for ZFS Boot Environments to userboot (for bhyve and others) While here, also fix a possible null pointer Reported by: lattera MFC after: 3 days Sponsored by: ScaleEngine Inc. --- sys/boot/i386/loader/main.c | 3 +- sys/boot/userboot/userboot/main.c | 55 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/sys/boot/i386/loader/main.c b/sys/boot/i386/loader/main.c index d4073e7da714..73f3507fb8f1 100644 --- a/sys/boot/i386/loader/main.c +++ b/sys/boot/i386/loader/main.c @@ -321,7 +321,8 @@ init_zfs_bootenv(char *currdev) currdev++; /* Remove the last element (current bootenv) */ beroot = strrchr(currdev, '/'); - beroot[0] = '\0'; + if (beroot != NULL) + beroot[0] = '\0'; beroot = currdev; diff --git a/sys/boot/userboot/userboot/main.c b/sys/boot/userboot/userboot/main.c index d4cefff42251..335c8fd05c15 100644 --- a/sys/boot/userboot/userboot/main.c +++ b/sys/boot/userboot/userboot/main.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); static void userboot_zfs_probe(void); static int userboot_zfs_found; +static void init_zfs_bootenv(char *currdev); #endif #define USERBOOT_VERSION USERBOOT_VERSION_3 @@ -190,6 +191,10 @@ extract_currdev(void) dev.d_unit = 0; } +#if defined(USERBOOT_ZFS_SUPPORT) + init_zfs_bootenv(zfs_fmtdev(&dev)); +#endif + env_setenv("currdev", EV_VOLATILE, userboot_fmtdev(&dev), userboot_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, userboot_fmtdev(&dev), @@ -197,6 +202,29 @@ extract_currdev(void) } #if defined(USERBOOT_ZFS_SUPPORT) +static void +init_zfs_bootenv(char *currdev) +{ + char *beroot; + + /* Remove the trailing : */ + currdev[strlen(currdev) - 1] = '\0'; + setenv("zfs_be_active", currdev, 1); + /* Do not overwrite if already set */ + setenv("vfs.root.mountfrom", currdev, 0); + /* Forward past zfs: */ + currdev = strchr(currdev, ':'); + currdev++; + /* Remove the last element (current bootenv) */ + beroot = strrchr(currdev, '/'); + if (beroot != NULL) + beroot[0] = '\0'; + + beroot = currdev; + + setenv("zfs_be_root", beroot, 1); +} + static void userboot_zfs_probe(void) { @@ -237,6 +265,33 @@ command_lszfs(int argc, char *argv[]) } return (CMD_OK); } + +COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments", + command_reloadbe); + +static int +command_reloadbe(int argc, char *argv[]) +{ + int err; + + if (argc > 2) { + command_errmsg = "wrong number of arguments"; + return (CMD_ERROR); + } + + if (argc == 2) { + err = zfs_bootenv(argv[1]); + } else { + err = zfs_bootenv(getenv("zfs_be_root")); + } + + if (err != 0) { + command_errmsg = strerror(err); + return (CMD_ERROR); + } + + return (CMD_OK); +} #endif /* USERBOOT_ZFS_SUPPORT */ COMMAND_SET(quit, "quit", "exit the loader", command_quit); From c373d9289d1987abe45e339b5aa37f05460e977f Mon Sep 17 00:00:00 2001 From: Xin LI Date: Fri, 8 Jan 2016 08:06:14 +0000 Subject: [PATCH 61/68] Vendor import of ntp-4.2.8p5. --- ChangeLog | 57 + CommitLog | 1477 +++++++++++++++++ NEWS | 107 +- configure | 28 +- html/miscopt.html | 6 +- include/Makefile.am | 1 + include/Makefile.in | 1 + include/ntp_refclock.h | 2 +- include/ntp_stdlib.h | 8 +- include/ntp_worker.h | 66 +- include/ntpd.h | 3 +- include/safecast.h | 34 + lib/isc/backtrace.c | 2 +- lib/isc/buffer.c | 4 +- lib/isc/inet_aton.c | 5 +- lib/isc/inet_pton.c | 6 +- lib/isc/log.c | 2 +- lib/isc/netaddr.c | 2 +- lib/isc/sockaddr.c | 4 +- lib/isc/task.c | 16 +- lib/isc/win32/interfaceiter.c | 2 +- lib/isc/win32/net.c | 3 +- libntp/a_md5encrypt.c | 28 +- libntp/atolfp.c | 4 +- libntp/authkeys.c | 30 +- libntp/authreadkeys.c | 89 +- libntp/authusekey.c | 2 +- libntp/dolfptoa.c | 6 +- libntp/hextolfp.c | 10 +- libntp/mstolfp.c | 3 +- libntp/msyslog.c | 2 +- libntp/ntp_crypto_rnd.c | 3 +- libntp/ntp_lineedit.c | 3 +- libntp/ntp_rfc2553.c | 8 +- libntp/ntp_worker.c | 3 +- libntp/snprintf.c | 20 +- libntp/socktohost.c | 12 +- libntp/systime.c | 24 +- libntp/work_thread.c | 579 ++++--- libparse/clk_computime.c | 2 +- libparse/clk_dcf7000.c | 2 +- libparse/clk_hopf6021.c | 2 +- libparse/clk_meinberg.c | 4 +- libparse/clk_rawdcf.c | 2 +- libparse/clk_rcc8000.c | 2 +- libparse/clk_schmid.c | 2 +- libparse/clk_trimtaip.c | 2 +- libparse/clk_varitext.c | 12 +- libparse/clk_wharton.c | 2 +- libparse/parse.c | 2 +- ntpd/invoke-ntp.conf.texi | 2 +- ntpd/invoke-ntp.keys.texi | 2 +- ntpd/invoke-ntpd.texi | 4 +- ntpd/ntp.conf.5man | 6 +- ntpd/ntp.conf.5mdoc | 4 +- ntpd/ntp.conf.html | 2 +- ntpd/ntp.conf.man.in | 6 +- ntpd/ntp.conf.mdoc.in | 4 +- ntpd/ntp.keys.5man | 4 +- ntpd/ntp.keys.5mdoc | 4 +- ntpd/ntp.keys.html | 2 +- ntpd/ntp.keys.man.in | 4 +- ntpd/ntp.keys.mdoc.in | 4 +- ntpd/ntp_control.c | 10 +- ntpd/ntp_crypto.c | 4 +- ntpd/ntp_io.c | 12 +- ntpd/ntp_loopfilter.c | 46 +- ntpd/ntp_parser.c | 349 ++-- ntpd/ntp_parser.y | 9 +- ntpd/ntp_proto.c | 323 ++-- ntpd/ntp_refclock.c | 6 +- ntpd/ntp_request.c | 4 +- ntpd/ntp_restrict.c | 4 +- ntpd/ntp_signd.c | 5 +- ntpd/ntp_timer.c | 13 +- ntpd/ntp_util.c | 6 +- ntpd/ntpd-opts.c | 14 +- ntpd/ntpd-opts.h | 6 +- ntpd/ntpd.1ntpdman | 6 +- ntpd/ntpd.1ntpdmdoc | 4 +- ntpd/ntpd.c | 14 +- ntpd/ntpd.html | 4 +- ntpd/ntpd.man.in | 6 +- ntpd/ntpd.mdoc.in | 4 +- ntpd/refclock_local.c | 1 + ntpd/refclock_parse.c | 4 +- ntpd/refclock_shm.c | 5 +- ntpd/refclock_true.c | 2 +- ntpd/refclock_tsyncpci.c | 2 +- ntpdate/ntpdate.c | 14 +- ntpdc/invoke-ntpdc.texi | 4 +- ntpdc/ntpdc-opts.c | 14 +- ntpdc/ntpdc-opts.h | 6 +- ntpdc/ntpdc.1ntpdcman | 6 +- ntpdc/ntpdc.1ntpdcmdoc | 4 +- ntpdc/ntpdc.c | 70 +- ntpdc/ntpdc.h | 2 +- ntpdc/ntpdc.html | 4 +- ntpdc/ntpdc.man.in | 6 +- ntpdc/ntpdc.mdoc.in | 4 +- ntpdc/ntpdc_ops.c | 218 +-- ntpq/invoke-ntpq.texi | 4 +- ntpq/libntpq.c | 16 +- ntpq/libntpq.h | 2 +- ntpq/libntpq_subs.c | 2 +- ntpq/ntpq-opts.c | 14 +- ntpq/ntpq-opts.h | 6 +- ntpq/ntpq-subs.c | 97 +- ntpq/ntpq.1ntpqman | 6 +- ntpq/ntpq.1ntpqmdoc | 4 +- ntpq/ntpq.c | 135 +- ntpq/ntpq.h | 18 +- ntpq/ntpq.html | 4 +- ntpq/ntpq.man.in | 6 +- ntpq/ntpq.mdoc.in | 4 +- ntpsnmpd/invoke-ntpsnmpd.texi | 4 +- ntpsnmpd/ntpsnmpd-opts.c | 14 +- ntpsnmpd/ntpsnmpd-opts.h | 6 +- ntpsnmpd/ntpsnmpd.1ntpsnmpdman | 6 +- ntpsnmpd/ntpsnmpd.1ntpsnmpdmdoc | 4 +- ntpsnmpd/ntpsnmpd.html | 2 +- ntpsnmpd/ntpsnmpd.man.in | 6 +- ntpsnmpd/ntpsnmpd.mdoc.in | 4 +- packageinfo.sh | 2 +- ports/winnt/include/config.h | 2 +- ports/winnt/include/ntp_iocompletionport.h | 2 +- ports/winnt/instsrv/instsrv.c | 12 +- ports/winnt/libntp/termios.c | 34 +- ports/winnt/ntpd/ntp_iocompletionport.c | 15 +- ports/winnt/vs2008/common.vsprops | 2 +- ports/winnt/vs2008/ntpd/ntpd.vcproj | 192 ++- ports/winnt/vs2013/common.props | 2 +- ports/winnt/vs2013/libntp/libntp.vcxproj | 1 + .../vs2013/libntp/libntp.vcxproj.filters | 3 + ports/winnt/vs2013/ntpd/ntpd.vcxproj | 8 +- scripts/calc_tickadj/Makefile.am | 2 + scripts/calc_tickadj/Makefile.in | 13 +- .../calc_tickadj.1calc_tickadjman | 6 +- .../calc_tickadj.1calc_tickadjmdoc | 4 +- scripts/calc_tickadj/calc_tickadj.html | 2 +- scripts/calc_tickadj/calc_tickadj.man.in | 6 +- scripts/calc_tickadj/calc_tickadj.mdoc.in | 4 +- scripts/calc_tickadj/invoke-calc_tickadj.texi | 2 +- scripts/invoke-plot_summary.texi | 4 +- scripts/invoke-summary.texi | 4 +- scripts/ntp-wait/invoke-ntp-wait.texi | 4 +- scripts/ntp-wait/ntp-wait-opts | 4 +- scripts/ntp-wait/ntp-wait.1ntp-waitman | 6 +- scripts/ntp-wait/ntp-wait.1ntp-waitmdoc | 4 +- scripts/ntp-wait/ntp-wait.html | 4 +- scripts/ntp-wait/ntp-wait.man.in | 6 +- scripts/ntp-wait/ntp-wait.mdoc.in | 4 +- scripts/ntpsweep/invoke-ntpsweep.texi | 4 +- scripts/ntpsweep/ntpsweep-opts | 4 +- scripts/ntpsweep/ntpsweep.1ntpsweepman | 6 +- scripts/ntpsweep/ntpsweep.1ntpsweepmdoc | 4 +- scripts/ntpsweep/ntpsweep.html | 4 +- scripts/ntpsweep/ntpsweep.man.in | 6 +- scripts/ntpsweep/ntpsweep.mdoc.in | 4 +- scripts/ntptrace/invoke-ntptrace.texi | 4 +- scripts/ntptrace/ntptrace-opts | 4 +- scripts/ntptrace/ntptrace.1ntptraceman | 6 +- scripts/ntptrace/ntptrace.1ntptracemdoc | 4 +- scripts/ntptrace/ntptrace.html | 4 +- scripts/ntptrace/ntptrace.man.in | 6 +- scripts/ntptrace/ntptrace.mdoc.in | 4 +- scripts/plot_summary-opts | 4 +- scripts/plot_summary.1plot_summaryman | 6 +- scripts/plot_summary.1plot_summarymdoc | 4 +- scripts/plot_summary.html | 4 +- scripts/plot_summary.man.in | 6 +- scripts/plot_summary.mdoc.in | 4 +- scripts/summary-opts | 4 +- scripts/summary.1summaryman | 6 +- scripts/summary.1summarymdoc | 4 +- scripts/summary.html | 4 +- scripts/summary.man.in | 6 +- scripts/summary.mdoc.in | 4 +- scripts/update-leap/invoke-update-leap.texi | 2 +- scripts/update-leap/update-leap-opts | 4 +- .../update-leap/update-leap.1update-leapman | 6 +- .../update-leap/update-leap.1update-leapmdoc | 4 +- scripts/update-leap/update-leap.html | 2 +- scripts/update-leap/update-leap.man.in | 6 +- scripts/update-leap/update-leap.mdoc.in | 4 +- sntp/configure | 23 +- sntp/include/version.def | 2 +- sntp/include/version.texi | 6 +- sntp/invoke-sntp.texi | 4 +- sntp/m4/ntp_libevent.m4 | 3 +- sntp/m4/ntp_problemtests.m4 | 5 +- sntp/m4/version.m4 | 2 +- sntp/networking.c | 2 +- sntp/sntp-opts.c | 14 +- sntp/sntp-opts.h | 6 +- sntp/sntp.1sntpman | 6 +- sntp/sntp.1sntpmdoc | 4 +- sntp/sntp.html | 4 +- sntp/sntp.man.in | 6 +- sntp/sntp.mdoc.in | 4 +- sntp/tests/keyFile.c | 31 +- sntp/tests/kodDatabase.c | 2 + sntp/tests/kodFile.c | 1 + sntp/tests/run-kodDatabase.c | 11 +- sntp/tests/run-t-log.c | 6 +- sntp/tests/t-log.c | 55 +- sntp/tests/utilities.c | 4 +- sntp/unity/unity_internals.h | 14 +- sntp/version.c | 2 +- tests/bug-2803/bug-2803.c | 2 +- tests/bug-2803/run-bug-2803.c | 2 + tests/libntp/a_md5encrypt.c | 42 +- tests/libntp/authkeys.c | 48 +- tests/libntp/buftvtots.c | 24 +- tests/libntp/calendar.c | 169 +- tests/libntp/caljulian.c | 65 +- tests/libntp/clocktime.c | 72 +- tests/libntp/decodenetnum.c | 10 + tests/libntp/humandate.c | 18 +- tests/libntp/lfpfunc.c | 198 ++- tests/libntp/lfptostr.c | 9 + tests/libntp/modetoa.c | 10 + tests/libntp/msyslog.c | 10 + tests/libntp/netof.c | 57 +- tests/libntp/numtoa.c | 11 + tests/libntp/numtohost.c | 13 +- tests/libntp/octtoint.c | 50 +- tests/libntp/prettydate.c | 15 +- tests/libntp/recvbuff.c | 5 +- tests/libntp/refidsmear.c | 15 +- tests/libntp/refnumtoa.c | 20 +- tests/libntp/run-a_md5encrypt.c | 10 +- tests/libntp/run-calendar.c | 30 +- tests/libntp/run-decodenetnum.c | 12 +- tests/libntp/run-humandate.c | 4 +- tests/libntp/run-lfpfunc.c | 18 +- tests/libntp/run-lfptostr.c | 22 +- tests/libntp/run-modetoa.c | 4 +- tests/libntp/run-msyslog.c | 16 +- tests/libntp/run-netof.c | 8 +- tests/libntp/run-numtoa.c | 4 +- tests/libntp/run-numtohost.c | 2 +- tests/libntp/run-prettydate.c | 2 +- tests/libntp/run-refnumtoa.c | 4 +- tests/libntp/run-sfptostr.c | 17 +- tests/libntp/run-socktoa.c | 12 +- tests/libntp/run-statestr.c | 8 +- tests/libntp/run-strtolfp.c | 14 +- tests/libntp/run-timespecops.c | 56 +- tests/libntp/run-timevalops.c | 56 +- tests/libntp/run-uglydate.c | 2 +- tests/libntp/sfptostr.c | 11 + tests/libntp/socktoa.c | 15 +- tests/libntp/statestr.c | 11 + tests/libntp/strtolfp.c | 10 + tests/libntp/timespecops.c | 229 ++- tests/libntp/timevalops.c | 228 ++- tests/libntp/uglydate.c | 18 +- tests/ntpd/leapsec.c | 323 +++- tests/ntpd/ntp_prio_q.c | 1 + tests/ntpd/ntp_restrict.c | 1 + tests/ntpd/rc_cmdlength.c | 1 + tests/ntpd/run-leapsec.c | 66 +- tests/ntpd/run-ntp_restrict.c | 16 +- tests/ntpd/run-rc_cmdlength.c | 3 +- tests/ntpd/run-t-ntp_signd.c | 14 +- tests/ntpd/t-ntp_scanner.c | 6 +- tests/ntpd/t-ntp_signd.c | 119 +- tests/sandbox/run-uglydate.c | 3 +- tests/sandbox/smeartest.c | 6 + tests/sandbox/uglydate.c | 23 +- tests/sec-2853/sec-2853.c | 17 +- util/invoke-ntp-keygen.texi | 4 +- util/ntp-keygen-opts.c | 14 +- util/ntp-keygen-opts.h | 6 +- util/ntp-keygen.1ntp-keygenman | 6 +- util/ntp-keygen.1ntp-keygenmdoc | 4 +- util/ntp-keygen.c | 6 +- util/ntp-keygen.html | 4 +- util/ntp-keygen.man.in | 6 +- util/ntp-keygen.mdoc.in | 4 +- 281 files changed, 5219 insertions(+), 2164 deletions(-) create mode 100644 include/safecast.h diff --git a/ChangeLog b/ChangeLog index 5d8346b310b0..304bd85ab7dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,61 @@ --- +(4.2.8p5) 2016/01/07 Released by Harlan Stenn + +* [Sec 2956] small-step/big-step. Close the panic gate earlier. HStenn. +* CID 1339955: Free allocated memory in caljulian test. HStenn. +* CID 1339962: Explicitly initialize variable in caljulian test. HStenn. +* CID 1341527: Quiet a CHECKED_RETURN in sntp/tests/t-log.c. HStenn. +* CID 1341533: Missing assertion in sntp/tests/t-log.c. HStenn. +* CID 1341534: Resource leak in tests/ntpd/t-ntp_signd.c. HStenn. +* CID 1341535: Resource leak in tests/ntpd/t-ntp_signd.c. HStenn. +* CID 1341536: Resource leak in tests/ntpd/t-ntp_signd.c. HStenn. +* CID 1341537: Resource leak in tests/ntpd/t-ntp_signd.c. HStenn. +* CID 1341538: Memory leak in tests/ntpd/ntp_prio_q.c:262. HStenn. +* CID 1341677: Nits in sntp/tests/keyFile.c. HStenn. +* CID 1341678: Nits in sntp/tests/keyFile.c. HStenn. +* CID 1341679: Nits in sntp/tests/keyFile.c. HStenn. +* CID 1341680: Nits in sntp/tests/keyFile.c. HStenn. +* CID 1341681: Nits in sntp/tests/keyFile.c. HStenn. +* CID 1341682: Nit in libntp/authreadkeys.c. HStenn. +* CID 1341684: Nit in tests/ntpd/t-ntp_signd.c. HStenn. +* [Bug 2829] Look at pipe_fds in ntpd.c (did so. perlinger@ntp.org) +* [Bug 2887] stratum -1 config results as showing value 99 + - fudge stratum should only accept values [0..16]. perlinger@ntp.org +* [Bug 2932] Update leapsecond file info in miscopt.html. CWoodbury, HStenn. +* [Bug 2934] tests/ntpd/t-ntp_scanner.c has a magic constant wired in. HMurray +* [Bug 2944] errno is not preserved properly in ntpdate after sendto call. + - applied patch by Christos Zoulas. perlinger@ntp.org +* [Bug 2952] Symmetric active/passive mode is broken. HStenn. +* [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - fixed data race conditions in threaded DNS worker. perlinger@ntp.org + - limit threading warm-up to linux; FreeBSD bombs on it. perlinger@ntp.org +* [Bug 2957] 'unsigned int' vs 'size_t' format clash. perlinger@ntp.org + - accept key file only if there are no parsing errors + - fixed size_t/u_int format clash + - fixed wrong use of 'strlcpy' +* [Bug 2958] ntpq: fatal error messages need a final newline. Craig Leres. +* [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets. perlinger@ntp.org + - fixed several other warnings (cast-alignment, missing const, missing prototypes) + - promote use of 'size_t' for values that express a size + - use ptr-to-const for read-only arguments + - make sure SOCKET values are not truncated (win32-specific) + - format string fixes +* [Bug 2965] Local clock didn't work since 4.2.8p4. Martin Burnicki. +* [Bug 2967] ntpdate command suffers an assertion failure + - fixed ntp_rfc2553.c to return proper address length. perlinger@ntp.org +* [Bug 2969] Seg fault from ntpq/mrulist when looking at server with + lots of clients. perlinger@ntp.org +* [Bug 2971] ntpq bails on ^C: select fails: Interrupted system call + - changed stacked/nested handling of CTRL-C. perlinger@ntp.org +* Unity cleanup for FreeBSD-6.4. Harlan Stenn. +* Unity test cleanup. Harlan Stenn. +* Libevent autoconf pthread fixes for FreeBSD-10. Harlan Stenn. +* Header cleanup in tests/sandbox/uglydate.c. Harlan Stenn. +* Header cleanup in tests/libntp/sfptostr.c. Harlan Stenn. +* Quiet a warning from clang. Harlan Stenn. +* Update the NEWS file. Harlan Stenn. +* Update scripts/calc_tickadj/Makefile.am. Harlan Stenn. +--- (4.2.8p4) 2015/10/21 Released by Harlan Stenn (4.2.8p4-RC1) 2015/10/06 Released by Harlan Stenn diff --git a/CommitLog b/CommitLog index 3366f2ff17e8..9caeaa2a6111 100644 --- a/CommitLog +++ b/CommitLog @@ -1,3 +1,1480 @@ +ChangeSet@1.3623, 2016-01-07 23:33:11+00:00, stenn@deacon.udel.edu + NTP_4_2_8P5 + TAG: NTP_4_2_8P5 + + ChangeLog@1.1791 +1 -0 + NTP_4_2_8P5 + + ntpd/invoke-ntp.conf.texi@1.194 +1 -1 + NTP_4_2_8P5 + + ntpd/invoke-ntp.keys.texi@1.186 +1 -1 + NTP_4_2_8P5 + + ntpd/invoke-ntpd.texi@1.503 +2 -2 + NTP_4_2_8P5 + + ntpd/ntp.conf.5man@1.228 +3 -3 + NTP_4_2_8P5 + + ntpd/ntp.conf.5mdoc@1.228 +2 -2 + NTP_4_2_8P5 + + ntpd/ntp.conf.html@1.182 +1 -1 + NTP_4_2_8P5 + + ntpd/ntp.conf.man.in@1.228 +3 -3 + NTP_4_2_8P5 + + ntpd/ntp.conf.mdoc.in@1.228 +2 -2 + NTP_4_2_8P5 + + ntpd/ntp.keys.5man@1.220 +2 -2 + NTP_4_2_8P5 + + ntpd/ntp.keys.5mdoc@1.220 +2 -2 + NTP_4_2_8P5 + + ntpd/ntp.keys.html@1.182 +1 -1 + NTP_4_2_8P5 + + ntpd/ntp.keys.man.in@1.220 +2 -2 + NTP_4_2_8P5 + + ntpd/ntp.keys.mdoc.in@1.220 +2 -2 + NTP_4_2_8P5 + + ntpd/ntpd-opts.c@1.525 +7 -7 + NTP_4_2_8P5 + + ntpd/ntpd-opts.h@1.524 +3 -3 + NTP_4_2_8P5 + + ntpd/ntpd.1ntpdman@1.332 +3 -3 + NTP_4_2_8P5 + + ntpd/ntpd.1ntpdmdoc@1.332 +2 -2 + NTP_4_2_8P5 + + ntpd/ntpd.html@1.176 +2 -2 + NTP_4_2_8P5 + + ntpd/ntpd.man.in@1.332 +3 -3 + NTP_4_2_8P5 + + ntpd/ntpd.mdoc.in@1.332 +2 -2 + NTP_4_2_8P5 + + ntpdc/invoke-ntpdc.texi@1.500 +2 -2 + NTP_4_2_8P5 + + ntpdc/ntpdc-opts.c@1.518 +7 -7 + NTP_4_2_8P5 + + ntpdc/ntpdc-opts.h@1.517 +3 -3 + NTP_4_2_8P5 + + ntpdc/ntpdc.1ntpdcman@1.331 +3 -3 + NTP_4_2_8P5 + + ntpdc/ntpdc.1ntpdcmdoc@1.331 +2 -2 + NTP_4_2_8P5 + + ntpdc/ntpdc.html@1.344 +2 -2 + NTP_4_2_8P5 + + ntpdc/ntpdc.man.in@1.331 +3 -3 + NTP_4_2_8P5 + + ntpdc/ntpdc.mdoc.in@1.331 +2 -2 + NTP_4_2_8P5 + + ntpq/invoke-ntpq.texi@1.507 +2 -2 + NTP_4_2_8P5 + + ntpq/ntpq-opts.c@1.524 +7 -7 + NTP_4_2_8P5 + + ntpq/ntpq-opts.h@1.522 +3 -3 + NTP_4_2_8P5 + + ntpq/ntpq.1ntpqman@1.335 +3 -3 + NTP_4_2_8P5 + + ntpq/ntpq.1ntpqmdoc@1.335 +2 -2 + NTP_4_2_8P5 + + ntpq/ntpq.html@1.173 +2 -2 + NTP_4_2_8P5 + + ntpq/ntpq.man.in@1.335 +3 -3 + NTP_4_2_8P5 + + ntpq/ntpq.mdoc.in@1.335 +2 -2 + NTP_4_2_8P5 + + ntpsnmpd/invoke-ntpsnmpd.texi@1.502 +2 -2 + NTP_4_2_8P5 + + ntpsnmpd/ntpsnmpd-opts.c@1.520 +7 -7 + NTP_4_2_8P5 + + ntpsnmpd/ntpsnmpd-opts.h@1.519 +3 -3 + NTP_4_2_8P5 + + ntpsnmpd/ntpsnmpd.1ntpsnmpdman@1.331 +3 -3 + NTP_4_2_8P5 + + ntpsnmpd/ntpsnmpd.1ntpsnmpdmdoc@1.331 +2 -2 + NTP_4_2_8P5 + + ntpsnmpd/ntpsnmpd.html@1.171 +1 -1 + NTP_4_2_8P5 + + ntpsnmpd/ntpsnmpd.man.in@1.331 +3 -3 + NTP_4_2_8P5 + + ntpsnmpd/ntpsnmpd.mdoc.in@1.331 +2 -2 + NTP_4_2_8P5 + + packageinfo.sh@1.522 +2 -2 + NTP_4_2_8P5 + + scripts/calc_tickadj/calc_tickadj.1calc_tickadjman@1.92 +3 -3 + NTP_4_2_8P5 + + scripts/calc_tickadj/calc_tickadj.1calc_tickadjmdoc@1.93 +2 -2 + NTP_4_2_8P5 + + scripts/calc_tickadj/calc_tickadj.html@1.94 +1 -1 + NTP_4_2_8P5 + + scripts/calc_tickadj/calc_tickadj.man.in@1.91 +3 -3 + NTP_4_2_8P5 + + scripts/calc_tickadj/calc_tickadj.mdoc.in@1.93 +2 -2 + NTP_4_2_8P5 + + scripts/calc_tickadj/invoke-calc_tickadj.texi@1.96 +1 -1 + NTP_4_2_8P5 + + scripts/invoke-plot_summary.texi@1.113 +2 -2 + NTP_4_2_8P5 + + scripts/invoke-summary.texi@1.113 +2 -2 + NTP_4_2_8P5 + + scripts/ntp-wait/invoke-ntp-wait.texi@1.323 +2 -2 + NTP_4_2_8P5 + + scripts/ntp-wait/ntp-wait-opts@1.59 +2 -2 + NTP_4_2_8P5 + + scripts/ntp-wait/ntp-wait.1ntp-waitman@1.320 +3 -3 + NTP_4_2_8P5 + + scripts/ntp-wait/ntp-wait.1ntp-waitmdoc@1.321 +2 -2 + NTP_4_2_8P5 + + scripts/ntp-wait/ntp-wait.html@1.340 +2 -2 + NTP_4_2_8P5 + + scripts/ntp-wait/ntp-wait.man.in@1.320 +3 -3 + NTP_4_2_8P5 + + scripts/ntp-wait/ntp-wait.mdoc.in@1.321 +2 -2 + NTP_4_2_8P5 + + scripts/ntpsweep/invoke-ntpsweep.texi@1.111 +2 -2 + NTP_4_2_8P5 + + scripts/ntpsweep/ntpsweep-opts@1.61 +2 -2 + NTP_4_2_8P5 + + scripts/ntpsweep/ntpsweep.1ntpsweepman@1.99 +3 -3 + NTP_4_2_8P5 + + scripts/ntpsweep/ntpsweep.1ntpsweepmdoc@1.99 +2 -2 + NTP_4_2_8P5 + + scripts/ntpsweep/ntpsweep.html@1.112 +2 -2 + NTP_4_2_8P5 + + scripts/ntpsweep/ntpsweep.man.in@1.99 +3 -3 + NTP_4_2_8P5 + + scripts/ntpsweep/ntpsweep.mdoc.in@1.100 +2 -2 + NTP_4_2_8P5 + + scripts/ntptrace/invoke-ntptrace.texi@1.112 +2 -2 + NTP_4_2_8P5 + + scripts/ntptrace/ntptrace-opts@1.61 +2 -2 + NTP_4_2_8P5 + + scripts/ntptrace/ntptrace.1ntptraceman@1.99 +3 -3 + NTP_4_2_8P5 + + scripts/ntptrace/ntptrace.1ntptracemdoc@1.100 +2 -2 + NTP_4_2_8P5 + + scripts/ntptrace/ntptrace.html@1.113 +2 -2 + NTP_4_2_8P5 + + scripts/ntptrace/ntptrace.man.in@1.99 +3 -3 + NTP_4_2_8P5 + + scripts/ntptrace/ntptrace.mdoc.in@1.101 +2 -2 + NTP_4_2_8P5 + + scripts/plot_summary-opts@1.61 +2 -2 + NTP_4_2_8P5 + + scripts/plot_summary.1plot_summaryman@1.111 +3 -3 + NTP_4_2_8P5 + + scripts/plot_summary.1plot_summarymdoc@1.111 +2 -2 + NTP_4_2_8P5 + + scripts/plot_summary.html@1.114 +2 -2 + NTP_4_2_8P5 + + scripts/plot_summary.man.in@1.111 +3 -3 + NTP_4_2_8P5 + + scripts/plot_summary.mdoc.in@1.111 +2 -2 + NTP_4_2_8P5 + + scripts/summary-opts@1.61 +2 -2 + NTP_4_2_8P5 + + scripts/summary.1summaryman@1.111 +3 -3 + NTP_4_2_8P5 + + scripts/summary.1summarymdoc@1.111 +2 -2 + NTP_4_2_8P5 + + scripts/summary.html@1.114 +2 -2 + NTP_4_2_8P5 + + scripts/summary.man.in@1.111 +3 -3 + NTP_4_2_8P5 + + scripts/summary.mdoc.in@1.111 +2 -2 + NTP_4_2_8P5 + + scripts/update-leap/invoke-update-leap.texi@1.12 +1 -1 + NTP_4_2_8P5 + + scripts/update-leap/update-leap-opts@1.12 +2 -2 + NTP_4_2_8P5 + + scripts/update-leap/update-leap.1update-leapman@1.12 +3 -3 + NTP_4_2_8P5 + + scripts/update-leap/update-leap.1update-leapmdoc@1.12 +2 -2 + NTP_4_2_8P5 + + scripts/update-leap/update-leap.html@1.12 +1 -1 + NTP_4_2_8P5 + + scripts/update-leap/update-leap.man.in@1.12 +3 -3 + NTP_4_2_8P5 + + scripts/update-leap/update-leap.mdoc.in@1.12 +2 -2 + NTP_4_2_8P5 + + sntp/invoke-sntp.texi@1.500 +2 -2 + NTP_4_2_8P5 + + sntp/sntp-opts.c@1.519 +7 -7 + NTP_4_2_8P5 + + sntp/sntp-opts.h@1.517 +3 -3 + NTP_4_2_8P5 + + sntp/sntp.1sntpman@1.335 +3 -3 + NTP_4_2_8P5 + + sntp/sntp.1sntpmdoc@1.335 +2 -2 + NTP_4_2_8P5 + + sntp/sntp.html@1.515 +2 -2 + NTP_4_2_8P5 + + sntp/sntp.man.in@1.335 +3 -3 + NTP_4_2_8P5 + + sntp/sntp.mdoc.in@1.335 +2 -2 + NTP_4_2_8P5 + + util/invoke-ntp-keygen.texi@1.503 +2 -2 + NTP_4_2_8P5 + + util/ntp-keygen-opts.c@1.521 +7 -7 + NTP_4_2_8P5 + + util/ntp-keygen-opts.h@1.519 +3 -3 + NTP_4_2_8P5 + + util/ntp-keygen.1ntp-keygenman@1.331 +3 -3 + NTP_4_2_8P5 + + util/ntp-keygen.1ntp-keygenmdoc@1.331 +2 -2 + NTP_4_2_8P5 + + util/ntp-keygen.html@1.177 +2 -2 + NTP_4_2_8P5 + + util/ntp-keygen.man.in@1.331 +3 -3 + NTP_4_2_8P5 + + util/ntp-keygen.mdoc.in@1.331 +2 -2 + NTP_4_2_8P5 + +ChangeSet@1.3622, 2016-01-07 17:52:24-05:00, stenn@deacon.udel.edu + ntp-4.2.8p5 + + packageinfo.sh@1.521 +1 -1 + ntp-4.2.8p5 + +ChangeSet@1.3621, 2016-01-07 22:20:05+00:00, stenn@psp-at1.ntp.org + cleanup + + NEWS@1.152 +2 -2 + cleanup + +ChangeSet@1.3620, 2016-01-07 09:33:11+00:00, stenn@psp-at1.ntp.org + typo in ntp_proto.c - leap smear. Reported by Martin Burnicki + + ntpd/ntp_proto.c@1.371 +1 -1 + typo in ntp_proto.c - leap smear. Reported by Martin Burnicki + +ChangeSet@1.3619, 2016-01-07 06:33:08+00:00, stenn@psp-at1.ntp.org + Update scripts/calc_tickadj/Makefile.am. Harlan Stenn. + + ChangeLog@1.1790 +1 -0 + Update scripts/calc_tickadj/Makefile.am. Harlan Stenn. + + scripts/calc_tickadj/Makefile.am@1.11 +2 -0 + Update scripts/calc_tickadj/Makefile.am. Harlan Stenn. + +ChangeSet@1.3616.1.1, 2016-01-05 10:57:45+00:00, stenn@psp-at1.ntp.org + Bug 2952 fixes + + ChangeLog@1.1787.1.1 +1 -0 + Bug 2952 fixes + + ntpd/ntp_proto.c@1.370 +165 -152 + Bug 2952 fixes + +ChangeSet@1.3617, 2016-01-05 09:56:31+00:00, stenn@psp-at1.ntp.org + ntp-4.2.8p5 prep + + ChangeLog@1.1788 +2 -1 + ntp-4.2.8p5 prep + + NEWS@1.151 +104 -3 + ntp-4.2.8p5 prep + +ChangeSet@1.3616, 2015-12-06 11:20:02+00:00, stenn@psp-deb1.ntp.org + Quiet a warning from clang. Harlan Stenn. + + ChangeLog@1.1787 +1 -0 + Quiet a warning from clang. Harlan Stenn. + + libntp/ntp_rfc2553.c@1.50 +3 -2 + Quiet a warning from clang. Harlan Stenn. + +ChangeSet@1.3615, 2015-12-05 10:41:51+00:00, stenn@psp-at1.ntp.org + CID 1341677: Nits in sntp/tests/keyFile.c. HStenn. + + ChangeLog@1.1786 +1 -0 + CID 1341677: Nits in sntp/tests/keyFile.c. HStenn. + + sntp/tests/keyFile.c@1.12 +5 -2 + CID 1341677: Nits in sntp/tests/keyFile.c. HStenn. + +ChangeSet@1.3614, 2015-12-05 10:38:28+00:00, stenn@psp-at1.ntp.org + CID 1341678: Nits in sntp/tests/keyFile.c. HStenn. + + ChangeLog@1.1785 +1 -0 + CID 1341678: Nits in sntp/tests/keyFile.c. HStenn. + + sntp/tests/keyFile.c@1.11 +5 -1 + CID 1341678: Nits in sntp/tests/keyFile.c. HStenn. + +ChangeSet@1.3613, 2015-12-05 10:31:39+00:00, stenn@psp-at1.ntp.org + CID 1341679: Nits in sntp/tests/keyFile.c. HStenn. + + ChangeLog@1.1784 +1 -0 + CID 1341679: Nits in sntp/tests/keyFile.c. HStenn. + + sntp/tests/keyFile.c@1.10 +4 -2 + CID 1341679: Nits in sntp/tests/keyFile.c. HStenn. + +ChangeSet@1.3612, 2015-12-05 10:27:40+00:00, stenn@psp-at1.ntp.org + CID 1341680: Nits in sntp/tests/keyFile.c. HStenn. + + ChangeLog@1.1783 +1 -0 + CID 1341680: Nits in sntp/tests/keyFile.c. HStenn. + + sntp/tests/keyFile.c@1.9 +4 -2 + CID 1341680: Nits in sntp/tests/keyFile.c. HStenn. + +ChangeSet@1.3611, 2015-12-05 10:21:07+00:00, stenn@psp-at1.ntp.org + CID 1341681: Nits in sntp/tests/keyFile.c. HStenn. + + ChangeLog@1.1782 +1 -0 + CID 1341681: Nits in sntp/tests/keyFile.c. HStenn. + +ChangeSet@1.3610, 2015-12-05 10:18:23+00:00, stenn@psp-at1.ntp.org + sntp/tests/keyFile.c lint + + sntp/tests/keyFile.c@1.8 +4 -2 + sntp/tests/keyFile.c lint + +ChangeSet@1.3609, 2015-12-05 10:01:47+00:00, stenn@psp-at1.ntp.org + CID 1341682: Nit in libntp/authreadkeys.c. HStenn. + + ChangeLog@1.1781 +1 -0 + CID 1341682: Nit in libntp/authreadkeys.c. HStenn. + + libntp/authreadkeys.c@1.24 +3 -4 + CID 1341682: Nit in libntp/authreadkeys.c. HStenn. + +ChangeSet@1.3608, 2015-12-05 09:40:44+00:00, stenn@psp-at1.ntp.org + CID 1341684: Nit in tests/ntpd/t-ntp_signd.c. HStenn. + + ChangeLog@1.1780 +1 -0 + CID 1341684: Nit in tests/ntpd/t-ntp_signd.c. HStenn. + + tests/ntpd/t-ntp_signd.c@1.15 +4 -0 + CID 1341684: Nit in tests/ntpd/t-ntp_signd.c. HStenn. + +ChangeSet@1.3607, 2015-12-03 12:07:30+00:00, stenn@psp-at1.ntp.org + Update some test runners + + tests/libntp/run-sfptostr.c@1.7 +9 -8 + update + + tests/sandbox/run-uglydate.c@1.7 +2 -1 + update + +ChangeSet@1.3606, 2015-12-03 03:28:15-08:00, cov-build@cov7.ntfo.org + Header cleanup in tests/libntp/sfptostr.c. Harlan Stenn. + + ChangeLog@1.1779 +1 -0 + Header cleanup in tests/libntp/sfptostr.c. Harlan Stenn. + + tests/libntp/sfptostr.c@1.5 +1 -0 + Header cleanup in tests/libntp/sfptostr.c. Harlan Stenn. + +ChangeSet@1.3605, 2015-12-03 03:26:50-08:00, cov-build@cov7.ntfo.org + Header cleanup in tests/sandbox/uglydate.c. Harlan Stenn. + + ChangeLog@1.1778 +1 -0 + Header cleanup in tests/sandbox/uglydate.c. Harlan Stenn. + + tests/sandbox/uglydate.c@1.6 +2 -1 + Header cleanup in tests/sandbox/uglydate.c. Harlan Stenn. + +ChangeSet@1.3604, 2015-12-03 02:16:02-08:00, cov-build@cov7.ntfo.org + CID 1341527: Quiet a CHECKED_RETURN in sntp/tests/t-log.c. HStenn. + + ChangeLog@1.1777 +1 -0 + CID 1341527: Quiet a CHECKED_RETURN in sntp/tests/t-log.c. HStenn. + + sntp/tests/t-log.c@1.7 +1 -1 + CID 1341527: Quiet a CHECKED_RETURN in sntp/tests/t-log.c. HStenn. + +ChangeSet@1.3603, 2015-12-03 02:00:58-08:00, cov-build@cov7.ntfo.org + CID 1341533: Missing assertion in sntp/tests/t-log.c. HStenn. + + ChangeLog@1.1776 +1 -0 + CID 1341533: Missing assertion in sntp/tests/t-log.c. HStenn. + + sntp/tests/t-log.c@1.6 +2 -0 + CID 1341533: Missing assertion in sntp/tests/t-log.c. HStenn. + +ChangeSet@1.3602, 2015-12-03 01:50:11-08:00, cov-build@cov7.ntfo.org + CID 134534-134537: Resource leaks in tests/ntpd/t-ntp_signd.c. HStenn. + + ChangeLog@1.1775 +4 -0 + CID 134534-134537: Resource leaks in tests/ntpd/t-ntp_signd.c. HStenn. + + tests/ntpd/t-ntp_signd.c@1.14 +9 -0 + CID 134534-134537: Resource leaks in tests/ntpd/t-ntp_signd.c. HStenn. + +ChangeSet@1.3601, 2015-12-03 01:22:22-08:00, cov-build@cov7.ntfo.org + CID 1341538: Memory leak in tests/ntpd/ntp_prio_q.c:262. HStenn. + + ChangeLog@1.1774 +1 -0 + CID 1341538: Memory leak in tests/ntpd/ntp_prio_q.c:262. HStenn. + + tests/ntpd/ntp_prio_q.c@1.3 +1 -0 + CID 1341538: Memory leak in tests/ntpd/ntp_prio_q.c:262. HStenn. + +ChangeSet@1.3597.4.1, 2015-11-30 06:03:47+01:00, jnperlin@hydra.localnet + [Bug 2829] Look at pipe_fds in ntpd.c (initial value issue) + + ChangeLog@1.1770.4.1 +1 -0 + [Bug 2829] Look at pipe_fds in ntpd.c + + ntpd/ntpd.c@1.167 +3 -0 + [Bug 2829] Look at pipe_fds in ntpd.c (initial value issue) + +ChangeSet@1.3597.3.1, 2015-11-29 13:03:58+01:00, jnperlin@hydra.localnet + [Bug 2887] stratum -1 config results as showing value 99 + - fudge stratum only accepts values [0..16]. + + ChangeLog@1.1770.3.1 +2 -0 + [Bug 2887] stratum -1 config results as showing value 99 + - fudge stratum only accepts values [0..16]. + + ntpd/ntp_parser.c@1.100 +178 -171 + [Bug 2887] stratum -1 config results as showing value 99 + - fudge stratum only accepts values [0..16]. (file regenerated by bison & trimmed manually) + + ntpd/ntp_parser.y@1.90 +8 -1 + [Bug 2887] stratum -1 config results as showing value 99 + - fudge stratum only accepts values [0..16], gives error otherwise + +ChangeSet@1.3597.2.1, 2015-11-28 22:59:39+01:00, jnperlin@hydra.localnet + [Bug 2944] errno is not preserved properly in ntpdate after sendto call. + - applied patch by Christos Zoulas. + + ChangeLog@1.1770.2.1 +2 -0 + [Bug 2944] errno is not preserved properly in ntpdate after sendto call. + - applied patch by Christos Zoulas. + + libntp/socktohost.c@1.16 +10 -2 + [Bug 2944] errno is not preserved properly in ntpdate after sendto call. + - save errno around calls to getnameinfo/getaddrinfo (patch by Christos Zoulas) + +ChangeSet@1.3597.1.4, 2015-11-28 19:09:53+01:00, jnperlin@hydra.localnet + Bug 2971 - ntpq bails on ^C: select fails: Interrupted system call + - changed stacked/nested handling of CTRL-C. + + ChangeLog@1.1770.1.2 +2 -0 + Bug 2971 - ntpq bails on ^C: select fails: Interrupted system call + - changed stacked/nested handling of CTRL-C. + + ntpq/ntpq-subs.c@1.114 +11 -8 + Bug 2971 - ntpq bails on ^C: select fails: Interrupted system call + - changed stacked/nested handling of CTRL-C. + + ntpq/ntpq.c@1.165 +57 -8 + Bug 2971 - ntpq bails on ^C: select fails: Interrupted system call + - changed stacked/nested handling of CTRL-C. + + ntpq/ntpq.h@1.31 +4 -0 + Bug 2971 - ntpq bails on ^C: select fails: Interrupted system call + - changed stacked/nested handling of CTRL-C. + +ChangeSet@1.3597.1.3, 2015-11-25 22:10:45-08:00, harlan@max.pfcs.com + Libevent autoconf pthread fixes for FreeBSD-10. Harlan Stenn. + + ChangeLog@1.1770.1.1 +1 -0 + Libevent autoconf pthread fixes for FreeBSD-10. Harlan Stenn. + + sntp/m4/ntp_libevent.m4@1.16 +2 -1 + Libevent autoconf pthread fixes for FreeBSD-10. Harlan Stenn. + +ChangeSet@1.3597.1.2, 2015-11-25 12:23:40+00:00, stenn@psp-at1.ntp.org + Unity test cleanup. Harlan Stenn. + + tests/ntpd/run-t-ntp_signd.c@1.11 +6 -6 + Unity test cleanup. Harlan Stenn. + + tests/ntpd/t-ntp_signd.c@1.13 +19 -5 + Unity test cleanup. Harlan Stenn. + +ChangeSet@1.3597.1.1, 2015-11-25 11:50:51+00:00, stenn@psp-at1.ntp.org + Unity test cleanup. Harlan Stenn. + + sntp/unity/unity_internals.h@1.5 +13 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/calendar.c@1.12 +8 -3 + Unity test cleanup. Harlan Stenn. + + tests/ntpd/leapsec.c@1.4 +241 -82 + Unity test cleanup. Harlan Stenn. + + tests/ntpd/run-leapsec.c@1.6 +33 -33 + Unity test cleanup. Harlan Stenn. + + tests/ntpd/run-t-ntp_signd.c@1.10 +6 -6 + Unity test cleanup. Harlan Stenn. + + tests/ntpd/t-ntp_signd.c@1.12 +40 -13 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/smeartest.c@1.10 +3 -0 + Unity test cleanup. Harlan Stenn. + +ChangeSet@1.3598, 2015-11-24 08:06:41+01:00, jnperlin@hydra.localnet + [Bug 2967] ntpdate command suffers an assertion failure + - fixed ntp_rfc2553.c to return proper address length. + + ChangeLog@1.1771 +2 -0 + [Bug 2967] ntpdate command suffers an assertion failure + - fixed ntp_rfc2553.c to return proper address length. + + libntp/ntp_rfc2553.c@1.49 +2 -1 + [Bug 2967] ntpdate command suffers an assertion failure + - fix do_nodename() to return the proper address length when name is NULL. + +ChangeSet@1.3597, 2015-11-23 10:55:16+00:00, stenn@psp-at1.ntp.org + ChangeLog, caljulian.c: + * CID 1339955: Free allocated memory in caljulian test. HStenn. + * CID 1339962: Explicitly initialize variable in caljulian test. HStenn. + + ChangeLog@1.1770 +2 -0 + * CID 1339955: Free allocated memory in caljulian test. HStenn. + * CID 1339962: Explicitly initialize variable in caljulian test. HStenn. + + tests/libntp/caljulian.c@1.14 +16 -10 + * CID 1339955: Free allocated memory in caljulian test. HStenn. + * CID 1339962: Explicitly initialize variable in caljulian test. HStenn. + +ChangeSet@1.3596, 2015-11-20 20:16:24-08:00, harlan@hms-mbp11.pfcs.com + Unity test cleanup. Harlan Stenn. + + sntp/tests/kodDatabase.c@1.9 +0 -4 + Unity test cleanup. Harlan Stenn. + + sntp/tests/run-kodDatabase.c@1.9 +5 -5 + Unity test cleanup. Harlan Stenn. + +ChangeSet@1.3595, 2015-11-20 19:41:16-08:00, harlan@hms-mbp11.pfcs.com + Unity test cleanup. Harlan Stenn. + + sntp/tests/kodDatabase.c@1.8 +6 -0 + Unity test cleanup. Harlan Stenn. + + sntp/tests/kodFile.c@1.9 +1 -0 + Unity test cleanup. Harlan Stenn. + + sntp/tests/run-kodDatabase.c@1.8 +6 -5 + Unity test cleanup. Harlan Stenn. + + sntp/tests/run-t-log.c@1.5 +3 -3 + Unity test cleanup. Harlan Stenn. + + sntp/tests/t-log.c@1.5 +32 -16 + Unity test cleanup. Harlan Stenn. + + tests/libntp/calendar.c@1.11 +11 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/caljulian.c@1.13 +1 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/decodenetnum.c@1.10 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/humandate.c@1.7 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/lfptostr.c@1.8 +9 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/modetoa.c@1.8 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/msyslog.c@1.7 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/netof.c@1.9 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/numtoa.c@1.7 +11 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/numtohost.c@1.7 +11 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/prettydate.c@1.6 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/recvbuff.c@1.7 +3 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/refidsmear.c@1.7 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/refnumtoa.c@1.7 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-calendar.c@1.11 +15 -15 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-decodenetnum.c@1.10 +6 -6 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-humandate.c@1.7 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-lfptostr.c@1.8 +11 -11 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-modetoa.c@1.12 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-msyslog.c@1.9 +8 -8 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-netof.c@1.8 +4 -4 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-numtoa.c@1.11 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-numtohost.c@1.11 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-prettydate.c@1.6 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-refidsmear.c@1.8 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-refnumtoa.c@1.9 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-sfptostr.c@1.6 +8 -8 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-socktoa.c@1.13 +6 -6 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-statestr.c@1.11 +4 -4 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-strtolfp.c@1.6 +7 -7 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-timespecops.c@1.11 +28 -28 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-timevalops.c@1.13 +28 -28 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-uglydate.c@1.11 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/sfptostr.c@1.4 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/socktoa.c@1.11 +11 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/statestr.c@1.6 +11 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/strtolfp.c@1.7 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/timespecops.c@1.10 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/timevalops.c@1.13 +10 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/uglydate.c@1.10 +13 -1 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/run-uglydate.c@1.6 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/smeartest.c@1.9 +2 -0 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/uglydate.c@1.5 +11 -0 + Unity test cleanup. Harlan Stenn. + +ChangeSet@1.3594, 2015-11-20 07:40:57+00:00, stenn@psp-at1.ntp.org + [Bug 2958] ntpq: fatal error messages need a final newline. Craig Leres. + + ChangeLog@1.1769 +1 -0 + [Bug 2958] ntpq: fatal error messages need a final newline. Craig Leres. + + ntpq/ntpq.c@1.164 +1 -1 + [Bug 2958] ntpq: fatal error messages need a final newline. Craig Leres. + +ChangeSet@1.3593, 2015-11-20 07:27:27+00:00, stenn@psp-at1.ntp.org + Unity test cleanup. Harlan Stenn. + + tests/libntp/authkeys.c@1.13 +36 -10 + Unity test cleanup. Harlan Stenn. + + tests/libntp/buftvtots.c@1.6 +18 -6 + Unity test cleanup. Harlan Stenn. + + tests/libntp/calendar.c@1.10 +100 -47 + Unity test cleanup. Harlan Stenn. + + tests/libntp/caljulian.c@1.12 +27 -9 + Unity test cleanup. Harlan Stenn. + + tests/libntp/clocktime.c@1.9 +48 -24 + Unity test cleanup. Harlan Stenn. + + tests/libntp/humandate.c@1.6 +6 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/lfpfunc.c@1.15 +113 -69 + Unity test cleanup. Harlan Stenn. + + tests/libntp/netof.c@1.8 +22 -7 + Unity test cleanup. Harlan Stenn. + + tests/libntp/numtohost.c@1.6 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/octtoint.c@1.7 +36 -14 + Unity test cleanup. Harlan Stenn. + + tests/libntp/refidsmear.c@1.6 +1 -4 + Unity test cleanup. Harlan Stenn. + + tests/libntp/refnumtoa.c@1.6 +5 -5 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-lfpfunc.c@1.18 +9 -9 + Unity test cleanup. Harlan Stenn. + + tests/libntp/run-refidsmear.c@1.7 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/timespecops.c@1.9 +173 -48 + Unity test cleanup. Harlan Stenn. + + tests/libntp/timestructs.h@1.3 +22 -22 + Unity test cleanup. Harlan Stenn. + + tests/libntp/timevalops.c@1.12 +168 -52 + Unity test cleanup. Harlan Stenn. + +ChangeSet@1.3592, 2015-11-20 02:57:37+01:00, jnperlin@nemesis.localnet + [Bug 2969] Seg fault from ntpq/mrulist when looking at server with lots of clients + + ChangeLog@1.1768 +2 -0 + [Bug 2969] Seg fault from ntpq/mrulist when looking at server with lots of clients + + lib/isc/sockaddr.c@1.14 +1 -1 + [Bug 2969] Seg fault from ntpq/mrulist when looking at server with lots of clients + - cast fro size_t to u_int (no overflow danger); not related the bug, found while double-checking changes + + ntpq/ntpq-subs.c@1.113 +1 -1 + [Bug 2969] Seg fault from ntpq/mrulist when looking at server with lots of clients + - make end-of-buffer test unsigned-safe + +ChangeSet@1.3591, 2015-11-17 11:12:02+00:00, stenn@psp-at1.ntp.org + [Bug 2932] Update leapsecond file info in miscopt.html. CWoodbury, HStenn. + + ChangeLog@1.1767 +1 -0 + [Bug 2932] Update leapsecond file info in miscopt.html. CWoodbury, HStenn. + + html/miscopt.html@1.84 +3 -3 + [Bug 2932] Update leapsecond file info in miscopt.html. CWoodbury, HStenn. + +ChangeSet@1.3588, 2015-11-17 05:02:10+00:00, stenn@psp-at1.ntp.org + Credit Martin for 2965 + + ChangeLog@1.1764.1.3 +1 -1 + Credit Martin for 2965 + +ChangeSet@1.3587, 2015-11-17 04:53:39+00:00, stenn@psp-at1.ntp.org + cleanup + + ChangeLog@1.1764.1.2 +1 -1 + cleanup + +ChangeSet@1.3584.2.1, 2015-11-16 11:59:55+01:00, burnicki@pc-martin4. + [Bug 2965] Local clock didn't work since 4.2.8p4 + + ChangeLog@1.1764.1.1 +1 -0 + [Bug 2965] Local clock didn't work since 4.2.8p4 + + ntpd/refclock_local.c@1.22 +1 -0 + [Bug 2965] Local clock didn't work since 4.2.8p4 + +ChangeSet@1.3584.1.2, 2015-11-14 01:01:05+01:00, jnperlin@hydra.localnet + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fix warnings in test cases + + tests/libntp/a_md5encrypt.c@1.14 +23 -15 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fix terrible const/noconst and alignment mess + + tests/libntp/authkeys.c@1.12 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fixed cast to const cast + + tests/libntp/run-a_md5encrypt.c@1.15 +5 -5 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - update generated file + + tests/ntpd/rc_cmdlength.c@1.3 +1 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - add header to get prototype + + tests/ntpd/run-rc_cmdlength.c@1.4 +2 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + +ChangeSet@1.3584.1.1, 2015-11-13 22:54:35+01:00, jnperlin@hydra.localnet + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fixed several other warnings (cast-alignment, missing const, missing prorotypes) + - promote use of 'size_t' for values that express a size + - use ptr-to-const for read-only arguments + - make sure SOCKET values are not truncated (win32-specific) + - format string fixes + + ChangeLog@1.1765 +6 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets. + + include/Makefile.am@1.53 +1 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - added 'safeconst.h' to noinstall-headers + + include/ntp_refclock.h@1.37 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use ptr-to-const for read-only values + + include/ntp_stdlib.h@1.80 +4 -4 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - use ptr-to-const for read-only data + + include/ntpd.h@1.193 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + include/safecast.h@1.1 +34 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - checked or saturated size conversion + - added unaligned pointer casts + + include/safecast.h@1.0 +0 -0 + + lib/isc/backtrace.c@1.3 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid increased-alignment-earning in pointer cast + + lib/isc/buffer.c@1.2 +2 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + lib/isc/inet_aton.c@1.6 +2 -3 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + lib/isc/inet_pton.c@1.7 +3 -3 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + lib/isc/log.c@1.9 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + lib/isc/netaddr.c@1.14 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - explicit cast (no overflow) to u_int + + lib/isc/sockaddr.c@1.13 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - explicit cast to 'u_int' (no overflow possible) + + lib/isc/task.c@1.8 +8 -8 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid warnings about increased alignment requirements (not using 'safecast.h' since it's not in this lib) + + lib/isc/win32/interfaceiter.c@1.23 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid truncation of SOCKET + + lib/isc/win32/net.c@1.17 +2 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid truncation of SOCKET + + libntp/a_md5encrypt.c@1.35 +14 -14 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - use ptr-to-const for read-only values + + libntp/atolfp.c@1.7 +2 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - explit cast from size_t to u_long (no overflow possoble) + + libntp/authkeys.c@1.27.1.1 +4 -4 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + libntp/authusekey.c@1.10 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + libntp/dolfptoa.c@1.12 +3 -3 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - explicit cast to size_t to in (no overflow possible) + + libntp/hextolfp.c@1.5 +6 -4 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - explicit cast size_t to u_long (no overflow possible) + + libntp/mstolfp.c@1.5 +1 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + libntp/msyslog.c@1.54 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + libntp/ntp_crypto_rnd.c@1.4 +2 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use checked cast for interface with openSSL + + libntp/ntp_lineedit.c@1.14 +2 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - downcast of size_t (no risk here) + + libntp/ntp_worker.c@1.6 +2 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - downcast of size_t (no real risk of overflow) + + libntp/snprintf.c@1.13 +10 -10 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use explicit downcasts in conversions + + libparse/clk_computime.c@1.13 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_dcf7000.c@1.13 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_hopf6021.c@1.12 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_meinberg.c@1.16 +2 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_rawdcf.c@1.23 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_rcc8000.c@1.12 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_schmid.c@1.15 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_trimtaip.c@1.13 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_varitext.c@1.12 +6 -6 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - commented unused static const values + --- + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/clk_wharton.c@1.11 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + libparse/parse.c@1.21 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use "%p" to format pointers + + ntpd/ntp_control.c@1.205 +5 -5 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + ntpd/ntp_crypto.c@1.185 +2 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fix small signed/unsigned clash + + ntpd/ntp_io.c@1.409 +6 -6 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - remove cast-alignment warnings by casting via 'void*' + - proper cast from SOCKET to int when file descriptor needed + + ntpd/ntp_loopfilter.c@1.188 +2 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid 'unused' warnings + + ntpd/ntp_proto.c@1.369 +8 -6 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - format string fixes + - fix signed/unsigned clash + + ntpd/ntp_refclock.c@1.121 +3 -3 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use ptr-to-const for read-only parameters + + ntpd/ntp_request.c@1.115 +2 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid serious LP64 problem by using uint32_t instead of u_long + + ntpd/ntp_restrict.c@1.40 +2 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + ntpd/ntp_signd.c@1.5 +3 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fixed missing 'const' in cast + + ntpd/ntp_timer.c@1.93 +7 -6 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid mixed float/int calculations + + ntpd/ntp_util.c@1.117 +3 -3 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + ntpd/refclock_parse.c@1.82 +2 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + ntpd/refclock_shm.c@1.38 +3 -2 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fixed some volatile madness & casts + + ntpd/refclock_true.c@1.25 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + ntpd/refclock_tsyncpci.c@1.10 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - remove cast-alignment warnings by omitting superfluous cast + + ntpdate/ntpdate.c@1.97 +7 -7 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - avoid truncation of SOCKET handles + + ntpdc/ntpdc.c@1.105 +36 -34 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - format string fixes + + ntpdc/ntpdc.h@1.12 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + ntpdc/ntpdc_ops.c@1.81 +109 -109 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - format string fixes + + ntpq/libntpq.c@1.13 +7 -9 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - format string fixes + + ntpq/libntpq.h@1.11 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - more size_t propagation and format string fixes + + ntpq/libntpq_subs.c@1.7 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - more size_t propagation and format string fixes + + ntpq/ntpq-subs.c@1.112 +39 -37 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - format string fixes + + ntpq/ntpq.c@1.163 +34 -34 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - format string fixes + + ntpq/ntpq.h@1.30 +7 -7 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + + ports/winnt/include/config.h@1.113 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - use ptr-to-const for read-only values + + ports/winnt/include/ntp_iocompletionport.h@1.21 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid truncation of SOCKET identifiers + + ports/winnt/instsrv/instsrv.c@1.7 +6 -6 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - explicit cast to DWORD (overflow hardly possible) + + ports/winnt/libntp/termios.c@1.32 +18 -16 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - promote use of 'size_t' for values that express a size + - use ptr-to-const for read-only values + - avoid truncation of handle + + ports/winnt/ntpd/ntp_iocompletionport.c@1.72 +9 -6 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - avoid truncation of SOCKET handles + + ports/winnt/vs2008/common.vsprops@1.2 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - disable a size_t cast warnings + + ports/winnt/vs2008/ntpd/ntpd.vcproj@1.50 +49 -17 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - disable C4307 (integer constant overflow) on refclock_arc.c + + ports/winnt/vs2013/common.props@1.2 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - disable the annoying truncation-of-value error + + ports/winnt/vs2013/libntp/libntp.vcxproj@1.9 +1 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - add 'safecast.h' header + + ports/winnt/vs2013/libntp/libntp.vcxproj.filters@1.7 +3 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - add safecast.h header + + ports/winnt/vs2013/ntpd/ntpd.vcxproj@1.8 +7 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - refclock_arc is very noisy with integer constant overflow + + sntp/networking.c@1.67 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - remove cast-alignment warnings by casting via 'void*' + + tests/libntp/authkeys.c@1.11 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fix missing 'const' in cast + + tests/ntpd/ntp_restrict.c@1.3 +1 -0 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fix function declarations + + tests/ntpd/run-ntp_restrict.c@1.5 +8 -8 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - update auto-generated file + + tests/ntpd/run-t-ntp_signd.c@1.9 +7 -7 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fix function prototypes + + tests/ntpd/t-ntp_scanner.c@1.7 +3 -3 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - add missing 'const' declarations + + tests/ntpd/t-ntp_signd.c@1.11 +24 -13 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - added missing prototypes and a fix serious pointer problem + + tests/sandbox/run-uglydate.c@1.3.1.1 +1 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - update generated file + + tests/sandbox/uglydate.c@1.2.1.1 +4 -1 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - add prototypes + + tests/sec-2853/sec-2853.c@1.7 +6 -6 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - fix size_t format + + util/ntp-keygen.c@1.107 +3 -3 + [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets + - let openssl sort out the string size + +ChangeSet@1.3585, 2015-11-07 23:46:41+00:00, stenn@psp-at1.ntp.org + Unity test cleanup. Harlan Stenn. + + sntp/tests/t-log.c@1.4 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/run-uglydate.c@1.4 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/uglydate.c@1.3 +2 -0 + Unity test cleanup. Harlan Stenn. + +ChangeSet@1.3581.1.1, 2015-11-06 08:33:23+01:00, jnperlin@hydra.localnet + [Bug 2957] format specifies type 'unsigned int' but the argument has type 'size_t' + - accept key file only if there are no parsing errors + - fixed size_t/u_int format clash + - restore pre-Bug1243 compatibility (revert 'strlcpy()' to 'strncpy()' as 'strlcpy()' is wrong here) + + ChangeLog@1.1761.1.1 +4 -0 + [Bug 2957] format specifies type 'unsigned int' but the argument has type 'size_t' + - accept key file only if there are no parsing errors + - fixed size_t/u_int format clash + - restore pre-Bug1243 compatibility (revert 'strlcpy()' to 'strncpy()' as 'strlcpy()' is wrong here) + + libntp/authkeys.c@1.28 +17 -5 + [Bug 2957] format specifies type 'unsigned int' but the argument has type 'size_t' + - restore pre-Bug1243 compatibility (revert 'strlcpy()' to 'strncpy()' as 'strlcpy()' is wrong here) + + libntp/authreadkeys.c@1.23 +68 -22 + [Bug 2957] format specifies type 'unsigned int' but the argument has type 'size_t' + - accept key file only if there are no parsing errors + - fixed size_t/u_int format clash + +ChangeSet@1.3584, 2015-11-05 11:47:50+00:00, stenn@psp-at1.ntp.org + Unity test cleanup. Harlan Stenn. + + ChangeLog@1.1764 +1 -0 + Unity test cleanup. Harlan Stenn. + + sntp/tests/run-t-log.c@1.4 +1 -1 + Unity test cleanup. Harlan Stenn. + + sntp/tests/t-log.c@1.3 +1 -0 + Unity test cleanup. Harlan Stenn. + + sntp/tests/utilities.c@1.5 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/bug-2803/bug-2803.c@1.10 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/bug-2803/run-bug-2803.c@1.9 +2 -0 + Unity test cleanup. Harlan Stenn. + + tests/libntp/a_md5encrypt.c@1.13 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/caljulian.c@1.11 +4 -4 + Unity test cleanup. Harlan Stenn. + + tests/libntp/lfpfunc.c@1.14 +9 -9 + Unity test cleanup. Harlan Stenn. + + tests/libntp/netof.c@1.7 +10 -10 + Unity test cleanup. Harlan Stenn. + + tests/libntp/prettydate.c@1.5 +3 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/recvbuff.c@1.6 +1 -1 + Unity test cleanup. Harlan Stenn. + + tests/libntp/socktoa.c@1.10 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/libntp/uglydate.c@1.9 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/smeartest.c@1.8 +1 -0 + Unity test cleanup. Harlan Stenn. + + tests/sandbox/uglydate.c@1.2 +2 -2 + Unity test cleanup. Harlan Stenn. + + tests/sec-2853/sec-2853.c@1.6 +1 -4 + Unity test cleanup. Harlan Stenn. + +ChangeSet@1.3583, 2015-11-05 10:37:38+00:00, stenn@psp-at1.ntp.org + Unity cleanup for FreeBSD-6.4. Harlan Stenn. + + ChangeLog@1.1763 +1 -1 + Unity cleanup for FreeBSD-6.4. Harlan Stenn. + + ChangeLog@1.1762 +1 -0 + Unity cleanup for FreeBSD-6.2. Harlan Stenn. + + sntp/m4/ntp_problemtests.m4@1.4 +4 -1 + Unity cleanup for FreeBSD-6.4. Harlan Stenn. + +ChangeSet@1.3582, 2015-11-05 10:01:57+00:00, stenn@psp-at1.ntp.org + Sec 2956 cleanup + + include/ntpd.h@1.192 +1 -0 + Sec 2956 cleanup + + libntp/systime.c@1.70 +2 -3 + Sec 2956 cleanup + + ntpd/ntp_loopfilter.c@1.187 +0 -2 + Sec 2956 cleanup + + ntpdate/ntpdate.c@1.96 +0 -3 + Sec 2956 cleanup + + ntpsnmpd/ntpsnmpd.c@1.10 +0 -3 + Sec 2956 cleanup + + sntp/main.c@1.98 +0 -3 + Sec 2956 cleanup + +ChangeSet@1.3581, 2015-11-04 10:02:25+00:00, stenn@psp-at1.ntp.org + [Bug 2934] tests/ntpd/t-ntp_scanner.c has a magic constant wired in. HMurray + + ChangeLog@1.1761 +2 -1 + [Bug 2934] tests/ntpd/t-ntp_scanner.c has a magic constant wired in. HMurray + + tests/ntpd/t-ntp_scanner.c@1.6 +1 -1 + [Bug 2934] tests/ntpd/t-ntp_scanner.c has a magic constant wired in. HMurray + +ChangeSet@1.3580, 2015-11-04 08:39:12+00:00, stenn@psp-at1.ntp.org + [Sec 2956] small-step/big-step. Close the panic gate earlier. + + ChangeLog@1.1760 +2 -0 + [Sec 2956] small-step/big-step. Close the panic gate earlier. + + libntp/systime.c@1.69 +23 -2 + [Sec 2956] small-step/big-step. Close the panic gate earlier. + + ntpd/ntp_loopfilter.c@1.186 +17 -27 + [Sec 2956] small-step/big-step. Close the panic gate earlier. + + ntpdate/ntpdate.c@1.95 +3 -0 + [Sec 2956] small-step/big-step. Close the panic gate earlier. + + ntpsnmpd/ntpsnmpd.c@1.9 +3 -0 + [Sec 2956] small-step/big-step. Close the panic gate earlier. + + sntp/main.c@1.97 +3 -0 + [Sec 2956] small-step/big-step. Close the panic gate earlier. + +ChangeSet@1.3579, 2015-11-03 22:08:46+01:00, jnperlin@hydra.localnet + [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - limit threading warm-up to linux; FreeBSD bombs on it. perlinger@ntp.org + + ChangeLog@1.1759 +1 -0 + [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - limit threading warm-up to linux; FreeBSD bombs on it. perlinger@ntp.org + + ntpd/ntpd.c@1.166 +9 -2 + [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - limit threading warm-up to linux; FreeBSD bombs on it. perlinger@ntp.org + +ChangeSet@1.3578, 2015-10-31 18:04:18+00:00, perlinger@psp-deb1.ntp.org + [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - fixed race conditions between worker and main thread in DNS worker + + ChangeLog@1.1758 +3 -0 + [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - fixed race conditions between worker and main thread in DNS worker + + include/ntp_worker.h@1.4 +45 -21 + [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - provide shared access lock based on semaphore + - better isolation of OS dependencies + + libntp/work_thread.c@1.18 +370 -231 + [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault + - fixed race conditions between worker and main thread + - better (still not perfect) isolation of OS dependent code for semaphore handling + ChangeSet@1.3577, 2015-10-21 12:42:02-04:00, stenn@deacon.udel.edu NTP_4_2_8P4 TAG: NTP_4_2_8P4 diff --git a/NEWS b/NEWS index e16d93700837..32c9288e63bb 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,108 @@ +--- + +NTP 4.2.8p5 + +Focus: Security, Bug fixes, enhancements. + +Severity: MEDIUM + +In addition to bug fixes and enhancements, this release fixes the +following medium-severity vulnerability: + +* Small-step/big-step. Close the panic gate earlier. + References: Sec 2956, CVE-2015-5300 + Affects: All ntp-4 releases up to, but not including 4.2.8p5, and + 4.3.0 up to, but not including 4.3.78 + CVSS3: (AV:N/AC:H/PR:H/UI:R/S:C/C:L/I:N/A:L) Base Score: 4.0, MEDIUM + Summary: If ntpd is always started with the -g option, which is + common and against long-standing recommendation, and if at the + moment ntpd is restarted an attacker can immediately respond to + enough requests from enough sources trusted by the target, which + is difficult and not common, there is a window of opportunity + where the attacker can cause ntpd to set the time to an + arbitrary value. Similarly, if an attacker is able to respond + to enough requests from enough sources trusted by the target, + the attacker can cause ntpd to abort and restart, at which + point it can tell the target to set the time to an arbitrary + value if and only if ntpd was re-started against long-standing + recommendation with the -g flag, or if ntpd was not given the + -g flag, the attacker can move the target system's time by at + most 900 seconds' time per attack. + Mitigation: + Configure ntpd to get time from multiple sources. + Upgrade to 4.2.8p5, or later, from the NTP Project Download + Page or the NTP Public Services Project Download Page + As we've long documented, only use the -g option to ntpd in + cold-start situations. + Monitor your ntpd instances. + Credit: This weakness was discovered by Aanchal Malhotra, + Isaac E. Cohen, and Sharon Goldberg at Boston University. + + NOTE WELL: The -g flag disables the limit check on the panic_gate + in ntpd, which is 900 seconds by default. The bug identified by + the researchers at Boston University is that the panic_gate + check was only re-enabled after the first change to the system + clock that was greater than 128 milliseconds, by default. The + correct behavior is that the panic_gate check should be + re-enabled after any initial time correction. + + If an attacker is able to inject consistent but erroneous time + responses to your systems via the network or "over the air", + perhaps by spoofing radio, cellphone, or navigation satellite + transmissions, they are in a great position to affect your + system's clock. There comes a point where your very best + defenses include: + + Configure ntpd to get time from multiple sources. + Monitor your ntpd instances. + +Other fixes: + +* Coverity submission process updated from Coverity 5 to Coverity 7. + The NTP codebase has been undergoing regular Coverity scans on an + ongoing basis since 2006. As part of our recent upgrade from + Coverity 5 to Coverity 7, Coverity identified 16 nits in some of + the newly-written Unity test programs. These were fixed. +* [Bug 2829] Clean up pipe_fds in ntpd.c perlinger@ntp.org +* [Bug 2887] stratum -1 config results as showing value 99 + - fudge stratum should only accept values [0..16]. perlinger@ntp.org +* [Bug 2932] Update leapsecond file info in miscopt.html. CWoodbury, HStenn. +* [Bug 2934] tests/ntpd/t-ntp_scanner.c has a magic constant wired in. HMurray +* [Bug 2944] errno is not preserved properly in ntpdate after sendto call. + - applied patch by Christos Zoulas. perlinger@ntp.org +* [Bug 2952] Peer associations broken by fix for Bug 2901/CVE-2015-7704. +* [Bug 2954] Version 4.2.8p4 crashes on startup on some OSes. + - fixed data race conditions in threaded DNS worker. perlinger@ntp.org + - limit threading warm-up to linux; FreeBSD bombs on it. perlinger@ntp.org +* [Bug 2957] 'unsigned int' vs 'size_t' format clash. perlinger@ntp.org + - accept key file only if there are no parsing errors + - fixed size_t/u_int format clash + - fixed wrong use of 'strlcpy' +* [Bug 2958] ntpq: fatal error messages need a final newline. Craig Leres. +* [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets. perlinger@ntp.org + - fixed several other warnings (cast-alignment, missing const, missing prototypes) + - promote use of 'size_t' for values that express a size + - use ptr-to-const for read-only arguments + - make sure SOCKET values are not truncated (win32-specific) + - format string fixes +* [Bug 2965] Local clock didn't work since 4.2.8p4. Martin Burnicki. +* [Bug 2967] ntpdate command suffers an assertion failure + - fixed ntp_rfc2553.c to return proper address length. perlinger@ntp.org +* [Bug 2969] Seg fault from ntpq/mrulist when looking at server with + lots of clients. perlinger@ntp.org +* [Bug 2971] ntpq bails on ^C: select fails: Interrupted system call + - changed stacked/nested handling of CTRL-C. perlinger@ntp.org +* Unity cleanup for FreeBSD-6.4. Harlan Stenn. +* Unity test cleanup. Harlan Stenn. +* Libevent autoconf pthread fixes for FreeBSD-10. Harlan Stenn. +* Header cleanup in tests/sandbox/uglydate.c. Harlan Stenn. +* Header cleanup in tests/libntp/sfptostr.c. Harlan Stenn. +* Quiet a warning from clang. Harlan Stenn. + --- NTP 4.2.8p4 -Focus: Security, Bug fies, enhancements. +Focus: Security, Bug fixes, enhancements. Severity: MEDIUM @@ -339,8 +440,8 @@ Credit: This weakness was discovered by Aleksandar Nikolic of Cisco Talos. Backward-Incompatible changes: * [Bug 2817] Default on Linux is now "rlimit memlock -1". -While the general default of 32M is still the case, under Linux -the default value has been changed to -1 (do not lock ntpd into + While the general default of 32M is still the case, under Linux + the default value has been changed to -1 (do not lock ntpd into memory). A value of 0 means "lock ntpd into memory with whatever memory it needs." If your ntp.conf file has an explicit "rlimit memlock" value in it, that value will continue to be used. diff --git a/configure b/configure index 04813a8d5245..758ffa926a52 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for ntp 4.2.8p4. +# Generated by GNU Autoconf 2.69 for ntp 4.2.8p5. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='ntp' PACKAGE_TARNAME='ntp' -PACKAGE_VERSION='4.2.8p4' -PACKAGE_STRING='ntp 4.2.8p4' +PACKAGE_VERSION='4.2.8p5' +PACKAGE_STRING='ntp 4.2.8p5' PACKAGE_BUGREPORT='http://bugs.ntp.org./' PACKAGE_URL='http://www.ntp.org./' @@ -1616,7 +1616,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures ntp 4.2.8p4 to adapt to many kinds of systems. +\`configure' configures ntp 4.2.8p5 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1686,7 +1686,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of ntp 4.2.8p4:";; + short | recursive ) echo "Configuration of ntp 4.2.8p5:";; esac cat <<\_ACEOF @@ -1919,7 +1919,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -ntp configure 4.2.8p4 +ntp configure 4.2.8p5 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2749,7 +2749,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by ntp $as_me 4.2.8p4, which was +It was created by ntp $as_me 4.2.8p5, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3750,7 +3750,7 @@ fi # Define the identity of the package. PACKAGE='ntp' - VERSION='4.2.8p4' + VERSION='4.2.8p5' cat >>confdefs.h <<_ACEOF @@ -20018,9 +20018,10 @@ $as_echo "$as_me: Using the installed libevent" >&6;} # LDADD_LIBEVENT=`$PKG_CONFIG --libs libevent | sed 's:-levent::'` # So now we dance... LDADD_LIBEVENT= - for i in `$PKG_CONFIG --libs libevent` + for i in `$PKG_CONFIG --libs libevent` `$PKG_CONFIG --cflags-only-other libevent_pthreads` do case "$i" in + -D*) ;; -levent*) ;; *) case "$LDADD_LIBEVENT" in '') LDADD_LIBEVENT="$i" ;; @@ -37035,8 +37036,9 @@ $as_echo "$ntp_ept" >&6; } $as_echo_n "checking if we can run test-ntp_restrict... " >&6; } ntp_test_ntp_restrict="no" case "$ntp_ept:$cross:$host" in + no:0:*-*-freebsd6.4) ;; + no:0:*-*-hpux11.23*) ;; no:0:*-*-solaris*) ;; - no:0:*-*-hpux-11.23*) ;; *) ntp_test_ntp_restrict="yes" ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ntp_test_ntp_restrict" >&5 @@ -37054,6 +37056,7 @@ fi $as_echo_n "checking if we can run test-ntp_scanner... " >&6; } ntp_test_ntp_scanner="no" case "$ntp_ept:$cross:$host" in + no:0:*-*-freebsd6.4) ;; no:0:*-*-solaris*) ;; *) ntp_test_ntp_scanner="yes" ;; esac @@ -37072,6 +37075,7 @@ fi $as_echo_n "checking if we can run test-ntp_signd... " >&6; } ntp_test_ntp_signd="no" case "$ntp_ept:$cross:$host" in + no:0:*-*-freebsd6.4) ;; no:0:*-*-solaris*) ;; *) ntp_test_ntp_signd="yes" ;; esac @@ -37836,7 +37840,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by ntp $as_me 4.2.8p4, which was +This file was extended by ntp $as_me 4.2.8p5, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -37903,7 +37907,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -ntp config.status 4.2.8p4 +ntp config.status 4.2.8p5 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/html/miscopt.html b/html/miscopt.html index c6190222bf96..261b08faca60 100644 --- a/html/miscopt.html +++ b/html/miscopt.html @@ -3,7 +3,7 @@ Miscellaneous Commands and Options - + @@ -11,7 +11,7 @@ giffrom Pogo, Walt Kelly

We have three, now looking for more.

Last update: - 23-Sep-2015 10:20 + 17-Nov-2015 11:06 UTC


Related Links

@@ -57,7 +57,7 @@
interface [listen | ignore | drop] [all | ipv4 | ipv6 | wildcard | name | address[/prefixlen]]
This command controls which network addresses ntpd opens, and whether input is dropped without processing. The first parameter determines the action for addresses which match the second parameter. That parameter specifies a class of addresses, or a specific interface name, or an address. In the address case, prefixlen determines how many bits must match for this rule to apply. ignore prevents opening matching addresses, drop causes ntpd to open the address and drop all received packets without examination. Multiple interface commands can be used. The last rule which matches a particular address determines the action for it. interface commands are disabled if any -I, --interface, -L, or --novirtualips command-line options are used. If none of those options are used and no interface actions are specified in the configuration file, all available network addresses are opened. The nic command is an alias for interface.
leapfile leapfile
-
This command loads the NIST leapseconds file and initializes the leapsecond values for the next leapsecond time, expiration time and TAI offset. The file can be obtained directly from NIST national time servers using ftp as the ASCII file pub/leap-seconds.
+
This command loads the IERS leapseconds file and initializes the leapsecond values for the next leapsecond time, expiration time and TAI offset. The file can be obtained directly from the IERS at https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list or ftp://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list.
The leapfile is scanned when ntpd processes the leapfile directive or when ntpd detects that leapfile has changed. ntpd checks once a day to see if the leapfile has changed.
While not strictly a security function, the Autokey protocol provides means to securely retrieve the current or updated leapsecond values from a server.
leapsmearinterval seconds
diff --git a/include/Makefile.am b/include/Makefile.am index f032c97e792d..d8b4dd2b54cf 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -66,6 +66,7 @@ noinst_HEADERS = \ recvbuff.h \ refclock_atom.h \ refidsmear.h \ + safecast.h \ ssl_applink.c \ timepps-SCO.h \ timepps-Solaris.h \ diff --git a/include/Makefile.in b/include/Makefile.in index 8f0968bf77b5..6e45e93f59e0 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -551,6 +551,7 @@ noinst_HEADERS = \ recvbuff.h \ refclock_atom.h \ refidsmear.h \ + safecast.h \ ssl_applink.c \ timepps-SCO.h \ timepps-Solaris.h \ diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h index f92d14cdb890..b264dfaa0d1a 100644 --- a/include/ntp_refclock.h +++ b/include/ntp_refclock.h @@ -220,7 +220,7 @@ extern void refclock_buginfo(sockaddr_u *, extern void refclock_control(sockaddr_u *, const struct refclockstat *, struct refclockstat *); -extern int refclock_open (char *, u_int, u_int); +extern int refclock_open (const char *, u_int, u_int); extern int refclock_setup (int, u_int, u_int); extern void refclock_timer (struct peer *); extern void refclock_transmit(struct peer *); diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index a2e62dabefd9..d735b41f4ba7 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -65,8 +65,8 @@ typedef void (*ctrl_c_fn)(void); /* authkeys.c */ extern void auth_delkeys (void); extern int auth_havekey (keyid_t); -extern int authdecrypt (keyid_t, u_int32 *, int, int); -extern int authencrypt (keyid_t, u_int32 *, int); +extern int authdecrypt (keyid_t, u_int32 *, size_t, size_t); +extern size_t authencrypt (keyid_t, u_int32 *, size_t); extern int authhavekey (keyid_t); extern int authistrusted (keyid_t); extern int authreadkeys (const char *); @@ -95,8 +95,8 @@ extern void auth_prealloc_symkeys(int); extern int ymd2yd (int, int, int); /* a_md5encrypt.c */ -extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int); -extern int MD5authencrypt (int, u_char *, u_int32 *, int); +extern int MD5authdecrypt (int, const u_char *, u_int32 *, size_t, size_t); +extern size_t MD5authencrypt (int, const u_char *, u_int32 *, size_t); extern void MD5auth_setkey (keyid_t, int, const u_char *, size_t); extern u_int32 addr2refid (sockaddr_u *); diff --git a/include/ntp_worker.h b/include/ntp_worker.h index f7e8d5be7086..50616b3df7dd 100644 --- a/include/ntp_worker.h +++ b/include/ntp_worker.h @@ -43,19 +43,22 @@ typedef struct blocking_pipe_header_tag { } blocking_pipe_header; # ifdef WORK_THREAD -# ifdef WORK_PIPE -typedef pthread_t * thr_ref; -typedef sem_t * sem_ref; +# ifdef SYS_WINNT +typedef struct { HANDLE thnd; } thread_type; +typedef struct { HANDLE shnd; } sema_type; # else -typedef HANDLE thr_ref; -typedef HANDLE sem_ref; +typedef pthread_t thread_type; +typedef sem_t sema_type; # endif +typedef thread_type *thr_ref; +typedef sema_type *sem_ref; # endif /* * */ -#ifdef WORK_FORK +#if defined(WORK_FORK) + typedef struct blocking_child_tag { int reusable; int pid; @@ -66,38 +69,59 @@ typedef struct blocking_child_tag { int resp_write_pipe; int ispipe; } blocking_child; + #elif defined(WORK_THREAD) + typedef struct blocking_child_tag { /* * blocking workitems and blocking_responses are dynamically-sized * one-dimensional arrays of pointers to blocking worker requests and * responses. + * + * IMPORTANT: This structure is shared between threads, and all access + * that is not atomic (especially queue operations) must hold the + * 'accesslock' semaphore to avoid data races. + * + * The resource management (thread/semaphore creation/destruction) + * functions and functions just testing a handle are safe because these + * are only changed by the main thread when no worker is running on the + * same data structure. */ int reusable; - thr_ref thread_ref; - u_int thread_id; - blocking_pipe_header * volatile * volatile + sem_ref accesslock; /* shared access lock */ + thr_ref thread_ref; /* thread 'handle' */ + + /* the reuest queue */ + blocking_pipe_header ** volatile workitems; volatile size_t workitems_alloc; - size_t next_workitem; /* parent */ - size_t next_workeritem; /* child */ - blocking_pipe_header * volatile * volatile + size_t head_workitem; /* parent */ + size_t tail_workitem; /* child */ + sem_ref workitems_pending; /* signalling */ + + /* the response queue */ + blocking_pipe_header ** volatile responses; volatile size_t responses_alloc; - size_t next_response; /* child */ - size_t next_workresp; /* parent */ + size_t head_response; /* child */ + size_t tail_response; /* parent */ + /* event handles / sem_t pointers */ - /* sem_ref child_is_blocking; */ - sem_ref blocking_req_ready; sem_ref wake_scheduled_sleep; + + /* some systems use a pipe for notification, others a semaphore. + * Both employ the queue above for the actual data transfer. + */ #ifdef WORK_PIPE - int resp_read_pipe; /* parent */ - int resp_write_pipe;/* child */ + int resp_read_pipe; /* parent */ + int resp_write_pipe; /* child */ int ispipe; - void * resp_read_ctx; /* child */ + void * resp_read_ctx; /* child */ #else - sem_ref blocking_response_ready; + sem_ref responses_pending; /* signalling */ #endif + sema_type sem_table[4]; + thread_type thr_table[1]; } blocking_child; #endif /* WORK_THREAD */ @@ -111,7 +135,7 @@ extern u_int available_blocking_child_slot(void); extern int queue_blocking_request(blocking_work_req, void *, size_t, blocking_work_callback, void *); -extern int queue_blocking_response(blocking_child *, +extern int queue_blocking_response(blocking_child *, blocking_pipe_header *, size_t, const blocking_pipe_header *); extern void process_blocking_resp(blocking_child *); diff --git a/include/ntpd.h b/include/ntpd.h index be3cd3e7619b..362068c765ed 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -156,7 +156,7 @@ extern u_int sys_tai; extern int freq_cnt; /* ntp_monitor.c */ -#define MON_HASH_SIZE (1U << mon_hash_bits) +#define MON_HASH_SIZE ((size_t)1U << mon_hash_bits) #define MON_HASH_MASK (MON_HASH_SIZE - 1) #define MON_HASH(addr) (sock_hash(addr) & MON_HASH_MASK) extern void init_mon (void); @@ -408,6 +408,7 @@ extern int hardpps_enable; /* kernel PPS discipline enabled */ extern int ext_enable; /* external clock enabled */ extern int cal_enable; /* refclock calibrate enable */ extern int allow_panic; /* allow panic correction (-g) */ +extern int enable_panic_check; /* Can we check allow_panic's state? */ extern int force_step_once; /* always step time once at startup (-G) */ extern int mode_ntpdate; /* exit on first clock set (-q) */ extern int peer_ntpdate; /* count of ntpdate peers */ diff --git a/include/safecast.h b/include/safecast.h new file mode 100644 index 000000000000..93004633a18a --- /dev/null +++ b/include/safecast.h @@ -0,0 +1,34 @@ +#ifndef SAFECAST_H +#define SAFECAST_H + +#include +static inline int size2int_chk(size_t v) +{ + if (v > INT_MAX) + abort(); + return (int)(v); +} + +static inline int size2int_sat(size_t v) +{ + return (v > INT_MAX) ? INT_MAX : (int)v; +} + +/* Compilers can emit warning about increased alignment requirements + * when casting pointers. The impact is tricky: on machines where + * alignment is just a performance issue (x86,x64,...) this might just + * cause a performance penalty. On others, an address error can occur + * and the process dies... + * + * Still, there are many cases where the pointer arithmetic and the + * buffer alignment make sure this does not happen. OTOH, the compiler + * doesn't know this and still emits warnings. + * + * The following cast macros are going through void pointers to tell + * the compiler that there is no alignment requirement to watch. + */ +#define UA_PTR(ptype,pval) ((ptype *)(void*)(pval)) +#define UAC_PTR(ptype,pval) ((const ptype *)(const void*)(pval)) +#define UAV_PTR(ptype,pval) ((volatile ptype *)(volatile void*)(pval)) + +#endif diff --git a/lib/isc/backtrace.c b/lib/isc/backtrace.c index 4274da31b463..e0425e14f41c 100644 --- a/lib/isc/backtrace.c +++ b/lib/isc/backtrace.c @@ -278,7 +278,7 @@ isc_backtrace_getsymbol(const void *addr, const char **symbolp, result = ISC_R_NOTFOUND; else { *symbolp = found->symbol; - *offsetp = (const char *)addr - (char *)found->addr; + *offsetp = (u_long)((const char *)addr - (char *)found->addr); } return (result); diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 1b59e650acde..6a50985c74ab 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -406,7 +406,7 @@ isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base, void isc__buffer_putstr(isc_buffer_t *b, const char *source) { - unsigned int l; + size_t l; unsigned char *cp; REQUIRE(ISC_BUFFER_VALID(b)); @@ -421,7 +421,7 @@ isc__buffer_putstr(isc_buffer_t *b, const char *source) { cp = isc_buffer_used(b); memcpy(cp, source, l); - b->used += l; + b->used += (u_int)l; /* checked above - no overflow here */ } isc_result_t diff --git a/lib/isc/inet_aton.c b/lib/isc/inet_aton.c index 14b4887f4f16..3fc3a4db87a5 100644 --- a/lib/isc/inet_aton.c +++ b/lib/isc/inet_aton.c @@ -92,7 +92,7 @@ static char rcsid[] = "$Id: inet_aton.c,v 1.23 2008/12/01 23:47:45 tbox Exp $"; int isc_net_aton(const char *cp, struct in_addr *addr) { unsigned long val; - int base, n; + int base; unsigned char c; isc_uint8_t parts[4]; isc_uint8_t *pp = parts; @@ -166,8 +166,7 @@ isc_net_aton(const char *cp, struct in_addr *addr) { * Concoct the address according to * the number of parts specified. */ - n = pp - parts + 1; - switch (n) { + switch (pp - parts + 1) { case 1: /* a -- 32 bits */ break; diff --git a/lib/isc/inet_pton.c b/lib/isc/inet_pton.c index 66b5de0bf4d2..eac631b58ea3 100644 --- a/lib/isc/inet_pton.c +++ b/lib/isc/inet_pton.c @@ -92,7 +92,7 @@ inet_pton4(const char *src, unsigned char *dst) { const char *pch; if ((pch = strchr(digits, ch)) != NULL) { - unsigned int newv = *tp * 10 + (pch - digits); + size_t newv = *tp * 10 + (pch - digits); if (saw_digit && *tp == 0) return (0); @@ -197,12 +197,12 @@ inet_pton6(const char *src, unsigned char *dst) { * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const size_t n = tp - colonp; int i; if (tp == endp) return (0); - for (i = 1; i <= n; i++) { + for (i = 1; (size_t)i <= n; i++) { endp[- i] = colonp[n - i]; colonp[n - i] = 0; } diff --git a/lib/isc/log.c b/lib/isc/log.c index 38f0c4ff51e6..dfe4fdfd497a 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -1146,7 +1146,7 @@ greatest_version(isc_logchannel_t *channel, int *greatestp) { char *basenam, *digit_end; const char *dirname; int version, greatest = -1; - unsigned int basenamelen; + size_t basenamelen; isc_dir_t dir; isc_result_t result; char sep = '/'; diff --git a/lib/isc/netaddr.c b/lib/isc/netaddr.c index 457576b77dd8..9710466281c6 100644 --- a/lib/isc/netaddr.c +++ b/lib/isc/netaddr.c @@ -159,7 +159,7 @@ isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target) { if (r == NULL) return (ISC_R_FAILURE); - alen = strlen(abuf); + alen = (unsigned int)strlen(abuf); /* no overflow possible */ INSIST(alen < sizeof(abuf)); zlen = 0; diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c index 1ae5e7c91697..c6932d48f2bb 100644 --- a/lib/isc/sockaddr.c +++ b/lib/isc/sockaddr.c @@ -134,7 +134,7 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { break; #ifdef ISC_PLAFORM_HAVESYSUNH case AF_UNIX: - plen = strlen(sockaddr->type.sunix.sun_path); + plen = (unsigned int)strlen(sockaddr->type.sunix.sun_path); if (plen >= isc_buffer_availablelength(target)) return (ISC_R_NOSPACE); @@ -153,7 +153,7 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { return (ISC_R_FAILURE); } - plen = strlen(pbuf); + plen = (unsigned int)strlen(pbuf); INSIST(plen < sizeof(pbuf)); isc_netaddr_fromsockaddr(&netaddr, sockaddr); diff --git a/lib/isc/task.c b/lib/isc/task.c index cd19d2d5270b..5b899b350423 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -329,7 +329,7 @@ ISC_TASKFUNC_SCOPE isc_result_t isc__task_create(isc_taskmgr_t *manager0, unsigned int quantum, isc_task_t **taskp) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; + isc__taskmgr_t *manager = (void*)manager0; isc__task_t *task; isc_boolean_t exiting; isc_result_t result; @@ -1463,7 +1463,7 @@ isc__taskmgr_destroy(isc_taskmgr_t **managerp) { */ REQUIRE(managerp != NULL); - manager = (isc__taskmgr_t *)*managerp; + manager = (void*)(*managerp); REQUIRE(VALID_MANAGER(manager)); #ifndef USE_WORKER_THREADS @@ -1559,7 +1559,7 @@ isc__taskmgr_destroy(isc_taskmgr_t **managerp) { ISC_TASKFUNC_SCOPE void isc__taskmgr_setmode(isc_taskmgr_t *manager0, isc_taskmgrmode_t mode) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; + isc__taskmgr_t *manager = (void*)manager0; LOCK(&manager->lock); manager->mode = mode; @@ -1568,7 +1568,7 @@ isc__taskmgr_setmode(isc_taskmgr_t *manager0, isc_taskmgrmode_t mode) { ISC_TASKFUNC_SCOPE isc_taskmgrmode_t isc__taskmgr_mode(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; + isc__taskmgr_t *manager = (void*)manager0; isc_taskmgrmode_t mode; LOCK(&manager->lock); mode = manager->mode; @@ -1579,7 +1579,7 @@ isc__taskmgr_mode(isc_taskmgr_t *manager0) { #ifndef USE_WORKER_THREADS isc_boolean_t isc__taskmgr_ready(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; + isc__taskmgr_t *manager = (void*)manager0; isc_boolean_t is_ready; #ifdef USE_SHARED_MANAGER @@ -1598,7 +1598,7 @@ isc__taskmgr_ready(isc_taskmgr_t *manager0) { isc_result_t isc__taskmgr_dispatch(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; + isc__taskmgr_t *manager = (void*)manager0; #ifdef USE_SHARED_MANAGER if (manager == NULL) @@ -1615,7 +1615,7 @@ isc__taskmgr_dispatch(isc_taskmgr_t *manager0) { #else ISC_TASKFUNC_SCOPE void isc__taskmgr_pause(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; + isc__taskmgr_t *manager = (void*)manager0; LOCK(&manager->lock); while (manager->tasks_running > 0) { WAIT(&manager->paused, &manager->lock); @@ -1626,7 +1626,7 @@ isc__taskmgr_pause(isc_taskmgr_t *manager0) { ISC_TASKFUNC_SCOPE void isc__taskmgr_resume(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; + isc__taskmgr_t *manager = (void*)manager0; LOCK(&manager->lock); if (manager->pause_requested) { diff --git a/lib/isc/win32/interfaceiter.c b/lib/isc/win32/interfaceiter.c index 8753aa8a9977..af52788f231c 100644 --- a/lib/isc/win32/interfaceiter.c +++ b/lib/isc/win32/interfaceiter.c @@ -54,7 +54,7 @@ struct isc_interfaceiter { IP_ADAPTER_ADDRESSES * ipaaCur; /* enumeration position */ IP_ADAPTER_UNICAST_ADDRESS *ipuaCur; /* enumeration subposition */ /* fields used for the older address enumeration ioctls */ - int socket; + SOCKET socket; INTERFACE_INFO IFData; /* Current Interface Info */ int numIF; /* Current Interface count */ int v4IF; /* Number of IPv4 Interfaces */ diff --git a/lib/isc/win32/net.c b/lib/isc/win32/net.c index 12876da2b880..53e143556721 100644 --- a/lib/isc/win32/net.c +++ b/lib/isc/win32/net.c @@ -216,7 +216,8 @@ initialize_ipv6only(void) { static void try_ipv6pktinfo(void) { - int s, on; + SOCKET s; + int on; char strbuf[ISC_STRERRORSIZE]; isc_result_t result; int optname; diff --git a/libntp/a_md5encrypt.c b/libntp/a_md5encrypt.c index ffabc47c7d09..beaf6fd35b05 100644 --- a/libntp/a_md5encrypt.c +++ b/libntp/a_md5encrypt.c @@ -16,12 +16,12 @@ * * Returns length of MAC including key ID and digest. */ -int +size_t MD5authencrypt( - int type, /* hash algorithm */ - u_char *key, /* key pointer */ - u_int32 *pkt, /* packet pointer */ - int length /* packet length */ + int type, /* hash algorithm */ + const u_char * key, /* key pointer */ + u_int32 * pkt, /* packet pointer */ + size_t length /* packet length */ ) { u_char digest[EVP_MAX_MD_SIZE]; @@ -44,7 +44,7 @@ MD5authencrypt( EVP_DigestInit(&ctx, EVP_get_digestbynid(type)); #endif EVP_DigestUpdate(&ctx, key, cache_secretsize); - EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length); + EVP_DigestUpdate(&ctx, (u_char *)pkt, length); EVP_DigestFinal(&ctx, digest, &len); memmove((u_char *)pkt + length + 4, digest, len); return (len + 4); @@ -58,11 +58,11 @@ MD5authencrypt( */ int MD5authdecrypt( - int type, /* hash algorithm */ - u_char *key, /* key pointer */ - u_int32 *pkt, /* packet pointer */ - int length, /* packet length */ - int size /* MAC size */ + int type, /* hash algorithm */ + const u_char * key, /* key pointer */ + u_int32 * pkt, /* packet pointer */ + size_t length, /* packet length */ + size_t size /* MAC size */ ) { u_char digest[EVP_MAX_MD_SIZE]; @@ -85,14 +85,14 @@ MD5authdecrypt( EVP_DigestInit(&ctx, EVP_get_digestbynid(type)); #endif EVP_DigestUpdate(&ctx, key, cache_secretsize); - EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length); + EVP_DigestUpdate(&ctx, (u_char *)pkt, length); EVP_DigestFinal(&ctx, digest, &len); - if ((u_int)size != len + 4) { + if (size != (size_t)len + 4) { msyslog(LOG_ERR, "MAC decrypt: MAC length error"); return (0); } - return !memcmp(digest, (char *)pkt + length + 4, len); + return !memcmp(digest, (const char *)pkt + length + 4, len); } /* diff --git a/libntp/atolfp.c b/libntp/atolfp.c index 9a2f6917873a..439194eda9bb 100644 --- a/libntp/atolfp.c +++ b/libntp/atolfp.c @@ -68,7 +68,7 @@ atolfp( while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) { dec_i = (dec_i << 3) + (dec_i << 1); /* multiply by 10 */ - dec_i += (ind - digits); + dec_i += (u_long)(ind - digits); cp++; } @@ -80,7 +80,7 @@ atolfp( && (ind = strchr(digits, *cp)) != NULL) { ndec++; dec_f = (dec_f << 3) + (dec_f << 1); /* *10 */ - dec_f += (ind - digits); + dec_f += (u_long)(ind - digits); cp++; } diff --git a/libntp/authkeys.c b/libntp/authkeys.c index 667ca298b96f..f7462a2463ae 100644 --- a/libntp/authkeys.c +++ b/libntp/authkeys.c @@ -63,7 +63,7 @@ symkey key_listhead; /* list of all in-use keys */; * keyid. We make this fairly big for potentially busy servers. */ #define DEF_AUTHHASHSIZE 64 -//#define HASHMASK ((HASHSIZE)-1) +/*#define HASHMASK ((HASHSIZE)-1)*/ #define KEYHASH(keyid) ((keyid) & authhashmask) int authhashdisabled; @@ -511,7 +511,17 @@ authistrusted( return TRUE; } - +/* Note: There are two locations below where 'strncpy()' is used. While + * this function is a hazard by itself, it's essential that it is used + * here. Bug 1243 involved that the secret was filled with NUL bytes + * after the first NUL encountered, and 'strlcpy()' simply does NOT have + * this behaviour. So disabling the fix and reverting to the buggy + * behaviour due to compatibility issues MUST also fill with NUL and + * this needs 'strncpy'. Also, the secret is managed as a byte blob of a + * given size, and eventually truncating it and replacing the last byte + * with a NUL would be a bug. + * perlinger@ntp.org 2015-10-10 + */ void MD5auth_setkey( keyid_t keyno, @@ -546,7 +556,8 @@ MD5auth_setkey( #ifndef DISABLE_BUG1243_FIX memcpy(sk->secret, key, secretsize); #else - strlcpy((char *)sk->secret, (const char *)key, + /* >MUST< use 'strncpy()' here! See above! */ + strncpy((char *)sk->secret, (const char *)key, secretsize); #endif if (cache_keyid == keyno) { @@ -565,7 +576,8 @@ MD5auth_setkey( #ifndef DISABLE_BUG1243_FIX memcpy(secret, key, secretsize); #else - strlcpy((char *)secret, (const char *)key, secretsize); + /* >MUST< use 'strncpy()' here! See above! */ + strncpy((char *)secret, (const char *)key, secretsize); #endif allocsymkey(bucket, keyno, 0, (u_short)keytype, 0, (u_short)secretsize, secret); @@ -641,13 +653,13 @@ auth_agekeys(void) * * Returns length of authenticator field, zero if key not found. */ -int +size_t authencrypt( keyid_t keyno, u_int32 * pkt, - int length + size_t length ) -{\ +{ /* * A zero key identifier means the sender has not verified * the last message was correctly authenticated. The MAC @@ -675,8 +687,8 @@ int authdecrypt( keyid_t keyno, u_int32 * pkt, - int length, - int size + size_t length, + size_t size ) { /* diff --git a/libntp/authreadkeys.c b/libntp/authreadkeys.c index 1c4c07ca5926..95a357a8c665 100644 --- a/libntp/authreadkeys.c +++ b/libntp/authreadkeys.c @@ -77,14 +77,23 @@ nexttok( * data on global/static level. */ -static const size_t nerr_loglimit = 5u; -static const size_t nerr_maxlimit = 15; +static const u_int nerr_loglimit = 5u; +static const u_int nerr_maxlimit = 15; -static void log_maybe(size_t*, const char*, ...) NTP_PRINTF(2, 3); +static void log_maybe(u_int*, const char*, ...) NTP_PRINTF(2, 3); + +typedef struct keydata KeyDataT; +struct keydata { + KeyDataT *next; /* queue/stack link */ + keyid_t keyid; /* stored key ID */ + u_short keytype; /* stored key type */ + u_short seclen; /* length of secret */ + u_char secbuf[1]; /* begin of secret (formal only)*/ +}; static void log_maybe( - size_t *pnerr, + u_int *pnerr, const char *fmt , ...) { @@ -113,25 +122,24 @@ authreadkeys( u_char keystr[32]; /* Bug 2537 */ size_t len; size_t j; - size_t nerr; + u_int nerr; + KeyDataT *list = NULL; + KeyDataT *next = NULL; /* * Open file. Complain and return if it can't be opened. */ fp = fopen(file, "r"); if (fp == NULL) { - msyslog(LOG_ERR, "authreadkeys: file %s: %m", + msyslog(LOG_ERR, "authreadkeys: file '%s': %m", file); - return (0); + goto onerror; } INIT_SSL(); /* - * Remove all existing keys - */ - auth_delkeys(); - - /* - * Now read lines from the file, looking for key entries + * Now read lines from the file, looking for key entries. Put + * the data into temporary store for later propagation to avoid + * two-pass processing. */ nerr = 0; while ((line = fgets(buf, sizeof buf, fp)) != NULL) { @@ -216,11 +224,16 @@ authreadkeys( "authreadkeys: no key for key %d", keyno); continue; } + next = NULL; len = strlen(token); if (len <= 20) { /* Bug 2537 */ - MD5auth_setkey(keyno, keytype, (u_char *)token, len); + next = emalloc(sizeof(KeyDataT) + len); + next->keyid = keyno; + next->keytype = keytype; + next->seclen = len; + memcpy(next->secbuf, token, len); } else { - char hex[] = "0123456789abcdef"; + static const char hex[] = "0123456789abcdef"; u_char temp; char *ptr; size_t jlim; @@ -242,19 +255,51 @@ authreadkeys( keyno); continue; } - MD5auth_setkey(keyno, keytype, keystr, jlim / 2); + len = jlim/2; /* hmmmm.... what about odd length?!? */ + next = emalloc(sizeof(KeyDataT) + len); + next->keyid = keyno; + next->keytype = keytype; + next->seclen = len; + memcpy(next->secbuf, keystr, len); } + INSIST(NULL != next); + next->next = list; + list = next; } fclose(fp); if (nerr > nerr_maxlimit) { msyslog(LOG_ERR, - "authreadkeys: emergency break after %u errors", - nerr); - return (0); - } else if (nerr > nerr_loglimit) { + "authreadkeys: rejecting file '%s' after %u errors (emergency break)", + file, nerr); + goto onerror; + } + if (nerr > 0) { msyslog(LOG_ERR, - "authreadkeys: found %u more error(s)", - nerr - nerr_loglimit); + "authreadkeys: rejecting file '%s' after %u error(s)", + file, nerr); + goto onerror; + } + + /* first remove old file-based keys */ + auth_delkeys(); + /* insert the new key material */ + while (NULL != (next = list)) { + list = next->next; + MD5auth_setkey(next->keyid, next->keytype, + next->secbuf, next->seclen); + /* purge secrets from memory before free()ing it */ + memset(next, 0, sizeof(*next) + next->seclen); + free(next); } return (1); + + onerror: + /* Mop up temporary storage before bailing out. */ + while (NULL != (next = list)) { + list = next->next; + /* purge secrets from memory before free()ing it */ + memset(next, 0, sizeof(*next) + next->seclen); + free(next); + } + return (0); } diff --git a/libntp/authusekey.c b/libntp/authusekey.c index c1d08132c318..0ccf522b238a 100644 --- a/libntp/authusekey.c +++ b/libntp/authusekey.c @@ -23,7 +23,7 @@ authusekey( const u_char *str ) { - int len; + size_t len; len = strlen((const char *)str); if (0 == len) diff --git a/libntp/dolfptoa.c b/libntp/dolfptoa.c index 07ead950f455..68f56e1637e2 100644 --- a/libntp/dolfptoa.c +++ b/libntp/dolfptoa.c @@ -40,7 +40,7 @@ dolfptoa( * including a possible rounding from the fractional part. */ cp = cpend = cpdec = &cbuf[10]; - for (dec = cp - cbuf; dec > 0 && fpi != 0; dec--) { + for (dec = (int)(cp - cbuf); dec > 0 && fpi != 0; dec--) { /* can add another digit */ u_int32 digit; @@ -62,7 +62,7 @@ dolfptoa( cpdec += 3; } if ((size_t)dec > sizeof(cbuf) - (cpend - cbuf)) - dec = sizeof(cbuf) - (cpend - cbuf); + dec = (int)(sizeof(cbuf) - (cpend - cbuf)); /* * If there's a fraction to deal with, do so. @@ -95,7 +95,7 @@ dolfptoa( u_char *tp = cpend; int carry = ((fpv & 0x80000000) != 0); - for (dec = tp - cbuf; carry && dec > 0; dec--) { + for (dec = (int)(tp - cbuf); carry && dec > 0; dec--) { *--tp += 1; if (*tp == 10) *tp = 0; diff --git a/libntp/hextolfp.c b/libntp/hextolfp.c index 2bff929dc388..19a93cdd427f 100644 --- a/libntp/hextolfp.c +++ b/libntp/hextolfp.c @@ -37,8 +37,9 @@ hextolfp( while (*cp != '\0' && (cp - cpstart) < 8 && (ind = strchr(digits, *cp)) != NULL) { dec_i = dec_i << 4; /* multiply by 16 */ - dec_i += ((ind - digits) > 15) ? (ind - digits) - 6 - : (ind - digits); + dec_i += ((ind - digits) > 15) + ? (u_long)(ind - digits - 6) + : (u_long)(ind - digits); cp++; } @@ -51,8 +52,9 @@ hextolfp( while (*cp != '\0' && (cp - cpstart) < 8 && (ind = strchr(digits, *cp)) != NULL) { dec_f = dec_f << 4; /* multiply by 16 */ - dec_f += ((ind - digits) > 15) ? (ind - digits) - 6 - : (ind - digits); + dec_f += ((ind - digits) > 15) + ? (u_long)(ind - digits - 6) + : (u_long)(ind - digits); cp++; } diff --git a/libntp/mstolfp.c b/libntp/mstolfp.c index 828b14cfbca8..7da20dc911e2 100644 --- a/libntp/mstolfp.c +++ b/libntp/mstolfp.c @@ -70,8 +70,7 @@ mstolfp( */ *bp++ = '.'; if ((cpdec - cp) < 3) { - register int i = 3 - (cpdec - cp); - + size_t i = 3 - (cpdec - cp); do { *bp++ = '0'; } while (--i > 0); diff --git a/libntp/msyslog.c b/libntp/msyslog.c index cc8868f8e7b8..9682d3002119 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -331,7 +331,7 @@ msnprintf( ) { va_list ap; - size_t rc; + int rc; va_start(ap, fmt); rc = mvsnprintf(buf, bufsiz, fmt, ap); diff --git a/libntp/ntp_crypto_rnd.c b/libntp/ntp_crypto_rnd.c index 96348f2e8696..2a4f91affad5 100644 --- a/libntp/ntp_crypto_rnd.c +++ b/libntp/ntp_crypto_rnd.c @@ -16,6 +16,7 @@ #include #include +#include "safecast.h" #ifdef USE_OPENSSL_CRYPTO_RAND #include @@ -93,7 +94,7 @@ ntp_crypto_random_buf( #ifdef USE_OPENSSL_CRYPTO_RAND int rc; - rc = RAND_bytes(buf, nbytes); + rc = RAND_bytes(buf, size2int_chk(nbytes)); if (1 != rc) { unsigned long err; char *err_str; diff --git a/libntp/ntp_lineedit.c b/libntp/ntp_lineedit.c index a2b2d2934705..ebd456ac5df1 100644 --- a/libntp/ntp_lineedit.c +++ b/libntp/ntp_lineedit.c @@ -29,6 +29,7 @@ #include "ntp.h" #include "ntp_stdlib.h" #include "ntp_lineedit.h" +#include "safecast.h" #define MAXEDITLINE 512 @@ -213,7 +214,7 @@ ntp_readline( line = fgets(line_buf, sizeof(line_buf), stdin); if (NULL != line && *line) { - *pcount = strlen(line); + *pcount = (int)strlen(line); /* cannot overflow here */ line = estrdup(line); } else line = NULL; diff --git a/libntp/ntp_rfc2553.c b/libntp/ntp_rfc2553.c index a9ebb4b35363..840962905f67 100644 --- a/libntp/ntp_rfc2553.c +++ b/libntp/ntp_rfc2553.c @@ -203,11 +203,12 @@ copy_addrinfo_common( else ai_nxt = ai_src->ai_next; *ai_cpy = *ai_src; - REQUIRE(ai_src->ai_addrlen <= sizeof(sockaddr_u)); + DEBUG_INSIST(ai_cpy->ai_canonname == ai_src->ai_canonname); + INSIST(ai_src->ai_addrlen <= sizeof(sockaddr_u)); memcpy(psau, ai_src->ai_addr, ai_src->ai_addrlen); ai_cpy->ai_addr = &psau->sa; ++psau; - if (NULL != ai_cpy->ai_canonname) { + if (NULL != ai_src->ai_canonname) { ai_cpy->ai_canonname = pcanon; str_octets = 1 + strlen(ai_src->ai_canonname); memcpy(pcanon, ai_src->ai_canonname, str_octets); @@ -480,15 +481,16 @@ do_nodename( * set elsewhere so that we can set the appropriate wildcard */ if (nodename == NULL) { - ai->ai_addrlen = sizeof(struct sockaddr_storage); if (ai->ai_family == AF_INET) { + ai->ai_addrlen = sizeof(struct sockaddr_in); sockin = (struct sockaddr_in *)ai->ai_addr; sockin->sin_family = (short) ai->ai_family; sockin->sin_addr.s_addr = htonl(INADDR_ANY); } else { + ai->ai_addrlen = sizeof(struct sockaddr_in6); sockin6 = (struct sockaddr_in6 *)ai->ai_addr; sockin6->sin6_family = (short) ai->ai_family; /* diff --git a/libntp/ntp_worker.c b/libntp/ntp_worker.c index 32970da0d124..f5642e10dc1e 100644 --- a/libntp/ntp_worker.c +++ b/libntp/ntp_worker.c @@ -150,7 +150,8 @@ available_blocking_child_slot(void) prev_octets); blocking_children_alloc = new_alloc; - return prev_alloc; + /* assume we'll never have enough workers to overflow u_int */ + return (u_int)prev_alloc; } diff --git a/libntp/snprintf.c b/libntp/snprintf.c index 2b6a37473e1f..f4685e1ad4b6 100644 --- a/libntp/snprintf.c +++ b/libntp/snprintf.c @@ -889,19 +889,19 @@ rpl_vsnprintf(char *str, size_t size, const char *format, va_list args) switch (cflags) { case PRINT_C_CHAR: charptr = va_arg(args, signed char *); - *charptr = len; + *charptr = (signed char)len; break; case PRINT_C_SHORT: shortptr = va_arg(args, short int *); - *shortptr = len; + *shortptr = (short int)len; break; case PRINT_C_LONG: longptr = va_arg(args, long int *); - *longptr = len; + *longptr = (long int)len; break; case PRINT_C_LLONG: llongptr = va_arg(args, LLONG *); - *llongptr = len; + *llongptr = (LLONG)len; break; case PRINT_C_SIZE: /* @@ -912,19 +912,19 @@ rpl_vsnprintf(char *str, size_t size, const char *format, va_list args) * size_t argument." (7.19.6.1, 7) */ sizeptr = va_arg(args, SSIZE_T *); - *sizeptr = len; + *sizeptr = (SSIZE_T)len; break; case PRINT_C_INTMAX: intmaxptr = va_arg(args, INTMAX_T *); - *intmaxptr = len; + *intmaxptr = (INTMAX_T)len; break; case PRINT_C_PTRDIFF: ptrdiffptr = va_arg(args, PTRDIFF_T *); - *ptrdiffptr = len; + *ptrdiffptr = (PTRDIFF_T)len; break; default: intptr = va_arg(args, int *); - *intptr = len; + *intptr = (int)len; break; } break; @@ -1209,7 +1209,7 @@ fmtflt(char *str, size_t *len, size_t size, LDOUBLE fvalue, int width, * Factor of ten with the number of digits needed for the fractional * part. For example, if the precision is 3, the mask will be 1000. */ - mask = mypow10(precision); + mask = (UINTMAX_T)mypow10(precision); /* * We "cheat" by converting the fractional part to integer by * multiplying by a factor of ten. @@ -1461,7 +1461,7 @@ cast(LDOUBLE value) if (value >= UINTMAX_MAX) return UINTMAX_MAX; - result = value; + result = (UINTMAX_T)value; /* * At least on NetBSD/sparc64 3.0.2 and 4.99.30, casting long double to * an integer type converts e.g. 1.9 to 2 instead of 1 (which violates diff --git a/libntp/socktohost.c b/libntp/socktohost.c index 3d9ab960e8a1..fdf9adb9e2e6 100644 --- a/libntp/socktohost.c +++ b/libntp/socktohost.c @@ -36,13 +36,18 @@ socktohost( sockaddr_u addr; size_t octets; int a_info; + int saved_errno; + + saved_errno = socket_errno(); /* reverse the address to purported DNS name */ LIB_GETBUF(pbuf); gni_flags = NI_DGRAM | NI_NAMEREQD; if (getnameinfo(&sock->sa, SOCKLEN(sock), pbuf, LIB_BUFLENGTH, - NULL, 0, gni_flags)) + NULL, 0, gni_flags)) { + errno = saved_errno; return stoa(sock); /* use address */ + } TRACE(1, ("%s reversed to %s\n", stoa(sock), pbuf)); @@ -97,8 +102,10 @@ socktohost( } freeaddrinfo(alist); - if (ai != NULL) + if (ai != NULL) { + errno = saved_errno; return pbuf; /* forward check passed */ + } forward_fail: TRACE(1, ("%s forward check lookup fail: %s\n", pbuf, @@ -106,5 +113,6 @@ socktohost( LIB_GETBUF(pliar); snprintf(pliar, LIB_BUFLENGTH, "%s (%s)", stoa(sock), pbuf); + errno = saved_errno; return pliar; } diff --git a/libntp/systime.c b/libntp/systime.c index f5eabcd1c9fd..c89d157cb2ad 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -25,6 +25,8 @@ # include #endif /* HAVE_UTMPX_H */ +int allow_panic = FALSE; /* allow panic correction (-g) */ +int enable_panic_check = TRUE; /* Can we check allow_panic's state? */ #ifndef USE_COMPILETIME_PIVOT # define USE_COMPILETIME_PIVOT 1 @@ -295,8 +297,13 @@ adj_systime( * EVNT_NSET adjtime() can be aborted by a tiny adjtime() * triggered by sys_residual. */ - if (0. == now) + if (0. == now) { + if (enable_panic_check && allow_panic) { + msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); + INSIST(!allow_panic); + } return TRUE; + } /* * Most Unix adjtime() implementations adjust the system clock @@ -333,9 +340,15 @@ adj_systime( if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) { if (adjtime(&adjtv, &oadjtv) < 0) { msyslog(LOG_ERR, "adj_systime: %m"); + if (enable_panic_check && allow_panic) { + msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); + } return FALSE; } } + if (enable_panic_check && allow_panic) { + msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); + } return TRUE; } #endif @@ -419,6 +432,9 @@ step_systime( /* now set new system time */ if (ntp_set_tod(&timetv, NULL) != 0) { msyslog(LOG_ERR, "step-systime: %m"); + if (enable_panic_check && allow_panic) { + msyslog(LOG_ERR, "step_systime: allow_panic is TRUE!"); + } return FALSE; } @@ -445,7 +461,7 @@ step_systime( * long ut_time; * }; * and appends line="|", name="date", host="", time for the OLD - * and appends line="{", name="date", host="", time for the NEW + * and appends line="{", name="date", host="", time for the NEW // } * to _PATH_WTMP . * * Some OSes have utmp, some have utmpx. @@ -564,6 +580,10 @@ step_systime( #endif /* UPDATE_WTMPX */ } + if (enable_panic_check && allow_panic) { + msyslog(LOG_ERR, "step_systime: allow_panic is TRUE!"); + INSIST(!allow_panic); + } return TRUE; } diff --git a/libntp/work_thread.c b/libntp/work_thread.c index 38d87470f01a..49e90c16c326 100644 --- a/libntp/work_thread.c +++ b/libntp/work_thread.c @@ -32,16 +32,20 @@ #define THREAD_MINSTACKSIZE (64U * 1024) #endif -#ifndef DEVOLATILE -#define DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) -#endif - #ifdef SYS_WINNT + # define thread_exit(c) _endthreadex(c) -# define tickle_sem SetEvent +# define tickle_sem(sh) ReleaseSemaphore((sh->shnd), 1, NULL) +u_int WINAPI blocking_thread(void *); +static BOOL same_os_sema(const sem_ref obj, void * osobj); + #else + # define thread_exit(c) pthread_exit((void*)(size_t)(c)) # define tickle_sem sem_post +void * blocking_thread(void *); +static void block_thread_signals(sigset_t *); + #endif #ifdef WORK_PIPE @@ -54,18 +58,10 @@ static void start_blocking_thread(blocking_child *); static void start_blocking_thread_internal(blocking_child *); static void prepare_child_sems(blocking_child *); static int wait_for_sem(sem_ref, struct timespec *); -static void ensure_workitems_empty_slot(blocking_child *); -static void ensure_workresp_empty_slot(blocking_child *); +static int ensure_workitems_empty_slot(blocking_child *); +static int ensure_workresp_empty_slot(blocking_child *); static int queue_req_pointer(blocking_child *, blocking_pipe_header *); static void cleanup_after_child(blocking_child *); -#ifdef SYS_WINNT -u_int WINAPI blocking_thread(void *); -#else -void * blocking_thread(void *); -#endif -#ifndef SYS_WINNT -static void block_thread_signals(sigset_t *); -#endif void @@ -76,7 +72,9 @@ exit_worker( thread_exit(exitcode); /* see #define thread_exit */ } - +/* -------------------------------------------------------------------- + * sleep for a given time or until the wakup semaphore is tickled. + */ int worker_sleep( blocking_child * c, @@ -98,9 +96,7 @@ worker_sleep( } # endif until.tv_sec += seconds; - do { - rc = wait_for_sem(c->wake_scheduled_sleep, &until); - } while (-1 == rc && EINTR == errno); + rc = wait_for_sem(c->wake_scheduled_sleep, &until); if (0 == rc) return -1; if (-1 == rc && ETIMEDOUT == errno) @@ -110,6 +106,9 @@ worker_sleep( } +/* -------------------------------------------------------------------- + * Wake up a worker that takes a nap. + */ void interrupt_worker_sleep(void) { @@ -124,65 +123,79 @@ interrupt_worker_sleep(void) } } - -static void +/* -------------------------------------------------------------------- + * Make sure there is an empty slot at the head of the request + * queue. Tell if the queue is currently empty. + */ +static int ensure_workitems_empty_slot( blocking_child *c ) { - const size_t each = sizeof(blocking_children[0]->workitems[0]); - size_t new_alloc; - size_t old_octets; - size_t new_octets; - void * nonvol_workitems; + /* + ** !!! PRECONDITION: caller holds access lock! + ** + ** This simply tries to increase the size of the buffer if it + ** becomes full. The resize operation does *not* maintain the + ** order of requests, but that should be irrelevant since the + ** processing is considered asynchronous anyway. + ** + ** Return if the buffer is currently empty. + */ + + static const size_t each = + sizeof(blocking_children[0]->workitems[0]); + size_t new_alloc; + size_t slots_used; - if (c->workitems != NULL && - NULL == c->workitems[c->next_workitem]) - return; - - new_alloc = c->workitems_alloc + WORKITEMS_ALLOC_INC; - old_octets = c->workitems_alloc * each; - new_octets = new_alloc * each; - nonvol_workitems = DEVOLATILE(void *, c->workitems); - c->workitems = erealloc_zero(nonvol_workitems, new_octets, - old_octets); - if (0 == c->next_workitem) - c->next_workitem = c->workitems_alloc; - c->workitems_alloc = new_alloc; + slots_used = c->head_workitem - c->tail_workitem; + if (slots_used >= c->workitems_alloc) { + new_alloc = c->workitems_alloc + WORKITEMS_ALLOC_INC; + c->workitems = erealloc(c->workitems, new_alloc * each); + c->tail_workitem = 0; + c->head_workitem = c->workitems_alloc; + c->workitems_alloc = new_alloc; + } + return (0 == slots_used); } - -static void +/* -------------------------------------------------------------------- + * Make sure there is an empty slot at the head of the response + * queue. Tell if the queue is currently empty. + */ +static int ensure_workresp_empty_slot( blocking_child *c ) { - const size_t each = sizeof(blocking_children[0]->responses[0]); - size_t new_alloc; - size_t old_octets; - size_t new_octets; - void * nonvol_responses; + /* + ** !!! PRECONDITION: caller holds access lock! + ** + ** Works like the companion function above. + */ + + static const size_t each = + sizeof(blocking_children[0]->responses[0]); - if (c->responses != NULL && - NULL == c->responses[c->next_response]) - return; + size_t new_alloc; + size_t slots_used; - new_alloc = c->responses_alloc + RESPONSES_ALLOC_INC; - old_octets = c->responses_alloc * each; - new_octets = new_alloc * each; - nonvol_responses = DEVOLATILE(void *, c->responses); - c->responses = erealloc_zero(nonvol_responses, new_octets, - old_octets); - if (0 == c->next_response) - c->next_response = c->responses_alloc; - c->responses_alloc = new_alloc; + slots_used = c->head_response - c->tail_response; + if (slots_used >= c->responses_alloc) { + new_alloc = c->responses_alloc + RESPONSES_ALLOC_INC; + c->responses = erealloc(c->responses, new_alloc * each); + c->tail_response = 0; + c->head_response = c->responses_alloc; + c->responses_alloc = new_alloc; + } + return (0 == slots_used); } -/* +/* -------------------------------------------------------------------- * queue_req_pointer() - append a work item or idle exit request to - * blocking_workitems[]. + * blocking_workitems[]. Employ proper locking. */ static int queue_req_pointer( @@ -190,21 +203,28 @@ queue_req_pointer( blocking_pipe_header * hdr ) { - c->workitems[c->next_workitem] = hdr; - c->next_workitem = (1 + c->next_workitem) % c->workitems_alloc; + size_t qhead; + + /* >>>> ACCESS LOCKING STARTS >>>> */ + wait_for_sem(c->accesslock, NULL); + ensure_workitems_empty_slot(c); + qhead = c->head_workitem; + c->workitems[qhead % c->workitems_alloc] = hdr; + c->head_workitem = 1 + qhead; + tickle_sem(c->accesslock); + /* <<<< ACCESS LOCKING ENDS <<<< */ - /* - * We only want to signal the wakeup event if the child is - * blocking on it, which is indicated by setting the blocking - * event. Wait with zero timeout to test. - */ - /* !!!! if (WAIT_OBJECT_0 == WaitForSingleObject(c->child_is_blocking, 0)) */ - tickle_sem(c->blocking_req_ready); + /* queue consumer wake-up notification */ + tickle_sem(c->workitems_pending); return 0; } - +/* -------------------------------------------------------------------- + * API function to make sure a worker is running, a proper private copy + * of the data is made, the data eneterd into the queue and the worker + * is signalled. + */ int send_blocking_req_internal( blocking_child * c, @@ -223,12 +243,8 @@ send_blocking_req_internal( return 1; /* failure */ payload_octets = hdr->octets - sizeof(*hdr); - ensure_workitems_empty_slot(c); - if (NULL == c->thread_ref) { - ensure_workresp_empty_slot(c); + if (NULL == c->thread_ref) start_blocking_thread(c); - } - threadcopy = emalloc(hdr->octets); memcpy(threadcopy, hdr, sizeof(*hdr)); memcpy((char *)threadcopy + sizeof(*hdr), data, payload_octets); @@ -236,43 +252,41 @@ send_blocking_req_internal( return queue_req_pointer(c, threadcopy); } - +/* -------------------------------------------------------------------- + * Wait for the 'incoming queue no longer empty' signal, lock the shared + * structure and dequeue an item. + */ blocking_pipe_header * receive_blocking_req_internal( blocking_child * c ) { blocking_pipe_header * req; - int rc; + size_t qhead, qtail; - /* - * Child blocks here when idle. SysV semaphores maintain a - * count and release from sem_wait() only when it reaches 0. - * Windows auto-reset events are simpler, and multiple SetEvent - * calls before any thread waits result in a single wakeup. - * On Windows, the child drains all workitems each wakeup, while - * with SysV semaphores wait_sem() is used before each item. - */ -#ifdef SYS_WINNT - while (NULL == c->workitems[c->next_workeritem]) { - /* !!!! SetEvent(c->child_is_blocking); */ - rc = wait_for_sem(c->blocking_req_ready, NULL); - INSIST(0 == rc); - /* !!!! ResetEvent(c->child_is_blocking); */ - } -#else + req = NULL; do { - rc = wait_for_sem(c->blocking_req_ready, NULL); - } while (-1 == rc && EINTR == errno); - INSIST(0 == rc); -#endif + /* wait for tickle from the producer side */ + wait_for_sem(c->workitems_pending, NULL); + + /* >>>> ACCESS LOCKING STARTS >>>> */ + wait_for_sem(c->accesslock, NULL); + qhead = c->head_workitem; + do { + qtail = c->tail_workitem; + if (qhead == qtail) + break; + c->tail_workitem = qtail + 1; + qtail %= c->workitems_alloc; + req = c->workitems[qtail]; + c->workitems[qtail] = NULL; + } while (NULL == req); + tickle_sem(c->accesslock); + /* <<<< ACCESS LOCKING ENDS <<<< */ + + } while (NULL == req); - req = c->workitems[c->next_workeritem]; INSIST(NULL != req); - c->workitems[c->next_workeritem] = NULL; - c->next_workeritem = (1 + c->next_workeritem) % - c->workitems_alloc; - if (CHILD_EXIT_REQ == req) { /* idled out */ send_blocking_resp_internal(c, CHILD_GONE_RESP); req = NULL; @@ -281,44 +295,74 @@ receive_blocking_req_internal( return req; } - +/* -------------------------------------------------------------------- + * Push a response into the return queue and eventually tickle the + * receiver. + */ int send_blocking_resp_internal( blocking_child * c, blocking_pipe_header * resp ) { - ensure_workresp_empty_slot(c); - - c->responses[c->next_response] = resp; - c->next_response = (1 + c->next_response) % c->responses_alloc; - -#ifdef WORK_PIPE - write(c->resp_write_pipe, "", 1); -#else - tickle_sem(c->blocking_response_ready); -#endif + size_t qhead; + int empty; + + /* >>>> ACCESS LOCKING STARTS >>>> */ + wait_for_sem(c->accesslock, NULL); + empty = ensure_workresp_empty_slot(c); + qhead = c->head_response; + c->responses[qhead % c->responses_alloc] = resp; + c->head_response = 1 + qhead; + tickle_sem(c->accesslock); + /* <<<< ACCESS LOCKING ENDS <<<< */ + /* queue consumer wake-up notification */ + if (empty) + { +# ifdef WORK_PIPE + write(c->resp_write_pipe, "", 1); +# else + tickle_sem(c->responses_pending); +# endif + } return 0; } #ifndef WORK_PIPE + +/* -------------------------------------------------------------------- + * Check if a (Windows-)hanndle to a semaphore is actually the same we + * are using inside the sema wrapper. + */ +static BOOL +same_os_sema( + const sem_ref obj, + void* osh + ) +{ + return obj && osh && (obj->shnd == (HANDLE)osh); +} + +/* -------------------------------------------------------------------- + * Find the shared context that associates to an OS handle and make sure + * the data is dequeued and processed. + */ void handle_blocking_resp_sem( void * context ) { - HANDLE ready; blocking_child * c; u_int idx; - ready = (HANDLE)context; c = NULL; for (idx = 0; idx < blocking_children_alloc; idx++) { c = blocking_children[idx]; - if (c != NULL && c->thread_ref != NULL && - ready == c->blocking_response_ready) + if (c != NULL && + c->thread_ref != NULL && + same_os_sema(c->responses_pending, context)) break; } if (idx < blocking_children_alloc) @@ -326,26 +370,41 @@ handle_blocking_resp_sem( } #endif /* !WORK_PIPE */ - +/* -------------------------------------------------------------------- + * Fetch the next response from the return queue. In case of signalling + * via pipe, make sure the pipe is flushed, too. + */ blocking_pipe_header * receive_blocking_resp_internal( blocking_child * c ) { blocking_pipe_header * removed; + size_t qhead, qtail, slot; + #ifdef WORK_PIPE int rc; char scratch[32]; - do { + do rc = read(c->resp_read_pipe, scratch, sizeof(scratch)); - } while (-1 == rc && EINTR == errno); + while (-1 == rc && EINTR == errno); #endif - removed = c->responses[c->next_workresp]; + + /* >>>> ACCESS LOCKING STARTS >>>> */ + wait_for_sem(c->accesslock, NULL); + qhead = c->head_response; + qtail = c->tail_response; + for (removed = NULL; !removed && (qhead != qtail); ++qtail) { + slot = qtail % c->responses_alloc; + removed = c->responses[slot]; + c->responses[slot] = NULL; + } + c->tail_response = qtail; + tickle_sem(c->accesslock); + /* <<<< ACCESS LOCKING ENDS <<<< */ + if (NULL != removed) { - c->responses[c->next_workresp] = NULL; - c->next_workresp = (1 + c->next_workresp) % - c->responses_alloc; DEBUG_ENSURE(CHILD_GONE_RESP == removed || BLOCKING_RESP_MAGIC == removed->magic_sig); } @@ -357,7 +416,9 @@ receive_blocking_resp_internal( return removed; } - +/* -------------------------------------------------------------------- + * Light up a new worker. + */ static void start_blocking_thread( blocking_child * c @@ -370,40 +431,45 @@ start_blocking_thread( start_blocking_thread_internal(c); } - +/* -------------------------------------------------------------------- + * Create a worker thread. There are several differences between POSIX + * and Windows, of course -- most notably the Windows thread is no + * detached thread, and we keep the handle around until we want to get + * rid of the thread. The notification scheme also differs: Windows + * makes use of semaphores in both directions, POSIX uses a pipe for + * integration with 'select()' or alike. + */ static void start_blocking_thread_internal( blocking_child * c ) #ifdef SYS_WINNT { - thr_ref blocking_child_thread; - u_int blocking_thread_id; BOOL resumed; - (*addremove_io_semaphore)(c->blocking_response_ready, FALSE); - blocking_child_thread = + c->thread_ref = NULL; + (*addremove_io_semaphore)(c->responses_pending->shnd, FALSE); + c->thr_table[0].thnd = (HANDLE)_beginthreadex( NULL, 0, &blocking_thread, c, CREATE_SUSPENDED, - &blocking_thread_id); + NULL); - if (NULL == blocking_child_thread) { + if (NULL == c->thr_table[0].thnd) { msyslog(LOG_ERR, "start blocking thread failed: %m"); exit(-1); } - c->thread_id = blocking_thread_id; - c->thread_ref = blocking_child_thread; /* remember the thread priority is only within the process class */ - if (!SetThreadPriority(blocking_child_thread, + if (!SetThreadPriority(c->thr_table[0].thnd, THREAD_PRIORITY_BELOW_NORMAL)) msyslog(LOG_ERR, "Error lowering blocking thread priority: %m"); - resumed = ResumeThread(blocking_child_thread); + resumed = ResumeThread(c->thr_table[0].thnd); DEBUG_INSIST(resumed); + c->thread_ref = &c->thr_table[0]; } #else /* pthreads start_blocking_thread_internal() follows */ { @@ -419,6 +485,8 @@ start_blocking_thread_internal( size_t stacksize; sigset_t saved_sig_mask; + c->thread_ref = NULL; + # ifdef NEED_PTHREAD_INIT /* * from lib/isc/unix/app.c: @@ -475,7 +543,7 @@ start_blocking_thread_internal( #endif c->thread_ref = emalloc_zero(sizeof(*c->thread_ref)); block_thread_signals(&saved_sig_mask); - rc = pthread_create(c->thread_ref, &thr_attr, + rc = pthread_create(&c->thr_table[0], &thr_attr, &blocking_thread, c); saved_errno = errno; pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL); @@ -485,11 +553,11 @@ start_blocking_thread_internal( msyslog(LOG_ERR, "pthread_create() blocking child: %m"); exit(1); } + c->thread_ref = &c->thr_table[0]; } #endif - -/* +/* -------------------------------------------------------------------- * block_thread_signals() * * Temporarily block signals used by ntpd main thread, so that signal @@ -538,61 +606,101 @@ block_thread_signals( #endif /* !SYS_WINNT */ -/* +/* -------------------------------------------------------------------- + * Create & destroy semaphores. This is sufficiently different between + * POSIX and Windows to warrant wrapper functions and close enough to + * use the concept of synchronization via semaphore for all platforms. + */ +static sem_ref +create_sema( + sema_type* semptr, + u_int inival, + u_int maxval) +{ +#ifdef SYS_WINNT + + long svini, svmax; + if (NULL != semptr) { + svini = (inival < LONG_MAX) + ? (long)inival : LONG_MAX; + svmax = (maxval < LONG_MAX && maxval > 0) + ? (long)maxval : LONG_MAX; + semptr->shnd = CreateSemaphore(NULL, svini, svmax, NULL); + if (NULL == semptr->shnd) + semptr = NULL; + } + +#else + + (void)maxval; + if (semptr && sem_init(semptr, FALSE, inival)) + semptr = NULL; + +#endif + + return semptr; +} + +/* ------------------------------------------------------------------ */ +static sem_ref +delete_sema( + sem_ref obj) +{ + +# ifdef SYS_WINNT + + if (obj) { + if (obj->shnd) + CloseHandle(obj->shnd); + obj->shnd = NULL; + } + +# else + + if (obj) + sem_destroy(obj); + +# endif + + return NULL; +} + +/* -------------------------------------------------------------------- * prepare_child_sems() * - * create sync events (semaphores) - * child_is_blocking initially unset - * blocking_req_ready initially unset + * create sync & access semaphores * - * Child waits for blocking_req_ready to be set after - * setting child_is_blocking. blocking_req_ready and - * blocking_response_ready are auto-reset, so wake one - * waiter and become unset (unsignalled) in one operation. + * All semaphores are cleared, only the access semaphore has 1 unit. + * Childs wait on 'workitems_pending', then grabs 'sema_access' + * and dequeues jobs. When done, 'sema_access' is given one unit back. + * + * The producer grabs 'sema_access', manages the queue, restores + * 'sema_access' and puts one unit into 'workitems_pending'. + * + * The story goes the same for the response queue. */ static void prepare_child_sems( blocking_child *c ) -#ifdef SYS_WINNT { - if (NULL == c->blocking_req_ready) { - /* manual reset using ResetEvent() */ - /* !!!! c->child_is_blocking = CreateEvent(NULL, TRUE, FALSE, NULL); */ - /* auto reset - one thread released from wait each set */ - c->blocking_req_ready = CreateEvent(NULL, FALSE, FALSE, NULL); - c->blocking_response_ready = CreateEvent(NULL, FALSE, FALSE, NULL); - c->wake_scheduled_sleep = CreateEvent(NULL, FALSE, FALSE, NULL); - } else { - /* !!!! ResetEvent(c->child_is_blocking); */ - /* ResetEvent(c->blocking_req_ready); */ - /* ResetEvent(c->blocking_response_ready); */ - /* ResetEvent(c->wake_scheduled_sleep); */ - } + c->accesslock = create_sema(&c->sem_table[0], 1, 1); + c->workitems_pending = create_sema(&c->sem_table[1], 0, 0); + c->wake_scheduled_sleep = create_sema(&c->sem_table[2], 0, 1); +# ifndef WORK_PIPE + c->responses_pending = create_sema(&c->sem_table[3], 0, 0); +# endif } -#else /* pthreads prepare_child_sems() follows */ -{ - size_t octets; - - if (NULL == c->blocking_req_ready) { - octets = sizeof(*c->blocking_req_ready); - octets += sizeof(*c->wake_scheduled_sleep); - /* !!!! octets += sizeof(*c->child_is_blocking); */ - c->blocking_req_ready = emalloc_zero(octets);; - c->wake_scheduled_sleep = 1 + c->blocking_req_ready; - /* !!!! c->child_is_blocking = 1 + c->wake_scheduled_sleep; */ - } else { - sem_destroy(c->blocking_req_ready); - sem_destroy(c->wake_scheduled_sleep); - /* !!!! sem_destroy(c->child_is_blocking); */ - } - sem_init(c->blocking_req_ready, FALSE, 0); - sem_init(c->wake_scheduled_sleep, FALSE, 0); - /* !!!! sem_init(c->child_is_blocking, FALSE, 0); */ -} -#endif - +/* -------------------------------------------------------------------- + * wait for semaphore. Where the wait can be interrupted, it will + * internally resume -- When this function returns, there is either no + * semaphore at all, a timeout occurred, or the caller could + * successfully take a token from the semaphore. + * + * For untimed wait, not checking the result of this function at all is + * definitely an option. + */ static int wait_for_sem( sem_ref sem, @@ -605,6 +713,11 @@ wait_for_sem( DWORD msec; DWORD rc; + if (!(sem && sem->shnd)) { + errno = EINVAL; + return -1; + } + if (NULL == timeout) { msec = INFINITE; } else { @@ -619,7 +732,7 @@ wait_for_sem( msec += delta.tv_nsec / (1000 * 1000); } } - rc = WaitForSingleObject(sem, msec); + rc = WaitForSingleObject(sem->shnd, msec); if (WAIT_OBJECT_0 == rc) return 0; if (WAIT_TIMEOUT == rc) { @@ -632,24 +745,28 @@ wait_for_sem( } #else /* pthreads wait_for_sem() follows */ { - int rc; + int rc = -1; - if (NULL == timeout) - rc = sem_wait(sem); + if (sem) do { + if (NULL == timeout) + rc = sem_wait(sem); + else + rc = sem_timedwait(sem, timeout); + } while (rc == -1 && errno == EINTR); else - rc = sem_timedwait(sem, timeout); - + errno = EINVAL; + return rc; } #endif - -/* - * blocking_thread - thread functions have WINAPI calling convention +/* -------------------------------------------------------------------- + * blocking_thread - thread functions have WINAPI (aka 'stdcall') + * calling conventions under Windows and POSIX-defined signature + * otherwise. */ #ifdef SYS_WINNT -u_int -WINAPI +u_int WINAPI #else void * #endif @@ -666,20 +783,28 @@ blocking_thread( return 0; } - -/* +/* -------------------------------------------------------------------- * req_child_exit() runs in the parent. + * + * This function is called from from the idle timer, too, and possibly + * without a thread being there any longer. Since we have folded up our + * tent in that case and all the semaphores are already gone, we simply + * ignore this request in this case. + * + * Since the existence of the semaphores is controlled exclusively by + * the parent, there's no risk of data race here. */ int req_child_exit( blocking_child *c ) { - return queue_req_pointer(c, CHILD_EXIT_REQ); + return (c->accesslock) + ? queue_req_pointer(c, CHILD_EXIT_REQ) + : 0; } - -/* +/* -------------------------------------------------------------------- * cleanup_after_child() runs in parent. */ static void @@ -687,17 +812,27 @@ cleanup_after_child( blocking_child * c ) { - u_int idx; - DEBUG_INSIST(!c->reusable); -#ifdef SYS_WINNT - INSIST(CloseHandle(c->thread_ref)); -#else - free(c->thread_ref); -#endif + +# ifdef SYS_WINNT + /* The thread was not created in detached state, so we better + * clean up. + */ + if (c->thread_ref && c->thread_ref->thnd) { + WaitForSingleObject(c->thread_ref->thnd, INFINITE); + INSIST(CloseHandle(c->thread_ref->thnd)); + c->thread_ref->thnd = NULL; + } +# endif c->thread_ref = NULL; - c->thread_id = 0; -#ifdef WORK_PIPE + + /* remove semaphores and (if signalling vi IO) pipes */ + + c->accesslock = delete_sema(c->accesslock); + c->workitems_pending = delete_sema(c->workitems_pending); + c->wake_scheduled_sleep = delete_sema(c->wake_scheduled_sleep); + +# ifdef WORK_PIPE DEBUG_INSIST(-1 != c->resp_read_pipe); DEBUG_INSIST(-1 != c->resp_write_pipe); (*addremove_io_fd)(c->resp_read_pipe, c->ispipe, TRUE); @@ -705,18 +840,22 @@ cleanup_after_child( close(c->resp_read_pipe); c->resp_write_pipe = -1; c->resp_read_pipe = -1; -#else - DEBUG_INSIST(NULL != c->blocking_response_ready); - (*addremove_io_semaphore)(c->blocking_response_ready, TRUE); -#endif - for (idx = 0; idx < c->workitems_alloc; idx++) - c->workitems[idx] = NULL; - c->next_workitem = 0; - c->next_workeritem = 0; - for (idx = 0; idx < c->responses_alloc; idx++) - c->responses[idx] = NULL; - c->next_response = 0; - c->next_workresp = 0; +# else + DEBUG_INSIST(NULL != c->responses_pending); + (*addremove_io_semaphore)(c->responses_pending->shnd, TRUE); + c->responses_pending = delete_sema(c->responses_pending); +# endif + + /* Is it necessary to check if there are pending requests and + * responses? If so, and if there are, what to do with them? + */ + + /* re-init buffer index sequencers */ + c->head_workitem = 0; + c->tail_workitem = 0; + c->head_response = 0; + c->tail_response = 0; + c->reusable = TRUE; } diff --git a/libparse/clk_computime.c b/libparse/clk_computime.c index 5026232ea5f0..7273ac762e37 100644 --- a/libparse/clk_computime.c +++ b/libparse/clk_computime.c @@ -157,7 +157,7 @@ inp_computime( { unsigned int rtc; - parseprintf(DD_PARSE, ("inp_computime(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_computime(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch (ch) { diff --git a/libparse/clk_dcf7000.c b/libparse/clk_dcf7000.c index f1da9ef8484e..0621cd5649e4 100644 --- a/libparse/clk_dcf7000.c +++ b/libparse/clk_dcf7000.c @@ -158,7 +158,7 @@ inp_dcf7000( { unsigned int rtc; - parseprintf(DD_PARSE, ("inp_dcf7000(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_dcf7000(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch (ch) { diff --git a/libparse/clk_hopf6021.c b/libparse/clk_hopf6021.c index 357ac2ec0f15..235962890f8c 100644 --- a/libparse/clk_hopf6021.c +++ b/libparse/clk_hopf6021.c @@ -227,7 +227,7 @@ inp_hopf6021( { unsigned int rtc; - parseprintf(DD_PARSE, ("inp_hopf6021(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_hopf6021(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch (ch) { diff --git a/libparse/clk_meinberg.c b/libparse/clk_meinberg.c index 9d2b676381c6..e4ebf0acc605 100644 --- a/libparse/clk_meinberg.c +++ b/libparse/clk_meinberg.c @@ -434,7 +434,7 @@ mbg_input( { unsigned int rtc; - parseprintf(DD_PARSE, ("mbg_input(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("mbg_input(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch (ch) { @@ -602,7 +602,7 @@ gps_input( msg_buf = (struct msg_buf *)parseio->parse_pdata; - parseprintf(DD_PARSE, ("gps_input(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("gps_input(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); if (!msg_buf) return PARSE_INP_SKIP; diff --git a/libparse/clk_rawdcf.c b/libparse/clk_rawdcf.c index ca4326336f88..e22ebb0a4808 100644 --- a/libparse/clk_rawdcf.c +++ b/libparse/clk_rawdcf.c @@ -627,7 +627,7 @@ inp_rawdcf( { static struct timeval timeout = { 1, 500000 }; /* 1.5 secongs denote second #60 */ - parseprintf(DD_PARSE, ("inp_rawdcf(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_rawdcf(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */ diff --git a/libparse/clk_rcc8000.c b/libparse/clk_rcc8000.c index a690e588b91b..11d52acc5a24 100644 --- a/libparse/clk_rcc8000.c +++ b/libparse/clk_rcc8000.c @@ -141,7 +141,7 @@ inp_rcc8000( { unsigned int rtc; - parseprintf(DD_PARSE, ("inp_rcc8000(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_rcc8000(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch (ch) { diff --git a/libparse/clk_schmid.c b/libparse/clk_schmid.c index c4f02b07ad13..d85b1a5da512 100644 --- a/libparse/clk_schmid.c +++ b/libparse/clk_schmid.c @@ -205,7 +205,7 @@ inp_schmid( { unsigned int rtc; - parseprintf(DD_PARSE, ("inp_schmid(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_schmid(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch ((uint8_t)ch) { diff --git a/libparse/clk_trimtaip.c b/libparse/clk_trimtaip.c index 426e897bec97..a60d01ec1870 100644 --- a/libparse/clk_trimtaip.c +++ b/libparse/clk_trimtaip.c @@ -155,7 +155,7 @@ inp_trimtaip( { unsigned int rtc; - parseprintf(DD_PARSE, ("inp_trimtaip(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_trimtaip(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch (ch) { diff --git a/libparse/clk_varitext.c b/libparse/clk_varitext.c index 022549e82f4a..0d830354d799 100644 --- a/libparse/clk_varitext.c +++ b/libparse/clk_varitext.c @@ -58,12 +58,12 @@ extern int printf (const char *, ...); #endif -static const u_char VT_INITIALISED = 0x01; -static const u_char VT_SYNCHRONISED = 0x02; -static const u_char VT_ALARM_STATE = 0x04; +/* static const u_char VT_INITIALISED = 0x01; */ +/* static const u_char VT_SYNCHRONISED = 0x02; */ +/* static const u_char VT_ALARM_STATE = 0x04; */ static const u_char VT_BST = 0x08; -static const u_char VT_SEASON_CHANGE = 0x10; -static const u_char VT_LAST_TELEGRAM_OK = 0x20; +/* static const u_char VT_SEASON_CHANGE = 0x10; */ +/* static const u_char VT_LAST_TELEGRAM_OK = 0x20; */ /* * The Varitext receiver sends a datagram in the following format every minute @@ -195,7 +195,7 @@ inp_varitext( struct varitext *t = (struct varitext *)parseio->parse_pdata; int rtc; - parseprintf(DD_PARSE, ("inp_varitext(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_varitext(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); if (!t) return PARSE_INP_SKIP; /* local data not allocated - sigh! */ diff --git a/libparse/clk_wharton.c b/libparse/clk_wharton.c index a65bc53860e6..e9e3d84644ac 100644 --- a/libparse/clk_wharton.c +++ b/libparse/clk_wharton.c @@ -137,7 +137,7 @@ inp_wharton_400a( { unsigned int rtc; - parseprintf(DD_PARSE, ("inp_wharton_400a(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); + parseprintf(DD_PARSE, ("inp_wharton_400a(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); switch (ch) { diff --git a/libparse/parse.c b/libparse/parse.c index 64167f152029..69395ac4a560 100644 --- a/libparse/parse.c +++ b/libparse/parse.c @@ -288,7 +288,7 @@ parse_ioread( break; } - parseprintf(DD_PARSE, ("parse_ioread(0x%lx, char=0x%x, ..., ...)\n", (unsigned long)parseio, ch & 0xFF)); + parseprintf(DD_PARSE, ("parse_ioread(0x%p, char=0x%x, ..., ...)\n", (void*)parseio, ch & 0xFF)); if (!clockformats[parseio->parse_lformat]->convert) { diff --git a/ntpd/invoke-ntp.conf.texi b/ntpd/invoke-ntp.conf.texi index 37427d679d45..32b41e69e192 100644 --- a/ntpd/invoke-ntp.conf.texi +++ b/ntpd/invoke-ntp.conf.texi @@ -6,7 +6,7 @@ # # EDIT THIS FILE WITH CAUTION (invoke-ntp.conf.texi) # -# It has been AutoGen-ed October 21, 2015 at 12:38:16 PM by AutoGen 5.18.5 +# It has been AutoGen-ed January 7, 2016 at 11:30:49 PM by AutoGen 5.18.5 # From the definitions ntp.conf.def # and the template file agtexi-file.tpl @end ignore diff --git a/ntpd/invoke-ntp.keys.texi b/ntpd/invoke-ntp.keys.texi index 33fdb8938ed6..b755d97a47fe 100644 --- a/ntpd/invoke-ntp.keys.texi +++ b/ntpd/invoke-ntp.keys.texi @@ -6,7 +6,7 @@ # # EDIT THIS FILE WITH CAUTION (invoke-ntp.keys.texi) # -# It has been AutoGen-ed October 21, 2015 at 12:38:19 PM by AutoGen 5.18.5 +# It has been AutoGen-ed January 7, 2016 at 11:30:52 PM by AutoGen 5.18.5 # From the definitions ntp.keys.def # and the template file agtexi-file.tpl @end ignore diff --git a/ntpd/invoke-ntpd.texi b/ntpd/invoke-ntpd.texi index a781b26681f8..66ce19dec1cb 100644 --- a/ntpd/invoke-ntpd.texi +++ b/ntpd/invoke-ntpd.texi @@ -6,7 +6,7 @@ # # EDIT THIS FILE WITH CAUTION (invoke-ntpd.texi) # -# It has been AutoGen-ed October 21, 2015 at 12:38:21 PM by AutoGen 5.18.5 +# It has been AutoGen-ed January 7, 2016 at 11:30:54 PM by AutoGen 5.18.5 # From the definitions ntpd-opts.def # and the template file agtexi-cmd.tpl @end ignore @@ -142,7 +142,7 @@ with a status code of 0. @exampleindent 0 @example -ntpd - NTP daemon program - Ver. 4.2.8p4 +ntpd - NTP daemon program - Ver. 4.2.8p5 Usage: ntpd [ - [] | --[@{=| @}] ]... \ [ ... ] Flg Arg Option-Name Description diff --git a/ntpd/ntp.conf.5man b/ntpd/ntp.conf.5man index ee457df4c8bb..6e6aa326bd9e 100644 --- a/ntpd/ntp.conf.5man +++ b/ntpd/ntp.conf.5man @@ -10,11 +10,11 @@ .ds B-Font B .ds I-Font I .ds R-Font R -.TH ntp.conf 5man "21 Oct 2015" "4.2.8p4" "File Formats" +.TH ntp.conf 5man "07 Jan 2016" "4.2.8p5" "File Formats" .\" -.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-9oaqYI/ag-OpaiXI) +.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-8qayqp/ag-Vraqpp) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:01 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:30:35 PM by AutoGen 5.18.5 .\" From the definitions ntp.conf.def .\" and the template file agman-cmd.tpl .SH NAME diff --git a/ntpd/ntp.conf.5mdoc b/ntpd/ntp.conf.5mdoc index a883aabaa8cb..800e995e0f61 100644 --- a/ntpd/ntp.conf.5mdoc +++ b/ntpd/ntp.conf.5mdoc @@ -1,9 +1,9 @@ -.Dd October 21 2015 +.Dd January 7 2016 .Dt NTP_CONF 5mdoc File Formats .Os .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:24 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:30:57 PM by AutoGen 5.18.5 .\" From the definitions ntp.conf.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/ntpd/ntp.conf.html b/ntpd/ntp.conf.html index 1f0c81908a05..d10a88d4e5e9 100644 --- a/ntpd/ntp.conf.html +++ b/ntpd/ntp.conf.html @@ -33,7 +33,7 @@ Up: (dir)

This document describes the configuration file for the NTP Project's ntpd program. -

This document applies to version 4.2.8p4 of ntp.conf. +

This document applies to version 4.2.8p5 of ntp.conf.

Short Contents

diff --git a/ntpd/ntp.conf.man.in b/ntpd/ntp.conf.man.in index 7c8a39f46588..f701b41fd2be 100644 --- a/ntpd/ntp.conf.man.in +++ b/ntpd/ntp.conf.man.in @@ -10,11 +10,11 @@ .ds B-Font B .ds I-Font I .ds R-Font R -.TH ntp.conf 5 "21 Oct 2015" "4.2.8p4" "File Formats" +.TH ntp.conf 5 "07 Jan 2016" "4.2.8p5" "File Formats" .\" -.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-9oaqYI/ag-OpaiXI) +.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-8qayqp/ag-Vraqpp) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:01 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:30:35 PM by AutoGen 5.18.5 .\" From the definitions ntp.conf.def .\" and the template file agman-cmd.tpl .SH NAME diff --git a/ntpd/ntp.conf.mdoc.in b/ntpd/ntp.conf.mdoc.in index 613ee7a84aed..7ad4cc1b3a12 100644 --- a/ntpd/ntp.conf.mdoc.in +++ b/ntpd/ntp.conf.mdoc.in @@ -1,9 +1,9 @@ -.Dd October 21 2015 +.Dd January 7 2016 .Dt NTP_CONF 5 File Formats .Os .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:24 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:30:57 PM by AutoGen 5.18.5 .\" From the definitions ntp.conf.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/ntpd/ntp.keys.5man b/ntpd/ntp.keys.5man index 3e5cb54d91a6..bb0028bd15bc 100644 --- a/ntpd/ntp.keys.5man +++ b/ntpd/ntp.keys.5man @@ -1,8 +1,8 @@ -.TH ntp.keys 5man "21 Oct 2015" "4.2.8p4" "File Formats" +.TH ntp.keys 5man "07 Jan 2016" "4.2.8p5" "File Formats" .\" .\" EDIT THIS FILE WITH CAUTION (ntp.man) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:08 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:30:41 PM by AutoGen 5.18.5 .\" From the definitions ntp.keys.def .\" and the template file agman-file.tpl .Sh NAME diff --git a/ntpd/ntp.keys.5mdoc b/ntpd/ntp.keys.5mdoc index 6355a39ca016..9524989cb1ad 100644 --- a/ntpd/ntp.keys.5mdoc +++ b/ntpd/ntp.keys.5mdoc @@ -1,9 +1,9 @@ -.Dd October 21 2015 +.Dd January 7 2016 .Dt NTP_KEYS 5mdoc File Formats .Os SunOS 5.10 .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:28 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:31:00 PM by AutoGen 5.18.5 .\" From the definitions ntp.keys.def .\" and the template file agmdoc-file.tpl .Sh NAME diff --git a/ntpd/ntp.keys.html b/ntpd/ntp.keys.html index 3671aaaace7a..738f9e03e73f 100644 --- a/ntpd/ntp.keys.html +++ b/ntpd/ntp.keys.html @@ -33,7 +33,7 @@ Up: (dir)

This document describes the symmetric key file for the NTP Project's ntpd program. -

This document applies to version 4.2.8p4 of ntp.keys. +

This document applies to version 4.2.8p5 of ntp.keys.

Short Contents

diff --git a/ntpd/ntp.keys.man.in b/ntpd/ntp.keys.man.in index bd64756a01c0..78d5f091d325 100644 --- a/ntpd/ntp.keys.man.in +++ b/ntpd/ntp.keys.man.in @@ -1,8 +1,8 @@ -.TH ntp.keys 5 "21 Oct 2015" "4.2.8p4" "File Formats" +.TH ntp.keys 5 "07 Jan 2016" "4.2.8p5" "File Formats" .\" .\" EDIT THIS FILE WITH CAUTION (ntp.man) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:08 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:30:41 PM by AutoGen 5.18.5 .\" From the definitions ntp.keys.def .\" and the template file agman-file.tpl .Sh NAME diff --git a/ntpd/ntp.keys.mdoc.in b/ntpd/ntp.keys.mdoc.in index 6600d57d5ea4..40c821e517d7 100644 --- a/ntpd/ntp.keys.mdoc.in +++ b/ntpd/ntp.keys.mdoc.in @@ -1,9 +1,9 @@ -.Dd October 21 2015 +.Dd January 7 2016 .Dt NTP_KEYS 5 File Formats .Os SunOS 5.10 .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:28 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:31:00 PM by AutoGen 5.18.5 .\" From the definitions ntp.keys.def .\" and the template file agmdoc-file.tpl .Sh NAME diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 77363117bda4..2e174d0210ab 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -846,7 +846,7 @@ ctl_error( u_char errcode ) { - int maclen; + size_t maclen; numctlerrors++; DPRINTF(3, ("sending control error %u\n", errcode)); @@ -1248,10 +1248,10 @@ ctl_flushpkt( ) { size_t i; - int dlen; - int sendlen; - int maclen; - int totlen; + size_t dlen; + size_t sendlen; + size_t maclen; + size_t totlen; keyid_t keyid; dlen = datapt - rpkt.u.data; diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c index 7ce7ccd26e79..7dd39a7c93a8 100644 --- a/ntpd/ntp_crypto.c +++ b/ntpd/ntp_crypto.c @@ -473,9 +473,9 @@ crypto_recv( } /* Check if the declared size fits into the remaining - * buffer. + * buffer. We *know* 'macbytes' > 0 here! */ - if (len > macbytes) { + if (len > (u_int)macbytes) { DPRINTF(1, ("crypto_recv: possible attack detected, associd %d\n", associd)); return XEVNT_LEN; diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 5fc6ed52acae..dd23459dff3a 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -41,6 +41,7 @@ #include "timevalops.h" #include "timespecops.h" #include "ntpd-opts.h" +#include "safecast.h" /* Don't include ISC's version of IPv6 variables and structures */ #define ISC_IPV6_H 1 @@ -772,7 +773,7 @@ is_ip_address( hints.ai_flags |= AI_NUMERICHOST; if (getaddrinfo(tmpbuf, NULL, &hints, &result) == 0) { AF(addr) = AF_INET6; - resaddr6 = (struct sockaddr_in6 *)result->ai_addr; + resaddr6 = UA_PTR(struct sockaddr_in6, result->ai_addr); SET_ADDR6N(addr, resaddr6->sin6_addr); SET_SCOPE(addr, resaddr6->sin6_scope_id); @@ -3365,7 +3366,7 @@ fetch_timestamp( #endif /* HAVE_BINTIME */ #ifdef HAVE_TIMESTAMPNS case SCM_TIMESTAMPNS: - tsp = (struct timespec *)CMSG_DATA(cmsghdr); + tsp = UA_PTR(struct timespec, CMSG_DATA(cmsghdr)); if (sys_tick > measured_tick && sys_tick > 1e-9) { ticks = (unsigned long)((tsp->tv_nsec * 1e-9) / @@ -3666,8 +3667,7 @@ input_handler( fds = activefds; tvzero.tv_sec = tvzero.tv_usec = 0; - n = select(maxactivefd + 1, &fds, (fd_set *)0, (fd_set *)0, - &tvzero); + n = select(maxactivefd + 1, &fds, NULL, NULL, &tvzero); /* * If there are no packets waiting just return @@ -4447,7 +4447,7 @@ close_and_delete_fd_from_list( break; case FD_TYPE_FILE: - closeserial(lsock->fd); + closeserial((int)lsock->fd); break; default: @@ -4643,7 +4643,7 @@ process_routing_msgs(struct asyncio_reader *reader) * process routing message */ #ifdef HAVE_RTNETLINK - for (nh = (struct nlmsghdr *)buffer; + for (nh = UA_PTR(struct nlmsghdr, buffer); NLMSG_OK(nh, cnt); nh = NLMSG_NEXT(nh, cnt)) { msg_type = nh->nlmsg_type; diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index 42c30de5679f..4b38aa8fd7d4 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -154,7 +154,6 @@ int hardpps_enable; /* kernel PPS discipline enabled */ int ext_enable; /* external clock enabled */ int pps_stratum; /* pps stratum */ int kernel_status; /* from ntp_adjtime */ -int allow_panic = FALSE; /* allow panic correction (-g) */ int force_step_once = FALSE; /* always step time once at startup (-G) */ int mode_ntpdate = FALSE; /* exit on first clock set (-q) */ int freq_cnt; /* initial frequency clamp */ @@ -459,16 +458,16 @@ local_clock( double dtemp, etemp; /* double temps */ char tbuf[80]; /* report buffer */ + (void)ntp_adj_ret; /* not always used below... */ /* * If the loop is opened or the NIST LOCKCLOCK is in use, * monitor and record the offsets anyway in order to determine * the open-loop response and then go home. */ -#ifdef LOCKCLOCK +#ifndef LOCKCLOCK + if (!ntp_enable) +#endif /* not LOCKCLOCK */ { -#else - if (!ntp_enable) { -#endif /* LOCKCLOCK */ record_loop_stats(fp_offset, drift_comp, clock_jitter, clock_stability, sys_poll); return (0); @@ -493,6 +492,8 @@ local_clock( return (-1); } + allow_panic = FALSE; + /* * This section simulates ntpdate. If the offset exceeds the * step threshold (128 ms), step the clock to that time and @@ -538,12 +539,8 @@ local_clock( else dtemp = (peer->delay - sys_mindly) / 2; fp_offset += dtemp; -#ifdef DEBUG - if (debug) - printf( - "local_clock: size %d mindly %.6f huffpuff %.6f\n", - sys_hufflen, sys_mindly, dtemp); -#endif + DPRINTF(1, ("local_clock: size %d mindly %.6f huffpuff %.6f\n", + sys_hufflen, sys_mindly, dtemp)); } /* @@ -694,7 +691,6 @@ local_clock( * startup until the initial transient has subsided. */ default: - allow_panic = FALSE; if (freq_cnt == 0) { /* @@ -921,15 +917,11 @@ local_clock( */ record_loop_stats(clock_offset, drift_comp, clock_jitter, clock_stability, sys_poll); -#ifdef DEBUG - if (debug) - printf( - "local_clock: offset %.9f jit %.9f freq %.3f stab %.3f poll %d\n", + DPRINTF(1, ("local_clock: offset %.9f jit %.9f freq %.3f stab %.3f poll %d\n", clock_offset, clock_jitter, drift_comp * 1e6, - clock_stability * 1e6, sys_poll); -#endif /* DEBUG */ + clock_stability * 1e6, sys_poll)); return (rval); -#endif /* LOCKCLOCK */ +#endif /* not LOCKCLOCK */ } @@ -1005,7 +997,10 @@ adj_host_clock( * but does not automatically stop slewing when an offset * has decayed to zero. */ + DEBUG_INSIST(enable_panic_check == TRUE); + enable_panic_check = FALSE; adj_systime(offset_adj + freq_adj); + enable_panic_check = TRUE; #endif /* LOCKCLOCK */ } @@ -1019,12 +1014,9 @@ rstclock( double offset /* new offset */ ) { -#ifdef DEBUG - if (debug > 1) - printf("local_clock: mu %lu state %d poll %d count %d\n", + DPRINTF(2, ("rstclock: mu %lu state %d poll %d count %d\n", current_time - clock_epoch, trans, sys_poll, - tc_counter); -#endif + tc_counter)); if (trans != state && trans != EVNT_FSET) report_event(trans, NULL, NULL); state = trans; @@ -1075,6 +1067,7 @@ set_freq( const char * loop_desc; int ntp_adj_ret; + (void)ntp_adj_ret; /* not always used below... */ drift_comp = freq; loop_desc = "ntpd"; #ifdef KERNEL_PLL @@ -1236,10 +1229,7 @@ loop_config( int i; double ftemp; -#ifdef DEBUG - if (debug > 1) - printf("loop_config: item %d freq %f\n", item, freq); -#endif + DPRINTF(2, ("loop_config: item %d freq %f\n", item, freq)); switch (item) { /* diff --git a/ntpd/ntp_parser.c b/ntpd/ntp_parser.c index 6235033feffb..cc179502c1e1 100644 --- a/ntpd/ntp_parser.c +++ b/ntpd/ntp_parser.c @@ -889,21 +889,21 @@ static const yytype_uint16 yyrline[] = 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 886, 891, 899, 904, 905, 906, 910, 915, 923, 928, 929, 930, 931, 932, 933, 934, 935, 943, 953, - 958, 966, 968, 970, 972, 974, 979, 980, 984, 985, - 986, 987, 995, 1000, 1005, 1013, 1018, 1019, 1020, 1029, - 1031, 1036, 1041, 1049, 1051, 1068, 1069, 1070, 1071, 1072, - 1073, 1077, 1078, 1086, 1091, 1096, 1104, 1109, 1110, 1111, - 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1127, 1128, 1129, - 1136, 1143, 1150, 1166, 1185, 1187, 1189, 1191, 1193, 1195, - 1202, 1207, 1208, 1209, 1213, 1217, 1226, 1227, 1231, 1232, - 1233, 1237, 1248, 1262, 1274, 1279, 1281, 1286, 1287, 1295, - 1297, 1305, 1310, 1318, 1343, 1350, 1360, 1361, 1365, 1366, - 1367, 1368, 1372, 1373, 1374, 1378, 1383, 1388, 1396, 1397, - 1398, 1399, 1400, 1401, 1402, 1412, 1417, 1425, 1430, 1438, - 1440, 1444, 1449, 1454, 1462, 1467, 1475, 1484, 1485, 1489, - 1490, 1499, 1517, 1521, 1526, 1534, 1539, 1540, 1544, 1549, - 1557, 1562, 1567, 1572, 1577, 1585, 1590, 1595, 1603, 1608, - 1609, 1610, 1611, 1612 + 958, 966, 968, 970, 979, 981, 986, 987, 991, 992, + 993, 994, 1002, 1007, 1012, 1020, 1025, 1026, 1027, 1036, + 1038, 1043, 1048, 1056, 1058, 1075, 1076, 1077, 1078, 1079, + 1080, 1084, 1085, 1093, 1098, 1103, 1111, 1116, 1117, 1118, + 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1134, 1135, 1136, + 1143, 1150, 1157, 1173, 1192, 1194, 1196, 1198, 1200, 1202, + 1209, 1214, 1215, 1216, 1220, 1224, 1233, 1234, 1238, 1239, + 1240, 1244, 1255, 1269, 1281, 1286, 1288, 1293, 1294, 1302, + 1304, 1312, 1317, 1325, 1350, 1357, 1367, 1368, 1372, 1373, + 1374, 1375, 1379, 1380, 1381, 1385, 1390, 1395, 1403, 1404, + 1405, 1406, 1407, 1408, 1409, 1419, 1424, 1432, 1437, 1445, + 1447, 1451, 1456, 1461, 1469, 1474, 1482, 1491, 1492, 1496, + 1497, 1506, 1524, 1528, 1533, 1541, 1546, 1547, 1551, 1556, + 1564, 1569, 1574, 1579, 1584, 1592, 1597, 1602, 1610, 1615, + 1616, 1617, 1618, 1619 }; #endif @@ -2684,90 +2684,97 @@ yyparse (void) case 173: #line 971 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ - { (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); } -#line 2689 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + { + if ((yyvsp[0].Integer) >= 0 && (yyvsp[0].Integer) <= 16) { + (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); + } else { + (yyval.Attr_val) = NULL; + yyerror("fudge factor: stratum value not in [0..16], ignored"); + } + } +#line 2696 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 174: -#line 973 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 980 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_sval((yyvsp[-1].Integer), (yyvsp[0].String)); } -#line 2695 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2702 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 175: -#line 975 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 982 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_sval((yyvsp[-1].Integer), (yyvsp[0].String)); } -#line 2701 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2708 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 182: -#line 996 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1003 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.rlimit, (yyvsp[0].Attr_val_fifo)); } -#line 2707 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2714 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 183: -#line 1001 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1008 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 2716 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2723 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 184: -#line 1006 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1013 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 2725 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2732 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 185: -#line 1014 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1021 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); } -#line 2731 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2738 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 189: -#line 1030 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1037 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.enable_opts, (yyvsp[0].Attr_val_fifo)); } -#line 2737 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2744 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 190: -#line 1032 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1039 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.disable_opts, (yyvsp[0].Attr_val_fifo)); } -#line 2743 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2750 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 191: -#line 1037 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1044 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 2752 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2759 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 192: -#line 1042 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1049 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 2761 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2768 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 193: -#line 1050 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1057 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_ival(T_Flag, (yyvsp[0].Integer)); } -#line 2767 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2774 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 194: -#line 1052 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1059 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { if (lex_from_file()) { (yyval.Attr_val) = create_attr_ival(T_Flag, (yyvsp[0].Integer)); @@ -2781,74 +2788,74 @@ yyparse (void) yyerror(err_str); } } -#line 2785 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2792 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 203: -#line 1087 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1094 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.tinker, (yyvsp[0].Attr_val_fifo)); } -#line 2791 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2798 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 204: -#line 1092 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1099 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 2800 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2807 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 205: -#line 1097 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1104 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 2809 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2816 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 206: -#line 1105 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1112 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_dval((yyvsp[-1].Integer), (yyvsp[0].Double)); } -#line 2815 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2822 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 219: -#line 1130 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1137 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { attr_val *av; av = create_attr_dval((yyvsp[-1].Integer), (yyvsp[0].Double)); APPEND_G_FIFO(cfgt.vars, av); } -#line 2826 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2833 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 220: -#line 1137 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1144 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { attr_val *av; av = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); APPEND_G_FIFO(cfgt.vars, av); } -#line 2837 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2844 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 221: -#line 1144 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1151 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { attr_val *av; av = create_attr_sval((yyvsp[-1].Integer), (yyvsp[0].String)); APPEND_G_FIFO(cfgt.vars, av); } -#line 2848 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2855 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 222: -#line 1151 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1158 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { char error_text[64]; attr_val *av; @@ -2864,11 +2871,11 @@ yyparse (void) yyerror(error_text); } } -#line 2868 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2875 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 223: -#line 1167 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1174 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { if (!lex_from_file()) { YYFREE((yyvsp[-1].String)); /* avoid leak */ @@ -2887,68 +2894,68 @@ yyparse (void) } YYFREE((yyvsp[-1].String)); /* avoid leak */ } -#line 2891 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2898 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 224: -#line 1186 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1193 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { lex_flush_stack(); } -#line 2897 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2904 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 225: -#line 1188 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1195 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { /* see drift_parm below for actions */ } -#line 2903 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2910 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 226: -#line 1190 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1197 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.logconfig, (yyvsp[0].Attr_val_fifo)); } -#line 2909 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2916 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 227: -#line 1192 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1199 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.phone, (yyvsp[0].String_fifo)); } -#line 2915 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2922 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 228: -#line 1194 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1201 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { APPEND_G_FIFO(cfgt.setvar, (yyvsp[0].Set_var)); } -#line 2921 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2928 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 229: -#line 1196 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1203 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { addr_opts_node *aon; aon = create_addr_opts_node((yyvsp[-1].Address_node), (yyvsp[0].Attr_val_fifo)); APPEND_G_FIFO(cfgt.trap, aon); } -#line 2932 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2939 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 230: -#line 1203 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1210 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.ttl, (yyvsp[0].Attr_val_fifo)); } -#line 2938 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2945 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 235: -#line 1218 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1225 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { #ifndef LEAP_SMEAR yyerror("Built without LEAP_SMEAR support."); #endif } -#line 2948 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2955 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 241: -#line 1238 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1245 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { if (lex_from_file()) { attr_val *av; @@ -2959,11 +2966,11 @@ yyparse (void) yyerror("driftfile remote configuration ignored"); } } -#line 2963 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2970 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 242: -#line 1249 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1256 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { if (lex_from_file()) { attr_val *av; @@ -2976,11 +2983,11 @@ yyparse (void) yyerror("driftfile remote configuration ignored"); } } -#line 2980 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 2987 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 243: -#line 1262 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1269 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { if (lex_from_file()) { attr_val *av; @@ -2990,71 +2997,71 @@ yyparse (void) yyerror("driftfile remote configuration ignored"); } } -#line 2994 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3001 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 244: -#line 1275 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1282 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Set_var) = create_setvar_node((yyvsp[-3].String), (yyvsp[-1].String), (yyvsp[0].Integer)); } -#line 3000 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3007 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 246: -#line 1281 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1288 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Integer) = 0; } -#line 3006 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3013 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 247: -#line 1286 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1293 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; } -#line 3012 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3019 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 248: -#line 1288 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1295 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 3021 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3028 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 249: -#line 1296 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1303 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); } -#line 3027 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3034 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 250: -#line 1298 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1305 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_sval((yyvsp[-1].Integer), estrdup((yyvsp[0].Address_node)->address)); destroy_address_node((yyvsp[0].Address_node)); } -#line 3036 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3043 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 251: -#line 1306 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1313 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 3045 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3052 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 252: -#line 1311 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1318 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 3054 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3061 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 253: -#line 1319 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1326 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { char prefix; char * type; @@ -3076,141 +3083,141 @@ yyparse (void) (yyval.Attr_val) = create_attr_sval(prefix, estrdup(type)); YYFREE((yyvsp[0].String)); } -#line 3080 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3087 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 254: -#line 1344 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1351 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { nic_rule_node *nrn; nrn = create_nic_rule_node((yyvsp[0].Integer), NULL, (yyvsp[-1].Integer)); APPEND_G_FIFO(cfgt.nic_rules, nrn); } -#line 3091 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3098 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 255: -#line 1351 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1358 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { nic_rule_node *nrn; nrn = create_nic_rule_node(0, (yyvsp[0].String), (yyvsp[-1].Integer)); APPEND_G_FIFO(cfgt.nic_rules, nrn); } -#line 3102 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3109 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 265: -#line 1379 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1386 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { CONCAT_G_FIFOS(cfgt.reset_counters, (yyvsp[0].Int_fifo)); } -#line 3108 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3115 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 266: -#line 1384 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1391 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Int_fifo) = (yyvsp[-1].Int_fifo); APPEND_G_FIFO((yyval.Int_fifo), create_int_node((yyvsp[0].Integer))); } -#line 3117 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3124 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 267: -#line 1389 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1396 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Int_fifo) = NULL; APPEND_G_FIFO((yyval.Int_fifo), create_int_node((yyvsp[0].Integer))); } -#line 3126 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3133 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 275: -#line 1413 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1420 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), create_int_node((yyvsp[0].Integer))); } -#line 3135 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3142 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 276: -#line 1418 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1425 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), create_int_node((yyvsp[0].Integer))); } -#line 3144 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3151 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 277: -#line 1426 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1433 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 3153 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3160 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 278: -#line 1431 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1438 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); } -#line 3162 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3169 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 279: -#line 1439 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1446 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_ival('i', (yyvsp[0].Integer)); } -#line 3168 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3175 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 281: -#line 1445 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1452 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_rangeval('-', (yyvsp[-3].Integer), (yyvsp[-1].Integer)); } -#line 3174 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3181 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 282: -#line 1450 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1457 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.String_fifo) = (yyvsp[-1].String_fifo); APPEND_G_FIFO((yyval.String_fifo), create_string_node((yyvsp[0].String))); } -#line 3183 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3190 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 283: -#line 1455 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1462 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.String_fifo) = NULL; APPEND_G_FIFO((yyval.String_fifo), create_string_node((yyvsp[0].String))); } -#line 3192 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3199 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 284: -#line 1463 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1470 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Address_fifo) = (yyvsp[-1].Address_fifo); APPEND_G_FIFO((yyval.Address_fifo), (yyvsp[0].Address_node)); } -#line 3201 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3208 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 285: -#line 1468 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1475 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Address_fifo) = NULL; APPEND_G_FIFO((yyval.Address_fifo), (yyvsp[0].Address_node)); } -#line 3210 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3217 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 286: -#line 1476 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1483 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { if ((yyvsp[0].Integer) != 0 && (yyvsp[0].Integer) != 1) { yyerror("Integer value is not boolean (0 or 1). Assuming 1"); @@ -3219,29 +3226,29 @@ yyparse (void) (yyval.Integer) = (yyvsp[0].Integer); } } -#line 3223 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3230 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 287: -#line 1484 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1491 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Integer) = 1; } -#line 3229 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3236 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 288: -#line 1485 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1492 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Integer) = 0; } -#line 3235 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3242 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 289: -#line 1489 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1496 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Double) = (double)(yyvsp[0].Integer); } -#line 3241 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3248 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 291: -#line 1500 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1507 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { sim_node *sn; @@ -3251,125 +3258,125 @@ yyparse (void) /* Revert from ; to \n for end-of-command */ old_config_style = 1; } -#line 3255 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3262 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 292: -#line 1517 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1524 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { old_config_style = 0; } -#line 3261 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3268 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 293: -#line 1522 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1529 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-2].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); } -#line 3270 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3277 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 294: -#line 1527 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1534 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); } -#line 3279 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3286 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 295: -#line 1535 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1542 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_dval((yyvsp[-2].Integer), (yyvsp[0].Double)); } -#line 3285 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3292 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 298: -#line 1545 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1552 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Sim_server_fifo) = (yyvsp[-1].Sim_server_fifo); APPEND_G_FIFO((yyval.Sim_server_fifo), (yyvsp[0].Sim_server)); } -#line 3294 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3301 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 299: -#line 1550 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1557 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Sim_server_fifo) = NULL; APPEND_G_FIFO((yyval.Sim_server_fifo), (yyvsp[0].Sim_server)); } -#line 3303 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3310 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 300: -#line 1558 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1565 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Sim_server) = ONLY_SIM(create_sim_server((yyvsp[-4].Address_node), (yyvsp[-2].Double), (yyvsp[-1].Sim_script_fifo))); } -#line 3309 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3316 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 301: -#line 1563 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1570 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Double) = (yyvsp[-1].Double); } -#line 3315 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3322 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 302: -#line 1568 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1575 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Address_node) = (yyvsp[0].Address_node); } -#line 3321 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3328 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 303: -#line 1573 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1580 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Sim_script_fifo) = (yyvsp[-1].Sim_script_fifo); APPEND_G_FIFO((yyval.Sim_script_fifo), (yyvsp[0].Sim_script)); } -#line 3330 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3337 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 304: -#line 1578 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1585 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Sim_script_fifo) = NULL; APPEND_G_FIFO((yyval.Sim_script_fifo), (yyvsp[0].Sim_script)); } -#line 3339 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3346 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 305: -#line 1586 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1593 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Sim_script) = ONLY_SIM(create_sim_script_info((yyvsp[-3].Double), (yyvsp[-1].Attr_val_fifo))); } -#line 3345 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3352 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 306: -#line 1591 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1598 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = (yyvsp[-2].Attr_val_fifo); APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); } -#line 3354 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3361 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 307: -#line 1596 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1603 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val_fifo) = NULL; APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); } -#line 3363 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3370 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; case 308: -#line 1604 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +#line 1611 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ { (yyval.Attr_val) = create_attr_dval((yyvsp[-2].Integer), (yyvsp[0].Double)); } -#line 3369 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3376 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ break; -#line 3373 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ +#line 3380 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -3597,7 +3604,7 @@ yyparse (void) #endif return yyresult; } -#line 1615 "../../ntpd/ntp_parser.y" /* yacc.c:1906 */ +#line 1622 "../../ntpd/ntp_parser.y" /* yacc.c:1906 */ void diff --git a/ntpd/ntp_parser.y b/ntpd/ntp_parser.y index 6f9841d52800..a4267e1a8d09 100644 --- a/ntpd/ntp_parser.y +++ b/ntpd/ntp_parser.y @@ -968,7 +968,14 @@ fudge_factor | fudge_factor_bool_keyword boolean { $$ = create_attr_ival($1, $2); } | T_Stratum T_Integer - { $$ = create_attr_ival($1, $2); } + { + if ($2 >= 0 && $2 <= 16) { + $$ = create_attr_ival($1, $2); + } else { + $$ = NULL; + yyerror("fudge factor: stratum value not in [0..16], ignored"); + } + } | T_Abbrev T_String { $$ = create_attr_sval($1, $2); } | T_Refid T_String diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 2a15d7242647..f7704722a9ba 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -15,6 +15,7 @@ #include "ntp_string.h" #include "ntp_leapsec.h" #include "refidsmear.h" +#include "lib_strbuf.h" #include #ifdef HAVE_LIBSCF_H @@ -172,8 +173,14 @@ void pool_name_resolved (int, int, void *, const char *, const struct addrinfo *); #endif /* WORKER */ +const char * amtoa (int am); + + void -set_sys_leap(u_char new_sys_leap) { +set_sys_leap( + u_char new_sys_leap + ) +{ sys_leap = new_sys_leap; xmt_leap = sys_leap; @@ -189,8 +196,9 @@ set_sys_leap(u_char new_sys_leap) { #ifdef LEAP_SMEAR else { /* - * If leap smear is enabled in general we must never send a leap second warning - * to clients, so make sure we only send "in sync". + * If leap smear is enabled in general we must + * never send a leap second warning to clients, + * so make sure we only send "in sync". */ if (leap_smear.enabled) xmt_leap = LEAP_NOWARNING; @@ -199,34 +207,39 @@ set_sys_leap(u_char new_sys_leap) { } } + /* * Kiss Code check */ -int kiss_code_check(u_char hisleap, u_char hisstratum, u_char hismode, u_int32 refid) { +int +kiss_code_check( + u_char hisleap, + u_char hisstratum, + u_char hismode, + u_int32 refid + ) +{ - if ( hismode == MODE_SERVER - && hisleap == LEAP_NOTINSYNC - && hisstratum == STRATUM_UNSPEC) { - if(memcmp(&refid,"RATE", 4) == 0) { - return (RATEKISS); - } - else if(memcmp(&refid,"DENY", 4) == 0) { - return (DENYKISS); - } - else if(memcmp(&refid,"RSTR", 4) == 0) { - return (RSTRKISS); - } - else if(memcmp(&refid,"X", 1) == 0) { - return (XKISS); - } - else { - return (UNKNOWNKISS); - } - } - else { - return (NOKISS); + if ( hismode == MODE_SERVER + && hisleap == LEAP_NOTINSYNC + && hisstratum == STRATUM_UNSPEC) { + if(memcmp(&refid,"RATE", 4) == 0) { + return (RATEKISS); + } else if(memcmp(&refid,"DENY", 4) == 0) { + return (DENYKISS); + } else if(memcmp(&refid,"RSTR", 4) == 0) { + return (RSTRKISS); + } else if(memcmp(&refid,"X", 1) == 0) { + return (XKISS); + } else { + return (UNKNOWNKISS); } + } else { + return (NOKISS); + } } + + /* * transmit - transmit procedure called by poll timeout */ @@ -303,7 +316,7 @@ transmit( peer->outdate = current_time; if ( (peer_associations <= 2 * sys_maxclock) && ( peer_associations < sys_maxclock - || sys_survivors < sys_minclock)) + || sys_survivors < sys_minclock)) pool_xmit(peer); poll_update(peer, hpoll); return; @@ -416,6 +429,33 @@ transmit( if (peer->hmode != MODE_BCLIENT) peer_xmit(peer); poll_update(peer, hpoll); + + return; +} + + +const char * +amtoa( + int am + ) +{ + char *bp; + + switch(am) { + case AM_ERR: return "AM_ERR"; + case AM_NOMATCH: return "AM_NOMATCH"; + case AM_PROCPKT: return "AM_PROCPKT"; + case AM_BCST: return "AM_BCST"; + case AM_FXMIT: return "AM_FXMIT"; + case AM_MANYCAST: return "AM_MANYCAST"; + case AM_NEWPASS: return "AM_NEWPASS"; + case AM_NEWBCL: return "AM_NEWBCL"; + case AM_POSSBCL: return "AM_POSSBCL"; + default: + LIB_GETBUF(bp); + snprintf(bp, LIB_BUFLENGTH, "AM_#%d", am); + return bp; + } } @@ -434,16 +474,18 @@ receive( u_char hismode; /* packet mode */ u_char hisstratum; /* packet stratum */ u_short restrict_mask; /* restrict bits */ - int kissCode = NOKISS; /* Kiss Code */ + const char *hm_str; /* hismode string */ + const char *am_str; /* association match string */ + int kissCode = NOKISS; /* Kiss Code */ int has_mac; /* length of MAC field */ int authlen; /* offset of MAC field */ int is_authentic = 0; /* cryptosum ok */ int retcode = AM_NOMATCH; /* match code */ keyid_t skeyid = 0; /* key IDs */ u_int32 opcode = 0; /* extension field opcode */ - sockaddr_u *dstadr_sin; /* active runway */ + sockaddr_u *dstadr_sin; /* active runway */ struct peer *peer2; /* aux peer structure pointer */ - endpt * match_ep; /* newpeer() local address */ + endpt *match_ep; /* newpeer() local address */ l_fp p_org; /* origin timestamp */ l_fp p_rec; /* receive timestamp */ l_fp p_xmt; /* transmit timestamp */ @@ -474,11 +516,12 @@ receive( return; /* bogus port */ } restrict_mask = restrictions(&rbufp->recv_srcadr); - DPRINTF(2, ("receive: at %ld %s<-%s flags %x restrict %03x\n", - current_time, stoa(&rbufp->dstadr->sin), - stoa(&rbufp->recv_srcadr), - rbufp->dstadr->flags, restrict_mask)); pkt = &rbufp->recv_pkt; + DPRINTF(2, ("receive: at %ld %s<-%s flags %x restrict %03x org %#010x.%08x xmt %#010x.%08x\n", + current_time, stoa(&rbufp->dstadr->sin), + stoa(&rbufp->recv_srcadr), rbufp->dstadr->flags, + restrict_mask, ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), + ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); hisversion = PKT_VERSION(pkt->li_vn_mode); hisleap = PKT_LEAP(pkt->li_vn_mode); hismode = (int)PKT_MODE(pkt->li_vn_mode); @@ -685,6 +728,8 @@ receive( NTOHL_FP(&pkt->org, &p_org); NTOHL_FP(&pkt->rec, &p_rec); NTOHL_FP(&pkt->xmt, &p_xmt); + hm_str = modetoa(hismode); + am_str = amtoa(retcode); /* * Authentication is conditioned by three switches: @@ -713,25 +758,21 @@ receive( if (has_mac == 0) { restrict_mask &= ~RES_MSSNTP; is_authentic = AUTH_NONE; /* not required */ -#ifdef DEBUG - if (debug) - printf( - "receive: at %ld %s<-%s mode %d len %d\n", + DPRINTF(2, ("receive: at %ld %s<-%s mode %d/%s:%s len %d org %#010x.%08x xmt %#010x.%08x NOMAC\n", current_time, stoa(dstadr_sin), - stoa(&rbufp->recv_srcadr), hismode, - authlen); -#endif + stoa(&rbufp->recv_srcadr), hismode, hm_str, am_str, + authlen, + ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), + ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); } else if (has_mac == 4) { restrict_mask &= ~RES_MSSNTP; is_authentic = AUTH_CRYPTO; /* crypto-NAK */ -#ifdef DEBUG - if (debug) - printf( - "receive: at %ld %s<-%s mode %d keyid %08x len %d auth %d\n", + DPRINTF(2, ("receive: at %ld %s<-%s mode %d/%s:%s keyid %08x len %d auth %d org %#010x.%08x xmt %#010x.%08x MAC4\n", current_time, stoa(dstadr_sin), - stoa(&rbufp->recv_srcadr), hismode, skeyid, - authlen + has_mac, is_authentic); -#endif + stoa(&rbufp->recv_srcadr), hismode, hm_str, am_str, + skeyid, authlen + has_mac, is_authentic, + ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), + ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); #ifdef HAVE_NTP_SIGND /* @@ -747,7 +788,7 @@ receive( && (restrict_mask & RES_MSSNTP) && (retcode == AM_FXMIT || retcode == AM_NEWPASS) && (memcmp(zero_key, (char *)pkt + authlen + 4, - MAX_MD5_LEN - 4) == 0)) { + MAX_MD5_LEN - 4) == 0)) { is_authentic = AUTH_NONE; #endif /* HAVE_NTP_SIGND */ @@ -856,14 +897,12 @@ receive( if (crypto_flags && skeyid > NTP_MAXKEY) authtrust(skeyid, 0); #endif /* AUTOKEY */ -#ifdef DEBUG - if (debug) - printf( - "receive: at %ld %s<-%s mode %d keyid %08x len %d auth %d\n", + DPRINTF(2, ("receive: at %ld %s<-%s mode %d/%s:%s keyid %08x len %d auth %d org %#010x.%08x xmt %#010x.%08x\n", current_time, stoa(dstadr_sin), - stoa(&rbufp->recv_srcadr), hismode, skeyid, - authlen + has_mac, is_authentic); -#endif + stoa(&rbufp->recv_srcadr), hismode, hm_str, am_str, + skeyid, authlen + has_mac, is_authentic, + ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), + ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); } /* @@ -1194,11 +1233,11 @@ receive( * debug-printed and not logged to avoid log * flooding. */ - DPRINTF(1, ("receive: at %ld refusing to mobilize passive association" - " with unknown peer %s mode %d keyid %08x len %d auth %d\n", + DPRINTF(2, ("receive: at %ld refusing to mobilize passive association" + " with unknown peer %s mode %d/%s:%s keyid %08x len %d auth %d\n", current_time, stoa(&rbufp->recv_srcadr), - hismode, skeyid, (authlen + has_mac), - is_authentic)); + hismode, hm_str, am_str, skeyid, + (authlen + has_mac), is_authentic)); sys_declined++; return; } @@ -1321,26 +1360,36 @@ receive( } /* - * Check for bogus packet in basic mode. If found, switch to - * interleaved mode and resynchronize, but only after confirming - * the packet is not bogus in symmetric interleaved mode. + * Basic mode checks: + * + * If there is no origin timestamp, it's an initial packet. + * + * Otherwise, check for bogus packet in basic mode. + * If it is bogus, switch to interleaved mode and resynchronize, + * but only after confirming the packet is not bogus in + * symmetric interleaved mode. * * This could also mean somebody is forging packets claiming to * be from us, attempting to cause our server to KoD us. */ } else if (peer->flip == 0) { - if (!L_ISEQU(&p_org, &peer->aorg)) { + if (0 < hisstratum && L_ISZERO(&p_org)) { + L_CLR(&peer->aorg); + } else if (!L_ISEQU(&p_org, &peer->aorg)) { peer->bogusorg++; peer->flash |= TEST2; /* bogus */ msyslog(LOG_INFO, - "receive: Unexpected origin timestamp from %s", - ntoa(&peer->srcadr)); + "receive: Unexpected origin timestamp %#010x.%08x from %s xmt %#010x.%08x", + ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), + ntoa(&peer->srcadr), + ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf)); if ( !L_ISZERO(&peer->dst) && L_ISEQU(&p_org, &peer->dst)) { + /* Might be the start of an interleave */ peer->flip = 1; report_event(PEVNT_XLEAVE, peer, NULL); } - return; /* Bogus packet, we are done */ + return; /* Bogus or possible interleave packet */ } else { L_CLR(&peer->aorg); } @@ -1694,11 +1743,8 @@ process_packet( */ if (peer->flash & PKT_TEST_MASK) { peer->seldisptoolarge++; -#ifdef DEBUG - if (debug) - printf("packet: flash header %04x\n", - peer->flash); -#endif + DPRINTF(1, ("packet: flash header %04x\n", + peer->flash)); return; } @@ -1871,15 +1917,12 @@ process_packet( * the roundtrip delay. Then it calculates the correction as a * fraction of d. */ - peer->t21 = t21; + peer->t21 = t21; peer->t21_last = peer->t21_bytes; peer->t34 = -t34; peer->t34_bytes = len; -#ifdef DEBUG - if (debug > 1) - printf("packet: t21 %.9lf %d t34 %.9lf %d\n", peer->t21, - peer->t21_bytes, peer->t34, peer->t34_bytes); -#endif + DPRINTF(2, ("packet: t21 %.9lf %d t34 %.9lf %d\n", peer->t21, + peer->t21_bytes, peer->t34, peer->t34_bytes)); if (peer->r21 > 0 && peer->r34 > 0 && p_del > 0) { if (peer->pmode != MODE_BROADCAST) td = (peer->r34 / (peer->r21 + peer->r34) - @@ -1888,7 +1931,7 @@ process_packet( td = 0; /* - * Unfortunately, in many cases the errors are + * Unfortunately, in many cases the errors are * unacceptable, so for the present the rates are not * used. In future, we might find conditions where the * calculations are useful, so this should be considered @@ -1896,12 +1939,9 @@ process_packet( */ t21 -= td; t34 -= td; -#ifdef DEBUG - if (debug > 1) - printf("packet: del %.6lf r21 %.1lf r34 %.1lf %.6lf\n", + DPRINTF(2, ("packet: del %.6lf r21 %.1lf r34 %.1lf %.6lf\n", p_del, peer->r21 / 1e3, peer->r34 / 1e3, - td); -#endif + td)); } #endif /* ASSYM */ @@ -1994,12 +2034,8 @@ clock_update( sys_rootdelay = peer->delay + peer->rootdelay; sys_reftime = peer->dst; -#ifdef DEBUG - if (debug) - printf( - "clock_update: at %lu sample %lu associd %d\n", - current_time, peer->epoch, peer->associd); -#endif + DPRINTF(1, ("clock_update: at %lu sample %lu associd %d\n", + current_time, peer->epoch, peer->associd)); /* * Comes now the moment of truth. Crank the clock discipline and @@ -2308,13 +2344,9 @@ peer_clear( #ifdef AUTOKEY peer->refresh = current_time + (1 << NTP_REFRESH); #endif /* AUTOKEY */ -#ifdef DEBUG - if (debug) - printf( - "peer_clear: at %ld next %ld associd %d refid %s\n", + DPRINTF(1, ("peer_clear: at %ld next %ld associd %d refid %s\n", current_time, peer->nextdate, peer->associd, - ident); -#endif + ident)); } @@ -2478,11 +2510,8 @@ clock_filter( * packets. */ if (peer->filter_epoch[k] <= peer->epoch) { -#if DEBUG - if (debug > 1) - printf("clock_filter: old sample %lu\n", current_time - - peer->filter_epoch[k]); -#endif + DPRINTF(2, ("clock_filter: old sample %lu\n", current_time - + peer->filter_epoch[k])); return; } peer->epoch = peer->filter_epoch[k]; @@ -2494,13 +2523,9 @@ clock_filter( */ record_peer_stats(&peer->srcadr, ctlpeerstatus(peer), peer->offset, peer->delay, peer->disp, peer->jitter); -#ifdef DEBUG - if (debug) - printf( - "clock_filter: n %d off %.6f del %.6f dsp %.6f jit %.6f\n", + DPRINTF(1, ("clock_filter: n %d off %.6f del %.6f dsp %.6f jit %.6f\n", m, peer->offset, peer->delay, peer->disp, - peer->jitter); -#endif + peer->jitter)); if (peer->burst == 0 || sys_leap == LEAP_NOTINSYNC) clock_select(); } @@ -3004,7 +3029,7 @@ clock_select(void) typesystem = typepps; sys_clockhop = 0; typesystem->new_status = CTL_PST_SEL_PPS; - sys_offset = typesystem->offset; + sys_offset = typesystem->offset; sys_jitter = typesystem->jitter; DPRINTF(1, ("select: pps offset %.9f jitter %.9f\n", sys_offset, sys_jitter)); @@ -3157,11 +3182,11 @@ peer_xmit( * might not be usable. */ sendlen = LEN_PKT_NOMAC; + if ( #ifdef AUTOKEY - if (!(peer->flags & FLAG_SKEY) && peer->keyid == 0) { -#else /* !AUTOKEY follows */ - if (peer->keyid == 0) { + !(peer->flags & FLAG_SKEY) && #endif /* !AUTOKEY */ + peer->keyid == 0) { /* * Transmit a-priori timestamps @@ -3207,13 +3232,11 @@ peer_xmit( } L_SUB(&xmt_ty, &xmt_tx); LFPTOD(&xmt_ty, peer->xleave); -#ifdef DEBUG - if (debug) - printf("transmit: at %ld %s->%s mode %d len %zu\n", - current_time, peer->dstadr ? - stoa(&peer->dstadr->sin) : "-", - stoa(&peer->srcadr), peer->hmode, sendlen); -#endif + DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d len %zu xmt %#010x.%08x\n", + current_time, + peer->dstadr ? stoa(&peer->dstadr->sin) : "-", + stoa(&peer->srcadr), peer->hmode, sendlen, + xmt_tx.l_ui, xmt_tx.l_uf)); return; } @@ -3498,7 +3521,7 @@ peer_xmit( authtrust(xkeyid, 0); #endif /* AUTOKEY */ if (sendlen > sizeof(xpkt)) { - msyslog(LOG_ERR, "proto: buffer overflow %zu", sendlen); + msyslog(LOG_ERR, "peer_xmit: buffer overflow %zu", sendlen); exit (-1); } peer->t21_bytes = sendlen; @@ -3521,30 +3544,33 @@ peer_xmit( L_SUB(&xmt_ty, &xmt_tx); LFPTOD(&xmt_ty, peer->xleave); #ifdef AUTOKEY -#ifdef DEBUG - if (debug) - printf("transmit: at %ld %s->%s mode %d keyid %08x len %zu index %d\n", + DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d keyid %08x len %zu index %d\n", current_time, latoa(peer->dstadr), ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen, - peer->keynumber); -#endif + peer->keynumber)); #else /* !AUTOKEY follows */ -#ifdef DEBUG - if (debug) - printf("transmit: at %ld %s->%s mode %d keyid %08x len %d\n", + DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d keyid %08x len %d\n", current_time, peer->dstadr ? ntoa(&peer->dstadr->sin) : "-", - ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen); -#endif + ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen)); #endif /* !AUTOKEY */ + + return; } #ifdef LEAP_SMEAR static void -leap_smear_add_offs(l_fp *t, l_fp *t_recv) { +leap_smear_add_offs( + l_fp *t, + l_fp *t_recv + ) +{ + L_ADD(t, &leap_smear.offset); + + return; } #endif /* LEAP_SMEAR */ @@ -3565,7 +3591,7 @@ fast_xmit( struct pkt xpkt; /* transmit packet structure */ struct pkt *rpkt; /* receive packet structure */ l_fp xmt_tx, xmt_ty; - int sendlen; + size_t sendlen; #ifdef AUTOKEY u_int32 temp32; #endif @@ -3684,13 +3710,10 @@ fast_xmit( if (rbufp->recv_length == sendlen) { sendpkt(&rbufp->recv_srcadr, rbufp->dstadr, 0, &xpkt, sendlen); -#ifdef DEBUG - if (debug) - printf( - "transmit: at %ld %s->%s mode %d len %d\n", + DPRINTF(1, ("fast_xmit: at %ld %s->%s mode %d len %lu\n", current_time, stoa(&rbufp->dstadr->sin), - stoa(&rbufp->recv_srcadr), xmode, sendlen); -#endif + stoa(&rbufp->recv_srcadr), xmode, + (u_long)sendlen)); return; } @@ -3717,7 +3740,7 @@ fast_xmit( */ cookie = session_key(&rbufp->recv_srcadr, &rbufp->dstadr->sin, 0, sys_private, 0); - if (rbufp->recv_length > sendlen + (int)MAX_MAC_LEN) { + if ((size_t)rbufp->recv_length > sendlen + MAX_MAC_LEN) { session_key(&rbufp->dstadr->sin, &rbufp->recv_srcadr, xkeyid, 0, 2); temp32 = CRYPTO_RESP; @@ -3741,13 +3764,10 @@ fast_xmit( get_systime(&xmt_ty); L_SUB(&xmt_ty, &xmt_tx); sys_authdelay = xmt_ty; -#ifdef DEBUG - if (debug) - printf( - "transmit: at %ld %s->%s mode %d keyid %08x len %d\n", + DPRINTF(1, ("fast_xmit: at %ld %s->%s mode %d keyid %08x len %lu\n", current_time, ntoa(&rbufp->dstadr->sin), - ntoa(&rbufp->recv_srcadr), xmode, xkeyid, sendlen); -#endif + ntoa(&rbufp->recv_srcadr), xmode, xkeyid, + (u_long)sendlen)); } @@ -3827,11 +3847,8 @@ pool_xmit( LEN_PKT_NOMAC); pool->sent++; pool->throttle += (1 << pool->minpoll) - 2; -#ifdef DEBUG - if (debug) - printf("transmit: at %ld %s->%s pool\n", - current_time, latoa(lcladr), stoa(rmtadr)); -#endif + DPRINTF(1, ("pool_xmit: at %ld %s->%s pool\n", + current_time, latoa(lcladr), stoa(rmtadr))); msyslog(LOG_INFO, "Soliciting pool server %s", stoa(rmtadr)); #endif /* WORKER */ } @@ -3849,7 +3866,8 @@ pool_xmit( * group different 1 ignore * * ignore if notrust */ -int group_test( +int +group_test( char *grp, char *ident ) @@ -3929,11 +3947,8 @@ key_expire( value_free(&peer->sndval); peer->keynumber = 0; peer->flags &= ~FLAG_ASSOC; -#ifdef DEBUG - if (debug) - printf("key_expire: at %lu associd %d\n", current_time, - peer->associd); -#endif + DPRINTF(1, ("key_expire: at %lu associd %d\n", current_time, + peer->associd)); } #endif /* AUTOKEY */ diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index 1f16ca797106..d25cc2c0df15 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -732,9 +732,9 @@ process_refclock_packet( */ int refclock_open( - char *dev, /* device name pointer */ - u_int speed, /* serial port speed (code) */ - u_int lflags /* line discipline flags */ + const char *dev, /* device name pointer */ + u_int speed, /* serial port speed (code) */ + u_int lflags /* line discipline flags */ ) { int fd; diff --git a/ntpd/ntp_request.c b/ntpd/ntp_request.c index 6073f99c456d..fa78ce1e4941 100644 --- a/ntpd/ntp_request.c +++ b/ntpd/ntp_request.c @@ -2006,11 +2006,11 @@ do_trustkey( u_long trust ) { - register u_long *kp; + register uint32_t *kp; register int items; items = INFO_NITEMS(inpkt->err_nitems); - kp = (u_long *)&inpkt->u; + kp = (uint32_t*)&inpkt->u; while (items-- > 0) { authtrust(*kp, trust); kp++; diff --git a/ntpd/ntp_restrict.c b/ntpd/ntp_restrict.c index 82bbaef25741..0b5fa2e3fa0e 100644 --- a/ntpd/ntp_restrict.c +++ b/ntpd/ntp_restrict.c @@ -160,7 +160,7 @@ alloc_res4(void) const size_t count = INC_RESLIST4; restrict_u * rl; restrict_u * res; - int i; + size_t i; UNLINK_HEAD_SLIST(res, resfree4, link); if (res != NULL) @@ -186,7 +186,7 @@ alloc_res6(void) const size_t count = INC_RESLIST6; restrict_u * rl; restrict_u * res; - int i; + size_t i; UNLINK_HEAD_SLIST(res, resfree6, link); if (res != NULL) diff --git a/ntpd/ntp_signd.c b/ntpd/ntp_signd.c index 2ba11d086614..857dcbf61082 100644 --- a/ntpd/ntp_signd.c +++ b/ntpd/ntp_signd.c @@ -66,7 +66,7 @@ write_all(int fd, const void *buf, size_t len) while (len) { int n = write(fd, buf, len); if (n <= 0) return total; - buf = n + (char *)buf; + buf = n + (const char *)buf; len -= n; total += n; } @@ -110,9 +110,10 @@ recv_packet(int fd, char **buf, uint32_t *len) { if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1; *len = ntohl(*len); - (*buf) = emalloc(*len); + *buf = emalloc(*len); if (read_all(fd, *buf, *len) != *len) { free(*buf); + *buf = NULL; return -1; } return 0; diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index 828aa8c273bf..03084a353622 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -626,18 +626,19 @@ check_leapsec( * announce the leap event has happened. */ const char *leapmsg = NULL; - if (lsdata.warped < 0) { + double lswarp = lsdata.warped; + if (lswarp < 0.0) { if (clock_max_back > 0.0 && - clock_max_back < fabs(lsdata.warped)) { - step_systime(lsdata.warped); + clock_max_back < -lswarp) { + step_systime(lswarp); leapmsg = leapmsg_p_step; } else { leapmsg = leapmsg_p_slew; } - } else if (lsdata.warped > 0) { + } else if (lswarp > 0.0) { if (clock_max_fwd > 0.0 && - clock_max_fwd < fabs(lsdata.warped)) { - step_systime(lsdata.warped); + clock_max_fwd < lswarp) { + step_systime(lswarp); leapmsg = leapmsg_n_step; } else { leapmsg = leapmsg_n_slew; diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index c4bc9011a518..3a95819821b5 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -334,7 +334,7 @@ stats_config( { FILE *fp; const char *value; - int len; + size_t len; double old_drift; l_fp now; time_t ttnow; @@ -437,7 +437,7 @@ stats_config( (int)sizeof(statsdir) - 2); } else { int add_dir_sep; - int value_l; + size_t value_l; /* Add a DIR_SEP unless we already have one. */ value_l = strlen(value); @@ -933,7 +933,7 @@ getauthkeys( const char *keyfile ) { - int len; + size_t len; len = strlen(keyfile); if (!len) diff --git a/ntpd/ntpd-opts.c b/ntpd/ntpd-opts.c index 1bbecfa0460d..660884b94b7b 100644 --- a/ntpd/ntpd-opts.c +++ b/ntpd/ntpd-opts.c @@ -1,7 +1,7 @@ /* * EDIT THIS FILE WITH CAUTION (ntpd-opts.c) * - * It has been AutoGen-ed October 21, 2015 at 12:36:00 PM by AutoGen 5.18.5 + * It has been AutoGen-ed January 7, 2016 at 11:28:29 PM by AutoGen 5.18.5 * From the definitions ntpd-opts.def * and the template file options * @@ -75,7 +75,7 @@ extern FILE * option_usage_fp; * static const strings for ntpd options */ static char const ntpd_opt_strs[3129] = -/* 0 */ "ntpd 4.2.8p4\n" +/* 0 */ "ntpd 4.2.8p5\n" "Copyright (C) 1992-2015 The University of Delaware and Network Time Foundation, all rights reserved.\n" "This is free software. It is licensed for use, modification and\n" "redistribution under the terms of the NTP License, copies of which\n" @@ -205,12 +205,12 @@ static char const ntpd_opt_strs[3129] = /* 2900 */ "output version information and exit\0" /* 2936 */ "version\0" /* 2944 */ "NTPD\0" -/* 2949 */ "ntpd - NTP daemon program - Ver. 4.2.8p4\n" +/* 2949 */ "ntpd - NTP daemon program - Ver. 4.2.8p5\n" "Usage: %s [ - [] | --[{=| }] ]... \\\n" "\t\t[ ... ]\n\0" /* 3080 */ "http://bugs.ntp.org, bugs@ntp.org\0" /* 3114 */ "\n\0" -/* 3116 */ "ntpd 4.2.8p4"; +/* 3116 */ "ntpd 4.2.8p5"; /** * ipv4 option description with @@ -1529,7 +1529,7 @@ static void bogus_function(void) { translate option names. */ /* referenced via ntpdOptions.pzCopyright */ - puts(_("ntpd 4.2.8p4\n\ + puts(_("ntpd 4.2.8p5\n\ Copyright (C) 1992-2015 The University of Delaware and Network Time Foundation, all rights reserved.\n\ This is free software. It is licensed for use, modification and\n\ redistribution under the terms of the NTP License, copies of which\n\ @@ -1670,7 +1670,7 @@ implied warranty.\n")); puts(_("output version information and exit")); /* referenced via ntpdOptions.pzUsageTitle */ - puts(_("ntpd - NTP daemon program - Ver. 4.2.8p4\n\ + puts(_("ntpd - NTP daemon program - Ver. 4.2.8p5\n\ Usage: %s [ - [] | --[{=| }] ]... \\\n\ \t\t[ ... ]\n")); @@ -1678,7 +1678,7 @@ Usage: %s [ - [] | --[{=| }] ]... \\\n\ puts(_("\n")); /* referenced via ntpdOptions.pzFullVersion */ - puts(_("ntpd 4.2.8p4")); + puts(_("ntpd 4.2.8p5")); /* referenced via ntpdOptions.pzFullUsage */ puts(_("<<>>")); diff --git a/ntpd/ntpd-opts.h b/ntpd/ntpd-opts.h index d87c2216dcb5..571fd342568e 100644 --- a/ntpd/ntpd-opts.h +++ b/ntpd/ntpd-opts.h @@ -1,7 +1,7 @@ /* * EDIT THIS FILE WITH CAUTION (ntpd-opts.h) * - * It has been AutoGen-ed October 21, 2015 at 12:35:59 PM by AutoGen 5.18.5 + * It has been AutoGen-ed January 7, 2016 at 11:28:28 PM by AutoGen 5.18.5 * From the definitions ntpd-opts.def * and the template file options * @@ -106,9 +106,9 @@ typedef enum { /** count of all options for ntpd */ #define OPTION_CT 38 /** ntpd version */ -#define NTPD_VERSION "4.2.8p4" +#define NTPD_VERSION "4.2.8p5" /** Full ntpd version text */ -#define NTPD_FULL_VERSION "ntpd 4.2.8p4" +#define NTPD_FULL_VERSION "ntpd 4.2.8p5" /** * Interface defines for all options. Replace "n" with the UPPER_CASED diff --git a/ntpd/ntpd.1ntpdman b/ntpd/ntpd.1ntpdman index 187a79a79a08..42d0caf54cbe 100644 --- a/ntpd/ntpd.1ntpdman +++ b/ntpd/ntpd.1ntpdman @@ -10,11 +10,11 @@ .ds B-Font B .ds I-Font I .ds R-Font R -.TH ntpd 1ntpdman "21 Oct 2015" "4.2.8p4" "User Commands" +.TH ntpd 1ntpdman "07 Jan 2016" "4.2.8p5" "User Commands" .\" -.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-dUaOfK/ag-qUaGeK) +.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-KDaWJq/ag-WDaOIq) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:11 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:30:44 PM by AutoGen 5.18.5 .\" From the definitions ntpd-opts.def .\" and the template file agman-cmd.tpl .SH NAME diff --git a/ntpd/ntpd.1ntpdmdoc b/ntpd/ntpd.1ntpdmdoc index 139de527781e..dc06f58a952c 100644 --- a/ntpd/ntpd.1ntpdmdoc +++ b/ntpd/ntpd.1ntpdmdoc @@ -1,9 +1,9 @@ -.Dd October 21 2015 +.Dd January 7 2016 .Dt NTPD 1ntpdmdoc User Commands .Os .\" EDIT THIS FILE WITH CAUTION (ntpd-opts.mdoc) .\" -.\" It has been AutoGen-ed October 21, 2015 at 12:38:30 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed January 7, 2016 at 11:31:02 PM by AutoGen 5.18.5 .\" From the definitions ntpd-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index a517391ba522..7630aee43bda 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -27,12 +27,16 @@ #include "ntp_libopts.h" #include "ntpd-opts.h" -/* there's a short treatise below what the thread stuff is for */ +/* there's a short treatise below what the thread stuff is for. + * [Bug 2954] enable the threading warm-up only for Linux. + */ #if defined(HAVE_PTHREADS) && HAVE_PTHREADS && !defined(NO_THREADS) # ifdef HAVE_PTHREAD_H # include # endif -# define NEED_PTHREAD_WARMUP +# if defined(linux) +# define NEED_PTHREAD_WARMUP +# endif #endif #ifdef HAVE_UNISTD_H @@ -269,6 +273,9 @@ static void library_unexpected_error(const char *, int, * This uses only the standard pthread API and should work with all * implementations of pthreads. It is not necessary everywhere, but it's * cheap enough to go on nearly unnoticed. + * + * Addendum: Bug 2954 showed that the assumption that this should work + * with all OS is wrong -- at least FreeBSD bombs heavily. */ #ifdef NEED_PTHREAD_WARMUP @@ -646,6 +653,9 @@ ntpdmain( # endif # ifdef HAVE_WORKING_FORK + /* make sure the FDs are initialised */ + pipe_fds[0] = -1; + pipe_fds[1] = -1; do { /* 'loop' once */ if (!HAVE_OPT( WAIT_SYNC )) break; diff --git a/ntpd/ntpd.html b/ntpd/ntpd.html index 8d6f9d6ad507..ae3e17ce7a33 100644 --- a/ntpd/ntpd.html +++ b/ntpd/ntpd.html @@ -39,7 +39,7 @@ The program can operate in any of several modes, including client/server, symmetric and broadcast modes, and with both symmetric-key and public-key cryptography. -

This document applies to version 4.2.8p4 of ntpd. +

This document applies to version 4.2.8p5 of ntpd.