From 7c2986bb34f8334d5906a1bdefa02de7b00f3df0 Mon Sep 17 00:00:00 2001 From: luojun1 Date: Thu, 28 Jul 2022 21:53:58 +0800 Subject: [PATCH] finetune the RA parsing procedure Signed-off-by: luojun1 Signed-off-by: chao.an --- net/icmpv6/icmpv6_input.c | 52 ++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/net/icmpv6/icmpv6_input.c b/net/icmpv6/icmpv6_input.c index 08272fe922..4684eb0f49 100644 --- a/net/icmpv6/icmpv6_input.c +++ b/net/icmpv6/icmpv6_input.c @@ -369,29 +369,47 @@ void icmpv6_input(FAR struct net_driver_s *dev, unsigned int iplen) for (ndx = 0; ndx + sizeof(struct icmpv6_prefixinfo_s) <= optlen; ) { - FAR struct icmpv6_srclladdr_s *sllopt = - (FAR struct icmpv6_srclladdr_s *)&options[ndx]; + FAR struct icmpv6_generic_s *opt = + (FAR struct icmpv6_generic_s *)&options[ndx]; - if (sllopt->opttype == ICMPv6_OPT_SRCLLADDR) + switch (opt->opttype) { - neighbor_add(dev, ipv6->srcipaddr, sllopt->srclladdr); - } + case ICMPv6_OPT_SRCLLADDR: + { + FAR struct icmpv6_srclladdr_s *sllopt = + (FAR struct icmpv6_srclladdr_s *)opt; + neighbor_add(dev, ipv6->srcipaddr, sllopt->srclladdr); + } + break; - FAR struct icmpv6_prefixinfo_s *opt = - (FAR struct icmpv6_prefixinfo_s *)&options[ndx]; + case ICMPv6_OPT_PREFIX: + { + FAR struct icmpv6_prefixinfo_s *prefixopt = + (FAR struct icmpv6_prefixinfo_s *)opt; - /* Is this the sought for prefix? Is it the correct size? Is - * the "A" flag set? - */ + /* Is the "A" flag set? */ - if (opt->opttype == ICMPv6_OPT_PREFIX && - (opt->flags & ICMPv6_PRFX_FLAG_A) != 0) - { - /* Yes.. Notify any waiting threads */ + if ((prefixopt->flags & ICMPv6_PRFX_FLAG_A) != 0) + { + /* Notify any waiting threads */ - icmpv6_rnotify(dev, ipv6->srcipaddr, - opt->prefix, opt->preflen); - prefix = true; + icmpv6_rnotify(dev, ipv6->srcipaddr, + prefixopt->prefix, prefixopt->preflen); + prefix = true; + } + } + break; + + case ICMPv6_OPT_MTU: + { + FAR struct icmpv6_mtu_s *mtuopt = + (FAR struct icmpv6_mtu_s *)opt; + dev->d_pktsize = mtuopt->mtu; + } + break; + + default: + break; } /* Skip to the next option (units of octets) */