Re: [systemd-devel] [PATCH] network: Implement fallback DHCPv6 prefix handling for older kernels

2015-04-09 Thread Alexander Sverdlin
Hi!

On 09/04/15 12:45, Patrik Flykt wrote:
 Hmm, in general, we really should try to create the same binaries,
  regardless if we are built on an old or new kernel. And the binaries
  should work as good as possible, regardless which kernel version they
  are running on. But with the change above the binary built on a newer
  kernel work differently from an older kernel, even though we added the
  definition to missing.h to make the distinction go away...
  
  Or in other words: we try to do runtime compat, not just compile time
  compat, so that we don't strictly have to sync kernel and userspace
  updated.
 Hmm, I was suspecting that for a moment. I need to come up with a better
 runtime solution for version 2 of the patch then.

You should construct and send netlink packet as for kernel 3.14, but be
prepared, you will get error back on 3.13, because the parameter is unknown.
So you just need to handle the error gacefully, not fail.

Alex.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] network: Implement fallback DHCPv6 prefix handling for older kernels

2015-04-09 Thread Lennart Poettering
On Thu, 09.04.15 13:37, Patrik Flykt (patrik.fl...@linux.intel.com) wrote:

  src/libsystemd/sd-rtnl/rtnl-types.c |  2 ++
  src/network/networkd-address.c  |  5 +++-
  src/network/networkd-dhcp6.c| 55 
 +++--
  src/network/networkd-link.c |  4 +++
  src/network/networkd-link.h |  2 ++
  5 files changed, 65 insertions(+), 3 deletions(-)
 
 diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c 
 b/src/libsystemd/sd-rtnl/rtnl-types.c
 index 49784bf..407b749 100644
 --- a/src/libsystemd/sd-rtnl/rtnl-types.c
 +++ b/src/libsystemd/sd-rtnl/rtnl-types.c
 @@ -360,7 +360,9 @@ static const NLType rtnl_address_types[CONST_MAX(IFA_MAX, 
 IFA_FLAGS) + 1] = {
  [IFA_ANYCAST],
  [IFA_MULTICAST],
  */
 +#if HAVE_DECL_IFA_FLAGS
  [IFA_FLAGS] = { .type = NLA_U32 },
 +#endif
  };

Hmm, in general, we really should try to create the same binaries,
regardless if we are built on an old or new kernel. And the binaries
should work as good as possible, regardless which kernel version they
are running on. But with the change above the binary built on a newer
kernel work differently from an older kernel, even though we added the
definition to missing.h to make the distinction go away...

Or in other words: we try to do runtime compat, not just compile time
compat, so that we don't strictly have to sync kernel and userspace
updated.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] network: Implement fallback DHCPv6 prefix handling for older kernels

2015-04-09 Thread Patrik Flykt
When setting IPv6 addresses acquired by DHCPv6, systemd-networkd sets
the IFA_F_NOPREFIXROUTE flag in the IFA_FLAGS netlink attribute. As the
flag and the attribute are present starting with Linux 3.14, older
kernels will need systemd-network to manage prefix route handling.

Support for IFA_FLAGS is done during compile time and implemented as
part of netlink type checking. When IFA_FLAGS is detected in an systemd
external kernel header, HAVE_DECL_IFA_FLAGS is defined and the type
check will be successful. If not, setting the attribute will fail and
systemd-network will record this fact to its Link structure. Later if
a prefix expires, the same Link structure will be queried for the
successful use of IFA_FLAGS, with the DHCPv6 addresses handled either
by the kernel or the systemd-networkd fallback code.

The prefix expiration and IPv6 address updating fallback code is
resurrected from the parts deleted with commit
47d45d3cde45d6545367570264e4e3636bc9e345.

This patch can be removed once the minimum kernel requirements are
greater than or equal to 3.14.
---

Hi,

This patch implements a compile time fix for IFA_FLAGS support. Doing the
fix run time has its difficulties as the kernel discarding DHCPv6 address
assignment in the error path of dhcp6_address_handler() can have been
caused by other error situations.

I got this one working on my machine by commenting IFA_FLAGS out/leaving
IFA_FLAGS defined in the kernel headers, please test against real running
3.8/3.14 Linux versions.


Cheers,

Patrik



 src/libsystemd/sd-rtnl/rtnl-types.c |  2 ++
 src/network/networkd-address.c  |  5 +++-
 src/network/networkd-dhcp6.c| 55 +++--
 src/network/networkd-link.c |  4 +++
 src/network/networkd-link.h |  2 ++
 5 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c 
b/src/libsystemd/sd-rtnl/rtnl-types.c
index 49784bf..407b749 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.c
+++ b/src/libsystemd/sd-rtnl/rtnl-types.c
@@ -360,7 +360,9 @@ static const NLType rtnl_address_types[CONST_MAX(IFA_MAX, 
IFA_FLAGS) + 1] = {
 [IFA_ANYCAST],
 [IFA_MULTICAST],
 */
+#if HAVE_DECL_IFA_FLAGS
 [IFA_FLAGS] = { .type = NLA_U32 },
+#endif
 };
 
 static const NLTypeSystem rtnl_address_type_system = {
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 85acc49..2057d05 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -218,7 +218,10 @@ int address_update(Address *address, Link *link,
 if (address-flags  ~0xff) {
 r = sd_rtnl_message_append_u32(req, IFA_FLAGS, address-flags);
 if (r  0)
-return log_error_errno(r, Could not set extended 
flags: %m);
+log_link_warning(link, Could not set extended flags: 
%s,
+ strerror(-r));
+else
+link-rtnl_extended_flags = true;
 }
 
 r = sd_rtnl_message_addr_set_scope(req, address-scope);
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index e863f4b..6b040bd 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -67,7 +67,7 @@ static int dhcp6_address_update(Link *link, struct in6_addr 
*ip6_addr,
 memcpy(addr-in_addr.in6, ip6_addr, sizeof(*ip6_addr));
 
 addr-flags = IFA_F_NOPREFIXROUTE;
-addr-prefixlen = 64;
+addr-prefixlen = prefixlen;
 
 addr-cinfo.ifa_prefered = lifetime_preferred;
 addr-cinfo.ifa_valid = lifetime_valid;
@@ -262,6 +262,52 @@ static int dhcp6_configure(Link *link, int event) {
 return r;
 }
 
+static int dhcp6_prefix_expired(Link *link) {
+int r;
+sd_dhcp6_lease *lease;
+struct in6_addr *expired_prefix, ip6_addr;
+uint8_t expired_prefixlen;
+uint32_t lifetime_preferred, lifetime_valid;
+
+r = sd_icmp6_ra_get_expired_prefix(link-icmp6_router_discovery,
+expired_prefix, expired_prefixlen);
+if (r  0)
+return r;
+
+r = sd_dhcp6_client_get_lease(link-dhcp6_client, lease);
+if (r  0)
+return r;
+
+log_link_struct(link, LOG_INFO,
+MESSAGE=%-*s: IPv6 prefix 
SD_ICMP6_ADDRESS_FORMAT_STR/%d expired,
+IFNAMSIZ, link-ifname,
+SD_ICMP6_ADDRESS_FORMAT_VAL(*expired_prefix),
+expired_prefixlen, NULL);
+
+sd_dhcp6_lease_reset_address_iter(lease);
+
+while (sd_dhcp6_lease_get_address(lease, ip6_addr,
+lifetime_preferred,
+lifetime_valid) = 0) {
+
+r = sd_icmp6_prefix_match(expired_prefix, expired_prefixlen,
+ 

Re: [systemd-devel] [PATCH] network: Implement fallback DHCPv6 prefix handling for older kernels

2015-04-09 Thread Patrik Flykt
On Thu, 2015-04-09 at 12:43 +0200, Lennart Poettering wrote:
 Hmm, in general, we really should try to create the same binaries,
 regardless if we are built on an old or new kernel. And the binaries
 should work as good as possible, regardless which kernel version they
 are running on. But with the change above the binary built on a newer
 kernel work differently from an older kernel, even though we added the
 definition to missing.h to make the distinction go away...
 
 Or in other words: we try to do runtime compat, not just compile time
 compat, so that we don't strictly have to sync kernel and userspace
 updated.

Hmm, I was suspecting that for a moment. I need to come up with a better
runtime solution for version 2 of the patch then.

Cheers,

Patrik


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel