xref: /linux-6.15/net/tipc/socket.h (revision 2e84c60b)
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 <net/sock.h>
39*2e84c60bSJon Paul Maloy #include "msg.h"
408826cde6SJon Paul Maloy 
41ac0074eeSJon Paul Maloy #define TIPC_CONN_OK      0
42ac0074eeSJon Paul Maloy #define TIPC_CONN_PROBING 1
43*2e84c60bSJon Paul Maloy #define TIPC_CONNACK_INTV         256
44*2e84c60bSJon Paul Maloy #define TIPC_FLOWCTRL_WIN        (TIPC_CONNACK_INTV * 2)
45*2e84c60bSJon Paul Maloy #define TIPC_CONN_OVERLOAD_LIMIT ((TIPC_FLOWCTRL_WIN * 2 + 1) * \
46*2e84c60bSJon Paul Maloy 				  SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE))
47*2e84c60bSJon Paul Maloy 
48*2e84c60bSJon Paul Maloy /**
49*2e84c60bSJon Paul Maloy  * struct tipc_port - TIPC port structure
50*2e84c60bSJon Paul Maloy  * @lock: pointer to spinlock for controlling access to port
51*2e84c60bSJon Paul Maloy  * @connected: non-zero if port is currently connected to a peer port
52*2e84c60bSJon Paul Maloy  * @conn_type: TIPC type used when connection was established
53*2e84c60bSJon Paul Maloy  * @conn_instance: TIPC instance used when connection was established
54*2e84c60bSJon Paul Maloy  * @published: non-zero if port has one or more associated names
55*2e84c60bSJon Paul Maloy  * @max_pkt: maximum packet size "hint" used when building messages sent by port
56*2e84c60bSJon Paul Maloy  * @ref: unique reference to port in TIPC object registry
57*2e84c60bSJon Paul Maloy  * @phdr: preformatted message header used when sending messages
58*2e84c60bSJon Paul Maloy  * @port_list: adjacent ports in TIPC's global list of ports
59*2e84c60bSJon Paul Maloy  * @publications: list of publications for port
60*2e84c60bSJon Paul Maloy  * @pub_count: total # of publications port has made during its lifetime
61*2e84c60bSJon Paul Maloy  * @probing_state:
62*2e84c60bSJon Paul Maloy  * @probing_interval:
63*2e84c60bSJon Paul Maloy  * @timer_ref:
64*2e84c60bSJon Paul Maloy  */
65*2e84c60bSJon Paul Maloy struct tipc_port {
66*2e84c60bSJon Paul Maloy 	int connected;
67*2e84c60bSJon Paul Maloy 	u32 conn_type;
68*2e84c60bSJon Paul Maloy 	u32 conn_instance;
69*2e84c60bSJon Paul Maloy 	int published;
70*2e84c60bSJon Paul Maloy 	u32 max_pkt;
71*2e84c60bSJon Paul Maloy 	u32 ref;
72*2e84c60bSJon Paul Maloy 	struct tipc_msg phdr;
73*2e84c60bSJon Paul Maloy 	struct list_head port_list;
74*2e84c60bSJon Paul Maloy 	struct list_head publications;
75*2e84c60bSJon Paul Maloy 	u32 pub_count;
76*2e84c60bSJon Paul Maloy 	u32 probing_state;
77*2e84c60bSJon Paul Maloy 	u32 probing_interval;
78*2e84c60bSJon Paul Maloy 	struct timer_list timer;
79*2e84c60bSJon Paul Maloy };
80ac0074eeSJon Paul Maloy 
818826cde6SJon Paul Maloy /**
828826cde6SJon Paul Maloy  * struct tipc_sock - TIPC socket structure
838826cde6SJon Paul Maloy  * @sk: socket - interacts with 'port' and with user via the socket API
848826cde6SJon Paul Maloy  * @port: port - interacts with 'sk' and with the rest of the TIPC stack
858826cde6SJon Paul Maloy  * @peer_name: the peer of the connection, if any
868826cde6SJon Paul Maloy  * @conn_timeout: the time we can wait for an unresponded setup request
874f4482dcSJon Paul Maloy  * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue
8860120526SJon Paul Maloy  * @link_cong: non-zero if owner must sleep because of link congestion
8960120526SJon Paul Maloy  * @sent_unacked: # messages sent by socket, and not yet acked by peer
9060120526SJon Paul Maloy  * @rcv_unacked: # messages read by user, but not yet acked back to peer
918826cde6SJon Paul Maloy  */
928826cde6SJon Paul Maloy 
938826cde6SJon Paul Maloy struct tipc_sock {
948826cde6SJon Paul Maloy 	struct sock sk;
958826cde6SJon Paul Maloy 	struct tipc_port port;
968826cde6SJon Paul Maloy 	unsigned int conn_timeout;
974f4482dcSJon Paul Maloy 	atomic_t dupl_rcvcnt;
9850100a5eSJon Paul Maloy 	bool link_cong;
9960120526SJon Paul Maloy 	uint sent_unacked;
10060120526SJon Paul Maloy 	uint rcv_unacked;
1018826cde6SJon Paul Maloy };
1028826cde6SJon Paul Maloy 
1038826cde6SJon Paul Maloy static inline struct tipc_sock *tipc_sk(const struct sock *sk)
1048826cde6SJon Paul Maloy {
1058826cde6SJon Paul Maloy 	return container_of(sk, struct tipc_sock, sk);
1068826cde6SJon Paul Maloy }
1078826cde6SJon Paul Maloy 
10858ed9442SJon Paul Maloy static inline struct tipc_sock *tipc_port_to_sock(const struct tipc_port *port)
1098826cde6SJon Paul Maloy {
11058ed9442SJon Paul Maloy 	return container_of(port, struct tipc_sock, port);
1118826cde6SJon Paul Maloy }
1128826cde6SJon Paul Maloy 
11360120526SJon Paul Maloy static inline int tipc_sk_conn_cong(struct tipc_sock *tsk)
11460120526SJon Paul Maloy {
11560120526SJon Paul Maloy 	return tsk->sent_unacked >= TIPC_FLOWCTRL_WIN;
11660120526SJon Paul Maloy }
11760120526SJon Paul Maloy 
1189816f061SJon Paul Maloy int tipc_sk_rcv(struct sk_buff *buf);
1195a9ee0beSJon Paul Maloy struct sk_buff *tipc_sk_socks_show(void);
120078bec82SJon Paul Maloy void tipc_sk_mcast_rcv(struct sk_buff *buf);
1215a9ee0beSJon Paul Maloy void tipc_sk_reinit(void);
122078bec82SJon Paul Maloy 
1238826cde6SJon Paul Maloy #endif
124