xref: /linux-6.15/net/tipc/socket.h (revision 50100a5e)
18826cde6SJon Paul Maloy /* net/tipc/socket.h: Include file for TIPC socket code
28826cde6SJon Paul Maloy  *
38826cde6SJon Paul Maloy  * Copyright (c) 2014, Ericsson AB
48826cde6SJon Paul Maloy  * All rights reserved.
58826cde6SJon Paul Maloy  *
68826cde6SJon Paul Maloy  * Redistribution and use in source and binary forms, with or without
78826cde6SJon Paul Maloy  * modification, are permitted provided that the following conditions are met:
88826cde6SJon Paul Maloy  *
98826cde6SJon Paul Maloy  * 1. Redistributions of source code must retain the above copyright
108826cde6SJon Paul Maloy  *    notice, this list of conditions and the following disclaimer.
118826cde6SJon Paul Maloy  * 2. Redistributions in binary form must reproduce the above copyright
128826cde6SJon Paul Maloy  *    notice, this list of conditions and the following disclaimer in the
138826cde6SJon Paul Maloy  *    documentation and/or other materials provided with the distribution.
148826cde6SJon Paul Maloy  * 3. Neither the names of the copyright holders nor the names of its
158826cde6SJon Paul Maloy  *    contributors may be used to endorse or promote products derived from
168826cde6SJon Paul Maloy  *    this software without specific prior written permission.
178826cde6SJon Paul Maloy  *
188826cde6SJon Paul Maloy  * Alternatively, this software may be distributed under the terms of the
198826cde6SJon Paul Maloy  * GNU General Public License ("GPL") version 2 as published by the Free
208826cde6SJon Paul Maloy  * Software Foundation.
218826cde6SJon Paul Maloy  *
228826cde6SJon Paul Maloy  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
238826cde6SJon Paul Maloy  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
248826cde6SJon Paul Maloy  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
258826cde6SJon Paul Maloy  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
268826cde6SJon Paul Maloy  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
278826cde6SJon Paul Maloy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
288826cde6SJon Paul Maloy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
298826cde6SJon Paul Maloy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
308826cde6SJon Paul Maloy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
318826cde6SJon Paul Maloy  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
328826cde6SJon Paul Maloy  * POSSIBILITY OF SUCH DAMAGE.
338826cde6SJon Paul Maloy  */
348826cde6SJon Paul Maloy 
358826cde6SJon Paul Maloy #ifndef _TIPC_SOCK_H
368826cde6SJon Paul Maloy #define _TIPC_SOCK_H
378826cde6SJon Paul Maloy 
388826cde6SJon Paul Maloy #include "port.h"
398826cde6SJon Paul Maloy #include <net/sock.h>
408826cde6SJon Paul Maloy 
41ac0074eeSJon Paul Maloy #define TIPC_CONN_OK      0
42ac0074eeSJon Paul Maloy #define TIPC_CONN_PROBING 1
43ac0074eeSJon Paul Maloy 
448826cde6SJon Paul Maloy /**
458826cde6SJon Paul Maloy  * struct tipc_sock - TIPC socket structure
468826cde6SJon Paul Maloy  * @sk: socket - interacts with 'port' and with user via the socket API
478826cde6SJon Paul Maloy  * @port: port - interacts with 'sk' and with the rest of the TIPC stack
488826cde6SJon Paul Maloy  * @peer_name: the peer of the connection, if any
498826cde6SJon Paul Maloy  * @conn_timeout: the time we can wait for an unresponded setup request
504f4482dcSJon Paul Maloy  * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue
5160120526SJon Paul Maloy  * @link_cong: non-zero if owner must sleep because of link congestion
5260120526SJon Paul Maloy  * @sent_unacked: # messages sent by socket, and not yet acked by peer
5360120526SJon Paul Maloy  * @rcv_unacked: # messages read by user, but not yet acked back to peer
548826cde6SJon Paul Maloy  */
558826cde6SJon Paul Maloy 
568826cde6SJon Paul Maloy struct tipc_sock {
578826cde6SJon Paul Maloy 	struct sock sk;
588826cde6SJon Paul Maloy 	struct tipc_port port;
598826cde6SJon Paul Maloy 	unsigned int conn_timeout;
604f4482dcSJon Paul Maloy 	atomic_t dupl_rcvcnt;
61*50100a5eSJon Paul Maloy 	bool link_cong;
6260120526SJon Paul Maloy 	uint sent_unacked;
6360120526SJon Paul Maloy 	uint rcv_unacked;
648826cde6SJon Paul Maloy };
658826cde6SJon Paul Maloy 
668826cde6SJon Paul Maloy static inline struct tipc_sock *tipc_sk(const struct sock *sk)
678826cde6SJon Paul Maloy {
688826cde6SJon Paul Maloy 	return container_of(sk, struct tipc_sock, sk);
698826cde6SJon Paul Maloy }
708826cde6SJon Paul Maloy 
7158ed9442SJon Paul Maloy static inline struct tipc_sock *tipc_port_to_sock(const struct tipc_port *port)
728826cde6SJon Paul Maloy {
7358ed9442SJon Paul Maloy 	return container_of(port, struct tipc_sock, port);
748826cde6SJon Paul Maloy }
758826cde6SJon Paul Maloy 
7660120526SJon Paul Maloy static inline int tipc_sk_conn_cong(struct tipc_sock *tsk)
7760120526SJon Paul Maloy {
7860120526SJon Paul Maloy 	return tsk->sent_unacked >= TIPC_FLOWCTRL_WIN;
7960120526SJon Paul Maloy }
8060120526SJon Paul Maloy 
819816f061SJon Paul Maloy int tipc_sk_rcv(struct sk_buff *buf);
8224be34b5SJon Paul Maloy 
83078bec82SJon Paul Maloy void tipc_sk_mcast_rcv(struct sk_buff *buf);
84078bec82SJon Paul Maloy 
858826cde6SJon Paul Maloy #endif
86