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
This commit is contained in:
Richard Scheffenegger 2024-12-19 14:47:32 +01:00
parent 38663adb61
commit 31034044ff
9 changed files with 17 additions and 17 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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);

View file

@ -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");

View file

@ -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]);
}

View file

@ -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++;
}

View file

@ -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');

View file

@ -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)",