Skip to content

Commit d7e774f

Browse files
dsaherndavem330
authored andcommitted
net: Add extack argument to ip_fib_metrics_init
Add extack argument to ip_fib_metrics_init and add messages for invalid metrics. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d0522f1 commit d7e774f

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

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 &&

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/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)