Bug Summary

File:net/if_pair.c
Warning:line 143, column 21
Value stored to 'dstsc' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name if_pair.c -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 -ffp-contract=on -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 -target-feature +retpoline-external-thunk -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/llvm16/lib/clang/16 -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/legacy-dpm -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc -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/swsmu/smu13 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/inc -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/pm/swsmu/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc/pmfw_if -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 SUSPEND -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 -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 -fcf-protection=branch -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 /home/ben/Projects/scan/2024-01-11-110808-61670-1 -x c /usr/src/sys/net/if_pair.c
1/* $OpenBSD: if_pair.c,v 1.17 2021/01/13 01:57:31 kn Exp $ */
2
3/*
4 * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
5 * Copyright (c) 2009 Theo de Raadt <deraadt@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include <sys/param.h>
21#include <sys/systm.h>
22#include <sys/mbuf.h>
23#include <sys/socket.h>
24#include <sys/sockio.h>
25#include <sys/ioctl.h>
26
27#include <net/if.h>
28#include <net/if_media.h>
29
30#include <netinet/in.h>
31#include <netinet/if_ether.h>
32
33#include "bpfilter.h"
34#if NBPFILTER1 > 0
35#include <net/bpf.h>
36#endif
37
38void pairattach(int);
39int pairioctl(struct ifnet *, u_long, caddr_t);
40void pairstart(struct ifqueue *);
41int pair_clone_create(struct if_clone *, int);
42int pair_clone_destroy(struct ifnet *);
43int pair_media_change(struct ifnet *);
44void pair_media_status(struct ifnet *, struct ifmediareq *);
45void pair_link_state(struct ifnet *);
46
47struct pair_softc {
48 struct arpcom sc_ac;
49 struct ifmedia sc_media;
50 unsigned int sc_pairedif;
51};
52
53struct if_clone pair_cloner =
54 IF_CLONE_INITIALIZER("pair", pair_clone_create, pair_clone_destroy){ .ifc_list = { ((void *)0), ((void *)0) }, .ifc_name = "pair"
, .ifc_namelen = sizeof("pair") - 1, .ifc_create = pair_clone_create
, .ifc_destroy = pair_clone_destroy, }
;
55
56int
57pair_media_change(struct ifnet *ifp)
58{
59 return (0);
60}
61
62void
63pair_media_status(struct ifnet *ifp, struct ifmediareq *imr)
64{
65 struct pair_softc *sc = ifp->if_softc;
66 struct ifnet *pairedifp;
67
68 imr->ifm_active = IFM_ETHER0x0000000000000100ULL | IFM_AUTO0ULL;
69
70 if ((pairedifp = if_get(sc->sc_pairedif)) == NULL((void *)0)) {
71 imr->ifm_status = 0;
72 return;
73 }
74 if_put(pairedifp);
75
76 imr->ifm_status = IFM_AVALID0x0000000000000001ULL | IFM_ACTIVE0x0000000000000002ULL;
77}
78
79void
80pair_link_state(struct ifnet *ifp)
81{
82 struct pair_softc *sc = ifp->if_softc;
83 struct ifnet *pairedifp;
84 unsigned int link_state;
85
86 /* The pair state is determined by the paired interface */
87 if ((pairedifp = if_get(sc->sc_pairedif)) != NULL((void *)0)) {
88 link_state = LINK_STATE_UP4;
89 if_put(pairedifp);
90 } else
91 link_state = LINK_STATE_DOWN2;
92
93 if (ifp->if_link_stateif_data.ifi_link_state != link_state) {
94 ifp->if_link_stateif_data.ifi_link_state = link_state;
95 if_link_state_change(ifp);
96 }
97}
98
99void
100pairattach(int npair)
101{
102 if_clone_attach(&pair_cloner);
103}
104
105int
106pair_clone_create(struct if_clone *ifc, int unit)
107{
108 struct ifnet *ifp;
109 struct pair_softc *sc;
110
111 sc = malloc(sizeof(*sc), M_DEVBUF2, M_WAITOK0x0001|M_ZERO0x0008);
112 ifp = &sc->sc_ac.ac_if;
113 snprintf(ifp->if_xname, sizeof ifp->if_xname, "pair%d", unit);
114 ifp->if_flags = IFF_BROADCAST0x2 | IFF_SIMPLEX0x800 | IFF_MULTICAST0x8000;
115 ether_fakeaddr(ifp);
116
117 ifp->if_softc = sc;
118 ifp->if_ioctl = pairioctl;
119 ifp->if_qstart = pairstart;
120 ifp->if_xflags = IFXF_CLONED0x2 | IFXF_MPSAFE0x1;
121
122 ifp->if_hardmtu = ETHER_MAX_HARDMTU_LEN65435;
123 ifp->if_capabilitiesif_data.ifi_capabilities = IFCAP_VLAN_MTU0x00000010;
124
125 ifmedia_init(&sc->sc_media, 0, pair_media_change,
126 pair_media_status);
127 ifmedia_add(&sc->sc_media, IFM_ETHER0x0000000000000100ULL | IFM_AUTO0ULL, 0, NULL((void *)0));
128 ifmedia_set(&sc->sc_media, IFM_ETHER0x0000000000000100ULL | IFM_AUTO0ULL);
129
130 if_attach(ifp);
131 ether_ifattach(ifp);
132
133 pair_link_state(ifp);
134
135 return (0);
136}
137
138int
139pair_clone_destroy(struct ifnet *ifp)
140{
141 struct pair_softc *sc = ifp->if_softc;
142 struct ifnet *pairedifp;
143 struct pair_softc *dstsc = ifp->if_softc;
Value stored to 'dstsc' during its initialization is never read
144
145 if ((pairedifp = if_get(sc->sc_pairedif)) != NULL((void *)0)) {
146 dstsc = pairedifp->if_softc;
147 dstsc->sc_pairedif = 0;
148 pair_link_state(pairedifp);
149 if_put(pairedifp);
150 }
151
152 ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY((uint64_t) -1));
153 ether_ifdetach(ifp);
154 if_detach(ifp);
155 free(sc, M_DEVBUF2, sizeof(*sc));
156
157 return (0);
158}
159
160void
161pairstart(struct ifqueue *ifq)
162{
163 struct ifnet *ifp = ifq->ifq_if;
164 struct pair_softc *sc = (struct pair_softc *)ifp->if_softc;
165 struct mbuf_list ml = MBUF_LIST_INITIALIZER(){ ((void *)0), ((void *)0), 0 };
166 struct ifnet *pairedifp;
167 struct mbuf *m;
168
169 pairedifp = if_get(sc->sc_pairedif);
170
171 while ((m = ifq_dequeue(ifq)) != NULL((void *)0)) {
172#if NBPFILTER1 > 0
173 if (ifp->if_bpf)
174 bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT(1 << 1));
175#endif /* NBPFILTER > 0 */
176
177 if (pairedifp != NULL((void *)0)) {
178 if (m->m_flagsm_hdr.mh_flags & M_PKTHDR0x0002)
179 m_resethdr(m);
180 ml_enqueue(&ml, m);
181 } else
182 m_freem(m);
183 }
184
185 if (pairedifp != NULL((void *)0)) {
186 if_input(pairedifp, &ml);
187 if_put(pairedifp);
188 }
189}
190
191int
192pairioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
193{
194 struct pair_softc *sc = (struct pair_softc *)ifp->if_softc;
195 struct ifreq *ifr = (struct ifreq *)data;
196 struct if_clone *ifc;
197 struct pair_softc *pairedsc = ifp->if_softc;
198 struct ifnet *oldifp = NULL((void *)0), *newifp = NULL((void *)0);
199 int error = 0, unit;
200
201 switch (cmd) {
202 case SIOCSIFADDR((unsigned long)0x80000000 | ((sizeof(struct ifreq) & 0x1fff
) << 16) | ((('i')) << 8) | ((12)))
:
203 ifp->if_flags |= IFF_UP0x1;
204 /* FALLTHROUGH */
205
206 case SIOCSIFFLAGS((unsigned long)0x80000000 | ((sizeof(struct ifreq) & 0x1fff
) << 16) | ((('i')) << 8) | ((16)))
:
207 if (ifp->if_flags & IFF_UP0x1)
208 ifp->if_flags |= IFF_RUNNING0x40;
209 else
210 ifp->if_flags &= ~IFF_RUNNING0x40;
211 break;
212
213 case SIOCADDMULTI((unsigned long)0x80000000 | ((sizeof(struct ifreq) & 0x1fff
) << 16) | ((('i')) << 8) | ((49)))
:
214 case SIOCDELMULTI((unsigned long)0x80000000 | ((sizeof(struct ifreq) & 0x1fff
) << 16) | ((('i')) << 8) | ((50)))
:
215 break;
216
217 case SIOCGIFMEDIA(((unsigned long)0x80000000|(unsigned long)0x40000000) | ((sizeof
(struct ifmediareq) & 0x1fff) << 16) | ((('i')) <<
8) | ((56)))
:
218 case SIOCSIFMEDIA(((unsigned long)0x80000000|(unsigned long)0x40000000) | ((sizeof
(struct ifreq) & 0x1fff) << 16) | ((('i')) <<
8) | ((55)))
:
219 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
220 break;
221
222 case SIOCSIFPAIR((unsigned long)0x80000000 | ((sizeof(struct ifreq) & 0x1fff
) << 16) | ((('i')) << 8) | ((176)))
:
223 if (sc->sc_pairedif == ifr->ifr_indexifr_ifru.ifru_index)
224 break;
225
226 /* Cannot link to myself */
227 if (ifr->ifr_indexifr_ifru.ifru_index == ifp->if_index) {
228 error = EINVAL22;
229 break;
230 }
231
232 oldifp = if_get(sc->sc_pairedif);
233 newifp = if_get(ifr->ifr_indexifr_ifru.ifru_index);
234
235 if (newifp != NULL((void *)0)) {
236 pairedsc = newifp->if_softc;
237
238 if (pairedsc->sc_pairedif != 0) {
239 error = EBUSY16;
240 break;
241 }
242
243 /* Only allow pair(4) interfaces for the pair */
244 if ((ifc = if_clone_lookup(newifp->if_xname,
245 &unit)) == NULL((void *)0) || strcmp("pair",
246 ifc->ifc_name) != 0) {
247 error = ENODEV19;
248 break;
249 }
250
251 pairedsc->sc_pairedif = ifp->if_index;
252 sc->sc_pairedif = ifr->ifr_indexifr_ifru.ifru_index;
253 } else
254 sc->sc_pairedif = 0;
255
256 if (oldifp != NULL((void *)0)) {
257 pairedsc = oldifp->if_softc;
258 pairedsc->sc_pairedif = 0;
259 }
260 break;
261
262 case SIOCGIFPAIR(((unsigned long)0x80000000|(unsigned long)0x40000000) | ((sizeof
(struct ifreq) & 0x1fff) << 16) | ((('i')) <<
8) | ((177)))
:
263 ifr->ifr_indexifr_ifru.ifru_index = sc->sc_pairedif;
264 break;
265
266 default:
267 error = ether_ioctl(ifp, &sc->sc_ac, cmd, data);
268 }
269
270 if (newifp != NULL((void *)0) || oldifp != NULL((void *)0))
271 pair_link_state(ifp);
272 if (oldifp != NULL((void *)0)) {
273 pair_link_state(oldifp);
274 if_put(oldifp);
275 }
276 if (newifp != NULL((void *)0)) {
277 pair_link_state(newifp);
278 if_put(newifp);
279 }
280
281 return (error);
282}