aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/bearer.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-05-14 05:39:13 -0400
committerDavid S. Miller <davem@davemloft.net>2014-05-14 15:19:48 -0400
commit38504c28a201a80d12a6a0f821fecb331cb1f223 (patch)
tree001139319f80f9d00cfa510638f61a1ec1725459 /net/tipc/bearer.c
parent37e22164a8a3c39bdad45aa463b1e69a1fdf4110 (diff)
tipc: improve and extend media address conversion functions
TIPC currently handles two media specific addresses: Ethernet MAC addresses and InfiniBand addresses. Those are kept in three different formats: 1) A "raw" format as obtained from the device. This format is known only by the media specific adapter code in eth_media.c and ib_media.c. 2) A "generic" internal format, in the form of struct tipc_media_addr, which can be referenced and passed around by the generic media- unaware code. 3) A serialized version of the latter, to be conveyed in neighbor discovery messages. Conversion between the three formats can only be done by the media specific code, so we have function pointers for this purpose in struct tipc_media. Here, the media adapters can install their own conversion functions at startup. We now introduce a new such function, 'raw2addr()', whose purpose is to convert from format 1 to format 2 above. We also try to as far as possible uniform commenting, variable names and usage of these functions, with the purpose of making them more comprehensible. We can now also remove the function tipc_l2_media_addr_set(), whose job is done better by the new function. Finally, we expand the field for serialized addresses (format 3) in discovery messages from 20 to 32 bytes. This is permitted according to the spec, and reduces the risk of problems when we add new media in the future. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/bearer.c')
-rw-r--r--net/tipc/bearer.c36
1 files changed, 7 insertions, 29 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index f3259d4133b6..264474394f9f 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -411,28 +411,6 @@ int tipc_disable_bearer(const char *name)
411 return res; 411 return res;
412} 412}
413 413
414
415/* tipc_l2_media_addr_set - initialize Ethernet media address structure
416 *
417 * Media-dependent "value" field stores MAC address in first 6 bytes
418 * and zeroes out the remaining bytes.
419 */
420void tipc_l2_media_addr_set(const struct tipc_bearer *b,
421 struct tipc_media_addr *a, char *mac)
422{
423 int len = b->media->hwaddr_len;
424
425 if (unlikely(sizeof(a->value) < len)) {
426 WARN_ONCE(1, "Media length invalid\n");
427 return;
428 }
429
430 memcpy(a->value, mac, len);
431 memset(a->value + len, 0, sizeof(a->value) - len);
432 a->media_id = b->media->type_id;
433 a->broadcast = !memcmp(mac, b->bcast_addr.value, len);
434}
435
436int tipc_enable_l2_media(struct tipc_bearer *b) 414int tipc_enable_l2_media(struct tipc_bearer *b)
437{ 415{
438 struct net_device *dev; 416 struct net_device *dev;
@@ -443,21 +421,21 @@ int tipc_enable_l2_media(struct tipc_bearer *b)
443 if (!dev) 421 if (!dev)
444 return -ENODEV; 422 return -ENODEV;
445 423
446 /* Associate TIPC bearer with Ethernet bearer */ 424 /* Associate TIPC bearer with L2 bearer */
447 rcu_assign_pointer(b->media_ptr, dev); 425 rcu_assign_pointer(b->media_ptr, dev);
448 memset(b->bcast_addr.value, 0, sizeof(b->bcast_addr.value)); 426 memset(&b->bcast_addr, 0, sizeof(b->bcast_addr));
449 memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len); 427 memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
450 b->bcast_addr.media_id = b->media->type_id; 428 b->bcast_addr.media_id = b->media->type_id;
451 b->bcast_addr.broadcast = 1; 429 b->bcast_addr.broadcast = 1;
452 b->mtu = dev->mtu; 430 b->mtu = dev->mtu;
453 tipc_l2_media_addr_set(b, &b->addr, (char *)dev->dev_addr); 431 b->media->raw2addr(b, &b->addr, (char *)dev->dev_addr);
454 rcu_assign_pointer(dev->tipc_ptr, b); 432 rcu_assign_pointer(dev->tipc_ptr, b);
455 return 0; 433 return 0;
456} 434}
457 435
458/* tipc_disable_l2_media - detach TIPC bearer from an Ethernet interface 436/* tipc_disable_l2_media - detach TIPC bearer from an L2 interface
459 * 437 *
460 * Mark Ethernet bearer as inactive so that incoming buffers are thrown away, 438 * Mark L2 bearer as inactive so that incoming buffers are thrown away,
461 * then get worker thread to complete bearer cleanup. (Can't do cleanup 439 * then get worker thread to complete bearer cleanup. (Can't do cleanup
462 * here because cleanup code needs to sleep and caller holds spinlocks.) 440 * here because cleanup code needs to sleep and caller holds spinlocks.)
463 */ 441 */
@@ -473,7 +451,7 @@ void tipc_disable_l2_media(struct tipc_bearer *b)
473} 451}
474 452
475/** 453/**
476 * tipc_l2_send_msg - send a TIPC packet out over an Ethernet interface 454 * tipc_l2_send_msg - send a TIPC packet out over an L2 interface
477 * @buf: the packet to be sent 455 * @buf: the packet to be sent
478 * @b_ptr: the bearer through which the packet is to be sent 456 * @b_ptr: the bearer through which the packet is to be sent
479 * @dest: peer destination address 457 * @dest: peer destination address
@@ -597,7 +575,7 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
597 tipc_reset_bearer(b_ptr); 575 tipc_reset_bearer(b_ptr);
598 break; 576 break;
599 case NETDEV_CHANGEADDR: 577 case NETDEV_CHANGEADDR:
600 tipc_l2_media_addr_set(b_ptr, &b_ptr->addr, 578 b_ptr->media->raw2addr(b_ptr, &b_ptr->addr,
601 (char *)dev->dev_addr); 579 (char *)dev->dev_addr);
602 tipc_reset_bearer(b_ptr); 580 tipc_reset_bearer(b_ptr);
603 break; 581 break;