aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/tipc/bearer.c70
-rw-r--r--net/tipc/bearer.h11
-rw-r--r--net/tipc/eth_media.c30
3 files changed, 45 insertions, 66 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index e2202de3d93e..75af271b9cfa 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -86,21 +86,8 @@ static struct media *media_find(const char *name)
86 * Bearers for this media type must be activated separately at a later stage. 86 * Bearers for this media type must be activated separately at a later stage.
87 */ 87 */
88 88
89int tipc_register_media(u32 media_type, 89int tipc_register_media(struct media *m_ptr)
90 char *name,
91 int (*enable)(struct tipc_bearer *),
92 void (*disable)(struct tipc_bearer *),
93 int (*send_msg)(struct sk_buff *,
94 struct tipc_bearer *,
95 struct tipc_media_addr *),
96 char *(*addr2str)(struct tipc_media_addr *a,
97 char *str_buf, int str_size),
98 struct tipc_media_addr *bcast_addr,
99 const u32 bearer_priority,
100 const u32 link_tolerance, /* [ms] */
101 const u32 send_window_limit)
102{ 90{
103 struct media *m_ptr;
104 u32 media_id; 91 u32 media_id;
105 u32 i; 92 u32 i;
106 int res = -EINVAL; 93 int res = -EINVAL;
@@ -108,62 +95,55 @@ int tipc_register_media(u32 media_type,
108 write_lock_bh(&tipc_net_lock); 95 write_lock_bh(&tipc_net_lock);
109 96
110 if (tipc_mode != TIPC_NET_MODE) { 97 if (tipc_mode != TIPC_NET_MODE) {
111 warn("Media <%s> rejected, not in networked mode yet\n", name); 98 warn("Media <%s> rejected, not in networked mode yet\n",
99 m_ptr->name);
112 goto exit; 100 goto exit;
113 } 101 }
114 if (!media_name_valid(name)) { 102 if (!media_name_valid(m_ptr->name)) {
115 warn("Media <%s> rejected, illegal name\n", name); 103 warn("Media <%s> rejected, illegal name\n", m_ptr->name);
116 goto exit; 104 goto exit;
117 } 105 }
118 if (!bcast_addr) { 106 if (m_ptr->bcast_addr.type != htonl(m_ptr->type_id)) {
119 warn("Media <%s> rejected, no broadcast address\n", name); 107 warn("Media <%s> rejected, illegal broadcast address\n",
108 m_ptr->name);
120 goto exit; 109 goto exit;
121 } 110 }
122 if ((bearer_priority < TIPC_MIN_LINK_PRI) || 111 if ((m_ptr->priority < TIPC_MIN_LINK_PRI) ||
123 (bearer_priority > TIPC_MAX_LINK_PRI)) { 112 (m_ptr->priority > TIPC_MAX_LINK_PRI)) {
124 warn("Media <%s> rejected, illegal priority (%u)\n", name, 113 warn("Media <%s> rejected, illegal priority (%u)\n",
125 bearer_priority); 114 m_ptr->name, m_ptr->priority);
126 goto exit; 115 goto exit;
127 } 116 }
128 if ((link_tolerance < TIPC_MIN_LINK_TOL) || 117 if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
129 (link_tolerance > TIPC_MAX_LINK_TOL)) { 118 (m_ptr->tolerance > TIPC_MAX_LINK_TOL)) {
130 warn("Media <%s> rejected, illegal tolerance (%u)\n", name, 119 warn("Media <%s> rejected, illegal tolerance (%u)\n",
131 link_tolerance); 120 m_ptr->name, m_ptr->tolerance);
132 goto exit; 121 goto exit;
133 } 122 }
134 123
135 media_id = media_count++; 124 media_id = media_count++;
136 if (media_id >= MAX_MEDIA) { 125 if (media_id >= MAX_MEDIA) {
137 warn("Media <%s> rejected, media limit reached (%u)\n", name, 126 warn("Media <%s> rejected, media limit reached (%u)\n",
138 MAX_MEDIA); 127 m_ptr->name, MAX_MEDIA);
139 media_count--; 128 media_count--;
140 goto exit; 129 goto exit;
141 } 130 }
142 for (i = 0; i < media_id; i++) { 131 for (i = 0; i < media_id; i++) {
143 if (media_list[i].type_id == media_type) { 132 if (media_list[i].type_id == m_ptr->type_id) {
144 warn("Media <%s> rejected, duplicate type (%u)\n", name, 133 warn("Media <%s> rejected, duplicate type (%u)\n",
145 media_type); 134 m_ptr->name, m_ptr->type_id);
146 media_count--; 135 media_count--;
147 goto exit; 136 goto exit;
148 } 137 }
149 if (!strcmp(name, media_list[i].name)) { 138 if (!strcmp(m_ptr->name, media_list[i].name)) {
150 warn("Media <%s> rejected, duplicate name\n", name); 139 warn("Media <%s> rejected, duplicate name\n",
140 m_ptr->name);
151 media_count--; 141 media_count--;
152 goto exit; 142 goto exit;
153 } 143 }
154 } 144 }
155 145
156 m_ptr = &media_list[media_id]; 146 media_list[media_id] = *m_ptr;
157 m_ptr->type_id = media_type;
158 m_ptr->send_msg = send_msg;
159 m_ptr->enable_bearer = enable;
160 m_ptr->disable_bearer = disable;
161 m_ptr->addr2str = addr2str;
162 memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr));
163 strcpy(m_ptr->name, name);
164 m_ptr->priority = bearer_priority;
165 m_ptr->tolerance = link_tolerance;
166 m_ptr->window = send_window_limit;
167 res = 0; 147 res = 0;
168exit: 148exit:
169 write_unlock_bh(&tipc_net_lock); 149 write_unlock_bh(&tipc_net_lock);
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index d696f9e414e3..148ed04493ac 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -145,16 +145,7 @@ extern struct tipc_bearer tipc_bearers[];
145/* 145/*
146 * TIPC routines available to supported media types 146 * TIPC routines available to supported media types
147 */ 147 */
148int tipc_register_media(u32 media_type, 148int tipc_register_media(struct media *m_ptr);
149 char *media_name, int (*enable)(struct tipc_bearer *),
150 void (*disable)(struct tipc_bearer *),
151 int (*send_msg)(struct sk_buff *,
152 struct tipc_bearer *, struct tipc_media_addr *),
153 char *(*addr2str)(struct tipc_media_addr *a,
154 char *str_buf, int str_size),
155 struct tipc_media_addr *bcast_addr, const u32 bearer_priority,
156 const u32 link_tolerance, /* [ms] */
157 const u32 send_window_limit);
158 149
159void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr); 150void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr);
160 151
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index e728d4ce2a1b..15c685b868db 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -38,9 +38,6 @@
38#include "bearer.h" 38#include "bearer.h"
39 39
40#define MAX_ETH_BEARERS MAX_BEARERS 40#define MAX_ETH_BEARERS MAX_BEARERS
41#define ETH_LINK_PRIORITY TIPC_DEF_LINK_PRI
42#define ETH_LINK_TOLERANCE TIPC_DEF_LINK_TOL
43#define ETH_LINK_WINDOW TIPC_DEF_LINK_WIN
44 41
45/** 42/**
46 * struct eth_bearer - Ethernet bearer data structure 43 * struct eth_bearer - Ethernet bearer data structure
@@ -257,6 +254,24 @@ static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size
257 return str_buf; 254 return str_buf;
258} 255}
259 256
257/*
258 * Ethernet media registration info
259 */
260
261static struct media eth_media_info = {
262 .send_msg = send_msg,
263 .enable_bearer = enable_bearer,
264 .disable_bearer = disable_bearer,
265 .addr2str = eth_addr2str,
266 .bcast_addr = { htonl(TIPC_MEDIA_TYPE_ETH),
267 { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} } },
268 .priority = TIPC_DEF_LINK_PRI,
269 .tolerance = TIPC_DEF_LINK_TOL,
270 .window = TIPC_DEF_LINK_WIN,
271 .type_id = TIPC_MEDIA_TYPE_ETH,
272 .name = "eth"
273};
274
260/** 275/**
261 * tipc_eth_media_start - activate Ethernet bearer support 276 * tipc_eth_media_start - activate Ethernet bearer support
262 * 277 *
@@ -266,21 +281,14 @@ static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size
266 281
267int tipc_eth_media_start(void) 282int tipc_eth_media_start(void)
268{ 283{
269 struct tipc_media_addr bcast_addr;
270 int res; 284 int res;
271 285
272 if (eth_started) 286 if (eth_started)
273 return -EINVAL; 287 return -EINVAL;
274 288
275 bcast_addr.type = htonl(TIPC_MEDIA_TYPE_ETH);
276 memset(&bcast_addr.dev_addr, 0xff, ETH_ALEN);
277
278 memset(eth_bearers, 0, sizeof(eth_bearers)); 289 memset(eth_bearers, 0, sizeof(eth_bearers));
279 290
280 res = tipc_register_media(TIPC_MEDIA_TYPE_ETH, "eth", 291 res = tipc_register_media(&eth_media_info);
281 enable_bearer, disable_bearer, send_msg,
282 eth_addr2str, &bcast_addr, ETH_LINK_PRIORITY,
283 ETH_LINK_TOLERANCE, ETH_LINK_WINDOW);
284 if (res) 292 if (res)
285 return res; 293 return res;
286 294