core.h 4.29 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

70
71
#define TIPC_MOD_VER "2.0.0"

72
73
74
#define NODE_HTABLE_SIZE   512
#define MAX_BEARERS	   3

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

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

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

	/* Bearer list */
	struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1];
93
94

	/* Broadcast link */
95
	spinlock_t bclock;
96
	struct tipc_bc_base *bcbase;
97
	struct tipc_link *bcl;
98
99
100

	/* Socket hash table */
	struct rhashtable sk_rht;
101
102
103
104

	/* Name table */
	spinlock_t nametbl_lock;
	struct name_table *nametbl;
105
106
107
108

	/* Topology subscription server */
	struct tipc_server *topsrv;
	atomic_t subscription_count;
109
110
};

Jon Paul Maloy's avatar
Jon Paul Maloy committed
111
112
113
114
115
static inline struct tipc_net *tipc_net(struct net *net)
{
	return net_generic(net, tipc_net_id);
}

116
117
118
119
120
static inline int tipc_netid(struct net *net)
{
	return tipc_net(net)->net_id;
}

121
122
123
124
125
static inline struct list_head *tipc_nodes(struct net *net)
{
	return &tipc_net(net)->node_list;
}

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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));
}

146
147
148
149
150
static inline int in_range(u16 val, u16 min, u16 max)
{
	return !less(val, min) && !more(val, max);
}

151
#ifdef CONFIG_SYSCTL
152
153
int tipc_register_sysctl(void);
void tipc_unregister_sysctl(void);
154
155
156
157
#else
#define tipc_register_sysctl() 0
#define tipc_unregister_sysctl()
#endif
158
#endif