Re: dig(1): SVCB and HTTPS RR types

2022-07-02 Thread Florian Obser
anyone?

On 2022-06-25 13:15 +02, Florian Obser  wrote:
> See https://datatracker.ietf.org/doc/draft-ietf-dnsop-svcb-https/
>
> $ ./obj/dig @8.8.8.8 +norec _dns.resolver.arpa svcb
>
> ; <<>> dig 9.10.8-P1 <<>> @8.8.8.8 +norec _dns.resolver.arpa svcb
> ; (1 server found)
> ;; global options: +cmd
> ;; Got answer:
> ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21245
> ;; flags: qr aa ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 4
>
> ;; QUESTION SECTION:
> ;_dns.resolver.arpa.IN  SVCB
>
> ;; ANSWER SECTION:
> _dns.resolver.arpa. 86400   IN  SVCB1 dns.google. alpn="dot"
> _dns.resolver.arpa.  86400 IN SVCB 2 dns.google. alpn="h2,h3"
> dohpath="/dns-query{?dns}"
>
> ;; ADDITIONAL SECTION:
> dns.google. 86400   IN  A   8.8.8.8
> dns.google. 86400   IN  A   8.8.4.4
> dns.google. 86400   IN  2001:4860:4860::
> dns.google. 86400   IN  2001:4860:4860::8844
>
> ;; Query time: 11 msec
> ;; SERVER: 8.8.8.8#53(8.8.8.8)
> ;; WHEN: Sat Jun 25 13:08:21 CEST 2022
> ;; MSG SIZE  rcvd: 224
>
> $ ./obj/dig +dnssec cloudflare.com https
>
> ; <<>> dig 9.10.8-P1 <<>> +dnssec cloudflare.com https
> ;; global options: +cmd
> ;; Got answer:
> ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22508
> ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
>
> ;; QUESTION SECTION:
> ;cloudflare.com.IN  HTTPS
>
> ;; ANSWER SECTION:
> cloudflare.com.  217 IN HTTPS 1 . alpn="h3,h3-29,h2"
> ipv4hint=104.16.132.229,104.16.133.229
> ipv6hint=2606:4700::6810:84e5,2606:4700::6810:85e5
> cloudflare.com.  217 IN RRSIG HTTPS 13 2 300 20220626120906
> 20220624100906 34505
> cloudflare.com. PbQwTGVBW2MIXubouK2vUo92UNvlJ874KCrqah/Or21Jo2oDxfgI15jA
> 8z/Q6mseLPWIlTxex+KoIqv9y+FNjg==
>
> ;; Query time: 0 msec
> ;; SERVER: 127.0.0.1#53(127.0.0.1)
> ;; WHEN: Sat Jun 25 13:10:29 CEST 2022
> ;; MSG SIZE  rcvd: 221
>
> OK?

diff --git lib/dns/include/dns/types.h lib/dns/include/dns/types.h
index 63ea8d67f51..7085ce29f2e 100644
--- lib/dns/include/dns/types.h
+++ lib/dns/include/dns/types.h
@@ -139,6 +139,8 @@ enum {
dns_rdatatype_openpgpkey = 61,
dns_rdatatype_csync = 62,
dns_rdatatype_zonemd = 63,
+   dns_rdatatype_svcb = 64,
+   dns_rdatatype_https = 65,
dns_rdatatype_spf = 99,
dns_rdatatype_unspec = 103,
dns_rdatatype_nid = 104,
diff --git lib/dns/rdata.c lib/dns/rdata.c
index c27409efc3c..d731eb3a846 100644
--- lib/dns/rdata.c
+++ lib/dns/rdata.c
@@ -775,6 +775,7 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, 
isc_textregion_t *source) {
{"gpos",27},
{"hinfo",   13},
{"hip", 55},
+   {"https",   65},
{"ipseckey",45},
{"isdn",20},
{"ixfr",251},
@@ -822,6 +823,7 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, 
isc_textregion_t *source) {
{"spf", 99},
{"srv", 33},
{"sshfp",   44},
+   {"svcb",64},
{"ta",  32768},
{"talink",  58},
{"tkey",249},
@@ -1006,6 +1008,10 @@ dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t 
*target) {
return (isc_str_tobuffer("CSYNC", target));
case 63:
return (isc_str_tobuffer("ZONEMD", target));
+   case 64:
+   return (isc_str_tobuffer("SVCB", target));
+   case 65:
+   return (isc_str_tobuffer("HTTPS", target));
case 99:
return (isc_str_tobuffer("SPF", target));
case 100:
diff --git lib/dns/rdata/in_1/https_65.c lib/dns/rdata/in_1/https_65.c
new file mode 100644
index 000..23d80f8d352
--- /dev/null
+++ lib/dns/rdata/in_1/https_65.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022 Florian Obser 
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* draft-ietf-dnsop-svcb-https-10 */
+
+#ifndef RDATA_IN_1_HTTPS_65_C
+#define RDATA_IN_1_HTTPS_65_C
+
+static inline isc_result_t
+totext_in_https(ARGS_TOTEXT) {
+   REQUIRE(rdata->type == dns_rdatatype_https);
+   REQUIRE(rdata->rdclass == 

Re: netstart: create virtual interfaces upfront when passing specific ones

2022-07-02 Thread Klemens Nanni
On Sat, Jul 02, 2022 at 03:00:00PM +0200, Alexander Hall wrote:
> On Thu, Jun 30, 2022 at 03:35:05PM +, Klemens Nanni wrote:
> > On Tue, Dec 07, 2021 at 08:15:41PM +, Klemens Nanni wrote:
> > > On Tue, Nov 23, 2021 at 01:17:14AM +, Klemens Nanni wrote:
> > > > On Tue, Nov 16, 2021 at 11:09:40PM +, Klemens Nanni wrote:
> > > > > Run on boot without arguments, netstart(8) creates all virtual
> > > > > interfaces *for which hostname.if files exist* before configuring 
> > > > > them.
> > > > > 
> > > > > This prevents ordering problems with bridges and its members, as dlg's
> > > > > commit message from 2018 reminds us.
> > > > > 
> > > > > But it also helps interface types like pair(4) which pair one another
> > > > > in whatever way the user says:
> > > > > 
> > > > >   $ cat /etc/hostname.pair1
> > > > >   patch pair2
> > > > >   $ cat /etc/hostname.pair2
> > > > >   rdomain 1
> > > > > 
> > > > > On boot this works, but `sh /etc/netstart pair1 pair2' won't work
> > > > > because pair2 does not exist a creation time of pair1 because netstart
> > > > > does not create virtual interfaces upfront.
> > > > > 
> > > > > I just hit this exact use case when setting up gelatod(8) (see 
> > > > > ports@).
> > > > > 
> > > > > To fix this, pass the list of interfaces to vifscreate() and make it
> > > > > create only those iff given.
> > > > > 
> > > > > Regular boot, i.e. `sh /etc/netstart', stays uneffected by this and
> > > > > selective runs as shown work as expected without requring users to 
> > > > > know
> > > > > the order in which netstart creates/configures interfaces.
> > > > > 
> > > > > The installer's internal version of netstart doesn't need this at all;
> > > > > neither does it have the selective semantic nor does vifscreate() 
> > > > > exist.
> > > > 
> > > > Anyone?
> > > > 
> > > > It seems only logical to treat subsets of interfaces the same way as
> > > > a full `sh /etc/netstart'.
> > > > 
> > > > A pair of pair(4) is one example, I'm certain there are more scenarios
> > > > where you craft interfaces with `ifconfig ...' in the shell, then set up
> > > > the hostname.* files and test them with `sh /etc/netstart bridge0 ...'
> > > > where pseudo interfaces are involved.
> > > 
> > > Anyone?
> > > 
> > > This is really practical and fixes things at least for me when I destroy
> > > interfaces, reconfigure and recreate them together, for example like so:
> > > 
> > >   # ifconfig pair2 destroy
> > >   # ifconfig pair1 destroy
> > >   ... edit hostname.*
> > >   # sh /etc/netstart pair1 pair2
> > >   ifconfig: patch pair2: No such file or directory
> > >   add net default: gateway 192.0.0.1
> > > 
> > > (redoing it because who knows what failed due to the order problem and
> > > what didn't...)
> > > 
> > >   # ifconfig pair2 destroy
> > >   # ifconfig pair1 destroy
> > >   # sh /usr/src/etc/netstart pair1 pair2
> > >   add net default: gateway 192.0.0.1
> > > 
> > > Feedback? Objection? OK?
> > 
> > One last ping with the same diff on top of -CURRENT.
> > 
> > 
> > Index: etc/netstart
> > ===
> > RCS file: /cvs/src/etc/netstart,v
> > retrieving revision 1.218
> > diff -u -p -r1.218 netstart
> > --- etc/netstart26 Jun 2022 09:36:13 -  1.218
> > +++ etc/netstart30 Jun 2022 14:48:46 -
> > @@ -94,9 +94,11 @@ ifcreate() {
> >  }
> >  
> >  # Create interfaces for network pseudo-devices referred to by hostname.if 
> > files.
> > -# Usage: vifscreate
> > +# Optionally, limit creation to given interfaces only.
> > +# Usage: vifscreate [if ...]
> >  vifscreate() {
> > -   local _vif _hn _if
> > +   local _vif _hn _if _ifs
> > +   set -A _ifs -- "$@"
> >  
> > for _vif in $(ifconfig -C); do
> > for _hn in /etc/hostname.${_vif}+([[:digit:]]); do
> > @@ -106,6 +108,9 @@ vifscreate() {
> > # loopback for routing domain is created by kernel
> > [[ -n ${_if##lo[1-9]*} ]] || continue
> >  
> > +   ((${#_ifs[*]} > 0)) && [[ ${_ifs[*]} != *${_if}* ]] &&
> > +   continue
> 
> My gut feeling says this is wrong.
> I suspect `netstart vlan0` will create an0.

Sorry, I don't follow;  how would it chop leading chars?

Maybe you meant that somehow `sh /etc/netstart an0' would attempt
creating an0 since *an0* would match e.g. "lo0 em0 vlan0" or so?

If so, my diff would change nothing in this regard and netstart already
behaves... off for bogus interfaces, with and without my diff:

# echo up > /etc/hostname.vlan0
# echo up > /etc/hostname.an0  
# sh /etc/netstart -n an0 ; echo $?
WARNING: /etc/hostname.an0 is insecure, fixing permissions.
{ ifconfig an0 || ifconfig an0 create; }
ifconfig an0 up
0
# sh /etc/netstart an0 ; echo $?
0

> You could probably do
> 
>   ((${#_ifs[*]} > 0)) && [[ " ${_ifs[*]} " != *" ${_if} "* ]] &&
> 
> but 

Remove leftovers of old poll/select

2022-07-02 Thread Visa Hankala
Remove the leftovers of the old poll/select mechanism.
This includes the fields si_seltid and si_flags in struct selinfo.
They should now always be zero because nothing calls selrecord().

selwakeup() becomes a wrapper for KNOTE(). I do not want to change
it further in this patch. This code can be subtle, as shown by the
socket selwakeup() experiment in May. ;)

The selwakeup() call in bpf_wakeup_cb() can be removed as the kqueue
event filter ignores it.

The patch makes kern.nselcoll sysctl constant. However, is there any
actual need to keep this sysctl? vmstat(1) is the only user of
KERN_NSELCOLL in base. Debian code search does not reveal uses that
would affect ports.

Index: bin/ps/ps.1
===
RCS file: src/bin/ps/ps.1,v
retrieving revision 1.125
diff -u -p -r1.125 ps.1
--- bin/ps/ps.1 31 Mar 2022 17:27:14 -  1.125
+++ bin/ps/ps.1 2 Jul 2022 13:51:19 -
@@ -222,7 +222,6 @@ P_PROFPEND0x2 this thread needs 
 P_ALRMPEND0x4 this thread needs SIGVTALRM
 P_SIGSUSPEND  0x8 need to restore before-suspend mask
 P_CANTSLEEP  0x10 this thread is not permitted to sleep
-P_SELECT 0x40 selecting; wakeup/waiting danger
 P_SINTR  0x80 sleep is interruptible
 P_SYSTEM0x200 system process: no sigs, stats, or
   swapping
Index: sys/dev/wscons/wsdisplay.c
===
RCS file: src/sys/dev/wscons/wsdisplay.c,v
retrieving revision 1.146
diff -u -p -r1.146 wsdisplay.c
--- sys/dev/wscons/wsdisplay.c  2 Jul 2022 08:50:42 -   1.146
+++ sys/dev/wscons/wsdisplay.c  2 Jul 2022 13:51:45 -
@@ -1441,7 +1441,7 @@ wsdisplaystart(struct tty *tp)
splx(s);
return;
}
-   if (tp->t_outq.c_cc == 0 && tp->t_wsel.si_seltid == 0)
+   if (tp->t_outq.c_cc == 0)
goto low;
 
if ((scr = sc->sc_scr[WSDISPLAYSCREEN(tp->t_dev)]) == NULL) {
Index: sys/kern/kern_sysctl.c
===
RCS file: src/sys/kern/kern_sysctl.c,v
retrieving revision 1.402
diff -u -p -r1.402 kern_sysctl.c
--- sys/kern/kern_sysctl.c  21 Mar 2022 09:12:34 -  1.402
+++ sys/kern/kern_sysctl.c  2 Jul 2022 13:51:45 -
@@ -120,7 +120,7 @@
 
 extern struct forkstat forkstat;
 extern struct nchstats nchstats;
-extern int nselcoll, fscale;
+extern int fscale;
 extern fixpt_t ccpu;
 extern long numvnodes;
 extern int allowdt;
@@ -298,7 +298,7 @@ const struct sysctl_bounded_args kern_va
{KERN_NFILES, , SYSCTL_INT_READONLY},
{KERN_TTYCOUNT, _count, SYSCTL_INT_READONLY},
{KERN_ARGMAX, _max, SYSCTL_INT_READONLY},
-   {KERN_NSELCOLL, , SYSCTL_INT_READONLY},
+   {KERN_NSELCOLL, _zero, SYSCTL_INT_READONLY},
{KERN_POSIX1, _version, SYSCTL_INT_READONLY},
{KERN_NGROUPS, _max, SYSCTL_INT_READONLY},
{KERN_JOB_CONTROL, _one, SYSCTL_INT_READONLY},
Index: sys/kern/sys_generic.c
===
RCS file: src/sys/kern/sys_generic.c,v
retrieving revision 1.147
diff -u -p -r1.147 sys_generic.c
--- sys/kern/sys_generic.c  8 Feb 2022 08:56:41 -   1.147
+++ sys/kern/sys_generic.c  2 Jul 2022 13:51:45 -
@@ -89,7 +89,6 @@ int dopselect(struct proc *, int, fd_set
 struct timespec *, const sigset_t *, register_t *);
 int doppoll(struct proc *, struct pollfd *, u_int, struct timespec *,
 const sigset_t *, register_t *);
-void doselwakeup(struct selinfo *);
 
 int
 iovec_copyin(const struct iovec *uiov, struct iovec **iovp, struct iovec *aiov,
@@ -522,8 +521,6 @@ out:
return (error);
 }
 
-intselwait, nselcoll;
-
 /*
  * Select system call.
  */
@@ -840,41 +837,6 @@ pselcollect(struct proc *p, struct keven
return (0);
 }
 
-int
-seltrue(dev_t dev, int events, struct proc *p)
-{
-
-   return (events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
-}
-
-int
-selfalse(dev_t dev, int events, struct proc *p)
-{
-
-   return (0);
-}
-
-/*
- * Record a select request.
- */
-void
-selrecord(struct proc *selector, struct selinfo *sip)
-{
-   struct proc *p;
-   pid_t mytid;
-
-   KERNEL_ASSERT_LOCKED();
-
-   mytid = selector->p_tid;
-   if (sip->si_seltid == mytid)
-   return;
-   if (sip->si_seltid && (p = tfind(sip->si_seltid)) &&
-   p->p_wchan == (caddr_t))
-   sip->si_flags |= SI_COLL;
-   else
-   sip->si_seltid = mytid;
-}
-
 /*
  * Do a wakeup when a selectable event occurs.
  */
@@ -883,34 +845,9 @@ selwakeup(struct selinfo *sip)
 {
KERNEL_LOCK();
KNOTE(>si_note, NOTE_SUBMIT);
-   doselwakeup(sip);
KERNEL_UNLOCK();
 }
 
-void
-doselwakeup(struct selinfo *sip)
-{
-   struct proc *p;
-
-   KERNEL_ASSERT_LOCKED();
-
-   if (sip->si_seltid == 0)
-   return;
-   if (sip->si_flags & 

Re: netstart: create virtual interfaces upfront when passing specific ones

2022-07-02 Thread Alexander Hall
On Thu, Jun 30, 2022 at 03:35:05PM +, Klemens Nanni wrote:
> On Tue, Dec 07, 2021 at 08:15:41PM +, Klemens Nanni wrote:
> > On Tue, Nov 23, 2021 at 01:17:14AM +, Klemens Nanni wrote:
> > > On Tue, Nov 16, 2021 at 11:09:40PM +, Klemens Nanni wrote:
> > > > Run on boot without arguments, netstart(8) creates all virtual
> > > > interfaces *for which hostname.if files exist* before configuring them.
> > > > 
> > > > This prevents ordering problems with bridges and its members, as dlg's
> > > > commit message from 2018 reminds us.
> > > > 
> > > > But it also helps interface types like pair(4) which pair one another
> > > > in whatever way the user says:
> > > > 
> > > > $ cat /etc/hostname.pair1
> > > > patch pair2
> > > > $ cat /etc/hostname.pair2
> > > > rdomain 1
> > > > 
> > > > On boot this works, but `sh /etc/netstart pair1 pair2' won't work
> > > > because pair2 does not exist a creation time of pair1 because netstart
> > > > does not create virtual interfaces upfront.
> > > > 
> > > > I just hit this exact use case when setting up gelatod(8) (see ports@).
> > > > 
> > > > To fix this, pass the list of interfaces to vifscreate() and make it
> > > > create only those iff given.
> > > > 
> > > > Regular boot, i.e. `sh /etc/netstart', stays uneffected by this and
> > > > selective runs as shown work as expected without requring users to know
> > > > the order in which netstart creates/configures interfaces.
> > > > 
> > > > The installer's internal version of netstart doesn't need this at all;
> > > > neither does it have the selective semantic nor does vifscreate() exist.
> > > 
> > > Anyone?
> > > 
> > > It seems only logical to treat subsets of interfaces the same way as
> > > a full `sh /etc/netstart'.
> > > 
> > > A pair of pair(4) is one example, I'm certain there are more scenarios
> > > where you craft interfaces with `ifconfig ...' in the shell, then set up
> > > the hostname.* files and test them with `sh /etc/netstart bridge0 ...'
> > > where pseudo interfaces are involved.
> > 
> > Anyone?
> > 
> > This is really practical and fixes things at least for me when I destroy
> > interfaces, reconfigure and recreate them together, for example like so:
> > 
> > # ifconfig pair2 destroy
> > # ifconfig pair1 destroy
> > ... edit hostname.*
> > # sh /etc/netstart pair1 pair2
> > ifconfig: patch pair2: No such file or directory
> > add net default: gateway 192.0.0.1
> > 
> > (redoing it because who knows what failed due to the order problem and
> > what didn't...)
> > 
> > # ifconfig pair2 destroy
> > # ifconfig pair1 destroy
> > # sh /usr/src/etc/netstart pair1 pair2
> > add net default: gateway 192.0.0.1
> > 
> > Feedback? Objection? OK?
> 
> One last ping with the same diff on top of -CURRENT.
> 
> 
> Index: etc/netstart
> ===
> RCS file: /cvs/src/etc/netstart,v
> retrieving revision 1.218
> diff -u -p -r1.218 netstart
> --- etc/netstart  26 Jun 2022 09:36:13 -  1.218
> +++ etc/netstart  30 Jun 2022 14:48:46 -
> @@ -94,9 +94,11 @@ ifcreate() {
>  }
>  
>  # Create interfaces for network pseudo-devices referred to by hostname.if 
> files.
> -# Usage: vifscreate
> +# Optionally, limit creation to given interfaces only.
> +# Usage: vifscreate [if ...]
>  vifscreate() {
> - local _vif _hn _if
> + local _vif _hn _if _ifs
> + set -A _ifs -- "$@"
>  
>   for _vif in $(ifconfig -C); do
>   for _hn in /etc/hostname.${_vif}+([[:digit:]]); do
> @@ -106,6 +108,9 @@ vifscreate() {
>   # loopback for routing domain is created by kernel
>   [[ -n ${_if##lo[1-9]*} ]] || continue
>  
> + ((${#_ifs[*]} > 0)) && [[ ${_ifs[*]} != *${_if}* ]] &&
> + continue

My gut feeling says this is wrong.
I suspect `netstart vlan0` will create an0.

You could probably do

((${#_ifs[*]} > 0)) && [[ " ${_ifs[*]} " != *" ${_if} "* ]] &&

but then it starts looking even worse. :-P

> +
>   if ! ifcreate $_if; then
>   print -u2 "${0##*/}: create for '$_if' failed."
>   fi
> @@ -314,6 +319,7 @@ $PRINT_ONLY || [[ ! -f /etc/soii.key ]] 
>  # If we were invoked with a list of interface names, just reconfigure these
>  # interfaces (or bridges), add default routes and return.
>  if (($# > 0)); then
> + vifscreate "$@"
>   for _if; do ifstart $_if; done
>   defaultroute
>   return

Would it be a problem just creating all pinpointed interfaces, be they
virtual or not, upfront?

/Alexander

diff --git a/etc/netstart b/etc/netstart
index 33e9689a819..62ca64803d8 100644
--- a/etc/netstart
+++ b/etc/netstart
@@ -314,6 +314,7 @@ $PRINT_ONLY || [[ ! -f /etc/soii.key ]] ||
 # If we were invoked with a list of interface names, just reconfigure these
 # interfaces (or bridges), 

Re: a few fixes for cat bugs

2022-07-02 Thread Otto Moerbeek
On Sat, Jul 02, 2022 at 08:38:53AM +0100, Leah Rowe wrote:

> 
> Hi Otto,
> 
> > Your fixes are not ok. See comment inline.
> 
> The other person (Theo) who responded, raised the same concerns as you.
> Sorry for wasting your time. I've reverted the patches myself, locally,
> knowing now that I made a few false assumptions.
> 
> I actually overlooked that the buf variable was static. I'm now of the
> opinion that OpenBSD's cat implementation is already perfect, and not
> in need of new changes.

It never hurts going back to code and reread it. To improve you code
reviewing skills, I suggest you keep doing it, but be critical of your
findings. You'll get better with more experience. Often code reading
skills are not valued high enough as opposed to code writing skills,
while the former is often more important than the latter, as anybody
doing maintenance of a large body of code will tell you.

-Otto



Re: em(4) multiqueue

2022-07-02 Thread David Gwynne



> On 2 Jul 2022, at 08:44, Hrvoje Popovski  wrote:
> 
> On 28.6.2022. 15:11, Jonathan Matthew wrote:
>> This adds the (not quite) final bits to em(4) to enable multiple rx/tx 
>> queues.
>> Note that desktop/laptop models (I218, I219 etc.) do not support multiple 
>> queues,
>> so this only really applies to servers and network appliances (including 
>> APU2).
>> 
>> It also removes the 'em_enable_msix' variable, in favour of using MSI-X on 
>> devices
>> that support multiple queues and MSI or INTX everywhere else.
>> 
>> I've tested this with an I350 on amd64 and arm64, where it works as 
>> expected, and
>> with the I218-LM in my laptop where it does nothing (as expected).
>> More testing is welcome, especially in forwarding environments.
> 
> 
> Hi,
> 
> I'm testing this diff in forwarding setup where source is 10.113.0/24
> connected to em2 and destination is 10.114.0/24 connected to em3. I'm
> doing random source and destination per ip.
> 
> dmesg:
> em2 at pci6 dev 0 function 2 "Intel I350" rev 0x01, msix, 8 queues
> em3 at pci6 dev 0 function 3 "Intel I350" rev 0x01, msix, 8 queues
> 
> netstat:
> 10.113.0/24192.168.113.11 UGS00 - 8 em2
> 10.114.0/24192.168.114.11 UGS0 404056853 - 8 em3
> 
> 
> ifconfig:
> em2: flags=8843 mtu 1500
>lladdr 40:f2:e9:ec:b4:14
>index 5 priority 0 llprio 3
>media: Ethernet autoselect (1000baseT full-duplex,master)
>status: active
>inet 192.168.113.1 netmask 0xff00 broadcast 192.168.113.255
> em3: flags=8843 mtu 1500
>lladdr 40:f2:e9:ec:b4:15
>index 6 priority 0 llprio 3
>media: Ethernet autoselect (1000baseT full-duplex,rxpause,txpause)
>status: active
>inet 192.168.114.1 netmask 0xff00 broadcast 192.168.114.255
> 
> 
> with vmstat -i
> irq160/em2:0  4740972 3538
> irq161/em2:1  4740979 3538
> irq162/em2:2  4740977 3538
> irq163/em2:3  4740978 3538
> irq164/em2:4  4740965 3538
> irq165/em2:5  4740972 3538
> irq166/em2:6  4740971 3538
> irq167/em2:7  4740965 3538
> irq168/em2  20
> irq169/em3:0  4741258 3538
> irq177/em3  20
> 
> 
> should I see 8 queues on em3 as on em2 ?

em(4) isn't populating the mbuf flowid field with the rss hash value the chip 
calculates when it receives packets, so there's no flow identifier for the 
network stack to use to assign packets to output queues on the way out. this 
means everything lands on the default (0th) queue.

cheers,
dlg


> 
> x3550m4# tcpdump -ni em3
> tcpdump: listening on em3, link-type EN10MB
> 00:39:26.663617 10.113.0.230.9 > 10.114.0.154.9: udp 18
> 00:39:26.663618 10.113.0.176.9 > 10.114.0.3.9: udp 18
> 00:39:26.663619 10.113.0.37.9 > 10.114.0.7.9: udp 18
> 00:39:26.663620 10.113.0.200.9 > 10.114.0.197.9: udp 18
> 00:39:26.663620 10.113.0.37.9 > 10.114.0.230.9: udp 18
> 00:39:26.663621 10.113.0.95.9 > 10.114.0.216.9: udp 18
> 00:39:26.663622 10.113.0.8.9 > 10.114.0.187.9: udp 18
> 00:39:26.663623 10.113.0.56.9 > 10.114.0.107.9: udp 18
> 00:39:26.663624 10.113.0.4.9 > 10.114.0.39.9: udp 18
> 00:39:26.663624 10.113.0.244.9 > 10.114.0.188.9: udp 18
> 00:39:26.663625 10.113.0.166.9 > 10.114.0.15.9: udp 18
> 00:39:26.663626 10.113.0.7.9 > 10.114.0.78.9: udp 18
> 00:39:26.663627 10.113.0.147.9 > 10.114.0.202.9: udp 18
> 00:39:26.663628 10.113.0.144.9 > 10.114.0.184.9: udp 18
> 00:39:26.663628 10.113.0.221.9 > 10.114.0.100.9: udp 18
> 00:39:26.663630 10.113.0.69.9 > 10.114.0.231.9: udp 18
> 00:39:26.663648 10.113.0.71.9 > 10.114.0.64.9: udp 18
> 
> 
> vmstat -iz
> irq160/em2:0  4740972 3501
> irq161/em2:1  4740979 3501
> irq162/em2:2  4740977 3501
> irq163/em2:3  4740978 3501
> irq164/em2:4  4740965 3501
> irq165/em2:5  4740972 3501
> irq166/em2:6  4740971 3501
> irq167/em2:7  4740965 3501
> irq168/em2  20
> irq169/em3:0  4741258 3501
> irq170/em3:100
> irq171/em3:200
> irq172/em3:300
> irq173/em3:400
> irq174/em3:500
> irq175/em3:600
> irq176/em3:700
> irq177/em3  20
> 



make timeout(1) -s behave like kill(1) -s and GNU timeout(1) -s

2022-07-02 Thread Klemens Nanni
timeout.c's parse_signal() basically does what kill.c's signame_to_num()
does, except it expects "SIG" in string signals.

Borrow the isalpha() check from kill.c to get the same behaviour:

$ time ./obj/timeout -s kill 1 sleep 3
Killed 
0m01.01s real 0m00.00s user 0m00.01s system
$ time timeout -s kill 1 sleep 3  
timeout: signal kill invalid
0m00.00s real 0m00.00s user 0m00.00s system

Feedback? OK?

Index: timeout.c
===
RCS file: /cvs/src/usr.bin/timeout/timeout.c,v
retrieving revision 1.20
diff -u -p -r1.20 timeout.c
--- timeout.c   12 Jan 2022 22:51:44 -  1.20
+++ timeout.c   2 Jul 2022 07:13:45 -
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -104,10 +105,11 @@ parse_signal(const char *str)
long longsig;
const char  *errstr;
 
-   if (strncasecmp(str, "SIG", 3) == 0) {
+   if (isalpha((unsigned char)*str)) {
int i;
 
-   str += 3;
+   if (strncasecmp(str, "SIG", 3) == 0)
+   str += 3;
for (i = 1; i < NSIG; i++) {
if (strcasecmp(str, sys_signame[i]) == 0)
return (i);



Re: a few fixes for cat bugs

2022-07-02 Thread Otto Moerbeek
On Sat, Jul 02, 2022 at 03:15:21AM +0100, Leah Rowe wrote:

> 
> Hi,
> 
> I've been playing around with a few OpenBSD userland programs. By that,
> I mean I've been studying them extensively. I'm working on creating a
> busybox-like userland for Linux with musl libc, and I need quality code
> so I decided I'd start ripping code out of OpenBSD for this purpose.
> 
> I spent today obsessing over your cat implementation. As part of my
> optimization efforts (I've been removing non-POSIX features, because I
> need the code to be as small as possible), I found several minor issues
> in cat:
> 
> 1) Unitialized variables that are assumed to be zero, judging by the
> logic in the code that uses them.
> 
> 2) Memory leak; in practise, most people will run can on a few files
> and it won't take more than a few moments, then cat terminates and the
> memory is freed
> 
> 3) Unnecessary check in raw_cat on a variable being NULL, when it will
> always evaluate true because it's explicitly already initialized to null
> 
> I fixed all of these, in the attached patches which I present for your
> enjoyment. I've done these on top of your github mirror, on top of
> commit 88e033f9985d9aec739c4497f51fb9348247d4db of the main OpenBSD git
> repository (I don't know how to use CVS, I've never used it, sorry! I
> got into programming in the late 2000s right when git was made lol)

Your fixes are not ok. See comment inline.

-Otto

> -- 
> Leah Rowe,
> Company Director
> 
> Minifree Ltd, trading as Ministry of Freedom.
> Registered in England, registration No. 9361826
> VAT Registration No. GB202190462
> Minifree Ltd, 19 Hilton Road, Canvey Island
> Essex SS8 9QA, United Kingdom
> United Kingdom

> From 63163120b6881f9d8ea2b03f722cd31e946f5704 Mon Sep 17 00:00:00 2001
> From: Leah Rowe 
> Date: Sat, 2 Jul 2022 02:27:51 +0100
> Subject: [PATCH 1/3] cat: fix uninitialized variables
> 
> ---
>  bin/cat/cat.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/bin/cat/cat.c b/bin/cat/cat.c
> index a2eff2e1b30..42960812ead 100644
> --- a/bin/cat/cat.c
> +++ b/bin/cat/cat.c
> @@ -62,6 +62,8 @@ main(int argc, char *argv[])
>   if (pledge("stdio rpath", NULL) == -1)
>   err(1, "pledge");
>  
> + rval = bflag = eflag = nflag = sflag = tflag = vflag = 0;
> +

These are globals, which are initialized to zero by the runtime before
main() is called.

>   while ((ch = getopt(argc, argv, "benstuv")) != -1) {
>   switch (ch) {
>   case 'b':
> @@ -210,7 +212,7 @@ void
>  raw_cat(int rfd, const char *filename)
>  {
>   int wfd;
> - ssize_t nr, nw, off;
> + ssize_t nr, off, nw = 0;

nw is initialized by the code below (with the return value of write())
before being used.

>   static size_t bsize;
>   static char *buf = NULL;
>   struct stat sbuf;
> -- 
> 2.25.1
> 

> From e36d05353d66cb42d33f9b5d5eb3e4dc44175e39 Mon Sep 17 00:00:00 2001
> From: Leah Rowe 
> Date: Sat, 2 Jul 2022 02:28:33 +0100
> Subject: [PATCH 2/3] cat: fix memory leak
> 
> ---
>  bin/cat/cat.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/bin/cat/cat.c b/bin/cat/cat.c
> index 42960812ead..dad337d5f68 100644
> --- a/bin/cat/cat.c
> +++ b/bin/cat/cat.c
> @@ -235,4 +235,5 @@ raw_cat(int rfd, const char *filename)
>   warn("%s", filename);
>   rval = 1;
>   }
> + free(buf);
>  }
> -- 
> 2.25.1
> 

> From b4e0ef740724523ed3752c6f5b82741d1acc5230 Mon Sep 17 00:00:00 2001
> From: Leah Rowe 
> Date: Sat, 2 Jul 2022 02:29:20 +0100
> Subject: [PATCH 3/3] cat: remove unnecessary check
> 
> ---
>  bin/cat/cat.c | 13 ++---
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/bin/cat/cat.c b/bin/cat/cat.c
> index dad337d5f68..97edcad2101 100644
> --- a/bin/cat/cat.c
> +++ b/bin/cat/cat.c
> @@ -218,13 +218,12 @@ raw_cat(int rfd, const char *filename)
>   struct stat sbuf;
>  
>   wfd = fileno(stdout);
> - if (buf == NULL) {
> - if (fstat(wfd, ) == -1)
> - err(1, "stdout");
> - bsize = MAXIMUM(sbuf.st_blksize, BUFSIZ);
> - if ((buf = malloc(bsize)) == NULL)
> - err(1, NULL);
> - }

You don't seem to understand how static vars work. The idea is that
that raw cat re-uses the buffer as buf is a static. No need to free
it, after process exit the memory will be cleaned up.


> + if (fstat(wfd, ) == -1)
> + err(1, "stdout");
> + bsize = MAXIMUM(sbuf.st_blksize, BUFSIZ);
> + if ((buf = malloc(bsize)) == NULL)
> + err(1, NULL);
> +
>   while ((nr = read(rfd, buf, bsize)) != -1 && nr != 0) {
>   for (off = 0; nr; nr -= nw, off += nw) {
>   if ((nw = write(wfd, buf + off, nr)) == -1 || nw == 0)
> -- 
> 2.25.1
>