All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
To: netdev@vger.kernel.org
Cc: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>,
	David Miller <davem@davemloft.net>,
	David Ahern <dsahern@gmail.com>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Ido Schimmel <idosch@nvidia.com>,
	Jakub Kicinski <kuba@kernel.org>, Roopa Prabhu <roopa@nvidia.com>,
	Andrei Vagin <avagin@gmail.com>,
	Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
	Alexander Mikhalitsyn <alexander@mihalicyn.com>
Subject: [PATCH iproute2] ip route: save: exclude rtnh_flags which can't be set
Date: Fri, 26 Nov 2021 16:43:10 +0300	[thread overview]
Message-ID: <20211126134311.920808-1-alexander.mikhalitsyn@virtuozzo.com> (raw)
In-Reply-To: <20211111160240.739294-1-alexander.mikhalitsyn@virtuozzo.com>

During "ip route save" we preserve all rtnh_flags,
even those that can't be set directly by the userspace.
This looks like a bug because a user can't restore
route dump which was generated by "ip route save" back.
This also prevents CRIU from correct restore of the
containers with some route configurations inside.

Reproducer:
$ ip link add type veth
$ ip addr add 10.0.0.1/24 dev veth0
$ ip link set veth0 up
$ ip route add default via 10.0.0.1
$ ip route save > route_dump
$ ip route restore < route_dump
Error: Invalid rtm_flags - can not contain DEAD or LINKDOWN.

Let's just omit non-settable rtnh_flags from the dump image.

According to the check in the fib_create_info() kernel
function it looks like we can't restore back only
RTNH_F_DEAD and RTNH_F_LINKDOWN flags, so RTNH_REJECT_MASK
contains this flags for now.

See also linux kernel patch:
[PATCH net-next] rtnetlink: add RTNH_REJECT_MASK

Cc: David Miller <davem@davemloft.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Roopa Prabhu <roopa@nvidia.com>
Cc: Andrei Vagin <avagin@gmail.com>
Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: Alexander Mikhalitsyn <alexander@mihalicyn.com>
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
---
 include/uapi/linux/rtnetlink.h | 3 +++
 ip/iproute.c                   | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index e01efa28..6de83c62 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_REJECT_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN)
+
 /* Macros to handle hexthops */
 
 #define RTNH_ALIGNTO	4
diff --git a/ip/iproute.c b/ip/iproute.c
index 1447a5f7..a72b652b 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1632,6 +1632,12 @@ static int save_route(struct nlmsghdr *n, void *arg)
 	if (!filter_nlmsg(n, tb, host_len))
 		return 0;
 
+	/*
+	 * Exclude flags which can't be set directly
+	 * by the userspace from the rtmsg dump.
+	 */
+	r->rtm_flags &= ~RTNH_REJECT_MASK;
+
 	ret = write(STDOUT_FILENO, n, n->nlmsg_len);
 	if ((ret > 0) && (ret != n->nlmsg_len)) {
 		fprintf(stderr, "Short write while saving nlmsg\n");
-- 
2.31.1


  parent reply	other threads:[~2021-11-26 13:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 16:02 [RFC PATCH iproute2] ip route: save: exclude rtnh_flags which can't be set Alexander Mikhalitsyn
2021-11-11 16:02 ` [RFC PATCH net-next] rtnetlink: add RTNH_F_REJECT_MASK Alexander Mikhalitsyn
2021-11-11 17:48   ` Jakub Kicinski
2021-11-11 17:51     ` Alexander Mikhalitsyn
2021-11-11 17:56       ` Jakub Kicinski
2021-11-11 18:01         ` Alexander Mikhalitsyn
2021-11-11 19:13   ` David Ahern
2021-11-11 19:23     ` Alexander Mikhalitsyn
2021-11-11 22:19       ` David Ahern
2021-11-12  1:02         ` Roopa Prabhu
2021-11-12  2:27           ` David Ahern
2021-11-26 13:43 ` Alexander Mikhalitsyn [this message]
2021-11-26 13:43   ` [PATCH net-next] rtnetlink: add RTNH_REJECT_MASK Alexander Mikhalitsyn
2021-11-28 14:01     ` Ido Schimmel
2021-11-29  0:19       ` David Ahern
2021-11-30  7:59         ` Ido Schimmel
2021-11-30  8:35           ` Alexander Mikhalitsyn
2021-11-30  9:28             ` Ido Schimmel
2021-11-30  9:53               ` Alexander Mikhalitsyn
2021-11-30 10:28                 ` Ido Schimmel
2021-11-30 15:12                   ` David Ahern
2021-11-30  8:18       ` Alexander Mikhalitsyn
2021-11-28 13:09   ` [PATCH iproute2] ip route: save: exclude rtnh_flags which can't be set Ido Schimmel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211126134311.920808-1-alexander.mikhalitsyn@virtuozzo.com \
    --to=alexander.mikhalitsyn@virtuozzo.com \
    --cc=alexander@mihalicyn.com \
    --cc=avagin@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=roopa@nvidia.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.