aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/tipc/bearer.h19
-rw-r--r--net/tipc/eth_media.c63
2 files changed, 79 insertions, 3 deletions
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index 4e9367f956a4..41a61d219c38 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -43,6 +43,17 @@
43#define MAX_MEDIA 2 43#define MAX_MEDIA 2
44 44
45/* 45/*
46 * Identifiers associated with TIPC message header media address info
47 *
48 * - address info field is 20 bytes long
49 * - media type identifier located at offset 3
50 * - remaining bytes vary according to media type
51 */
52
53#define TIPC_MEDIA_ADDR_SIZE 20
54#define TIPC_MEDIA_TYPE_OFFSET 3
55
56/*
46 * Identifiers of supported TIPC media types 57 * Identifiers of supported TIPC media types
47 */ 58 */
48#define TIPC_MEDIA_TYPE_ETH 1 59#define TIPC_MEDIA_TYPE_ETH 1
@@ -68,7 +79,10 @@ struct tipc_bearer;
68 * @send_msg: routine which handles buffer transmission 79 * @send_msg: routine which handles buffer transmission
69 * @enable_bearer: routine which enables a bearer 80 * @enable_bearer: routine which enables a bearer
70 * @disable_bearer: routine which disables a bearer 81 * @disable_bearer: routine which disables a bearer
71 * @addr2str: routine which converts bearer's address to string form 82 * @addr2str: routine which converts media address to string
83 * @str2addr: routine which converts media address from string
84 * @addr2msg: routine which converts media address to protocol message area
85 * @msg2addr: routine which converts media address from protocol message area
72 * @bcast_addr: media address used in broadcasting 86 * @bcast_addr: media address used in broadcasting
73 * @priority: default link (and bearer) priority 87 * @priority: default link (and bearer) priority
74 * @tolerance: default time (in ms) before declaring link failure 88 * @tolerance: default time (in ms) before declaring link failure
@@ -84,6 +98,9 @@ struct media {
84 int (*enable_bearer)(struct tipc_bearer *b_ptr); 98 int (*enable_bearer)(struct tipc_bearer *b_ptr);
85 void (*disable_bearer)(struct tipc_bearer *b_ptr); 99 void (*disable_bearer)(struct tipc_bearer *b_ptr);
86 int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size); 100 int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size);
101 int (*str2addr)(struct tipc_media_addr *a, char *str_buf);
102 int (*addr2msg)(struct tipc_media_addr *a, char *msg_area);
103 int (*msg2addr)(struct tipc_media_addr *a, char *msg_area);
87 struct tipc_media_addr bcast_addr; 104 struct tipc_media_addr bcast_addr;
88 u32 priority; 105 u32 priority;
89 u32 tolerance; 106 u32 tolerance;
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index 67f616aa5dbb..ebba0fcd937e 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -39,6 +39,8 @@
39 39
40#define MAX_ETH_BEARERS MAX_BEARERS 40#define MAX_ETH_BEARERS MAX_BEARERS
41 41
42#define ETH_ADDR_OFFSET 4 /* message header offset of MAC address */
43
42/** 44/**
43 * struct eth_bearer - Ethernet bearer data structure 45 * struct eth_bearer - Ethernet bearer data structure
44 * @bearer: ptr to associated "generic" bearer structure 46 * @bearer: ptr to associated "generic" bearer structure
@@ -57,6 +59,16 @@ static int eth_started;
57static struct notifier_block notifier; 59static struct notifier_block notifier;
58 60
59/** 61/**
62 * eth_media_addr_set - initialize Ethernet media address structure
63 */
64
65static void eth_media_addr_set(struct tipc_media_addr *a, char *mac)
66{
67 a->type = htonl(TIPC_MEDIA_TYPE_ETH);
68 memcpy(&a->dev_addr.eth_addr, mac, ETH_ALEN);
69}
70
71/**
60 * send_msg - send a TIPC message out over an Ethernet interface 72 * send_msg - send a TIPC message out over an Ethernet interface
61 */ 73 */
62 74
@@ -169,8 +181,7 @@ static int enable_bearer(struct tipc_bearer *tb_ptr)
169 tb_ptr->usr_handle = (void *)eb_ptr; 181 tb_ptr->usr_handle = (void *)eb_ptr;
170 tb_ptr->mtu = dev->mtu; 182 tb_ptr->mtu = dev->mtu;
171 tb_ptr->blocked = 0; 183 tb_ptr->blocked = 0;
172 tb_ptr->addr.type = htonl(TIPC_MEDIA_TYPE_ETH); 184 eth_media_addr_set(&tb_ptr->addr, (char *)dev->dev_addr);
173 memcpy(&tb_ptr->addr.dev_addr, dev->dev_addr, ETH_ALEN);
174 return 0; 185 return 0;
175} 186}
176 187
@@ -254,6 +265,51 @@ static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
254 return 0; 265 return 0;
255} 266}
256 267
268/**
269 * eth_str2addr - convert string to Ethernet address
270 */
271
272static int eth_str2addr(struct tipc_media_addr *a, char *str_buf)
273{
274 char mac[ETH_ALEN];
275 int r;
276
277 r = sscanf(str_buf, "%02x:%02x:%02x:%02x:%02x:%02x",
278 (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2],
279 (u32 *)&mac[3], (u32 *)&mac[4], (u32 *)&mac[5]);
280
281 if (r != ETH_ALEN)
282 return 1;
283
284 eth_media_addr_set(a, mac);
285 return 0;
286}
287
288/**
289 * eth_str2addr - convert Ethernet address format to message header format
290 */
291
292static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area)
293{
294 memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE);
295 msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH;
296 memcpy(msg_area + ETH_ADDR_OFFSET, a->dev_addr.eth_addr, ETH_ALEN);
297 return 0;
298}
299
300/**
301 * eth_str2addr - convert message header address format to Ethernet format
302 */
303
304static int eth_msg2addr(struct tipc_media_addr *a, char *msg_area)
305{
306 if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH)
307 return 1;
308
309 eth_media_addr_set(a, msg_area + ETH_ADDR_OFFSET);
310 return 0;
311}
312
257/* 313/*
258 * Ethernet media registration info 314 * Ethernet media registration info
259 */ 315 */
@@ -263,6 +319,9 @@ static struct media eth_media_info = {
263 .enable_bearer = enable_bearer, 319 .enable_bearer = enable_bearer,
264 .disable_bearer = disable_bearer, 320 .disable_bearer = disable_bearer,
265 .addr2str = eth_addr2str, 321 .addr2str = eth_addr2str,
322 .str2addr = eth_str2addr,
323 .addr2msg = eth_addr2msg,
324 .msg2addr = eth_msg2addr,
266 .bcast_addr = { htonl(TIPC_MEDIA_TYPE_ETH), 325 .bcast_addr = { htonl(TIPC_MEDIA_TYPE_ETH),
267 { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} } }, 326 { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} } },
268 .priority = TIPC_DEF_LINK_PRI, 327 .priority = TIPC_DEF_LINK_PRI,