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

Function ng_nat_rcvdata

freebsd/netgraph/ng_nat.c:754–903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

752}
753
754static int
755ng_nat_rcvdata(hook_p hook, item_p item )
756{
757 const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
758 struct mbuf *m;
759 struct ip *ip;
760 int rval, ipofs, error = 0;
761 char *c;
762
763 /* We have no required hooks. */
764 if (!(priv->flags & NGNAT_CONNECTED)) {
765 NG_FREE_ITEM(item);
766 return (ENXIO);
767 }
768
769 /* We have no alias address yet to do anything. */
770 if (!(priv->flags & NGNAT_ADDR_DEFINED))
771 goto send;
772
773 m = NGI_M(item);
774
775 if ((m = m_megapullup(m, m->m_pkthdr.len)) == NULL) {
776 NGI_M(item) = NULL; /* avoid double free */
777 NG_FREE_ITEM(item);
778 return (ENOBUFS);
779 }
780
781 NGI_M(item) = m;
782
783 switch (priv->dlt) {
784 case DLT_RAW:
785 ipofs = 0;
786 break;
787 case DLT_EN10MB:
788 {
789 struct ether_header *eh;
790
791 if (m->m_pkthdr.len < sizeof(struct ether_header)) {
792 NG_FREE_ITEM(item);
793 return (ENXIO);
794 }
795 eh = mtod(m, struct ether_header *);
796 switch (ntohs(eh->ether_type)) {
797 case ETHERTYPE_IP:
798 ipofs = sizeof(struct ether_header);
799 break;
800 default:
801 goto send;
802 }
803 break;
804 }
805 default:
806 panic("Corrupted priv->dlt: %u", priv->dlt);
807 }
808
809 if (m->m_pkthdr.len < ipofs + sizeof(struct ip))
810 goto send; /* packet too short to hold IP */
811

Callers

nothing calls this directly

Calls 6

m_megapullupFunction · 0.85
LibAliasInFunction · 0.85
LibAliasOutFunction · 0.85
in_delayed_cksumFunction · 0.85
panicFunction · 0.50
in_pseudoFunction · 0.50

Tested by

no test coverage detected