162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * net/tipc/subscr.h: Include file for TIPC network topology service
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2003-2017, Ericsson AB
562306a36Sopenharmony_ci * Copyright (c) 2005-2007, 2012-2013, Wind River Systems
662306a36Sopenharmony_ci * Copyright (c) 2020-2021, Red Hat Inc
762306a36Sopenharmony_ci * All rights reserved.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
1062306a36Sopenharmony_ci * modification, are permitted provided that the following conditions are met:
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1362306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
1462306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
1562306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
1662306a36Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
1762306a36Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its
1862306a36Sopenharmony_ci *    contributors may be used to endorse or promote products derived from
1962306a36Sopenharmony_ci *    this software without specific prior written permission.
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2262306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2362306a36Sopenharmony_ci * Software Foundation.
2462306a36Sopenharmony_ci *
2562306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2662306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2762306a36Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2862306a36Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2962306a36Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3062306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3162306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3262306a36Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3362306a36Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3462306a36Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3562306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE.
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#ifndef _TIPC_SUBSCR_H
3962306a36Sopenharmony_ci#define _TIPC_SUBSCR_H
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#include "topsrv.h"
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define TIPC_MAX_SUBSCR         65535
4462306a36Sopenharmony_ci#define TIPC_MAX_PUBL           65535
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cistruct publication;
4762306a36Sopenharmony_cistruct tipc_subscription;
4862306a36Sopenharmony_cistruct tipc_conn;
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/**
5162306a36Sopenharmony_ci * struct tipc_subscription - TIPC network topology subscription object
5262306a36Sopenharmony_ci * @s: host-endian copy of the user subscription
5362306a36Sopenharmony_ci * @evt: template for events generated by subscription
5462306a36Sopenharmony_ci * @kref: reference count for this subscription
5562306a36Sopenharmony_ci * @net: network namespace associated with subscription
5662306a36Sopenharmony_ci * @timer: timer governing subscription duration (optional)
5762306a36Sopenharmony_ci * @service_list: adjacent subscriptions in name sequence's subscription list
5862306a36Sopenharmony_ci * @sub_list: adjacent subscriptions in subscriber's subscription list
5962306a36Sopenharmony_ci * @conid: connection identifier of topology server
6062306a36Sopenharmony_ci * @inactive: true if this subscription is inactive
6162306a36Sopenharmony_ci * @lock: serialize up/down and timer events
6262306a36Sopenharmony_ci */
6362306a36Sopenharmony_cistruct tipc_subscription {
6462306a36Sopenharmony_ci	struct tipc_subscr s;
6562306a36Sopenharmony_ci	struct tipc_event evt;
6662306a36Sopenharmony_ci	struct kref kref;
6762306a36Sopenharmony_ci	struct net *net;
6862306a36Sopenharmony_ci	struct timer_list timer;
6962306a36Sopenharmony_ci	struct list_head service_list;
7062306a36Sopenharmony_ci	struct list_head sub_list;
7162306a36Sopenharmony_ci	int conid;
7262306a36Sopenharmony_ci	bool inactive;
7362306a36Sopenharmony_ci	spinlock_t lock;
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cistruct tipc_subscription *tipc_sub_subscribe(struct net *net,
7762306a36Sopenharmony_ci					     struct tipc_subscr *s,
7862306a36Sopenharmony_ci					     int conid);
7962306a36Sopenharmony_civoid tipc_sub_unsubscribe(struct tipc_subscription *sub);
8062306a36Sopenharmony_civoid tipc_sub_report_overlap(struct tipc_subscription *sub,
8162306a36Sopenharmony_ci			     struct publication *p,
8262306a36Sopenharmony_ci			     u32 event, bool must);
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ciint __net_init tipc_topsrv_init_net(struct net *net);
8562306a36Sopenharmony_civoid __net_exit tipc_topsrv_exit_net(struct net *net);
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_civoid tipc_sub_put(struct tipc_subscription *subscription);
8862306a36Sopenharmony_civoid tipc_sub_get(struct tipc_subscription *subscription);
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL)
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* tipc_sub_read - return field_ of struct sub_ in host endian format
9362306a36Sopenharmony_ci */
9462306a36Sopenharmony_ci#define tipc_sub_read(sub_, field_)					\
9562306a36Sopenharmony_ci	({								\
9662306a36Sopenharmony_ci		struct tipc_subscr *sub__ = sub_;			\
9762306a36Sopenharmony_ci		u32 val__ = (sub__)->field_;				\
9862306a36Sopenharmony_ci		int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);	\
9962306a36Sopenharmony_ci		(swap_ ? swab32(val__) : val__);			\
10062306a36Sopenharmony_ci	})
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/* tipc_sub_write - write val_ to field_ of struct sub_ in user endian format
10362306a36Sopenharmony_ci */
10462306a36Sopenharmony_ci#define tipc_sub_write(sub_, field_, val_)				\
10562306a36Sopenharmony_ci	({								\
10662306a36Sopenharmony_ci		struct tipc_subscr *sub__ = sub_;			\
10762306a36Sopenharmony_ci		u32 val__ = val_;					\
10862306a36Sopenharmony_ci		int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);	\
10962306a36Sopenharmony_ci		(sub__)->field_ = swap_ ? swab32(val__) : val__;	\
11062306a36Sopenharmony_ci	})
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_ci#define tipc_evt_write(evt_, field_, val_)				\
11562306a36Sopenharmony_ci	({								\
11662306a36Sopenharmony_ci		struct tipc_event *evt__ = evt_;			\
11762306a36Sopenharmony_ci		u32 val__ = val_;					\
11862306a36Sopenharmony_ci		int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK));	\
11962306a36Sopenharmony_ci		(evt__)->field_ = swap_ ? swab32(val__) : val__;	\
12062306a36Sopenharmony_ci	})
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci#endif
123