Re: make ssh -qO {stop,exit} less noisy

2016-10-19 Thread Darren Tucker
patch applied, thanks.

On Sun, Oct 16, 2016 at 11:20 AM, Tim Kuijsten  wrote:
> Hi tech@
>
> This makes the tear down of ssh control masters better play with shell
> scripts that are run by cron. If nothing unexpected happens and in quiet
> mode, then don't echo back the command that is being requested.
>
> -Tim
>
>
> Index: mux.c
> ===
> RCS file: /cvs/src/usr.bin/ssh/mux.c,v
> retrieving revision 1.62
> diff -u -p -r1.62 mux.c
> --- mux.c   30 Sep 2016 09:19:13 -  1.62
> +++ mux.c   16 Oct 2016 18:18:53 -
> @@ -2212,7 +2212,8 @@ muxclient(const char *path)
> exit(0);
> case SSHMUX_COMMAND_TERMINATE:
> mux_client_request_terminate(sock);
> -   fprintf(stderr, "Exit request sent.\r\n");
> +   if (options.log_level != SYSLOG_LEVEL_QUIET)
> +   fprintf(stderr, "Exit request sent.\r\n");
> exit(0);
> case SSHMUX_COMMAND_FORWARD:
> if (mux_client_forwards(sock, 0) != 0)
> @@ -2230,7 +2231,8 @@ muxclient(const char *path)
> exit(0);
> case SSHMUX_COMMAND_STOP:
> mux_client_request_stop_listening(sock);
> -   fprintf(stderr, "Stop listening request sent.\r\n");
> +   if (options.log_level != SYSLOG_LEVEL_QUIET)
> +   fprintf(stderr, "Stop listening request sent.\r\n");
> exit(0);
> case SSHMUX_COMMAND_CANCEL_FWD:
> if (mux_client_forwards(sock, 1) != 0)
>



-- 
Darren Tucker (dtucker at zip.com.au)
GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860  37F4 9357 ECEF 11EA A6FA (new)
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.



pf_route pf_pdesc

2016-10-19 Thread Alexander Bluhm
Hi,

I would like to pass a struct pf_pdesc to pf_route() like it is
done in the other pf functions.  That means less parameters, more
consistency and later I can call functions that need an pd from
pf_route().

Unfortunately pf_route() is called from pfsync which has no idea
of packet descriptors.  As I do not want to rewrite pfsync, I create
a temporary pf_pdesc on the stack.

ok?

bluhm

Index: net/if_pfsync.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_pfsync.c,v
retrieving revision 1.235
diff -u -p -u -p -r1.235 if_pfsync.c
--- net/if_pfsync.c 4 Oct 2016 13:54:32 -   1.235
+++ net/if_pfsync.c 19 Oct 2016 21:22:27 -
@@ -1732,6 +1732,7 @@ void
 pfsync_undefer(struct pfsync_deferral *pd, int drop)
 {
struct pfsync_softc *sc = pfsyncif;
+   struct pf_pdesc pdesc;
 
splsoftassert(IPL_SOFTNET);
 
@@ -1743,17 +1744,18 @@ pfsync_undefer(struct pfsync_deferral *p
m_freem(pd->pd_m);
else {
if (pd->pd_st->rule.ptr->rt == PF_ROUTETO) {
+   memset(, 0, sizeof(pdesc));
+   pdesc.dir = pd->pd_st->direction;
+   pdesc.kif = pd->pd_st->rt_kif;
switch (pd->pd_st->key[PF_SK_WIRE]->af) {
case AF_INET:
-   pf_route(>pd_m, pd->pd_st->rule.ptr,
-   pd->pd_st->direction,
-   pd->pd_st->rt_kif->pfik_ifp, pd->pd_st);
+   pf_route(>pd_m, ,
+   pd->pd_st->rule.ptr, pd->pd_st);
break;
 #ifdef INET6
case AF_INET6:
-   pf_route6(>pd_m, pd->pd_st->rule.ptr,
-   pd->pd_st->direction,
-   pd->pd_st->rt_kif->pfik_ifp, pd->pd_st);
+   pf_route6(>pd_m, ,
+   pd->pd_st->rule.ptr, pd->pd_st);
break;
 #endif /* INET6 */
}
Index: net/pf.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf.c,v
retrieving revision 1.992
diff -u -p -u -p -r1.992 pf.c
--- net/pf.c18 Oct 2016 13:28:01 -  1.992
+++ net/pf.c19 Oct 2016 21:26:59 -
@@ -5764,7 +5764,7 @@ pf_rtlabel_match(struct pf_addr *addr, s
 }
 
 void
-pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
+pf_route(struct mbuf **m, struct pf_pdesc *pd, struct pf_rule *r,
 struct pf_state *s)
 {
struct mbuf *m0, *m1;
@@ -5777,8 +5777,7 @@ pf_route(struct mbuf **m, struct pf_rule
int  error = 0;
unsigned int rtableid;
 
-   if (m == NULL || *m == NULL || r == NULL ||
-   (dir != PF_IN && dir != PF_OUT) || oifp == NULL)
+   if (m == NULL || *m == NULL || r == NULL)
panic("pf_route: invalid parameters");
 
if ((*m)->m_pkthdr.pf.routed++ > 3) {
@@ -5791,7 +5790,7 @@ pf_route(struct mbuf **m, struct pf_rule
if ((m0 = m_dup_pkt(*m, max_linkhdr, M_NOWAIT)) == NULL)
return;
} else {
-   if ((r->rt == PF_REPLYTO) == (r->direction == dir))
+   if ((r->rt == PF_REPLYTO) == (r->direction == pd->dir))
return;
m0 = *m;
}
@@ -5856,7 +5855,7 @@ pf_route(struct mbuf **m, struct pf_rule
goto bad;
 
 
-   if (oifp != ifp) {
+   if (pd->kif->pfik_ifp != ifp) {
if (pf_test(AF_INET, PF_OUT, ifp, ) != PF_PASS)
goto bad;
else if (m0 == NULL)
@@ -5931,7 +5930,7 @@ bad:
 
 #ifdef INET6
 void
-pf_route6(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
+pf_route6(struct mbuf **m, struct pf_pdesc *pd, struct pf_rule *r,
 struct pf_state *s)
 {
struct mbuf *m0;
@@ -5944,8 +5943,7 @@ pf_route6(struct mbuf **m, struct pf_rul
struct m_tag*mtag;
unsigned int rtableid;
 
-   if (m == NULL || *m == NULL || r == NULL ||
-   (dir != PF_IN && dir != PF_OUT) || oifp == NULL)
+   if (m == NULL || *m == NULL || r == NULL)
panic("pf_route6: invalid parameters");
 
if ((*m)->m_pkthdr.pf.routed++ > 3) {
@@ -5958,7 +5956,7 @@ pf_route6(struct mbuf **m, struct pf_rul
if ((m0 = m_dup_pkt(*m, max_linkhdr, M_NOWAIT)) == NULL)
return;
} else {
-   if ((r->rt == PF_REPLYTO) == (r->direction == dir))
+   if ((r->rt == PF_REPLYTO) == (r->direction == pd->dir))
return;
m0 = *m;
}
@@ -6004,7 +6002,7 @@ pf_route6(struct mbuf **m, struct 

remove useless extern declaration

2016-10-19 Thread Jan Stary
extern char *optarg is already declared in unistd.h
This is the only occurence in src/sbin and src/bin;
others will follow in separate mails.

Jan


Index: bioctl.c
===
RCS file: /cvs/src/sbin/bioctl/bioctl.c,v
retrieving revision 1.139
diff -u -p -r1.139 bioctl.c
--- bioctl.c21 Sep 2016 17:50:05 -  1.139
+++ bioctl.c19 Oct 2016 21:43:43 -
@@ -59,7 +59,7 @@ struct timing {
int start;
 };
 
-void   usage(void);
+static void __dead usage(void);
 const char *str2locator(const char *, struct locator *);
 const char *str2patrol(const char *, struct timing *);
 void   bio_status(struct bio_status *);
@@ -100,7 +100,6 @@ int
 main(int argc, char *argv[])
 {
struct bio_locate   bl;
-   extern char *optarg;
u_int64_t   func = 0;
char*devicename = NULL;
char*realname = NULL, *al_arg = NULL;
@@ -273,7 +272,7 @@ main(int argc, char *argv[])
return (0);
 }
 
-void
+static void __dead
 usage(void)
 {
extern char *__progname;



aml_rdpciaddr is busted

2016-10-19 Thread Mark Kettenis
The bus number it reports will be totally bogus for devices behind PCI
bridges.  As a consequence AML will peek and poke at registers of the
wrong device.  This is what caused the suspend issues with Joris'
Macbook.

The diff below attempts to fix this by using the mapping between AML
nodes and PCI devices that we establish.  Because _INI methods may end
up executing AML that ends up calling aml_rdpciaddr(), the mapping is
now established before we execute _INI.  I'm not 100% sure this is
correct as there is a possibility that _INI will poke some PCI bridges
in a way that changes the mapping.  Only one way to find out...

The code also deals with devices that aren't there in a slightly
different way.  They are now included in the node -> PCI mapping, but
they're still not included in the list of PCI device nodes that we
create.  Writing to config space for devices that aren't there is
implemented as a no-op.  Reading will return an all-ones pattern.

So far I've only tested this on my x1.  More testing is needed.


Index: dev/acpi/acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.316
diff -u -p -r1.316 acpi.c
--- dev/acpi/acpi.c 18 Sep 2016 23:56:45 -  1.316
+++ dev/acpi/acpi.c 19 Oct 2016 19:42:51 -
@@ -614,6 +614,7 @@ acpi_getpci(struct aml_node *node, void 
pci->dev = ACPI_ADR_PCIDEV(val);
pci->fun = ACPI_ADR_PCIFUN(val);
pci->node = node;
+   node->pci = pci;
pci->sub = -1;
 
dnprintf(10, "%.2x:%.2x.%x -> %s\n", 
@@ -639,17 +640,12 @@ acpi_getpci(struct aml_node *node, void 
pci->_s4w = -1;
 
/* Check if PCI device exists */
-   if (pci->dev > 0x1F || pci->fun > 7) {
-   free(pci, M_DEVBUF, sizeof(*pci));
-   return (1);
-   }
+   if (pci->dev > 31 || pci->fun > 7)
+   return 1;
tag = pci_make_tag(pc, pci->bus, pci->dev, pci->fun);
reg = pci_conf_read(pc, tag, PCI_ID_REG);
-   if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID) {
-   free(pci, M_DEVBUF, sizeof(*pci));
-   return (1);
-   }
-   node->pci = pci;
+   if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID)
+   return 1;
 
TAILQ_INSERT_TAIL(_pcidevs, pci, next);
 
@@ -1066,11 +1062,11 @@ acpi_attach(struct device *parent, struc
config_found_sm(self, , acpi_print, acpi_submatch);
}
 
+   /* get PCI mapping */
+   aml_walknodes(_root, AML_WALK_PRE, acpi_getpci, sc);
+
/* initialize runtime environment */
aml_find_node(_root, "_INI", acpi_inidev, sc);
-
-   /* Get PCI mapping */
-   aml_walknodes(_root, AML_WALK_PRE, acpi_getpci, sc);
 
/* attach pci interrupt routing tables */
aml_find_node(_root, "_PRT", acpi_foundprt, sc);
Index: dev/acpi/dsdt.c
===
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.225
diff -u -p -r1.225 dsdt.c
--- dev/acpi/dsdt.c 27 Sep 2016 10:04:19 -  1.225
+++ dev/acpi/dsdt.c 19 Oct 2016 19:42:51 -
@@ -2216,21 +2216,16 @@ aml_rdpciaddr(struct aml_node *pcidev, u
 {
int64_t res;
 
-   if (aml_evalinteger(acpi_softc, pcidev, "_ADR", 0, NULL, ) == 0) {
-   addr->fun = res & 0x;
-   addr->dev = res >> 16;
-   }
-   while (pcidev != NULL) {
-   /* HID device (PCI or PCIE root): eval _BBN */
-   if (__aml_search(pcidev, "_HID", 0)) {
-   if (aml_evalinteger(acpi_softc, pcidev, "_BBN", 0, 
NULL, ) == 0) {
-   addr->bus = res;
-   break;
-   }
-   }
-   pcidev = pcidev->parent;
-   }
-   return (0);
+   if (pcidev->pci == NULL)
+   return -1;
+
+   if (aml_evalinteger(acpi_softc, pcidev, "_ADR", 0, NULL, ))
+   return -1;
+
+   addr->fun = res & 0x;
+   addr->dev = res >> 16;
+   addr->bus = pcidev->pci->bus;
+   return 0;
 }
 
 /* Read/Write from opregion object */
@@ -2272,7 +2267,12 @@ aml_rwgas(struct aml_value *rgn, int bpo
 
if (rgn->v_opregion.iospace == GAS_PCI_CFG_SPACE) {
/* Get PCI Root Address for this opregion */
-   aml_rdpciaddr(rgn->node->parent, );
+   if (aml_rdpciaddr(rgn->node->parent, )) {
+   if (mode == ACPI_IOREAD)
+   pi.fun = 0x;
+   else
+   return;
+   }
}
 
tbit = _integer;



Re: malloc canaries for > page sized objects

2016-10-19 Thread Otto Moerbeek
On Tue, Oct 18, 2016 at 11:12:39AM +0200, Theo Buehler wrote:

> > That is certainly not correct: snprintf and friends return the length as
> > it would have been if an infinite buffer was passed in. 
> > So the strlen should stay.
> 

New diff, though the snprintf return value check might be overkill.

-Otto

Index: malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.202
diff -u -p -r1.202 malloc.c
--- malloc.c15 Oct 2016 18:24:40 -  1.202
+++ malloc.c19 Oct 2016 19:00:33 -
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -199,6 +200,8 @@ static union {
 char   *malloc_options;/* compile-time options */
 
 static u_char getrbyte(struct dir_info *d);
+static __dead void wrterror(struct dir_info *d, char *msg, ...)
+__attribute__((__format__ (printf, 2, 3)));
 
 #ifdef MALLOC_STATS
 void malloc_dump(int, struct dir_info *);
@@ -261,40 +264,26 @@ struct dir_info *getpool(void) 
 }
 
 static __dead void
-wrterror(struct dir_info *d, char *msg, void *p)
+wrterror(struct dir_info *d, char *msg, ...)
 {
-   char*q = " error: ";
-   struct ioveciov[7];
-   charpidbuf[20];
-   charbuf[20];
-   int saved_errno = errno, i;
-
-   iov[0].iov_base = __progname;
-   iov[0].iov_len = strlen(__progname);
-   iov[1].iov_base = pidbuf;
-   snprintf(pidbuf, sizeof(pidbuf), "(%d) in ", getpid());
-   iov[1].iov_len = strlen(pidbuf);
-   if (d != NULL) {
-   iov[2].iov_base = d->func;
-   iov[2].iov_len = strlen(d->func);
-   } else {
-   iov[2].iov_base = "unknown";
-   iov[2].iov_len = 7;
-   }
-   iov[3].iov_base = q;
-   iov[3].iov_len = strlen(q);
-   iov[4].iov_base = msg;
-   iov[4].iov_len = strlen(msg);
-   iov[5].iov_base = buf;
-   if (p == NULL)
-   iov[5].iov_len = 0;
-   else {
-   snprintf(buf, sizeof(buf), " %010p", p);
-   iov[5].iov_len = strlen(buf);
-   }
-   iov[6].iov_base = "\n";
-   iov[6].iov_len = 1;
-   writev(STDERR_FILENO, iov, 7);
+   struct ioveciov[3];
+   charpidbuf[80];
+   charbuf[80];
+   int saved_errno = errno, ret;
+   va_list ap;
+
+   iov[0].iov_base = pidbuf;
+   ret = snprintf(pidbuf, sizeof(pidbuf), "%.50s(%d) in %s(): ",
+   __progname, getpid(), d->func ? d->func : "unknown");
+   iov[0].iov_len = ret > 0 ? strlen(pidbuf) : 0;
+   iov[1].iov_base = buf;
+   va_start(ap, msg);
+   ret = vsnprintf(buf, sizeof(buf), msg, ap);
+   va_end(ap);
+   iov[1].iov_len = ret > 0 ? strlen(buf) : 0;
+   iov[2].iov_base = "\n";
+   iov[2].iov_len = 1;
+   writev(STDERR_FILENO, iov, 3);
 
 #ifdef MALLOC_STATS
if (mopts.malloc_stats)
@@ -342,12 +331,12 @@ unmap(struct dir_info *d, void *p, size_
u_int i, offset;
 
if (sz != PAGEROUND(sz))
-   wrterror(d, "munmap round", NULL);
+   wrterror(d, "munmap round");
 
if (psz > mopts.malloc_cache) {
i = munmap(p, sz);
if (i)
-   wrterror(d, "munmap", p);
+   wrterror(d, "munmap %p", p);
STATS_SUB(d->malloc_used, sz);
return;
}
@@ -361,7 +350,7 @@ unmap(struct dir_info *d, void *p, size_
if (r->p != NULL) {
rsz = r->size << MALLOC_PAGESHIFT;
if (munmap(r->p, rsz))
-   wrterror(d, "munmap", r->p);
+   wrterror(d, "munmap %p", r->p);
r->p = NULL;
if (tounmap > r->size)
tounmap -= r->size;
@@ -373,7 +362,7 @@ unmap(struct dir_info *d, void *p, size_
}
}
if (tounmap > 0)
-   wrterror(d, "malloc cache underflow", NULL);
+   wrterror(d, "malloc cache underflow");
for (i = 0; i < mopts.malloc_cache; i++) {
r = >free_regions[(i + offset) & (mopts.malloc_cache - 1)];
if (r->p == NULL) {
@@ -393,9 +382,9 @@ unmap(struct dir_info *d, void *p, size_
}
}
if (i == mopts.malloc_cache)
-   wrterror(d, "malloc free slot lost", NULL);
+   wrterror(d, "malloc free slot lost");
if (d->free_regions_size > mopts.malloc_cache)
-   wrterror(d, "malloc cache overflow", NULL);
+   wrterror(d, "malloc cache overflow");
 }
 
 static void
@@ -410,7 +399,7 @@ zapcacheregion(struct dir_info *d, void 
if (r->p >= p && r->p <= (void *)((char *)p + len)) {
rsz = r->size << 

Re: FAQ entry for vmm

2016-10-19 Thread Daniel Jakots
On Wed, 19 Oct 2016 17:09:20 +0100, Edd Barrett 
wrote:

> On Mon, Oct 17, 2016 at 05:28:38PM +0100, Edd Barrett wrote:
> > Thanks. The general consensus was to try to reduce this a lot before
> > commit though. I will probably only include the wireless setup in
> > the FAQ.  
> 
> Here is the reduced version. I also moved this into the networking
> section.

The second sentence in the FAQ is 'It covers the latest release of
OpenBSD.'. Maybe it would be worth adding a sentence about the fact
that it covers mainly current (as in -stable vmm is not enabled).

Cheers,
Daniel



Re: vm.conf(5) manual tweak for switches

2016-10-19 Thread Jason McIntyre
On Wed, Oct 19, 2016 at 05:10:26PM +0100, Edd Barrett wrote:
> On Sun, Oct 16, 2016 at 07:15:41PM +0100, Edd Barrett wrote:
> > The following diff attempts to fix this, and tweaks the surrounding text
> > a bit too.
> 
> Any love for this?
> 

just be patient, please.
jmc



Re: vm.conf(5) manual tweak for switches

2016-10-19 Thread Edd Barrett
On Sun, Oct 16, 2016 at 07:15:41PM +0100, Edd Barrett wrote:
> The following diff attempts to fix this, and tweaks the surrounding text
> a bit too.

Any love for this?

-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk



Re: FAQ entry for vmm

2016-10-19 Thread Edd Barrett
Hi,

On Mon, Oct 17, 2016 at 05:28:38PM +0100, Edd Barrett wrote:
> Thanks. The general consensus was to try to reduce this a lot before
> commit though. I will probably only include the wireless setup in the
> FAQ.

Here is the reduced version. I also moved this into the networking
section.

Better? OK?

Index: faq/faq6.html
===
RCS file: /home/edd/cvsync/www/faq/faq6.html,v
retrieving revision 1.419
diff -u -p -r1.419 faq6.html
--- faq/faq6.html   8 Oct 2016 03:17:45 -   1.419
+++ faq/faq6.html   19 Oct 2016 15:56:20 -
@@ -50,6 +50,7 @@
 Setting up a network bridge
 Equal-cost multipath routing
 Adding and replacing NICs
+Networking vmm(4) guests
 
 
 
@@ -1183,6 +1184,96 @@ Some likely candidates might include:
   Bridge configuration (/etc/hostname.bridge*)
   Trunk configuration (/etc/hostname.trunk*)
 
+
+Networking vmm(4) guests
+
+
+Giving a http://man.openbsd.org/vmm;>vmm(4) guest network
+access is easy if the host machine uses a wired network interface: you can then
+simply put the guest's http://man.openbsd.org/tap;>tap(4)
+interface into a bridged virtual switch with the host's wired interface.
+Inside the guest, the http://man.openbsd.org/vio;>vio(4)
+interface can then be configured as if it were a real machine physically
+connected to the host network.
+Unfortunately, this strategy does not work if the host machine has a wireless
+network interface.
+Due to a limitation of the IEEE 802.11 standard, wireless interfaces can not
+participate in network bridges.
+One way to work around this is to give the guest VM its own network and use
+network address translation (NAT) to the host's network.
+
+
+Suppose that we have a host machine with network access via a wireless
+iwn0 interface on the 192.168.1.0/24 network, and that we
+want to install an OpenBSD guest onto a the 192.168.10.0/24 network 
and
+give the guest access to the host's network via a NAT.
+Assume that we configured the guest's host-side interface to be fixed as
+tap0.
+Although we could set up NAT directly between the tap0 and
+iwn0, this tends to complicate matters, as tap0 will appear
+and disappear as the guest is powered up and down.
+This would mean that we would have to reconfigure the address of tap0
+manually after each guest power-on.
+A more robust approach is to use an always-existing
+http://man.openbsd.org/vether;vether(4) interface and
+have http://man.openbsd.org/vmd;vmd(8) bridge this with
+tap0 when the guest is powered on.
+Since vether0 always exists regardless of whether the guest is powered
+up or not, its configuration will persist across guest power cycles.
+
+
+Let's make a vether0 interface:
+
+
+# echo "inet 192.168.10.1 255.255.255.0" > /etc/hostname.vether0
+# sh /etc/netstart vether0
+
+
+
+We need to add a http://man.openbsd.org/pf;pf(4) rule to
+do the NATting.
+Put in the correct place in /etc/pf.conf:
+
+
+match out on iwn0 inet from vether0:network to any nat-to (iwn0)
+
+
+
+And to finish off the NAT configuration:
+
+
+# pfctl -f /etc/pf.conf
+# echo "net.inet.ip.forwarding=1" >> /etc/sysctl.conf
+# sysctl net.inet.ip.forwarding=1
+net.inet.ip.forwarding: 0 -> 1
+
+
+
+In
+http://man.openbsd.org/vm.conf;vm.conf(5), ensure
+that you put vether0 into a virtual switch alongside tap0.
+For example:
+
+
+switch "my_switch" {
+add vether0
+interface bridge0
+}
+
+vm "my_vm" {
+...
+interface tap0 { switch "my_switch" }
+}
+
+
+
+Inside the guest if we now assign vio0 an address on the
+192.168.10.0/24 network, and set the default route to
+192.168.10.1, we should be able to ping systems on the host network.
+For convenience, you may wish to set up a DHCP server on vether0.
+See http://man.openbsd.org/dhcpd;dhcpd(8) and
+http://man.openbsd.org/dhcpd.conf;dhcpd(5) for
+details on how to set up a DHCP server.
 
 
 
Index: faq/index.html
===
RCS file: /home/edd/cvsync/www/faq/index.html,v
retrieving revision 1.495
diff -u -p -r1.495 index.html
--- faq/index.html  2 Oct 2016 21:16:26 -   1.495
+++ faq/index.html  19 Oct 2016 16:07:59 -
@@ -112,6 +112,7 @@ that are not covered in the FAQ.
 Setting up a network bridge
 Equal-cost multipath routing
 Adding and replacing NICs
+Networking vmm(4) guests
 
 
 Keyboard and Display Controls

-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk



Re: syslog_r() should use strerror_r()

2016-10-19 Thread Alexander Bluhm
On Wed, Oct 19, 2016 at 09:52:13AM -0600, Todd C. Miller wrote:
> On Wed, 19 Oct 2016 09:11:36 -0600, "Todd C. Miller" wrote:
> 
> > Currently, syslog_r() avoids using strerror() since it is not
> > reentrant.  We have a reentrant strerror_r() so let's use it.
> 
> Since strerror_r() always fills in the buffer there is no need to
> check the return value.  If saved_errno is not a valid error number,
> strerror_r() will use "Unknown error: %d".

OK bluhm@

> 
>  - todd
> 
> Index: lib/libc/gen/syslog_r.c
> ===
> RCS file: /cvs/src/lib/libc/gen/syslog_r.c,v
> retrieving revision 1.15
> diff -u -p -u -r1.15 syslog_r.c
> --- lib/libc/gen/syslog_r.c   27 Mar 2016 16:28:56 -  1.15
> +++ lib/libc/gen/syslog_r.c   19 Oct 2016 15:48:41 -
> @@ -138,18 +138,13 @@ __vsyslog_r(int pri, struct syslog_data 
>   }
>   }
>  
> - /* strerror() is not reentrant */
> -
>   for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
>   if (ch == '%' && fmt[1] == 'm') {
> + char ebuf[NL_TEXTMAX];
> +
>   ++fmt;
> - if (reentrant) {
> - prlen = snprintf(t, fmt_left, "Error %d",
> - saved_errno); 
> - } else {
> - prlen = snprintf(t, fmt_left, "%s",
> - strerror(saved_errno)); 
> - }
> + (void)strerror_r(saved_errno, ebuf, sizeof(ebuf));
> + prlen = snprintf(t, fmt_left, "%s", ebuf);
>   if (prlen < 0)
>   prlen = 0;
>   if (prlen >= fmt_left)



Re: syslog_r() should use strerror_r()

2016-10-19 Thread Alexander Bluhm
On Wed, Oct 19, 2016 at 09:34:16AM -0600, Theo de Raadt wrote:
> Inside strerror_r, I'm unsure why there is a save_errno dance.

That is from the time when we had national language support.

ok?

bluhm

Index: lib/libc/string/strerror_r.c
===
RCS file: /data/mirror/openbsd/cvs/src/lib/libc/string/strerror_r.c,v
retrieving revision 1.12
diff -u -p -r1.12 strerror_r.c
--- lib/libc/string/strerror_r.c25 Oct 2015 10:22:09 -  1.12
+++ lib/libc/string/strerror_r.c19 Oct 2016 15:57:45 -
@@ -85,15 +85,13 @@ __num2string(int num, int sign, int seti
 int
 strerror_r(int errnum, char *strerrbuf, size_t buflen)
 {
-   int save_errno;
int ret_errno;
 
-   save_errno = errno;
-
ret_errno = __num2string(errnum, 1, 1, strerrbuf, buflen,
sys_errlist, sys_nerr, UPREFIX);
 
-   errno = ret_errno ? ret_errno : save_errno;
+   if (ret_errno)
+   errno = ret_errno;
return (ret_errno);
 }
 DEF_WEAK(strerror_r);



Re: syslog_r() should use strerror_r()

2016-10-19 Thread Todd C. Miller
On Wed, 19 Oct 2016 09:11:36 -0600, "Todd C. Miller" wrote:

> Currently, syslog_r() avoids using strerror() since it is not
> reentrant.  We have a reentrant strerror_r() so let's use it.

Since strerror_r() always fills in the buffer there is no need to
check the return value.  If saved_errno is not a valid error number,
strerror_r() will use "Unknown error: %d".

 - todd

Index: lib/libc/gen/syslog_r.c
===
RCS file: /cvs/src/lib/libc/gen/syslog_r.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 syslog_r.c
--- lib/libc/gen/syslog_r.c 27 Mar 2016 16:28:56 -  1.15
+++ lib/libc/gen/syslog_r.c 19 Oct 2016 15:48:41 -
@@ -138,18 +138,13 @@ __vsyslog_r(int pri, struct syslog_data 
}
}
 
-   /* strerror() is not reentrant */
-
for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
if (ch == '%' && fmt[1] == 'm') {
+   char ebuf[NL_TEXTMAX];
+
++fmt;
-   if (reentrant) {
-   prlen = snprintf(t, fmt_left, "Error %d",
-   saved_errno); 
-   } else {
-   prlen = snprintf(t, fmt_left, "%s",
-   strerror(saved_errno)); 
-   }
+   (void)strerror_r(saved_errno, ebuf, sizeof(ebuf));
+   prlen = snprintf(t, fmt_left, "%s", ebuf);
if (prlen < 0)
prlen = 0;
if (prlen >= fmt_left)



Re: syslog_r() should use strerror_r()

2016-10-19 Thread Todd C. Miller
On Wed, 19 Oct 2016 09:34:16 -0600, "Theo de Raadt" wrote:

> Inside strerror_r, I'm unsure why there is a save_errno dance.

I don't see anything called by strerror_r() that would touch errno
so we could get rid of the save_errno dance and just do:

if (ret_errno)
errno = ret_errno;

 - todd



Re: syslog_r() should use strerror_r()

2016-10-19 Thread Todd C. Miller
On Wed, 19 Oct 2016 17:29:18 +0200, Mark Kettenis wrote:

> Perhaps add a comment explicitly stating that OpenBSD's strerror_r()
> *is* reentrant?

I thought that was implicit in the name.

 - todd



Re: syslog_r() should use strerror_r()

2016-10-19 Thread Theo de Raadt
> > Currently, syslog_r() avoids using strerror() since it is not
> > reentrant.  We have a reentrant strerror_r() so let's use it.
> > 
> > OK?
> 
> Perhaps add a comment explicitly stating that OpenBSD's strerror_r()
> *is* reentrant?

Also, signal-handler safe.

We've done something a little crazy -- pushing hard at libc to make
our syslog_r function threadsafe + reentrant + and signal-handler
safe, as long as the format string doesn't contain floating point.

So Mark is right, any public layers below syslog_r should declare
their safety conditions also, otherwise people may puzzle.

Inside strerror_r, I'm unsure why there is a save_errno dance.



Re: syslog_r() should use strerror_r()

2016-10-19 Thread Mark Kettenis
> From: "Todd C. Miller" 
> Date: Wed, 19 Oct 2016 09:11:36 -0600
> 
> Currently, syslog_r() avoids using strerror() since it is not
> reentrant.  We have a reentrant strerror_r() so let's use it.
> 
> OK?

Perhaps add a comment explicitly stating that OpenBSD's strerror_r()
*is* reentrant?

> Index: lib/libc/gen/syslog_r.c
> ===
> RCS file: /cvs/src/lib/libc/gen/syslog_r.c,v
> retrieving revision 1.15
> diff -u -p -u -r1.15 syslog_r.c
> --- lib/libc/gen/syslog_r.c   27 Mar 2016 16:28:56 -  1.15
> +++ lib/libc/gen/syslog_r.c   19 Oct 2016 15:06:48 -
> @@ -138,17 +138,16 @@ __vsyslog_r(int pri, struct syslog_data 
>   }
>   }
>  
> - /* strerror() is not reentrant */
> -
>   for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
>   if (ch == '%' && fmt[1] == 'm') {
> + char ebuf[NL_TEXTMAX];
> +
>   ++fmt;
> - if (reentrant) {
> + if (strerror_r(saved_errno, ebuf, sizeof(ebuf)) != 0) {
>   prlen = snprintf(t, fmt_left, "Error %d",
>   saved_errno); 
>   } else {
> - prlen = snprintf(t, fmt_left, "%s",
> - strerror(saved_errno)); 
> + prlen = snprintf(t, fmt_left, "%s", ebuf);
>   }
>   if (prlen < 0)
>   prlen = 0;
> 
> 



syslog_r() should use strerror_r()

2016-10-19 Thread Todd C. Miller
Currently, syslog_r() avoids using strerror() since it is not
reentrant.  We have a reentrant strerror_r() so let's use it.

OK?

 - todd

Index: lib/libc/gen/syslog_r.c
===
RCS file: /cvs/src/lib/libc/gen/syslog_r.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 syslog_r.c
--- lib/libc/gen/syslog_r.c 27 Mar 2016 16:28:56 -  1.15
+++ lib/libc/gen/syslog_r.c 19 Oct 2016 15:06:48 -
@@ -138,17 +138,16 @@ __vsyslog_r(int pri, struct syslog_data 
}
}
 
-   /* strerror() is not reentrant */
-
for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
if (ch == '%' && fmt[1] == 'm') {
+   char ebuf[NL_TEXTMAX];
+
++fmt;
-   if (reentrant) {
+   if (strerror_r(saved_errno, ebuf, sizeof(ebuf)) != 0) {
prlen = snprintf(t, fmt_left, "Error %d",
saved_errno); 
} else {
-   prlen = snprintf(t, fmt_left, "%s",
-   strerror(saved_errno)); 
+   prlen = snprintf(t, fmt_left, "%s", ebuf);
}
if (prlen < 0)
prlen = 0;



Re: usb disk dirty after every reboot

2016-10-19 Thread Jan Stary
On Oct 16 10:14:14, s...@sfritsch.de wrote:
> [moving to tech@]
> 
> On Tuesday, 20 September 2016 08:03:32 CEST Stefan Fritsch wrote:
> > On Tue, 20 Sep 2016, Darren Tucker wrote:
> > > On Tue, Sep 20, 2016 at 1:43 AM, Jan Stary  wrote:
> > > > This is current/i386 on an ALIX.1E (demsg below).
> > > > I have an USB disk connected for /backup.
> > > > 
> > > > Upon every reboot, the filesystem on that disk is dirty:
> > > > WARNING: R/W mount of /backup denied.  Filesystem is not clean - run
> > > > fsck

Since then, I have used three different disks and USB enclosures,
each working flawlessly anywhere else. The problem is still there,
so it's most probably not the disk.

> > > I saw something similar on an APU where the root disk was on
> > > (USB-attached) sdcard:
> > > http://marc.info/?l=openbsd-misc=144237305322074=2
> > > 
> > > It seems to be a race.  There used to be a 4sec pause in the kernel
> > > that was removed:
> > > 
> > > """
> > > Remove 4 second delay on reboot/shutdown that was added 8 years
> > > ago to "workaround MP timeout/splhigh/scsi race at reboot time".
> > > """

> > I think before we re-add some arbitrary delays, we should check if we are
> > actually sending an explicit cache flush command to the disk controllers.
> > I have some code somewhere that does this for umount and mount -ur. I will
> > look for it and send it to tech@, but probably not today.

For now, I just put 'umount /backup' in my rc.shutdown
and that makes it umount cleanly.

> I found a few cases, where we should send a cache flush but don't. 
> Unfortunately, none of these cases explain the problem seen by Jan and Darren.
> 
> The cases I have found are:
> 
> * When a R/W mount is updated to R/O. I will send patches for this in a 
> separate mail.

Not this case.

> * When a R/W mount is unmounted but there is still another partition from the 
> same disk mounted.

Not this case.

> For the usb disk issue, some more debugging is necessary.

How can I help debug this?

Jan


Controller /dev/usb0:
addr 1: high speed, self powered, config 1, EHCI root hub(0x), AMD(0x1022), 
rev 1.00
 port 1 powered
 port 2 powered
 port 3 addr 2: high speed, self powered, config 1, Mass Storage 
Device(0x2506), Prolific Technology Inc.(0x067b), rev 1.00, iSerialNumber 

 port 4 powered
Controller /dev/usb1:
addr 1: full speed, self powered, config 1, OHCI root hub(0x), AMD(0x1022), 
rev 1.00
 port 1 powered
 port 2 powered
 port 3 powered
 port 4 powered



Re: iwm: rts for long frames only

2016-10-19 Thread Stefan Sperling
On Wed, Oct 19, 2016 at 02:04:44PM +0200, Jan Stary wrote:
> Since I have applied this patch (dmesg below),
> I haven't seen the errors I was seeing before
> (don't know if it's related).

Good, I've committed this. I haven't seen any downside either.

Thank you for testing.



Re: Append system start up messages to new /var/log/dmesg in /etc/rc

2016-10-19 Thread Landry Breuil
On Wed, Oct 19, 2016 at 02:19:22PM +0100, Craig Skinner wrote:
> Hi,
> 
> With dmesg's new -s flag, append each boot's full log to a new
> /var/log/dmesg semi-private log file.
> 
> Inspired by Alexander Hall's recent post:
> http://marc.info/?l=openbsd-misc=147674181621645
> 
> This works for me (on 5.9) & rotates correctly:

Note that dmesg is already saved in var/run/dmesg.boot but not dmesg
-s.

Landry



Append system start up messages to new /var/log/dmesg in /etc/rc

2016-10-19 Thread Craig Skinner
Hi,

With dmesg's new -s flag, append each boot's full log to a new
/var/log/dmesg semi-private log file.

Inspired by Alexander Hall's recent post:
http://marc.info/?l=openbsd-misc=147674181621645

This works for me (on 5.9) & rotates correctly:



Index: rc
===
RCS file: /cvs/src/etc/rc,v
retrieving revision 1.486
diff -u -p -r1.486 rc
--- rc  10 Jul 2016 09:08:18 -  1.486
+++ rc  19 Oct 2016 13:04:04 -
@@ -563,4 +563,7 @@ start_daemon apmd sensorsd hotplugd watc
 echo '.'
 
 date
-exit 0
+umask 027
+dmesg >>/var/log/dmesg
+dmesg -s >>/var/log/dmesg
+umask 022
Index: newsyslog.conf
===
RCS file: /cvs/src/etc/newsyslog.conf,v
retrieving revision 1.35
diff -u -p -r1.35 newsyslog.conf
--- newsyslog.conf  1 Jun 2016 16:57:07 -   1.35
+++ newsyslog.conf  19 Oct 2016 13:04:04 -
@@ -10,6 +10,7 @@
 /var/log/lpd-errs  640  7 10   * Z
 /var/log/maillog   640  7 *24Z
 /var/log/messages  644  5 300  * Z
+/var/log/dmesg 640  3 100  * Z
 /var/log/secure600  7 *168   Z
 /var/log/wtmp  644  7 *$W6D4 B
 /var/log/xferlog   640  7 250  * Z



switchd manual pages minor diff

2016-10-19 Thread Kapetanakis Giannis
Hi,

just a minor change to manual pages of switch daemon.

G


Index: switchd.8
===
RCS file: /cvs/src/usr.sbin/switchd/switchd.8,v
retrieving revision 1.2
diff -u -p -r1.2 switchd.8
--- switchd.8   25 Sep 2016 23:05:29 -  1.2
+++ switchd.8   19 Oct 2016 12:08:36 -
@@ -68,6 +68,9 @@ options increase the verbosity.
 .It Pa /etc/switchd.conf
 Default configuration file.
 .El
+.Sh SEE ALSO
+.Xr switchd.conf 5 ,
+.Xr switchctl 8
 .Sh STANDARDS
 .Rs
 .%A Open Networking Foundation (ONF)
Index: switchd.conf.5
===
RCS file: /cvs/src/usr.sbin/switchd/switchd.conf.5,v
retrieving revision 1.3
diff -u -p -r1.3 switchd.conf.5
--- switchd.conf.5  20 Jul 2016 07:21:24 -  1.3
+++ switchd.conf.5  19 Oct 2016 12:08:36 -
@@ -112,4 +112,5 @@ listen on 0.0.0.0 port 6633
 .\"device "/dev/switch1" forward to tcp:192.168.0.1:6633
 .Ed
 .Sh SEE ALSO
+.Xr switchctl 8 ,
 .Xr switchd 8

Index: switchctl.8
===
RCS file: /cvs/src/usr.sbin/switchctl/switchctl.8,v
retrieving revision 1.2
diff -u -p -r1.2 switchctl.8
--- switchctl.8 12 Oct 2016 19:07:42 -  1.2
+++ switchctl.8 19 Oct 2016 12:09:09 -
@@ -100,7 +100,8 @@ socket used for communication with
 .Xr switchd 8
 .El
 .Sh SEE ALSO
-.Xr bridge 4
+.Xr bridge 4 ,
+.Xr switchd.conf 8 ,
 .Xr switchd 8
 .Sh HISTORY
 The



Re: iwm: rts for long frames only

2016-10-19 Thread Jan Stary
On Oct 06 17:56:50, s...@stsp.name wrote:
> Stop using RTS for every data frame sent by iwm(4).
> RTS adds unneccessary overhead if small data frames are sent.
> 
> The USE_RTS flag in iwm's LQ command enables RTS unconditionally, so only
> set it while the AP is enforcing protection. The flag will be kept up-to-date
> as a side effect of iwm_setrates(), which is called when the Tx rate changes.
> 
> RTS is still used for long frames since the Tx command takes care of that.
> (iwm firmware exposes 3 different flags which enable RTS... don't ask.)
> 
> ok?
> 
> Index: if_iwm.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
> retrieving revision 1.143
> diff -u -p -r1.143 if_iwm.c
> --- if_iwm.c  5 Oct 2016 18:13:25 -   1.143
> +++ if_iwm.c  6 Oct 2016 13:52:08 -
> @@ -5286,7 +5286,9 @@ iwm_setrates(struct iwm_node *in)
>  
>   memset(lq, 0, sizeof(*lq));
>   lq->sta_id = IWM_STATION_ID;
> - lq->flags = IWM_LQ_FLAG_USE_RTS_MSK;
> +
> + if (ic->ic_flags & IEEE80211_F_USEPROT)
> + lq->flags |= IWM_LQ_FLAG_USE_RTS_MSK;
>  
>   sgi_ok = ((ni->ni_flags & IEEE80211_NODE_HT) &&
>   (ni->ni_htcaps & IEEE80211_HTCAP_SGI20));
> 

Since I have applied this patch (dmesg below),
I haven't seen the errors I was seeing before
(don't know if it's related).

Oct 11 16:26:56 dell /bsd: iwm0: fatal firmware error
Oct 11 16:26:56 dell /bsd: iwm0: device timeout
Oct 11 16:26:56 dell /bsd: iwm0: device timeout
Oct 11 16:26:57 dell /bsd: iwm0: could not add MAC context (error 35)
Oct 11 16:34:03 dell /bsd: iwm0: fatal firmware error
Oct 11 16:34:03 dell /bsd: iwm0: device timeout
Oct 11 16:34:03 dell /bsd: iwm0: device timeout
Oct 11 16:34:04 dell /bsd: iwm0: could not add MAC context (error 35)
Oct 11 16:37:34 dell /bsd: iwm0: fatal firmware error
Oct 11 16:37:34 dell /bsd: iwm0: device timeout
Oct 11 16:37:34 dell /bsd: iwm0: device timeout
Oct 11 16:37:35 dell /bsd: iwm0: could not add MAC context (error 35)
Oct 11 17:04:28 dell /bsd: iwm0: fatal firmware error
Oct 11 17:04:28 dell /bsd: iwm0: device timeout
Oct 11 17:04:28 dell /bsd: iwm0: device timeout
Oct 11 17:04:29 dell /bsd: iwm0: could not add MAC context (error 35)
Oct 11 17:08:37 dell /bsd: iwm0: fatal firmware error
Oct 11 17:08:37 dell /bsd: iwm0: device timeout
Oct 11 17:08:37 dell /bsd: iwm0: device timeout
Oct 11 17:08:38 dell /bsd: iwm0: could not add MAC context (error 35)
Oct 11 17:27:47 dell /bsd: iwm0: fatal firmware error
Oct 11 17:27:47 dell /bsd: iwm0: device timeout
Oct 11 17:27:47 dell /bsd: iwm0: device timeout
Oct 11 17:27:48 dell /bsd: iwm0: could not add MAC context (error 35)
Oct 11 17:31:20 dell /bsd: iwm0: fatal firmware error
Oct 11 17:31:20 dell /bsd: iwm0: device timeout
Oct 11 17:31:20 dell /bsd: iwm0: device timeout
Oct 11 17:31:21 dell /bsd: iwm0: could not add MAC context (error 35)


Jan



OpenBSD 6.0-current (GENERIC.MP) #6: Fri Oct 14 10:39:16 CEST 2016
h...@dell.stare.cz:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 16810340352 (16031MB)
avail mem = 16296337408 (15541MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xeac10 (107 entries)
bios0: vendor Dell Inc. version "1.5.0" date 04/22/2016
bios0: Dell Inc. Latitude E5570
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT FIDT MCFG HPET SSDT LPIT SSDT SSDT SSDT DBGP 
DBG2 SSDT UEFI SSDT SSDT SLIC ASF!
acpi0: wakeup devices PEGP(S4) PEG0(S4) PEGP(S4) PEG1(S4) PEGP(S4) PEG2(S4) 
PXSX(S4) RP09(S4) PXSX(S4) RP10(S4) PXSX(S4) RP11(S4) PXSX(S4) RP12(S4) 
PXSX(S4) RP13(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-6440HQ CPU @ 2.60GHz, 2295.51 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 23MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i5-6440HQ CPU @ 2.60GHz, 2294.64 MHz
cpu1: 

Re: drop unused locale junk from sort(1)

2016-10-19 Thread Jan Stary
ping

On Oct 11 15:37:03, schwa...@usta.de wrote:
> Jan Stary wrote on Tue, Oct 11, 2016 at 11:26:50AM +0200:
> 
> > Feeling encouraged by Ingo's ok to remove locale from cp/rm,
> > here's a diff that removes the locale stuff we don't actually do
> > from the code and documentation of sort(1). Leave just LC_CTYPE
> 
> You removed that too, but that's OK because the code doesn't
> currently use it.  Right now, even though some wide character
> code is there, it always operates in narrow mode.
> 
> > which determines isblank() and case conversions.
> 
> LC_CTYPE does NOT affect isblank(), all the wide-character-related
> functions are in dead code as far as i can see, and OpenBSD does
> not support wide character case conversions.
> 
> 
> Your diff is related to more than one thing:
> 
>  1. Kill LC_NUMERIC support.
> I very strongly agree with that.
> I think we should never support that anywhere.
> It is an absolutely terrible idea no matter how you look at it.
> Your removal was incomplete, though.
> In the patch below, i delete some additional bits
> that you left behind.
> 
>  2. Remove LC_COLLATE support for now.
> I also agree with that, even if not quite as strongly.
> In the distant future, we might or might not want LC_COLLATE support.
> In Belgrade, i talked to Baptiste Daroussin who just implemented
> LC_COLLATE in FreeBSD libc and who was utterly scared by the complexity.
> Knowing ourselves, we will be scared even more once we get there.
> So it will definitely not happen quickly.
> 
> If it ever does, the trivial bits that are present right now
> are so tiny that they won't help at all.  It might even be
> easier to have clean earth to till when starting.
> Who knows at this point.
> 
> In any case, deleting the incomplete pieces scattered around
> the current code makes maintenance easier until that time,
> which seems worthwhile.
> 
>  3. With step 2 above, some flags become explicitly const
> that appear to be variable now (but actually aren't).
> That would allow deleting large amounts of dead code,
> but i didn't add that to the patch below.
> 
> The grep multibyte code is absolutely horrible, with insanity
> up to and including unions of char and wchar_t coming with
> hosts of trivial non-standard wrapper functions and tons
> of duplicate, in some case triplicate code.  Another
> example:  Even though the code half-heartedly attempts to
> isolate multibyte stuff in bwstring.{c,h} - superficially
> reminding of our utf8.c technique, but half-hearted because
> the respective functions are numerous and called all over the
> place, such that isolation is effectively a failure -
> the main program (!) at one place abuses btowc(3) (!)
> on an ASCII (!) command line argument and stores the result
> as wchar_t in the top level global state structure (!) -
> that is obviously functionally completely futile, but very
> effective for polluting *all* of the code with complicated
> data types and headers.
> 
> But cleaning up all the parts of item 3 would be way too intrusive
> for this patch, so it leaves behind hundreds of lines of code
> that is already both dead and duplicate right now.
> 
> > Annotate a missed -z flag while there,
> 
> Committed.
> 
> > and change /var/tmp to /tmp.
> 
> No, according to file.c, the program still writes to /var/tmp,
> not to /tmp.  Before changing that in the manual, we would have
> to change it in the code.
> 
> 
> The following version of the patch survives our test suite,
> but it no doubt needs more testing.
> 
> Yours,
>   Ingo
> 
> 
> Index: bwstring.c
> ===
> RCS file: /cvs/src/usr.bin/sort/bwstring.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 bwstring.c
> --- bwstring.c1 Apr 2015 22:38:08 -   1.7
> +++ bwstring.c11 Oct 2016 13:20:59 -
> @@ -40,8 +40,8 @@
>  #include "bwstring.h"
>  #include "sort.h"
>  
> -bool byte_sort;
> -size_t sort_mb_cur_max = 1;
> +static const bool byte_sort = true;
> +const size_t sort_mb_cur_max = 1;
>  
>  static wchar_t **wmonths;
>  static char **cmonths;
> Index: bwstring.h
> ===
> RCS file: /cvs/src/usr.bin/sort/bwstring.h,v
> retrieving revision 1.2
> diff -u -p -r1.2 bwstring.h
> --- bwstring.h31 Dec 2015 16:09:31 -  1.2
> +++ bwstring.h11 Oct 2016 13:20:59 -
> @@ -37,8 +37,7 @@
>  
>  #include "mem.h"
>  
> -extern bool byte_sort;
> -extern size_t sort_mb_cur_max;
> +extern const size_t sort_mb_cur_max;
>  
>  /* wchar_t is of 4 bytes: */
>  #define  SIZEOF_WCHAR_STRING(LEN) ((LEN)*sizeof(wchar_t))
> Index: coll.c
> ===
> RCS file: /cvs/src/usr.bin/sort/coll.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 

tcpdump(8): teach how to read ofp

2016-10-19 Thread Rafael Zalamena
This is the first step to teach tcpdump(8) how to read OpenFlow protocol
packets. I've implemented support for most messages switchd(8) uses and
currently only for OpenFlow 1.3.5, but we might reuse some functions for
OpenFlow 1.0 as well. For now we don't support showing strings of
definitions instead of numbers.

Right now we might not be able to tcpdump local switchd(8) <-> switch(4),
however for remote switchd(8) using TCP it is possible (remote switch(4),
HP device, Mininet etc...).

Supported messages:
 * Hello (with bitmap, there is a diff for switchd(8) as well);
 * Error (with encapsulated ofp header printing);
 * Echo Request/Reply;
 * Features Request/Reply;
 * Set Config;
 * Packet-in (with encapsulated ethernet printing);
 * Packet-out (with encapsulated ethernet printing);
 * Flow removed;

Missing:
 * Multipart request/reply;
 * Flow mod;

I'll show some packet capture output examples and you can find the diff
in the end of this e-mail.

Normal packet capture:
---snip---
12:07:18.700340 172.23.1.203.63996 > 172.23.1.210.6633: P 1:9(8) ack 1 win 
33304  OpenFlow(ver 0x4 type 0 len 8 xid 
2711) HELLO (DF)
12:07:18.701825 172.23.1.210.6633 > 172.23.1.203.63996: P 1:9(8) ack 9 win 271 
 OpenFlow(ver 0x4 type 0 len 8 xid 0) 
HELLO (DF)
12:07:18.701986 172.23.1.210.6633 > 172.23.1.203.63996: P 9:17(8) ack 9 win 271 
 OpenFlow(ver 0x4 type 5 len 8 xid 1) 
FEATURES REQUEST (DF)
12:07:18.704463 172.23.1.203.63996 > 172.23.1.210.6633: P 9:41(32) ack 17 win 
33296  OpenFlow(ver 0x4 type 6 len 32 xid 
1) FEATURES REPLY  (DF)
12:07:18.705252 172.23.1.210.6633 > 172.23.1.203.63996: P 17:29(12) ack 41 win 
271  OpenFlow(ver 0x4 type 9 len 12 xid 
2) SET CONFIG  (DF)
12:07:18.705452 172.23.1.210.6633 > 172.23.1.203.63996: P 29:109(80) ack 41 win 
271  OpenFlow(ver 0x4 type 14 len 80 xid 
3) (DF)
12:07:18.778120 172.23.1.203.63996 > 172.23.1.210.6633: P 41:169(128) ack 109 
win 33250  OpenFlow(ver 0x4 type 10 len 
128 xid 2712) PACKET-IN  OXM  OXM  OXM  
fe80::b283:feff:fe70:7e7a > ff02::2: icmp6: router solicitation  (DF)
12:07:18.780401 172.23.1.210.6633 > 172.23.1.203.63996: P 109:219(110) ack 169 
win 271  OpenFlow(ver 0x4 type 13 len 110 
xid 4) PACKET-OUT  ACTION  fe80::b283:feff:fe70:7e7a > ff02::2: 
icmp6: router solicitation  (DF)
12:07:26.446497 172.23.1.203.63996 > 172.23.1.210.6633: P 463:603(140) ack 495 
win 33057  OpenFlow(ver 0x4 type 10 len 
140 xid 2714) PACKET-IN  OXM  OXM  OXM  
172.23.1.206.61780 > 224.0.0.253.3544: udp 40 [ttl 1] (DF)
12:07:26.448460 172.23.1.210.6633 > 172.23.1.203.63996: P 495:617(122) ack 603 
win 271  OpenFlow(ver 0x4 type 13 len 122 
xid 6) PACKET-OUT  ACTION  172.23.1.206.61780 > 
224.0.0.253.3544: udp 40 [ttl 1] (DF)
12:07:26.658565 172.23.1.203.63996 > 172.23.1.210.6633: P 603:1013(410) ack 617 
win 32996  OpenFlow(ver 0x4 type 10 len 
410 xid 2715) PACKET-IN  OXM  OXM  OXM  
172.23.1.62.1900 > 239.255.255.250.1900: udp 310 (DF)
12:07:26.662728 172.23.1.210.6633 > 172.23.1.203.63996: P 617:1009(392) ack 
1013 win 271  OpenFlow(ver 0x4 type 13 
len 392 xid 7) PACKET-OUT  
ACTION  172.23.1.62.1900 > 
239.255.255.250.1900: udp 310 (DF)
12:07:26.709177 172.23.1.203.63996 > 172.23.1.210.6633: P 1013:1423(410) ack 
1009 win 32800  OpenFlow(ver 0x4 type 10 
len 410 xid 2716)PACKET-IN  OXM  OXM  OXM  
172.23.1.62.1900 > 239.255.255.250.1900: udp 310 (DF)
12:07:26.713609 172.23.1.210.6633 > 172.23.1.203.63996: P 1009:1401(392) ack 
1423 win 271  OpenFlow(ver 0x4 type 13 
len 392 xid 8) PACKET-OUT  
ACTION  172.23.1.62.1900 > 
239.255.255.250.1900: udp 310 (DF)
12:07:26.759321 172.23.1.203.63996 > 172.23.1.210.6633: P 1423:1842(419) ack 
1401 win 32604  OpenFlow(ver 0x4 type 10 
len 419 xid 2717)PACKET-IN  OXM  OXM  OXM  
172.23.1.62.1900 > 239.255.255.250.1900: udp 319 (DF)
12:07:26.761087 172.23.1.210.6633 > 172.23.1.203.63996: P 1401:1802(401) ack 
1842 win 271  OpenFlow(ver 0x4 type 13 
len 401 xid 9) PACKET-OUT  
ACTION  172.23.1.62.1900 > 
239.255.255.250.1900: udp 319 (DF)
12:07:26.810621 172.23.1.203.63996 > 172.23.1.210.6633: P 1842:2261(419) ack 
1802 win 33304  OpenFlow(ver 0x4 type 10 
len 419 xid 2718)PACKET-IN  OXM  OXM  OXM  
172.23.1.62.1900 > 239.255.255.250.1900: udp 319 (DF)
12:07:26.812693 172.23.1.210.6633 > 172.23.1.203.63996: P 1802:2203(401) ack 
2261 win 271  OpenFlow(ver 0x4