core.h 5.3 KB
Newer Older
P
Per Liden 已提交
1 2
/*
 * net/tipc/core.h: Include file for TIPC global declarations
3
 *
4
 * Copyright (c) 2005-2006, 2013-2018 Ericsson AB
5
 * Copyright (c) 2005-2007, 2010-2013, Wind River Systems
P
Per Liden 已提交
6 7
 * All rights reserved.
 *
P
Per Liden 已提交
8
 * Redistribution and use in source and binary forms, with or without
P
Per Liden 已提交
9 10
 * modification, are permitted provided that the following conditions are met:
 *
P
Per Liden 已提交
11 12 13 14 15 16 17 18
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the names of the copyright holders nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
P
Per Liden 已提交
19
 *
P
Per Liden 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
P
Per Liden 已提交
34 35 36 37 38 39
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _TIPC_CORE_H
#define _TIPC_CORE_H

J
Jon Maloy 已提交
40 41
#include <linux/tipc.h>
#include <linux/tipc_config.h>
42
#include <linux/tipc_netlink.h>
P
Per Liden 已提交
43 44 45 46 47 48
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/timer.h>
#include <linux/string.h>
49
#include <linux/uaccess.h>
P
Per Liden 已提交
50
#include <linux/interrupt.h>
A
Arun Sharma 已提交
51
#include <linux/atomic.h>
P
Per Liden 已提交
52
#include <linux/netdevice.h>
53
#include <linux/in.h>
P
Per Liden 已提交
54
#include <linux/list.h>
55
#include <linux/slab.h>
P
Per Liden 已提交
56
#include <linux/vmalloc.h>
57
#include <linux/rtnetlink.h>
58
#include <linux/etherdevice.h>
59
#include <net/netns/generic.h>
60
#include <linux/rhashtable.h>
61
#include <net/genetlink.h>
62
#include <net/netns/hash.h>
63

64 65
struct tipc_node;
struct tipc_bearer;
66
struct tipc_bc_base;
67 68
struct tipc_link;
struct tipc_name_table;
69
struct tipc_topsrv;
70
struct tipc_monitor;
71

72 73
#define TIPC_MOD_VER "2.0.0"

74 75 76
#define NODE_HTABLE_SIZE       512
#define MAX_BEARERS	         3
#define TIPC_DEF_MON_THRESHOLD  32
J
Jon Maloy 已提交
77 78
#define NODE_ID_LEN             16
#define NODE_ID_STR_LEN        (NODE_ID_LEN * 2 + 1)
79

80
extern unsigned int tipc_net_id __read_mostly;
81
extern int sysctl_tipc_rmem[3] __read_mostly;
82
extern int sysctl_tipc_named_timeout __read_mostly;
P
Per Liden 已提交
83

84
struct tipc_net {
J
Jon Maloy 已提交
85 86
	u8  node_id[NODE_ID_LEN];
	u32 node_addr;
87 88
	u32 trial_addr;
	unsigned long addr_trial_end;
J
Jon Maloy 已提交
89
	char node_id_string[NODE_ID_STR_LEN];
90
	int net_id;
91
	int random;
92
	bool legacy_addr_format;
93 94 95 96 97 98 99

	/* Node table and node list */
	spinlock_t node_list_lock;
	struct hlist_head node_htable[NODE_HTABLE_SIZE];
	struct list_head node_list;
	u32 num_nodes;
	u32 num_links;
100

101 102 103 104
	/* Neighbor monitoring list */
	struct tipc_monitor *monitors[MAX_BEARERS];
	int mon_threshold;

105 106
	/* Bearer list */
	struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1];
107 108

	/* Broadcast link */
109
	spinlock_t bclock;
110
	struct tipc_bc_base *bcbase;
111
	struct tipc_link *bcl;
112 113 114

	/* Socket hash table */
	struct rhashtable sk_rht;
115 116 117 118

	/* Name table */
	spinlock_t nametbl_lock;
	struct name_table *nametbl;
119

E
Erik Hugne 已提交
120 121 122
	/* Name dist queue */
	struct list_head dist_queue;

123
	/* Topology subscription server */
124
	struct tipc_topsrv *topsrv;
125
	atomic_t subscription_count;
126 127 128

	/* Cluster capabilities */
	u16 capabilities;
129 130 131

	/* Tracing of node internal messages */
	struct packet_type loopback_pt;
132 133
};

J
Jon Paul Maloy 已提交
134 135 136 137 138
static inline struct tipc_net *tipc_net(struct net *net)
{
	return net_generic(net, tipc_net_id);
}

139 140 141 142 143
static inline int tipc_netid(struct net *net)
{
	return tipc_net(net)->net_id;
}

144 145 146 147 148
static inline struct list_head *tipc_nodes(struct net *net)
{
	return &tipc_net(net)->node_list;
}

149 150 151 152 153
static inline struct name_table *tipc_name_table(struct net *net)
{
	return tipc_net(net)->nametbl;
}

154
static inline struct tipc_topsrv *tipc_topsrv(struct net *net)
155 156 157 158
{
	return tipc_net(net)->topsrv;
}

159 160 161 162 163
static inline unsigned int tipc_hashfn(u32 addr)
{
	return addr & (NODE_HTABLE_SIZE - 1);
}

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
static inline u16 mod(u16 x)
{
	return x & 0xffffu;
}

static inline int less_eq(u16 left, u16 right)
{
	return mod(right - left) < 32768u;
}

static inline int more(u16 left, u16 right)
{
	return !less_eq(left, right);
}

static inline int less(u16 left, u16 right)
{
	return less_eq(left, right) && (mod(right) != mod(left));
}

184 185 186 187 188
static inline int in_range(u16 val, u16 min, u16 max)
{
	return !less(val, min) && !more(val, max);
}

189 190 191 192 193
static inline u32 tipc_net_hash_mixes(struct net *net, int tn_rand)
{
	return net_hash_mix(&init_net) ^ net_hash_mix(net) ^ tn_rand;
}

194
#ifdef CONFIG_SYSCTL
195 196
int tipc_register_sysctl(void);
void tipc_unregister_sysctl(void);
197 198 199 200
#else
#define tipc_register_sysctl() 0
#define tipc_unregister_sysctl()
#endif
201
#endif