git: 31034044ff27 - main - tcp: cleanup of nits after use of accessor tcp_get_flags

From: Richard Scheffenegger <rscheff_at_FreeBSD.org>
Date: Thu, 19 Dec 2024 15:39:37 UTC
The branch main has been updated by rscheff:

URL: https://cgit.FreeBSD.org/src/commit/?id=31034044ff27443489cb416ca520c07421712f69

commit 31034044ff27443489cb416ca520c07421712f69
Author:     Richard Scheffenegger <rscheff@FreeBSD.org>
AuthorDate: 2024-12-19 13:47:32 +0000
Commit:     Richard Scheffenegger <rscheff@FreeBSD.org>
CommitDate: 2024-12-19 15:37:24 +0000

    tcp: cleanup of nits after use of accessor tcp_get_flags
    
    Remove unneeded th_x2 initalization, use named constants
    instead of magic numbers (fixing one oversight) and add
    some line breaks. Expand one man page slightly.
    
    No functional change intended.
    
    Reviewed By: tuexen, cc
    Sponsored by: NetApp, Inc.
    Differential Revision: https://reviews.freebsd.org/D48065
---
 cddl/lib/libdtrace/tcp.d      |  4 ++--
 sbin/ipf/iplang/iplang_y.y    |  3 ++-
 sbin/ipf/ipsend/ipsend.1      |  2 +-
 sbin/ipf/ipsend/ipsend.c      |  2 +-
 sbin/ipf/ipsend/iptests.c     |  3 +--
 sbin/ipf/ipsend/resend.c      |  2 +-
 sbin/ipf/libipf/ipft_tx.c     | 10 ++++++----
 sbin/ipf/libipf/printpacket.c |  4 ++--
 usr.sbin/ppp/ip.c             |  4 +---
 9 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/cddl/lib/libdtrace/tcp.d b/cddl/lib/libdtrace/tcp.d
index 0df4e16d41d0..8f51675df305 100644
--- a/cddl/lib/libdtrace/tcp.d
+++ b/cddl/lib/libdtrace/tcp.d
@@ -97,7 +97,7 @@ inline uint16_t TH_ECE =	0x40;
 #pragma D binding "1.6.3" TH_CWR
 inline uint16_t TH_CWR =	0x80;
 #pragma D binding "1.6.3" TH_AE
-inline uint16_t TH_AE =		0x100;
+inline uint16_t TH_AE  =	0x100;
 
 /* TCP connection state strings. */
 #pragma D binding "1.6.3" tcp_state_string
@@ -332,7 +332,7 @@ inline string tcpflag_string[uint16_t flags] =
 	flags & TH_URG ?	"URG" :
 	flags & TH_ECE ?	"ECE" :
 	flags & TH_CWR ?	"CWR" :
-	flags & TH_AE ? 	"AE" :
+	flags & TH_AE  ?	"AE" :
 	"unknown" ;
 
 #pragma D binding "1.12.1" PRU_ATTACH
diff --git a/sbin/ipf/iplang/iplang_y.y b/sbin/ipf/iplang/iplang_y.y
index ce55ad277c1a..9e8ebf4e4312 100644
--- a/sbin/ipf/iplang/iplang_y.y
+++ b/sbin/ipf/iplang/iplang_y.y
@@ -1059,7 +1059,8 @@ void set_tcpflags(char **arg)
 			__tcp_set_flags(tcp, strtol(*arg, NULL, 0));
 			break;
 		} else
-			__tcp_set_flags(tcp, __tcp_get_flags(tcp) | flagv[t - flags]);
+			__tcp_set_flags(tcp, __tcp_get_flags(tcp) |
+					flagv[t - flags]);
 	free(*arg);
 	*arg = NULL;
 }
diff --git a/sbin/ipf/ipsend/ipsend.1 b/sbin/ipf/ipsend/ipsend.1
index 57d29ba8569a..3cbb991694b1 100644
--- a/sbin/ipf/ipsend/ipsend.1
+++ b/sbin/ipf/ipsend/ipsend.1
@@ -39,7 +39,7 @@ ipsend \- sends IP packets
 packets to a destination host, using command line options to specify various
 attributes present in the headers.  The \fIdestination\fP must be given as
 the last command line option, except for when TCP flags are specified as
-a combination of A, S, F, U, P and R, last.
+a combination of A, S, F, U, P, R, E, W and e, last.
 .PP
 The other way it may be compiled, with DOSOCKET defined, is to allow an
 attempt at making a TCP connection using a with ipsend resending the SYN
diff --git a/sbin/ipf/ipsend/ipsend.c b/sbin/ipf/ipsend/ipsend.c
index 2e2cf8f36fa2..78a8ccaa3f30 100644
--- a/sbin/ipf/ipsend/ipsend.c
+++ b/sbin/ipf/ipsend/ipsend.c
@@ -399,7 +399,7 @@ main(int argc, char **argv)
 	printf("Source:  %s\n", inet_ntoa(ip->ip_src));
 	printf("Dest:    %s\n", inet_ntoa(ip->ip_dst));
 	printf("Gateway: %s\n", inet_ntoa(gwip));
-	if (ip->ip_p == IPPROTO_TCP && __tcp_get_flags(tcp))
+	if (ip->ip_p == IPPROTO_TCP && __tcp_get_flags(tcp) != 0)
 		printf("Flags:   %#x\n", __tcp_get_flags(tcp));
 	printf("mtu:     %d\n", mtu);
 
diff --git a/sbin/ipf/ipsend/iptests.c b/sbin/ipf/ipsend/iptests.c
index eb8001b579d8..6f95970a83aa 100644
--- a/sbin/ipf/ipsend/iptests.c
+++ b/sbin/ipf/ipsend/iptests.c
@@ -903,7 +903,6 @@ ip_test5(char *dev, int mtu, ip_t *ip, struct  in_addr gwip, int ptest)
 	int	nfd, i;
 
 	t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2));
-	t->th_x2 = 0;
 	TCP_OFF_A(t, 0);
 	t->th_sport = htons(1);
 	t->th_dport = htons(1);
@@ -920,7 +919,7 @@ ip_test5(char *dev, int mtu, ip_t *ip, struct  in_addr gwip, int ptest)
 
 	if (!ptest || (ptest == 1)) {
 		/*
-		 * Test 1: flags variations, 0 - 3f
+		 * Test 1: flags variations, 0 - 1ff
 		 */
 		TCP_OFF_A(t, sizeof(*t) >> 2);
 		printf("5.1 Test TCP flag combinations\n");
diff --git a/sbin/ipf/ipsend/resend.c b/sbin/ipf/ipsend/resend.c
index bbecf46e51c0..a306edddff19 100644
--- a/sbin/ipf/ipsend/resend.c
+++ b/sbin/ipf/ipsend/resend.c
@@ -50,7 +50,7 @@ dumppacket(ip_t *ip)
 	if (ip->ip_p == IPPROTO_TCP) {
 		printf(" seq %lu:%lu flags ",
 			(u_long)t->th_seq, (u_long)t->th_ack);
-		for (j = 0, i = 1; i < 256; i *= 2, j++)
+		for (j = 0, i = 1; i < TH_FLAGS; i <<= 1, j++)
 			if (__tcp_get_flags(t) & i)
 				printf("%c", "FSRPAUEWe"[j]);
 	}
diff --git a/sbin/ipf/libipf/ipft_tx.c b/sbin/ipf/libipf/ipft_tx.c
index 87e0fcb449d2..1e23f06be3fd 100644
--- a/sbin/ipf/libipf/ipft_tx.c
+++ b/sbin/ipf/libipf/ipft_tx.c
@@ -267,8 +267,9 @@ parseline(char *line, ip_t *ip, char **ifn, int *out)
 
 			__tcp_set_flags(tcp, 0);
 			for (s = *cpp; *s; s++)
-				if ((t  = strchr(myflagset, *s)))
-					__tcp_set_flags(tcp, __tcp_get_flags(tcp) | myflags[t-myflagset]);
+				if ((t = strchr(myflagset, *s)))
+					__tcp_set_flags(tcp, __tcp_get_flags(tcp) |
+							myflags[t-myflagset]);
 			if (__tcp_get_flags(tcp))
 				cpp++;
 		}
@@ -438,8 +439,9 @@ parseipv6(char **cpp, ip6_t *ip6, char **ifn, int *out)
 
 			__tcp_set_flags(tcp, 0);
 			for (s = *cpp; *s; s++)
-				if ((t  = strchr(myflagset, *s)))
-					__tcp_set_flags(tcp, __tcp_get_flags(tcp) | myflags[t-myflagset]);
+				if ((t = strchr(myflagset, *s)))
+					__tcp_set_flags(tcp, __tcp_get_flags(tcp) |
+							myflags[t-myflagset]);
 			if (__tcp_get_flags(tcp))
 				cpp++;
 		}
diff --git a/sbin/ipf/libipf/printpacket.c b/sbin/ipf/libipf/printpacket.c
index 5d1d79bb4bb9..f8407c3a3102 100644
--- a/sbin/ipf/libipf/printpacket.c
+++ b/sbin/ipf/libipf/printpacket.c
@@ -13,7 +13,6 @@
 # define	IP_OFFMASK	0x3fff
 #endif
 
-
 void
 printpacket(int dir, mb_t *m)
 {
@@ -83,7 +82,8 @@ printpacket(int dir, mb_t *m)
 	if (!(off & IP_OFFMASK)) {
 		if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
 			PRINTF(",%d", ntohs(tcp->th_dport));
-		if ((ip->ip_p == IPPROTO_TCP) && ((tcpflags = __tcp_get_flags(tcp)) != 0)) {
+		if ((ip->ip_p == IPPROTO_TCP) &&
+		    ((tcpflags = __tcp_get_flags(tcp)) != 0)) {
 			putchar(' ');
 			if (tcpflags & TH_FIN)
 				putchar('F');
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index b4c38f1933e5..aea1a812e2ea 100644
--- a/usr.sbin/ppp/ip.c
+++ b/usr.sbin/ppp/ip.c
@@ -829,13 +829,11 @@ PacketCheck(struct bundle *bundle, u_int32_t family,
       snprintf(logbuf + loglen, sizeof logbuf - loglen,
                "%s:%d", ncpaddr_ntoa(&dstaddr), ntohs(th->th_dport));
       loglen += strlen(logbuf + loglen);
-      n = 0;
-      for (mask = TH_FIN; mask <= TH_FLAGS; mask <<= 1) {
+      for (mask = TH_FIN, n = 0; mask <= TH_FLAGS; mask <<= 1, n++) {
         if (__tcp_get_flags(th) & mask) {
           snprintf(logbuf + loglen, sizeof logbuf - loglen, " %s", TcpFlags[n]);
           loglen += strlen(logbuf + loglen);
         }
-        n++;
       }
       snprintf(logbuf + loglen, sizeof logbuf - loglen,
                "  seq:%lx  ack:%lx (%d/%d)",