tipc: add extack messages for bearer/media failure

Add extack error messages for -EINVAL errors when enabling bearer,
getting/setting properties for a media/bearer

Acked-by: Jon Maloy <jmaloy@redhat.com>
Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Hoang Le 2021-03-25 08:56:41 +07:00 committed by David S. Miller
parent 50dad399ca
commit b83e214b2e

View File

@ -243,7 +243,8 @@ void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest)
*/ */
static int tipc_enable_bearer(struct net *net, const char *name, static int tipc_enable_bearer(struct net *net, const char *name,
u32 disc_domain, u32 prio, u32 disc_domain, u32 prio,
struct nlattr *attr[]) struct nlattr *attr[],
struct netlink_ext_ack *extack)
{ {
struct tipc_net *tn = tipc_net(net); struct tipc_net *tn = tipc_net(net);
struct tipc_bearer_names b_names; struct tipc_bearer_names b_names;
@ -257,17 +258,20 @@ static int tipc_enable_bearer(struct net *net, const char *name,
if (!bearer_name_validate(name, &b_names)) { if (!bearer_name_validate(name, &b_names)) {
errstr = "illegal name"; errstr = "illegal name";
NL_SET_ERR_MSG(extack, "Illegal name");
goto rejected; goto rejected;
} }
if (prio > TIPC_MAX_LINK_PRI && prio != TIPC_MEDIA_LINK_PRI) { if (prio > TIPC_MAX_LINK_PRI && prio != TIPC_MEDIA_LINK_PRI) {
errstr = "illegal priority"; errstr = "illegal priority";
NL_SET_ERR_MSG(extack, "Illegal priority");
goto rejected; goto rejected;
} }
m = tipc_media_find(b_names.media_name); m = tipc_media_find(b_names.media_name);
if (!m) { if (!m) {
errstr = "media not registered"; errstr = "media not registered";
NL_SET_ERR_MSG(extack, "Media not registered");
goto rejected; goto rejected;
} }
@ -281,6 +285,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
break; break;
if (!strcmp(name, b->name)) { if (!strcmp(name, b->name)) {
errstr = "already enabled"; errstr = "already enabled";
NL_SET_ERR_MSG(extack, "Already enabled");
goto rejected; goto rejected;
} }
bearer_id++; bearer_id++;
@ -292,6 +297,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
name, prio); name, prio);
if (prio == TIPC_MIN_LINK_PRI) { if (prio == TIPC_MIN_LINK_PRI) {
errstr = "cannot adjust to lower"; errstr = "cannot adjust to lower";
NL_SET_ERR_MSG(extack, "Cannot adjust to lower");
goto rejected; goto rejected;
} }
pr_warn("Bearer <%s>: trying with adjusted priority\n", name); pr_warn("Bearer <%s>: trying with adjusted priority\n", name);
@ -302,6 +308,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
if (bearer_id >= MAX_BEARERS) { if (bearer_id >= MAX_BEARERS) {
errstr = "max 3 bearers permitted"; errstr = "max 3 bearers permitted";
NL_SET_ERR_MSG(extack, "Max 3 bearers permitted");
goto rejected; goto rejected;
} }
@ -315,6 +322,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
if (res) { if (res) {
kfree(b); kfree(b);
errstr = "failed to enable media"; errstr = "failed to enable media";
NL_SET_ERR_MSG(extack, "Failed to enable media");
goto rejected; goto rejected;
} }
@ -331,6 +339,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
if (res) { if (res) {
bearer_disable(net, b); bearer_disable(net, b);
errstr = "failed to create discoverer"; errstr = "failed to create discoverer";
NL_SET_ERR_MSG(extack, "Failed to create discoverer");
goto rejected; goto rejected;
} }
@ -909,6 +918,7 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
bearer = tipc_bearer_find(net, name); bearer = tipc_bearer_find(net, name);
if (!bearer) { if (!bearer) {
err = -EINVAL; err = -EINVAL;
NL_SET_ERR_MSG(info->extack, "Bearer not found");
goto err_out; goto err_out;
} }
@ -948,8 +958,10 @@ int __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
bearer = tipc_bearer_find(net, name); bearer = tipc_bearer_find(net, name);
if (!bearer) if (!bearer) {
NL_SET_ERR_MSG(info->extack, "Bearer not found");
return -EINVAL; return -EINVAL;
}
bearer_disable(net, bearer); bearer_disable(net, bearer);
@ -1007,7 +1019,8 @@ int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]); prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
} }
return tipc_enable_bearer(net, bearer, domain, prio, attrs); return tipc_enable_bearer(net, bearer, domain, prio, attrs,
info->extack);
} }
int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
@ -1046,6 +1059,7 @@ int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
b = tipc_bearer_find(net, name); b = tipc_bearer_find(net, name);
if (!b) { if (!b) {
rtnl_unlock(); rtnl_unlock();
NL_SET_ERR_MSG(info->extack, "Bearer not found");
return -EINVAL; return -EINVAL;
} }
@ -1086,8 +1100,10 @@ int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
b = tipc_bearer_find(net, name); b = tipc_bearer_find(net, name);
if (!b) if (!b) {
NL_SET_ERR_MSG(info->extack, "Bearer not found");
return -EINVAL; return -EINVAL;
}
if (attrs[TIPC_NLA_BEARER_PROP]) { if (attrs[TIPC_NLA_BEARER_PROP]) {
struct nlattr *props[TIPC_NLA_PROP_MAX + 1]; struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
@ -1106,12 +1122,18 @@ int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
if (props[TIPC_NLA_PROP_WIN]) if (props[TIPC_NLA_PROP_WIN])
b->max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]); b->max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
if (props[TIPC_NLA_PROP_MTU]) { if (props[TIPC_NLA_PROP_MTU]) {
if (b->media->type_id != TIPC_MEDIA_TYPE_UDP) if (b->media->type_id != TIPC_MEDIA_TYPE_UDP) {
NL_SET_ERR_MSG(info->extack,
"MTU property is unsupported");
return -EINVAL; return -EINVAL;
}
#ifdef CONFIG_TIPC_MEDIA_UDP #ifdef CONFIG_TIPC_MEDIA_UDP
if (tipc_udp_mtu_bad(nla_get_u32 if (tipc_udp_mtu_bad(nla_get_u32
(props[TIPC_NLA_PROP_MTU]))) (props[TIPC_NLA_PROP_MTU]))) {
NL_SET_ERR_MSG(info->extack,
"MTU value is out-of-range");
return -EINVAL; return -EINVAL;
}
b->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]); b->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]);
tipc_node_apply_property(net, b, TIPC_NLA_PROP_MTU); tipc_node_apply_property(net, b, TIPC_NLA_PROP_MTU);
#endif #endif
@ -1239,6 +1261,7 @@ int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
rtnl_lock(); rtnl_lock();
media = tipc_media_find(name); media = tipc_media_find(name);
if (!media) { if (!media) {
NL_SET_ERR_MSG(info->extack, "Media not found");
err = -EINVAL; err = -EINVAL;
goto err_out; goto err_out;
} }
@ -1275,9 +1298,10 @@ int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]); name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
m = tipc_media_find(name); m = tipc_media_find(name);
if (!m) if (!m) {
NL_SET_ERR_MSG(info->extack, "Media not found");
return -EINVAL; return -EINVAL;
}
if (attrs[TIPC_NLA_MEDIA_PROP]) { if (attrs[TIPC_NLA_MEDIA_PROP]) {
struct nlattr *props[TIPC_NLA_PROP_MAX + 1]; struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
@ -1293,12 +1317,18 @@ int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
if (props[TIPC_NLA_PROP_WIN]) if (props[TIPC_NLA_PROP_WIN])
m->max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]); m->max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
if (props[TIPC_NLA_PROP_MTU]) { if (props[TIPC_NLA_PROP_MTU]) {
if (m->type_id != TIPC_MEDIA_TYPE_UDP) if (m->type_id != TIPC_MEDIA_TYPE_UDP) {
NL_SET_ERR_MSG(info->extack,
"MTU property is unsupported");
return -EINVAL; return -EINVAL;
}
#ifdef CONFIG_TIPC_MEDIA_UDP #ifdef CONFIG_TIPC_MEDIA_UDP
if (tipc_udp_mtu_bad(nla_get_u32 if (tipc_udp_mtu_bad(nla_get_u32
(props[TIPC_NLA_PROP_MTU]))) (props[TIPC_NLA_PROP_MTU]))) {
NL_SET_ERR_MSG(info->extack,
"MTU value is out-of-range");
return -EINVAL; return -EINVAL;
}
m->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]); m->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]);
#endif #endif
} }