Skip to content

Commit 52dfae5

Browse files
Jon Maloydavem330
authored andcommitted
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>
1 parent 25b0b9c commit 52dfae5

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

net/tipc/bearer.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,6 @@ static int tipc_enable_bearer(struct net *net, const char *name,
243243
int res = -EINVAL;
244244
char *errstr = "";
245245

246-
if (!tipc_own_id(net)) {
247-
errstr = "not supported in standalone mode";
248-
res = -ENOPROTOOPT;
249-
goto rejected;
250-
}
251-
252246
if (!bearer_name_validate(name, &b_names)) {
253247
errstr = "illegal name";
254248
goto rejected;
@@ -381,26 +375,38 @@ static void bearer_disable(struct net *net, struct tipc_bearer *b)
381375
int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
382376
struct nlattr *attr[])
383377
{
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,};
384381
struct net_device *dev;
385-
char *driver_name = strchr((const char *)b->name, ':') + 1;
386382

387383
/* Find device with specified name */
388-
dev = dev_get_by_name(net, driver_name);
384+
dev = dev_get_by_name(net, dev_name);
389385
if (!dev)
390386
return -ENODEV;
391387
if (tipc_mtu_bad(dev, 0)) {
392388
dev_put(dev);
393389
return -EINVAL;
394390
}
395391

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+
396402
/* Associate TIPC bearer with L2 bearer */
397403
rcu_assign_pointer(b->media_ptr, dev);
398404
b->pt.dev = dev;
399405
b->pt.type = htons(ETH_P_TIPC);
400406
b->pt.func = tipc_l2_rcv_msg;
401407
dev_add_pack(&b->pt);
402408
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);
404410
b->bcast_addr.media_id = b->media->type_id;
405411
b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT;
406412
b->mtu = dev->mtu;

net/tipc/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
extern const struct nla_policy tipc_nl_net_policy[];
4343

44+
int tipc_net_init(struct net *net, u8 *node_id, u32 addr);
4445
void tipc_net_finalize(struct net *net, u32 addr);
4546
void tipc_net_stop(struct net *net);
4647
int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb);

net/tipc/udp_media.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <net/addrconf.h>
4848
#include <linux/tipc_netlink.h>
4949
#include "core.h"
50+
#include "addr.h"
51+
#include "net.h"
5052
#include "bearer.h"
5153
#include "netlink.h"
5254
#include "msg.h"
@@ -647,6 +649,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
647649
struct udp_port_cfg udp_conf = {0};
648650
struct udp_tunnel_sock_cfg tuncfg = {NULL};
649651
struct nlattr *opts[TIPC_NLA_UDP_MAX + 1];
652+
u8 node_id[NODE_ID_LEN] = {0,};
650653

651654
ub = kzalloc(sizeof(*ub), GFP_ATOMIC);
652655
if (!ub)
@@ -677,6 +680,16 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
677680
if (err)
678681
goto err;
679682

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+
680693
b->bcast_addr.media_id = TIPC_MEDIA_TYPE_UDP;
681694
b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT;
682695
rcu_assign_pointer(b->media_ptr, ub);

0 commit comments

Comments
 (0)