xref: /linux/net/tipc/subscr.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
1b97bf3fdSPer Liden /*
25b06c85cSAllan Stephens  * net/tipc/subscr.h: Include file for TIPC network topology service
3b97bf3fdSPer Liden  *
4242e82ccSJon Maloy  * Copyright (c) 2003-2017, Ericsson AB
513a2e898SYing Xue  * Copyright (c) 2005-2007, 2012-2013, Wind River Systems
609f78b85SJon Maloy  * Copyright (c) 2020-2021, Red Hat Inc
7b97bf3fdSPer Liden  * All rights reserved.
8b97bf3fdSPer Liden  *
9b97bf3fdSPer Liden  * Redistribution and use in source and binary forms, with or without
10b97bf3fdSPer Liden  * modification, are permitted provided that the following conditions are met:
11b97bf3fdSPer Liden  *
129ea1fd3cSPer Liden  * 1. Redistributions of source code must retain the above copyright
139ea1fd3cSPer Liden  *    notice, this list of conditions and the following disclaimer.
149ea1fd3cSPer Liden  * 2. Redistributions in binary form must reproduce the above copyright
159ea1fd3cSPer Liden  *    notice, this list of conditions and the following disclaimer in the
169ea1fd3cSPer Liden  *    documentation and/or other materials provided with the distribution.
179ea1fd3cSPer Liden  * 3. Neither the names of the copyright holders nor the names of its
189ea1fd3cSPer Liden  *    contributors may be used to endorse or promote products derived from
199ea1fd3cSPer Liden  *    this software without specific prior written permission.
209ea1fd3cSPer Liden  *
219ea1fd3cSPer Liden  * Alternatively, this software may be distributed under the terms of the
229ea1fd3cSPer Liden  * GNU General Public License ("GPL") version 2 as published by the Free
239ea1fd3cSPer Liden  * Software Foundation.
24b97bf3fdSPer Liden  *
25b97bf3fdSPer Liden  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26b97bf3fdSPer Liden  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27b97bf3fdSPer Liden  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28b97bf3fdSPer Liden  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29b97bf3fdSPer Liden  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30b97bf3fdSPer Liden  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31b97bf3fdSPer Liden  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32b97bf3fdSPer Liden  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33b97bf3fdSPer Liden  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34b97bf3fdSPer Liden  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35b97bf3fdSPer Liden  * POSSIBILITY OF SUCH DAMAGE.
36b97bf3fdSPer Liden  */
37b97bf3fdSPer Liden 
38b97bf3fdSPer Liden #ifndef _TIPC_SUBSCR_H
39b97bf3fdSPer Liden #define _TIPC_SUBSCR_H
40b97bf3fdSPer Liden 
41026321c6SJon Maloy #include "topsrv.h"
4213a2e898SYing Xue 
43242e82ccSJon Maloy #define TIPC_MAX_SUBSCR         65535
44218527feSJon Maloy #define TIPC_MAX_PUBL           65535
45859fc7c0SYing Xue 
4609f78b85SJon Maloy struct publication;
47fead3909SPaul Gortmaker struct tipc_subscription;
48df79d040SJon Maloy struct tipc_conn;
49e15f8804SAllan Stephens 
50b97bf3fdSPer Liden /**
51fead3909SPaul Gortmaker  * struct tipc_subscription - TIPC network topology subscription object
52*02fdc14dSJon Maloy  * @s: host-endian copy of the user subscription
53*02fdc14dSJon Maloy  * @evt: template for events generated by subscription
54ff10527eSRandy Dunlap  * @kref: reference count for this subscription
55ff10527eSRandy Dunlap  * @net: network namespace associated with subscription
565b06c85cSAllan Stephens  * @timer: timer governing subscription duration (optional)
57ff10527eSRandy Dunlap  * @service_list: adjacent subscriptions in name sequence's subscription list
58da0a75e8SJon Maloy  * @sub_list: adjacent subscriptions in subscriber's subscription list
59ff10527eSRandy Dunlap  * @conid: connection identifier of topology server
60ff10527eSRandy Dunlap  * @inactive: true if this subscription is inactive
61ff10527eSRandy Dunlap  * @lock: serialize up/down and timer events
62b97bf3fdSPer Liden  */
63fead3909SPaul Gortmaker struct tipc_subscription {
64429189acSJon Maloy 	struct tipc_subscr s;
65429189acSJon Maloy 	struct tipc_event evt;
66d094c4d5SParthasarathy Bhuvaragan 	struct kref kref;
675c45ab24SJon Maloy 	struct net *net;
685b06c85cSAllan Stephens 	struct timer_list timer;
69218527feSJon Maloy 	struct list_head service_list;
70da0a75e8SJon Maloy 	struct list_head sub_list;
71df79d040SJon Maloy 	int conid;
72df79d040SJon Maloy 	bool inactive;
73ff10527eSRandy Dunlap 	spinlock_t lock;
74b97bf3fdSPer Liden };
75b97bf3fdSPer Liden 
765c45ab24SJon Maloy struct tipc_subscription *tipc_sub_subscribe(struct net *net,
77df79d040SJon Maloy 					     struct tipc_subscr *s,
788985ecc7SJon Maloy 					     int conid);
79242e82ccSJon Maloy void tipc_sub_unsubscribe(struct tipc_subscription *sub);
80da0a75e8SJon Maloy void tipc_sub_report_overlap(struct tipc_subscription *sub,
8109f78b85SJon Maloy 			     struct publication *p,
8209f78b85SJon Maloy 			     u32 event, bool must);
83526f5b85SJunwei Hu 
84526f5b85SJunwei Hu int __net_init tipc_topsrv_init_net(struct net *net);
85526f5b85SJunwei Hu void __net_exit tipc_topsrv_exit_net(struct net *net);
86b97bf3fdSPer Liden 
87da0a75e8SJon Maloy void tipc_sub_put(struct tipc_subscription *subscription);
88da0a75e8SJon Maloy void tipc_sub_get(struct tipc_subscription *subscription);
897efea60dSYing Xue 
908985ecc7SJon Maloy #define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL)
918985ecc7SJon Maloy 
928985ecc7SJon Maloy /* tipc_sub_read - return field_ of struct sub_ in host endian format
938985ecc7SJon Maloy  */
948985ecc7SJon Maloy #define tipc_sub_read(sub_, field_)					\
958985ecc7SJon Maloy 	({								\
968985ecc7SJon Maloy 		struct tipc_subscr *sub__ = sub_;			\
978985ecc7SJon Maloy 		u32 val__ = (sub__)->field_;				\
988985ecc7SJon Maloy 		int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);	\
998985ecc7SJon Maloy 		(swap_ ? swab32(val__) : val__);			\
1008985ecc7SJon Maloy 	})
1018985ecc7SJon Maloy 
10288690b10STuong Lien /* tipc_sub_write - write val_ to field_ of struct sub_ in user endian format
10388690b10STuong Lien  */
10488690b10STuong Lien #define tipc_sub_write(sub_, field_, val_)				\
10588690b10STuong Lien 	({								\
10688690b10STuong Lien 		struct tipc_subscr *sub__ = sub_;			\
10788690b10STuong Lien 		u32 val__ = val_;					\
10888690b10STuong Lien 		int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);	\
10988690b10STuong Lien 		(sub__)->field_ = swap_ ? swab32(val__) : val__;	\
11088690b10STuong Lien 	})
11188690b10STuong Lien 
1128985ecc7SJon Maloy /* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format
1138985ecc7SJon Maloy  */
1148985ecc7SJon Maloy #define tipc_evt_write(evt_, field_, val_)				\
1158985ecc7SJon Maloy 	({								\
1168985ecc7SJon Maloy 		struct tipc_event *evt__ = evt_;			\
1178985ecc7SJon Maloy 		u32 val__ = val_;					\
1188985ecc7SJon Maloy 		int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK));	\
1198985ecc7SJon Maloy 		(evt__)->field_ = swap_ ? swab32(val__) : val__;	\
1208985ecc7SJon Maloy 	})
1218985ecc7SJon Maloy 
122b97bf3fdSPer Liden #endif
123