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

Function ng_bridge_rcvdata

freebsd/netgraph/ng_bridge.c:654–812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654static int
655ng_bridge_rcvdata(hook_p hook, item_p item)
656{
657 const node_p node = NG_HOOK_NODE(hook);
658 const priv_p priv = NG_NODE_PRIVATE(node);
659 struct ng_bridge_host *host;
660 struct ether_header *eh;
661 struct ng_bridge_send_ctx ctx = { 0 };
662 hook_p ret;
663
664 NGI_GET_M(item, ctx.m);
665
666 ctx.incoming = NG_HOOK_PRIVATE(hook);
667 /* Sanity check packet and pull up header */
668 if (ctx.m->m_pkthdr.len < ETHER_HDR_LEN) {
669 ctx.incoming->stats.recvRunts++;
670 NG_FREE_ITEM(item);
671 NG_FREE_M(ctx.m);
672 return (EINVAL);
673 }
674 if (ctx.m->m_len < ETHER_HDR_LEN && !(ctx.m = m_pullup(ctx.m, ETHER_HDR_LEN))) {
675 ctx.incoming->stats.memoryFailures++;
676 NG_FREE_ITEM(item);
677 return (ENOBUFS);
678 }
679 eh = mtod(ctx.m, struct ether_header *);
680 if ((eh->ether_shost[0] & 1) != 0) {
681 ctx.incoming->stats.recvInvalid++;
682 NG_FREE_ITEM(item);
683 NG_FREE_M(ctx.m);
684 return (EINVAL);
685 }
686
687 /* Is link disabled due to a loopback condition? */
688 if (ctx.incoming->loopCount != 0) {
689 ctx.incoming->stats.loopDrops++;
690 NG_FREE_ITEM(item);
691 NG_FREE_M(ctx.m);
692 return (ELOOP); /* XXX is this an appropriate error? */
693 }
694
695 /* Update stats */
696 ctx.incoming->stats.recvPackets++;
697 ctx.incoming->stats.recvOctets += ctx.m->m_pkthdr.len;
698 if ((ctx.manycast = (eh->ether_dhost[0] & 1)) != 0) {
699 if (ETHER_EQUAL(eh->ether_dhost, ng_bridge_bcast_addr)) {
700 ctx.incoming->stats.recvBroadcasts++;
701 ctx.manycast = 2;
702 } else
703 ctx.incoming->stats.recvMulticasts++;
704 }
705
706 /* Look up packet's source Ethernet address in hashtable */
707 if ((host = ng_bridge_get(priv, eh->ether_shost)) != NULL) {
708 /* Update time since last heard from this host */
709 host->staleness = 0;
710
711 /* Did host jump to a different link? */

Callers

nothing calls this directly

Calls 7

m_pullupFunction · 0.85
ng_bridge_getFunction · 0.85
snprintfFunction · 0.85
ng_bridge_nodenameFunction · 0.85
ng_bridge_remove_hostsFunction · 0.85
ng_bridge_putFunction · 0.85
logFunction · 0.50

Tested by

no test coverage detected