sync with OpenBSD -current

This commit is contained in:
purplerain 2024-08-26 19:12:03 +00:00
parent f6cff6bc9b
commit 84a7643638
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
38 changed files with 674 additions and 418 deletions

View file

@ -1,4 +1,4 @@
.\" $OpenBSD: hostname.1,v 1.21 2011/01/24 19:58:32 jmc Exp $
.\" $OpenBSD: hostname.1,v 1.22 2024/08/25 09:32:08 tb Exp $
.\" $NetBSD: hostname.1,v 1.11 1995/09/07 06:28:39 jtc Exp $
.\"
.\" Copyright (c) 1983, 1988, 1990, 1993
@ -30,7 +30,7 @@
.\"
.\" @(#)hostname.1 8.2 (Berkeley) 4/28/95
.\"
.Dd $Mdocdate: January 24 2011 $
.Dd $Mdocdate: August 25 2024 $
.Dt HOSTNAME 1
.Os
.Sh NAME
@ -53,7 +53,7 @@ or by supplying a
.Xr myname 5
file,
which is used at system boot time by
.Xr netstart 8
.Xr rc 8
to initialize the hostname.
.Pp
The options are as follows:
@ -67,7 +67,7 @@ name.
.Xr gethostname 3 ,
.Xr myname 5 ,
.Xr hostname 7 ,
.Xr netstart 8
.Xr rc 8
.Sh HISTORY
The
.Nm

View file

@ -1,6 +1,6 @@
# $OpenBSD: Makefile,v 1.5 2019/04/30 20:38:30 deraadt Exp $
SUBDIR= ramdisk_cd ramdiskA
SUBDIR= ramdisk_cd
.if make(obj) || make(cleandir) || make(clean)
SUBDIR+= iso
@ -8,6 +8,5 @@ SUBDIR+= iso
unconfig:
cd ramdisk_cd; ${MAKE} unconfig
cd ramdiskA; ${MAKE} unconfig
.include <bsd.subdir.mk>

View file

@ -1,4 +1,4 @@
/* $OpenBSD: bitstring.h,v 1.6 2020/05/10 00:56:06 guenther Exp $ */
/* $OpenBSD: bitstring.h,v 1.7 2024/08/26 11:52:54 bluhm Exp $ */
/* $NetBSD: bitstring.h,v 1.5 1997/05/14 15:49:55 pk Exp $ */
/*
@ -70,16 +70,22 @@ typedef unsigned char bitstr_t;
((name)[bitstr_size(nbits)])
/* is bit N of bitstring name set? */
#define bit_test(name, bit) \
((name)[_bit_byte(bit)] & _bit_mask(bit))
#define bit_test(name, bit) ({ \
register int __tbit = (bit); \
((name)[_bit_byte(__tbit)] & _bit_mask(__tbit)); \
})
/* set bit N of bitstring name */
#define bit_set(name, bit) \
((name)[_bit_byte(bit)] |= _bit_mask(bit))
#define bit_set(name, bit) do { \
register int __sbit = (bit); \
((name)[_bit_byte(__sbit)] |= _bit_mask(__sbit)); \
} while(0)
/* clear bit N of bitstring name */
#define bit_clear(name, bit) \
((name)[_bit_byte(bit)] &= ~_bit_mask(bit))
#define bit_clear(name, bit) do { \
register int __cbit = (bit); \
((name)[_bit_byte(__cbit)] &= ~_bit_mask(__cbit)); \
} while(0)
/* clear bits start ... stop in bitstring */
#define bit_nclear(name, start, stop) do { \

View file

@ -1,4 +1,4 @@
/* $OpenBSD: imsg-buffer.c,v 1.18 2023/12/12 15:47:41 claudio Exp $ */
/* $OpenBSD: imsg-buffer.c,v 1.19 2024/08/26 13:57:34 claudio Exp $ */
/*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@ -94,9 +94,10 @@ ibuf_realloc(struct ibuf *buf, size_t len)
return (-1);
}
b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1);
b = realloc(buf->buf, buf->wpos + len);
if (b == NULL)
return (-1);
memset(b + buf->size, 0, buf->wpos + len - buf->size);
buf->buf = b;
buf->size = buf->wpos + len;

View file

@ -1,27 +1,20 @@
# $OpenBSD: Makefile,v 1.4 2002/09/02 20:01:43 avsm Exp $
# $OpenBSD: Makefile,v 1.5 2024/08/26 12:15:40 bluhm Exp $
# $NetBSD: Makefile,v 1.4 1995/04/20 22:37:50 cgd Exp $
PROG= ./bitstring_test
PROG= bitstring_test
REGRESS_TARGETS=test-8 test-27 test-32 test-49 test-64 test-67
REGRESS_TARGETS=
test-8: ${PROG}
${PROG} 8 | diff - ${.CURDIR}/good/8
.for i in 8 27 32 49 64 67
test-27: ${PROG}
${PROG} 27 | diff - ${.CURDIR}/good/27
REGRESS_TARGETS+= run-test-$i
run-test-$i: ${PROG}
./${PROG} $i | diff - ${.CURDIR}/good/$i
test-32: ${PROG}
${PROG} 32 | diff - ${.CURDIR}/good/32
test-49: ${PROG}
${PROG} 49 | diff - ${.CURDIR}/good/49
test-64: ${PROG}
${PROG} 64 | diff - ${.CURDIR}/good/64
test-67: ${PROG}
${PROG} 67 | diff - ${.CURDIR}/good/67
create-good: create-$i
create-$i: ${PROG}
./${PROG} $i >${.CURDIR}/good/$i
.endfor
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
/* $OpenBSD: bitstring_test.c,v 1.6 2024/08/23 17:19:16 florian Exp $ */
/* $OpenBSD: bitstring_test.c,v 1.7 2024/08/26 12:15:40 bluhm Exp $ */
/* $NetBSD: bitstring_test.c,v 1.4 1995/04/29 05:44:35 cgd Exp $ */
/*
@ -6,7 +6,7 @@
* inspect the output, you should notice problems
* choose the ATT or BSD flavor
*/
/* #define ATT /*- */
// #define ATT /*-*/
#define BSD /*-*/
/*
@ -39,7 +39,7 @@ clearbits(bitstr_t *b, int n)
static void
printbits(bitstr_t *b, int n)
{
register int i;
register int i, k;
int jc, js;
bit_ffc(b, n, &jc);
@ -54,7 +54,7 @@ printbits(bitstr_t *b, int n)
int
main(int argc, char *argv[])
{
int i;
int i, j, k, *p;
bitstr_t *bs;
bitstr_t bit_decl(bss, DECL_TEST_LENGTH);
@ -64,7 +64,8 @@ main(int argc, char *argv[])
TEST_LENGTH = DECL_TEST_LENGTH;
if (TEST_LENGTH < 4) {
fprintf(stderr, "TEST_LENGTH must be at least 4, but it is %d\n",
fprintf(stderr,
"TEST_LENGTH must be at least 4, but it is %d\n",
TEST_LENGTH);
exit(1);
}
@ -92,7 +93,7 @@ main(int argc, char *argv[])
}
(void) printf("be: 1 0 ");
for (i = 0; i < TEST_LENGTH; i++)
(void) putchar(*("100" + (i % 3)));
(void) putchar("100"[i % 3]);
(void) printf("\nis: ");
printbits(bs, TEST_LENGTH);
@ -102,7 +103,7 @@ main(int argc, char *argv[])
}
(void) printf("be: 0 3 ");
for (i = 0; i < TEST_LENGTH; i++)
(void) putchar(*("000100" + (i % 6)));
(void) putchar("000100"[i % 6]);
(void) printf("\nis: ");
printbits(bs, TEST_LENGTH);
@ -220,6 +221,38 @@ main(int argc, char *argv[])
printbits(bs, TEST_LENGTH);
}
(void) printf("\n");
(void) printf("macros should evaluate arguments only once\n");
i = j = 0;
_bit_byte(i++);
(void) printf("_bit_byte(%d) -> %d\n", j++, i);
_bit_mask(i++);
(void) printf("_bit_mask(%d) -> %d\n", j++, i);
bitstr_size(i++);
(void) printf("bitstr_size(%d) -> %d\n", j++, i);
free(bit_alloc(i++));
(void) printf("bit_alloc(%d) -> %d\n", j++, i);
{ bitstr_t bit_decl(bd, i++); }
(void) printf("bit_alloc(%d) -> %d\n", j++, i);
bit_test(bs, i++);
(void) printf("bit_test(%d) -> %d\n", j++, i);
bit_set(bs, i++);
(void) printf("bit_set(%d) -> %d\n", j++, i);
bit_clear(bs, i++);
(void) printf("bit_clear(%d) -> %d\n", j++, i);
i %= TEST_LENGTH; j %= TEST_LENGTH;
bit_nclear(bs, i++, i++);
(void) printf("bit_nclear(%d, %d) -> %d\n", j, j + 1, i);
j += 2;
bit_nset(bs, i++, i++);
(void) printf("bit_nset(%d, %d) -> %d\n", j, j + 1, i);
j += 2;
p = &k;
bit_ffc(bs, i++, p++);
(void) printf("bit_ffc(%d, %ld) -> %d\n", j++, --p - &k, i);
bit_ffs(bs, i++, p++);
(void) printf("bit_ffs(%d, %ld) -> %d\n", j++, --p - &k, i);
(void) free(bs);
(void) exit(0);
return (0);
}

View file

@ -290,3 +290,17 @@ CHI square test
24 0 2 001000000000000000000000100
25 0 1 010000000000000000000000010
26 1 0 100000000000000000000000001
macros should evaluate arguments only once
_bit_byte(0) -> 1
_bit_mask(1) -> 2
bitstr_size(2) -> 3
bit_alloc(3) -> 4
bit_alloc(4) -> 5
bit_test(5) -> 6
bit_set(6) -> 7
bit_clear(7) -> 8
bit_nclear(8, 9) -> 10
bit_nset(10, 11) -> 12
bit_ffc(12, 0) -> 13
bit_ffs(13, 0) -> 14

View file

@ -335,3 +335,17 @@ CHI square test
29 0 2 00100000000000000000000000000100
30 0 1 01000000000000000000000000000010
31 1 0 10000000000000000000000000000001
macros should evaluate arguments only once
_bit_byte(0) -> 1
_bit_mask(1) -> 2
bitstr_size(2) -> 3
bit_alloc(3) -> 4
bit_alloc(4) -> 5
bit_test(5) -> 6
bit_set(6) -> 7
bit_clear(7) -> 8
bit_nclear(8, 9) -> 10
bit_nset(10, 11) -> 12
bit_ffc(12, 0) -> 13
bit_ffs(13, 0) -> 14

View file

@ -488,3 +488,17 @@ CHI square test
46 0 2 0010000000000000000000000000000000000000000000100
47 0 1 0100000000000000000000000000000000000000000000010
48 1 0 1000000000000000000000000000000000000000000000001
macros should evaluate arguments only once
_bit_byte(0) -> 1
_bit_mask(1) -> 2
bitstr_size(2) -> 3
bit_alloc(3) -> 4
bit_alloc(4) -> 5
bit_test(5) -> 6
bit_set(6) -> 7
bit_clear(7) -> 8
bit_nclear(8, 9) -> 10
bit_nset(10, 11) -> 12
bit_ffc(12, 0) -> 13
bit_ffs(13, 0) -> 14

View file

@ -623,3 +623,17 @@ CHI square test
61 0 2 0010000000000000000000000000000000000000000000000000000000000100
62 0 1 0100000000000000000000000000000000000000000000000000000000000010
63 1 0 1000000000000000000000000000000000000000000000000000000000000001
macros should evaluate arguments only once
_bit_byte(0) -> 1
_bit_mask(1) -> 2
bitstr_size(2) -> 3
bit_alloc(3) -> 4
bit_alloc(4) -> 5
bit_test(5) -> 6
bit_set(6) -> 7
bit_clear(7) -> 8
bit_nclear(8, 9) -> 10
bit_nset(10, 11) -> 12
bit_ffc(12, 0) -> 13
bit_ffs(13, 0) -> 14

View file

@ -650,3 +650,17 @@ CHI square test
64 0 2 0010000000000000000000000000000000000000000000000000000000000000100
65 0 1 0100000000000000000000000000000000000000000000000000000000000000010
66 1 0 1000000000000000000000000000000000000000000000000000000000000000001
macros should evaluate arguments only once
_bit_byte(0) -> 1
_bit_mask(1) -> 2
bitstr_size(2) -> 3
bit_alloc(3) -> 4
bit_alloc(4) -> 5
bit_test(5) -> 6
bit_set(6) -> 7
bit_clear(7) -> 8
bit_nclear(8, 9) -> 10
bit_nset(10, 11) -> 12
bit_ffc(12, 0) -> 13
bit_ffs(13, 0) -> 14

View file

@ -119,3 +119,17 @@ CHI square test
5 0 2 00100100
6 0 1 01000010
7 1 0 10000001
macros should evaluate arguments only once
_bit_byte(0) -> 1
_bit_mask(1) -> 2
bitstr_size(2) -> 3
bit_alloc(3) -> 4
bit_alloc(4) -> 5
bit_test(5) -> 6
bit_set(6) -> 7
bit_clear(7) -> 8
bit_nclear(0, 1) -> 2
bit_nset(2, 3) -> 4
bit_ffc(4, 0) -> 5
bit_ffs(5, 0) -> 6

View file

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.4 2021/08/01 09:07:03 florian Exp $ */
/* $OpenBSD: control.c,v 1.5 2024/08/25 09:53:53 florian Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -224,6 +224,8 @@ control_dispatch_imsg(int fd, short event, void *bula)
struct imsg imsg;
ssize_t n;
int verbose;
uint32_t if_index, type;
pid_t pid;
if ((c = control_connbyfd(fd)) == NULL) {
log_warnx("%s: fd %d: not found", __func__, fd);
@ -252,40 +254,47 @@ control_dispatch_imsg(int fd, short event, void *bula)
if (n == 0)
break;
switch (imsg.hdr.type) {
type = imsg_get_type(&imsg);
pid = imsg_get_pid(&imsg);
switch (type) {
case IMSG_CTL_RELOAD:
frontend_imsg_compose_main(imsg.hdr.type, 0, NULL, 0);
frontend_imsg_compose_main(type, 0, NULL, 0);
break;
case IMSG_CTL_LOG_VERBOSE:
if (IMSG_DATA_SIZE(imsg) != sizeof(verbose))
if (imsg_get_data(&imsg, &verbose,
sizeof(verbose)) == -1)
break;
c->iev.ibuf.pid = imsg.hdr.pid;
/* Forward to all other processes. */
frontend_imsg_compose_main(imsg.hdr.type, imsg.hdr.pid,
imsg.data, IMSG_DATA_SIZE(imsg));
frontend_imsg_compose_engine(imsg.hdr.type, 0,
imsg.hdr.pid, imsg.data, IMSG_DATA_SIZE(imsg));
memcpy(&verbose, imsg.data, sizeof(verbose));
c->iev.ibuf.pid = pid;
/* Forward to all other processes. */
frontend_imsg_compose_main(type, pid, &verbose,
sizeof(verbose));
frontend_imsg_compose_engine(type, 0, pid, &verbose,
sizeof(verbose));
log_setverbose(verbose);
break;
case IMSG_CTL_SHOW_INTERFACE_INFO:
if (IMSG_DATA_SIZE(imsg) != sizeof(uint32_t))
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
break;
c->iev.ibuf.pid = imsg.hdr.pid;
frontend_imsg_compose_engine(imsg.hdr.type, 0,
imsg.hdr.pid, imsg.data, IMSG_DATA_SIZE(imsg));
c->iev.ibuf.pid = pid;
frontend_imsg_compose_engine(type, 0, pid, &if_index,
sizeof(if_index));
break;
case IMSG_CTL_SEND_REQUEST:
if (IMSG_DATA_SIZE(imsg) != sizeof(uint32_t))
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
break;
c->iev.ibuf.pid = imsg.hdr.pid;
c->iev.ibuf.pid = pid;
frontend_imsg_compose_engine(IMSG_REQUEST_REBOOT, 0,
imsg.hdr.pid, imsg.data, IMSG_DATA_SIZE(imsg));
pid, &if_index, sizeof(&if_index));
break;
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
log_debug("%s: error handling imsg %d", __func__, type);
break;
}
imsg_free(&imsg);
@ -299,9 +308,8 @@ control_imsg_relay(struct imsg *imsg)
{
struct ctl_conn *c;
if ((c = control_connbypid(imsg->hdr.pid)) == NULL)
if ((c = control_connbypid(imsg_get_pid(imsg))) == NULL)
return (0);
return (imsg_compose_event(&c->iev, imsg->hdr.type, 0, imsg->hdr.pid,
-1, imsg->data, IMSG_DATA_SIZE(*imsg)));
return (imsg_forward_event(&c->iev, imsg));
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dhcpleased.c,v 1.30 2023/10/10 16:09:53 florian Exp $ */
/* $OpenBSD: dhcpleased.c,v 1.31 2024/08/25 09:53:53 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@ -436,7 +436,7 @@ main_dispatch_frontend(int fd, short event, void *bula)
struct imsg_ifinfo imsg_ifinfo;
ssize_t n;
int shut = 0;
uint32_t if_index;
uint32_t if_index, type;
#ifndef SMALL
int verbose;
#endif /* SMALL */
@ -462,12 +462,14 @@ main_dispatch_frontend(int fd, short event, void *bula)
if (n == 0) /* No more messages. */
break;
switch (imsg.hdr.type) {
type = imsg_get_type(&imsg);
switch (type) {
case IMSG_OPEN_BPFSOCK:
if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatalx("%s: IMSG_OPEN_BPFSOCK wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
open_bpfsock(if_index);
break;
#ifndef SMALL
@ -478,25 +480,24 @@ main_dispatch_frontend(int fd, short event, void *bula)
log_warnx("configuration reloaded");
break;
case IMSG_CTL_LOG_VERBOSE:
if (IMSG_DATA_SIZE(imsg) != sizeof(verbose))
fatalx("%s: IMSG_CTL_LOG_VERBOSE wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&verbose, imsg.data, sizeof(verbose));
if (imsg_get_data(&imsg, &verbose,
sizeof(verbose)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
log_setverbose(verbose);
break;
#endif /* SMALL */
case IMSG_UPDATE_IF:
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_ifinfo))
fatalx("%s: IMSG_UPDATE_IF wrong length: %lu",
__func__, IMSG_DATA_SIZE(imsg));
memcpy(&imsg_ifinfo, imsg.data, sizeof(imsg_ifinfo));
if (imsg_get_data(&imsg, &imsg_ifinfo,
sizeof(imsg_ifinfo)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
read_lease_file(&imsg_ifinfo);
main_imsg_compose_engine(IMSG_UPDATE_IF, -1,
&imsg_ifinfo, sizeof(imsg_ifinfo));
break;
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
log_debug("%s: error handling imsg %d", __func__, type);
break;
}
imsg_free(&imsg);
@ -517,6 +518,7 @@ main_dispatch_engine(int fd, short event, void *bula)
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
uint32_t type;
int shut = 0;
ibuf = &iev->ibuf;
@ -540,15 +542,16 @@ main_dispatch_engine(int fd, short event, void *bula)
if (n == 0) /* No more messages. */
break;
switch (imsg.hdr.type) {
type = imsg_get_type(&imsg);
switch (type) {
case IMSG_CONFIGURE_INTERFACE: {
struct imsg_configure_interface imsg_interface;
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_interface))
fatalx("%s: IMSG_CONFIGURE_INTERFACE wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&imsg_interface, imsg.data,
sizeof(imsg_interface));
if (imsg_get_data(&imsg, &imsg_interface,
sizeof(imsg_interface)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if (imsg_interface.routes_len >= MAX_DHCP_ROUTES)
fatalx("%s: too many routes in imsg", __func__);
configure_interface(&imsg_interface);
@ -556,14 +559,13 @@ main_dispatch_engine(int fd, short event, void *bula)
}
case IMSG_DECONFIGURE_INTERFACE: {
struct imsg_configure_interface imsg_interface;
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_interface))
fatalx("%s: IMSG_CONFIGURE_INTERFACE wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&imsg_interface, imsg.data,
sizeof(imsg_interface));
if (imsg_get_data(&imsg, &imsg_interface,
sizeof(imsg_interface)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if (imsg_interface.routes_len >= MAX_DHCP_ROUTES)
fatalx("%s: too many routes in imsg", __func__);
deconfigure_interface(&imsg_interface);
main_imsg_compose_frontend(IMSG_CLOSE_UDPSOCK, -1,
&imsg_interface.if_index,
@ -572,48 +574,44 @@ main_dispatch_engine(int fd, short event, void *bula)
}
case IMSG_WITHDRAW_ROUTES: {
struct imsg_configure_interface imsg_interface;
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_interface))
fatalx("%s: IMSG_CONFIGURE_INTERFACE wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&imsg_interface, imsg.data,
sizeof(imsg_interface));
if (imsg_get_data(&imsg, &imsg_interface,
sizeof(imsg_interface)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if (imsg_interface.routes_len >= MAX_DHCP_ROUTES)
fatalx("%s: too many routes in imsg", __func__);
if (imsg_interface.routes_len > 0)
configure_routes(RTM_DELETE, &imsg_interface);
break;
}
case IMSG_PROPOSE_RDNS: {
struct imsg_propose_rdns rdns;
if (IMSG_DATA_SIZE(imsg) != sizeof(rdns))
fatalx("%s: IMSG_PROPOSE_RDNS wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&rdns, imsg.data, sizeof(rdns));
if (imsg_get_data(&imsg, &rdns, sizeof(rdns)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((2 + rdns.rdns_count * sizeof(struct in_addr)) >
sizeof(struct sockaddr_rtdns))
fatalx("%s: rdns_count too big: %d", __func__,
rdns.rdns_count);
propose_rdns(&rdns);
break;
}
case IMSG_WITHDRAW_RDNS: {
struct imsg_propose_rdns rdns;
if (IMSG_DATA_SIZE(imsg) != sizeof(rdns))
fatalx("%s: IMSG_WITHDRAW_RDNS wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&rdns, imsg.data, sizeof(rdns));
if (imsg_get_data(&imsg, &rdns, sizeof(rdns)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if (rdns.rdns_count != 0)
fatalx("%s: expected rdns_count == 0: %d",
__func__, rdns.rdns_count);
propose_rdns(&rdns);
break;
}
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
log_debug("%s: error handling imsg %d", __func__, type);
break;
}
imsg_free(&imsg);
@ -672,6 +670,17 @@ imsg_compose_event(struct imsgev *iev, uint16_t type, uint32_t peerid,
return (ret);
}
int
imsg_forward_event(struct imsgev *iev, struct imsg *imsg)
{
int ret;
if ((ret = imsg_forward(&iev->ibuf, imsg)) != -1)
imsg_event_add(iev);
return (ret);
}
static int
main_imsg_send_ipc_sockets(struct imsgbuf *frontend_buf,
struct imsgbuf *engine_buf)
@ -1293,4 +1302,52 @@ config_clear(struct dhcpleased_conf *conf)
free(conf);
}
#define I2S(x) case x: return #x
const char*
i2s(uint32_t type)
{
static char unknown[sizeof("IMSG_4294967295")];
switch (type) {
I2S(IMSG_NONE);
I2S(IMSG_CTL_LOG_VERBOSE);
I2S(IMSG_CTL_SHOW_INTERFACE_INFO);
I2S(IMSG_CTL_SEND_REQUEST);
I2S(IMSG_CTL_RELOAD);
I2S(IMSG_CTL_END);
I2S(IMSG_RECONF_CONF);
I2S(IMSG_RECONF_IFACE);
I2S(IMSG_RECONF_VC_ID);
I2S(IMSG_RECONF_C_ID);
I2S(IMSG_RECONF_H_NAME);
I2S(IMSG_RECONF_END);
I2S(IMSG_SEND_DISCOVER);
I2S(IMSG_SEND_REQUEST);
I2S(IMSG_SOCKET_IPC);
I2S(IMSG_OPEN_BPFSOCK);
I2S(IMSG_BPFSOCK);
I2S(IMSG_UDPSOCK);
I2S(IMSG_CLOSE_UDPSOCK);
I2S(IMSG_ROUTESOCK);
I2S(IMSG_CONTROLFD);
I2S(IMSG_STARTUP);
I2S(IMSG_UPDATE_IF);
I2S(IMSG_REMOVE_IF);
I2S(IMSG_DHCP);
I2S(IMSG_CONFIGURE_INTERFACE);
I2S(IMSG_DECONFIGURE_INTERFACE);
I2S(IMSG_PROPOSE_RDNS);
I2S(IMSG_WITHDRAW_RDNS);
I2S(IMSG_WITHDRAW_ROUTES);
I2S(IMSG_REPROPOSE_RDNS);
I2S(IMSG_REQUEST_REBOOT);
default:
snprintf(unknown, sizeof(unknown), "IMSG_%u", type);
return unknown;
}
}
#undef I2S
#endif /* SMALL */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dhcpleased.h,v 1.16 2024/01/26 21:14:08 jan Exp $ */
/* $OpenBSD: dhcpleased.h,v 1.17 2024/08/25 09:53:53 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@ -158,7 +158,6 @@
#define MAX_SERVERS 16 /* max servers that can be ignored per if */
#define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
#define DHCP_SNAME_LEN 64
#define DHCP_FILE_LEN 128
@ -252,9 +251,9 @@ struct iface_conf {
SIMPLEQ_ENTRY(iface_conf) entry;
char name[IF_NAMESIZE];
uint8_t *vc_id;
int vc_id_len;
size_t vc_id_len;
uint8_t *c_id;
int c_id_len;
size_t c_id_len;
char *h_name;
int ignore;
struct in_addr ignore_servers[MAX_SERVERS];
@ -304,12 +303,14 @@ struct imsg_req_dhcp {
void imsg_event_add(struct imsgev *);
int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
pid_t, int, void *, uint16_t);
int imsg_forward_event(struct imsgev *, struct imsg *);
#ifndef SMALL
void config_clear(struct dhcpleased_conf *);
struct dhcpleased_conf *config_new_empty(void);
void merge_config(struct dhcpleased_conf *, struct
dhcpleased_conf *);
const char *sin_to_str(struct sockaddr_in *);
const char *i2s(uint32_t);
/* frontend.c */
struct iface_conf *find_iface_conf(struct iface_conf_head *, char *);
@ -323,6 +324,7 @@ void print_config(struct dhcpleased_conf *);
struct dhcpleased_conf *parse_config(const char *);
int cmdline_symset(char *);
#else
#define sin_to_str(x...) ""
#define sin_to_str(x) ""
#define i2s(x) ""
#endif /* SMALL */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: engine.c,v 1.45 2024/06/03 17:58:33 deraadt Exp $ */
/* $OpenBSD: engine.c,v 1.49 2024/08/26 06:06:04 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@ -127,7 +127,7 @@ void engine_dispatch_frontend(int, short, void *);
void engine_dispatch_main(int, short, void *);
#ifndef SMALL
void send_interface_info(struct dhcpleased_iface *, pid_t);
void engine_showinfo_ctl(struct imsg *, uint32_t);
void engine_showinfo_ctl(pid_t, uint32_t);
#endif /* SMALL */
void engine_update_iface(struct imsg_ifinfo *);
struct dhcpleased_iface *get_dhcpleased_iface_by_id(uint32_t);
@ -286,7 +286,7 @@ engine_dispatch_frontend(int fd, short event, void *bula)
#ifndef SMALL
int verbose;
#endif /* SMALL */
uint32_t if_index;
uint32_t if_index, type;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
@ -307,29 +307,29 @@ engine_dispatch_frontend(int fd, short event, void *bula)
if (n == 0) /* No more messages. */
break;
switch (imsg.hdr.type) {
type = imsg_get_type(&imsg);
switch (type) {
#ifndef SMALL
case IMSG_CTL_LOG_VERBOSE:
if (IMSG_DATA_SIZE(imsg) != sizeof(verbose))
fatalx("%s: IMSG_CTL_LOG_VERBOSE wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&verbose, imsg.data, sizeof(verbose));
if (imsg_get_data(&imsg, &verbose,
sizeof(verbose)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
log_setverbose(verbose);
break;
case IMSG_CTL_SHOW_INTERFACE_INFO:
if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatalx("%s: IMSG_CTL_SHOW_INTERFACE_INFO wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
engine_showinfo_ctl(&imsg, if_index);
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
engine_showinfo_ctl(imsg_get_pid(&imsg), if_index);
break;
case IMSG_REQUEST_REBOOT:
if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatalx("%s: IMSG_CTL_SEND_DISCOVER wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
iface = get_dhcpleased_iface_by_id(if_index);
if (iface != NULL) {
switch (iface->state) {
@ -351,18 +351,19 @@ engine_dispatch_frontend(int fd, short event, void *bula)
break;
#endif /* SMALL */
case IMSG_REMOVE_IF:
if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatalx("%s: IMSG_REMOVE_IF wrong length: %lu",
__func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
remove_dhcpleased_iface(if_index);
break;
case IMSG_DHCP: {
struct imsg_dhcp imsg_dhcp;
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_dhcp))
fatalx("%s: IMSG_DHCP wrong length: %lu",
__func__, IMSG_DATA_SIZE(imsg));
memcpy(&imsg_dhcp, imsg.data, sizeof(imsg_dhcp));
if (imsg_get_data(&imsg, &imsg_dhcp,
sizeof(imsg_dhcp)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
iface = get_dhcpleased_iface_by_id(imsg_dhcp.if_index);
if (iface != NULL)
parse_dhcp(iface, &imsg_dhcp);
@ -373,8 +374,7 @@ engine_dispatch_frontend(int fd, short event, void *bula)
send_rdns_proposal(iface);
break;
default:
log_debug("%s: unexpected imsg %d", __func__,
imsg.hdr.type);
log_debug("%s: unexpected imsg %d", __func__, type);
break;
}
imsg_free(&imsg);
@ -400,6 +400,7 @@ engine_dispatch_main(int fd, short event, void *bula)
struct imsgbuf *ibuf = &iev->ibuf;
struct imsg_ifinfo imsg_ifinfo;
ssize_t n;
uint32_t type;
int shut = 0;
if (event & EV_READ) {
@ -421,7 +422,9 @@ engine_dispatch_main(int fd, short event, void *bula)
if (n == 0) /* No more messages. */
break;
switch (imsg.hdr.type) {
type = imsg_get_type(&imsg);
switch (type) {
case IMSG_SOCKET_IPC:
/*
* Setup pipe and event handler to the frontend
@ -453,12 +456,12 @@ engine_dispatch_main(int fd, short event, void *bula)
break;
case IMSG_UPDATE_IF:
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_ifinfo))
fatalx("%s: IMSG_UPDATE_IF wrong length: %lu",
__func__, IMSG_DATA_SIZE(imsg));
memcpy(&imsg_ifinfo, imsg.data, sizeof(imsg_ifinfo));
if (imsg_get_data(&imsg, &imsg_ifinfo,
sizeof(imsg_ifinfo)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if (imsg_ifinfo.lease[LEASE_SIZE - 1] != '\0')
fatalx("Invalid lease");
engine_update_iface(&imsg_ifinfo);
break;
#ifndef SMALL
@ -472,15 +475,14 @@ engine_dispatch_main(int fd, short event, void *bula)
SIMPLEQ_INIT(&nconf->iface_list);
break;
case IMSG_RECONF_IFACE:
if (IMSG_DATA_SIZE(imsg) != sizeof(struct
iface_conf))
fatalx("%s: IMSG_RECONF_IFACE wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
if ((iface_conf = malloc(sizeof(struct iface_conf)))
== NULL)
fatal(NULL);
memcpy(iface_conf, imsg.data, sizeof(struct
iface_conf));
if (imsg_get_data(&imsg, iface_conf,
sizeof(struct iface_conf)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
iface_conf->vc_id = NULL;
iface_conf->vc_id_len = 0;
iface_conf->c_id = NULL;
@ -491,44 +493,57 @@ engine_dispatch_main(int fd, short event, void *bula)
break;
case IMSG_RECONF_VC_ID:
if (iface_conf == NULL)
fatal("IMSG_RECONF_VC_ID without "
"IMSG_RECONF_IFACE");
if (IMSG_DATA_SIZE(imsg) > 255 + 2)
fatalx("%s: IMSG_RECONF_VC_ID wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
if ((iface_conf->vc_id = malloc(IMSG_DATA_SIZE(imsg)))
fatalx("%s: %s without IMSG_RECONF_IFACE",
__func__, i2s(type));
if (iface_conf->vc_id != NULL)
fatalx("%s: multiple %s for the same interface",
__func__, i2s(type));
if ((iface_conf->vc_id_len = imsg_get_len(&imsg))
> 255 + 2 || iface_conf->vc_id_len == 0)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface_conf->vc_id = malloc(iface_conf->vc_id_len))
== NULL)
fatal(NULL);
memcpy(iface_conf->vc_id, imsg.data,
IMSG_DATA_SIZE(imsg));
iface_conf->vc_id_len = IMSG_DATA_SIZE(imsg);
if (imsg_get_data(&imsg, iface_conf->vc_id,
iface_conf->vc_id_len) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
break;
case IMSG_RECONF_C_ID:
if (iface_conf == NULL)
fatal("IMSG_RECONF_C_ID without "
"IMSG_RECONF_IFACE");
if (IMSG_DATA_SIZE(imsg) > 255 + 2)
fatalx("%s: IMSG_RECONF_C_ID wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
if ((iface_conf->c_id = malloc(IMSG_DATA_SIZE(imsg)))
fatalx("%s: %s without IMSG_RECONF_IFACE",
__func__, i2s(type));
if (iface_conf->c_id != NULL)
fatalx("%s: multiple %s for the same interface",
__func__, i2s(type));
if ((iface_conf->c_id_len = imsg_get_len(&imsg))
> 255 + 2 || iface_conf->c_id_len == 0)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface_conf->c_id = malloc(iface_conf->c_id_len))
== NULL)
fatal(NULL);
memcpy(iface_conf->c_id, imsg.data,
IMSG_DATA_SIZE(imsg));
iface_conf->c_id_len = IMSG_DATA_SIZE(imsg);
if (imsg_get_data(&imsg, iface_conf->c_id,
iface_conf->c_id_len) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
break;
case IMSG_RECONF_H_NAME:
case IMSG_RECONF_H_NAME: {
size_t len;
if (iface_conf == NULL)
fatal("IMSG_RECONF_H_NAME without "
"IMSG_RECONF_IFACE");
if (((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] !=
'\0')
fatalx("Invalid hostname");
if (IMSG_DATA_SIZE(imsg) > 256)
fatalx("Invalid hostname");
if ((iface_conf->h_name = strdup(imsg.data)) == NULL)
fatalx("%s: %s without IMSG_RECONF_IFACE",
__func__, i2s(type));
if (iface_conf->h_name != NULL)
fatalx("%s: multiple %s for the same interface",
__func__, i2s(type));
if ((len = imsg_get_len(&imsg)) > 256 || len == 0)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface_conf->h_name = malloc(len)) == NULL)
fatal(NULL);
if (imsg_get_data(&imsg, iface_conf->h_name, len) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if (iface_conf->h_name[len - 1] != '\0')
fatalx("Invalid hostname");
break;
}
case IMSG_RECONF_END: {
struct dhcpleased_iface *iface;
int *ifaces;
@ -537,8 +552,9 @@ engine_dispatch_main(int fd, short event, void *bula)
char ifnamebuf[IF_NAMESIZE];
if (nconf == NULL)
fatalx("%s: IMSG_RECONF_END without "
"IMSG_RECONF_CONF", __func__);
fatalx("%s: %s without IMSG_RECONF_CONF",
__func__, i2s(type));
ifaces = changed_ifaces(engine_conf, nconf);
merge_config(engine_conf, nconf);
nconf = NULL;
@ -562,8 +578,7 @@ engine_dispatch_main(int fd, short event, void *bula)
}
#endif /* SMALL */
default:
log_debug("%s: unexpected imsg %d", __func__,
imsg.hdr.type);
log_debug("%s: unexpected imsg %d", __func__, type);
break;
}
imsg_free(&imsg);
@ -605,22 +620,14 @@ send_interface_info(struct dhcpleased_iface *iface, pid_t pid)
}
void
engine_showinfo_ctl(struct imsg *imsg, uint32_t if_index)
engine_showinfo_ctl(pid_t pid, uint32_t if_index)
{
struct dhcpleased_iface *iface;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_INTERFACE_INFO:
if ((iface = get_dhcpleased_iface_by_id(if_index)) != NULL)
send_interface_info(iface, imsg->hdr.pid);
else
engine_imsg_compose_frontend(IMSG_CTL_END,
imsg->hdr.pid, NULL, 0);
break;
default:
log_debug("%s: error handling imsg", __func__);
break;
}
if ((iface = get_dhcpleased_iface_by_id(if_index)) != NULL)
send_interface_info(iface, pid);
else
engine_imsg_compose_frontend(IMSG_CTL_END, pid, NULL, 0);
}
#endif /* SMALL */
@ -1427,7 +1434,7 @@ state_transition(struct dhcpleased_iface *iface, enum if_state new_state)
iface->xid = arc4random();
break;
case IF_BOUND:
fatal("invalid transition Bound -> Init");
fatalx("invalid transition Bound -> Init");
break;
}
request_dhcp_discover(iface);
@ -1491,7 +1498,7 @@ state_transition(struct dhcpleased_iface *iface, enum if_state new_state)
iface->timo.tv_sec = iface->ipv6_only_time;
break;
case IF_BOUND:
fatal("invalid transition Bound -> IPv6 only");
fatalx("invalid transition Bound -> IPv6 only");
break;
}
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: frontend.c,v 1.35 2024/06/27 14:53:06 florian Exp $ */
/* $OpenBSD: frontend.c,v 1.38 2024/08/26 06:06:04 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@ -238,6 +238,7 @@ frontend_dispatch_main(int fd, short event, void *bula)
struct imsgbuf *ibuf = &iev->ibuf;
struct iface *iface;
ssize_t n;
uint32_t type;
int shut = 0, bpfsock, if_index, udpsock;
if (event & EV_READ) {
@ -259,7 +260,9 @@ frontend_dispatch_main(int fd, short event, void *bula)
if (n == 0) /* No more messages. */
break;
switch (imsg.hdr.type) {
type = imsg_get_type(&imsg);
switch (type) {
case IMSG_SOCKET_IPC:
/*
* Setup pipe and event handler to the engine
@ -291,10 +294,10 @@ frontend_dispatch_main(int fd, short event, void *bula)
fatalx("%s: expected to receive imsg "
"bpf fd but didn't receive any",
__func__);
if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatalx("%s: IMSG_BPFSOCK wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
set_bpfsock(bpfsock, if_index);
break;
case IMSG_UDPSOCK:
@ -302,10 +305,10 @@ frontend_dispatch_main(int fd, short event, void *bula)
fatalx("%s: expected to receive imsg "
"udpsocket fd but didn't receive any",
__func__);
if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatalx("%s: IMSG_UDPSOCK wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface = get_iface_by_id(if_index)) == NULL) {
close(fd);
break;
@ -316,10 +319,10 @@ frontend_dispatch_main(int fd, short event, void *bula)
iface->udpsock = udpsock;
break;
case IMSG_CLOSE_UDPSOCK:
if (IMSG_DATA_SIZE(imsg) != sizeof(if_index))
fatalx("%s: IMSG_UDPSOCK wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
memcpy(&if_index, imsg.data, sizeof(if_index));
if (imsg_get_data(&imsg, &if_index,
sizeof(if_index)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface = get_iface_by_id(if_index)) != NULL &&
iface->udpsock != -1) {
close(iface->udpsock);
@ -348,15 +351,14 @@ frontend_dispatch_main(int fd, short event, void *bula)
SIMPLEQ_INIT(&nconf->iface_list);
break;
case IMSG_RECONF_IFACE:
if (IMSG_DATA_SIZE(imsg) != sizeof(struct
iface_conf))
fatalx("%s: IMSG_RECONF_IFACE wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
if ((iface_conf = malloc(sizeof(struct iface_conf)))
== NULL)
fatal(NULL);
memcpy(iface_conf, imsg.data, sizeof(struct
iface_conf));
if (imsg_get_data(&imsg, iface_conf,
sizeof(struct iface_conf)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
iface_conf->vc_id = NULL;
iface_conf->vc_id_len = 0;
iface_conf->c_id = NULL;
@ -367,52 +369,65 @@ frontend_dispatch_main(int fd, short event, void *bula)
break;
case IMSG_RECONF_VC_ID:
if (iface_conf == NULL)
fatal("IMSG_RECONF_VC_ID without "
"IMSG_RECONF_IFACE");
if (IMSG_DATA_SIZE(imsg) > 255 + 2)
fatalx("%s: IMSG_RECONF_VC_ID wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
if ((iface_conf->vc_id = malloc(IMSG_DATA_SIZE(imsg)))
fatalx("%s: %s without IMSG_RECONF_IFACE",
__func__, i2s(type));
if (iface_conf->vc_id != NULL)
fatalx("%s: multiple %s for the same interface",
__func__, i2s(type));
if ((iface_conf->vc_id_len = imsg_get_len(&imsg))
> 255 + 2 || iface_conf->vc_id_len == 0)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface_conf->vc_id = malloc(iface_conf->vc_id_len))
== NULL)
fatal(NULL);
memcpy(iface_conf->vc_id, imsg.data,
IMSG_DATA_SIZE(imsg));
iface_conf->vc_id_len = IMSG_DATA_SIZE(imsg);
if (imsg_get_data(&imsg, iface_conf->vc_id,
iface_conf->vc_id_len) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
break;
case IMSG_RECONF_C_ID:
if (iface_conf == NULL)
fatal("IMSG_RECONF_C_ID without "
"IMSG_RECONF_IFACE");
if (IMSG_DATA_SIZE(imsg) > 255 + 2)
fatalx("%s: IMSG_RECONF_C_ID wrong length: "
"%lu", __func__, IMSG_DATA_SIZE(imsg));
if ((iface_conf->c_id = malloc(IMSG_DATA_SIZE(imsg)))
fatalx("%s: %s without IMSG_RECONF_IFACE",
__func__, i2s(type));
if (iface_conf->c_id != NULL)
fatalx("%s: multiple %s for the same interface",
__func__, i2s(type));
if ((iface_conf->c_id_len = imsg_get_len(&imsg))
> 255 + 2 || iface_conf->c_id_len == 0)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface_conf->c_id = malloc(iface_conf->c_id_len))
== NULL)
fatal(NULL);
memcpy(iface_conf->c_id, imsg.data,
IMSG_DATA_SIZE(imsg));
iface_conf->c_id_len = IMSG_DATA_SIZE(imsg);
if (imsg_get_data(&imsg, iface_conf->c_id,
iface_conf->c_id_len) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
break;
case IMSG_RECONF_H_NAME:
case IMSG_RECONF_H_NAME: {
size_t len;
if (iface_conf == NULL)
fatal("IMSG_RECONF_H_NAME without "
"IMSG_RECONF_IFACE");
if (((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] !=
'\0')
fatalx("Invalid hostname");
if (IMSG_DATA_SIZE(imsg) > 256)
fatalx("Invalid hostname");
if ((iface_conf->h_name = strdup(imsg.data)) == NULL)
fatalx("%s: %s without IMSG_RECONF_IFACE",
__func__, i2s(type));
if (iface_conf->h_name != NULL)
fatalx("%s: multiple %s for the same interface",
__func__, i2s(type));
if ((len = imsg_get_len(&imsg)) > 256 || len == 0)
fatalx("%s: invalid %s", __func__, i2s(type));
if ((iface_conf->h_name = malloc(len)) == NULL)
fatal(NULL);
if (imsg_get_data(&imsg, iface_conf->h_name, len) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
if (iface_conf->h_name[len - 1] != '\0')
fatalx("Invalid hostname");
break;
}
case IMSG_RECONF_END: {
int i;
int *ifaces;
char ifnamebuf[IF_NAMESIZE], *if_name;
if (nconf == NULL)
fatalx("%s: IMSG_RECONF_END without "
"IMSG_RECONF_CONF", __func__);
fatalx("%s: %s without IMSG_RECONF_CONF",
__func__, i2s(type));
ifaces = changed_ifaces(frontend_conf, nconf);
merge_config(frontend_conf, nconf);
@ -442,8 +457,7 @@ frontend_dispatch_main(int fd, short event, void *bula)
break;
#endif /* SMALL */
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
log_debug("%s: error handling imsg %d", __func__, type);
break;
}
imsg_free(&imsg);
@ -465,6 +479,7 @@ frontend_dispatch_engine(int fd, short event, void *bula)
struct imsg imsg;
struct iface *iface;
ssize_t n;
uint32_t type;
int shut = 0;
if (event & EV_READ) {
@ -486,7 +501,9 @@ frontend_dispatch_engine(int fd, short event, void *bula)
if (n == 0) /* No more messages. */
break;
switch (imsg.hdr.type) {
type = imsg_get_type(&imsg);
switch (type) {
#ifndef SMALL
case IMSG_CTL_END:
case IMSG_CTL_SHOW_INTERFACE_INFO:
@ -495,12 +512,10 @@ frontend_dispatch_engine(int fd, short event, void *bula)
#endif /* SMALL */
case IMSG_SEND_DISCOVER: {
struct imsg_req_dhcp imsg_req_dhcp;
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_req_dhcp))
fatalx("%s: IMSG_SEND_DISCOVER wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&imsg_req_dhcp, imsg.data,
sizeof(imsg_req_dhcp));
if (imsg_get_data(&imsg, &imsg_req_dhcp,
sizeof(imsg_req_dhcp)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
iface = get_iface_by_id(imsg_req_dhcp.if_index);
@ -513,12 +528,10 @@ frontend_dispatch_engine(int fd, short event, void *bula)
}
case IMSG_SEND_REQUEST: {
struct imsg_req_dhcp imsg_req_dhcp;
if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_req_dhcp))
fatalx("%s: IMSG_SEND_REQUEST wrong "
"length: %lu", __func__,
IMSG_DATA_SIZE(imsg));
memcpy(&imsg_req_dhcp, imsg.data,
sizeof(imsg_req_dhcp));
if (imsg_get_data(&imsg, &imsg_req_dhcp,
sizeof(imsg_req_dhcp)) == -1)
fatalx("%s: invalid %s", __func__, i2s(type));
iface = get_iface_by_id(imsg_req_dhcp.if_index);
@ -530,8 +543,7 @@ frontend_dispatch_engine(int fd, short event, void *bula)
break;
}
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
log_debug("%s: error handling imsg %d", __func__, type);
break;
}
imsg_free(&imsg);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: slaacd.h,v 1.40 2024/08/24 16:34:23 florian Exp $ */
/* $OpenBSD: slaacd.h,v 1.41 2024/08/25 07:04:05 florian Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@ -207,6 +207,6 @@ int imsg_forward_event(struct imsgev *, struct imsg *);
const char *sin6_to_str(struct sockaddr_in6 *);
const char *i2s(uint32_t);
#else
#define sin6_to_str(x...) ""
#define i2s(x...) ""
#define sin6_to_str(x) ""
#define i2s(x) ""
#endif /* SMALL */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: pmap.c,v 1.103 2024/05/28 15:16:45 claudio Exp $ */
/* $OpenBSD: pmap.c,v 1.104 2024/08/26 03:37:56 jsg Exp $ */
/*
* Copyright (c) 2008-2009,2014-2016 Dale Rahn <drahn@dalerahn.com>
*
@ -2237,34 +2237,35 @@ pmap_show_mapping(uint64_t va)
pted, vp3->l3[VP_IDX3(va)], VP_IDX3(va)*8);
}
__attribute__((target("+pauth")))
void
pmap_setpauthkeys(struct pmap *pm)
{
if (ID_AA64ISAR1_APA(cpu_id_aa64isar1) >= ID_AA64ISAR1_APA_BASE ||
ID_AA64ISAR1_API(cpu_id_aa64isar1) >= ID_AA64ISAR1_API_BASE) {
__asm volatile (".arch armv8.3-a; msr apiakeylo_el1, %0"
__asm volatile ("msr apiakeylo_el1, %0"
:: "r"(pm->pm_apiakey[0]));
__asm volatile (".arch armv8.3-a; msr apiakeyhi_el1, %0"
__asm volatile ("msr apiakeyhi_el1, %0"
:: "r"(pm->pm_apiakey[1]));
__asm volatile (".arch armv8.3-a; msr apdakeylo_el1, %0"
__asm volatile ("msr apdakeylo_el1, %0"
:: "r"(pm->pm_apdakey[0]));
__asm volatile (".arch armv8.3-a; msr apdakeyhi_el1, %0"
__asm volatile ("msr apdakeyhi_el1, %0"
:: "r"(pm->pm_apdakey[1]));
__asm volatile (".arch armv8.3-a; msr apibkeylo_el1, %0"
__asm volatile ("msr apibkeylo_el1, %0"
:: "r"(pm->pm_apibkey[0]));
__asm volatile (".arch armv8.3-a; msr apibkeyhi_el1, %0"
__asm volatile ("msr apibkeyhi_el1, %0"
:: "r"(pm->pm_apibkey[1]));
__asm volatile (".arch armv8.3-a; msr apdbkeylo_el1, %0"
__asm volatile ("msr apdbkeylo_el1, %0"
:: "r"(pm->pm_apdbkey[0]));
__asm volatile (".arch armv8.3-a; msr apdbkeyhi_el1, %0"
__asm volatile ("msr apdbkeyhi_el1, %0"
:: "r"(pm->pm_apdbkey[1]));
}
if (ID_AA64ISAR1_GPA(cpu_id_aa64isar1) >= ID_AA64ISAR1_GPA_IMPL ||
ID_AA64ISAR1_GPI(cpu_id_aa64isar1) >= ID_AA64ISAR1_GPI_IMPL) {
__asm volatile (".arch armv8.3-a; msr apgakeylo_el1, %0"
__asm volatile ("msr apgakeylo_el1, %0"
:: "r"(pm->pm_apgakey[0]));
__asm volatile (".arch armv8.3-a; msr apgakeyhi_el1, %0"
__asm volatile ("msr apgakeyhi_el1, %0"
:: "r"(pm->pm_apgakey[1]));
}
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: kern_sysctl.c,v 1.444 2024/08/23 01:31:04 mvs Exp $ */
/* $OpenBSD: kern_sysctl.c,v 1.445 2024/08/26 08:24:25 mvs Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@ -487,8 +487,8 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
switch (name[0]) {
#if NAUDIO > 0
case KERN_AUDIO:
return (sysctl_audio(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen));
return (sysctl_audio(name + 1, namelen - 1,
oldp, oldlenp, newp, newlen));
#endif
default:
break;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tcp_input.c,v 1.406 2024/06/07 08:02:17 jsg Exp $ */
/* $OpenBSD: tcp_input.c,v 1.407 2024/08/26 13:55:14 bluhm Exp $ */
/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
/*
@ -871,14 +871,15 @@ findpcb:
/*
* Process options.
*/
if (optp
#ifdef TCP_SIGNATURE
if (optp || (tp->t_flags & TF_SIGNATURE))
#else
if (optp)
|| (tp->t_flags & TF_SIGNATURE)
#endif
) {
if (tcp_dooptions(tp, optp, optlen, th, m, iphlen, &opti,
m->m_pkthdr.ph_rtableid, now))
goto drop;
}
if (opti.ts_present && opti.ts_ecr) {
int32_t rtt_test;
@ -2124,7 +2125,7 @@ tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcphdr *th,
#ifdef TCP_SIGNATURE
caddr_t sigp = NULL;
struct tdb *tdb = NULL;
#endif /* TCP_SIGNATURE */
#endif
for (; cp && cnt > 0; cnt -= optlen, cp += optlen) {
opt = cp[0];
@ -2289,7 +2290,7 @@ tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcphdr *th,
#ifdef TCP_SIGNATURE
bad:
tdb_unref(tdb);
#endif /* TCP_SIGNATURE */
#endif
return (-1);
}
@ -3783,11 +3784,11 @@ syn_cache_add(struct sockaddr *src, struct sockaddr *dst, struct tcphdr *th,
win = TCP_MAXWIN;
bzero(&tb, sizeof(tb));
if (optp
#ifdef TCP_SIGNATURE
if (optp || (tp->t_flags & TF_SIGNATURE)) {
#else
if (optp) {
|| (tp->t_flags & TF_SIGNATURE)
#endif
) {
tb.pf = tp->pf;
tb.sack_enable = tp->sack_enable;
tb.t_flags = tcp_do_rfc1323 ? (TF_REQ_SCALE|TF_REQ_TSTMP) : 0;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: printf.c,v 1.27 2021/05/07 14:31:27 martijn Exp $ */
/* $OpenBSD: printf.c,v 1.28 2024/08/26 03:49:06 deraadt Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
@ -113,7 +113,7 @@ main(int argc, char *argv[])
start = fmt++;
if (*fmt == '%') {
putchar ('%');
putchar('%');
break;
} else if (*fmt == 'b') {
char *p = getstr();
@ -149,7 +149,7 @@ main(int argc, char *argv[])
}
if (!*fmt) {
warnx ("missing format character");
warnx("missing format character");
return(1);
}
@ -206,7 +206,7 @@ main(int argc, char *argv[])
break;
}
default:
warnx ("%s: invalid directive", start);
warnx("%s: invalid directive", start);
return(1);
}
*(fmt + 1) = nextch;
@ -217,7 +217,7 @@ main(int argc, char *argv[])
break;
default:
putchar (*fmt);
putchar(*fmt);
break;
}
}
@ -251,7 +251,7 @@ print_escape_str(const char *str)
value <<= 3;
value += octtobin(*str);
}
putchar (value);
putchar(value);
str--;
} else if (*str == 'c') {
return 1;
@ -260,7 +260,7 @@ print_escape_str(const char *str)
str += print_escape(str);
}
} else {
putchar (*str);
putchar(*str);
}
str++;
}
@ -297,7 +297,7 @@ print_escape(const char *str)
value <<= 4;
value += hextobin(*str);
}
putchar (value);
putchar(value);
return str - start - 1;
/* NOTREACHED */
@ -433,7 +433,7 @@ getlong(void)
return (unsigned char) *((*gargv++)+1);
errno = 0;
val = strtol (*gargv, &ep, 0);
val = strtol(*gargv, &ep, 0);
check_conversion(*gargv++, ep);
return val;
}
@ -451,7 +451,7 @@ getulong(void)
return (unsigned char) *((*gargv++)+1);
errno = 0;
val = strtoul (*gargv, &ep, 0);
val = strtoul(*gargv, &ep, 0);
check_conversion(*gargv++, ep);
return val;
}
@ -469,7 +469,7 @@ getdouble(void)
return (unsigned char) *((*gargv++)+1);
errno = 0;
val = strtod (*gargv, &ep);
val = strtod(*gargv, &ep);
check_conversion(*gargv++, ep);
return val;
}
@ -479,9 +479,9 @@ check_conversion(const char *s, const char *ep)
{
if (*ep) {
if (ep == s)
warnx ("%s: expected numeric value", s);
warnx("%s: expected numeric value", s);
else
warnx ("%s: not completely converted", s);
warnx("%s: not completely converted", s);
rval = 1;
} else if (errno == ERANGE) {
warnc(ERANGE, "%s", s);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: sock.c,v 1.50 2024/08/01 14:36:27 ratchov Exp $ */
/* $OpenBSD: sock.c,v 1.51 2024/08/25 05:43:36 jsg Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@ -1805,7 +1805,7 @@ sock_write(struct sock *f)
}
f->wstate = SOCK_WDATA;
f->wsize = f->wtodo = ntohl(f->wmsg.u.data.size);
/* PASSTHROUGH */
/* FALLTHROUGH */
case SOCK_WDATA:
if (!sock_wdata(f))
return 0;
@ -1823,7 +1823,7 @@ sock_write(struct sock *f)
}
#endif
}
/* PASSTHROUGH */
/* FALLTHROUGH */
case SOCK_WIDLE:
if (f->rstate == SOCK_RRET) {
f->wmsg = f->rmsg;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.162 2024/05/15 09:59:12 nicm Exp $ */
/* $OpenBSD: client.c,v 1.163 2024/08/26 07:30:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -445,11 +445,12 @@ client_send_identify(const char *ttynam, const char *termname, char **caps,
{
char **ss;
size_t sslen;
int fd, flags = client_flags;
int fd;
uint64_t flags = client_flags;
pid_t pid;
u_int i;
proc_send(client_peer, MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags);
proc_send(client_peer, MSG_IDENTIFY_LONGFLAGS, -1, &flags, sizeof flags);
proc_send(client_peer, MSG_IDENTIFY_LONGFLAGS, -1, &client_flags,
sizeof client_flags);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: cmd-copy-mode.c,v 1.47 2021/08/21 10:22:38 nicm Exp $ */
/* $OpenBSD: cmd-copy-mode.c,v 1.48 2024/08/26 07:09:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -30,8 +30,8 @@ const struct cmd_entry cmd_copy_mode_entry = {
.name = "copy-mode",
.alias = NULL,
.args = { "eHMs:t:uq", 0, 0, NULL },
.usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
.args = { "deHMs:t:uq", 0, 0, NULL },
.usage = "[-deHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
.source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_PANE, 0 },
@ -91,6 +91,8 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
}
if (args_has(args, 'u'))
window_copy_pageup(wp, 0);
if (args_has(args, 'd'))
window_copy_pagedown(wp, 0, args_has(args, 'e'));
return (CMD_RETURN_NORMAL);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: colour.c,v 1.26 2023/01/03 11:43:24 nicm Exp $ */
/* $OpenBSD: colour.c,v 1.27 2024/08/26 13:02:15 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -942,13 +942,17 @@ colour_byname(const char *name)
{ "yellow3", 0xcdcd00 },
{ "yellow4", 0x8b8b00 }
};
u_int i;
int c;
u_int i;
int c;
const char *errstr;
if (strncmp(name, "grey", 4) == 0 || strncmp(name, "gray", 4) == 0) {
if (!isdigit((u_char)name[4]))
return (0xbebebe|COLOUR_FLAG_RGB);
c = round(2.55 * atoi(name + 4));
if (name[4] == '\0')
return (-1);
c = strtonum(name + 4, 0, 100, &errstr);
if (errstr != NULL)
return (-1);
c = round(2.55 * c);
if (c < 0 || c > 255)
return (-1);
return (colour_join_rgb(c, c, c));

View file

@ -1,4 +1,4 @@
/* $OpenBSD: format.c,v 1.319 2024/08/21 04:17:09 nicm Exp $ */
/* $OpenBSD: format.c,v 1.320 2024/08/26 07:14:40 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -1136,8 +1136,7 @@ format_cb_mouse_word(struct format_tree *ft)
return (NULL);
if (!TAILQ_EMPTY(&wp->modes)) {
if (TAILQ_FIRST(&wp->modes)->mode == &window_copy_mode ||
TAILQ_FIRST(&wp->modes)->mode == &window_view_mode)
if (window_pane_mode(wp) != WINDOW_PANE_NO_MODE)
return (window_copy_get_word(wp, x, y));
return (NULL);
}
@ -1181,8 +1180,7 @@ format_cb_mouse_line(struct format_tree *ft)
return (NULL);
if (!TAILQ_EMPTY(&wp->modes)) {
if (TAILQ_FIRST(&wp->modes)->mode == &window_copy_mode ||
TAILQ_FIRST(&wp->modes)->mode == &window_view_mode)
if (window_pane_mode(wp) != WINDOW_PANE_NO_MODE)
return (window_copy_get_line(wp, y));
return (NULL);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: input-keys.c,v 1.97 2024/08/23 13:25:39 nicm Exp $ */
/* $OpenBSD: input-keys.c,v 1.98 2024/08/26 07:45:05 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -608,8 +608,9 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key)
* key and no modifiers.
*/
if (!(key & ~KEYC_MASK_KEY)) {
if (key == C0_BS || key == C0_HT ||
key == C0_CR || key == C0_ESC ||
if (key == C0_HT ||
key == C0_CR ||
key == C0_ESC ||
(key >= 0x20 && key <= 0x7f)) {
ud.data[0] = key;
input_key_write(__func__, bev, &ud.data[0], 1);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: screen-redraw.c,v 1.96 2022/06/30 09:55:53 nicm Exp $ */
/* $OpenBSD: screen-redraw.c,v 1.98 2024/08/26 07:34:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -109,12 +109,13 @@ screen_redraw_two_panes(struct window *w, int direction)
/* Check if cell is on the border of a pane. */
static enum screen_redraw_border_type
screen_redraw_pane_border(struct window_pane *wp, u_int px, u_int py,
int pane_status)
screen_redraw_pane_border(struct screen_redraw_ctx *ctx, struct window_pane *wp,
u_int px, u_int py)
{
struct options *oo = wp->window->options;
int split = 0;
u_int ex = wp->xoff + wp->sx, ey = wp->yoff + wp->sy;
u_int ex = wp->xoff + wp->sx, ey = wp->yoff + wp->sy;
int pane_status = ctx->pane_status;
/* Inside pane. */
if (px >= wp->xoff && px < ex && py >= wp->yoff && py < ey)
@ -189,8 +190,9 @@ screen_redraw_pane_border(struct window_pane *wp, u_int px, u_int py,
/* Check if a cell is on a border. */
static int
screen_redraw_cell_border(struct client *c, u_int px, u_int py, int pane_status)
screen_redraw_cell_border(struct screen_redraw_ctx *ctx, u_int px, u_int py)
{
struct client *c = ctx->c;
struct window *w = c->session->curw->window;
struct window_pane *wp;
@ -206,7 +208,7 @@ screen_redraw_cell_border(struct client *c, u_int px, u_int py, int pane_status)
TAILQ_FOREACH(wp, &w->panes, entry) {
if (!window_pane_visible(wp))
continue;
switch (screen_redraw_pane_border(wp, px, py, pane_status)) {
switch (screen_redraw_pane_border(ctx, wp, px, py)) {
case SCREEN_REDRAW_INSIDE:
return (0);
case SCREEN_REDRAW_OUTSIDE:
@ -221,9 +223,10 @@ screen_redraw_cell_border(struct client *c, u_int px, u_int py, int pane_status)
/* Work out type of border cell from surrounding cells. */
static int
screen_redraw_type_of_cell(struct client *c, u_int px, u_int py,
int pane_status)
screen_redraw_type_of_cell(struct screen_redraw_ctx *ctx, u_int px, u_int py)
{
struct client *c = ctx->c;
int pane_status = ctx->pane_status;
struct window *w = c->session->curw->window;
u_int sx = w->sx, sy = w->sy;
int borders = 0;
@ -236,28 +239,28 @@ screen_redraw_type_of_cell(struct client *c, u_int px, u_int py,
* Construct a bitmask of whether the cells to the left (bit 4), right,
* top, and bottom (bit 1) of this cell are borders.
*/
if (px == 0 || screen_redraw_cell_border(c, px - 1, py, pane_status))
if (px == 0 || screen_redraw_cell_border(ctx, px - 1, py))
borders |= 8;
if (px <= sx && screen_redraw_cell_border(c, px + 1, py, pane_status))
if (px <= sx && screen_redraw_cell_border(ctx, px + 1, py))
borders |= 4;
if (pane_status == PANE_STATUS_TOP) {
if (py != 0 &&
screen_redraw_cell_border(c, px, py - 1, pane_status))
screen_redraw_cell_border(ctx, px, py - 1))
borders |= 2;
if (screen_redraw_cell_border(c, px, py + 1, pane_status))
if (screen_redraw_cell_border(ctx, px, py + 1))
borders |= 1;
} else if (pane_status == PANE_STATUS_BOTTOM) {
if (py == 0 ||
screen_redraw_cell_border(c, px, py - 1, pane_status))
screen_redraw_cell_border(ctx, px, py - 1))
borders |= 2;
if (py != sy - 1 &&
screen_redraw_cell_border(c, px, py + 1, pane_status))
screen_redraw_cell_border(ctx, px, py + 1))
borders |= 1;
} else {
if (py == 0 ||
screen_redraw_cell_border(c, px, py - 1, pane_status))
screen_redraw_cell_border(ctx, px, py - 1))
borders |= 2;
if (screen_redraw_cell_border(c, px, py + 1, pane_status))
if (screen_redraw_cell_border(ctx, px, py + 1))
borders |= 1;
}
@ -295,11 +298,13 @@ screen_redraw_type_of_cell(struct client *c, u_int px, u_int py,
/* Check if cell inside a pane. */
static int
screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
screen_redraw_check_cell(struct screen_redraw_ctx *ctx, u_int px, u_int py,
struct window_pane **wpp)
{
struct client *c = ctx->c;
struct window *w = c->session->curw->window;
struct window_pane *wp, *active;
int pane_status = ctx->pane_status;
int border;
u_int right, line;
@ -308,7 +313,7 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
if (px > w->sx || py > w->sy)
return (CELL_OUTSIDE);
if (px == w->sx || py == w->sy) /* window border */
return (screen_redraw_type_of_cell(c, px, py, pane_status));
return (screen_redraw_type_of_cell(ctx, px, py));
if (pane_status != PANE_STATUS_OFF) {
active = wp = server_client_get_pane(c);
@ -342,12 +347,12 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
* If definitely inside, return. If not on border, skip.
* Otherwise work out the cell.
*/
border = screen_redraw_pane_border(wp, px, py, pane_status);
border = screen_redraw_pane_border(ctx, wp, px, py);
if (border == SCREEN_REDRAW_INSIDE)
return (CELL_INSIDE);
if (border == SCREEN_REDRAW_OUTSIDE)
goto next2;
return (screen_redraw_type_of_cell(c, px, py, pane_status));
return (screen_redraw_type_of_cell(ctx, px, py));
next2:
wp = TAILQ_NEXT(wp, entry);
@ -360,12 +365,12 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
/* Check if the border of a particular pane. */
static int
screen_redraw_check_is(u_int px, u_int py, int pane_status,
screen_redraw_check_is(struct screen_redraw_ctx *ctx, u_int px, u_int py,
struct window_pane *wp)
{
enum screen_redraw_border_type border;
border = screen_redraw_pane_border(wp, px, py, pane_status);
border = screen_redraw_pane_border(ctx, wp, px, py);
if (border != SCREEN_REDRAW_INSIDE && border != SCREEN_REDRAW_OUTSIDE)
return (1);
return (0);
@ -409,11 +414,11 @@ screen_redraw_make_pane_status(struct client *c, struct window_pane *wp,
for (i = 0; i < width; i++) {
px = wp->xoff + 2 + i;
if (rctx->pane_status == PANE_STATUS_TOP)
if (pane_status == PANE_STATUS_TOP)
py = wp->yoff - 1;
else
py = wp->yoff + wp->sy;
cell_type = screen_redraw_type_of_cell(c, px, py, pane_status);
cell_type = screen_redraw_type_of_cell(rctx, px, py);
screen_redraw_border_set(w, wp, pane_lines, cell_type, &gc);
screen_write_cell(&ctx, &gc);
}
@ -496,8 +501,8 @@ screen_redraw_draw_pane_status(struct screen_redraw_ctx *ctx)
}
/* Update status line and change flags if unchanged. */
static int
screen_redraw_update(struct client *c, int flags)
static uint64_t
screen_redraw_update(struct client *c, uint64_t flags)
{
struct window *w = c->session->curw->window;
struct window_pane *wp;
@ -567,7 +572,7 @@ void
screen_redraw_screen(struct client *c)
{
struct screen_redraw_ctx ctx;
int flags;
uint64_t flags;
if (c->flags & CLIENT_SUSPENDED)
return;
@ -638,7 +643,7 @@ screen_redraw_draw_borders_style(struct screen_redraw_ctx *ctx, u_int x,
wp->border_gc_set = 1;
ft = format_create_defaults(NULL, c, s, s->curw, wp);
if (screen_redraw_check_is(x, y, ctx->pane_status, active))
if (screen_redraw_check_is(ctx, x, y, active))
style_apply(&wp->border_gc, oo, "pane-active-border-style", ft);
else
style_apply(&wp->border_gc, oo, "pane-border-style", ft);
@ -663,7 +668,7 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
struct overlay_ranges r;
u_int cell_type, x = ctx->ox + i, y = ctx->oy + j;
int arrows = 0, border;
int pane_status = ctx->pane_status, isolates;
int isolates;
if (c->overlay_check != NULL) {
c->overlay_check(c, c->overlay_data, x, y, 1, &r);
@ -671,7 +676,7 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
return;
}
cell_type = screen_redraw_check_cell(c, x, y, pane_status, &wp);
cell_type = screen_redraw_check_cell(ctx, x, y, &wp);
if (cell_type == CELL_INSIDE)
return;
@ -692,7 +697,7 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
memcpy(&gc, tmp, sizeof gc);
if (server_is_marked(s, s->curw, marked_pane.wp) &&
screen_redraw_check_is(x, y, pane_status, marked_pane.wp))
screen_redraw_check_is(ctx, x, y, marked_pane.wp))
gc.attr ^= GRID_ATTR_REVERSE;
}
screen_redraw_border_set(w, wp, ctx->pane_lines, cell_type, &gc);
@ -719,7 +724,7 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
}
if (wp != NULL && arrows) {
border = screen_redraw_pane_border(active, x, y, pane_status);
border = screen_redraw_pane_border(ctx, active, x, y);
if (((i == wp->xoff + 1 &&
(cell_type == CELL_LEFTRIGHT ||
(cell_type == CELL_TOPJOIN &&
@ -732,7 +737,7 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
border == SCREEN_REDRAW_BORDER_RIGHT) ||
(cell_type == CELL_RIGHTJOIN &&
border == SCREEN_REDRAW_BORDER_LEFT)))) &&
screen_redraw_check_is(x, y, pane_status, active)) {
screen_redraw_check_is(ctx, x, y, active)) {
gc.attr |= GRID_ATTR_CHARSET;
utf8_set(&gc.data, BORDER_MARKERS[border]);
}
@ -751,7 +756,7 @@ screen_redraw_draw_borders(struct screen_redraw_ctx *ctx)
struct session *s = c->session;
struct window *w = s->curw->window;
struct window_pane *wp;
u_int i, j;
u_int i, j;
log_debug("%s: %s @%u", __func__, c->name, w->id);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: server-client.c,v 1.405 2024/04/10 07:29:15 nicm Exp $ */
/* $OpenBSD: server-client.c,v 1.406 2024/08/26 07:30:46 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -1870,7 +1870,8 @@ server_client_key_callback(struct cmdq_item *item, void *data)
struct timeval tv;
struct key_table *table, *first;
struct key_binding *bd;
int xtimeout, flags;
int xtimeout;
uint64_t flags;
struct cmd_find_state fs;
key_code key0, prefix, prefix2;
@ -2569,7 +2570,8 @@ server_client_check_redraw(struct client *c)
struct tty *tty = &c->tty;
struct window *w = c->session->curw->window;
struct window_pane *wp;
int needed, flags, mode = tty->mode, new_flags = 0;
int needed, tty_flags, mode = tty->mode;
uint64_t client_flags = 0;
int redraw;
u_int bit = 0;
struct timeval tv = { .tv_usec = 1000 };
@ -2603,7 +2605,7 @@ server_client_check_redraw(struct client *c)
}
}
if (needed)
new_flags |= CLIENT_REDRAWPANES;
client_flags |= CLIENT_REDRAWPANES;
}
if (needed && (left = EVBUFFER_LENGTH(tty->out)) != 0) {
log_debug("%s: redraw deferred (%zu left)", c->name, left);
@ -2626,20 +2628,20 @@ server_client_check_redraw(struct client *c)
* If more that 64 panes, give up and
* just redraw the window.
*/
new_flags &= CLIENT_REDRAWPANES;
new_flags |= CLIENT_REDRAWWINDOW;
client_flags &= CLIENT_REDRAWPANES;
client_flags |= CLIENT_REDRAWWINDOW;
break;
}
}
if (c->redraw_panes != 0)
c->flags |= CLIENT_REDRAWPANES;
}
c->flags |= new_flags;
c->flags |= client_flags;
return;
} else if (needed)
log_debug("%s: redraw needed", c->name);
flags = tty->flags & (TTY_BLOCK|TTY_FREEZE|TTY_NOCURSOR);
tty_flags = tty->flags & (TTY_BLOCK|TTY_FREEZE|TTY_NOCURSOR);
tty->flags = (tty->flags & ~(TTY_BLOCK|TTY_FREEZE))|TTY_NOCURSOR;
if (~c->flags & CLIENT_REDRAWWINDOW) {
@ -2671,9 +2673,10 @@ server_client_check_redraw(struct client *c)
screen_redraw_screen(c);
}
tty->flags = (tty->flags & ~TTY_NOCURSOR)|(flags & TTY_NOCURSOR);
tty->flags = (tty->flags & ~TTY_NOCURSOR)|(tty_flags & TTY_NOCURSOR);
tty_update_mode(tty, mode, NULL);
tty->flags = (tty->flags & ~(TTY_BLOCK|TTY_FREEZE|TTY_NOCURSOR))|flags;
tty->flags = (tty->flags & ~(TTY_BLOCK|TTY_FREEZE|TTY_NOCURSOR))|
tty_flags;
c->flags &= ~(CLIENT_ALLREDRAWFLAGS|CLIENT_STATUSFORCE);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: server.c,v 1.206 2024/05/14 10:11:09 nicm Exp $ */
/* $OpenBSD: server.c,v 1.207 2024/08/26 07:30:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -104,8 +104,8 @@ server_check_marked(void)
}
/* Create server socket. */
static int
server_create_socket(int flags, char **cause)
int
server_create_socket(uint64_t flags, char **cause)
{
struct sockaddr_un sa;
size_t size;
@ -170,7 +170,7 @@ server_tidy_event(__unused int fd, __unused short events, __unused void *data)
/* Fork new server. */
int
server_start(struct tmuxproc *client, int flags, struct event_base *base,
server_start(struct tmuxproc *client, uint64_t flags, struct event_base *base,
int lockfd, char *lockfile)
{
int fd;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: style.c,v 1.34 2024/01/22 16:34:46 nicm Exp $ */
/* $OpenBSD: style.c,v 1.35 2024/08/26 13:02:15 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -58,10 +58,11 @@ int
style_parse(struct style *sy, const struct grid_cell *base, const char *in)
{
struct style saved;
const char delimiters[] = " ,\n", *cp;
const char delimiters[] = " ,\n", *errstr;
char tmp[256], *found;
int value;
size_t end;
u_int n;
if (*in == '\0')
return (0);
@ -137,34 +138,31 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in)
goto error;
if (*found != '%' || found[1] == '\0')
goto error;
for (cp = found + 1; *cp != '\0'; cp++) {
if (!isdigit((u_char)*cp))
goto error;
}
n = strtonum(found + 1, 0, UINT_MAX, &errstr);
if (errstr != NULL)
goto error;
sy->range_type = STYLE_RANGE_PANE;
sy->range_argument = atoi(found + 1);
sy->range_argument = n;
style_set_range_string(sy, "");
} else if (strcasecmp(tmp + 6, "window") == 0) {
if (found == NULL)
goto error;
for (cp = found; *cp != '\0'; cp++) {
if (!isdigit((u_char)*cp))
goto error;
}
n = strtonum(found, 0, UINT_MAX, &errstr);
if (errstr != NULL)
goto error;
sy->range_type = STYLE_RANGE_WINDOW;
sy->range_argument = atoi(found);
sy->range_argument = n;
style_set_range_string(sy, "");
} else if (strcasecmp(tmp + 6, "session") == 0) {
if (found == NULL)
goto error;
if (*found != '$' || found[1] == '\0')
goto error;
for (cp = found + 1; *cp != '\0'; cp++) {
if (!isdigit((u_char)*cp))
goto error;
}
n = strtonum(found + 1, 0, UINT_MAX, &errstr);
if (errstr != NULL)
goto error;
sy->range_type = STYLE_RANGE_SESSION;
sy->range_argument = atoi(found + 1);
sy->range_argument = n;
style_set_range_string(sy, "");
} else if (strcasecmp(tmp + 6, "user") == 0) {
if (found == NULL)

View file

@ -1,4 +1,4 @@
.\" $OpenBSD: tmux.1,v 1.951 2024/08/22 09:05:51 nicm Exp $
.\" $OpenBSD: tmux.1,v 1.952 2024/08/26 07:09:34 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: August 22 2024 $
.Dd $Mdocdate: August 26 2024 $
.Dt TMUX 1
.Os
.Sh NAME
@ -2108,14 +2108,15 @@ The synopsis for the
command is:
.Bl -tag -width Ds
.It Xo Ic copy-mode
.Op Fl eHMqu
.Op Fl deHMqu
.Op Fl s Ar src-pane
.Op Fl t Ar target-pane
.Xc
Enter copy mode.
The
.Fl u
option scrolls one page up.
also scrolls one page up after entering and
.Fl d
one page down if already in copy mode.
.Fl M
begins a mouse drag (only valid if bound to a mouse key binding, see
.Sx MOUSE SUPPORT ) .
@ -2138,6 +2139,7 @@ This is intended to allow fast scrolling through a pane's history, for
example with:
.Bd -literal -offset indent
bind PageUp copy-mode -eu
bind PageDown copy-mode -ed
.Ed
.El
.Pp

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tmux.h,v 1.1222 2024/08/23 13:25:39 nicm Exp $ */
/* $OpenBSD: tmux.h,v 1.1225 2024/08/26 07:30:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -966,6 +966,11 @@ enum pane_lines {
#define PANE_BORDER_ARROWS 2
#define PANE_BORDER_BOTH 3
/* Mode returned by window_pane_mode function. */
#define WINDOW_PANE_NO_MODE 0
#define WINDOW_PANE_COPY_MODE 1
#define WINDOW_PANE_VIEW_MODE 2
/* Screen redraw context. */
struct screen_redraw_ctx {
struct client *c;
@ -2698,10 +2703,12 @@ void server_clear_marked(void);
int server_is_marked(struct session *, struct winlink *,
struct window_pane *);
int server_check_marked(void);
int server_start(struct tmuxproc *, int, struct event_base *, int, char *);
int server_start(struct tmuxproc *, uint64_t, struct event_base *, int,
char *);
void server_update_socket(void);
void server_add_accept(int);
void printflike(1, 2) server_add_message(const char *, ...);
int server_create_socket(uint64_t, char **);
/* server-client.c */
RB_PROTOTYPE(client_windows, client_window, entry, server_client_window_cmp);
@ -3112,6 +3119,7 @@ void window_pane_update_used_data(struct window_pane *,
struct window_pane_offset *, size_t);
void window_set_fill_character(struct window *);
void window_pane_default_cursor(struct window_pane *);
int window_pane_mode(struct window_pane *);
/* layout.c */
u_int layout_count_cells(struct layout_cell *);
@ -3218,6 +3226,7 @@ void printflike(3, 4) window_copy_add(struct window_pane *, int, const char *,
void printflike(3, 0) window_copy_vadd(struct window_pane *, int, const char *,
va_list);
void window_copy_pageup(struct window_pane *, int);
void window_copy_pagedown(struct window_pane *, int, int);
void window_copy_start_drag(struct client *, struct mouse_event *);
char *window_copy_get_word(struct window_pane *, u_int, u_int);
char *window_copy_get_line(struct window_pane *, u_int);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tty-keys.c,v 1.177 2024/08/21 04:17:09 nicm Exp $ */
/* $OpenBSD: tty-keys.c,v 1.178 2024/08/26 07:45:05 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -812,8 +812,9 @@ first_key:
* lowercase, so ^A becomes a|CTRL.
*/
onlykey = key & KEYC_MASK_KEY;
if (onlykey < 0x20 && onlykey != C0_BS &&
onlykey != C0_HT && onlykey != C0_CR &&
if (onlykey < 0x20 &&
onlykey != C0_HT &&
onlykey != C0_CR &&
onlykey != C0_ESC) {
onlykey |= 0x40;
if (onlykey >= 'A' && onlykey <= 'Z')

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tty-term.c,v 1.101 2023/10/17 09:55:32 nicm Exp $ */
/* $OpenBSD: tty-term.c,v 1.102 2024/08/26 13:02:15 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -528,9 +528,10 @@ tty_term_create(struct tty *tty, char *name, char **caps, u_int ncaps,
struct options_array_item *a;
union options_value *ov;
u_int i, j;
const char *s, *value;
const char *s, *value, *errstr;
size_t offset, namelen;
char *first;
int n;
log_debug("adding term %s", name);
@ -564,8 +565,13 @@ tty_term_create(struct tty *tty, char *name, char **caps, u_int ncaps,
code->value.string = tty_term_strip(value);
break;
case TTYCODE_NUMBER:
code->type = TTYCODE_NUMBER;
code->value.number = atoi(value);
n = strtonum(value, 0, INT_MAX, &errstr);
if (errstr != NULL)
log_debug("%s: %s", ent->name, errstr);
else {
code->type = TTYCODE_NUMBER;
code->value.number = n;
}
break;
case TTYCODE_FLAG:
code->type = TTYCODE_FLAG;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: window-copy.c,v 1.350 2024/05/14 09:32:37 nicm Exp $ */
/* $OpenBSD: window-copy.c,v 1.351 2024/08/26 07:09:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -41,7 +41,7 @@ static void window_copy_resize(struct window_mode_entry *, u_int, u_int);
static void window_copy_formats(struct window_mode_entry *,
struct format_tree *);
static void window_copy_pageup1(struct window_mode_entry *, int);
static int window_copy_pagedown(struct window_mode_entry *, int, int);
static int window_copy_pagedown1(struct window_mode_entry *, int, int);
static void window_copy_next_paragraph(struct window_mode_entry *);
static void window_copy_previous_paragraph(struct window_mode_entry *);
static void window_copy_redraw_selection(struct window_mode_entry *, u_int);
@ -646,8 +646,18 @@ window_copy_pageup1(struct window_mode_entry *wme, int half_page)
window_copy_redraw_screen(wme);
}
void
window_copy_pagedown(struct window_pane *wp, int half_page, int scroll_exit)
{
if (window_copy_pagedown1(TAILQ_FIRST(&wp->modes), half_page,
scroll_exit)) {
window_pane_reset_mode(wp);
return;
}
}
static int
window_copy_pagedown(struct window_mode_entry *wme, int half_page,
window_copy_pagedown1(struct window_mode_entry *wme, int half_page,
int scroll_exit)
{
struct window_copy_mode_data *data = wme->data;
@ -1347,7 +1357,7 @@ window_copy_cmd_halfpage_down(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 1, data->scroll_exit))
if (window_copy_pagedown1(wme, 1, data->scroll_exit))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);
@ -1361,7 +1371,7 @@ window_copy_cmd_halfpage_down_and_cancel(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 1, 1))
if (window_copy_pagedown1(wme, 1, 1))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);
@ -1789,7 +1799,7 @@ window_copy_cmd_page_down(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 0, data->scroll_exit))
if (window_copy_pagedown1(wme, 0, data->scroll_exit))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);
@ -1802,7 +1812,7 @@ window_copy_cmd_page_down_and_cancel(struct window_copy_cmd_state *cs)
u_int np = wme->prefix;
for (; np != 0; np--) {
if (window_copy_pagedown(wme, 0, 1))
if (window_copy_pagedown1(wme, 0, 1))
return (WINDOW_COPY_CMD_CANCEL);
}
return (WINDOW_COPY_CMD_NOTHING);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: window.c,v 1.291 2024/06/24 08:30:50 nicm Exp $ */
/* $OpenBSD: window.c,v 1.292 2024/08/26 07:14:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -1662,3 +1662,15 @@ window_pane_default_cursor(struct window_pane *wp)
s->default_mode = 0;
screen_set_cursor_style(c, &s->default_cstyle, &s->default_mode);
}
int
window_pane_mode(struct window_pane *wp)
{
if (TAILQ_FIRST(&wp->modes) != NULL) {
if (TAILQ_FIRST(&wp->modes)->mode == &window_copy_mode)
return (WINDOW_PANE_COPY_MODE);
if (TAILQ_FIRST(&wp->modes)->mode == &window_view_mode)
return (WINDOW_PANE_VIEW_MODE);
}
return (WINDOW_PANE_NO_MODE);
}