xref: /linux/net/tipc/subscr.h (revision ff10527e89826aaf76480ee47e6fd05213189963)
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
6b6f88d9cSJon Maloy  * Copyright (c) 2020, 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 
46fead3909SPaul Gortmaker struct tipc_subscription;
47df79d040SJon Maloy struct tipc_conn;
48e15f8804SAllan Stephens 
49b97bf3fdSPer Liden /**
50fead3909SPaul Gortmaker  * struct tipc_subscription - TIPC network topology subscription object
51*ff10527eSRandy Dunlap  * @kref: reference count for this subscription
52*ff10527eSRandy Dunlap  * @net: network namespace associated with subscription
535b06c85cSAllan Stephens  * @timer: timer governing subscription duration (optional)
54*ff10527eSRandy Dunlap  * @service_list: adjacent subscriptions in name sequence's subscription list
55da0a75e8SJon Maloy  * @sub_list: adjacent subscriptions in subscriber's subscription list
56b97bf3fdSPer Liden  * @evt: template for events generated by subscription
57*ff10527eSRandy Dunlap  * @conid: connection identifier of topology server
58*ff10527eSRandy Dunlap  * @inactive: true if this subscription is inactive
59*ff10527eSRandy Dunlap  * @lock: serialize up/down and timer events
60b97bf3fdSPer Liden  */
61fead3909SPaul Gortmaker struct tipc_subscription {
62d094c4d5SParthasarathy Bhuvaragan 	struct kref kref;
635c45ab24SJon Maloy 	struct net *net;
645b06c85cSAllan Stephens 	struct timer_list timer;
65218527feSJon Maloy 	struct list_head service_list;
66da0a75e8SJon Maloy 	struct list_head sub_list;
67b97bf3fdSPer Liden 	struct tipc_event evt;
68df79d040SJon Maloy 	int conid;
69df79d040SJon Maloy 	bool inactive;
70*ff10527eSRandy Dunlap 	spinlock_t lock;
71b97bf3fdSPer Liden };
72b97bf3fdSPer Liden 
735c45ab24SJon Maloy struct tipc_subscription *tipc_sub_subscribe(struct net *net,
74df79d040SJon Maloy 					     struct tipc_subscr *s,
758985ecc7SJon Maloy 					     int conid);
76242e82ccSJon Maloy void tipc_sub_unsubscribe(struct tipc_subscription *sub);
778985ecc7SJon Maloy 
78b6f88d9cSJon Maloy int tipc_sub_check_overlap(struct tipc_service_range *seq,
79b6f88d9cSJon Maloy 			   u32 found_lower, u32 found_upper);
80da0a75e8SJon Maloy void tipc_sub_report_overlap(struct tipc_subscription *sub,
818985ecc7SJon Maloy 			     u32 found_lower, u32 found_upper,
828985ecc7SJon Maloy 			     u32 event, u32 port, u32 node,
838985ecc7SJon Maloy 			     u32 scope, int must);
84526f5b85SJunwei Hu 
85526f5b85SJunwei Hu int __net_init tipc_topsrv_init_net(struct net *net);
86526f5b85SJunwei Hu void __net_exit tipc_topsrv_exit_net(struct net *net);
87b97bf3fdSPer Liden 
88da0a75e8SJon Maloy void tipc_sub_put(struct tipc_subscription *subscription);
89da0a75e8SJon Maloy void tipc_sub_get(struct tipc_subscription *subscription);
907efea60dSYing Xue 
918985ecc7SJon Maloy #define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL)
928985ecc7SJon Maloy 
938985ecc7SJon Maloy /* tipc_sub_read - return field_ of struct sub_ in host endian format
948985ecc7SJon Maloy  */
958985ecc7SJon Maloy #define tipc_sub_read(sub_, field_)					\
968985ecc7SJon Maloy 	({								\
978985ecc7SJon Maloy 		struct tipc_subscr *sub__ = sub_;			\
988985ecc7SJon Maloy 		u32 val__ = (sub__)->field_;				\
998985ecc7SJon Maloy 		int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);	\
1008985ecc7SJon Maloy 		(swap_ ? swab32(val__) : val__);			\
1018985ecc7SJon Maloy 	})
1028985ecc7SJon Maloy 
10388690b10STuong Lien /* tipc_sub_write - write val_ to field_ of struct sub_ in user endian format
10488690b10STuong Lien  */
10588690b10STuong Lien #define tipc_sub_write(sub_, field_, val_)				\
10688690b10STuong Lien 	({								\
10788690b10STuong Lien 		struct tipc_subscr *sub__ = sub_;			\
10888690b10STuong Lien 		u32 val__ = val_;					\
10988690b10STuong Lien 		int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);	\
11088690b10STuong Lien 		(sub__)->field_ = swap_ ? swab32(val__) : val__;	\
11188690b10STuong Lien 	})
11288690b10STuong Lien 
1138985ecc7SJon Maloy /* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format
1148985ecc7SJon Maloy  */
1158985ecc7SJon Maloy #define tipc_evt_write(evt_, field_, val_)				\
1168985ecc7SJon Maloy 	({								\
1178985ecc7SJon Maloy 		struct tipc_event *evt__ = evt_;			\
1188985ecc7SJon Maloy 		u32 val__ = val_;					\
1198985ecc7SJon Maloy 		int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK));	\
1208985ecc7SJon Maloy 		(evt__)->field_ = swap_ ? swab32(val__) : val__;	\
1218985ecc7SJon Maloy 	})
1228985ecc7SJon Maloy 
123b97bf3fdSPer Liden #endif
124