aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/bearer.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/bearer.c')
-rw-r--r--net/tipc/bearer.c63
1 files changed, 16 insertions, 47 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index c2101c0bfd6d..826aa9fdf45f 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/bearer.c: TIPC bearer code 2 * net/tipc/bearer.c: TIPC bearer code
3 * 3 *
4 * Copyright (c) 1996-2006, Ericsson AB 4 * Copyright (c) 1996-2006, 2013, Ericsson AB
5 * Copyright (c) 2004-2006, 2010-2011, Wind River Systems 5 * Copyright (c) 2004-2006, 2010-2011, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -41,8 +41,13 @@
41 41
42#define MAX_ADDR_STR 60 42#define MAX_ADDR_STR 60
43 43
44static struct tipc_media *media_list[MAX_MEDIA]; 44static struct tipc_media * const media_list[] = {
45static u32 media_count; 45 &eth_media_info,
46#ifdef CONFIG_TIPC_MEDIA_IB
47 &ib_media_info,
48#endif
49 NULL
50};
46 51
47struct tipc_bearer tipc_bearers[MAX_BEARERS]; 52struct tipc_bearer tipc_bearers[MAX_BEARERS];
48 53
@@ -55,11 +60,11 @@ struct tipc_media *tipc_media_find(const char *name)
55{ 60{
56 u32 i; 61 u32 i;
57 62
58 for (i = 0; i < media_count; i++) { 63 for (i = 0; media_list[i] != NULL; i++) {
59 if (!strcmp(media_list[i]->name, name)) 64 if (!strcmp(media_list[i]->name, name))
60 return media_list[i]; 65 break;
61 } 66 }
62 return NULL; 67 return media_list[i];
63} 68}
64 69
65/** 70/**
@@ -69,44 +74,11 @@ static struct tipc_media *media_find_id(u8 type)
69{ 74{
70 u32 i; 75 u32 i;
71 76
72 for (i = 0; i < media_count; i++) { 77 for (i = 0; media_list[i] != NULL; i++) {
73 if (media_list[i]->type_id == type) 78 if (media_list[i]->type_id == type)
74 return media_list[i]; 79 break;
75 } 80 }
76 return NULL; 81 return media_list[i];
77}
78
79/**
80 * tipc_register_media - register a media type
81 *
82 * Bearers for this media type must be activated separately at a later stage.
83 */
84int tipc_register_media(struct tipc_media *m_ptr)
85{
86 int res = -EINVAL;
87
88 write_lock_bh(&tipc_net_lock);
89
90 if ((strlen(m_ptr->name) + 1) > TIPC_MAX_MEDIA_NAME)
91 goto exit;
92 if (m_ptr->priority > TIPC_MAX_LINK_PRI)
93 goto exit;
94 if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
95 (m_ptr->tolerance > TIPC_MAX_LINK_TOL))
96 goto exit;
97 if (media_count >= MAX_MEDIA)
98 goto exit;
99 if (tipc_media_find(m_ptr->name) || media_find_id(m_ptr->type_id))
100 goto exit;
101
102 media_list[media_count] = m_ptr;
103 media_count++;
104 res = 0;
105exit:
106 write_unlock_bh(&tipc_net_lock);
107 if (res)
108 pr_warn("Media <%s> registration error\n", m_ptr->name);
109 return res;
110} 82}
111 83
112/** 84/**
@@ -144,13 +116,11 @@ struct sk_buff *tipc_media_get_names(void)
144 if (!buf) 116 if (!buf)
145 return NULL; 117 return NULL;
146 118
147 read_lock_bh(&tipc_net_lock); 119 for (i = 0; media_list[i] != NULL; i++) {
148 for (i = 0; i < media_count; i++) {
149 tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, 120 tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
150 media_list[i]->name, 121 media_list[i]->name,
151 strlen(media_list[i]->name) + 1); 122 strlen(media_list[i]->name) + 1);
152 } 123 }
153 read_unlock_bh(&tipc_net_lock);
154 return buf; 124 return buf;
155} 125}
156 126
@@ -247,7 +217,7 @@ struct sk_buff *tipc_bearer_get_names(void)
247 return NULL; 217 return NULL;
248 218
249 read_lock_bh(&tipc_net_lock); 219 read_lock_bh(&tipc_net_lock);
250 for (i = 0; i < media_count; i++) { 220 for (i = 0; media_list[i] != NULL; i++) {
251 for (j = 0; j < MAX_BEARERS; j++) { 221 for (j = 0; j < MAX_BEARERS; j++) {
252 b_ptr = &tipc_bearers[j]; 222 b_ptr = &tipc_bearers[j];
253 if (b_ptr->active && (b_ptr->media == media_list[i])) { 223 if (b_ptr->active && (b_ptr->media == media_list[i])) {
@@ -472,5 +442,4 @@ void tipc_bearer_stop(void)
472 if (tipc_bearers[i].active) 442 if (tipc_bearers[i].active)
473 bearer_disable(&tipc_bearers[i]); 443 bearer_disable(&tipc_bearers[i]);
474 } 444 }
475 media_count = 0;
476} 445}