xref: /linux-6.15/net/tipc/socket.h (revision 24be34b5)
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 
418826cde6SJon Paul Maloy /**
428826cde6SJon Paul Maloy  * struct tipc_sock - TIPC socket structure
438826cde6SJon Paul Maloy  * @sk: socket - interacts with 'port' and with user via the socket API
448826cde6SJon Paul Maloy  * @port: port - interacts with 'sk' and with the rest of the TIPC stack
458826cde6SJon Paul Maloy  * @peer_name: the peer of the connection, if any
468826cde6SJon Paul Maloy  * @conn_timeout: the time we can wait for an unresponded setup request
478826cde6SJon Paul Maloy  */
488826cde6SJon Paul Maloy 
498826cde6SJon Paul Maloy struct tipc_sock {
508826cde6SJon Paul Maloy 	struct sock sk;
518826cde6SJon Paul Maloy 	struct tipc_port port;
528826cde6SJon Paul Maloy 	unsigned int conn_timeout;
538826cde6SJon Paul Maloy };
548826cde6SJon Paul Maloy 
558826cde6SJon Paul Maloy static inline struct tipc_sock *tipc_sk(const struct sock *sk)
568826cde6SJon Paul Maloy {
578826cde6SJon Paul Maloy 	return container_of(sk, struct tipc_sock, sk);
588826cde6SJon Paul Maloy }
598826cde6SJon Paul Maloy 
608826cde6SJon Paul Maloy static inline struct tipc_port *tipc_sk_port(const struct sock *sk)
618826cde6SJon Paul Maloy {
628826cde6SJon Paul Maloy 	return &(tipc_sk(sk)->port);
638826cde6SJon Paul Maloy }
648826cde6SJon Paul Maloy 
658826cde6SJon Paul Maloy static inline struct sock *tipc_port_to_sk(const struct tipc_port *port)
668826cde6SJon Paul Maloy {
678826cde6SJon Paul Maloy 	return &(container_of(port, struct tipc_sock, port))->sk;
688826cde6SJon Paul Maloy }
698826cde6SJon Paul Maloy 
70*24be34b5SJon Paul Maloy static inline void tipc_sk_wakeup(struct sock *sk)
71*24be34b5SJon Paul Maloy {
72*24be34b5SJon Paul Maloy 	sk->sk_write_space(sk);
73*24be34b5SJon Paul Maloy }
74*24be34b5SJon Paul Maloy 
75*24be34b5SJon Paul Maloy u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf);
76*24be34b5SJon Paul Maloy 
778826cde6SJon Paul Maloy #endif
78