* Incoming messages get passed up to the control socket. * Unless they are for us specifically (socket_type) */
| 888 | * Unless they are for us specifically (socket_type) |
| 889 | */ |
| 890 | static int |
| 891 | ngs_rcvmsg(node_p node, item_p item, hook_p lasthook) |
| 892 | { |
| 893 | struct ngsock *const priv = NG_NODE_PRIVATE(node); |
| 894 | struct ngpcb *pcbp; |
| 895 | struct socket *so; |
| 896 | struct sockaddr_ng addr; |
| 897 | struct ng_mesg *msg; |
| 898 | struct mbuf *m; |
| 899 | ng_ID_t retaddr = NGI_RETADDR(item); |
| 900 | int addrlen; |
| 901 | int error = 0; |
| 902 | |
| 903 | NGI_GET_MSG(item, msg); |
| 904 | NG_FREE_ITEM(item); |
| 905 | |
| 906 | /* |
| 907 | * Grab priv->mtx here to prevent destroying of control socket |
| 908 | * after checking that priv->ctlsock is not NULL. |
| 909 | */ |
| 910 | mtx_lock(&priv->mtx); |
| 911 | pcbp = priv->ctlsock; |
| 912 | |
| 913 | /* |
| 914 | * Only allow mesgs to be passed if we have the control socket. |
| 915 | * Data sockets can only support the generic messages. |
| 916 | */ |
| 917 | if (pcbp == NULL) { |
| 918 | mtx_unlock(&priv->mtx); |
| 919 | TRAP_ERROR; |
| 920 | NG_FREE_MSG(msg); |
| 921 | return (EINVAL); |
| 922 | } |
| 923 | so = pcbp->ng_socket; |
| 924 | SOCKBUF_LOCK(&so->so_rcv); |
| 925 | |
| 926 | /* As long as the race is handled, priv->mtx may be unlocked now. */ |
| 927 | mtx_unlock(&priv->mtx); |
| 928 | |
| 929 | #ifdef TRACE_MESSAGES |
| 930 | printf("[%x]:---------->[socket]: c=<%d>cmd=%x(%s) f=%x #%d\n", |
| 931 | retaddr, |
| 932 | msg->header.typecookie, |
| 933 | msg->header.cmd, |
| 934 | msg->header.cmdstr, |
| 935 | msg->header.flags, |
| 936 | msg->header.token); |
| 937 | #endif |
| 938 | |
| 939 | if (msg->header.typecookie == NGM_SOCKET_COOKIE) { |
| 940 | switch (msg->header.cmd) { |
| 941 | case NGM_SOCK_CMD_NOLINGER: |
| 942 | priv->flags |= NGS_FLAG_NOLINGER; |
| 943 | break; |
| 944 | case NGM_SOCK_CMD_LINGER: |
| 945 | priv->flags &= ~NGS_FLAG_NOLINGER; |
| 946 | break; |
| 947 | default: |
nothing calls this directly
no test coverage detected