ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski at intel.com>
To: ell at lists.01.org
Subject: Re: [PATCH 04/13] netconfig: Support IPv6 static configurations
Date: Wed, 27 Apr 2022 16:18:19 +0200	[thread overview]
Message-ID: <CAOq732+5r43LtLMGJe21sMWDhk9LXZLR8FDvOWq-3G8ZGhtOQQ@mail.gmail.com> (raw)
In-Reply-To: d40420e6-e9c5-c6a4-b007-ee43c6e5b0dd@gmail.com

[-- Attachment #1: Type: text/plain, Size: 3099 bytes --]

On Wed, 27 Apr 2022 at 15:30, Denis Kenzior <denkenz(a)gmail.com> wrote:
> On 4/22/22 13:59, Andrew Zaborowski wrote:
> > +     /* Zero out host address bits to produce network address */
> > +     if (prefix_len & 7)
> > +             in6_addr.s6_addr[prefix_len / 8] &= 0xff00 >> (prefix_len & 7);
>
> Can we make this a bit cleaner? Something like
>
> last_byte = prefix_len / 8;
>
> if (prefix_len & 7) {
>         /* zero out lsb bits */
>         last_byte += 1;
> }
>
> memset(in6_addr + last_byte, 0, 16 - last_byte);

Ok.

>
> However, the more general question here is why do we want to store and compute
> the prefix route separately?  Is the assumption here that all addresses use the
> noprefixroute flag?  Wouldn't it be simpler to just have the kernel handle this?

So I think we can do that if we're committing the addresses to the
kernel ourselves.  If we have to delegate it to NM we still need this
code.  In the end I think it's easier to have just one branch here.

Having the kernel handle the subnet routes is even more obvious for
IPv4 because it works for static as well as DHCP.  For some reason the
IWD code always sets this flag for both IPv4 and IPv6.

> > @@ -580,11 +629,56 @@ static bool netconfig_check_v4_config(struct l_netconfig *netconfig)
> >       return true;
> >   }
> >
> > +static bool netconfig_check_v6_config(struct l_netconfig *netconfig)
> > +{
> > +     struct in6_addr local;
> > +     struct in6_addr gateway;
> > +     uint8_t prefix_len = 0;
> > +     unsigned int dns_num = 0;
> > +     _auto_(l_free) struct in6_addr *dns_list = NULL;
> > +
> > +     if (!netconfig->v6_enabled)
> > +             return true;
> > +
> > +     if (netconfig->v6_static_addr) {
> > +             char str[INET6_ADDRSTRLEN];
> > +
> > +             prefix_len = l_rtnl_address_get_prefix_length(
> > +                                             netconfig->v6_static_addr);
> > +             if (unlikely(prefix_len > 126))
> > +                     return false;
> > +
> > +             l_rtnl_address_get_address(netconfig->v6_static_addr, str);
> > +             inet_pton(AF_INET6, str, &local);
> > +     }
> > +
> > +     if (netconfig->v6_gateway_override) {
> > +             if (unlikely(inet_pton(AF_INET6, netconfig->v6_gateway_override,
> > +                                     &gateway) != 1))
> > +                     return false;
> > +     }
> > +
> > +     if (netconfig->v6_dns_override &&
> > +                     (dns_num = l_strv_length(netconfig->v6_dns_override))) {
> > +             unsigned int i;
> > +
> > +             dns_list = l_new(struct in6_addr, dns_num);
> > +
> > +             for (i = 0; i < dns_num; i++)
> > +                     if (inet_pton(AF_INET6, netconfig->v6_dns_override[i],
> > +                                     &dns_list[i]) != 1)
> > +                             return false;
> > +     }
> > +
>
> All this checking is pure copy-paste of the v4 version.  Can they be combined?

Ok, let me do it that way.

Best regards

             reply	other threads:[~2022-04-27 14:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27 14:18 Andrew Zaborowski [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-04-27 22:01 [PATCH 04/13] netconfig: Support IPv6 static configurations Denis Kenzior
2022-04-27 21:42 Andrew Zaborowski
2022-04-27 14:47 Denis Kenzior
2022-04-27 13:30 Denis Kenzior
2022-04-22 18:59 Andrew Zaborowski

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=CAOq732+5r43LtLMGJe21sMWDhk9LXZLR8FDvOWq-3G8ZGhtOQQ@mail.gmail.com \
    --to=ell@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).