Re: move PRU_CONTROL request to (*pru_control)()
Yes, splitting {tcp,udp}_usrreqs and {tcp,udp}6_usrreqs is clearly the Right Thing. ok guenther@ Unrelated to this specific callback, but I think you should consider splitting out uipc_dgram_usrreqs out from uipc_usrreqs, as the SOCK_DGRAM case differs from the other two for multiple callbacks. Philip On Thu, Sep 1, 2022 at 10:54 AM Vitaliy Makkoveev wrote: > The 'proc *' is not used for PRU_CONTROL request, so remove it from > pru_control() wrapper. > > I want to use existing in{6,}_control for tcp(4) and udp(4) sockets, so > for inet6 case I introduced `tcp6_usrreqs' and `udp6_usrreqs' > structures. I also want to use them for the following PRU_SOCKADDR and > PRU_PEERADDR. > > Since the PRU_SOCKADDR and PRU_PEERADDR are the last ones, I want to > move the corresponding (*pru_)() handlers and kill (*pru_usrreq)() with > single diff. Is it ok to review? > > Index: sys/sys/protosw.h > === > RCS file: /cvs/src/sys/sys/protosw.h,v > retrieving revision 1.51 > diff -u -p -r1.51 protosw.h > --- sys/sys/protosw.h 1 Sep 2022 18:21:23 - 1.51 > +++ sys/sys/protosw.h 1 Sep 2022 19:35:08 - > @@ -59,6 +59,7 @@ struct socket; > struct domain; > struct proc; > struct stat; > +struct ifnet; > > struct pr_usrreqs { > /* user request: see list below */ > @@ -77,6 +78,8 @@ struct pr_usrreqs { > int (*pru_send)(struct socket *, struct mbuf *, struct mbuf *, > struct mbuf *); > int (*pru_abort)(struct socket *); > + int (*pru_control)(struct socket *, u_long, caddr_t, > + struct ifnet *); > int (*pru_sense)(struct socket *, struct stat *); > int (*pru_rcvoob)(struct socket *, struct mbuf *, int); > int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf > *, > @@ -343,12 +346,12 @@ pru_abort(struct socket *so) > } > > static inline int > -pru_control(struct socket *so, u_long cmd, caddr_t data, > -struct ifnet *ifp, struct proc *p) > +pru_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet > *ifp) > { > - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, > - PRU_CONTROL, (struct mbuf *)cmd, (struct mbuf *)data, > - (struct mbuf *)ifp, p); > + if (so->so_proto->pr_usrreqs->pru_control) > + return (*so->so_proto->pr_usrreqs->pru_control)(so, > + cmd, data, ifp); > + return (EOPNOTSUPP); > } > > static inline int > Index: sys/kern/sys_socket.c > === > RCS file: /cvs/src/sys/kern/sys_socket.c,v > retrieving revision 1.53 > diff -u -p -r1.53 sys_socket.c > --- sys/kern/sys_socket.c 14 Aug 2022 01:58:28 - 1.53 > +++ sys/kern/sys_socket.c 1 Sep 2022 19:35:07 - > @@ -137,7 +137,7 @@ soo_ioctl(struct file *fp, u_long cmd, c > if (IOCGROUP(cmd) == 'r') > return (EOPNOTSUPP); > KERNEL_LOCK(); > - error = pru_control(so, cmd, data, NULL, p); > + error = pru_control(so, cmd, data, NULL); > KERNEL_UNLOCK(); > break; > } > Index: sys/kern/uipc_usrreq.c > === > RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v > retrieving revision 1.182 > diff -u -p -r1.182 uipc_usrreq.c > --- sys/kern/uipc_usrreq.c 1 Sep 2022 18:21:22 - 1.182 > +++ sys/kern/uipc_usrreq.c 1 Sep 2022 19:35:07 - > @@ -219,8 +219,6 @@ uipc_usrreq(struct socket *so, int req, > struct socket *so2; > int error = 0; > > - if (req == PRU_CONTROL) > - return (EOPNOTSUPP); > if (req != PRU_SEND && control && control->m_len) { > error = EOPNOTSUPP; > goto release; > Index: sys/net/if.c > === > RCS file: /cvs/src/sys/net/if.c,v > retrieving revision 1.663 > diff -u -p -r1.663 if.c > --- sys/net/if.c13 Aug 2022 21:01:46 - 1.663 > +++ sys/net/if.c1 Sep 2022 19:35:07 - > @@ -2360,7 +2360,7 @@ forceup: > break; > /* FALLTHROUGH */ > default: > - error = pru_control(so, cmd, data, ifp, p); > + error = pru_control(so, cmd, data, ifp); > if (error != EOPNOTSUPP) > break; > switch (cmd) { > Index: sys/net/pfkeyv2.c > === > RCS file: /cvs/src/sys/net/pfkeyv2.c,v > retrieving revision 1.249 > diff -u -p -r1.249 pfkeyv2.c > --- sys/net/pfkeyv2.c 1 Sep 2022 18:21:23 - 1.249 > +++ sys/net/pfkeyv2.c 1 Sep 2022 19:35:07 - > @@ -395,9 +395,6 @@ pfkeyv2_usrreq(struct socket *so, int re > struct
sparc64: ofwboot: support booting from softraid 1C
This is practically the same diff we already landed for arm64. The kernel already supports booting off 1C and with tech@'s "installboot: sparc64: fix -r on multi-chunk softraid chunk" diff the install process will no longer fail when installing bootstraps onto any softraid volume which requires at least two chunks by design. Feedback? OK? Index: boot.c === RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/boot.c,v retrieving revision 1.39 diff -u -p -r1.39 boot.c --- boot.c 4 Aug 2022 09:16:53 - 1.39 +++ boot.c 1 Sep 2022 20:10:55 - @@ -366,7 +366,8 @@ srbootdev(const char *bootline) return ENODEV; } - if (bv->sbv_level == 'C' && bv->sbv_keys == NULL) + if ((bv->sbv_level == 'C' || bv->sbv_level == 0x1C) && + bv->sbv_keys == NULL) if (sr_crypto_unlock_volume(bv) != 0) return EPERM; Index: softraid_sparc64.c === RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/softraid_sparc64.c,v retrieving revision 1.5 diff -u -p -r1.5 softraid_sparc64.c --- softraid_sparc64.c 9 Dec 2020 18:10:19 - 1.5 +++ softraid_sparc64.c 1 Sep 2022 20:08:03 - @@ -290,6 +290,7 @@ srprobe(void) break; case 1: + case 0x1C: if (bv->sbv_chunk_no == bv->sbv_chunks_found) bv->sbv_state = BIOC_SVONLINE; else if (bv->sbv_chunks_found > 0) @@ -312,7 +313,8 @@ sr_vol_boot_chunk(struct sr_boot_volume { struct sr_boot_chunk *bc = NULL; - if (bv->sbv_level == 1 || bv->sbv_level == 'C' ) { /* RAID1 or CRYPTO */ + if (bv->sbv_level == 1 || bv->sbv_level == 'C' || + bv->sbv_level == 0x1C) { /* Select first online chunk. */ SLIST_FOREACH(bc, >sbv_chunks, sbc_link) if (bc->sbc_state == BIOC_SDONLINE) @@ -368,7 +370,7 @@ sr_strategy(struct sr_boot_volume *bv, i err = strategy(, rw, blk, size, buf, rsize); return err; - } else if (bv->sbv_level == 'C') { + } else if (bv->sbv_level == 'C' || bv->sbv_level == 0x1C) { /* XXX - select correct key. */ aes_xts_setkey(, (u_char *)bv->sbv_keys, 64); Index: vers.c === RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/vers.c,v retrieving revision 1.24 diff -u -p -r1.24 vers.c --- vers.c 4 Aug 2022 09:16:53 - 1.24 +++ vers.c 20 Aug 2022 03:59:47 - @@ -1 +1 @@ -const char version[] = "1.23"; +const char version[] = "1.24";
installboot: sparc64: fix -r on multi-chunk softraid chunk
Running installboot(8) on softraid(4) volumes means installing stages on every softraid chunk. The overall idea is the same, but MD implementations differ. sparc64_softraid.c's sr_install_bootblk() reuses sparc64_installboot.c's md_installboot() for this. For sparc64, md_installboot() does the copy of stage 2, usually /usr/mdec/ofwboot to /ofwboot, so when `-r root' is passed, it prefixes the file path with "root". For single-disk installations (plain-disk and single-chunk softraid) this is fine, but as soon as multiple chunks are used, md_installboot() currently prefixes the path each time, obviously resulting in invalid paths starting with the second run. Other architectures do reuse md_installboot() as well but either don't do such a copy or implement the prefixing differently -- plus they must support softraid in the firt place to be able to hit this type of bug. The fix is not super pretty and makes sparc64's code look a little of, but this seems to be the simplest and most straight forward fix. Alternatives could perhaps be reworking the fileprefix() function to be resilient against reuse, but that doesn't seem like a sane idea and would involves testing on all architectures. With this fixed, installboot regress finally passes on sparc64 and installboot no longer fails at the end of a fresh installation onto softraid with multiple chunks. Feedback? OK? Index: regress/usr.sbin/installboot/Makefile === RCS file: /cvs/src/regress/usr.sbin/installboot/Makefile,v retrieving revision 1.17 diff -u -p -r1.17 Makefile --- regress/usr.sbin/installboot/Makefile 1 Sep 2022 17:23:36 - 1.17 +++ regress/usr.sbin/installboot/Makefile 1 Sep 2022 19:46:09 - @@ -43,7 +43,6 @@ STAGEDIR =/usr/mdec STAGEFILES = ${STAGENAMES:=${STAGEDIR}/%} .if ${USE_SOFTRAID:L} == "yes" -# installboot(8) behaviour for multi-chunk softraid(4) differs across platforms NDISKS ?= 1 2 .else NDISKS = 1 @@ -121,7 +120,6 @@ dry-default: dry-root: ${SUDO} ${DRY_RUN} -r/ -- "$$(<${ROOTDEVFILE})" -# XXX fails with NDISKS > 1 on sparc64, 1 <= NDISKS <= 4 works on amd64 root: ${SUDO} ${REAL_RUN} -r ${MOUNTPOINT} "$$(<${ROOTDEVFILE})" root-stages: Index: usr.sbin/installboot/sparc64_installboot.c === RCS file: /cvs/src/usr.sbin/installboot/sparc64_installboot.c,v retrieving revision 1.10 diff -u -p -r1.10 sparc64_installboot.c --- usr.sbin/installboot/sparc64_installboot.c 31 Aug 2022 19:40:37 - 1.10 +++ usr.sbin/installboot/sparc64_installboot.c 1 Sep 2022 19:46:09 - @@ -97,10 +97,17 @@ md_prepareboot(int devfd, char *dev) void md_installboot(int devfd, char *dev) { + static int prefixed = 0; + /* XXX - is this necessary? */ sync(); - bootldr = fileprefix(root, bootldr); + /* +* sr_install_bootblk() calls md_installboot() for every softraid chunk +* but the path must be prefixed only once. +*/ + if (!prefixed++) + bootldr = fileprefix(root, bootldr); if (bootldr == NULL) exit(1); if (verbose)
Re: protocol attach wait
On Thu, Sep 01, 2022 at 10:58:49PM +0300, Vitaliy Makkoveev wrote: > On Thu, Sep 01, 2022 at 09:00:50PM +0200, Alexander Bluhm wrote: > > On Mon, Aug 15, 2022 at 05:12:22PM +0200, Alexander Bluhm wrote: > > > System calls should not fail due to temporary memory shortage in > > > malloc(9) or pool_get(9). > > > > > > Pass down a wait flag to pru_attach(). During syscall socket(2) > > > it is ok to wait, this logic was missing for internet pcb. Pfkey > > > and route sockets were already waiting. > > > > > > sonewconn() cannot wait when called during TCP 3-way handshake. > > > This logic has been preserved. Unix domain stream socket connect(2) > > > can wait until the other side has created the socket to accept. > > > > rebased to -current. > > > > Anyone? > > > > At least these ones should have the "pcb == NULL" check as the inet and > unix cases. Or the `wait' could be ignored for all cases except tcp. > > > - kp = pool_get(_pool, PR_WAITOK|PR_ZERO); > > + kp = pool_get(_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) | > > + PR_ZERO); > > so->so_pcb = kp; > > > - rop = pool_get(_pool, PR_WAITOK|PR_ZERO); > > + rop = pool_get(_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) | > > + PR_ZERO); > > so->so_pcb = rop; > But I don't understand what this diff fixes? Userland will check the socket(2) return value in any cases, because it's absolutely normal to fail here. And nothing stops userland to call socket(2) as times as required.
Re: protocol attach wait
On Thu, Sep 01, 2022 at 09:00:50PM +0200, Alexander Bluhm wrote: > On Mon, Aug 15, 2022 at 05:12:22PM +0200, Alexander Bluhm wrote: > > System calls should not fail due to temporary memory shortage in > > malloc(9) or pool_get(9). > > > > Pass down a wait flag to pru_attach(). During syscall socket(2) > > it is ok to wait, this logic was missing for internet pcb. Pfkey > > and route sockets were already waiting. > > > > sonewconn() cannot wait when called during TCP 3-way handshake. > > This logic has been preserved. Unix domain stream socket connect(2) > > can wait until the other side has created the socket to accept. > > rebased to -current. > > Anyone? > At least these ones should have the "pcb == NULL" check as the inet and unix cases. Or the `wait' could be ignored for all cases except tcp. > - kp = pool_get(_pool, PR_WAITOK|PR_ZERO); > + kp = pool_get(_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) | > + PR_ZERO); > so->so_pcb = kp; > - rop = pool_get(_pool, PR_WAITOK|PR_ZERO); > + rop = pool_get(_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) | > + PR_ZERO); > so->so_pcb = rop;
move PRU_CONTROL request to (*pru_control)()
The 'proc *' is not used for PRU_CONTROL request, so remove it from pru_control() wrapper. I want to use existing in{6,}_control for tcp(4) and udp(4) sockets, so for inet6 case I introduced `tcp6_usrreqs' and `udp6_usrreqs' structures. I also want to use them for the following PRU_SOCKADDR and PRU_PEERADDR. Since the PRU_SOCKADDR and PRU_PEERADDR are the last ones, I want to move the corresponding (*pru_)() handlers and kill (*pru_usrreq)() with single diff. Is it ok to review? Index: sys/sys/protosw.h === RCS file: /cvs/src/sys/sys/protosw.h,v retrieving revision 1.51 diff -u -p -r1.51 protosw.h --- sys/sys/protosw.h 1 Sep 2022 18:21:23 - 1.51 +++ sys/sys/protosw.h 1 Sep 2022 19:35:08 - @@ -59,6 +59,7 @@ struct socket; struct domain; struct proc; struct stat; +struct ifnet; struct pr_usrreqs { /* user request: see list below */ @@ -77,6 +78,8 @@ struct pr_usrreqs { int (*pru_send)(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); int (*pru_abort)(struct socket *); + int (*pru_control)(struct socket *, u_long, caddr_t, + struct ifnet *); int (*pru_sense)(struct socket *, struct stat *); int (*pru_rcvoob)(struct socket *, struct mbuf *, int); int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *, @@ -343,12 +346,12 @@ pru_abort(struct socket *so) } static inline int -pru_control(struct socket *so, u_long cmd, caddr_t data, -struct ifnet *ifp, struct proc *p) +pru_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) { - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, - PRU_CONTROL, (struct mbuf *)cmd, (struct mbuf *)data, - (struct mbuf *)ifp, p); + if (so->so_proto->pr_usrreqs->pru_control) + return (*so->so_proto->pr_usrreqs->pru_control)(so, + cmd, data, ifp); + return (EOPNOTSUPP); } static inline int Index: sys/kern/sys_socket.c === RCS file: /cvs/src/sys/kern/sys_socket.c,v retrieving revision 1.53 diff -u -p -r1.53 sys_socket.c --- sys/kern/sys_socket.c 14 Aug 2022 01:58:28 - 1.53 +++ sys/kern/sys_socket.c 1 Sep 2022 19:35:07 - @@ -137,7 +137,7 @@ soo_ioctl(struct file *fp, u_long cmd, c if (IOCGROUP(cmd) == 'r') return (EOPNOTSUPP); KERNEL_LOCK(); - error = pru_control(so, cmd, data, NULL, p); + error = pru_control(so, cmd, data, NULL); KERNEL_UNLOCK(); break; } Index: sys/kern/uipc_usrreq.c === RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v retrieving revision 1.182 diff -u -p -r1.182 uipc_usrreq.c --- sys/kern/uipc_usrreq.c 1 Sep 2022 18:21:22 - 1.182 +++ sys/kern/uipc_usrreq.c 1 Sep 2022 19:35:07 - @@ -219,8 +219,6 @@ uipc_usrreq(struct socket *so, int req, struct socket *so2; int error = 0; - if (req == PRU_CONTROL) - return (EOPNOTSUPP); if (req != PRU_SEND && control && control->m_len) { error = EOPNOTSUPP; goto release; Index: sys/net/if.c === RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.663 diff -u -p -r1.663 if.c --- sys/net/if.c13 Aug 2022 21:01:46 - 1.663 +++ sys/net/if.c1 Sep 2022 19:35:07 - @@ -2360,7 +2360,7 @@ forceup: break; /* FALLTHROUGH */ default: - error = pru_control(so, cmd, data, ifp, p); + error = pru_control(so, cmd, data, ifp); if (error != EOPNOTSUPP) break; switch (cmd) { Index: sys/net/pfkeyv2.c === RCS file: /cvs/src/sys/net/pfkeyv2.c,v retrieving revision 1.249 diff -u -p -r1.249 pfkeyv2.c --- sys/net/pfkeyv2.c 1 Sep 2022 18:21:23 - 1.249 +++ sys/net/pfkeyv2.c 1 Sep 2022 19:35:07 - @@ -395,9 +395,6 @@ pfkeyv2_usrreq(struct socket *so, int re struct pkpcb *kp; int error = 0; - if (req == PRU_CONTROL) - return (EOPNOTSUPP); - soassertlocked(so); if (control && control->m_len) { Index: sys/net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.350 diff -u -p -r1.350 rtsock.c --- sys/net/rtsock.c1 Sep 2022 18:21:23 - 1.350 +++ sys/net/rtsock.c1 Sep 2022 19:35:07 - @@ -220,9 +220,6 @@ route_usrreq(struct socket *so, int req, struct rtpcb*rop; int
Re: httpd: overwrite rather than error for duplicate type entries
Pretty sure this doesn't compile. If it were to compile it would leak memory. On 1 September 2022 20:32:55 CEST, Ben Fuller wrote: >Hi, > >In my httpd.conf, I include /usr/share/misc/mime.types but also want to >define a few of my own type rules: in particular, I wanted to use > >text/"plain;charset=UTF-8" txt > >to get UTF-8 plain text to be displayed correctly. However, this txt >rule collides with the text/plain rule in /usr/share/misc/mime.types. > >This patch allows duplicate type entries in httpd.conf, with rules >further down the file overwriting earlier ones. So now I can include >mime.types and write changed rules underneath. > >Ben > >--- > usr.sbin/httpd/httpd.c | 4 ++-- > usr.sbin/httpd/httpd.conf.5 | 1 + > 2 files changed, 3 insertions(+), 2 deletions(-) > >diff --git usr.sbin/httpd/httpd.c usr.sbin/httpd/httpd.c >index 2acecd1732f..abc2991aaf0 100644 >--- usr.sbin/httpd/httpd.c >+++ usr.sbin/httpd/httpd.c >@@ -1080,9 +1080,9 @@ media_add(struct mediatypes *types, struct media_type >*media) > struct media_type *entry; > > if ((entry = RB_FIND(mediatypes, types, media)) != NULL) { >- log_debug("%s: duplicated entry for \"%s\"", __func__, >+ log_debug("%s: entry overwritten for \"%s\"", __func__, > media->media_name); >- return (NULL); >+ RB_REMOVE(mediatypes, types, media); > } > > if ((entry = malloc(sizeof(*media))) == NULL) >diff --git usr.sbin/httpd/httpd.conf.5 usr.sbin/httpd/httpd.conf.5 >index b5f0be465a0..02f240091b0 100644 >--- usr.sbin/httpd/httpd.conf.5 >+++ usr.sbin/httpd/httpd.conf.5 >@@ -753,6 +753,7 @@ to the specified extension > .Ar name . > One or more names can be specified per line. > Each line may end with an optional semicolon. >+Later lines overwrite earlier lines. > .It Ic include Ar file > Include types definitions from an external file, for example > .Pa /usr/share/misc/mime.types . > -- Sent from a mobile device. Please excuse poor formatting.
Re: protocol attach wait
On Mon, Aug 15, 2022 at 05:12:22PM +0200, Alexander Bluhm wrote: > System calls should not fail due to temporary memory shortage in > malloc(9) or pool_get(9). > > Pass down a wait flag to pru_attach(). During syscall socket(2) > it is ok to wait, this logic was missing for internet pcb. Pfkey > and route sockets were already waiting. > > sonewconn() cannot wait when called during TCP 3-way handshake. > This logic has been preserved. Unix domain stream socket connect(2) > can wait until the other side has created the socket to accept. rebased to -current. Anyone? bluhm Index: kern/uipc_socket.c === RCS file: /data/mirror/openbsd/cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.286 diff -u -p -r1.286 uipc_socket.c --- kern/uipc_socket.c 28 Aug 2022 18:43:12 - 1.286 +++ kern/uipc_socket.c 1 Sep 2022 18:47:36 - @@ -138,11 +138,12 @@ soinit(void) } struct socket * -soalloc(int prflags) +soalloc(int wait) { struct socket *so; - so = pool_get(_pool, prflags); + so = pool_get(_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) | + PR_ZERO); if (so == NULL) return (NULL); rw_init_flags(>so_lock, "solock", RWL_DUPOK); @@ -174,7 +175,7 @@ socreate(int dom, struct socket **aso, i return (EPROTONOSUPPORT); if (prp->pr_type != type) return (EPROTOTYPE); - so = soalloc(PR_WAITOK | PR_ZERO); + so = soalloc(M_WAIT); klist_init(>so_rcv.sb_sel.si_note, _klistops, so); klist_init(>so_snd.sb_sel.si_note, _klistops, so); sigio_init(>so_sigio); @@ -193,7 +194,7 @@ socreate(int dom, struct socket **aso, i so->so_rcv.sb_timeo_nsecs = INFSLP; solock(so); - error = pru_attach(so, proto); + error = pru_attach(so, proto, M_WAIT); if (error) { so->so_state |= SS_NOFDREF; /* sofree() calls sounlock(). */ Index: kern/uipc_socket2.c === RCS file: /data/mirror/openbsd/cvs/src/sys/kern/uipc_socket2.c,v retrieving revision 1.127 diff -u -p -r1.127 uipc_socket2.c --- kern/uipc_socket2.c 13 Aug 2022 21:01:46 - 1.127 +++ kern/uipc_socket2.c 1 Sep 2022 18:47:36 - @@ -168,7 +168,7 @@ soisdisconnected(struct socket *so) * Connstatus may be 0 or SS_ISCONNECTED. */ struct socket * -sonewconn(struct socket *head, int connstatus) +sonewconn(struct socket *head, int connstatus, int wait) { struct socket *so; int persocket = solock_persocket(head); @@ -185,7 +185,7 @@ sonewconn(struct socket *head, int conns return (NULL); if (head->so_qlen + head->so_q0len > head->so_qlimit * 3) return (NULL); - so = soalloc(PR_NOWAIT | PR_ZERO); + so = soalloc(wait); if (so == NULL) return (NULL); so->so_type = head->so_type; @@ -238,7 +238,7 @@ sonewconn(struct socket *head, int conns sounlock(head); } - error = pru_attach(so, 0); + error = pru_attach(so, 0, wait); if (persocket) { sounlock(so); Index: kern/uipc_usrreq.c === RCS file: /data/mirror/openbsd/cvs/src/sys/kern/uipc_usrreq.c,v retrieving revision 1.181 diff -u -p -r1.181 uipc_usrreq.c --- kern/uipc_usrreq.c 31 Aug 2022 21:23:02 - 1.181 +++ kern/uipc_usrreq.c 1 Sep 2022 18:47:36 - @@ -302,7 +302,7 @@ const struct sysctl_bounded_args unpdgct }; int -uipc_attach(struct socket *so, int proto) +uipc_attach(struct socket *so, int proto, int wait) { struct unpcb *unp; int error; @@ -330,7 +330,8 @@ uipc_attach(struct socket *so, int proto if (error) return (error); } - unp = pool_get(_pool, PR_NOWAIT|PR_ZERO); + unp = pool_get(_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) | + PR_ZERO); if (unp == NULL) return (ENOBUFS); refcnt_init(>unp_refcnt); @@ -855,7 +856,7 @@ unp_connect(struct socket *so, struct mb solock(so2); if ((so2->so_options & SO_ACCEPTCONN) == 0 || - (so3 = sonewconn(so2, 0)) == NULL) { + (so3 = sonewconn(so2, 0, M_WAIT)) == NULL) { error = ECONNREFUSED; } Index: net/pfkeyv2.c === RCS file: /data/mirror/openbsd/cvs/src/sys/net/pfkeyv2.c,v retrieving revision 1.248 diff -u -p -r1.248 pfkeyv2.c --- net/pfkeyv2.c 31 Aug 2022 21:23:02 - 1.248 +++ net/pfkeyv2.c 1 Sep 2022 18:47:36 - @@ -169,7 +169,7 @@ static int npromisc = 0; void pfkey_init(void); -int pfkeyv2_attach(struct socket *, int); +int pfkeyv2_attach(struct socket *, int, int); int
Re: printcap.5: Fix phototypesetter name
On Wed, Aug 31, 2022 at 10:57:21AM -0400, Josiah Frentsos wrote: > Index: printcap.5 > === > RCS file: /cvs/src/share/man/man5/printcap.5,v > retrieving revision 1.28 > diff -u -p -r1.28 printcap.5 > --- printcap.510 Feb 2020 13:18:20 - 1.28 > +++ printcap.531 Aug 2022 14:54:14 - > @@ -112,7 +112,7 @@ blocks); 0=unlimited > .It "sf" Ta "bool" Ta "false" Ta "suppress form feeds" > .It "sh" Ta "bool" Ta "false" Ta "suppress printing of burst page header" > .It "st" Ta "str" Ta Pa status Ta "status file name" > -.It "tf" Ta "str" Ta Dv NULL Ta "troff data filter (cat phototypesetter)" > +.It "tf" Ta "str" Ta Dv NULL Ta "troff data filter (C/A/T phototypesetter)" > .It "tr" Ta "str" Ta Dv NULL Ta "trailer string to print when queue empties" > .It "vf" Ta "str" Ta Dv NULL Ta "raster image filter" > .El > fixed, thanks. jmc
Re: move PRU_CONNECT2 request to (*pru_connect2)()
On Thu, Sep 01, 2022 at 08:42:33PM +0300, Vitaliy Makkoveev wrote: > Well, let's be conservative. The `unp2' assignment restored to it's > original place. OK bluhm@ > Index: sys/kern/uipc_usrreq.c > === > RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v > retrieving revision 1.181 > diff -u -p -r1.181 uipc_usrreq.c > --- sys/kern/uipc_usrreq.c31 Aug 2022 21:23:02 - 1.181 > +++ sys/kern/uipc_usrreq.c1 Sep 2022 17:20:32 - > @@ -140,6 +140,7 @@ const struct pr_usrreqs uipc_usrreqs = { > .pru_send = uipc_send, > .pru_abort = uipc_abort, > .pru_sense = uipc_sense, > + .pru_connect2 = uipc_connect2, > }; > > void > @@ -215,7 +216,6 @@ uipc_usrreq(struct socket *so, int req, > struct mbuf *control, struct proc *p) > { > struct unpcb *unp = sotounpcb(so); > - struct unpcb *unp2; > struct socket *so2; > int error = 0; > > @@ -232,21 +232,6 @@ uipc_usrreq(struct socket *so, int req, > > switch (req) { > > - case PRU_CONNECT2: > - error = unp_connect2(so, (struct socket *)nam); > - if (!error) { > - unp->unp_connid.uid = p->p_ucred->cr_uid; > - unp->unp_connid.gid = p->p_ucred->cr_gid; > - unp->unp_connid.pid = p->p_p->ps_pid; > - unp->unp_flags |= UNP_FEIDS; > - unp2 = sotounpcb((struct socket *)nam); > - unp2->unp_connid.uid = p->p_ucred->cr_uid; > - unp2->unp_connid.gid = p->p_ucred->cr_gid; > - unp2->unp_connid.pid = p->p_p->ps_pid; > - unp2->unp_flags |= UNP_FEIDS; > - } > - break; > - > case PRU_SOCKADDR: > uipc_setaddr(unp, nam); > break; > @@ -592,6 +577,28 @@ uipc_sense(struct socket *so, struct sta > sb->st_mtim.tv_nsec = > sb->st_ctim.tv_nsec = unp->unp_ctime.tv_nsec; > sb->st_ino = unp->unp_ino; > + > + return (0); > +} > + > +int > +uipc_connect2(struct socket *so, struct socket *so2) > +{ > + struct unpcb *unp = sotounpcb(so), *unp2; > + int error; > + > + if ((error = unp_connect2(so, so2))) > + return (error); > + > + unp->unp_connid.uid = curproc->p_ucred->cr_uid; > + unp->unp_connid.gid = curproc->p_ucred->cr_gid; > + unp->unp_connid.pid = curproc->p_p->ps_pid; > + unp->unp_flags |= UNP_FEIDS; > + unp2 = sotounpcb(so2); > + unp2->unp_connid.uid = curproc->p_ucred->cr_uid; > + unp2->unp_connid.gid = curproc->p_ucred->cr_gid; > + unp2->unp_connid.pid = curproc->p_p->ps_pid; > + unp2->unp_flags |= UNP_FEIDS; > > return (0); > } > Index: sys/net/pfkeyv2.c > === > RCS file: /cvs/src/sys/net/pfkeyv2.c,v > retrieving revision 1.248 > diff -u -p -r1.248 pfkeyv2.c > --- sys/net/pfkeyv2.c 31 Aug 2022 21:23:02 - 1.248 > +++ sys/net/pfkeyv2.c 1 Sep 2022 17:20:33 - > @@ -412,11 +412,6 @@ pfkeyv2_usrreq(struct socket *so, int re > } > > switch (req) { > - /* no connect, bind, accept. Socket is connected from the start */ > - case PRU_CONNECT2: > - error = EOPNOTSUPP; > - break; > - > /* minimal support, just implement a fake peer address */ > case PRU_SOCKADDR: > error = EINVAL; > Index: sys/net/rtsock.c > === > RCS file: /cvs/src/sys/net/rtsock.c,v > retrieving revision 1.349 > diff -u -p -r1.349 rtsock.c > --- sys/net/rtsock.c 31 Aug 2022 21:23:02 - 1.349 > +++ sys/net/rtsock.c 1 Sep 2022 17:20:33 - > @@ -237,11 +237,6 @@ route_usrreq(struct socket *so, int req, > } > > switch (req) { > - /* no connect, bind, accept. Socket is connected from the start */ > - case PRU_CONNECT2: > - error = EOPNOTSUPP; > - break; > - > /* minimal support, just implement a fake peer address */ > case PRU_SOCKADDR: > error = EINVAL; > Index: sys/netinet/ip_divert.c > === > RCS file: /cvs/src/sys/netinet/ip_divert.c,v > retrieving revision 1.82 > diff -u -p -r1.82 ip_divert.c > --- sys/netinet/ip_divert.c 31 Aug 2022 21:23:02 - 1.82 > +++ sys/netinet/ip_divert.c 1 Sep 2022 17:20:33 - > @@ -279,7 +279,6 @@ divert_usrreq(struct socket *so, int req > in_setpeeraddr(inp, addr); > break; > > - case PRU_CONNECT2: > case PRU_FASTTIMO: > case PRU_SLOWTIMO: > case PRU_PROTORCV: > Index: sys/netinet/raw_ip.c > === > RCS file: /cvs/src/sys/netinet/raw_ip.c,v > retrieving revision 1.143 > diff -u -p -r1.143 raw_ip.c > ---
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
Job Snijders(j...@openbsd.org) on 2022.09.01 03:37:59 +: > Dear all, > > Some ps(1) implementations have an '-d' ('descendancy') option. Through > ASCII art parent/child process relationships are grouped and displayed. > Here is an example: > > $ ps ad -O ppid,user > PID PPID USER TT STATTIME COMMAND > 18180 12529 job pb I+p 0:00.01 `-- -sh (sh) > 26689 56460 job p3 Ip 0:00.01 `-- -ksh (ksh) > 5153 26689 job p3 I+p 0:40.18 `-- mutt > 62046 25272 job p4 Sp 0:00.25 `-- -ksh (ksh) > 61156 62046 job p4 R+/0 0:00.00 `-- ps -ad -O ppid > 26816 2565 job p5 Ip 0:00.01 `-- -ksh (ksh) > 79431 26816 root p5 Ip 0:00.16 `-- /bin/ksh > 43915 79431 _rpki-cl p5 S+pU 0:06.97 `-- rpki-client > 70511 43915 _rpki-cl p5 I+pU 0:01.26 |-- rpki-client: parser > (rpki-client) > 96992 43915 _rpki-cl p5 I+pU 0:00.00 |-- rpki-client: rsync > (rpki-client) > 49160 43915 _rpki-cl p5 S+p 0:01.52 |-- rpki-client: http > (rpki-client) > 99329 43915 _rpki-cl p5 S+p 0:03.20 `-- rpki-client: rrdp > (rpki-client) > > The functionality is similar to pstree(1) in the ports collection. > > The below changeset borrows heavily from the following two > implementations: > > > https://github.com/freebsd/freebsd-src/commit/044fce530f89a819827d351de364d208a30e9645.patch > > https://github.com/NetBSD/src/commit/b82f6d00d93d880d3976c4f1e88c33d88a8054ad.patch > > Thoughts? i like it. found some little things below, with those fixed and some agreement on the option letter (which i dont care about) it has my ok. > > Kind regards, > > Job > > Index: extern.h > === > RCS file: /cvs/src/bin/ps/extern.h,v > retrieving revision 1.23 > diff -u -p -r1.23 extern.h > --- extern.h 5 Jan 2022 04:10:36 - 1.23 > +++ extern.h 1 Sep 2022 03:31:36 - > @@ -44,44 +44,44 @@ extern VAR var[]; > extern VARENT *vhead; > > __BEGIN_DECLS > -void command(const struct kinfo_proc *, VARENT *); > -void cputime(const struct kinfo_proc *, VARENT *); > +void command(const struct pinfo *, VARENT *); > +void cputime(const struct pinfo *, VARENT *); > int donlist(void); > -void elapsed(const struct kinfo_proc *, VARENT *); > +void elapsed(const struct pinfo *, VARENT *); > doublegetpcpu(const struct kinfo_proc *); > -doublegetpmem(const struct kinfo_proc *); > -void gname(const struct kinfo_proc *, VARENT *); > -void supgid(const struct kinfo_proc *, VARENT *); > -void supgrp(const struct kinfo_proc *, VARENT *); > -void logname(const struct kinfo_proc *, VARENT *); > -void longtname(const struct kinfo_proc *, VARENT *); > -void lstarted(const struct kinfo_proc *, VARENT *); > -void maxrss(const struct kinfo_proc *, VARENT *); > +doublegetpmem(const struct pinfo *); > +void gname(const struct pinfo *, VARENT *); > +void supgid(const struct pinfo *, VARENT *); > +void supgrp(const struct pinfo *, VARENT *); > +void logname(const struct pinfo *, VARENT *); > +void longtname(const struct pinfo *, VARENT *); > +void lstarted(const struct pinfo *, VARENT *); > +void maxrss(const struct pinfo *, VARENT *); > void nlisterr(struct nlist *); > -void p_rssize(const struct kinfo_proc *, VARENT *); > -void pagein(const struct kinfo_proc *, VARENT *); > +void p_rssize(const struct pinfo *, VARENT *); > +void pagein(const struct pinfo *, VARENT *); > void parsefmt(char *); > -void pcpu(const struct kinfo_proc *, VARENT *); > -void pmem(const struct kinfo_proc *, VARENT *); > -void pri(const struct kinfo_proc *, VARENT *); > +void pcpu(const struct pinfo *, VARENT *); > +void pmem(const struct pinfo *, VARENT *); > +void pri(const struct pinfo *, VARENT *); > void printheader(void); > -void pvar(const struct kinfo_proc *kp, VARENT *); > -void pnice(const struct kinfo_proc *kp, VARENT *); > -void rgname(const struct kinfo_proc *, VARENT *); > -void rssize(const struct kinfo_proc *, VARENT *); > -void runame(const struct kinfo_proc *, VARENT *); > +void pvar(const struct pinfo *, VARENT *); > +void pnice(const struct pinfo *, VARENT *); > +void rgname(const struct pinfo *, VARENT *); > +void rssize(const struct pinfo *, VARENT *); > +void runame(const struct pinfo *, VARENT *); > void showkey(void); > -void started(const struct kinfo_proc *, VARENT *); > -void printstate(const struct kinfo_proc *, VARENT *); > -void printpledge(const struct kinfo_proc *, VARENT *); > -void tdev(const struct kinfo_proc *, VARENT *); > -void tname(const struct kinfo_proc *, VARENT *); > -void tsize(const struct kinfo_proc *, VARENT *); > -void dsize(const struct kinfo_proc *, VARENT *); > -void ssize(const struct kinfo_proc *, VARENT *); > -void ucomm(const struct kinfo_proc *, VARENT *); >
Re: move PRU_CONNECT2 request to (*pru_connect2)()
On Thu, Sep 01, 2022 at 05:59:44PM +0200, Alexander Bluhm wrote: > On Thu, Sep 01, 2022 at 01:27:18AM +0300, Vitaliy Makkoveev wrote: > > +int > > +uipc_connect2(struct socket *so, struct socket *so2) > > +{ > > + struct unpcb *unp = sotounpcb(so), *unp2 = sotounpcb(so2); > > + int error; > > + > > + if ((error = unp_connect2(so, so2))) > > + return (error); > > + > > + unp->unp_connid.uid = curproc->p_ucred->cr_uid; > > + unp->unp_connid.gid = curproc->p_ucred->cr_gid; > > + unp->unp_connid.pid = curproc->p_p->ps_pid; > > + unp->unp_flags |= UNP_FEIDS; > > + unp2->unp_connid.uid = curproc->p_ucred->cr_uid; > > + unp2->unp_connid.gid = curproc->p_ucred->cr_gid; > > + unp2->unp_connid.pid = curproc->p_p->ps_pid; > > + unp2->unp_flags |= UNP_FEIDS; > > > > return (0); > > } > > You should not move the unp2 = sotounpcb(so2) before unp_connect2(so, > so2). There is this check in unp_connect2(), don't assume so2 has > an unpcb too early. > > if (so2->so_type != so->so_type) > return (EPROTOTYPE); > unp2 = sotounpcb(so2); > > bluhm > This is not true. The "so2->so_type != so->so_type" check within unp_connect2() just prevents the connection between the sockets with different types, but not protocols. You can't connect unix(4) socket to the socket of another protocol like inet(4), but you could try to connect SOCK_STREAM unix(4) socket to another unix(4) socket, for example, of SOCK_DGRAM type. And this check prevents this. This is actual for the PRU_CONNECT and PRU_SEND requests, but not for the PRU_CONNECT2 request, which called only from socketpair(2) ant both sockets have the same protocol and the same type. Also, as you can see, unp_connect2() does not check the "so->so_pcb == NULL", because all sockets have attached PCB. int unp_connect2(struct socket *so, struct socket *so2) { struct unpcb *unp = sotounpcb(so); struct unpcb *unp2; soassertlocked(so); soassertlocked(so2); if (so2->so_type != so->so_type) return (EPROTOTYPE); unp2 = sotounpcb(so2); unp->unp_conn = unp2; Actually, unp_connect2() can't fail in the PRU_CONNECT2, and the check after unp_connect2() could be skipped. Well, let's be conservative. The `unp2' assignment restored to it's original place. Index: sys/kern/uipc_usrreq.c === RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v retrieving revision 1.181 diff -u -p -r1.181 uipc_usrreq.c --- sys/kern/uipc_usrreq.c 31 Aug 2022 21:23:02 - 1.181 +++ sys/kern/uipc_usrreq.c 1 Sep 2022 17:20:32 - @@ -140,6 +140,7 @@ const struct pr_usrreqs uipc_usrreqs = { .pru_send = uipc_send, .pru_abort = uipc_abort, .pru_sense = uipc_sense, + .pru_connect2 = uipc_connect2, }; void @@ -215,7 +216,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *control, struct proc *p) { struct unpcb *unp = sotounpcb(so); - struct unpcb *unp2; struct socket *so2; int error = 0; @@ -232,21 +232,6 @@ uipc_usrreq(struct socket *so, int req, switch (req) { - case PRU_CONNECT2: - error = unp_connect2(so, (struct socket *)nam); - if (!error) { - unp->unp_connid.uid = p->p_ucred->cr_uid; - unp->unp_connid.gid = p->p_ucred->cr_gid; - unp->unp_connid.pid = p->p_p->ps_pid; - unp->unp_flags |= UNP_FEIDS; - unp2 = sotounpcb((struct socket *)nam); - unp2->unp_connid.uid = p->p_ucred->cr_uid; - unp2->unp_connid.gid = p->p_ucred->cr_gid; - unp2->unp_connid.pid = p->p_p->ps_pid; - unp2->unp_flags |= UNP_FEIDS; - } - break; - case PRU_SOCKADDR: uipc_setaddr(unp, nam); break; @@ -592,6 +577,28 @@ uipc_sense(struct socket *so, struct sta sb->st_mtim.tv_nsec = sb->st_ctim.tv_nsec = unp->unp_ctime.tv_nsec; sb->st_ino = unp->unp_ino; + + return (0); +} + +int +uipc_connect2(struct socket *so, struct socket *so2) +{ + struct unpcb *unp = sotounpcb(so), *unp2; + int error; + + if ((error = unp_connect2(so, so2))) + return (error); + + unp->unp_connid.uid = curproc->p_ucred->cr_uid; + unp->unp_connid.gid = curproc->p_ucred->cr_gid; + unp->unp_connid.pid = curproc->p_p->ps_pid; + unp->unp_flags |= UNP_FEIDS; + unp2 = sotounpcb(so2); + unp2->unp_connid.uid = curproc->p_ucred->cr_uid; + unp2->unp_connid.gid = curproc->p_ucred->cr_gid; + unp2->unp_connid.pid = curproc->p_p->ps_pid; + unp2->unp_flags |= UNP_FEIDS; return (0); } Index: sys/net/pfkeyv2.c
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
On Thu, Sep 01, 2022 at 06:14:17PM +0200, Florian Obser wrote: > >> NetBSD's and FreeBSD's ps(1) use '-d' to display process hierarchy. > > > > using -f would follow the path of least resistance. Is there really a > > common > > user commnity between freebsd netbsd and openbsd? I doubt it. > > > > Curious, my Jesus Laptop (macOS 12.5) has > -A Display information about other users' processes, including > those without controlling terminals. > [...] > -d Like -A, but excludes session leaders. > > It does not have this feature at all. Is this a new thing in FreeBSD? FreeBSD May 2009: https://github.com/freebsd/freebsd-src/commit/044fce530f89a819827d351de364d208a30e9645 NetBSD December 2016: https://github.com/NetBSD/src/commit/b82f6d00d93d880d3976c4f1e88c33d88a8054ad GPL ps probably introduced '-f' more than 20 years ago. Kind regards, Job
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
Florian Obser wrote: > On 2022-09-01 09:55 -06, "Theo de Raadt" wrote: > > Job Snijders wrote: > > > >> On Thu, Sep 01, 2022 at 03:14:40PM +0200, Martin Schröder wrote: > >> > Am Do., 1. Sept. 2022 um 05:38 Uhr schrieb Job Snijders > >> > : > >> > > Some ps(1) implementations have an '-d' ('descendancy') option. Through > >> > > ASCII art parent/child process relationships are grouped and displayed. > >> > > > >> > > Thoughts? > >> > > >> > gnu ps has > >> > > >> > -d Select all processes except session leaders. > >> > > >> > and > >> > > >> >f ASCII art process hierarchy (forest). > >> > > >> >--forest > >> > ASCII art process tree. > >> > >> GNU ps uses both '-f', '--forest', and '-H' to display process > >> hierarchy. The '-H' option uses indenting (no ASCII art). > >> > >> NetBSD's and FreeBSD's ps(1) use '-d' to display process hierarchy. > > > > using -f would follow the path of least resistance. Is there really a > > common > > user commnity between freebsd netbsd and openbsd? I doubt it. > > > > Curious, my Jesus Laptop (macOS 12.5) has > -A Display information about other users' processes, including > those without controlling terminals. > [...] > -d Like -A, but excludes session leaders. > > It does not have this feature at all. Is this a new thing in FreeBSD? A lot of macos is really old, and does not follow any upstream.
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
On 2022-09-01 09:55 -06, "Theo de Raadt" wrote: > Job Snijders wrote: > >> On Thu, Sep 01, 2022 at 03:14:40PM +0200, Martin Schröder wrote: >> > Am Do., 1. Sept. 2022 um 05:38 Uhr schrieb Job Snijders : >> > > Some ps(1) implementations have an '-d' ('descendancy') option. Through >> > > ASCII art parent/child process relationships are grouped and displayed. >> > > >> > > Thoughts? >> > >> > gnu ps has >> > >> > -d Select all processes except session leaders. >> > >> > and >> > >> >f ASCII art process hierarchy (forest). >> > >> >--forest >> > ASCII art process tree. >> >> GNU ps uses both '-f', '--forest', and '-H' to display process >> hierarchy. The '-H' option uses indenting (no ASCII art). >> >> NetBSD's and FreeBSD's ps(1) use '-d' to display process hierarchy. > > using -f would follow the path of least resistance. Is there really a common > user commnity between freebsd netbsd and openbsd? I doubt it. > Curious, my Jesus Laptop (macOS 12.5) has -A Display information about other users' processes, including those without controlling terminals. [...] -d Like -A, but excludes session leaders. It does not have this feature at all. Is this a new thing in FreeBSD? -- I'm not entirely sure you are real.
Re: add sendmmsg and recvmmsg systemcalls
I addressed your concerns as well as these of jca, just the kernel part (and the new ktrace stuff) below. One minor thing: I didn't see any kdump output where one struct was contained in another one but I am printing it like ddb would so I guess it should be fine. Index: kern/syscalls.master === RCS file: /mount/openbsd/cvs/src/sys/kern/syscalls.master,v retrieving revision 1.229 diff -u -p -r1.229 syscalls.master --- kern/syscalls.master1 Aug 2022 14:56:59 - 1.229 +++ kern/syscalls.master1 Sep 2022 14:52:47 - @@ -244,8 +244,10 @@ const char *permissions); } 115STD { int sys___realpath(const char *pathname, \ char *resolved); } -116OBSOL t32_gettimeofday -117OBSOL t32_getrusage +116STD NOLOCK { int sys_recvmmsg(int s, struct mmsghdr *mmsg, \ + unsigned int vlen, unsigned int flags, \ + struct timespec *timeout); } +117UNIMPL sendmmsg 118STD { int sys_getsockopt(int s, int level, int name, \ void *val, socklen_t *avalsize); } 119STD { int sys_thrkill(pid_t tid, int signum, void *tcb); } Index: kern/uipc_syscalls.c === RCS file: /mount/openbsd/cvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.201 diff -u -p -r1.201 uipc_syscalls.c --- kern/uipc_syscalls.c14 Aug 2022 01:58:28 - 1.201 +++ kern/uipc_syscalls.c1 Sep 2022 14:37:26 - @@ -805,6 +805,140 @@ done: } int +sys_recvmmsg(struct proc *p, void *v, register_t *retval) +{ + struct sys_recvmmsg_args /* { + syscallarg(int) s; + syscallarg(struct mmsghdr *)mmsg; + syscallarg(unsigned int)vlen; + syscallarg(unsigned int)flags; + syscallarg(struct timespec *) timeout; + } */ *uap = v; + struct mmsghdr mmsg, *mmsgp; + struct timespec ts, now; + struct iovec aiov[UIO_SMALLIOV], *uiov, *iov = aiov; + struct file *fp; + struct socket *so; + struct timespec *timeout; + size_t iovlen = UIO_SMALLIOV; + register_t retrec; + unsigned int vlen, dgrams; + int error = 0, flags, s; + + s = SCARG(uap, s); + if ((error = getsock(p, s, ))) + return (error); + so = (struct socket *)fp->f_data; + + timeout = SCARG(uap, timeout); + if (timeout != NULL) { + error = copyin(timeout, , sizeof(ts)); + if (error) + return error; +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrreltimespec(p, ); +#endif + getnanotime(); + timespecadd(, , ); + } + + flags = SCARG(uap, flags); + + /* Arbitrarily capped at 1024 datagrams. */ + vlen = SCARG(uap, vlen); + if (vlen > 1024) + vlen = 1024; + + mmsgp = SCARG(uap, mmsg); + for (dgrams = 0; dgrams < vlen;) { + error = copyin([dgrams], , sizeof(mmsg)); + if (error) + break; + + if (mmsg.msg_hdr.msg_iovlen > IOV_MAX) { + error = EMSGSIZE; + break; + } + + if (mmsg.msg_hdr.msg_iovlen > iovlen) { + if (iov != aiov) + free(iov, M_IOV, iovlen * + sizeof(struct iovec)); + + iovlen = mmsg.msg_hdr.msg_iovlen; + iov = mallocarray(iovlen, sizeof(struct iovec), + M_IOV, M_WAITOK); + } + + if (mmsg.msg_hdr.msg_iovlen > 0) { + error = copyin(mmsg.msg_hdr.msg_iov, iov, + mmsg.msg_hdr.msg_iovlen * sizeof(struct iovec)); + if (error) + break; + } + + uiov = mmsg.msg_hdr.msg_iov; + mmsg.msg_hdr.msg_iov = iov; + mmsg.msg_hdr.msg_flags = flags; + + error = recvit(p, s, _hdr, NULL, ); + if (error) { + if (error == EAGAIN && dgrams > 0) + error = 0; + break; + } + + if (dgrams == 0 && flags & MSG_WAITFORONE) { + flags &= ~MSG_WAITFORONE; + flags |= MSG_DONTWAIT; + } + + mmsg.msg_hdr.msg_iov = uiov; + mmsg.msg_len = retrec; +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) { + ktrmmsghdr(p, ); + if
Re: move PRU_CONNECT2 request to (*pru_connect2)()
On Thu, Sep 01, 2022 at 01:27:18AM +0300, Vitaliy Makkoveev wrote: > +int > +uipc_connect2(struct socket *so, struct socket *so2) > +{ > + struct unpcb *unp = sotounpcb(so), *unp2 = sotounpcb(so2); > + int error; > + > + if ((error = unp_connect2(so, so2))) > + return (error); > + > + unp->unp_connid.uid = curproc->p_ucred->cr_uid; > + unp->unp_connid.gid = curproc->p_ucred->cr_gid; > + unp->unp_connid.pid = curproc->p_p->ps_pid; > + unp->unp_flags |= UNP_FEIDS; > + unp2->unp_connid.uid = curproc->p_ucred->cr_uid; > + unp2->unp_connid.gid = curproc->p_ucred->cr_gid; > + unp2->unp_connid.pid = curproc->p_p->ps_pid; > + unp2->unp_flags |= UNP_FEIDS; > > return (0); > } You should not move the unp2 = sotounpcb(so2) before unp_connect2(so, so2). There is this check in unp_connect2(), don't assume so2 has an unpcb too early. if (so2->so_type != so->so_type) return (EPROTOTYPE); unp2 = sotounpcb(so2); bluhm
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
Job Snijders wrote: > On Thu, Sep 01, 2022 at 03:14:40PM +0200, Martin Schröder wrote: > > Am Do., 1. Sept. 2022 um 05:38 Uhr schrieb Job Snijders : > > > Some ps(1) implementations have an '-d' ('descendancy') option. Through > > > ASCII art parent/child process relationships are grouped and displayed. > > > > > > Thoughts? > > > > gnu ps has > > > > -d Select all processes except session leaders. > > > > and > > > >f ASCII art process hierarchy (forest). > > > >--forest > > ASCII art process tree. > > GNU ps uses both '-f', '--forest', and '-H' to display process > hierarchy. The '-H' option uses indenting (no ASCII art). > > NetBSD's and FreeBSD's ps(1) use '-d' to display process hierarchy. using -f would follow the path of least resistance. Is there really a common user commnity between freebsd netbsd and openbsd? I doubt it.
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
On 2022/09/01 15:14, Martin Schröder wrote: > Am Do., 1. Sept. 2022 um 05:38 Uhr schrieb Job Snijders : > > Some ps(1) implementations have an '-d' ('descendancy') option. Through > > ASCII art parent/child process relationships are grouped and displayed. > > > > Thoughts? > > gnu ps has > > -d Select all processes except session leaders. > > and > >f ASCII art process hierarchy (forest). > >--forest > ASCII art process tree. > > Best > Martin > given the big differences for flags in ps between sysv-ish and bsd-ish OS, it totally makes sense to follow the flag used by other BSDs here.
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
On Thu, Sep 01, 2022 at 03:14:40PM +0200, Martin Schröder wrote: > Am Do., 1. Sept. 2022 um 05:38 Uhr schrieb Job Snijders : > > Some ps(1) implementations have an '-d' ('descendancy') option. Through > > ASCII art parent/child process relationships are grouped and displayed. > > > > Thoughts? > > gnu ps has > > -d Select all processes except session leaders. > > and > >f ASCII art process hierarchy (forest). > >--forest > ASCII art process tree. GNU ps uses both '-f', '--forest', and '-H' to display process hierarchy. The '-H' option uses indenting (no ASCII art). NetBSD's and FreeBSD's ps(1) use '-d' to display process hierarchy. Kind regards, Job
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
Am Do., 1. Sept. 2022 um 05:38 Uhr schrieb Job Snijders : > Some ps(1) implementations have an '-d' ('descendancy') option. Through > ASCII art parent/child process relationships are grouped and displayed. > > Thoughts? gnu ps has -d Select all processes except session leaders. and f ASCII art process hierarchy (forest). --forest ASCII art process tree. Best Martin
immutable userland mappings
In the last few years, I have been improving the strictness of userland memory layout. An example is the recent addition of MAP_STACK and msyscall(). The first one marks pages that are stack, so that upon entry to the kernel we can check if the stack-pointer is pointing in the stack range. If it isn't, the most obvious conclusion is that a ROP pivot has occured, and we kills the process. The second one marks the region which contains syscall traps, if upon entry to the kernel the PC is not in that region, we know somone is trying to do system calls via an unapproved method. My next attempt is to lock memory mappings. The current working name is mimmutable(void *addr, size_t len). This identifies all current mapped memory in a region, and tags the mappings. Such mappings can never be unmapped. No new mmap can be done on top of the mappings. And the permissions cannot be changed. Other than that, the underlying storage memory works fine, it is just the mapping that is locked. I'm aware of an method used at least once (not on openbsd) which managed to mprotect a region of libc, and then place things there, for later execution. That makes msyscall() less useful, so I want to restore the strenth. In this version of the diff, the kernel manages to mark immutable most of the main binary, and in the shared-binary case, also most of ld.so. But it cannot mark all of the ELF mapping -- because of two remaining problems (RELRO in .data, and the malloc.c self-protected bookkeeping page in .bss). I am looking into various solutions for both of those. So for now, crt0 self-immutables the remaining parts, and ld.so does the same for itself. ld.so is also responsible for immutable marking on libraries it loads. To my surprise, the diff is working quite well. With kern.allowkmem=1, "procmap -a" can see what process mappings look like, and they are quite locked down. This is a view of a "sed", with 'grep -v anon'. The "I" marker indicates mapping immutability. A few small chunks must still be fixed. StartEnd Size Offset rwxSeIpc RWX I/W/A Dev Inode - File 03128621a000-03128621cfff 12k rIp+ (rwx) 1/0/0 04:05 77840 - /usr/bin/sed [0xfd83e38b3640] 03128621d000-031286222fff 24k 2000 r-x--Ip+ (rwx) 1/0/0 04:05 77840 - /usr/bin/sed [0xfd83e38b3640] 03148bbc3000-03148bbc3fff 4k rIs- (r--) 1/0/1 00:00 0 - [ uvm_aobj ] 0314ea4e7000-0314ea51dfff 220k rIp+ (rwx) 1/0/0 04:05 103688 - /usr/lib/libc.so.96.1 [0xfd83e0c62608] 0314ea51e000-0314ea5c2fff 660k 00036000 r-x-eIp+ (rwx) 1/0/0 04:05 103688 - /usr/lib/libc.so.96.1 [0xfd83e0c62608] 0314ea5c3000-0314ea5c8fff 24k 000da000 rIp- (rwx) 1/0/0 04:05 103688 - /usr/lib/libc.so.96.1 [0xfd83e0c62608] 0314ea5c9000-0314ea5cbfff 12k 000df000 rw---Ip- (rwx) 1/0/0 04:05 103688 - /usr/lib/libc.so.96.1 [0xfd83e0c62608] 031526544000-031526544fff 4k r-x-eIp+ (rwx) 1/0/1 00:00 0 - [ uvm_aobj ] 031535da7000-031535da9fff 12k rIp+ (rwx) 1/0/0 04:05 336963 - /usr/libexec/ld.so [0xfd83e27f90e8] 031535eac000-031535eb6fff 44k 5000 r-x-eIp+ (rwx) 1/0/0 04:05 336963 - /usr/libexec/ld.so [0xfd83e27f90e8] 031535fa7000-031535fa7fff 4k 0001 r-p- (rwx) 1/0/0 04:05 336963 - /usr/libexec/ld.so [0xfd83e27f90e8] 031535fa8000-031535fa8fff 4k 00011000 rwp- (rwx) 1/0/0 04:05 336963 - /usr/libexec/ld.so [0xfd83e27f90e8] 03154a19e000-03154a1b1fff 80k rIp+ (rwx) 1/0/0 04:04 3654731 - /var/run/ld.so.hints [0xfd83e1098960] 7f7ffdebd000-7f7fffbbcfff 29696k --p+ (rwx) 1/0/0 00:00 0 - [ stack ] total 5724k I wanted to show it a bit early. To try the diff: - apply patch - cd /usr/src/sys/kern; make syscalls - build and boot new kernel - cd /usr/src; make includes - cd lib/libc; make && make install - cd /usr/src/*/ld.so; make && make install - cd /usr/src/lib/csu; make && make install - then other binaries can be built, including procmap Index: lib/csu/boot.h === RCS file: /cvs/src/lib/csu/boot.h,v retrieving revision 1.33 diff -u -p -u -r1.33 boot.h --- lib/csu/boot.h 12 Jan 2022 21:41:06 - 1.33 +++ lib/csu/boot.h 31 Aug 2022 05:14:09 - @@ -35,7 +35,6 @@ #define_DYN_LOADER #include -#include #include @@ -50,6 +49,7 @@ void _dl_exit(int); */ #define REDIRECT_SYSCALL(x)typeof(x) x asm("_libc_"#x) __dso_hidden REDIRECT_SYSCALL(mprotect); +REDIRECT_SYSCALL(mimmutable); #if RELOC_TAG == DT_RELA typedef
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
Hi Job, * Job Snijders wrote: > Dear all, > > Some ps(1) implementations have an '-d' ('descendancy') option. Through > ASCII art parent/child process relationships are grouped and displayed. > Here is an example: > > $ ps ad -O ppid,user > PID PPID USER TT STATTIME COMMAND > 18180 12529 job pb I+p 0:00.01 `-- -sh (sh) > 26689 56460 job p3 Ip 0:00.01 `-- -ksh (ksh) > 5153 26689 job p3 I+p 0:40.18 `-- mutt > 62046 25272 job p4 Sp 0:00.25 `-- -ksh (ksh) > 61156 62046 job p4 R+/0 0:00.00 `-- ps -ad -O ppid > 26816 2565 job p5 Ip 0:00.01 `-- -ksh (ksh) > 79431 26816 root p5 Ip 0:00.16 `-- /bin/ksh > 43915 79431 _rpki-cl p5 S+pU 0:06.97 `-- rpki-client > 70511 43915 _rpki-cl p5 I+pU 0:01.26 |-- rpki-client: parser > (rpki-client) > 96992 43915 _rpki-cl p5 I+pU 0:00.00 |-- rpki-client: rsync > (rpki-client) > 49160 43915 _rpki-cl p5 S+p 0:01.52 |-- rpki-client: http > (rpki-client) > 99329 43915 _rpki-cl p5 S+p 0:03.20 `-- rpki-client: rrdp > (rpki-client) > > The functionality is similar to pstree(1) in the ports collection. > > The below changeset borrows heavily from the following two > implementations: > > > https://github.com/freebsd/freebsd-src/commit/044fce530f89a819827d351de364d208a30e9645.patch > > https://github.com/NetBSD/src/commit/b82f6d00d93d880d3976c4f1e88c33d88a8054ad.patch > > Thoughts? As someone who is running two OpenBSD based multi-user systems I would love to see this feature integrated. From time to time I investigate processes/scripts from users and seeing the process tree without additional tools like htop would really be appreciated. Cheers Matthias
Re: ps(1): add -d (descendancy) option to display parent/child process relationships
On 01/09/22(Thu) 03:37, Job Snijders wrote: > Dear all, > > Some ps(1) implementations have an '-d' ('descendancy') option. Through > ASCII art parent/child process relationships are grouped and displayed. > Here is an example: > > $ ps ad -O ppid,user > PID PPID USER TT STATTIME COMMAND > 18180 12529 job pb I+p 0:00.01 `-- -sh (sh) > 26689 56460 job p3 Ip 0:00.01 `-- -ksh (ksh) > 5153 26689 job p3 I+p 0:40.18 `-- mutt > 62046 25272 job p4 Sp 0:00.25 `-- -ksh (ksh) > 61156 62046 job p4 R+/0 0:00.00 `-- ps -ad -O ppid > 26816 2565 job p5 Ip 0:00.01 `-- -ksh (ksh) > 79431 26816 root p5 Ip 0:00.16 `-- /bin/ksh > 43915 79431 _rpki-cl p5 S+pU 0:06.97 `-- rpki-client > 70511 43915 _rpki-cl p5 I+pU 0:01.26 |-- rpki-client: parser > (rpki-client) > 96992 43915 _rpki-cl p5 I+pU 0:00.00 |-- rpki-client: rsync > (rpki-client) > 49160 43915 _rpki-cl p5 S+p 0:01.52 |-- rpki-client: http > (rpki-client) > 99329 43915 _rpki-cl p5 S+p 0:03.20 `-- rpki-client: rrdp > (rpki-client) > > The functionality is similar to pstree(1) in the ports collection. > > The below changeset borrows heavily from the following two > implementations: > > > https://github.com/freebsd/freebsd-src/commit/044fce530f89a819827d351de364d208a30e9645.patch > > https://github.com/NetBSD/src/commit/b82f6d00d93d880d3976c4f1e88c33d88a8054ad.patch > > Thoughts? I'd love to have such feature in base. > Index: extern.h > === > RCS file: /cvs/src/bin/ps/extern.h,v > retrieving revision 1.23 > diff -u -p -r1.23 extern.h > --- extern.h 5 Jan 2022 04:10:36 - 1.23 > +++ extern.h 1 Sep 2022 03:31:36 - > @@ -44,44 +44,44 @@ extern VAR var[]; > extern VARENT *vhead; > > __BEGIN_DECLS > -void command(const struct kinfo_proc *, VARENT *); > -void cputime(const struct kinfo_proc *, VARENT *); > +void command(const struct pinfo *, VARENT *); > +void cputime(const struct pinfo *, VARENT *); > int donlist(void); > -void elapsed(const struct kinfo_proc *, VARENT *); > +void elapsed(const struct pinfo *, VARENT *); > doublegetpcpu(const struct kinfo_proc *); > -doublegetpmem(const struct kinfo_proc *); > -void gname(const struct kinfo_proc *, VARENT *); > -void supgid(const struct kinfo_proc *, VARENT *); > -void supgrp(const struct kinfo_proc *, VARENT *); > -void logname(const struct kinfo_proc *, VARENT *); > -void longtname(const struct kinfo_proc *, VARENT *); > -void lstarted(const struct kinfo_proc *, VARENT *); > -void maxrss(const struct kinfo_proc *, VARENT *); > +doublegetpmem(const struct pinfo *); > +void gname(const struct pinfo *, VARENT *); > +void supgid(const struct pinfo *, VARENT *); > +void supgrp(const struct pinfo *, VARENT *); > +void logname(const struct pinfo *, VARENT *); > +void longtname(const struct pinfo *, VARENT *); > +void lstarted(const struct pinfo *, VARENT *); > +void maxrss(const struct pinfo *, VARENT *); > void nlisterr(struct nlist *); > -void p_rssize(const struct kinfo_proc *, VARENT *); > -void pagein(const struct kinfo_proc *, VARENT *); > +void p_rssize(const struct pinfo *, VARENT *); > +void pagein(const struct pinfo *, VARENT *); > void parsefmt(char *); > -void pcpu(const struct kinfo_proc *, VARENT *); > -void pmem(const struct kinfo_proc *, VARENT *); > -void pri(const struct kinfo_proc *, VARENT *); > +void pcpu(const struct pinfo *, VARENT *); > +void pmem(const struct pinfo *, VARENT *); > +void pri(const struct pinfo *, VARENT *); > void printheader(void); > -void pvar(const struct kinfo_proc *kp, VARENT *); > -void pnice(const struct kinfo_proc *kp, VARENT *); > -void rgname(const struct kinfo_proc *, VARENT *); > -void rssize(const struct kinfo_proc *, VARENT *); > -void runame(const struct kinfo_proc *, VARENT *); > +void pvar(const struct pinfo *, VARENT *); > +void pnice(const struct pinfo *, VARENT *); > +void rgname(const struct pinfo *, VARENT *); > +void rssize(const struct pinfo *, VARENT *); > +void runame(const struct pinfo *, VARENT *); > void showkey(void); > -void started(const struct kinfo_proc *, VARENT *); > -void printstate(const struct kinfo_proc *, VARENT *); > -void printpledge(const struct kinfo_proc *, VARENT *); > -void tdev(const struct kinfo_proc *, VARENT *); > -void tname(const struct kinfo_proc *, VARENT *); > -void tsize(const struct kinfo_proc *, VARENT *); > -void dsize(const struct kinfo_proc *, VARENT *); > -void ssize(const struct kinfo_proc *, VARENT *); > -void ucomm(const struct kinfo_proc *, VARENT *); > -void curwd(const struct kinfo_proc *, VARENT *); > -void euname(const struct kinfo_proc *, VARENT *); > -void vsize(const struct kinfo_proc *, VARENT
Re: bgpd switch rde_peer to RB tree
Claudio Jeker(cje...@diehard.n-r-g.com) on 2022.09.01 12:04:03 +0200: > Convert the rde_peer hash table to an RB tree. This is a bit more complex > because rde_peer list is used in a lot of places. As a bonus use > peer_foreach in mrt.c to write the table v2 peer header (this needs a > special callback struct because two values need to be passed to the > callback). > > The rest of the code is mostly a simple conversion. Only peer_match > required to be adjusted because the code is now able to use peer_get() > to find the start point. > -- > :wq Claudio ok benno@ > > Index: mrt.c > === > RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v > retrieving revision 1.109 > diff -u -p -r1.109 mrt.c > --- mrt.c 17 Aug 2022 15:15:26 - 1.109 > +++ mrt.c 1 Sep 2022 00:25:24 - > @@ -783,14 +783,33 @@ fail: > return (-1); > } > > +struct cb_arg { > + struct ibuf *buf; > + int nump; > +}; > + > +static void > +mrt_dump_v2_hdr_peer(struct rde_peer *peer, void *arg) > +{ > + struct cb_arg *a = arg; > + > + if (a->nump == -1) > + return; > + peer->mrt_idx = a->nump; > + if (mrt_dump_peer(a->buf, peer) == -1) { > + a->nump = -1; > + return; > + } > + a->nump++; > +} > + > int > -mrt_dump_v2_hdr(struct mrt *mrt, struct bgpd_config *conf, > -struct rde_peer_head *ph) > +mrt_dump_v2_hdr(struct mrt *mrt, struct bgpd_config *conf) > { > - struct rde_peer *peer; > struct ibuf *buf, *hbuf = NULL; > size_t len, off; > uint16_t nlen, nump; > + struct cb_argarg; > > if ((buf = ibuf_dynamic(0, UINT_MAX)) == NULL) { > log_warn("%s: ibuf_dynamic", __func__); > @@ -812,14 +831,13 @@ mrt_dump_v2_hdr(struct mrt *mrt, struct > log_warn("%s: ibuf_reserve error", __func__); > goto fail; > } > - nump = 0; > - LIST_FOREACH(peer, ph, peer_l) { > - peer->mrt_idx = nump; > - if (mrt_dump_peer(buf, peer) == -1) > - goto fail; > - nump++; > - } > - nump = htons(nump); > + arg.nump = 0; > + arg.buf = buf; > + peer_foreach(mrt_dump_v2_hdr_peer, ); > + if (arg.nump == -1) > + goto fail; > + > + nump = htons(arg.nump); > memcpy(ibuf_seek(buf, off, sizeof(nump)), , sizeof(nump)); > > len = ibuf_size(buf); > Index: rde.c > === > RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v > retrieving revision 1.573 > diff -u -p -r1.573 rde.c > --- rde.c 31 Aug 2022 15:51:44 - 1.573 > +++ rde.c 1 Sep 2022 08:29:31 - > @@ -114,8 +114,8 @@ struct rde_memstatsrdemem; > int softreconfig; > static intrde_eval_all; > > -extern struct rde_peer_head peerlist; > -extern struct rde_peer *peerself; > +extern struct peer_tree peertable; > +extern struct rde_peer *peerself; > > struct rde_dump_ctx { > LIST_ENTRY(rde_dump_ctx)entry; > @@ -145,8 +145,6 @@ rde_sighdlr(int sig) > } > } > > -uint32_t peerhashsize = 1024; > - > void > rde_main(int debug, int verbose) > { > @@ -194,7 +192,7 @@ rde_main(int debug, int verbose) > > /* initialize the RIB structures */ > pt_init(); > - peer_init(peerhashsize); > + peer_init(); > > /* make sure the default RIBs are setup */ > rib_new("Adj-RIB-In", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE); > @@ -2982,7 +2980,7 @@ rde_dump_mrt_new(struct mrt *mrt, pid_t > } > > if (ctx->mrt.type == MRT_TABLE_DUMP_V2) > - mrt_dump_v2_hdr(>mrt, conf, ); > + mrt_dump_v2_hdr(>mrt, conf); > > if (rib_dump_new(rid, AID_UNSPEC, CTL_MSG_HIGH_MARK, >mrt, > mrt_dump_upcall, rde_mrt_done, rde_mrt_throttled) == -1) > @@ -3105,7 +3103,7 @@ rde_update_queue_pending(void) > if (ibuf_se && ibuf_se->w.queued >= SESS_MSG_HIGH_MARK) > return 0; > > - LIST_FOREACH(peer, , peer_l) { > + RB_FOREACH(peer, peer_tree, ) { > if (peer->conf.id == 0) > continue; > if (peer->state != PEER_UP) > @@ -3131,7 +3129,7 @@ rde_update_queue_runner(void) > len = sizeof(queue_buf) - MSGSIZE_HEADER; > do { > sent = 0; > - LIST_FOREACH(peer, , peer_l) { > + RB_FOREACH(peer, peer_tree, ) { > if (peer->conf.id == 0) > continue; > if (peer->state != PEER_UP) > @@ -3189,7 +3187,7 @@ rde_update6_queue_runner(uint8_t aid) > /* first withdraws ... */ > do { > sent = 0; > - LIST_FOREACH(peer, , peer_l) { > + RB_FOREACH(peer, peer_tree, ) { > if (peer->conf.id == 0) >
Re: bgpd switch rde_peer to RB tree
On Thu, Sep 01, 2022 at 12:04:03PM +0200, Claudio Jeker wrote: > Convert the rde_peer hash table to an RB tree. This is a bit more complex > because rde_peer list is used in a lot of places. As a bonus use > peer_foreach in mrt.c to write the table v2 peer header (this needs a > special callback struct because two values need to be passed to the > callback). > > The rest of the code is mostly a simple conversion. Only peer_match > required to be adjusted because the code is now able to use peer_get() > to find the start point. ok tb
Re: bgpd cleanup hash leftovers
On Thu, Sep 01, 2022 at 12:48:32PM +0200, Claudio Jeker wrote: > bgpd no longer needs siphash.h and also remove a hash member and a > prototype which are now unused. ok
Re: bgpd cleanup hash leftovers
ok Claudio Jeker(cje...@diehard.n-r-g.com) on 2022.09.01 12:48:32 +0200: > bgpd no longer needs siphash.h and also remove a hash member and a > prototype which are now unused. > > -- > :wq Claudio > > Index: rde.h > === > RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v > retrieving revision 1.268 > diff -u -p -r1.268 rde.h > --- rde.h 31 Aug 2022 14:29:36 - 1.268 > +++ rde.h 1 Sep 2022 09:55:49 - > @@ -217,7 +217,6 @@ struct rde_aspath { > RB_ENTRY(rde_aspath) entry; > struct attr **others; > struct aspath *aspath; > - uint64_t hash; > int refcnt; > uint32_t flags; /* internally used */ > uint32_t med; /* multi exit disc */ > @@ -434,7 +433,6 @@ intattr_optadd(struct rde_aspath *, u > struct attr *attr_optget(const struct rde_aspath *, uint8_t); > void attr_copy(struct rde_aspath *, const struct rde_aspath *); > int attr_compare(struct rde_aspath *, struct rde_aspath *); > -uint64_t attr_hash(struct rde_aspath *); > void attr_freeall(struct rde_aspath *); > void attr_free(struct rde_aspath *, struct attr *); > #define attr_optlen(x) \ > Index: rde_attr.c > === > RCS file: /cvs/src/usr.sbin/bgpd/rde_attr.c,v > retrieving revision 1.130 > diff -u -p -r1.130 rde_attr.c > --- rde_attr.c31 Aug 2022 14:29:36 - 1.130 > +++ rde_attr.c1 Sep 2022 09:56:55 - > @@ -24,7 +24,6 @@ > #include > #include > #include > -#include > > #include "bgpd.h" > #include "rde.h" > Index: rde_community.c > === > RCS file: /cvs/src/usr.sbin/bgpd/rde_community.c,v > retrieving revision 1.8 > diff -u -p -r1.8 rde_community.c > --- rde_community.c 29 Aug 2022 16:44:47 - 1.8 > +++ rde_community.c 1 Sep 2022 09:56:57 - > @@ -21,7 +21,6 @@ > #include > #include > #include > -#include > > #include "bgpd.h" > #include "rde.h" > Index: rde_rib.c > === > RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v > retrieving revision 1.247 > diff -u -p -r1.247 rde_rib.c > --- rde_rib.c 30 Aug 2022 18:50:21 - 1.247 > +++ rde_rib.c 1 Sep 2022 09:57:02 - > @@ -22,7 +22,6 @@ > #include > #include > #include > -#include > #include > > #include "bgpd.h" > @@ -640,7 +639,7 @@ path_lookup(struct rde_aspath *aspath) > } > > /* > - * Link this aspath into the global hash table. > + * Link this aspath into the global table. > * The asp had to be alloced with path_get. > */ > static void > @@ -679,7 +678,6 @@ struct rde_aspath * > path_copy(struct rde_aspath *dst, const struct rde_aspath *src) > { > dst->aspath = aspath_copy(src->aspath); > - dst->hash = 0; /* not linked so no hash and no refcnt */ > dst->refcnt = 0; > dst->flags = src->flags & ~F_ATTR_LINKED; > > Index: rde_update.c > === > RCS file: /cvs/src/usr.sbin/bgpd/rde_update.c,v > retrieving revision 1.146 > diff -u -p -r1.146 rde_update.c > --- rde_update.c 17 Aug 2022 15:15:26 - 1.146 > +++ rde_update.c 1 Sep 2022 09:57:06 - > @@ -22,7 +22,6 @@ > #include > #include > #include > -#include > #include > > #include "bgpd.h" >
bgpd cleanup hash leftovers
bgpd no longer needs siphash.h and also remove a hash member and a prototype which are now unused. -- :wq Claudio Index: rde.h === RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v retrieving revision 1.268 diff -u -p -r1.268 rde.h --- rde.h 31 Aug 2022 14:29:36 - 1.268 +++ rde.h 1 Sep 2022 09:55:49 - @@ -217,7 +217,6 @@ struct rde_aspath { RB_ENTRY(rde_aspath) entry; struct attr **others; struct aspath *aspath; - uint64_t hash; int refcnt; uint32_t flags; /* internally used */ uint32_t med; /* multi exit disc */ @@ -434,7 +433,6 @@ int attr_optadd(struct rde_aspath *, u struct attr*attr_optget(const struct rde_aspath *, uint8_t); voidattr_copy(struct rde_aspath *, const struct rde_aspath *); int attr_compare(struct rde_aspath *, struct rde_aspath *); -uint64_tattr_hash(struct rde_aspath *); voidattr_freeall(struct rde_aspath *); voidattr_free(struct rde_aspath *, struct attr *); #define attr_optlen(x) \ Index: rde_attr.c === RCS file: /cvs/src/usr.sbin/bgpd/rde_attr.c,v retrieving revision 1.130 diff -u -p -r1.130 rde_attr.c --- rde_attr.c 31 Aug 2022 14:29:36 - 1.130 +++ rde_attr.c 1 Sep 2022 09:56:55 - @@ -24,7 +24,6 @@ #include #include #include -#include #include "bgpd.h" #include "rde.h" Index: rde_community.c === RCS file: /cvs/src/usr.sbin/bgpd/rde_community.c,v retrieving revision 1.8 diff -u -p -r1.8 rde_community.c --- rde_community.c 29 Aug 2022 16:44:47 - 1.8 +++ rde_community.c 1 Sep 2022 09:56:57 - @@ -21,7 +21,6 @@ #include #include #include -#include #include "bgpd.h" #include "rde.h" Index: rde_rib.c === RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v retrieving revision 1.247 diff -u -p -r1.247 rde_rib.c --- rde_rib.c 30 Aug 2022 18:50:21 - 1.247 +++ rde_rib.c 1 Sep 2022 09:57:02 - @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "bgpd.h" @@ -640,7 +639,7 @@ path_lookup(struct rde_aspath *aspath) } /* - * Link this aspath into the global hash table. + * Link this aspath into the global table. * The asp had to be alloced with path_get. */ static void @@ -679,7 +678,6 @@ struct rde_aspath * path_copy(struct rde_aspath *dst, const struct rde_aspath *src) { dst->aspath = aspath_copy(src->aspath); - dst->hash = 0; /* not linked so no hash and no refcnt */ dst->refcnt = 0; dst->flags = src->flags & ~F_ATTR_LINKED; Index: rde_update.c === RCS file: /cvs/src/usr.sbin/bgpd/rde_update.c,v retrieving revision 1.146 diff -u -p -r1.146 rde_update.c --- rde_update.c17 Aug 2022 15:15:26 - 1.146 +++ rde_update.c1 Sep 2022 09:57:06 - @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "bgpd.h"
bgpd switch rde_peer to RB tree
Convert the rde_peer hash table to an RB tree. This is a bit more complex because rde_peer list is used in a lot of places. As a bonus use peer_foreach in mrt.c to write the table v2 peer header (this needs a special callback struct because two values need to be passed to the callback). The rest of the code is mostly a simple conversion. Only peer_match required to be adjusted because the code is now able to use peer_get() to find the start point. -- :wq Claudio Index: mrt.c === RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v retrieving revision 1.109 diff -u -p -r1.109 mrt.c --- mrt.c 17 Aug 2022 15:15:26 - 1.109 +++ mrt.c 1 Sep 2022 00:25:24 - @@ -783,14 +783,33 @@ fail: return (-1); } +struct cb_arg { + struct ibuf *buf; + int nump; +}; + +static void +mrt_dump_v2_hdr_peer(struct rde_peer *peer, void *arg) +{ + struct cb_arg *a = arg; + + if (a->nump == -1) + return; + peer->mrt_idx = a->nump; + if (mrt_dump_peer(a->buf, peer) == -1) { + a->nump = -1; + return; + } + a->nump++; +} + int -mrt_dump_v2_hdr(struct mrt *mrt, struct bgpd_config *conf, -struct rde_peer_head *ph) +mrt_dump_v2_hdr(struct mrt *mrt, struct bgpd_config *conf) { - struct rde_peer *peer; struct ibuf *buf, *hbuf = NULL; size_t len, off; uint16_t nlen, nump; + struct cb_argarg; if ((buf = ibuf_dynamic(0, UINT_MAX)) == NULL) { log_warn("%s: ibuf_dynamic", __func__); @@ -812,14 +831,13 @@ mrt_dump_v2_hdr(struct mrt *mrt, struct log_warn("%s: ibuf_reserve error", __func__); goto fail; } - nump = 0; - LIST_FOREACH(peer, ph, peer_l) { - peer->mrt_idx = nump; - if (mrt_dump_peer(buf, peer) == -1) - goto fail; - nump++; - } - nump = htons(nump); + arg.nump = 0; + arg.buf = buf; + peer_foreach(mrt_dump_v2_hdr_peer, ); + if (arg.nump == -1) + goto fail; + + nump = htons(arg.nump); memcpy(ibuf_seek(buf, off, sizeof(nump)), , sizeof(nump)); len = ibuf_size(buf); Index: rde.c === RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v retrieving revision 1.573 diff -u -p -r1.573 rde.c --- rde.c 31 Aug 2022 15:51:44 - 1.573 +++ rde.c 1 Sep 2022 08:29:31 - @@ -114,8 +114,8 @@ struct rde_memstats rdemem; int softreconfig; static int rde_eval_all; -extern struct rde_peer_head peerlist; -extern struct rde_peer *peerself; +extern struct peer_tree peertable; +extern struct rde_peer *peerself; struct rde_dump_ctx { LIST_ENTRY(rde_dump_ctx)entry; @@ -145,8 +145,6 @@ rde_sighdlr(int sig) } } -uint32_t peerhashsize = 1024; - void rde_main(int debug, int verbose) { @@ -194,7 +192,7 @@ rde_main(int debug, int verbose) /* initialize the RIB structures */ pt_init(); - peer_init(peerhashsize); + peer_init(); /* make sure the default RIBs are setup */ rib_new("Adj-RIB-In", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE); @@ -2982,7 +2980,7 @@ rde_dump_mrt_new(struct mrt *mrt, pid_t } if (ctx->mrt.type == MRT_TABLE_DUMP_V2) - mrt_dump_v2_hdr(>mrt, conf, ); + mrt_dump_v2_hdr(>mrt, conf); if (rib_dump_new(rid, AID_UNSPEC, CTL_MSG_HIGH_MARK, >mrt, mrt_dump_upcall, rde_mrt_done, rde_mrt_throttled) == -1) @@ -3105,7 +3103,7 @@ rde_update_queue_pending(void) if (ibuf_se && ibuf_se->w.queued >= SESS_MSG_HIGH_MARK) return 0; - LIST_FOREACH(peer, , peer_l) { + RB_FOREACH(peer, peer_tree, ) { if (peer->conf.id == 0) continue; if (peer->state != PEER_UP) @@ -3131,7 +3129,7 @@ rde_update_queue_runner(void) len = sizeof(queue_buf) - MSGSIZE_HEADER; do { sent = 0; - LIST_FOREACH(peer, , peer_l) { + RB_FOREACH(peer, peer_tree, ) { if (peer->conf.id == 0) continue; if (peer->state != PEER_UP) @@ -3189,7 +3187,7 @@ rde_update6_queue_runner(uint8_t aid) /* first withdraws ... */ do { sent = 0; - LIST_FOREACH(peer, , peer_l) { + RB_FOREACH(peer, peer_tree, ) { if (peer->conf.id == 0) continue; if (peer->state != PEER_UP) @@ -3214,7 +3212,7 @@ rde_update6_queue_runner(uint8_t aid) max = RDE_RUNNER_ROUNDS / 2; do { sent = 0; -