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

Function ng_etf_rcvdata

freebsd/netgraph/ng_etf.c:363–427  ·  view source on GitHub ↗

* Receive data, and do something with it. * Actually we receive a queue item which holds the data. * If we free the item it will also free the data unless we have previously * disassociated it using the NGI_GET_etf() macro. * Possibly send it out on another link after processing. * Possibly do something different if it comes from different * hooks. The caller will never free m , so if we use

Source from the content-addressed store, hash-verified

361 * in the connect() method.
362 */
363static int
364ng_etf_rcvdata(hook_p hook, item_p item )
365{
366 const etf_p etfp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
367 struct ether_header *eh;
368 int error = 0;
369 struct mbuf *m;
370 u_int16_t ethertype;
371 struct filter *fil;
372
373 if (NG_HOOK_PRIVATE(hook) == NULL) { /* Shouldn't happen but.. */
374 NG_FREE_ITEM(item);
375 }
376
377 /*
378 * Everything not from the downstream hook goes to the
379 * downstream hook. But only if it matches the ethertype
380 * of the source hook. Un matching must go to/from 'nomatch'.
381 */
382
383 /* Make sure we have an entire header */
384 NGI_GET_M(item, m);
385 if (m->m_len < sizeof(*eh) ) {
386 m = m_pullup(m, sizeof(*eh));
387 if (m == NULL) {
388 NG_FREE_ITEM(item);
389 return(EINVAL);
390 }
391 }
392
393 eh = mtod(m, struct ether_header *);
394 ethertype = eh->ether_type;
395 fil = ng_etf_findentry(etfp, ethertype);
396
397 /*
398 * if from downstream, select between a match hook or
399 * the nomatch hook
400 */
401 if (hook == etfp->downstream_hook.hook) {
402 etfp->packets_in++;
403 if (fil && fil->match_hook) {
404 NG_FWD_NEW_DATA(error, item, fil->match_hook, m);
405 } else {
406 NG_FWD_NEW_DATA(error, item,etfp->nomatch_hook.hook, m);
407 }
408 } else {
409 /*
410 * It must be heading towards the downstream.
411 * Check that it's ethertype matches
412 * the filters for it's input hook.
413 * If it doesn't have one, check it's from nomatch.
414 */
415 if ((fil && (fil->match_hook != hook))
416 || ((fil == NULL) && (hook != etfp->nomatch_hook.hook))) {
417 NG_FREE_ITEM(item);
418 NG_FREE_M(m);
419 return (EPROTOTYPE);
420 }

Callers

nothing calls this directly

Calls 2

m_pullupFunction · 0.85
ng_etf_findentryFunction · 0.85

Tested by

no test coverage detected