sync libfido2 with upstream

2020-08-09 Thread Damien Miller
Hi,

This syncs libfido2 with the current state of upstream. It includes
a few new APIs that I want to use in OpenSSH to improve FIDO token
support (require-PIN and fixing some corner-case bugs around multiple
inserted tokens).

ok?

(major crank for ABI change)

Index: Makefile
===
RCS file: /cvs/src/lib/libfido2/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- Makefile7 Feb 2020 00:57:49 -   1.5
+++ Makefile10 Aug 2020 02:02:50 -
@@ -30,7 +30,7 @@ MAN+= fido_cbor_info_new.3 fido_cred_exc
 MAN+=  fido_cred_set_authdata.3 fido_cred_verify.3 fido_credman_metadata_new.3
 MAN+=  fido_dev_get_assert.3 fido_dev_info_manifest.3 fido_dev_make_cred.3
 MAN+=  fido_dev_open.3 fido_dev_set_io_functions.3 fido_dev_set_pin.3
-MAN+=  fido_init.3 fido_strerr.3 rs256_pk_new.3
+MAN+=  fido_init.3 fido_strerr.3 rs256_pk_new.3 fido_dev_get_touch_begin.3
 
 includes:
@for i in $(HDRS); do \
Index: README.openbsd
===
RCS file: /cvs/src/lib/libfido2/README.openbsd,v
retrieving revision 1.2
diff -u -p -r1.2 README.openbsd
--- README.openbsd  7 Feb 2020 00:57:49 -   1.2
+++ README.openbsd  10 Aug 2020 02:02:50 -
@@ -1,4 +1,4 @@
-This is an import of https://github.com/Yubico/libfido2 780ad3c25 (20120123)
+This is an import of https://github.com/Yubico/libfido2 2fa20b889c (20200810)
 
 Local changes:
 
Index: shlib_version
===
RCS file: /cvs/src/lib/libfido2/shlib_version,v
retrieving revision 1.3
diff -u -p -r1.3 shlib_version
--- shlib_version   7 Feb 2020 00:57:49 -   1.3
+++ shlib_version   10 Aug 2020 02:02:50 -
@@ -1,2 +1,2 @@
-major=2
+major=3
 minor=0
Index: man/fido_assert_new.3
===
RCS file: /cvs/src/lib/libfido2/man/fido_assert_new.3,v
retrieving revision 1.3
diff -u -p -r1.3 fido_assert_new.3
--- man/fido_assert_new.3   7 Feb 2020 00:57:49 -   1.3
+++ man/fido_assert_new.3   10 Aug 2020 02:02:50 -
@@ -9,6 +9,7 @@
 .Nm fido_assert_new ,
 .Nm fido_assert_free ,
 .Nm fido_assert_count ,
+.Nm fido_assert_rp_id ,
 .Nm fido_assert_user_display_name ,
 .Nm fido_assert_user_icon ,
 .Nm fido_assert_user_name ,
@@ -17,12 +18,15 @@
 .Nm fido_assert_hmac_secret_ptr ,
 .Nm fido_assert_user_id_ptr ,
 .Nm fido_assert_sig_ptr ,
+.Nm fido_assert_id_ptr ,
 .Nm fido_assert_authdata_len ,
 .Nm fido_assert_clientdata_hash_len ,
 .Nm fido_assert_hmac_secret_len ,
 .Nm fido_assert_user_id_len ,
 .Nm fido_assert_sig_len ,
-.Nm fido_assert_sigcount
+.Nm fido_assert_id_len ,
+.Nm fido_assert_sigcount ,
+.Nm fido_assert_flags
 .Nd FIDO 2 assertion API
 .Sh SYNOPSIS
 .In fido.h
@@ -33,6 +37,8 @@
 .Ft size_t
 .Fn fido_assert_count "const fido_assert_t *assert"
 .Ft const char *
+.Fn fido_assert_rp_id "const fido_assert_t *assert"
+.Ft const char *
 .Fn fido_assert_user_display_name "const fido_assert_t *assert" "size_t idx"
 .Ft const char *
 .Fn fido_assert_user_icon "const fido_assert_t *assert" "size_t idx"
@@ -48,6 +54,8 @@
 .Fn fido_assert_user_id_ptr "const fido_assert_t *assert" "size_t idx"
 .Ft const unsigned char *
 .Fn fido_assert_sig_ptr "const fido_assert_t *assert" "size_t idx"
+.Ft const unsigned char *
+.Fn fido_assert_id_ptr "const fido_assert_t *assert" "size_t idx"
 .Ft size_t
 .Fn fido_assert_authdata_len "const fido_assert_t *assert" "size_t idx"
 .Ft size_t
@@ -58,8 +66,12 @@
 .Fn fido_assert_user_id_len "const fido_assert_t *assert" "size_t idx"
 .Ft size_t
 .Fn fido_assert_sig_len "const fido_assert_t *assert" "size_t idx"
+.Ft size_t
+.Fn fido_assert_id_len "const fido_assert_t *assert" "size_t idx"
 .Ft uint32_t
 .Fn fido_assert_sigcount "const fido_assert_t *assert" "size_t idx"
+.Ft uint8_t
+.Fn fido_assert_flags "const fido_assert_t *assert" "size_t idx"
 .Sh DESCRIPTION
 FIDO 2 assertions are abstracted in
 .Em libfido2
@@ -110,6 +122,12 @@ function returns the number of statement
 .Fa assert .
 .Pp
 The
+.Fn fido_assert_rp_id
+function returns a pointer to a NUL-terminated string holding the
+relying party ID of
+.Fa assert .
+.Pp
+The
 .Fn fido_assert_user_display_name ,
 .Fn fido_assert_user_icon ,
 and
@@ -126,10 +144,11 @@ The
 .Fn fido_assert_user_id_ptr ,
 .Fn fido_assert_authdata_ptr ,
 .Fn fido_assert_hmac_secret_ptr ,
+.Fn fido_assert_sig_ptr ,
 and
-.Fn fido_assert_sig_ptr
+.Fn fido_assert_id_ptr
 functions return pointers to the user ID, authenticator data,
-hmac-secret, and signature attributes of statement
+hmac-secret, signature, and credential ID attributes of statement
 .Fa idx
 in
 .Fa assert .
@@ -137,14 +156,22 @@ The
 .Fn fido_assert_user_id_len ,
 .Fn fido_assert_authdata_len ,
 .Fn fido_assert_hmac_secret_len ,
+.Fn fido_assert_sig_len ,
 and
-.Fn fido_assert_sig_len
+.Fn fido_assert_id_len
 functions can be used to retrieve the 

Re: TCP congestion control progression

2020-08-09 Thread Chris Cappuccio
Brian Brombacher [br...@planetunix.net] wrote:
> 
> I am wondering what approach the project is planning to use to modernize 
> the congestion control algorithms.  I'm interested in assisting the project 
> with development effort in this area.  I've spent time making modifications
> for my own purposes and would prefer to understand the projects goals before
> continuing, if possible.
> 

Various improvements have been made over the years for dynamic window size,
also further tweaks for higher bandwidth over high latency connections. I'd
recommend sharing your current modifications here to get feedback.

Chris



Re: PATCH: iostat spacing

2020-08-09 Thread Klemens Nanni
On Sat, Aug 08, 2020 at 04:12:31AM +0200, Klemens Nanni wrote:
> This is OK with me as it fixes the default view, but I think other views
> need fixing as well, e.g.
> 
>   $ iostat -I
>   ttysd0 sd1
> cpu
>  tin tout  KB/t   xfr MB   KB/t   xfr MB  us ni sy sp in 
> id
>   178524 22139320 26.99 10698431 281987.61  11.78 7582117 87218.82   7  0 
>  3  1  0 88
That was a bad example since `-I' shows the running total, hence values
that only ever increase and most likely change in magnitude.

> I'm testing with `dd if=/dev/rsd0c of=/dev/null bs=1m' on a X230 with
> sd0 at scsibus1 targ 0 lun 0:  
> naa.5002538d410a7bce

> I don't have that fast disks at hand, but expanding it by another column
> makes sense to me and could further simplify some of the code.
Here's a diff that expands `-d' (done by default) showing MB values by
two columns and `-D' showing KB values by one column;  `-I' is not
changed for above mentioned reasons.

This seems consistent to me on all disk related views and leaves room
for faster disks, should they ever read/write faster than 1000 MB/s.

Running with above `dd' to get reads, here's the visible change of this
diff:

$ iostat -c2
  tty  sd0   sd1cpu
 tin tout  KB/t  t/s  MB/s   KB/t  t/s  MB/s  us ni sy sp in id
   2  394 60.83  285 16.90  18.43   20  0.36   4  0  3  1  0 91
   1  195 63.97 3954 247.00   2.002  0.00   0  0 11  0  0 89
$ ./obj/iostat -c2
  ttysd0 sd1cpu
 tin tout  KB/t  t/sMB/s   KB/t  t/sMB/s  us ni sy sp in id
   2  393 60.94  294   17.51  18.43   200.36   4  0  3  1  0 91
   1  205 64.00 3560  222.52   0.0000.00   0  0 14  1  2 83

$ iostat -d -c2  
  sd0   sd1 
  KB/t  t/s  MB/s   KB/t  t/s  MB/s 
 61.02  301 17.96  18.43   20  0.35 
 64.00 3613 225.81   0.000  0.00 
$ ./obj/iostat -d -c2
sd0 sd1 
  KB/t  t/sMB/s   KB/t  t/sMB/s 
 61.06  305   18.18  18.43   200.35 
 64.00 3602  225.12   0.0000.00 

$ iostat -D -c2  
  sd0   sd1 
 KB  xfr time  KB  xfr time 
  19260  315 0.04 362   20 0.00 
 230590 3603 0.48   00 0.00 
$ ./obj/iostat -D -c2
   sd0sd1 
  KB  xfr time   KB  xfr time 
   19708  322 0.04  361   20 0.00 
  24 3750 0.5000 0.00

Feedback? OK?


Index: iostat.c
===
RCS file: /cvs/src/usr.sbin/iostat/iostat.c,v
retrieving revision 1.42
diff -u -p -r1.42 iostat.c
--- iostat.c14 Oct 2019 19:22:17 -  1.42
+++ iostat.c9 Aug 2020 22:04:21 -
@@ -224,15 +224,12 @@ header(void)
if (ISSET(todo, SHOW_STATS_1))
for (i = 0; i < dk_ndrive; i++)
if (cur.dk_select[i]) {
-   if (ISSET(todo, SHOW_TOTALS))
-   printf(" %18.18s ", cur.dk_name[i]);
-   else
-   printf(" %16.16s ", cur.dk_name[i]);
+   printf(" %18.18s ", cur.dk_name[i]);
}
if (ISSET(todo, SHOW_STATS_2))
for (i = 0; i < dk_ndrive; i++)
if (cur.dk_select[i])
-   printf(" %16.16s ", cur.dk_name[i]);
+   printf(" %17.17s ", cur.dk_name[i]);
 
if (ISSET(todo, SHOW_CPU))
printf("   cpu");
@@ -252,12 +249,12 @@ header(void)
if (ISSET(todo, SHOW_TOTALS))
printf("  KB/t   xfr MB ");
else
-   printf("  KB/t  t/s  MB/s ");
+   printf("  KB/t  t/sMB/s ");
}
if (ISSET(todo, SHOW_STATS_2))
for (i = 0; i < dk_ndrive; i++)
if (cur.dk_select[i])
-   printf(" KB  xfr time ");
+   printf("  KB  xfr time ");
 
if (ISSET(todo, SHOW_CPU))
printf(" us ni sy sp in id");
@@ -302,7 +299,7 @@ disk_stats(double etime)
if (ISSET(todo, SHOW_TOTALS))
printf(" %6.2f ", mbps / etime);
else
-   printf(" %5.2f ", mbps / etime);
+   printf(" %7.2f ", mbps / etime);
}
 }
 
@@ -317,7 +314,7 @@ disk_stats2(double etime)
  

TCP congestion control progression

2020-08-09 Thread Brian Brombacher
Hello,

I've been spending some time hacking on the TCP stack, specifically congestion 
control.  I've also spent time evaluating the NetBSD, FreeBSD, Darwin, and 
Linux TCP stacks to varying degrees.

I am wondering what approach the project is planning to use to modernize 
the congestion control algorithms.  I'm interested in assisting the project 
with development effort in this area.  I've spent time making modifications
for my own purposes and would prefer to understand the projects goals before
continuing, if possible.

Thanks,
Brian



Re: PATCH: iostat spacing

2020-08-09 Thread Sebastian Benoit
Klemens Nanni(k...@openbsd.org) on 2020.08.08 04:12:31 +0200:
> On Fri, Aug 07, 2020 at 12:04:59PM -0700, jo...@armadilloaerospace.com wrote:
> > IO rates above 100 MB/s are common with SSD; this patch expands the
> > column so it stays neatly printed.
> This is OK with me as it fixes the default view, but I think other views

ok benno@

> need fixing as well, e.g.
> 
>   $ iostat -I
>   ttysd0 sd1
> cpu
>  tin tout  KB/t   xfr MB   KB/t   xfr MB  us ni sy sp in 
> id
>   178524 22139320 26.99 10698431 281987.61  11.78 7582117 87218.82   7  0 
>  3  1  0 88
> 
> I'm testing with `dd if=/dev/rsd0c of=/dev/null bs=1m' on a X230 with
> sd0 at scsibus1 targ 0 lun 0:  
> naa.5002538d410a7bce
> 
> > An argument can be made for expanding it one more for fast M.2 drives.
> I don't have that fast disks at hand, but expanding it by another column
> makes sense to me and could further simplify some of the code.
> 



Re: pfsync: start without kernel lock

2020-08-09 Thread Vitaliy Makkoveev
On Sun, Aug 09, 2020 at 08:53:04PM +0200, Klemens Nanni wrote:
> On Sun, Aug 09, 2020 at 06:42:07PM +0300, Vitaliy Makkoveev wrote:
> > Does `IFXF_MPSAFE' bit assume that pfsyncioctl() should not rely to
> > kernel lock and pfsync(4) related data structures already have their own
> > protection?
> I say it does not.
> 
> There's PF_LOCK(), but it a) has to be enabled manually and b) is not
> specific to pfsync(4) alone.
> 
> IFXF_MPSAFE is about the driver's start routing alone, it does not
> concern the ioctl(2) path.
> 
> Does that answer your questions?
> 

Yes, thanks, `IFXF_MPSAFE' has this commentary.

I have no objections. OK mvs@. 



top: filter by routing table

2020-08-09 Thread Klemens Nanni
Sometimes I want to see processes outside the default routing table with
`-T -0', sometimes those in in a specific one with `-T 3' (for testing).

Since others have poked around with routing tables and/or domains as of
late, perhaps this deemed useful enough?

Semantically, filtering is identical to that of users: pick or hide one;
this makes the code pretty much copy/paste within top(1), manual wording
and command line flag is taken from pgrep(1).

pgrep is currently the only way to identify processes by routing table.
After netstat(1)'s relatively recent addition of `-R', filtering in top
makes for a quite handy set of tooling around rtable(4).

Feedback? OK?


Index: display.c
===
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.63
diff -u -p -r1.63 display.c
--- display.c   26 Jul 2020 21:59:16 -  1.63
+++ display.c   9 Aug 2020 17:55:56 -
@@ -824,6 +824,8 @@ show_help(void)
"r count pid  - renice process `pid' to nice value `count'\n"
"S- toggle the display of system processes\n"
"s time   - change delay between displays to `time' seconds\n"
+   "T [-]rtable  - show processes associated with routing table 
`rtable'\n"
+   "   (T+ shows all, T -rtable hides rtable)\n"
"u [-]user- show processes for `user' (u+ shows all, u -user 
hides user)\n"
"\n");
 
Index: machine.c
===
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.107
diff -u -p -r1.107 machine.c
--- machine.c   6 Jul 2020 16:27:59 -   1.107
+++ machine.c   9 Aug 2020 18:06:36 -
@@ -414,7 +414,7 @@ get_process_info(struct system_info *si,
 int (*compare) (const void *, const void *))
 {
int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd;
-   int hide_uid;
+   int show_rtable, hide_rtable, hide_uid;
int total_procs, active_procs;
struct kinfo_proc **prefp, *pp;
int what = KERN_PROC_ALL;
@@ -446,6 +446,8 @@ get_process_info(struct system_info *si,
show_uid = sel->uid != (uid_t)-1;
hide_uid = sel->huid != (uid_t)-1;
show_pid = sel->pid != (pid_t)-1;
+   show_rtable = sel->rtableid != -1;
+   hide_rtable = sel->hrtableid != -1;
show_cmd = sel->command != NULL;
 
/* count up process states and get pointers to interesting procs */
@@ -474,6 +476,8 @@ get_process_info(struct system_info *si,
(!hide_uid || pp->p_ruid != sel->huid) &&
(!show_uid || pp->p_ruid == sel->uid) &&
(!show_pid || pp->p_pid == sel->pid) &&
+   (!hide_rtable || pp->p_rtableid != sel->hrtableid) 
&&
+   (!show_rtable || pp->p_rtableid == sel->rtableid) &&
(!show_cmd || cmd_matches(pp, sel->command))) {
*prefp++ = pp;
active_procs++;
Index: machine.h
===
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.29
diff -u -p -r1.29 machine.h
--- machine.h   25 Jun 2020 20:38:41 -  1.29
+++ machine.h   9 Aug 2020 17:50:14 -
@@ -77,6 +77,8 @@ struct process_select {
uid_t   uid;/* only this uid (unless uid == -1) */
uid_t   huid;   /* hide this uid (unless huid == -1) */
pid_t   pid;/* only this pid (unless pid == -1) */
+   int rtableid;   /* only this rtable (unless rtableid == 
-1) */
+   int hrtableid;  /* hide this rtable (unless hrtableid 
== -1) */
char   *command;/* only this command (unless == NULL) */
 };
 
Index: top.1
===
RCS file: /cvs/src/usr.bin/top/top.1,v
retrieving revision 1.75
diff -u -p -r1.75 top.1
--- top.1   26 Jul 2020 21:59:16 -  1.75
+++ top.1   9 Aug 2020 18:16:12 -
@@ -38,6 +38,7 @@
 .Op Fl o Oo - Oc Ns Ar field
 .Op Fl p Ar pid
 .Op Fl s Ar time
+.Op Fl T Oo - Oc Ns Ar rtable
 .Op Fl U Oo - Oc Ns Ar user
 .Op Ar number
 .Ek
@@ -179,6 +180,14 @@ Set the delay between screen updates to
 seconds.
 The value may be fractional, to permit delays of less than 1 second.
 The default delay between updates is 5 seconds.
+.It Fl T Oo - Oc Ns Ar rtable
+Display only processes associated with the specified routing table
+.Ar rtable .
+.Sq T+
+shows processes associated with all routing tables.
+The
+.Sq -
+prefix hides proccesses associated with a single routing table.
 .It Fl U Oo - Oc Ns Ar user
 Show only those processes owned by username or UID
 .Ar user .
@@ -371,6 +380,14 @@ Toggle the display of system processes.
 Set the delay between screen updates to
 .Ar time
 

Re: pfsync: start without kernel lock

2020-08-09 Thread Klemens Nanni
On Sun, Aug 09, 2020 at 06:42:07PM +0300, Vitaliy Makkoveev wrote:
> Does `IFXF_MPSAFE' bit assume that pfsyncioctl() should not rely to
> kernel lock and pfsync(4) related data structures already have their own
> protection?
I say it does not.

There's PF_LOCK(), but it a) has to be enabled manually and b) is not
specific to pfsync(4) alone.

IFXF_MPSAFE is about the driver's start routing alone, it does not
concern the ioctl(2) path.

Does that answer your questions?



Re: pipex "idle-timeout" work with pppx(4).

2020-08-09 Thread Vitaliy Makkoveev
On Sun, Aug 09, 2020 at 06:20:13PM +0300, Vitaliy Makkoveev wrote:
> Hello Yasuoka.
> 
> You propose to unlink pppx(4) related session which reached timeout. I'm
> ok with this direction. But I see no reason to rework _get_closed()
> routines.
> 
> in pppac(4) case it's assumed what if session is not yet destroyed by
> garbage collector, it will be destroyed while we performing PIPEXGCLOSED
> command. We can make pppx(4) behavior the same and I propose to
> pppx_get_closed() be like below. 
> 
> Also, nothing requires to modify pipex_get_closed(). 
> 
>  cut begin 
> 
> pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
> {
>   struct pppx_if *pxi;
> 
>   pxi = pppx_if_find(pxd, req->pcr_session_id, req->pcr_protocol);
>   if (pxi == NULL)
>   return (EINVAL);
> 
>   memset(req, 0, sizeof(*req));
>   req->plr_ppp_id[req->plr_ppp_id_count++] = pxi->pxi_session->ppp_id;
>   pppx_if_destroy(pxi);
> 
> return 0;
> }
> 
>  cut end 
>

Sorry, I mean

pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
{
struct pppx_if  *pxi;

memset(req, 0, sizeof(*req));

while ((pxi = LIST_FIRST(>pxd_pxis))) {
if (pxi->pxi_session->state == session->state =
PIPEX_STATE_CLOSED) {
req->plr_ppp_id[req->plr_ppp_id_count++] =
pxi->pxi_session->ppp_id;
pppx_if_destroy(pxi);
}
}

return 0;
}


> Also I have one inlined comment within your diff. 
> 
> On Sun, Aug 09, 2020 at 05:14:13PM +0900, YASUOKA Masahiko wrote:
> > This diff makes pipex "idle-timeout" work with pppx(4).
> > 
> > ok?
> > 
> > Index: sys/net/if_pppx.c
> > ===
> > RCS file: /disk/cvs/openbsd/src/sys/net/if_pppx.c,v
> > retrieving revision 1.98
> > diff -u -p -r1.98 if_pppx.c
> > --- sys/net/if_pppx.c   28 Jul 2020 09:53:36 -  1.98
> > +++ sys/net/if_pppx.c   9 Aug 2020 08:05:16 -
> > @@ -185,6 +185,7 @@ int pppx_config_session(struct pppx_dev
> > struct pipex_session_config_req *);
> >  intpppx_get_stat(struct pppx_dev *,
> > struct pipex_session_stat_req *);
> > +intpppx_is_owner(void *, struct pipex_session *);
> >  intpppx_get_closed(struct pppx_dev *,
> > struct pipex_session_list_req *);
> >  intpppx_set_session_descr(struct pppx_dev *,
> > @@ -645,14 +646,6 @@ pppx_add_session(struct pppx_dev *pxd, s
> > struct in_ifaddr *ia;
> > struct sockaddr_in ifaddr;
> >  
> > -   /*
> > -* XXX: As long as `session' is allocated as part of a `pxi'
> > -*  it isn't possible to free it separately.  So disallow
> > -*  the timeout feature until this is fixed.
> > -*/
> > -   if (req->pr_timeout_sec != 0)
> > -   return (EINVAL);
> > -
> > error = pipex_init_session(, req);
> > if (error)
> > return (error);
> > @@ -812,12 +805,22 @@ pppx_get_stat(struct pppx_dev *pxd, stru
> >  }
> >  
> >  int
> > -pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
> > +pppx_is_owner(void *ctx, struct pipex_session *session)
> >  {
> > -   /* XXX: Only opened sessions exist for pppx(4) */
> > -   memset(req, 0, sizeof(*req));
> > +   struct pppx_dev *pxd = ctx;
> > +   struct pppx_if *pxi;
> >  
> > -   return 0;
> > +   pxi = pppx_if_find(pxd, session->session_id, session->protocol);
> > +   if (pxi != NULL)
> > +   return (1);
> > +
> > +   return (0);
> > +}
> > +
> > +int
> > +pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
> > +{
> > +   return (pipex_get_closed(req, pppx_is_owner, pxd));
> >  }
> >  
> >  int
> > @@ -1059,6 +1062,7 @@ static intpppac_ioctl(struct ifnet *, u
> >  static int pppac_output(struct ifnet *, struct mbuf *, struct sockaddr *,
> > struct rtentry *);
> >  static voidpppac_start(struct ifnet *);
> > +static int pppac_is_owner(void *, struct pipex_session *);
> >  
> >  static inline struct pppac_softc *
> >  pppac_lookup(dev_t dev)
> > @@ -1251,6 +1255,16 @@ pppacwrite(dev_t dev, struct uio *uio, i
> >  }
> >  
> >  int
> > +pppac_is_owner(void *ctx, struct pipex_session *session)
> > +{
> > +   struct pppac_softc *sc = ctx;
> > +
> > +   if (session->ifindex == sc->sc_if.if_index)
> > +   return (1);
> > +   return (0);
> > +}
> > +
> > +int
> >  pppacioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
> >  {
> > struct pppac_softc *sc = pppac_lookup(dev);
> > @@ -1264,6 +1278,13 @@ pppacioctl(dev_t dev, u_long cmd, caddr_
> > break;
> > case FIONREAD:
> > *(int *)data = mq_hdatalen(>sc_mq);
> > +   break;
> > +
> > +   case PIPEXGCLOSED:
> > +   NET_LOCK();
> > +  

Re: pfsync: start without kernel lock

2020-08-09 Thread Vitaliy Makkoveev
On Sun, Aug 09, 2020 at 02:33:01PM +0200, Klemens Nanni wrote:
> mvs's vnet(4) diff reminded me of pfsync(4).
> 
> This works on my my pair of amd64 firewalls.
> 
> Feedback? OK?
> 

Does `IFXF_MPSAFE' bit assume that pfsyncioctl() should not rely to
kernel lock and pfsync(4) related data structures already have their own
protection?

> 
> Index: if_pfsync.c
> ===
> RCS file: /cvs/src/sys/net/if_pfsync.c,v
> retrieving revision 1.275
> diff -u -p -r1.275 if_pfsync.c
> --- if_pfsync.c   29 Jul 2020 12:08:15 -  1.275
> +++ if_pfsync.c   9 Aug 2020 00:52:41 -
> @@ -253,7 +253,7 @@ void  pfsync_update_net_tdb(struct pfsync
>  int  pfsyncoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
>   struct rtentry *);
>  int  pfsyncioctl(struct ifnet *, u_long, caddr_t);
> -void pfsyncstart(struct ifnet *);
> +void pfsyncstart(struct ifqueue *);
>  void pfsync_syncdev_state(void *);
>  void pfsync_ifdetach(void *);
>  
> @@ -339,12 +339,12 @@ pfsync_clone_create(struct if_clone *ifc
>   ifp->if_softc = sc;
>   ifp->if_ioctl = pfsyncioctl;
>   ifp->if_output = pfsyncoutput;
> - ifp->if_start = pfsyncstart;
> + ifp->if_qstart = pfsyncstart;
>   ifp->if_type = IFT_PFSYNC;
>   ifq_set_maxlen(>if_snd, IFQ_MAXLEN);
>   ifp->if_hdrlen = sizeof(struct pfsync_header);
>   ifp->if_mtu = ETHERMTU;
> - ifp->if_xflags = IFXF_CLONED;
> + ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
>   timeout_set_proc(>sc_tmo, pfsync_timeout, NULL);
>   timeout_set_proc(>sc_bulk_tmo, pfsync_bulk_update, NULL);
>   timeout_set_proc(>sc_bulkfail_tmo, pfsync_bulk_fail, NULL);
> @@ -418,9 +418,9 @@ pfsync_clone_destroy(struct ifnet *ifp)
>   * Start output on the pfsync interface.
>   */
>  void
> -pfsyncstart(struct ifnet *ifp)
> +pfsyncstart(struct ifqueue *ifq)
>  {
> - ifq_purge(>if_snd);
> + ifq_purge(ifq);
>  }
>  
>  void
> 



Re: process: annotate locking for setitimer(2) state

2020-08-09 Thread Mark Kettenis
> Date: Sun, 9 Aug 2020 10:02:38 -0500
> From: Scott Cheloha 
> 
> On Sun, Aug 09, 2020 at 04:43:24PM +0200, Mark Kettenis wrote:
> > > Date: Sat, 8 Aug 2020 19:46:14 -0500
> > > From: Scott Cheloha 
> > > 
> > > Hi,
> > > 
> > > I want to annotate the locking for the per-process interval timers.
> > > 
> > > In the process struct, the ITIMER_REAL itimerspec and the ps_itimer_to
> > > timeout are protected by the kernel lock.  These should be annotated
> > > with "K", right?
> > > 
> > > Also in the process struct, the ITIMER_VIRTUAL and ITIMER_PROF
> > > itimerspecs are protected by the global itimer_mtx.
> > > 
> > > However, I don't think "itimer_mtx" isn't the best name for it, as it
> > > doesn't protect state for *all* per-process interval timers.  Just the
> > > virtual ones.
> > > 
> > > Could I rename the mutex to "virtual_itimer_mtx"?  Then I can annotate
> > > the state protected by it with "V", as shown here in this patch.
> > 
> > That's quite a long variable name though.  And it also protects
> > ITIMER_PROF.  So I'd say the name would be at least as misleading as
> > the current one and perhaps even more so.  You can just use "I" as the
> > annotation perhaps?
> 
> The convention is to use "I" for immutable variables.  We do it
> everywhere.  I don't think we should buck convention here.
> 
> I also proposed using "i" in a prior patch to annotate these
> variables, but mpi@ said it was too close to "I".  Also, it's a global
> lock, and we have settled on only annotate global locks with capital
> letters.
> 
> If you don't want to rename the mutex I guess we could use "T" for
> "timer".  We use "T" for other global locks (tc_lock, timeout_mutex)
> but not in this context.
> 
> However, there are only so many letters.  Eventually this scheme will
> run afoul of that limitation.  An idea I had re. the letter shortage
> was to use two letters where necessary.  So instead of "I" you could
> use "It" for "itimer".  We annotate locking hierarchies with commas so
> there isn't an ambiguity when reading it.
> 
> For example, if the code for writing a hypothetical "ps_foo" process
> struct member was:
> 
>   KERNEL_LOCK();
>   mtx_enter(_mtx);
>   ps.ps_foo = 10;
>   mtx_leave(_mtx);
>   KERNEL_UNLOCK();
> 
> You could annotate it like this:
> 
> /*
>  * Locks used to protect process struct members:
>  *
>  *It  itimer_mtx
>  *K   kernel lock
>  */
> struct process {
>   /* [...] */
>   int ps_foo; /* [K,It] per-process foobar */
>   /* [...] */
> };
> 
> anton@, mpi@: is that too radical or easily misread?
> 
> Sorry if this all seems fussy, but I'd like to get this right the
> first time.

'T' is fine with me.  But I'm clearly not an authority here.  Anyway,
renaming variables because you don't have a matching letter to
annotate the lock doesn't feel right.



Re: pipex "idle-timeout" work with pppx(4).

2020-08-09 Thread Vitaliy Makkoveev
Hello Yasuoka.

You propose to unlink pppx(4) related session which reached timeout. I'm
ok with this direction. But I see no reason to rework _get_closed()
routines.

in pppac(4) case it's assumed what if session is not yet destroyed by
garbage collector, it will be destroyed while we performing PIPEXGCLOSED
command. We can make pppx(4) behavior the same and I propose to
pppx_get_closed() be like below. 

Also, nothing requires to modify pipex_get_closed(). 

 cut begin 

pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
{
struct pppx_if *pxi;

pxi = pppx_if_find(pxd, req->pcr_session_id, req->pcr_protocol);
if (pxi == NULL)
return (EINVAL);

memset(req, 0, sizeof(*req));
req->plr_ppp_id[req->plr_ppp_id_count++] = pxi->pxi_session->ppp_id;
pppx_if_destroy(pxi);

return 0;
}

 cut end 

Also I have one inlined comment within your diff. 

On Sun, Aug 09, 2020 at 05:14:13PM +0900, YASUOKA Masahiko wrote:
> This diff makes pipex "idle-timeout" work with pppx(4).
> 
> ok?
> 
> Index: sys/net/if_pppx.c
> ===
> RCS file: /disk/cvs/openbsd/src/sys/net/if_pppx.c,v
> retrieving revision 1.98
> diff -u -p -r1.98 if_pppx.c
> --- sys/net/if_pppx.c 28 Jul 2020 09:53:36 -  1.98
> +++ sys/net/if_pppx.c 9 Aug 2020 08:05:16 -
> @@ -185,6 +185,7 @@ int   pppx_config_session(struct pppx_dev
>   struct pipex_session_config_req *);
>  int  pppx_get_stat(struct pppx_dev *,
>   struct pipex_session_stat_req *);
> +int  pppx_is_owner(void *, struct pipex_session *);
>  int  pppx_get_closed(struct pppx_dev *,
>   struct pipex_session_list_req *);
>  int  pppx_set_session_descr(struct pppx_dev *,
> @@ -645,14 +646,6 @@ pppx_add_session(struct pppx_dev *pxd, s
>   struct in_ifaddr *ia;
>   struct sockaddr_in ifaddr;
>  
> - /*
> -  * XXX: As long as `session' is allocated as part of a `pxi'
> -  *  it isn't possible to free it separately.  So disallow
> -  *  the timeout feature until this is fixed.
> -  */
> - if (req->pr_timeout_sec != 0)
> - return (EINVAL);
> -
>   error = pipex_init_session(, req);
>   if (error)
>   return (error);
> @@ -812,12 +805,22 @@ pppx_get_stat(struct pppx_dev *pxd, stru
>  }
>  
>  int
> -pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
> +pppx_is_owner(void *ctx, struct pipex_session *session)
>  {
> - /* XXX: Only opened sessions exist for pppx(4) */
> - memset(req, 0, sizeof(*req));
> + struct pppx_dev *pxd = ctx;
> + struct pppx_if *pxi;
>  
> - return 0;
> + pxi = pppx_if_find(pxd, session->session_id, session->protocol);
> + if (pxi != NULL)
> + return (1);
> +
> + return (0);
> +}
> +
> +int
> +pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
> +{
> + return (pipex_get_closed(req, pppx_is_owner, pxd));
>  }
>  
>  int
> @@ -1059,6 +1062,7 @@ static int  pppac_ioctl(struct ifnet *, u
>  static int   pppac_output(struct ifnet *, struct mbuf *, struct sockaddr *,
>   struct rtentry *);
>  static void  pppac_start(struct ifnet *);
> +static int   pppac_is_owner(void *, struct pipex_session *);
>  
>  static inline struct pppac_softc *
>  pppac_lookup(dev_t dev)
> @@ -1251,6 +1255,16 @@ pppacwrite(dev_t dev, struct uio *uio, i
>  }
>  
>  int
> +pppac_is_owner(void *ctx, struct pipex_session *session)
> +{
> + struct pppac_softc *sc = ctx;
> +
> + if (session->ifindex == sc->sc_if.if_index)
> + return (1);
> + return (0);
> +}
> +
> +int
>  pppacioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
>  {
>   struct pppac_softc *sc = pppac_lookup(dev);
> @@ -1264,6 +1278,13 @@ pppacioctl(dev_t dev, u_long cmd, caddr_
>   break;
>   case FIONREAD:
>   *(int *)data = mq_hdatalen(>sc_mq);
> + break;
> +
> + case PIPEXGCLOSED:
> + NET_LOCK();
> + error = pipex_get_closed((struct pipex_session_list_req *)data,
> + pppac_is_owner, sc);
> + NET_UNLOCK();
>   break;
>  
>   default:
> Index: sys/net/pipex.c
> ===
> RCS file: /disk/cvs/openbsd/src/sys/net/pipex.c,v
> retrieving revision 1.123
> diff -u -p -r1.123 pipex.c
> --- sys/net/pipex.c   4 Aug 2020 09:32:05 -   1.123
> +++ sys/net/pipex.c   9 Aug 2020 08:05:16 -
> @@ -240,11 +240,6 @@ pipex_ioctl(struct pipex_iface_context *
>   pipex_iface);
>   break;
>  
> - case PIPEXGCLOSED:
> - ret = pipex_get_closed((struct pipex_session_list_req *)data,
> - pipex_iface);
> - break;
> -
>   default:

Re: PATCH: better error return for exFAT filesystem

2020-08-09 Thread Ted Unangst
On 2020-08-09, Jonathan Gray wrote:
> mount_msdos(8) knows about EINVAL and will print "not an MSDOS filesystem"

I think mount_msdos could also inspect the filesytem for the common case of
exfat confusion.

Index: mount_msdos.c
===
RCS file: /home/cvs/src/sbin/mount_msdos/mount_msdos.c,v
retrieving revision 1.34
diff -u -p -r1.34 mount_msdos.c
--- mount_msdos.c   28 Jun 2019 13:32:45 -  1.34
+++ mount_msdos.c   9 Aug 2020 15:10:08 -
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -58,6 +59,7 @@ gid_t a_gid(char *);
 uid_t  a_uid(char *);
 mode_t a_mask(char *);
 void   usage(void);
+intcheckexfat(const char *);
 
 int
 main(int argc, char **argv)
@@ -140,6 +142,9 @@ main(int argc, char **argv)
case EINVAL:
errcause =
"not an MSDOS filesystem";
+   if (checkexfat(dev)) {
+   errcause = "exFAT is not supported";
+   }
break;
default:
errcause = strerror(errno);
@@ -204,4 +209,20 @@ usage(void)
fprintf(stderr,
"usage: mount_msdos [-9ls] [-g gid] [-m mask] [-o options] [-u uid] 
special node\n");
exit(1);
+}
+
+int
+checkexfat(const char *dev)
+{
+   char buf[4096];
+   int fd;
+
+   fd = open(dev, O_RDONLY);
+   if (fd != -1) {
+   ssize_t amt = read(fd, buf, sizeof(buf));
+   close(fd);
+   if (amt >= 11 && memcmp(buf + 3, "EXFAT   ", 8) == 0)
+   return 1;
+   }
+   return 0;
 }



Reduce kqueue_scan()'s stack usage

2020-08-09 Thread Visa Hankala
sys_kevent() and kqueue_scan() consume a relatively large amount of
kernel stack space, 352 and 544 bytes, respectively, on amd64. The
portion of kqueue_scan() can be reduced by 256 bytes to 288 bytes
by reusing sys_kevent()'s kev[] array.

This diff overlaps with the non-committed kqueue_scan() refactoring.
However, there is an unsolved system hang issue with the related
kqueue_scan_state patch. The change below reduces the likelihood of
kernel stack exhaustion, though it is unlikely that it would help with
the hang. I think the reduction of stack usage is useful in itself,
however.

The added asserts state that the retry branch should be taken only
if no events have been collected.

OK?

Index: kern/kern_event.c
===
RCS file: src/sys/kern/kern_event.c,v
retrieving revision 1.141
diff -u -p -r1.141 kern_event.c
--- kern/kern_event.c   4 Jul 2020 08:33:43 -   1.141
+++ kern/kern_event.c   9 Aug 2020 14:51:35 -
@@ -66,7 +66,7 @@ void  KQRELE(struct kqueue *);
 intkqueue_sleep(struct kqueue *, struct timespec *);
 intkqueue_scan(struct kqueue *kq, int maxevents,
struct kevent *ulistp, struct timespec *timeout,
-   struct proc *p, int *retval);
+   struct kevent *kev, struct proc *p, int *retval);
 
 intkqueue_read(struct file *, struct uio *, int);
 intkqueue_write(struct file *, struct uio *, int);
@@ -638,7 +638,7 @@ sys_kevent(struct proc *p, void *v, regi
KQREF(kq);
FRELE(fp, p);
error = kqueue_scan(kq, SCARG(uap, nevents), SCARG(uap, eventlist),
-   tsp, p, );
+   tsp, kev, p, );
KQRELE(kq);
*retval = n;
return (error);
@@ -896,12 +896,14 @@ kqueue_sleep(struct kqueue *kq, struct t
 
 int
 kqueue_scan(struct kqueue *kq, int maxevents, struct kevent *ulistp,
-struct timespec *tsp, struct proc *p, int *retval)
+struct timespec *tsp, struct kevent *kev, struct proc *p, int *retval)
 {
struct kevent *kevp;
struct knote mend, mstart, *kn;
-   int s, count, nkev = 0, error = 0;
-   struct kevent kev[KQ_NEVENTS];
+   int s, count, nkev, error = 0;
+
+   nkev = 0;
+   kevp = kev;
 
count = maxevents;
if (count == 0)
@@ -911,12 +913,14 @@ kqueue_scan(struct kqueue *kq, int maxev
memset(, 0, sizeof(mend));
 
 retry:
+   KASSERT(count == maxevents);
+   KASSERT(nkev == 0);
+
if (kq->kq_state & KQ_DYING) {
error = EBADF;
goto done;
}
 
-   kevp = [0];
s = splhigh();
if (kq->kq_count == 0) {
if (tsp != NULL && !timespecisset(tsp)) {
@@ -1019,7 +1023,7 @@ retry:
sizeof(struct kevent) * nkev);
ulistp += nkev;
nkev = 0;
-   kevp = [0];
+   kevp = kev;
s = splhigh();
if (error)
break;



Re: process: annotate locking for setitimer(2) state

2020-08-09 Thread Scott Cheloha
On Sun, Aug 09, 2020 at 04:43:24PM +0200, Mark Kettenis wrote:
> > Date: Sat, 8 Aug 2020 19:46:14 -0500
> > From: Scott Cheloha 
> > 
> > Hi,
> > 
> > I want to annotate the locking for the per-process interval timers.
> > 
> > In the process struct, the ITIMER_REAL itimerspec and the ps_itimer_to
> > timeout are protected by the kernel lock.  These should be annotated
> > with "K", right?
> > 
> > Also in the process struct, the ITIMER_VIRTUAL and ITIMER_PROF
> > itimerspecs are protected by the global itimer_mtx.
> > 
> > However, I don't think "itimer_mtx" isn't the best name for it, as it
> > doesn't protect state for *all* per-process interval timers.  Just the
> > virtual ones.
> > 
> > Could I rename the mutex to "virtual_itimer_mtx"?  Then I can annotate
> > the state protected by it with "V", as shown here in this patch.
> 
> That's quite a long variable name though.  And it also protects
> ITIMER_PROF.  So I'd say the name would be at least as misleading as
> the current one and perhaps even more so.  You can just use "I" as the
> annotation perhaps?

The convention is to use "I" for immutable variables.  We do it
everywhere.  I don't think we should buck convention here.

I also proposed using "i" in a prior patch to annotate these
variables, but mpi@ said it was too close to "I".  Also, it's a global
lock, and we have settled on only annotate global locks with capital
letters.

If you don't want to rename the mutex I guess we could use "T" for
"timer".  We use "T" for other global locks (tc_lock, timeout_mutex)
but not in this context.

However, there are only so many letters.  Eventually this scheme will
run afoul of that limitation.  An idea I had re. the letter shortage
was to use two letters where necessary.  So instead of "I" you could
use "It" for "itimer".  We annotate locking hierarchies with commas so
there isn't an ambiguity when reading it.

For example, if the code for writing a hypothetical "ps_foo" process
struct member was:

KERNEL_LOCK();
mtx_enter(_mtx);
ps.ps_foo = 10;
mtx_leave(_mtx);
KERNEL_UNLOCK();

You could annotate it like this:

/*
 * Locks used to protect process struct members:
 *
 *  It  itimer_mtx
 *  K   kernel lock
 */
struct process {
/* [...] */
int ps_foo; /* [K,It] per-process foobar */
/* [...] */
};

anton@, mpi@: is that too radical or easily misread?

Sorry if this all seems fussy, but I'd like to get this right the
first time.

-Scott



Re: hardclock(9): fix race with setitimer(2)

2020-08-09 Thread Mark Kettenis
> Date: Sun, 9 Aug 2020 06:54:53 -0500
> From: Scott Cheloha 
> 
> Hi,
> 
> We update the ITIMER_VIRTUAL and ITIMER_PROF per-process interval
> timers from hardclock(9).  If a timer is enabled we call itimerdecr()
> to update and reload it as needed.  If a timer has expired we then set
> a flag on the current thread to signal itself when returning to
> userspace.
> 
> However, there is a race here with setitimer(2).  In hardclock(9) we
> check whether a timer is enabled *before* entering itimer_mtx in
> itimerdecr(), but once we have entered the mutex we don't double-check
> that the timer is still enabled.  This is wrong.  Another thread may
> have disabled the timer via setitimer(2) while we were entering the
> mutex.
> 
> This patch adds the second check to itimerdecr().  If we lost the race
> and the timer is disabled we return 1 to indicate that the timer has
> not expired, i.e. that the thread should take no action.
> 
> ok?

ok kettenis@

> Index: kern_time.c
> ===
> RCS file: /cvs/src/sys/kern/kern_time.c,v
> retrieving revision 1.134
> diff -u -p -r1.134 kern_time.c
> --- kern_time.c   8 Aug 2020 01:01:26 -   1.134
> +++ kern_time.c   9 Aug 2020 11:47:02 -
> @@ -682,6 +682,20 @@ itimerdecr(struct itimerspec *itp, long 
>   NSEC_TO_TIMESPEC(nsec, );
>  
>   mtx_enter(_mtx);
> +
> + /*
> +  * Double-check that the timer is enabled.  We may have lost
> +  * a race with another thread in setitimer(2) when entering
> +  * itimer_mtx.
> +  */
> + if (!timespecisset(>it_value)) {
> + mtx_leave(_mtx);
> + return (1);
> + }
> +
> + /*
> +  * The timer is enabled.  Update and reload it as needed.
> +  */
>   timespecsub(>it_value, , >it_value);
>   if (itp->it_value.tv_sec >= 0 && timespecisset(>it_value)) {
>   mtx_leave(_mtx);
> 
> 



Re: process: annotate locking for setitimer(2) state

2020-08-09 Thread Mark Kettenis
> Date: Sat, 8 Aug 2020 19:46:14 -0500
> From: Scott Cheloha 
> 
> Hi,
> 
> I want to annotate the locking for the per-process interval timers.
> 
> In the process struct, the ITIMER_REAL itimerspec and the ps_itimer_to
> timeout are protected by the kernel lock.  These should be annotated
> with "K", right?
> 
> Also in the process struct, the ITIMER_VIRTUAL and ITIMER_PROF
> itimerspecs are protected by the global itimer_mtx.
> 
> However, I don't think "itimer_mtx" isn't the best name for it, as it
> doesn't protect state for *all* per-process interval timers.  Just the
> virtual ones.
> 
> Could I rename the mutex to "virtual_itimer_mtx"?  Then I can annotate
> the state protected by it with "V", as shown here in this patch.

That's quite a long variable name though.  And it also protects
ITIMER_PROF.  So I'd say the name would be at least as misleading as
the current one and perhaps even more so.  You can just use "I" as the
annotation perhaps?

> Preferences?  ok?
> 
> Index: kern/kern_time.c
> ===
> RCS file: /cvs/src/sys/kern/kern_time.c,v
> retrieving revision 1.134
> diff -u -p -r1.134 kern_time.c
> --- kern/kern_time.c  8 Aug 2020 01:01:26 -   1.134
> +++ kern/kern_time.c  9 Aug 2020 00:41:10 -
> @@ -488,7 +488,13 @@ out:
>  }
>  
>  
> -struct mutex itimer_mtx = MUTEX_INITIALIZER(IPL_CLOCK);
> +/*
> + * Global virtual interval timer mutex.
> + *
> + * Protects state for the per-process ITIMER_VIRTUAL and ITIMER_PROF
> + * interval timers.
> + */
> +struct mutex virtual_itimer_mtx = MUTEX_INITIALIZER(IPL_CLOCK);
>  
>  /*
>   * Get value of an interval timer.  The process virtual and
> @@ -526,10 +532,10 @@ sys_getitimer(struct proc *p, void *v, r
>   return (EINVAL);
>   itimer = >p_p->ps_timer[which];
>   memset(, 0, sizeof(aitv));
> - mtx_enter(_mtx);
> + mtx_enter(_itimer_mtx);
>   TIMESPEC_TO_TIMEVAL(_interval, >it_interval);
>   TIMESPEC_TO_TIMEVAL(_value, >it_value);
> - mtx_leave(_mtx);
> + mtx_leave(_itimer_mtx);
>  
>   if (which == ITIMER_REAL) {
>   struct timeval now;
> @@ -604,9 +610,9 @@ sys_setitimer(struct proc *p, void *v, r
>   }
>   pr->ps_timer[ITIMER_REAL] = aits;
>   } else {
> - mtx_enter(_mtx);
> + mtx_enter(_itimer_mtx);
>   pr->ps_timer[which] = aits;
> - mtx_leave(_mtx);
> + mtx_leave(_itimer_mtx);
>   }
>  
>   return (0);
> @@ -681,20 +687,20 @@ itimerdecr(struct itimerspec *itp, long 
>  
>   NSEC_TO_TIMESPEC(nsec, );
>  
> - mtx_enter(_mtx);
> + mtx_enter(_itimer_mtx);
>   timespecsub(>it_value, , >it_value);
>   if (itp->it_value.tv_sec >= 0 && timespecisset(>it_value)) {
> - mtx_leave(_mtx);
> + mtx_leave(_itimer_mtx);
>   return (1);
>   }
>   if (!timespecisset(>it_interval)) {
>   timespecclear(>it_value);
> - mtx_leave(_mtx);
> + mtx_leave(_itimer_mtx);
>   return (0);
>   }
>   while (itp->it_value.tv_sec < 0 || !timespecisset(>it_value))
>   timespecadd(>it_value, >it_interval, >it_value);
> - mtx_leave(_mtx);
> + mtx_leave(_itimer_mtx);
>   return (0);
>  }
>  
> Index: sys/proc.h
> ===
> RCS file: /cvs/src/sys/sys/proc.h,v
> retrieving revision 1.297
> diff -u -p -r1.297 proc.h
> --- sys/proc.h6 Jul 2020 13:33:09 -   1.297
> +++ sys/proc.h9 Aug 2020 00:41:11 -
> @@ -150,9 +150,11 @@ struct unveil;
>  /*
>   * Locks used to protect struct members in this file:
>   *   a   atomic operations
> + *   K   kernel lock
>   *   m   this process' `ps_mtx'
>   *   p   this process' `ps_lock'
>   *   R   rlimit_lock
> + *   V   virtual_itimer_mtx
>   */
>  struct process {
>   /*
> @@ -216,7 +218,8 @@ struct process {
>   struct  rusage *ps_ru;  /* sum of stats for dead threads. */
>   struct  tusage ps_tu;   /* accumulated times. */
>   struct  rusage ps_cru;  /* sum of stats for reaped children */
> - struct  itimerspec ps_timer[3]; /* timers, indexed by ITIMER_* */
> + struct  itimerspec ps_timer[3]; /* [K] ITIMER_REAL timer */
> + /* [V] ITIMER_{PROF,VIRTUAL} timers */
>   struct  timeout ps_rucheck_to;  /* [] resource limit check timer */
>   time_t  ps_nextxcpu;/* when to send next SIGXCPU, */
>   /* in seconds of process runtime */
> @@ -269,7 +272,7 @@ struct process {
>   int ps_refcnt;  /* Number of references. */
>  
>   struct  timespec ps_start;  /* starting uptime. */
> - struct  timeout ps_realit_to;   /* real-time itimer trampoline. */
> + struct  timeout ps_realit_to;   /* [K] ITIMER_REAL 

snmpd(8) Remove struct listen_sock

2020-08-09 Thread Martijn van Duren
I still want to move udp/tcp handling out of snmpe, so that there's 
better layering, but my previous diff never got any response and might  
do with some more polishing.

For now, lets remove listen_sock from snmpd, since there's a 1:1
correlation with struct address. This saves a couple of callocs during
startup and 18 LoC.

OK?

martijn@

Index: parse.y
===
RCS file: /cvs/src/usr.sbin/snmpd/parse.y,v
retrieving revision 1.58
diff -u -p -r1.58 parse.y
--- parse.y 30 Jun 2020 17:11:49 -  1.58
+++ parse.y 9 Aug 2020 14:08:18 -
@@ -997,7 +997,6 @@ parse_config(const char *filename, u_int
conf->sc_flags = flags;
conf->sc_confpath = filename;
TAILQ_INIT(>sc_addresses);
-   TAILQ_INIT(>sc_sockets);
strlcpy(conf->sc_rdcommunity, "public", SNMPD_MAXCOMMUNITYLEN);
strlcpy(conf->sc_rwcommunity, "private", SNMPD_MAXCOMMUNITYLEN);
strlcpy(conf->sc_trcommunity, "public", SNMPD_MAXCOMMUNITYLEN);
Index: snmpd.h
===
RCS file: /cvs/src/usr.sbin/snmpd/snmpd.h,v
retrieving revision 1.88
diff -u -p -r1.88 snmpd.h
--- snmpd.h 8 Aug 2020 13:39:57 -   1.88
+++ snmpd.h 9 Aug 2020 14:08:18 -
@@ -482,6 +482,9 @@ struct address {
struct sockaddr_storage  ss;
in_port_tport;
int  ipproto;
+   int  fd;
+   struct event ev;
+   struct event evt;
 
TAILQ_ENTRY(address) entry;
 
@@ -492,15 +495,6 @@ struct address {
 };
 TAILQ_HEAD(addresslist, address);
 
-struct listen_sock {
-   int s_fd;
-   int s_ipproto;
-   struct events_ev;
-   struct events_evt;
-   TAILQ_ENTRY(listen_sock)entry;
-};
-TAILQ_HEAD(socklist, listen_sock);
-
 enum usmauth {
AUTH_NONE = 0,
AUTH_MD5,   /* HMAC-MD5-96, RFC3414 */
@@ -545,7 +539,6 @@ struct snmpd {
 
const char  *sc_confpath;
struct addresslist   sc_addresses;
-   struct socklist  sc_sockets;
struct timeval   sc_starttime;
u_int32_tsc_engine_boots;
 
Index: snmpe.c
===
RCS file: /cvs/src/usr.sbin/snmpd/snmpe.c,v
retrieving revision 1.63
diff -u -p -r1.63 snmpe.c
--- snmpe.c 8 Aug 2020 13:39:57 -   1.63
+++ snmpe.c 9 Aug 2020 14:08:18 -
@@ -68,7 +68,6 @@ snmpe(struct privsep *ps, struct privsep
 {
struct snmpd*env = ps->ps_env;
struct address  *h;
-   struct listen_sock  *so;
 #ifdef DEBUG
char buf[BUFSIZ];
struct oid  *oid;
@@ -82,14 +81,9 @@ snmpe(struct privsep *ps, struct privsep
 #endif
 
/* bind SNMP UDP/TCP sockets */
-   TAILQ_FOREACH(h, >sc_addresses, entry) {
-   if ((so = calloc(1, sizeof(*so))) == NULL)
-   fatal("snmpe: %s", __func__);
-   if ((so->s_fd = snmpe_bind(h)) == -1)
+   TAILQ_FOREACH(h, >sc_addresses, entry)
+   if ((h->fd = snmpe_bind(h)) == -1)
fatal("snmpe: failed to bind SNMP socket");
-   so->s_ipproto = h->ipproto;
-   TAILQ_INSERT_TAIL(>sc_sockets, so, entry);
-   }
 
proc_run(ps, p, procs, nitems(procs), snmpe_init, NULL);
 }
@@ -99,7 +93,7 @@ void
 snmpe_init(struct privsep *ps, struct privsep_proc *p, void *arg)
 {
struct snmpd*env = ps->ps_env;
-   struct listen_sock  *so;
+   struct address  *h;
 
kr_init();
trap_init();
@@ -107,17 +101,17 @@ snmpe_init(struct privsep *ps, struct pr
usm_generate_keys();
 
/* listen for incoming SNMP UDP/TCP messages */
-   TAILQ_FOREACH(so, >sc_sockets, entry) {
-   if (so->s_ipproto == IPPROTO_TCP) {
-   if (listen(so->s_fd, 5) < 0)
+   TAILQ_FOREACH(h, >sc_addresses, entry) {
+   if (h->ipproto == IPPROTO_TCP) {
+   if (listen(h->fd, 5) < 0)
fatalx("snmpe: failed to listen on socket");
-   event_set(>s_ev, so->s_fd, EV_READ, snmpe_acceptcb, 
so);
-   evtimer_set(>s_evt, snmpe_acceptcb, so);
+   event_set(>ev, h->fd, EV_READ, snmpe_acceptcb, h);
+   evtimer_set(>evt, snmpe_acceptcb, h);
} else {
-   event_set(>s_ev, so->s_fd, EV_READ|EV_PERSIST,
+   event_set(>ev, h->fd, EV_READ|EV_PERSIST,
snmpe_recvmsg, env);
}
-   event_add(>s_ev, NULL);
+   event_add(>ev, NULL);
}
 
/* no filesystem 

pfsync: start without kernel lock

2020-08-09 Thread Klemens Nanni
mvs's vnet(4) diff reminded me of pfsync(4).

This works on my my pair of amd64 firewalls.

Feedback? OK?


Index: if_pfsync.c
===
RCS file: /cvs/src/sys/net/if_pfsync.c,v
retrieving revision 1.275
diff -u -p -r1.275 if_pfsync.c
--- if_pfsync.c 29 Jul 2020 12:08:15 -  1.275
+++ if_pfsync.c 9 Aug 2020 00:52:41 -
@@ -253,7 +253,7 @@ voidpfsync_update_net_tdb(struct pfsync
 intpfsyncoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
 intpfsyncioctl(struct ifnet *, u_long, caddr_t);
-void   pfsyncstart(struct ifnet *);
+void   pfsyncstart(struct ifqueue *);
 void   pfsync_syncdev_state(void *);
 void   pfsync_ifdetach(void *);
 
@@ -339,12 +339,12 @@ pfsync_clone_create(struct if_clone *ifc
ifp->if_softc = sc;
ifp->if_ioctl = pfsyncioctl;
ifp->if_output = pfsyncoutput;
-   ifp->if_start = pfsyncstart;
+   ifp->if_qstart = pfsyncstart;
ifp->if_type = IFT_PFSYNC;
ifq_set_maxlen(>if_snd, IFQ_MAXLEN);
ifp->if_hdrlen = sizeof(struct pfsync_header);
ifp->if_mtu = ETHERMTU;
-   ifp->if_xflags = IFXF_CLONED;
+   ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
timeout_set_proc(>sc_tmo, pfsync_timeout, NULL);
timeout_set_proc(>sc_bulk_tmo, pfsync_bulk_update, NULL);
timeout_set_proc(>sc_bulkfail_tmo, pfsync_bulk_fail, NULL);
@@ -418,9 +418,9 @@ pfsync_clone_destroy(struct ifnet *ifp)
  * Start output on the pfsync interface.
  */
 void
-pfsyncstart(struct ifnet *ifp)
+pfsyncstart(struct ifqueue *ifq)
 {
-   ifq_purge(>if_snd);
+   ifq_purge(ifq);
 }
 
 void



Re: video -c: showing auto white balance temperature

2020-08-09 Thread Laurence Tratt
On Sat, Aug 08, 2020 at 11:29:41PM +0200, Marcus Glocker wrote:

Hello Marcus,

 One other thing has occurred to me -- but can be done in a future patch
 -- is that we probably want to be able to do:

   $ video white_balance_temperature=auto

Please find attached a patch which does this. It also makes setting auto
controls more generic for if/when we gain more. If you set (say)
"saturation=auto" we warn, but don't error. So for example:

  $ video -d
  $ video white_balance_temperature=3000
  white_balance_temperature: auto -> 3000
  $ video white_balance_temperature=auto
  white_balance_temperature: 3000 -> auto
  $ video white_balance_temperature=auto
  white_balance_temperature: auto -> auto
  $ video white_balance_temperature=3000 saturation=auto
  white_balance_temperature: auto -> 3000
  saturation: no automatic control found


Laurie


Index: video.c
===
RCS file: /cvs/xenocara/app/video/video.c,v
retrieving revision 1.35
diff -u -r1.35 video.c
--- video.c 9 Aug 2020 06:51:04 -   1.35
+++ video.c 9 Aug 2020 11:58:35 -
@@ -219,8 +219,8 @@
 int dev_init(struct video *);
 int dev_set_ctrl_abs(struct video *vid, int, int);
 void dev_set_ctrl_rel(struct video *, int, int);
-void dev_set_ctrl_auto_white_balance(struct video *, int, int);
 int dev_get_ctrl_auto(struct video *, int);
+void dev_set_ctrl_auto(struct video *, int, int, int);
 void dev_reset_ctrls(struct video *);
 
 int parse_ctrl(struct video *, int, char **);
@@ -1037,7 +1037,7 @@
 * The spec requires auto-white balance to be off before
 * we can set the white balance temperature.
 */
-   dev_set_ctrl_auto_white_balance(vid, 0, 0);
+   dev_set_ctrl_auto(vid, ctrl, 0, 0);
}
if (val > ctrls[ctrl].max)
val = ctrls[ctrl].max;
@@ -1082,12 +1082,15 @@
 }
 
 void
-dev_set_ctrl_auto_white_balance(struct video *vid, int value, int reset)
+dev_set_ctrl_auto(struct video *vid, int ctrl, int value, int reset)
 {
struct dev *d = >dev;
struct v4l2_control control;
 
-   control.id = V4L2_CID_AUTO_WHITE_BALANCE;
+   if (!ctrls[ctrl].id_auto)
+   return;
+
+   control.id = ctrls[ctrl].id_auto;
if (ioctl(d->fd, VIDIOC_G_CTRL, ) != 0) {
warn("VIDIOC_G_CTRL");
return;
@@ -1134,8 +1137,7 @@
if (!ctrls[i].supported)
continue;
dev_set_ctrl_abs(vid, i, ctrls[i].def);
-   if (i == CTRL_WHITE_BALANCE_TEMPERATURE)
-   dev_set_ctrl_auto_white_balance(vid, 1, 0);
+   dev_set_ctrl_auto(vid, i, 1, 0);
}
 }
 
@@ -1303,7 +1305,7 @@
}
}
if (i == CTRL_LAST)
-   warnx("%s: unknown control", *argv);
+   warnx("%s: unknown control", *argv);
continue;
}
 
@@ -1315,21 +1317,34 @@
warnx("%s: no value", *argv);
break;
}
-   val_new = strtonum(p, -32768, 32768, );
-   if (errstr != NULL) {
-   warnx("%s: %s", *argv, errstr);
-   return 0;
-   }
-   val_old = ctrls[i].cur;
auto_old = dev_get_ctrl_auto(vid, i);
-   if (dev_set_ctrl_abs(vid, i, val_new) == 0) {
-   if (auto_old) {
-   fprintf(stderr, "%s: auto -> %d\n",
-   ctrls[i].name, ctrls[i].cur);
+   val_old = ctrls[i].cur;
+   if (strcmp(p, "auto") == 0) {
+   if (ctrls[i].id_auto == 0) {
+   fprintf(stderr, "%s: no automatic 
control found\n",
+   ctrls[i].name);
+   } else if (!auto_old) {
+   fprintf(stderr, "%s: %d -> auto\n",
+   ctrls[i].name, val_old);
+   dev_set_ctrl_auto(vid, i, 1, 0);
} else {
-   fprintf(stderr, "%s: %d -> %d\n",
-   ctrls[i].name, val_old,
-   ctrls[i].cur);
+   fprintf(stderr, "%s: auto -> auto\n", 
ctrls[i].name);
+   }
+   } else {
+   val_new = strtonum(p, -32768, 32768, );
+   if (errstr != NULL) 

hardclock(9): fix race with setitimer(2)

2020-08-09 Thread Scott Cheloha
Hi,

We update the ITIMER_VIRTUAL and ITIMER_PROF per-process interval
timers from hardclock(9).  If a timer is enabled we call itimerdecr()
to update and reload it as needed.  If a timer has expired we then set
a flag on the current thread to signal itself when returning to
userspace.

However, there is a race here with setitimer(2).  In hardclock(9) we
check whether a timer is enabled *before* entering itimer_mtx in
itimerdecr(), but once we have entered the mutex we don't double-check
that the timer is still enabled.  This is wrong.  Another thread may
have disabled the timer via setitimer(2) while we were entering the
mutex.

This patch adds the second check to itimerdecr().  If we lost the race
and the timer is disabled we return 1 to indicate that the timer has
not expired, i.e. that the thread should take no action.

ok?

Index: kern_time.c
===
RCS file: /cvs/src/sys/kern/kern_time.c,v
retrieving revision 1.134
diff -u -p -r1.134 kern_time.c
--- kern_time.c 8 Aug 2020 01:01:26 -   1.134
+++ kern_time.c 9 Aug 2020 11:47:02 -
@@ -682,6 +682,20 @@ itimerdecr(struct itimerspec *itp, long 
NSEC_TO_TIMESPEC(nsec, );
 
mtx_enter(_mtx);
+
+   /*
+* Double-check that the timer is enabled.  We may have lost
+* a race with another thread in setitimer(2) when entering
+* itimer_mtx.
+*/
+   if (!timespecisset(>it_value)) {
+   mtx_leave(_mtx);
+   return (1);
+   }
+
+   /*
+* The timer is enabled.  Update and reload it as needed.
+*/
timespecsub(>it_value, , >it_value);
if (itp->it_value.tv_sec >= 0 && timespecisset(>it_value)) {
mtx_leave(_mtx);



Re: PATCH: better error return for exFAT filesystem

2020-08-09 Thread Klemens Nanni
On Sun, Aug 09, 2020 at 07:48:21PM +1000, Jonathan Gray wrote:
> Thinking about this some more the problem is really the choice of errno.
> It used to be EINVAL but was changed to EFTYPE in
> 
> 
> revision 1.7
> date: 1997/06/20 14:04:30;  author: kstailey;  state: Exp;  lines: +7 -7;
> Change errno cause by mounting invalid filesystems from EINVAL to EFTYPE.
> 
> 
> mount_msdos(8) knows about EINVAL and will print "not an MSDOS filesystem"
> 
> On reading mount(2) EOPNOTSUPP would be suitable for when the kernel
> did not have msdos support built in not when the blocks found are not
> msdos.
> 
> So either mount_msdos gains a EFTYPE case or we go back to EINVAL.
Reverting EFTYPE makes sense to me and having mount_msdos say
"not an MSDOS filesystem" on exFAT is an improvement.

OK kn



[Patch] Change httpd's handling of request "Host:" headers

2020-08-09 Thread Ross L Richardson


At present, if a request contains no "Host:" header [HTTP pre-1.1] or
if the supplied header does not match any of the servers configured
in httpd.conf, the request is directed to the first server.  This
isn't documented, AFAICT.

For example, if httpd.conf has just one server
server "www.example.com"
then we currently get
$ printf "HEAD / HTTP/1.0\r\nHost: www.openbsd.org\r\n\r\n" \
| nc www.example.com www | sed 1q 
HTTP/1.0 200 OK

This behaviour strikes me as wrong (or at least sub-optimal) in the
case of non-matching "Host:" headers.  The simplistic patch below
changes things to return a 404 status if no matching server is found.

[If status code 400 (bad request) is preferred, "goto fail;"
could be used.]

Justification:
- This seems more correct, and is consistent with the "fail closed"
  approach.
- There is a net gain in functionality, as use of glob/patterns
  wildcards can easily re-establish the current behaviour.  In
  contrast, there's no way at present to disable the implicit
  match-anything behaviour.

If this is adopted, it should be document in current.html
A followup patch could merge this if statement with the one above it.

Several other issues exist in "Host:" header handling.

Ross
--

Index: server_http.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.140
diff -u -p -r1.140 server_http.c
--- server_http.c   3 Aug 2020 10:59:53 -   1.140
+++ server_http.c   9 Aug 2020 04:37:08 -
@@ -1200,7 +1200,7 @@ server_response(struct httpd *httpd, str
struct server_config*srv_conf = >srv_conf;
struct kv   *kv, key, *host;
struct str_find  sm;
-   int  portval = -1, ret;
+   int  hostmatch = 0, portval = -1, ret;
char*hostval, *query;
const char  *errstr = NULL;
 
@@ -1277,16 +1277,20 @@ server_response(struct httpd *httpd, str
/* Replace host configuration */
clt->clt_srv_conf = srv_conf;
srv_conf = NULL;
+   hostmatch = 1;
break;
}
}
}
 
-   if (srv_conf != NULL) {
+   if (host == NULL) {
/* Use the actual server IP address */
if (server_http_host(>clt_srv_ss, hostname,
sizeof(hostname)) == NULL)
goto fail;
+   } else if (!hostmatch) {
+   server_abort_http(clt, 404, "not found");
+   return (-1);
} else {
/* Host header was valid and found */
if (strlcpy(hostname, host->kv_value, sizeof(hostname)) >=



Re: PATCH: better error return for exFAT filesystem

2020-08-09 Thread Jonathan Gray
On Sat, Aug 08, 2020 at 01:13:20PM +1000, Jonathan Gray wrote:
> On Fri, Aug 07, 2020 at 12:59:00PM -0700, jo...@armadilloaerospace.com wrote:
> > Perform an explicit check for the unsupported exFAT MSDOS filesystem
> > instead of letting it fail mysteriously when it gets cluster sizes
> > of 0 from the normal fields.
> > 
> > This causes mount_msdos to report:
> > mount_msdos: /dev/sd1i on /root/mnt: filesystem not supported by kernel
> > 
> > Instead of the more obscure:
> > mount_msdos: /dev/sd1i on /root/mnt: Inapropriate file type or format
> > 
> > Index: msdosfs_vfsops.c
> > ===
> > RCS file: /cvs/src/sys/msdosfs/msdosfs_vfsops.c,v
> > retrieving revision 1.93
> > diff -u -p -r1.93 msdosfs_vfsops.c
> > --- msdosfs_vfsops.c24 Jan 2020 03:49:34 -  1.93
> > +++ msdosfs_vfsops.c7 Aug 2020 19:52:04 -
> > @@ -298,6 +298,12 @@ msdosfs_mountfs(struct vnode *devvp, str
> > b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
> > b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB;
> >  
> > +   /* No support for exFAT filesystems */
> > +   if (!strncmp("EXFAT", bsp->bs33.bsOemName, 5)) {
> > +   error = EOPNOTSUPP;
> > +   goto error_exit;
> > +   }
> > +
> > pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK | M_ZERO);
> > pmp->pm_mountp = mp;
> 
> The microsoft specification states it is EXFAT followed by three spaces
> 
>   if (!memcmp("EXFAT   ", bsp->bs33.bsOemName, 8)) {
> 
> may be more suitable here.

Thinking about this some more the problem is really the choice of errno.
It used to be EINVAL but was changed to EFTYPE in


revision 1.7
date: 1997/06/20 14:04:30;  author: kstailey;  state: Exp;  lines: +7 -7;
Change errno cause by mounting invalid filesystems from EINVAL to EFTYPE.


mount_msdos(8) knows about EINVAL and will print "not an MSDOS filesystem"

On reading mount(2) EOPNOTSUPP would be suitable for when the kernel
did not have msdos support built in not when the blocks found are not
msdos.

So either mount_msdos gains a EFTYPE case or we go back to EINVAL.

Index: sys/msdosfs/msdosfs_vfsops.c
===
RCS file: /cvs/src/sys/msdosfs/msdosfs_vfsops.c,v
retrieving revision 1.93
diff -u -p -r1.93 msdosfs_vfsops.c
--- sys/msdosfs/msdosfs_vfsops.c24 Jan 2020 03:49:34 -  1.93
+++ sys/msdosfs/msdosfs_vfsops.c9 Aug 2020 09:22:31 -
@@ -321,7 +321,7 @@ msdosfs_mountfs(struct vnode *devvp, str
pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
 
if (!pmp->pm_BytesPerSec || !SecPerClust) {
-   error = EFTYPE;
+   error = EINVAL;
goto error_exit;
}
 
@@ -451,7 +451,7 @@ msdosfs_mountfs(struct vnode *devvp, str
 * must be a power of 2
 */
if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
-   error = EFTYPE;
+   error = EINVAL;
goto error_exit;
}
 
Index: sys/ufs/ffs/ffs_vfsops.c
===
RCS file: /cvs/src/sys/ufs/ffs/ffs_vfsops.c,v
retrieving revision 1.185
diff -u -p -r1.185 ffs_vfsops.c
--- sys/ufs/ffs/ffs_vfsops.c24 Jun 2020 22:03:45 -  1.185
+++ sys/ufs/ffs/ffs_vfsops.c9 Aug 2020 09:24:58 -
@@ -754,14 +754,6 @@ ffs_mountfs(struct vnode *devvp, struct 
fs = (struct fs *) bp->b_data;
sbloc = sbtry[i];
 
-#if 0
-   if (fs->fs_magic == FS_UFS2_MAGIC) {
-   printf("ffs_mountfs(): Sorry, no UFS2 support (yet)\n");
-   error = EFTYPE;
-   goto out;
-   }
-#endif
-
/*
 * Do not look for an FFS1 file system at SBLOCK_UFS2. Doing so
 * will find the wrong super-block for file systems with 64k
@@ -813,7 +805,7 @@ ffs_mountfs(struct vnode *devvp, struct 
printf("ffs_mountfs(): obsolete rotational table format, "
"please use fsck_ffs(8) -c 1\n");
 #endif
-   error = EFTYPE;
+   error = EINVAL;
goto out;
}
 



pipex "idle-timeout" work with pppx(4).

2020-08-09 Thread YASUOKA Masahiko
This diff makes pipex "idle-timeout" work with pppx(4).

ok?

Index: sys/net/if_pppx.c
===
RCS file: /disk/cvs/openbsd/src/sys/net/if_pppx.c,v
retrieving revision 1.98
diff -u -p -r1.98 if_pppx.c
--- sys/net/if_pppx.c   28 Jul 2020 09:53:36 -  1.98
+++ sys/net/if_pppx.c   9 Aug 2020 08:05:16 -
@@ -185,6 +185,7 @@ int pppx_config_session(struct pppx_dev
struct pipex_session_config_req *);
 intpppx_get_stat(struct pppx_dev *,
struct pipex_session_stat_req *);
+intpppx_is_owner(void *, struct pipex_session *);
 intpppx_get_closed(struct pppx_dev *,
struct pipex_session_list_req *);
 intpppx_set_session_descr(struct pppx_dev *,
@@ -645,14 +646,6 @@ pppx_add_session(struct pppx_dev *pxd, s
struct in_ifaddr *ia;
struct sockaddr_in ifaddr;
 
-   /*
-* XXX: As long as `session' is allocated as part of a `pxi'
-*  it isn't possible to free it separately.  So disallow
-*  the timeout feature until this is fixed.
-*/
-   if (req->pr_timeout_sec != 0)
-   return (EINVAL);
-
error = pipex_init_session(, req);
if (error)
return (error);
@@ -812,12 +805,22 @@ pppx_get_stat(struct pppx_dev *pxd, stru
 }
 
 int
-pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
+pppx_is_owner(void *ctx, struct pipex_session *session)
 {
-   /* XXX: Only opened sessions exist for pppx(4) */
-   memset(req, 0, sizeof(*req));
+   struct pppx_dev *pxd = ctx;
+   struct pppx_if *pxi;
 
-   return 0;
+   pxi = pppx_if_find(pxd, session->session_id, session->protocol);
+   if (pxi != NULL)
+   return (1);
+
+   return (0);
+}
+
+int
+pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
+{
+   return (pipex_get_closed(req, pppx_is_owner, pxd));
 }
 
 int
@@ -1059,6 +1062,7 @@ static intpppac_ioctl(struct ifnet *, u
 static int pppac_output(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
 static voidpppac_start(struct ifnet *);
+static int pppac_is_owner(void *, struct pipex_session *);
 
 static inline struct pppac_softc *
 pppac_lookup(dev_t dev)
@@ -1251,6 +1255,16 @@ pppacwrite(dev_t dev, struct uio *uio, i
 }
 
 int
+pppac_is_owner(void *ctx, struct pipex_session *session)
+{
+   struct pppac_softc *sc = ctx;
+
+   if (session->ifindex == sc->sc_if.if_index)
+   return (1);
+   return (0);
+}
+
+int
 pppacioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
 {
struct pppac_softc *sc = pppac_lookup(dev);
@@ -1264,6 +1278,13 @@ pppacioctl(dev_t dev, u_long cmd, caddr_
break;
case FIONREAD:
*(int *)data = mq_hdatalen(>sc_mq);
+   break;
+
+   case PIPEXGCLOSED:
+   NET_LOCK();
+   error = pipex_get_closed((struct pipex_session_list_req *)data,
+   pppac_is_owner, sc);
+   NET_UNLOCK();
break;
 
default:
Index: sys/net/pipex.c
===
RCS file: /disk/cvs/openbsd/src/sys/net/pipex.c,v
retrieving revision 1.123
diff -u -p -r1.123 pipex.c
--- sys/net/pipex.c 4 Aug 2020 09:32:05 -   1.123
+++ sys/net/pipex.c 9 Aug 2020 08:05:16 -
@@ -240,11 +240,6 @@ pipex_ioctl(struct pipex_iface_context *
pipex_iface);
break;
 
-   case PIPEXGCLOSED:
-   ret = pipex_get_closed((struct pipex_session_list_req *)data,
-   pipex_iface);
-   break;
-
default:
ret = ENOTTY;
break;
@@ -430,6 +425,7 @@ pipex_link_session(struct pipex_session 
struct pipex_iface_context *iface)
 {
struct pipex_hash_head *chain;
+   struct ifnet *ifp;
 
NET_ASSERT_LOCKED();
 
@@ -442,6 +438,11 @@ pipex_link_session(struct pipex_session 
session->pipex_iface = iface;
session->ifindex = iface->ifindex;
 
+   ifp = if_get(iface->ifindex);
+   if (ifp != NULL && ifp->if_flags & IFF_POINTOPOINT)
+   session->is_p2p = 1;
+   if_put(ifp);
+
LIST_INSERT_HEAD(_session_list, session, session_list);
chain = PIPEX_ID_HASHTABLE(session->session_id);
LIST_INSERT_HEAD(chain, session, id_chain);
@@ -469,6 +470,8 @@ pipex_unlink_session(struct pipex_sessio
session->ifindex = 0;
 
NET_ASSERT_LOCKED();
+   if (session->state == PIPEX_STATE_CLOSED)
+   return;
LIST_REMOVE(session, id_chain);
 #if defined(PIPEX_PPTP) || defined(PIPEX_L2TP)
switch (session->protocol) {
@@ -622,7 +625,7 @@ pipex_get_stat(struct pipex_session_stat
 
 Static int