All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski at intel.com>
To: ell at lists.01.org
Subject: Re: [PATCH 02/11] netconfig: Add DHCP override and static IP API
Date: Tue, 19 Apr 2022 09:59:44 +0200	[thread overview]
Message-ID: <CAOq732LdD-1p_b=GQLP_ULXo+EY3h0cFCw8JwWBLQcnnpXtRtw@mail.gmail.com> (raw)
In-Reply-To: 39949927-436f-7869-5957-2342b5364800@gmail.com

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

On Mon, 18 Apr 2022 at 21:15, Denis Kenzior <denkenz(a)gmail.com> wrote:
> On 4/11/22 09:20, Andrew Zaborowski wrote:
> > +     switch (family) {
> > +     case AF_INET:
> > +             l_rtnl_address_free(l_steal_ptr(netconfig->v4_static_addr));
> > +
> > +             if (addr)
> > +                     break;
>
> I take it this should be !addr?

Yep.

>
> > +
> > +             netconfig->v4_static_addr = l_rtnl_address_clone(addr);
> > +             l_rtnl_address_set_lifetimes(netconfig->v4_static_addr, 0, 0);
> > +
> > +             /*
> > +              * We could leave the decision about this flag up to the
> > +              * caller but for simplicity override to true.
> > +              */
> > +             l_rtnl_address_set_noprefixroute(netconfig->v4_static_addr,
> > +                                                     true);
> > +             return true;
> > +     case AF_INET6:
> > +             l_rtnl_address_free(l_steal_ptr(netconfig->v6_static_addr));
> > +
> > +             if (addr)
> > +                     break;
> > +
>
> And here as well?

Yep.

> > +     /*
> > +      * If using a static IP and there's no gateway all the DNSes mut be on
>
> typo: mut -> must

Right.

>
> > +     /*
> > +      * If using a static IP, we can validate right now that the gateway is
> > +      * in the local subnet.
> > +      */
> > +     if (netconfig->v6_static_addr && netconfig->v6_gateway_override)
> > +             if (!l_net_subnet_matches(&local, &gateway, prefix_len))
> > +                     return false;
>
> Not sure this is true?  AFAIK the default gateway could be a link local address...

True, that's also a good catch.  I'll add a check for that (unless you
prefer we don't validate this address.)

>
> > +
> > +     /*
> > +      * If using a static IP and there's no gateway all the DNSes mut be on
>
> Same typo as above.
>
> > +      * the local subnet too.
> > +      */
> > +     if (netconfig->v6_static_addr && !netconfig->v6_gateway_override &&
> > +                     netconfig->v6_dns_override) {
> > +             unsigned int i;
> > +
> > +             for (i = 0; i < dns_num; i++)
> > +                     if (!l_net_subnet_matches(&local, &dns_list[i],
> > +                                                     prefix_len))
> > +                             return false;
>
> This whole block maybe should be a static convenience function?  In fact, much
> of these checks are the same as in v4 version of this function and could be
> combined?

Ok, let me try to combine them.

>
> > +     }
> > +
> > +     return true;
> > +}
> > +
>
> <snip>
>
> >   LIB_EXPORT bool l_netconfig_start(struct l_netconfig *netconfig)
> >   {
> >       if (unlikely(!netconfig || netconfig->started))
> >               return false;
> >
> > -     if (netconfig->v4_enabled &&
> > -                     !l_dhcp_client_start(netconfig->dhcp_client))
> > +     if (!netconfig_check_config(netconfig))
> >               return false;
> >
>
> Can we check that both v4_enabled and v6_enabled are false and return appropriately?

Ok.  We effectively do but let me add one at the beginning.

>
> > -     netconfig->started = true;
> > +     if (netconfig->v4_enabled) {
>
> I'd prefer less nesting, so something like:
>
> if (!netconfig->v4_enabled)
>         goto configure_ipv6;

Ok.

>
> > +             if (netconfig->v4_static_addr) {
> > +                     /*
> > +                      * We're basically ready to configure the interface
> > +                      * but do this in an idle callback.
> > +                      */
> > +                     netconfig->do_static_work = l_idle_create(
> > +                                             netconfig_do_static_config,
> > +                                             netconfig, NULL);
>
> goto here..
>
> > +             } else {
> > +                     if (!l_dhcp_client_start(netconfig->dhcp_client))
> > +                             return false;
> > +             }
> > +     }
> >
> > +     netconfig->started = true;
> >       return true;
> >   }
> >
>
> <snip>
>
> > diff --git a/ell/netconfig.h b/ell/netconfig.h
> > index 682f4aa..aab9d3f 100644
> > --- a/ell/netconfig.h
> > +++ b/ell/netconfig.h
> > @@ -53,6 +53,22 @@ typedef void (*l_netconfig_destroy_cb_t)(void *user_data);
> >
> >   struct l_netconfig *l_netconfig_new(uint32_t ifindex);
> >   void l_netconfig_destroy(struct l_netconfig *netconfig);
> > +bool l_netconfig_set_af_enabled(struct l_netconfig *netconfig, uint8_t family,
> > +                             bool enabled);
>
> Can we call it family_enabled?

Sure.

>
> > +bool l_netconfig_set_static_addr(struct l_netconfig *netconfig, uint8_t family,
> > +                                     const struct l_rtnl_address *addr);
> > +bool l_netconfig_set_gateway_override(struct l_netconfig *netconfig,
> > +                                     uint8_t family,
> > +                                     const char *gateway_str);
>
> Wonder why you use l_rtnl_address for 'set_static_addr' and a string for the
> gateway?

So l_rtnl_address includes the prefix length and such, so the struct
maps to our own addresses.  The gateway would map to the next-hop
address in the l_rtnl_route struct so it didn't seem fitting.  Note
that l_rtnl_route doesn't use l_rtnl_address for that in its API.

Best regards

             reply	other threads:[~2022-04-19  7:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19  7:59 Andrew Zaborowski [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-04-18 19:15 [PATCH 02/11] netconfig: Add DHCP override and static IP API Denis Kenzior
2022-04-11 14:20 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='CAOq732LdD-1p_b=GQLP_ULXo+EY3h0cFCw8JwWBLQcnnpXtRtw@mail.gmail.com' \
    --to=unknown@example.com \
    /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.