tipc: make legacy address flag readable over netlink

To enable iproute2/tipc to generate backwards compatible
printouts and validate command parameters for nodes using a
<z.c.n> node address, it needs to be able to read the legacy
address flag from the kernel.  The legacy address flag records
the way in which the node identity was originally specified.

The legacy address flag is requested by the netlink message
TIPC_NL_ADDR_LEGACY_GET.  If the flag is set the attribute
TIPC_NLA_NET_ADDR_LEGACY is set in the return message.

Signed-off-by: John Rutherford <john.rutherford@dektech.com.au>
Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
John Rutherford 2019-12-19 16:03:57 +11:00 committed by David S. Miller
parent 17338900cc
commit e1b5e598e5
4 changed files with 65 additions and 0 deletions

View File

@ -65,6 +65,7 @@ enum {
TIPC_NL_UDP_GET_REMOTEIP, TIPC_NL_UDP_GET_REMOTEIP,
TIPC_NL_KEY_SET, TIPC_NL_KEY_SET,
TIPC_NL_KEY_FLUSH, TIPC_NL_KEY_FLUSH,
TIPC_NL_ADDR_LEGACY_GET,
__TIPC_NL_CMD_MAX, __TIPC_NL_CMD_MAX,
TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1 TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
@ -176,6 +177,7 @@ enum {
TIPC_NLA_NET_ADDR, /* u32 */ TIPC_NLA_NET_ADDR, /* u32 */
TIPC_NLA_NET_NODEID, /* u64 */ TIPC_NLA_NET_NODEID, /* u64 */
TIPC_NLA_NET_NODEID_W1, /* u64 */ TIPC_NLA_NET_NODEID_W1, /* u64 */
TIPC_NLA_NET_ADDR_LEGACY, /* flag */
__TIPC_NLA_NET_MAX, __TIPC_NLA_NET_MAX,
TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1 TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1

View File

@ -302,3 +302,59 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
return err; return err;
} }
static int __tipc_nl_addr_legacy_get(struct net *net, struct tipc_nl_msg *msg)
{
struct tipc_net *tn = tipc_net(net);
struct nlattr *attrs;
void *hdr;
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
0, TIPC_NL_ADDR_LEGACY_GET);
if (!hdr)
return -EMSGSIZE;
attrs = nla_nest_start(msg->skb, TIPC_NLA_NET);
if (!attrs)
goto msg_full;
if (tn->legacy_addr_format)
if (nla_put_flag(msg->skb, TIPC_NLA_NET_ADDR_LEGACY))
goto attr_msg_full;
nla_nest_end(msg->skb, attrs);
genlmsg_end(msg->skb, hdr);
return 0;
attr_msg_full:
nla_nest_cancel(msg->skb, attrs);
msg_full:
genlmsg_cancel(msg->skb, hdr);
return -EMSGSIZE;
}
int tipc_nl_net_addr_legacy_get(struct sk_buff *skb, struct genl_info *info)
{
struct net *net = sock_net(skb->sk);
struct tipc_nl_msg msg;
struct sk_buff *rep;
int err;
rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
if (!rep)
return -ENOMEM;
msg.skb = rep;
msg.portid = info->snd_portid;
msg.seq = info->snd_seq;
err = __tipc_nl_addr_legacy_get(net, &msg);
if (err) {
nlmsg_free(msg.skb);
return err;
}
return genlmsg_reply(msg.skb, info);
}

View File

@ -47,5 +47,6 @@ void tipc_net_stop(struct net *net);
int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb);
int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info); int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);
int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info); int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);
int tipc_nl_net_addr_legacy_get(struct sk_buff *skb, struct genl_info *info);
#endif #endif

View File

@ -83,6 +83,7 @@ const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
[TIPC_NLA_NET_ADDR] = { .type = NLA_U32 }, [TIPC_NLA_NET_ADDR] = { .type = NLA_U32 },
[TIPC_NLA_NET_NODEID] = { .type = NLA_U64 }, [TIPC_NLA_NET_NODEID] = { .type = NLA_U64 },
[TIPC_NLA_NET_NODEID_W1] = { .type = NLA_U64 }, [TIPC_NLA_NET_NODEID_W1] = { .type = NLA_U64 },
[TIPC_NLA_NET_ADDR_LEGACY] = { .type = NLA_FLAG }
}; };
const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = { const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = {
@ -273,6 +274,11 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
.doit = tipc_nl_node_flush_key, .doit = tipc_nl_node_flush_key,
}, },
#endif #endif
{
.cmd = TIPC_NL_ADDR_LEGACY_GET,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
.doit = tipc_nl_net_addr_legacy_get,
},
}; };
struct genl_family tipc_genl_family __ro_after_init = { struct genl_family tipc_genl_family __ro_after_init = {