[Git][NTPsec/ntpsec][master] Eliminate more grotty macros.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Jan 2 17:00:41 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
c98030e9 by Eric S. Raymond at 2017-01-02T12:00:34-05:00
Eliminate more grotty macros.

- - - - -


3 changed files:

- include/ntp_fp.h
- ntpd/ntp_peer.c
- ntpd/ntp_proto.c


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -95,23 +95,19 @@ typedef uint32_t u_fp;
 #define	HTONS_FP(x)	(htonl(x))
 #define	NTOHS_FP(x)	(ntohl(x))
 
-#define	NTOHL_MFP(ni, nf, hi, hf)				\
-	do {							\
-		(hi) = ntohl(ni);				\
-		(hf) = ntohl(nf);				\
-	} while (false)
-
-#define	HTONL_MFP(hi, hf, ni, nf)				\
-	do {							\
-		(ni) = htonl(hi);				\
-		(nf) = htonl(hf);				\
-	} while (false)
-
-#define HTONL_FP(h, n)						\
-	HTONL_MFP(lfpuint(*h), lfpfrac(*h), lfpuint(*n), lfpfrac(*n))
+static inline l_fp htonl_fp(l_fp lfp) {
+    extern uint32_t htonl(uint32_t hostlong);
+    setlfpuint(lfp, htonl(lfpuint(lfp)));
+    setlfpfrac(lfp, htonl(lfpfrac(lfp)));
+    return lfp;
+}
 
-#define NTOHL_FP(n, h)						\
-	NTOHL_MFP(lfpuint(*n), lfpfrac(*n), lfpuint(*h), lfpfrac(*h))
+static inline l_fp ntohl_fp(l_fp lfp) {
+    extern uint32_t ntohl(uint32_t hostlong);
+    setlfpuint(lfp, ntohl(lfpuint(lfp)));
+    setlfpfrac(lfp, ntohl(lfpfrac(lfp)));
+    return lfp;
+}
 
 /* Convert unsigned ts fraction to net order ts */
 #define	HTONL_UF(uf, nts)					\


=====================================
ntpd/ntp_peer.c
=====================================
--- a/ntpd/ntp_peer.c
+++ b/ntpd/ntp_peer.c
@@ -305,7 +305,7 @@ findpeer(
                  */
                 if (MODE_SERVER == pkt_mode && AM_PROCPKT == *action) {
                         pkt = &rbufp->recv_pkt;
-                        NTOHL_FP(&pkt->org, &pkt_org);
+                        pkt_org = ntohl_fp(pkt->org);
                         if (!L_ISEQU(&p->org, &pkt_org) &&
                             findmanycastpeer(rbufp))
                                 *action = AM_ERR;
@@ -858,7 +858,7 @@ findmanycastpeer(
 	pkt = &rbufp->recv_pkt;
 	for (peer = peer_list; peer != NULL; peer = peer->p_link)
 		if (MDF_SOLICIT_MASK & peer->cast_flags) {
-			NTOHL_FP(&pkt->org, &p_org);
+			p_org = ntohl_fp(pkt->org);
 			if (L_ISEQU(&p_org, &peer->org))
 				break;
 		}


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -2136,9 +2136,9 @@ peer_xmit(
 	xpkt.refid = sys_refid;
 	xpkt.rootdelay = HTONS_FP(DTOFP(sys_rootdelay));
 	xpkt.rootdisp =	 HTONS_FP(DTOUFP(sys_rootdisp));
-	HTONL_FP(&sys_reftime, &xpkt.reftime);
-	HTONL_FP(&peer->rec, &xpkt.org);
-	HTONL_FP(&peer->dst, &xpkt.rec);
+	xpkt.reftime = htonl_fp(sys_reftime);
+	xpkt.org = htonl_fp(peer->rec);
+	xpkt.rec = htonl_fp(peer->dst);
 
 	/*
 	 * If the received packet contains a MAC, the transmitted packet
@@ -2153,7 +2153,7 @@ peer_xmit(
 		 */
 		get_systime(&xmt_tx);
 		peer->org = xmt_tx;
-		HTONL_FP(&xmt_tx, &xpkt.xmt);
+		xpkt.xmt = htonl_fp(xmt_tx);
 		peer->t21_bytes = sendlen;
 		sendpkt(&peer->srcadr, peer->dstadr, sys_ttl[peer->ttl],
 		    &xpkt, sendlen);
@@ -2181,7 +2181,7 @@ peer_xmit(
 	 */
 	get_systime(&xmt_tx);
 	peer->org = xmt_tx;
-	HTONL_FP(&xmt_tx, &xpkt.xmt);
+	xpkt.xmt = htonl_fp(xmt_tx);
 	xkeyid = peer->keyid;
 	authlen = authencrypt(xkeyid, (uint32_t *)&xpkt, sendlen);
 	if (authlen == 0) {
@@ -2308,9 +2308,9 @@ fast_xmit(
 				lfptoa(&leap_smear.offset, 8)
 				));
 		}
-		HTONL_FP(&this_ref_time, &xpkt.reftime);
+		xpkt.reftime = htonl_fp(this_ref_time);
 #else
-		HTONL_FP(&sys_reftime, &xpkt.reftime);
+		xpkt.reftime = htonl_fp(sys_reftime);
 #endif
 
 		xpkt.org = rpkt->xmt;
@@ -2319,9 +2319,9 @@ fast_xmit(
 		this_recv_time = rbufp->recv_time;
 		if (leap_smear.in_progress)
 			leap_smear_add_offs(&this_recv_time, NULL);
-		HTONL_FP(&this_recv_time, &xpkt.rec);
+		xpkt.rec = htonl_fp(this_recv_time);
 #else
-		HTONL_FP(&rbufp->recv_time, &xpkt.rec);
+		xpkt.rec = htonl_fp(rbufp->recv_time);
 #endif
 
 		get_systime(&xmt_tx);
@@ -2329,7 +2329,7 @@ fast_xmit(
 		if (leap_smear.in_progress)
 			leap_smear_add_offs(&xmt_tx, &this_recv_time);
 #endif
-		HTONL_FP(&xmt_tx, &xpkt.xmt);
+		xpkt.xmt = htonl_fp(xmt_tx);
 	}
 
 #ifdef ENABLE_MSSNTP
@@ -2448,10 +2448,10 @@ pool_xmit(
 	xpkt.refid = sys_refid;
 	xpkt.rootdelay = HTONS_FP(DTOFP(sys_rootdelay));
 	xpkt.rootdisp = HTONS_FP(DTOUFP(sys_rootdisp));
-	HTONL_FP(&sys_reftime, &xpkt.reftime);
+	xpkt.reftime = htonl_fp(sys_reftime);
 	get_systime(&xmt_tx);
 	pool->org = xmt_tx;
-	HTONL_FP(&xmt_tx, &xpkt.xmt);
+	xpkt.xmt = htonl_fp(xmt_tx);
 	sendpkt(rmtadr, lcladr, sys_ttl[pool->ttl], &xpkt, LEN_PKT_NOMAC);
 	pool->sent++;
 	pool->throttle += (1 << pool->minpoll) - 2;



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/c98030e935a33a4b0e1b6a39fa209c336f5621aa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170102/c322a405/attachment.html>


More information about the vc mailing list