From 0a2b5415dce9e071f63c96dd2dbfcd2c6c2c6734 Mon Sep 17 00:00:00 2001 From: kn Date: Fri, 6 Jan 2023 14:24:36 +0000 Subject: [PATCH] Simplify nd6_options() initialise logic nd_opts_{search,last,done} are exlusively used in the internal option handling machinery; the only two nd6_options() callers only use nd_opts_{src,tgt}_lladdr. nd6_options() always zeroes and initialises the caller's struct nd_opts. If icmp6len is zero, i.e. if there are no ICMP6 header options left, everything inside *ndopts is zero, except nd_opts_done=1 which is not used by the callers. Set the internal nd_opts_{search,last,done} members only when needed. OK claudio --- sys/netinet6/nd6.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 5dafa5f5a96..f13f31875b4 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.260 2022/12/10 21:26:21 kn Exp $ */ +/* $OpenBSD: nd6.c,v 1.261 2023/01/06 14:24:36 kn Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -196,16 +196,14 @@ nd6_options(void *opt, int icmp6len, struct nd_opts *ndopts) int i = 0; bzero(ndopts, sizeof(*ndopts)); + + if (icmp6len == 0) + return 0; + ndopts->nd_opts_search = nd_opt; ndopts->nd_opts_last = (struct nd_opt_hdr *)(((u_char *)nd_opt) + icmp6len); - if (icmp6len == 0) { - ndopts->nd_opts_done = 1; - ndopts->nd_opts_search = NULL; - return 0; - } - while (1) { nd_opt = nd6_option(ndopts); if (nd_opt == NULL && ndopts->nd_opts_last == NULL) { -- 2.20.1