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

Function ngh_rcvmsg

freebsd/netgraph/ng_hole.c:145–199  ·  view source on GitHub ↗

* Receive a control message. */

Source from the content-addressed store, hash-verified

143 * Receive a control message.
144 */
145static int
146ngh_rcvmsg(node_p node, item_p item, hook_p lasthook)
147{
148 struct ng_mesg *msg;
149 struct ng_mesg *resp = NULL;
150 int error = 0;
151 struct ng_hole_hookstat *stats;
152 hook_p hook;
153
154 NGI_GET_MSG(item, msg);
155 switch (msg->header.typecookie) {
156 case NGM_HOLE_COOKIE:
157 switch (msg->header.cmd) {
158 case NGM_HOLE_GET_STATS:
159 case NGM_HOLE_CLR_STATS:
160 case NGM_HOLE_GETCLR_STATS:
161 /* Sanity check. */
162 if (msg->header.arglen != NG_HOOKSIZ) {
163 error = EINVAL;
164 break;
165 }
166 /* Find hook. */
167 hook = ng_findhook(node, (char *)msg->data);
168 if (hook == NULL) {
169 error = ENOENT;
170 break;
171 }
172 stats = &((hinfo_p)NG_HOOK_PRIVATE(hook))->stats;
173 /* Build response (if desired). */
174 if (msg->header.cmd != NGM_HOLE_CLR_STATS) {
175 NG_MKRESPONSE(resp, msg, sizeof(*stats),
176 M_NOWAIT);
177 if (resp == NULL) {
178 error = ENOMEM;
179 break;
180 }
181 bcopy(stats, resp->data, sizeof(*stats));
182 }
183 /* Clear stats (if desired). */
184 if (msg->header.cmd != NGM_HOLE_GET_STATS)
185 bzero(stats, sizeof(*stats));
186 break;
187 default: /* Unknown command. */
188 error = EINVAL;
189 break;
190 }
191 break;
192 default: /* Unknown type cookie. */
193 error = EINVAL;
194 break;
195 }
196 NG_RESPOND_MSG(error, node, item, resp);
197 NG_FREE_MSG(msg);
198 return (error);
199}
200
201/*
202 * Receive data

Callers

nothing calls this directly

Calls 2

bzeroFunction · 0.85
ng_findhookFunction · 0.70

Tested by

no test coverage detected