Print learned DNS from sppp(4) in ifconfig(8)

2021-11-16 Thread Bjorn Ketelaars
Like umb(4), sppp(4) natively learns DNS information. Among the
differences between these two devices is that umb prints this
information from ifconfig(8) and sppp does not. I would like to equalize
this behaviour, and add the necessary bits to sppp(4) and ifconfig(8).

Diff below is largely based on a diff from Peter J. Philipp [0].

Comments/OK?

[0] https://marc.info/?l=openbsd-tech=159405677416423=2


diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index e02c0550b4f..976cc9a0241 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -718,6 +718,7 @@ u_int   getwpacipher(const char *);
 void   print_cipherset(u_int32_t);
 
 void   spppauthinfo(struct sauthreq *, int);
+void   spppdnsinfo(struct sdnsreq *);
 
 /* Known address families */
 const struct afswtch {
@@ -5454,6 +5455,17 @@ spppauthinfo(struct sauthreq *spa, int d)
err(1, "SIOCGSARAMS(SPPPIOGXAUTH)");
 }
 
+void
+spppdnsinfo(struct sdnsreq *spd)
+{
+   memset(spd, 0, sizeof(*spd));
+
+   ifr.ifr_data = (caddr_t)spd;
+   spd->cmd = SPPPIOGDNS;
+   if (ioctl(sock, SIOCGSARAMS, ) == -1)
+   err(1, "SIOCGSARAMS(SPPPIOGDNS)");
+}
+
 void
 setsroto(const char *val, int d)
 {
@@ -5588,6 +5600,9 @@ sppp_status(void)
 {
struct spppreq spr;
struct sauthreq spa;
+   struct sdnsreq spd;
+   char astr[INET_ADDRSTRLEN];
+   int i, n;
 
bzero(, sizeof(spr));
 
@@ -5627,6 +5642,16 @@ sppp_status(void)
if (spa.flags & AUTHFLAG_NORECHALLENGE)
printf("norechallenge ");
putchar('\n');
+
+   spppdnsinfo();
+   for (i = 0, n = 0; i < IPCP_MAX_DNSSRV; i++) {
+   if (spd.dns[i].s_addr == INADDR_ANY)
+   break;
+   printf("%s %s", n++ ? "" : "\tdns:",
+   inet_ntop(AF_INET, [i], astr, sizeof(astr)));
+   }
+   if (n)
+   printf("\n");
 }
 
 void
diff --git sys/net/if_sppp.h sys/net/if_sppp.h
index 6b5e7d41a4a..af11526ee0a 100644
--- sys/net/if_sppp.h
+++ sys/net/if_sppp.h
@@ -82,12 +82,21 @@ struct spppreq {
enum ppp_phase phase;   /* phase we're currently in */
 };
 
+#include 
+
+#define IPCP_MAX_DNSSRV2
+struct sdnsreq {
+   int cmd;
+   struct in_addr dns[IPCP_MAX_DNSSRV];
+};
+
 #define SPPPIOGDEFS  ((int)(('S' << 24) + (1 << 16) + sizeof(struct spppreq)))
 #define SPPPIOSDEFS  ((int)(('S' << 24) + (2 << 16) + sizeof(struct spppreq)))
 #define SPPPIOGMAUTH ((int)(('S' << 24) + (3 << 16) + sizeof(struct sauthreq)))
 #define SPPPIOSMAUTH ((int)(('S' << 24) + (4 << 16) + sizeof(struct sauthreq)))
 #define SPPPIOGHAUTH ((int)(('S' << 24) + (5 << 16) + sizeof(struct sauthreq)))
 #define SPPPIOSHAUTH ((int)(('S' << 24) + (6 << 16) + sizeof(struct sauthreq)))
+#define SPPPIOGDNS   ((int)(('S' << 24) + (7 << 16) + sizeof(struct sdnsreq)))
 
 
 #ifdef _KERNEL
@@ -96,7 +105,6 @@ struct spppreq {
 #include 
 
 #ifdef INET6
-#include 
 #include 
 #endif
 
@@ -132,7 +140,6 @@ struct sipcp {
  * original one here, in network byte order */
u_int32_t req_hisaddr;  /* remote address requested (IPv4) */
u_int32_t req_myaddr;   /* local address requested (IPv4) */
-#define IPCP_MAX_DNSSRV2
struct in_addr dns[IPCP_MAX_DNSSRV]; /* IPv4 DNS servers (RFC 1877) */
 #ifdef INET6
struct in6_aliasreq req_ifid;   /* local ifid requested (IPv6) */
diff --git sys/net/if_spppsubr.c sys/net/if_spppsubr.c
index 759370e7be7..37be7ccd722 100644
--- sys/net/if_spppsubr.c
+++ sys/net/if_spppsubr.c
@@ -4561,6 +4561,23 @@ sppp_get_params(struct sppp *sp, struct ifreq *ifr)
free(spa, M_DEVBUF, sizeof(*spa));
break;
}
+   case SPPPIOGDNS:
+   {
+   struct sdnsreq *spd;
+
+   spd = malloc(sizeof(*spd), M_DEVBUF, M_WAITOK);
+
+   spd->cmd = cmd;
+   memcpy(spd->dns, sp->ipcp.dns, sizeof(spd->dns));
+
+   if (copyout(spd, (caddr_t)ifr->ifr_data, sizeof(*spd)) != 0) {
+   free(spd, M_DEVBUF, 0);
+   return EFAULT;
+   }
+
+   free(spd, M_DEVBUF, sizeof(*spd));
+   break;
+   }
default:
return EINVAL;
}



uhidev: missing claim multiple report ids

2021-11-16 Thread Anton Lindqvist
Hi,
Here are the last drivers missing a claim multiple report ids
conditional. None of them currently claims more than one report id.
With this is place, the old problematic approach of signalling
that multiple report ids should be claimed to the match routines using
__UHIDEV_CLAIM_MULTIPLE_REPORTID can be removed.

Comments? OK?

Index: sys/dev/usb/ukbd.c
===
RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.84
diff -u -p -r1.84 ukbd.c
--- sys/dev/usb/ukbd.c  12 Sep 2021 06:58:08 -  1.84
+++ sys/dev/usb/ukbd.c  17 Nov 2021 06:23:28 -
@@ -201,6 +201,9 @@ ukbd_match(struct device *parent, void *
int size;
void *desc;
 
+   if (UHIDEV_CLAIM_MULTIPLE_REPORTID(uha))
+   return (UMATCH_NONE);
+
uhidev_get_report_desc(uha->parent, , );
if (!hid_is_collection(desc, size, uha->reportid,
HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_KEYBOARD)))
Index: sys/dev/usb/ums.c
===
RCS file: /cvs/src/sys/dev/usb/ums.c,v
retrieving revision 1.50
diff -u -p -r1.50 ums.c
--- sys/dev/usb/ums.c   12 Sep 2021 06:58:08 -  1.50
+++ sys/dev/usb/ums.c   17 Nov 2021 06:23:28 -
@@ -93,6 +93,9 @@ ums_match(struct device *parent, void *m
int size;
void *desc;
 
+   if (UHIDEV_CLAIM_MULTIPLE_REPORTID(uha))
+   return (UMATCH_NONE);
+
uhidev_get_report_desc(uha->parent, , );
 
if (hid_is_collection(desc, size, uha->reportid,
Index: sys/dev/usb/umstc.c
===
RCS file: /cvs/src/sys/dev/usb/umstc.c,v
retrieving revision 1.6
diff -u -p -r1.6 umstc.c
--- sys/dev/usb/umstc.c 12 Sep 2021 06:58:08 -  1.6
+++ sys/dev/usb/umstc.c 17 Nov 2021 06:23:28 -
@@ -80,6 +80,9 @@ umstc_match(struct device *parent, void 
int size;
void *desc;
 
+   if (UHIDEV_CLAIM_MULTIPLE_REPORTID(uha))
+   return (UMATCH_NONE);
+
if (!usb_lookup(umstc_devs, uha->uaa->vendor, uha->uaa->product))
return UMATCH_NONE;
 
Index: sys/dev/usb/utpms.c
===
RCS file: /cvs/src/sys/dev/usb/utpms.c,v
retrieving revision 1.11
diff -u -p -r1.11 utpms.c
--- sys/dev/usb/utpms.c 23 Oct 2020 21:23:58 -  1.11
+++ sys/dev/usb/utpms.c 17 Nov 2021 06:23:28 -
@@ -269,6 +269,9 @@ utpms_match(struct device *parent, void 
usb_interface_descriptor_t *id;
int i;
 
+   if (UHIDEV_CLAIM_MULTIPLE_REPORTID(uha))
+   return (UMATCH_NONE);
+
id = usbd_get_interface_descriptor(uha->uaa->iface);
if (id == NULL ||
id->bInterfaceSubClass != UISUBCLASS_BOOT ||
Index: sys/dev/usb/uwacom.c
===
RCS file: /cvs/src/sys/dev/usb/uwacom.c,v
retrieving revision 1.4
diff -u -p -r1.4 uwacom.c
--- sys/dev/usb/uwacom.c12 Sep 2021 06:58:08 -  1.4
+++ sys/dev/usb/uwacom.c17 Nov 2021 06:23:28 -
@@ -75,6 +75,9 @@ uwacom_match(struct device *parent, void
int size;
void *desc;
 
+   if (UHIDEV_CLAIM_MULTIPLE_REPORTID(uha))
+   return (UMATCH_NONE);
+
if (usb_lookup(uwacom_devs, uha->uaa->vendor,
uha->uaa->product) == NULL)
return (UMATCH_NONE);



Re: fix for X crash with the radeon(4) driver

2021-11-16 Thread Matthieu Herrb
On Sun, Nov 14, 2021 at 05:25:32PM +0100, Matthieu Herrb wrote:
> Hi,
> 
> after the upgrade to X server 21.1.1, some people reported crashes in
> the radeon driver when using xrandr(1) or a similar utility.
> 
> If you are seeing these crashes, please test the patch below (copied
> for a similar "fix" in the amdgpu(4) driver)
> 
> get the xenocara sources if you don't alreaady, apply the patch in the
> driver/xf86-video-ati directory and there run (as root)
> 
> make -f Makefile.bsd-wrapper obj
> make -f Makefile.bsd-wrapper build
> 
> Then restart xenodm and try the xrandr invocation again.
> 
> Please report success or failure.

Ping. .

Anyone tried this patch ?

This is not the bug that happens semi-randomly on mouse button events,
but still, if you have a Radeon card and are using xrandr(1) to setup
multiple monitors, you're likely to hit that bug

> 
> Index: src/radeon_kms.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/driver/xf86-video-ati/src/radeon_kms.c,v
> retrieving revision 1.21
> diff -u -p -u -r1.21 radeon_kms.c
> --- src/radeon_kms.c  11 Nov 2021 09:30:14 -  1.21
> +++ src/radeon_kms.c  14 Nov 2021 16:16:08 -
> @@ -931,6 +931,13 @@ radeon_dirty_update(ScrnInfoPtr scrn)
>   }
>  }
>  
> +static void
> +radeonSourceValidate(DrawablePtr draw, int x, int y, int w, int h,
> +  unsigned int subWindowMode)
> +{
> +}
> +
> +
>  
>  Bool
>  radeon_scanout_do_update(xf86CrtcPtr xf86_crtc, int scanout_id,
> @@ -993,7 +1000,7 @@ radeon_scanout_do_update(xf86CrtcPtr xf8
>   SetPicturePictFilter(src, xf86_crtc->filter, xf86_crtc->params,
>xf86_crtc->nparams);
>  
> - pScreen->SourceValidate = NULL;
> + pScreen->SourceValidate = radeonSourceValidate;
>   CompositePicture(PictOpSrc,
>src, NULL, dst,
>extents.x1, extents.y1, 0, 0, extents.x1,
> 
> 
> -- 
> Matthieu Herrb

-- 
Matthieu Herrb



Re: ssh/sshd change in snaps

2021-11-16 Thread Damien Miller
On Wed, 17 Nov 2021, Damien Miller wrote:

> On Tue, 16 Nov 2021, Damien Miller wrote:
> 
> > Another couple of fixes in tomorrow's snaps. One to avoid errors like:
> > 
> > > channel 3: chan_read_failed for istate 3
> > 
> > Another avoids a situation where sshd could get stuck spinning on poll()
> > if it fails.
> > 
> > (Both uncovered by web browsing through a SOCKS dynamic forwarder)
> 
> BTW I have uploaded the diff for this change to github in case anyone
> is curious:
> 
> https://patch-diff.githubusercontent.com/raw/djmdjm/openssh-wip/pull/6

sorry, bad link. Correct one is:

https://github.com/djmdjm/openssh-wip/pull/6.diff
https://github.com/djmdjm/openssh-wip/pull/6



Re: ssh/sshd change in snaps

2021-11-16 Thread Damien Miller
On Tue, 16 Nov 2021, Damien Miller wrote:

> Another couple of fixes in tomorrow's snaps. One to avoid errors like:
> 
> > channel 3: chan_read_failed for istate 3
> 
> Another avoids a situation where sshd could get stuck spinning on poll()
> if it fails.
> 
> (Both uncovered by web browsing through a SOCKS dynamic forwarder)

BTW I have uploaded the diff for this change to github in case anyone
is curious:

https://patch-diff.githubusercontent.com/raw/djmdjm/openssh-wip/pull/6

or in patch(1) format:

https://patch-diff.githubusercontent.com/raw/djmdjm/openssh-wip/pull/6.diff



Re: make 'set skip on ...' dynamic

2021-11-16 Thread Alexandr Nedvedicky
Hello,

I've sent older version of diff. The new version contains
a minor tweak to pfi_set_flags() to make it more defensive:

+   if (name[n-1] >= '0' && name[n-1] <= '9') {
+   p = pfi_kif_get(name, NULL);
+   if (p != NULL) {
+   p->pfik_flags_new = p->pfik_flags | flags;
+   pfi_kif_ref(p, PFI_KIF_REF_FLAG);
+   if (p->pfik_flags_new == p->pfik_flags)
+   pfi_kif_unref(p, PFI_KIF_REF_FLAG);

older version did not dropped/destroyed pfi_kif obtained from pfi_kif_get()
when flags were actually same.

thanks and
regards
sashan

On Wed, Nov 17, 2021 at 03:07:04AM +0100, Alexandr Nedvedicky wrote:
> Hello,
> 
> back in Gouveia claudio@ complained 'set skip on ...' requires reloading
> pf.conf, when new interface appears. Diff below should fix that.
> 
> the idea is to introduce yet another reference type (PFI_KIF_REF_FLAG) pfi_kif
> objects. PFI_KIF_REF_FLAG type keeps pfi_kif object in pf's interface table,
> when there is no other reference to interface/group than 'set skip ...'
> statement itself.  The PFI_KIF_REF_FLAG is grabbed/dropped if and only if the
> interface flag is being changed.
> 
> OK?
> 
> thanks and
> regards
> sashan
> 

8<---8<---8<--8<
diff --git a/share/man/man5/pf.conf.5 b/share/man/man5/pf.conf.5
index bff448aa8dc..4afe841651f 100644
--- a/share/man/man5/pf.conf.5
+++ b/share/man/man5/pf.conf.5
@@ -1383,9 +1383,6 @@ Packets passing in or out on such interfaces are passed 
as if pf was
 disabled, i.e. pf does not process them in any way.
 This can be useful on loopback and other virtual interfaces, when
 packet filtering is not desired and can have unexpected effects.
-.Ar ifspec
-is only evaluated when the ruleset is loaded; interfaces created
-later will not be skipped.
 PF filters traffic on all interfaces by default.
 .It Ic set Cm state-defaults Ar state-option , ...
 The
diff --git a/sys/net/pf_if.c b/sys/net/pf_if.c
index 8de37375ab4..d241717ee7e 100644
--- a/sys/net/pf_if.c
+++ b/sys/net/pf_if.c
@@ -187,6 +187,9 @@ pfi_kif_ref(struct pfi_kif *kif, enum pfi_kif_refs what)
case PFI_KIF_REF_SRCNODE:
kif->pfik_srcnodes++;
break;
+   case PFI_KIF_REF_FLAG:
+   kif->pfik_flagrefs++;
+   break;
default:
panic("pfi_kif_ref with unknown type");
}
@@ -233,15 +236,23 @@ pfi_kif_unref(struct pfi_kif *kif, enum pfi_kif_refs what)
}
kif->pfik_srcnodes--;
break;
+   case PFI_KIF_REF_FLAG:
+   if (kif->pfik_flagrefs <= 0) {
+   DPFPRINTF(LOG_ERR,
+   "pfi_kif_unref: flags refcount <= 0");
+   return;
+   }
+   kif->pfik_flagrefs--;
+   break;
default:
panic("pfi_kif_unref with unknown type");
}
 
-   if (kif->pfik_ifp != NULL || kif->pfik_group != NULL || kif == pfi_all)
+   if (kif->pfik_ifp != NULL || kif->pfik_group != NULL ||kif == pfi_all)
return;
 
if (kif->pfik_rules || kif->pfik_states || kif->pfik_routes ||
-   kif->pfik_srcnodes)
+   kif->pfik_srcnodes || kif->pfik_flagrefs)
return;
 
RB_REMOVE(pfi_ifhead, _ifs, kif);
@@ -786,24 +797,53 @@ int
 pfi_set_flags(const char *name, int flags)
 {
struct pfi_kif  *p;
+   size_t n;
 
-   RB_FOREACH(p, pfi_ifhead, _ifs) {
-   if (pfi_skip_if(name, p))
-   continue;
-   p->pfik_flags_new = p->pfik_flags | flags;
+   if (name == NULL)
+   return (0);
+
+   n = strlen(name);
+   if ((n < 1) || (n >= IFNAMSIZ))
+   return (0);
+
+   if (name[n-1] >= '0' && name[n-1] <= '9') {
+   p = pfi_kif_get(name, NULL);
+   if (p != NULL) {
+   p->pfik_flags_new = p->pfik_flags | flags;
+   pfi_kif_ref(p, PFI_KIF_REF_FLAG);
+   if (p->pfik_flags_new == p->pfik_flags)
+   pfi_kif_unref(p, PFI_KIF_REF_FLAG);
+   }
+   } else {
+   p = pfi_kif_get(name, NULL);
+   if (p != NULL) {
+   p->pfik_flags_new = p->pfik_flags | flags;
+   pfi_kif_ref(p, PFI_KIF_REF_FLAG);
+   if (p->pfik_flags_new == p->pfik_flags)
+   pfi_kif_unref(p, PFI_KIF_REF_FLAG);
+   }
+
+   RB_FOREACH(p, pfi_ifhead, _ifs) {
+   if (pfi_skip_if(name, p))
+   continue;
+   p->pfik_flags_new = p->pfik_flags | flags;
+   }
}
+
return (0);
 }
 
 int
 pfi_clear_flags(const char *name, int flags)
 {
-   struct 

make 'set skip on ...' dynamic

2021-11-16 Thread Alexandr Nedvedicky
Hello,

back in Gouveia claudio@ complained 'set skip on ...' requires reloading
pf.conf, when new interface appears. Diff below should fix that.

the idea is to introduce yet another reference type (PFI_KIF_REF_FLAG) pfi_kif
objects. PFI_KIF_REF_FLAG type keeps pfi_kif object in pf's interface table,
when there is no other reference to interface/group than 'set skip ...'
statement itself.  The PFI_KIF_REF_FLAG is grabbed/dropped if and only if the
interface flag is being changed.

OK?

thanks and
regards
sashan

8<---8<---8<--8<
diff --git a/share/man/man5/pf.conf.5 b/share/man/man5/pf.conf.5
index bff448aa8dc..4afe841651f 100644
--- a/share/man/man5/pf.conf.5
+++ b/share/man/man5/pf.conf.5
@@ -1383,9 +1383,6 @@ Packets passing in or out on such interfaces are passed 
as if pf was
 disabled, i.e. pf does not process them in any way.
 This can be useful on loopback and other virtual interfaces, when
 packet filtering is not desired and can have unexpected effects.
-.Ar ifspec
-is only evaluated when the ruleset is loaded; interfaces created
-later will not be skipped.
 PF filters traffic on all interfaces by default.
 .It Ic set Cm state-defaults Ar state-option , ...
 The
diff --git a/sys/net/pf_if.c b/sys/net/pf_if.c
index 8de37375ab4..e91ba692a57 100644
--- a/sys/net/pf_if.c
+++ b/sys/net/pf_if.c
@@ -187,6 +187,9 @@ pfi_kif_ref(struct pfi_kif *kif, enum pfi_kif_refs what)
case PFI_KIF_REF_SRCNODE:
kif->pfik_srcnodes++;
break;
+   case PFI_KIF_REF_FLAG:
+   kif->pfik_flagrefs++;
+   break;
default:
panic("pfi_kif_ref with unknown type");
}
@@ -233,15 +236,23 @@ pfi_kif_unref(struct pfi_kif *kif, enum pfi_kif_refs what)
}
kif->pfik_srcnodes--;
break;
+   case PFI_KIF_REF_FLAG:
+   if (kif->pfik_flagrefs <= 0) {
+   DPFPRINTF(LOG_ERR,
+   "pfi_kif_unref: flags refcount <= 0");
+   return;
+   }
+   kif->pfik_flagrefs--;
+   break;
default:
panic("pfi_kif_unref with unknown type");
}
 
-   if (kif->pfik_ifp != NULL || kif->pfik_group != NULL || kif == pfi_all)
+   if (kif->pfik_ifp != NULL || kif->pfik_group != NULL ||kif == pfi_all)
return;
 
if (kif->pfik_rules || kif->pfik_states || kif->pfik_routes ||
-   kif->pfik_srcnodes)
+   kif->pfik_srcnodes || kif->pfik_flagrefs)
return;
 
RB_REMOVE(pfi_ifhead, _ifs, kif);
@@ -786,24 +797,51 @@ int
 pfi_set_flags(const char *name, int flags)
 {
struct pfi_kif  *p;
+   size_t n;
 
-   RB_FOREACH(p, pfi_ifhead, _ifs) {
-   if (pfi_skip_if(name, p))
-   continue;
-   p->pfik_flags_new = p->pfik_flags | flags;
+   if (name == NULL)
+   return (0);
+
+   n = strlen(name);
+   if ((n < 1) || (n >= IFNAMSIZ))
+   return (0);
+
+   if (name[n-1] >= '0' && name[n-1] <= '9') {
+   p = pfi_kif_get(name, NULL);
+   if (p != NULL) {
+   p->pfik_flags_new = p->pfik_flags | flags;
+   if (p->pfik_flags_new != p->pfik_flags)
+   pfi_kif_ref(p, PFI_KIF_REF_FLAG);
+   }
+   } else {
+   p = pfi_kif_get(name, NULL);
+   if (p != NULL) {
+   p->pfik_flags_new = p->pfik_flags | flags;
+   if (p->pfik_flags_new != p->pfik_flags)
+   pfi_kif_ref(p, PFI_KIF_REF_FLAG);
+   }
+
+   RB_FOREACH(p, pfi_ifhead, _ifs) {
+   if (pfi_skip_if(name, p))
+   continue;
+   p->pfik_flags_new = p->pfik_flags | flags;
+   }
}
+
return (0);
 }
 
 int
 pfi_clear_flags(const char *name, int flags)
 {
-   struct pfi_kif  *p;
+   struct pfi_kif  *p, *w;
 
-   RB_FOREACH(p, pfi_ifhead, _ifs) {
+   RB_FOREACH_SAFE(p, pfi_ifhead, _ifs, w) {
if (pfi_skip_if(name, p))
continue;
p->pfik_flags_new = p->pfik_flags & ~flags;
+   if (p->pfik_flags_new != p->pfik_flags)
+   pfi_kif_unref(p, PFI_KIF_REF_FLAG);
}
return (0);
 }
diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index 514b9e156f3..53ced8ab97d 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -1171,6 +1171,7 @@ struct pfi_kif {
int  pfik_rules;
int  pfik_routes;
int  pfik_srcnodes;
+   int  pfik_flagrefs;
TAILQ_HEAD(, pfi_dynaddr)pfik_dynaddrs;
 };
 
@@ 

Re: possible fix for Xorg 21.1.1 crashes

2021-11-16 Thread Matthieu Herrb
On Tue, Nov 16, 2021 at 11:26:40PM +0100, Matthieu Herrb wrote:
> Hi,
> 
> I think I found the bug that causes crashes in X for some people.
> 
> If X started crashing since you upgraded to the last snapshots, can
> you try the patch below ?
> 
> get /usr/xenocara from CVS then
> 
> cd /usr/xenocara/xserver
> patch -p0 -E < /this/patch
> doas make -f Makefile.bsd-wrapper obj
> doas make -f Makefile.bsd-wrapper build
> 
> And restart the X server, for example : 
> doas rcctl restart xenodm
> 

Here's a more complete fix. Ust this one instead, sorry.

Index: Xi/exevents.c
===
RCS file: /cvs/OpenBSD/xenocara/xserver/Xi/exevents.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 exevents.c
--- Xi/exevents.c   11 Nov 2021 09:03:02 -  1.24
+++ Xi/exevents.c   16 Nov 2021 23:15:44 -
@@ -1901,7 +1901,7 @@ ProcessDeviceEvent(InternalEvent *ev, De
  * nested) to clients. */
 if (event->source_type == EVENT_SOURCE_FOCUS)
 return;
-if (!grab && CheckDeviceGrabs(device, event, 0))
+if (!grab && CheckDeviceGrabs(device, ev, 0))
 return;
 break;
 case ET_KeyRelease:
@@ -1914,7 +1914,7 @@ ProcessDeviceEvent(InternalEvent *ev, De
 if (b->map[key] == 0)   /* there's no button 0 */
 return;
 event->detail.button = b->map[key];
-if (!grab && CheckDeviceGrabs(device, event, 0)) {
+if (!grab && CheckDeviceGrabs(device, ev, 0)) {
 /* if a passive grab was activated, the event has been sent
  * already */
 return;
Index: dix/events.c
===
RCS file: /cvs/OpenBSD/xenocara/xserver/dix/events.c,v
retrieving revision 1.22
diff -u -p -u -r1.22 events.c
--- dix/events.c11 Nov 2021 09:03:03 -  1.22
+++ dix/events.c16 Nov 2021 23:15:44 -
@@ -1191,7 +1191,7 @@ EnqueueEvent(InternalEvent *ev, DeviceIn
 }
 }
 
-eventlen = event->length;
+eventlen = sizeof(InternalEvent);
 
 qe = malloc(sizeof(QdEventRec) + eventlen);
 if (!qe)
@@ -1319,7 +1319,7 @@ ComputeFreezes(void)
 
 syncEvents.replayDev = (DeviceIntPtr) NULL;
 
-if (!CheckDeviceGrabs(replayDev, >device_event,
+if (!CheckDeviceGrabs(replayDev, event,
   syncEvents.replayWin)) {
 if (IsTouchEvent(event)) {
 TouchPointInfoPtr ti =
@@ -3027,7 +3027,7 @@ BOOL
 ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
 {
 BOOL rc = FALSE;
-DeviceEvent event;
+InternalEvent event;
 
 if (dev->deviceGrab.grab) {
 if (!dev->deviceGrab.fromPassiveGrab ||
@@ -3042,16 +3042,16 @@ ActivateFocusInGrab(DeviceIntPtr dev, Wi
 if (win == NoneWin || win == PointerRootWin)
 return FALSE;
 
-event = (DeviceEvent) {
-.header = ET_Internal,
-.type = ET_FocusIn,
-.length = sizeof(DeviceEvent),
-.time = GetTimeInMillis(),
-.deviceid = dev->id,
-.sourceid = dev->id,
-.detail.button = 0
+event = (InternalEvent) {
+.device_event.header = ET_Internal,
+.device_event.type = ET_FocusIn,
+.device_event.length = sizeof(DeviceEvent),
+.device_event.time = GetTimeInMillis(),
+.device_event.deviceid = dev->id,
+.device_event.sourceid = dev->id,
+.device_event.detail.button = 0
 };
-rc = (CheckPassiveGrabsOnWindow(win, dev, (InternalEvent *) , FALSE,
+rc = (CheckPassiveGrabsOnWindow(win, dev, , FALSE,
 TRUE) != NULL);
 if (rc)
 DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveGrab);
@@ -3068,7 +3068,7 @@ static BOOL
 ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
 {
 BOOL rc = FALSE;
-DeviceEvent event;
+InternalEvent event;
 
 if (dev->deviceGrab.grab) {
 if (!dev->deviceGrab.fromPassiveGrab ||
@@ -3080,16 +3080,16 @@ ActivateEnterGrab(DeviceIntPtr dev, Wind
 (*dev->deviceGrab.DeactivateGrab) (dev);
 }
 
-event = (DeviceEvent) {
-.header = ET_Internal,
-.type = ET_Enter,
-.length = sizeof(DeviceEvent),
-.time = GetTimeInMillis(),
-.deviceid = dev->id,
-.sourceid = dev->id,
-.detail.button = 0
+event = (InternalEvent) {
+.device_event.header = ET_Internal,
+.device_event.type = ET_Enter,
+.device_event.length = sizeof(DeviceEvent),
+.device_event.time = GetTimeInMillis(),
+.device_event.deviceid = dev->id,
+.device_event.sourceid = dev->id,
+.device_event.detail.button = 0
 };
-rc = (CheckPassiveGrabsOnWindow(win, dev, (InternalEvent *) , FALSE,
+rc = (CheckPassiveGrabsOnWindow(win, dev, , FALSE,
 TRUE) != NULL);
 if (rc)
 

netstart: create virtual interfaces upfront when passing specific ones

2021-11-16 Thread Klemens Nanni
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.


Feedback? Objection? OK?

Index: netstart
===
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.216
diff -u -p -r1.216 netstart
--- netstart2 Sep 2021 19:38:20 -   1.216
+++ netstart16 Nov 2021 22:58:31 -
@@ -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
+
if ! ifcreate $_if; then
print -u2 "${0##*/}: create for '$_if' failed."
fi
@@ -303,6 +308,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



possible fix for Xorg 21.1.1 crashes

2021-11-16 Thread Matthieu Herrb
Hi,

I think I found the bug that causes crashes in X for some people.

If X started crashing since you upgraded to the last snapshots, can
you try the patch below ?

get /usr/xenocara from CVS then

cd /usr/xenocara/xserver
patch -p0 -E < /this/patch
doas make -f Makefile.bsd-wrapper obj
doas make -f Makefile.bsd-wrapper build

And restart the X server, for example : 
doas rcctl restart xenodm

Index: dix/events.c
===
RCS file: /cvs/OpenBSD/xenocara/xserver/dix/events.c,v
retrieving revision 1.22
diff -u -p -u -r1.22 events.c
--- dix/events.c11 Nov 2021 09:03:03 -  1.22
+++ dix/events.c16 Nov 2021 22:15:06 -
@@ -1319,7 +1319,7 @@ ComputeFreezes(void)
 
 syncEvents.replayDev = (DeviceIntPtr) NULL;
 
-if (!CheckDeviceGrabs(replayDev, >device_event,
+if (!CheckDeviceGrabs(replayDev, event,
   syncEvents.replayWin)) {
 if (IsTouchEvent(event)) {
 TouchPointInfoPtr ti =
@@ -3027,7 +3027,7 @@ BOOL
 ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
 {
 BOOL rc = FALSE;
-DeviceEvent event;
+InternalEvent event;
 
 if (dev->deviceGrab.grab) {
 if (!dev->deviceGrab.fromPassiveGrab ||
@@ -3042,16 +3042,16 @@ ActivateFocusInGrab(DeviceIntPtr dev, Wi
 if (win == NoneWin || win == PointerRootWin)
 return FALSE;
 
-event = (DeviceEvent) {
-.header = ET_Internal,
-.type = ET_FocusIn,
-.length = sizeof(DeviceEvent),
-.time = GetTimeInMillis(),
-.deviceid = dev->id,
-.sourceid = dev->id,
-.detail.button = 0
+event = (InternalEvent) {
+.device_event.header = ET_Internal,
+.device_event.type = ET_FocusIn,
+.device_event.length = sizeof(DeviceEvent),
+.device_event.time = GetTimeInMillis(),
+.device_event.deviceid = dev->id,
+.device_event.sourceid = dev->id,
+.device_event.detail.button = 0
 };
-rc = (CheckPassiveGrabsOnWindow(win, dev, (InternalEvent *) , FALSE,
+rc = (CheckPassiveGrabsOnWindow(win, dev, , FALSE,
 TRUE) != NULL);
 if (rc)
 DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveGrab);
@@ -3068,7 +3068,7 @@ static BOOL
 ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
 {
 BOOL rc = FALSE;
-DeviceEvent event;
+InternalEvent event;
 
 if (dev->deviceGrab.grab) {
 if (!dev->deviceGrab.fromPassiveGrab ||
@@ -3080,16 +3080,16 @@ ActivateEnterGrab(DeviceIntPtr dev, Wind
 (*dev->deviceGrab.DeactivateGrab) (dev);
 }
 
-event = (DeviceEvent) {
-.header = ET_Internal,
-.type = ET_Enter,
-.length = sizeof(DeviceEvent),
-.time = GetTimeInMillis(),
-.deviceid = dev->id,
-.sourceid = dev->id,
-.detail.button = 0
+event = (InternalEvent) {
+.device_event.header = ET_Internal,
+.device_event.type = ET_Enter,
+.device_event.length = sizeof(DeviceEvent),
+.device_event.time = GetTimeInMillis(),
+.device_event.deviceid = dev->id,
+.device_event.sourceid = dev->id,
+.device_event.detail.button = 0
 };
-rc = (CheckPassiveGrabsOnWindow(win, dev, (InternalEvent *) , FALSE,
+rc = (CheckPassiveGrabsOnWindow(win, dev, , FALSE,
 TRUE) != NULL);
 if (rc)
 DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveGrab);
@@ -4141,14 +4141,15 @@ CheckPassiveGrabsOnWindow(WindowPtr pWin
 */
 
 Bool
-CheckDeviceGrabs(DeviceIntPtr device, DeviceEvent *event, WindowPtr ancestor)
+CheckDeviceGrabs(DeviceIntPtr device, InternalEvent *ievent, WindowPtr 
ancestor)
 {
 int i;
 WindowPtr pWin = NULL;
 FocusClassPtr focus =
-IsPointerEvent((InternalEvent *) event) ? NULL : device->focus;
+IsPointerEvent(ievent) ? NULL : device->focus;
 BOOL sendCore = (IsMaster(device) && device->coreEvents);
 Bool ret = FALSE;
+DeviceEvent *event = >device_event;
 
 if (event->type != ET_ButtonPress && event->type != ET_KeyPress)
 return FALSE;
@@ -4171,7 +4172,7 @@ CheckDeviceGrabs(DeviceIntPtr device, De
 if (focus) {
 for (; i < focus->traceGood; i++) {
 pWin = focus->trace[i];
-if (CheckPassiveGrabsOnWindow(pWin, device, (InternalEvent *) 
event,
+if (CheckPassiveGrabsOnWindow(pWin, device, ievent,
   sendCore, TRUE)) {
 ret = TRUE;
 goto out;
@@ -4186,7 +4187,7 @@ CheckDeviceGrabs(DeviceIntPtr device, De
 
 for (; i < device->spriteInfo->sprite->spriteTraceGood; i++) {
 pWin = device->spriteInfo->sprite->spriteTrace[i];
-if (CheckPassiveGrabsOnWindow(pWin, device, (InternalEvent *) event,
+if (CheckPassiveGrabsOnWindow(pWin, device, 

cwm: fix invalid KeyCode in configuration

2021-11-16 Thread Luís Henriques
Hi!

I've tried to setup a line like:

bind-key XF86MonBrightnessDown ""

in my .cwmrc and the result was that no key event was sent to my windows.

Looking at the code, it looks like XKeysymToKeycode() is returning 0 for
the XF86MonBrightnessDown keysym.  And this means that XGrabKey() will get
'AnyKey' (0) as the keycode.  The patch bellow fixes this.

Cheers,
--
Luís

diff --git app/cwm/conf.c app/cwm/conf.c
index 1e95bd9e12d9..4125aa2aea42 100644
--- app/cwm/conf.c
+++ app/cwm/conf.c
@@ -669,6 +669,8 @@ conf_grab_kbd(Window win)
 
TAILQ_FOREACH(kb, , entry) {
kc = XKeysymToKeycode(X_Dpy, kb->press.keysym);
+   if (kc == 0)
+   continue;
if ((XkbKeycodeToKeysym(X_Dpy, kc, 0, 0) != kb->press.keysym) &&
(XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym))
kb->modmask |= ShiftMask;



Re: wc(1): fix NULL pointer dereference

2021-11-16 Thread Todd C . Miller
On Tue, 16 Nov 2021 13:53:25 -0600, Scott Cheloha wrote:

> How would you do it?  This seemed like the smallest diff to me because
> we don't have to change all the warn(3) calls.  Is there an easier thing?

Nevermind, I missed that print_counts() needs to easily distinguish
between stdin and a file.

OK millert@

 - todd



Re: wc(1): fix NULL pointer dereference

2021-11-16 Thread Scott Cheloha
On Tue, Nov 16, 2021 at 12:39:32PM -0700, Todd C. Miller wrote:
> On Tue, 16 Nov 2021 12:35:59 -0600, Scott Cheloha wrote:
> 
> > In wc(1), the "file" argument to cnt() is NULL when we're enumerating
> > the standard input.  This causes a NULL pointer dereference if we ever
> > hit one of the warn(3) calls in that function.
> >
> > To fix, change the argument name to "path" and make "file" a local
> > variable that is always initialized to point to a C string.
> >
> > While we're here we may as well const the argument pointers.
> 
> I don't see the need for separate "path" and "file" variables but
> if it makes you happy, then OK.

How would you do it?  This seemed like the smallest diff to me because
we don't have to change all the warn(3) calls.  Is there an easier thing?



Re: wc(1): fix NULL pointer dereference

2021-11-16 Thread Todd C . Miller
On Tue, 16 Nov 2021 12:35:59 -0600, Scott Cheloha wrote:

> In wc(1), the "file" argument to cnt() is NULL when we're enumerating
> the standard input.  This causes a NULL pointer dereference if we ever
> hit one of the warn(3) calls in that function.
>
> To fix, change the argument name to "path" and make "file" a local
> variable that is always initialized to point to a C string.
>
> While we're here we may as well const the argument pointers.

I don't see the need for separate "path" and "file" variables but
if it makes you happy, then OK.

 - todd



wc(1): fix NULL pointer dereference

2021-11-16 Thread Scott Cheloha
In wc(1), the "file" argument to cnt() is NULL when we're enumerating
the standard input.  This causes a NULL pointer dereference if we ever
hit one of the warn(3) calls in that function.

To fix, change the argument name to "path" and make "file" a local
variable that is always initialized to point to a C string.

While we're here we may as well const the argument pointers.

ok?

Index: wc.c
===
RCS file: /cvs/src/usr.bin/wc/wc.c,v
retrieving revision 1.27
diff -u -p -r1.27 wc.c
--- wc.c24 Oct 2021 21:24:18 -  1.27
+++ wc.c16 Nov 2021 18:34:14 -
@@ -48,9 +48,9 @@ int   doline, doword, dochar, humanchar, m
 intrval;
 extern char *__progname;
 
-static void print_counts(int64_t, int64_t, int64_t, char *);
+static void print_counts(int64_t, int64_t, int64_t, const char *);
 static void format_and_print(int64_t);
-static void cnt(char *);
+static void cnt(const char *);
 
 int
 main(int argc, char *argv[])
@@ -115,12 +115,13 @@ main(int argc, char *argv[])
 }
 
 static void
-cnt(char *file)
+cnt(const char *path)
 {
static char *buf;
static size_t bufsz;
 
FILE *stream;
+   const char *file;
char *C;
wchar_t wc;
short gotsp;
@@ -131,13 +132,15 @@ cnt(char *file)
 
linect = wordct = charct = 0;
stream = NULL;
-   if (file) {
+   if (path != NULL) {
+   file = path;
if ((fd = open(file, O_RDONLY)) == -1) {
warn("%s", file);
rval = 1;
return;
}
} else  {
+   file = "(stdin)";
fd = STDIN_FILENO;
}
 
@@ -191,7 +194,7 @@ cnt(char *file)
}
}
} else {
-   if (file == NULL)
+   if (path == NULL)
stream = stdin;
else if ((stream = fdopen(fd, "r")) == NULL) {
warn("%s", file);
@@ -249,7 +252,7 @@ cnt(char *file)
}
}
 
-   print_counts(linect, wordct, charct, file);
+   print_counts(linect, wordct, charct, path);
 
/*
 * Don't bother checking doline, doword, or dochar -- speeds
@@ -279,7 +282,7 @@ format_and_print(int64_t v)
 }
 
 static void
-print_counts(int64_t lines, int64_t words, int64_t chars, char *name)
+print_counts(int64_t lines, int64_t words, int64_t chars, const char *name)
 {
if (doline)
format_and_print(lines);



dhcpleased - set ciaddr per RFC

2021-11-16 Thread Joel Knight
Hi. On a firewall recently upgraded to 7.0, I noticed that dhcpleased
was not getting a reply from my ISP's DHCP server during renewal at
T1. At T2, dhcpleased would broadcast the REQUEST which would be
answered. Testing with dhclient showed successful renewals at T1.

Inspecting the REQUEST packets showed that dhclient was setting the
ciaddr to the existing leased IP address while dhcpleased was not
setting this field. RFC 2131 4.3.2 (with a nice summary at 4.3.6) is
pretty strict about when ciaddr and the 'requested ip' option should
be used. The diff below modifies dhcpleased to set ciaddr and
'requested ip' at the appropriate times.

While here, I also noticed that if you configure an interface in
dhcpleased.conf but do not use "set client id", dhcpleased will not
send the default client id as is stated in dhcpleased.conf(5).

Since gmail will undoubtedly muck up this diff, a clean copy is here:
www.packetmischief.ca/files/patches/dhcpleased.ciaddr.diff


.joel

Index: src/sbin/dhcpleased/dhcpleased.h
===
RCS file: /data/cvs-mirror/OpenBSD/src/sbin/dhcpleased/dhcpleased.h,v
retrieving revision 1.11
diff -p -u -r1.11 dhcpleased.h
--- src/sbin/dhcpleased/dhcpleased.h 12 Aug 2021 12:41:08 - 1.11
+++ src/sbin/dhcpleased/dhcpleased.h 16 Nov 2021 04:06:06 -
@@ -191,6 +191,18 @@ struct dhcp_route {
  struct in_addr gw;
 };

+enum if_state {
+ IF_DOWN,
+ IF_INIT,
+ /* IF_SELECTING, */
+ IF_REQUESTING,
+ IF_BOUND,
+ IF_RENEWING,
+ IF_REBINDING,
+ /* IF_INIT_REBOOT, */
+ IF_REBOOTING,
+};
+
 enum imsg_type {
  IMSG_NONE,
 #ifndef SMALL
@@ -294,6 +306,7 @@ struct imsg_req_discover {
 };

 struct imsg_req_request {
+ enum if_state if_state;
  uint32_t if_index;
  uint32_t xid;
  struct in_addr requested_ip;
Index: src/sbin/dhcpleased/engine.c
===
RCS file: /data/cvs-mirror/OpenBSD/src/sbin/dhcpleased/engine.c,v
retrieving revision 1.29
diff -p -u -r1.29 engine.c
--- src/sbin/dhcpleased/engine.c 14 Nov 2021 18:13:19 - 1.29
+++ src/sbin/dhcpleased/engine.c 16 Nov 2021 04:06:34 -
@@ -60,18 +60,6 @@
 #define MAX_EXP_BACKOFF_FAST 2
 #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))

-enum if_state {
- IF_DOWN,
- IF_INIT,
- /* IF_SELECTING, */
- IF_REQUESTING,
- IF_BOUND,
- IF_RENEWING,
- IF_REBINDING,
- /* IF_INIT_REBOOT, */
- IF_REBOOTING,
-};
-
 const char* if_state_name[] = {
  "Down",
  "Init",
@@ -1485,6 +1473,7 @@ request_dhcp_request(struct dhcpleased_i

  iface->xid = arc4random();
  imsg_req_request.if_index = iface->if_index;
+ imsg_req_request.if_state = iface->state;
  imsg_req_request.xid = iface->xid;
  imsg_req_request.server_identifier.s_addr =
  iface->server_identifier.s_addr;
Index: src/sbin/dhcpleased/frontend.c
===
RCS file: /data/cvs-mirror/OpenBSD/src/sbin/dhcpleased/frontend.c,v
retrieving revision 1.23
diff -p -u -r1.23 frontend.c
--- src/sbin/dhcpleased/frontend.c 20 Oct 2021 07:04:49 - 1.23
+++ src/sbin/dhcpleased/frontend.c 16 Nov 2021 04:14:23 -
@@ -74,6 +74,7 @@ struct iface {
  struct in_addr server_identifier;
  struct in_addr dhcp_server;
  int udpsock;
+ enum if_state state;
 };

 __dead void frontend_shutdown(void);
@@ -91,7 +92,7 @@ struct iface *get_iface_by_id(uint32_t);
 void remove_iface(uint32_t);
 void set_bpfsock(int, uint32_t);
 ssize_t build_packet(uint8_t, char *, uint32_t, struct ether_addr *,
-  struct in_addr *, struct in_addr *);
+  struct in_addr *, struct in_addr *, enum if_state *);
 void send_discover(struct iface *);
 void send_request(struct iface *);
 void bpf_send_packet(struct iface *, uint8_t *, ssize_t);
@@ -511,6 +512,7 @@ frontend_dispatch_engine(int fd, short e
  imsg_req_request.server_identifier.s_addr;
  iface->dhcp_server.s_addr =
  imsg_req_request.dhcp_server.s_addr;
+ iface->state = imsg_req_request.if_state;
  send_request(iface);
  }
  break;
@@ -888,7 +890,7 @@ bpf_receive(int fd, short events, void *
 ssize_t
 build_packet(uint8_t message_type, char *if_name, uint32_t xid,
 struct ether_addr *hw_address, struct in_addr *requested_ip,
-struct in_addr *server_identifier)
+struct in_addr *server_identifier, enum if_state *if_state)
 {
  static uint8_t dhcp_cookie[] = DHCP_COOKIE;
  static uint8_t dhcp_message_type[] = {DHO_DHCP_MESSAGE_TYPE, 1,
@@ -926,6 +928,9 @@ build_packet(uint8_t message_type, char
  hdr->hops = 0;
  hdr->xid = xid;
  hdr->secs = 0;
+ if (message_type == DHCPREQUEST && (*if_state == IF_RENEWING ||
+ *if_state == IF_REBINDING))
+ memcpy(>ciaddr, requested_ip, sizeof(*requested_ip));
  memcpy(hdr->chaddr, hw_address, sizeof(*hw_address));
  p += sizeof(struct dhcp_hdr);
  memcpy(p, dhcp_cookie, sizeof(dhcp_cookie));
@@ -946,6 +951,11 @@ build_packet(uint8_t message_type, char
  /* XXX check space */
  memcpy(p, iface_conf->c_id, iface_conf->c_id_len);
  p += iface_conf->c_id_len;
+ 

Re: Fix vi(1) recovery - new method

2021-11-16 Thread Jan Stary
On Oct 09 20:26:13, tro...@kagu-tsuchi.com wrote:
> This is a new attempt at fixing vi(1) recovery by actually writing
> to the recovery file.  Previously I restored the SIGALRM method that
> was deleted in the 90's but wondered if that was still the best way
> to handle this.  Checking and syncing to the recovery every 2 minutes
> seems arbitrary and overly cautious.
> 
> This attempt takes it to the other direction.  I'm writing each
> change to the recovery file immediately after the in-memory database
> is modified.  Though, I can see that this might have a noticeable
> impact on slower file systems.

This recovers close to what the file was at the KILL moment.
The writing impact is still bareable e.g. on a SD card in a Raspberry
(that is to say, slow, but not much slower than without this).

Thank you!

Jan



Retry sleep in poll/select

2021-11-16 Thread Visa Hankala
Currently, dopselect() and doppoll() call tsleep_nsec() without retry.
cheloha@ asked if the functions should handle spurious wakeups. I guess
such wakeups are unlikely with the nowake wait channel, but I am not
sure if that is a safe guess.

The following diff adds the retrying. The code is a bit arduous, so the
retry loop is put in a separate function that both poll and select use.

Index: kern/sys_generic.c
===
RCS file: src/sys/kern/sys_generic.c,v
retrieving revision 1.141
diff -u -p -r1.141 sys_generic.c
--- kern/sys_generic.c  16 Nov 2021 13:48:23 -  1.141
+++ kern/sys_generic.c  16 Nov 2021 13:50:08 -
@@ -90,6 +90,7 @@ int dopselect(struct proc *, int, fd_set
 int doppoll(struct proc *, struct pollfd *, u_int, struct timespec *,
 const sigset_t *, register_t *);
 void doselwakeup(struct selinfo *);
+int selsleep(struct timespec *);
 
 int
 iovec_copyin(const struct iovec *uiov, struct iovec **iovp, struct iovec *aiov,
@@ -664,19 +665,7 @@ dopselect(struct proc *p, int nd, fd_set
 * there's nothing to wait for.
 */
if (nevents == 0 && ncollected == 0) {
-   uint64_t nsecs = INFSLP;
-
-   if (timeout != NULL) {
-   if (!timespecisset(timeout))
-   goto done;
-   nsecs = MAX(1, MIN(TIMESPEC_TO_NSEC(timeout), MAXTSLP));
-   }
-   error = tsleep_nsec(, PSOCK | PCATCH, "kqsel", nsecs);
-   /* select is not restarted after signals... */
-   if (error == ERESTART)
-   error = EINTR;
-   if (error == EWOULDBLOCK)
-   error = 0;
+   error = selsleep(timeout);
goto done;
}
 
@@ -849,6 +838,46 @@ selfalse(dev_t dev, int events, struct p
 }
 
 /*
+ * Sleep until a signal arrives or the optional timeout expires.
+ */
+int
+selsleep(struct timespec *timeout)
+{
+   uint64_t end, now, nsecs;
+   int error;
+
+   if (timeout != NULL) {
+   if (!timespecisset(timeout))
+   return (0);
+   now = getnsecuptime();
+   end = MIN(now + TIMESPEC_TO_NSEC(timeout), MAXTSLP);
+   if (end < now)
+   end = MAXTSLP;
+   }
+
+   do {
+   if (timeout != NULL)
+   nsecs = MAX(1, end - now);
+   else
+   nsecs = INFSLP;
+   error = tsleep_nsec(, PSOCK | PCATCH, "selslp", nsecs);
+   if (timeout != NULL) {
+   now = getnsecuptime();
+   if (now >= end)
+   break;
+   }
+   } while (error == 0);
+
+   /* poll/select is not restarted after signals... */
+   if (error == ERESTART)
+   error = EINTR;
+   if (error == EWOULDBLOCK)
+   error = 0;
+
+   return (error);
+}
+
+/*
  * Record a select request.
  */
 void
@@ -1158,19 +1187,7 @@ doppoll(struct proc *p, struct pollfd *f
 * there's nothing to wait for.
 */
if (nevents == 0 && ncollected == 0) {
-   uint64_t nsecs = INFSLP;
-
-   if (timeout != NULL) {
-   if (!timespecisset(timeout))
-   goto done;
-   nsecs = MAX(1, MIN(TIMESPEC_TO_NSEC(timeout), MAXTSLP));
-   }
-
-   error = tsleep_nsec(, PSOCK | PCATCH, "kqpoll", nsecs);
-   if (error == ERESTART)
-   error = EINTR;
-   if (error == EWOULDBLOCK)
-   error = 0;
+   error = selsleep(timeout);
goto done;
}
 



Re: better audio defaults: please test

2021-11-16 Thread Bryan Linton
On 2021-11-04 16:21:12, Alexandre Ratchov  wrote:
> The current sndiod latency (minimum time between when the program
> plays something and when sound reaches Joe's ears) is too large and
> makes OpenBSD unpleasant to use for telephony, games, and makes
> controls of video players slugish.
> 
> [...]
>
> Please try to switch you system to 40ms buffers (i.e. 1920 samples at
> the default 48kHz rate), for instance either apply diff below or
> simply do:
> 
>   rcctl set sndiod flags -z 480 -b 1920
>   rcctl restart sndiod
> 
> then report any significant increase of stuttering, and what
> software/hardware triggers it. If you think 20ms or 30ms (i.e. 960 and
> 1440 sample buffers) are better, let me know as well.
> 

I experienced stuttering while watching YouTube videos with
"-z 480 -b 1920" when pegging all CPUs to 100% (building a large port like
Firefox or building a kernel).

I tried doubling it to "-z 960 -b 3840" and the stuttering went away.

I then tried taking the middle and set "-z 720 -b 2880" and the
audio was still OK.  So it seems my system can't be set as low as
480/1920 but 720/2880 or higher works.

This is on a:
cpu0: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz, 3890.94 MHz, 06-9e-09

in a ThinkPad T470p running on:
OpenBSD 7.0-current (GENERIC.MP) #93: Sat Nov 13 18:25:45 MST 2021
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

Hopefully this information helps.

Please let me know if you require any more information.

-- 
Bryan



Re: bt.5 document count()

2021-11-16 Thread Dave Voutila


Claudio Jeker  writes:

> This documents count(). This function only works when used like this
>   @map[key] = count();
> But it is implemented and works. If used differently you get a syntax
> error which is not helpful. This is why I chose to document it like this.
> Another option would be to document the language (so it is clear where it
> is possible to use what).
>
> max(), min() and sum() are other functions that behave like this. Their
> documentation should also be adjusted IMO.

Since these are all "map functions" per bpftrace [1] and we're aiming to
keep parity with that language, should we separate them from the vague
list of "functions" into their own section? They can't be used elsewhere.

-dv

[1] 
https://github.com/iovisor/bpftrace/blob/master/docs/reference_guide.md#map-functions



Re: bt.5 document count()

2021-11-16 Thread Martin Pieuchot
On 16/11/21(Tue) 11:07, Claudio Jeker wrote:
> This documents count(). This function only works when used like this
>   @map[key] = count();
> But it is implemented and works. If used differently you get a syntax
> error which is not helpful. This is why I chose to document it like this.
> Another option would be to document the language (so it is clear where it
> is possible to use what). 

ok mpi@

> max(), min() and sum() are other functions that behave like this. Their
> documentation should also be adjusted IMO.
> 
> -- 
> :wq Claudio
> 
> Index: bt.5
> ===
> RCS file: /cvs/src/usr.sbin/btrace/bt.5,v
> retrieving revision 1.13
> diff -u -p -r1.13 bt.5
> --- bt.5  12 Nov 2021 16:57:24 -  1.13
> +++ bt.5  16 Nov 2021 09:50:52 -
> @@ -120,6 +120,11 @@ Functions:
>  .It Fn clear "@map"
>  Delete all (key, value) pairs from
>  .Va @map .
> +.It "@map[key]" = Fn count
> +Increment the value of
> +.Va key
> +from
> +.Va @map .
>  .It Fn delete "@map[key]"
>  Delete the pair indexed by
>  .Va key
> 



bt.5 document count()

2021-11-16 Thread Claudio Jeker
This documents count(). This function only works when used like this
@map[key] = count();
But it is implemented and works. If used differently you get a syntax
error which is not helpful. This is why I chose to document it like this.
Another option would be to document the language (so it is clear where it
is possible to use what). 

max(), min() and sum() are other functions that behave like this. Their
documentation should also be adjusted IMO.

-- 
:wq Claudio

Index: bt.5
===
RCS file: /cvs/src/usr.sbin/btrace/bt.5,v
retrieving revision 1.13
diff -u -p -r1.13 bt.5
--- bt.512 Nov 2021 16:57:24 -  1.13
+++ bt.516 Nov 2021 09:50:52 -
@@ -120,6 +120,11 @@ Functions:
 .It Fn clear "@map"
 Delete all (key, value) pairs from
 .Va @map .
+.It "@map[key]" = Fn count
+Increment the value of
+.Va key
+from
+.Va @map .
 .It Fn delete "@map[key]"
 Delete the pair indexed by
 .Va key



Re: IPsec tdb ddb print

2021-11-16 Thread Vitaliy Makkoveev
On Mon, Nov 15, 2021 at 05:23:43PM +0100, Alexander Bluhm wrote:
> Hi,
> 
> To debug IPsec and tdb refcounting it may be useful to have "show
> tdb" and "show all tdbs" in ddb.
> 
> ok?
> 

Indeed this is useful.

ok mvs@

> bluhm
> 
> Index: share/man/man4/ddb.4
> ===
> RCS file: /data/mirror/openbsd/cvs/src/share/man/man4/ddb.4,v
> retrieving revision 1.99
> diff -u -p -r1.99 ddb.4
> --- share/man/man4/ddb.4  26 Oct 2020 18:53:20 -  1.99
> +++ share/man/man4/ddb.4  15 Nov 2021 14:43:46 -
> @@ -812,6 +812,19 @@ as a struct
>  Nested structures and bit fields are not printed.
>  Character arrays are printed as bytes.
>  .\" 
> +.It Xo
> +.Ic show tdb
> +.Op Cm /f
> +.Ar addr
> +.Xc
> +Prints the
> +.Li struct tdb
> +at
> +.Ar addr .
> +If the
> +.Cm /f
> +modifier is specified prints out all fields of this IPsec SA.
> +.\" 
>  .It Ic show uvmexp
>  Displays a selection of uvm counters and statistics.
>  .\" 
> @@ -938,6 +951,17 @@ Display information for all outstanding 
>  For each NFS requests, print a more detailed output.
>  See the
>  .Ic show nfsreq
> +command for more information.
> +.El
> +.\" 
> +.It Ic show all tdbs Op Cm /f
> +Display information about all IPsec SAs in the system.
> +.Pp
> +.Bl -tag -width foo -compact
> +.It Cm /f
> +For each tdb, print a more detailed output.
> +See the
> +.Ic show tdb
>  command for more information.
>  .El
>  .\" 
> Index: sys/ddb/db_command.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/ddb/db_command.c,v
> retrieving revision 1.91
> diff -u -p -r1.91 db_command.c
> --- sys/ddb/db_command.c  2 Jun 2021 00:39:25 -   1.91
> +++ sys/ddb/db_command.c  15 Nov 2021 13:54:41 -
> @@ -56,6 +56,7 @@
>  #include 
>  #include 
>  
> +#include 
>  #include 
>  
>  /*
> @@ -89,12 +90,14 @@ void  db_mount_print_cmd(db_expr_t, int, 
>  void db_show_all_mounts(db_expr_t, int, db_expr_t, char *);
>  void db_show_all_vnodes(db_expr_t, int, db_expr_t, char *);
>  void db_show_all_bufs(db_expr_t, int, db_expr_t, char *);
> +void db_show_all_tdbs(db_expr_t, int, db_expr_t, char *);
>  void db_object_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_page_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_extent_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_pool_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_proc_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_uvmexp_print_cmd(db_expr_t, int, db_expr_t, char *);
> +void db_tdb_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_vnode_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_nfsreq_print_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_nfsnode_print_cmd(db_expr_t, int, db_expr_t, char *);
> @@ -399,6 +402,19 @@ db_show_all_bufs(db_expr_t addr, int hav
>   pool_walk(, full, db_printf, vfs_buf_print);
>  }
>  
> +#ifdef IPSEC
> +void
> +db_show_all_tdbs(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
> +{
> + int full = 0;
> +
> + if (modif[0] == 'f')
> + full = 1;
> +
> + pool_walk(_pool, full, db_printf, tdb_printit);
> +}
> +#endif
> +
>  /*ARGSUSED*/
>  void
>  db_object_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char 
> *modif)
> @@ -509,6 +525,19 @@ db_proc_print_cmd(db_expr_t addr, int ha
>   proc_printit((struct proc *)addr, modif, db_printf);
>  }
>  
> +#ifdef IPSEC
> +void
> +db_tdb_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
> +{
> + int full = 0;
> +
> + if (modif[0] == 'f')
> + full = 1;
> +
> + tdb_printit((void *)addr, full, db_printf);
> +}
> +#endif
> +
>  /*ARGSUSED*/
>  void
>  db_uvmexp_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char 
> *modif)
> @@ -540,6 +569,9 @@ struct db_command db_show_all_cmds[] = {
>   { "nfsreqs",db_show_all_nfsreqs,0, NULL },
>   { "nfsnodes",   db_show_all_nfsnodes,   0, NULL },
>  #endif
> +#ifdef IPSEC
> + { "tdbs",   db_show_all_tdbs,   0, NULL },
> +#endif
>  #ifdef WITNESS
>   { "locks",  db_witness_list_all,0, NULL },
>  #endif
> @@ -571,6 +603,9 @@ struct db_command db_show_cmds[] = {
>   { "registers",  db_show_regs,   0,  NULL },
>   { "socket", db_socket_print_cmd,0,  NULL },
>   { "struct", db_ctf_show_struct, CS_OWN, NULL },
> +#ifdef IPSEC
> + { "tdb",db_tdb_print_cmd,   0,  NULL },
> +#endif
>   { "uvmexp", db_uvmexp_print_cmd,0,  NULL },
>   { "vnode",  db_vnode_print_cmd, 0,  NULL },
>   { "watches",db_listwatch_cmd,   0,  NULL },
> Index: sys/netinet/ip_ipsp.c
> ===
> RCS file: