diff options
author | Jon Maloy <jon.maloy@ericsson.com> | 2018-03-22 15:42:52 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-03-23 13:12:18 -0400 |
commit | 52dfae5c85a4c1078e9f1d5e8947d4a25f73dd81 (patch) | |
tree | 86cc334de0ac0f6dad6ebd55fdcdcee97ac50841 /net/tipc | |
parent | 25b0b9c4e835ffaa65b61c3efe2e28acf84d0259 (diff) |
tipc: obtain node identity from interface by default
Selecting and explicitly configuring a TIPC node identity may be
unwanted in some cases.
In this commit we introduce a default setting if the identity has not
been set at the moment the first bearer is enabled. We do this by
using a raw copy of a unique identifier from the used interface: MAC
address in the case of an L2 bearer, IPv4/IPv6 address in the case
of a UDP bearer.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/bearer.c | 24 | ||||
-rw-r--r-- | net/tipc/net.h | 1 | ||||
-rw-r--r-- | net/tipc/udp_media.c | 13 |
3 files changed, 29 insertions, 9 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index ae5b44ca1c1e..f7d47c89d658 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -243,12 +243,6 @@ static int tipc_enable_bearer(struct net *net, const char *name, | |||
243 | int res = -EINVAL; | 243 | int res = -EINVAL; |
244 | char *errstr = ""; | 244 | char *errstr = ""; |
245 | 245 | ||
246 | if (!tipc_own_id(net)) { | ||
247 | errstr = "not supported in standalone mode"; | ||
248 | res = -ENOPROTOOPT; | ||
249 | goto rejected; | ||
250 | } | ||
251 | |||
252 | if (!bearer_name_validate(name, &b_names)) { | 246 | if (!bearer_name_validate(name, &b_names)) { |
253 | errstr = "illegal name"; | 247 | errstr = "illegal name"; |
254 | goto rejected; | 248 | goto rejected; |
@@ -381,11 +375,13 @@ static void bearer_disable(struct net *net, struct tipc_bearer *b) | |||
381 | int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b, | 375 | int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b, |
382 | struct nlattr *attr[]) | 376 | struct nlattr *attr[]) |
383 | { | 377 | { |
378 | char *dev_name = strchr((const char *)b->name, ':') + 1; | ||
379 | int hwaddr_len = b->media->hwaddr_len; | ||
380 | u8 node_id[NODE_ID_LEN] = {0,}; | ||
384 | struct net_device *dev; | 381 | struct net_device *dev; |
385 | char *driver_name = strchr((const char *)b->name, ':') + 1; | ||
386 | 382 | ||
387 | /* Find device with specified name */ | 383 | /* Find device with specified name */ |
388 | dev = dev_get_by_name(net, driver_name); | 384 | dev = dev_get_by_name(net, dev_name); |
389 | if (!dev) | 385 | if (!dev) |
390 | return -ENODEV; | 386 | return -ENODEV; |
391 | if (tipc_mtu_bad(dev, 0)) { | 387 | if (tipc_mtu_bad(dev, 0)) { |
@@ -393,6 +389,16 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b, | |||
393 | return -EINVAL; | 389 | return -EINVAL; |
394 | } | 390 | } |
395 | 391 | ||
392 | /* Autoconfigure own node identity if needed */ | ||
393 | if (!tipc_own_id(net) && hwaddr_len <= NODE_ID_LEN) { | ||
394 | memcpy(node_id, dev->dev_addr, hwaddr_len); | ||
395 | tipc_net_init(net, node_id, 0); | ||
396 | } | ||
397 | if (!tipc_own_id(net)) { | ||
398 | pr_warn("Failed to obtain node identity\n"); | ||
399 | return -EINVAL; | ||
400 | } | ||
401 | |||
396 | /* Associate TIPC bearer with L2 bearer */ | 402 | /* Associate TIPC bearer with L2 bearer */ |
397 | rcu_assign_pointer(b->media_ptr, dev); | 403 | rcu_assign_pointer(b->media_ptr, dev); |
398 | b->pt.dev = dev; | 404 | b->pt.dev = dev; |
@@ -400,7 +406,7 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b, | |||
400 | b->pt.func = tipc_l2_rcv_msg; | 406 | b->pt.func = tipc_l2_rcv_msg; |
401 | dev_add_pack(&b->pt); | 407 | dev_add_pack(&b->pt); |
402 | memset(&b->bcast_addr, 0, sizeof(b->bcast_addr)); | 408 | memset(&b->bcast_addr, 0, sizeof(b->bcast_addr)); |
403 | memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len); | 409 | memcpy(b->bcast_addr.value, dev->broadcast, hwaddr_len); |
404 | b->bcast_addr.media_id = b->media->type_id; | 410 | b->bcast_addr.media_id = b->media->type_id; |
405 | b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT; | 411 | b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT; |
406 | b->mtu = dev->mtu; | 412 | b->mtu = dev->mtu; |
diff --git a/net/tipc/net.h b/net/tipc/net.h index 08efa6010022..09ad02b50bb1 100644 --- a/net/tipc/net.h +++ b/net/tipc/net.h | |||
@@ -41,6 +41,7 @@ | |||
41 | 41 | ||
42 | extern const struct nla_policy tipc_nl_net_policy[]; | 42 | extern const struct nla_policy tipc_nl_net_policy[]; |
43 | 43 | ||
44 | int tipc_net_init(struct net *net, u8 *node_id, u32 addr); | ||
44 | void tipc_net_finalize(struct net *net, u32 addr); | 45 | void tipc_net_finalize(struct net *net, u32 addr); |
45 | void tipc_net_stop(struct net *net); | 46 | void tipc_net_stop(struct net *net); |
46 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); | 47 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); |
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index 3deabcab4882..2c13b18426d9 100644 --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c | |||
@@ -47,6 +47,8 @@ | |||
47 | #include <net/addrconf.h> | 47 | #include <net/addrconf.h> |
48 | #include <linux/tipc_netlink.h> | 48 | #include <linux/tipc_netlink.h> |
49 | #include "core.h" | 49 | #include "core.h" |
50 | #include "addr.h" | ||
51 | #include "net.h" | ||
50 | #include "bearer.h" | 52 | #include "bearer.h" |
51 | #include "netlink.h" | 53 | #include "netlink.h" |
52 | #include "msg.h" | 54 | #include "msg.h" |
@@ -647,6 +649,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, | |||
647 | struct udp_port_cfg udp_conf = {0}; | 649 | struct udp_port_cfg udp_conf = {0}; |
648 | struct udp_tunnel_sock_cfg tuncfg = {NULL}; | 650 | struct udp_tunnel_sock_cfg tuncfg = {NULL}; |
649 | struct nlattr *opts[TIPC_NLA_UDP_MAX + 1]; | 651 | struct nlattr *opts[TIPC_NLA_UDP_MAX + 1]; |
652 | u8 node_id[NODE_ID_LEN] = {0,}; | ||
650 | 653 | ||
651 | ub = kzalloc(sizeof(*ub), GFP_ATOMIC); | 654 | ub = kzalloc(sizeof(*ub), GFP_ATOMIC); |
652 | if (!ub) | 655 | if (!ub) |
@@ -677,6 +680,16 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, | |||
677 | if (err) | 680 | if (err) |
678 | goto err; | 681 | goto err; |
679 | 682 | ||
683 | /* Autoconfigure own node identity if needed */ | ||
684 | if (!tipc_own_id(net)) { | ||
685 | memcpy(node_id, local.ipv6.in6_u.u6_addr8, 16); | ||
686 | tipc_net_init(net, node_id, 0); | ||
687 | } | ||
688 | if (!tipc_own_id(net)) { | ||
689 | pr_warn("Failed to set node id, please configure manually\n"); | ||
690 | return -EINVAL; | ||
691 | } | ||
692 | |||
680 | b->bcast_addr.media_id = TIPC_MEDIA_TYPE_UDP; | 693 | b->bcast_addr.media_id = TIPC_MEDIA_TYPE_UDP; |
681 | b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT; | 694 | b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT; |
682 | rcu_assign_pointer(b->media_ptr, ub); | 695 | rcu_assign_pointer(b->media_ptr, ub); |