* Receive incoming data on our hook. Send it out the socket. */
| 879 | * Receive incoming data on our hook. Send it out the socket. |
| 880 | */ |
| 881 | static int |
| 882 | ng_ksocket_rcvdata(hook_p hook, item_p item) |
| 883 | { |
| 884 | struct thread *td = curthread; /* XXX broken */ |
| 885 | const node_p node = NG_HOOK_NODE(hook); |
| 886 | const priv_p priv = NG_NODE_PRIVATE(node); |
| 887 | struct socket *const so = priv->so; |
| 888 | struct sockaddr *sa = NULL; |
| 889 | int error; |
| 890 | struct mbuf *m; |
| 891 | #ifdef ALIGNED_POINTER |
| 892 | struct mbuf *n; |
| 893 | #endif /* ALIGNED_POINTER */ |
| 894 | struct sa_tag *stag; |
| 895 | |
| 896 | /* Extract data */ |
| 897 | NGI_GET_M(item, m); |
| 898 | NG_FREE_ITEM(item); |
| 899 | #ifdef ALIGNED_POINTER |
| 900 | if (!ALIGNED_POINTER(mtod(m, caddr_t), uint32_t)) { |
| 901 | n = m_defrag(m, M_NOWAIT); |
| 902 | if (n == NULL) { |
| 903 | m_freem(m); |
| 904 | return (ENOBUFS); |
| 905 | } |
| 906 | m = n; |
| 907 | } |
| 908 | #endif /* ALIGNED_POINTER */ |
| 909 | /* |
| 910 | * Look if socket address is stored in packet tags. |
| 911 | * If sockaddr is ours, or provided by a third party (zero id), |
| 912 | * then we accept it. |
| 913 | */ |
| 914 | if (((stag = (struct sa_tag *)m_tag_locate(m, NGM_KSOCKET_COOKIE, |
| 915 | NG_KSOCKET_TAG_SOCKADDR, NULL)) != NULL) && |
| 916 | (stag->id == NG_NODE_ID(node) || stag->id == 0)) |
| 917 | sa = &stag->sa; |
| 918 | |
| 919 | /* Reset specific mbuf flags to prevent addressing problems. */ |
| 920 | m->m_flags &= ~(M_BCAST|M_MCAST); |
| 921 | |
| 922 | /* Send packet */ |
| 923 | error = sosend(so, sa, 0, m, 0, 0, td); |
| 924 | |
| 925 | return (error); |
| 926 | } |
| 927 | |
| 928 | /* |
| 929 | * Destroy node |
nothing calls this directly
no test coverage detected