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 6b97bf3fdSPer Liden * All rights reserved. 7b97bf3fdSPer Liden * 8b97bf3fdSPer Liden * Redistribution and use in source and binary forms, with or without 9b97bf3fdSPer Liden * modification, are permitted provided that the following conditions are met: 10b97bf3fdSPer Liden * 119ea1fd3cSPer Liden * 1. Redistributions of source code must retain the above copyright 129ea1fd3cSPer Liden * notice, this list of conditions and the following disclaimer. 139ea1fd3cSPer Liden * 2. Redistributions in binary form must reproduce the above copyright 149ea1fd3cSPer Liden * notice, this list of conditions and the following disclaimer in the 159ea1fd3cSPer Liden * documentation and/or other materials provided with the distribution. 169ea1fd3cSPer Liden * 3. Neither the names of the copyright holders nor the names of its 179ea1fd3cSPer Liden * contributors may be used to endorse or promote products derived from 189ea1fd3cSPer Liden * this software without specific prior written permission. 199ea1fd3cSPer Liden * 209ea1fd3cSPer Liden * Alternatively, this software may be distributed under the terms of the 219ea1fd3cSPer Liden * GNU General Public License ("GPL") version 2 as published by the Free 229ea1fd3cSPer Liden * Software Foundation. 23b97bf3fdSPer Liden * 24b97bf3fdSPer Liden * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25b97bf3fdSPer Liden * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26b97bf3fdSPer Liden * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27b97bf3fdSPer Liden * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 28b97bf3fdSPer Liden * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29b97bf3fdSPer Liden * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30b97bf3fdSPer Liden * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31b97bf3fdSPer Liden * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32b97bf3fdSPer Liden * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33b97bf3fdSPer Liden * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34b97bf3fdSPer Liden * POSSIBILITY OF SUCH DAMAGE. 35b97bf3fdSPer Liden */ 36b97bf3fdSPer Liden 37b97bf3fdSPer Liden #ifndef _TIPC_SUBSCR_H 38b97bf3fdSPer Liden #define _TIPC_SUBSCR_H 39b97bf3fdSPer Liden 40026321c6SJon Maloy #include "topsrv.h" 4113a2e898SYing Xue 42242e82ccSJon Maloy #define TIPC_MAX_SUBSCR 65535 43218527feSJon Maloy #define TIPC_MAX_PUBL 65535 44859fc7c0SYing Xue 45fead3909SPaul Gortmaker struct tipc_subscription; 46df79d040SJon Maloy struct tipc_conn; 47e15f8804SAllan Stephens 48b97bf3fdSPer Liden /** 49fead3909SPaul Gortmaker * struct tipc_subscription - TIPC network topology subscription object 5013a2e898SYing Xue * @subscriber: pointer to its subscriber 51b97bf3fdSPer Liden * @seq: name sequence associated with subscription 525b06c85cSAllan Stephens * @timer: timer governing subscription duration (optional) 535b06c85cSAllan Stephens * @nameseq_list: adjacent subscriptions in name sequence's subscription list 54da0a75e8SJon Maloy * @sub_list: adjacent subscriptions in subscriber's subscription list 55b97bf3fdSPer Liden * @evt: template for events generated by subscription 56b97bf3fdSPer Liden */ 57fead3909SPaul Gortmaker struct tipc_subscription { 58d094c4d5SParthasarathy Bhuvaragan struct kref kref; 595c45ab24SJon Maloy struct net *net; 605b06c85cSAllan Stephens struct timer_list timer; 61218527feSJon Maloy struct list_head service_list; 62da0a75e8SJon Maloy struct list_head sub_list; 63b97bf3fdSPer Liden struct tipc_event evt; 64df79d040SJon Maloy int conid; 65df79d040SJon Maloy bool inactive; 66df79d040SJon Maloy spinlock_t lock; /* serialize up/down and timer events */ 67b97bf3fdSPer Liden }; 68b97bf3fdSPer Liden 695c45ab24SJon Maloy struct tipc_subscription *tipc_sub_subscribe(struct net *net, 70df79d040SJon Maloy struct tipc_subscr *s, 718985ecc7SJon Maloy int conid); 72242e82ccSJon Maloy void tipc_sub_unsubscribe(struct tipc_subscription *sub); 738985ecc7SJon Maloy 74da0a75e8SJon Maloy int tipc_sub_check_overlap(struct tipc_name_seq *seq, u32 found_lower, 75b97bf3fdSPer Liden u32 found_upper); 76da0a75e8SJon Maloy void tipc_sub_report_overlap(struct tipc_subscription *sub, 778985ecc7SJon Maloy u32 found_lower, u32 found_upper, 788985ecc7SJon Maloy u32 event, u32 port, u32 node, 798985ecc7SJon Maloy u32 scope, int must); 80526f5b85SJunwei Hu 81526f5b85SJunwei Hu int __net_init tipc_topsrv_init_net(struct net *net); 82526f5b85SJunwei Hu void __net_exit tipc_topsrv_exit_net(struct net *net); 83b97bf3fdSPer Liden 84da0a75e8SJon Maloy void tipc_sub_put(struct tipc_subscription *subscription); 85da0a75e8SJon Maloy void tipc_sub_get(struct tipc_subscription *subscription); 867efea60dSYing Xue 878985ecc7SJon Maloy #define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL) 888985ecc7SJon Maloy 898985ecc7SJon Maloy /* tipc_sub_read - return field_ of struct sub_ in host endian format 908985ecc7SJon Maloy */ 918985ecc7SJon Maloy #define tipc_sub_read(sub_, field_) \ 928985ecc7SJon Maloy ({ \ 938985ecc7SJon Maloy struct tipc_subscr *sub__ = sub_; \ 948985ecc7SJon Maloy u32 val__ = (sub__)->field_; \ 958985ecc7SJon Maloy int swap_ = !((sub__)->filter & TIPC_FILTER_MASK); \ 968985ecc7SJon Maloy (swap_ ? swab32(val__) : val__); \ 978985ecc7SJon Maloy }) 988985ecc7SJon Maloy 99*88690b10STuong Lien /* tipc_sub_write - write val_ to field_ of struct sub_ in user endian format 100*88690b10STuong Lien */ 101*88690b10STuong Lien #define tipc_sub_write(sub_, field_, val_) \ 102*88690b10STuong Lien ({ \ 103*88690b10STuong Lien struct tipc_subscr *sub__ = sub_; \ 104*88690b10STuong Lien u32 val__ = val_; \ 105*88690b10STuong Lien int swap_ = !((sub__)->filter & TIPC_FILTER_MASK); \ 106*88690b10STuong Lien (sub__)->field_ = swap_ ? swab32(val__) : val__; \ 107*88690b10STuong Lien }) 108*88690b10STuong Lien 1098985ecc7SJon Maloy /* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format 1108985ecc7SJon Maloy */ 1118985ecc7SJon Maloy #define tipc_evt_write(evt_, field_, val_) \ 1128985ecc7SJon Maloy ({ \ 1138985ecc7SJon Maloy struct tipc_event *evt__ = evt_; \ 1148985ecc7SJon Maloy u32 val__ = val_; \ 1158985ecc7SJon Maloy int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK)); \ 1168985ecc7SJon Maloy (evt__)->field_ = swap_ ? swab32(val__) : val__; \ 1178985ecc7SJon Maloy }) 1188985ecc7SJon Maloy 119b97bf3fdSPer Liden #endif 120