Commit 78055998 authored by David Ahern's avatar David Ahern Committed by David S. Miller

net: ipv4: Add extack message for invalid prefix or length

Add extack error message for invalid prefix length and invalid prefix.
Example of the latter is a route spec containing 172.16.100.1/24, where
the /24 mask means the lower 8-bits should be 0. Amazing how easy that
one is to overlook when an EINVAL is returned.
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ba277e8e
...@@ -266,7 +266,8 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, ...@@ -266,7 +266,8 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
struct fib_result *res, int fib_flags); struct fib_result *res, int fib_flags);
int fib_table_insert(struct net *, struct fib_table *, struct fib_config *, int fib_table_insert(struct net *, struct fib_table *, struct fib_config *,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int fib_table_delete(struct net *, struct fib_table *, struct fib_config *); int fib_table_delete(struct net *, struct fib_table *, struct fib_config *,
struct netlink_ext_ack *extack);
int fib_table_dump(struct fib_table *table, struct sk_buff *skb, int fib_table_dump(struct fib_table *table, struct sk_buff *skb,
struct netlink_callback *cb); struct netlink_callback *cb);
int fib_table_flush(struct net *net, struct fib_table *table); int fib_table_flush(struct net *net, struct fib_table *table);
......
...@@ -588,7 +588,8 @@ int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg) ...@@ -588,7 +588,8 @@ int ip_rt_ioctl(struct net *net, unsigned int cmd, void __user *arg)
if (cmd == SIOCDELRT) { if (cmd == SIOCDELRT) {
tb = fib_get_table(net, cfg.fc_table); tb = fib_get_table(net, cfg.fc_table);
if (tb) if (tb)
err = fib_table_delete(net, tb, &cfg); err = fib_table_delete(net, tb, &cfg,
NULL);
else else
err = -ESRCH; err = -ESRCH;
} else { } else {
...@@ -732,7 +733,7 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -732,7 +733,7 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
goto errout; goto errout;
} }
err = fib_table_delete(net, tb, &cfg); err = fib_table_delete(net, tb, &cfg, extack);
errout: errout:
return err; return err;
} }
...@@ -851,7 +852,7 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad ...@@ -851,7 +852,7 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad
if (cmd == RTM_NEWROUTE) if (cmd == RTM_NEWROUTE)
fib_table_insert(net, tb, &cfg, NULL); fib_table_insert(net, tb, &cfg, NULL);
else else
fib_table_delete(net, tb, &cfg); fib_table_delete(net, tb, &cfg, NULL);
} }
void fib_add_ifaddr(struct in_ifaddr *ifa) void fib_add_ifaddr(struct in_ifaddr *ifa)
......
...@@ -1099,13 +1099,18 @@ static int fib_insert_alias(struct trie *t, struct key_vector *tp, ...@@ -1099,13 +1099,18 @@ static int fib_insert_alias(struct trie *t, struct key_vector *tp,
return 0; return 0;
} }
static bool fib_valid_key_len(u32 key, u8 plen) static bool fib_valid_key_len(u32 key, u8 plen, struct netlink_ext_ack *extack)
{ {
if (plen > KEYLENGTH) if (plen > KEYLENGTH) {
NL_SET_ERR_MSG(extack, "Invalid prefix length");
return false; return false;
}
if ((plen < KEYLENGTH) && (key << plen)) if ((plen < KEYLENGTH) && (key << plen)) {
NL_SET_ERR_MSG(extack,
"Invalid prefix for given prefix length");
return false; return false;
}
return true; return true;
} }
...@@ -1128,7 +1133,7 @@ int fib_table_insert(struct net *net, struct fib_table *tb, ...@@ -1128,7 +1133,7 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
key = ntohl(cfg->fc_dst); key = ntohl(cfg->fc_dst);
if (!fib_valid_key_len(key, plen)) if (!fib_valid_key_len(key, plen, extack))
return -EINVAL; return -EINVAL;
pr_debug("Insert table=%u %08x/%d\n", tb->tb_id, key, plen); pr_debug("Insert table=%u %08x/%d\n", tb->tb_id, key, plen);
...@@ -1516,7 +1521,7 @@ static void fib_remove_alias(struct trie *t, struct key_vector *tp, ...@@ -1516,7 +1521,7 @@ static void fib_remove_alias(struct trie *t, struct key_vector *tp,
/* Caller must hold RTNL. */ /* Caller must hold RTNL. */
int fib_table_delete(struct net *net, struct fib_table *tb, int fib_table_delete(struct net *net, struct fib_table *tb,
struct fib_config *cfg) struct fib_config *cfg, struct netlink_ext_ack *extack)
{ {
struct trie *t = (struct trie *) tb->tb_data; struct trie *t = (struct trie *) tb->tb_data;
struct fib_alias *fa, *fa_to_delete; struct fib_alias *fa, *fa_to_delete;
...@@ -1528,7 +1533,7 @@ int fib_table_delete(struct net *net, struct fib_table *tb, ...@@ -1528,7 +1533,7 @@ int fib_table_delete(struct net *net, struct fib_table *tb,
key = ntohl(cfg->fc_dst); key = ntohl(cfg->fc_dst);
if (!fib_valid_key_len(key, plen)) if (!fib_valid_key_len(key, plen, extack))
return -EINVAL; return -EINVAL;
l = fib_find_node(t, &tp, key); l = fib_find_node(t, &tp, key);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment