dhcpd domain-search patch

2019-02-26 Thread William Ahern
systemd's dhcp client doesn't accept the hack of putting multiple,
space-separated search domains in the domain-name option. The following
patch parses option domain-search as a list of host names and uses
dn_comp(3) from libc to compress the list for the on-wire option value.

Example dhcpd.conf usage:

  option domain-search openbsd.org, example.com, a.example.com;

Index: confpars.c
===
RCS file: /cvs/src/usr.sbin/dhcpd/confpars.c,v
retrieving revision 1.33
diff -u -p -r1.33 confpars.c
--- confpars.c  24 Apr 2017 14:58:36 -  1.33
+++ confpars.c  27 Feb 2019 07:23:41 -
@@ -43,7 +43,9 @@
 
 #include 
 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1207,6 +1209,12 @@ parse_option_param(FILE *cfile, struct g
tree = tree_concat(tree, tree_const(
buf, (cprefix + 7) / 8));
break;
+   case 'Z':
+   t = parse_domain_and_comp(cfile, uniform);
+   if (!t)
+   return;
+   tree = tree_concat(tree, t);
+   break;
default:
log_warnx("Bad format %c in "
"parse_option_param.", *fmt);
@@ -1467,4 +1475,82 @@ parse_address_range(FILE *cfile, struct 
 
/* Create the new address range. */
new_address_range(low, high, subnet, dynamic);
+}
+
+static void push_domain_list(char ***domains, size_t *count, char *domain)
+{
+   *domains = reallocarray(*domains, *count + 1, sizeof **domains);
+   if (!*domains)
+   fatalx("Can't allocate domain list");
+
+   (*domains)[*count] = domain;
+   ++*count;
+}
+
+static void
+free_domain_list(char **domains, size_t count)
+{
+   for (size_t i = 0; i < count; i++)
+   free(domains[i]);
+   free(domains);
+}
+
+struct tree *
+parse_domain_and_comp(FILE *cfile, int uniform)
+{
+   char **domains = NULL;
+   size_t count = 0;
+   unsigned char *buf = NULL;
+   size_t bufsiz = 0, bufn = 0;
+   unsigned char **bufptrs = NULL;
+   struct tree *rv = NULL;
+   int token;
+
+   do {
+   char *domain;
+
+   domain = parse_host_name(cfile);
+   if (!domain)
+   goto error;
+   push_domain_list(, , domain);
+   /*
+* openbsd.org normally compresses to [7]openbsd[3]org[0]. 
+* +2 to string length provides space for leading and
+* trailing (root) prefix lengths not already accounted for
+* by dots, and also provides sufficient space for pointer
+* compression.
+*/
+   bufsiz = bufsiz + 2 + strlen(domain);
+   token = peek_token(NULL, cfile);
+   if (token == ',')
+   token = next_token(NULL, cfile);
+   } while (uniform && token == ',');
+
+   buf = malloc(bufsiz);
+   if (!buf)
+   fatalx("Can't allocate compressed domain buffer");
+   bufptrs = calloc(count + 1, sizeof *bufptrs);
+   if (!bufptrs)
+   fatalx("Can't allocate compressed pointer list");
+   bufptrs[0] = buf;
+   
+   /* dn_comp takes an int for the output buffer size */
+   if (!(bufsiz <= INT_MAX))
+   fatalx("Size of compressed domain buffer too large");
+   for (size_t i = 0; i < count; i++) {
+   int n;
+
+   /* see bufsiz <= INT_MAX assertion, above */
+   n = dn_comp(domains[i], [bufn], bufsiz - bufn, bufptrs, 
[count + 1]);
+   if (n == -1)
+   fatalx("Can't compress domain");
+   bufn += (size_t)n;
+   }
+
+   rv = tree_const(buf, bufn);
+error:
+   free_domain_list(domains, count);
+   free(buf);
+   free(bufptrs);
+   return rv;
 }
Index: dhcp.h
===
RCS file: /cvs/src/usr.sbin/dhcpd/dhcp.h,v
retrieving revision 1.10
diff -u -p -r1.10 dhcp.h
--- dhcp.h  21 Jan 2014 03:07:51 -  1.10
+++ dhcp.h  27 Feb 2019 07:23:41 -
@@ -171,6 +171,7 @@ struct dhcp_packet {
 #define DHO_NDS_SERVERS85
 #define DHO_NDS_TREE_NAME  86
 #define DHO_NDS_CONTEXT87
+#define DHO_DOMAIN_SEARCH  119
 #define DHO_CLASSLESS_STATIC_ROUTES121
 #define DHO_TFTP_CONFIG_FILE   144
 #define DHO_VOIP_CONFIGURATION_SERVER  150
Index: dhcpd.h
===
RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.h,v
retrieving revision 1.66
diff -u -p -r1.66 dhcpd.h
--- dhcpd.h 4 Aug 2017 02:01:46 

xenocara: update to libfontenc 1.1.4

2019-02-26 Thread Matthieu Herrb
minor bug fix update...

ok ?

Index: ChangeLog
===
RCS file: /cvs/OpenBSD/xenocara/lib/libfontenc/ChangeLog,v
retrieving revision 1.6
diff -u -r1.6 ChangeLog
--- ChangeLog   10 May 2015 09:27:16 -  1.6
+++ ChangeLog   26 Feb 2019 21:10:24 -
@@ -1,3 +1,86 @@
+commit 2baea13978759d1a011fc6d739465893b554d30a
+Author: Alan Coopersmith 
+Date:   Tue Feb 19 17:31:57 2019 -0800
+
+libfontenc 1.1.4
+
+Signed-off-by: Alan Coopersmith 
+
+commit d7f661849c18c354f1692d9859e057aa3a7ddf93
+Author: Alan Coopersmith 
+Date:   Fri Dec 7 19:29:22 2018 -0800
+
+Update configure.ac bug URL for gitlab migration
+
+Signed-off-by: Alan Coopersmith 
+
+commit b12b2d71f1547e832ac14b66a0d94d88b3675b25
+Author: Alan Coopersmith 
+Date:   Mon Nov 19 23:01:09 2018 -0800
+
+Update README for gitlab migration
+
+Signed-off-by: Alan Coopersmith 
+
+commit b28c2d111e9d02ea1a42ac27a1330b0ba1efb4a6
+Author: Alan Coopersmith 
+Date:   Sun Nov 11 13:58:34 2018 -0800
+
+Fix iso8859-7 mappings for 0xA1, 0xA2, & 0xFF
+
+Fixes: https://gitlab.freedesktop.org/xorg/lib/libfontenc/issues/1
+
+Signed-off-by: Alan Coopersmith 
+
+commit 8d30ca25b54934e29206da64e80c044d05b14470
+Author: Mihail Konev 
+Date:   Thu Jan 26 13:52:49 2017 +1000
+
+autogen: add default patch prefix
+
+Signed-off-by: Mihail Konev 
+
+commit cc7e0f5529ab5c25aa2adc31a629a5e43cf1f319
+Author: Emil Velikov 
+Date:   Mon Mar 9 12:00:52 2015 +
+
+autogen.sh: use quoted string variables
+
+Place quotes around the $srcdir, $ORIGDIR and $0 variables to prevent
+fall-outs, when they contain space.
+
+Signed-off-by: Emil Velikov 
+Reviewed-by: Peter Hutterer 
+Signed-off-by: Peter Hutterer 
+
+commit 38aac013fcfd6e54a9fd9847ed798a5a20bd7139
+Author: Peter Hutterer 
+Date:   Tue Jan 24 10:32:07 2017 +1000
+
+autogen.sh: use exec instead of waiting for configure to finish
+
+Syncs the invocation of configure with the one from the server.
+
+Signed-off-by: Peter Hutterer 
+Reviewed-by: Emil Velikov 
+
+commit 8bbc9af3ef1160f16f176be07c917f9cccf229b2
+Author: Julien Cristau 
+Date:   Sun Jul 26 18:32:23 2015 +0200
+
+make FontEncDirectory return a const string
+
+Its comment already said "This string is static and should not be
+modified".
+
+encparse.c: In function 'FontEncDirectory':
+encparse.c:844:17: warning: assignment discards 'const' qualifier from 
pointer target type
+ dir = FONT_ENCODINGS_DIRECTORY;
+ ^
+
+Signed-off-by: Julien Cristau 
+Reviewed-by: Alan Coopersmith 
+
 commit 42f3a39c3085afd9ef904ae39102fd49bbc2e4a5
 Author: Alan Coopersmith 
 Date:   Thu Apr 30 21:39:51 2015 -0700
Index: Makefile.am
===
RCS file: /cvs/OpenBSD/xenocara/lib/libfontenc/Makefile.am,v
retrieving revision 1.4
diff -u -r1.4 Makefile.am
--- Makefile.am 4 Mar 2012 18:25:21 -   1.4
+++ Makefile.am 26 Feb 2019 21:10:24 -
@@ -40,3 +40,5 @@
 lint:
(cd src && $(MAKE) $(MFLAGS) lint)
 endif LINT
+
+EXTRA_DIST = README.md
Index: Makefile.in
===
RCS file: /cvs/OpenBSD/xenocara/lib/libfontenc/Makefile.in,v
retrieving revision 1.10
diff -u -r1.10 Makefile.in
--- Makefile.in 11 Oct 2016 22:15:41 -  1.10
+++ Makefile.in 26 Feb 2019 21:10:25 -
@@ -72,7 +72,7 @@
 build_triplet = @build@
 host_triplet = @host@
 subdir = .
-DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
+DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \
$(srcdir)/fontenc.pc.in $(top_srcdir)/configure COPYING \
ChangeLog INSTALL compile config.guess config.sub depcomp \
@@ -340,6 +340,7 @@
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = fontenc.pc
 MAINTAINERCLEANFILES = ChangeLog INSTALL
+EXTRA_DIST = README.md
 all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
 
Index: README
===
RCS file: README
diff -N README
--- README  31 Oct 2009 19:05:27 -  1.2
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,25 +0,0 @@
-libfontenc - font encoding library
-
-All questions regarding this software should be directed at the
-Xorg mailing list:
-
-http://lists.freedesktop.org/mailman/listinfo/xorg
-
-Please submit bug reports to the Xorg bugzilla:
-
-https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
-
-The master development code repository can be found at:
-
-git://anongit.freedesktop.org/git/xorg/lib/libfontenc
-
-http://cgit.freedesktop.org/xorg/lib/libfontenc
-
-For patch submission instructions, see:
-
-   http://www.x.org/wiki/Development/Documentation/SubmittingPatches
-
-For more information on 

Re: iked(8): fix the sending of certain IPv6 addresses in the configuration payload

2019-02-26 Thread Aram Hăvărneanu
Excellent, thanks!

-- 
Aram Hăvărneanu



xterm: fix build with -DOPT_TRACE=1

2019-02-26 Thread Matthieu Herrb
Hi,

The patch below allows to build a version of xterm with tracing (very
verbose debugging log) active. This is only useful to debug xterm, and
I've been carrying this local change for years now.
After all, every developer may want to be able to see how xterm is
processing its data.

To enable tracing, add -DOPT_TRACE=1 to CPPFLAGS Makefile. Avoid
installing this version, it will fill your disks.

The patch builds an additional file needed for tracing (VTparse.cin)
and disables visibleTekparse() if the Tektronics widget isn't built.

ok ?

Index: Makefile
===
RCS file: /cvs/OpenBSD/xenocara/app/xterm/Makefile,v
retrieving revision 1.32
diff -u -r1.32 Makefile
--- Makefile18 Jun 2017 21:09:07 -  1.32
+++ Makefile26 Feb 2019 20:53:28 -
@@ -37,6 +37,8 @@
 
 misc.o:builtin_icons.h
 
+trace.o: VTparse.cin
+
 # do this to quiet gcc -Wcast-qual warnings 
 builtin_icons.h :
@echo "#if OPT_BUILTIN_XPMS" >$@
@@ -57,7 +59,7 @@
 beforedepend: builtin_icons.h VTparse.hin
 BUILDFIRST = builtin_icons.h VTparse.hin
 
-.SUFFIXES: .man .1
+.SUFFIXES: .man .1 .def .cin .hin
 
 PATCH_NUM != sed -n '/XTERM_PATCH/s/[^0-9]*//gp' ${.CURDIR}/version.h
 PATCH_YMD != sed -n '/XTERM_DATE/s,[^0-9/.-]*,,gp' ${.CURDIR}/version.h
@@ -82,7 +84,7 @@
-e s%/etc/wtmp%/var/run/wtmp%g \
 < $< > $@
 
-CLEANFILES+=   ${MAN} builtin_icons.h VTparse.hin
+CLEANFILES+=   ${MAN} builtin_icons.h VTparse.cin VTparse.hin
 
 afterinstall:
${INSTALL} ${INSTALL_COPY} -m ${SHAREMODE} \
@@ -93,6 +95,14 @@
${DESTDIR}${X11BASE}/share/X11/app-defaults/XTerm-color
 
 obj: _xenocara_obj
+
+AWK?= awk
+
+.def.cin:
+   $(AWK) '/^CASE_/{printf "{ %d, \"%s\" },\n", n++, $$1; }' < $< >$@
+
+.def.hin:
+   $(AWK) '/^CASE_/{printf "#define %s %d\n", $$1, n++}' < $< >$@
 
 .include 
 .include 
Index: trace.c
===
RCS file: /cvs/OpenBSD/xenocara/app/xterm/trace.c,v
retrieving revision 1.29
diff -u -r1.29 trace.c
--- trace.c 24 Feb 2019 11:41:42 -  1.29
+++ trace.c 26 Feb 2019 20:53:31 -
@@ -492,6 +492,7 @@
 return result;
 }
 
+#if OPT_TEK4014
 const char *
 visibleTekparse(int code)
 {
@@ -511,6 +512,7 @@
 }
 return result;
 }
+#endif
 
 const char *
 visibleVTparse(int code)

-- 
Matthieu Herrb



Re: patch axen(4) (WIP)

2019-02-26 Thread Artturi Alm
On Tue, Feb 26, 2019 at 03:00:15PM +0100, Nils Frohberg wrote:
> On Mon, Feb 25, 2019 at 03:50:48PM -0300, Martin Pieuchot wrote:
> > On 25/02/19(Mon) 14:52, Nils Frohberg wrote:
> > > Hi,
> > > 
> > > as mentioned previously, I'm looking into axen(4). While searching
> > > for the cause of a panic (fixed since, thanks mpi@) I started to
> > > rewrite parts of the driver. References were mainly the FreeBSD and
> > > Linux drivers.
> > 
> > Please try to isolate parts of your diff that fixes issues and cosmetic
> > changes.  The simpler it gets the easier it is for us to review it.
> 
> Sure, I'll send separate patches.
> 
> (I cvs up'ed my src forder in order to test compile the individual
> patches and found out that xhci.c,v1.91 breaks my USB devices. I'll
> send a mail to bugs@ later.)
> 
> > > I didn't get around to much testing/debugging lately, therefore I
> > > wanted to share the current state (diff below).
> > > 
> > > The current state works a lot better than previously (for me). I
> > > used to have a huge amount of ierrs (aprrox. 1 ierr per ipkt) and
> > > often no packets would be transferred at all (or stop being transferred
> > > after some time).
> > 
> > Do you know why?  What were the problems?
> 
> I'm not 100% sure, since I did a lot of back and forth. It finally
> got better once I disabled EEE and lowered the watermark levels.
> 

Have you looked at what NetBSD has done with their axen(4)? there has
been 20commits in 2019 so far[0], while some of them are possibly,
idk., useless to us(thinking about hw checksum offloading), there was
some bug fixes that did look relevant to me, but i succesfully
installed kernels on nfs over axen(4) a couple of weeks ago,
so the bugs it has didn't feel critical enough for me to make
a branch for them. that was on arm64/dwctwo(4), tbh. i haven't been
happy with axen(4) on amd64/{e,x}hci(4) myself in the past either. :]

I guess i'm trying to say maybe it wouldn't hurt to sync a bit before
deviating as much as atleast your whole WIP diff did. I haven't read
your separate patches yet, but i'll try to get around to also testing
those before weekend:]

-Artturi

[0] https://github.com/NetBSD/src/commits/trunk/sys/dev/usb/if_axen.c



Olde Fort Inn , are you available today at 3:00 PM?

2019-02-26 Thread Frank FREE POS System
If you are not able to see this mail, click 
http://r.email.fmspaymentprocessing.com/mk/mr/SoF62UGQ02tiuhqDDC7ur3AQVmMTmWOY4ItFheydt-OMVsu9VuSGbgWcVWiYF6aEBLwVlvIwiJySTkxQfQvYta6ZUPMGett9Y_iP6Fj4q7Pn_6Ind0x_Eeu2PS3Z
 
 


Hi Owner of  Olde Fort Inn
 

I am writing on behalf of Harbortouch POS Systems to request a meeting with you 
to
discuss Upgrade to a touchscreen POS system for FREE!

Harbortouch POS systems combine state-of-the-art software with high quality 
hardware to deliver the ultimate business management solution. Offering 
countless time and money saving features, POS systems streamline your 
operations and give you a top-level view of your business with comprehensive 
reporting functionality so that you can focus on what's important: keeping your 
customers satisfied and spending! Now available with a 30 day risk-free trial, 
Harbortouch can upgrade your current terminal to a full-featured, touchscreen 
POS system with no up-front costs!

WHY UPGRADE?
• Streamline your operations for greater efficiency
• Take advantage of countless time and money saving features
• Get a top-level view of your business with robust reporting
• Manage employees with a built-in time clock
• Track inventory to monitor stock levels
• Installation, training and 24/7 support
• Lifetime equipment warranty**

In the instance that you’re not the right person who looks into this, I would 
appreciate it if you could direct me to the right contact.

Would you be available today to learn if we're a fit for you? What is the best 
number to reach you?


Sincerely,

Frank Peralta | Tel:914-222-3037
POS Systems Expertise
 
PS: [ You can read more about our POS systems in our website ]( 
http://r.email.fmspaymentprocessing.com/mk/cl/f/jsc_fnm20vpSP9X-nr68GNXU-yAVH-RP8foYwX47Pr2w8BAvzI1jbvm5LDhtGXbVZHfrElAm23HlUswm7gyUdsyjpT673BoWioXCKzPjPX76vJDtN3-9gv8EhVp-Rng8-vRzYDuqvsN2uvIGUfd87064qCmD_7p_6XTbzfXYuQ9BrTOzvkiqxvEw
 )
    
 

POS SYSTEMS FREE
302 Bedford Ave Ste 494
Williamsburg , NY 11249
he...@possystemsfree.com
   
 
This email was sent to tech@openbsd.org
You received this email because you are registered with POS Systems FREE
 
[ Unsubscribe here ]( 
http://r.email.fmspaymentprocessing.com/mk/un/4YCdJHdJtnj_FZKo9FeNO62YspsKcZ9zptBpX16z1pso_yMa9zfkNlnqFsUXE-2FQwEim3D6S4ATCMsDJtdR-9NT_OliMvpS7V6w36FP3iHKE6XrpgG_065crD-docq-P0oyZHPZkYovo8jEDdJrsZtW
 )  

Sent by
[  ]( 
http://r.email.fmspaymentprocessing.com/mk/cl/f/_ZtdzKejCJzy7umm6cpPeKSlxztheYofOVSGt7RsMyUajQcASQ3Rq5jqqfnn7wsdfQJ_K9bAm61ucCxTshuL5IuT-mLebEGak7hMZDzMMH00xOXafgwva0TsGVtInLo5-zqeYF_rJQ8MyDEgg1aykstewIZ95NCJUQjNYvkGYlBSBp_TmEa102BuC6myTemuRAe8pJUKOLagfIC2FMYpHJmDlJOfbV_fXAKYD-t0k_7tPxwtpbSlXMmYPBL-Ub5kdunym1mGVYUAMs2t13-JARivpmi6EgrAiyOhV1AbnTAOmkiy8u-vED4
 )   
 
© 2018 POS Systems FREE  
    Mauris commodo massa tortor, u [ sit amet,consectetur adipisicing ]( # ) 
Nunc fermentum neque quam, sodales eleifend elit imperdiet vitae. Aliquam id 
euismod nulla. Suspendisse imperdiet, sem et sollicitudin egestas, urna nunc 
auctor massa, vulputate pharetra mi odio nec tortor. Ut ultricies massa viverra 
quis.   



Re: iked(8): fix the sending of certain IPv6 addresses in the configuration payload

2019-02-26 Thread Patrick Wildt
On Tue, Feb 26, 2019 at 06:45:38PM +0100, Patrick Wildt wrote:
> On Thu, Feb 21, 2019 at 06:29:15PM +0100, Aram Hăvărneanu wrote:
> > This change fixes the sending of INTERNAL_IP6_DNS, INTERNAL_IP6_DHCP
> > (RFC5996); INTERNAL_IP6_NBNS (RFC4306); and INTERNAL_IP6_SERVER
> > (MS-IKEE).
> > 
> > Prior to this fix the data sent to clients was garbled.
> 
> Oh, good catch!  That looks fine to me.

Thanks, committed!

> > Index: ikev2.c
> > ===
> > RCS file: /cvs/src/sbin/iked/ikev2.c,v
> > retrieving revision 1.166
> > diff -u -p -u -p -r1.166 ikev2.c
> > --- ikev2.c 5 Mar 2018 14:30:30 -   1.166
> > +++ ikev2.c 21 Feb 2019 17:19:21 -
> > @@ -1935,7 +1935,7 @@ ikev2_add_cp(struct iked *env, struct ik
> > case IKEV2_CFG_INTERNAL_IP6_DHCP:
> > case IKEV2_CFG_INTERNAL_IP6_SERVER:
> > /* 16 bytes IPv6 address */
> > -   in6 = (struct sockaddr_in6 *)>cfg.address;
> > +   in6 = (struct sockaddr_in6 *)>cfg.address.addr;
> > cfg->cfg_length = htobe16(16);
> > if (ibuf_add(buf, >sin6_addr.s6_addr, 16) == -1)
> > return (-1);
> > 



Re: iked(8): fix the sending of certain IPv6 addresses in the configuration payload

2019-02-26 Thread Patrick Wildt
On Thu, Feb 21, 2019 at 06:29:15PM +0100, Aram Hăvărneanu wrote:
> This change fixes the sending of INTERNAL_IP6_DNS, INTERNAL_IP6_DHCP
> (RFC5996); INTERNAL_IP6_NBNS (RFC4306); and INTERNAL_IP6_SERVER
> (MS-IKEE).
> 
> Prior to this fix the data sent to clients was garbled.

Oh, good catch!  That looks fine to me.

> Index: ikev2.c
> ===
> RCS file: /cvs/src/sbin/iked/ikev2.c,v
> retrieving revision 1.166
> diff -u -p -u -p -r1.166 ikev2.c
> --- ikev2.c   5 Mar 2018 14:30:30 -   1.166
> +++ ikev2.c   21 Feb 2019 17:19:21 -
> @@ -1935,7 +1935,7 @@ ikev2_add_cp(struct iked *env, struct ik
>   case IKEV2_CFG_INTERNAL_IP6_DHCP:
>   case IKEV2_CFG_INTERNAL_IP6_SERVER:
>   /* 16 bytes IPv6 address */
> - in6 = (struct sockaddr_in6 *)>cfg.address;
> + in6 = (struct sockaddr_in6 *)>cfg.address.addr;
>   cfg->cfg_length = htobe16(16);
>   if (ibuf_add(buf, >sin6_addr.s6_addr, 16) == -1)
>   return (-1);
> 



mkhybrid: fix format-string warnings

2019-02-26 Thread Scott Cheloha
I don't want to see these warnings at the end of my compilation logs
anymore.

ok?

Index: desktop.c
===
RCS file: /cvs/src/gnu/usr.sbin/mkhybrid/src/desktop.c,v
retrieving revision 1.4
diff -u -p -r1.4 desktop.c
--- desktop.c   29 Mar 2016 10:21:41 -  1.4
+++ desktop.c   26 Feb 2019 16:38:08 -
@@ -95,28 +95,28 @@ make_desktop(hfsvol *vol, int end)

/* open file */
if((hfp = hfs_open(vol, DB)) == 0)
-   err(1, hfs_error);
+   err(1, "%s", hfs_error);
 
/* "write" file */
write_fork(hfp, clps);
 
/* set DB file attributes */
if (hfs_fsetattr(hfp, ) < 0)
-   err(1, hfs_error);
+   err(1, "%s", hfs_error);
 
/* find the real start of the file */
end += hce->hfs_ce_size;
 
/* close DB file */
if (hfs_close(hfp, end, 0) < 0)
-   err(1, hfs_error);
+   err(1, "%s", hfs_error);
}
else
{
/* if it already exists, then make sure it has the correct
   type/creator and flags */
if(hfs_setattr(vol, DB, ) < 0)
-   err(1, hfs_error);
+   err(1, "%s", hfs_error);
}
 
/* setup "Desktop DF" file as an empty file */
@@ -128,7 +128,7 @@ make_desktop(hfsvol *vol, int end)
 
/* set DB file attributes */
if (hfs_setattr(vol, DF, ) < 0)
-   err(1, hfs_error);
+   err(1, "%s", hfs_error);
return 0;
 }
 #endif /* APPLE_HYB */ 
Index: write.c
===
RCS file: /cvs/src/gnu/usr.sbin/mkhybrid/src/write.c,v
retrieving revision 1.4
diff -u -p -r1.4 write.c
--- write.c 9 Sep 2015 20:02:31 -   1.4
+++ write.c 26 Feb 2019 16:38:08 -
@@ -1545,7 +1545,7 @@ static int file_gen()
/* exit with the error */
if (*hce->error)
fprintf(stderr, "%s\n", hce->error);
-   err(1, hfs_error);
+   err(1, "%s", hfs_error);
}
else
{
@@ -1575,7 +1575,7 @@ static int file_gen()
   if (gen_mac_label(_boot)) {
if (*hce->error)
fprintf(stderr, "%s\n", hce->error);
-   err(1, hfs_error);
+   err(1, "%s", hfs_error);
   }
 }
 



iked(8): add support for IKEv2 Message Fragmentation

2019-02-26 Thread Tobias Heider
Hi,

this diff adds support for IKEv2 Message Fragmentation as defined in
RFC 7383 (https://tools.ietf.org/html/rfc7383) to iked(8).

Tobias

Index: regress/sbin/iked/parser/common.c
===
RCS file: /mount/openbsd/cvs/src/regress/sbin/iked/parser/common.c,v
retrieving revision 1.1
diff -u -p -u -r1.1 common.c
--- regress/sbin/iked/parser/common.c   29 May 2017 20:59:28 -  1.1
+++ regress/sbin/iked/parser/common.c   26 Feb 2019 12:37:35 -
@@ -166,6 +166,12 @@ config_add_proposal(struct iked_proposal
return (NULL);
 }
 
+void
+config_free_fragments(struct iked_frag *frag)
+{
+   return;
+}
+
 int
 ikev2_send_informational(struct iked *env, struct iked_message *msg)
 {
Index: regress/sbin/iked/parser/test_parser_fuzz.c
===
RCS file: /mount/openbsd/cvs/src/regress/sbin/iked/parser/test_parser_fuzz.c,v
retrieving revision 1.2
diff -u -p -u -r1.2 test_parser_fuzz.c
--- regress/sbin/iked/parser/test_parser_fuzz.c 22 Mar 2018 21:11:49 -  
1.2
+++ regress/sbin/iked/parser/test_parser_fuzz.c 26 Feb 2019 12:40:50 -
@@ -227,6 +227,50 @@ u_int8_t sk_pld[] = {
 0x3d, 0xa1, 0xa5, 0x8f
 };
 
+u_int8_t skf_1of1_pld[] = {
+   0x21, 0x00, 0x01, 0x98, 0x00, 0x01, 0x00, 0x01, 0x14, 0x77,
+   0x25, 0x7b, 0x82, 0xc0, 0xdb, 0x0b, 0x24, 0x36, 0x36, 0x13,
+   0x36, 0xe4, 0x99, 0xad, 0xf5, 0xaf, 0x26, 0x6f, 0x47, 0xd2,
+   0x0d, 0x65, 0xe1, 0xa8, 0xcb, 0x35, 0x1e, 0x53, 0xce, 0x6d,
+   0x8e, 0xf9, 0xe4, 0x51, 0xe3, 0x27, 0x10, 0x43, 0x38, 0x84,
+   0x54, 0x1d, 0x7a, 0x1a, 0x89, 0x34, 0x06, 0xb3, 0x62, 0x86,
+   0x98, 0x3b, 0x39, 0x91, 0x6e, 0xe8, 0x65, 0x3e, 0x31, 0xa8,
+   0x08, 0xfe, 0x83, 0x56, 0x30, 0xd3, 0xe0, 0xfd, 0x73, 0x92,
+   0x85, 0x2d, 0xae, 0x1d, 0x7d, 0xdb, 0x47, 0x05, 0x57, 0xe7,
+   0x8e, 0xc5, 0xa5, 0x1b, 0x0e, 0x85, 0x1f, 0x12, 0x6d, 0xe6,
+   0xdb, 0x3a, 0x3e, 0x99, 0xd1, 0x23, 0x41, 0xa4, 0x1c, 0x46,
+   0x38, 0xd1, 0xa8, 0x84, 0x96, 0x13, 0xdb, 0x2a, 0x1d, 0x3b,
+   0xb8, 0xd2, 0x04, 0xb3, 0x0d, 0xb4, 0x71, 0x90, 0xdb, 0xf6,
+   0x2d, 0x60, 0x01, 0xc2, 0xb2, 0x89, 0xbd, 0xe9, 0x95, 0x7b,
+   0x53, 0xa4, 0x94, 0x7e, 0x12, 0xe9, 0x5f, 0xfc, 0x51, 0x17,
+   0x94, 0x3e, 0xba, 0xc2, 0xa5, 0x4d, 0x3a, 0x4d, 0x4b, 0x95,
+   0x6d, 0x91, 0xc2, 0xb0, 0x2d, 0xb7, 0x24, 0xe8, 0x3b, 0xbd,
+   0xe0, 0xcc, 0x09, 0x50, 0x11, 0x83, 0xc0, 0xcd, 0x29, 0x33,
+   0xd5, 0x8f, 0x8a, 0xd1, 0xe3, 0xe8, 0x4f, 0x6a, 0x10, 0x4a,
+   0x64, 0x97, 0x0f, 0x38, 0x58, 0x8d, 0x7f, 0x5d, 0xb4, 0x6b,
+   0xa0, 0x42, 0x5e, 0x95, 0xe6, 0x08, 0x3e, 0x01, 0xf8, 0x82,
+   0x90, 0x81, 0xd4, 0x70, 0xb5, 0xb2, 0x8c, 0x64, 0xa9, 0x56,
+   0xdd, 0xc2, 0xda, 0xe1, 0xd3, 0xad, 0xf8, 0x5b, 0x99, 0x0b,
+   0x19, 0x5e, 0x88, 0x0d, 0x81, 0x04, 0x4d, 0xc1, 0x43, 0x41,
+   0xf1, 0xd3, 0x45, 0x65, 0x62, 0x70, 0x2f, 0xfa, 0x62, 0xbe,
+   0x7d, 0xf4, 0x94, 0x91, 0xe0, 0xbb, 0xb1, 0xbc, 0xe5, 0x27,
+   0xc8, 0x15, 0xd4, 0xcb, 0x82, 0x97, 0x15, 0x46, 0x82, 0xbb,
+   0x48, 0xbb, 0x16, 0x25, 0xbe, 0x82, 0xe4, 0x27, 0x80, 0xf3,
+   0xc2, 0x92, 0x3b, 0xd6, 0xc3, 0x65, 0x20, 0xec, 0x50, 0xdb,
+   0x6a, 0xcb, 0x47, 0x73, 0xf7, 0x98, 0xf1, 0x66, 0x5e, 0xc4,
+   0xe9, 0x87, 0xf8, 0xcb, 0x1e, 0x06, 0xa7, 0x67, 0xf5, 0xec,
+   0x73, 0xe5, 0xc7, 0x4d, 0xc2, 0x90, 0xe4, 0xdf, 0x9d, 0x1f,
+   0x05, 0x67, 0x99, 0xd6, 0xf0, 0xc4, 0x20, 0xbc, 0xf8, 0xf5,
+   0x3e, 0x19, 0xe9, 0x3a, 0x12, 0xe1, 0xcc, 0x9f, 0x81, 0x55,
+   0x1e, 0xad, 0xc8, 0xa3, 0xe5, 0x98, 0xbe, 0xe0, 0x4d, 0xb7,
+   0x6b, 0xd5, 0xbe, 0x6a, 0x3d, 0x76, 0xb6, 0xe2, 0xa5, 0xa7,
+   0x96, 0x68, 0xeb, 0x91, 0xee, 0x02, 0xfc, 0xe4, 0x01, 0xc3,
+   0x24, 0xda, 0x4c, 0xff, 0x10, 0x27, 0x78, 0xb0, 0x0b, 0x55,
+   0x5c, 0xce, 0x62, 0x7d, 0x33, 0x2b, 0x25, 0x99, 0xaa, 0x99,
+   0xea, 0xa3, 0x1d, 0xd8, 0x2b, 0x57, 0xb5, 0xe4, 0x04, 0x21,
+   0x75, 0xd9, 0xc4, 0xd0, 0x3d, 0xa1, 0xa5, 0x8f
+};
+
 u_int8_t cp_pld[] = {
0x2f, 0x00, 0x00, 0x0c,
0x01, 0x00, 0x00, 0x00, /* REQUEST */
@@ -450,6 +494,25 @@ parser_fuzz_tests(void)
FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END |
FUZZ_BASE64,
ibuf_data(data), ibuf_size(data));
+   ibuf_free(data);
+   perform_test(fuzz);
+   TEST_DONE();
+
+   TEST_START("fuzz skf_1of1 payload");
+   ASSERT_PTR_NE(data = ibuf_new(cookies, sizeof(cookies)), NULL);
+   ASSERT_INT_EQ(ibuf_add(data, genhdr, sizeof(genhdr)), 0);
+   ASSERT_INT_EQ(ibuf_add(data, skf_1of1_pld, sizeof(skf_1of1_pld)), 0);
+   set_length(ibuf_data(data), ibuf_size(data));
+   set_nextpayload(ibuf_data(data), IKEV2_PAYLOAD_SA);
+   print_hex(ibuf_data(data), 0, ibuf_size(data));
+   prepare_header(, data);
+   prepare_message(, data);
+   ASSERT_INT_EQ(ikev2_pld_parse(NULL, , , 0), 0);
+   fuzz = 

Re: dynamic RTS threshold in 11n mode

2019-02-26 Thread Stefan Sperling
On Tue, Feb 26, 2019 at 03:04:35PM +0100, Stefan Sperling wrote:
> This diff makes the RTS threshold dynamic in 11n mode.
> I am looking for tests with iwn(4), iwm(4), and athn(4) drivers.
> 
> When there's a lot of competition for air time, RTS can do more harm than
> good because we end up causing more RTS/CTS frames on the air than actual
> data frames. So a fixed RTS threshold really doesn't make a lot of sense.
> 
> This diff implements a heuristic for setting this threshold, based on section
> 5.2 of the MiRa paper. It should improve Tx throughput on busy channels which
> are especially common in the 2GHz band. In my testing it helps quite a bit.
> 
> This diff won't change the situation in 11a/b/g modes, and it might
> not make a difference if there are 11a/b/g networks in range.

I realized the previous diff might take some time to raise throughput,
so please try this one instead. The difference is just that the previous
diff starts out with RTS threshold enabled, while this one starts out with
RTS threshold disabled. This should make results look better for people
doing quick tests rather than looking at long-term effects.  :-)

diff f727f040295e17987bfffe9c9952e45fd6ad7859 /usr/src
blob - 7cf96bf074b3eef4d9fbb85c9253bac7e5550fd7
file + sys/dev/ic/ar5008.c
--- sys/dev/ic/ar5008.c
+++ sys/dev/ic/ar5008.c
@@ -1514,11 +1514,16 @@ ar5008_tx(struct athn_softc *sc, struct mbuf *m, struc
if (!IEEE80211_IS_MULTICAST(wh->i_addr1) &&
(wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
IEEE80211_FC0_TYPE_DATA) {
+   int rtsthres = ic->ic_rtsthreshold;
enum ieee80211_htprot htprot;
-   
+
+   if (ni->ni_flags & IEEE80211_NODE_HT)
+   rtsthres = ieee80211_mira_get_rts_threshold(>mn,
+   ic, ni, totlen);
htprot = (ic->ic_bss->ni_htop1 & IEEE80211_HTOP1_PROT_MASK);
+
/* NB: Group frames are sent using CCK in 802.11b/g. */
-   if (totlen > ic->ic_rtsthreshold) {
+   if (totlen > rtsthres) {
ds->ds_ctl0 |= AR_TXC0_RTS_ENABLE;
} else if (((ic->ic_flags & IEEE80211_F_USEPROT) &&
athn_rates[ridx[0]].phy == IEEE80211_T_OFDM) ||
blob - 7d7f0697a2b609f4a6e0fab09ede9a480baa7bd3
file + sys/dev/pci/if_iwm.c
--- sys/dev/pci/if_iwm.c
+++ sys/dev/pci/if_iwm.c
@@ -4216,7 +4216,7 @@ iwm_tx(struct iwm_softc *sc, struct mbuf *m, struct ie
bus_dma_segment_t *seg;
uint8_t tid, type;
int i, totlen, err, pad;
-   int hdrlen2;
+   int hdrlen2, rtsthres = ic->ic_rtsthreshold;
 
wh = mtod(m, struct ieee80211_frame *);
hdrlen = ieee80211_get_hdrlen(wh);
@@ -4292,9 +4292,13 @@ iwm_tx(struct iwm_softc *sc, struct mbuf *m, struct ie
flags |= IWM_TX_CMD_FLG_ACK;
}
 
+   if (ni->ni_flags & IEEE80211_NODE_HT)
+   rtsthres = ieee80211_mira_get_rts_threshold(>in_mn, ic, ni,
+   totlen + IEEE80211_CRC_LEN);
+
if (type == IEEE80211_FC0_TYPE_DATA &&
!IEEE80211_IS_MULTICAST(wh->i_addr1) &&
-   (totlen + IEEE80211_CRC_LEN > ic->ic_rtsthreshold ||
+   (totlen + IEEE80211_CRC_LEN > rtsthres ||
(ic->ic_flags & IEEE80211_F_USEPROT)))
flags |= IWM_TX_CMD_FLG_PROT_REQUIRE;
 
blob - 1dab60807c0709735799436e7a4a8e2d8d9f1ff9
file + sys/dev/pci/if_iwn.c
--- sys/dev/pci/if_iwn.c
+++ sys/dev/pci/if_iwn.c
@@ -3069,8 +3069,13 @@ iwn_tx(struct iwn_softc *sc, struct mbuf *m, struct ie
 
/* Check if frame must be protected using RTS/CTS or CTS-to-self. */
if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
+   int rtsthres = ic->ic_rtsthreshold;
+   if (ni->ni_flags & IEEE80211_NODE_HT)
+   rtsthres = ieee80211_mira_get_rts_threshold(>mn,
+   ic, ni, totlen + IEEE80211_CRC_LEN);
+
/* NB: Group frames are sent using CCK in 802.11b/g/n (2GHz). */
-   if (totlen + IEEE80211_CRC_LEN > ic->ic_rtsthreshold) {
+   if (totlen + IEEE80211_CRC_LEN > rtsthres) {
flags |= IWN_TX_NEED_RTS;
} else if ((ic->ic_flags & IEEE80211_F_USEPROT) &&
ridx >= IWN_RIDX_OFDM6) {
blob - 4edd26a5fde82a9d9ddfd31e0bd075c0f59d2143
file + sys/net80211/ieee80211_mira.c
--- sys/net80211/ieee80211_mira.c
+++ sys/net80211/ieee80211_mira.c
@@ -85,6 +85,9 @@ int   ieee80211_mira_valid_tx_mcs(struct ieee80211com *,
 uint32_t ieee80211_mira_valid_rates(struct ieee80211com *,
struct ieee80211_node *);
 uint32_t ieee80211_mira_mcs_below(struct ieee80211_mira_node *, int, int);
+void   ieee80211_mira_set_rts_threshold(struct ieee80211_mira_node *,
+   struct ieee80211com *, struct ieee80211_node *);
+void   ieee80211_mira_reset_collision_stats(struct ieee80211_mira_node *);
 
 /* We use fixed point arithmetic with 64 bit 

[axen 5/7] fix #defines and comments

2019-02-26 Thread Nils Frohberg
fix defines/comments for L3_TYPE and CRC errors.

---
 dev/usb/if_axenreg.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/dev/usb/if_axenreg.h b/dev/usb/if_axenreg.h
index bc594a0..e6b8355 100644
--- a/dev/usb/if_axenreg.h
+++ b/dev/usb/if_axenreg.h
@@ -27,8 +27,8 @@
  * || ++-L3_type (1:ipv4, 0/2:ipv6)
  *pkt_len(13)  || ||+ ++-L4_type(0: icmp, 1: UDP, 4: TCP)
  * |765|43210 76543210|7654 3210 7654 3210|
- *  ||+-crc_err  |+-L4_err |+-L4_CSUM_ERR
- *  |+-mii_err   +--L3_err +--L3_CSUM_ERR
+ *  ||+-crc_err   |+-L4_err |+-L4_CSUM_ERR
+ *  |+-mii_err+--L3_err +--L3_CSUM_ERR
  *  +-drop_err
  *
  * ex) pkt_hdr 0x00680820
@@ -75,7 +75,7 @@
 #define   AXEN_RXHDR_L4_TYPE_TCP   0x4
 
 /* L3 packet type (2bit) */
-#define AXEN_RXHDR_L3_TYPE_MASK0x0600
+#define AXEN_RXHDR_L3_TYPE_MASK0x0060
 #define AXEN_RXHDR_L3_TYPE_OFFSET  5
 #define   AXEN_RXHDR_L3_TYPE_UNDEF 0x0
 #define   AXEN_RXHDR_L3_TYPE_IPV4  0x1
-- 
2.20.1



[axen 6/7] add more #defines (currently not used)

2019-02-26 Thread Nils Frohberg
add missing defines (currently unused).

---
 dev/usb/if_axenreg.h | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/dev/usb/if_axenreg.h b/dev/usb/if_axenreg.h
index e6b8355..9b4c721 100644
--- a/dev/usb/if_axenreg.h
+++ b/dev/usb/if_axenreg.h
@@ -157,7 +157,7 @@
 #define AXEN_RXCTL_STOP  0x
 #define AXEN_RXCTL_PROMISC   0x0001
 #define AXEN_RXCTL_ACPT_ALL_MCAST0x0002
-#define AXEN_RXCTL_HA8B  0x0004 
+#define AXEN_RXCTL_AUTOPAD_BNDRY 0x0004
 #define AXEN_RXCTL_ACPT_BCAST0x0008
 #define AXEN_RXCTL_ACPT_MCAST0x0010
 #define AXEN_RXCTL_ACPT_PHY_MCAST0x0020
@@ -170,17 +170,27 @@
 #defineAXEN_MEDIUM_GIGA  0x0001
 #defineAXEN_MEDIUM_FDX   0x0002
 #defineAXEN_MEDIUM_ALWAYS_ONE0x0004
-#defineAXEN_MEDIUM_EN_125MHZ 0x0008
+#defineAXEN_MEDIUM_ALWAYS_ZERO1  0x0008
 #defineAXEN_MEDIUM_RXFLOW_CTRL_EN0x0010
 #defineAXEN_MEDIUM_TXFLOW_CTRL_EN0x0020
+#defineAXEN_MEDIUM_JUMBOFRAME_EN 0x0040
+#defineAXEN_MEDIUM_PAUSEFRAME_LT_ONLY_EN 0x0080
 #defineAXEN_MEDIUM_RECV_EN   0x0100
 #defineAXEN_MEDIUM_PORTSPEED_100 0x0200
-#defineAXEN_MEDIUM_JUMBO_EN  0x8040
+#defineAXEN_MEDIUM_ALWAYS_ZERO2  0x0400
+#defineAXEN_MEDIUM_STOP_BACKPRESSURE 0x0800
+#defineAXEN_MEDIUM_SUPERMAC  0x1000
+#defineAXEN_MEDIUM_ALWAYS_ZERO3  0x2000
+#defineAXEN_MEDIUM_ALWAYS_ZERO4  0x4000
+#defineAXEN_MEDIUM_ALWAYS_ZERO5  0x8000
+#defineAXEN_MEDIUM_JUMBO_EN \
+   (AXEN_MEDIUM_JUMBOFRAME_EN | AXEN_MEDIUM_STOP_BACKPRESSURE)
 #define   AXEN_PHYPWR_RSTCTL   0x26
 #define AXEN_PHYPWR_RSTCTL_BZ_AUTOCLEAR_DIS  0x0004
 #define AXEN_PHYPWR_RSTCTL_BZ0x0010
 #define AXEN_PHYPWR_RSTCTL_IPRL  0x0020
 #define AXEN_PHYPWR_RSTCTL_AUTODETACH0x1000
+#define AXEN_PHYPWR_RSTCTL_WOL_LOWPOWER  0x8000
 
 #define AXEN_CMD_EEPROM_READ   0x2004
 #defineAXEN_EEPROM_STAT  0x43
-- 
2.20.1



dynamic RTS threshold in 11n mode

2019-02-26 Thread Stefan Sperling
This diff makes the RTS threshold dynamic in 11n mode.
I am looking for tests with iwn(4), iwm(4), and athn(4) drivers.

When there's a lot of competition for air time, RTS can do more harm than
good because we end up causing more RTS/CTS frames on the air than actual
data frames. So a fixed RTS threshold really doesn't make a lot of sense.

This diff implements a heuristic for setting this threshold, based on section
5.2 of the MiRa paper. It should improve Tx throughput on busy channels which
are especially common in the 2GHz band. In my testing it helps quite a bit.

This diff won't change the situation in 11a/b/g modes, and it might
not make a difference if there are 11a/b/g networks in range.

diff f727f040295e17987bfffe9c9952e45fd6ad7859 /usr/src
blob - 7cf96bf074b3eef4d9fbb85c9253bac7e5550fd7
file + sys/dev/ic/ar5008.c
--- sys/dev/ic/ar5008.c
+++ sys/dev/ic/ar5008.c
@@ -1514,11 +1514,16 @@ ar5008_tx(struct athn_softc *sc, struct mbuf *m, struc
if (!IEEE80211_IS_MULTICAST(wh->i_addr1) &&
(wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
IEEE80211_FC0_TYPE_DATA) {
+   int rtsthres = ic->ic_rtsthreshold;
enum ieee80211_htprot htprot;
-   
+
+   if (ni->ni_flags & IEEE80211_NODE_HT)
+   rtsthres = ieee80211_mira_get_rts_threshold(>mn,
+   ic, ni, totlen);
htprot = (ic->ic_bss->ni_htop1 & IEEE80211_HTOP1_PROT_MASK);
+
/* NB: Group frames are sent using CCK in 802.11b/g. */
-   if (totlen > ic->ic_rtsthreshold) {
+   if (totlen > rtsthres) {
ds->ds_ctl0 |= AR_TXC0_RTS_ENABLE;
} else if (((ic->ic_flags & IEEE80211_F_USEPROT) &&
athn_rates[ridx[0]].phy == IEEE80211_T_OFDM) ||
blob - 7d7f0697a2b609f4a6e0fab09ede9a480baa7bd3
file + sys/dev/pci/if_iwm.c
--- sys/dev/pci/if_iwm.c
+++ sys/dev/pci/if_iwm.c
@@ -4216,7 +4216,7 @@ iwm_tx(struct iwm_softc *sc, struct mbuf *m, struct ie
bus_dma_segment_t *seg;
uint8_t tid, type;
int i, totlen, err, pad;
-   int hdrlen2;
+   int hdrlen2, rtsthres = ic->ic_rtsthreshold;
 
wh = mtod(m, struct ieee80211_frame *);
hdrlen = ieee80211_get_hdrlen(wh);
@@ -4292,9 +4292,13 @@ iwm_tx(struct iwm_softc *sc, struct mbuf *m, struct ie
flags |= IWM_TX_CMD_FLG_ACK;
}
 
+   if (ni->ni_flags & IEEE80211_NODE_HT)
+   rtsthres = ieee80211_mira_get_rts_threshold(>in_mn, ic, ni,
+   totlen + IEEE80211_CRC_LEN);
+
if (type == IEEE80211_FC0_TYPE_DATA &&
!IEEE80211_IS_MULTICAST(wh->i_addr1) &&
-   (totlen + IEEE80211_CRC_LEN > ic->ic_rtsthreshold ||
+   (totlen + IEEE80211_CRC_LEN > rtsthres ||
(ic->ic_flags & IEEE80211_F_USEPROT)))
flags |= IWM_TX_CMD_FLG_PROT_REQUIRE;
 
blob - 1dab60807c0709735799436e7a4a8e2d8d9f1ff9
file + sys/dev/pci/if_iwn.c
--- sys/dev/pci/if_iwn.c
+++ sys/dev/pci/if_iwn.c
@@ -3069,8 +3069,13 @@ iwn_tx(struct iwn_softc *sc, struct mbuf *m, struct ie
 
/* Check if frame must be protected using RTS/CTS or CTS-to-self. */
if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
+   int rtsthres = ic->ic_rtsthreshold;
+   if (ni->ni_flags & IEEE80211_NODE_HT)
+   rtsthres = ieee80211_mira_get_rts_threshold(>mn,
+   ic, ni, totlen + IEEE80211_CRC_LEN);
+
/* NB: Group frames are sent using CCK in 802.11b/g/n (2GHz). */
-   if (totlen + IEEE80211_CRC_LEN > ic->ic_rtsthreshold) {
+   if (totlen + IEEE80211_CRC_LEN > rtsthres) {
flags |= IWN_TX_NEED_RTS;
} else if ((ic->ic_flags & IEEE80211_F_USEPROT) &&
ridx >= IWN_RIDX_OFDM6) {
blob - 4edd26a5fde82a9d9ddfd31e0bd075c0f59d2143
file + sys/net80211/ieee80211_mira.c
--- sys/net80211/ieee80211_mira.c
+++ sys/net80211/ieee80211_mira.c
@@ -85,6 +85,9 @@ int   ieee80211_mira_valid_tx_mcs(struct ieee80211com *,
 uint32_t ieee80211_mira_valid_rates(struct ieee80211com *,
struct ieee80211_node *);
 uint32_t ieee80211_mira_mcs_below(struct ieee80211_mira_node *, int, int);
+void   ieee80211_mira_set_rts_threshold(struct ieee80211_mira_node *,
+   struct ieee80211com *, struct ieee80211_node *);
+void   ieee80211_mira_reset_collision_stats(struct ieee80211_mira_node *);
 
 /* We use fixed point arithmetic with 64 bit integers. */
 #define MIRA_FP_SHIFT  21
@@ -309,7 +312,7 @@ ieee80211_mira_ack_rate(struct ieee80211_node *ni)
 {
/* 
 * Assume the ACK was sent at a mandatory ERP OFDM rate.
-* In the worst case, the firmware has retried at non-HT rates,
+* In the worst case, the driver has retried at non-HT rates,
 * so for MCS 0 assume we didn't actually send an OFDM frame
 * and ACKs arrived at a basic rate.
  

[axen 7/7] DPRINTF and cosmetic changes

2019-02-26 Thread Nils Frohberg
cosmetic changes

---
 dev/usb/if_axen.c | 142 +++---
 1 file changed, 120 insertions(+), 22 deletions(-)

diff --git a/dev/usb/if_axen.c b/dev/usb/if_axen.c
index 817cad8..f3a71f4 100644
--- a/dev/usb/if_axen.c
+++ b/dev/usb/if_axen.c
@@ -162,7 +162,7 @@ axen_cmd(struct axen_softc *sc, int cmd, int index, int 
val, void *buf)
USETW(req.wLength, AXEN_CMD_LEN(cmd));
 
err = usbd_do_request(sc->axen_udev, , buf);
-   DPRINTFN(5, ("axen_cmd: cmd 0x%04x val 0x%04x len %d\n",
+   DPRINTFN(15, ("axen_cmd: cmd 0x%04x val 0x%04x len %d\n",
cmd, val, AXEN_CMD_LEN(cmd)));
 
if (err) {
@@ -199,7 +199,7 @@ axen_miibus_readreg(struct device *dev, int phy, int reg)
}
 
ival = UGETW(val);
-   DPRINTFN(2,("axen_miibus_readreg: phy 0x%x reg 0x%x val 0x%x\n",
+   DPRINTFN(12,("axen_miibus_readreg: phy 0x%x reg 0x%x val 0x%x\n",
phy, reg, ival));
 
if (reg == MII_BMSR) {
@@ -226,7 +226,7 @@ axen_miibus_writereg(struct device *dev, int phy, int reg, 
int val)
axen_lock_mii(sc);
err = axen_cmd(sc, AXEN_CMD_MII_WRITE_REG, reg, phy, );
axen_unlock_mii(sc);
-   DPRINTFN(2, ("axen_miibus_writereg: phy 0x%x reg 0x%x val 0x%0x\n",
+   DPRINTFN(12, ("axen_miibus_writereg: phy 0x%x reg 0x%x val 0x%0x\n",
phy, reg, val));
 
if (err) {
@@ -269,13 +269,18 @@ axen_miibus_statchg(struct device *dev)
}
 
/* Lost link, do nothing. */
-   if (sc->axen_link == 0)
+   if (sc->axen_link == 0) {
+   DPRINTF(("%s: %s: lost link\n", sc->axen_dev.dv_xname,
+   __func__));
goto done;
+   }
 
err = axen_cmd(sc, AXEN_CMD_MAC_READ, 1, AXEN_PHYSICAL_LINK_STATUS,
_status);
if (err)
goto error;
+   DPRINTF(("%s: %s: link status: 0x%x\n", sc->axen_dev.dv_xname,
+   __func__, link_status));
 
/* both freebsd and linux don't define/set AXEN_MEDIUM_ALWAYS_ONE,
 * but 6.2.2.10 of the datasheet (p40) sets it to 1 */
@@ -283,11 +288,22 @@ axen_miibus_statchg(struct device *dev)
 
if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
val |= AXEN_MEDIUM_FDX;
+#if 0
+   if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
+   val |= AXEN_MEDIUM_TXFLOW_CTRL_EN;
+   if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
+   val |= AXEN_MEDIUM_RXFLOW_CTRL_EN;
+#else
val |= AXEN_MEDIUM_TXFLOW_CTRL_EN | AXEN_MEDIUM_RXFLOW_CTRL_EN;
+#endif
}
 
switch (IFM_SUBTYPE(mii->mii_media_active)) {
case IFM_1000_T:
+   if (!(link_status & AXEN_EPHY_1000)) {
+   printf("%s: wrong phy link (want 1000)\n",
+   sc->axen_dev.dv_xname);
+   }
val |= AXEN_MEDIUM_GIGA;
if (link_status & AXEN_USB_SS)
qctrl = _bulk_size[0];
@@ -297,6 +313,10 @@ axen_miibus_statchg(struct device *dev)
qctrl = _bulk_size[3];
break;
case IFM_100_TX:
+   if (!(link_status & AXEN_EPHY_100)) {
+   printf("%s: wrong phy link (want 100)\n",
+   sc->axen_dev.dv_xname);
+   }
val |= AXEN_MEDIUM_PORTSPEED_100;
if (link_status & (AXEN_USB_SS | AXEN_USB_HS))
qctrl = _bulk_size[2];
@@ -304,6 +324,10 @@ axen_miibus_statchg(struct device *dev)
qctrl = _bulk_size[3];
break;
case IFM_10_T:
+   if (!(link_status & AXEN_EPHY_10)) {
+   printf("%s: wrong phy link (want 10)\n",
+   sc->axen_dev.dv_xname);
+   }
qctrl = _bulk_size[3];
break;
default:
@@ -314,6 +338,9 @@ axen_miibus_statchg(struct device *dev)
/* XXX change buffer size here */
 
/* RX bulk configuration. */
+   DPRINTF(("%s: %s: qtrl bufsize = 0x%x, ifg = 0x%x\n",
+   sc->axen_dev.dv_xname, __func__,
+   qctrl->bufsize, qctrl->ifg));
err = axen_cmd(sc, AXEN_CMD_MAC_SET_RXSR, 5, AXEN_RX_BULKIN_QCTRL,
qctrl);
if (err)
@@ -385,6 +412,8 @@ axen_iff(struct axen_softc *sc)
u_int8_thashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
uWord   wval;
 
+   DPRINTFN(2,("%s: %s: enter\n", sc->axen_dev.dv_xname,__func__));
+
if (usbd_is_dying(sc->axen_udev))
return;
 
@@ -422,9 +451,15 @@ axen_iff(struct axen_softc *sc)
}
}
 
-   axen_cmd(sc, AXEN_CMD_MAC_WRITE_FILTER, 8, AXEN_FILTER_MULTI, 
+   DPRINTFN(5,("%s: %s: hashtbl: %x %x %x %x %x %x %x %x\n",
+   sc->axen_dev.dv_xname,__func__,
+   

[axen 4/7] init/stop/attach/detach

2019-02-26 Thread Nils Frohberg
try to align attach/detach/init/stop routines with what freebsd and
linux are doing.

one important part of this diff is disabling Energy Efficient
Ethernet (EEE) and setting the low/high watermarks. this reduces
the amount of RXHDR_DROP_ERRs, but could maybe be tweaked (improved).

---
 dev/usb/if_axen.c| 145 +++
 dev/usb/if_axenreg.h |  20 +-
 2 files changed, 110 insertions(+), 55 deletions(-)

diff --git a/dev/usb/if_axen.c b/dev/usb/if_axen.c
index 088f40f..817cad8 100644
--- a/dev/usb/if_axen.c
+++ b/dev/usb/if_axen.c
@@ -433,13 +433,16 @@ axen_iff(struct axen_softc *sc)
 void
 axen_reset(struct axen_softc *sc)
 {
+   DPRINTFN(2,("%s: %s: enter\n", sc->axen_dev.dv_xname,__func__));
+
if (usbd_is_dying(sc->axen_udev))
return;
-   
-   axen_ax88179_init(sc);
 
/* Wait a little while for the chip to get its brains in order. */
DELAY(1000);
+
+   axen_ax88179_init(sc);
+
return;
 }
 
@@ -510,63 +513,65 @@ axen_ax88179_init(struct axen_softc *sc)
sc->axen_dev.dv_xname, ctl);
}
 
-   /* Set MAC address. */
-   axen_cmd(sc, AXEN_CMD_MAC_WRITE_ETHER, ETHER_ADDR_LEN,
-   AXEN_CMD_MAC_NODE_ID, >arpcom.ac_enaddr);
-
/*
 * set buffer high/low watermark to pause/resume.
 * write 2byte will set high/log simultaneous with AXEN_PAUSE_HIGH.
-* XXX: what is the best value? OSX driver uses 0x3c-0x4c as LOW-HIGH
-* watermark parameters.
+* XXX: what is the best value?
+* - defaults (datasheet): 0x24-0x42 as LOW-HIGH watermark parameters.
+* - OSX driver uses 0x3c-0x4c as LOW-HIGH watermark parameters.(?)
+* - FreeBSD driver uses 0x34-0x52 as LOW-HIGH watermark parameters.
+* - Linux driver uses 0x34-0x52 as LOW-HIGH watermark parameters.
 */
-   val = 0x34;
+   val = 0x24;
axen_cmd(sc, AXEN_CMD_MAC_WRITE, 1, AXEN_PAUSE_LOW_WATERMARK, );
-   val = 0x52;
+   val = 0x42;
axen_cmd(sc, AXEN_CMD_MAC_WRITE, 1, AXEN_PAUSE_HIGH_WATERMARK, );
 
/* Set RX/TX configuration. */
-   /* Offloadng enable */
 #ifdef AXEN_TOE
-   val = AXEN_RXCOE_IPv4 | AXEN_RXCOE_TCPv4 | AXEN_RXCOE_UDPv4 |
- AXEN_RXCOE_TCPv6 | AXEN_RXCOE_UDPv6;
+   /* enable offloading */
+   val = AXEN_RXCOE_IPv4 |
+ AXEN_RXCOE_TCPv4 | AXEN_RXCOE_UDPv4 | AXEN_RXCOE_ICMPv4 |
+ AXEN_RXCOE_IGMP |
+ AXEN_RXCOE_TCPv6 | AXEN_RXCOE_UDPv6 | AXEN_RXCOE_ICMPv6;
 #else
val = AXEN_RXCOE_OFF;
 #endif
axen_cmd(sc, AXEN_CMD_MAC_WRITE, 1, AXEN_RX_COE, );
 
 #ifdef AXEN_TOE
-   val = AXEN_TXCOE_IPv4 | AXEN_TXCOE_TCPv4 | AXEN_TXCOE_UDPv4 |
- AXEN_TXCOE_TCPv6 | AXEN_TXCOE_UDPv6;
+   val = AXEN_TXCOE_IPv4 |
+ AXEN_TXCOE_TCPv4 | AXEN_TXCOE_UDPv4 |AXEN_TXCOE_ICMPv4 |
+ AXEN_TXCOE_IGMP |
+ AXEN_TXCOE_TCPv6 | AXEN_TXCOE_UDPv6 | AXEN_TXCOE_ICMPv6;
 #else
val = AXEN_TXCOE_OFF;
 #endif
axen_cmd(sc, AXEN_CMD_MAC_WRITE, 1, AXEN_TX_COE, );
 
-   /* Set RX control register */
-   ctl = AXEN_RXCTL_DROPCRCERR;
-   ctl |= AXEN_RXCTL_ACPT_PHY_MCAST | AXEN_RXCTL_ACPT_ALL_MCAST;
-   ctl |= AXEN_RXCTL_START;
-   USETW(wval, ctl);
-   axen_cmd(sc, AXEN_CMD_MAC_WRITE2, 2, AXEN_MAC_RXCTL, );
-
-   /* set monitor mode (enable) */
-   val = AXEN_MONITOR_PMETYPE | AXEN_MONITOR_PMEPOL | AXEN_MONITOR_RWMP;
+   /* set monitor mode (XXX enable) */
+   /* AXEN_MONITOR_PMETYPE | AXEN_MONITOR_PMEPOL | AXEN_MONITOR_RWMP; */
+   val = 0;
axen_cmd(sc, AXEN_CMD_MAC_WRITE, 1, AXEN_MONITOR_MODE, );
+#ifdef AXEN_DEBUG
axen_cmd(sc, AXEN_CMD_MAC_READ, 1, AXEN_MONITOR_MODE, );
DPRINTF(("axen: Monitor mode = 0x%02x\n", val));
+#endif
 
/* set medium type */
-   ctl = AXEN_MEDIUM_GIGA | AXEN_MEDIUM_FDX | AXEN_MEDIUM_ALWAYS_ONE |
- AXEN_MEDIUM_RXFLOW_CTRL_EN | AXEN_MEDIUM_TXFLOW_CTRL_EN;
-   ctl |= AXEN_MEDIUM_RECV_EN;
+   ctl = AXEN_MEDIUM_GIGA | AXEN_MEDIUM_FDX |
+ AXEN_MEDIUM_RXFLOW_CTRL_EN | AXEN_MEDIUM_TXFLOW_CTRL_EN |
+ AXEN_MEDIUM_RECV_EN;
USETW(wval, ctl);
DPRINTF(("axen: set to medium mode: 0x%04x\n", UGETW(wval)));
axen_cmd(sc, AXEN_CMD_MAC_WRITE2, 2, AXEN_MEDIUM_STATUS, );
-   usbd_delay_ms(sc->axen_udev, 100);
 
+#ifdef AXEN_DEBUG
+   usbd_delay_ms(sc->axen_udev, 100);
axen_cmd(sc, AXEN_CMD_MAC_READ2, 2, AXEN_MEDIUM_STATUS, );
DPRINTF(("axen: current medium mode: 0x%04x\n", UGETW(wval)));
+#endif
+
axen_unlock_mii(sc);
 
 #if 0 /* XXX: TBD */
@@ -580,7 +585,15 @@ axen_ax88179_init(struct axen_softc *sc)
0x002c);
 #endif
 
-#if 1 /* XXX: phy hack ? */
+   /* disable eee */
+   axen_miibus_writereg(>axen_dev, sc->axen_phyno,
+   AXEN_GMII_PHY_PAGE_SELECT, AXEN_GMII_PHY_PGSEL_PAGE3);
+  

[axen 3/7] rebuild the filter flags from scratch

2019-02-26 Thread Nils Frohberg
rebuild the filter flags from scratch instead of pulling the state
from the card and setting/unsetting the necessary bits.

---
 dev/usb/if_axen.c| 23 ---
 dev/usb/if_axenreg.h |  4 ++--
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/dev/usb/if_axen.c b/dev/usb/if_axen.c
index dfdcecf..088f40f 100644
--- a/dev/usb/if_axen.c
+++ b/dev/usb/if_axen.c
@@ -392,27 +392,27 @@ axen_iff(struct axen_softc *sc)
 
/* Enable receiver, set RX mode */
axen_lock_mii(sc);
-   axen_cmd(sc, AXEN_CMD_MAC_READ2, 2, AXEN_MAC_RXCTL, );
-   rxmode = UGETW(wval);
-   rxmode &= ~(AXEN_RXCTL_ACPT_ALL_MCAST | AXEN_RXCTL_ACPT_PHY_MCAST |
- AXEN_RXCTL_PROMISC);
+   rxmode = AXEN_RXCTL_DROPCRCERR | AXEN_RXCTL_START;
ifp->if_flags &= ~IFF_ALLMULTI;
 
/*
-* Always accept broadcast frames.
 * Always accept frames destined to our station address.
 */
-   rxmode |= AXEN_RXCTL_ACPT_BCAST;
+   rxmode |= AXEN_RXCTL_ACPT_PHY_MCAST;
+   /*
+* Accept broadcast frames iff interface has IFF_BROADCAST set.
+*/
+   if (ifp->if_flags & IFF_BROADCAST)
+   rxmode |= AXEN_RXCTL_ACPT_BCAST;
 
if (ifp->if_flags & IFF_PROMISC || ac->ac_multirangecnt > 0) {
ifp->if_flags |= IFF_ALLMULTI;
-   rxmode |= AXEN_RXCTL_ACPT_ALL_MCAST | AXEN_RXCTL_ACPT_PHY_MCAST;
+   rxmode |= AXEN_RXCTL_ACPT_ALL_MCAST;
if (ifp->if_flags & IFF_PROMISC)
rxmode |= AXEN_RXCTL_PROMISC;
} else {
-   rxmode |= AXEN_RXCTL_ACPT_ALL_MCAST | AXEN_RXCTL_ACPT_PHY_MCAST;
-
-   /* now program new ones */
+   rxmode |= AXEN_RXCTL_ACPT_MCAST;
+   /* compute multicast filter array */
ETHER_FIRST_MULTI(step, ac, enm);
while (enm != NULL) {
h = ether_crc32_be(enm->enm_addrlo,
@@ -424,6 +424,7 @@ axen_iff(struct axen_softc *sc)
 
axen_cmd(sc, AXEN_CMD_MAC_WRITE_FILTER, 8, AXEN_FILTER_MULTI, 
(void *));
+
USETW(wval, rxmode);
axen_cmd(sc, AXEN_CMD_MAC_WRITE2, 2, AXEN_MAC_RXCTL, );
axen_unlock_mii(sc);
@@ -543,7 +544,7 @@ axen_ax88179_init(struct axen_softc *sc)
axen_cmd(sc, AXEN_CMD_MAC_WRITE, 1, AXEN_TX_COE, );
 
/* Set RX control register */
-   ctl = AXEN_RXCTL_DROPCRCERR | AXEN_RXCTL_AUTOB;
+   ctl = AXEN_RXCTL_DROPCRCERR;
ctl |= AXEN_RXCTL_ACPT_PHY_MCAST | AXEN_RXCTL_ACPT_ALL_MCAST;
ctl |= AXEN_RXCTL_START;
USETW(wval, ctl);
diff --git a/dev/usb/if_axenreg.h b/dev/usb/if_axenreg.h
index 336727f..766c89e 100644
--- a/dev/usb/if_axenreg.h
+++ b/dev/usb/if_axenreg.h
@@ -157,8 +157,8 @@
 #define AXEN_RXCTL_PROMISC   0x0001
 #define AXEN_RXCTL_ACPT_ALL_MCAST0x0002
 #define AXEN_RXCTL_HA8B  0x0004 
-#define AXEN_RXCTL_AUTOB 0x0008
-#define AXEN_RXCTL_ACPT_BCAST0x0010
+#define AXEN_RXCTL_ACPT_BCAST0x0008
+#define AXEN_RXCTL_ACPT_MCAST0x0010
 #define AXEN_RXCTL_ACPT_PHY_MCAST0x0020
 #define AXEN_RXCTL_START 0x0080
 #define AXEN_RXCTL_DROPCRCERR0x0100
-- 
2.20.1



[axen 2/7] set bulk buffers according to link and bus speed

2019-02-26 Thread Nils Frohberg
set bulk buffers according to link and bus speed. values are taken
from freebsd and linux drivers.

while here, only enable full duplex if link is also full duplex.

---
 dev/usb/if_axen.c| 119 +++
 dev/usb/if_axenreg.h |  13 +++--
 2 files changed, 72 insertions(+), 60 deletions(-)

diff --git a/dev/usb/if_axen.c b/dev/usb/if_axen.c
index 909c04f..dfdcecf 100644
--- a/dev/usb/if_axen.c
+++ b/dev/usb/if_axen.c
@@ -120,6 +120,13 @@ void   axen_unlock_mii(struct axen_softc *sc);
 
 void   axen_ax88179_init(struct axen_softc *);
 
+struct axen_qctrl axen_bulk_size[] = {
+   { 7, 0x4f, 0x00, AXEN_BUFSZ_SS, 0xff },
+   { 7, 0x20, 0x03, AXEN_BUFSZ_HS, 0xff },
+   { 7, 0xae, 0x07, AXEN_BUFSZ_LS, 0xff },
+   { 7, 0xcc, 0x4c, AXEN_BUFSZ_LS, 0x08 }
+};
+
 /* Get exclusive access to the MII registers */
 void
 axen_lock_mii(struct axen_softc *sc)
@@ -235,13 +242,17 @@ axen_miibus_statchg(struct device *dev)
struct mii_data *mii = GET_MII(sc);
struct ifnet*ifp;
int err;
+   uint8_t link_status;
uint16_tval;
uWord   wval;
+   struct axen_qctrl   *qctrl;
+
+   axen_lock_mii(sc);
 
ifp = GET_IFP(sc);
if (mii == NULL || ifp == NULL ||
(ifp->if_flags & IFF_RUNNING) == 0)
-   return;
+   goto done;
 
sc->axen_link = 0;
if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
@@ -249,10 +260,8 @@ axen_miibus_statchg(struct device *dev)
switch (IFM_SUBTYPE(mii->mii_media_active)) {
case IFM_10_T:
case IFM_100_TX:
-   sc->axen_link++;
-   break;
case IFM_1000_T:
-   sc->axen_link++;
+   sc->axen_link = 1;
break;
default:
break;
@@ -261,36 +270,68 @@ axen_miibus_statchg(struct device *dev)
 
/* Lost link, do nothing. */
if (sc->axen_link == 0)
-   return;
+   goto done;
 
-   val = 0;
-   if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0)
-   val |= AXEN_MEDIUM_FDX;
+   err = axen_cmd(sc, AXEN_CMD_MAC_READ, 1, AXEN_PHYSICAL_LINK_STATUS,
+   _status);
+   if (err)
+   goto error;
 
-   val |= (AXEN_MEDIUM_RECV_EN | AXEN_MEDIUM_ALWAYS_ONE);
-   val |= (AXEN_MEDIUM_RXFLOW_CTRL_EN | AXEN_MEDIUM_TXFLOW_CTRL_EN);
+   /* both freebsd and linux don't define/set AXEN_MEDIUM_ALWAYS_ONE,
+* but 6.2.2.10 of the datasheet (p40) sets it to 1 */
+   val = AXEN_MEDIUM_RECV_EN | AXEN_MEDIUM_ALWAYS_ONE;
+
+   if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
+   val |= AXEN_MEDIUM_FDX;
+   val |= AXEN_MEDIUM_TXFLOW_CTRL_EN | AXEN_MEDIUM_RXFLOW_CTRL_EN;
+   }
 
switch (IFM_SUBTYPE(mii->mii_media_active)) {
case IFM_1000_T:
-   val |= AXEN_MEDIUM_GIGA | AXEN_MEDIUM_EN_125MHZ;
+   val |= AXEN_MEDIUM_GIGA;
+   if (link_status & AXEN_USB_SS)
+   qctrl = _bulk_size[0];
+   else if (link_status & AXEN_USB_HS)
+   qctrl = _bulk_size[1];
+   else
+   qctrl = _bulk_size[3];
break;
case IFM_100_TX:
-   val |= AXEN_MEDIUM_PS;
+   val |= AXEN_MEDIUM_PORTSPEED_100;
+   if (link_status & (AXEN_USB_SS | AXEN_USB_HS))
+   qctrl = _bulk_size[2];
+   else
+   qctrl = _bulk_size[3];
break;
case IFM_10_T:
-   /* doesn't need to be handled */
+   qctrl = _bulk_size[3];
break;
+   default:
+   printf("%s: unknown uplink bus: 0x%02x\n",
+   sc->axen_dev.dv_xname, link_status);
+   goto error;
}
+   /* XXX change buffer size here */
+
+   /* RX bulk configuration. */
+   err = axen_cmd(sc, AXEN_CMD_MAC_SET_RXSR, 5, AXEN_RX_BULKIN_QCTRL,
+   qctrl);
+   if (err)
+   goto error;
 
-   DPRINTF(("axen_miibus_statchg: val=0x%x\n", val));
+   DPRINTF(("%s: %s: val=0x%x\n", sc->axen_dev.dv_xname, __func__,val));
USETW(wval, val);
-   axen_lock_mii(sc);
err = axen_cmd(sc, AXEN_CMD_MAC_WRITE2, 2, AXEN_MEDIUM_STATUS, );
+   if (err)
+   goto error;
+
+   goto done;
+
+error:
+   printf("%s: media change failed (err: 0x%x)\n", sc->axen_dev.dv_xname,
+   err);
+done:
axen_unlock_mii(sc);
-   if (err) {
-   printf("%s: media change failed\n", sc->axen_dev.dv_xname);
-   return;
-   }
 }
 
 /*
@@ -407,7 +448,6 @@ axen_ax88179_init(struct 

[axen 1/7] rx path

2019-02-26 Thread Nils Frohberg
adjust rx path:
- do not set RXCTL_IPE, thus eliminating padding bytes on each
  packet
- switch from MGETHDR/MCLGET/memcpy to m_getdev
- improve buffer length and packet checks

---
 dev/usb/if_axen.c| 172 +++
 dev/usb/if_axenreg.h |   4 +
 2 files changed, 95 insertions(+), 81 deletions(-)

diff --git a/dev/usb/if_axen.c b/dev/usb/if_axen.c
index 190bf2e..909c04f 100644
--- a/dev/usb/if_axen.c
+++ b/dev/usb/if_axen.c
@@ -97,7 +97,6 @@ const struct cfattach axen_ca = {
 
 intaxen_tx_list_init(struct axen_softc *);
 intaxen_rx_list_init(struct axen_softc *);
-struct mbuf *axen_newbuf(void);
 intaxen_encap(struct axen_softc *, struct mbuf *, int);
 void   axen_rxeof(struct usbd_xfer *, void *, usbd_status);
 void   axen_txeof(struct usbd_xfer *, void *, usbd_status);
@@ -535,7 +534,7 @@ axen_ax88179_init(struct axen_softc *sc)
axen_cmd(sc, AXEN_CMD_MAC_WRITE, 1, AXEN_TX_COE, );
 
/* Set RX control register */
-   ctl = AXEN_RXCTL_IPE | AXEN_RXCTL_DROPCRCERR | AXEN_RXCTL_AUTOB;
+   ctl = AXEN_RXCTL_DROPCRCERR | AXEN_RXCTL_AUTOB;
ctl |= AXEN_RXCTL_ACPT_PHY_MCAST | AXEN_RXCTL_ACPT_ALL_MCAST;
ctl |= AXEN_RXCTL_START;
USETW(wval, ctl);
@@ -787,27 +786,6 @@ axen_detach(struct device *self, int flags)
return 0;
 }
 
-struct mbuf *
-axen_newbuf(void)
-{
-   struct mbuf *m;
-
-   MGETHDR(m, M_DONTWAIT, MT_DATA);
-   if (m == NULL)
-   return NULL;
-
-   MCLGET(m, M_DONTWAIT);
-   if (!(m->m_flags & M_EXT)) {
-   m_freem(m);
-   return NULL;
-   }
-
-   m->m_len = m->m_pkthdr.len = MCLBYTES;
-   m_adj(m, ETHER_ALIGN);
-
-   return m;
-}
-
 int
 axen_rx_list_init(struct axen_softc *sc)
 {
@@ -885,11 +863,13 @@ axen_rxeof(struct usbd_xfer *xfer, void *priv, 
usbd_status status)
struct mbuf *m;
u_int32_t   total_len;
u_int32_t   rx_hdr, pkt_hdr;
-   u_int32_t   *hdr_p;
+   u_int32_t   *hdr_p, *pkt_end, *hdr_end;
u_int16_t   hdr_offset, pkt_count;
size_t  pkt_len;
-   size_t  temp;
int s;
+#ifdef AXEN_DEBUG
+   u_int16_t   total_pkt_count;
+#endif
 
DPRINTFN(10,("%s: %s: enter\n", sc->axen_dev.dv_xname,__func__));
 
@@ -913,56 +893,72 @@ axen_rxeof(struct usbd_xfer *xfer, void *priv, 
usbd_status status)
 
usbd_get_xfer_status(xfer, NULL, NULL, _len, NULL);
 
-   if (total_len < sizeof(pkt_hdr)) {
+   if (total_len < sizeof(rx_hdr)) {
+   printf("%s: rxeof: too short transfer (len %u)\n",
+   sc->axen_dev.dv_xname, total_len);
+   ifp->if_ierrors++;
+   goto done;
+   }
+
+   if (total_len > sc->axen_bufsz) {
+   printf("%s: rxeof: too large transfer (len %u)\n",
+   sc->axen_dev.dv_xname, total_len);
ifp->if_ierrors++;
goto done;
}
 
-   /* 
-* buffer map
-* [packet #0]...[packet #n][pkt hdr#0]..[pkt hdr#n][recv_hdr]
-* each packet has 0x as psuedo header..
+   /*
+* <- total_len >
+* [pkt #0]...[pkt #n][pkt_hdr #0]...[pkt_hdr #n][rx_hdr]
+* ^buf   ^pkt_end   ^hdr_end
+*
+* Each RX frame is aligned on 8 bytes boundary. If RXCTL_IPE
+* bit is set in MAC_RXCTL register, there would be 2
+* padding bytes and 6 dummy bytes(as the padding also should
+* be aligned on 8 bytes boundary) for each RX frame to align
+* IP header on 32bits boundary. We don't set RXCTL_IPE bit
+* of MAC_RXCTL register, so there should be no padding bytes
+* which simplifies RX logic a lot.
 */
-   hdr_p = (u_int32_t *)(buf + total_len - sizeof(u_int32_t));
-   rx_hdr = letoh32(*hdr_p);
+
+   hdr_end = (u_int32_t *)(buf + total_len - sizeof(rx_hdr));
+   rx_hdr = le32toh(*hdr_end);
hdr_offset = (u_int16_t)(rx_hdr >> 16);
pkt_count  = (u_int16_t)(rx_hdr & 0x);
 
-   if (total_len > sc->axen_bufsz) {
-   printf("%s: rxeof: too large transfer\n",
-   sc->axen_dev.dv_xname);
-   goto done;
-   }
+#ifdef AXEN_DEBUG
+   total_pkt_count = pkt_count;
+#endif
 
/* sanity check */
-   if (hdr_offset > total_len) {
+   if (hdr_offset > total_len - sizeof(rx_hdr)) {
ifp->if_ierrors++;
goto done;
}
 
/* point first packet header */
-   hdr_p = (u_int32_t*)(buf + hdr_offset);
-
-   /*
-* ax88179 will pack multiple ip packet to a USB transaction.
-* process all of packets in the buffer
-*/
+   hdr_p = pkt_end = (u_int32_t *)(buf + hdr_offset);
 
-#if 1 /* 

Re: patch axen(4) (WIP)

2019-02-26 Thread Nils Frohberg
On Mon, Feb 25, 2019 at 03:50:48PM -0300, Martin Pieuchot wrote:
> On 25/02/19(Mon) 14:52, Nils Frohberg wrote:
> > Hi,
> > 
> > as mentioned previously, I'm looking into axen(4). While searching
> > for the cause of a panic (fixed since, thanks mpi@) I started to
> > rewrite parts of the driver. References were mainly the FreeBSD and
> > Linux drivers.
> 
> Please try to isolate parts of your diff that fixes issues and cosmetic
> changes.  The simpler it gets the easier it is for us to review it.

Sure, I'll send separate patches.

(I cvs up'ed my src forder in order to test compile the individual
patches and found out that xhci.c,v1.91 breaks my USB devices. I'll
send a mail to bugs@ later.)

> > I didn't get around to much testing/debugging lately, therefore I
> > wanted to share the current state (diff below).
> > 
> > The current state works a lot better than previously (for me). I
> > used to have a huge amount of ierrs (aprrox. 1 ierr per ipkt) and
> > often no packets would be transferred at all (or stop being transferred
> > after some time).
> 
> Do you know why?  What were the problems?

I'm not 100% sure, since I did a lot of back and forth. It finally
got better once I disabled EEE and lowered the watermark levels.

> > This box hosts backups (rsync and TimeMachine), so it gets its fair
> > share of traffic. I could reduce the ierrs to ~2100 with 5d uptime,
> > and the packets keep flowing:
> > 
> > $ netstat -niI axen0
> > NameMtu   Network Address  Ipkts IerrsOpkts Oerrs 
> > Colls
> > axen0   150094:c6:91:1f:85:a5 141199356  2099 112289969 0 
> > 0
> > $ uptime
> >  7:15PM  up 5 days,  9:57, 3 users, load averages: 0.11, 0.13, 0.14
> > $ 
> > 
> > But there a still a few problems:
> > 
> > 1) There are still ierrs. These happen when the rx path can't
> > allocate mbufs (cf. diff below for DPRINTF):
> > axen0: could not allocate rx mbuf (2 total, 2 remaining)
> > axen0: could not allocate rx mbuf (3 total, 3 remaining)
> > axen0: could not allocate rx mbuf (2 total, 2 remaining)
> > axen0: could not allocate rx mbuf (1 total, 1 remaining)
> 
> Look at the pools when this happen, what do you see?  What is the size
> of `pkt_len' when this happen?

I added pkt_len to the DPRINTF so that I can check the relevant
pools once I see this error.

> > 2) If the adapter is plugged into a USB 3 port at boot, it will
> > return 0x42 when aked for AXEN_PHYSICAL_LINK_STATUS, ie.
> > (AXEN_EPHY_1000|AXEN_USB_HS). The adapter most often then simply
> > doesn't receive packets. If I plug in the adapter after boot is
> > complete, 0x44 is returned (AXEN_EPHY_1000|AXEN_USB_SS), as expected.
> > I'm not sure if I'm still missing something in init (probably) or
> > if this results from something higher in the stack (xhci?).
> > (Didn't test USB 2 or lower.)
> 
> Do you see any difference in 'usbdevs -vv' output during the two cases? 

Yes, high speed vs super speed and power draw:

# Plugged in after boot:

$ usbdevs -vv
Controller /dev/usb0:
addr 01: 8086: Intel, xHCI root hub
 super speed, self powered, config 1, rev 1.00
 driver: uhub0
 port 01: 0001.02a0 power Rx.detect
 port 02: 0011.02a0 power Rx.detect
 port 03: .0503 connect enabled recovery
 port 04: .0503 connect enabled recovery
 port 05: .02a0 power Rx.detect
 port 06: .02a0 power Rx.detect
 port 07: .02a0 power Rx.detect
 port 08: .0103 connect enabled recovery
 port 09: .02a0 power Rx.detect
 port 10: .0203 connect enabled power U0
 port 11: .0203 connect enabled power U0
 port 12: .0203 connect enabled power U0
 port 13: .02a0 power Rx.detect
 port 14: .02a0 power Rx.detect
 port 15: .02a0 power Rx.detect
addr 04: 0bc2:ab44 Seagate, Backup+ Hub
 high speed, self powered, config 1, rev 48.85, iSerial 01CB7236B0N6
 driver: uhub2
 port 01: .0100 power
 port 02: .0100 power
 port 03: .0100 power
addr 05: 05e3:0610 GenesysLogic, USB2.0 Hub
 high speed, self powered, config 1, rev 92.16
 driver: uhub3
 port 01: .0100 power
 port 02: .0100 power
 port 03: .0100 power
 port 04: .0100 power
addr 06: 8087:0aa7 Intel, product 0x0aa7
 full speed, self powered, config 1, rev 0.01
 driver: ugen0
addr 07: 0bc2:ab45 Seagate, Backup+ Hub
 super speed, self powered, config 1, rev 48.85, iSerial 01CB7236B0N6
 driver: uhub4
 port 01: .0203 connect enabled power U0
 port 02: .02a0 power Rx.detect
 port 03: .0203 connect enabled power U0
addr 08: 0bc2:ab38 Seagate, Backup+ Hub BK
 super speed, self powered, config 1, rev 1.00, iSerial NA8TMK6F
 driver: umass0
addr 09: 05e3:0612 GenesysLogic, USB3.0 Hub
 super speed, self powered, config 

less(1) UTF-8 cleanup: store_char()

2019-02-26 Thread Ingo Schwarze
Hi,

Nicholas Marriott wrote on Tue, Feb 26, 2019 at 07:20:47AM +:

> Looks good, ok nicm

Thanks to all of you for checking.

Here is the next step, slowly coming closer to the meat of the
matter: Start cleaning up the function store_char(), which takes a
wide character, receiving both the Unicode codepoint "LWCHAR ch"
and the UTF-8 multibyte representation "char *rep" as (redundant)
input, behaves specially when ch is part of an ESC[...m ANSI sequence,
otherwise measures the display width of ch, checks that it still
fits on the screen, copies the multibyte representation to the line
buffer, and advances the global variables "curr" (byte position)
and "column" (visual display position).

This is the only function calling in_ansi_esc_seq(), and having that
function separate is actually counter-productive: if an escape sequence
is found, then store_char() currently does the same backward iteration
again if the sequence is incomplete and needs to be deleted.
Consequently, merging in_ansi_esc_seq() into store_char() simplifies
the code.

If ch neither continues an ANSI sequence begun earlier nor starts a
new one, the code needs to find the previous character in order to
measure the width of the current one with pwidth(): the current one
might be BACKSPACE.  Currently, this backward iteration is done
with the horrific, buggy function step_char(-1) which we aim to
delete.  Instead, iterate backwards until we find something that
is not a UTF-8 continuation byte (i.e. which is an ASCII byte or a
UTF-8 start byte) then decode the character with the standard
function mbtowc(3).

For extra safety, let's not only check that the previous character
is valid (mbtowc() != -1) but also that there are no stray continuation
bytes between the previous character and the character currently
being added (i + w == curr).  Maybe invalid UTF-8 can't actually
make it into the line buffer, but let's better play it safe.  If
there is no previous character on the line, if it is invalid, or
if there are stray continuation bytes after it, use a dummy blank,
which means that in case of doubt, we assume that a backspace backs
up by one visual column.

Note that the function still contains a call to the buggy function
utf_len() that we want to delete.  Ultimately, most instances of
utf_len() will be replaced with the standard function mblen(3), but
we can't do that right now in store_char().  At this point, the
function store_char() may still receive bogus characters incorrectly
parsed with get_wchar(), and handling these at least consistently
(even though not correctly) requires sticking with utf_len() for
now.

I tested that emboldening with "c\bc" and underlining with "c\b_"
still works, even when "c" is a width two East Asian character,
and that behaviour is sane with intervening stray continuation
bytes.

OK?
  Ingo


Index: line.c
===
RCS file: /cvs/src/usr.bin/less/line.c,v
retrieving revision 1.24
diff -u -p -r1.24 line.c
--- line.c  26 Feb 2019 11:01:54 -  1.24
+++ line.c  26 Feb 2019 12:26:42 -
@@ -458,27 +458,6 @@ backc(void)
 }
 
 /*
- * Are we currently within a recognized ANSI escape sequence?
- */
-static int
-in_ansi_esc_seq(void)
-{
-   int i;
-
-   /*
-* Search backwards for either an ESC (which means we ARE in a seq);
-* or an end char (which means we're NOT in a seq).
-*/
-   for (i = curr - 1; i >= 0; i--) {
-   if (linebuf[i] == ESC)
-   return (1);
-   if (!is_ansi_middle(linebuf[i]))
-   return (0);
-   }
-   return (0);
-}
-
-/*
  * Is a character the end of an ANSI escape sequence?
  */
 int
@@ -512,6 +491,7 @@ is_ansi_middle(LWCHAR ch)
 static int
 store_char(LWCHAR ch, char a, char *rep, off_t pos)
 {
+   int i;
int w;
int replen;
char cs;
@@ -529,22 +509,43 @@ store_char(LWCHAR ch, char a, char *rep,
}
}
 
-   if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq()) {
-   if (!is_ansi_end(ch) && !is_ansi_middle(ch)) {
+   w = -1;
+   if (ctldisp == OPT_ONPLUS) {
+   /*
+* Set i to the beginning of an ANSI escape sequence
+* that was begun and not yet ended, or to -1 otherwise.
+*/
+   for (i = curr - 1; i >= 0; i--) {
+   if (linebuf[i] == ESC)
+   break;
+   if (!is_ansi_middle(linebuf[i]))
+   i = 0;
+   }
+   if (i >= 0 && !is_ansi_end(ch) && !is_ansi_middle(ch)) {
/* Remove whole unrecognized sequence.  */
-   do {
-   curr--;
-   } while (curr > 0 && linebuf[curr] != ESC);
+   curr = i;
return (0);
}
- 

bgpd another sockaddr conversion

2019-02-26 Thread Claudio Jeker
That last usage of ss_len in bgpctl is there to print the local and remote
connection info. Now there are two options, a) pass or deduce the length
or b) don't use sockaddr_storage to pass this data around.
Now after a bit of back and forth I decided to go for b) since it
simplifies some code in bgpd and also bgpctl becomes a bit lighter.
So this diff does exactly that.

-- 
:wq Claudio

Index: bgpctl/bgpctl.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.233
diff -u -p -r1.233 bgpctl.c
--- bgpctl/bgpctl.c 25 Feb 2019 11:51:58 -  1.233
+++ bgpctl/bgpctl.c 26 Feb 2019 10:18:49 -
@@ -657,7 +657,7 @@ show_neighbor_msg(struct imsg *imsg, enu
struct peer *p;
struct ctl_timer*t;
struct in_addr   ina;
-   char buf[NI_MAXHOST], pbuf[NI_MAXSERV], *s;
+   char*s;
int  hascapamp = 0;
u_int8_t i;
 
@@ -759,25 +759,11 @@ show_neighbor_msg(struct imsg *imsg, enu
if (errstr)
printf("  Last error: %s\n\n", errstr);
} else {
-   if (getnameinfo((struct sockaddr *)>sa_local,
-   (socklen_t)p->sa_local.ss_len,
-   buf, sizeof(buf), pbuf, sizeof(pbuf),
-   NI_NUMERICHOST | NI_NUMERICSERV)) {
-   strlcpy(buf, "(unknown)", sizeof(buf));
-   strlcpy(pbuf, "", sizeof(pbuf));
-   }
-   printf("  Local host:  %20s, Local port:  %5s\n", buf,
-   pbuf);
+   printf("  Local host:  %20s, Local port:  %5u\n",
+   log_addr(>local), p->local_port);
 
-   if (getnameinfo((struct sockaddr *)>sa_remote,
-   (socklen_t)p->sa_remote.ss_len,
-   buf, sizeof(buf), pbuf, sizeof(pbuf),
-   NI_NUMERICHOST | NI_NUMERICSERV)) {
-   strlcpy(buf, "(unknown)", sizeof(buf));
-   strlcpy(pbuf, "", sizeof(pbuf));
-   }
-   printf("  Remote host: %20s, Remote port: %5s\n", buf,
-   pbuf);
+   printf("  Remote host: %20s, Remote port: %5u\n",
+   log_addr(>remote), p->remote_port);
printf("\n");
}
break;
Index: bgpctl/parser.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/parser.c,v
retrieving revision 1.91
diff -u -p -r1.91 parser.c
--- bgpctl/parser.c 18 Feb 2019 21:10:25 -  1.91
+++ bgpctl/parser.c 26 Feb 2019 10:19:10 -
@@ -944,7 +944,7 @@ parse_addr(const char *word, struct bgpd
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(word, "0", , ) == 0) {
-   sa2addr(r->ai_addr, addr);
+   sa2addr(r->ai_addr, addr, NULL);
freeaddrinfo(r);
return (1);
}
Index: bgpd/bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.374
diff -u -p -r1.374 bgpd.h
--- bgpd/bgpd.h 21 Feb 2019 11:17:22 -  1.374
+++ bgpd/bgpd.h 26 Feb 2019 10:15:47 -
@@ -1301,7 +1301,7 @@ intafi2aid(u_int16_t, u_int8_t, u_int
 sa_family_t aid2af(u_int8_t);
 int af2aid(sa_family_t, u_int8_t, u_int8_t *);
 struct sockaddr*addr2sa(struct bgpd_addr *, u_int16_t, socklen_t *);
-voidsa2addr(struct sockaddr *, struct bgpd_addr *);
+voidsa2addr(struct sockaddr *, struct bgpd_addr *, u_int16_t *);
 const char *get_baudrate(unsigned long long, char *);
 
 static const char * const log_procnames[] = {
Index: bgpd/config.c
===
RCS file: /cvs/src/usr.sbin/bgpd/config.c,v
retrieving revision 1.83
diff -u -p -r1.83 config.c
--- bgpd/config.c   18 Feb 2019 09:58:19 -  1.83
+++ bgpd/config.c   26 Feb 2019 10:16:16 -
@@ -367,7 +367,7 @@ host_ip(const char *s, struct bgpd_addr 
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(s, NULL, , ) == 0) {
*len = res->ai_family == AF_INET6 ? 128 : 32;
-   sa2addr(res->ai_addr, h);
+   sa2addr(res->ai_addr, h, NULL);
freeaddrinfo(res);
} else {/* ie. for 10/8 parsing */
if ((bits = inet_net_pton(AF_INET, s, >v4, sizeof(h->v4))) 
== -1)
Index: bgpd/mrt.c
===
RCS file: