From 550dd574396201ef79ba6c2f935576b2ddf998bf Mon Sep 17 00:00:00 2001 From: purplerain Date: Fri, 9 Feb 2024 22:30:40 +0000 Subject: [PATCH] sync with OpenBSD -current --- lib/libcrypto/sm2/sm2_crypt.c | 3 +- lib/libradius/radius_eapmsk.c | 39 +- lib/libz/gzguts.h | 10 +- lib/libz/gzlib.c | 17 +- regress/lib/libcrypto/bio/bio_dump.c | 60 +- regress/usr.bin/ssh/putty-ciphers.sh | 51 +- regress/usr.bin/ssh/putty-kex.sh | 44 +- regress/usr.bin/ssh/putty-transfer.sh | 13 +- regress/usr.bin/ssh/test-exec.sh | 24 +- sys/dev/dt/dt_dev.c | 24 +- sys/dev/dt/dt_prov_profile.c | 66 +- sys/dev/dt/dtvar.h | 10 +- sys/dev/ic/qwx.c | 1012 ++++++++++++++++++++++++- sys/dev/ic/qwxvar.h | 108 ++- sys/dev/pci/if_qwx_pci.c | 5 +- sys/dev/pci/if_vmx.c | 13 +- sys/kern/kern_clock.c | 13 +- sys/kern/kern_clockintr.c | 53 +- sys/net/route.c | 14 +- sys/netinet/in.h | 4 +- sys/netinet/in_pcb.c | 25 +- sys/netinet6/in6.h | 4 +- sys/netinet6/in6_pcb.c | 5 +- sys/netinet6/in6_src.c | 8 +- sys/sys/clockintr.h | 9 +- usr.bin/bgplg/bgplg.c | 16 +- usr.bin/bgplg/bgplg.foot | 2 +- usr.bin/bgplg/bgplg.head | 2 +- usr.bin/bgplg/index.html | 7 +- usr.sbin/radiusd/radiusd.c | 272 ++++--- usr.sbin/radiusd/radiusd_bsdauth.c | 4 +- usr.sbin/radiusd/radiusd_module.c | 6 +- usr.sbin/radiusd/radiusd_module.h | 2 +- usr.sbin/radiusd/radiusd_radius.c | 4 +- usr.sbin/radiusd/radiusd_standard.c | 4 +- usr.sbin/rpki-client/version.h | 4 +- usr.sbin/vmd/i8253.c | 6 +- usr.sbin/vmd/vionet.c | 12 +- usr.sbin/vmd/virtio.c | 26 +- 39 files changed, 1599 insertions(+), 402 deletions(-) diff --git a/lib/libcrypto/sm2/sm2_crypt.c b/lib/libcrypto/sm2/sm2_crypt.c index b51161d64..63fe1e6ab 100644 --- a/lib/libcrypto/sm2/sm2_crypt.c +++ b/lib/libcrypto/sm2/sm2_crypt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sm2_crypt.c,v 1.2 2022/11/26 16:08:54 tb Exp $ */ +/* $OpenBSD: sm2_crypt.c,v 1.3 2024/02/09 07:43:52 tb Exp $ */ /* * Copyright (c) 2017, 2019 Ribose Inc * @@ -203,7 +203,6 @@ sm2_kdf(uint8_t *key, size_t key_len, uint8_t *secret, size_t secret_len, goto err; } - EVP_MD_CTX_init(hash); while ((key_len > 0) && (ctr != 0)) { if (!EVP_DigestInit_ex(hash, digest, NULL)) { SM2error(ERR_R_EVP_LIB); diff --git a/lib/libradius/radius_eapmsk.c b/lib/libradius/radius_eapmsk.c index a06831a39..3237301b4 100644 --- a/lib/libradius/radius_eapmsk.c +++ b/lib/libradius/radius_eapmsk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radius_eapmsk.c,v 1.2 2023/07/08 08:53:26 yasuoka Exp $ */ +/* $OpenBSD: radius_eapmsk.c,v 1.3 2024/02/09 11:59:23 yasuoka Exp $ */ /*- * Copyright (c) 2013 Internet Initiative Japan Inc. @@ -34,35 +34,32 @@ #include "radius_local.h" int -radius_get_eap_msk(const RADIUS_PACKET * packet, void *buf, size_t * len, +radius_get_eap_msk(const RADIUS_PACKET * packet, void *buf, size_t *len, const char *secret) { - /* - * Unfortunately, the way to pass EAP MSK/EMSK over RADIUS - * is not standardized. - */ uint8_t buf0[256]; uint8_t buf1[256]; - size_t len0, len1; + size_t len0, len1, msklen; - /* - * EAP MSK via MPPE keys - * - * MSK = MPPE-Recv-Key + MPPE-Send-Key + 32byte zeros - * http://msdn.microsoft.com/en-us/library/cc224635.aspx - */ + /* RFC 3748 defines the MSK minimum size is 64 bytes */ + if (*len < 64) + return (-1); len0 = sizeof(buf0); len1 = sizeof(buf1); if (radius_get_mppe_recv_key_attr(packet, buf0, &len0, secret) == 0 && radius_get_mppe_send_key_attr(packet, buf1, &len1, secret) == 0) { - if (len0 < 16 || len1 < 16) - return (-1); - if (*len < 64) - return (-1); - memcpy(buf, buf0, 16); - memcpy(((char *)buf) + 16, buf1, 16); - memset(((char *)buf) + 32, 0, 32); - *len = 64; + /* addition cannot overflow since len{0,1} are limited to 256 */ + msklen = len0 + len1; + if (msklen > *len) + return (-1); /* not enougth */ + memcpy(buf, buf0, len0); + memcpy(((char *)buf) + len0, buf1, len1); + /* zero padding to the minimum size, 64 bytes. */ + if (msklen < 64) { + memset(((char *)buf) + msklen, 0, 64 - msklen); + msklen = 64; + } + *len = msklen; return (0); } diff --git a/lib/libz/gzguts.h b/lib/libz/gzguts.h index 074ec84ec..bd0a6fe21 100644 --- a/lib/libz/gzguts.h +++ b/lib/libz/gzguts.h @@ -17,6 +17,10 @@ # define ZLIB_INTERNAL #endif +#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS) +# define _CRT_SECURE_NO_WARNINGS +#endif + #include #include "zlib.h" #ifdef STDC @@ -36,13 +40,15 @@ #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) # include +# include +# include #endif -#if defined(_WIN32) +#if defined(_WIN32) && !defined(WIDECHAR) # define WIDECHAR #endif -#ifdef WINAPI_FAMILY +#if defined(_WIN32) || defined(WINAPI_FAMILY) # define open _open # define read _read # define write _write diff --git a/lib/libz/gzlib.c b/lib/libz/gzlib.c index 983153cc8..05a9ae519 100644 --- a/lib/libz/gzlib.c +++ b/lib/libz/gzlib.c @@ -52,7 +52,8 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) { msgbuf[chars] = 0; } - wcstombs(buf, msgbuf, chars + 1); + z_size_t len; + wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1); LocalFree(msgbuf); } else { @@ -180,8 +181,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { /* save the path name for error messages */ #ifdef WIDECHAR if (fd == -2) { - len = wcstombs(NULL, path, 0); - if (len == (z_size_t)-1) + if (wcstombs_s(&len, NULL, 0, path, 0) != 0) len = 0; } else @@ -195,7 +195,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { #ifdef WIDECHAR if (fd == -2) if (len) - wcstombs(state->path, path, len + 1); + wcstombs_s(&len, state->path, len + 1, path, len + 1); else *(state->path) = 0; else @@ -228,11 +228,14 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { O_APPEND))); /* open the file with the appropriate flags (or just use fd) */ - state->fd = fd > -1 ? fd : ( + if (fd == -1) + state->fd = open((const char *)path, oflag, 0666); #ifdef WIDECHAR - fd == -2 ? _wopen(path, oflag, 0666) : + else if (fd == -2) + _wsopen_s(&state->fd, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE); #endif - open((const char *)path, oflag, 0666)); + else + state->fd = fd; if (state->fd == -1) { free(state->path); free(state); diff --git a/regress/lib/libcrypto/bio/bio_dump.c b/regress/lib/libcrypto/bio/bio_dump.c index 069f677fe..22db80fa3 100644 --- a/regress/lib/libcrypto/bio/bio_dump.c +++ b/regress/lib/libcrypto/bio/bio_dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bio_dump.c,v 1.3 2024/02/02 06:47:21 tb Exp $ */ +/* $OpenBSD: bio_dump.c,v 1.4 2024/02/09 12:48:32 tb Exp $ */ /* * Copyright (c) 2024 Theo Buehler * @@ -55,6 +55,42 @@ const uint8_t dump[] = { }; #define DUMP_LEN (sizeof(dump) / sizeof(dump[0])) +const uint8_t bytes[] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, +}; +#define BYTES_LEN (sizeof(bytes) / sizeof(bytes[0])) + static const struct bio_dump_testcase { int indent; const char *input; @@ -726,6 +762,28 @@ static const struct bio_dump_testcase { " 00d3 - 1a .\n" " 00f6 - \n", }, + { + .indent = 4, + .input = bytes, + .inlen = BYTES_LEN, + .output = +" 0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n" +" 0010 - 10 11 12 13 14 15 16 17-18 19 1a 1b 1c 1d 1e 1f ................\n" +" 0020 - 20 21 22 23 24 25 26 27-28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n" +" 0030 - 30 31 32 33 34 35 36 37-38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n" +" 0040 - 40 41 42 43 44 45 46 47-48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n" +" 0050 - 50 51 52 53 54 55 56 57-58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n" +" 0060 - 60 61 62 63 64 65 66 67-68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n" +" 0070 - 70 71 72 73 74 75 76 77-78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n" +" 0080 - 80 81 82 83 84 85 86 87-88 89 8a 8b 8c 8d 8e 8f ................\n" +" 0090 - 90 91 92 93 94 95 96 97-98 99 9a 9b 9c 9d 9e 9f ................\n" +" 00a0 - a0 a1 a2 a3 a4 a5 a6 a7-a8 a9 aa ab ac ad ae af ................\n" +" 00b0 - b0 b1 b2 b3 b4 b5 b6 b7-b8 b9 ba bb bc bd be bf ................\n" +" 00c0 - c0 c1 c2 c3 c4 c5 c6 c7-c8 c9 ca cb cc cd ce cf ................\n" +" 00d0 - d0 d1 d2 d3 d4 d5 d6 d7-d8 d9 da db dc dd de df ................\n" +" 00e0 - e0 e1 e2 e3 e4 e5 e6 e7-e8 e9 ea eb ec ed ee ef ................\n" +" 00f0 - f0 f1 f2 f3 f4 f5 f6 f7-f8 f9 fa fb fc fd fe ff ................\n", + }, }; #define N_TESTS (sizeof(bio_dump_testcases) / sizeof(bio_dump_testcases[0])) diff --git a/regress/usr.bin/ssh/putty-ciphers.sh b/regress/usr.bin/ssh/putty-ciphers.sh index 5b8e25a27..30f6461cc 100644 --- a/regress/usr.bin/ssh/putty-ciphers.sh +++ b/regress/usr.bin/ssh/putty-ciphers.sh @@ -1,24 +1,47 @@ -# $OpenBSD: putty-ciphers.sh,v 1.11 2021/09/01 03:16:06 dtucker Exp $ +# $OpenBSD: putty-ciphers.sh,v 1.13 2024/02/09 08:56:59 dtucker Exp $ # Placed in the Public Domain. tid="putty ciphers" -if test "x$REGRESS_INTEROP_PUTTY" != "xyes" ; then - skip "putty interop tests not enabled" -fi +puttysetup -# Re-enable ssh-rsa on older PuTTY versions. -oldver="`${PLINK} --version | awk '/plink: Release/{if ($3<0.76)print "yes"}'`" -if [ "x$oldver" = "xyes" ]; then - echo "HostKeyAlgorithms +ssh-rsa" >> ${OBJ}/sshd_proxy - echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> ${OBJ}/sshd_proxy -fi +cp ${OBJ}/sshd_proxy ${OBJ}/sshd_proxy_bak -for c in aes 3des aes128-ctr aes192-ctr aes256-ctr chacha20 ; do - verbose "$tid: cipher $c" +# Since there doesn't seem to be a way to set MACs on the PuTTY client side, +# we force each in turn on the server side, omitting the ones PuTTY doesn't +# support. Grepping the binary is pretty janky, but AFAIK there's no way to +# query for supported algos. +macs="" +for m in `${SSH} -Q MACs`; do + if strings "${PLINK}" | grep -E "^${m}$" >/dev/null; then + macs="${macs} ${m}" + else + trace "omitting unsupported MAC ${m}" + fi +done + +ciphers="" +for c in `${SSH} -Q Ciphers`; do + if strings "${PLINK}" | grep -E "^${c}$" >/dev/null; then + ciphers="${ciphers} ${c}" + else + trace "omitting unsupported cipher ${c}" + fi +done + +for c in default $ciphers; do + for m in default ${macs}; do + verbose "$tid: cipher $c mac $m" cp ${OBJ}/.putty/sessions/localhost_proxy \ ${OBJ}/.putty/sessions/cipher_$c - echo "Cipher=$c" >> ${OBJ}/.putty/sessions/cipher_$c + if [ "${c}" != "default" ]; then + echo "Cipher=$c" >> ${OBJ}/.putty/sessions/cipher_$c + fi + + cp ${OBJ}/sshd_proxy_bak ${OBJ}/sshd_proxy + if [ "${m}" != "default" ]; then + echo "MACs $m" >> ${OBJ}/sshd_proxy + fi rm -f ${COPY} env HOME=$PWD ${PLINK} -load cipher_$c -batch -i ${OBJ}/putty.rsa2 \ @@ -27,6 +50,6 @@ for c in aes 3des aes128-ctr aes192-ctr aes256-ctr chacha20 ; do fail "ssh cat $DATA failed" fi cmp ${DATA} ${COPY} || fail "corrupted copy" + done done rm -f ${COPY} - diff --git a/regress/usr.bin/ssh/putty-kex.sh b/regress/usr.bin/ssh/putty-kex.sh index c75802a06..22f8bd706 100644 --- a/regress/usr.bin/ssh/putty-kex.sh +++ b/regress/usr.bin/ssh/putty-kex.sh @@ -1,28 +1,36 @@ -# $OpenBSD: putty-kex.sh,v 1.9 2021/09/01 03:16:06 dtucker Exp $ +# $OpenBSD: putty-kex.sh,v 1.11 2024/02/09 08:56:59 dtucker Exp $ # Placed in the Public Domain. tid="putty KEX" -if test "x$REGRESS_INTEROP_PUTTY" != "xyes" ; then - skip "putty interop tests not enabled" -fi +puttysetup -# Re-enable ssh-rsa on older PuTTY versions. -oldver="`${PLINK} --version | awk '/plink: Release/{if ($3<0.76)print "yes"}'`" -if [ "x$oldver" = "xyes" ]; then - echo "HostKeyAlgorithms +ssh-rsa" >> ${OBJ}/sshd_proxy - echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> ${OBJ}/sshd_proxy -fi +cp ${OBJ}/sshd_proxy ${OBJ}/sshd_proxy_bak -for k in dh-gex-sha1 dh-group1-sha1 dh-group14-sha1 ecdh ; do - verbose "$tid: kex $k" - cp ${OBJ}/.putty/sessions/localhost_proxy \ - ${OBJ}/.putty/sessions/kex_$k - echo "KEX=$k" >> ${OBJ}/.putty/sessions/kex_$k +# Enable group1, which PuTTY now disables by default +echo "KEX=dh-group1-sha1" >>${OBJ}/.putty/sessions/localhost_proxy - env HOME=$PWD ${PLINK} -load kex_$k -batch -i ${OBJ}/putty.rsa2 true - if [ $? -ne 0 ]; then - fail "KEX $k failed" +# Grepping algos out of the binary is pretty janky, but AFAIK there's no way +# to query supported algos. +kex="" +for k in `$SSH -Q kex`; do + if strings "${PLINK}" | grep -E "^${k}$" >/dev/null; then + kex="${kex} ${k}" + else + trace "omitting unsupported KEX ${k}" fi done +for k in ${kex}; do + verbose "$tid: kex $k" + cp ${OBJ}/sshd_proxy_bak ${OBJ}/sshd_proxy + echo "KexAlgorithms ${k}" >>${OBJ}/sshd_proxy + + env HOME=$PWD ${PLINK} -v -load localhost_proxy -batch -i ${OBJ}/putty.rsa2 true \ + 2>${OBJ}/log/putty-kex-$k.log + if [ $? -ne 0 ]; then + fail "KEX $k failed" + fi + kexmsg=`grep -E '^Doing.* key exchange' ${OBJ}/log/putty-kex-$k.log` + trace putty: ${kexmsg} +done diff --git a/regress/usr.bin/ssh/putty-transfer.sh b/regress/usr.bin/ssh/putty-transfer.sh index a6864f951..1920f49ac 100644 --- a/regress/usr.bin/ssh/putty-transfer.sh +++ b/regress/usr.bin/ssh/putty-transfer.sh @@ -1,18 +1,9 @@ -# $OpenBSD: putty-transfer.sh,v 1.11 2021/09/01 03:16:06 dtucker Exp $ +# $OpenBSD: putty-transfer.sh,v 1.12 2024/02/09 08:47:42 dtucker Exp $ # Placed in the Public Domain. tid="putty transfer data" -if test "x$REGRESS_INTEROP_PUTTY" != "xyes" ; then - skip "putty interop tests not enabled" -fi - -# Re-enable ssh-rsa on older PuTTY versions. -oldver="`${PLINK} --version | awk '/plink: Release/{if ($3<0.76)print "yes"}'`" -if [ "x$oldver" = "xyes" ]; then - echo "HostKeyAlgorithms +ssh-rsa" >> ${OBJ}/sshd_proxy - echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> ${OBJ}/sshd_proxy -fi +puttysetup if [ "`${SSH} -Q compression`" = "none" ]; then comp="0" diff --git a/regress/usr.bin/ssh/test-exec.sh b/regress/usr.bin/ssh/test-exec.sh index 1dba670a7..2143cbe16 100644 --- a/regress/usr.bin/ssh/test-exec.sh +++ b/regress/usr.bin/ssh/test-exec.sh @@ -1,4 +1,4 @@ -# $OpenBSD: test-exec.sh,v 1.105 2023/10/31 04:15:40 dtucker Exp $ +# $OpenBSD: test-exec.sh,v 1.106 2024/02/09 08:47:42 dtucker Exp $ # Placed in the Public Domain. #SUDO=sudo @@ -571,6 +571,11 @@ case "$SCRIPT" in esac if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then + puttysetup() { + if test "x$REGRESS_INTEROP_PUTTY" != "xyes" ; then + skip "putty interop tests not enabled" + fi + mkdir -p ${OBJ}/.putty # Add a PuTTY key to authorized_keys @@ -602,6 +607,23 @@ if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy echo "ProxyTelnetCommand=${OBJ}/sshd-log-wrapper.sh -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy echo "ProxyLocalhost=1" >> ${OBJ}/.putty/sessions/localhost_proxy + + PUTTYVER="`${PLINK} --version | awk '/plink: Release/{print $3}'`" + PUTTYMINORVER="`echo ${PUTTYVER} | cut -f2 -d.`" + verbose "plink version ${PUTTYVER} minor ${PUTTYMINORVER}" + + # Re-enable ssh-rsa on older PuTTY versions since they don't do newer + # key types. + if [ "$PUTTYMINORVER" -lt "76" ]; then + echo "HostKeyAlgorithms +ssh-rsa" >> ${OBJ}/sshd_proxy + echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> ${OBJ}/sshd_proxy + fi + + if [ "$PUTTYMINORVER" -le "64" ]; then + echo "KexAlgorithms +diffie-hellman-group14-sha1" \ + >>${OBJ}/sshd_proxy + fi + } fi REGRESS_INTEROP_DROPBEAR=no diff --git a/sys/dev/dt/dt_dev.c b/sys/dev/dt/dt_dev.c index 12c5390cd..2383d3a73 100644 --- a/sys/dev/dt/dt_dev.c +++ b/sys/dev/dt/dt_dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_dev.c,v 1.29 2024/01/02 16:32:48 bluhm Exp $ */ +/* $OpenBSD: dt_dev.c,v 1.30 2024/02/09 17:42:18 cheloha Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -56,13 +57,13 @@ * proc_trampoline+0x1c */ #if defined(__amd64__) -#define DT_FA_PROFILE 7 +#define DT_FA_PROFILE 5 #define DT_FA_STATIC 2 #elif defined(__i386__) -#define DT_FA_PROFILE 8 +#define DT_FA_PROFILE 5 #define DT_FA_STATIC 2 #elif defined(__macppc__) -#define DT_FA_PROFILE 7 +#define DT_FA_PROFILE 5 #define DT_FA_STATIC 2 #elif defined(__octeon__) #define DT_FA_PROFILE 6 @@ -492,6 +493,14 @@ dt_ioctl_record_start(struct dt_softc *sc) SMR_SLIST_INSERT_HEAD_LOCKED(&dtp->dtp_pcbs, dp, dp_pnext); dtp->dtp_recording++; dtp->dtp_prov->dtpv_recording++; + + if (dp->dp_nsecs != 0) { + clockintr_bind(&dp->dp_clockintr, dp->dp_cpu, dt_clock, + dp); + clockintr_stagger(&dp->dp_clockintr, dp->dp_nsecs, + CPU_INFO_UNIT(dp->dp_cpu), MAXCPUS); + clockintr_advance(&dp->dp_clockintr, dp->dp_nsecs); + } } rw_exit_write(&dt_lock); @@ -518,6 +527,13 @@ dt_ioctl_record_stop(struct dt_softc *sc) TAILQ_FOREACH(dp, &sc->ds_pcbs, dp_snext) { struct dt_probe *dtp = dp->dp_dtp; + /* + * Set an execution barrier to ensure the shared + * reference to dp is inactive. + */ + if (dp->dp_nsecs != 0) + clockintr_unbind(&dp->dp_clockintr, CL_BARRIER); + dtp->dtp_recording--; dtp->dtp_prov->dtpv_recording--; SMR_SLIST_REMOVE_LOCKED(&dtp->dtp_pcbs, dp, dt_pcb, dp_pnext); diff --git a/sys/dev/dt/dt_prov_profile.c b/sys/dev/dt/dt_prov_profile.c index d6db0797b..1388770fb 100644 --- a/sys/dev/dt/dt_prov_profile.c +++ b/sys/dev/dt/dt_prov_profile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_prov_profile.c,v 1.5 2023/04/26 16:53:59 claudio Exp $ */ +/* $OpenBSD: dt_prov_profile.c,v 1.6 2024/02/09 17:42:18 cheloha Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -31,13 +32,11 @@ struct dt_probe *dtpp_interval; /* global periodic probe */ int dt_prov_profile_alloc(struct dt_probe *, struct dt_softc *, struct dt_pcb_list *, struct dtioc_req *); -int dt_prov_profile_enter(struct dt_provider *, ...); -int dt_prov_interval_enter(struct dt_provider *, ...); struct dt_provider dt_prov_profile = { .dtpv_name = "profile", .dtpv_alloc = dt_prov_profile_alloc, - .dtpv_enter = dt_prov_profile_enter, + .dtpv_enter = NULL, .dtpv_leave = NULL, .dtpv_dealloc = NULL, }; @@ -45,7 +44,7 @@ struct dt_provider dt_prov_profile = { struct dt_provider dt_prov_interval = { .dtpv_name = "interval", .dtpv_alloc = dt_prov_profile_alloc, - .dtpv_enter = dt_prov_interval_enter, + .dtpv_enter = NULL, .dtpv_leave = NULL, .dtpv_dealloc = NULL, }; @@ -90,8 +89,8 @@ dt_prov_profile_alloc(struct dt_probe *dtp, struct dt_softc *sc, return ENOMEM; } - dp->dp_maxtick = hz / dtrq->dtrq_rate; - dp->dp_cpuid = ci->ci_cpuid; + dp->dp_nsecs = SEC_TO_NSEC(1) / dtrq->dtrq_rate; + dp->dp_cpu = ci; dp->dp_filter = dtrq->dtrq_filter; dp->dp_evtflags = dtrq->dtrq_evtflags & DTEVT_PROV_PROFILE; @@ -101,51 +100,18 @@ dt_prov_profile_alloc(struct dt_probe *dtp, struct dt_softc *sc, return 0; } -static inline void -dt_prov_profile_fire(struct dt_pcb *dp) +void +dt_clock(struct clockrequest *cr, void *cf, void *arg) { + uint64_t count, i; struct dt_evt *dtev; + struct dt_pcb *dp = arg; - if (++dp->dp_nticks < dp->dp_maxtick) - return; - - dtev = dt_pcb_ring_get(dp, 1); - if (dtev == NULL) - return; - dt_pcb_ring_consume(dp, dtev); - dp->dp_nticks = 0; -} - -int -dt_prov_profile_enter(struct dt_provider *dtpv, ...) -{ - struct cpu_info *ci = curcpu(); - struct dt_pcb *dp; - - KASSERT(dtpv == &dt_prov_profile); - - smr_read_enter(); - SMR_SLIST_FOREACH(dp, &dtpp_profile->dtp_pcbs, dp_pnext) { - if (dp->dp_cpuid != ci->ci_cpuid) - continue; - - dt_prov_profile_fire(dp); + count = clockrequest_advance(cr, dp->dp_nsecs); + for (i = 0; i < count; i++) { + dtev = dt_pcb_ring_get(dp, 1); + if (dtev == NULL) + return; + dt_pcb_ring_consume(dp, dtev); } - smr_read_leave(); - return 0; -} - -int -dt_prov_interval_enter(struct dt_provider *dtpv, ...) -{ - struct dt_pcb *dp; - - KASSERT(dtpv == &dt_prov_interval); - - smr_read_enter(); - SMR_SLIST_FOREACH(dp, &dtpp_interval->dtp_pcbs, dp_pnext) { - dt_prov_profile_fire(dp); - } - smr_read_leave(); - return 0; } diff --git a/sys/dev/dt/dtvar.h b/sys/dev/dt/dtvar.h index 9b5d3de08..f69a41c65 100644 --- a/sys/dev/dt/dtvar.h +++ b/sys/dev/dt/dtvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dtvar.h,v 1.17 2023/04/26 16:53:59 claudio Exp $ */ +/* $OpenBSD: dtvar.h,v 1.18 2024/02/09 17:42:18 cheloha Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -175,6 +175,7 @@ int dtioc_req_isvalid(struct dtioc_req *); * userland read(2)s them. * * Locks used to protect struct members in this file: + * D dt_lock * I immutable after creation * K kernel lock * K,S kernel lock for writing and SMR for reading @@ -197,9 +198,9 @@ struct dt_pcb { struct dt_filter dp_filter; /* [I] filter to match */ /* Provider specific fields. */ - unsigned int dp_cpuid; /* [I] on which CPU */ - unsigned int dp_maxtick; /* [I] freq. of profiling */ - unsigned int dp_nticks; /* [c] current tick count */ + struct clockintr dp_clockintr; /* [D] profiling handle */ + uint64_t dp_nsecs; /* [I] profiling period */ + struct cpu_info *dp_cpu; /* [I] on which CPU */ /* Counters */ uint64_t dp_dropevt; /* [m] # dropped event */ @@ -270,6 +271,7 @@ struct dt_probe *dt_dev_alloc_probe(const char *, const char *, struct dt_provider *); void dt_dev_register_probe(struct dt_probe *); +void dt_clock(struct clockrequest *, void *, void *); extern volatile uint32_t dt_tracing; /* currently tracing? */ diff --git a/sys/dev/ic/qwx.c b/sys/dev/ic/qwx.c index 920cad162..587147a7b 100644 --- a/sys/dev/ic/qwx.c +++ b/sys/dev/ic/qwx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: qwx.c,v 1.28 2024/02/08 14:36:22 stsp Exp $ */ +/* $OpenBSD: qwx.c,v 1.36 2024/02/09 14:11:00 stsp Exp $ */ /* * Copyright 2023 Stefan Sperling @@ -144,12 +144,13 @@ int qwx_mac_register(struct qwx_softc *); int qwx_mac_start(struct qwx_softc *); void qwx_mac_scan_finish(struct qwx_softc *); int qwx_mac_mgmt_tx_wmi(struct qwx_softc *, struct qwx_vif *, uint8_t, - struct mbuf *); + struct ieee80211_node *, struct mbuf *); int qwx_dp_tx(struct qwx_softc *, struct qwx_vif *, uint8_t, struct ieee80211_node *, struct mbuf *); int qwx_dp_tx_send_reo_cmd(struct qwx_softc *, struct dp_rx_tid *, enum hal_reo_cmd_type , struct ath11k_hal_reo_cmd *, void (*func)(struct qwx_dp *, void *, enum hal_reo_cmd_status)); +void qwx_dp_rx_deliver_msdu(struct qwx_softc *, struct qwx_rx_msdu *); int qwx_scan(struct qwx_softc *); void qwx_scan_abort(struct qwx_softc *); @@ -376,7 +377,7 @@ qwx_tx(struct qwx_softc *sc, struct mbuf *m, struct ieee80211_node *ni) #endif if (frame_type == IEEE80211_FC0_TYPE_MGT) - return qwx_mac_mgmt_tx_wmi(sc, arvif, pdev_id, m); + return qwx_mac_mgmt_tx_wmi(sc, arvif, pdev_id, ni, m); return qwx_dp_tx(sc, arvif, pdev_id, ni, m); } @@ -8378,7 +8379,7 @@ qwx_qmi_load_bdf_qmi(struct qwx_softc *sc, int regdb) ret = qwx_core_fetch_bdf(sc, &data, &len, &boardfw, &boardfw_len, regdb ? ATH11K_REGDB_FILE : ATH11K_BOARD_API2_FILE); if (ret) - goto out; + return ret; if (regdb) bdf_type = ATH11K_QMI_BDF_TYPE_REGDB; @@ -12730,6 +12731,9 @@ qwx_wmi_process_mgmt_tx_comp(struct qwx_softc *sc, m_freem(tx_data->m); tx_data->m = NULL; + ieee80211_release_node(ic, tx_data->ni); + tx_data->ni = NULL; + if (arvif->txmgmt.queued > 0) arvif->txmgmt.queued--; @@ -12892,7 +12896,6 @@ qwx_wmi_tlv_op_rx(struct qwx_softc *sc, struct mbuf *m) break; #endif case WMI_MGMT_RX_EVENTID: - DPRINTF("%s: 0x%x: mgmt rx event\n", __func__, id); qwx_mgmt_rx_event(sc, m); /* mgmt_rx_event() owns the skb now! */ return; @@ -12900,7 +12903,6 @@ qwx_wmi_tlv_op_rx(struct qwx_softc *sc, struct mbuf *m) qwx_mgmt_tx_compl_event(sc, m); break; case WMI_SCAN_EVENTID: - DPRINTF("%s: 0x%x: scan event\n", __func__, id); qwx_scan_event(sc, m); break; #if 0 @@ -12912,7 +12914,6 @@ qwx_wmi_tlv_op_rx(struct qwx_softc *sc, struct mbuf *m) qwx_roam_event(sc, m); break; case WMI_CHAN_INFO_EVENTID: - DPRINTF("%s: 0x%x: chan info event\n", __func__, id); qwx_chan_info_event(sc, m); break; #if 0 @@ -14859,11 +14860,84 @@ qwx_dp_tx_process_htt_tx_complete(struct qwx_softc *sc, void *desc, } } +int +qwx_mac_hw_ratecode_to_legacy_rate(struct ieee80211_node *ni, uint8_t hw_rc, + uint8_t preamble, uint8_t *rateidx, uint16_t *rate) +{ + struct ieee80211_rateset *rs = &ni->ni_rates; + int i; + + if (preamble == WMI_RATE_PREAMBLE_CCK) { + hw_rc &= ~ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK; + switch (hw_rc) { + case ATH11K_HW_RATE_CCK_LP_1M: + *rate = 2; + break; + case ATH11K_HW_RATE_CCK_LP_2M: + case ATH11K_HW_RATE_CCK_SP_2M: + *rate = 4; + break; + case ATH11K_HW_RATE_CCK_LP_5_5M: + case ATH11K_HW_RATE_CCK_SP_5_5M: + *rate = 11; + break; + case ATH11K_HW_RATE_CCK_LP_11M: + case ATH11K_HW_RATE_CCK_SP_11M: + *rate = 22; + break; + default: + return EINVAL; + } + } else { + switch (hw_rc) { + case ATH11K_HW_RATE_OFDM_6M: + *rate = 12; + break; + case ATH11K_HW_RATE_OFDM_9M: + *rate = 18; + break; + case ATH11K_HW_RATE_OFDM_12M: + *rate = 24; + break; + case ATH11K_HW_RATE_OFDM_18M: + *rate = 36; + break; + case ATH11K_HW_RATE_OFDM_24M: + *rate = 48; + break; + case ATH11K_HW_RATE_OFDM_36M: + *rate = 72; + break; + case ATH11K_HW_RATE_OFDM_48M: + *rate = 96; + break; + case ATH11K_HW_RATE_OFDM_54M: + *rate = 104; + break; + default: + return EINVAL; + } + } + + for (i = 0; i < rs->rs_nrates; i++) { + uint8_t rval = rs->rs_rates[i] & IEEE80211_RATE_VAL; + if (rval == *rate) { + *rateidx = i; + return 0; + } + } + + return EINVAL; +} + void qwx_dp_tx_complete_msdu(struct qwx_softc *sc, struct dp_tx_ring *tx_ring, uint32_t msdu_id, struct hal_tx_status *ts) { + struct ieee80211com *ic = &sc->sc_ic; struct qwx_tx_data *tx_data = &tx_ring->data[msdu_id]; + uint8_t pkt_type, mcs, rateidx; + uint16_t rate; if (ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_TQM) { /* Must not happen */ @@ -14874,7 +14948,14 @@ qwx_dp_tx_complete_msdu(struct qwx_softc *sc, struct dp_tx_ring *tx_ring, m_freem(tx_data->m); tx_data->m = NULL; - /* TODO: Tx rate adjustment? */ + pkt_type = FIELD_GET(HAL_TX_RATE_STATS_INFO0_PKT_TYPE, ts->rate_stats); + mcs = FIELD_GET(HAL_TX_RATE_STATS_INFO0_MCS, ts->rate_stats); + if (qwx_mac_hw_ratecode_to_legacy_rate(tx_data->ni, mcs, pkt_type, + &rateidx, &rate) == 0) + tx_data->ni->ni_txrate = rateidx; + + ieee80211_release_node(ic, tx_data->ni); + tx_data->ni = NULL; if (tx_ring->queued > 0) tx_ring->queued--; @@ -14967,16 +15048,540 @@ qwx_dp_tx_completion_handler(struct qwx_softc *sc, int ring_id) return 0; } +void +qwx_hal_rx_reo_ent_paddr_get(struct qwx_softc *sc, void *desc, uint64_t *paddr, + uint32_t *desc_bank) +{ + struct ath11k_buffer_addr *buff_addr = desc; + + *paddr = ((uint64_t)(FIELD_GET(BUFFER_ADDR_INFO1_ADDR, + buff_addr->info1)) << 32) | + FIELD_GET(BUFFER_ADDR_INFO0_ADDR, buff_addr->info0); + + *desc_bank = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE, buff_addr->info1); +} + +int +qwx_hal_desc_reo_parse_err(struct qwx_softc *sc, uint32_t *rx_desc, + uint64_t *paddr, uint32_t *desc_bank) +{ + struct hal_reo_dest_ring *desc = (struct hal_reo_dest_ring *)rx_desc; + enum hal_reo_dest_ring_push_reason push_reason; + enum hal_reo_dest_ring_error_code err_code; + + push_reason = FIELD_GET(HAL_REO_DEST_RING_INFO0_PUSH_REASON, + desc->info0); + err_code = FIELD_GET(HAL_REO_DEST_RING_INFO0_ERROR_CODE, + desc->info0); +#if 0 + ab->soc_stats.reo_error[err_code]++; +#endif + if (push_reason != HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED && + push_reason != HAL_REO_DEST_RING_PUSH_REASON_ROUTING_INSTRUCTION) { + printf("%s: expected error push reason code, received %d\n", + sc->sc_dev.dv_xname, push_reason); + return EINVAL; + } + + if (FIELD_GET(HAL_REO_DEST_RING_INFO0_BUFFER_TYPE, desc->info0) != + HAL_REO_DEST_RING_BUFFER_TYPE_LINK_DESC) { + printf("%s: expected buffer type link_desc", + sc->sc_dev.dv_xname); + return EINVAL; + } + + qwx_hal_rx_reo_ent_paddr_get(sc, rx_desc, paddr, desc_bank); + + return 0; +} + +void +qwx_hal_rx_msdu_link_info_get(void *link_desc, uint32_t *num_msdus, + uint32_t *msdu_cookies, enum hal_rx_buf_return_buf_manager *rbm) +{ + struct hal_rx_msdu_link *link = (struct hal_rx_msdu_link *)link_desc; + struct hal_rx_msdu_details *msdu; + int i; + + *num_msdus = HAL_NUM_RX_MSDUS_PER_LINK_DESC; + + msdu = &link->msdu_link[0]; + *rbm = FIELD_GET(BUFFER_ADDR_INFO1_RET_BUF_MGR, + msdu->buf_addr_info.info1); + + for (i = 0; i < *num_msdus; i++) { + msdu = &link->msdu_link[i]; + + if (!FIELD_GET(BUFFER_ADDR_INFO0_ADDR, + msdu->buf_addr_info.info0)) { + *num_msdus = i; + break; + } + *msdu_cookies = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE, + msdu->buf_addr_info.info1); + msdu_cookies++; + } +} + +void +qwx_hal_rx_msdu_link_desc_set(struct qwx_softc *sc, void *desc, + void *link_desc, enum hal_wbm_rel_bm_act action) +{ + struct hal_wbm_release_ring *dst_desc = desc; + struct hal_wbm_release_ring *src_desc = link_desc; + + dst_desc->buf_addr_info = src_desc->buf_addr_info; + dst_desc->info0 |= FIELD_PREP(HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE, + HAL_WBM_REL_SRC_MODULE_SW) | + FIELD_PREP(HAL_WBM_RELEASE_INFO0_BM_ACTION, action) | + FIELD_PREP(HAL_WBM_RELEASE_INFO0_DESC_TYPE, + HAL_WBM_REL_DESC_TYPE_MSDU_LINK); +} + +int +qwx_dp_rx_link_desc_return(struct qwx_softc *sc, uint32_t *link_desc, + enum hal_wbm_rel_bm_act action) +{ + struct qwx_dp *dp = &sc->dp; + struct hal_srng *srng; + uint32_t *desc; + int ret = 0; + + srng = &sc->hal.srng_list[dp->wbm_desc_rel_ring.ring_id]; +#ifdef notyet + spin_lock_bh(&srng->lock); +#endif + qwx_hal_srng_access_begin(sc, srng); + + desc = qwx_hal_srng_src_get_next_entry(sc, srng); + if (!desc) { + ret = ENOBUFS; + goto exit; + } + + qwx_hal_rx_msdu_link_desc_set(sc, (void *)desc, (void *)link_desc, + action); + +exit: + qwx_hal_srng_access_end(sc, srng); +#ifdef notyet + spin_unlock_bh(&srng->lock); +#endif + return ret; +} + +int +qwx_dp_rx_frag_h_mpdu(struct qwx_softc *sc, struct mbuf *m, + uint32_t *ring_desc) +{ + printf("%s: not implemented\n", __func__); + return ENOTSUP; +} + +static inline uint16_t +qwx_dp_rx_h_msdu_start_msdu_len(struct qwx_softc *sc, struct hal_rx_desc *desc) +{ + return sc->hw_params.hw_ops->rx_desc_get_msdu_len(desc); +} + +void +qwx_dp_process_rx_err_buf(struct qwx_softc *sc, uint32_t *ring_desc, + int buf_id, int drop) +{ + struct qwx_pdev_dp *dp = &sc->pdev_dp; + struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring; + struct mbuf *m; + struct qwx_rx_data *rx_data; + struct hal_rx_desc *rx_desc; + uint16_t msdu_len; + uint32_t hal_rx_desc_sz = sc->hw_params.hal_desc_sz; + + if (buf_id >= rx_ring->bufs_max) + return; + + rx_data = &rx_ring->rx_data[buf_id]; + if (rx_data->m == NULL) + return; + + bus_dmamap_unload(sc->sc_dmat, rx_data->map); + m = rx_data->m; + rx_data->m = NULL; + + if (drop) { + m_freem(m); + return; + } + + rx_desc = mtod(m, struct hal_rx_desc *); + msdu_len = qwx_dp_rx_h_msdu_start_msdu_len(sc, rx_desc); + if ((msdu_len + hal_rx_desc_sz) > DP_RX_BUFFER_SIZE) { +#if 0 + uint8_t *hdr_status = ath11k_dp_rx_h_80211_hdr(ar->ab, rx_desc); + ath11k_warn(ar->ab, "invalid msdu leng %u", msdu_len); + ath11k_dbg_dump(ar->ab, ATH11K_DBG_DATA, NULL, "", hdr_status, + sizeof(struct ieee80211_hdr)); + ath11k_dbg_dump(ar->ab, ATH11K_DBG_DATA, NULL, "", rx_desc, + sizeof(struct hal_rx_desc)); +#endif + m_freem(m); + return; + } + + if (qwx_dp_rx_frag_h_mpdu(sc, m, ring_desc)) { + qwx_dp_rx_link_desc_return(sc, ring_desc, + HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); + } + + m_freem(m); +} + int qwx_dp_process_rx_err(struct qwx_softc *sc) { + struct ieee80211com *ic = &sc->sc_ic; + struct ifnet *ifp = &ic->ic_if; + uint32_t msdu_cookies[HAL_NUM_RX_MSDUS_PER_LINK_DESC]; + struct dp_link_desc_bank *link_desc_banks; + enum hal_rx_buf_return_buf_manager rbm; + int tot_n_bufs_reaped, ret, i; + int n_bufs_reaped[MAX_RADIOS] = {0}; + struct dp_rxdma_ring *rx_ring; + struct dp_srng *reo_except; + uint32_t desc_bank, num_msdus; + struct hal_srng *srng; + struct qwx_dp *dp; + void *link_desc_va; + int buf_id, mac_id; + uint64_t paddr; + uint32_t *desc; + int is_frag; + uint8_t drop = 0; + + tot_n_bufs_reaped = 0; + + dp = &sc->dp; + reo_except = &dp->reo_except_ring; + link_desc_banks = dp->link_desc_banks; + + srng = &sc->hal.srng_list[reo_except->ring_id]; +#ifdef notyet + spin_lock_bh(&srng->lock); +#endif + qwx_hal_srng_access_begin(sc, srng); + + while ((desc = qwx_hal_srng_dst_get_next_entry(sc, srng))) { + struct hal_reo_dest_ring *reo_desc = + (struct hal_reo_dest_ring *)desc; +#if 0 + ab->soc_stats.err_ring_pkts++; +#endif + ret = qwx_hal_desc_reo_parse_err(sc, desc, &paddr, &desc_bank); + if (ret) { + printf("%s: failed to parse error reo desc %d\n", + sc->sc_dev.dv_xname, ret); + continue; + } + link_desc_va = link_desc_banks[desc_bank].vaddr + + (paddr - link_desc_banks[desc_bank].paddr); + qwx_hal_rx_msdu_link_info_get(link_desc_va, &num_msdus, + msdu_cookies, &rbm); + if (rbm != HAL_RX_BUF_RBM_WBM_IDLE_DESC_LIST && + rbm != HAL_RX_BUF_RBM_SW3_BM) { +#if 0 + ab->soc_stats.invalid_rbm++; +#endif + printf("%s: invalid return buffer manager %d\n", + sc->sc_dev.dv_xname, rbm); + qwx_dp_rx_link_desc_return(sc, desc, + HAL_WBM_REL_BM_ACT_REL_MSDU); + continue; + } + + is_frag = !!(reo_desc->rx_mpdu_info.info0 & + RX_MPDU_DESC_INFO0_FRAG_FLAG); + + /* Process only rx fragments with one msdu per link desc below, + * and drop msdu's indicated due to error reasons. + */ + if (!is_frag || num_msdus > 1) { + drop = 1; + /* Return the link desc back to wbm idle list */ + qwx_dp_rx_link_desc_return(sc, desc, + HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); + } + + for (i = 0; i < num_msdus; i++) { + buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, + msdu_cookies[i]); + + mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, + msdu_cookies[i]); + + qwx_dp_process_rx_err_buf(sc, desc, buf_id, drop); + n_bufs_reaped[mac_id]++; + tot_n_bufs_reaped++; + } + } + + qwx_hal_srng_access_end(sc, srng); +#ifdef notyet + spin_unlock_bh(&srng->lock); +#endif + for (i = 0; i < sc->num_radios; i++) { + if (!n_bufs_reaped[i]) + continue; + + rx_ring = &sc->pdev_dp.rx_refill_buf_ring; + + qwx_dp_rxbufs_replenish(sc, i, rx_ring, n_bufs_reaped[i], + sc->hw_params.hal_params->rx_buf_rbm); + } + + ifp->if_ierrors += tot_n_bufs_reaped; + + return tot_n_bufs_reaped; +} + +int +qwx_hal_wbm_desc_parse_err(void *desc, struct hal_rx_wbm_rel_info *rel_info) +{ + struct hal_wbm_release_ring *wbm_desc = desc; + enum hal_wbm_rel_desc_type type; + enum hal_wbm_rel_src_module rel_src; + enum hal_rx_buf_return_buf_manager ret_buf_mgr; + + type = FIELD_GET(HAL_WBM_RELEASE_INFO0_DESC_TYPE, wbm_desc->info0); + + /* We expect only WBM_REL buffer type */ + if (type != HAL_WBM_REL_DESC_TYPE_REL_MSDU) + return -EINVAL; + + rel_src = FIELD_GET(HAL_WBM_RELEASE_INFO0_REL_SRC_MODULE, + wbm_desc->info0); + if (rel_src != HAL_WBM_REL_SRC_MODULE_RXDMA && + rel_src != HAL_WBM_REL_SRC_MODULE_REO) + return EINVAL; + + ret_buf_mgr = FIELD_GET(BUFFER_ADDR_INFO1_RET_BUF_MGR, + wbm_desc->buf_addr_info.info1); + if (ret_buf_mgr != HAL_RX_BUF_RBM_SW3_BM) { +#if 0 + ab->soc_stats.invalid_rbm++; +#endif + return EINVAL; + } + + rel_info->cookie = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE, + wbm_desc->buf_addr_info.info1); + rel_info->err_rel_src = rel_src; + if (rel_src == HAL_WBM_REL_SRC_MODULE_REO) { + rel_info->push_reason = FIELD_GET( + HAL_WBM_RELEASE_INFO0_REO_PUSH_REASON, wbm_desc->info0); + rel_info->err_code = FIELD_GET( + HAL_WBM_RELEASE_INFO0_REO_ERROR_CODE, wbm_desc->info0); + } else { + rel_info->push_reason = FIELD_GET( + HAL_WBM_RELEASE_INFO0_RXDMA_PUSH_REASON, wbm_desc->info0); + rel_info->err_code = FIELD_GET( + HAL_WBM_RELEASE_INFO0_RXDMA_ERROR_CODE, wbm_desc->info0); + } + + rel_info->first_msdu = FIELD_GET(HAL_WBM_RELEASE_INFO2_FIRST_MSDU, + wbm_desc->info2); + rel_info->last_msdu = FIELD_GET(HAL_WBM_RELEASE_INFO2_LAST_MSDU, + wbm_desc->info2); + return 0; } +int +qwx_dp_rx_h_null_q_desc(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + struct qwx_rx_msdu_list *msdu_list) +{ + printf("%s: not implemented\n", __func__); + return ENOTSUP; +} + +int +qwx_dp_rx_h_reo_err(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + struct qwx_rx_msdu_list *msdu_list) +{ + int drop = 0; +#if 0 + ar->ab->soc_stats.reo_error[rxcb->err_code]++; +#endif + switch (msdu->err_code) { + case HAL_REO_DEST_RING_ERROR_CODE_DESC_ADDR_ZERO: + if (qwx_dp_rx_h_null_q_desc(sc, msdu, msdu_list)) + drop = 1; + break; + case HAL_REO_DEST_RING_ERROR_CODE_PN_CHECK_FAILED: + /* TODO: Do not drop PN failed packets in the driver; + * instead, it is good to drop such packets in mac80211 + * after incrementing the replay counters. + */ + /* fallthrough */ + default: + /* TODO: Review other errors and process them to mac80211 + * as appropriate. + */ + drop = 1; + break; + } + + return drop; +} + +int +qwx_dp_rx_h_rxdma_err(struct qwx_softc *sc, struct qwx_rx_msdu *msdu) +{ + int drop = 0; +#if 0 + ar->ab->soc_stats.rxdma_error[rxcb->err_code]++; +#endif + switch (msdu->err_code) { + case HAL_REO_ENTR_RING_RXDMA_ECODE_TKIP_MIC_ERR: + drop = 1; /* OpenBSD uses TKIP in software crypto mode only */ + break; + default: + /* TODO: Review other rxdma error code to check if anything is + * worth reporting to mac80211 + */ + drop = 1; + break; + } + + return drop; +} + +void +qwx_dp_rx_wbm_err(struct qwx_softc *sc, struct qwx_rx_msdu *msdu, + struct qwx_rx_msdu_list *msdu_list) +{ + int drop = 1; + + switch (msdu->err_rel_src) { + case HAL_WBM_REL_SRC_MODULE_REO: + drop = qwx_dp_rx_h_reo_err(sc, msdu, msdu_list); + break; + case HAL_WBM_REL_SRC_MODULE_RXDMA: + drop = qwx_dp_rx_h_rxdma_err(sc, msdu); + break; + default: + /* msdu will get freed */ + break; + } + + if (drop) { + m_freem(msdu->m); + msdu->m = NULL; + return; + } + + qwx_dp_rx_deliver_msdu(sc, msdu); +} + int qwx_dp_rx_process_wbm_err(struct qwx_softc *sc) { - return 0; + struct ieee80211com *ic = &sc->sc_ic; + struct ifnet *ifp = &ic->ic_if; + struct qwx_dp *dp = &sc->dp; + struct dp_rxdma_ring *rx_ring; + struct hal_rx_wbm_rel_info err_info; + struct hal_srng *srng; + struct qwx_rx_msdu_list msdu_list[MAX_RADIOS]; + struct qwx_rx_msdu *msdu; + struct mbuf *m; + struct qwx_rx_data *rx_data; + uint32_t *rx_desc; + int idx, mac_id; + int num_buffs_reaped[MAX_RADIOS] = {0}; + int total_num_buffs_reaped = 0; + int ret, i; + + for (i = 0; i < sc->num_radios; i++) + TAILQ_INIT(&msdu_list[i]); + + srng = &sc->hal.srng_list[dp->rx_rel_ring.ring_id]; +#ifdef notyet + spin_lock_bh(&srng->lock); +#endif + qwx_hal_srng_access_begin(sc, srng); + + while ((rx_desc = qwx_hal_srng_dst_get_next_entry(sc, srng))) { + ret = qwx_hal_wbm_desc_parse_err(rx_desc, &err_info); + if (ret) { + printf("%s: failed to parse rx error in wbm_rel " + "ring desc %d\n", sc->sc_dev.dv_xname, ret); + continue; + } + + idx = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, err_info.cookie); + mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, err_info.cookie); + + if (mac_id >= MAX_RADIOS) + continue; + + rx_ring = &sc->pdev_dp.rx_refill_buf_ring; + if (idx >= rx_ring->bufs_max) + continue; + rx_data = &rx_ring->rx_data[idx]; + + bus_dmamap_unload(sc->sc_dmat, rx_data->map); + m = rx_data->m; + rx_data->m = NULL; + + num_buffs_reaped[mac_id]++; + total_num_buffs_reaped++; + + if (err_info.push_reason != + HAL_REO_DEST_RING_PUSH_REASON_ERR_DETECTED) { + m_freem(m); + continue; + } + + msdu = &rx_data->rx_msdu; + memset(&msdu->rxi, 0, sizeof(msdu->rxi)); + msdu->m = m; + msdu->err_rel_src = err_info.err_rel_src; + msdu->err_code = err_info.err_code; + msdu->rx_desc = mtod(m, struct hal_rx_desc *); + TAILQ_INSERT_TAIL(&msdu_list[mac_id], msdu, entry); + } + + qwx_hal_srng_access_end(sc, srng); +#ifdef notyet + spin_unlock_bh(&srng->lock); +#endif + if (!total_num_buffs_reaped) + goto done; + + for (i = 0; i < sc->num_radios; i++) { + if (!num_buffs_reaped[i]) + continue; + + rx_ring = &sc->pdev_dp.rx_refill_buf_ring; + qwx_dp_rxbufs_replenish(sc, i, rx_ring, num_buffs_reaped[i], + sc->hw_params.hal_params->rx_buf_rbm); + } + + for (i = 0; i < sc->num_radios; i++) { + while ((msdu = TAILQ_FIRST(msdu_list))) { + TAILQ_REMOVE(msdu_list, msdu, entry); + if (test_bit(ATH11K_CAC_RUNNING, sc->sc_flags)) { + m_freem(msdu->m); + msdu->m = NULL; + continue; + } + qwx_dp_rx_wbm_err(sc, msdu, &msdu_list[i]); + msdu->m = NULL; + } + } +done: + ifp->if_ierrors += total_num_buffs_reaped; + + return total_num_buffs_reaped; } struct qwx_rx_msdu * @@ -15008,12 +15613,6 @@ qwx_dp_rx_h_msdu_end_l3pad(struct qwx_softc *sc, struct hal_rx_desc *desc) return sc->hw_params.hw_ops->rx_desc_get_l3_pad_bytes(desc); } -static inline uint16_t -qwx_dp_rx_h_msdu_start_msdu_len(struct qwx_softc *sc, struct hal_rx_desc *desc) -{ - return sc->hw_params.hw_ops->rx_desc_get_msdu_len(desc); -} - static inline int qwx_dp_rx_h_attn_msdu_done(struct rx_attention *attn) { @@ -15842,15 +16441,380 @@ qwx_dp_rx_process_mon_rings(struct qwx_softc *sc, int mac_id) } int -qwx_dp_process_rxdma_err(struct qwx_softc *sc) +qwx_dp_process_rxdma_err(struct qwx_softc *sc, int mac_id) { - return 0; + struct ieee80211com *ic = &sc->sc_ic; + struct ifnet *ifp = &ic->ic_if; + struct dp_srng *err_ring; + struct dp_rxdma_ring *rx_ring; + struct dp_link_desc_bank *link_desc_banks = sc->dp.link_desc_banks; + struct hal_srng *srng; + uint32_t msdu_cookies[HAL_NUM_RX_MSDUS_PER_LINK_DESC]; + enum hal_rx_buf_return_buf_manager rbm; + enum hal_reo_entr_rxdma_ecode rxdma_err_code; + struct qwx_rx_data *rx_data; + struct hal_reo_entrance_ring *entr_ring; + void *desc; + int num_buf_freed = 0; + uint64_t paddr; + uint32_t desc_bank; + void *link_desc_va; + int num_msdus; + int i, idx, srng_id; + + srng_id = sc->hw_params.hw_ops->mac_id_to_srng_id(&sc->hw_params, + mac_id); + err_ring = &sc->pdev_dp.rxdma_err_dst_ring[srng_id]; + rx_ring = &sc->pdev_dp.rx_refill_buf_ring; + + srng = &sc->hal.srng_list[err_ring->ring_id]; +#ifdef notyet + spin_lock_bh(&srng->lock); +#endif + qwx_hal_srng_access_begin(sc, srng); + + while ((desc = qwx_hal_srng_dst_get_next_entry(sc, srng))) { + qwx_hal_rx_reo_ent_paddr_get(sc, desc, &paddr, &desc_bank); + + entr_ring = (struct hal_reo_entrance_ring *)desc; + rxdma_err_code = FIELD_GET( + HAL_REO_ENTR_RING_INFO1_RXDMA_ERROR_CODE, + entr_ring->info1); +#if 0 + ab->soc_stats.rxdma_error[rxdma_err_code]++; +#endif + link_desc_va = link_desc_banks[desc_bank].vaddr + + (paddr - link_desc_banks[desc_bank].paddr); + qwx_hal_rx_msdu_link_info_get(link_desc_va, &num_msdus, + msdu_cookies, &rbm); + + for (i = 0; i < num_msdus; i++) { + idx = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, + msdu_cookies[i]); + if (idx >= rx_ring->bufs_max) + continue; + + rx_data = &rx_ring->rx_data[idx]; + + bus_dmamap_unload(sc->sc_dmat, rx_data->map); + m_freem(rx_data->m); + rx_data->m = NULL; + + num_buf_freed++; + } + + qwx_dp_rx_link_desc_return(sc, desc, + HAL_WBM_REL_BM_ACT_PUT_IN_IDLE); + } + + qwx_hal_srng_access_end(sc, srng); +#ifdef notyet + spin_unlock_bh(&srng->lock); +#endif + if (num_buf_freed) + qwx_dp_rxbufs_replenish(sc, mac_id, rx_ring, num_buf_freed, + sc->hw_params.hal_params->rx_buf_rbm); + + ifp->if_ierrors += num_buf_freed; + + return num_buf_freed; +} + +void +qwx_hal_reo_status_queue_stats(struct qwx_softc *sc, uint32_t *reo_desc, + struct hal_reo_status *status) +{ + struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; + struct hal_reo_get_queue_stats_status *desc = + (struct hal_reo_get_queue_stats_status *)tlv->value; + + status->uniform_hdr.cmd_num = + FIELD_GET(HAL_REO_STATUS_HDR_INFO0_STATUS_NUM, desc->hdr.info0); + status->uniform_hdr.cmd_status = + FIELD_GET(HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS, desc->hdr.info0); +#if 0 + ath11k_dbg(ab, ATH11K_DBG_HAL, "Queue stats status:\n"); + ath11k_dbg(ab, ATH11K_DBG_HAL, "header: cmd_num %d status %d\n", + status->uniform_hdr.cmd_num, + status->uniform_hdr.cmd_status); + ath11k_dbg(ab, ATH11K_DBG_HAL, "ssn %ld cur_idx %ld\n", + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO0_SSN, + desc->info0), + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO0_CUR_IDX, + desc->info0)); + ath11k_dbg(ab, ATH11K_DBG_HAL, "pn = [%08x, %08x, %08x, %08x]\n", + desc->pn[0], desc->pn[1], desc->pn[2], desc->pn[3]); + ath11k_dbg(ab, ATH11K_DBG_HAL, + "last_rx: enqueue_tstamp %08x dequeue_tstamp %08x\n", + desc->last_rx_enqueue_timestamp, + desc->last_rx_dequeue_timestamp); + ath11k_dbg(ab, ATH11K_DBG_HAL, + "rx_bitmap [%08x %08x %08x %08x %08x %08x %08x %08x]\n", + desc->rx_bitmap[0], desc->rx_bitmap[1], desc->rx_bitmap[2], + desc->rx_bitmap[3], desc->rx_bitmap[4], desc->rx_bitmap[5], + desc->rx_bitmap[6], desc->rx_bitmap[7]); + ath11k_dbg(ab, ATH11K_DBG_HAL, "count: cur_mpdu %ld cur_msdu %ld\n", + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO1_MPDU_COUNT, + desc->info1), + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO1_MSDU_COUNT, + desc->info1)); + ath11k_dbg(ab, ATH11K_DBG_HAL, "fwd_timeout %ld fwd_bar %ld dup_count %ld\n", + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_TIMEOUT_COUNT, + desc->info2), + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_FDTB_COUNT, + desc->info2), + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO2_DUPLICATE_COUNT, + desc->info2)); + ath11k_dbg(ab, ATH11K_DBG_HAL, "frames_in_order %ld bar_rcvd %ld\n", + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO3_FIO_COUNT, + desc->info3), + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO3_BAR_RCVD_CNT, + desc->info3)); + ath11k_dbg(ab, ATH11K_DBG_HAL, "num_mpdus %d num_msdus %d total_bytes %d\n", + desc->num_mpdu_frames, desc->num_msdu_frames, + desc->total_bytes); + ath11k_dbg(ab, ATH11K_DBG_HAL, "late_rcvd %ld win_jump_2k %ld hole_cnt %ld\n", + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_LATE_RX_MPDU, + desc->info4), + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_WINDOW_JMP2K, + desc->info4), + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO4_HOLE_COUNT, + desc->info4)); + ath11k_dbg(ab, ATH11K_DBG_HAL, "looping count %ld\n", + FIELD_GET(HAL_REO_GET_QUEUE_STATS_STATUS_INFO5_LOOPING_CNT, + desc->info5)); +#endif +} + +void +qwx_hal_reo_flush_queue_status(struct qwx_softc *sc, uint32_t *reo_desc, + struct hal_reo_status *status) +{ + struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; + struct hal_reo_flush_queue_status *desc = + (struct hal_reo_flush_queue_status *)tlv->value; + + status->uniform_hdr.cmd_num = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_STATUS_NUM, desc->hdr.info0); + status->uniform_hdr.cmd_status = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS, desc->hdr.info0); + status->u.flush_queue.err_detected = FIELD_GET( + HAL_REO_FLUSH_QUEUE_INFO0_ERR_DETECTED, desc->info0); +} + +void +qwx_hal_reo_flush_cache_status(struct qwx_softc *sc, uint32_t *reo_desc, + struct hal_reo_status *status) +{ + struct ath11k_hal *hal = &sc->hal; + struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; + struct hal_reo_flush_cache_status *desc = + (struct hal_reo_flush_cache_status *)tlv->value; + + status->uniform_hdr.cmd_num = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_STATUS_NUM, desc->hdr.info0); + status->uniform_hdr.cmd_status = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS, desc->hdr.info0); + + status->u.flush_cache.err_detected = FIELD_GET( + HAL_REO_FLUSH_CACHE_STATUS_INFO0_IS_ERR, desc->info0); + status->u.flush_cache.err_code = FIELD_GET( + HAL_REO_FLUSH_CACHE_STATUS_INFO0_BLOCK_ERR_CODE, desc->info0); + if (!status->u.flush_cache.err_code) + hal->avail_blk_resource |= BIT(hal->current_blk_index); + + status->u.flush_cache.cache_controller_flush_status_hit = FIELD_GET( + HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_STATUS_HIT, desc->info0); + + status->u.flush_cache.cache_controller_flush_status_desc_type = + FIELD_GET(HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_DESC_TYPE, + desc->info0); + status->u.flush_cache.cache_controller_flush_status_client_id = + FIELD_GET(HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_CLIENT_ID, + desc->info0); + status->u.flush_cache.cache_controller_flush_status_err = + FIELD_GET(HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_ERR, + desc->info0); + status->u.flush_cache.cache_controller_flush_status_cnt = + FIELD_GET(HAL_REO_FLUSH_CACHE_STATUS_INFO0_FLUSH_COUNT, + desc->info0); +} + +void +qwx_hal_reo_unblk_cache_status(struct qwx_softc *sc, uint32_t *reo_desc, + struct hal_reo_status *status) +{ + struct ath11k_hal *hal = &sc->hal; + struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; + struct hal_reo_unblock_cache_status *desc = + (struct hal_reo_unblock_cache_status *)tlv->value; + + status->uniform_hdr.cmd_num = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_STATUS_NUM, desc->hdr.info0); + status->uniform_hdr.cmd_status = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS, desc->hdr.info0); + + status->u.unblock_cache.err_detected = FIELD_GET( + HAL_REO_UNBLOCK_CACHE_STATUS_INFO0_IS_ERR, desc->info0); + status->u.unblock_cache.unblock_type = FIELD_GET( + HAL_REO_UNBLOCK_CACHE_STATUS_INFO0_TYPE, desc->info0); + + if (!status->u.unblock_cache.err_detected && + status->u.unblock_cache.unblock_type == + HAL_REO_STATUS_UNBLOCK_BLOCKING_RESOURCE) + hal->avail_blk_resource &= ~BIT(hal->current_blk_index); +} + +void +qwx_hal_reo_flush_timeout_list_status(struct qwx_softc *ab, uint32_t *reo_desc, + struct hal_reo_status *status) +{ + struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; + struct hal_reo_flush_timeout_list_status *desc = + (struct hal_reo_flush_timeout_list_status *)tlv->value; + + status->uniform_hdr.cmd_num = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_STATUS_NUM, desc->hdr.info0); + status->uniform_hdr.cmd_status = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS, desc->hdr.info0); + + status->u.timeout_list.err_detected = FIELD_GET( + HAL_REO_FLUSH_TIMEOUT_STATUS_INFO0_IS_ERR, desc->info0); + status->u.timeout_list.list_empty = FIELD_GET( + HAL_REO_FLUSH_TIMEOUT_STATUS_INFO0_LIST_EMPTY, desc->info0); + + status->u.timeout_list.release_desc_cnt = FIELD_GET( + HAL_REO_FLUSH_TIMEOUT_STATUS_INFO1_REL_DESC_COUNT, desc->info1); + status->u.timeout_list.fwd_buf_cnt = FIELD_GET( + HAL_REO_FLUSH_TIMEOUT_STATUS_INFO1_FWD_BUF_COUNT, desc->info1); +} + +void +qwx_hal_reo_desc_thresh_reached_status(struct qwx_softc *sc, uint32_t *reo_desc, + struct hal_reo_status *status) +{ + struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; + struct hal_reo_desc_thresh_reached_status *desc = + (struct hal_reo_desc_thresh_reached_status *)tlv->value; + + status->uniform_hdr.cmd_num = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_STATUS_NUM, desc->hdr.info0); + status->uniform_hdr.cmd_status = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS, desc->hdr.info0); + + status->u.desc_thresh_reached.threshold_idx = FIELD_GET( + HAL_REO_DESC_THRESH_STATUS_INFO0_THRESH_INDEX, desc->info0); + + status->u.desc_thresh_reached.link_desc_counter0 = FIELD_GET( + HAL_REO_DESC_THRESH_STATUS_INFO1_LINK_DESC_COUNTER0, desc->info1); + + status->u.desc_thresh_reached.link_desc_counter1 = FIELD_GET( + HAL_REO_DESC_THRESH_STATUS_INFO2_LINK_DESC_COUNTER1, desc->info2); + + status->u.desc_thresh_reached.link_desc_counter2 = FIELD_GET( + HAL_REO_DESC_THRESH_STATUS_INFO3_LINK_DESC_COUNTER2, desc->info3); + + status->u.desc_thresh_reached.link_desc_counter_sum = FIELD_GET( + HAL_REO_DESC_THRESH_STATUS_INFO4_LINK_DESC_COUNTER_SUM, + desc->info4); +} + +void +qwx_hal_reo_update_rx_reo_queue_status(struct qwx_softc *ab, uint32_t *reo_desc, + struct hal_reo_status *status) +{ + struct hal_tlv_hdr *tlv = (struct hal_tlv_hdr *)reo_desc; + struct hal_reo_status_hdr *desc = + (struct hal_reo_status_hdr *)tlv->value; + + status->uniform_hdr.cmd_num = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_STATUS_NUM, desc->info0); + status->uniform_hdr.cmd_status = FIELD_GET( + HAL_REO_STATUS_HDR_INFO0_EXEC_STATUS, desc->info0); } int qwx_dp_process_reo_status(struct qwx_softc *sc) { - return 0; + struct qwx_dp *dp = &sc->dp; + struct hal_srng *srng; + struct dp_reo_cmd *cmd, *tmp; + int found = 0, ret = 0; + uint32_t *reo_desc; + uint16_t tag; + struct hal_reo_status reo_status; + + srng = &sc->hal.srng_list[dp->reo_status_ring.ring_id]; + memset(&reo_status, 0, sizeof(reo_status)); +#ifdef notyet + spin_lock_bh(&srng->lock); +#endif + qwx_hal_srng_access_begin(sc, srng); + + while ((reo_desc = qwx_hal_srng_dst_get_next_entry(sc, srng))) { + ret = 1; + + tag = FIELD_GET(HAL_SRNG_TLV_HDR_TAG, *reo_desc); + switch (tag) { + case HAL_REO_GET_QUEUE_STATS_STATUS: + qwx_hal_reo_status_queue_stats(sc, reo_desc, + &reo_status); + break; + case HAL_REO_FLUSH_QUEUE_STATUS: + qwx_hal_reo_flush_queue_status(sc, reo_desc, + &reo_status); + break; + case HAL_REO_FLUSH_CACHE_STATUS: + qwx_hal_reo_flush_cache_status(sc, reo_desc, + &reo_status); + break; + case HAL_REO_UNBLOCK_CACHE_STATUS: + qwx_hal_reo_unblk_cache_status(sc, reo_desc, + &reo_status); + break; + case HAL_REO_FLUSH_TIMEOUT_LIST_STATUS: + qwx_hal_reo_flush_timeout_list_status(sc, reo_desc, + &reo_status); + break; + case HAL_REO_DESCRIPTOR_THRESHOLD_REACHED_STATUS: + qwx_hal_reo_desc_thresh_reached_status(sc, reo_desc, + &reo_status); + break; + case HAL_REO_UPDATE_RX_REO_QUEUE_STATUS: + qwx_hal_reo_update_rx_reo_queue_status(sc, reo_desc, + &reo_status); + break; + default: + printf("%s: Unknown reo status type %d\n", + sc->sc_dev.dv_xname, tag); + continue; + } +#ifdef notyet + spin_lock_bh(&dp->reo_cmd_lock); +#endif + TAILQ_FOREACH_SAFE(cmd, &dp->reo_cmd_list, entry, tmp) { + if (reo_status.uniform_hdr.cmd_num == cmd->cmd_num) { + found = 1; + TAILQ_REMOVE(&dp->reo_cmd_list, cmd, entry); + break; + } + } +#ifdef notyet + spin_unlock_bh(&dp->reo_cmd_lock); +#endif + if (found) { + cmd->handler(dp, (void *)&cmd->data, + reo_status.uniform_hdr.cmd_status); + free(cmd, M_DEVBUF, sizeof(*cmd)); + } + found = 0; + } + + qwx_hal_srng_access_end(sc, srng); +#ifdef notyet + spin_unlock_bh(&srng->lock); +#endif + return ret; } int @@ -15908,7 +16872,7 @@ qwx_dp_service_srng(struct qwx_softc *sc, int grp_id) (1 << (id))) == 0) continue; - if (qwx_dp_process_rxdma_err(sc)) + if (qwx_dp_process_rxdma_err(sc, id)) ret = 1; qwx_dp_rxbufs_replenish(sc, id, &dp->rx_refill_buf_ring, @@ -22381,6 +23345,7 @@ qwx_dp_tx(struct qwx_softc *sc, struct qwx_vif *arvif, uint8_t pdev_id, } tx_data->m = m; + tx_data->ni = ni; qwx_hal_tx_cmd_desc_setup(sc, hal_tcl_desc + sizeof(struct hal_tlv_hdr), &ti); @@ -22441,7 +23406,7 @@ free_peer: int qwx_mac_mgmt_tx_wmi(struct qwx_softc *sc, struct qwx_vif *arvif, - uint8_t pdev_id, struct mbuf *m) + uint8_t pdev_id, struct ieee80211_node *ni, struct mbuf *m) { struct qwx_txmgmt_queue *txmgmt = &arvif->txmgmt; struct qwx_tx_data *tx_data; @@ -22495,6 +23460,7 @@ qwx_mac_mgmt_tx_wmi(struct qwx_softc *sc, struct qwx_vif *arvif, sc->sc_dev.dv_xname, ret); goto err_unmap_buf; } + tx_data->ni = ni; txmgmt->cur = (txmgmt->cur + 1) % nitems(txmgmt->data); txmgmt->queued++; @@ -23058,6 +24024,7 @@ qwx_auth(struct qwx_softc *sc) } qwx_recalculate_mgmt_rate(sc, ni, arvif->vdev_id, pdev->pdev_id); + ni->ni_txrate = 0; ret = qwx_mac_station_add(sc, arvif, pdev->pdev_id, ni); if (ret) @@ -23283,8 +24250,13 @@ qwx_run(struct qwx_softc *sc) int qwx_run_stop(struct qwx_softc *sc) { + struct ieee80211com *ic = &sc->sc_ic; + sc->ops.irq_disable(sc); + if (ic->ic_opmode == IEEE80211_M_STA) + ic->ic_bss->ni_txrate = 0; + printf("%s: not implemented\n", __func__); return ENOTSUP; } diff --git a/sys/dev/ic/qwxvar.h b/sys/dev/ic/qwxvar.h index 7bb50bac8..73411943b 100644 --- a/sys/dev/ic/qwxvar.h +++ b/sys/dev/ic/qwxvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: qwxvar.h,v 1.14 2024/02/08 14:35:07 stsp Exp $ */ +/* $OpenBSD: qwxvar.h,v 1.18 2024/02/09 14:09:19 stsp Exp $ */ /* * Copyright (c) 2018-2019 The Linux Foundation. @@ -662,6 +662,100 @@ struct hal_srng_config { #define QWX_NUM_SRNG_CFG 21 +struct hal_reo_status_header { + uint16_t cmd_num; + enum hal_reo_cmd_status cmd_status; + uint16_t cmd_exe_time; + uint32_t timestamp; +}; + +struct hal_reo_status_queue_stats { + uint16_t ssn; + uint16_t curr_idx; + uint32_t pn[4]; + uint32_t last_rx_queue_ts; + uint32_t last_rx_dequeue_ts; + uint32_t rx_bitmap[8]; /* Bitmap from 0-255 */ + uint32_t curr_mpdu_cnt; + uint32_t curr_msdu_cnt; + uint16_t fwd_due_to_bar_cnt; + uint16_t dup_cnt; + uint32_t frames_in_order_cnt; + uint32_t num_mpdu_processed_cnt; + uint32_t num_msdu_processed_cnt; + uint32_t total_num_processed_byte_cnt; + uint32_t late_rx_mpdu_cnt; + uint32_t reorder_hole_cnt; + uint8_t timeout_cnt; + uint8_t bar_rx_cnt; + uint8_t num_window_2k_jump_cnt; +}; + +struct hal_reo_status_flush_queue { + bool err_detected; +}; + +enum hal_reo_status_flush_cache_err_code { + HAL_REO_STATUS_FLUSH_CACHE_ERR_CODE_SUCCESS, + HAL_REO_STATUS_FLUSH_CACHE_ERR_CODE_IN_USE, + HAL_REO_STATUS_FLUSH_CACHE_ERR_CODE_NOT_FOUND, +}; + +struct hal_reo_status_flush_cache { + bool err_detected; + enum hal_reo_status_flush_cache_err_code err_code; + bool cache_controller_flush_status_hit; + uint8_t cache_controller_flush_status_desc_type; + uint8_t cache_controller_flush_status_client_id; + uint8_t cache_controller_flush_status_err; + uint8_t cache_controller_flush_status_cnt; +}; + +enum hal_reo_status_unblock_cache_type { + HAL_REO_STATUS_UNBLOCK_BLOCKING_RESOURCE, + HAL_REO_STATUS_UNBLOCK_ENTIRE_CACHE_USAGE, +}; + +struct hal_reo_status_unblock_cache { + bool err_detected; + enum hal_reo_status_unblock_cache_type unblock_type; +}; + +struct hal_reo_status_flush_timeout_list { + bool err_detected; + bool list_empty; + uint16_t release_desc_cnt; + uint16_t fwd_buf_cnt; +}; + +enum hal_reo_threshold_idx { + HAL_REO_THRESHOLD_IDX_DESC_COUNTER0, + HAL_REO_THRESHOLD_IDX_DESC_COUNTER1, + HAL_REO_THRESHOLD_IDX_DESC_COUNTER2, + HAL_REO_THRESHOLD_IDX_DESC_COUNTER_SUM, +}; + +struct hal_reo_status_desc_thresh_reached { + enum hal_reo_threshold_idx threshold_idx; + uint32_t link_desc_counter0; + uint32_t link_desc_counter1; + uint32_t link_desc_counter2; + uint32_t link_desc_counter_sum; +}; + +struct hal_reo_status { + struct hal_reo_status_header uniform_hdr; + uint8_t loop_cnt; + union { + struct hal_reo_status_queue_stats queue_stats; + struct hal_reo_status_flush_queue flush_queue; + struct hal_reo_status_flush_cache flush_cache; + struct hal_reo_status_unblock_cache unblock_cache; + struct hal_reo_status_flush_timeout_list timeout_list; + struct hal_reo_status_desc_thresh_reached desc_thresh_reached; + } u; +}; + /* HAL context to be used to access SRNG APIs (currently used by data path * and transport (CE) modules) */ @@ -777,6 +871,7 @@ struct qwx_rx_data { }; struct qwx_tx_data { + struct ieee80211_node *ni; struct mbuf *m; bus_dmamap_t map; uint8_t eid; @@ -1380,6 +1475,15 @@ struct hal_rx_user_status { uint32_t mpdu_err_byte_count; }; +struct hal_rx_wbm_rel_info { + uint32_t cookie; + enum hal_wbm_rel_src_module err_rel_src; + enum hal_reo_dest_ring_push_reason push_reason; + uint32_t err_code; + int first_msdu; + int last_msdu; +}; + #define HAL_INVALID_PEERID 0xffff #define VHT_SIG_SU_NSS_MASK 0x7 @@ -1772,7 +1876,6 @@ struct qwx_softc { struct qmi_wlanfw_request_mem_ind_msg_v01 *sc_req_mem_ind; -#if NBPFILTER > 0 caddr_t sc_drvbpf; union { @@ -1788,7 +1891,6 @@ struct qwx_softc { } sc_txtapu; #define sc_txtap sc_txtapu.th int sc_txtap_len; -#endif }; int qwx_ce_intr(void *); diff --git a/sys/dev/pci/if_qwx_pci.c b/sys/dev/pci/if_qwx_pci.c index fea6df0a0..5e0bc0d17 100644 --- a/sys/dev/pci/if_qwx_pci.c +++ b/sys/dev/pci/if_qwx_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_qwx_pci.c,v 1.6 2024/02/05 10:45:47 kettenis Exp $ */ +/* $OpenBSD: if_qwx_pci.c,v 1.8 2024/02/09 14:57:36 bluhm Exp $ */ /* * Copyright 2023 Stefan Sperling @@ -50,10 +50,13 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "bpfilter.h" + #include #include #include #include +#include #include #include #include diff --git a/sys/dev/pci/if_vmx.c b/sys/dev/pci/if_vmx.c index 30e5b124d..4a9c76235 100644 --- a/sys/dev/pci/if_vmx.c +++ b/sys/dev/pci/if_vmx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vmx.c,v 1.79 2023/11/10 15:51:24 bluhm Exp $ */ +/* $OpenBSD: if_vmx.c,v 1.80 2024/02/09 15:22:41 jan Exp $ */ /* * Copyright (c) 2013 Tsubai Masanari @@ -404,8 +404,10 @@ vmxnet3_attach(struct device *parent, struct device *self, void *aux) if (sc->sc_ds->upt_features & UPT1_F_CSUM) ifp->if_capabilities |= IFCAP_CSUM_TCPv4 | IFCAP_CSUM_UDPv4; #endif +#if NVLAN > 0 if (sc->sc_ds->upt_features & UPT1_F_VLAN) ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING; +#endif ifq_init_maxlen(&ifp->if_snd, NTXDESC); @@ -503,7 +505,10 @@ vmxnet3_dma_init(struct vmxnet3_softc *sc) #endif ds->vmxnet3_revision = 1; ds->upt_version = 1; - ds->upt_features = UPT1_F_CSUM | UPT1_F_VLAN; + ds->upt_features = UPT1_F_CSUM; +#if NVLAN > 0 + ds->upt_features |= UPT1_F_VLAN; +#endif ds->driver_data = ~0ULL; ds->driver_data_len = 0; ds->queue_shared = qs_pa; @@ -1117,11 +1122,13 @@ vmxnet3_rxintr(struct vmxnet3_softc *sc, struct vmxnet3_rxqueue *rq) m->m_pkthdr.len = m->m_len = len; vmxnet3_rx_csum(rxcd, m); +#if NVLAN > 0 if (letoh32(rxcd->rxc_word2 & VMXNET3_RXC_VLAN)) { m->m_flags |= M_VLANTAG; m->m_pkthdr.ether_vtag = letoh32((rxcd->rxc_word2 >> VMXNET3_RXC_VLANTAG_S) & VMXNET3_RXC_VLANTAG_M); } +#endif if (((letoh32(rxcd->rxc_word0) >> VMXNET3_RXC_RSSTYPE_S) & VMXNET3_RXC_RSSTYPE_M) != VMXNET3_RXC_RSSTYPE_NONE) { m->m_pkthdr.ph_flowid = letoh32(rxcd->rxc_word1); @@ -1462,11 +1469,13 @@ vmxnet3_start(struct ifqueue *ifq) } txd->tx_word3 = htole32(VMXNET3_TX_EOP | VMXNET3_TX_COMPREQ); +#if NVLAN > 0 if (ISSET(m->m_flags, M_VLANTAG)) { sop->tx_word3 |= htole32(VMXNET3_TX_VTAG_MODE); sop->tx_word3 |= htole32((m->m_pkthdr.ether_vtag & VMXNET3_TX_VLANTAG_M) << VMXNET3_TX_VLANTAG_S); } +#endif ring->prod = prod; /* Change the ownership by flipping the "generation" bit */ diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index e1669bafe..f6f98b734 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.121 2023/10/17 00:04:02 cheloha Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.122 2024/02/09 17:42:18 cheloha Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -50,11 +50,6 @@ #include #include -#include "dt.h" -#if NDT > 0 -#include -#endif - /* * Clock handling routines. * @@ -145,12 +140,6 @@ initclocks(void) void hardclock(struct clockframe *frame) { -#if NDT > 0 - DT_ENTER(profile, NULL); - if (CPU_IS_PRIMARY(curcpu())) - DT_ENTER(interval, NULL); -#endif - /* * If we are not the primary CPU, we're not allowed to do * any more work. diff --git a/sys/kern/kern_clockintr.c b/sys/kern/kern_clockintr.c index f52ddc37f..4141a2bbe 100644 --- a/sys/kern/kern_clockintr.c +++ b/sys/kern/kern_clockintr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clockintr.c,v 1.64 2024/01/24 19:23:38 cheloha Exp $ */ +/* $OpenBSD: kern_clockintr.c,v 1.66 2024/02/09 16:52:58 cheloha Exp $ */ /* * Copyright (c) 2003 Dale Rahn * Copyright (c) 2020 Mark Kettenis @@ -31,6 +31,7 @@ #include #include +void clockintr_cancel_locked(struct clockintr *); void clockintr_hardclock(struct clockrequest *, void *, void *); void clockintr_schedule_locked(struct clockintr *, uint64_t); void clockqueue_intrclock_install(struct clockintr_queue *, @@ -226,6 +227,12 @@ clockintr_dispatch(void *frame) CLR(request->cr_flags, CR_RESCHEDULE); clockqueue_pend_insert(cq, cl, request->cr_expiration); } + if (ISSET(cq->cq_flags, CQ_NEED_WAKEUP)) { + CLR(cq->cq_flags, CQ_NEED_WAKEUP); + mtx_leave(&cq->cq_mtx); + wakeup(&cq->cq_running); + mtx_enter(&cq->cq_mtx); + } run++; } @@ -317,9 +324,20 @@ void clockintr_cancel(struct clockintr *cl) { struct clockintr_queue *cq = cl->cl_queue; - int was_next; mtx_enter(&cq->cq_mtx); + clockintr_cancel_locked(cl); + mtx_leave(&cq->cq_mtx); +} + +void +clockintr_cancel_locked(struct clockintr *cl) +{ + struct clockintr_queue *cq = cl->cl_queue; + int was_next; + + MUTEX_ASSERT_LOCKED(&cq->cq_mtx); + if (ISSET(cl->cl_flags, CLST_PENDING)) { was_next = cl == TAILQ_FIRST(&cq->cq_pend); clockqueue_pend_delete(cq, cl); @@ -332,7 +350,6 @@ clockintr_cancel(struct clockintr *cl) } if (cl == cq->cq_running) SET(cq->cq_flags, CQ_IGNORE_REQUEST); - mtx_leave(&cq->cq_mtx); } void @@ -341,15 +358,41 @@ clockintr_bind(struct clockintr *cl, struct cpu_info *ci, { struct clockintr_queue *cq = &ci->ci_queue; + splassert(IPL_NONE); + KASSERT(cl->cl_queue == NULL); + + mtx_enter(&cq->cq_mtx); cl->cl_arg = arg; cl->cl_func = func; cl->cl_queue = cq; - - mtx_enter(&cq->cq_mtx); TAILQ_INSERT_TAIL(&cq->cq_all, cl, cl_alink); mtx_leave(&cq->cq_mtx); } +void +clockintr_unbind(struct clockintr *cl, uint32_t flags) +{ + struct clockintr_queue *cq = cl->cl_queue; + + KASSERT(!ISSET(flags, ~CL_FLAG_MASK)); + + mtx_enter(&cq->cq_mtx); + + clockintr_cancel_locked(cl); + + cl->cl_arg = NULL; + cl->cl_func = NULL; + cl->cl_queue = NULL; + TAILQ_REMOVE(&cq->cq_all, cl, cl_alink); + + if (ISSET(flags, CL_BARRIER) && cl == cq->cq_running) { + SET(cq->cq_flags, CQ_NEED_WAKEUP); + msleep_nsec(&cq->cq_running, &cq->cq_mtx, PWAIT | PNORELOCK, + "clkbar", INFSLP); + } else + mtx_leave(&cq->cq_mtx); +} + void clockintr_schedule(struct clockintr *cl, uint64_t expiration) { diff --git a/sys/net/route.c b/sys/net/route.c index ae8867da4..bb9c7b050 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.430 2024/02/07 23:52:20 bluhm Exp $ */ +/* $OpenBSD: route.c,v 1.431 2024/02/09 14:02:11 bluhm Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -201,7 +201,7 @@ route_init(void) #endif } -void +int route_cache(struct route *ro, struct in_addr addr, u_int rtableid) { u_long gen; @@ -215,7 +215,7 @@ route_cache(struct route *ro, struct in_addr addr, u_int rtableid) ro->ro_dst.sa_family == AF_INET && satosin(&ro->ro_dst)->sin_addr.s_addr == addr.s_addr) { ipstat_inc(ips_rtcachehit); - return; + return (0); } ipstat_inc(ips_rtcachemiss); @@ -228,10 +228,12 @@ route_cache(struct route *ro, struct in_addr addr, u_int rtableid) 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; + + return (ESRCH); } #ifdef INET6 -void +int route6_cache(struct route_in6 *ro, const struct in6_addr *addr, u_int rtableid) { @@ -246,7 +248,7 @@ route6_cache(struct route_in6 *ro, const struct in6_addr *addr, ro->ro_dst.sin6_family == AF_INET6 && IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, addr)) { ip6stat_inc(ip6s_rtcachehit); - return; + return (0); } ip6stat_inc(ip6s_rtcachemiss); @@ -259,6 +261,8 @@ route6_cache(struct route_in6 *ro, const struct in6_addr *addr, ro->ro_dst.sin6_family = AF_INET6; ro->ro_dst.sin6_len = sizeof(struct sockaddr_in6); ro->ro_dst.sin6_addr = *addr; + + return (ESRCH); } #endif diff --git a/sys/netinet/in.h b/sys/netinet/in.h index 65110f27e..7b75fe8a7 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in.h,v 1.146 2024/02/05 12:52:11 aoyama Exp $ */ +/* $OpenBSD: in.h,v 1.147 2024/02/09 14:02:11 bluhm Exp $ */ /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ /* @@ -789,7 +789,7 @@ void in_len2mask(struct in_addr *, int); int in_nam2sin(const struct mbuf *, struct sockaddr_in **); int in_sa2sin(struct sockaddr *, struct sockaddr_in **); -void route_cache(struct route *, struct in_addr, u_int); +int route_cache(struct route *, struct in_addr, u_int); char *inet_ntoa(struct in_addr); int inet_nat64(int, const void *, void *, const void *, u_int8_t); diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 456135a72..2acf37e1b 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.290 2024/02/07 23:40:40 bluhm Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.291 2024/02/09 14:02:11 bluhm Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -918,8 +918,7 @@ in_pcbrtentry(struct inpcb *inp) if (inp->inp_faddr.s_addr == INADDR_ANY) return (NULL); - route_cache(ro, inp->inp_faddr, inp->inp_rtableid); - if (ro->ro_rt == NULL) { + if (route_cache(ro, inp->inp_faddr, inp->inp_rtableid)) { ro->ro_rt = rtalloc_mpath(&ro->ro_dst, &inp->inp_laddr.s_addr, ro->ro_tableid); } @@ -941,8 +940,6 @@ in_pcbselsrc(struct in_addr *insrc, struct sockaddr_in *sin, const struct in_addr *laddr = &inp->inp_laddr; u_int rtableid = inp->inp_rtableid; struct sockaddr *ip4_source = NULL; - - struct sockaddr_in *sin2; struct in_ifaddr *ia = NULL; /* @@ -984,25 +981,9 @@ in_pcbselsrc(struct in_addr *insrc, struct sockaddr_in *sin, * If route is known or can be allocated now, * our src addr is taken from the i/f, else punt. */ - if (!rtisvalid(ro->ro_rt) || (ro->ro_tableid != rtableid) || - (satosin(&ro->ro_dst)->sin_addr.s_addr != sin->sin_addr.s_addr)) { - rtfree(ro->ro_rt); - ro->ro_rt = NULL; - } - if (ro->ro_rt == NULL) { + if (route_cache(ro, sin->sin_addr, rtableid)) { /* No route yet, so try to acquire one */ - ro->ro_dst.sa_family = AF_INET; - ro->ro_dst.sa_len = sizeof(struct sockaddr_in); - satosin(&ro->ro_dst)->sin_addr = sin->sin_addr; - ro->ro_tableid = rtableid; ro->ro_rt = rtalloc_mpath(&ro->ro_dst, NULL, ro->ro_tableid); - - /* - * It is important to zero out the rest of the - * struct sockaddr_in when mixing v6 & v4! - */ - sin2 = satosin(&ro->ro_dst); - memset(sin2->sin_zero, 0, sizeof(sin2->sin_zero)); } /* diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h index 771f26c9c..da0256128 100644 --- a/sys/netinet6/in6.h +++ b/sys/netinet6/in6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.h,v 1.114 2024/02/07 23:40:40 bluhm Exp $ */ +/* $OpenBSD: in6.h,v 1.115 2024/02/09 14:02:12 bluhm Exp $ */ /* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ /* @@ -428,7 +428,7 @@ int in6_mask2len(struct in6_addr *, u_char *); int in6_nam2sin6(const struct mbuf *, struct sockaddr_in6 **); int in6_sa2sin6(struct sockaddr *, struct sockaddr_in6 **); -void route6_cache(struct route_in6 *, const struct in6_addr *, u_int); +int route6_cache(struct route_in6 *, const struct in6_addr *, u_int); struct ip6_pktopts; struct ip6_moptions; diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 0be0c4587..ab7acb7d7 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_pcb.c,v 1.135 2024/02/07 23:40:40 bluhm Exp $ */ +/* $OpenBSD: in6_pcb.c,v 1.136 2024/02/09 14:02:12 bluhm Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -568,8 +568,7 @@ in6_pcbrtentry(struct inpcb *inp) if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) return (NULL); - route6_cache(ro, &inp->inp_faddr6, inp->inp_rtableid); - if (ro->ro_rt == NULL) { + if (route6_cache(ro, &inp->inp_faddr6, inp->inp_rtableid)) { ro->ro_rt = rtalloc_mpath(sin6tosa(&ro->ro_dst), &inp->inp_laddr6.s6_addr32[0], ro->ro_tableid); } diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 78205a08d..d34af5065 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_src.c,v 1.92 2024/02/07 23:40:40 bluhm Exp $ */ +/* $OpenBSD: in6_src.c,v 1.93 2024/02/09 14:02:12 bluhm Exp $ */ /* $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $ */ /* @@ -179,8 +179,7 @@ in6_pcbselsrc(const struct in6_addr **in6src, struct sockaddr_in6 *dstsock, * If route is known or can be allocated now, * our src addr is taken from the i/f, else punt. */ - route6_cache(ro, dst, rtableid); - if (ro->ro_rt == NULL) { + if (route6_cache(ro, dst, rtableid)) { ro->ro_rt = rtalloc(sin6tosa(&ro->ro_dst), RT_RESOLVE, ro->ro_tableid); } @@ -306,8 +305,7 @@ in6_selectroute(const struct in6_addr *dst, struct ip6_pktopts *opts, * a new one. */ if (ro) { - route6_cache(ro, dst, rtableid); - if (ro->ro_rt == NULL) { + if (route6_cache(ro, dst, rtableid)) { /* No route yet, so try to acquire one */ ro->ro_rt = rtalloc_mpath(sin6tosa(&ro->ro_dst), NULL, ro->ro_tableid); diff --git a/sys/sys/clockintr.h b/sys/sys/clockintr.h index 6395bc789..66b10420f 100644 --- a/sys/sys/clockintr.h +++ b/sys/sys/clockintr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: clockintr.h,v 1.25 2024/01/24 19:23:38 cheloha Exp $ */ +/* $OpenBSD: clockintr.h,v 1.26 2024/02/09 16:52:58 cheloha Exp $ */ /* * Copyright (c) 2020-2022 Scott Cheloha * @@ -113,7 +113,8 @@ struct clockintr_queue { #define CQ_INIT 0x00000001 /* clockintr_cpu_init() done */ #define CQ_INTRCLOCK 0x00000002 /* intrclock installed */ #define CQ_IGNORE_REQUEST 0x00000004 /* ignore callback requests */ -#define CQ_STATE_MASK 0x00000007 +#define CQ_NEED_WAKEUP 0x00000008 /* caller at barrier */ +#define CQ_STATE_MASK 0x0000000f void clockintr_cpu_init(const struct intrclock *); int clockintr_dispatch(void *); @@ -123,12 +124,16 @@ void clockintr_trigger(void); * Kernel API */ +#define CL_BARRIER 0x00000001 /* block if callback is running */ +#define CL_FLAG_MASK 0x00000001 + uint64_t clockintr_advance(struct clockintr *, uint64_t); void clockintr_bind(struct clockintr *, struct cpu_info *, void (*)(struct clockrequest *, void *, void *), void *); void clockintr_cancel(struct clockintr *); void clockintr_schedule(struct clockintr *, uint64_t); void clockintr_stagger(struct clockintr *, uint64_t, uint32_t, uint32_t); +void clockintr_unbind(struct clockintr *, uint32_t); uint64_t clockrequest_advance(struct clockrequest *, uint64_t); uint64_t clockrequest_advance_random(struct clockrequest *, uint64_t, uint32_t); void clockqueue_init(struct clockintr_queue *); diff --git a/usr.bin/bgplg/bgplg.c b/usr.bin/bgplg/bgplg.c index fc825bc5b..09306ff66 100644 --- a/usr.bin/bgplg/bgplg.c +++ b/usr.bin/bgplg/bgplg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgplg.c,v 1.19 2018/03/05 10:53:37 denis Exp $ */ +/* $OpenBSD: bgplg.c,v 1.20 2024/02/09 12:56:53 claudio Exp $ */ /* * Copyright (c) 2005, 2006 Reyk Floeter @@ -260,17 +260,15 @@ main(void) printf("Content-Type: %s\n" "Cache-Control: no-cache\n\n" - "\n" - "\n" - "\n" + "\n" + "\n" "\n" "%s\n", CONTENT_TYPE, myname); if (stat(INC_STYLE, &st) == 0) { - printf("\n"); + printf("\n"); } if (stat(INC_HEAD, &st) != 0 || lg_incl(INC_HEAD) != 0) { printf("\n" @@ -308,8 +306,8 @@ main(void) } printf("\n" - "\n" - "\n" + "\n" + "\n" "\n" "\n" "
\n", req ? req : "");
diff --git a/usr.bin/bgplg/bgplg.foot b/usr.bin/bgplg/bgplg.foot
index d5ce3a7ed..f6a5ddb5d 100644
--- a/usr.bin/bgplg/bgplg.foot
+++ b/usr.bin/bgplg/bgplg.foot
@@ -1,2 +1,2 @@
 
-
+
diff --git a/usr.bin/bgplg/bgplg.head b/usr.bin/bgplg/bgplg.head index b31a9ed53..05867cab1 100644 --- a/usr.bin/bgplg/bgplg.head +++ b/usr.bin/bgplg/bgplg.head @@ -2,5 +2,5 @@
-OpenBGPD +OpenBGPD diff --git a/usr.bin/bgplg/index.html b/usr.bin/bgplg/index.html index 32bebcbc8..8aa690554 100644 --- a/usr.bin/bgplg/index.html +++ b/usr.bin/bgplg/index.html @@ -1,9 +1,8 @@ - - - + + bgplg... - +

bgplg...

diff --git a/usr.sbin/radiusd/radiusd.c b/usr.sbin/radiusd/radiusd.c index 7d87d04ab..3fc7ad0e4 100644 --- a/usr.sbin/radiusd/radiusd.c +++ b/usr.sbin/radiusd/radiusd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd.c,v 1.34 2024/01/08 04:16:48 yasuoka Exp $ */ +/* $OpenBSD: radiusd.c,v 1.35 2024/02/09 07:46:32 yasuoka Exp $ */ /* * Copyright (c) 2013, 2023 Internet Initiative Japan Inc. @@ -54,12 +54,14 @@ static int radiusd_start(struct radiusd *); static void radiusd_stop(struct radiusd *); static void radiusd_free(struct radiusd *); static void radiusd_listen_on_event(int, short, void *); +static void radiusd_listen_handle_packet(struct radiusd_listen *, + RADIUS_PACKET *, struct sockaddr *, socklen_t); static void radiusd_on_sigterm(int, short, void *); static void radiusd_on_sigint(int, short, void *); static void radiusd_on_sighup(int, short, void *); static void radiusd_on_sigchld(int, short, void *); -static void radius_query_request(struct radius_query *); -static void radius_query_response(struct radius_query *); +static void raidus_query_access_request(struct radius_query *); +static void radius_query_access_response(struct radius_query *); static const char *radius_code_string(int); static int radiusd_access_response_fixup (struct radius_query *); @@ -350,19 +352,12 @@ radiusd_free(struct radiusd *radiusd) static void radiusd_listen_on_event(int fd, short evmask, void *ctx) { - int i, sz, req_id, req_code; - struct radiusd_listen *listn = ctx; - static u_char buf[65535]; - static char username[256]; + int sz; + RADIUS_PACKET *packet = NULL; struct sockaddr_storage peer; socklen_t peersz; - RADIUS_PACKET *packet = NULL; - char peerstr[NI_MAXHOST + NI_MAXSERV + 30]; - struct radiusd_authentication *authen; - struct radiusd_client *client; - struct radius_query *q; -#define in(_x) (((struct sockaddr_in *)_x)->sin_addr) -#define in6(_x) (((struct sockaddr_in6 *)_x)->sin6_addr) + struct radiusd_listen *listn = ctx; + static u_char buf[65535]; if (evmask & EV_READ) { peersz = sizeof(peer); @@ -371,115 +366,128 @@ radiusd_listen_on_event(int fd, short evmask, void *ctx) if (errno == EAGAIN) return; log_warn("%s: recvfrom() failed", __func__); - goto on_error; + return; } RADIUSD_ASSERT(peer.ss_family == AF_INET || peer.ss_family == AF_INET6); - - /* prepare some information about this messages */ - if (addrport_tostring((struct sockaddr *)&peer, peersz, - peerstr, sizeof(peerstr)) == NULL) { - log_warn("%s: getnameinfo() failed", __func__); - goto on_error; - } - if ((packet = radius_convert_packet(buf, sz)) == NULL) { + if ((packet = radius_convert_packet(buf, sz)) == NULL) log_warn("%s: radius_convert_packet() failed", __func__); - goto on_error; - } - req_id = radius_get_id(packet); - req_code = radius_get_code(packet); + else + radiusd_listen_handle_packet(listn, packet, + (struct sockaddr *)&peer, peersz); + } +} - /* - * Find a matching `client' entry - */ - TAILQ_FOREACH(client, &listn->radiusd->client, next) { - if (client->af != peer.ss_family) - continue; - if (peer.ss_family == AF_INET && - IPv4_cmp(&((struct sockaddr_in *)&peer)->sin_addr, - &client->addr, &client->mask)) - break; - else if (peer.ss_family == AF_INET6 && - IPv6_cmp(&((struct sockaddr_in6 *)&peer)->sin6_addr, - &client->addr, &client->mask)) - break; - } - if (client == NULL) { - log_warnx("Received %s(code=%d) from %s id=%d: " - "no `client' matches", radius_code_string(req_code), - req_code, peerstr, req_id); - goto on_error; - } +static void +radiusd_listen_handle_packet(struct radiusd_listen *listn, + RADIUS_PACKET *packet, struct sockaddr *peer, socklen_t peerlen) +{ + int i, req_id, req_code; + static char username[256]; + char peerstr[NI_MAXHOST + NI_MAXSERV + 30]; + struct radiusd_authentication *authen; + struct radiusd_client *client; + struct radius_query *q = NULL; +#define in(_x) (((struct sockaddr_in *)_x)->sin_addr) +#define in6(_x) (((struct sockaddr_in6 *)_x)->sin6_addr) - /* Check the client's Message-Authenticator */ - if (client->msgauth_required && - !radius_has_attr(packet, - RADIUS_TYPE_MESSAGE_AUTHENTICATOR)) { - log_warnx("Received %s(code=%d) from %s id=%d: " - "no message authenticator", - radius_code_string(req_code), req_code, peerstr, - req_id); - goto on_error; - } + req_id = radius_get_id(packet); + req_code = radius_get_code(packet); + /* prepare some information about this messages */ + if (addrport_tostring(peer, peerlen, peerstr, sizeof(peerstr)) == + NULL) { + log_warn("%s: getnameinfo() failed", __func__); + goto on_error; + } - if (radius_has_attr(packet, - RADIUS_TYPE_MESSAGE_AUTHENTICATOR) && - radius_check_message_authenticator(packet, client->secret) - != 0) { - log_warnx("Received %s(code=%d) from %s id=%d: " - "bad message authenticator", - radius_code_string(req_code), req_code, peerstr, - req_id); - goto on_error; - } + /* + * Find a matching `client' entry + */ + TAILQ_FOREACH(client, &listn->radiusd->client, next) { + if (client->af != peer->sa_family) + continue; + if (peer->sa_family == AF_INET && IPv4_cmp( + &in(peer), &client->addr, &client->mask)) + break; + else if (peer->sa_family == AF_INET6 && IPv6_cmp( + &in6(peer), &client->addr, &client->mask)) + break; + } + if (client == NULL) { + log_warnx("Received %s(code=%d) from %s id=%d: no `client' " + "matches", radius_code_string(req_code), req_code, peerstr, + req_id); + goto on_error; + } - /* - * Find a duplicate request. In RFC 2865, it has the same - * source IP address and source UDP port and Identifier. - */ - TAILQ_FOREACH(q, &listn->radiusd->query, next) { - if (peer.ss_family == q->clientaddr.ss_family && - ((peer.ss_family == AF_INET && - in(&q->clientaddr).s_addr == - in(&peer).s_addr) || - (peer.ss_family == AF_INET6 && - IN6_ARE_ADDR_EQUAL( - &in6(&q->clientaddr), &in6(&peer)))) && - ((struct sockaddr_in *)&q->clientaddr)->sin_port == - ((struct sockaddr_in *)&peer)->sin_port && - req_id == q->req_id) - break; /* found it */ - } - if (q != NULL) { - log_info("Received %s(code=%d) from %s id=%d: " - "duplicate request by q=%u", - radius_code_string(req_code), req_code, peerstr, - req_id, q->id); - /* XXX RFC 5080 suggests to answer the cached result */ - goto on_error; - } + /* Check the client's Message-Authenticator */ + if (client->msgauth_required && !radius_has_attr(packet, + RADIUS_TYPE_MESSAGE_AUTHENTICATOR)) { + log_warnx("Received %s(code=%d) from %s id=%d: no message " + "authenticator", radius_code_string(req_code), req_code, + peerstr, req_id); + goto on_error; + } - /* FIXME: we can support other request codes */ - if (req_code != RADIUS_CODE_ACCESS_REQUEST) { - log_info("Received %s(code=%d) from %s id=%d: %s " - "is not supported in this implementation", - radius_code_string(req_code), req_code, peerstr, - req_id, radius_code_string(req_code)); - goto on_error; - } + if (radius_has_attr(packet, RADIUS_TYPE_MESSAGE_AUTHENTICATOR) && + radius_check_message_authenticator(packet, client->secret) != 0) { + log_warnx("Received %s(code=%d) from %s id=%d: bad message " + "authenticator", radius_code_string(req_code), req_code, + peerstr, req_id); + goto on_error; + } + /* + * Find a duplicate request. In RFC 2865, it has the same source IP + * address and source UDP port and Identifier. + */ + TAILQ_FOREACH(q, &listn->radiusd->query, next) { + if (peer->sa_family == q->clientaddr.ss_family && + ((peer->sa_family == AF_INET && in(&q->clientaddr).s_addr == + in(peer).s_addr) || (peer->sa_family == AF_INET6 && + IN6_ARE_ADDR_EQUAL(&in6(&q->clientaddr), &in6(peer)))) && + ((struct sockaddr_in *)&q->clientaddr)->sin_port == + ((struct sockaddr_in *)peer)->sin_port && + req_id == q->req_id) + break; /* found it */ + } + if (q != NULL) { + log_info("Received %s(code=%d) from %s id=%d: duplicate " + "request by q=%u", radius_code_string(req_code), req_code, + peerstr, req_id, q->id); + /* XXX RFC 5080 suggests to answer the cached result */ + goto on_error; + } + + if ((q = calloc(1, sizeof(struct radius_query))) == NULL) { + log_warn("%s: Out of memory", __func__); + goto on_error; + } + if (radius_get_string_attr(packet, RADIUS_TYPE_USER_NAME, username, + sizeof(username)) != 0) { + log_info("Received %s(code=%d) from %s id=%d: no User-Name " + "attribute", radius_code_string(req_code), req_code, + peerstr, req_id); + } else + strlcpy(q->username, username, sizeof(q->username)); + + q->id = ++radius_query_id_seq; + q->clientaddrlen = peerlen; + memcpy(&q->clientaddr, peer, peerlen); + q->listen = listn; + q->req = packet; + q->client = client; + q->req_id = req_id; + radius_get_authenticator(packet, q->req_auth); + packet = NULL; + TAILQ_INSERT_TAIL(&listn->radiusd->query, q, next); + + switch (req_code) { + case RADIUS_CODE_ACCESS_REQUEST: /* * Find a matching `authenticate' entry */ - if (radius_get_string_attr(packet, RADIUS_TYPE_USER_NAME, - username, sizeof(username)) != 0) { - log_info("Received %s(code=%d) from %s id=%d: " - "no User-Name attribute", - radius_code_string(req_code), req_code, peerstr, - req_id); - goto on_error; - } TAILQ_FOREACH(authen, &listn->radiusd->authen, next) { for (i = 0; authen->username[i] != NULL; i++) { if (fnmatch(authen->username[i], username, 0) @@ -487,7 +495,7 @@ radiusd_listen_on_event(int fd, short evmask, void *ctx) goto found; } } -found: + found: if (authen == NULL) { log_warnx("Received %s(code=%d) from %s id=%d " "username=%s: no `authenticate' matches.", @@ -495,7 +503,7 @@ found: req_id, username); goto on_error; } - RADIUSD_ASSERT(authen->auth != NULL); + q->authen = authen; if (!MODULE_DO_USERPASS(authen->auth->module) && !MODULE_DO_ACCSREQ(authen->auth->module)) { @@ -505,42 +513,32 @@ found: req_id, username, authen->auth->module->name); goto on_error; } - if ((q = calloc(1, sizeof(struct radius_query))) == NULL) { - log_warn("%s: Out of memory", __func__); - goto on_error; - } - memcpy(&q->clientaddr, &peer, peersz); - strlcpy(q->username, username, sizeof(q->username)); - q->id = ++radius_query_id_seq; - q->clientaddrlen = peersz; - q->authen = authen; - q->listen = listn; - q->req = packet; - q->client = client; - q->req_id = req_id; - radius_get_authenticator(packet, q->req_auth); log_info("Received %s(code=%d) from %s id=%d username=%s " "q=%u: `%s' authentication is starting", radius_code_string(req_code), req_code, peerstr, q->req_id, q->username, q->id, q->authen->auth->module->name); - TAILQ_INSERT_TAIL(&listn->radiusd->query, q, next); - - radius_query_request(q); + raidus_query_access_request(q); return; + default: + log_info("Received %s(code=%d) from %s id=%d: %s is not " + "supported in this implementation", radius_code_string( + req_code), req_code, peerstr, req_id, radius_code_string( + req_code)); + break; } on_error: if (packet != NULL) radius_delete_packet(packet); + if (q != NULL) + radiusd_access_request_aborted(q); #undef in #undef in6 - - return; } static void -radius_query_request(struct radius_query *q) +raidus_query_access_request(struct radius_query *q) { struct radiusd_authentication *authen = q->authen; @@ -566,7 +564,7 @@ radius_query_request(struct radius_query *q) } static void -radius_query_response(struct radius_query *q) +radius_query_access_response(struct radius_query *q) { int sz, res_id, res_code; char buf[NI_MAXHOST + NI_MAXSERV + 30]; @@ -609,7 +607,6 @@ radius_query_response(struct radius_query *q) log_warn("Sending a RADIUS response failed"); on_error: radiusd_access_request_aborted(q); - } /*********************************************************************** @@ -643,7 +640,7 @@ radiusd_access_request_answer(struct radius_query *q) } RADIUSD_ASSERT(q->deco == NULL); - radius_query_response(q); + radius_query_access_response(q); return; on_error: @@ -957,7 +954,8 @@ radiusd_module_load(struct radiusd *radiusd, const char *path, const char *name) goto on_error; } if (fcntl(module->fd, F_SETFL, ival | O_NONBLOCK) == -1) { - log_warn("Could not load module `%s': fcntl(F_SETFL,O_NONBLOCK)", + log_warn( + "Could not load module `%s': fcntl(F_SETFL,O_NONBLOCK)", name); goto on_error; } @@ -1281,7 +1279,7 @@ radiusd_module_imsg(struct radiusd_module *module, struct imsg *imsg) radius_delete_packet(q->req); q->req = radpkt; } - radius_query_request(q); + raidus_query_access_request(q); break; case IMSG_RADIUSD_MODULE_ACCSREQ_ANSWER: if (radpkt == NULL) { @@ -1299,7 +1297,7 @@ radiusd_module_imsg(struct radiusd_module *module, struct imsg *imsg) q->req); q->res = radpkt; } - radius_query_response(q); + radius_query_access_response(q); break; } } diff --git a/usr.sbin/radiusd/radiusd_bsdauth.c b/usr.sbin/radiusd/radiusd_bsdauth.c index 69907bf9a..9f37ffa74 100644 --- a/usr.sbin/radiusd/radiusd_bsdauth.c +++ b/usr.sbin/radiusd/radiusd_bsdauth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd_bsdauth.c,v 1.15 2023/08/18 06:12:27 yasuoka Exp $ */ +/* $OpenBSD: radiusd_bsdauth.c,v 1.16 2024/02/09 07:41:32 yasuoka Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -247,7 +247,7 @@ module_bsdauth_main(void) &module_bsdauth_handlers)) == NULL) err(1, "Could not create a module instance"); - module_drop_privilege(module_bsdauth.base); + module_drop_privilege(module_bsdauth.base, 0); module_load(module_bsdauth.base); imsg_init(&module_bsdauth.ibuf, 3); diff --git a/usr.sbin/radiusd/radiusd_module.c b/usr.sbin/radiusd/radiusd_module.c index 0b482a140..85236db2c 100644 --- a/usr.sbin/radiusd/radiusd_module.c +++ b/usr.sbin/radiusd/radiusd_module.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd_module.c,v 1.15 2024/01/08 04:16:48 yasuoka Exp $ */ +/* $OpenBSD: radiusd_module.c,v 1.16 2024/02/09 07:41:32 yasuoka Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -162,7 +162,7 @@ module_load(struct module_base *base) } void -module_drop_privilege(struct module_base *base) +module_drop_privilege(struct module_base *base, int nochroot) { struct passwd *pw; @@ -171,7 +171,7 @@ module_drop_privilege(struct module_base *base) /* Drop the privilege */ if ((pw = getpwnam(RADIUSD_USER)) == NULL) goto on_fail; - if (chroot(pw->pw_dir) == -1) + if (nochroot == 0 && chroot(pw->pw_dir) == -1) goto on_fail; if (chdir("/") == -1) goto on_fail; diff --git a/usr.sbin/radiusd/radiusd_module.h b/usr.sbin/radiusd/radiusd_module.h index 6b993adc2..5fb44513f 100644 --- a/usr.sbin/radiusd/radiusd_module.h +++ b/usr.sbin/radiusd/radiusd_module.h @@ -60,7 +60,7 @@ void module_stop(struct module_base *); int module_run(struct module_base *); void module_destroy(struct module_base *); void module_load(struct module_base *); -void module_drop_privilege(struct module_base *); +void module_drop_privilege(struct module_base *, int); int module_notify_secret(struct module_base *, const char *); int module_send_message(struct module_base *, uint32_t, diff --git a/usr.sbin/radiusd/radiusd_radius.c b/usr.sbin/radiusd/radiusd_radius.c index 3b3b67ea5..c0aa8f825 100644 --- a/usr.sbin/radiusd/radiusd_radius.c +++ b/usr.sbin/radiusd/radiusd_radius.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd_radius.c,v 1.19 2023/09/04 10:49:20 yasuoka Exp $ */ +/* $OpenBSD: radiusd_radius.c,v 1.20 2024/02/09 07:41:32 yasuoka Exp $ */ /* * Copyright (c) 2013 Internet Initiative Japan Inc. @@ -125,7 +125,7 @@ main(int argc, char *argv[]) if ((module_radius.base = module_create( STDIN_FILENO, &module_radius, &module_radius_handlers)) == NULL) err(1, "Could not create a module instance"); - module_drop_privilege(module_radius.base); + module_drop_privilege(module_radius.base, 0); setproctitle("[main]"); module_load(module_radius.base); diff --git a/usr.sbin/radiusd/radiusd_standard.c b/usr.sbin/radiusd/radiusd_standard.c index 115748340..f819e3b47 100644 --- a/usr.sbin/radiusd/radiusd_standard.c +++ b/usr.sbin/radiusd/radiusd_standard.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd_standard.c,v 1.3 2024/02/06 10:53:20 yasuoka Exp $ */ +/* $OpenBSD: radiusd_standard.c,v 1.4 2024/02/09 07:41:32 yasuoka Exp $ */ /* * Copyright (c) 2013, 2023 Internet Initiative Japan Inc. @@ -74,7 +74,7 @@ main(int argc, char *argv[]) STDIN_FILENO, &module_standard, &handlers)) == NULL) err(1, "Could not create a module instance"); - module_drop_privilege(module_standard.base); + module_drop_privilege(module_standard.base, 0); if (pledge("stdio", NULL) == -1) err(1, "pledge"); diff --git a/usr.sbin/rpki-client/version.h b/usr.sbin/rpki-client/version.h index 5a707aac1..ffbda5b70 100644 --- a/usr.sbin/rpki-client/version.h +++ b/usr.sbin/rpki-client/version.h @@ -1,3 +1,3 @@ -/* $OpenBSD: version.h,v 1.20 2023/12/29 18:52:11 tb Exp $ */ +/* $OpenBSD: version.h,v 1.21 2024/02/09 13:49:41 job Exp $ */ -#define RPKI_VERSION "8.8" +#define RPKI_VERSION "8.9" diff --git a/usr.sbin/vmd/i8253.c b/usr.sbin/vmd/i8253.c index 9cc06d3f3..100dd0891 100644 --- a/usr.sbin/vmd/i8253.c +++ b/usr.sbin/vmd/i8253.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i8253.c,v 1.38 2023/10/25 12:44:28 dv Exp $ */ +/* $OpenBSD: i8253.c,v 1.39 2024/02/09 14:35:47 dv Exp $ */ /* * Copyright (c) 2016 Mike Larkin * @@ -298,8 +298,8 @@ vcpu_exit_i8253(struct vm_run_params *vrp) if (i8253_channel[sel].start == 0) i8253_channel[sel].start = 0xffff; - log_debug("%s: channel %d reset, mode=%d, " - "start=%d", __func__, + DPRINTF("%s: channel %d reset, mode=%d, " + "start=%d\n", __func__, sel, i8253_channel[sel].mode, i8253_channel[sel].start); diff --git a/usr.sbin/vmd/vionet.c b/usr.sbin/vmd/vionet.c index 5ed06fb8a..0de50784b 100644 --- a/usr.sbin/vmd/vionet.c +++ b/usr.sbin/vmd/vionet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vionet.c,v 1.10 2024/02/05 21:58:09 dv Exp $ */ +/* $OpenBSD: vionet.c,v 1.12 2024/02/10 02:19:12 dv Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -514,8 +514,9 @@ vionet_rx_copy(struct vionet_dev *dev, int fd, const struct iovec *iov, /* If reading the tap(4), we should get valid ethernet. */ log_warnx("%s: invalid packet size", __func__); return (0); - } else if (sz != sizeof(struct packet)) { - log_warnx("%s: invalid injected packet object", __func__); + } else if (fd == pipe_inject[READ] && sz != sizeof(struct packet)) { + log_warnx("%s: invalid injected packet object (sz=%ld)", + __func__, sz); return (0); } @@ -764,8 +765,9 @@ vionet_notify_tx(struct virtio_dev *dev) if (vionet->local) { dhcpsz = dhcp_request(dev, iov->iov_base, iov->iov_len, &dhcppkt); - log_debug("%s: detected dhcp request of %zu bytes", - __func__, dhcpsz); + if (dhcpsz > 0) + log_debug("%s: detected dhcp request of %zu bytes", + __func__, dhcpsz); } /* Write our packet to the tap(4). */ diff --git a/usr.sbin/vmd/virtio.c b/usr.sbin/vmd/virtio.c index afe3dd8f7..4b69f05e8 100644 --- a/usr.sbin/vmd/virtio.c +++ b/usr.sbin/vmd/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.111 2024/02/05 21:58:09 dv Exp $ */ +/* $OpenBSD: virtio.c,v 1.112 2024/02/10 02:10:41 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -1301,8 +1301,8 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) { char *nargv[12], num[32], vmm_fd[32], vm_name[VM_NAME_MAX], t[2]; pid_t dev_pid; - int data_fds[VM_MAX_BASE_PER_DISK], sync_fds[2], async_fds[2], ret = 0; - size_t i, data_fds_sz, sz = 0; + int sync_fds[2], async_fds[2], ret = 0; + size_t sz = 0; struct viodev_msg msg; struct virtio_dev *dev_entry; struct imsg imsg; @@ -1310,14 +1310,10 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) switch (dev->dev_type) { case VMD_DEVTYPE_NET: - data_fds[0] = dev->vionet.data_fd; - data_fds_sz = 1; log_debug("%s: launching vionet%d", vm->vm_params.vmc_params.vcp_name, dev->vionet.idx); break; case VMD_DEVTYPE_DISK: - memcpy(&data_fds, dev->vioblk.disk_fd, sizeof(data_fds)); - data_fds_sz = dev->vioblk.ndisk_fd; log_debug("%s: launching vioblk%d", vm->vm_params.vmc_params.vcp_name, dev->vioblk.idx); break; @@ -1359,10 +1355,6 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) dev->sync_fd = sync_fds[1]; dev->async_fd = async_fds[1]; - /* Close data fds. Only the child device needs them now. */ - for (i = 0; i < data_fds_sz; i++) - close_fd(data_fds[i]); - /* 1. Send over our configured device. */ log_debug("%s: sending '%c' type device struct", __func__, dev->dev_type); @@ -1373,6 +1365,13 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) goto err; } + /* Close data fds. Only the child device needs them now. */ + if (virtio_dev_closefds(dev) == -1) { + log_warnx("%s: failed to close device data fds", + __func__); + goto err; + } + /* 2. Send over details on the VM (including memory fds). */ log_debug("%s: sending vm message for '%s'", __func__, vm->vm_params.vmc_params.vcp_name); @@ -1775,5 +1774,10 @@ virtio_dev_closefds(struct virtio_dev *dev) return (-1); } + close_fd(dev->async_fd); + dev->async_fd = -1; + close_fd(dev->sync_fd); + dev->sync_fd = -1; + return (0); }