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
-/* $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 $ */
/*
/* 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)));
-/* $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 $ */
/*
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.
*/
* 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);
-/* $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 $ */
/*
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);
-/* $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 $ */
/*
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 */
}
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 */
-/* $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 $ */
/*
}
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)) {
}
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;