aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/eth_media.c
diff options
context:
space:
mode:
authorAllan Stephens <allan.stephens@windriver.com>2011-10-07 13:37:34 -0400
committerPaul Gortmaker <paul.gortmaker@windriver.com>2011-12-27 11:33:27 -0500
commit4d163a326fa4868cce1bb75dd95855d40e5497c6 (patch)
tree7c126c2875c638bd85c7edc083c3f014a57b6a42 /net/tipc/eth_media.c
parentc61b666e260d5cc2e0203b21c689321e6ab0d676 (diff)
tipc: Add new address conversion routines for Ethernet media
Enhances TIPC's Ethernet media support to provide 3 new address conversion routines, which allow TIPC to interpret an address that is in string form and to convert an address to and from the 20 byte format used in TIPC's neighbor discovery messages. These routines are pre-requisites to a follow on commit that hides all media-specific addressing details from TIPC's generic bearer code. Signed-off-by: Allan Stephens <allan.stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'net/tipc/eth_media.c')
-rw-r--r--net/tipc/eth_media.c63
1 files changed, 61 insertions, 2 deletions
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,