Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * net/tipc/core.h: Include file for TIPC global declarations
0003  *
0004  * Copyright (c) 2005-2006, 2013-2018 Ericsson AB
0005  * Copyright (c) 2005-2007, 2010-2013, Wind River Systems
0006  * Copyright (c) 2020, 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_CORE_H
0039 #define _TIPC_CORE_H
0040 
0041 #include <linux/tipc.h>
0042 #include <linux/tipc_config.h>
0043 #include <linux/tipc_netlink.h>
0044 #include <linux/types.h>
0045 #include <linux/kernel.h>
0046 #include <linux/errno.h>
0047 #include <linux/mm.h>
0048 #include <linux/timer.h>
0049 #include <linux/string.h>
0050 #include <linux/uaccess.h>
0051 #include <linux/interrupt.h>
0052 #include <linux/atomic.h>
0053 #include <linux/netdevice.h>
0054 #include <linux/in.h>
0055 #include <linux/list.h>
0056 #include <linux/slab.h>
0057 #include <linux/vmalloc.h>
0058 #include <linux/rtnetlink.h>
0059 #include <linux/etherdevice.h>
0060 #include <net/netns/generic.h>
0061 #include <linux/rhashtable.h>
0062 #include <net/genetlink.h>
0063 #include <net/netns/hash.h>
0064 
0065 #ifdef pr_fmt
0066 #undef pr_fmt
0067 #endif
0068 
0069 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0070 
0071 struct tipc_node;
0072 struct tipc_bearer;
0073 struct tipc_bc_base;
0074 struct tipc_link;
0075 struct tipc_name_table;
0076 struct tipc_topsrv;
0077 struct tipc_monitor;
0078 #ifdef CONFIG_TIPC_CRYPTO
0079 struct tipc_crypto;
0080 #endif
0081 
0082 #define TIPC_MOD_VER "2.0.0"
0083 
0084 #define NODE_HTABLE_SIZE       512
0085 #define MAX_BEARERS          3
0086 #define TIPC_DEF_MON_THRESHOLD  32
0087 #define NODE_ID_LEN             16
0088 #define NODE_ID_STR_LEN        (NODE_ID_LEN * 2 + 1)
0089 
0090 extern unsigned int tipc_net_id __read_mostly;
0091 extern int sysctl_tipc_rmem[3] __read_mostly;
0092 extern int sysctl_tipc_named_timeout __read_mostly;
0093 
0094 struct tipc_net {
0095     u8  node_id[NODE_ID_LEN];
0096     u32 node_addr;
0097     u32 trial_addr;
0098     unsigned long addr_trial_end;
0099     char node_id_string[NODE_ID_STR_LEN];
0100     int net_id;
0101     int random;
0102     bool legacy_addr_format;
0103 
0104     /* Node table and node list */
0105     spinlock_t node_list_lock;
0106     struct hlist_head node_htable[NODE_HTABLE_SIZE];
0107     struct list_head node_list;
0108     u32 num_nodes;
0109     u32 num_links;
0110 
0111     /* Neighbor monitoring list */
0112     struct tipc_monitor *monitors[MAX_BEARERS];
0113     int mon_threshold;
0114 
0115     /* Bearer list */
0116     struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1];
0117 
0118     /* Broadcast link */
0119     spinlock_t bclock;
0120     struct tipc_bc_base *bcbase;
0121     struct tipc_link *bcl;
0122 
0123     /* Socket hash table */
0124     struct rhashtable sk_rht;
0125 
0126     /* Name table */
0127     spinlock_t nametbl_lock;
0128     struct name_table *nametbl;
0129 
0130     /* Topology subscription server */
0131     struct tipc_topsrv *topsrv;
0132     atomic_t subscription_count;
0133 
0134     /* Cluster capabilities */
0135     u16 capabilities;
0136 
0137     /* Tracing of node internal messages */
0138     struct packet_type loopback_pt;
0139 
0140 #ifdef CONFIG_TIPC_CRYPTO
0141     /* TX crypto handler */
0142     struct tipc_crypto *crypto_tx;
0143 #endif
0144     /* Work item for net finalize */
0145     struct work_struct work;
0146     /* The numbers of work queues in schedule */
0147     atomic_t wq_count;
0148 };
0149 
0150 static inline struct tipc_net *tipc_net(struct net *net)
0151 {
0152     return net_generic(net, tipc_net_id);
0153 }
0154 
0155 static inline int tipc_netid(struct net *net)
0156 {
0157     return tipc_net(net)->net_id;
0158 }
0159 
0160 static inline struct list_head *tipc_nodes(struct net *net)
0161 {
0162     return &tipc_net(net)->node_list;
0163 }
0164 
0165 static inline struct name_table *tipc_name_table(struct net *net)
0166 {
0167     return tipc_net(net)->nametbl;
0168 }
0169 
0170 static inline struct tipc_topsrv *tipc_topsrv(struct net *net)
0171 {
0172     return tipc_net(net)->topsrv;
0173 }
0174 
0175 static inline unsigned int tipc_hashfn(u32 addr)
0176 {
0177     return addr & (NODE_HTABLE_SIZE - 1);
0178 }
0179 
0180 static inline u16 mod(u16 x)
0181 {
0182     return x & 0xffffu;
0183 }
0184 
0185 static inline int less_eq(u16 left, u16 right)
0186 {
0187     return mod(right - left) < 32768u;
0188 }
0189 
0190 static inline int more(u16 left, u16 right)
0191 {
0192     return !less_eq(left, right);
0193 }
0194 
0195 static inline int less(u16 left, u16 right)
0196 {
0197     return less_eq(left, right) && (mod(right) != mod(left));
0198 }
0199 
0200 static inline int in_range(u16 val, u16 min, u16 max)
0201 {
0202     return !less(val, min) && !more(val, max);
0203 }
0204 
0205 static inline u32 tipc_net_hash_mixes(struct net *net, int tn_rand)
0206 {
0207     return net_hash_mix(&init_net) ^ net_hash_mix(net) ^ tn_rand;
0208 }
0209 
0210 static inline u32 hash128to32(char *bytes)
0211 {
0212     __be32 *tmp = (__be32 *)bytes;
0213     u32 res;
0214 
0215     res = ntohl(tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3]);
0216     if (likely(res))
0217         return res;
0218     return  ntohl(tmp[0] | tmp[1] | tmp[2] | tmp[3]);
0219 }
0220 
0221 #ifdef CONFIG_SYSCTL
0222 int tipc_register_sysctl(void);
0223 void tipc_unregister_sysctl(void);
0224 #else
0225 #define tipc_register_sysctl() 0
0226 #define tipc_unregister_sysctl()
0227 #endif
0228 #endif