2 * net/tipc/socket.c: TIPC socket API
4 * Copyright (c) 2001-2007, 2012 Ericsson AB
5 * Copyright (c) 2004-2008, 2010-2013, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
40 #include <linux/export.h>
43 #define SS_LISTENING -1 /* socket is listening */
44 #define SS_READY -2 /* socket is connectionless */
46 #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
51 struct tipc_portid peer_name;
52 unsigned int conn_timeout;
55 #define tipc_sk(sk) ((struct tipc_sock *)(sk))
56 #define tipc_sk_port(sk) (tipc_sk(sk)->p)
58 #define tipc_rx_ready(sock) (!skb_queue_empty(&sock->sk->sk_receive_queue) || \
59 (sock->state == SS_DISCONNECTING))
61 static int backlog_rcv(struct sock *sk, struct sk_buff *skb);
62 static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf);
63 static void wakeupdispatch(struct tipc_port *tport);
64 static void tipc_data_ready(struct sock *sk, int len);
65 static void tipc_write_space(struct sock *sk);
66 static int release(struct socket *sock);
67 static int accept(struct socket *sock, struct socket *new_sock, int flags);
69 static const struct proto_ops packet_ops;
70 static const struct proto_ops stream_ops;
71 static const struct proto_ops msg_ops;
73 static struct proto tipc_proto;
74 static struct proto tipc_proto_kern;
76 static int sockets_enabled;
79 * Revised TIPC socket locking policy:
81 * Most socket operations take the standard socket lock when they start
82 * and hold it until they finish (or until they need to sleep). Acquiring
83 * this lock grants the owner exclusive access to the fields of the socket
84 * data structures, with the exception of the backlog queue. A few socket
85 * operations can be done without taking the socket lock because they only
86 * read socket information that never changes during the life of the socket.
88 * Socket operations may acquire the lock for the associated TIPC port if they
89 * need to perform an operation on the port. If any routine needs to acquire
90 * both the socket lock and the port lock it must take the socket lock first
91 * to avoid the risk of deadlock.
93 * The dispatcher handling incoming messages cannot grab the socket lock in
94 * the standard fashion, since invoked it runs at the BH level and cannot block.
95 * Instead, it checks to see if the socket lock is currently owned by someone,
96 * and either handles the message itself or adds it to the socket's backlog
97 * queue; in the latter case the queued message is processed once the process
98 * owning the socket lock releases it.
100 * NOTE: Releasing the socket lock while an operation is sleeping overcomes
101 * the problem of a blocked socket operation preventing any other operations
102 * from occurring. However, applications must be careful if they have
103 * multiple threads trying to send (or receive) on the same socket, as these
104 * operations might interfere with each other. For example, doing a connect
105 * and a receive at the same time might allow the receive to consume the
106 * ACK message meant for the connect. While additional work could be done
107 * to try and overcome this, it doesn't seem to be worthwhile at the present.
109 * NOTE: Releasing the socket lock while an operation is sleeping also ensures
110 * that another operation that must be performed in a non-blocking manner is
111 * not delayed for very long because the lock has already been taken.
113 * NOTE: This code assumes that certain fields of a port/socket pair are
114 * constant over its lifetime; such fields can be examined without taking
115 * the socket lock and/or port lock, and do not need to be re-read even
116 * after resuming processing after waiting. These fields include:
118 * - pointer to socket sk structure (aka tipc_sock structure)
119 * - pointer to port structure
124 * advance_rx_queue - discard first buffer in socket receive queue
126 * Caller must hold socket lock
128 static void advance_rx_queue(struct sock *sk)
130 kfree_skb(__skb_dequeue(&sk->sk_receive_queue));
134 * reject_rx_queue - reject all buffers in socket receive queue
136 * Caller must hold socket lock
138 static void reject_rx_queue(struct sock *sk)
142 while ((buf = __skb_dequeue(&sk->sk_receive_queue)))
143 tipc_reject_msg(buf, TIPC_ERR_NO_PORT);
147 * tipc_sk_create - create a TIPC socket
148 * @net: network namespace (must be default network)
149 * @sock: pre-allocated socket structure
150 * @protocol: protocol indicator (must be 0)
151 * @kern: caused by kernel or by userspace?
153 * This routine creates additional data structures used by the TIPC socket,
154 * initializes them, and links them together.
156 * Returns 0 on success, errno otherwise
158 static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
161 const struct proto_ops *ops;
164 struct tipc_port *tp_ptr;
166 /* Validate arguments */
167 if (unlikely(protocol != 0))
168 return -EPROTONOSUPPORT;
170 switch (sock->type) {
173 state = SS_UNCONNECTED;
177 state = SS_UNCONNECTED;
188 /* Allocate socket's protocol area */
190 sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto);
192 sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto_kern);
197 /* Allocate TIPC port for socket to use */
198 tp_ptr = tipc_createport(sk, &dispatch, &wakeupdispatch,
199 TIPC_LOW_IMPORTANCE);
200 if (unlikely(!tp_ptr)) {
205 /* Finish initializing socket data structures */
209 sock_init_data(sock, sk);
210 sk->sk_backlog_rcv = backlog_rcv;
211 sk->sk_rcvbuf = sysctl_tipc_rmem[1];
212 sk->sk_data_ready = tipc_data_ready;
213 sk->sk_write_space = tipc_write_space;
214 tipc_sk(sk)->p = tp_ptr;
215 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT;
217 spin_unlock_bh(tp_ptr->lock);
219 if (sock->state == SS_READY) {
220 tipc_set_portunreturnable(tp_ptr->ref, 1);
221 if (sock->type == SOCK_DGRAM)
222 tipc_set_portunreliable(tp_ptr->ref, 1);
229 * tipc_sock_create_local - create TIPC socket from inside TIPC module
230 * @type: socket type - SOCK_RDM or SOCK_SEQPACKET
232 * We cannot use sock_creat_kern here because it bumps module user count.
233 * Since socket owner and creator is the same module we must make sure
234 * that module count remains zero for module local sockets, otherwise
235 * we cannot do rmmod.
237 * Returns 0 on success, errno otherwise
239 int tipc_sock_create_local(int type, struct socket **res)
243 rc = sock_create_lite(AF_TIPC, type, 0, res);
245 pr_err("Failed to create kernel socket\n");
248 tipc_sk_create(&init_net, *res, 0, 1);
254 * tipc_sock_release_local - release socket created by tipc_sock_create_local
255 * @sock: the socket to be released.
257 * Module reference count is not incremented when such sockets are created,
258 * so we must keep it from being decremented when they are released.
260 void tipc_sock_release_local(struct socket *sock)
268 * tipc_sock_accept_local - accept a connection on a socket created
269 * with tipc_sock_create_local. Use this function to avoid that
270 * module reference count is inadvertently incremented.
272 * @sock: the accepting socket
273 * @newsock: reference to the new socket to be created
274 * @flags: socket flags
277 int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
280 struct sock *sk = sock->sk;
283 ret = sock_create_lite(sk->sk_family, sk->sk_type,
284 sk->sk_protocol, newsock);
288 ret = accept(sock, *newsock, flags);
290 sock_release(*newsock);
293 (*newsock)->ops = sock->ops;
298 * release - destroy a TIPC socket
299 * @sock: socket to destroy
301 * This routine cleans up any messages that are still queued on the socket.
302 * For DGRAM and RDM socket types, all queued messages are rejected.
303 * For SEQPACKET and STREAM socket types, the first message is rejected
304 * and any others are discarded. (If the first message on a STREAM socket
305 * is partially-read, it is discarded and the next one is rejected instead.)
307 * NOTE: Rejected messages are not necessarily returned to the sender! They
308 * are returned or discarded according to the "destination droppable" setting
309 * specified for the message by the sender.
311 * Returns 0 on success, errno otherwise
313 static int release(struct socket *sock)
315 struct sock *sk = sock->sk;
316 struct tipc_port *tport;
321 * Exit if socket isn't fully initialized (occurs when a failed accept()
322 * releases a pre-allocated child socket that was never used)
327 tport = tipc_sk_port(sk);
331 * Reject all unreceived messages, except on an active connection
332 * (which disconnects locally & sends a 'FIN+' to peer)
334 while (sock->state != SS_DISCONNECTING) {
335 buf = __skb_dequeue(&sk->sk_receive_queue);
338 if (TIPC_SKB_CB(buf)->handle != NULL)
341 if ((sock->state == SS_CONNECTING) ||
342 (sock->state == SS_CONNECTED)) {
343 sock->state = SS_DISCONNECTING;
344 tipc_disconnect(tport->ref);
346 tipc_reject_msg(buf, TIPC_ERR_NO_PORT);
351 * Delete TIPC port; this ensures no more messages are queued
352 * (also disconnects an active connection & sends a 'FIN-' to peer)
354 res = tipc_deleteport(tport);
356 /* Discard any remaining (connection-based) messages in receive queue */
357 __skb_queue_purge(&sk->sk_receive_queue);
359 /* Reject any messages that accumulated in backlog queue */
360 sock->state = SS_DISCONNECTING;
370 * bind - associate or disassocate TIPC name(s) with a socket
371 * @sock: socket structure
372 * @uaddr: socket address describing name(s) and desired operation
373 * @uaddr_len: size of socket address data structure
375 * Name and name sequence binding is indicated using a positive scope value;
376 * a negative scope value unbinds the specified name. Specifying no name
377 * (i.e. a socket address length of 0) unbinds all names from the socket.
379 * Returns 0 on success, errno otherwise
381 * NOTE: This routine doesn't need to take the socket lock since it doesn't
382 * access any non-constant socket information.
384 static int bind(struct socket *sock, struct sockaddr *uaddr, int uaddr_len)
386 struct sock *sk = sock->sk;
387 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
388 struct tipc_port *tport = tipc_sk_port(sock->sk);
392 if (unlikely(!uaddr_len)) {
393 res = tipc_withdraw(tport, 0, NULL);
397 if (uaddr_len < sizeof(struct sockaddr_tipc)) {
401 if (addr->family != AF_TIPC) {
406 if (addr->addrtype == TIPC_ADDR_NAME)
407 addr->addr.nameseq.upper = addr->addr.nameseq.lower;
408 else if (addr->addrtype != TIPC_ADDR_NAMESEQ) {
413 if ((addr->addr.nameseq.type < TIPC_RESERVED_TYPES) &&
414 (addr->addr.nameseq.type != TIPC_TOP_SRV) &&
415 (addr->addr.nameseq.type != TIPC_CFG_SRV)) {
420 res = (addr->scope > 0) ?
421 tipc_publish(tport, addr->scope, &addr->addr.nameseq) :
422 tipc_withdraw(tport, -addr->scope, &addr->addr.nameseq);
429 * get_name - get port ID of socket or peer socket
430 * @sock: socket structure
431 * @uaddr: area for returned socket address
432 * @uaddr_len: area for returned length of socket address
433 * @peer: 0 = own ID, 1 = current peer ID, 2 = current/former peer ID
435 * Returns 0 on success, errno otherwise
437 * NOTE: This routine doesn't need to take the socket lock since it only
438 * accesses socket information that is unchanging (or which changes in
439 * a completely predictable manner).
441 static int get_name(struct socket *sock, struct sockaddr *uaddr,
442 int *uaddr_len, int peer)
444 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
445 struct tipc_sock *tsock = tipc_sk(sock->sk);
447 memset(addr, 0, sizeof(*addr));
449 if ((sock->state != SS_CONNECTED) &&
450 ((peer != 2) || (sock->state != SS_DISCONNECTING)))
452 addr->addr.id.ref = tsock->peer_name.ref;
453 addr->addr.id.node = tsock->peer_name.node;
455 addr->addr.id.ref = tsock->p->ref;
456 addr->addr.id.node = tipc_own_addr;
459 *uaddr_len = sizeof(*addr);
460 addr->addrtype = TIPC_ADDR_ID;
461 addr->family = AF_TIPC;
463 addr->addr.name.domain = 0;
469 * poll - read and possibly block on pollmask
470 * @file: file structure associated with the socket
471 * @sock: socket for which to calculate the poll bits
474 * Returns pollmask value
477 * It appears that the usual socket locking mechanisms are not useful here
478 * since the pollmask info is potentially out-of-date the moment this routine
479 * exits. TCP and other protocols seem to rely on higher level poll routines
480 * to handle any preventable race conditions, so TIPC will do the same ...
482 * TIPC sets the returned events as follows:
484 * socket state flags set
485 * ------------ ---------
486 * unconnected no read flags
487 * POLLOUT if port is not congested
489 * connecting POLLIN/POLLRDNORM if ACK/NACK in rx queue
492 * connected POLLIN/POLLRDNORM if data in rx queue
493 * POLLOUT if port is not congested
495 * disconnecting POLLIN/POLLRDNORM/POLLHUP
498 * listening POLLIN if SYN in rx queue
501 * ready POLLIN/POLLRDNORM if data in rx queue
502 * [connectionless] POLLOUT (since port cannot be congested)
504 * IMPORTANT: The fact that a read or write operation is indicated does NOT
505 * imply that the operation will succeed, merely that it should be performed
506 * and will not block.
508 static unsigned int poll(struct file *file, struct socket *sock,
511 struct sock *sk = sock->sk;
514 sock_poll_wait(file, sk_sleep(sk), wait);
516 switch ((int)sock->state) {
518 if (!tipc_sk_port(sk)->congested)
523 if (!tipc_sk_port(sk)->congested)
528 if (!skb_queue_empty(&sk->sk_receive_queue))
529 mask |= (POLLIN | POLLRDNORM);
531 case SS_DISCONNECTING:
532 mask = (POLLIN | POLLRDNORM | POLLHUP);
540 * dest_name_check - verify user is permitted to send to specified port name
541 * @dest: destination address
542 * @m: descriptor for message to be sent
544 * Prevents restricted configuration commands from being issued by
545 * unauthorized users.
547 * Returns 0 if permission is granted, otherwise errno
549 static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
551 struct tipc_cfg_msg_hdr hdr;
553 if (likely(dest->addr.name.name.type >= TIPC_RESERVED_TYPES))
555 if (likely(dest->addr.name.name.type == TIPC_TOP_SRV))
557 if (likely(dest->addr.name.name.type != TIPC_CFG_SRV))
560 if (!m->msg_iovlen || (m->msg_iov[0].iov_len < sizeof(hdr)))
562 if (copy_from_user(&hdr, m->msg_iov[0].iov_base, sizeof(hdr)))
564 if ((ntohs(hdr.tcm_type) & 0xC000) && (!capable(CAP_NET_ADMIN)))
571 * send_msg - send message in connectionless manner
572 * @iocb: if NULL, indicates that socket lock is already held
573 * @sock: socket structure
574 * @m: message to send
575 * @total_len: length of message
577 * Message must have an destination specified explicitly.
578 * Used for SOCK_RDM and SOCK_DGRAM messages,
579 * and for 'SYN' messages on SOCK_SEQPACKET and SOCK_STREAM connections.
580 * (Note: 'SYN+' is prohibited on SOCK_STREAM.)
582 * Returns the number of bytes sent on success, or errno otherwise
584 static int send_msg(struct kiocb *iocb, struct socket *sock,
585 struct msghdr *m, size_t total_len)
587 struct sock *sk = sock->sk;
588 struct tipc_port *tport = tipc_sk_port(sk);
589 struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name;
595 return -EDESTADDRREQ;
596 if (unlikely((m->msg_namelen < sizeof(*dest)) ||
597 (dest->family != AF_TIPC)))
599 if (total_len > TIPC_MAX_USER_MSG_SIZE)
605 needs_conn = (sock->state != SS_READY);
606 if (unlikely(needs_conn)) {
607 if (sock->state == SS_LISTENING) {
611 if (sock->state != SS_UNCONNECTED) {
615 if (tport->published) {
619 if (dest->addrtype == TIPC_ADDR_NAME) {
620 tport->conn_type = dest->addr.name.name.type;
621 tport->conn_instance = dest->addr.name.name.instance;
624 /* Abort any pending connection attempts (very unlikely) */
628 timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
631 if (dest->addrtype == TIPC_ADDR_NAME) {
632 res = dest_name_check(dest, m);
635 res = tipc_send2name(tport->ref,
636 &dest->addr.name.name,
637 dest->addr.name.domain,
640 } else if (dest->addrtype == TIPC_ADDR_ID) {
641 res = tipc_send2port(tport->ref,
645 } else if (dest->addrtype == TIPC_ADDR_MCAST) {
650 res = dest_name_check(dest, m);
653 res = tipc_multicast(tport->ref,
658 if (likely(res != -ELINKCONG)) {
659 if (needs_conn && (res >= 0))
660 sock->state = SS_CONNECTING;
663 if (timeout_val <= 0L) {
664 res = timeout_val ? timeout_val : -EWOULDBLOCK;
668 timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk),
669 !tport->congested, timeout_val);
680 * send_packet - send a connection-oriented message
681 * @iocb: if NULL, indicates that socket lock is already held
682 * @sock: socket structure
683 * @m: message to send
684 * @total_len: length of message
686 * Used for SOCK_SEQPACKET messages and SOCK_STREAM data.
688 * Returns the number of bytes sent on success, or errno otherwise
690 static int send_packet(struct kiocb *iocb, struct socket *sock,
691 struct msghdr *m, size_t total_len)
693 struct sock *sk = sock->sk;
694 struct tipc_port *tport = tipc_sk_port(sk);
695 struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name;
699 /* Handle implied connection establishment */
701 return send_msg(iocb, sock, m, total_len);
703 if (total_len > TIPC_MAX_USER_MSG_SIZE)
709 timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
712 if (unlikely(sock->state != SS_CONNECTED)) {
713 if (sock->state == SS_DISCONNECTING)
720 res = tipc_send(tport->ref, m->msg_iov, total_len);
721 if (likely(res != -ELINKCONG))
723 if (timeout_val <= 0L) {
724 res = timeout_val ? timeout_val : -EWOULDBLOCK;
728 timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk),
729 (!tport->congested || !tport->connected), timeout_val);
739 * send_stream - send stream-oriented data
741 * @sock: socket structure
743 * @total_len: total length of data to be sent
745 * Used for SOCK_STREAM data.
747 * Returns the number of bytes sent on success (or partial success),
748 * or errno if no data sent
750 static int send_stream(struct kiocb *iocb, struct socket *sock,
751 struct msghdr *m, size_t total_len)
753 struct sock *sk = sock->sk;
754 struct tipc_port *tport = tipc_sk_port(sk);
755 struct msghdr my_msg;
757 struct iovec *curr_iov;
759 char __user *curr_start;
768 /* Handle special cases where there is no connection */
769 if (unlikely(sock->state != SS_CONNECTED)) {
770 if (sock->state == SS_UNCONNECTED)
771 res = send_packet(NULL, sock, m, total_len);
773 res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN;
777 if (unlikely(m->msg_name)) {
782 if (total_len > (unsigned int)INT_MAX) {
788 * Send each iovec entry using one or more messages
790 * Note: This algorithm is good for the most likely case
791 * (i.e. one large iovec entry), but could be improved to pass sets
792 * of small iovec entries into send_packet().
794 curr_iov = m->msg_iov;
795 curr_iovlen = m->msg_iovlen;
796 my_msg.msg_iov = &my_iov;
797 my_msg.msg_iovlen = 1;
798 my_msg.msg_flags = m->msg_flags;
799 my_msg.msg_name = NULL;
802 hdr_size = msg_hdr_sz(&tport->phdr);
804 while (curr_iovlen--) {
805 curr_start = curr_iov->iov_base;
806 curr_left = curr_iov->iov_len;
809 bytes_to_send = tport->max_pkt - hdr_size;
810 if (bytes_to_send > TIPC_MAX_USER_MSG_SIZE)
811 bytes_to_send = TIPC_MAX_USER_MSG_SIZE;
812 if (curr_left < bytes_to_send)
813 bytes_to_send = curr_left;
814 my_iov.iov_base = curr_start;
815 my_iov.iov_len = bytes_to_send;
816 res = send_packet(NULL, sock, &my_msg, bytes_to_send);
822 curr_left -= bytes_to_send;
823 curr_start += bytes_to_send;
824 bytes_sent += bytes_to_send;
836 * auto_connect - complete connection setup to a remote port
837 * @sock: socket structure
838 * @msg: peer's response message
840 * Returns 0 on success, errno otherwise
842 static int auto_connect(struct socket *sock, struct tipc_msg *msg)
844 struct tipc_sock *tsock = tipc_sk(sock->sk);
845 struct tipc_port *p_ptr;
847 tsock->peer_name.ref = msg_origport(msg);
848 tsock->peer_name.node = msg_orignode(msg);
849 p_ptr = tipc_port_deref(tsock->p->ref);
853 __tipc_connect(tsock->p->ref, p_ptr, &tsock->peer_name);
855 if (msg_importance(msg) > TIPC_CRITICAL_IMPORTANCE)
857 msg_set_importance(&p_ptr->phdr, (u32)msg_importance(msg));
858 sock->state = SS_CONNECTED;
863 * set_orig_addr - capture sender's address for received message
864 * @m: descriptor for message info
865 * @msg: received message header
867 * Note: Address is not captured if not requested by receiver.
869 static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
871 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name;
874 addr->family = AF_TIPC;
875 addr->addrtype = TIPC_ADDR_ID;
876 memset(&addr->addr, 0, sizeof(addr->addr));
877 addr->addr.id.ref = msg_origport(msg);
878 addr->addr.id.node = msg_orignode(msg);
879 addr->addr.name.domain = 0; /* could leave uninitialized */
880 addr->scope = 0; /* could leave uninitialized */
881 m->msg_namelen = sizeof(struct sockaddr_tipc);
886 * anc_data_recv - optionally capture ancillary data for received message
887 * @m: descriptor for message info
888 * @msg: received message header
889 * @tport: TIPC port associated with message
891 * Note: Ancillary data is not captured if not requested by receiver.
893 * Returns 0 if successful, otherwise errno
895 static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
896 struct tipc_port *tport)
904 if (likely(m->msg_controllen == 0))
907 /* Optionally capture errored message object(s) */
908 err = msg ? msg_errcode(msg) : 0;
911 anc_data[1] = msg_data_sz(msg);
912 res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data);
916 res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1],
923 /* Optionally capture message destination object */
924 dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG;
928 anc_data[0] = msg_nametype(msg);
929 anc_data[1] = msg_namelower(msg);
930 anc_data[2] = msg_namelower(msg);
934 anc_data[0] = msg_nametype(msg);
935 anc_data[1] = msg_namelower(msg);
936 anc_data[2] = msg_nameupper(msg);
939 has_name = (tport->conn_type != 0);
940 anc_data[0] = tport->conn_type;
941 anc_data[1] = tport->conn_instance;
942 anc_data[2] = tport->conn_instance;
948 res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data);
957 * recv_msg - receive packet-oriented message
959 * @m: descriptor for message info
960 * @buf_len: total size of user buffer area
961 * @flags: receive flags
963 * Used for SOCK_DGRAM, SOCK_RDM, and SOCK_SEQPACKET messages.
964 * If the complete message doesn't fit in user area, truncate it.
966 * Returns size of returned message data, errno otherwise
968 static int recv_msg(struct kiocb *iocb, struct socket *sock,
969 struct msghdr *m, size_t buf_len, int flags)
971 struct sock *sk = sock->sk;
972 struct tipc_port *tport = tipc_sk_port(sk);
974 struct tipc_msg *msg;
980 /* Catch invalid receive requests */
981 if (unlikely(!buf_len))
986 if (unlikely(sock->state == SS_UNCONNECTED)) {
991 timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
994 /* Look for a message in receive queue; wait if necessary */
995 while (skb_queue_empty(&sk->sk_receive_queue)) {
996 if (sock->state == SS_DISCONNECTING) {
1000 if (timeout <= 0L) {
1001 res = timeout ? timeout : -EWOULDBLOCK;
1005 timeout = wait_event_interruptible_timeout(*sk_sleep(sk),
1006 tipc_rx_ready(sock),
1011 /* Look at first message in receive queue */
1012 buf = skb_peek(&sk->sk_receive_queue);
1014 sz = msg_data_sz(msg);
1015 err = msg_errcode(msg);
1017 /* Discard an empty non-errored message & try again */
1018 if ((!sz) && (!err)) {
1019 advance_rx_queue(sk);
1023 /* Capture sender's address (optional) */
1024 set_orig_addr(m, msg);
1026 /* Capture ancillary data (optional) */
1027 res = anc_data_recv(m, msg, tport);
1031 /* Capture message data (if valid) & compute return value (always) */
1033 if (unlikely(buf_len < sz)) {
1035 m->msg_flags |= MSG_TRUNC;
1037 res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg),
1043 if ((sock->state == SS_READY) ||
1044 ((err == TIPC_CONN_SHUTDOWN) || m->msg_control))
1050 /* Consume received message (optional) */
1051 if (likely(!(flags & MSG_PEEK))) {
1052 if ((sock->state != SS_READY) &&
1053 (++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1054 tipc_acknowledge(tport->ref, tport->conn_unacked);
1055 advance_rx_queue(sk);
1063 * recv_stream - receive stream-oriented data
1065 * @m: descriptor for message info
1066 * @buf_len: total size of user buffer area
1067 * @flags: receive flags
1069 * Used for SOCK_STREAM messages only. If not enough data is available
1070 * will optionally wait for more; never truncates data.
1072 * Returns size of returned message data, errno otherwise
1074 static int recv_stream(struct kiocb *iocb, struct socket *sock,
1075 struct msghdr *m, size_t buf_len, int flags)
1077 struct sock *sk = sock->sk;
1078 struct tipc_port *tport = tipc_sk_port(sk);
1079 struct sk_buff *buf;
1080 struct tipc_msg *msg;
1083 int sz_to_copy, target, needed;
1088 /* Catch invalid receive attempts */
1089 if (unlikely(!buf_len))
1094 if (unlikely((sock->state == SS_UNCONNECTED))) {
1099 target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len);
1100 timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
1103 /* Look for a message in receive queue; wait if necessary */
1104 while (skb_queue_empty(&sk->sk_receive_queue)) {
1105 if (sock->state == SS_DISCONNECTING) {
1109 if (timeout <= 0L) {
1110 res = timeout ? timeout : -EWOULDBLOCK;
1114 timeout = wait_event_interruptible_timeout(*sk_sleep(sk),
1115 tipc_rx_ready(sock),
1120 /* Look at first message in receive queue */
1121 buf = skb_peek(&sk->sk_receive_queue);
1123 sz = msg_data_sz(msg);
1124 err = msg_errcode(msg);
1126 /* Discard an empty non-errored message & try again */
1127 if ((!sz) && (!err)) {
1128 advance_rx_queue(sk);
1132 /* Optionally capture sender's address & ancillary data of first msg */
1133 if (sz_copied == 0) {
1134 set_orig_addr(m, msg);
1135 res = anc_data_recv(m, msg, tport);
1140 /* Capture message data (if valid) & compute return value (always) */
1142 u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle);
1145 needed = (buf_len - sz_copied);
1146 sz_to_copy = (sz <= needed) ? sz : needed;
1148 res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg) + offset,
1149 m->msg_iov, sz_to_copy);
1153 sz_copied += sz_to_copy;
1155 if (sz_to_copy < sz) {
1156 if (!(flags & MSG_PEEK))
1157 TIPC_SKB_CB(buf)->handle =
1158 (void *)(unsigned long)(offset + sz_to_copy);
1163 goto exit; /* can't add error msg to valid data */
1165 if ((err == TIPC_CONN_SHUTDOWN) || m->msg_control)
1171 /* Consume received message (optional) */
1172 if (likely(!(flags & MSG_PEEK))) {
1173 if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN))
1174 tipc_acknowledge(tport->ref, tport->conn_unacked);
1175 advance_rx_queue(sk);
1178 /* Loop around if more data is required */
1179 if ((sz_copied < buf_len) && /* didn't get all requested data */
1180 (!skb_queue_empty(&sk->sk_receive_queue) ||
1181 (sz_copied < target)) && /* and more is ready or required */
1182 (!(flags & MSG_PEEK)) && /* and aren't just peeking at data */
1183 (!err)) /* and haven't reached a FIN */
1188 return sz_copied ? sz_copied : res;
1192 * tipc_write_space - wake up thread if port congestion is released
1195 static void tipc_write_space(struct sock *sk)
1197 struct socket_wq *wq;
1200 wq = rcu_dereference(sk->sk_wq);
1201 if (wq_has_sleeper(wq))
1202 wake_up_interruptible_sync_poll(&wq->wait, POLLOUT |
1203 POLLWRNORM | POLLWRBAND);
1208 * tipc_data_ready - wake up threads to indicate messages have been received
1210 * @len: the length of messages
1212 static void tipc_data_ready(struct sock *sk, int len)
1214 struct socket_wq *wq;
1217 wq = rcu_dereference(sk->sk_wq);
1218 if (wq_has_sleeper(wq))
1219 wake_up_interruptible_sync_poll(&wq->wait, POLLIN |
1220 POLLRDNORM | POLLRDBAND);
1225 * filter_connect - Handle all incoming messages for a connection-based socket
1226 * @tsock: TIPC socket
1229 * Returns TIPC error status code and socket error status code
1230 * once it encounters some errors
1232 static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf)
1234 struct socket *sock = tsock->sk.sk_socket;
1235 struct tipc_msg *msg = buf_msg(*buf);
1236 struct sock *sk = &tsock->sk;
1237 u32 retval = TIPC_ERR_NO_PORT;
1243 switch ((int)sock->state) {
1245 /* Accept only connection-based messages sent by peer */
1246 if (msg_connected(msg) && tipc_port_peer_msg(tsock->p, msg)) {
1247 if (unlikely(msg_errcode(msg))) {
1248 sock->state = SS_DISCONNECTING;
1249 __tipc_disconnect(tsock->p);
1255 /* Accept only ACK or NACK message */
1256 if (unlikely(msg_errcode(msg))) {
1257 sock->state = SS_DISCONNECTING;
1258 sk->sk_err = ECONNREFUSED;
1263 if (unlikely(!msg_connected(msg)))
1266 res = auto_connect(sock, msg);
1268 sock->state = SS_DISCONNECTING;
1274 /* If an incoming message is an 'ACK-', it should be
1275 * discarded here because it doesn't contain useful
1276 * data. In addition, we should try to wake up
1277 * connect() routine if sleeping.
1279 if (msg_data_sz(msg) == 0) {
1282 if (waitqueue_active(sk_sleep(sk)))
1283 wake_up_interruptible(sk_sleep(sk));
1288 case SS_UNCONNECTED:
1289 /* Accept only SYN message */
1290 if (!msg_connected(msg) && !(msg_errcode(msg)))
1293 case SS_DISCONNECTING:
1296 pr_err("Unknown socket state %u\n", sock->state);
1302 * rcvbuf_limit - get proper overload limit of socket receive queue
1306 * For all connection oriented messages, irrespective of importance,
1307 * the default overload value (i.e. 67MB) is set as limit.
1309 * For all connectionless messages, by default new queue limits are
1312 * TIPC_LOW_IMPORTANCE (4 MB)
1313 * TIPC_MEDIUM_IMPORTANCE (8 MB)
1314 * TIPC_HIGH_IMPORTANCE (16 MB)
1315 * TIPC_CRITICAL_IMPORTANCE (32 MB)
1317 * Returns overload limit according to corresponding message importance
1319 static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf)
1321 struct tipc_msg *msg = buf_msg(buf);
1323 if (msg_connected(msg))
1324 return sysctl_tipc_rmem[2];
1326 return sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE <<
1327 msg_importance(msg);
1331 * filter_rcv - validate incoming message
1335 * Enqueues message on receive queue if acceptable; optionally handles
1336 * disconnect indication for a connected socket.
1338 * Called with socket lock already taken; port lock may also be taken.
1340 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1342 static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
1344 struct socket *sock = sk->sk_socket;
1345 struct tipc_msg *msg = buf_msg(buf);
1346 unsigned int limit = rcvbuf_limit(sk, buf);
1349 /* Reject message if it is wrong sort of message for socket */
1350 if (msg_type(msg) > TIPC_DIRECT_MSG)
1351 return TIPC_ERR_NO_PORT;
1353 if (sock->state == SS_READY) {
1354 if (msg_connected(msg))
1355 return TIPC_ERR_NO_PORT;
1357 res = filter_connect(tipc_sk(sk), &buf);
1358 if (res != TIPC_OK || buf == NULL)
1362 /* Reject message if there isn't room to queue it */
1363 if (sk_rmem_alloc_get(sk) + buf->truesize >= limit)
1364 return TIPC_ERR_OVERLOAD;
1366 /* Enqueue message */
1367 TIPC_SKB_CB(buf)->handle = NULL;
1368 __skb_queue_tail(&sk->sk_receive_queue, buf);
1369 skb_set_owner_r(buf, sk);
1371 sk->sk_data_ready(sk, 0);
1376 * backlog_rcv - handle incoming message from backlog queue
1380 * Caller must hold socket lock, but not port lock.
1384 static int backlog_rcv(struct sock *sk, struct sk_buff *buf)
1388 res = filter_rcv(sk, buf);
1390 tipc_reject_msg(buf, res);
1395 * dispatch - handle incoming message
1396 * @tport: TIPC port that received message
1399 * Called with port lock already taken.
1401 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1403 static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf)
1405 struct sock *sk = tport->sk;
1409 * Process message if socket is unlocked; otherwise add to backlog queue
1411 * This code is based on sk_receive_skb(), but must be distinct from it
1412 * since a TIPC-specific filter/reject mechanism is utilized
1415 if (!sock_owned_by_user(sk)) {
1416 res = filter_rcv(sk, buf);
1418 if (sk_add_backlog(sk, buf, rcvbuf_limit(sk, buf)))
1419 res = TIPC_ERR_OVERLOAD;
1429 * wakeupdispatch - wake up port after congestion
1430 * @tport: port to wakeup
1432 * Called with port lock already taken.
1434 static void wakeupdispatch(struct tipc_port *tport)
1436 struct sock *sk = tport->sk;
1438 sk->sk_write_space(sk);
1442 * connect - establish a connection to another TIPC port
1443 * @sock: socket structure
1444 * @dest: socket address for destination port
1445 * @destlen: size of socket address data structure
1446 * @flags: file-related flags associated with socket
1448 * Returns 0 on success, errno otherwise
1450 static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1453 struct sock *sk = sock->sk;
1454 struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest;
1455 struct msghdr m = {NULL,};
1456 unsigned int timeout;
1461 /* For now, TIPC does not allow use of connect() with DGRAM/RDM types */
1462 if (sock->state == SS_READY) {
1468 * Reject connection attempt using multicast address
1470 * Note: send_msg() validates the rest of the address fields,
1471 * so there's no need to do it here
1473 if (dst->addrtype == TIPC_ADDR_MCAST) {
1478 timeout = (flags & O_NONBLOCK) ? 0 : tipc_sk(sk)->conn_timeout;
1480 switch (sock->state) {
1481 case SS_UNCONNECTED:
1482 /* Send a 'SYN-' to destination */
1484 m.msg_namelen = destlen;
1486 /* If connect is in non-blocking case, set MSG_DONTWAIT to
1487 * indicate send_msg() is never blocked.
1490 m.msg_flags = MSG_DONTWAIT;
1492 res = send_msg(NULL, sock, &m, 0);
1493 if ((res < 0) && (res != -EWOULDBLOCK))
1496 /* Just entered SS_CONNECTING state; the only
1497 * difference is that return value in non-blocking
1498 * case is EINPROGRESS, rather than EALREADY.
1513 if (sock->state == SS_CONNECTING) {
1517 /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */
1519 res = wait_event_interruptible_timeout(*sk_sleep(sk),
1520 sock->state != SS_CONNECTING,
1521 timeout ? (long)msecs_to_jiffies(timeout)
1522 : MAX_SCHEDULE_TIMEOUT);
1531 if (unlikely(sock->state == SS_DISCONNECTING))
1532 res = sock_error(sk);
1542 * listen - allow socket to listen for incoming connections
1543 * @sock: socket structure
1546 * Returns 0 on success, errno otherwise
1548 static int listen(struct socket *sock, int len)
1550 struct sock *sk = sock->sk;
1555 if (sock->state != SS_UNCONNECTED)
1558 sock->state = SS_LISTENING;
1567 * accept - wait for connection request
1568 * @sock: listening socket
1569 * @newsock: new socket that is to be connected
1570 * @flags: file-related flags associated with socket
1572 * Returns 0 on success, errno otherwise
1574 static int accept(struct socket *sock, struct socket *new_sock, int flags)
1576 struct sock *new_sk, *sk = sock->sk;
1577 struct sk_buff *buf;
1578 struct tipc_sock *new_tsock;
1579 struct tipc_port *new_tport;
1580 struct tipc_msg *msg;
1587 if (sock->state != SS_LISTENING) {
1592 while (skb_queue_empty(&sk->sk_receive_queue)) {
1593 if (flags & O_NONBLOCK) {
1598 res = wait_event_interruptible(*sk_sleep(sk),
1599 (!skb_queue_empty(&sk->sk_receive_queue)));
1605 buf = skb_peek(&sk->sk_receive_queue);
1607 res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, 1);
1611 new_sk = new_sock->sk;
1612 new_tsock = tipc_sk(new_sk);
1613 new_tport = new_tsock->p;
1614 new_ref = new_tport->ref;
1617 /* we lock on new_sk; but lockdep sees the lock on sk */
1618 lock_sock_nested(new_sk, SINGLE_DEPTH_NESTING);
1621 * Reject any stray messages received by new socket
1622 * before the socket lock was taken (very, very unlikely)
1624 reject_rx_queue(new_sk);
1626 /* Connect new socket to it's peer */
1627 new_tsock->peer_name.ref = msg_origport(msg);
1628 new_tsock->peer_name.node = msg_orignode(msg);
1629 tipc_connect(new_ref, &new_tsock->peer_name);
1630 new_sock->state = SS_CONNECTED;
1632 tipc_set_portimportance(new_ref, msg_importance(msg));
1633 if (msg_named(msg)) {
1634 new_tport->conn_type = msg_nametype(msg);
1635 new_tport->conn_instance = msg_nameinst(msg);
1639 * Respond to 'SYN-' by discarding it & returning 'ACK'-.
1640 * Respond to 'SYN+' by queuing it on new socket.
1642 if (!msg_data_sz(msg)) {
1643 struct msghdr m = {NULL,};
1645 advance_rx_queue(sk);
1646 send_packet(NULL, new_sock, &m, 0);
1648 __skb_dequeue(&sk->sk_receive_queue);
1649 __skb_queue_head(&new_sk->sk_receive_queue, buf);
1650 skb_set_owner_r(buf, new_sk);
1652 release_sock(new_sk);
1660 * shutdown - shutdown socket connection
1661 * @sock: socket structure
1662 * @how: direction to close (must be SHUT_RDWR)
1664 * Terminates connection (if necessary), then purges socket's receive queue.
1666 * Returns 0 on success, errno otherwise
1668 static int shutdown(struct socket *sock, int how)
1670 struct sock *sk = sock->sk;
1671 struct tipc_port *tport = tipc_sk_port(sk);
1672 struct sk_buff *buf;
1675 if (how != SHUT_RDWR)
1680 switch (sock->state) {
1685 /* Disconnect and send a 'FIN+' or 'FIN-' message to peer */
1686 buf = __skb_dequeue(&sk->sk_receive_queue);
1688 if (TIPC_SKB_CB(buf)->handle != NULL) {
1692 tipc_disconnect(tport->ref);
1693 tipc_reject_msg(buf, TIPC_CONN_SHUTDOWN);
1695 tipc_shutdown(tport->ref);
1698 sock->state = SS_DISCONNECTING;
1702 case SS_DISCONNECTING:
1704 /* Discard any unreceived messages */
1705 __skb_queue_purge(&sk->sk_receive_queue);
1707 /* Wake up anyone sleeping in poll */
1708 sk->sk_state_change(sk);
1721 * setsockopt - set socket option
1722 * @sock: socket structure
1723 * @lvl: option level
1724 * @opt: option identifier
1725 * @ov: pointer to new option value
1726 * @ol: length of option value
1728 * For stream sockets only, accepts and ignores all IPPROTO_TCP options
1729 * (to ease compatibility).
1731 * Returns 0 on success, errno otherwise
1733 static int setsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1736 struct sock *sk = sock->sk;
1737 struct tipc_port *tport = tipc_sk_port(sk);
1741 if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM))
1743 if (lvl != SOL_TIPC)
1744 return -ENOPROTOOPT;
1745 if (ol < sizeof(value))
1747 res = get_user(value, (u32 __user *)ov);
1754 case TIPC_IMPORTANCE:
1755 res = tipc_set_portimportance(tport->ref, value);
1757 case TIPC_SRC_DROPPABLE:
1758 if (sock->type != SOCK_STREAM)
1759 res = tipc_set_portunreliable(tport->ref, value);
1763 case TIPC_DEST_DROPPABLE:
1764 res = tipc_set_portunreturnable(tport->ref, value);
1766 case TIPC_CONN_TIMEOUT:
1767 tipc_sk(sk)->conn_timeout = value;
1768 /* no need to set "res", since already 0 at this point */
1780 * getsockopt - get socket option
1781 * @sock: socket structure
1782 * @lvl: option level
1783 * @opt: option identifier
1784 * @ov: receptacle for option value
1785 * @ol: receptacle for length of option value
1787 * For stream sockets only, returns 0 length result for all IPPROTO_TCP options
1788 * (to ease compatibility).
1790 * Returns 0 on success, errno otherwise
1792 static int getsockopt(struct socket *sock, int lvl, int opt, char __user *ov,
1795 struct sock *sk = sock->sk;
1796 struct tipc_port *tport = tipc_sk_port(sk);
1801 if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM))
1802 return put_user(0, ol);
1803 if (lvl != SOL_TIPC)
1804 return -ENOPROTOOPT;
1805 res = get_user(len, ol);
1812 case TIPC_IMPORTANCE:
1813 res = tipc_portimportance(tport->ref, &value);
1815 case TIPC_SRC_DROPPABLE:
1816 res = tipc_portunreliable(tport->ref, &value);
1818 case TIPC_DEST_DROPPABLE:
1819 res = tipc_portunreturnable(tport->ref, &value);
1821 case TIPC_CONN_TIMEOUT:
1822 value = tipc_sk(sk)->conn_timeout;
1823 /* no need to set "res", since already 0 at this point */
1825 case TIPC_NODE_RECVQ_DEPTH:
1826 value = 0; /* was tipc_queue_size, now obsolete */
1828 case TIPC_SOCK_RECVQ_DEPTH:
1829 value = skb_queue_len(&sk->sk_receive_queue);
1838 return res; /* "get" failed */
1840 if (len < sizeof(value))
1843 if (copy_to_user(ov, &value, sizeof(value)))
1846 return put_user(sizeof(value), ol);
1849 /* Protocol switches for the various types of TIPC sockets */
1851 static const struct proto_ops msg_ops = {
1852 .owner = THIS_MODULE,
1857 .socketpair = sock_no_socketpair,
1858 .accept = sock_no_accept,
1859 .getname = get_name,
1861 .ioctl = sock_no_ioctl,
1862 .listen = sock_no_listen,
1863 .shutdown = shutdown,
1864 .setsockopt = setsockopt,
1865 .getsockopt = getsockopt,
1866 .sendmsg = send_msg,
1867 .recvmsg = recv_msg,
1868 .mmap = sock_no_mmap,
1869 .sendpage = sock_no_sendpage
1872 static const struct proto_ops packet_ops = {
1873 .owner = THIS_MODULE,
1878 .socketpair = sock_no_socketpair,
1880 .getname = get_name,
1882 .ioctl = sock_no_ioctl,
1884 .shutdown = shutdown,
1885 .setsockopt = setsockopt,
1886 .getsockopt = getsockopt,
1887 .sendmsg = send_packet,
1888 .recvmsg = recv_msg,
1889 .mmap = sock_no_mmap,
1890 .sendpage = sock_no_sendpage
1893 static const struct proto_ops stream_ops = {
1894 .owner = THIS_MODULE,
1899 .socketpair = sock_no_socketpair,
1901 .getname = get_name,
1903 .ioctl = sock_no_ioctl,
1905 .shutdown = shutdown,
1906 .setsockopt = setsockopt,
1907 .getsockopt = getsockopt,
1908 .sendmsg = send_stream,
1909 .recvmsg = recv_stream,
1910 .mmap = sock_no_mmap,
1911 .sendpage = sock_no_sendpage
1914 static const struct net_proto_family tipc_family_ops = {
1915 .owner = THIS_MODULE,
1917 .create = tipc_sk_create
1920 static struct proto tipc_proto = {
1922 .owner = THIS_MODULE,
1923 .obj_size = sizeof(struct tipc_sock),
1924 .sysctl_rmem = sysctl_tipc_rmem
1927 static struct proto tipc_proto_kern = {
1929 .obj_size = sizeof(struct tipc_sock),
1930 .sysctl_rmem = sysctl_tipc_rmem
1934 * tipc_socket_init - initialize TIPC socket interface
1936 * Returns 0 on success, errno otherwise
1938 int tipc_socket_init(void)
1942 res = proto_register(&tipc_proto, 1);
1944 pr_err("Failed to register TIPC protocol type\n");
1948 res = sock_register(&tipc_family_ops);
1950 pr_err("Failed to register TIPC socket type\n");
1951 proto_unregister(&tipc_proto);
1955 sockets_enabled = 1;
1961 * tipc_socket_stop - stop TIPC socket interface
1963 void tipc_socket_stop(void)
1965 if (!sockets_enabled)
1968 sockets_enabled = 0;
1969 sock_unregister(tipc_family_ops.family);
1970 proto_unregister(&tipc_proto);