All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/14] netconfig: Reset {v4, v6}_configured to false on netconfig stop
@ 2022-06-15 22:47 Andrew Zaborowski
  2022-06-15 22:47 ` [PATCH 07/14] netconfig: Add getters for DNS addresses and domain names Andrew Zaborowski
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Zaborowski @ 2022-06-15 22:47 UTC (permalink / raw)
  To: ell

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

---
 ell/netconfig.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ell/netconfig.c b/ell/netconfig.c
index 2a1b3ed..5de5d74 100644
--- a/ell/netconfig.c
+++ b/ell/netconfig.c
@@ -1163,6 +1163,8 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig)
 	netconfig->v4_subnet_route = NULL;
 	netconfig->v4_default_route = NULL;
 	netconfig->v6_address = NULL;
+	netconfig->v4_configured = false;
+	netconfig->v6_configured = false;
 
 	l_dhcp_client_stop(netconfig->dhcp_client);
 	l_dhcp6_client_stop(netconfig->dhcp6_client);
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 07/14] netconfig: Add getters for DNS addresses and domain names
@ 2022-06-15 22:47 ` Andrew Zaborowski
       [not found]   ` <da1459dd-2402-161e-b24f-f55a02356a31@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Zaborowski @ 2022-06-15 22:47 UTC (permalink / raw)
  To: ell

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

---
 ell/ell.sym     |  2 ++
 ell/netconfig.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
 ell/netconfig.h |  2 ++
 3 files changed, 68 insertions(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index 50f8909..d74e8c9 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -757,6 +757,8 @@ global:
 	l_netconfig_apply_rtnl;
 	l_netconfig_get_addresses;
 	l_netconfig_get_routes;
+	l_netconfig_get_dns_list;
+	l_netconfig_get_domain_names;
 local:
 	*;
 };
diff --git a/ell/netconfig.c b/ell/netconfig.c
index ce5bfe3..94faef0 100644
--- a/ell/netconfig.c
+++ b/ell/netconfig.c
@@ -1425,3 +1425,67 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(
 
 	return l_queue_get_entries(netconfig->routes.current);
 }
+
+/* Returns a new strv array to be freed by the caller */
+LIB_EXPORT char **l_netconfig_get_dns_list(struct l_netconfig *netconfig)
+{
+	char **ret = NULL;
+	const struct l_dhcp_lease *v4_lease;
+	const struct l_dhcp6_lease *v6_lease;
+
+#define CONCAT(dest, src, free)		\
+	do {				\
+		char **tmp = src;	\
+		tmp = free ? tmp : l_strv_copy(tmp);	\
+		if (!dest)		\
+			dest = tmp;	\
+		else if (tmp) {		\
+			unsigned int destlen = l_strv_length(dest);	\
+			unsigned int srclen = l_strv_length(tmp);	\
+			dest = l_realloc(dest, sizeof(char *) *	\
+				(destlen + srclen + 1));	\
+			memcpy(dest + destlen, tmp, sizeof(char *) *	\
+					(srclen + 1));	\
+			l_free(tmp);	\
+		}			\
+	} while (0)
+
+	if (netconfig->v4_dns_override)
+		CONCAT(ret, netconfig->v4_dns_override, false);
+	else if ((v4_lease =
+			l_dhcp_client_get_lease(netconfig->dhcp_client)))
+		CONCAT(ret, l_dhcp_lease_get_dns(v4_lease), true);
+
+	if (netconfig->v6_dns_override)
+		CONCAT(ret, netconfig->v6_dns_override, false);
+	else if ((v6_lease =
+			l_dhcp6_client_get_lease(netconfig->dhcp6_client)))
+		CONCAT(ret, l_dhcp6_lease_get_dns(v6_lease), true);
+
+	return ret;
+}
+
+/* Returns a new strv array to be freed by the caller */
+LIB_EXPORT char **l_netconfig_get_domain_names(struct l_netconfig *netconfig)
+{
+	char **ret = NULL;
+	const struct l_dhcp_lease *v4_lease;
+	const struct l_dhcp6_lease *v6_lease;
+
+	if (netconfig->v4_domain_names_override)
+		CONCAT(ret, netconfig->v4_domain_names_override, false);
+	else if ((v4_lease =
+			l_dhcp_client_get_lease(netconfig->dhcp_client)) &&
+			l_dhcp_lease_get_domain_name(v4_lease)) {
+		ret = l_new(char *, 2);
+		ret[0] = l_dhcp_lease_get_domain_name(v4_lease);
+	}
+
+	if (netconfig->v6_dns_override)
+		CONCAT(ret, netconfig->v6_domain_names_override, false);
+	else if ((v6_lease =
+			l_dhcp6_client_get_lease(netconfig->dhcp6_client)))
+		CONCAT(ret, l_dhcp6_lease_get_domains(v6_lease), true);
+
+	return ret;
+}
diff --git a/ell/netconfig.h b/ell/netconfig.h
index 69100a2..0b1182d 100644
--- a/ell/netconfig.h
+++ b/ell/netconfig.h
@@ -98,6 +98,8 @@ const struct l_queue_entry *l_netconfig_get_routes(
 				const struct l_queue_entry **out_updated,
 				const struct l_queue_entry **out_removed,
 				const struct l_queue_entry **out_expired);
+char **l_netconfig_get_dns_list(struct l_netconfig *netconfig);
+char **l_netconfig_get_domain_names(struct l_netconfig *netconfig);
 
 #ifdef __cplusplus
 }
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 07/14] netconfig: Add getters for DNS addresses and domain names
       [not found]   ` <da1459dd-2402-161e-b24f-f55a02356a31@gmail.com>
@ 2022-06-18  0:38     ` Andrew Zaborowski
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Zaborowski @ 2022-06-18  0:38 UTC (permalink / raw)
  To: Denis Kenzior; +Cc: ell, ell

Hi Denis,

On Fri, 17 Jun 2022 at 18:32, Denis Kenzior <denkenz@gmail.com> wrote:
> Hi Andrew,
>
> On 6/15/22 17:47, Andrew Zaborowski wrote:
> > ---
> >   ell/ell.sym     |  2 ++
> >   ell/netconfig.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
> >   ell/netconfig.h |  2 ++
> >   3 files changed, 68 insertions(+)
> >
>
> So I applied all patches in this series

Great.

> except this one.  Just a minor nit here:
>
> > diff --git a/ell/ell.sym b/ell/ell.sym
> > index 50f8909..d74e8c9 100644
> > --- a/ell/ell.sym
> > +++ b/ell/ell.sym
> > @@ -757,6 +757,8 @@ global:
> >       l_netconfig_apply_rtnl;
> >       l_netconfig_get_addresses;
> >       l_netconfig_get_routes;
> > +     l_netconfig_get_dns_list;
> > +     l_netconfig_get_domain_names;
> >   local:
> >       *;
> >   };
> > diff --git a/ell/netconfig.c b/ell/netconfig.c
> > index ce5bfe3..94faef0 100644
> > --- a/ell/netconfig.c
> > +++ b/ell/netconfig.c
> > @@ -1425,3 +1425,67 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(
> >
> >       return l_queue_get_entries(netconfig->routes.current);
> >   }
> > +
> > +/* Returns a new strv array to be freed by the caller */
> > +LIB_EXPORT char **l_netconfig_get_dns_list(struct l_netconfig *netconfig)
> > +{
> > +     char **ret = NULL;
> > +     const struct l_dhcp_lease *v4_lease;
> > +     const struct l_dhcp6_lease *v6_lease;
> > +
> > +#define CONCAT(dest, src, free)              \
>
> Why do we define this in the function body itself?  That seems weird for a macro
> that is used outside of this function.

True, I could have placed it before the function start.

>
> > +     do {                            \
> > +             char **tmp = src;       \
> > +             tmp = free ? tmp : l_strv_copy(tmp);    \
> > +             if (!dest)              \
> > +                     dest = tmp;     \
> > +             else if (tmp) {         \
> > +                     unsigned int destlen = l_strv_length(dest);     \
> > +                     unsigned int srclen = l_strv_length(tmp);       \
> > +                     dest = l_realloc(dest, sizeof(char *) * \
> > +                             (destlen + srclen + 1));        \
> > +                     memcpy(dest + destlen, tmp, sizeof(char *) *    \
> > +                                     (srclen + 1));  \
> > +                     l_free(tmp);    \
> > +             }                       \
> > +     } while (0)
>
> But really, can't we just turn this macro into a static convenience function
> instead?  Let the compiler decide whether inlining is appropriate.

Ok.

Best regards

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-18  0:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 22:47 [PATCH 01/14] netconfig: Reset {v4, v6}_configured to false on netconfig stop Andrew Zaborowski
2022-06-15 22:47 ` [PATCH 07/14] netconfig: Add getters for DNS addresses and domain names Andrew Zaborowski
     [not found]   ` <da1459dd-2402-161e-b24f-f55a02356a31@gmail.com>
2022-06-18  0:38     ` Andrew Zaborowski

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.