[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] libiproute: fix filtering ip6 route by table id
From:       Yousong Zhou <yszhou4tech () gmail ! com>
Date:       2023-02-16 11:59:53
Message-ID: CAECwjAiVyfA+jwx8Q+cS=PU3dF2RSgSu_eOx5oq4pHXU1FJpaw () mail ! gmail ! com
[Download RAW message or body]

On Thu, 16 Feb 2023 at 19:16, Denys Vlasenko <vda.linux@googlemail.com> wrote:
>
> On Sun, Feb 12, 2023 at 5:30 AM Yousong Zhou <yszhou4tech@gmail.com> wrote:
> >
> > Otherwise
> >
> >  - "ip -6 route show" shows routes from all tables
> >  - "ip -6 route show table 200" shows nothing
> >
> > function                                             old     new   delta
> > print_route                                         1962    1941     -21
> > ------------------------------------------------------------------------------
> > (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-21)             Total: -21 bytes
> >
> > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
> > ---
> >  networking/libiproute/iproute.c | 10 +---------
> >  1 file changed, 1 insertion(+), 9 deletions(-)
> >
> > diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
> > index 5a972f8b2..cd77f642f 100644
> > --- a/networking/libiproute/iproute.c
> > +++ b/networking/libiproute/iproute.c
> > @@ -111,15 +111,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
> >                                 if (r->rtm_flags & RTM_F_CLONED) {
> >                                         return 0;
> >                                 }
> > -                               if (G_filter.tb == RT_TABLE_LOCAL) {
> > -                                       if (r->rtm_type != RTN_LOCAL) {
> > -                                               return 0;
> > -                                       }
> > -                               } else if (G_filter.tb == RT_TABLE_MAIN) {
> > -                                       if (r->rtm_type == RTN_LOCAL) {
> > -                                               return 0;
> > -                                       }
> > -                               } else {
> > +                               if (G_filter.tb != tid) {
> >                                         return 0;
> >                                 }
> >                         }
>
> The very same code exists in current iproute2 git tree.
> Is it also buggy in the same way?

Hi Denys

I checked before and iproute2 works just fine.  The code is a bit different:

>
> iproute.c
> static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
> {
>         struct rtmsg *r = NLMSG_DATA(n);
>         inet_prefix dst = { .family = r->rtm_family };
>         inet_prefix src = { .family = r->rtm_family };
>         inet_prefix via = { .family = r->rtm_family };
>         inet_prefix prefsrc = { .family = r->rtm_family };
>         __u32 table;
>         static int ip6_multiple_tables;
>
>         table = rtm_get_table(r, tb);
>
>         if (preferred_family != AF_UNSPEC && r->rtm_family != preferred_family)
>                 return 0;
>
>         if (r->rtm_family == AF_INET6 && table != RT_TABLE_MAIN)
>                 ip6_multiple_tables = 1;

It sets ip6_multiple_tables here.

>
>         if (filter.cloned == !(r->rtm_flags & RTM_F_CLONED))
>                 return 0;
>
>         if (r->rtm_family == AF_INET6 && !ip6_multiple_tables) {

So it won't go into this branch

>                 if (filter.tb) {
>                         if (filter.tb == RT_TABLE_LOCAL) {
>                                 if (r->rtm_type != RTN_LOCAL)
>                                         return 0;
>                         } else if (filter.tb == RT_TABLE_MAIN) {
>                                 if (r->rtm_type == RTN_LOCAL)
>                                         return 0;
>                         } else {
>                                 return 0;
>                         }
>                 }
>         } else {
>                 if (filter.tb > 0 && filter.tb != table)
>                         return 0;

The check happens here.

Regards,
               yousong

>         }
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic