From: emohandesi@linux.microsoft.com
To: u-boot@lists.denx.de
Cc: joe.hershberger@ni.com, rfried.dev@gmail.com, sjg@chromium.org,
xypron.glpk@gmx.de, ilias.apalodimas@linaro.org,
masahisa.kojima@linaro.org, tobias@waldekranz.com,
john@metanate.com, v.v.mitrofanov@yadro.com, saproj@gmail.com,
mario.six@gdsys.cc
Subject: [PATCH v2 4/4] test: eth: IPv6 network discovery unit test
Date: Mon, 10 Apr 2023 12:34:47 -0700 [thread overview]
Message-ID: <1681155287-28437-5-git-send-email-emohandesi@linux.microsoft.com> (raw)
In-Reply-To: <1681155287-28437-1-git-send-email-emohandesi@linux.microsoft.com>
From: Ehsan Mohandesi <emohandesi@microsoft.com>
Test router advertisement validation and processing functions.
Signed-off-by: Ehsan Mohandesi <emohandesi@microsoft.com>
---
test/dm/eth.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/test/dm/eth.c b/test/dm/eth.c
index ebf01d8..d05d2a9 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -20,6 +20,7 @@
#include <dm/uclass-internal.h>
#include <test/test.h>
#include <test/ut.h>
+#include <ndisc.h>
#define DM_TEST_ETH_NUM 4
@@ -607,3 +608,90 @@ static int dm_test_eth_async_ping_reply(struct unit_test_state *uts)
}
DM_TEST(dm_test_eth_async_ping_reply, UT_TESTF_SCAN_FDT);
+
+#if IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)
+
+static u8 ip6_ra_buf[] = {0x60, 0xf, 0xc5, 0x4a, 0x0, 0x38, 0x3a, 0xff, 0xfe,
+ 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x85, 0xe6,
+ 0x29, 0x77, 0xcb, 0xc8, 0x53, 0xff, 0x2, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x1, 0x86, 0x0, 0xdc, 0x90, 0x40, 0x80, 0x15, 0x18,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x4,
+ 0x40, 0xc0, 0x0, 0x0, 0x37, 0xdc, 0x0, 0x0, 0x37,
+ 0x78, 0x0, 0x0, 0x0, 0x0, 0x20, 0x1, 0xca, 0xfe, 0xca,
+ 0xfe, 0xca, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x1, 0x1, 0x0, 0x15, 0x5d, 0xe2, 0x8a, 0x2};
+
+static int dm_test_validate_ra(struct unit_test_state *uts)
+{
+ struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf;
+ struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
+ __be16 temp = 0;
+
+ ut_assert(validate_ra(ip6) == true);
+
+ temp = ip6->payload_len;
+ ip6->payload_len = 15;
+ ut_assert(validate_ra(ip6) == false);
+ ip6->payload_len = temp;
+
+ temp = ip6->saddr.s6_addr16[0];
+ ip6->saddr.s6_addr16[0] = 0x2001;
+ ut_assert(validate_ra(ip6) == false);
+ ip6->saddr.s6_addr16[0] = temp;
+
+ temp = ip6->hop_limit;
+ ip6->hop_limit = 15;
+ ut_assert(validate_ra(ip6) == false);
+ ip6->hop_limit = temp;
+
+ temp = icmp->icmp6_code;
+ icmp->icmp6_code = 15;
+ ut_assert(validate_ra(ip6) == false);
+ icmp->icmp6_code = temp;
+
+ return 0;
+}
+
+DM_TEST(dm_test_validate_ra, 0);
+
+static int dm_test_process_ra(struct unit_test_state *uts)
+{
+ int len = sizeof(ip6_ra_buf);
+ struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf;
+ struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
+ struct ra_msg *msg = (struct ra_msg *)icmp;
+ unsigned char *option = msg->opt;
+ struct icmp6_ra_prefix_info *prefix =
+ (struct icmp6_ra_prefix_info *)option;
+ __be16 temp = 0;
+ unsigned char option_len = option[1];
+
+ ut_assert(process_ra(ip6, len) == 0);
+
+ temp = icmp->icmp6_rt_lifetime;
+ icmp->icmp6_rt_lifetime = 0;
+ ut_assert(process_ra(ip6, len) != 0);
+ icmp->icmp6_rt_lifetime = temp;
+
+ ut_assert(process_ra(ip6, 0) != 0);
+
+ option[1] = 0;
+ ut_assert(process_ra(ip6, len) != 0);
+ option[1] = option_len;
+
+ prefix->on_link = false;
+ ut_assert(process_ra(ip6, len) != 0);
+ prefix->on_link = true;
+
+ temp = prefix->prefix.s6_addr16[0];
+ prefix->prefix.s6_addr16[0] = 0x80fe;
+ ut_assert(process_ra(ip6, len) != 0);
+ prefix->prefix.s6_addr16[0] = temp;
+
+ return 0;
+}
+
+DM_TEST(dm_test_process_ra, 0);
+
+#endif
--
1.8.3.1
next prev parent reply other threads:[~2023-04-10 19:35 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 16:58 [PATCH] net: ipv6: Add support for default gateway discovery emohandesi
2023-03-16 8:47 ` Vyacheslav V. Mitrofanov
2023-03-23 16:44 ` Ehsan Mohandesi
2023-03-23 16:59 ` Vyacheslav V. Mitrofanov
2023-04-01 19:02 ` Ramon Fried
2023-04-10 19:34 ` [PATCH v2 0/4] Add IPv6 Network Discovery emohandesi
2023-04-10 19:34 ` [PATCH v2 1/4] Revert "net: ipv6: Add support for default gateway discovery." emohandesi
2023-04-11 7:01 ` Vyacheslav V. Mitrofanov
2023-04-11 14:51 ` Ehsan Mohandesi
2023-04-10 19:34 ` [PATCH v2 2/4] net: ipv6: Add support for default gateway discovery emohandesi
2023-04-10 19:34 ` [PATCH v2 3/4] test/py: IPv6 network discovery test emohandesi
2023-04-10 19:34 ` emohandesi [this message]
2023-04-12 16:10 ` [PATCH v3 0/3] Add IPv6 Network Discovery emohandesi
2023-04-12 16:10 ` [PATCH v3 1/3] net: ipv6: Add support for default gateway discovery emohandesi
2023-04-20 13:44 ` Vyacheslav V. Mitrofanov
2023-04-12 16:10 ` [PATCH v3 2/3] test/py: IPv6 network discovery test emohandesi
2023-04-19 1:46 ` Simon Glass
2023-04-12 16:10 ` [PATCH v3 3/3] test: eth: IPv6 network discovery unit test emohandesi
2023-04-19 1:46 ` Simon Glass
2023-04-22 0:08 ` [PATCH v4 0/3] Add IPv6 Network Discovery emohandesi
2023-04-22 0:08 ` [PATCH v4 1/3] net: ipv6: Add support for default gateway discovery emohandesi
2023-04-24 7:58 ` Vyacheslav V. Mitrofanov
2023-04-24 8:03 ` Vyacheslav V. Mitrofanov
2023-05-04 14:30 ` Sergei Antonov
2023-05-04 14:52 ` Sergei Antonov
2023-05-05 14:13 ` Ehsan Mohandesi
2023-05-06 14:53 ` Tom Rini
2023-05-10 10:05 ` Sergei Antonov
2023-05-10 11:16 ` Vyacheslav V. Mitrofanov
2023-04-22 0:08 ` [PATCH v4 2/3] test/py: IPv6 network discovery test emohandesi
2023-04-24 7:59 ` Vyacheslav V. Mitrofanov
2023-05-06 14:53 ` Tom Rini
2023-04-22 0:08 ` [PATCH v4 3/3] test: eth: IPv6 network discovery unit test emohandesi
2023-04-24 8:01 ` Vyacheslav V. Mitrofanov
2023-05-06 14:53 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1681155287-28437-5-git-send-email-emohandesi@linux.microsoft.com \
--to=emohandesi@linux.microsoft.com \
--cc=ilias.apalodimas@linaro.org \
--cc=joe.hershberger@ni.com \
--cc=john@metanate.com \
--cc=mario.six@gdsys.cc \
--cc=masahisa.kojima@linaro.org \
--cc=rfried.dev@gmail.com \
--cc=saproj@gmail.com \
--cc=sjg@chromium.org \
--cc=tobias@waldekranz.com \
--cc=u-boot@lists.denx.de \
--cc=v.v.mitrofanov@yadro.com \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox