switchd.conf(5): mention default values used for global configurations

2018-11-08 Thread Ayaka Koshibe
Hi all,

After a second thought, I've split off the diff for switchd.conf(5)
from the diffs for changing switchd(8)'s default listen port.

As suggested by kn@, it now notes the default listen port and address.

Comments/OKs?


Thanks,
Ayaka

Index: switchd.conf.5
===
RCS file: /cvs/src/usr.sbin/switchd/switchd.conf.5,v
retrieving revision 1.8
diff -u -p -u -r1.8 switchd.conf.5
--- switchd.conf.5  30 Oct 2018 07:25:57 -  1.8
+++ switchd.conf.5  8 Nov 2018 07:39:17 -
@@ -81,6 +81,9 @@ OpenFlow switches.
 Secure connections can be enabled with the optional
 .Ic tls
 keyword.
+By default,
+.Xr switchd 8
+uses port 6653 and listen address 0.0.0.0.
 .\".It Ic device on Ar device-name Oo Ic forward to Ar uri Oc
 .\"Attach to a
 .\".Xr switch 4



Re: tcpdump: revisiting some old diffs, cleanup unused functions

2018-11-08 Thread Ricardo Mestre
Still works as advertised, ok mestre@

On 19:32 Wed 07 Nov , Bryan Steele wrote:
> On Wed, Nov 07, 2018 at 07:06:09PM -0500, Bryan Steele wrote:
> > I'm revisiting some old tcpdump diffs, now that mestre@ has added proper
> > unveil(2) support! :-)
> > 
> > Refresher: https://marc.info/?l=openbsd-tech&m=150535073209723&w=2
> > 
> > This hoists opening pf.os(5) fingerprints '-o' from the 'RUN' state to
> > the 'FILTER' state, this will allow for a reduced pledge(2) at runtime
> > in the (currently root) monitor process.
> 
> This was a bit of copy & paste, sorry. This moves the opening of pf.os
> earlier and avoids the unveil later on. Of course, reducing the runtime
> pledge(2) promises will come later! :-)
> 
> > 
> > This still works as well as it already has. :-)
> > 
> > ( ... ) [tcp sum ok] (src OS: OpenBSD 6.1) 3311509932:3311509932(0) win 
> > 16384  
> > (DF) (ttl 64, id 41239, len 64)
> > 
> > The only potential difference is that if /etc/pf.os is replaced at
> > runtime, tcpdump won't reopen it.
> > 
> > I don't think that's a problem..
> > 
> > ok?
> > 
> > -Bryan.
> 
> Remove the now unused internal privsep "getline" code, which passed
> lines over a socket, replaced with explicit fdpassing of /etc/pf.os.
> 
> This depends on the previous diff..
> 
> ok?
> 
> -Bryan.
> 
> Index: privsep.c
> ===
> RCS file: /cvs/src/usr.sbin/tcpdump/privsep.c,v
> retrieving revision 1.49
> diff -u -p -u -r1.49 privsep.c
> --- privsep.c 28 Sep 2018 06:48:59 -  1.49
> +++ privsep.c 8 Nov 2018 00:19:47 -
> @@ -77,8 +77,8 @@ static const int allowed_max[] = {
>   ALLOW(PRIV_GETPROTOENTRIES) |
>   ALLOW(PRIV_ETHER_NTOHOST) | ALLOW(PRIV_INIT_DONE),
>   /* RUN */   ALLOW(PRIV_GETHOSTBYADDR) | ALLOW(PRIV_ETHER_NTOHOST) |
> - ALLOW(PRIV_GETRPCBYNUMBER) | ALLOW(PRIV_GETLINES) |
> - ALLOW(PRIV_LOCALTIME) | ALLOW(PRIV_PCAP_STATS),
> + ALLOW(PRIV_GETRPCBYNUMBER) | ALLOW(PRIV_LOCALTIME) |
> + ALLOW(PRIV_PCAP_STATS),
>   /* EXIT */  0
>  };
>  
> @@ -90,21 +90,10 @@ static int allowed_ext[] = {
>   /* INIT */  ALLOW(PRIV_SETFILTER),
>   /* BPF */   ALLOW(PRIV_SETFILTER),
>   /* FILTER */ALLOW(PRIV_GETSERVENTRIES),
> - /* RUN */   ALLOW(PRIV_GETLINES) | ALLOW(PRIV_LOCALTIME) |
> - ALLOW(PRIV_PCAP_STATS),
> + /* RUN */   ALLOW(PRIV_LOCALTIME) | ALLOW(PRIV_PCAP_STATS),
>   /* EXIT */  0
>  };
>  
> -struct ftab {
> - char *name;
> - int max;
> - int count;
> -};
> -
> -static struct ftab file_table[] = {{PF_OSFP_FILE, 1, 0}};
> -
> -#define NUM_FILETAB (sizeof(file_table) / sizeof(struct ftab))
> -
>  int  debug_level = LOG_INFO;
>  int  priv_fd = -1;
>  volatile pid_t child_pid = -1;
> @@ -123,7 +112,6 @@ static void   impl_getrpcbynumber(int);
>  static void  impl_getserventries(int);
>  static void  impl_getprotoentries(int);
>  static void  impl_localtime(int fd);
> -static void  impl_getlines(int);
>  static void  impl_pcap_stats(int, int *);
>  
>  static void  test_state(int, int);
> @@ -345,10 +333,6 @@ priv_exec(int argc, char *argv[])
>   test_state(cmd, STATE_RUN);
>   impl_localtime(sock);
>   break;
> - case PRIV_GETLINES:
> - test_state(cmd, STATE_RUN);
> - impl_getlines(sock);
> - break;
>   case PRIV_PCAP_STATS:
>   test_state(cmd, STATE_RUN);
>   impl_pcap_stats(sock, &bpfd);
> @@ -577,55 +561,6 @@ impl_localtime(int fd)
>  }
>  
>  static void
> -impl_getlines(int fd)
> -{
> - FILE *fp;
> - char *buf, *lbuf, *file;
> - size_t len, fid;
> -
> - logmsg(LOG_DEBUG, "[priv]: msg PRIV_GETLINES received");
> -
> - must_read(fd, &fid, sizeof(size_t));
> - if (fid >= NUM_FILETAB)
> - errx(1, "invalid file id");
> -
> - file = file_table[fid].name;
> -
> - if (file == NULL)
> - errx(1, "invalid file referenced");
> -
> - if (file_table[fid].count >= file_table[fid].max)
> - errx(1, "maximum open count exceeded for %s", file);
> -
> - file_table[fid].count++;
> -
> - if ((fp = fopen(file, "r")) == NULL) {
> - write_zero(fd);
> - return;
> - }
> -
> - lbuf = NULL;
> - while ((buf = fgetln(fp, &len))) {
> - if (buf[len - 1] == '\n')
> - buf[len - 1] = '\0';
> - else {
> - if ((lbuf = malloc(len + 1)) == NULL)
> - err(1, NULL);
> - memcpy(lbuf, buf, len);
> - lbuf[len] = '\0';
> - buf = lbuf;
> - }
> -
> - write_string(fd, buf);
> -
> - 

Re: tcpdump: revisiting some old diffs, cleanup unused functions

2018-11-08 Thread Klemens Nanni
OK



Re: unveil error - src/usr.bin/passwd/local_passwd.c (-current)

2018-11-08 Thread Ricardo Mestre
Hi Mark,

Thanks for the report, don't know how I missed it but it's now fixed.

On 16:20 Thu 08 Nov , Mark Patruck wrote:
> Hi Ricardo,
> 
> when running
> 
> $ passwd
> 
> with src/usr.bin/passwd/local_passwd.c v1.54
> 
> i see the following error in /var/log/messages
> 
> passwd: cannot stat /etc/login.conf: No such file or directory
> 
> With the following diff, the error disappears
> 
> Index: local_passwd.c
> ===
> RCS file: /cvs/src/usr.bin/passwd/local_passwd.c,v
> retrieving revision 1.54
> diff -u -p -r1.54 local_passwd.c
> --- local_passwd.c  25 Oct 2018 06:41:38 -  1.54
> +++ local_passwd.c  8 Nov 2018 15:17:40 -
> @@ -76,6 +76,8 @@ local_passwd(char *uname, int authentica
>   err(1, "unveil");
>   if (unveil(_PATH_MASTERPASSWD, "r") == -1)
>   err(1, "unveil");
> + if (unveil(_PATH_LOGIN_CONF, "r") == -1)
> + err(1, "unveil");
>   if (unveil(_PATH_BSHELL, "x") == -1)
>   err(1, "unveil");
>   if (unveil(_PATH_PWD_MKDB, "x") == -1)
> 
> 
> 
> -- 
> Mark Patruck ( mark at wrapped.cx )
> GPG key 0xF2865E51 / 187F F6D3 EE04 1DCE 1C74  F644 0D3C F66F F286 5E51
> 
> http://www.wrapped.cx



free(9) size for USB endpoints

2018-11-08 Thread Martin Pieuchot
Keep track of the number of allocated endpoints and use it when freeing
the array.

ok?

Index: usb_subr.c
===
RCS file: /cvs/src/sys/dev/usb/usb_subr.c,v
retrieving revision 1.138
diff -u -p -r1.138 usb_subr.c
--- usb_subr.c  19 Jul 2018 12:35:14 -  1.138
+++ usb_subr.c  8 Nov 2018 16:10:57 -
@@ -515,6 +515,7 @@ usbd_fill_iface_data(struct usbd_device 
ifc->endpoints = NULL;
ifc->priv = NULL;
LIST_INIT(&ifc->pipes);
+   ifc->nendpt = nendpt;
 
if (nendpt != 0) {
ifc->endpoints = mallocarray(nendpt, sizeof(*ifc->endpoints),
@@ -592,8 +593,8 @@ void
 usbd_free_iface_data(struct usbd_device *dev, int ifcno)
 {
struct usbd_interface *ifc = &dev->ifaces[ifcno];
-   if (ifc->endpoints)
-   free(ifc->endpoints, M_USB, 0);
+
+   free(ifc->endpoints, M_USB, ifc->nendpt * sizeof(*ifc->endpoints));
 }
 
 usbd_status
Index: usbdi.c
===
RCS file: /cvs/src/sys/dev/usb/usbdi.c,v
retrieving revision 1.98
diff -u -p -r1.98 usbdi.c
--- usbdi.c 29 Apr 2018 08:57:48 -  1.98
+++ usbdi.c 8 Nov 2018 16:31:13 -
@@ -657,19 +657,20 @@ usbd_set_interface(struct usbd_interface
 {
usb_device_request_t req;
usbd_status err;
-   void *endpoints;
+   struct usbd_endpoint *endpoints;
+   int nendpt;
 
if (LIST_FIRST(&iface->pipes) != 0)
return (USBD_IN_USE);
 
endpoints = iface->endpoints;
+   nendpt = iface->nendpt;
err = usbd_fill_iface_data(iface->device, iface->index, altidx);
if (err)
return (err);
 
/* new setting works, we can free old endpoints */
-   if (endpoints != NULL)
-   free(endpoints, M_USB, 0);
+   free(endpoints, M_USB, nendpt * sizeof(*endpoints));
 
 #ifdef DIAGNOSTIC
if (iface->idesc == NULL) {
Index: usbdivar.h
===
RCS file: /cvs/src/sys/dev/usb/usbdivar.h,v
retrieving revision 1.75
diff -u -p -r1.75 usbdivar.h
--- usbdivar.h  1 May 2018 18:14:46 -   1.75
+++ usbdivar.h  8 Nov 2018 16:09:32 -
@@ -173,7 +173,8 @@ struct usbd_interface {
struct usbd_endpoint   *endpoints;
void   *priv;
LIST_HEAD(, usbd_pipe)  pipes;
-   u_int8_tclaimed;
+   uint8_t claimed;
+   uint8_t nendpt;
 };
 
 struct usbd_pipe {



free(9) sizes for uhub(4)

2018-11-08 Thread Martin Pieuchot
The driver already keeps track of the number of ports, so use this piece
of information to free allocated structures.

Ok?

Index: uhub.c
===
RCS file: /cvs/src/sys/dev/usb/uhub.c,v
retrieving revision 1.90
diff -u -p -r1.90 uhub.c
--- uhub.c  8 Apr 2017 02:57:25 -   1.90
+++ uhub.c  8 Nov 2018 16:45:44 -
@@ -292,7 +292,7 @@ uhub_attach(struct device *parent, struc
 
if (UHUB_IS_HIGH_SPEED(sc)) {
tts = mallocarray((UHUB_IS_SINGLE_TT(sc) ? 1 : nports),
-   sizeof (struct usbd_tt), M_USBDEV, M_NOWAIT);
+   sizeof(struct usbd_tt), M_USBDEV, M_NOWAIT);
if (!tts)
goto bad;
}
@@ -339,12 +339,10 @@ uhub_attach(struct device *parent, struc
return;
 
  bad:
-   if (sc->sc_statusbuf)
-   free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen);
+   free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen);
if (hub) {
-   if (hub->ports)
-   free(hub->ports, M_USBDEV, 0);
-   free(hub, M_USBDEV, sizeof *hub);
+   free(hub->ports, M_USBDEV, hub->nports * sizeof(*hub->ports));
+   free(hub, M_USBDEV, sizeof(*hub));
}
dev->hub = NULL;
 }
@@ -474,13 +472,11 @@ uhub_detach(struct device *self, int fla
}
}
 
-   if (hub->ports[0].tt)
-   free(hub->ports[0].tt, M_USBDEV, 0);
-   if (sc->sc_statusbuf)
-   free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen);
-   if (hub->ports)
-   free(hub->ports, M_USBDEV, 0);
-   free(hub, M_USBDEV, sizeof *hub);
+   free(hub->ports[0].tt, M_USBDEV,
+   (UHUB_IS_SINGLE_TT(sc) ? 1 : hub->nports) * sizeof(struct usbd_tt));
+   free(sc->sc_statusbuf, M_USBDEV, sc->sc_statuslen);
+   free(hub->ports, M_USBDEV, hub->nports * sizeof(*hub->ports));
+   free(hub, M_USBDEV, sizeof(*hub));
sc->sc_hub->hub = NULL;
 
return (0);



free(9) size for wi(4) @ USB

2018-11-08 Thread Martin Pieuchot
The driver already keeps track of the size of the allocated buffer, so
use it.

Diff is untested as I don't have a wi(4) @ USB.

ok?

Index: if_wi_usb.c
===
RCS file: /cvs/src/sys/dev/usb/if_wi_usb.c,v
retrieving revision 1.68
diff -u -p -r1.68 if_wi_usb.c
--- if_wi_usb.c 24 Nov 2015 17:11:40 -  1.68
+++ if_wi_usb.c 8 Nov 2018 16:53:12 -
@@ -409,9 +409,10 @@ wi_usb_detach(struct device *self, int f
 
while (sc->wi_usb_nummem) {
sc->wi_usb_nummem--;
-   if (sc->wi_usb_txmem[sc->wi_usb_nummem] != NULL)
-   free(sc->wi_usb_txmem[sc->wi_usb_nummem], M_DEVBUF, 0);
+   free(sc->wi_usb_txmem[sc->wi_usb_nummem], M_DEVBUF,
+ sc->wi_usb_txmemsize[sc->wi_usb_nummem]);
sc->wi_usb_txmem[sc->wi_usb_nummem] = NULL;
+   sc->wi_usb_txmemsize[sc->wi_usb_nummem] = 0;
}
 
if (sc->wi_usb_ep[WI_USB_ENDPT_INTR] != NULL) {
@@ -541,8 +542,10 @@ wi_cmd_usb(struct wi_softc *wsc, int cmd
/* free alloc_nicmem regions */
while (sc->wi_usb_nummem) {
sc->wi_usb_nummem--;
-   free(sc->wi_usb_txmem[sc->wi_usb_nummem], M_DEVBUF, 0);
+   free(sc->wi_usb_txmem[sc->wi_usb_nummem], M_DEVBUF,
+ sc->wi_usb_txmemsize[sc->wi_usb_nummem]);
sc->wi_usb_txmem[sc->wi_usb_nummem] = NULL;
+   sc->wi_usb_txmemsize[sc->wi_usb_nummem] = 0;
}
 
 #if 0



free(9) sizes for USB cdesc

2018-11-08 Thread Martin Pieuchot
The length of the configuration descriptor is already used in
usbd_parse_idesc().  The diff below reuses the same pattern to
add the size argument to free(9), ok?

Index: usb_subr.c
===
RCS file: /cvs/src/sys/dev/usb/usb_subr.c,v
retrieving revision 1.138
diff -u -p -r1.138 usb_subr.c
--- usb_subr.c  19 Jul 2018 12:35:14 -  1.138
+++ usb_subr.c  8 Nov 2018 17:31:26 -
@@ -647,7 +647,7 @@ usbd_set_config_index(struct usbd_device
for (ifcidx = 0; ifcidx < nifc; ifcidx++)
usbd_free_iface_data(dev, ifcidx);
free(dev->ifaces, M_USB, 0);
-   free(dev->cdesc, M_USB, 0);
+   free(dev->cdesc, M_USB, UGETW(dev->cdesc->wTotalLength));
dev->ifaces = NULL;
dev->cdesc = NULL;
dev->config = USB_UNCONFIG_NO;
@@ -1407,7 +1407,7 @@ usb_free_device(struct usbd_device *dev)
free(dev->ifaces, M_USB, 0);
}
if (dev->cdesc != NULL)
-   free(dev->cdesc, M_USB, 0);
+   free(dev->cdesc, M_USB, UGETW(dev->cdesc->wTotalLength));
if (dev->subdevs != NULL)
free(dev->subdevs, M_USB, 0);
dev->bus->devices[dev->address] = NULL;
Index: ugen.c
===
RCS file: /cvs/src/sys/dev/usb/ugen.c,v
retrieving revision 1.98
diff -u -p -r1.98 ugen.c
--- ugen.c  1 May 2018 18:14:46 -   1.98
+++ ugen.c  8 Nov 2018 17:00:28 -
@@ -1051,12 +1051,12 @@ ugen_do_ioctl(struct ugen_softc *sc, int
return (EINVAL);
idesc = usbd_find_idesc(cdesc, ai->uai_interface_index, 0);
if (idesc == NULL) {
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
return (EINVAL);
}
ai->uai_alt_no = usbd_get_no_alts(cdesc,
idesc->bInterfaceNumber);
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
break;
case USB_GET_DEVICE_DESC:
*(usb_device_descriptor_t *)addr =
@@ -1068,7 +1068,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int
if (cdesc == NULL)
return (EINVAL);
cd->ucd_desc = *cdesc;
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
break;
case USB_GET_INTERFACE_DESC:
id = (struct usb_interface_desc *)addr;
@@ -1082,11 +1082,11 @@ ugen_do_ioctl(struct ugen_softc *sc, int
alt = id->uid_alt_index;
idesc = usbd_find_idesc(cdesc, id->uid_interface_index, alt);
if (idesc == NULL) {
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
return (EINVAL);
}
id->uid_desc = *idesc;
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
break;
case USB_GET_ENDPOINT_DESC:
ed = (struct usb_endpoint_desc *)addr;
@@ -1101,11 +1101,11 @@ ugen_do_ioctl(struct ugen_softc *sc, int
edesc = usbd_find_edesc(cdesc, ed->ued_interface_index,
alt, ed->ued_endpoint_index);
if (edesc == NULL) {
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
return (EINVAL);
}
ed->ued_desc = *edesc;
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
break;
case USB_GET_FULL_DESC:
{
@@ -1130,7 +1130,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int
uio.uio_rw = UIO_READ;
uio.uio_procp = p;
error = uiomove((void *)cdesc, len, &uio);
-   free(cdesc, M_TEMP, 0);
+   free(cdesc, M_TEMP, UGETW(cdesc->wTotalLength));
return (error);
}
case USB_DO_REQUEST:
@@ -1196,8 +1196,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int
}
}
ret:
-   if (ptr)
-   free(ptr, M_TEMP, len);
+   free(ptr, M_TEMP, len);
return (error);
}
case USB_GET_DEVICEINFO:



batch copyout(9) in bridge(4)

2018-11-08 Thread Martin Pieuchot
I'd like to protect bridge(4) data structures with a mutex.  Using a
mutex is necessary because bridge_output() is called from interrupt
handlers in wireless drivers.  This forces us to decouple data gathering
from copying to userland when executing some ioctl(2)s.  Diff below does
that by moving the copyout(9)s outside of the loops.

Ok?

Index: net/bridgectl.c
===
RCS file: /cvs/src/sys/net/bridgectl.c,v
retrieving revision 1.11
diff -u -p -r1.11 bridgectl.c
--- net/bridgectl.c 26 Oct 2018 14:55:27 -  1.11
+++ net/bridgectl.c 8 Nov 2018 18:17:37 -
@@ -470,40 +470,48 @@ bridge_rtdelete(struct bridge_softc *sc,
 int
 bridge_rtfind(struct bridge_softc *sc, struct ifbaconf *baconf)
 {
-   int i, error = 0, onlycnt = 0;
-   u_int32_t cnt = 0;
+   struct ifbareq *bareq, *bareqs = NULL;
struct bridge_rtnode *n;
-   struct ifbareq bareq;
+   u_int32_t i = 0, total = 0;
+   int k, error = 0;
 
-   if (baconf->ifbac_len == 0)
-   onlycnt = 1;
+   for (k = 0; k < BRIDGE_RTABLE_SIZE; k++) {
+   LIST_FOREACH(n, &sc->sc_rts[k], brt_next)
+   total++;
+   }
 
-   for (i = 0, cnt = 0; i < BRIDGE_RTABLE_SIZE; i++) {
-   LIST_FOREACH(n, &sc->sc_rts[i], brt_next) {
-   if (!onlycnt) {
-   if (baconf->ifbac_len < sizeof(struct ifbareq))
-   goto done;
-   bcopy(sc->sc_if.if_xname, bareq.ifba_name,
-   sizeof(bareq.ifba_name));
-   bcopy(n->brt_if->if_xname, bareq.ifba_ifsname,
-   sizeof(bareq.ifba_ifsname));
-   bcopy(&n->brt_addr, &bareq.ifba_dst,
-   sizeof(bareq.ifba_dst));
-   bridge_copyaddr(&n->brt_tunnel.brtag_peer.sa,
-   sstosa(&bareq.ifba_dstsa));
-   bareq.ifba_age = n->brt_age;
-   bareq.ifba_flags = n->brt_flags;
-   error = copyout((caddr_t)&bareq,
-   (caddr_t)(baconf->ifbac_req + cnt), 
sizeof(bareq));
-   if (error)
-   goto done;
-   baconf->ifbac_len -= sizeof(struct ifbareq);
-   }
-   cnt++;
+   if (baconf->ifbac_len == 0) {
+   i = total;
+   goto done;
+   }
+
+   bareqs = mallocarray(total, sizeof(*bareqs), M_TEMP, M_WAITOK|M_ZERO);
+   if (bareqs == NULL)
+   goto done;
+
+   for (k = 0; k < BRIDGE_RTABLE_SIZE; k++) {
+   LIST_FOREACH(n, &sc->sc_rts[k], brt_next) {
+   if (baconf->ifbac_len < (i + 1) * sizeof(*bareqs))
+   goto done;
+   bareq = &bareqs[i];
+   bcopy(sc->sc_if.if_xname, bareq->ifba_name,
+   sizeof(bareq->ifba_name));
+   bcopy(n->brt_if->if_xname, bareq->ifba_ifsname,
+   sizeof(bareq->ifba_ifsname));
+   bcopy(&n->brt_addr, &bareq->ifba_dst,
+   sizeof(bareq->ifba_dst));
+   bridge_copyaddr(&n->brt_tunnel.brtag_peer.sa,
+   sstosa(&bareq->ifba_dstsa));
+   bareq->ifba_age = n->brt_age;
+   bareq->ifba_flags = n->brt_flags;
+   i++;
}
}
+
+   error = copyout(bareqs, baconf->ifbac_req, i * sizeof(*bareqs));
 done:
-   baconf->ifbac_len = cnt * sizeof(struct ifbareq);
+   free(bareqs, M_TEMP, total * sizeof(*bareqs));
+   baconf->ifbac_len = i * sizeof(struct ifbareq);
return (error);
 }
 
@@ -550,7 +558,7 @@ bridge_brlconf(struct bridge_iflist *bif
 {
struct bridge_softc *sc = bif->bridge_sc;
struct brl_node *n;
-   struct ifbrlreq req;
+   struct ifbrlreq *req, *reqs = NULL;
int error = 0;
u_int32_t i = 0, total = 0;
 
@@ -566,56 +574,52 @@ bridge_brlconf(struct bridge_iflist *bif
goto done;
}
 
+   reqs = mallocarray(total, sizeof(*reqs), M_TEMP, M_WAITOK|M_ZERO);
+   if (reqs == NULL)
+   goto done;
+
SIMPLEQ_FOREACH(n, &bif->bif_brlin, brl_next) {
-   bzero(&req, sizeof req);
-   if (bc->ifbrl_len < sizeof(req))
+   if (bc->ifbrl_len < (i + 1) * sizeof(*reqs))
goto done;
-   strlcpy(req.ifbr_name, sc->sc_if.if_xname, IFNAMSIZ);
-   strlcpy(req.ifbr_ifsname, bif->ifp->if_xname, IFNAMSIZ);
-   req.ifbr_action = n->brl_action;
-   

Re: tcpdump: revisiting some old diffs, remove unused pledges

2018-11-08 Thread Bryan Steele
On Wed, Nov 07, 2018 at 07:32:25PM -0500, Bryan Steele wrote:
> On Wed, Nov 07, 2018 at 07:06:09PM -0500, Bryan Steele wrote:
> > I'm revisiting some old tcpdump diffs, now that mestre@ has added proper
> > unveil(2) support! :-)
> > 
> > Refresher: https://marc.info/?l=openbsd-tech&m=150535073209723&w=2
> > 
> > This hoists opening pf.os(5) fingerprints '-o' from the 'RUN' state to
> > the 'FILTER' state, this will allow for a reduced pledge(2) at runtime
> > in the (currently root) monitor process.
> 
> This was a bit of copy & paste, sorry. This moves the opening of pf.os
> earlier and avoids the unveil later on. Of course, reducing the runtime
> pledge(2) promises will come later! :-)
> 
> > 
> > This still works as well as it already has. :-)
> > 
> > ( ... ) [tcp sum ok] (src OS: OpenBSD 6.1) 3311509932:3311509932(0) win 
> > 16384  
> > (DF) (ttl 64, id 41239, len 64)
> > 
> > The only potential difference is that if /etc/pf.os is replaced at
> > runtime, tcpdump won't reopen it.
> > 
> > I don't think that's a problem..
> > 
> > ok?
> > 
> > -Bryan.
>

The first two diffs are in now. Thanks!

The "recvfd" promise doesn't appear to be used by the privileged
monitor process, which currently only handles resolving domain names,
and displaying BIOCGSTATS on ^C. It never sends or receives any file
descriptors while in the 'RUN' state. We can drop it. :-)

Unfortunately the "inet" promise appears to be necessary for some yp(8)
environments, as documented in ether_ntohost(3). I'm not familiar enough
with YP to know if this special /etc/ethers '+' line is typical, or if
DNS should be used instead? In that case it would be covered by the
existing "dns" promise and we could drop "inet" here.

I'd like to try this, and hopefully there's a better solution for YP &
pledge(2) later?

comments or ok?

-Bryan.

Index: privsep.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/privsep.c,v
retrieving revision 1.50
diff -u -p -u -r1.50 privsep.c
--- usr.sbin/tcpdump/privsep.c  8 Nov 2018 14:06:09 -   1.50
+++ usr.sbin/tcpdump/privsep.c  8 Nov 2018 18:43:06 -
@@ -309,7 +309,7 @@ priv_exec(int argc, char *argv[])
err(1, "unveil");
if (unveil("/etc/rpc", "r") == -1)
err(1, "unveil");
-   if (pledge("stdio rpath inet dns recvfd bpf", NULL) == 
-1)
+   if (pledge("stdio rpath dns bpf", NULL) == -1)
err(1, "pledge");
 
break;



netcat report listen

2018-11-08 Thread Alexander Bluhm
Hi,

It is easier to write race free tests if netcat reports when the
listen system call has finished.  This avoids ugly kernel lookups
with fstat.  Just report bind or listen like accepted connections
in verbose mode to stderr.  Then the other end can proceed.

ok?

Index: usr.bin/nc/netcat.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.197
diff -u -p -r1.197 netcat.c
--- usr.bin/nc/netcat.c 6 Nov 2018 20:39:19 -   1.197
+++ usr.bin/nc/netcat.c 8 Nov 2018 21:06:30 -
@@ -137,7 +137,7 @@ voidset_common_sockopts(int, int);
 intprocess_tos_opt(char *, int *);
 intprocess_tls_opt(char *, int *);
 void   save_peer_cert(struct tls *_tls_ctx, FILE *_fp);
-void   report_connect(const struct sockaddr *, socklen_t, char *);
+void   report_sock(const char *, const struct sockaddr *, socklen_t, char *);
 void   report_tls(struct tls *tls_ctx, char * host);
 void   usage(int);
 ssize_t drainbuf(int, unsigned char *, size_t *, struct tls *);
@@ -596,7 +596,8 @@ main(int argc, char *argv[])
err(1, "connect");
 
if (vflag)
-   report_connect((struct sockaddr *)&z, 
len, NULL);
+   report_sock("Connection received",
+   (struct sockaddr *)&z, len, NULL);
 
readwrite(s, NULL);
} else {
@@ -611,7 +612,8 @@ main(int argc, char *argv[])
err(1, "accept");
}
if (vflag)
-   report_connect((struct sockaddr 
*)&cliaddr, len,
+   report_sock("Connection received",
+   (struct sockaddr *)&cliaddr, len,
family == AF_UNIX ? host : NULL);
if ((usetls) &&
(tls_cctx = tls_setup_server(tls_ctx, 
connfd, host)))
@@ -754,6 +756,8 @@ unix_bind(char *path, int flags)
errno = save_errno;
return -1;
}
+   if (vflag)
+   report_sock("Bound", NULL, 0, path);
 
return s;
 }
@@ -890,13 +894,16 @@ int
 unix_listen(char *path)
 {
int s;
+
if ((s = unix_bind(path, 0)) < 0)
return -1;
-
if (listen(s, 5) < 0) {
close(s);
return -1;
}
+   if (vflag)
+   report_sock("Listening", NULL, 0, path);
+
return s;
 }
 
@@ -1037,6 +1044,16 @@ local_listen(const char *host, const cha
if (listen(s, 1) < 0)
err(1, "listen");
}
+   if (vflag && s != -1) {
+   struct sockaddr_storage ss;
+   socklen_t len;
+
+   len = sizeof(ss);
+   if (getsockname(s, (struct sockaddr *)&ss, &len) == -1)
+   err(1, "getsockname");
+   report_sock(uflag ? "Bound" : "Listening",
+   (struct sockaddr *)&ss, len, NULL);
+   }
 
freeaddrinfo(res0);
 
@@ -1689,34 +1706,30 @@ report_tls(struct tls * tls_ctx, char * 
 }
 
 void
-report_connect(const struct sockaddr *sa, socklen_t salen, char *path)
+report_sock(const char *msg, const struct sockaddr *sa, socklen_t salen,
+char *path)
 {
-   char remote_host[NI_MAXHOST];
-   char remote_port[NI_MAXSERV];
+   char host[NI_MAXHOST], port[NI_MAXSERV];
int herr;
int flags = NI_NUMERICSERV;
 
if (path != NULL) {
-   fprintf(stderr, "Connection on %s received!\n", path);
+   fprintf(stderr, "%s on %s\n", msg, path);
return;
}
 
if (nflag)
flags |= NI_NUMERICHOST;
 
-   if ((herr = getnameinfo(sa, salen,
-   remote_host, sizeof(remote_host),
-   remote_port, sizeof(remote_port),
-   flags)) != 0) {
+   if ((herr = getnameinfo(sa, salen, host, sizeof(host),
+   port, sizeof(port), flags)) != 0) {
if (herr == EAI_SYSTEM)
err(1, "getnameinfo");
else
errx(1, "getnameinfo: %s", gai_strerror(herr));
}
 
-   fprintf(stderr,
-   "Connection from %s %s "
-   "received!\n", remote_host, remote_port);
+   fprintf(stderr, "%s on %s %s\n", msg, host, port);
 }
 
 void



Re: netcat report listen

2018-11-08 Thread Theo Buehler
On Thu, Nov 08, 2018 at 02:12:35PM -0700, Alexander Bluhm wrote:
> Hi,
> 
> It is easier to write race free tests if netcat reports when the
> listen system call has finished.  This avoids ugly kernel lookups
> with fstat.  Just report bind or listen like accepted connections
> in verbose mode to stderr.  Then the other end can proceed.
> 
> ok?

ok (with one tiny nit below)

> @@ -1037,6 +1044,16 @@ local_listen(const char *host, const cha
>   if (listen(s, 1) < 0)
>   err(1, "listen");
>   }
> + if (vflag && s != -1) {
> + struct sockaddr_storage ss;
> + socklen_t len;
> +
> + len = sizeof(ss);
> + if (getsockname(s, (struct sockaddr *)&ss, &len) == -1)
> + err(1, "getsockname");

indent with a tab instead of four spaces.



YP/NIS support in /etc/ethers, libc ether_ntohost/ether_hostton

2018-11-08 Thread Bryan Steele
These libc functions are used to map hardware MAC addresses to hostnames
and vice versa. If it exists, /etc/ethers will typically contain a
number of lines like so:

34:00:8a:56:10:20   superman

In addition to that, there is support for using a YP (nee Yellow Pee)
lookup service:

"If a '+' appears alone on a line in the file, then ether_hostton() will
 consult the x ethers.byname YP map, and ether_ntohost() will consult the
 ethers.byaddr YP map."

This support currently interferes with my work to reduce the pledge(2)
in tcpdump(8), as the "inet" promise is required to perform these
lookups..

I've come up with small a diff to remove it, but it was suggested there
may be some interactions with ldap, and I'm not sure how important this
functionality may be to existing YP users (I am not one).

Any objections to this approach? (Missing man page removal bits)

-Bryan.

Index: ethers.c
===
RCS file: /cvs/src/lib/libc/net/ethers.c,v
retrieving revision 1.25
diff -u -p -u -r1.25 ethers.c
--- lib/libc/net/ethers.c   21 Sep 2016 04:38:56 -  1.25
+++ lib/libc/net/ethers.c   8 Nov 2018 23:54:19 -
@@ -34,9 +34,6 @@
 #include 
 #include 
 #include 
-#ifdef YP
-#include 
-#endif
 
 #ifndef _PATH_ETHERS
 #define _PATH_ETHERS   "/etc/ethers"
@@ -99,18 +96,6 @@ ether_ntohost(char *hostname, struct eth
char buf[BUFSIZ+1], *p;
size_t len;
struct ether_addr try;
-#ifdef YP
-   char trybuf[sizeof("xx:xx:xx:xx:xx:xx")];
-   int trylen;
-#endif
-
-#ifdef YP
-   snprintf(trybuf, sizeof trybuf, "%x:%x:%x:%x:%x:%x", 
-   e->ether_addr_octet[0], e->ether_addr_octet[1],
-   e->ether_addr_octet[2], e->ether_addr_octet[3],
-   e->ether_addr_octet[4], e->ether_addr_octet[5]);
-   trylen = strlen(trybuf);
-#endif
 
f = fopen(_PATH_ETHERS, "re");
if (f == NULL)
@@ -123,26 +108,9 @@ ether_ntohost(char *hostname, struct eth
(void)memcpy(buf, p, len);
buf[len] = '\n';/* code assumes newlines later on */
buf[len+1] = '\0';
-#ifdef YP
-   /* A + in the file means try YP now.  */
-   if (!strncmp(buf, "+\n", sizeof(buf))) {
-   char *ypbuf, *ypdom;
-   int ypbuflen;
-
-   if (yp_get_default_domain(&ypdom))
-   continue;
-   if (yp_match(ypdom, "ethers.byaddr", trybuf,
-   trylen, &ypbuf, &ypbuflen))
-   continue;
-   if (ether_line(ypbuf, &try, hostname) == 0) {
-   free(ypbuf);
-   (void)fclose(f);
-   return (0);
-   }
-   free(ypbuf);
+   /* A + in the file meant try YP, ignore it. */
+   if (!strncmp(buf, "+\n", sizeof(buf)))
continue;
-   }
-#endif
if (ether_line(buf, &try, hostname) == 0 &&
memcmp(&try, e, sizeof(try)) == 0) {
(void)fclose(f);
@@ -161,9 +129,6 @@ ether_hostton(const char *hostname, stru
char buf[BUFSIZ+1], *p;
char try[HOST_NAME_MAX+1];
size_t len;
-#ifdef YP
-   int hostlen = strlen(hostname);
-#endif
 
f = fopen(_PATH_ETHERS, "re");
if (f==NULL)
@@ -177,26 +142,9 @@ ether_hostton(const char *hostname, stru
memcpy(buf, p, len);
buf[len] = '\n';/* code assumes newlines later on */
buf[len+1] = '\0';
-#ifdef YP
-   /* A + in the file means try YP now.  */
-   if (!strncmp(buf, "+\n", sizeof(buf))) {
-   char *ypbuf, *ypdom;
-   int ypbuflen;
-
-   if (yp_get_default_domain(&ypdom))
-   continue;
-   if (yp_match(ypdom, "ethers.byname", hostname, hostlen,
-   &ypbuf, &ypbuflen))
-   continue;
-   if (ether_line(ypbuf, e, try) == 0) {
-   free(ypbuf);
-   (void)fclose(f);
-   return (0);
-   }
-   free(ypbuf);
+   /* A + in the file meant try YP, ignore it. */
+   if (!strncmp(buf, "+\n", sizeof(buf)))
continue;
-   }
-#endif
if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) 
{
(void)fclose(f);
return (0);



Re: YP/NIS support in /etc/ethers, libc ether_ntohost/ether_hostton

2018-11-08 Thread Bryan Steele
This was suggested by deraadt@, sorry.

On Thu, Nov 08, 2018 at 08:05:13PM -0500, Bryan Steele wrote:
> These libc functions are used to map hardware MAC addresses to hostnames
> and vice versa. If it exists, /etc/ethers will typically contain a
> number of lines like so:
> 
> 34:00:8a:56:10:20 superman
> 
> In addition to that, there is support for using a YP (nee Yellow Pee)
> lookup service:
> 
> "If a '+' appears alone on a line in the file, then ether_hostton() will
>  consult the x ethers.byname YP map, and ether_ntohost() will consult the
>  ethers.byaddr YP map."
> 
> This support currently interferes with my work to reduce the pledge(2)
> in tcpdump(8), as the "inet" promise is required to perform these
> lookups..
> 
> I've come up with small a diff to remove it, but it was suggested there
> may be some interactions with ldap, and I'm not sure how important this
> functionality may be to existing YP users (I am not one).
> 
> Any objections to this approach? (Missing man page removal bits)
> 
> -Bryan.
> 
> Index: ethers.c
> ===
> RCS file: /cvs/src/lib/libc/net/ethers.c,v
> retrieving revision 1.25
> diff -u -p -u -r1.25 ethers.c
> --- lib/libc/net/ethers.c 21 Sep 2016 04:38:56 -  1.25
> +++ lib/libc/net/ethers.c 8 Nov 2018 23:54:19 -
> @@ -34,9 +34,6 @@
>  #include 
>  #include 
>  #include 
> -#ifdef YP
> -#include 
> -#endif
>  
>  #ifndef _PATH_ETHERS
>  #define _PATH_ETHERS "/etc/ethers"
> @@ -99,18 +96,6 @@ ether_ntohost(char *hostname, struct eth
>   char buf[BUFSIZ+1], *p;
>   size_t len;
>   struct ether_addr try;
> -#ifdef YP
> - char trybuf[sizeof("xx:xx:xx:xx:xx:xx")];
> - int trylen;
> -#endif
> -
> -#ifdef YP
> - snprintf(trybuf, sizeof trybuf, "%x:%x:%x:%x:%x:%x", 
> - e->ether_addr_octet[0], e->ether_addr_octet[1],
> - e->ether_addr_octet[2], e->ether_addr_octet[3],
> - e->ether_addr_octet[4], e->ether_addr_octet[5]);
> - trylen = strlen(trybuf);
> -#endif
>  
>   f = fopen(_PATH_ETHERS, "re");
>   if (f == NULL)
> @@ -123,26 +108,9 @@ ether_ntohost(char *hostname, struct eth
>   (void)memcpy(buf, p, len);
>   buf[len] = '\n';/* code assumes newlines later on */
>   buf[len+1] = '\0';
> -#ifdef YP
> - /* A + in the file means try YP now.  */
> - if (!strncmp(buf, "+\n", sizeof(buf))) {
> - char *ypbuf, *ypdom;
> - int ypbuflen;
> -
> - if (yp_get_default_domain(&ypdom))
> - continue;
> - if (yp_match(ypdom, "ethers.byaddr", trybuf,
> - trylen, &ypbuf, &ypbuflen))
> - continue;
> - if (ether_line(ypbuf, &try, hostname) == 0) {
> - free(ypbuf);
> - (void)fclose(f);
> - return (0);
> - }
> - free(ypbuf);
> + /* A + in the file meant try YP, ignore it. */
> + if (!strncmp(buf, "+\n", sizeof(buf)))
>   continue;
> - }
> -#endif
>   if (ether_line(buf, &try, hostname) == 0 &&
>   memcmp(&try, e, sizeof(try)) == 0) {
>   (void)fclose(f);
> @@ -161,9 +129,6 @@ ether_hostton(const char *hostname, stru
>   char buf[BUFSIZ+1], *p;
>   char try[HOST_NAME_MAX+1];
>   size_t len;
> -#ifdef YP
> - int hostlen = strlen(hostname);
> -#endif
>  
>   f = fopen(_PATH_ETHERS, "re");
>   if (f==NULL)
> @@ -177,26 +142,9 @@ ether_hostton(const char *hostname, stru
>   memcpy(buf, p, len);
>   buf[len] = '\n';/* code assumes newlines later on */
>   buf[len+1] = '\0';
> -#ifdef YP
> - /* A + in the file means try YP now.  */
> - if (!strncmp(buf, "+\n", sizeof(buf))) {
> - char *ypbuf, *ypdom;
> - int ypbuflen;
> -
> - if (yp_get_default_domain(&ypdom))
> - continue;
> - if (yp_match(ypdom, "ethers.byname", hostname, hostlen,
> - &ypbuf, &ypbuflen))
> - continue;
> - if (ether_line(ypbuf, e, try) == 0) {
> - free(ypbuf);
> - (void)fclose(f);
> - return (0);
> - }
> - free(ypbuf);
> + /* A + in the file meant try YP, ignore it. */
> + if (!strncmp(buf, "+\n", sizeof(buf)))
>   continue;
> - }
> -#endif
>   if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) 
> {
>   (void)fclose(f);
>  

[PATCH] Add elan(4) touchpad driver

2018-11-08 Thread ben
Hi all,

This patch adds a new touchpad driver, elan(4), which supports older non
PTP I2C Elantech touchpads. I have tested this on my HP Chromebook 13
and it appears to work well, multitouch is working as well as the three
physical mouse buttons. I do not know how well this will work on other
Elantech touchpads however; I believe there are a few devices that use
the same protocol though they may have different ACPI hids. 

This driver is similar to iatp(4) and is largely based upon it although
the actual protocol used by the touchpad is quite different.

I have added a basic man page following iatp(4) as a guide. I wasn't
sure if I should add the copyright and OpenBSD headers and so for this
first patch I have omitted them.

This together with my previous sdhc(4) patch results in a mostly working
OpenBSD install on the HP Chromebook 13, unfortunately apm(4) is still
problematic and the device gets stuck in sleep.

Thanks,
Ben.


Index: sys/arch/amd64/conf/GENERIC
===
RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
retrieving revision 1.464
diff -u -p -r1.464 GENERIC
--- sys/arch/amd64/conf/GENERIC 26 Oct 2018 20:26:19 -  1.464
+++ sys/arch/amd64/conf/GENERIC 9 Nov 2018 03:25:17 -
@@ -177,6 +177,8 @@ imt*at ihidev?  # HID-over-i2c multitou
 wsmouse* at imt? mux 0
 iatp* at iic?  # Atmel maXTouch i2c touchpad/touchscreen
 wsmouse* at iatp? mux 0
+elan* at iic?  # Elantech i2c touchpad
+wsmouse* at elan? mux 0
 
 skgpio0 at isa? port 0x680 # Soekris net6501 GPIO and LEDs
 gpio* at skgpio?
Index: sys/dev/acpi/dwiic_acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/dwiic_acpi.c,v
retrieving revision 1.8
diff -u -p -r1.8 dwiic_acpi.c
--- sys/dev/acpi/dwiic_acpi.c   1 Jul 2018 11:37:11 -   1.8
+++ sys/dev/acpi/dwiic_acpi.c   9 Nov 2018 03:25:18 -
@@ -51,6 +51,8 @@ int   dwiic_acpi_found_ihidev(struct dwii
struct aml_node *, char *, struct dwiic_crs);
 intdwiic_acpi_found_iatp(struct dwiic_softc *, struct aml_node *,
char *, struct dwiic_crs);
+intdwiic_acpi_found_elan(struct dwiic_softc *, struct aml_node *,
+   char *, struct dwiic_crs);
 void   dwiic_acpi_get_params(struct dwiic_softc *, char *, uint16_t *,
uint16_t *, uint32_t *);
 void   dwiic_acpi_power(struct dwiic_softc *, int);
@@ -87,6 +89,11 @@ const char *iatp_hids[] = {
NULL
 };
 
+const char *elan_hids[] = {
+   "ELAN",
+   NULL
+};
+
 int
 dwiic_acpi_match(struct device *parent, void *match, void *aux)
 {
@@ -388,6 +395,8 @@ dwiic_acpi_found_hid(struct aml_node *no
return dwiic_acpi_found_ihidev(sc, node, dev, crs);
else if (dwiic_matchhids(dev, iatp_hids))
return dwiic_acpi_found_iatp(sc, node, dev, crs);
+   else if (dwiic_matchhids(dev, elan_hids))
+   return dwiic_acpi_found_elan(sc, node, dev, crs);
 
memset(&ia, 0, sizeof(ia));
ia.ia_tag = sc->sc_iba.iba_tag;
@@ -489,6 +498,34 @@ dwiic_acpi_found_iatp(struct dwiic_softc
ia.ia_tag = sc->sc_iba.iba_tag;
ia.ia_size = 1;
ia.ia_name = "iatp";
+   ia.ia_addr = crs.i2c_addr;
+   ia.ia_cookie = dev;
+
+   if (crs.irq_int <= 0 && crs.gpio_int_node == NULL) {
+   printf("%s: couldn't find irq for %s\n", sc->sc_dev.dv_xname,
+  aml_nodename(node->parent));
+   return 0;
+   }
+   ia.ia_intr = &crs;
+
+   if (config_found(sc->sc_iic, &ia, dwiic_i2c_print)) {
+   node->parent->attached = 1;
+   return 0;
+   }
+
+   return 1;
+}
+
+int
+dwiic_acpi_found_elan(struct dwiic_softc *sc, struct aml_node *node, char *dev,
+struct dwiic_crs crs)
+{
+   struct i2c_attach_args ia;
+
+   memset(&ia, 0, sizeof(ia));
+   ia.ia_tag = sc->sc_iba.iba_tag;
+   ia.ia_size = 1;
+   ia.ia_name = "elan";
ia.ia_addr = crs.i2c_addr;
ia.ia_cookie = dev;
 
Index: sys/dev/i2c/elan.c
===
RCS file: sys/dev/i2c/elan.c
diff -N sys/dev/i2c/elan.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ sys/dev/i2c/elan.c  9 Nov 2018 03:25:18 -
@@ -0,0 +1,511 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/* #define ELAN_DEBUG */
+
+#ifdef ELAN_DEBUG
+#define DPRINTF(x) printf x
+#else
+#define DPRINTF(x)
+#endif
+
+#define ELAN_INPUT 0x0003
+#define ELAN_MAX_X_AXIS0x0106
+#define ELAN_MAX_Y_AXIS0x0107
+#define ELAN_RESOLUTION0x0108
+
+#define ELAN_COMMAND   0x0005
+#define ELAN_CONTROL   0x0300
+
+#define ELAN_CMD_WAKEUP0x0800
+#define ELAN

let ping6 set the IPv6 traffic class like it does for IPv4 TOS

2018-11-08 Thread David Gwynne
This sets ping6 up to specify the traffic class field for the IPv6
traffic class field. The v6 traffic class is equivalent to the IPv6
TOS/DSCP field, so this uses the same getopt param and parsing to get
the value.

ok?

Index: ping.8
===
RCS file: /cvs/src/sbin/ping/ping.8,v
retrieving revision 1.59
diff -u -p -r1.59 ping.8
--- ping.8  26 Oct 2016 16:18:45 -  1.59
+++ ping.8  9 Nov 2018 05:05:35 -
@@ -87,6 +87,7 @@
 .Op Fl l Ar preload
 .Op Fl p Ar pattern
 .Op Fl s Ar packetsize
+.Op Fl T Ar toskeyword
 .Op Fl V Ar rtable
 .Op Fl w Ar maxwait
 .Ar host
@@ -221,8 +222,7 @@ which translates into 64 ICMP data bytes
 when combined with the 8 bytes of ICMP header data.
 The maximum packet size is 65467 for IPv4 and 65527 for IPv6.
 .It Fl T Ar toskeyword
-.Pq IPv4 only
-Change the TOS value.
+Change the IPv4 TOS or IPv6 Traffic Class value.
 .Ar toskeyword
 may be one of
 .Cm critical ,
Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.230
diff -u -p -r1.230 ping.c
--- ping.c  14 Oct 2018 19:47:53 -  1.230
+++ ping.c  9 Nov 2018 05:05:35 -
@@ -150,7 +150,7 @@ int options;
 /* 0x0200 */
 #defineF_HDRINCL   0x0400
 #defineF_TTL   0x0800
-/* 0x1000 */
+#defineF_TOS   0x1000
 #defineF_AUD_RECV  0x2000
 #defineF_AUD_MISS  0x4000
 
@@ -291,7 +291,7 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ECHOLEN + ECHOTMLEN];
while ((ch = getopt(argc, argv, v6flag ?
-   "c:dEefHh:I:i:Ll:mNnp:qS:s:V:vw:" :
+   "c:dEefHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
"DEI:LRS:c:defHi:l:np:qs:T:t:V:vw:")) != -1) {
switch(ch) {
case 'c':
@@ -386,6 +386,7 @@ main(int argc, char *argv[])
 #ifndef SMALL
case 'T':
options |= F_HDRINCL;
+   options |= F_TOS;
errno = 0;
errstr = NULL;
if (map_tos(optarg, &tos))
@@ -671,6 +672,13 @@ main(int argc, char *argv[])
scmsg->cmsg_level = IPPROTO_IPV6;
scmsg->cmsg_type = IPV6_HOPLIMIT;
*(int *)(CMSG_DATA(scmsg)) = hoplimit;
+   }
+
+   if (options & F_TOS) {
+   optval = tos;
+   if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &optval,
+   (socklen_t)sizeof(optval)) < 0)
+   warn("setsockopt(IPV6_TVAL)"); /* XXX err? */
}
 
optval = 1;



Re: [PATCH] Add elan(4) touchpad driver

2018-11-08 Thread joshua stein
On Fri, 09 Nov 2018 at 03:30:07 +, b...@curlybracket.co.uk wrote:
> Hi all,
> 
> This patch adds a new touchpad driver, elan(4), which supports older non
> PTP I2C Elantech touchpads. I have tested this on my HP Chromebook 13
> and it appears to work well, multitouch is working as well as the three
> physical mouse buttons. I do not know how well this will work on other
> Elantech touchpads however; I believe there are a few devices that use
> the same protocol though they may have different ACPI hids. 
> 
> This driver is similar to iatp(4) and is largely based upon it although
> the actual protocol used by the touchpad is quite different.
> 
> I have added a basic man page following iatp(4) as a guide. I wasn't
> sure if I should add the copyright and OpenBSD headers and so for this
> first patch I have omitted them.
> 
> This together with my previous sdhc(4) patch results in a mostly working
> OpenBSD install on the HP Chromebook 13, unfortunately apm(4) is still
> problematic and the device gets stuck in sleep.

Hi,

Well done!  The code looks mostly ok.  There are a bunch of 8-space 
indentations instead of tabs that need to be fixed.  You should 
include a comment header with your copyright and a license, 
preferably /usr/share/misc/license.template.

We have a habit of naming USB and i2c devices starting with 'u' and 
'i', and since there is already a bunch of Elantech touchpad device 
support in pms(4), it would be best to rename this from 'elan' to 
something more narrow.  Maybe ietp (since iatp is for i2c Atmel 
touchpads) or ielantp or something.

As for the driver itself, is this implementing a specific protocol 
version for Elantech devices like the four in pms(4)?  If this 
driver is limited to a specific protocol version or model, it would 
be beneficial to mention that in the driver code and man page.


> Index: sys/arch/amd64/conf/GENERIC
> ===
> RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
> retrieving revision 1.464
> diff -u -p -r1.464 GENERIC
> --- sys/arch/amd64/conf/GENERIC   26 Oct 2018 20:26:19 -  1.464
> +++ sys/arch/amd64/conf/GENERIC   9 Nov 2018 03:25:17 -
> @@ -177,6 +177,8 @@ imt*  at ihidev?  # HID-over-i2c multitou
>  wsmouse* at imt? mux 0
>  iatp* at iic?# Atmel maXTouch i2c 
> touchpad/touchscreen
>  wsmouse* at iatp? mux 0
> +elan* at iic?# Elantech i2c touchpad
> +wsmouse* at elan? mux 0
>  
>  skgpio0 at isa? port 0x680   # Soekris net6501 GPIO and LEDs
>  gpio* at skgpio?
> Index: sys/dev/acpi/dwiic_acpi.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/dwiic_acpi.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 dwiic_acpi.c
> --- sys/dev/acpi/dwiic_acpi.c 1 Jul 2018 11:37:11 -   1.8
> +++ sys/dev/acpi/dwiic_acpi.c 9 Nov 2018 03:25:18 -
> @@ -51,6 +51,8 @@ int dwiic_acpi_found_ihidev(struct dwii
>   struct aml_node *, char *, struct dwiic_crs);
>  int  dwiic_acpi_found_iatp(struct dwiic_softc *, struct aml_node *,
>   char *, struct dwiic_crs);
> +int  dwiic_acpi_found_elan(struct dwiic_softc *, struct aml_node *,
> + char *, struct dwiic_crs);
>  void dwiic_acpi_get_params(struct dwiic_softc *, char *, uint16_t *,
>   uint16_t *, uint32_t *);
>  void dwiic_acpi_power(struct dwiic_softc *, int);
> @@ -87,6 +89,11 @@ const char *iatp_hids[] = {
>   NULL
>  };
>  
> +const char *elan_hids[] = {
> + "ELAN",
> + NULL
> +};
> +
>  int
>  dwiic_acpi_match(struct device *parent, void *match, void *aux)
>  {
> @@ -388,6 +395,8 @@ dwiic_acpi_found_hid(struct aml_node *no
>   return dwiic_acpi_found_ihidev(sc, node, dev, crs);
>   else if (dwiic_matchhids(dev, iatp_hids))
>   return dwiic_acpi_found_iatp(sc, node, dev, crs);
> + else if (dwiic_matchhids(dev, elan_hids))
> + return dwiic_acpi_found_elan(sc, node, dev, crs);
>  
>   memset(&ia, 0, sizeof(ia));
>   ia.ia_tag = sc->sc_iba.iba_tag;
> @@ -489,6 +498,34 @@ dwiic_acpi_found_iatp(struct dwiic_softc
>   ia.ia_tag = sc->sc_iba.iba_tag;
>   ia.ia_size = 1;
>   ia.ia_name = "iatp";
> + ia.ia_addr = crs.i2c_addr;
> + ia.ia_cookie = dev;
> +
> + if (crs.irq_int <= 0 && crs.gpio_int_node == NULL) {
> + printf("%s: couldn't find irq for %s\n", sc->sc_dev.dv_xname,
> +aml_nodename(node->parent));
> + return 0;
> + }
> + ia.ia_intr = &crs;
> +
> + if (config_found(sc->sc_iic, &ia, dwiic_i2c_print)) {
> + node->parent->attached = 1;
> + return 0;
> + }
> +
> + return 1;
> +}
> +
> +int
> +dwiic_acpi_found_elan(struct dwiic_softc *sc, struct aml_node *node, char 
> *dev,
> +struct dwiic_crs crs)
> +{
> + struct i2c_attach_args 

Re: let ping6 set the IPv6 traffic class like it does for IPv4 TOS

2018-11-08 Thread Florian Obser
please update usage(), then it's OK florian@

Could you do tracerute6, too?

On Fri, Nov 09, 2018 at 03:08:20PM +1000, David Gwynne wrote:
> This sets ping6 up to specify the traffic class field for the IPv6
> traffic class field. The v6 traffic class is equivalent to the IPv6
> TOS/DSCP field, so this uses the same getopt param and parsing to get
> the value.
> 
> ok?
> 
> Index: ping.8
> ===
> RCS file: /cvs/src/sbin/ping/ping.8,v
> retrieving revision 1.59
> diff -u -p -r1.59 ping.8
> --- ping.826 Oct 2016 16:18:45 -  1.59
> +++ ping.89 Nov 2018 05:05:35 -
> @@ -87,6 +87,7 @@
>  .Op Fl l Ar preload
>  .Op Fl p Ar pattern
>  .Op Fl s Ar packetsize
> +.Op Fl T Ar toskeyword
>  .Op Fl V Ar rtable
>  .Op Fl w Ar maxwait
>  .Ar host
> @@ -221,8 +222,7 @@ which translates into 64 ICMP data bytes
>  when combined with the 8 bytes of ICMP header data.
>  The maximum packet size is 65467 for IPv4 and 65527 for IPv6.
>  .It Fl T Ar toskeyword
> -.Pq IPv4 only
> -Change the TOS value.
> +Change the IPv4 TOS or IPv6 Traffic Class value.
>  .Ar toskeyword
>  may be one of
>  .Cm critical ,
> Index: ping.c
> ===
> RCS file: /cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.230
> diff -u -p -r1.230 ping.c
> --- ping.c14 Oct 2018 19:47:53 -  1.230
> +++ ping.c9 Nov 2018 05:05:35 -
> @@ -150,7 +150,7 @@ int options;
>  /*   0x0200 */
>  #define  F_HDRINCL   0x0400
>  #define  F_TTL   0x0800
> -/*   0x1000 */
> +#define  F_TOS   0x1000
>  #define  F_AUD_RECV  0x2000
>  #define  F_AUD_MISS  0x4000
>  
> @@ -291,7 +291,7 @@ main(int argc, char *argv[])
>   preload = 0;
>   datap = &outpack[ECHOLEN + ECHOTMLEN];
>   while ((ch = getopt(argc, argv, v6flag ?
> - "c:dEefHh:I:i:Ll:mNnp:qS:s:V:vw:" :
> + "c:dEefHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
>   "DEI:LRS:c:defHi:l:np:qs:T:t:V:vw:")) != -1) {
>   switch(ch) {
>   case 'c':
> @@ -386,6 +386,7 @@ main(int argc, char *argv[])
>  #ifndef SMALL
>   case 'T':
>   options |= F_HDRINCL;
> + options |= F_TOS;
>   errno = 0;
>   errstr = NULL;
>   if (map_tos(optarg, &tos))
> @@ -671,6 +672,13 @@ main(int argc, char *argv[])
>   scmsg->cmsg_level = IPPROTO_IPV6;
>   scmsg->cmsg_type = IPV6_HOPLIMIT;
>   *(int *)(CMSG_DATA(scmsg)) = hoplimit;
> + }
> +
> + if (options & F_TOS) {
> + optval = tos;
> + if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &optval,
> + (socklen_t)sizeof(optval)) < 0)
> + warn("setsockopt(IPV6_TVAL)"); /* XXX err? */
>   }
>  
>   optval = 1;
> 

-- 
I'm not entirely sure you are real.



Unused defines in ed25519

2018-11-08 Thread Geoff Hill
Looking at the ed25519 code, these defines are unused. They appear to be unused
upstream as well (in djt's supercop ed25519/ref implementation), so maybe this
should be suggested there instead of deviating. Up to you.


Index: usr.bin/signify/fe25519.c
===
RCS file: /cvs/src/usr.bin/signify/fe25519.c,v
retrieving revision 1.1
diff -u -p -u -r1.1 fe25519.c
--- usr.bin/signify/fe25519.c   22 Jul 2014 00:41:19 -  1.1
+++ usr.bin/signify/fe25519.c   9 Nov 2018 05:58:45 -
@@ -6,9 +6,6 @@
  * Copied from supercop-20130419/crypto_sign/ed25519/ref/fe25519.c
  */
 
-#define WINDOWSIZE 1 /* Should be 1,2, or 4 */
-#define WINDOWMASK ((1<

Re: let ping6 set the IPv6 traffic class like it does for IPv4 TOS

2018-11-08 Thread David Gwynne
On Fri, Nov 09, 2018 at 06:33:46AM +0100, Florian Obser wrote:
> please update usage(), then it's OK florian@
> 
> Could you do tracerute6, too?

like this?

Index: sbin/ping/ping.8
===
RCS file: /cvs/src/sbin/ping/ping.8,v
retrieving revision 1.59
diff -u -p -r1.59 ping.8
--- sbin/ping/ping.826 Oct 2016 16:18:45 -  1.59
+++ sbin/ping/ping.89 Nov 2018 07:00:46 -
@@ -87,6 +87,7 @@
 .Op Fl l Ar preload
 .Op Fl p Ar pattern
 .Op Fl s Ar packetsize
+.Op Fl T Ar toskeyword
 .Op Fl V Ar rtable
 .Op Fl w Ar maxwait
 .Ar host
@@ -221,8 +222,7 @@ which translates into 64 ICMP data bytes
 when combined with the 8 bytes of ICMP header data.
 The maximum packet size is 65467 for IPv4 and 65527 for IPv6.
 .It Fl T Ar toskeyword
-.Pq IPv4 only
-Change the TOS value.
+Change the IPv4 TOS or IPv6 Traffic Class value.
 .Ar toskeyword
 may be one of
 .Cm critical ,
Index: sbin/ping/ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.230
diff -u -p -r1.230 ping.c
--- sbin/ping/ping.c14 Oct 2018 19:47:53 -  1.230
+++ sbin/ping/ping.c9 Nov 2018 07:00:46 -
@@ -150,7 +150,7 @@ int options;
 /* 0x0200 */
 #defineF_HDRINCL   0x0400
 #defineF_TTL   0x0800
-/* 0x1000 */
+#defineF_TOS   0x1000
 #defineF_AUD_RECV  0x2000
 #defineF_AUD_MISS  0x4000
 
@@ -291,7 +291,7 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ECHOLEN + ECHOTMLEN];
while ((ch = getopt(argc, argv, v6flag ?
-   "c:dEefHh:I:i:Ll:mNnp:qS:s:V:vw:" :
+   "c:dEefHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
"DEI:LRS:c:defHi:l:np:qs:T:t:V:vw:")) != -1) {
switch(ch) {
case 'c':
@@ -386,6 +386,7 @@ main(int argc, char *argv[])
 #ifndef SMALL
case 'T':
options |= F_HDRINCL;
+   options |= F_TOS;
errno = 0;
errstr = NULL;
if (map_tos(optarg, &tos))
@@ -673,6 +674,13 @@ main(int argc, char *argv[])
*(int *)(CMSG_DATA(scmsg)) = hoplimit;
}
 
+   if (options & F_TOS) {
+   optval = tos;
+   if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &optval,
+   (socklen_t)sizeof(optval)) < 0)
+   warn("setsockopt(IPV6_TVAL)"); /* XXX err? */
+   }
+
optval = 1;
if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &optval,
(socklen_t)sizeof(optval)) < 0)
@@ -2160,7 +2168,8 @@ usage(void)
fprintf(stderr,
"usage: ping6 [-dEefHLmnqv] [-c count] [-h hoplimit] "
"[-I sourceaddr]\n\t[-i wait] [-l preload] [-p pattern] "
-   "[-s packetsize] [-V rtable]\n\t[-w maxwait] host\n");
+   "[-s packetsize] [-T toskeyword]\n\t"
+   "[-V rtable] [-w maxwait] host\n");
} else {
fprintf(stderr,
"usage: ping [-DdEefHLnqRv] [-c count] [-I ifaddr]"
Index: usr.sbin/traceroute/traceroute.c
===
RCS file: /cvs/src/usr.sbin/traceroute/traceroute.c,v
retrieving revision 1.157
diff -u -p -r1.157 traceroute.c
--- usr.sbin/traceroute/traceroute.c20 Oct 2018 19:55:01 -  1.157
+++ usr.sbin/traceroute/traceroute.c9 Nov 2018 07:00:46 -
@@ -414,7 +414,7 @@ main(int argc, char *argv[])
err(1, "sysctl");
conf->max_ttl = i;
 
-   while ((ch = getopt(argc, argv, v6flag ? "AcDdf:Ilm:np:q:Ss:w:vV:" :
+   while ((ch = getopt(argc, argv, v6flag ? "AcDdf:Ilm:np:q:Ss:t:w:vV:" :
"AcDdf:g:Ilm:nP:p:q:Ss:t:V:vw:x")) != -1)
switch (ch) {
case 'A':
@@ -802,6 +802,12 @@ main(int argc, char *argv[])
0)
err(1, "bind sndsock");
 
+   if (conf->tflag) {
+   if (setsockopt(sndsock, IPPROTO_IPV6, IPV6_TCLASS,
+   &conf->tos, sizeof(conf->tos)) < 0)
+   err(6, "IPV6_TCLASS");
+   }
+
len = sizeof(from6);
if (getsockname(sndsock, (struct sockaddr *)&from6, &len) < 0)
err(1, "getsockname");
@@ -943,10 +949,10 @@ void
 usage(int v6flag)
 {
if (v6flag) {
-   fprintf(stderr, "usage: traceroute6 [-AcDdIlnSv] [-f first_hop] 
"
-   "[-m max_hop] [-p port]\n"
-   "\t[-q nqueries] [-s src_addr] [-V rtable] [-w waittime] "
-   "host\n\t[datalen]\n");
+   fprintf(stderr, "usage: %s "
+ 

Re: let ping6 set the IPv6 traffic class like it does for IPv4 TOS

2018-11-08 Thread Denis Fondras
On Fri, Nov 09, 2018 at 05:07:10PM +1000, David Gwynne wrote:
> On Fri, Nov 09, 2018 at 06:33:46AM +0100, Florian Obser wrote:
> > please update usage(), then it's OK florian@
> > 
> > Could you do tracerute6, too?
> 
> like this?
> 

Can you also update traceroute.8 ? :)


> Index: sbin/ping/ping.8
> ===
> RCS file: /cvs/src/sbin/ping/ping.8,v
> retrieving revision 1.59
> diff -u -p -r1.59 ping.8
> --- sbin/ping/ping.8  26 Oct 2016 16:18:45 -  1.59
> +++ sbin/ping/ping.8  9 Nov 2018 07:00:46 -
> @@ -87,6 +87,7 @@
>  .Op Fl l Ar preload
>  .Op Fl p Ar pattern
>  .Op Fl s Ar packetsize
> +.Op Fl T Ar toskeyword
>  .Op Fl V Ar rtable
>  .Op Fl w Ar maxwait
>  .Ar host
> @@ -221,8 +222,7 @@ which translates into 64 ICMP data bytes
>  when combined with the 8 bytes of ICMP header data.
>  The maximum packet size is 65467 for IPv4 and 65527 for IPv6.
>  .It Fl T Ar toskeyword
> -.Pq IPv4 only
> -Change the TOS value.
> +Change the IPv4 TOS or IPv6 Traffic Class value.
>  .Ar toskeyword
>  may be one of
>  .Cm critical ,
> Index: sbin/ping/ping.c
> ===
> RCS file: /cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.230
> diff -u -p -r1.230 ping.c
> --- sbin/ping/ping.c  14 Oct 2018 19:47:53 -  1.230
> +++ sbin/ping/ping.c  9 Nov 2018 07:00:46 -
> @@ -150,7 +150,7 @@ int options;
>  /*   0x0200 */
>  #define  F_HDRINCL   0x0400
>  #define  F_TTL   0x0800
> -/*   0x1000 */
> +#define  F_TOS   0x1000
>  #define  F_AUD_RECV  0x2000
>  #define  F_AUD_MISS  0x4000
>  
> @@ -291,7 +291,7 @@ main(int argc, char *argv[])
>   preload = 0;
>   datap = &outpack[ECHOLEN + ECHOTMLEN];
>   while ((ch = getopt(argc, argv, v6flag ?
> - "c:dEefHh:I:i:Ll:mNnp:qS:s:V:vw:" :
> + "c:dEefHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
>   "DEI:LRS:c:defHi:l:np:qs:T:t:V:vw:")) != -1) {
>   switch(ch) {
>   case 'c':
> @@ -386,6 +386,7 @@ main(int argc, char *argv[])
>  #ifndef SMALL
>   case 'T':
>   options |= F_HDRINCL;
> + options |= F_TOS;
>   errno = 0;
>   errstr = NULL;
>   if (map_tos(optarg, &tos))
> @@ -673,6 +674,13 @@ main(int argc, char *argv[])
>   *(int *)(CMSG_DATA(scmsg)) = hoplimit;
>   }
>  
> + if (options & F_TOS) {
> + optval = tos;
> + if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &optval,
> + (socklen_t)sizeof(optval)) < 0)
> + warn("setsockopt(IPV6_TVAL)"); /* XXX err? */
> + }
> +
>   optval = 1;
>   if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &optval,
>   (socklen_t)sizeof(optval)) < 0)
> @@ -2160,7 +2168,8 @@ usage(void)
>   fprintf(stderr,
>   "usage: ping6 [-dEefHLmnqv] [-c count] [-h hoplimit] "
>   "[-I sourceaddr]\n\t[-i wait] [-l preload] [-p pattern] "
> - "[-s packetsize] [-V rtable]\n\t[-w maxwait] host\n");
> + "[-s packetsize] [-T toskeyword]\n\t"
> + "[-V rtable] [-w maxwait] host\n");
>   } else {
>   fprintf(stderr,
>   "usage: ping [-DdEefHLnqRv] [-c count] [-I ifaddr]"
> Index: usr.sbin/traceroute/traceroute.c
> ===
> RCS file: /cvs/src/usr.sbin/traceroute/traceroute.c,v
> retrieving revision 1.157
> diff -u -p -r1.157 traceroute.c
> --- usr.sbin/traceroute/traceroute.c  20 Oct 2018 19:55:01 -  1.157
> +++ usr.sbin/traceroute/traceroute.c  9 Nov 2018 07:00:46 -
> @@ -414,7 +414,7 @@ main(int argc, char *argv[])
>   err(1, "sysctl");
>   conf->max_ttl = i;
>  
> - while ((ch = getopt(argc, argv, v6flag ? "AcDdf:Ilm:np:q:Ss:w:vV:" :
> + while ((ch = getopt(argc, argv, v6flag ? "AcDdf:Ilm:np:q:Ss:t:w:vV:" :
>   "AcDdf:g:Ilm:nP:p:q:Ss:t:V:vw:x")) != -1)
>   switch (ch) {
>   case 'A':
> @@ -802,6 +802,12 @@ main(int argc, char *argv[])
>   0)
>   err(1, "bind sndsock");
>  
> + if (conf->tflag) {
> + if (setsockopt(sndsock, IPPROTO_IPV6, IPV6_TCLASS,
> + &conf->tos, sizeof(conf->tos)) < 0)
> + err(6, "IPV6_TCLASS");
> + }
> +
>   len = sizeof(from6);
>   if (getsockname(sndsock, (struct sockaddr *)&from6, &len) < 0)
>   err(1, "getsockname");
> @@ -943,10 +949,10 @@ void
>  usage(int v6flag)
>  {
>   if (v6flag) {
> - fprintf(stderr, "usage: traceroute6 [-AcDdIlnSv] [-f first_hop] 
> "
>