diff mbox series

[14/17] test: dm: eth: Add ip6_addr_in_subnet test

Message ID 20220830123104.256224-15-v.v.mitrofanov@yadro.com
State Superseded
Delegated to: Ramon Fried
Headers show
Series IPv6 support | expand

Commit Message

Vyacheslav V. Mitrofanov Aug. 30, 2022, 12:31 p.m. UTC
Add a test if two address are in the same subnet. Use in sandbox

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
---
 test/dm/eth.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Simon Glass Sept. 1, 2022, 2:27 a.m. UTC | #1
On Tue, 30 Aug 2022 at 07:03, Viacheslav Mitrofanov
<v.v.mitrofanov@yadro.com> wrote:
>
> Add a test if two address are in the same subnet. Use in sandbox
>
> Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
> ---
>  test/dm/eth.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/test/dm/eth.c b/test/dm/eth.c
index bbfa14ef6d..d4a39e53d9 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -99,6 +99,31 @@  static int dm_test_csum_ipv6_magic(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_csum_ipv6_magic, 0);
 
+static int dm_test_ip6_addr_in_subnet(struct unit_test_state *uts)
+{
+	struct in6_addr our = {.s6_addr32[0] = 0x000080fe,
+				 .s6_addr32[1] = 0x00000000,
+				 .s6_addr32[2] = 0xffe9f242,
+				 .s6_addr32[3] = 0xe8f66dfe};
+	struct in6_addr neigh1 = {.s6_addr32[0] = 0x000080fe,
+				 .s6_addr32[1] = 0x00000000,
+				 .s6_addr32[2] = 0xffd5b372,
+				 .s6_addr32[3] = 0x3ef692fe};
+	struct in6_addr neigh2 = {.s6_addr32[0] = 0x60480120,
+				 .s6_addr32[1] = 0x00006048,
+				 .s6_addr32[2] = 0x00000000,
+				 .s6_addr32[3] = 0x00008888};
+
+	/* in */
+	ut_assert(ip6_addr_in_subnet(&our, &neigh1, 64));
+	/* outside */
+	ut_assert(!ip6_addr_in_subnet(&our, &neigh2, 64));
+	ut_assert(!ip6_addr_in_subnet(&our, &neigh1, 128));
+
+	return 0;
+}
+DM_TEST(dm_test_ip6_addr_in_subnet, 0);
+
 static int dm_test_eth(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");