Repository: zephyrproject-rtos/zephyr
Pull request #87644: Add snippets for setting up IPv6 and dual IPv4/6 for Wi-Fi
Author: login: jukkar
Labels: name: area: Networking
name: area: Build System
name: area: Wi-Fi
description: Wi-Fi
Created: 2025-03-25T15:42:49Z | Merged: 2025-03-28T11:20:55Z

There is wifi-ipv4 snippet already, so add IPv6 only snippet and also dual IPv4/IPv6 stack snippet.


Diff:
diff --git a/snippets/wifi-ip/README.rst b/snippets/wifi-ip/README.rst
new file mode 100644
index 0000000000000..b9d6808ce8568
--- /dev/null
+++ b/snippets/wifi-ip/README.rst
@@ -0,0 +1,28 @@
+.. _snippet-wifi-ip:
+
+Wi-Fi IPv4 and IPv6 Snippet (wifi-ip)
+#####################################
+
+.. code-block:: console
+
+   west build -S wifi-ip [...]
+
+Overview
+********
+
+This snippet enables IPv4 and IPv6 Wi-Fi support in supported networking samples.
+The sample execution is postponed until Wi-Fi connectivity is established.
+
+Use Wi-Fi shell to connect to the Wi-Fi network:
+
+.. code-block:: console
+
+   wifi connect -s <SSID> -k <key_management> -p <passphrase>
+
+Requirements
+************
+
+Hardware support for:
+
+- :kconfig:option:`CONFIG_WIFI`
+- :kconfig:option:`CONFIG_WIFI_USE_NATIVE_NETWORKING`
diff --git a/snippets/wifi-ip/snippet.yml b/snippets/wifi-ip/snippet.yml
new file mode 100644
index 0000000000000..0c4b0759b608b
--- /dev/null
+++ b/snippets/wifi-ip/snippet.yml
@@ -0,0 +1,3 @@
+name: wifi-ip
+append:
+  EXTRA_CONF_FILE: wifi-ip.conf
diff --git a/snippets/wifi-ip/wifi-ip.conf b/snippets/wifi-ip/wifi-ip.conf
new file mode 100644
index 0000000000000..788715d59b701
--- /dev/null
+++ b/snippets/wifi-ip/wifi-ip.conf
@@ -0,0 +1,32 @@
+# Wi-Fi
+CONFIG_WIFI=y
+CONFIG_NET_L2_ETHERNET=y
+CONFIG_WIFI_NM_WPA_SUPPLICANT=y
+
+# Make sure there is enough resources for supplicant and most of the samples
+CONFIG_MAIN_STACK_SIZE=2048
+CONFIG_ZVFS_OPEN_MAX=24
+CONFIG_NET_MAX_CONN=10
+CONFIG_ZVFS_POLL_MAX=10
+
+# Enable both IPv4 and IPv6
+CONFIG_NET_IPV6=y
+CONFIG_NET_IPV4=y
+
+# DHCPv4 and DHCPv6 are enabled
+CONFIG_NET_DHCPV4=y
+CONFIG_NET_DHCPV6=y
+CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
+CONFIG_NET_CONFIG_MY_IPV6_ADDR=""
+CONFIG_NET_CONFIG_INIT_TIMEOUT=0
+
+# DNS
+CONFIG_DNS_RESOLVER=y
+
+# Connection manager
+CONFIG_NET_CONNECTION_MANAGER=y
+
+# Wi-Fi shell
+CONFIG_NET_SHELL=y
+CONFIG_NET_L2_WIFI_SHELL=y
+CONFIG_SHELL_STACK_SIZE=5200
diff --git a/snippets/wifi-ipv6/README.rst b/snippets/wifi-ipv6/README.rst
new file mode 100644
index 0000000000000..1675c493c6387
--- /dev/null
+++ b/snippets/wifi-ipv6/README.rst
@@ -0,0 +1,28 @@
+.. _snippet-wifi-ipv6:
+
+Wi-Fi IPv6 Snippet (wifi-ipv6)
+##############################
+
+.. code-block:: console
+
+   west build -S wifi-ipv6 [...]
+
+Overview
+********
+
+This snippet enables IPv6 Wi-Fi support in supported networking samples.
+The sample execution is postponed until Wi-Fi connectivity is established.
+
+Use Wi-Fi shell to connect to the Wi-Fi network:
+
+.. code-block:: console
+
+   wifi connect -s <SSID> -k <key_management> -p <passphrase>
+
+Requirements
+************
+
+Hardware support for:
+
+- :kconfig:option:`CONFIG_WIFI`
+- :kconfig:option:`CONFIG_WIFI_USE_NATIVE_NETWORKING`
diff --git a/snippets/wifi-ipv6/snippet.yml b/snippets/wifi-ipv6/snippet.yml
new file mode 100644
index 0000000000000..88983250c94cc
--- /dev/null
+++ b/snippets/wifi-ipv6/snippet.yml
@@ -0,0 +1,3 @@
+name: wifi-ipv6
+append:
+  EXTRA_CONF_FILE: wifi-ipv6.conf
diff --git a/snippets/wifi-ipv6/wifi-ipv6.conf b/snippets/wifi-ipv6/wifi-ipv6.conf
new file mode 100644
index 0000000000000..f4ea1214ece17
--- /dev/null
+++ b/snippets/wifi-ipv6/wifi-ipv6.conf
@@ -0,0 +1,31 @@
+# Wi-Fi
+CONFIG_WIFI=y
+CONFIG_NET_L2_ETHERNET=y
+CONFIG_WIFI_NM_WPA_SUPPLICANT=y
+
+# Make sure there is enough resources for supplicant and most of the samples
+CONFIG_MAIN_STACK_SIZE=2048
+CONFIG_ZVFS_OPEN_MAX=24
+CONFIG_NET_MAX_CONN=10
+CONFIG_ZVFS_POLL_MAX=10
+
+# IPv6 only for now
+CONFIG_NET_IPV6=y
+CONFIG_NET_CONFIG_NEED_IPV4=n
+CONFIG_NET_IPV4=n
+
+# DHCPv6
+CONFIG_NET_DHCPV6=y
+CONFIG_NET_CONFIG_MY_IPV6_ADDR=""
+CONFIG_NET_CONFIG_INIT_TIMEOUT=0
+
+# DNS
+CONFIG_DNS_RESOLVER=y
+
+# Connection manager
+CONFIG_NET_CONNECTION_MANAGER=y
+
+# Wi-Fi shell
+CONFIG_NET_SHELL=y
+CONFIG_NET_L2_WIFI_SHELL=y
+CONFIG_SHELL_STACK_SIZE=5200


Reviews:
user: login: tejlmand
body: Couple of small observations, rest is looking fine.

Small thought, would it be better to have two snippets specifically for ipv4 and ipv6, and then users can use them like this ?
`west build -S wifi-ipv4`
`west build -S wifi-ipv6`
`west build -S wifi-ipv4 -S wifi-ipv6`

Note, current approach is also approved :slightly_smiling_face: 
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-27T13:59:11Z
user: login: rlubos
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-28T08:07:54Z
user: login: tejlmand
body: Approved.

But I do think it's slightly wrong that an IPv6 snippet has opinion regarding IPv4 settings, such as disabling IPv4.
After all, the snippet is named `wifi-ipv6` and not `wifi-ipv6-only`.
(and same goes for the existing IPv4 snippet).
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-28T10:47:10Z

Review comments:
diff_hunk: @@ -0,0 +1,28 @@
+.. _snippet-wifi-ip:
+
+Wi-Fi IPv6 Snippet (wifi-ip)
path: snippets/wifi-ip/README.rst
user: login: tejlmand
body: should this title include `IPv4` ?
created_at: 2025-03-27T13:52:04Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,31 @@
+# Wi-Fi
+CONFIG_WIFI=y
+CONFIG_NET_L2_ETHERNET=y
+CONFIG_WIFI_NM_WPA_SUPPLICANT=y
+
+# Make sure there is enough resources for supplicant and most of the samples
+CONFIG_MAIN_STACK_SIZE=2048
+CONFIG_ZVFS_OPEN_MAX=24
+CONFIG_NET_MAX_CONN=10
+CONFIG_ZVFS_POLL_MAX=10
+
+# IPv4 only for now
path: snippets/wifi-ipv6/wifi-ipv6.conf
user: login: tejlmand
body: Comment looks wrong.
This file enables ipv6, not ipv4.
created_at: 2025-03-27T13:53:16Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,32 @@
+# Wi-Fi
+CONFIG_WIFI=y
+CONFIG_NET_L2_ETHERNET=y
+CONFIG_WIFI_NM_WPA_SUPPLICANT=y
+
+# Make sure there is enough resources for supplicant and most of the samples
+CONFIG_MAIN_STACK_SIZE=2048
+CONFIG_ZVFS_OPEN_MAX=24
+CONFIG_NET_MAX_CONN=10
+CONFIG_ZVFS_POLL_MAX=10
+
+# IPv4 only for now
path: snippets/wifi-ip/wifi-ip.conf
user: login: tejlmand
body: Comment needs an update.
created_at: 2025-03-27T13:58:46Z
author_association: CONTRIBUTOR

PR comments:
user: login: tejlmand
created_at: 2025-03-27T14:01:36Z
body: > Small thought, would it be better to have two snippets specifically for ipv4 and ipv6, and then users can use them like this ?

Nevermind, just noticed there's already a https://github.com/zephyrproject-rtos/zephyr/tree/main/snippets/wifi-ipv4 snippet.

Perhaps we could just have the wifi-ipv6 snippet and user combines them ?
Note: one for each combo like now is also ok.
author_association: CONTRIBUTOR
user: login: jukkar
created_at: 2025-03-27T15:32:33Z
body: > Perhaps we could just have the wifi-ipv6 snippet and user combines them ?

This would have been my preferred option too, but unfortunately this is not really possible as for example the wifi-ipv4 snippet disables IPv6, so combining them is not really practical. So because of this I created the dual IPv4/6 snippet. 
author_association: MEMBER
user: login: jukkar
created_at: 2025-03-27T15:39:24Z
body: * Updated according to comments
author_association: MEMBER
user: login: tejlmand
created_at: 2025-03-28T10:43:04Z
body: >  as for example the wifi-ipv4 snippet disables IPv6,

yes I noticed that, but I would like to question if that is correct.

I could have an existing app which uses IPv6, and on top want to use the IPv4 enabling snippet.
In such case I would not expect an IPv4 enabling snippet to disable IPv6, because I never requested that to happen.
author_association: CONTRIBUTOR