Bug Summary

File:netinet/tcp_debug.c
Warning:line 163, column 4
Value stored to 'th' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name tcp_debug.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -D CONFIG_DRM_AMD_DC_DCN3_0 -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /usr/obj/sys/arch/amd64/compile/GENERIC.MP/scan-build/2022-01-12-131800-47421-1 -x c /usr/src/sys/netinet/tcp_debug.c
1/* $OpenBSD: tcp_debug.c,v 1.29 2019/04/05 14:42:06 bluhm Exp $ */
2/* $NetBSD: tcp_debug.c,v 1.10 1996/02/13 23:43:36 christos Exp $ */
3
4/*
5 * Copyright (c) 1982, 1986, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
33 *
34 * NRL grants permission for redistribution and use in source and binary
35 * forms, with or without modification, of the software and documentation
36 * created at NRL provided that the following conditions are met:
37 *
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgements:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * This product includes software developed at the Information
48 * Technology Division, US Naval Research Laboratory.
49 * 4. Neither the name of the NRL nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
54 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
56 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR
57 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *
65 * The views and conclusions contained in the software and documentation
66 * are those of the authors and should not be interpreted as representing
67 * official policies, either expressed or implied, of the US Naval
68 * Research Laboratory (NRL).
69 */
70
71#ifdef TCPDEBUG
72/* load symbolic names */
73#define PRUREQUESTS
74#define TCPSTATES
75#define TCPTIMERS
76#define TANAMES
77#endif
78
79#include <sys/param.h>
80#include <sys/systm.h>
81#include <sys/mbuf.h>
82#include <sys/socket.h>
83#include <sys/protosw.h>
84
85#include <net/route.h>
86
87#include <netinet/in.h>
88#include <netinet/in_systm.h>
89#include <netinet/ip.h>
90#include <netinet/in_pcb.h>
91#include <netinet/ip_var.h>
92#include <netinet/tcp.h>
93#include <netinet/tcp_timer.h>
94#include <netinet/tcp_var.h>
95#include <netinet/tcp_debug.h>
96#include <netinet/tcp_fsm.h>
97
98#ifdef INET61
99#include <netinet/ip6.h>
100#endif /* INET6 */
101
102#ifdef TCPDEBUG
103int tcpconsdebug = 0;
104#endif
105
106struct tcp_debug tcp_debug[TCP_NDEBUG100];
107int tcp_debx;
108
109/*
110 * Tcp debug routines
111 */
112void
113tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp,
114 caddr_t headers, int req, int len)
115{
116#ifdef TCPDEBUG
117 tcp_seq seq, ack;
118 int flags;
119#endif
120 int pf = PF_UNSPEC0;
121 struct tcp_debug *td = &tcp_debug[tcp_debx++];
122 struct tcpiphdr *ti = (struct tcpiphdr *)headers;
123 struct tcpipv6hdr *ti6 = (struct tcpipv6hdr *)headers;
124 struct tcphdr *th;
125
126 if (tcp_debx == TCP_NDEBUG100)
127 tcp_debx = 0;
128 td->td_time = iptime();
129 td->td_act = act;
130 td->td_ostate = ostate;
131 td->td_tcb = (caddr_t)otp;
132 if (tp) {
133 pf = tp->pf;
134 td->td_cb = *tp;
135 } else
136 bzero((caddr_t)&td->td_cb, sizeof (*tp))__builtin_bzero(((caddr_t)&td->td_cb), (sizeof (*tp)));
137
138 bzero(&td->td_ti6, sizeof(struct tcpipv6hdr))__builtin_bzero((&td->td_ti6), (sizeof(struct tcpipv6hdr
)))
;
139 bzero(&td->td_ti, sizeof(struct tcpiphdr))__builtin_bzero((&td->td_ti), (sizeof(struct tcpiphdr)
))
;
140 if (headers) {
141 /* The address family may be in tcpcb or ip header. */
142 if (pf == PF_UNSPEC0) {
143 switch (ti6->ti6_i.ip6_vfcip6_ctlun.ip6_un2_vfc & IPV6_VERSION_MASK0xf0) {
144#ifdef INET61
145 case IPV6_VERSION0x60:
146 pf = PF_INET624;
147 break;
148#endif /* INET6 */
149 case IPVERSION4:
150 pf = PF_INET2;
151 break;
152 }
153 }
154 switch (pf) {
155#ifdef INET61
156 case PF_INET624:
157 th = &ti6->ti6_t;
158 td->td_ti6 = *ti6;
159 td->td_ti6.ti6_plenti6_i.ip6_ctlun.ip6_un1.ip6_un1_plen = len;
160 break;
161#endif /* INET6 */
162 case PF_INET2:
163 th = &ti->ti_t;
Value stored to 'th' is never read
164 td->td_ti = *ti;
165 td->td_ti.ti_lenti_i.ih_len = len;
166 break;
167 default:
168 headers = NULL((void *)0);
169 break;
170 }
171 }
172
173 td->td_req = req;
174#ifdef TCPDEBUG
175 if (tcpconsdebug == 0)
176 return;
177 if (otp)
178 printf("%p %s:", otp, tcpstates[ostate]);
179 else
180 printf("???????? ");
181 printf("%s ", tanames[act]);
182 switch (act) {
183
184 case TA_INPUT0:
185 case TA_OUTPUT1:
186 case TA_DROP4:
187 if (headers == NULL((void *)0))
188 break;
189 seq = th->th_seq;
190 ack = th->th_ack;
191 if (act == TA_OUTPUT1) {
192 seq = ntohl(seq)(__uint32_t)(__builtin_constant_p(seq) ? (__uint32_t)(((__uint32_t
)(seq) & 0xff) << 24 | ((__uint32_t)(seq) & 0xff00
) << 8 | ((__uint32_t)(seq) & 0xff0000) >> 8 |
((__uint32_t)(seq) & 0xff000000) >> 24) : __swap32md
(seq))
;
193 ack = ntohl(ack)(__uint32_t)(__builtin_constant_p(ack) ? (__uint32_t)(((__uint32_t
)(ack) & 0xff) << 24 | ((__uint32_t)(ack) & 0xff00
) << 8 | ((__uint32_t)(ack) & 0xff0000) >> 8 |
((__uint32_t)(ack) & 0xff000000) >> 24) : __swap32md
(ack))
;
194 }
195 if (len)
196 printf("[%x..%x)", seq, seq+len);
197 else
198 printf("%x", seq);
199 printf("@%x, urp=%x", ack, th->th_urp);
200 flags = th->th_flags;
201 if (flags) {
202 char *cp = "<";
203#define pf(f) { if (th->th_flags&TH_##f) { printf("%s%s", cp, #f); cp = ","; } }
204 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
205 printf(">");
206 }
207 break;
208
209 case TA_USER2:
210 printf("%s", prurequests[req]);
211 break;
212
213 case TA_TIMER5:
214 printf("%s", tcptimers[req]);
215 break;
216 }
217 if (tp)
218 printf(" -> %s", tcpstates[tp->t_state]);
219 /* print out internal state of tp !?! */
220 printf("\n");
221 if (tp == NULL((void *)0))
222 return;
223 printf("\trcv_(nxt,wnd,up) (%x,%lx,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
224 tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
225 tp->snd_max);
226 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%lx)\n",
227 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
228#endif /* TCPDEBUG */
229}