From 6dadaa4a5d5182e48c49e94db303a8c313afbc7d Mon Sep 17 00:00:00 2001 From: purplerain Date: Fri, 10 Jan 2025 03:18:05 +0000 Subject: [PATCH] sync with OpenBSD -current --- etc/MAKEDEV.common | 4 +- etc/etc.amd64/MAKEDEV | 12 +-- etc/etc.arm64/MAKEDEV | 8 +- etc/etc.armv7/MAKEDEV | 8 +- etc/etc.i386/MAKEDEV | 12 +-- lib/libc/crypt/crypt.3 | 6 +- lib/libcrypto/bn/bn_recp.c | 47 +++++------ lib/libcrypto/ec/ec_lib.c | 6 +- .../sosplice/error/args-unsplice-EPROTO.pl | 26 ++++++ share/man/man9/sosplice.9 | 6 +- share/misc/airport | 3 +- sys/dev/dt/dt_prov_static.c | 4 +- sys/dev/fdt/gpiokeys.c | 38 +++++++-- sys/dev/fdt/qcgpio_fdt.c | 18 ++++- sys/dev/ofw/ofw_gpio.c | 30 ++++++- sys/dev/ofw/ofw_gpio.h | 8 +- sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c | 6 +- sys/dev/pci/pcidevs | 7 +- sys/dev/pci/pcidevs.h | 7 +- sys/dev/pci/pcidevs_data.h | 22 ++++- sys/dev/pv/virtio.c | 23 +++++- sys/dev/pv/virtiovar.h | 7 +- sys/dev/softraid.c | 5 +- sys/kern/subr_hibernate.c | 5 +- sys/kern/uipc_socket.c | 9 ++- sys/net/rtsock.c | 4 +- sys/netinet/in_pcb.c | 14 ++-- sys/netinet/in_pcb.h | 6 +- sys/netinet/tcp_input.c | 6 +- sys/netinet/tcp_usrreq.c | 71 ++++++++++------ sys/sys/refcnt.h | 7 +- usr.sbin/bgpd/bgpd.conf.5 | 6 +- usr.sbin/bgpd/bgpd.h | 6 +- usr.sbin/bgpd/parse.y | 9 ++- usr.sbin/bgpd/printconf.c | 6 +- usr.sbin/bgpd/rde.c | 37 ++++++++- usr.sbin/bgpd/rde.h | 4 +- usr.sbin/bgpd/rde_peer.c | 26 ++++-- usr.sbin/bgpd/rde_update.c | 81 ++++++++++--------- usr.sbin/bgpd/rtr_proto.c | 4 +- usr.sbin/bgpd/util.c | 4 +- usr.sbin/vmd/virtio.c | 78 ++++++++++++++---- usr.sbin/vmd/virtio.h | 10 ++- usr.sbin/vmd/vmd.h | 4 +- 44 files changed, 503 insertions(+), 207 deletions(-) create mode 100644 regress/sys/kern/sosplice/error/args-unsplice-EPROTO.pl diff --git a/etc/MAKEDEV.common b/etc/MAKEDEV.common index eaf77bba6..3b90b9127 100644 --- a/etc/MAKEDEV.common +++ b/etc/MAKEDEV.common @@ -1,4 +1,4 @@ -vers(a, {-$OpenBSD: MAKEDEV.common,v 1.121 2024/09/03 09:35:46 bluhm Exp $-})dnl +vers(a, {-$OpenBSD: MAKEDEV.common,v 1.122 2025/01/08 23:09:25 kirill Exp $-})dnl dnl dnl Copyright (c) 2001-2006 Todd T. Fries dnl @@ -144,7 +144,7 @@ twrget(all, lpt, lpa, 0, 1, 2)dnl target(all, joy, 0, 1)dnl twrget(all, rnd, random)dnl target(all, uk, 0)dnl -twrget(all, vi, video, 0, 1)dnl +twrget(all, vi, video, 0, 1, 2, 3)dnl twrget(all, speak, speaker)dnl target(all, asc, 0)dnl target(all, radio, 0)dnl diff --git a/etc/etc.amd64/MAKEDEV b/etc/etc.amd64/MAKEDEV index 7a4455625..9ebdc191d 100644 --- a/etc/etc.amd64/MAKEDEV +++ b/etc/etc.amd64/MAKEDEV @@ -4,7 +4,7 @@ # generated from: # # OpenBSD: etc.amd64/MAKEDEV.md,v 1.83 2024/09/03 09:35:46 bluhm Exp -# OpenBSD: MAKEDEV.common,v 1.121 2024/09/03 09:35:46 bluhm Exp +# OpenBSD: MAKEDEV.common,v 1.122 2025/01/08 23:09:25 kirill Exp # OpenBSD: MAKEDEV.mi,v 1.83 2016/09/11 03:06:31 deraadt Exp # OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp # @@ -612,11 +612,11 @@ all) R ch0 audio0 audio1 audio2 audio3 psp kstat dt kcov bpf pvbus0 R pvbus1 vmm fuse pppac pppx hotplug ptm local wscons pci0 R pci1 pci2 pci3 uall rmidi0 rmidi1 rmidi2 rmidi3 rmidi4 - R rmidi5 rmidi6 rmidi7 tuner0 radio0 speaker video0 video1 uk0 - R random lpa0 lpa1 lpa2 lpt0 lpt1 lpt2 tty00 tty01 tty02 tty03 - R tty04 tty05 tty06 tty07 tty08 tty09 tty0a tty0b ttyc0 ttyc1 - R ttyc2 ttyc3 ttyc4 ttyc5 ttyc6 ttyc7 apm pf pctr wd0 wd1 wd2 - R wd3 std st0 st1 fd + R rmidi5 rmidi6 rmidi7 tuner0 radio0 speaker video0 video1 + R video2 video3 uk0 random lpa0 lpa1 lpa2 lpt0 lpt1 lpt2 tty00 + R tty01 tty02 tty03 tty04 tty05 tty06 tty07 tty08 tty09 tty0a + R tty0b ttyc0 ttyc1 ttyc2 ttyc3 ttyc4 ttyc5 ttyc6 ttyc7 apm pf + R pctr wd0 wd1 wd2 wd3 std st0 st1 fd ;; wd*|sd*) diff --git a/etc/etc.arm64/MAKEDEV b/etc/etc.arm64/MAKEDEV index 58d282419..d588fcf45 100644 --- a/etc/etc.arm64/MAKEDEV +++ b/etc/etc.arm64/MAKEDEV @@ -4,7 +4,7 @@ # generated from: # # OpenBSD: etc.arm64/MAKEDEV.md,v 1.16 2023/01/14 12:15:12 kettenis Exp -# OpenBSD: MAKEDEV.common,v 1.120 2023/01/28 11:04:47 phessler Exp +# OpenBSD: MAKEDEV.common,v 1.122 2025/01/08 23:09:25 kirill Exp # OpenBSD: MAKEDEV.mi,v 1.83 2016/09/11 03:06:31 deraadt Exp # OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp # @@ -514,9 +514,9 @@ all) R ch0 audio0 audio1 audio2 audio3 kstat dt bpf fuse pppac pppx R hotplug ptm local wscons pci0 pci1 pci2 pci3 uall rmidi0 R rmidi1 rmidi2 rmidi3 rmidi4 rmidi5 rmidi6 rmidi7 tuner0 - R radio0 video0 video1 uk0 random tty00 tty01 tty02 tty03 - R tty04 tty05 tty06 tty07 tty08 tty09 tty0a tty0b apm pf wd0 - R wd1 wd2 wd3 std fd + R radio0 video0 video1 video2 video3 uk0 random tty00 tty01 + R tty02 tty03 tty04 tty05 tty06 tty07 tty08 tty09 tty0a tty0b + R apm pf wd0 wd1 wd2 wd3 std fd ;; wd*|sd*) diff --git a/etc/etc.armv7/MAKEDEV b/etc/etc.armv7/MAKEDEV index 5a3c5903a..da49bc997 100644 --- a/etc/etc.armv7/MAKEDEV +++ b/etc/etc.armv7/MAKEDEV @@ -4,7 +4,7 @@ # generated from: # # OpenBSD: etc.armv7/MAKEDEV.md,v 1.22 2022/11/09 19:35:23 krw Exp -# OpenBSD: MAKEDEV.common,v 1.120 2023/01/28 11:04:47 phessler Exp +# OpenBSD: MAKEDEV.common,v 1.122 2025/01/08 23:09:25 kirill Exp # OpenBSD: MAKEDEV.mi,v 1.83 2016/09/11 03:06:31 deraadt Exp # OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp # @@ -497,9 +497,9 @@ all) R diskmap vscsi0 ch0 audio0 audio1 audio2 kstat dt bpf fuse R pppac pppx hotplug ptm local wscons pci0 pci1 pci2 pci3 uall R rmidi0 rmidi1 rmidi2 rmidi3 rmidi4 rmidi5 rmidi6 rmidi7 - R tuner0 radio0 video0 video1 uk0 random tty00 tty01 tty02 - R tty03 tty04 tty05 tty06 tty07 tty08 tty09 tty0a tty0b apm pf - R wd0 wd1 wd2 wd3 std st0 st1 fd + R tuner0 radio0 video0 video1 video2 video3 uk0 random tty00 + R tty01 tty02 tty03 tty04 tty05 tty06 tty07 tty08 tty09 tty0a + R tty0b apm pf wd0 wd1 wd2 wd3 std st0 st1 fd ;; wd*|sd*) diff --git a/etc/etc.i386/MAKEDEV b/etc/etc.i386/MAKEDEV index 1b98cfb18..828741fa2 100644 --- a/etc/etc.i386/MAKEDEV +++ b/etc/etc.i386/MAKEDEV @@ -4,7 +4,7 @@ # generated from: # # OpenBSD: etc.i386/MAKEDEV.md,v 1.96 2022/11/09 19:35:23 krw Exp -# OpenBSD: MAKEDEV.common,v 1.120 2023/01/28 11:04:47 phessler Exp +# OpenBSD: MAKEDEV.common,v 1.122 2025/01/08 23:09:25 kirill Exp # OpenBSD: MAKEDEV.mi,v 1.83 2016/09/11 03:06:31 deraadt Exp # OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp # @@ -602,11 +602,11 @@ all) R audio3 kstat dt kcov bpf pvbus0 pvbus1 fuse pppac pppx R hotplug ptm local wscons pci0 pci1 pci2 pci3 uall rmidi0 R rmidi1 rmidi2 rmidi3 rmidi4 rmidi5 rmidi6 rmidi7 tuner0 - R radio0 speaker video0 video1 uk0 random joy0 joy1 lpa0 lpa1 - R lpa2 lpt0 lpt1 lpt2 tty00 tty01 tty02 tty03 tty04 tty05 - R tty06 tty07 tty08 tty09 tty0a tty0b ttyc0 ttyc1 ttyc2 ttyc3 - R ttyc4 ttyc5 ttyc6 ttyc7 apm pf pctr wd0 wd1 wd2 wd3 std st0 - R st1 fd + R radio0 speaker video0 video1 video2 video3 uk0 random joy0 + R joy1 lpa0 lpa1 lpa2 lpt0 lpt1 lpt2 tty00 tty01 tty02 tty03 + R tty04 tty05 tty06 tty07 tty08 tty09 tty0a tty0b ttyc0 ttyc1 + R ttyc2 ttyc3 ttyc4 ttyc5 ttyc6 ttyc7 apm pf pctr wd0 wd1 wd2 + R wd3 std st0 st1 fd ;; wd*|sd*) diff --git a/lib/libc/crypt/crypt.3 b/lib/libc/crypt/crypt.3 index c8ebf9861..6a21571dd 100644 --- a/lib/libc/crypt/crypt.3 +++ b/lib/libc/crypt/crypt.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: crypt.3,v 1.45 2015/04/06 20:49:41 tedu Exp $ +.\" $OpenBSD: crypt.3,v 1.46 2025/01/09 23:18:08 jsg Exp $ .\" .\" FreeSec: libcrypt .\" @@ -31,7 +31,7 @@ .\" .\" Manual page, using -mandoc macros .\" -.Dd $Mdocdate: April 6 2015 $ +.Dd $Mdocdate: January 9 2025 $ .Dt CRYPT 3 .Os .Sh NAME @@ -125,7 +125,7 @@ on failure. .Xr getpass 3 , .Xr passwd 5 .Sh HISTORY -A rotor-based +An M-209 based .Fn crypt function appeared in .At v3 . diff --git a/lib/libcrypto/bn/bn_recp.c b/lib/libcrypto/bn/bn_recp.c index c9a83f848..44c5b05e4 100644 --- a/lib/libcrypto/bn/bn_recp.c +++ b/lib/libcrypto/bn/bn_recp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_recp.c,v 1.21 2025/01/06 13:47:37 tb Exp $ */ +/* $OpenBSD: bn_recp.c,v 1.25 2025/01/08 20:21:28 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -65,8 +65,8 @@ void BN_RECP_CTX_init(BN_RECP_CTX *recp) { - BN_init(&(recp->N)); - BN_init(&(recp->Nr)); + BN_init(&recp->N); + BN_init(&recp->Nr); recp->num_bits = 0; recp->flags = 0; } @@ -77,11 +77,11 @@ BN_RECP_CTX_new(void) BN_RECP_CTX *ret; if ((ret = malloc(sizeof(BN_RECP_CTX))) == NULL) - return (NULL); + return NULL; BN_RECP_CTX_init(ret); ret->flags = BN_FLG_MALLOCED; - return (ret); + return ret; } void @@ -90,8 +90,8 @@ BN_RECP_CTX_free(BN_RECP_CTX *recp) if (recp == NULL) return; - BN_free(&(recp->N)); - BN_free(&(recp->Nr)); + BN_free(&recp->N); + BN_free(&recp->Nr); if (recp->flags & BN_FLG_MALLOCED) free(recp); } @@ -99,12 +99,14 @@ BN_RECP_CTX_free(BN_RECP_CTX *recp) int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) { - if (!bn_copy(&(recp->N), d)) + if (!bn_copy(&recp->N, d)) return 0; - BN_zero(&(recp->Nr)); - recp->num_bits = BN_num_bits(d); + recp->num_bits = BN_num_bits(&recp->N); + + BN_zero(&recp->Nr); recp->shift = 0; - return (1); + + return 1; } /* len is the expected size of the result @@ -125,14 +127,14 @@ BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) if (!BN_set_bit(t, len)) goto err; - if (!BN_div_ct(r, NULL, t,m, ctx)) + if (!BN_div_ct(r, NULL, t, m, ctx)) goto err; ret = len; err: BN_CTX_end(ctx); - return (ret); + return ret; } int @@ -156,14 +158,14 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, if (a == NULL || b == NULL || d == NULL || r == NULL) goto err; - if (BN_ucmp(m, &(recp->N)) < 0) { + if (BN_ucmp(m, &recp->N) < 0) { BN_zero(d); if (!bn_copy(r, m)) { BN_CTX_end(ctx); return 0; } BN_CTX_end(ctx); - return (1); + return 1; } /* We want the remainder @@ -180,7 +182,7 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, /* Nr := round(2^i / N) */ if (i != recp->shift) - recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx); + recp->shift = BN_reciprocal(&recp->Nr, &recp->N, i, ctx); /* BN_reciprocal returns i, or -1 for an error */ if (recp->shift == -1) @@ -193,13 +195,13 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, */ if (!BN_rshift(a, m, recp->num_bits)) goto err; - if (!BN_mul(b, a,&(recp->Nr), ctx)) + if (!BN_mul(b, a, &recp->Nr, ctx)) goto err; if (!BN_rshift(d, b, i - recp->num_bits)) goto err; d->neg = 0; - if (!BN_mul(b, &(recp->N), d, ctx)) + if (!BN_mul(b, &recp->N, d, ctx)) goto err; if (!BN_usub(r, m, b)) goto err; @@ -207,12 +209,12 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, #if 1 j = 0; - while (BN_ucmp(r, &(recp->N)) >= 0) { + while (BN_ucmp(r, &recp->N) >= 0) { if (j++ > 2) { BNerror(BN_R_BAD_RECIPROCAL); goto err; } - if (!BN_usub(r, r, &(recp->N))) + if (!BN_usub(r, r, &recp->N)) goto err; if (!BN_add_word(d, 1)) goto err; @@ -226,10 +228,9 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, err: BN_CTX_end(ctx); - return (ret); + return ret; } - int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, BN_RECP_CTX *recp, BN_CTX *ctx) @@ -257,5 +258,5 @@ BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, err: BN_CTX_end(ctx); - return (ret); + return ret; } diff --git a/lib/libcrypto/ec/ec_lib.c b/lib/libcrypto/ec/ec_lib.c index a50b1e563..d7f0bc635 100644 --- a/lib/libcrypto/ec/ec_lib.c +++ b/lib/libcrypto/ec/ec_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_lib.c,v 1.103 2025/01/07 08:30:52 tb Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.105 2025/01/09 11:35:46 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -623,7 +623,8 @@ EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx_in) goto err; /* - * Check that the discriminant 4a^3 + 27b^2 is non-zero modulo p. + * Check that the discriminant 4a^3 + 27b^2 is non-zero modulo p + * assuming that p > 3 is prime and that a and b are in [0, p). */ if (BN_is_zero(a) && BN_is_zero(b)) @@ -1425,4 +1426,3 @@ EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, return 0; } LCRYPTO_ALIAS(EC_POINT_get_Jprojective_coordinates_GFp); - diff --git a/regress/sys/kern/sosplice/error/args-unsplice-EPROTO.pl b/regress/sys/kern/sosplice/error/args-unsplice-EPROTO.pl new file mode 100644 index 000000000..e4bb0e87c --- /dev/null +++ b/regress/sys/kern/sosplice/error/args-unsplice-EPROTO.pl @@ -0,0 +1,26 @@ +# test EPROTO for unsplicing non-spliced sockets + +use strict; +use warnings; +use IO::Socket::IP; +use BSD::Socket::Splice "SO_SPLICE"; + +our %args = ( + errno => 'EPROTO', + func => sub { + my $sl = IO::Socket::IP->new( + Proto => "tcp", + Listen => 5, + LocalAddr => "127.0.0.1", + ) or die "socket listen failed: $!"; + + my $s = IO::Socket::IP->new( + Proto => "tcp", + PeerAddr => $sl->sockhost(), + PeerPort => $sl->sockport(), + ) or die "socket failed: $!"; + + $s->setsockopt(SOL_SOCKET, SO_SPLICE, pack('i', -1)) + and die "unsplice non spliced socket succeeded"; + }, +); diff --git a/share/man/man9/sosplice.9 b/share/man/man9/sosplice.9 index 319ca52be..b51df25ca 100644 --- a/share/man/man9/sosplice.9 +++ b/share/man/man9/sosplice.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sosplice.9,v 1.10 2019/07/04 17:42:17 bluhm Exp $ +.\" $OpenBSD: sosplice.9,v 1.11 2025/01/09 17:42:38 mvs Exp $ .\" .\" Copyright (c) 2011-2013 Alexander Bluhm .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: July 4 2019 $ +.Dd $Mdocdate: January 9 2025 $ .Dt SOSPLICE 9 .Os .Sh NAME @@ -238,6 +238,8 @@ nor in the process of connecting to a peer. .It Bq Er ENOTCONN The drain socket is neither connected nor in the process of connecting to a peer. +.It Bq Er EPROTO +The source socket is not spliced with the drain socket. .It Bq Er ENOTSOCK The given file descriptor .Fa fd diff --git a/share/misc/airport b/share/misc/airport index e90f5c58f..e93a990ad 100644 --- a/share/misc/airport +++ b/share/misc/airport @@ -1,4 +1,4 @@ -# $OpenBSD: airport,v 1.99 2024/11/07 08:43:18 sthen Exp $ +# $OpenBSD: airport,v 1.100 2025/01/08 22:26:22 kn Exp $ # @(#)airport 8.1 (Berkeley) 6/8/93 # # Some of this information from the Airport Search Engine at @@ -1346,6 +1346,7 @@ PKB:Wood County, Parkersburg / Marietta, West Virginia, USA PKE:Parkes, New South Wales, Australia PKR:Pokhara, Nepal PKU:Simpang Tiga, Pekanbaru, Indonesia +PKV:Pskov, Russia PLB:Plattsburgh, New York, USA PLH:Plymouth, England, United Kingdom PLM:Sultan Mahmud Badaruddin Ii, Palembang, Indonesia diff --git a/sys/dev/dt/dt_prov_static.c b/sys/dev/dt/dt_prov_static.c index 4a87bc916..b4bdbf64c 100644 --- a/sys/dev/dt/dt_prov_static.c +++ b/sys/dev/dt/dt_prov_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_prov_static.c,v 1.23 2024/04/06 11:18:02 mpi Exp $ */ +/* $OpenBSD: dt_prov_static.c,v 1.24 2025/01/09 17:43:33 mvs Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -100,6 +100,7 @@ DT_STATIC_PROBE3(refcnt, ifaddr, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, ifmaddr, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, inpcb, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, rtentry, "void *", "int", "int"); +DT_STATIC_PROBE3(refcnt, socket, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, syncache, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, tdb, "void *", "int", "int"); @@ -153,6 +154,7 @@ struct dt_probe *const dtps_static[] = { &_DT_STATIC_P(refcnt, ifmaddr), &_DT_STATIC_P(refcnt, inpcb), &_DT_STATIC_P(refcnt, rtentry), + &_DT_STATIC_P(refcnt, socket), &_DT_STATIC_P(refcnt, syncache), &_DT_STATIC_P(refcnt, tdb), }; diff --git a/sys/dev/fdt/gpiokeys.c b/sys/dev/fdt/gpiokeys.c index 041c75e17..d06628f8e 100644 --- a/sys/dev/fdt/gpiokeys.c +++ b/sys/dev/fdt/gpiokeys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpiokeys.c,v 1.3 2023/03/31 12:07:54 kn Exp $ */ +/* $OpenBSD: gpiokeys.c,v 1.5 2025/01/09 22:03:38 kettenis Exp $ */ /* * Copyright (c) 2021 Klemens Nanni * @@ -54,12 +54,13 @@ struct gpiokeys_key { uint32_t key_input_type; uint32_t key_code; struct ksensor key_sensor; - SLIST_ENTRY(gpiokeys_key) entries; + SLIST_ENTRY(gpiokeys_key) key_next; + void (*key_func)(void *); + void *key_ih; }; struct gpiokeys_softc { struct device sc_dev; - int sc_node; struct ksensordev sc_sensordev; SLIST_HEAD(, gpiokeys_key) sc_keys; }; @@ -76,6 +77,7 @@ struct cfdriver gpiokeys_cd = { }; void gpiokeys_update_key(void *); +int gpiokeys_intr(void *); int gpiokeys_match(struct device *parent, void *match, void *aux) @@ -131,8 +133,9 @@ gpiokeys_attach(struct device *parent, struct device *self, void *aux) strlcpy(key->key_sensor.desc, "lid open", sizeof(key->key_sensor.desc)); key->key_sensor.type = SENSOR_INDICATOR; - sensor_attach(&sc->sc_sensordev, &key->key_sensor); - sensor_task_register(key, gpiokeys_update_key, 1); + sensor_attach(&sc->sc_sensordev, + &key->key_sensor); + key->key_func = gpiokeys_update_key; have_sensors = 1; break; } @@ -145,7 +148,21 @@ gpiokeys_attach(struct device *parent, struct device *self, void *aux) have_labels = 1; } - SLIST_INSERT_HEAD(&sc->sc_keys, key, entries); + SLIST_INSERT_HEAD(&sc->sc_keys, key, key_next); + } + + SLIST_FOREACH(key, &sc->sc_keys, key_next) { + if (!key->key_func) + continue; + + if (OF_is_compatible(faa->fa_node, "gpio-keys")) { + key->key_ih = gpio_controller_intr_establish(key->key_pin, + IPL_BIO, NULL, gpiokeys_intr, key, DEVNAME(sc)); + } + if (key->key_ih == NULL) + sensor_task_register(key, gpiokeys_update_key, 1); + else + gpiokeys_update_key(key); } if (have_sensors) { @@ -181,3 +198,12 @@ gpiokeys_update_key(void *arg) break; } } + +int +gpiokeys_intr(void *arg) +{ + struct gpiokeys_key *key = arg; + + key->key_func(key); + return 1; +} diff --git a/sys/dev/fdt/qcgpio_fdt.c b/sys/dev/fdt/qcgpio_fdt.c index e4a5443e9..6901cb89b 100644 --- a/sys/dev/fdt/qcgpio_fdt.c +++ b/sys/dev/fdt/qcgpio_fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: qcgpio_fdt.c,v 1.4 2024/07/02 19:43:52 patrick Exp $ */ +/* $OpenBSD: qcgpio_fdt.c,v 1.5 2025/01/09 21:52:25 kettenis Exp $ */ /* * Copyright (c) 2022 Mark Kettenis * @@ -86,6 +86,8 @@ const struct cfattach qcgpio_fdt_ca = { void qcgpio_fdt_config_pin(void *, uint32_t *, int); int qcgpio_fdt_get_pin(void *, uint32_t *); void qcgpio_fdt_set_pin(void *, uint32_t *, int); +void *qcgpio_fdt_intr_establish_pin(void *, uint32_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); void *qcgpio_fdt_intr_establish(void *, int *, int, struct cpu_info *, int (*)(void *), void *, char *); @@ -136,6 +138,7 @@ qcgpio_fdt_attach(struct device *parent, struct device *self, void *aux) sc->sc_gc.gc_config_pin = qcgpio_fdt_config_pin; sc->sc_gc.gc_get_pin = qcgpio_fdt_get_pin; sc->sc_gc.gc_set_pin = qcgpio_fdt_set_pin; + sc->sc_gc.gc_intr_establish = qcgpio_fdt_intr_establish_pin; gpio_controller_register(&sc->sc_gc); sc->sc_ic.ic_node = faa->fa_node; @@ -213,6 +216,19 @@ qcgpio_fdt_set_pin(void *cookie, uint32_t *cells, int val) } } +void * +qcgpio_fdt_intr_establish_pin(void *cookie, uint32_t *cells, int ipl, + struct cpu_info *ci, int (*func)(void *), void *arg, char *name) +{ + struct qcgpio_softc *sc = cookie; + uint32_t icells[2]; + + icells[0] = cells[0]; + icells[1] = 3; /* both edges */ + + return qcgpio_fdt_intr_establish(sc, icells, ipl, ci, func, arg, name); +} + void * qcgpio_fdt_intr_establish(void *cookie, int *cells, int ipl, struct cpu_info *ci, int (*func)(void *), void *arg, char *name) diff --git a/sys/dev/ofw/ofw_gpio.c b/sys/dev/ofw/ofw_gpio.c index f8f818e8f..929a87aea 100644 --- a/sys/dev/ofw/ofw_gpio.c +++ b/sys/dev/ofw/ofw_gpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_gpio.c,v 1.3 2019/08/26 09:22:27 kettenis Exp $ */ +/* $OpenBSD: ofw_gpio.c,v 1.4 2025/01/09 19:38:13 kettenis Exp $ */ /* * Copyright (c) 2016, 2019 Mark Kettenis * @@ -19,6 +19,8 @@ #include #include +#include + #include #include @@ -141,3 +143,29 @@ gpio_controller_next_pin(uint32_t *cells) return NULL; } + +void * +gpio_controller_intr_establish(uint32_t *cells, int ipl, struct cpu_info *ci, + int (*func)(void *), void *arg, char *name) +{ + struct gpio_controller *gc; + uint32_t phandle = cells[0]; + + LIST_FOREACH(gc, &gpio_controllers, gc_list) { + if (gc->gc_phandle == phandle) + break; + } + + if (gc && gc->gc_intr_establish) { + return gc->gc_intr_establish(gc->gc_cookie, &cells[1], ipl, + ci, func, arg, name); + } + + return NULL; +} + +void +gpio_controller_intr_disestablish(void *ih) +{ + fdt_intr_disestablish(ih); +} diff --git a/sys/dev/ofw/ofw_gpio.h b/sys/dev/ofw/ofw_gpio.h index 95bcea953..027dfc484 100644 --- a/sys/dev/ofw/ofw_gpio.h +++ b/sys/dev/ofw/ofw_gpio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_gpio.h,v 1.5 2020/12/18 22:14:13 kettenis Exp $ */ +/* $OpenBSD: ofw_gpio.h,v 1.6 2025/01/09 19:38:13 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -34,6 +34,8 @@ struct gpio_controller { void (*gc_config_pin)(void *, uint32_t *, int); int (*gc_get_pin)(void *, uint32_t *); void (*gc_set_pin)(void *, uint32_t *, int); + void *(*gc_intr_establish)(void *, uint32_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); LIST_ENTRY(gpio_controller) gc_list; uint32_t gc_phandle; @@ -56,4 +58,8 @@ int gpio_controller_get_pin(uint32_t *); void gpio_controller_set_pin(uint32_t *, int); uint32_t *gpio_controller_next_pin(uint32_t *); +void *gpio_controller_intr_establish(uint32_t *, int, struct cpu_info *, + int (*)(void *), void *, char *); +void gpio_controller_intr_disestablish(void *); + #endif /* _DEV_OFW_GPIO_H_ */ diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c index a21972837..0c0dc44bb 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c @@ -3255,8 +3255,12 @@ static int amdgpu_device_ip_resume_phase3(struct amdgpu_device *adev) continue; if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) { r = adev->ip_blocks[i].version->funcs->resume(adev); - if (r) + if (r) { + DRM_ERROR("resume of IP block <%s> failed %d\n", + adev->ip_blocks[i].version->funcs->name, r); return r; + } + adev->ip_blocks[i].status.hw = true; } } diff --git a/sys/dev/pci/pcidevs b/sys/dev/pci/pcidevs index 5683ccb99..99cf8cc13 100644 --- a/sys/dev/pci/pcidevs +++ b/sys/dev/pci/pcidevs @@ -1,4 +1,4 @@ -$OpenBSD: pcidevs,v 1.2094 2024/11/09 10:23:06 miod Exp $ +$OpenBSD: pcidevs,v 1.2095 2025/01/08 02:12:24 jsg Exp $ /* $NetBSD: pcidevs,v 1.30 1997/06/24 06:20:24 thorpej Exp $ */ /* @@ -6460,9 +6460,13 @@ product INTEL MTL_U_HB_1 0x7d16 Core Ultra Host product INTEL MTL_IPU 0x7d19 Core Ultra IPU product INTEL MTL_NPU 0x7d1d Core Ultra NPU product INTEL MTL_U4_GT_1 0x7d40 Graphics +product INTEL ARL_U_GT_1 0x7d41 Graphics product INTEL MTL_U_GT_1 0x7d45 Graphics +product INTEL ARL_H_GT_1 0x7d51 Graphics product INTEL MTL_H_GT_1 0x7d55 Arc Graphics product INTEL MTL_U_GT_2 0x7d60 Graphics +product INTEL ARL_S_GT_1 0x7d67 Graphics +product INTEL ARL_H_GT_2 0x7dd1 Graphics product INTEL MTL_H_GT_2 0x7dd5 Graphics product INTEL MTL_H_ESPI 0x7e02 Core Ultra eSPI product INTEL MTL_U_ESPI 0x7e03 Core Ultra eSPI @@ -7349,6 +7353,7 @@ product INTEL LNL_XHCI 0xa87d Core Ultra xHCI product INTEL LNL_SRAM 0xa87f Core Ultra SRAM product INTEL 21152 0xb152 S21152BB product INTEL 21154 0xb154 21154AE/BE +product INTEL ARL_S_GT_2 0xb640 Graphics product INTEL CORE_DMI_0 0xd130 Core DMI product INTEL CORE_DMI_1 0xd131 Core DMI product INTEL CORE_DMI_2 0xd132 Core DMI diff --git a/sys/dev/pci/pcidevs.h b/sys/dev/pci/pcidevs.h index f14af3063..8fd8706c0 100644 --- a/sys/dev/pci/pcidevs.h +++ b/sys/dev/pci/pcidevs.h @@ -2,7 +2,7 @@ * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT. * * generated from: - * OpenBSD: pcidevs,v 1.2094 2024/11/09 10:23:06 miod Exp + * OpenBSD: pcidevs,v 1.2095 2025/01/08 02:12:24 jsg Exp */ /* $NetBSD: pcidevs,v 1.30 1997/06/24 06:20:24 thorpej Exp $ */ @@ -6465,9 +6465,13 @@ #define PCI_PRODUCT_INTEL_MTL_IPU 0x7d19 /* Core Ultra IPU */ #define PCI_PRODUCT_INTEL_MTL_NPU 0x7d1d /* Core Ultra NPU */ #define PCI_PRODUCT_INTEL_MTL_U4_GT_1 0x7d40 /* Graphics */ +#define PCI_PRODUCT_INTEL_ARL_U_GT_1 0x7d41 /* Graphics */ #define PCI_PRODUCT_INTEL_MTL_U_GT_1 0x7d45 /* Graphics */ +#define PCI_PRODUCT_INTEL_ARL_H_GT_1 0x7d51 /* Graphics */ #define PCI_PRODUCT_INTEL_MTL_H_GT_1 0x7d55 /* Arc Graphics */ #define PCI_PRODUCT_INTEL_MTL_U_GT_2 0x7d60 /* Graphics */ +#define PCI_PRODUCT_INTEL_ARL_S_GT_1 0x7d67 /* Graphics */ +#define PCI_PRODUCT_INTEL_ARL_H_GT_2 0x7dd1 /* Graphics */ #define PCI_PRODUCT_INTEL_MTL_H_GT_2 0x7dd5 /* Graphics */ #define PCI_PRODUCT_INTEL_MTL_H_ESPI 0x7e02 /* Core Ultra eSPI */ #define PCI_PRODUCT_INTEL_MTL_U_ESPI 0x7e03 /* Core Ultra eSPI */ @@ -7354,6 +7358,7 @@ #define PCI_PRODUCT_INTEL_LNL_SRAM 0xa87f /* Core Ultra SRAM */ #define PCI_PRODUCT_INTEL_21152 0xb152 /* S21152BB */ #define PCI_PRODUCT_INTEL_21154 0xb154 /* 21154AE/BE */ +#define PCI_PRODUCT_INTEL_ARL_S_GT_2 0xb640 /* Graphics */ #define PCI_PRODUCT_INTEL_CORE_DMI_0 0xd130 /* Core DMI */ #define PCI_PRODUCT_INTEL_CORE_DMI_1 0xd131 /* Core DMI */ #define PCI_PRODUCT_INTEL_CORE_DMI_2 0xd132 /* Core DMI */ diff --git a/sys/dev/pci/pcidevs_data.h b/sys/dev/pci/pcidevs_data.h index 546ae7d8a..51027526e 100644 --- a/sys/dev/pci/pcidevs_data.h +++ b/sys/dev/pci/pcidevs_data.h @@ -2,7 +2,7 @@ * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT. * * generated from: - * OpenBSD: pcidevs,v 1.2094 2024/11/09 10:23:06 miod Exp + * OpenBSD: pcidevs,v 1.2095 2025/01/08 02:12:24 jsg Exp */ /* $NetBSD: pcidevs,v 1.30 1997/06/24 06:20:24 thorpej Exp $ */ @@ -23187,10 +23187,18 @@ static const struct pci_known_product pci_known_products[] = { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_MTL_U4_GT_1, "Graphics", }, + { + PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_ARL_U_GT_1, + "Graphics", + }, { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_MTL_U_GT_1, "Graphics", }, + { + PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_ARL_H_GT_1, + "Graphics", + }, { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_MTL_H_GT_1, "Arc Graphics", @@ -23199,6 +23207,14 @@ static const struct pci_known_product pci_known_products[] = { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_MTL_U_GT_2, "Graphics", }, + { + PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_ARL_S_GT_1, + "Graphics", + }, + { + PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_ARL_H_GT_2, + "Graphics", + }, { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_MTL_H_GT_2, "Graphics", @@ -26743,6 +26759,10 @@ static const struct pci_known_product pci_known_products[] = { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_21154, "21154AE/BE", }, + { + PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_ARL_S_GT_2, + "Graphics", + }, { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_CORE_DMI_0, "Core DMI", diff --git a/sys/dev/pv/virtio.c b/sys/dev/pv/virtio.c index 69eb26386..aa63fd5e9 100644 --- a/sys/dev/pv/virtio.c +++ b/sys/dev/pv/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.36 2024/12/20 22:18:27 sf Exp $ */ +/* $OpenBSD: virtio.c,v 1.37 2025/01/09 10:55:22 sf Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -167,6 +167,8 @@ virtio_attach_finish(struct virtio_softc *sc, struct virtio_attach_args *va) for (i = 0; i < sc->sc_nvqs; i++) { struct virtqueue *vq = &sc->sc_vqs[i]; + if (vq->vq_num == 0) + continue; virtio_setup_queue(sc, vq, vq->vq_dmamap->dm_segs[0].ds_addr); } virtio_set_status(sc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); @@ -185,9 +187,9 @@ virtio_reinit_start(struct virtio_softc *sc) for (i = 0; i < sc->sc_nvqs; i++) { int n; struct virtqueue *vq = &sc->sc_vqs[i]; - n = virtio_read_queue_size(sc, vq->vq_index); - if (n == 0) /* vq disappeared */ + if (vq->vq_num == 0) /* not used */ continue; + n = virtio_read_queue_size(sc, vq->vq_index); if (n != vq->vq_num) { panic("%s: virtqueue size changed, vq index %d", sc->sc_dev.dv_xname, vq->vq_index); @@ -274,8 +276,11 @@ virtio_check_vqs(struct virtio_softc *sc) int i, r = 0; /* going backwards is better for if_vio */ - for (i = sc->sc_nvqs - 1; i >= 0; i--) + for (i = sc->sc_nvqs - 1; i >= 0; i--) { + if (sc->sc_vqs[i].vq_num == 0) /* not used */ + continue; r |= virtio_check_vq(sc, &sc->sc_vqs[i]); + } return r; } @@ -305,6 +310,7 @@ virtio_init_vq(struct virtio_softc *sc, struct virtqueue *vq) int i, j; int vq_size = vq->vq_num; + VIRTIO_ASSERT(vq_size > 0); memset(vq->vq_vaddr, 0, vq->vq_bytesize); /* build the indirect descriptor chain */ @@ -468,6 +474,11 @@ virtio_free_vq(struct virtio_softc *sc, struct virtqueue *vq) struct vq_entry *qe; int i = 0; + if (vq->vq_num == 0) { + /* virtio_alloc_vq() was never called */ + return 0; + } + /* device must be already deactivated */ /* confirm the vq is empty */ SLIST_FOREACH(qe, &vq->vq_freelist, qe_list) { @@ -1017,6 +1028,10 @@ virtio_vq_dump(struct virtqueue *vq) #endif /* Common fields */ printf(" + addr: %p\n", vq); + if (vq->vq_num == 0) { + printf(" + vq is unused\n"); + return; + } printf(" + vq num: %d\n", vq->vq_num); printf(" + vq mask: 0x%X\n", vq->vq_mask); printf(" + vq index: %d\n", vq->vq_index); diff --git a/sys/dev/pv/virtiovar.h b/sys/dev/pv/virtiovar.h index 03a18b2dd..c4f35a9f1 100644 --- a/sys/dev/pv/virtiovar.h +++ b/sys/dev/pv/virtiovar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: virtiovar.h,v 1.26 2024/12/20 22:18:27 sf Exp $ */ +/* $OpenBSD: virtiovar.h,v 1.27 2025/01/09 10:55:22 sf Exp $ */ /* $NetBSD: virtiovar.h,v 1.1 2011/10/30 12:12:21 hannken Exp $ */ /* @@ -103,7 +103,8 @@ struct vq_entry { struct virtqueue { struct virtio_softc *vq_owner; - unsigned int vq_num; /* queue size (# of entries) */ + unsigned int vq_num; /* queue size (# of entries), + * 0 if unused/non-existant */ unsigned int vq_mask; /* (1 << vq_num - 1) */ int vq_index; /* queue number (0, 1, ...) */ @@ -180,7 +181,7 @@ struct virtio_softc { int sc_indirect; int sc_version_1; - int sc_nvqs; /* set by child */ + int sc_nvqs; /* size of sc_vqs, set by child */ struct virtqueue *sc_vqs; /* set by child */ struct device *sc_child; /* set by child, diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index c50a15072..c10ebeaaa 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.432 2024/12/24 19:19:18 krw Exp $ */ +/* $OpenBSD: softraid.c,v 1.433 2025/01/08 23:40:40 lucas Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom * Copyright (c) 2008 Chris Kuethe @@ -5148,7 +5148,8 @@ sr_hibernate_io(dev_t dev, daddr_t blkno, vaddr_t addr, size_t size, int op, voi /* Initialize the sub-device */ return my->subfn(my->subdev, sub_raidoff + blkno, addr, size, op, page); - } + } else if (op == HIB_DONE) + return my->subfn(my->subdev, blkno, addr, size, op, page); /* Hibernate only uses (and we only support) writes */ if (op != HIB_W) diff --git a/sys/kern/subr_hibernate.c b/sys/kern/subr_hibernate.c index a05b965a6..1dd446cc1 100644 --- a/sys/kern/subr_hibernate.c +++ b/sys/kern/subr_hibernate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_hibernate.c,v 1.149 2025/01/06 21:37:16 krw Exp $ */ +/* $OpenBSD: subr_hibernate.c,v 1.150 2025/01/09 19:22:39 mglocker Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt @@ -2019,7 +2019,8 @@ hibernate_suspend(void) * Give the device-specific I/O function a notification that we're * done, and that it can clean up or shutdown as needed. */ - hib->io_func(hib->dev, 0, (vaddr_t)NULL, 0, HIB_DONE, hib->io_page); + if (hib->io_func(hib->dev, 0, (vaddr_t)NULL, 0, HIB_DONE, hib->io_page)) + printf("Warning: hibernate done failed\n"); return (0); } diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 8ce0decd8..ad2c34b61 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.357 2025/01/07 23:13:46 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.359 2025/01/09 17:43:33 mvs Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -154,7 +154,7 @@ soalloc(const struct protosw *prp, int wait) } #endif - refcnt_init(&so->so_refcnt); + refcnt_init_trace(&so->so_refcnt, DT_REFCNT_IDX_SOCKET); rw_init_flags(&so->so_lock, dom_name, RWL_DUPOK); rw_init(&so->so_rcv.sb_lock, "sbufrcv"); rw_init(&so->so_snd.sb_lock, "sbufsnd"); @@ -1388,9 +1388,10 @@ sosplice(struct socket *so, int fd, off_t max, struct timeval *tv) sosp = soref(so->so_sp->ssp_socket); sounsplice(so, so->so_sp->ssp_socket, 0); sorele(sosp); - } + } else + error = EPROTO; sbunlock(&so->so_rcv); - return (0); + return (error); } if (sosplice_taskq == NULL) { diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 97235eee3..78e87c273 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.376 2025/01/03 21:27:40 bluhm Exp $ */ +/* $OpenBSD: rtsock.c,v 1.377 2025/01/09 18:20:29 bluhm Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -359,7 +359,7 @@ int route_peeraddr(struct socket *so, struct mbuf *nam) { /* minimal support, just implement a fake peer address */ - bcopy(&route_src, mtod(nam, caddr_t), route_src.sa_len); + memcpy(mtod(nam, caddr_t), &route_src, route_src.sa_len); nam->m_len = route_src.sa_len; return (0); } diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 2894276ee..61525bded 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.309 2025/01/03 12:56:15 mvs Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.310 2025/01/09 16:47:24 bluhm Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -623,7 +623,7 @@ in_pcbdetach(struct inpcb *inp) } struct socket * -in_pcbsolock(struct inpcb *inp) +in_pcbsolock_ref(struct inpcb *inp) { struct socket *so; @@ -634,18 +634,18 @@ in_pcbsolock(struct inpcb *inp) mtx_leave(&inp->inp_sofree_mtx); if (so == NULL) return NULL; - rw_enter_write(&so->so_lock); - sorele(so); - return so; } void -in_pcbsounlock(struct inpcb *inp, struct socket *so) +in_pcbsounlock_rele(struct inpcb *inp, struct socket *so) { - KASSERT(inp->inp_socket == so); + if (so == NULL) + return; + KASSERT(inp->inp_socket == NULL || inp->inp_socket == so); rw_exit_write(&so->so_lock); + sorele(so); } struct inpcb * diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 36011c6c4..56adec0c6 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.163 2025/01/05 12:10:39 bluhm Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.164 2025/01/09 16:47:24 bluhm Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -311,8 +311,8 @@ int in_pcbaddrisavail(const struct inpcb *, struct sockaddr_in *, int, int in_pcbconnect(struct inpcb *, struct mbuf *); void in_pcbdetach(struct inpcb *); struct socket * - in_pcbsolock(struct inpcb *); -void in_pcbsounlock(struct inpcb *, struct socket *); + in_pcbsolock_ref(struct inpcb *); +void in_pcbsounlock_rele(struct inpcb *, struct socket *); struct inpcb * in_pcbref(struct inpcb *); void in_pcbunref(struct inpcb *); diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 0ecd7e0f9..715b5e005 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_input.c,v 1.420 2025/01/05 12:18:48 bluhm Exp $ */ +/* $OpenBSD: tcp_input.c,v 1.421 2025/01/09 16:47:24 bluhm Exp $ */ /* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */ /* @@ -3410,7 +3410,7 @@ syn_cache_timer(void *arg) mtx_leave(&syn_cache_mtx); NET_LOCK_SHARED(); - so = in_pcbsolock(inp); + so = in_pcbsolock_ref(inp); if (so != NULL) { now = tcp_now(); #ifdef TCP_ECN @@ -3418,8 +3418,8 @@ syn_cache_timer(void *arg) #endif (void) syn_cache_respond(sc, NULL, now, do_ecn); tcpstat_inc(tcps_sc_retransmitted); - in_pcbsounlock(inp, so); } + in_pcbsounlock_rele(inp, so); NET_UNLOCK_SHARED(); in_pcbunref(inp); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 9a8a12098..bc40c3524 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.238 2025/01/05 12:23:38 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.239 2025/01/09 16:47:24 bluhm Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -1122,15 +1122,13 @@ tcp_ident(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int dodrop) int error = 0; struct tcp_ident_mapping tir; struct inpcb *inp; - struct tcpcb *tp = NULL; + struct socket *so = NULL; struct sockaddr_in *fin, *lin; #ifdef INET6 struct sockaddr_in6 *fin6, *lin6; struct in6_addr f6, l6; #endif - NET_ASSERT_LOCKED(); - if (dodrop) { if (oldp != NULL || *oldlenp != 0) return (EINVAL); @@ -1150,25 +1148,41 @@ tcp_ident(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int dodrop) if ((error = copyin(oldp, &tir, sizeof (tir))) != 0 ) return (error); } + + NET_LOCK_SHARED(); + switch (tir.faddr.ss_family) { #ifdef INET6 case AF_INET6: + if (tir.laddr.ss_family != AF_INET6) { + NET_UNLOCK_SHARED(); + return (EAFNOSUPPORT); + } fin6 = (struct sockaddr_in6 *)&tir.faddr; error = in6_embedscope(&f6, fin6, NULL, NULL); - if (error) + if (error) { + NET_UNLOCK_SHARED(); return EINVAL; /*?*/ + } lin6 = (struct sockaddr_in6 *)&tir.laddr; error = in6_embedscope(&l6, lin6, NULL, NULL); - if (error) + if (error) { + NET_UNLOCK_SHARED(); return EINVAL; /*?*/ + } break; #endif case AF_INET: + if (tir.laddr.ss_family != AF_INET) { + NET_UNLOCK_SHARED(); + return (EAFNOSUPPORT); + } fin = (struct sockaddr_in *)&tir.faddr; lin = (struct sockaddr_in *)&tir.laddr; break; default: - return (EINVAL); + NET_UNLOCK_SHARED(); + return (EAFNOSUPPORT); } switch (tir.faddr.ss_family) { @@ -1187,11 +1201,20 @@ tcp_ident(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int dodrop) } if (dodrop) { - if (inp && (tp = intotcpcb(inp)) && - ((inp->inp_socket->so_options & SO_ACCEPTCONN) == 0)) + struct tcpcb *tp = NULL; + + if (inp != NULL) { + so = in_pcbsolock_ref(inp); + if (so != NULL) + tp = intotcpcb(inp); + } + if (tp != NULL && !ISSET(so->so_options, SO_ACCEPTCONN)) tp = tcp_drop(tp, ECONNABORTED); else error = ESRCH; + + in_pcbsounlock_rele(inp, so); + NET_UNLOCK_SHARED(); in_pcbunref(inp); return (error); } @@ -1212,18 +1235,23 @@ tcp_ident(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int dodrop) } } - if (inp != NULL && (inp->inp_socket->so_state & SS_CONNECTOUT)) { - tir.ruid = inp->inp_socket->so_ruid; - tir.euid = inp->inp_socket->so_euid; + if (inp != NULL) + so = in_pcbsolock_ref(inp); + + if (so != NULL && ISSET(so->so_state, SS_CONNECTOUT)) { + tir.ruid = so->so_ruid; + tir.euid = so->so_euid; } else { tir.ruid = -1; tir.euid = -1; } - *oldlenp = sizeof (tir); - error = copyout((void *)&tir, oldp, sizeof (tir)); + in_pcbsounlock_rele(inp, so); + NET_UNLOCK_SHARED(); in_pcbunref(inp); - return (error); + + *oldlenp = sizeof(tir); + return copyout(&tir, oldp, sizeof(tir)); } int @@ -1428,16 +1456,10 @@ tcp_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, return (error); case TCPCTL_IDENT: - NET_LOCK(); - error = tcp_ident(oldp, oldlenp, newp, newlen, 0); - NET_UNLOCK(); - return (error); + return tcp_ident(oldp, oldlenp, newp, newlen, 0); case TCPCTL_DROP: - NET_LOCK(); - error = tcp_ident(oldp, oldlenp, newp, newlen, 1); - NET_UNLOCK(); - return (error); + return tcp_ident(oldp, oldlenp, newp, newlen, 1); case TCPCTL_REASS_LIMIT: NET_LOCK(); @@ -1506,9 +1528,8 @@ tcp_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, return (error); default: - error = sysctl_bounded_arr(tcpctl_vars, nitems(tcpctl_vars), + return sysctl_bounded_arr(tcpctl_vars, nitems(tcpctl_vars), name, namelen, oldp, oldlenp, newp, newlen); - return (error); } /* NOTREACHED */ } diff --git a/sys/sys/refcnt.h b/sys/sys/refcnt.h index 38fb995e1..cad1e8d0a 100644 --- a/sys/sys/refcnt.h +++ b/sys/sys/refcnt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: refcnt.h,v 1.12 2023/08/28 14:50:02 bluhm Exp $ */ +/* $OpenBSD: refcnt.h,v 1.13 2025/01/09 17:43:33 mvs Exp $ */ /* * Copyright (c) 2015 David Gwynne @@ -49,8 +49,9 @@ unsigned int refcnt_read(struct refcnt *); #define DT_REFCNT_IDX_IFMADDR 3 #define DT_REFCNT_IDX_INPCB 4 #define DT_REFCNT_IDX_RTENTRY 5 -#define DT_REFCNT_IDX_SYNCACHE 6 -#define DT_REFCNT_IDX_TDB 7 +#define DT_REFCNT_IDX_SOCKET 6 +#define DT_REFCNT_IDX_SYNCACHE 7 +#define DT_REFCNT_IDX_TDB 8 #endif /* _KERNEL */ diff --git a/usr.sbin/bgpd/bgpd.conf.5 b/usr.sbin/bgpd/bgpd.conf.5 index f0199a6c1..830c3f1a6 100644 --- a/usr.sbin/bgpd/bgpd.conf.5 +++ b/usr.sbin/bgpd/bgpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: bgpd.conf.5,v 1.246 2025/01/07 12:11:45 claudio Exp $ +.\" $OpenBSD: bgpd.conf.5,v 1.247 2025/01/09 15:57:31 claudio Exp $ .\" .\" Copyright (c) 2004 Claudio Jeker .\" Copyright (c) 2003, 2004 Henning Brauer @@ -16,7 +16,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 7 2025 $ +.Dd $Mdocdate: January 9 2025 $ .Dt BGPD.CONF 5 .Os .Sh NAME @@ -1103,7 +1103,7 @@ The default is .Ic no . .Pp .It Xo -.Ic announce extended +.Ic announce extended message .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index ce5b3c6fe..c2c59ddd4 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.507 2025/01/07 17:43:31 denis Exp $ */ +/* $OpenBSD: bgpd.h,v 1.508 2025/01/09 12:16:21 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -415,17 +415,19 @@ struct capabilities { } grestart; int8_t mp[AID_MAX]; /* multiprotocol extensions, RFC 4760 */ int8_t add_path[AID_MAX]; /* ADD_PATH, RFC 7911 */ + int8_t ext_nexthop[AID_MAX]; /* Ext Nexthop Encoding, RFC 8950 */ int8_t refresh; /* route refresh, RFC 2918 */ int8_t as4byte; /* 4-byte ASnum, RFC 4893 */ int8_t enhanced_rr; /* enhanced route refresh, RFC 7313 */ int8_t policy; /* Open Policy, RFC 9234, 2 = enforce */ - int8_t ext_msg; /* Extended Msg, RFC8654 */ + int8_t ext_msg; /* Extended Msg, RFC 8654 */ }; enum capa_codes { CAPA_NONE = 0, CAPA_MP = 1, CAPA_REFRESH = 2, + CAPA_EXT_NEXTHOP = 5, CAPA_EXT_MSG = 6, CAPA_ROLE = 9, CAPA_RESTART = 64, diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 98742b5e5..f7ad98fd3 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.474 2024/12/14 21:24:31 denis Exp $ */ +/* $OpenBSD: parse.y,v 1.475 2025/01/09 15:57:31 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -249,7 +249,7 @@ typedef struct { %token FLOWSPEC PROTO FLAGS FRAGMENT TOS LENGTH ICMPTYPE CODE %token LOCALAS REMOTEAS DESCR LOCALADDR MULTIHOP PASSIVE MAXPREFIX RESTART %token ANNOUNCE REFRESH AS4BYTE CONNECTRETRY ENHANCED ADDPATH EXTENDED -%token SEND RECV PLUS POLICY ROLE GRACEFUL NOTIFICATION +%token SEND RECV PLUS POLICY ROLE GRACEFUL NOTIFICATION MESSAGE %token DEMOTE ENFORCE NEIGHBORAS ASOVERRIDE REFLECTOR DEPEND DOWN %token DUMP IN OUT SOCKET RESTRICTED %token LOG TRANSPARENT FILTERED @@ -2030,8 +2030,8 @@ peeropts : REMOTEAS as4number { | ANNOUNCE POLICY yesnoenforce { curpeer->conf.capabilities.policy = $3; } - | ANNOUNCE EXTENDED yesnoenforce { - curpeer->conf.capabilities.ext_msg = $3; + | ANNOUNCE EXTENDED MESSAGE yesnoenforce { + curpeer->conf.capabilities.ext_msg = $4; } | ROLE STRING { if (strcmp($2, "provider") == 0) { @@ -3596,6 +3596,7 @@ lookup(char *s) { "maxlen", MAXLEN }, { "md5sig", MD5SIG }, { "med", MED }, + { "message", MESSAGE }, { "metric", METRIC }, { "min", YMIN }, { "min-version", MINVERSION }, diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c index b3c4c5006..4b1b83154 100644 --- a/usr.sbin/bgpd/printconf.c +++ b/usr.sbin/bgpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.178 2024/12/13 19:21:03 claudio Exp $ */ +/* $OpenBSD: printconf.c,v 1.179 2025/01/09 15:57:31 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -969,9 +969,9 @@ print_announce(struct peer_config *p, const char *c) printf("%s\tannounce as4byte no\n", c); if (p->capabilities.ext_msg == 2) - printf("%s\tannounce extended enforce\n", c); + printf("%s\tannounce extended message enforce\n", c); else if (p->capabilities.ext_msg == 1) - printf("%s\tannounce extended yes\n", c); + printf("%s\tannounce extended message yes\n", c); if (p->capabilities.add_path[AID_MIN] & CAPA_AP_RECV_ENFORCE) printf("%s\tannounce add-path recv enforce\n", c); diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index a7a2378a2..d6754a379 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.647 2025/01/04 16:58:46 denis Exp $ */ +/* $OpenBSD: rde.c,v 1.648 2025/01/09 12:16:21 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1560,6 +1560,12 @@ rde_update_dispatch(struct rde_peer *peer, struct ibuf *buf) pathid = 0; switch (aid) { + case AID_INET: + log_peer_warnx(&peer->conf, + "bad MP withdraw for %s", aid2str(aid)); + rde_update_err(peer, ERR_UPDATE, + ERR_UPD_OPTATTR, &unreachbuf); + goto done; case AID_INET6: if (nlri_get_prefix6(&unreachbuf, &prefix, &prefixlen) == -1) { @@ -1689,7 +1695,7 @@ rde_update_dispatch(struct rde_peer *peer, struct ibuf *buf) goto done; } - if (aid == AID_INET6) { + if (aid == AID_INET6 || aid == AID_INET) { /* inject open policy OTC attribute if needed */ if ((state.aspath.flags & F_ATTR_OTC) == 0) { uint32_t tmp; @@ -1740,6 +1746,20 @@ rde_update_dispatch(struct rde_peer *peer, struct ibuf *buf) pathid = 0; switch (aid) { + case AID_INET: + /* + * rde_get_mp_nexthop already enforces that + * this is only used for RFC 8950. + */ + if (nlri_get_prefix(&reachbuf, + &prefix, &prefixlen) == -1) { + log_peer_warnx(&peer->conf, + "bad IPv4 MP nlri prefix"); + rde_update_err(peer, ERR_UPDATE, + ERR_UPD_OPTATTR, &reachbuf); + goto done; + } + break; case AID_INET6: if (nlri_get_prefix6(&reachbuf, &prefix, &prefixlen) == -1) { @@ -2411,8 +2431,19 @@ rde_get_mp_nexthop(struct ibuf *buf, uint8_t aid, if (ibuf_skip(buf, 1) == -1) return (-1); + if (aid == AID_INET && peer_has_ext_nexthop(peer, AID_INET) && + (nhlen == 16 || nhlen == 32)) + aid = AID_INET6; + if (aid == AID_VPN_IPv4 && peer_has_ext_nexthop(peer, AID_VPN_IPv4) && + (nhlen == 24 || nhlen == 48)) + aid = AID_VPN_IPv6; + memset(&nexthop, 0, sizeof(nexthop)); switch (aid) { + case AID_INET: + log_peer_warnx(&peer->conf, "bad multiprotocol nexthop, " + "IPv4 unexpected"); + return (-1); case AID_INET6: /* * RFC2545 describes that there may be a link-local @@ -2466,7 +2497,7 @@ rde_get_mp_nexthop(struct ibuf *buf, uint8_t aid, nexthop.aid = AID_INET; break; case AID_VPN_IPv6: - if (nhlen != 24) { + if (nhlen != 24 && nhlen != 48) { log_peer_warnx(&peer->conf, "bad %s nexthop, " "bad size %d", aid2str(aid), nhlen); return (-1); diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 3a6a867aa..a3f2b0439 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.311 2025/01/07 17:43:31 denis Exp $ */ +/* $OpenBSD: rde.h,v 1.312 2025/01/09 12:16:21 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker and @@ -355,6 +355,8 @@ int rde_match_peer(struct rde_peer *, struct ctl_neighbor *); /* rde_peer.c */ int peer_has_as4byte(struct rde_peer *); int peer_has_add_path(struct rde_peer *, uint8_t, int); +int peer_has_ext_msg(struct rde_peer *); +int peer_has_ext_nexthop(struct rde_peer *, uint8_t); int peer_accept_no_as_set(struct rde_peer *); void peer_init(struct filter_head *); void peer_shutdown(void); diff --git a/usr.sbin/bgpd/rde_peer.c b/usr.sbin/bgpd/rde_peer.c index 45bf85d51..e53fef721 100644 --- a/usr.sbin/bgpd/rde_peer.c +++ b/usr.sbin/bgpd/rde_peer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_peer.c,v 1.43 2025/01/07 17:43:31 denis Exp $ */ +/* $OpenBSD: rde_peer.c,v 1.44 2025/01/09 12:16:21 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker @@ -42,7 +42,7 @@ struct iq { int peer_has_as4byte(struct rde_peer *peer) { - return (peer->capa.as4byte); + return peer->capa.as4byte; } /* @@ -54,13 +54,27 @@ peer_has_add_path(struct rde_peer *peer, uint8_t aid, int mode) { if (aid >= AID_MAX) return 0; - return (peer->capa.add_path[aid] & mode); + return peer->capa.add_path[aid] & mode; +} + +int +peer_has_ext_msg(struct rde_peer *peer) +{ + return peer->capa.ext_msg; +} + +int +peer_has_ext_nexthop(struct rde_peer *peer, uint8_t aid) +{ + if (aid >= AID_MAX) + return 0; + return peer->capa.ext_nexthop[aid]; } int peer_accept_no_as_set(struct rde_peer *peer) { - return (peer->flags & PEERFLAG_NO_AS_SET); + return peer->flags & PEERFLAG_NO_AS_SET; } void @@ -147,7 +161,7 @@ peer_add(uint32_t id, struct peer_config *p_conf, struct filter_head *rules) if ((peer = peer_get(id))) { memcpy(&peer->conf, p_conf, sizeof(struct peer_config)); - return (peer); + return peer; } peer = calloc(1, sizeof(struct rde_peer)); @@ -188,7 +202,7 @@ peer_add(uint32_t id, struct peer_config *p_conf, struct filter_head *rules) if (RB_INSERT(peer_tree, &peertable, peer) != NULL) fatalx("rde peer table corrupted"); - return (peer); + return peer; } struct filter_head * diff --git a/usr.sbin/bgpd/rde_update.c b/usr.sbin/bgpd/rde_update.c index 72a630d87..e76a261d7 100644 --- a/usr.sbin/bgpd/rde_update.c +++ b/usr.sbin/bgpd/rde_update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_update.c,v 1.172 2025/01/07 12:11:45 claudio Exp $ */ +/* $OpenBSD: rde_update.c,v 1.173 2025/01/09 12:16:21 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker @@ -877,7 +877,7 @@ up_generate_mp_reach(struct ibuf *buf, struct rde_peer *peer, struct nexthop *nh, uint8_t aid) { struct bgpd_addr *nexthop; - size_t off; + size_t off, nhoff; uint16_t len, afi; uint8_t safi; @@ -898,59 +898,59 @@ up_generate_mp_reach(struct ibuf *buf, struct rde_peer *peer, return -1; if (ibuf_add_n8(buf, safi) == -1) return -1; + nhoff = ibuf_size(buf); + if (ibuf_add_zero(buf, 1) == -1) + return -1; + + if (aid == AID_VPN_IPv4 || aid == AID_VPN_IPv6) { + /* write zero rd */ + if (ibuf_add_zero(buf, sizeof(uint64_t)) == -1) + return -1; + } switch (aid) { - case AID_INET6: - if (nh == NULL) - return -1; - /* NH LEN */ - if (ibuf_add_n8(buf, sizeof(struct in6_addr)) == -1) - return -1; - /* write nexthop */ - nexthop = &nh->exit_nexthop; - if (ibuf_add(buf, &nexthop->v6, sizeof(struct in6_addr)) == -1) - return -1; - break; + case AID_INET: case AID_VPN_IPv4: if (nh == NULL) return -1; - /* NH LEN */ - if (ibuf_add_n8(buf, - sizeof(uint64_t) + sizeof(struct in_addr)) == -1) - return -1; - /* write zero rd */ - if (ibuf_add_zero(buf, sizeof(uint64_t)) == -1) - return -1; - /* write nexthop */ nexthop = &nh->exit_nexthop; - if (ibuf_add(buf, &nexthop->v4, sizeof(struct in_addr)) == -1) + /* AID_INET must only use this path with an IPv6 nexthop */ + if (nexthop->aid == AID_INET && aid != AID_INET) { + if (ibuf_add(buf, &nexthop->v4, + sizeof(nexthop->v4)) == -1) + return -1; + break; + } else if (nexthop->aid == AID_INET6 && + peer_has_ext_nexthop(peer, aid)) { + if (ibuf_add(buf, &nexthop->v6, + sizeof(nexthop->v6)) == -1) + return -1; + } else { + /* can't encode nexthop, give up and withdraw prefix */ return -1; + } break; + case AID_INET6: case AID_VPN_IPv6: if (nh == NULL) return -1; - /* NH LEN */ - if (ibuf_add_n8(buf, - sizeof(uint64_t) + sizeof(struct in6_addr)) == -1) - return -1; - /* write zero rd */ - if (ibuf_add_zero(buf, sizeof(uint64_t)) == -1) - return -1; - /* write nexthop */ nexthop = &nh->exit_nexthop; - if (ibuf_add(buf, &nexthop->v6, sizeof(struct in6_addr)) == -1) + if (ibuf_add(buf, &nexthop->v6, sizeof(nexthop->v6)) == -1) return -1; break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: - if (ibuf_add_zero(buf, 1) == -1) /* NH LEN MUST be 0 */ - return -1; /* no NH */ break; default: fatalx("up_generate_mp_reach: unknown AID"); } + /* update nexthop len */ + len = ibuf_size(buf) - nhoff - 1; + if (ibuf_set_n8(buf, nhoff, len) == -1) + return -1; + if (ibuf_add_zero(buf, 1) == -1) /* Reserved must be 0 */ return -1; @@ -999,7 +999,7 @@ up_dump_withdraws(struct rde_peer *peer, uint8_t aid) uint16_t afi, len; uint8_t safi; - if (peer->capa.ext_msg) + if (peer_has_ext_msg(peer)) pkgsize = MAX_EXT_PKTSIZE; if ((buf = ibuf_dynamic(4, pkgsize - MSGSIZE_HEADER)) == NULL) @@ -1148,14 +1148,21 @@ up_dump_update(struct rde_peer *peer, uint8_t aid) struct prefix *p; size_t off, pkgsize = MAX_PKTSIZE; uint16_t len; + int force_ip4mp = 0; p = RB_MIN(prefix_tree, &peer->updates[aid]); if (p == NULL) return NULL; - if (peer->capa.ext_msg) + if (peer_has_ext_msg(peer)) pkgsize = MAX_EXT_PKTSIZE; + if (aid == AID_INET && peer_has_ext_nexthop(peer, AID_INET)) { + struct nexthop *nh = prefix_nexthop(p); + if (nh != NULL && nh->exit_nexthop.aid == AID_INET6) + force_ip4mp = 1; + } + if ((buf = ibuf_dynamic(4, pkgsize - MSGSIZE_HEADER)) == NULL) goto fail; @@ -1172,7 +1179,7 @@ up_dump_update(struct rde_peer *peer, uint8_t aid) prefix_communities(p), prefix_nexthop(p), aid) == -1) goto drop; - if (aid != AID_INET) { + if (aid != AID_INET || force_ip4mp) { /* write mp attribute including nlri */ /* @@ -1191,7 +1198,7 @@ up_dump_update(struct rde_peer *peer, uint8_t aid) if (ibuf_set_n16(buf, off, len) == -1) goto fail; - if (aid == AID_INET) { + if (aid == AID_INET && !force_ip4mp) { /* last but not least dump the IPv4 nlri */ if (up_dump_prefix(buf, &peer->updates[aid], peer, 0) == -1) goto drop; diff --git a/usr.sbin/bgpd/rtr_proto.c b/usr.sbin/bgpd/rtr_proto.c index 431a1e031..2fba7ea99 100644 --- a/usr.sbin/bgpd/rtr_proto.c +++ b/usr.sbin/bgpd/rtr_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtr_proto.c,v 1.47 2024/11/26 13:59:54 claudio Exp $ */ +/* $OpenBSD: rtr_proto.c,v 1.48 2025/01/09 12:07:49 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker @@ -42,7 +42,7 @@ struct rtr_header { uint32_t length; } __packed; -#define RTR_MAX_PDU_SIZE 49152 /* XXX < IBUF_READ_SIZE */ +#define RTR_MAX_PDU_SIZE 65535 #define RTR_MAX_PDU_ERROR_SIZE 256 #define RTR_DEFAULT_REFRESH 3600 #define RTR_DEFAULT_RETRY 600 diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index 62c8557d5..a3d7cb9ba 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.90 2025/01/07 19:24:53 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.91 2025/01/09 12:16:21 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker @@ -323,6 +323,8 @@ log_capability(uint8_t capa) return "Multiprotocol Extensions"; case CAPA_REFRESH: return "Route Refresh"; + case CAPA_EXT_NEXTHOP: + return "Extended Nexhop Encoding"; case CAPA_EXT_MSG: return "Extended Message"; case CAPA_ROLE: diff --git a/usr.sbin/vmd/virtio.c b/usr.sbin/vmd/virtio.c index 37185b7f9..a8d6b8b75 100644 --- a/usr.sbin/vmd/virtio.c +++ b/usr.sbin/vmd/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.122 2024/11/21 13:39:34 claudio Exp $ */ +/* $OpenBSD: virtio.c,v 1.123 2025/01/08 15:46:10 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -68,6 +68,7 @@ static int virtio_dev_launch(struct vmd_vm *, struct virtio_dev *); static void virtio_dispatch_dev(int, short, void *); static int handle_dev_msg(struct viodev_msg *, struct virtio_dev *); static int virtio_dev_closefds(struct virtio_dev *); +static void vmmci_pipe_dispatch(int, short, void *); const char * virtio_reg_name(uint8_t reg) @@ -275,17 +276,29 @@ virtio_rnd_io(int dir, uint16_t reg, uint32_t *data, uint8_t *intr, return (0); } +/* + * vmmci_ctl + * + * Inject a command into the vmmci device, potentially delivering interrupt. + * + * Called by the vm process's event(3) loop. + */ int vmmci_ctl(unsigned int cmd) { + int ret = 0; struct timeval tv = { 0, 0 }; + mutex_lock(&vmmci.mutex); + if ((vmmci.cfg.device_status & - VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK) == 0) - return (-1); + VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK) == 0) { + ret = -1; + goto unlock; + } if (cmd == vmmci.cmd) - return (0); + goto unlock; switch (cmd) { case VMMCI_NONE: @@ -307,7 +320,7 @@ vmmci_ctl(unsigned int cmd) vcpu_assert_irq(vmmci.vm_id, 0, vmmci.irq); /* Add ACK timeout */ - tv.tv_sec = VMMCI_TIMEOUT; + tv.tv_sec = VMMCI_TIMEOUT_SHORT; evtimer_add(&vmmci.timeout, &tv); break; case VMMCI_SYNCRTC: @@ -326,14 +339,22 @@ vmmci_ctl(unsigned int cmd) fatalx("invalid vmmci command: %d", cmd); } - return (0); +unlock: + mutex_unlock(&vmmci.mutex); + + return (ret); } +/* + * vmmci_ack + * + * Process a write to the command register. + * + * Called by the vcpu thread. Must be called with the mutex held. + */ void vmmci_ack(unsigned int cmd) { - struct timeval tv = { 0, 0 }; - switch (cmd) { case VMMCI_NONE: break; @@ -347,8 +368,7 @@ vmmci_ack(unsigned int cmd) if (vmmci.cmd == 0) { log_debug("%s: vm %u requested shutdown", __func__, vmmci.vm_id); - tv.tv_sec = VMMCI_TIMEOUT; - evtimer_add(&vmmci.timeout, &tv); + vm_pipe_send(&vmmci.dev_pipe, VMMCI_SET_TIMEOUT_SHORT); return; } /* FALLTHROUGH */ @@ -360,12 +380,10 @@ vmmci_ack(unsigned int cmd) * rc.shutdown on the VM), so increase the timeout before * killing it forcefully. */ - if (cmd == vmmci.cmd && - evtimer_pending(&vmmci.timeout, NULL)) { + if (cmd == vmmci.cmd) { log_debug("%s: vm %u acknowledged shutdown request", __func__, vmmci.vm_id); - tv.tv_sec = VMMCI_SHUTDOWN_TIMEOUT; - evtimer_add(&vmmci.timeout, &tv); + vm_pipe_send(&vmmci.dev_pipe, VMMCI_SET_TIMEOUT_LONG); } break; case VMMCI_SYNCRTC: @@ -392,6 +410,7 @@ vmmci_io(int dir, uint16_t reg, uint32_t *data, uint8_t *intr, { *intr = 0xFF; + mutex_lock(&vmmci.mutex); if (dir == 0) { switch (reg) { case VIRTIO_CONFIG_DEVICE_FEATURES: @@ -466,6 +485,8 @@ vmmci_io(int dir, uint16_t reg, uint32_t *data, uint8_t *intr, break; } } + mutex_unlock(&vmmci.mutex); + return (0); } @@ -482,6 +503,27 @@ virtio_get_base(int fd, char *path, size_t npath, int type, const char *dpath) return -1; } +static void +vmmci_pipe_dispatch(int fd, short event, void *arg) +{ + enum pipe_msg_type msg; + struct timeval tv = { 0, 0 }; + + msg = vm_pipe_recv(&vmmci.dev_pipe); + switch (msg) { + case VMMCI_SET_TIMEOUT_SHORT: + tv.tv_sec = VMMCI_TIMEOUT_SHORT; + evtimer_add(&vmmci.timeout, &tv); + break; + case VMMCI_SET_TIMEOUT_LONG: + tv.tv_sec = VMMCI_TIMEOUT_LONG; + evtimer_add(&vmmci.timeout, &tv); + break; + default: + log_warnx("%s: invalid pipe message type %d", __func__, msg); + } +} + void virtio_init(struct vmd_vm *vm, int child_cdrom, int child_disks[][VM_MAX_BASE_PER_DISK], int *child_taps) @@ -491,6 +533,7 @@ virtio_init(struct vmd_vm *vm, int child_cdrom, struct virtio_dev *dev; uint8_t id; uint8_t i, j; + int ret = 0; /* Virtio entropy device */ if (pci_add_device(&id, PCI_VENDOR_QUMRANET, @@ -745,8 +788,15 @@ virtio_init(struct vmd_vm *vm, int child_cdrom, vmmci.vm_id = vcp->vcp_id; vmmci.irq = pci_get_dev_irq(id); vmmci.pci_id = id; + ret = pthread_mutex_init(&vmmci.mutex, NULL); + if (ret) { + errno = ret; + fatal("could not initialize vmmci mutex"); + } evtimer_set(&vmmci.timeout, vmmci_timeout, NULL); + vm_pipe_init(&vmmci.dev_pipe, vmmci_pipe_dispatch); + event_add(&vmmci.dev_pipe.read_ev, NULL); } /* diff --git a/usr.sbin/vmd/virtio.h b/usr.sbin/vmd/virtio.h index c29374305..87d5f8b20 100644 --- a/usr.sbin/vmd/virtio.h +++ b/usr.sbin/vmd/virtio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.h,v 1.52 2024/07/10 09:27:33 dv Exp $ */ +/* $OpenBSD: virtio.h,v 1.53 2025/01/08 15:46:10 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -53,8 +53,8 @@ #define VIONET_MAX_TXLEN VIONET_HARD_MTU + ETHER_HDR_LEN /* VMM Control Interface shutdown timeout (in seconds) */ -#define VMMCI_TIMEOUT 3 -#define VMMCI_SHUTDOWN_TIMEOUT 120 +#define VMMCI_TIMEOUT_SHORT 3 +#define VMMCI_TIMEOUT_LONG 120 /* All the devices we support have either 1, 2 or 3 queues */ /* viornd - 1 queue @@ -321,8 +321,10 @@ struct vmmci_dev { enum vmmci_cmd cmd; uint32_t vm_id; int irq; - uint8_t pci_id; + + pthread_mutex_t mutex; + struct vm_dev_pipe dev_pipe; }; /* XXX to be removed once vioscsi is adapted to vectorized io. */ diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h index b84656fc2..ef98fa5a2 100644 --- a/usr.sbin/vmd/vmd.h +++ b/usr.sbin/vmd/vmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.h,v 1.131 2024/11/06 23:04:45 bluhm Exp $ */ +/* $OpenBSD: vmd.h,v 1.132 2025/01/08 15:46:10 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -424,6 +424,8 @@ enum pipe_msg_type { VIRTIO_THREAD_PAUSE, VIRTIO_THREAD_STOP, VIRTIO_THREAD_ACK, + VMMCI_SET_TIMEOUT_SHORT, + VMMCI_SET_TIMEOUT_LONG, }; static inline struct sockaddr_in *