| 752 | } |
| 753 | |
| 754 | static int |
| 755 | ng_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 |
nothing calls this directly
no test coverage detected