0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
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
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
0112 struct tipc_monitor *monitors[MAX_BEARERS];
0113 int mon_threshold;
0114
0115
0116 struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1];
0117
0118
0119 spinlock_t bclock;
0120 struct tipc_bc_base *bcbase;
0121 struct tipc_link *bcl;
0122
0123
0124 struct rhashtable sk_rht;
0125
0126
0127 spinlock_t nametbl_lock;
0128 struct name_table *nametbl;
0129
0130
0131 struct tipc_topsrv *topsrv;
0132 atomic_t subscription_count;
0133
0134
0135 u16 capabilities;
0136
0137
0138 struct packet_type loopback_pt;
0139
0140 #ifdef CONFIG_TIPC_CRYPTO
0141
0142 struct tipc_crypto *crypto_tx;
0143 #endif
0144
0145 struct work_struct work;
0146
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