Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * net/tipc/subscr.h: Include file for TIPC network topology service
0003  *
0004  * Copyright (c) 2003-2017, Ericsson AB
0005  * Copyright (c) 2005-2007, 2012-2013, Wind River Systems
0006  * Copyright (c) 2020-2021, Red Hat Inc
0007  * All rights reserved.
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions are met:
0011  *
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  * 3. Neither the names of the copyright holders nor the names of its
0018  *    contributors may be used to endorse or promote products derived from
0019  *    this software without specific prior written permission.
0020  *
0021  * Alternatively, this software may be distributed under the terms of the
0022  * GNU General Public License ("GPL") version 2 as published by the Free
0023  * Software Foundation.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifndef _TIPC_SUBSCR_H
0039 #define _TIPC_SUBSCR_H
0040 
0041 #include "topsrv.h"
0042 
0043 #define TIPC_MAX_SUBSCR         65535
0044 #define TIPC_MAX_PUBL           65535
0045 
0046 struct publication;
0047 struct tipc_subscription;
0048 struct tipc_conn;
0049 
0050 /**
0051  * struct tipc_subscription - TIPC network topology subscription object
0052  * @s: host-endian copy of the user subscription
0053  * @evt: template for events generated by subscription
0054  * @kref: reference count for this subscription
0055  * @net: network namespace associated with subscription
0056  * @timer: timer governing subscription duration (optional)
0057  * @service_list: adjacent subscriptions in name sequence's subscription list
0058  * @sub_list: adjacent subscriptions in subscriber's subscription list
0059  * @conid: connection identifier of topology server
0060  * @inactive: true if this subscription is inactive
0061  * @lock: serialize up/down and timer events
0062  */
0063 struct tipc_subscription {
0064     struct tipc_subscr s;
0065     struct tipc_event evt;
0066     struct kref kref;
0067     struct net *net;
0068     struct timer_list timer;
0069     struct list_head service_list;
0070     struct list_head sub_list;
0071     int conid;
0072     bool inactive;
0073     spinlock_t lock;
0074 };
0075 
0076 struct tipc_subscription *tipc_sub_subscribe(struct net *net,
0077                          struct tipc_subscr *s,
0078                          int conid);
0079 void tipc_sub_unsubscribe(struct tipc_subscription *sub);
0080 void tipc_sub_report_overlap(struct tipc_subscription *sub,
0081                  struct publication *p,
0082                  u32 event, bool must);
0083 
0084 int __net_init tipc_topsrv_init_net(struct net *net);
0085 void __net_exit tipc_topsrv_exit_net(struct net *net);
0086 
0087 void tipc_sub_put(struct tipc_subscription *subscription);
0088 void tipc_sub_get(struct tipc_subscription *subscription);
0089 
0090 #define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL)
0091 
0092 /* tipc_sub_read - return field_ of struct sub_ in host endian format
0093  */
0094 #define tipc_sub_read(sub_, field_)                 \
0095     ({                              \
0096         struct tipc_subscr *sub__ = sub_;           \
0097         u32 val__ = (sub__)->field_;                \
0098         int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);  \
0099         (swap_ ? swab32(val__) : val__);            \
0100     })
0101 
0102 /* tipc_sub_write - write val_ to field_ of struct sub_ in user endian format
0103  */
0104 #define tipc_sub_write(sub_, field_, val_)              \
0105     ({                              \
0106         struct tipc_subscr *sub__ = sub_;           \
0107         u32 val__ = val_;                   \
0108         int swap_ = !((sub__)->filter & TIPC_FILTER_MASK);  \
0109         (sub__)->field_ = swap_ ? swab32(val__) : val__;    \
0110     })
0111 
0112 /* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format
0113  */
0114 #define tipc_evt_write(evt_, field_, val_)              \
0115     ({                              \
0116         struct tipc_event *evt__ = evt_;            \
0117         u32 val__ = val_;                   \
0118         int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK));  \
0119         (evt__)->field_ = swap_ ? swab32(val__) : val__;    \
0120     })
0121 
0122 #endif