diff options
author | Klemens Nanni <kn@cvs.openbsd.org> | 2022-12-10 21:26:22 +0000 |
---|---|---|
committer | Klemens Nanni <kn@cvs.openbsd.org> | 2022-12-10 21:26:22 +0000 |
commit | 0b108b96037a89413e3343dc43a4e0ecdbf27e22 (patch) | |
tree | e74a8988ff5e51a8523b79d6a39566eac332c314 /sys/netinet6 | |
parent | f18483b6eddcf59e8eb397d77bb8727ecfae8146 (diff) |
Merge nd6_option_init() into nd6_options()
All call-sites call nd6_options() directly after nd6_option_init().
Fold them to simplify the logic and do less pointing around.
Feedback OK bluhm florian
Diffstat (limited to 'sys/netinet6')
-rw-r--r-- | sys/netinet6/icmp6.c | 5 | ||||
-rw-r--r-- | sys/netinet6/nd6.c | 31 | ||||
-rw-r--r-- | sys/netinet6/nd6.h | 5 | ||||
-rw-r--r-- | sys/netinet6/nd6_nbr.c | 8 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 23 |
5 files changed, 32 insertions, 40 deletions
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index fb218628b85..6274685a024 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.243 2022/12/09 17:32:53 claudio Exp $ */ +/* $OpenBSD: icmp6.c,v 1.244 2022/12/10 21:26:21 kn Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -1342,8 +1342,7 @@ icmp6_redirect_input(struct mbuf *m, int off) /* validation passed */ icmp6len -= sizeof(*nd_rd); - nd6_option_init(nd_rd + 1, icmp6len, &ndopts); - if (nd6_options(&ndopts) < 0) { + if (nd6_options(nd_rd + 1, icmp6len, &ndopts) < 0) { nd6log((LOG_INFO, "icmp6_redirect_input: " "invalid ND option, rejected: %s\n", icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 37c2f320af1..5dafa5f5a96 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.259 2022/12/09 17:32:53 claudio Exp $ */ +/* $OpenBSD: nd6.c,v 1.260 2022/12/10 21:26:21 kn Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -139,20 +139,6 @@ nd6_ifdetach(struct ifnet *ifp) free(nd, M_IP6NDP, sizeof(*nd)); } -void -nd6_option_init(void *opt, int icmp6len, struct nd_opts *ndopts) -{ - bzero(ndopts, sizeof(*ndopts)); - ndopts->nd_opts_search = (struct nd_opt_hdr *)opt; - ndopts->nd_opts_last - = (struct nd_opt_hdr *)(((u_char *)opt) + icmp6len); - - if (icmp6len == 0) { - ndopts->nd_opts_done = 1; - ndopts->nd_opts_search = NULL; - } -} - /* * Take one ND option. */ @@ -204,14 +190,21 @@ nd6_option(struct nd_opts *ndopts) * multiple options of the same type. */ int -nd6_options(struct nd_opts *ndopts) +nd6_options(void *opt, int icmp6len, struct nd_opts *ndopts) { - struct nd_opt_hdr *nd_opt; + struct nd_opt_hdr *nd_opt = opt; int i = 0; - KASSERT(ndopts->nd_opts_last != NULL); - if (ndopts->nd_opts_search == NULL) + bzero(ndopts, sizeof(*ndopts)); + 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); diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h index 780434a2e82..0826d9753b5 100644 --- a/sys/netinet6/nd6.h +++ b/sys/netinet6/nd6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.h,v 1.93 2022/12/09 17:32:53 claudio Exp $ */ +/* $OpenBSD: nd6.h,v 1.94 2022/12/10 21:26:21 kn Exp $ */ /* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */ /* @@ -120,8 +120,7 @@ void nd6_init(void); void nd6_ifattach(struct ifnet *); void nd6_ifdetach(struct ifnet *); int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); -void nd6_option_init(void *, int, struct nd_opts *); -int nd6_options(struct nd_opts *); +int nd6_options(void *, int, struct nd_opts *); struct rtentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *, u_int); void nd6_llinfo_settimer(const struct llinfo_nd6 *, unsigned int); diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index b7377f51639..0c1ae3d0384 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_nbr.c,v 1.139 2022/12/09 17:32:53 claudio Exp $ */ +/* $OpenBSD: nd6_nbr.c,v 1.140 2022/12/10 21:26:21 kn Exp $ */ /* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ /* @@ -170,8 +170,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) taddr6.s6_addr16[1] = htons(ifp->if_index); icmp6len -= sizeof(*nd_ns); - nd6_option_init(nd_ns + 1, icmp6len, &ndopts); - if (nd6_options(&ndopts) < 0) { + if (nd6_options(nd_ns + 1, icmp6len, &ndopts) < 0) { nd6log((LOG_INFO, "nd6_ns_input: invalid ND option, ignored\n")); /* nd6_options have incremented stats */ @@ -620,8 +619,7 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len) } icmp6len -= sizeof(*nd_na); - nd6_option_init(nd_na + 1, icmp6len, &ndopts); - if (nd6_options(&ndopts) < 0) { + if (nd6_options(nd_na + 1, icmp6len, &ndopts) < 0) { nd6log((LOG_INFO, "nd6_na_input: invalid ND option, ignored\n")); /* nd6_options have incremented stats */ diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index c91aa4bfa78..1e1e4851161 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.168 2022/12/09 17:32:53 claudio Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.169 2022/12/10 21:26:21 kn Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -107,7 +107,12 @@ nd6_rtr_cache(struct mbuf *m, int off, int icmp6len, int icmp6_type) } icmp6len -= sizeof(*nd_rs); - nd6_option_init(nd_rs + 1, icmp6len, &ndopts); + if (nd6_options(nd_rs + 1, icmp6len, &ndopts) < 0) { + nd6log((LOG_INFO, + "%s: invalid ND option, ignored\n", __func__)); + /* nd6_options have incremented stats */ + goto freeit; + } break; case ND_ROUTER_ADVERT: if (!IN6_IS_ADDR_LINKLOCAL(&saddr6)) { @@ -125,17 +130,15 @@ nd6_rtr_cache(struct mbuf *m, int off, int icmp6len, int icmp6_type) } icmp6len -= sizeof(*nd_ra); - nd6_option_init(nd_ra + 1, icmp6len, &ndopts); + if (nd6_options(nd_ra + 1, icmp6len, &ndopts) < 0) { + nd6log((LOG_INFO, + "%s: invalid ND option, ignored\n", __func__)); + /* nd6_options have incremented stats */ + goto freeit; + } break; } - if (nd6_options(&ndopts) < 0) { - nd6log((LOG_INFO, - "%s: invalid ND option, ignored\n", __func__)); - /* nd6_options have incremented stats */ - goto freeit; - } - if (ndopts.nd_opts_src_lladdr) { lladdr = (char *)(ndopts.nd_opts_src_lladdr + 1); lladdrlen = ndopts.nd_opts_src_lladdr->nd_opt_len << 3; |