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

Function sysctl_ifdata

freebsd/net/if_mib.c:76–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74 "Number of configured interfaces");
75
76static int
77sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */
78{
79 int *name = (int *)arg1;
80 int error;
81 u_int namelen = arg2;
82 struct ifnet *ifp;
83 struct ifmibdata ifmd;
84 struct epoch_tracker et;
85 size_t dlen;
86 char *dbuf;
87
88 if (namelen != 2)
89 return EINVAL;
90 if (name[0] <= 0)
91 return (ENOENT);
92 NET_EPOCH_ENTER(et);
93 ifp = ifnet_byindex_ref(name[0]);
94 NET_EPOCH_EXIT(et);
95 if (ifp == NULL)
96 return (ENOENT);
97
98 switch(name[1]) {
99 default:
100 error = ENOENT;
101 goto out;
102
103 case IFDATA_GENERAL:
104 bzero(&ifmd, sizeof(ifmd));
105 strlcpy(ifmd.ifmd_name, ifp->if_xname, sizeof(ifmd.ifmd_name));
106
107 ifmd.ifmd_pcount = ifp->if_pcount;
108 if_data_copy(ifp, &ifmd.ifmd_data);
109
110 ifmd.ifmd_flags = ifp->if_flags | ifp->if_drv_flags;
111 ifmd.ifmd_snd_len = ifp->if_snd.ifq_len;
112 ifmd.ifmd_snd_maxlen = ifp->if_snd.ifq_maxlen;
113 ifmd.ifmd_snd_drops =
114 ifp->if_get_counter(ifp, IFCOUNTER_OQDROPS);
115
116 error = SYSCTL_OUT(req, &ifmd, sizeof ifmd);
117 if (error)
118 goto out;
119 break;
120
121 case IFDATA_LINKSPECIFIC:
122 error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen);
123 if (error || !req->newptr)
124 goto out;
125 break;
126
127 case IFDATA_DRIVERNAME:
128 /* 20 is enough for 64bit ints */
129 dlen = strlen(ifp->if_dname) + 20 + 1;
130 if ((dbuf = malloc(dlen, M_TEMP, M_NOWAIT)) == NULL) {
131 error = ENOMEM;
132 goto out;
133 }

Callers

nothing calls this directly

Calls 8

ifnet_byindex_refFunction · 0.85
bzeroFunction · 0.85
if_data_copyFunction · 0.85
mallocFunction · 0.85
sprintfFunction · 0.85
if_releFunction · 0.85
strlcpyFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected