sync with OpenBSD -current

This commit is contained in:
purplerain 2024-07-16 03:02:11 +00:00
parent bc7421a947
commit 4cca26dc5a
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
120 changed files with 4168 additions and 640 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: icmp6.c,v 1.253 2024/06/20 19:25:42 bluhm Exp $ */
/* $OpenBSD: icmp6.c,v 1.254 2024/07/14 18:53:39 bluhm Exp $ */
/* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */
/*
@ -1228,6 +1228,7 @@ icmp6_redirect_input(struct mbuf *m, int off)
char *lladdr = NULL;
int lladdrlen = 0;
struct rtentry *rt = NULL;
int i_am_router = (atomic_load_int(&ip6_forwarding) != 0);
int is_router;
int is_onlink;
struct in6_addr src6 = ip6->ip6_src;
@ -1241,7 +1242,7 @@ icmp6_redirect_input(struct mbuf *m, int off)
return;
/* if we are router, we don't update route by icmp6 redirect */
if (ip6_forwarding != 0)
if (i_am_router)
goto freeit;
if (!(ifp->if_xflags & IFXF_AUTOCONF6))
goto freeit;
@ -1366,7 +1367,7 @@ icmp6_redirect_input(struct mbuf *m, int off)
/* RFC 2461 8.3 */
nd6_cache_lladdr(ifp, &redtgt6, lladdr, lladdrlen, ND_REDIRECT,
is_onlink ? ND_REDIRECT_ONLINK : ND_REDIRECT_ROUTER);
is_onlink ? ND_REDIRECT_ONLINK : ND_REDIRECT_ROUTER, i_am_router);
if (!is_onlink) { /* better router case. perform rtredirect. */
/* perform rtredirect */
@ -1438,11 +1439,12 @@ icmp6_redirect_output(struct mbuf *m0, struct rtentry *rt)
size_t maxlen;
u_char *p;
struct sockaddr_in6 src_sa;
int i_am_router = (atomic_load_int(&ip6_forwarding) != 0);
icmp6_errcount(ND_REDIRECT, 0);
/* if we are not router, we don't send icmp6 redirect */
if (ip6_forwarding == 0)
if (!i_am_router)
goto fail;
/* sanity check */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ip6_input.c,v 1.264 2024/07/04 12:50:08 bluhm Exp $ */
/* $OpenBSD: ip6_input.c,v 1.265 2024/07/14 18:53:39 bluhm Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
@ -416,7 +416,7 @@ ip6_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp)
SET(flags, IPV6_REDIRECT);
#endif
switch (ip6_forwarding) {
switch (atomic_load_int(&ip6_forwarding)) {
case 2:
SET(flags, IPV6_FORWARDING_IPSEC);
/* FALLTHROUGH */
@ -1443,12 +1443,15 @@ const u_char inet6ctlerrmap[PRC_NCMDS] = {
extern int ip6_mrtproto;
#endif
const struct sysctl_bounded_args ipv6ctl_vars_unlocked[] = {
{ IPV6CTL_FORWARDING, &ip6_forwarding, 0, 2 },
};
const struct sysctl_bounded_args ipv6ctl_vars[] = {
{ IPV6CTL_DAD_PENDING, &ip6_dad_pending, SYSCTL_INT_READONLY },
#ifdef MROUTING
{ IPV6CTL_MRTPROTO, &ip6_mrtproto, SYSCTL_INT_READONLY },
#endif
{ IPV6CTL_FORWARDING, &ip6_forwarding, 0, 2 },
{ IPV6CTL_SENDREDIRECTS, &ip6_sendredirects, 0, 1 },
{ IPV6CTL_DEFHLIM, &ip6_defhlim, 0, 255 },
{ IPV6CTL_MAXFRAGPACKETS, &ip6_maxfragpackets, 0, 1000 },
@ -1568,6 +1571,10 @@ ip6_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
atomic_inc_long(&rtgeneration);
NET_UNLOCK();
return (error);
case IPV6CTL_FORWARDING:
return (sysctl_bounded_arr(
ipv6ctl_vars_unlocked, nitems(ipv6ctl_vars_unlocked),
name, namelen, oldp, oldlenp, newp, newlen));
default:
NET_LOCK();
error = sysctl_bounded_arr(ipv6ctl_vars, nitems(ipv6ctl_vars),

View file

@ -1,4 +1,4 @@
/* $OpenBSD: nd6.c,v 1.281 2024/06/20 19:25:42 bluhm Exp $ */
/* $OpenBSD: nd6.c,v 1.282 2024/07/14 18:53:39 bluhm Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@ -107,8 +107,8 @@ void nd6_slowtimo(void *);
void nd6_expire(void *);
void nd6_expire_timer(void *);
void nd6_invalidate(struct rtentry *);
void nd6_free(struct rtentry *);
int nd6_llinfo_timer(struct rtentry *);
void nd6_free(struct rtentry *, int);
int nd6_llinfo_timer(struct rtentry *, int);
struct timeout nd6_timer_to;
struct timeout nd6_slowtimo_ch;
@ -264,6 +264,7 @@ nd6_timer(void *unused)
{
struct llinfo_nd6 *ln, *nln;
time_t uptime, expire;
int i_am_router = (atomic_load_int(&ip6_forwarding) != 0);
int secs;
NET_LOCK();
@ -276,7 +277,7 @@ nd6_timer(void *unused)
struct rtentry *rt = ln->ln_rt;
if (rt->rt_expire && rt->rt_expire <= uptime)
if (nd6_llinfo_timer(rt))
if (nd6_llinfo_timer(rt, i_am_router))
continue;
if (rt->rt_expire && rt->rt_expire < expire)
@ -300,7 +301,7 @@ nd6_timer(void *unused)
* Returns 1 if `rt' should no longer be used, 0 otherwise.
*/
int
nd6_llinfo_timer(struct rtentry *rt)
nd6_llinfo_timer(struct rtentry *rt, int i_am_router)
{
struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
struct sockaddr_in6 *dst = satosin6(rt_key(rt));
@ -346,7 +347,7 @@ nd6_llinfo_timer(struct rtentry *rt)
} else
atomic_sub_int(&ln_hold_total, len);
nd6_free(rt);
nd6_free(rt, i_am_router);
ln = NULL;
}
break;
@ -362,7 +363,7 @@ nd6_llinfo_timer(struct rtentry *rt)
case ND6_LLINFO_PURGE:
/* Garbage Collection(RFC 2461 5.3) */
if (!ND6_LLINFO_PERMANENT(ln)) {
nd6_free(rt);
nd6_free(rt, i_am_router);
ln = NULL;
}
break;
@ -383,7 +384,7 @@ nd6_llinfo_timer(struct rtentry *rt)
nd6_ns_output(ifp, &dst->sin6_addr, &dst->sin6_addr,
&ln->ln_saddr6, 0);
} else {
nd6_free(rt);
nd6_free(rt, i_am_router);
ln = NULL;
}
break;
@ -477,6 +478,7 @@ void
nd6_purge(struct ifnet *ifp)
{
struct llinfo_nd6 *ln, *nln;
int i_am_router = (atomic_load_int(&ip6_forwarding) != 0);
NET_ASSERT_LOCKED_EXCLUSIVE();
@ -492,7 +494,7 @@ nd6_purge(struct ifnet *ifp)
rt->rt_gateway->sa_family == AF_LINK) {
sdl = satosdl(rt->rt_gateway);
if (sdl->sdl_index == ifp->if_index)
nd6_free(rt);
nd6_free(rt, i_am_router);
}
}
}
@ -661,7 +663,7 @@ nd6_invalidate(struct rtentry *rt)
* Free an nd6 llinfo entry.
*/
void
nd6_free(struct rtentry *rt)
nd6_free(struct rtentry *rt, int i_am_router)
{
struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
struct in6_addr in6 = satosin6(rt_key(rt))->sin6_addr;
@ -671,7 +673,7 @@ nd6_free(struct rtentry *rt)
ifp = if_get(rt->rt_ifidx);
if (ip6_forwarding == 0) {
if (!i_am_router) {
if (ln->ln_router) {
/*
* rt6_flush must be called whether or not the neighbor
@ -1031,7 +1033,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
*/
void
nd6_cache_lladdr(struct ifnet *ifp, const struct in6_addr *from, char *lladdr,
int lladdrlen, int type, int code)
int lladdrlen, int type, int code, int i_am_router)
{
struct rtentry *rt;
struct llinfo_nd6 *ln;
@ -1080,7 +1082,7 @@ nd6_cache_lladdr(struct ifnet *ifp, const struct in6_addr *from, char *lladdr,
return;
if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) {
fail:
nd6_free(rt);
nd6_free(rt, i_am_router);
rtfree(rt);
return;
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: nd6.h,v 1.99 2023/05/04 06:56:56 bluhm Exp $ */
/* $OpenBSD: nd6.h,v 1.100 2024/07/14 18:53:39 bluhm Exp $ */
/* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */
/*
@ -134,7 +134,7 @@ void nd6_nud_hint(struct rtentry *);
void nd6_rtrequest(struct ifnet *, int, struct rtentry *);
int nd6_ioctl(u_long, caddr_t, struct ifnet *);
void nd6_cache_lladdr(struct ifnet *, const struct in6_addr *, char *,
int, int, int);
int, int, int, int);
int nd6_resolve(struct ifnet *, struct rtentry *, struct mbuf *,
struct sockaddr *, u_char *);
int nd6_need_cache(struct ifnet *);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: nd6_nbr.c,v 1.152 2024/06/20 19:25:42 bluhm Exp $ */
/* $OpenBSD: nd6_nbr.c,v 1.153 2024/07/14 18:53:39 bluhm Exp $ */
/* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */
/*
@ -108,7 +108,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len)
struct ifaddr *ifa = NULL;
int lladdrlen = 0;
int anycast = 0, proxy = 0, tentative = 0;
int i_am_router = (ip6_forwarding != 0);
int i_am_router = (atomic_load_int(&ip6_forwarding) != 0);
int tlladdr;
struct nd_opts ndopts;
struct sockaddr_dl *proxydl = NULL;
@ -323,7 +323,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len)
}
nd6_cache_lladdr(ifp, &saddr6, lladdr, lladdrlen, ND_NEIGHBOR_SOLICIT,
0);
0, i_am_router);
nd6_na_output(ifp, &saddr6, &taddr6,
((anycast || proxy || !tlladdr) ? 0 : ND_NA_FLAG_OVERRIDE) |
@ -559,7 +559,7 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len)
int is_override;
char *lladdr = NULL;
int lladdrlen = 0;
int i_am_router = (ip6_forwarding != 0);
int i_am_router = (atomic_load_int(&ip6_forwarding) != 0);
struct ifaddr *ifa;
struct in6_ifaddr *ifa6;
struct llinfo_nd6 *ln;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: nd6_rtr.c,v 1.170 2023/03/31 19:43:33 bluhm Exp $ */
/* $OpenBSD: nd6_rtr.c,v 1.171 2024/07/14 18:53:39 bluhm Exp $ */
/* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */
/*
@ -73,6 +73,7 @@ nd6_rtr_cache(struct mbuf *m, int off, int icmp6len, int icmp6_type)
struct in6_addr saddr6 = ip6->ip6_src;
char *lladdr = NULL;
int lladdrlen = 0;
int i_am_router = (atomic_load_int(&ip6_forwarding) != 0);
struct nd_opts ndopts;
char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
@ -157,7 +158,8 @@ nd6_rtr_cache(struct mbuf *m, int off, int icmp6len, int icmp6_type)
goto bad;
}
nd6_cache_lladdr(ifp, &saddr6, lladdr, lladdrlen, icmp6_type, 0);
nd6_cache_lladdr(ifp, &saddr6, lladdr, lladdrlen, icmp6_type, 0,
i_am_router);
if_put(ifp);
freeit: