diff options
Diffstat (limited to 'net/tipc/eth_media.c')
-rw-r--r-- | net/tipc/eth_media.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c index 67cf3f935dba..5e1426f1751f 100644 --- a/net/tipc/eth_media.c +++ b/net/tipc/eth_media.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/eth_media.c: Ethernet bearer support for TIPC | 2 | * net/tipc/eth_media.c: Ethernet bearer support for TIPC |
3 | * | 3 | * |
4 | * Copyright (c) 2001-2007, 2013, Ericsson AB | 4 | * Copyright (c) 2001-2007, 2013-2014, Ericsson AB |
5 | * Copyright (c) 2005-2008, 2011-2013, Wind River Systems | 5 | * Copyright (c) 2005-2008, 2011-2013, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -37,39 +37,52 @@ | |||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "bearer.h" | 38 | #include "bearer.h" |
39 | 39 | ||
40 | #define ETH_ADDR_OFFSET 4 /* message header offset of MAC address */ | 40 | #define ETH_ADDR_OFFSET 4 /* MAC addr position inside address field */ |
41 | 41 | ||
42 | /* convert Ethernet address to string */ | 42 | /* Convert Ethernet address (media address format) to string */ |
43 | static int tipc_eth_addr2str(struct tipc_media_addr *a, char *str_buf, | 43 | static int tipc_eth_addr2str(struct tipc_media_addr *addr, |
44 | int str_size) | 44 | char *strbuf, int bufsz) |
45 | { | 45 | { |
46 | if (str_size < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */ | 46 | if (bufsz < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */ |
47 | return 1; | 47 | return 1; |
48 | 48 | ||
49 | sprintf(str_buf, "%pM", a->value); | 49 | sprintf(strbuf, "%pM", addr->value); |
50 | return 0; | 50 | return 0; |
51 | } | 51 | } |
52 | 52 | ||
53 | /* convert Ethernet address format to message header format */ | 53 | /* Convert from media address format to discovery message addr format */ |
54 | static int tipc_eth_addr2msg(struct tipc_media_addr *a, char *msg_area) | 54 | static int tipc_eth_addr2msg(char *msg, struct tipc_media_addr *addr) |
55 | { | 55 | { |
56 | memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); | 56 | memset(msg, 0, TIPC_MEDIA_ADDR_SIZE); |
57 | msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH; | 57 | msg[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH; |
58 | memcpy(msg_area + ETH_ADDR_OFFSET, a->value, ETH_ALEN); | 58 | memcpy(msg + ETH_ADDR_OFFSET, addr->value, ETH_ALEN); |
59 | return 0; | 59 | return 0; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* convert message header address format to Ethernet format */ | 62 | /* Convert raw mac address format to media addr format */ |
63 | static int tipc_eth_msg2addr(const struct tipc_bearer *tb_ptr, | 63 | static int tipc_eth_raw2addr(struct tipc_bearer *b, |
64 | struct tipc_media_addr *a, char *msg_area) | 64 | struct tipc_media_addr *addr, |
65 | char *msg) | ||
65 | { | 66 | { |
66 | if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH) | 67 | char bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
67 | return 1; | ||
68 | 68 | ||
69 | tipc_l2_media_addr_set(tb_ptr, a, msg_area + ETH_ADDR_OFFSET); | 69 | memset(addr, 0, sizeof(*addr)); |
70 | ether_addr_copy(addr->value, msg); | ||
71 | addr->media_id = TIPC_MEDIA_TYPE_ETH; | ||
72 | addr->broadcast = !memcmp(addr->value, bcast_mac, ETH_ALEN); | ||
70 | return 0; | 73 | return 0; |
71 | } | 74 | } |
72 | 75 | ||
76 | /* Convert discovery msg addr format to Ethernet media addr format */ | ||
77 | static int tipc_eth_msg2addr(struct tipc_bearer *b, | ||
78 | struct tipc_media_addr *addr, | ||
79 | char *msg) | ||
80 | { | ||
81 | /* Skip past preamble: */ | ||
82 | msg += ETH_ADDR_OFFSET; | ||
83 | return tipc_eth_raw2addr(b, addr, msg); | ||
84 | } | ||
85 | |||
73 | /* Ethernet media registration info */ | 86 | /* Ethernet media registration info */ |
74 | struct tipc_media eth_media_info = { | 87 | struct tipc_media eth_media_info = { |
75 | .send_msg = tipc_l2_send_msg, | 88 | .send_msg = tipc_l2_send_msg, |
@@ -78,6 +91,7 @@ struct tipc_media eth_media_info = { | |||
78 | .addr2str = tipc_eth_addr2str, | 91 | .addr2str = tipc_eth_addr2str, |
79 | .addr2msg = tipc_eth_addr2msg, | 92 | .addr2msg = tipc_eth_addr2msg, |
80 | .msg2addr = tipc_eth_msg2addr, | 93 | .msg2addr = tipc_eth_msg2addr, |
94 | .raw2addr = tipc_eth_raw2addr, | ||
81 | .priority = TIPC_DEF_LINK_PRI, | 95 | .priority = TIPC_DEF_LINK_PRI, |
82 | .tolerance = TIPC_DEF_LINK_TOL, | 96 | .tolerance = TIPC_DEF_LINK_TOL, |
83 | .window = TIPC_DEF_LINK_WIN, | 97 | .window = TIPC_DEF_LINK_WIN, |
@@ -85,4 +99,3 @@ struct tipc_media eth_media_info = { | |||
85 | .hwaddr_len = ETH_ALEN, | 99 | .hwaddr_len = ETH_ALEN, |
86 | .name = "eth" | 100 | .name = "eth" |
87 | }; | 101 | }; |
88 | |||