sync with OpenBSD -current

This commit is contained in:
purplerain 2024-01-25 02:58:42 +00:00
parent 029e4bda60
commit 125fcc4eee
Signed by: purplerain
GPG Key ID: F42C07F07E2E35B7
28 changed files with 244 additions and 238 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: conf_api.c,v 1.16 2023/07/08 08:26:26 beck Exp $ */ /* $OpenBSD: conf_api.c,v 1.17 2024/01/24 14:05:10 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved. * All rights reserved.
* *
@ -205,9 +205,6 @@ _CONF_free_data(CONF *conf)
if (conf == NULL || conf->data == NULL) if (conf == NULL || conf->data == NULL)
return; return;
lh_CONF_VALUE_down_load(conf->data) = 0; /* evil thing to make
* sure the 'free()' works as
* expected */
lh_CONF_VALUE_doall_arg(conf->data, lh_CONF_VALUE_doall_arg(conf->data,
LHASH_DOALL_ARG_FN(value_free_hash), LHASH_DOALL_ARG_FN(value_free_hash),
LHASH_OF(CONF_VALUE), conf->data); LHASH_OF(CONF_VALUE), conf->data);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: lhash.c,v 1.20 2023/07/07 13:40:44 beck Exp $ */ /* $OpenBSD: lhash.c,v 1.21 2024/01/24 14:02:52 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved. * All rights reserved.
* *
@ -250,12 +250,21 @@ static void
doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)
{ {
int i;
LHASH_NODE *a, *n; LHASH_NODE *a, *n;
int down_load;
int i;
if (lh == NULL) if (lh == NULL)
return; return;
/*
* Disable contraction of the hash while walking, as some consumers use
* it to delete hash entries. A better option would be to snapshot the
* hash, making it insert safe as well.
*/
down_load = lh->down_load;
lh->down_load = 0;
/* reverse the order so we search from 'top to bottom' /* reverse the order so we search from 'top to bottom'
* We were having memory leaks otherwise */ * We were having memory leaks otherwise */
for (i = lh->num_nodes - 1; i >= 0; i--) { for (i = lh->num_nodes - 1; i >= 0; i--) {
@ -273,6 +282,10 @@ doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
a = n; a = n;
} }
} }
/* Restore down load factor and trigger contraction. */
lh->down_load = down_load;
contract(lh);
} }
void void

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: lh_new.3,v 1.9 2022/03/31 17:27:17 naddy Exp $ .\" $OpenBSD: lh_new.3,v 1.10 2024/01/24 14:02:52 jsing Exp $
.\" full merge up to: .\" full merge up to:
.\" OpenSSL doc/crypto/lhash.pod 1bc74519 May 20 08:11:46 2016 -0400 .\" OpenSSL doc/crypto/lhash.pod 1bc74519 May 20 08:11:46 2016 -0400
.\" selective merge up to: .\" selective merge up to:
@ -118,7 +118,7 @@
.\" copied and put under another distribution licence .\" copied and put under another distribution licence
.\" [including the GNU Public Licence.] .\" [including the GNU Public Licence.]
.\" .\"
.Dd $Mdocdate: March 31 2022 $ .Dd $Mdocdate: January 24 2024 $
.Dt LH_NEW 3 .Dt LH_NEW 3
.Os .Os
.Sh NAME .Sh NAME
@ -342,15 +342,8 @@ lh_STUFF_doall(hashtable, LHASH_DOALL_FN(STUFF_cleanup));
lh_STUFF_free(hashtable); lh_STUFF_free(hashtable);
.Ed .Ed
.Pp .Pp
When doing this, be careful if you delete entries from the hash table in A callback may delete entries from the hash table, however, it is
your callbacks: the table may decrease in size, moving the item that you not safe to insert new entries.
are currently on down lower in the hash table \(em this could cause some
entries to be skipped during the iteration.
The second best solution to this problem is to set hash->down_load=0
before you start (which will stop the hash table ever decreasing in
size).
The best solution is probably to avoid deleting items from the hash
table inside a doall callback!
.Pp .Pp
.Fn lh_<type>_doall_arg .Fn lh_<type>_doall_arg
is the same as is the same as

View File

@ -714,7 +714,7 @@ sub mmx_loop() {
} }
&mov (&LB($nlo),&LB($dat)); &mov (&LB($nlo),&LB($dat));
&mov ($dat,&DWP(528+$j,"esp")) if (--$j%4==0); &mov ($dat,&DWP(528+$j,"esp")) if (--$j%4==0 && $j>=0);
&movd ($rem[0],$Zlo); &movd ($rem[0],$Zlo);
&movz ($rem[1],&LB($rem[1])) if ($i>0); &movz ($rem[1],&LB($rem[1])) if ($i>0);

View File

@ -285,7 +285,7 @@ $code.=".align 16\n.Louter_loop:\n";
&shr ($Zlo,8); &shr ($Zlo,8);
&movz ($rem[0],&LB($rem[0])); &movz ($rem[0],&LB($rem[0]));
&mov ($dat,"$j($Xi)") if (--$j%4==0); &mov ($dat,"$j($Xi)") if (--$j%4==0 && $j>=0);
&shr ($Zhi,8); &shr ($Zhi,8);
&xor ($Zlo,"-128($Hshr4,$nhi[0],8)"); &xor ($Zlo,"-128($Hshr4,$nhi[0],8)");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: obj_dat.c,v 1.84 2024/01/13 11:57:51 tb Exp $ */ /* $OpenBSD: obj_dat.c,v 1.85 2024/01/24 14:05:10 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved. * All rights reserved.
* *
@ -188,7 +188,7 @@ OBJ_cleanup(void)
{ {
if (added == NULL) if (added == NULL)
return; return;
lh_ADDED_OBJ_down_load(added) = 0;
lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup1)); /* zero counters */ lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup1)); /* zero counters */
lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup2)); /* set counters */ lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup2)); /* set counters */
lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup3)); /* free objects */ lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup3)); /* free objects */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssl_sess.c,v 1.123 2023/11/19 15:51:49 tb Exp $ */ /* $OpenBSD: ssl_sess.c,v 1.124 2024/01/24 14:05:10 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved. * All rights reserved.
* *
@ -1159,7 +1159,6 @@ timeout_LHASH_DOALL_ARG(void *arg1, void *arg2)
void void
SSL_CTX_flush_sessions(SSL_CTX *s, long t) SSL_CTX_flush_sessions(SSL_CTX *s, long t)
{ {
unsigned long i;
TIMEOUT_PARAM tp; TIMEOUT_PARAM tp;
tp.ctx = s; tp.ctx = s;
@ -1167,12 +1166,10 @@ SSL_CTX_flush_sessions(SSL_CTX *s, long t)
if (tp.cache == NULL) if (tp.cache == NULL)
return; return;
tp.time = t; tp.time = t;
CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
i = CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;
CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = 0;
lh_SSL_SESSION_doall_arg(tp.cache, timeout_LHASH_DOALL_ARG, lh_SSL_SESSION_doall_arg(tp.cache, timeout_LHASH_DOALL_ARG,
TIMEOUT_PARAM, &tp); TIMEOUT_PARAM, &tp);
CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = i;
CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
} }
LSSL_ALIAS(SSL_CTX_flush_sessions); LSSL_ALIAS(SSL_CTX_flush_sessions);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde_community_test.c,v 1.9 2023/10/11 07:05:11 claudio Exp $ */ /* $OpenBSD: rde_community_test.c,v 1.10 2024/01/24 14:51:56 claudio Exp $ */
/* /*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
@ -43,9 +43,9 @@ dump(uint8_t *b, size_t len)
} }
static int static int
test_parsing(size_t num, uint8_t *in, size_t inlen, uint8_t *out, size_t outlen) test_parsing(size_t num, struct ibuf *in, struct ibuf *out)
{ {
struct ibuf *buf; struct ibuf *buf, abuf;
uint8_t flags, type, attr[256]; uint8_t flags, type, attr[256];
size_t skip; size_t skip;
uint16_t attr_len; uint16_t attr_len;
@ -54,42 +54,40 @@ test_parsing(size_t num, uint8_t *in, size_t inlen, uint8_t *out, size_t outlen)
communities_clean(&comm); communities_clean(&comm);
do { do {
flags = in[0]; if (ibuf_get_n8(in, &flags) == -1 ||
type = in[1]; ibuf_get_n8(in, &type) == -1)
skip = 2; goto bad;
if (flags & ATTR_EXTLEN) { if (flags & ATTR_EXTLEN) {
memcpy(&attr_len, in + 2, sizeof(attr_len)); if (ibuf_get_n16(in, &attr_len) == -1)
attr_len = ntohs(attr_len); goto bad;
skip += 2;
} else { } else {
attr_len = in[2]; uint8_t tmp;
skip += 1; if (ibuf_get_n8(in, &tmp) == -1)
goto bad;
attr_len = tmp;
} }
if (skip + attr_len > inlen) { if (ibuf_get_ibuf(in, attr_len, &abuf) == -1) {
bad:
printf("Test %zu: attribute parse failure\n", num); printf("Test %zu: attribute parse failure\n", num);
return -1; return -1;
} }
switch (type) { switch (type) {
case ATTR_COMMUNITIES: case ATTR_COMMUNITIES:
r = community_add(&comm, flags, in + skip, attr_len); r = community_add(&comm, flags, &abuf);
break; break;
case ATTR_EXT_COMMUNITIES: case ATTR_EXT_COMMUNITIES:
r = community_ext_add(&comm, flags, 0, in + skip, r = community_ext_add(&comm, flags, 0, &abuf);
attr_len);
break; break;
case ATTR_LARGE_COMMUNITIES: case ATTR_LARGE_COMMUNITIES:
r = community_large_add(&comm, flags, in + skip, r = community_large_add(&comm, flags, &abuf);
attr_len);
break; break;
} }
if (r == -1) { if (r == -1) {
printf("Test %zu: community_add failed\n", num); printf("Test %zu: community_add failed\n", num);
return -1; return -1;
} }
in += skip + attr_len; } while (ibuf_size(in) > 0);
inlen -= (skip + attr_len);
} while (inlen > 0);
if ((buf = ibuf_dynamic(0, 4096)) == NULL) { if ((buf = ibuf_dynamic(0, 4096)) == NULL) {
printf("Test %zu: ibuf_dynamic failed\n", num); printf("Test %zu: ibuf_dynamic failed\n", num);
@ -109,19 +107,19 @@ test_parsing(size_t num, uint8_t *in, size_t inlen, uint8_t *out, size_t outlen)
return -1; return -1;
} }
if (ibuf_size(buf) != outlen) { if (ibuf_size(buf) != ibuf_size(out)) {
printf("Test %zu: ibuf size value %zd != %zd:", printf("Test %zu: ibuf size value %zd != %zd:",
num, ibuf_size(buf), outlen); num, ibuf_size(buf), ibuf_size(out));
dump(ibuf_data(buf), ibuf_size(buf)); dump(ibuf_data(buf), ibuf_size(buf));
printf("expected: "); printf("expected: ");
dump(out, outlen); dump(ibuf_data(out), ibuf_size(out));
return -1; return -1;
} }
if (memcmp(ibuf_data(buf), out, outlen) != 0) { if (memcmp(ibuf_data(buf), ibuf_data(out), ibuf_size(out)) != 0) {
printf("Test %zu: unexpected encoding: ", num); printf("Test %zu: unexpected encoding: ", num);
dump(ibuf_data(buf), ibuf_size(buf)); dump(ibuf_data(buf), ibuf_size(buf));
printf("expected: "); printf("expected: ");
dump(out, outlen); dump(ibuf_data(out), ibuf_size(out));
return -1; return -1;
} }
@ -206,16 +204,17 @@ main(int argc, char *argv[])
int error = 0; int error = 0;
for (t = 0; t < sizeof(vectors) / sizeof(*vectors); t++) { for (t = 0; t < sizeof(vectors) / sizeof(*vectors); t++) {
size_t outlen = vectors[t].expsize; struct ibuf in, out;
uint8_t *out = vectors[t].expected;
if (vectors[t].expected == NULL) { ibuf_from_buffer(&in, vectors[t].data, vectors[t].size);
outlen = vectors[t].size; if (vectors[t].expected == NULL)
out = vectors[t].data; ibuf_from_buffer(&out,
} vectors[t].data, vectors[t].size);
else
ibuf_from_buffer(&out,
vectors[t].expected, vectors[t].expsize);
if (test_parsing(t, vectors[t].data, vectors[t].size, if (test_parsing(t, &in, &out) == -1)
out, outlen) == -1)
error = 1; error = 1;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ca.c,v 1.98 2024/01/15 15:29:00 tobhe Exp $ */ /* $OpenBSD: ca.c,v 1.99 2024/01/24 10:09:07 tobhe Exp $ */
/* /*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@ -76,7 +76,7 @@ int ca_x509_subjectaltname_get(X509 *cert, struct iked_id *);
int ca_dispatch_parent(int, struct privsep_proc *, struct imsg *); int ca_dispatch_parent(int, struct privsep_proc *, struct imsg *);
int ca_dispatch_ikev2(int, struct privsep_proc *, struct imsg *); int ca_dispatch_ikev2(int, struct privsep_proc *, struct imsg *);
int ca_dispatch_control(int, struct privsep_proc *, struct imsg *); int ca_dispatch_control(int, struct privsep_proc *, struct imsg *);
void ca_store_info(struct iked *, const char *, X509_STORE *); void ca_store_info(struct iked *, struct imsg *, const char *, X509_STORE *);
static struct privsep_proc procs[] = { static struct privsep_proc procs[] = {
{ "parent", PROC_PARENT, ca_dispatch_parent }, { "parent", PROC_PARENT, ca_dispatch_parent },
@ -391,11 +391,12 @@ ca_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
switch (imsg->hdr.type) { switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_CERTSTORE: case IMSG_CTL_SHOW_CERTSTORE:
ca_store_info(env, "CA", store->ca_cas); ca_store_info(env, imsg, "CA", store->ca_cas);
ca_store_info(env, "CERT", store->ca_certs); ca_store_info(env, imsg, "CERT", store->ca_certs);
/* Send empty reply to indicate end of information. */ /* Send empty reply to indicate end of information. */
proc_compose(&env->sc_ps, PROC_CONTROL, IMSG_CTL_SHOW_CERTSTORE, proc_compose_imsg(&env->sc_ps, PROC_CONTROL, -1,
NULL, 0); IMSG_CTL_SHOW_CERTSTORE, imsg->hdr.peerid,
-1, NULL, 0);
break; break;
default: default:
return (-1); return (-1);
@ -1333,7 +1334,7 @@ ca_subjectpubkey_digest(X509 *x509, uint8_t *md, unsigned int *size)
} }
void void
ca_store_info(struct iked *env, const char *msg, X509_STORE *ctx) ca_store_info(struct iked *env, struct imsg *imsg, const char *msg, X509_STORE *ctx)
{ {
STACK_OF(X509_OBJECT) *h; STACK_OF(X509_OBJECT) *h;
X509_OBJECT *xo; X509_OBJECT *xo;
@ -1357,8 +1358,9 @@ ca_store_info(struct iked *env, const char *msg, X509_STORE *ctx)
OPENSSL_free(name); OPENSSL_free(name);
if (buflen == -1) if (buflen == -1)
continue; continue;
proc_compose(&env->sc_ps, PROC_CONTROL, IMSG_CTL_SHOW_CERTSTORE, proc_compose_imsg(&env->sc_ps, PROC_CONTROL, -1,
buf, buflen + 1); IMSG_CTL_SHOW_CERTSTORE, imsg->hdr.peerid,
-1, buf, buflen + 1);
free(buf); free(buf);
} }
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.37 2023/03/08 04:43:06 guenther Exp $ */ /* $OpenBSD: control.c,v 1.38 2024/01/24 10:09:07 tobhe Exp $ */
/* /*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@ -36,6 +36,7 @@
#define CONTROL_BACKLOG 5 #define CONTROL_BACKLOG 5
struct ctl_connlist ctl_conns = TAILQ_HEAD_INITIALIZER(ctl_conns); struct ctl_connlist ctl_conns = TAILQ_HEAD_INITIALIZER(ctl_conns);
uint32_t ctl_peerid;
void void
control_accept(int, short, void *); control_accept(int, short, void *);
@ -45,6 +46,7 @@ void control_close(int, struct control_sock *);
void control_dispatch_imsg(int, short, void *); void control_dispatch_imsg(int, short, void *);
void control_dispatch_parent(int, short, void *); void control_dispatch_parent(int, short, void *);
void control_imsg_forward(struct imsg *); void control_imsg_forward(struct imsg *);
void control_imsg_forward_peerid(struct imsg *);
void control_run(struct privsep *, struct privsep_proc *, void *); void control_run(struct privsep *, struct privsep_proc *, void *);
int control_dispatch_ikev2(int, struct privsep_proc *, struct imsg *); int control_dispatch_ikev2(int, struct privsep_proc *, struct imsg *);
int control_dispatch_ca(int, struct privsep_proc *, struct imsg *); int control_dispatch_ca(int, struct privsep_proc *, struct imsg *);
@ -160,6 +162,7 @@ control_accept(int listenfd, short event, void *arg)
socklen_t len; socklen_t len;
struct sockaddr_un s_un; struct sockaddr_un s_un;
struct ctl_conn *c; struct ctl_conn *c;
struct ctl_conn *other;
event_add(&cs->cs_ev, NULL); event_add(&cs->cs_ev, NULL);
if ((event & EV_TIMEOUT)) if ((event & EV_TIMEOUT))
@ -197,6 +200,12 @@ control_accept(int listenfd, short event, void *arg)
c->iev.handler, c->iev.data); c->iev.handler, c->iev.data);
event_add(&c->iev.ev, NULL); event_add(&c->iev.ev, NULL);
/* O(n^2), but n is small */
c->peerid = ctl_peerid++;
TAILQ_FOREACH(other, &ctl_conns, entry)
if (c->peerid == other->peerid)
c->peerid = ctl_peerid++;
TAILQ_INSERT_TAIL(&ctl_conns, c, entry); TAILQ_INSERT_TAIL(&ctl_conns, c, entry);
} }
@ -277,6 +286,9 @@ control_dispatch_imsg(int fd, short event, void *arg)
control_imsg_forward(&imsg); control_imsg_forward(&imsg);
/* record peerid of connection for reply */
imsg.hdr.peerid = c->peerid;
switch (imsg.hdr.type) { switch (imsg.hdr.type) {
case IMSG_CTL_NOTIFY: case IMSG_CTL_NOTIFY:
if (c->flags & CTL_CONN_NOTIFY) { if (c->flags & CTL_CONN_NOTIFY) {
@ -311,11 +323,9 @@ control_dispatch_imsg(int fd, short event, void *arg)
case IMSG_CTL_SHOW_SA: case IMSG_CTL_SHOW_SA:
case IMSG_CTL_SHOW_STATS: case IMSG_CTL_SHOW_STATS:
proc_forward_imsg(&env->sc_ps, &imsg, PROC_IKEV2, -1); proc_forward_imsg(&env->sc_ps, &imsg, PROC_IKEV2, -1);
c->flags |= CTL_CONN_NOTIFY;
break; break;
case IMSG_CTL_SHOW_CERTSTORE: case IMSG_CTL_SHOW_CERTSTORE:
proc_forward_imsg(&env->sc_ps, &imsg, PROC_CERT, -1); proc_forward_imsg(&env->sc_ps, &imsg, PROC_CERT, -1);
c->flags |= CTL_CONN_NOTIFY;
break; break;
default: default:
log_debug("%s: error handling imsg %d", log_debug("%s: error handling imsg %d",
@ -340,13 +350,25 @@ control_imsg_forward(struct imsg *imsg)
imsg->hdr.len - IMSG_HEADER_SIZE); imsg->hdr.len - IMSG_HEADER_SIZE);
} }
void
control_imsg_forward_peerid(struct imsg *imsg)
{
struct ctl_conn *c;
TAILQ_FOREACH(c, &ctl_conns, entry)
if (c->peerid == imsg->hdr.peerid)
imsg_compose_event(&c->iev, imsg->hdr.type,
0, imsg->hdr.pid, -1, imsg->data,
imsg->hdr.len - IMSG_HEADER_SIZE);
}
int int
control_dispatch_ikev2(int fd, struct privsep_proc *p, struct imsg *imsg) control_dispatch_ikev2(int fd, struct privsep_proc *p, struct imsg *imsg)
{ {
switch (imsg->hdr.type) { switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_SA: case IMSG_CTL_SHOW_SA:
case IMSG_CTL_SHOW_STATS: case IMSG_CTL_SHOW_STATS:
control_imsg_forward(imsg); control_imsg_forward_peerid(imsg);
return (0); return (0);
default: default:
break; break;
@ -360,7 +382,7 @@ control_dispatch_ca(int fd, struct privsep_proc *p, struct imsg *imsg)
{ {
switch (imsg->hdr.type) { switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_CERTSTORE: case IMSG_CTL_SHOW_CERTSTORE:
control_imsg_forward(imsg); control_imsg_forward_peerid(imsg);
return (0); return (0);
default: default:
break; break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: iked.h,v 1.225 2024/01/15 15:29:00 tobhe Exp $ */ /* $OpenBSD: iked.h,v 1.226 2024/01/24 10:09:07 tobhe Exp $ */
/* /*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@ -99,6 +99,7 @@ struct ctl_conn {
uint8_t flags; uint8_t flags;
#define CTL_CONN_NOTIFY 0x01 #define CTL_CONN_NOTIFY 0x01
struct imsgev iev; struct imsgev iev;
uint32_t peerid;
}; };
TAILQ_HEAD(ctl_connlist, ctl_conn); TAILQ_HEAD(ctl_connlist, ctl_conn);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ikev2.c,v 1.382 2024/01/15 21:37:58 jan Exp $ */ /* $OpenBSD: ikev2.c,v 1.383 2024/01/24 10:09:07 tobhe Exp $ */
/* /*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@ -48,10 +48,13 @@
#include "chap_ms.h" #include "chap_ms.h"
#include "version.h" #include "version.h"
void ikev2_info(struct iked *, int); void ikev2_info(struct iked *, struct imsg *, int);
void ikev2_info_sa(struct iked *, int, const char *, struct iked_sa *); void ikev2_info_sa(struct iked *, struct imsg *, int, const char *,
void ikev2_info_csa(struct iked *, int, const char *, struct iked_childsa *); struct iked_sa *);
void ikev2_info_flow(struct iked *, int, const char *, struct iked_flow *); void ikev2_info_csa(struct iked *, struct imsg *, int, const char *,
struct iked_childsa *);
void ikev2_info_flow(struct iked *, struct imsg *, int, const char *,
struct iked_flow *);
void ikev2_log_established(struct iked_sa *); void ikev2_log_established(struct iked_sa *);
void ikev2_log_proposal(struct iked_sa *, struct iked_proposals *); void ikev2_log_proposal(struct iked_sa *, struct iked_proposals *);
void ikev2_log_cert_info(const char *, struct iked_id *); void ikev2_log_cert_info(const char *, struct iked_id *);
@ -188,8 +191,8 @@ int ikev2_resp_informational(struct iked *, struct iked_sa *,
struct iked_message *); struct iked_message *);
void ikev2_ctl_reset_id(struct iked *, struct imsg *, unsigned int); void ikev2_ctl_reset_id(struct iked *, struct imsg *, unsigned int);
void ikev2_ctl_show_sa(struct iked *); void ikev2_ctl_show_sa(struct iked *, struct imsg *);
void ikev2_ctl_show_stats(struct iked *); void ikev2_ctl_show_stats(struct iked *, struct imsg *);
static struct privsep_proc procs[] = { static struct privsep_proc procs[] = {
{ "parent", PROC_PARENT, ikev2_dispatch_parent }, { "parent", PROC_PARENT, ikev2_dispatch_parent },
@ -512,10 +515,10 @@ ikev2_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
ikev2_ctl_reset_id(env, imsg, imsg->hdr.type); ikev2_ctl_reset_id(env, imsg, imsg->hdr.type);
break; break;
case IMSG_CTL_SHOW_SA: case IMSG_CTL_SHOW_SA:
ikev2_ctl_show_sa(env); ikev2_ctl_show_sa(env, imsg);
break; break;
case IMSG_CTL_SHOW_STATS: case IMSG_CTL_SHOW_STATS:
ikev2_ctl_show_stats(env); ikev2_ctl_show_stats(env, imsg);
break; break;
default: default:
return (-1); return (-1);
@ -572,15 +575,16 @@ ikev2_ctl_reset_id(struct iked *env, struct imsg *imsg, unsigned int type)
} }
void void
ikev2_ctl_show_sa(struct iked *env) ikev2_ctl_show_sa(struct iked *env, struct imsg *imsg)
{ {
ikev2_info(env, 0); ikev2_info(env, imsg, 0);
} }
void void
ikev2_ctl_show_stats(struct iked *env) ikev2_ctl_show_stats(struct iked *env, struct imsg *imsg)
{ {
proc_compose(&env->sc_ps, PROC_CONTROL, IMSG_CTL_SHOW_STATS, proc_compose_imsg(&env->sc_ps, PROC_CONTROL, -1,
IMSG_CTL_SHOW_STATS, imsg->hdr.peerid, -1,
&env->sc_stats, sizeof(env->sc_stats)); &env->sc_stats, sizeof(env->sc_stats));
} }
@ -7444,7 +7448,8 @@ ikev2_update_sa_addresses(struct iked *env, struct iked_sa *sa)
} }
void void
ikev2_info_sa(struct iked *env, int dolog, const char *msg, struct iked_sa *sa) ikev2_info_sa(struct iked *env, struct imsg *imsg, int dolog, const char *msg,
struct iked_sa *sa)
{ {
char idstr[IKED_ID_SIZE]; char idstr[IKED_ID_SIZE];
char *buf; char *buf;
@ -7476,13 +7481,15 @@ ikev2_info_sa(struct iked *env, int dolog, const char *msg, struct iked_sa *sa)
buf[buflen - 1] = '\0'; buf[buflen - 1] = '\0';
log_debug("%s", buf); log_debug("%s", buf);
} else } else
proc_compose(&env->sc_ps, PROC_CONTROL, IMSG_CTL_SHOW_SA, proc_compose_imsg(&env->sc_ps, PROC_CONTROL, -1,
IMSG_CTL_SHOW_SA, imsg->hdr.peerid, -1,
buf, buflen + 1); buf, buflen + 1);
free(buf); free(buf);
} }
void void
ikev2_info_csa(struct iked *env, int dolog, const char *msg, struct iked_childsa *csa) ikev2_info_csa(struct iked *env, struct imsg *imsg, int dolog, const char *msg,
struct iked_childsa *csa)
{ {
char *buf; char *buf;
int buflen; int buflen;
@ -7510,13 +7517,15 @@ ikev2_info_csa(struct iked *env, int dolog, const char *msg, struct iked_childsa
buf[buflen - 1] = '\0'; buf[buflen - 1] = '\0';
log_debug("%s", buf); log_debug("%s", buf);
} else } else
proc_compose(&env->sc_ps, PROC_CONTROL, IMSG_CTL_SHOW_SA, proc_compose_imsg(&env->sc_ps, PROC_CONTROL, -1,
IMSG_CTL_SHOW_SA, imsg->hdr.peerid, -1,
buf, buflen + 1); buf, buflen + 1);
free(buf); free(buf);
} }
void void
ikev2_info_flow(struct iked *env, int dolog, const char *msg, struct iked_flow *flow) ikev2_info_flow(struct iked *env, struct imsg *imsg, int dolog, const char *msg,
struct iked_flow *flow)
{ {
char prenat_mask[10]; char prenat_mask[10];
char *buf; char *buf;
@ -7555,13 +7564,14 @@ ikev2_info_flow(struct iked *env, int dolog, const char *msg, struct iked_flow *
buf[buflen - 1] = '\0'; buf[buflen - 1] = '\0';
log_debug("%s", buf); log_debug("%s", buf);
} else } else
proc_compose(&env->sc_ps, PROC_CONTROL, IMSG_CTL_SHOW_SA, proc_compose_imsg(&env->sc_ps, PROC_CONTROL, -1,
IMSG_CTL_SHOW_SA, imsg->hdr.peerid, -1,
buf, buflen + 1); buf, buflen + 1);
free(buf); free(buf);
} }
void void
ikev2_info(struct iked *env, int dolog) ikev2_info(struct iked *env, struct imsg *imsg, int dolog)
{ {
struct iked_sa *sa; struct iked_sa *sa;
struct iked_childsa *csa, *ipcomp; struct iked_childsa *csa, *ipcomp;
@ -7570,32 +7580,33 @@ ikev2_info(struct iked *env, int dolog)
log_debug("%s: called", __func__); log_debug("%s: called", __func__);
RB_FOREACH(sa, iked_sas, &env->sc_sas) { RB_FOREACH(sa, iked_sas, &env->sc_sas) {
ikev2_info_sa(env, dolog, "iked_sas", sa); ikev2_info_sa(env, imsg, dolog, "iked_sas", sa);
TAILQ_FOREACH(csa, &sa->sa_childsas, csa_entry) { TAILQ_FOREACH(csa, &sa->sa_childsas, csa_entry) {
ikev2_info_csa(env, dolog, " sa_childsas", csa); ikev2_info_csa(env, imsg, dolog, " sa_childsas", csa);
if ((ipcomp = csa->csa_bundled) != NULL) if ((ipcomp = csa->csa_bundled) != NULL)
ikev2_info_csa(env, dolog, " ", ikev2_info_csa(env, imsg, dolog, " ",
ipcomp); ipcomp);
} }
TAILQ_FOREACH(flow, &sa->sa_flows, flow_entry) { TAILQ_FOREACH(flow, &sa->sa_flows, flow_entry) {
ikev2_info_flow(env, dolog, " sa_flows", flow); ikev2_info_flow(env, imsg, dolog, " sa_flows", flow);
} }
} }
RB_FOREACH(csa, iked_activesas, &env->sc_activesas) { RB_FOREACH(csa, iked_activesas, &env->sc_activesas) {
ikev2_info_csa(env, dolog, "iked_activesas", csa); ikev2_info_csa(env, imsg, dolog, "iked_activesas", csa);
if ((ipcomp = csa->csa_bundled) != NULL) if ((ipcomp = csa->csa_bundled) != NULL)
ikev2_info_csa(env, dolog, " ", ipcomp); ikev2_info_csa(env, imsg, dolog, " ", ipcomp);
} }
RB_FOREACH(flow, iked_flows, &env->sc_activeflows) { RB_FOREACH(flow, iked_flows, &env->sc_activeflows) {
ikev2_info_flow(env, dolog, "iked_flows", flow); ikev2_info_flow(env, imsg, dolog, "iked_flows", flow);
} }
RB_FOREACH(sa, iked_dstid_sas, &env->sc_dstid_sas) { RB_FOREACH(sa, iked_dstid_sas, &env->sc_dstid_sas) {
ikev2_info_sa(env, dolog, "iked_dstid_sas", sa); ikev2_info_sa(env, imsg, dolog, "iked_dstid_sas", sa);
} }
if (dolog) if (dolog)
return; return;
/* Send empty reply to indicate end of information. */ /* Send empty reply to indicate end of information. */
proc_compose(&env->sc_ps, PROC_CONTROL, IMSG_CTL_SHOW_SA, NULL, 0); proc_compose_imsg(&env->sc_ps, PROC_CONTROL, -1, IMSG_CTL_SHOW_SA,
imsg->hdr.peerid, -1, NULL, 0);
} }
const char * const char *

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: apldcp.4,v 1.1 2024/01/22 18:56:18 kettenis Exp $ .\" $OpenBSD: apldcp.4,v 1.2 2024/01/24 14:17:37 kettenis Exp $
.\" .\"
.\" Copyright (c) 2024 Mark Kettenis <kettenis@openbsd.org> .\" Copyright (c) 2024 Mark Kettenis <kettenis@openbsd.org>
.\" .\"
@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: January 22 2024 $ .Dd $Mdocdate: January 24 2024 $
.Dt APLDCP 4 arm64 .Dt APLDCP 4 arm64
.Os .Os
.Sh NAME .Sh NAME
@ -40,9 +40,11 @@ device driver first appeared in
The The
.Nm .Nm
driver was written by driver was written by
.An Alyssa Rosenzweig .An Alyssa Rosenzweig ,
.An Janne Grunau ,
.An Martin Povi\[u0161]er
and and
.An Janne Grunau .An Sven Peter
for Linux and ported to for Linux and ported to
.Ox .Ox
by by

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cpu.h,v 1.159 2023/08/23 01:55:46 cheloha Exp $ */ /* $OpenBSD: cpu.h,v 1.160 2024/01/24 19:23:39 cheloha Exp $ */
/* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
/*- /*-
@ -208,7 +208,7 @@ struct cpu_info {
u_int64_t ci_hz_aperf; u_int64_t ci_hz_aperf;
#if defined(GPROF) || defined(DDBPROF) #if defined(GPROF) || defined(DDBPROF)
struct gmonparam *ci_gmon; struct gmonparam *ci_gmon;
struct clockintr *ci_gmonclock; struct clockintr ci_gmonclock;
#endif #endif
u_int32_t ci_vmm_flags; u_int32_t ci_vmm_flags;
#define CI_VMM_VMX (1 << 0) #define CI_VMM_VMX (1 << 0)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cpu.h,v 1.64 2023/08/23 01:55:46 cheloha Exp $ */ /* $OpenBSD: cpu.h,v 1.65 2024/01/24 19:23:39 cheloha Exp $ */
/* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */ /* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */
/* /*
@ -198,7 +198,7 @@ struct cpu_info {
#ifdef GPROF #ifdef GPROF
struct gmonparam *ci_gmon; struct gmonparam *ci_gmon;
struct clockintr *ci_gmonclock; struct clockintr ci_gmonclock;
#endif #endif
struct clockintr_queue ci_queue; struct clockintr_queue ci_queue;
char ci_panicbuf[512]; char ci_panicbuf[512];

View File

@ -1,4 +1,4 @@
# $OpenBSD: GENERIC,v 1.281 2024/01/22 18:54:01 kettenis Exp $ # $OpenBSD: GENERIC,v 1.282 2024/01/24 07:36:52 kevlo Exp $
# #
# GENERIC machine description file # GENERIC machine description file
# #
@ -398,6 +398,7 @@ vmx* at pci? # VMware VMXNET3 virtual interface
athn* at pci? # Atheros AR9k (802.11a/g/n) athn* at pci? # Atheros AR9k (802.11a/g/n)
bwfm* at pci? # Broadcom FullMAC bwfm* at pci? # Broadcom FullMAC
iwn* at pci? # Intel WiFi Link 4965/5000/1000/6000 iwn* at pci? # Intel WiFi Link 4965/5000/1000/6000
iwm* at pci? # Intel WiFi Link 7xxx
iwx* at pci? # Intel WiFi Link 22xxx iwx* at pci? # Intel WiFi Link 22xxx
#qwx* at pci? # Qualcomm 802.11ax #qwx* at pci? # Qualcomm 802.11ax

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cpu.h,v 1.41 2024/01/15 11:58:45 kettenis Exp $ */ /* $OpenBSD: cpu.h,v 1.42 2024/01/24 19:23:39 cheloha Exp $ */
/* /*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com> * Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
* *
@ -174,7 +174,7 @@ struct cpu_info {
#ifdef GPROF #ifdef GPROF
struct gmonparam *ci_gmon; struct gmonparam *ci_gmon;
struct clockintr *ci_gmonclock; struct clockintr ci_gmonclock;
#endif #endif
struct clockintr_queue ci_queue; struct clockintr_queue ci_queue;
char ci_panicbuf[512]; char ci_panicbuf[512];

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cpu.h,v 1.183 2023/08/23 01:55:46 cheloha Exp $ */ /* $OpenBSD: cpu.h,v 1.184 2024/01/24 19:23:39 cheloha Exp $ */
/* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */ /* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */
/*- /*-
@ -168,7 +168,7 @@ struct cpu_info {
struct ksensor ci_sensor; struct ksensor ci_sensor;
#if defined(GPROF) || defined(DDBPROF) #if defined(GPROF) || defined(DDBPROF)
struct gmonparam *ci_gmon; struct gmonparam *ci_gmon;
struct clockintr *ci_gmonclock; struct clockintr ci_gmonclock;
#endif #endif
struct clockintr_queue ci_queue; struct clockintr_queue ci_queue;
char ci_panicbuf[512]; char ci_panicbuf[512];

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_clockintr.c,v 1.63 2024/01/15 01:15:37 cheloha Exp $ */ /* $OpenBSD: kern_clockintr.c,v 1.64 2024/01/24 19:23:38 cheloha Exp $ */
/* /*
* Copyright (c) 2003 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2003 Dale Rahn <drahn@openbsd.org>
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@ -62,11 +62,9 @@ clockintr_cpu_init(const struct intrclock *ic)
clockqueue_intrclock_install(cq, ic); clockqueue_intrclock_install(cq, ic);
/* TODO: Remove this from struct clockintr_queue. */ /* TODO: Remove this from struct clockintr_queue. */
if (cq->cq_hardclock == NULL) { if (cq->cq_hardclock.cl_expiration == 0) {
cq->cq_hardclock = clockintr_establish(ci, clockintr_hardclock, clockintr_bind(&cq->cq_hardclock, ci, clockintr_hardclock,
NULL); NULL);
if (cq->cq_hardclock == NULL)
panic("%s: failed to establish hardclock", __func__);
} }
/* /*
@ -96,16 +94,16 @@ clockintr_cpu_init(const struct intrclock *ic)
* behalf. * behalf.
*/ */
if (CPU_IS_PRIMARY(ci)) { if (CPU_IS_PRIMARY(ci)) {
if (cq->cq_hardclock->cl_expiration == 0) if (cq->cq_hardclock.cl_expiration == 0)
clockintr_schedule(cq->cq_hardclock, 0); clockintr_schedule(&cq->cq_hardclock, 0);
else else
clockintr_advance(cq->cq_hardclock, hardclock_period); clockintr_advance(&cq->cq_hardclock, hardclock_period);
} else { } else {
if (cq->cq_hardclock->cl_expiration == 0) { if (cq->cq_hardclock.cl_expiration == 0) {
clockintr_stagger(cq->cq_hardclock, hardclock_period, clockintr_stagger(&cq->cq_hardclock, hardclock_period,
multiplier, MAXCPUS); multiplier, MAXCPUS);
} }
clockintr_advance(cq->cq_hardclock, hardclock_period); clockintr_advance(&cq->cq_hardclock, hardclock_period);
} }
/* /*
@ -113,30 +111,30 @@ clockintr_cpu_init(const struct intrclock *ic)
* stagger a randomized statclock. * stagger a randomized statclock.
*/ */
if (!statclock_is_randomized) { if (!statclock_is_randomized) {
if (spc->spc_statclock->cl_expiration == 0) { if (spc->spc_statclock.cl_expiration == 0) {
clockintr_stagger(spc->spc_statclock, statclock_avg, clockintr_stagger(&spc->spc_statclock, statclock_avg,
multiplier, MAXCPUS); multiplier, MAXCPUS);
} }
} }
clockintr_advance(spc->spc_statclock, statclock_avg); clockintr_advance(&spc->spc_statclock, statclock_avg);
/* /*
* XXX Need to find a better place to do this. We can't do it in * XXX Need to find a better place to do this. We can't do it in
* sched_init_cpu() because initclocks() runs after it. * sched_init_cpu() because initclocks() runs after it.
*/ */
if (spc->spc_itimer->cl_expiration == 0) { if (spc->spc_itimer.cl_expiration == 0) {
clockintr_stagger(spc->spc_itimer, hardclock_period, clockintr_stagger(&spc->spc_itimer, hardclock_period,
multiplier, MAXCPUS); multiplier, MAXCPUS);
} }
if (spc->spc_profclock->cl_expiration == 0) { if (spc->spc_profclock.cl_expiration == 0) {
clockintr_stagger(spc->spc_profclock, profclock_period, clockintr_stagger(&spc->spc_profclock, profclock_period,
multiplier, MAXCPUS); multiplier, MAXCPUS);
} }
if (spc->spc_roundrobin->cl_expiration == 0) { if (spc->spc_roundrobin.cl_expiration == 0) {
clockintr_stagger(spc->spc_roundrobin, hardclock_period, clockintr_stagger(&spc->spc_roundrobin, hardclock_period,
multiplier, MAXCPUS); multiplier, MAXCPUS);
} }
clockintr_advance(spc->spc_roundrobin, roundrobin_period); clockintr_advance(&spc->spc_roundrobin, roundrobin_period);
if (reset_cq_intrclock) if (reset_cq_intrclock)
SET(cq->cq_flags, CQ_INTRCLOCK); SET(cq->cq_flags, CQ_INTRCLOCK);
@ -337,16 +335,12 @@ clockintr_cancel(struct clockintr *cl)
mtx_leave(&cq->cq_mtx); mtx_leave(&cq->cq_mtx);
} }
struct clockintr * void
clockintr_establish(struct cpu_info *ci, clockintr_bind(struct clockintr *cl, struct cpu_info *ci,
void (*func)(struct clockrequest *, void *, void *), void *arg) void (*func)(struct clockrequest *, void *, void *), void *arg)
{ {
struct clockintr *cl;
struct clockintr_queue *cq = &ci->ci_queue; struct clockintr_queue *cq = &ci->ci_queue;
cl = malloc(sizeof *cl, M_DEVBUF, M_NOWAIT | M_ZERO);
if (cl == NULL)
return NULL;
cl->cl_arg = arg; cl->cl_arg = arg;
cl->cl_func = func; cl->cl_func = func;
cl->cl_queue = cq; cl->cl_queue = cq;
@ -354,7 +348,6 @@ clockintr_establish(struct cpu_info *ci,
mtx_enter(&cq->cq_mtx); mtx_enter(&cq->cq_mtx);
TAILQ_INSERT_TAIL(&cq->cq_all, cl, cl_alink); TAILQ_INSERT_TAIL(&cq->cq_all, cl, cl_alink);
mtx_leave(&cq->cq_mtx); mtx_leave(&cq->cq_mtx);
return cl;
} }
void void

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_fork.c,v 1.256 2024/01/19 01:43:26 bluhm Exp $ */ /* $OpenBSD: kern_fork.c,v 1.257 2024/01/24 19:23:38 cheloha Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/* /*
@ -704,11 +704,11 @@ proc_trampoline_mi(void)
/* Start any optional clock interrupts needed by the thread. */ /* Start any optional clock interrupts needed by the thread. */
if (ISSET(p->p_p->ps_flags, PS_ITIMER)) { if (ISSET(p->p_p->ps_flags, PS_ITIMER)) {
atomic_setbits_int(&spc->spc_schedflags, SPCF_ITIMER); atomic_setbits_int(&spc->spc_schedflags, SPCF_ITIMER);
clockintr_advance(spc->spc_itimer, hardclock_period); clockintr_advance(&spc->spc_itimer, hardclock_period);
} }
if (ISSET(p->p_p->ps_flags, PS_PROFIL)) { if (ISSET(p->p_p->ps_flags, PS_PROFIL)) {
atomic_setbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK); atomic_setbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK);
clockintr_advance(spc->spc_profclock, profclock_period); clockintr_advance(&spc->spc_profclock, profclock_period);
} }
nanouptime(&spc->spc_runtime); nanouptime(&spc->spc_runtime);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_sched.c,v 1.93 2023/10/24 13:20:11 claudio Exp $ */ /* $OpenBSD: kern_sched.c,v 1.94 2024/01/24 19:23:38 cheloha Exp $ */
/* /*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org> * Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
* *
@ -88,18 +88,10 @@ sched_init_cpu(struct cpu_info *ci)
spc->spc_idleproc = NULL; spc->spc_idleproc = NULL;
spc->spc_itimer = clockintr_establish(ci, itimer_update, NULL); clockintr_bind(&spc->spc_itimer, ci, itimer_update, NULL);
if (spc->spc_itimer == NULL) clockintr_bind(&spc->spc_profclock, ci, profclock, NULL);
panic("%s: clockintr_establish itimer_update", __func__); clockintr_bind(&spc->spc_roundrobin, ci, roundrobin, NULL);
spc->spc_profclock = clockintr_establish(ci, profclock, NULL); clockintr_bind(&spc->spc_statclock, ci, statclock, NULL);
if (spc->spc_profclock == NULL)
panic("%s: clockintr_establish profclock", __func__);
spc->spc_roundrobin = clockintr_establish(ci, roundrobin, NULL);
if (spc->spc_roundrobin == NULL)
panic("%s: clockintr_establish roundrobin", __func__);
spc->spc_statclock = clockintr_establish(ci, statclock, NULL);
if (spc->spc_statclock == NULL)
panic("%s: clockintr_establish statclock", __func__);
kthread_create_deferred(sched_kthreads_create, ci); kthread_create_deferred(sched_kthreads_create, ci);
@ -244,11 +236,11 @@ sched_toidle(void)
if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) { if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) {
atomic_clearbits_int(&spc->spc_schedflags, SPCF_ITIMER); atomic_clearbits_int(&spc->spc_schedflags, SPCF_ITIMER);
clockintr_cancel(spc->spc_itimer); clockintr_cancel(&spc->spc_itimer);
} }
if (ISSET(spc->spc_schedflags, SPCF_PROFCLOCK)) { if (ISSET(spc->spc_schedflags, SPCF_PROFCLOCK)) {
atomic_clearbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK); atomic_clearbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK);
clockintr_cancel(spc->spc_profclock); clockintr_cancel(&spc->spc_profclock);
} }
atomic_clearbits_int(&spc->spc_schedflags, SPCF_SWITCHCLEAR); atomic_clearbits_int(&spc->spc_schedflags, SPCF_SWITCHCLEAR);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sched_bsd.c,v 1.89 2023/10/17 00:04:02 cheloha Exp $ */ /* $OpenBSD: sched_bsd.c,v 1.90 2024/01/24 19:23:38 cheloha Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*- /*-
@ -396,11 +396,11 @@ mi_switch(void)
/* Stop any optional clock interrupts. */ /* Stop any optional clock interrupts. */
if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) { if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) {
atomic_clearbits_int(&spc->spc_schedflags, SPCF_ITIMER); atomic_clearbits_int(&spc->spc_schedflags, SPCF_ITIMER);
clockintr_cancel(spc->spc_itimer); clockintr_cancel(&spc->spc_itimer);
} }
if (ISSET(spc->spc_schedflags, SPCF_PROFCLOCK)) { if (ISSET(spc->spc_schedflags, SPCF_PROFCLOCK)) {
atomic_clearbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK); atomic_clearbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK);
clockintr_cancel(spc->spc_profclock); clockintr_cancel(&spc->spc_profclock);
} }
/* /*
@ -451,11 +451,11 @@ mi_switch(void)
/* Start any optional clock interrupts needed by the thread. */ /* Start any optional clock interrupts needed by the thread. */
if (ISSET(p->p_p->ps_flags, PS_ITIMER)) { if (ISSET(p->p_p->ps_flags, PS_ITIMER)) {
atomic_setbits_int(&spc->spc_schedflags, SPCF_ITIMER); atomic_setbits_int(&spc->spc_schedflags, SPCF_ITIMER);
clockintr_advance(spc->spc_itimer, hardclock_period); clockintr_advance(&spc->spc_itimer, hardclock_period);
} }
if (ISSET(p->p_p->ps_flags, PS_PROFIL)) { if (ISSET(p->p_p->ps_flags, PS_PROFIL)) {
atomic_setbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK); atomic_setbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK);
clockintr_advance(spc->spc_profclock, profclock_period); clockintr_advance(&spc->spc_profclock, profclock_period);
} }
nanouptime(&spc->spc_runtime); nanouptime(&spc->spc_runtime);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: subr_prof.c,v 1.40 2023/10/17 00:04:02 cheloha Exp $ */ /* $OpenBSD: subr_prof.c,v 1.41 2024/01/24 19:23:38 cheloha Exp $ */
/* $NetBSD: subr_prof.c,v 1.12 1996/04/22 01:38:50 christos Exp $ */ /* $NetBSD: subr_prof.c,v 1.12 1996/04/22 01:38:50 christos Exp $ */
/*- /*-
@ -101,19 +101,16 @@ prof_init(void)
/* Allocate and initialize one profiling buffer per CPU. */ /* Allocate and initialize one profiling buffer per CPU. */
CPU_INFO_FOREACH(cii, ci) { CPU_INFO_FOREACH(cii, ci) {
ci->ci_gmonclock = clockintr_establish(ci, gmonclock, NULL);
if (ci->ci_gmonclock == NULL) {
printf("%s: clockintr_establish gmonclock\n", __func__);
return;
}
clockintr_stagger(ci->ci_gmonclock, profclock_period,
CPU_INFO_UNIT(ci), MAXCPUS);
cp = km_alloc(round_page(size), &kv_any, &kp_zero, &kd_nowait); cp = km_alloc(round_page(size), &kv_any, &kp_zero, &kd_nowait);
if (cp == NULL) { if (cp == NULL) {
printf("No memory for profiling.\n"); printf("No memory for profiling.\n");
return; return;
} }
clockintr_bind(&ci->ci_gmonclock, ci, gmonclock, NULL);
clockintr_stagger(&ci->ci_gmonclock, profclock_period,
CPU_INFO_UNIT(ci), MAXCPUS);
p = (struct gmonparam *)cp; p = (struct gmonparam *)cp;
cp += sizeof(*p); cp += sizeof(*p);
p->tos = (struct tostruct *)cp; p->tos = (struct tostruct *)cp;
@ -159,7 +156,7 @@ prof_state_toggle(struct cpu_info *ci, int oldstate)
if (error == 0) { if (error == 0) {
if (++gmon_cpu_count == 1) if (++gmon_cpu_count == 1)
startprofclock(&process0); startprofclock(&process0);
clockintr_advance(ci->ci_gmonclock, profclock_period); clockintr_advance(&ci->ci_gmonclock, profclock_period);
} }
break; break;
default: default:
@ -167,7 +164,7 @@ prof_state_toggle(struct cpu_info *ci, int oldstate)
gp->state = GMON_PROF_OFF; gp->state = GMON_PROF_OFF;
/* FALLTHROUGH */ /* FALLTHROUGH */
case GMON_PROF_OFF: case GMON_PROF_OFF:
clockintr_cancel(ci->ci_gmonclock); clockintr_cancel(&ci->ci_gmonclock);
if (--gmon_cpu_count == 0) if (--gmon_cpu_count == 0)
stopprofclock(&process0); stopprofclock(&process0);
#if !defined(GPROF) #if !defined(GPROF)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: clockintr.h,v 1.24 2024/01/15 01:15:37 cheloha Exp $ */ /* $OpenBSD: clockintr.h,v 1.25 2024/01/24 19:23:38 cheloha Exp $ */
/* /*
* Copyright (c) 2020-2022 Scott Cheloha <cheloha@openbsd.org> * Copyright (c) 2020-2022 Scott Cheloha <cheloha@openbsd.org>
* *
@ -102,7 +102,7 @@ struct clockintr_queue {
TAILQ_HEAD(, clockintr) cq_all; /* [m] established clockintr list */ TAILQ_HEAD(, clockintr) cq_all; /* [m] established clockintr list */
TAILQ_HEAD(, clockintr) cq_pend;/* [m] pending clockintr list */ TAILQ_HEAD(, clockintr) cq_pend;/* [m] pending clockintr list */
struct clockintr *cq_running; /* [m] running clockintr */ struct clockintr *cq_running; /* [m] running clockintr */
struct clockintr *cq_hardclock; /* [o] hardclock handle */ struct clockintr cq_hardclock; /* [o] hardclock handle */
struct intrclock cq_intrclock; /* [I] local interrupt clock */ struct intrclock cq_intrclock; /* [I] local interrupt clock */
struct clockintr_stat cq_stat; /* [o] dispatch statistics */ struct clockintr_stat cq_stat; /* [o] dispatch statistics */
volatile uint32_t cq_gen; /* [o] cq_stat update generation */ volatile uint32_t cq_gen; /* [o] cq_stat update generation */
@ -124,9 +124,9 @@ void clockintr_trigger(void);
*/ */
uint64_t clockintr_advance(struct clockintr *, uint64_t); uint64_t clockintr_advance(struct clockintr *, uint64_t);
void clockintr_cancel(struct clockintr *); void clockintr_bind(struct clockintr *, struct cpu_info *,
struct clockintr *clockintr_establish(struct cpu_info *,
void (*)(struct clockrequest *, void *, void *), void *); void (*)(struct clockrequest *, void *, void *), void *);
void clockintr_cancel(struct clockintr *);
void clockintr_schedule(struct clockintr *, uint64_t); void clockintr_schedule(struct clockintr *, uint64_t);
void clockintr_stagger(struct clockintr *, uint64_t, uint32_t, uint32_t); void clockintr_stagger(struct clockintr *, uint64_t, uint32_t, uint32_t);
uint64_t clockrequest_advance(struct clockrequest *, uint64_t); uint64_t clockrequest_advance(struct clockrequest *, uint64_t);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sched.h,v 1.69 2024/01/14 17:23:56 cheloha Exp $ */ /* $OpenBSD: sched.h,v 1.70 2024/01/24 19:23:38 cheloha Exp $ */
/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */ /* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
/*- /*-
@ -95,11 +95,11 @@ struct cpustats {
#ifdef _KERNEL #ifdef _KERNEL
#include <sys/clockintr.h>
#include <sys/queue.h> #include <sys/queue.h>
#define SCHED_NQS 32 /* 32 run queues. */ #define SCHED_NQS 32 /* 32 run queues. */
struct clockintr;
struct smr_entry; struct smr_entry;
/* /*
@ -115,10 +115,10 @@ struct schedstate_percpu {
u_int64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */ u_int64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */
u_char spc_curpriority; /* usrpri of curproc */ u_char spc_curpriority; /* usrpri of curproc */
struct clockintr *spc_itimer; /* [o] itimer_update handle */ struct clockintr spc_itimer; /* [o] itimer_update handle */
struct clockintr *spc_profclock; /* [o] profclock handle */ struct clockintr spc_profclock; /* [o] profclock handle */
struct clockintr *spc_roundrobin; /* [o] roundrobin handle */ struct clockintr spc_roundrobin;/* [o] roundrobin handle */
struct clockintr *spc_statclock; /* [o] statclock handle */ struct clockintr spc_statclock; /* [o] statclock handle */
u_int spc_nrun; /* procs on the run queues */ u_int spc_nrun; /* procs on the run queues */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde.c,v 1.616 2024/01/23 16:13:35 claudio Exp $ */ /* $OpenBSD: rde.c,v 1.617 2024/01/24 14:51:11 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -2139,8 +2139,8 @@ rde_attr_parse(struct ibuf *buf, struct rde_peer *peer,
if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE,
ATTR_PARTIAL)) ATTR_PARTIAL))
goto bad_flags; goto bad_flags;
if (community_add(&state->communities, flags, p, if (community_add(&state->communities, flags,
attr_len) == -1) { &attrbuf) == -1) {
/* /*
* mark update as bad and withdraw all routes as per * mark update as bad and withdraw all routes as per
* RFC 7606 * RFC 7606
@ -2149,14 +2149,13 @@ rde_attr_parse(struct ibuf *buf, struct rde_peer *peer,
log_peer_warnx(&peer->conf, "bad COMMUNITIES, " log_peer_warnx(&peer->conf, "bad COMMUNITIES, "
"path invalidated and prefix withdrawn"); "path invalidated and prefix withdrawn");
} }
plen += attr_len;
break; break;
case ATTR_LARGE_COMMUNITIES: case ATTR_LARGE_COMMUNITIES:
if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE,
ATTR_PARTIAL)) ATTR_PARTIAL))
goto bad_flags; goto bad_flags;
if (community_large_add(&state->communities, flags, p, if (community_large_add(&state->communities, flags,
attr_len) == -1) { &attrbuf) == -1) {
/* /*
* mark update as bad and withdraw all routes as per * mark update as bad and withdraw all routes as per
* RFC 7606 * RFC 7606
@ -2165,14 +2164,13 @@ rde_attr_parse(struct ibuf *buf, struct rde_peer *peer,
log_peer_warnx(&peer->conf, "bad LARGE COMMUNITIES, " log_peer_warnx(&peer->conf, "bad LARGE COMMUNITIES, "
"path invalidated and prefix withdrawn"); "path invalidated and prefix withdrawn");
} }
plen += attr_len;
break; break;
case ATTR_EXT_COMMUNITIES: case ATTR_EXT_COMMUNITIES:
if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE,
ATTR_PARTIAL)) ATTR_PARTIAL))
goto bad_flags; goto bad_flags;
if (community_ext_add(&state->communities, flags, if (community_ext_add(&state->communities, flags,
peer->conf.ebgp, p, attr_len) == -1) { peer->conf.ebgp, &attrbuf) == -1) {
/* /*
* mark update as bad and withdraw all routes as per * mark update as bad and withdraw all routes as per
* RFC 7606 * RFC 7606
@ -2181,7 +2179,6 @@ rde_attr_parse(struct ibuf *buf, struct rde_peer *peer,
log_peer_warnx(&peer->conf, "bad EXT_COMMUNITIES, " log_peer_warnx(&peer->conf, "bad EXT_COMMUNITIES, "
"path invalidated and prefix withdrawn"); "path invalidated and prefix withdrawn");
} }
plen += attr_len;
break; break;
case ATTR_ORIGINATOR_ID: case ATTR_ORIGINATOR_ID:
if (attr_len != 4) if (attr_len != 4)
@ -2338,14 +2335,11 @@ rde_attr_add(struct filterstate *state, struct ibuf *buf)
switch (type) { switch (type) {
case ATTR_COMMUNITIES: case ATTR_COMMUNITIES:
return community_add(&state->communities, flags, return community_add(&state->communities, flags, buf);
ibuf_data(buf), attr_len);
case ATTR_LARGE_COMMUNITIES: case ATTR_LARGE_COMMUNITIES:
return community_large_add(&state->communities, flags, return community_large_add(&state->communities, flags, buf);
ibuf_data(buf), attr_len);
case ATTR_EXT_COMMUNITIES: case ATTR_EXT_COMMUNITIES:
return community_ext_add(&state->communities, flags, 0, return community_ext_add(&state->communities, flags, 0, buf);
ibuf_data(buf), attr_len);
} }
if (attr_optadd(&state->aspath, flags, type, ibuf_data(buf), if (attr_optadd(&state->aspath, flags, type, ibuf_data(buf),

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde.h,v 1.298 2024/01/23 16:13:35 claudio Exp $ */ /* $OpenBSD: rde.h,v 1.299 2024/01/24 14:51:12 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
@ -435,10 +435,9 @@ int community_set(struct rde_community *, struct community *,
void community_delete(struct rde_community *, struct community *, void community_delete(struct rde_community *, struct community *,
struct rde_peer *); struct rde_peer *);
int community_add(struct rde_community *, int, void *, size_t); int community_add(struct rde_community *, int, struct ibuf *);
int community_large_add(struct rde_community *, int, void *, size_t); int community_large_add(struct rde_community *, int, struct ibuf *);
int community_ext_add(struct rde_community *, int, int, void *, size_t); int community_ext_add(struct rde_community *, int, int, struct ibuf *);
int community_writebuf(struct rde_community *, uint8_t, int, struct ibuf *); int community_writebuf(struct rde_community *, uint8_t, int, struct ibuf *);
void communities_shutdown(void); void communities_shutdown(void);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde_community.c,v 1.14 2023/10/10 14:36:28 claudio Exp $ */ /* $OpenBSD: rde_community.c,v 1.15 2024/01/24 14:51:12 claudio Exp $ */
/* /*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
@ -418,24 +418,23 @@ struct rde_peer *peer)
* - community_ext_add for ATTR_EXT_COMMUNITIES * - community_ext_add for ATTR_EXT_COMMUNITIES
*/ */
int int
community_add(struct rde_community *comm, int flags, void *buf, size_t len) community_add(struct rde_community *comm, int flags, struct ibuf *buf)
{ {
struct community set = { .flags = COMMUNITY_TYPE_BASIC }; struct community set = { .flags = COMMUNITY_TYPE_BASIC };
uint8_t *b = buf; uint16_t data1, data2;
uint16_t c;
size_t l;
if (len == 0 || len % 4 != 0) if (ibuf_size(buf) == 0 || ibuf_size(buf) % 4 != 0)
return -1; return -1;
if (flags & ATTR_PARTIAL) if (flags & ATTR_PARTIAL)
comm->flags |= PARTIAL_COMMUNITIES; comm->flags |= PARTIAL_COMMUNITIES;
for (l = 0; l < len; l += 4, b += 4) { while (ibuf_size(buf) > 0) {
memcpy(&c, b, sizeof(c)); if (ibuf_get_n16(buf, &data1) == -1 ||
set.data1 = ntohs(c); ibuf_get_n16(buf, &data2) == -1)
memcpy(&c, b + 2, sizeof(c)); return -1;
set.data2 = ntohs(c); set.data1 = data1;
set.data2 = data2;
insert_community(comm, &set); insert_community(comm, &set);
} }
@ -443,26 +442,21 @@ community_add(struct rde_community *comm, int flags, void *buf, size_t len)
} }
int int
community_large_add(struct rde_community *comm, int flags, void *buf, community_large_add(struct rde_community *comm, int flags, struct ibuf *buf)
size_t len)
{ {
struct community set = { .flags = COMMUNITY_TYPE_LARGE }; struct community set = { .flags = COMMUNITY_TYPE_LARGE };
uint8_t *b = buf;
size_t l;
if (len == 0 || len % 12 != 0) if (ibuf_size(buf) == 0 || ibuf_size(buf) % 12 != 0)
return -1; return -1;
if (flags & ATTR_PARTIAL) if (flags & ATTR_PARTIAL)
comm->flags |= PARTIAL_LARGE_COMMUNITIES; comm->flags |= PARTIAL_LARGE_COMMUNITIES;
for (l = 0; l < len; l += 12, b += 12) { while (ibuf_size(buf) > 0) {
memcpy(&set.data1, b, sizeof(set.data1)); if (ibuf_get_n32(buf, &set.data1) == -1 ||
memcpy(&set.data2, b + 4, sizeof(set.data2)); ibuf_get_n32(buf, &set.data2) == -1 ||
memcpy(&set.data3, b + 8, sizeof(set.data3)); ibuf_get_n32(buf, &set.data3) == -1)
set.data1 = ntohl(set.data1); return -1;
set.data2 = ntohl(set.data2);
set.data3 = ntohl(set.data3);
insert_community(comm, &set); insert_community(comm, &set);
} }
@ -471,23 +465,22 @@ community_large_add(struct rde_community *comm, int flags, void *buf,
int int
community_ext_add(struct rde_community *comm, int flags, int ebgp, community_ext_add(struct rde_community *comm, int flags, int ebgp,
void *buf, size_t len) struct ibuf *buf)
{ {
struct community set = { .flags = COMMUNITY_TYPE_EXT }; struct community set = { .flags = COMMUNITY_TYPE_EXT };
uint8_t *b = buf, type;
uint64_t c; uint64_t c;
size_t l; uint8_t type;
if (len == 0 || len % 8 != 0) if (ibuf_size(buf) == 0 || ibuf_size(buf) % 8 != 0)
return -1; return -1;
if (flags & ATTR_PARTIAL) if (flags & ATTR_PARTIAL)
comm->flags |= PARTIAL_EXT_COMMUNITIES; comm->flags |= PARTIAL_EXT_COMMUNITIES;
for (l = 0; l < len; l += 8, b += 8) { while (ibuf_size(buf) > 0) {
memcpy(&c, b, 8); if (ibuf_get_n64(buf, &c) == -1)
return (-1);
c = be64toh(c);
type = c >> 56; type = c >> 56;
/* filter out non-transitive ext communuties from ebgp peers */ /* filter out non-transitive ext communuties from ebgp peers */
if (ebgp && (type & EXT_COMMUNITY_NON_TRANSITIVE)) if (ebgp && (type & EXT_COMMUNITY_NON_TRANSITIVE))