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

Function ng_etf_rcvmsg

freebsd/netgraph/ng_etf.c:246–346  ·  view source on GitHub ↗

* Get a netgraph control message. * We actually receive a queue item that has a pointer to the message. * If we free the item, the message will be freed too, unless we remove * it from the item using NGI_GET_MSG(); * The return address is also stored in the item, as an ng_ID_t, * accessible as NGI_RETADDR(item); * Check it is one we understand. If needed, send a response. * We could save th

Source from the content-addressed store, hash-verified

244 * (so that old userland programs could continue to work).
245 */
246static int
247ng_etf_rcvmsg(node_p node, item_p item, hook_p lasthook)
248{
249 const etf_p etfp = NG_NODE_PRIVATE(node);
250 struct ng_mesg *resp = NULL;
251 int error = 0;
252 struct ng_mesg *msg;
253
254 NGI_GET_MSG(item, msg);
255 /* Deal with message according to cookie and command */
256 switch (msg->header.typecookie) {
257 case NGM_ETF_COOKIE:
258 switch (msg->header.cmd) {
259 case NGM_ETF_GET_STATUS:
260 {
261 struct ng_etfstat *stats;
262
263 NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
264 if (!resp) {
265 error = ENOMEM;
266 break;
267 }
268 stats = (struct ng_etfstat *) resp->data;
269 stats->packets_in = etfp->packets_in;
270 stats->packets_out = etfp->packets_out;
271 break;
272 }
273 case NGM_ETF_SET_FLAG:
274 if (msg->header.arglen != sizeof(u_int32_t)) {
275 error = EINVAL;
276 break;
277 }
278 etfp->flags = *((u_int32_t *) msg->data);
279 break;
280 case NGM_ETF_SET_FILTER:
281 {
282 struct ng_etffilter *f;
283 struct filter *fil;
284 hook_p hook;
285
286 /* Check message long enough for this command */
287 if (msg->header.arglen != sizeof(*f)) {
288 error = EINVAL;
289 break;
290 }
291
292 /* Make sure hook referenced exists */
293 f = (struct ng_etffilter *)msg->data;
294 hook = ng_findhook(node, f->matchhook);
295 if (hook == NULL) {
296 error = ENOENT;
297 break;
298 }
299
300 /* and is not the downstream hook */
301 if (hook == etfp->downstream_hook.hook) {
302 error = EINVAL;
303 break;

Callers

nothing calls this directly

Calls 3

ng_etf_findentryFunction · 0.85
mallocFunction · 0.85
ng_findhookFunction · 0.70

Tested by

no test coverage detected