Introduce RTNH_F_REJECT_MASK mask which contains
all rtnh_flags which can't be set by the userspace
directly.
This mask will be used in the iproute utility
to exclude rtnh_flags which can't be restored
from "ip route save" image.
This patch doesn't change kernel behavior, but
it looks like we need to prohibit setting
RTNH_F_OFFLOAD, RTNH_F_TRAP flags too.
Am I right?
Please, take a look on
[RFC PATCH iproute2] ip route: save: exclude rtnh_flags which can't be set
Cc: David Miller <davem@davemloft.net>
Cc: David Ahern <redacted>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Andrei Vagin <redacted>
Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: Alexander Mikhalitsyn <redacted>
Signed-off-by: Alexander Mikhalitsyn <redacted>
---
include/uapi/linux/rtnetlink.h | 3 +++
net/ipv4/fib_semantics.c | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 5888492a5257..c15e591e5d25 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -417,6 +417,9 @@ struct rtnexthop {
#define RTNH_COMPARE_MASK (RTNH_F_DEAD | RTNH_F_LINKDOWN | \
RTNH_F_OFFLOAD | RTNH_F_TRAP)
+/* these flags can't be set by the userspace */
+#define RTNH_F_REJECT_MASK (RTNH_F_DEAD | RTNH_F_LINKDOWN)
+
/* Macros to handle hexthops */
#define RTNH_ALIGNTO 4diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 4c0c33e4710d..7a383c54fe46 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -685,7 +685,7 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
return -EINVAL;
}
- if (rtnh->rtnh_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN)) {
+ if (rtnh->rtnh_flags & RTNH_F_REJECT_MASK) {
NL_SET_ERR_MSG(extack,
"Invalid flags for nexthop - can not contain DEAD or LINKDOWN");
return -EINVAL;@@ -1363,7 +1363,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
goto err_inval;
}
- if (cfg->fc_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN)) {
+ if (cfg->fc_flags & RTNH_F_REJECT_MASK) {
NL_SET_ERR_MSG(extack,
"Invalid rtm_flags - can not contain DEAD or LINKDOWN");
goto err_inval;--
2.31.1