core.h 4.59 KB
Newer Older
Per Liden's avatar
Per Liden committed
1
2
/*
 * net/tipc/core.h: Include file for TIPC global declarations
3
 *
4
5
 * Copyright (c) 2005-2006, 2013 Ericsson AB
 * Copyright (c) 2005-2007, 2010-2013, Wind River Systems
Per Liden's avatar
Per Liden committed
6
7
 * All rights reserved.
 *
Per Liden's avatar
Per Liden committed
8
 * Redistribution and use in source and binary forms, with or without
Per Liden's avatar
Per Liden committed
9
10
 * modification, are permitted provided that the following conditions are met:
 *
Per Liden's avatar
Per Liden committed
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.
Per Liden's avatar
Per Liden committed
19
 *
Per Liden's avatar
Per Liden committed
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
Per Liden's avatar
Per Liden committed
34
35
36
37
38
39
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _TIPC_CORE_H
#define _TIPC_CORE_H

Jon Maloy's avatar
Jon Maloy committed
40
41
#include <linux/tipc.h>
#include <linux/tipc_config.h>
42
#include <linux/tipc_netlink.h>
Per Liden's avatar
Per Liden committed
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>
Per Liden's avatar
Per Liden committed
50
#include <linux/interrupt.h>
Arun Sharma's avatar
Arun Sharma committed
51
#include <linux/atomic.h>
Per Liden's avatar
Per Liden committed
52
53
#include <asm/hardirq.h>
#include <linux/netdevice.h>
54
#include <linux/in.h>
Per Liden's avatar
Per Liden committed
55
#include <linux/list.h>
56
#include <linux/slab.h>
Per Liden's avatar
Per Liden committed
57
#include <linux/vmalloc.h>
58
#include <linux/rtnetlink.h>
59
#include <linux/etherdevice.h>
60
#include <net/netns/generic.h>
61
#include <linux/rhashtable.h>
62

63
64
struct tipc_node;
struct tipc_bearer;
65
struct tipc_bc_base;
66
67
68
struct tipc_link;
struct tipc_name_table;
struct tipc_server;
69
struct tipc_monitor;
70

71
72
#define TIPC_MOD_VER "2.0.0"

73
74
75
#define NODE_HTABLE_SIZE       512
#define MAX_BEARERS	         3
#define TIPC_DEF_MON_THRESHOLD  32
76

77
extern int tipc_net_id __read_mostly;
78
extern int sysctl_tipc_rmem[3] __read_mostly;
79
extern int sysctl_tipc_named_timeout __read_mostly;
Per Liden's avatar
Per Liden committed
80

81
struct tipc_net {
82
	u32 own_addr;
83
	int net_id;
84
	int random;
85
86
87
88
89
90
91

	/* 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;
92

93
94
95
96
	/* Neighbor monitoring list */
	struct tipc_monitor *monitors[MAX_BEARERS];
	int mon_threshold;

97
98
	/* Bearer list */
	struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1];
99
100

	/* Broadcast link */
101
	spinlock_t bclock;
102
	struct tipc_bc_base *bcbase;
103
	struct tipc_link *bcl;
104
105
106

	/* Socket hash table */
	struct rhashtable sk_rht;
107
108
109
110

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

Erik Hugne's avatar
Erik Hugne committed
112
113
114
	/* Name dist queue */
	struct list_head dist_queue;

115
116
117
	/* Topology subscription server */
	struct tipc_server *topsrv;
	atomic_t subscription_count;
118
119
};

Jon Paul Maloy's avatar
Jon Paul Maloy committed
120
121
122
123
124
static inline struct tipc_net *tipc_net(struct net *net)
{
	return net_generic(net, tipc_net_id);
}

125
126
127
128
129
static inline int tipc_netid(struct net *net)
{
	return tipc_net(net)->net_id;
}

130
131
132
133
134
static inline struct list_head *tipc_nodes(struct net *net)
{
	return &tipc_net(net)->node_list;
}

135
136
137
138
139
static inline unsigned int tipc_hashfn(u32 addr)
{
	return addr & (NODE_HTABLE_SIZE - 1);
}

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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));
}

160
161
162
163
164
static inline int in_range(u16 val, u16 min, u16 max)
{
	return !less(val, min) && !more(val, max);
}

165
#ifdef CONFIG_SYSCTL
166
167
int tipc_register_sysctl(void);
void tipc_unregister_sysctl(void);
168
169
170
171
#else
#define tipc_register_sysctl() 0
#define tipc_unregister_sysctl()
#endif
172
#endif