All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, David Ahern <dsahern@gmail.com>,
	Andrei Vagin <avagin@gmail.com>,
	Alexander Mikhalitsyn <alexander@mihalicyn.com>
Subject: Re: [PATCHv2 iproute2] ip route: ignore ENOENT during save if RT_TABLE_MAIN is being dumped
Date: Fri, 25 Jun 2021 13:59:54 +0300	[thread overview]
Message-ID: <20210625135954.44ecba2e8875141380a52d7d@virtuozzo.com> (raw)
In-Reply-To: <20210624083647.0f173c4b@hermes.local>

On Thu, 24 Jun 2021 08:36:47 -0700
Stephen Hemminger <stephen@networkplumber.org> wrote:

> On Thu, 24 Jun 2021 18:28:12 +0300
> Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com> wrote:
> 
> > We started to use in-kernel filtering feature which allows to get only needed
> > tables (see iproute_dump_filter()). From the kernel side it's implemented in
> > net/ipv4/fib_frontend.c (inet_dump_fib), net/ipv6/ip6_fib.c (inet6_dump_fib).
> > The problem here is that behaviour of "ip route save" was changed after
> > c7e6371bc ("ip route: Add protocol, table id and device to dump request").
> > If filters are used, then kernel returns ENOENT error if requested table is absent,
> > but in newly created net namespace even RT_TABLE_MAIN table doesn't exist.
> > It is really allocated, for instance, after issuing "ip l set lo up".
> > 
> > Reproducer is fairly simple:
> > $ unshare -n ip route save > dump
> > Error: ipv4: FIB table does not exist.
> > Dump terminated
> > 
> > Expected result here is to get empty dump file (as it was before this change).
> > 
> > v2: reworked, so, now it takes into account NLMSGERR_ATTR_MSG
> > (see nl_dump_ext_ack_done() function). We want to suppress error messages
> > in stderr about absent FIB table from kernel too.
> > 
> > Fixes: c7e6371bc ("ip route: Add protocol, table id and device to dump request")
> > Cc: David Ahern <dsahern@gmail.com>
> > Cc: Stephen Hemminger <stephen@networkplumber.org>
> > Cc: Andrei Vagin <avagin@gmail.com>
> > Cc: Alexander Mikhalitsyn <alexander@mihalicyn.com>
> > Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
> > ---
> >  include/libnetlink.h |  5 +++++
> >  ip/iproute.c         |  8 +++++++-
> >  lib/libnetlink.c     | 31 ++++++++++++++++++++++++++-----
> >  3 files changed, 38 insertions(+), 6 deletions(-)
> > 
> > diff --git a/include/libnetlink.h b/include/libnetlink.h
> > index b9073a6a..93c22a09 100644
> > --- a/include/libnetlink.h
> > +++ b/include/libnetlink.h
> > @@ -121,6 +121,11 @@ int rtnl_dump_filter_nc(struct rtnl_handle *rth,
> >  			void *arg, __u16 nc_flags);
> >  #define rtnl_dump_filter(rth, filter, arg) \
> >  	rtnl_dump_filter_nc(rth, filter, arg, 0)
> > +int rtnl_dump_filter_suppress_rtnl_errmsg_nc(struct rtnl_handle *rth,
> > +		     rtnl_filter_t filter,
> > +		     void *arg1, __u16 nc_flags, const int *errnos);
> > +#define rtnl_dump_filter_suppress_rtnl_errmsg(rth, filter, arg, errnos) \
> > +	rtnl_dump_filter_suppress_rtnl_errmsg_nc(rth, filter, arg, 0, errnos)
> >  int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
> >  	      struct nlmsghdr **answer)
> >  	__attribute__((warn_unused_result));
> > diff --git a/ip/iproute.c b/ip/iproute.c
> > index 5853f026..796d6d17 100644
> > --- a/ip/iproute.c
> > +++ b/ip/iproute.c
> > @@ -1734,6 +1734,8 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
> >  	char *od = NULL;
> >  	unsigned int mark = 0;
> >  	rtnl_filter_t filter_fn;
> > +	/* last 0 is array trailing */
> > +	int suppress_rtnl_errnos[2] = { 0, 0 };
> >  
> 
> The design would be clearer if there were two arguments rather than magic array of size 2.
> Also these are being used as boolean.
I've reworked that to make code cleaner and sent v3.
I decided to keep array on the stack but introduced initializer-macro SUPPRESS_ERRORS_INIT which
can be extended anytime (now it allows to suppress up to 3 errors).

In iplink_vrf.c rtnl_talk_suppress_rtnl_errmsg function is used, which allows to suppress all errors,
but sometime it may be helpful to suppress just a few errors. That's a reason why I didn't implemented
variant which allows to suppress only one errno (ENOENT) for my particular case.

Thanks,
Alex

  parent reply	other threads:[~2021-06-25 11:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 15:03 [PATCH iproute2] ip route: ignore ENOENT during save if RT_TABLE_MAIN is being dumped Alexander Mikhalitsyn
2021-06-23 15:36 ` David Ahern
2021-06-23 16:11   ` Alexander Mikhalitsyn
2021-06-24 15:28 ` [PATCHv2 " Alexander Mikhalitsyn
2021-06-24 15:36   ` Stephen Hemminger
2021-06-24 15:40     ` Alexander Mikhalitsyn
2021-06-25 10:59     ` Alexander Mikhalitsyn [this message]
2021-06-25 10:44   ` [PATCHv3 " Alexander Mikhalitsyn
2021-06-27 21:54     ` Stephen Hemminger
2021-06-28  6:31       ` Alexander Mikhalitsyn
2021-06-28 17:17         ` Stephen Hemminger
2021-06-28 17:21           ` Alexander Mikhalitsyn
2021-06-29 15:51     ` [PATCHv4 " Alexander Mikhalitsyn
2021-07-06  7:47       ` Alexander Mikhalitsyn
2021-07-06 15:34       ` Stephen Hemminger
2021-07-06 15:44         ` Alexander Mikhalitsyn
2021-07-06 16:18           ` Stephen Hemminger
2021-07-06 17:17             ` Alexander Mikhalitsyn
2021-07-07  0:05               ` Stephen Hemminger
2021-07-07 12:22                 ` Alexander Mikhalitsyn
2021-07-07 14:31                   ` Stephen Hemminger
2021-07-07 14:32                     ` Alexander Mikhalitsyn
2021-07-07 12:09     ` [PATCHv5 " Alexander Mikhalitsyn
2021-07-07 12:22     ` Alexander Mikhalitsyn
2021-07-07 14:35       ` Stephen Hemminger
2021-07-07 14:38         ` Alexander Mikhalitsyn
2021-07-07 14:50       ` patchwork-bot+netdevbpf
2021-07-11 10:59         ` Roi Dayan
2021-07-11 11:09           ` Roi Dayan
2021-07-11 11:12             ` Alexander Mihalicyn

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=20210625135954.44ecba2e8875141380a52d7d@virtuozzo.com \
    --to=alexander.mikhalitsyn@virtuozzo.com \
    --cc=alexander@mihalicyn.com \
    --cc=avagin@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --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.