From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B1C72C7618E for ; Sat, 22 Apr 2023 00:09:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0F18C863DA; Sat, 22 Apr 2023 02:08:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="k2fnRM5c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E47CB863D2; Sat, 22 Apr 2023 02:08:33 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by phobos.denx.de (Postfix) with ESMTP id C87CE86296 for ; Sat, 22 Apr 2023 02:08:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=emohandesi@linux.microsoft.com Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 6DFC521C253D; Fri, 21 Apr 2023 17:08:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6DFC521C253D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1682122107; bh=evte6j1h+KW2lnJL63F2/fGH21dAjPDAWGW8FbYC+0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k2fnRM5ce4yNRsZE/wQTMgrZrWNf8kMPUoKnzo9qbLGn7b66rDt5DgTaBCQWOFohX HZwM5XygtPfp8S/oMDbXRNcsRZlOrqEGnEn7rpMjX16NM3CZ1Woha2kxBMFxHEG0Sv tKM9eogO2Ar6bn/ut0cFZ7h2yrHGcwOs6Ct+FK4o= From: emohandesi@linux.microsoft.com To: u-boot@lists.denx.de Cc: sjg@chromium.org, mario.six@gdsys.cc, joe.hershberger@ni.com, rfried.dev@gmail.com, xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, masahisa.kojima@linaro.org, pali@kernel.org, tobias@waldekranz.com, john@metanate.com, v.v.mitrofanov@yadro.com, saproj@gmail.com Subject: [PATCH v4 3/3] test: eth: IPv6 network discovery unit test Date: Fri, 21 Apr 2023 17:08:23 -0700 Message-Id: <1682122103-21466-4-git-send-email-emohandesi@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1682122103-21466-1-git-send-email-emohandesi@linux.microsoft.com> References: <1677776290-11067-1-git-send-email-emohandesi@linux.microsoft.com> <1682122103-21466-1-git-send-email-emohandesi@linux.microsoft.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Ehsan Mohandesi Test router advertisement validation and processing functions. Signed-off-by: Ehsan Mohandesi --- 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 #include #include +#include #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