systemd: Enable DHCPv6 and Ipv6AcceptRA.

This will enable a COS node to get an ipv6 address via DHCP, and apply
routes advertised by the DHCP server.

In addition, it is also adding a patch where the boot process of  VM
with the above configuration enabled should not regress if there is only
IPV4 address available.

BUG=b/74356284
TEST=presubmit and validation test; testing mentioned in https://b.corp.google.com/issues/74356284#comment152
RELEASE_NOTE=Enabled COS VM to get an IPV6 address if available.

Change-Id: I2289d7e48ed6f4179e3104d5bdff32ad7c966252
Reviewed-on: https://cos-review.googlesource.com/c/cos/overlays/board-overlays/+/18834
Reviewed-by: Robert Kolchmeyer <rkolchmeyer@google.com>
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
diff --git a/project-lakitu/sys-apps/systemd/files/239-no-stall-network-wait-online-for-ipv6.patch b/project-lakitu/sys-apps/systemd/files/239-no-stall-network-wait-online-for-ipv6.patch
new file mode 100644
index 0000000..35ee25e
--- /dev/null
+++ b/project-lakitu/sys-apps/systemd/files/239-no-stall-network-wait-online-for-ipv6.patch
@@ -0,0 +1,46 @@
+From 7d680a0fdd0b6b8373096121014c7ca78e6c41ac Mon Sep 17 00:00:00 2001
+From: Vaibhav Rustagi <vaibhavrustagi@google.com>
+Date: Wed, 30 Jun 2021 14:21:42 -0700
+Subject: [PATCH] network-wait-online should not stall when ipv4 is available.
+
+When IPV6 related configurations are available, systemd will try to find
+the IPV6 address till timeout. This creates a problem when there is no
+IPV6 address available. Due to this, network-wait-online will come up
+after the timeout and it delays the system boot process.
+
+This CL is a mixture of
+https://github.com/systemd/systemd/commit/552081a4992 and
+https://github.com/systemd/systemd/commit/3cd5924c850929b03bc8d4ba5db614d662edb49a
+---
+ src/network/networkd-link.c | 15 ++++++---------
+ 1 file changed, 6 insertions(+), 9 deletions(-)
+
+diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
+index 4afcf843bd..f33701a90d 100644
+--- a/src/network/networkd-link.c
++++ b/src/network/networkd-link.c
+@@ -745,15 +745,12 @@ void link_check_ready(Link *link) {
+                         if (in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address) > 0)
+                                 return;
+ 
+-                if ((link_dhcp4_enabled(link) && !link_dhcp6_enabled(link) &&
+-                     !link->dhcp4_configured) ||
+-                    (link_dhcp6_enabled(link) && !link_dhcp4_enabled(link) &&
+-                     !link->dhcp6_configured) ||
+-                    (link_dhcp4_enabled(link) && link_dhcp6_enabled(link) &&
+-                     !link->dhcp4_configured && !link->dhcp6_configured))
+-                        return;
+-
+-                if (link_ipv6_accept_ra_enabled(link) && !link->ndisc_configured)
++                if ((link_dhcp4_enabled(link) || link_dhcp6_enabled(link) || link_ipv6_accept_ra_enabled(link)) &&
++                    !link->dhcp4_configured &&
++                    !link->dhcp6_configured &&
++                    !link->ndisc_configured)
++                        /* When DHCP or RA is enabled, at least one protocol must
++                         * provide an address. */
+                         return;
+         }
+ 
+-- 
+2.32.0.93.g670b81a890-goog
+
diff --git a/project-lakitu/sys-apps/systemd/files/99-virtio.network b/project-lakitu/sys-apps/systemd/files/99-virtio.network
index 8c0c18b..e974508 100644
--- a/project-lakitu/sys-apps/systemd/files/99-virtio.network
+++ b/project-lakitu/sys-apps/systemd/files/99-virtio.network
@@ -6,10 +6,8 @@
 Driver=virtio_net
 
 [Network]
-DHCP=ipv4
-# Disable IPv6 completely.
-# https://github.com/systemd/systemd/issues/1982#issuecomment-158779777
-IPv6AcceptRA=no
+DHCP=yes
+IPv6AcceptRA=yes
 
 [DHCP]
 UseMTU=true
diff --git a/project-lakitu/sys-apps/systemd/systemd-239-r23.ebuild b/project-lakitu/sys-apps/systemd/systemd-239-r24.ebuild
similarity index 100%
rename from project-lakitu/sys-apps/systemd/systemd-239-r23.ebuild
rename to project-lakitu/sys-apps/systemd/systemd-239-r24.ebuild
diff --git a/project-lakitu/sys-apps/systemd/systemd-239.ebuild b/project-lakitu/sys-apps/systemd/systemd-239.ebuild
index 7b45604..a52536c 100644
--- a/project-lakitu/sys-apps/systemd/systemd-239.ebuild
+++ b/project-lakitu/sys-apps/systemd/systemd-239.ebuild
@@ -225,6 +225,13 @@
 			"${FILESDIR}"/243-seccomp-old-libsec-fix.patch
 			# Fixes b/182952897
 			"${FILESDIR}"/246-basic-cap-list-parse-print-numerical-capabilities.patch
+			# Do not stall network-wait-online when atleast one
+			# protcol provides an address.
+			# This is a mixture of
+			# https://github.com/systemd/systemd/commit/552081a4992
+			# and
+			# https://github.com/systemd/systemd/commit/3cd5924c850.
+			"${FILESDIR}"/239-no-stall-network-wait-online-for-ipv6.patch
 	)
 	default
 }