diff options
-rw-r--r-- | net/tipc/bearer.c | 36 | ||||
-rw-r--r-- | net/tipc/bearer.h | 35 | ||||
-rw-r--r-- | net/tipc/core.h | 1 | ||||
-rw-r--r-- | net/tipc/discover.c | 2 | ||||
-rw-r--r-- | net/tipc/eth_media.c | 51 | ||||
-rw-r--r-- | net/tipc/ib_media.c | 34 |
6 files changed, 83 insertions, 76 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 | */ | ||
420 | void 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 | |||
436 | int tipc_enable_l2_media(struct tipc_bearer *b) | 414 | int 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; |
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index a983b3005e71..78fccc49de23 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
@@ -42,14 +42,12 @@ | |||
42 | #define MAX_BEARERS 2 | 42 | #define MAX_BEARERS 2 |
43 | #define MAX_MEDIA 2 | 43 | #define MAX_MEDIA 2 |
44 | 44 | ||
45 | /* | 45 | /* Identifiers associated with TIPC message header media address info |
46 | * Identifiers associated with TIPC message header media address info | 46 | * - address info field is 32 bytes long |
47 | * | 47 | * - the field's actual content and length is defined per media |
48 | * - address info field is 20 bytes long | 48 | * - remaining unused bytes in the field are set to zero |
49 | * - media type identifier located at offset 3 | ||
50 | * - remaining bytes vary according to media type | ||
51 | */ | 49 | */ |
52 | #define TIPC_MEDIA_ADDR_SIZE 20 | 50 | #define TIPC_MEDIA_ADDR_SIZE 32 |
53 | #define TIPC_MEDIA_TYPE_OFFSET 3 | 51 | #define TIPC_MEDIA_TYPE_OFFSET 3 |
54 | 52 | ||
55 | /* | 53 | /* |
@@ -77,9 +75,10 @@ struct tipc_bearer; | |||
77 | * @send_msg: routine which handles buffer transmission | 75 | * @send_msg: routine which handles buffer transmission |
78 | * @enable_media: routine which enables a media | 76 | * @enable_media: routine which enables a media |
79 | * @disable_media: routine which disables a media | 77 | * @disable_media: routine which disables a media |
80 | * @addr2str: routine which converts media address to string | 78 | * @addr2str: convert media address format to string |
81 | * @addr2msg: routine which converts media address to protocol message area | 79 | * @addr2msg: convert from media addr format to discovery msg addr format |
82 | * @msg2addr: routine which converts media address from protocol message area | 80 | * @msg2addr: convert from discovery msg addr format to media addr format |
81 | * @raw2addr: convert from raw addr format to media addr format | ||
83 | * @priority: default link (and bearer) priority | 82 | * @priority: default link (and bearer) priority |
84 | * @tolerance: default time (in ms) before declaring link failure | 83 | * @tolerance: default time (in ms) before declaring link failure |
85 | * @window: default window (in packets) before declaring link congestion | 84 | * @window: default window (in packets) before declaring link congestion |
@@ -93,10 +92,16 @@ struct tipc_media { | |||
93 | struct tipc_media_addr *dest); | 92 | struct tipc_media_addr *dest); |
94 | int (*enable_media)(struct tipc_bearer *b_ptr); | 93 | int (*enable_media)(struct tipc_bearer *b_ptr); |
95 | void (*disable_media)(struct tipc_bearer *b_ptr); | 94 | void (*disable_media)(struct tipc_bearer *b_ptr); |
96 | int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size); | 95 | int (*addr2str)(struct tipc_media_addr *addr, |
97 | int (*addr2msg)(struct tipc_media_addr *a, char *msg_area); | 96 | char *strbuf, |
98 | int (*msg2addr)(const struct tipc_bearer *b_ptr, | 97 | int bufsz); |
99 | struct tipc_media_addr *a, char *msg_area); | 98 | int (*addr2msg)(char *msg, struct tipc_media_addr *addr); |
99 | int (*msg2addr)(struct tipc_bearer *b, | ||
100 | struct tipc_media_addr *addr, | ||
101 | char *msg); | ||
102 | int (*raw2addr)(struct tipc_bearer *b, | ||
103 | struct tipc_media_addr *addr, | ||
104 | char *raw); | ||
100 | u32 priority; | 105 | u32 priority; |
101 | u32 tolerance; | 106 | u32 tolerance; |
102 | u32 window; | 107 | u32 window; |
@@ -175,8 +180,6 @@ int tipc_media_set_priority(const char *name, u32 new_value); | |||
175 | int tipc_media_set_window(const char *name, u32 new_value); | 180 | int tipc_media_set_window(const char *name, u32 new_value); |
176 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); | 181 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); |
177 | struct sk_buff *tipc_media_get_names(void); | 182 | struct sk_buff *tipc_media_get_names(void); |
178 | void tipc_l2_media_addr_set(const struct tipc_bearer *b, | ||
179 | struct tipc_media_addr *a, char *mac); | ||
180 | int tipc_enable_l2_media(struct tipc_bearer *b); | 183 | int tipc_enable_l2_media(struct tipc_bearer *b); |
181 | void tipc_disable_l2_media(struct tipc_bearer *b); | 184 | void tipc_disable_l2_media(struct tipc_bearer *b); |
182 | int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, | 185 | int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, |
diff --git a/net/tipc/core.h b/net/tipc/core.h index 2e00682bc455..bb26ed1ee966 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
@@ -57,6 +57,7 @@ | |||
57 | #include <linux/slab.h> | 57 | #include <linux/slab.h> |
58 | #include <linux/vmalloc.h> | 58 | #include <linux/vmalloc.h> |
59 | #include <linux/rtnetlink.h> | 59 | #include <linux/rtnetlink.h> |
60 | #include <linux/etherdevice.h> | ||
60 | 61 | ||
61 | #define TIPC_MOD_VER "2.0.0" | 62 | #define TIPC_MOD_VER "2.0.0" |
62 | 63 | ||
diff --git a/net/tipc/discover.c b/net/tipc/discover.c index bd35c4a0746f..b15cbedfea13 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c | |||
@@ -83,7 +83,7 @@ static void tipc_disc_init_msg(struct sk_buff *buf, u32 type, | |||
83 | msg_set_node_sig(msg, tipc_random); | 83 | msg_set_node_sig(msg, tipc_random); |
84 | msg_set_dest_domain(msg, dest_domain); | 84 | msg_set_dest_domain(msg, dest_domain); |
85 | msg_set_bc_netid(msg, tipc_net_id); | 85 | msg_set_bc_netid(msg, tipc_net_id); |
86 | b_ptr->media->addr2msg(&b_ptr->addr, msg_media_addr(msg)); | 86 | b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr); |
87 | } | 87 | } |
88 | 88 | ||
89 | /** | 89 | /** |
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 | |||
diff --git a/net/tipc/ib_media.c b/net/tipc/ib_media.c index 844a77e25828..8522eef9c136 100644 --- a/net/tipc/ib_media.c +++ b/net/tipc/ib_media.c | |||
@@ -42,7 +42,7 @@ | |||
42 | #include "core.h" | 42 | #include "core.h" |
43 | #include "bearer.h" | 43 | #include "bearer.h" |
44 | 44 | ||
45 | /* convert InfiniBand address to string */ | 45 | /* convert InfiniBand address (media address format) media address to string */ |
46 | static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf, | 46 | static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf, |
47 | int str_size) | 47 | int str_size) |
48 | { | 48 | { |
@@ -54,23 +54,35 @@ static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf, | |||
54 | return 0; | 54 | return 0; |
55 | } | 55 | } |
56 | 56 | ||
57 | /* convert InfiniBand address format to message header format */ | 57 | /* Convert from media address format to discovery message addr format */ |
58 | static int tipc_ib_addr2msg(struct tipc_media_addr *a, char *msg_area) | 58 | static int tipc_ib_addr2msg(char *msg, struct tipc_media_addr *addr) |
59 | { | 59 | { |
60 | memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); | 60 | memset(msg, 0, TIPC_MEDIA_ADDR_SIZE); |
61 | msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB; | 61 | memcpy(msg, addr->value, INFINIBAND_ALEN); |
62 | memcpy(msg_area, a->value, INFINIBAND_ALEN); | ||
63 | return 0; | 62 | return 0; |
64 | } | 63 | } |
65 | 64 | ||
66 | /* convert message header address format to InfiniBand format */ | 65 | /* Convert raw InfiniBand address format to media addr format */ |
67 | static int tipc_ib_msg2addr(const struct tipc_bearer *tb_ptr, | 66 | static int tipc_ib_raw2addr(struct tipc_bearer *b, |
68 | struct tipc_media_addr *a, char *msg_area) | 67 | struct tipc_media_addr *addr, |
68 | char *msg) | ||
69 | { | 69 | { |
70 | tipc_l2_media_addr_set(tb_ptr, a, msg_area); | 70 | memset(addr, 0, sizeof(*addr)); |
71 | memcpy(addr->value, msg, INFINIBAND_ALEN); | ||
72 | addr->media_id = TIPC_MEDIA_TYPE_IB; | ||
73 | addr->broadcast = !memcmp(msg, b->bcast_addr.value, | ||
74 | INFINIBAND_ALEN); | ||
71 | return 0; | 75 | return 0; |
72 | } | 76 | } |
73 | 77 | ||
78 | /* Convert discovery msg addr format to InfiniBand media addr format */ | ||
79 | static int tipc_ib_msg2addr(struct tipc_bearer *b, | ||
80 | struct tipc_media_addr *addr, | ||
81 | char *msg) | ||
82 | { | ||
83 | return tipc_ib_raw2addr(b, addr, msg); | ||
84 | } | ||
85 | |||
74 | /* InfiniBand media registration info */ | 86 | /* InfiniBand media registration info */ |
75 | struct tipc_media ib_media_info = { | 87 | struct tipc_media ib_media_info = { |
76 | .send_msg = tipc_l2_send_msg, | 88 | .send_msg = tipc_l2_send_msg, |
@@ -79,6 +91,7 @@ struct tipc_media ib_media_info = { | |||
79 | .addr2str = tipc_ib_addr2str, | 91 | .addr2str = tipc_ib_addr2str, |
80 | .addr2msg = tipc_ib_addr2msg, | 92 | .addr2msg = tipc_ib_addr2msg, |
81 | .msg2addr = tipc_ib_msg2addr, | 93 | .msg2addr = tipc_ib_msg2addr, |
94 | .raw2addr = tipc_ib_raw2addr, | ||
82 | .priority = TIPC_DEF_LINK_PRI, | 95 | .priority = TIPC_DEF_LINK_PRI, |
83 | .tolerance = TIPC_DEF_LINK_TOL, | 96 | .tolerance = TIPC_DEF_LINK_TOL, |
84 | .window = TIPC_DEF_LINK_WIN, | 97 | .window = TIPC_DEF_LINK_WIN, |
@@ -86,4 +99,3 @@ struct tipc_media ib_media_info = { | |||
86 | .hwaddr_len = INFINIBAND_ALEN, | 99 | .hwaddr_len = INFINIBAND_ALEN, |
87 | .name = "ib" | 100 | .name = "ib" |
88 | }; | 101 | }; |
89 | |||