sync with OpenBSD -current

This commit is contained in:
purplerain 2024-02-13 19:37:16 +00:00
parent c151d49b7a
commit be76e7e421
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
96 changed files with 2153 additions and 617 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: if_bridge.c,v 1.368 2023/05/16 14:32:54 jan Exp $ */
/* $OpenBSD: if_bridge.c,v 1.369 2024/02/13 12:22:09 bluhm Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@ -48,6 +48,7 @@
#include <net/if_types.h>
#include <net/if_llc.h>
#include <net/netisr.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/ip.h>

View file

@ -1,4 +1,4 @@
/* $OpenBSD: if_etherip.c,v 1.54 2023/12/23 10:52:54 bluhm Exp $ */
/* $OpenBSD: if_etherip.c,v 1.55 2024/02/13 12:22:09 bluhm Exp $ */
/*
* Copyright (c) 2015 Kazuya GODA <goda@openbsd.org>
*
@ -31,6 +31,7 @@
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/route.h>
#include <net/rtable.h>
#include <netinet/in.h>

View file

@ -1,4 +1,4 @@
/* $OpenBSD: if_ethersubr.c,v 1.291 2023/07/27 20:21:25 jan Exp $ */
/* $OpenBSD: if_ethersubr.c,v 1.292 2024/02/13 13:58:19 bluhm Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */
/*
@ -140,6 +140,20 @@ didn't get a copy, you may request one from <license@ipv6.nrl.navy.mil>.
#include <netmpls/mpls.h>
#endif /* MPLS */
/* #define ETHERDEBUG 1 */
#ifdef ETHERDEBUG
int etherdebug = ETHERDEBUG;
#define DNPRINTF(level, fmt, args...) \
do { \
if (etherdebug >= level) \
printf("%s: " fmt "\n", __func__, ## args); \
} while (0)
#else
#define DNPRINTF(level, fmt, args...) \
do { } while (0)
#endif
#define DPRINTF(fmt, args...) DNPRINTF(1, fmt, args)
u_int8_t etherbroadcastaddr[ETHER_ADDR_LEN] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
u_int8_t etheranyaddr[ETHER_ADDR_LEN] =
@ -1034,56 +1048,126 @@ ether_e64_to_addr(struct ether_addr *ea, uint64_t e64)
/* Parse different TCP/IP protocol headers for a quick view inside an mbuf. */
void
ether_extract_headers(struct mbuf *mp, struct ether_extracted *ext)
ether_extract_headers(struct mbuf *m0, struct ether_extracted *ext)
{
struct mbuf *m;
uint64_t hlen;
size_t hlen;
int hoff;
uint8_t ipproto;
uint16_t ether_type;
/* gcc 4.2.1 on sparc64 may create 32 bit loads on unaligned mbuf */
union {
u_char hc_data;
#if _BYTE_ORDER == _LITTLE_ENDIAN
struct {
u_int hl:4, /* header length */
v:4; /* version */
} hc_ip;
struct {
u_int x2:4, /* (unused) */
off:4; /* data offset */
} hc_th;
#endif
#if _BYTE_ORDER == _BIG_ENDIAN
struct {
u_int v:4, /* version */
hl:4; /* header length */
} hc_ip;
struct {
u_int off:4, /* data offset */
x2:4; /* (unused) */
} hc_th;
#endif
} hdrcpy;
/* Return NULL if header was not recognized. */
memset(ext, 0, sizeof(*ext));
if (mp->m_len < sizeof(*ext->eh))
return;
KASSERT(ISSET(m0->m_flags, M_PKTHDR));
ext->paylen = m0->m_pkthdr.len;
ext->eh = mtod(mp, struct ether_header *);
if (m0->m_len < sizeof(*ext->eh)) {
DPRINTF("m_len %d, eh %zu", m0->m_len, sizeof(*ext->eh));
return;
}
ext->eh = mtod(m0, struct ether_header *);
ether_type = ntohs(ext->eh->ether_type);
hlen = sizeof(*ext->eh);
if (ext->paylen < hlen) {
DPRINTF("paylen %u, ehlen %zu", ext->paylen, hlen);
ext->eh = NULL;
return;
}
ext->paylen -= hlen;
#if NVLAN > 0
if (ether_type == ETHERTYPE_VLAN) {
ext->evh = mtod(mp, struct ether_vlan_header *);
if (m0->m_len < sizeof(*ext->evh)) {
DPRINTF("m_len %d, evh %zu",
m0->m_len, sizeof(*ext->evh));
return;
}
ext->evh = mtod(m0, struct ether_vlan_header *);
ether_type = ntohs(ext->evh->evl_proto);
hlen = sizeof(*ext->evh);
if (sizeof(*ext->eh) + ext->paylen < hlen) {
DPRINTF("paylen %zu, evhlen %zu",
sizeof(*ext->eh) + ext->paylen, hlen);
ext->evh = NULL;
return;
}
ext->paylen = sizeof(*ext->eh) + ext->paylen - hlen;
}
#endif
switch (ether_type) {
case ETHERTYPE_IP:
m = m_getptr(mp, hlen, &hoff);
if (m == NULL || m->m_len - hoff < sizeof(*ext->ip4))
m = m_getptr(m0, hlen, &hoff);
if (m == NULL || m->m_len - hoff < sizeof(*ext->ip4)) {
DPRINTF("m_len %d, hoff %d, ip4 %zu",
m ? m->m_len : -1, hoff, sizeof(*ext->ip4));
return;
}
ext->ip4 = (struct ip *)(mtod(m, caddr_t) + hoff);
memcpy(&hdrcpy.hc_data, ext->ip4, 1);
hlen = hdrcpy.hc_ip.hl << 2;
if (m->m_len - hoff < hlen) {
DPRINTF("m_len %d, hoff %d, iphl %zu",
m ? m->m_len : -1, hoff, hlen);
ext->ip4 = NULL;
return;
}
if (ext->paylen < hlen) {
DPRINTF("paylen %u, ip4hlen %zu", ext->paylen, hlen);
ext->ip4 = NULL;
return;
}
ext->ip4hlen = hlen;
ext->paylen -= hlen;
ipproto = ext->ip4->ip_p;
if (ISSET(ntohs(ext->ip4->ip_off), IP_MF|IP_OFFMASK))
return;
hlen = ext->ip4->ip_hl << 2;
ipproto = ext->ip4->ip_p;
break;
#ifdef INET6
case ETHERTYPE_IPV6:
m = m_getptr(mp, hlen, &hoff);
if (m == NULL || m->m_len - hoff < sizeof(*ext->ip6))
m = m_getptr(m0, hlen, &hoff);
if (m == NULL || m->m_len - hoff < sizeof(*ext->ip6)) {
DPRINTF("m_len %d, hoff %d, ip6 %zu",
m ? m->m_len : -1, hoff, sizeof(*ext->ip6));
return;
}
ext->ip6 = (struct ip6_hdr *)(mtod(m, caddr_t) + hoff);
hlen = sizeof(*ext->ip6);
if (ext->paylen < hlen) {
DPRINTF("paylen %u, ip6hlen %zu", ext->paylen, hlen);
ext->ip6 = NULL;
return;
}
ext->paylen -= hlen;
ipproto = ext->ip6->ip6_nxt;
break;
#endif
default:
@ -1093,16 +1177,51 @@ ether_extract_headers(struct mbuf *mp, struct ether_extracted *ext)
switch (ipproto) {
case IPPROTO_TCP:
m = m_getptr(m, hoff + hlen, &hoff);
if (m == NULL || m->m_len - hoff < sizeof(*ext->tcp))
if (m == NULL || m->m_len - hoff < sizeof(*ext->tcp)) {
DPRINTF("m_len %d, hoff %d, tcp %zu",
m ? m->m_len : -1, hoff, sizeof(*ext->tcp));
return;
}
ext->tcp = (struct tcphdr *)(mtod(m, caddr_t) + hoff);
memcpy(&hdrcpy.hc_data, &ext->tcp->th_flags - 1, 1);
hlen = hdrcpy.hc_th.off << 2;
if (m->m_len - hoff < hlen) {
DPRINTF("m_len %d, hoff %d, thoff %zu",
m ? m->m_len : -1, hoff, hlen);
ext->tcp = NULL;
return;
}
if (ext->paylen < hlen) {
DPRINTF("paylen %u, tcphlen %zu", ext->paylen, hlen);
ext->tcp = NULL;
return;
}
ext->tcphlen = hlen;
ext->paylen -= hlen;
break;
case IPPROTO_UDP:
m = m_getptr(m, hoff + hlen, &hoff);
if (m == NULL || m->m_len - hoff < sizeof(*ext->udp))
if (m == NULL || m->m_len - hoff < sizeof(*ext->udp)) {
DPRINTF("m_len %d, hoff %d, tcp %zu",
m ? m->m_len : -1, hoff, sizeof(*ext->tcp));
return;
}
ext->udp = (struct udphdr *)(mtod(m, caddr_t) + hoff);
hlen = sizeof(*ext->udp);
if (ext->paylen < hlen) {
DPRINTF("paylen %u, udphlen %zu", ext->paylen, hlen);
ext->udp = NULL;
return;
}
break;
}
DNPRINTF(2, "%s%s%s%s%s%s ip4h %u, tcph %u, payl %u",
ext->eh ? "eh," : "", ext->evh ? "evh," : "",
ext->ip4 ? "ip4," : "", ext->ip6 ? "ip6," : "",
ext->tcp ? "tcp," : "", ext->udp ? "udp," : "",
ext->ip4hlen, ext->tcphlen, ext->paylen);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: if_pfsync.c,v 1.324 2023/12/23 10:52:54 bluhm Exp $ */
/* $OpenBSD: if_pfsync.c,v 1.325 2024/02/13 12:22:09 bluhm Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
@ -69,6 +69,7 @@
#include <net/if_types.h>
#include <net/bpf.h>
#include <net/netisr.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>

View file

@ -1,4 +1,4 @@
/* $OpenBSD: if_veb.c,v 1.34 2023/12/23 10:52:54 bluhm Exp $ */
/* $OpenBSD: if_veb.c,v 1.35 2024/02/13 12:22:09 bluhm Exp $ */
/*
* Copyright (c) 2021 David Gwynne <dlg@openbsd.org>
@ -46,7 +46,6 @@
#ifdef INET6
#include <netinet6/in6_var.h>
#include <netinet/ip6.h>
#include <netinet6/ip6_var.h>
#endif
#if 0 && defined(IPSEC)

View file

@ -1,4 +1,4 @@
/* $OpenBSD: route.c,v 1.431 2024/02/09 14:02:11 bluhm Exp $ */
/* $OpenBSD: route.c,v 1.432 2024/02/13 12:22:09 bluhm Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@ -212,8 +212,8 @@ route_cache(struct route *ro, struct in_addr addr, u_int rtableid)
if (rtisvalid(ro->ro_rt) &&
ro->ro_generation == gen &&
ro->ro_tableid == rtableid &&
ro->ro_dst.sa_family == AF_INET &&
satosin(&ro->ro_dst)->sin_addr.s_addr == addr.s_addr) {
ro->ro_dstsa.sa_family == AF_INET &&
ro->ro_dstsin.sin_addr.s_addr == addr.s_addr) {
ipstat_inc(ips_rtcachehit);
return (0);
}
@ -225,17 +225,16 @@ route_cache(struct route *ro, struct in_addr addr, u_int rtableid)
ro->ro_tableid = rtableid;
memset(&ro->ro_dst, 0, sizeof(ro->ro_dst));
satosin(&ro->ro_dst)->sin_family = AF_INET;
satosin(&ro->ro_dst)->sin_len = sizeof(struct sockaddr_in);
satosin(&ro->ro_dst)->sin_addr = addr;
ro->ro_dstsin.sin_family = AF_INET;
ro->ro_dstsin.sin_len = sizeof(struct sockaddr_in);
ro->ro_dstsin.sin_addr = addr;
return (ESRCH);
}
#ifdef INET6
int
route6_cache(struct route_in6 *ro, const struct in6_addr *addr,
u_int rtableid)
route6_cache(struct route *ro, const struct in6_addr *addr, u_int rtableid)
{
u_long gen;
@ -245,8 +244,8 @@ route6_cache(struct route_in6 *ro, const struct in6_addr *addr,
if (rtisvalid(ro->ro_rt) &&
ro->ro_generation == gen &&
ro->ro_tableid == rtableid &&
ro->ro_dst.sin6_family == AF_INET6 &&
IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, addr)) {
ro->ro_dstsa.sa_family == AF_INET6 &&
IN6_ARE_ADDR_EQUAL(&ro->ro_dstsin6.sin6_addr, addr)) {
ip6stat_inc(ip6s_rtcachehit);
return (0);
}
@ -258,9 +257,9 @@ route6_cache(struct route_in6 *ro, const struct in6_addr *addr,
ro->ro_tableid = rtableid;
memset(&ro->ro_dst, 0, sizeof(ro->ro_dst));
ro->ro_dst.sin6_family = AF_INET6;
ro->ro_dst.sin6_len = sizeof(struct sockaddr_in6);
ro->ro_dst.sin6_addr = *addr;
ro->ro_dstsin6.sin6_family = AF_INET6;
ro->ro_dstsin6.sin6_len = sizeof(struct sockaddr_in6);
ro->ro_dstsin6.sin6_addr = *addr;
return (ESRCH);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: route.h,v 1.205 2024/02/05 12:52:11 aoyama Exp $ */
/* $OpenBSD: route.h,v 1.206 2024/02/13 12:22:09 bluhm Exp $ */
/* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */
/*
@ -370,6 +370,19 @@ struct sockaddr_rtsearch {
char sr_search[RTSEARCH_LEN];
};
struct rt_addrinfo {
int rti_addrs;
const struct sockaddr *rti_info[RTAX_MAX];
int rti_flags;
struct ifaddr *rti_ifa;
struct rt_msghdr *rti_rtm;
u_char rti_mpls;
};
#ifdef __BSD_VISIBLE
#include <netinet/in.h>
/*
* A route consists of a destination address and a reference
* to a routing entry. These are often held by protocols
@ -379,17 +392,17 @@ struct route {
struct rtentry *ro_rt;
u_long ro_generation;
u_long ro_tableid; /* u_long because of alignment */
struct sockaddr ro_dst;
union {
struct sockaddr rod_sa;
struct sockaddr_in rod_sin;
struct sockaddr_in6 rod_sin6;
} ro_dst;
#define ro_dstsa ro_dst.rod_sa
#define ro_dstsin ro_dst.rod_sin
#define ro_dstsin6 ro_dst.rod_sin6
};
struct rt_addrinfo {
int rti_addrs;
const struct sockaddr *rti_info[RTAX_MAX];
int rti_flags;
struct ifaddr *rti_ifa;
struct rt_msghdr *rti_rtm;
u_char rti_mpls;
};
#endif /* __BSD_VISIBLE */
#ifdef _KERNEL
@ -449,6 +462,8 @@ struct if_ieee80211_data;
struct bfd_config;
void route_init(void);
int route_cache(struct route *, struct in_addr, u_int);
int route6_cache(struct route *, const struct in6_addr *, u_int);
void rtm_ifchg(struct ifnet *);
void rtm_ifannounce(struct ifnet *, int);
void rtm_bfd(struct bfd_config *);