MCPcopy Create free account
hub / github.com/F-Stack/f-stack / netisr_load_kvm_proto

Function netisr_load_kvm_proto

tools/netstat/netisr.c:211–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209
210#ifndef FSTACK
211static void
212netisr_load_kvm_proto(void)
213{
214 struct netisr_proto *np_array, *npp;
215 u_int i, protocount;
216 struct sysctl_netisr_proto *snpp;
217 size_t len;
218
219 /*
220 * Kernel compile-time and user compile-time definitions of
221 * NETISR_MAXPROT must match, as we use that to size work arrays.
222 */
223 kread(nl[N_NETISR_MAXPROT].n_value, &maxprot, sizeof(u_int));
224 if (maxprot != NETISR_MAXPROT)
225 xo_errx(-1, "%s: NETISR_MAXPROT mismatch", __func__);
226 len = maxprot * sizeof(*np_array);
227 np_array = malloc(len);
228 if (np_array == NULL)
229 xo_err(-1, "%s: malloc", __func__);
230 if (kread(nl[N_NETISR_PROTO].n_value, np_array, len) != 0)
231 xo_errx(-1, "%s: kread(_netisr_proto)", __func__);
232
233 /*
234 * Size and allocate memory to hold only live protocols.
235 */
236 protocount = 0;
237 for (i = 0; i < maxprot; i++) {
238 if (np_array[i].np_name == NULL)
239 continue;
240 protocount++;
241 }
242 proto_array = calloc(protocount, sizeof(*proto_array));
243 if (proto_array == NULL)
244 err(-1, "malloc");
245 protocount = 0;
246 for (i = 0; i < maxprot; i++) {
247 npp = &np_array[i];
248 if (npp->np_name == NULL)
249 continue;
250 snpp = &proto_array[protocount];
251 snpp->snp_version = sizeof(*snpp);
252 netisr_load_kvm_string((uintptr_t)npp->np_name,
253 snpp->snp_name, sizeof(snpp->snp_name));
254 snpp->snp_proto = i;
255 snpp->snp_qlimit = npp->np_qlimit;
256 snpp->snp_policy = npp->np_policy;
257 snpp->snp_dispatch = npp->np_dispatch;
258 if (npp->np_m2flow != NULL)
259 snpp->snp_flags |= NETISR_SNP_FLAGS_M2FLOW;
260 if (npp->np_m2cpuid != NULL)
261 snpp->snp_flags |= NETISR_SNP_FLAGS_M2CPUID;
262 if (npp->np_drainedcpu != NULL)
263 snpp->snp_flags |= NETISR_SNP_FLAGS_DRAINEDCPU;
264 protocount++;
265 }
266 proto_array_len = protocount;
267 free(np_array);
268}

Callers 1

netisr_statsFunction · 0.85

Calls 7

xo_errxFunction · 0.85
mallocFunction · 0.85
xo_errFunction · 0.85
callocFunction · 0.85
netisr_load_kvm_stringFunction · 0.85
kreadFunction · 0.70
freeFunction · 0.50

Tested by

no test coverage detected