Skip to content

Commit 95772ec

Browse files
committed
Merge branch 'net-More-extack-messages'
David Ahern says: ==================== net: More extack messages Add more extack messages for several link create errors (e.g., invalid number of queues, unknown link kind) and invalid metrics argument. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 0b215b9 + 68d57f3 commit 95772ec

File tree

11 files changed

+48
-25
lines changed

11 files changed

+48
-25
lines changed

drivers/net/can/vxcan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int vxcan_newlink(struct net *net, struct net_device *dev,
207207
return PTR_ERR(peer_net);
208208

209209
peer = rtnl_create_link(peer_net, ifname, name_assign_type,
210-
&vxcan_link_ops, tbp);
210+
&vxcan_link_ops, tbp, extack);
211211
if (IS_ERR(peer)) {
212212
put_net(peer_net);
213213
return PTR_ERR(peer);

drivers/net/geneve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ struct net_device *geneve_dev_create_fb(struct net *net, const char *name,
16661666

16671667
memset(tb, 0, sizeof(tb));
16681668
dev = rtnl_create_link(net, name, name_assign_type,
1669-
&geneve_link_ops, tb);
1669+
&geneve_link_ops, tb, NULL);
16701670
if (IS_ERR(dev))
16711671
return dev;
16721672

drivers/net/veth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
12531253
return PTR_ERR(net);
12541254

12551255
peer = rtnl_create_link(net, ifname, name_assign_type,
1256-
&veth_link_ops, tbp);
1256+
&veth_link_ops, tbp, extack);
12571257
if (IS_ERR(peer)) {
12581258
put_net(net);
12591259
return PTR_ERR(peer);

drivers/net/vxlan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3749,7 +3749,7 @@ struct net_device *vxlan_dev_create(struct net *net, const char *name,
37493749
memset(&tb, 0, sizeof(tb));
37503750

37513751
dev = rtnl_create_link(net, name, name_assign_type,
3752-
&vxlan_link_ops, tb);
3752+
&vxlan_link_ops, tb, NULL);
37533753
if (IS_ERR(dev))
37543754
return dev;
37553755

include/net/ip.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ static inline unsigned int ip_skb_dst_mtu(struct sock *sk,
421421
}
422422

423423
struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
424-
int fc_mx_len);
424+
int fc_mx_len,
425+
struct netlink_ext_ack *extack);
425426
static inline void ip_fib_metrics_put(struct dst_metrics *fib_metrics)
426427
{
427428
if (fib_metrics != &dst_default_metrics &&

include/net/rtnetlink.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
159159
struct net_device *rtnl_create_link(struct net *net, const char *ifname,
160160
unsigned char name_assign_type,
161161
const struct rtnl_link_ops *ops,
162-
struct nlattr *tb[]);
162+
struct nlattr *tb[],
163+
struct netlink_ext_ack *extack);
163164
int rtnl_delete_link(struct net_device *dev);
164165
int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
165166

net/core/rtnetlink.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,9 +2885,11 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm)
28852885
}
28862886
EXPORT_SYMBOL(rtnl_configure_link);
28872887

2888-
struct net_device *rtnl_create_link(struct net *net,
2889-
const char *ifname, unsigned char name_assign_type,
2890-
const struct rtnl_link_ops *ops, struct nlattr *tb[])
2888+
struct net_device *rtnl_create_link(struct net *net, const char *ifname,
2889+
unsigned char name_assign_type,
2890+
const struct rtnl_link_ops *ops,
2891+
struct nlattr *tb[],
2892+
struct netlink_ext_ack *extack)
28912893
{
28922894
struct net_device *dev;
28932895
unsigned int num_tx_queues = 1;
@@ -2903,11 +2905,15 @@ struct net_device *rtnl_create_link(struct net *net,
29032905
else if (ops->get_num_rx_queues)
29042906
num_rx_queues = ops->get_num_rx_queues();
29052907

2906-
if (num_tx_queues < 1 || num_tx_queues > 4096)
2908+
if (num_tx_queues < 1 || num_tx_queues > 4096) {
2909+
NL_SET_ERR_MSG(extack, "Invalid number of transmit queues");
29072910
return ERR_PTR(-EINVAL);
2911+
}
29082912

2909-
if (num_rx_queues < 1 || num_rx_queues > 4096)
2913+
if (num_rx_queues < 1 || num_rx_queues > 4096) {
2914+
NL_SET_ERR_MSG(extack, "Invalid number of receive queues");
29102915
return ERR_PTR(-EINVAL);
2916+
}
29112917

29122918
dev = alloc_netdev_mqs(ops->priv_size, ifname, name_assign_type,
29132919
ops->setup, num_tx_queues, num_rx_queues);
@@ -3048,7 +3054,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
30483054
if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
30493055
err = nla_parse_nested(attr, ops->maxtype,
30503056
linkinfo[IFLA_INFO_DATA],
3051-
ops->policy, NULL);
3057+
ops->policy, extack);
30523058
if (err < 0)
30533059
return err;
30543060
data = attr;
@@ -3070,7 +3076,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
30703076
m_ops->slave_maxtype,
30713077
linkinfo[IFLA_INFO_SLAVE_DATA],
30723078
m_ops->slave_policy,
3073-
NULL);
3079+
extack);
30743080
if (err < 0)
30753081
return err;
30763082
slave_data = slave_attr;
@@ -3134,6 +3140,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
31343140
goto replay;
31353141
}
31363142
#endif
3143+
NL_SET_ERR_MSG(extack, "Unknown device type");
31373144
return -EOPNOTSUPP;
31383145
}
31393146

@@ -3154,6 +3161,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
31543161

31553162
link_net = get_net_ns_by_id(dest_net, id);
31563163
if (!link_net) {
3164+
NL_SET_ERR_MSG(extack, "Unknown network namespace id");
31573165
err = -EINVAL;
31583166
goto out;
31593167
}
@@ -3163,7 +3171,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
31633171
}
31643172

31653173
dev = rtnl_create_link(link_net ? : dest_net, ifname,
3166-
name_assign_type, ops, tb);
3174+
name_assign_type, ops, tb, extack);
31673175
if (IS_ERR(dev)) {
31683176
err = PTR_ERR(dev);
31693177
goto out;

net/ipv4/fib_semantics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
10761076
if (!fi)
10771077
goto failure;
10781078
fi->fib_metrics = ip_fib_metrics_init(fi->fib_net, cfg->fc_mx,
1079-
cfg->fc_mx_len);
1079+
cfg->fc_mx_len, extack);
10801080
if (unlikely(IS_ERR(fi->fib_metrics))) {
10811081
err = PTR_ERR(fi->fib_metrics);
10821082
kfree(fi);

net/ipv4/ip_gre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name,
16011601
memset(&tb, 0, sizeof(tb));
16021602

16031603
dev = rtnl_create_link(net, name, name_assign_type,
1604-
&ipgre_tap_ops, tb);
1604+
&ipgre_tap_ops, tb, NULL);
16051605
if (IS_ERR(dev))
16061606
return dev;
16071607

net/ipv4/metrics.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include <net/tcp.h>
77

88
static int ip_metrics_convert(struct net *net, struct nlattr *fc_mx,
9-
int fc_mx_len, u32 *metrics)
9+
int fc_mx_len, u32 *metrics,
10+
struct netlink_ext_ack *extack)
1011
{
1112
bool ecn_ca = false;
1213
struct nlattr *nla;
@@ -21,19 +22,26 @@ static int ip_metrics_convert(struct net *net, struct nlattr *fc_mx,
2122

2223
if (!type)
2324
continue;
24-
if (type > RTAX_MAX)
25+
if (type > RTAX_MAX) {
26+
NL_SET_ERR_MSG(extack, "Invalid metric type");
2527
return -EINVAL;
28+
}
2629

2730
if (type == RTAX_CC_ALGO) {
2831
char tmp[TCP_CA_NAME_MAX];
2932

3033
nla_strlcpy(tmp, nla, sizeof(tmp));
3134
val = tcp_ca_get_key_by_name(net, tmp, &ecn_ca);
32-
if (val == TCP_CA_UNSPEC)
35+
if (val == TCP_CA_UNSPEC) {
36+
NL_SET_ERR_MSG(extack, "Unknown tcp congestion algorithm");
3337
return -EINVAL;
38+
}
3439
} else {
35-
if (nla_len(nla) != sizeof(u32))
40+
if (nla_len(nla) != sizeof(u32)) {
41+
NL_SET_ERR_MSG_ATTR(extack, nla,
42+
"Invalid attribute in metrics");
3643
return -EINVAL;
44+
}
3745
val = nla_get_u32(nla);
3846
}
3947
if (type == RTAX_ADVMSS && val > 65535 - 40)
@@ -42,8 +50,10 @@ static int ip_metrics_convert(struct net *net, struct nlattr *fc_mx,
4250
val = 65535 - 15;
4351
if (type == RTAX_HOPLIMIT && val > 255)
4452
val = 255;
45-
if (type == RTAX_FEATURES && (val & ~RTAX_FEATURE_MASK))
53+
if (type == RTAX_FEATURES && (val & ~RTAX_FEATURE_MASK)) {
54+
NL_SET_ERR_MSG(extack, "Unknown flag set in feature mask in metrics attribute");
4655
return -EINVAL;
56+
}
4757
metrics[type - 1] = val;
4858
}
4959

@@ -54,7 +64,8 @@ static int ip_metrics_convert(struct net *net, struct nlattr *fc_mx,
5464
}
5565

5666
struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
57-
int fc_mx_len)
67+
int fc_mx_len,
68+
struct netlink_ext_ack *extack)
5869
{
5970
struct dst_metrics *fib_metrics;
6071
int err;
@@ -66,7 +77,8 @@ struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
6677
if (unlikely(!fib_metrics))
6778
return ERR_PTR(-ENOMEM);
6879

69-
err = ip_metrics_convert(net, fc_mx, fc_mx_len, fib_metrics->metrics);
80+
err = ip_metrics_convert(net, fc_mx, fc_mx_len, fib_metrics->metrics,
81+
extack);
7082
if (!err) {
7183
refcount_set(&fib_metrics->refcnt, 1);
7284
} else {

net/ipv6/route.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,8 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
29752975
if (!rt)
29762976
goto out;
29772977

2978-
rt->fib6_metrics = ip_fib_metrics_init(net, cfg->fc_mx, cfg->fc_mx_len);
2978+
rt->fib6_metrics = ip_fib_metrics_init(net, cfg->fc_mx, cfg->fc_mx_len,
2979+
extack);
29792980
if (IS_ERR(rt->fib6_metrics)) {
29802981
err = PTR_ERR(rt->fib6_metrics);
29812982
/* Do not leave garbage there. */
@@ -3708,7 +3709,7 @@ struct fib6_info *addrconf_f6i_alloc(struct net *net,
37083709
if (!f6i)
37093710
return ERR_PTR(-ENOMEM);
37103711

3711-
f6i->fib6_metrics = ip_fib_metrics_init(net, NULL, 0);
3712+
f6i->fib6_metrics = ip_fib_metrics_init(net, NULL, 0, NULL);
37123713
f6i->dst_nocount = true;
37133714
f6i->dst_host = true;
37143715
f6i->fib6_protocol = RTPROT_KERNEL;

0 commit comments

Comments
 (0)