[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210624184044.80130fdc38822ee173a271b9@virtuozzo.com>
Date: Thu, 24 Jun 2021 18:40:44 +0300
From: Alexander Mikhalitsyn <alexander.mikhalitsyn@...tuozzo.com>
To: Stephen Hemminger <stephen@...workplumber.org>
Cc: netdev@...r.kernel.org, David Ahern <dsahern@...il.com>,
Andrei Vagin <avagin@...il.com>,
Alexander Mikhalitsyn <alexander@...alicyn.com>
Subject: Re: [PATCHv2 iproute2] ip route: ignore ENOENT during save if
RT_TABLE_MAIN is being dumped
On Thu, 24 Jun 2021 08:36:47 -0700
Stephen Hemminger <stephen@...workplumber.org> wrote:
> On Thu, 24 Jun 2021 18:28:12 +0300
> Alexander Mikhalitsyn <alexander.mikhalitsyn@...tuozzo.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@...il.com>
> > Cc: Stephen Hemminger <stephen@...workplumber.org>
> > Cc: Andrei Vagin <avagin@...il.com>
> > Cc: Alexander Mikhalitsyn <alexander@...alicyn.com>
> > Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn@...tuozzo.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.
You mean replace extra (int *) to pair (int *, size_t size)?
For my case I need to filter only ENOENT error, but maybe for some other cases someone may want
to filter out ENOENT and ENOSUPP, for instance then and use { ENOENT, ENOSUPP, 0 } as array.
Regards,
Alex
Powered by blists - more mailing lists