Silence some warnings in tftp(1)

2017-05-29 Thread Brian Callahan
Hi tech --

Silence some warnings in tftp(1) found by WARNINGS=yes.

~Brian

Index: main.c
===
RCS file: /cvs/src/usr.bin/tftp/main.c,v
retrieving revision 1.41
diff -u -p -u -p -r1.41 main.c
--- main.c  21 Jan 2017 11:32:04 -  1.41
+++ main.c  30 May 2017 01:38:56 -
@@ -458,15 +458,15 @@ get(int argc, char *argv[])
if (src == NULL)
src = argv[n];
else {
-   char *cp;
+   char *cpy;
 
*src++ = 0;
-   cp = argv[n];
-   if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') {
-   cp[strlen(cp) - 1] = '\0';
-   cp++;
+   cpy = argv[n];
+   if (cpy[0] == '[' && cpy[strlen(cpy) - 1] == ']') {
+   cpy[strlen(cpy) - 1] = '\0';
+   cpy++;
}
-   setpeer(cp, NULL);
+   setpeer(cpy, NULL);
if (!connected)
continue;
}
Index: tftp.c
===
RCS file: /cvs/src/usr.bin/tftp/tftp.c,v
retrieving revision 1.24
diff -u -p -u -p -r1.24 tftp.c
--- tftp.c  21 Oct 2014 06:15:16 -  1.24
+++ tftp.c  30 May 2017 01:38:56 -
@@ -506,7 +506,7 @@ nak(int error, struct sockaddr *peer)
 static void
 tpacket(const char *s, struct tftphdr *tp, int n)
 {
-   char*cp, *file;
+   char*cp, *ofile;
static char *opcodes[] =
{ "#0", "RRQ", "WRQ", "DATA", "ACK", "ERROR", "OACK" };
 
@@ -521,9 +521,9 @@ tpacket(const char *s, struct tftphdr *t
case RRQ:
case WRQ:
n -= 2;
-   file = cp = tp->th_stuff;
+   ofile = cp = tp->th_stuff;
cp = strchr(cp, '\0');
-   

Silence some warnings in top(1)

2017-05-29 Thread Brian Callahan
Hi tech --

Silence some warnings in top(1) found by WARNINGS=yes.

~Brian

Index: machine.c
===
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.88
diff -u -p -u -p -r1.88 machine.c
--- machine.c   15 Mar 2017 04:24:14 -  1.88
+++ machine.c   30 May 2017 01:29:45 -
@@ -159,14 +159,14 @@ int
 getncpu(void)
 {
int mib[] = { CTL_HW, HW_NCPU };
-   int ncpu;
-   size_t size = sizeof(ncpu);
+   int numcpu;
+   size_t size = sizeof(numcpu);
 
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]),
-   , , NULL, 0) == -1)
+   , , NULL, 0) == -1)
return (-1);
 
-   return (ncpu);
+   return (numcpu);
 }
 
 int
@@ -545,7 +545,7 @@ format_comm(struct kinfo_proc *kp)
 }
 
 char *
-format_next_process(caddr_t handle, char *(*get_userid)(uid_t), pid_t *pid,
+format_next_process(caddr_t hndl, char *(*get_userid)(uid_t), pid_t *pid,
 int show_threads)
 {
char *p_wait;
@@ -556,7 +556,7 @@ format_next_process(caddr_t handle, char
char buf[16];
 
/* find and remember the next proc structure */
-   hp = (struct handle *) handle;
+   hp = (struct handle *) hndl;
pp = *(hp->next_proc++);
hp->remaining--;
 



Re: pcdisplay(4): remove unused pcdisplay_mapchar_simple function

2017-05-29 Thread Mike Larkin
On Mon, May 29, 2017 at 11:09:06PM +0200, Frederic Cambus wrote:
> Hi tech@,
> 
> Here is a diff to remove the unused pcdisplay_mapchar_simple function
> in pcdisplay(4).
> 
> It has been unused since this code was imported from NetBSD.
> 
> Comments? OK?
> 

ok mlarkin

> Index: sys/dev/ic/pcdisplay_subr.c
> ===
> RCS file: /cvs/src/sys/dev/ic/pcdisplay_subr.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 pcdisplay_subr.c
> --- sys/dev/ic/pcdisplay_subr.c   11 Apr 2011 19:11:01 -  1.11
> +++ sys/dev/ic/pcdisplay_subr.c   29 May 2017 20:56:31 -
> @@ -144,17 +144,6 @@ done:
>  #endif   /* PCDISPLAY_SOFTCURSOR */
>  }
>  
> -#if 0
> -unsigned int
> -pcdisplay_mapchar_simple(void *id, int uni)
> -{
> - if (uni < 128)
> - return (uni);
> -
> - return (1); /* XXX ??? smiley */
> -}
> -#endif
> -
>  int
>  pcdisplay_putchar(void *id, int row, int col, u_int c, long attr)
>  {
> Index: sys/dev/ic/pcdisplayvar.h
> ===
> RCS file: /cvs/src/sys/dev/ic/pcdisplayvar.h,v
> retrieving revision 1.11
> diff -u -p -r1.11 pcdisplayvar.h
> --- sys/dev/ic/pcdisplayvar.h 28 Aug 2010 12:48:14 -  1.11
> +++ sys/dev/ic/pcdisplayvar.h 29 May 2017 20:56:31 -
> @@ -76,9 +76,6 @@ _pcdisplay_6845_write(struct pcdisplay_h
>  void pcdisplay_cursor_init(struct pcdisplayscreen *, int);
>  void pcdisplay_cursor_reset(struct pcdisplayscreen *);
>  int  pcdisplay_cursor(void *, int, int, int);
> -#if 0
> -unsigned int pcdisplay_mapchar_simple(void *, int);
> -#endif
>  int  pcdisplay_mapchar(void *, int, unsigned int *);
>  int  pcdisplay_putchar(void *, int, int, u_int, long);
>  struct wsdisplay_charcell;
> 



Silence some warnings in calendar(1)

2017-05-29 Thread Brian Callahan
Hi tech --

Fix some warnings found with WARNINGS=yes. I believe setting
ev1 = NULL in io.c is a false positive by cc but I fixed it anyway.

~Brian

Index: day.c
===
RCS file: /cvs/src/usr.bin/calendar/day.c,v
retrieving revision 1.34
diff -u -p -u -p -r1.34 day.c
--- day.c   14 Sep 2016 15:09:46 -  1.34
+++ day.c   30 May 2017 01:11:39 -
@@ -77,7 +77,9 @@ static struct fixs ndays[8];  /*
 static struct fixs fnmonths[13];  /* full national months names */
 static struct fixs nmonths[13];   /* short national month names */
 
-void
+static void fill_print_date(struct match *, struct tm *);
+
+static void
 fill_print_date(struct match *m, struct tm *tm)
 {
if (strftime(m->print_date, sizeof(m->print_date),
@@ -616,19 +618,19 @@ getday(char *s)
 int
 getdayvar(char *s)
 {
-   int offset;
+   int d_offset;
 
 
-   offset = strlen(s);
+   d_offset = strlen(s);
 
/* Sun+1 or Wednesday-2
 *^  ^   */
 
-   /* printf ("x: %s %s %d\n", s, s + offset - 2, offset); */
-   switch(*(s + offset - 2)) {
+   /* printf ("x: %s %s %d\n", s, s + d_offset - 2, d_offset); */
+   switch(*(s + d_offset - 2)) {
case '-':
case '+':
-   return(atoi(s + offset - 2));
+   return(atoi(s + d_offset - 2));
break;
}
 
@@ -637,15 +639,15 @@ getdayvar(char *s)
 */
 
/* last */
-   if  (offset > 4 && !strcasecmp(s + offset - 4, "last"))
+   if  (d_offset > 4 && !strcasecmp(s + d_offset - 4, "last"))
return(-1);
-   else if (offset > 5 && !strcasecmp(s + offset - 5, "first"))
+   else if (d_offset > 5 && !strcasecmp(s + d_offset - 5, "first"))
return(+1);
-   else if (offset > 6 && !strcasecmp(s + offset - 6, "second"))
+   else if (d_offset > 6 && !strcasecmp(s + d_offset - 6, "second"))
return(+2);
-   else if (offset > 5 && !strcasecmp(s + offset - 5, "third"))
+   else if (d_offset > 5 && !strcasecmp(s + d_offset - 5, "third"))
return(+3);
-   else if (offset > 6 && !strcasecmp(s + offset - 6, "fourth"))
+   else if (d_offset > 6 && !strcasecmp(s + d_offset - 6, "fourth"))
return(+4);
 
/* no offset detected */
@@ -667,13 +669,13 @@ void
 variable_weekday(int *day, int month, int year)
 {
int v1, v2;
-   int *cumdays;
+   int *cumuldays;
int day1;
 
if (isleap(year))
-   cumdays = daytab[1];
+   cumuldays = daytab[1];
else
-   cumdays = daytab[0];
+   cumuldays = daytab[0];
day1 = foy(year);
/* negative offset; last, -4 .. -1 */
if (*day < 0) {
@@ -681,10 +683,10 @@ variable_weekday(int *day, int month, in
*day = 10 + (*day % 10);/* day 1 ... 7 */
 
/* which weekday the end of the month is (1-7) */
-   v2 = (cumdays[month + 1] + day1) % 7 + 1;
+   v2 = (cumuldays[month + 1] + day1) % 7 + 1;
 
/* and subtract enough days */
-   *day = cumdays[month + 1] - cumdays[month] +
+   *day = cumuldays[month + 1] - cumuldays[month] +
(v1 + 1) * 7 - (v2 - *day + 7) % 7;
 #if DEBUG
fprintf(stderr, "\nMonth %d ends on weekday %d\n", month, v2);
@@ -697,7 +699,7 @@ variable_weekday(int *day, int month, in
*day = *day % 10;
 
/* which weekday the first of the month is (1-7) */
-   v2 = (cumdays[month] + 1 + day1) % 7 + 1;
+   v2 = (cumuldays[month] + 1 + day1) % 7 + 1;
 
/* and add enough days */
*day = 1 + (v1 - 1) * 7 + (*day - v2 + 7) % 7;
Index: io.c
===
RCS file: /cvs/src/usr.bin/calendar/io.c,v
retrieving revision 1.44
diff -u -p -u -p -r1.44 io.c
--- io.c31 Aug 2016 09:38:47 -  1.44
+++ io.c30 May 2017 01:11:39 -
@@ -74,6 +74,7 @@ cal(void)
 
events = NULL;
cur_evt = NULL;
+   ev1 = NULL;
if ((fp = opencal()) == NULL)
return;
for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) {



Silence a hexdump(1) warning

2017-05-29 Thread Brian Callahan
Hi tech --

Silence a -Wshadow warning found with WARNINGS=yes.

~Brian

Index: odsyntax.c
===
RCS file: /cvs/src/usr.bin/hexdump/odsyntax.c,v
retrieving revision 1.27
diff -u -p -u -p -r1.27 odsyntax.c
--- odsyntax.c  15 Mar 2016 04:19:13 -  1.27
+++ odsyntax.c  30 May 2017 00:57:15 -
@@ -403,12 +403,12 @@ odoffset(int argc, char ***argvp)
 }
 
 static void
-odadd(const char *fmt)
+odadd(const char *format)
 {
static int needpad;
 
if (needpad)
add("\""PADDING"\"");
-   add(fmt);
+   add(format);
needpad = 1;
 }



Fix vmstat(8) warnings

2017-05-29 Thread Brian Callahan
Hi tech --

Silence a pair of -Wshadow warnings caught by WARNINGS=yes.

~Brian

Index: dkstats.c
===
RCS file: /cvs/src/usr.bin/vmstat/dkstats.c,v
retrieving revision 1.39
diff -u -p -u -p -r1.39 dkstats.c
--- dkstats.c   4 Sep 2016 14:21:05 -   1.39
+++ dkstats.c   29 May 2017 21:20:26 -
@@ -201,9 +201,9 @@ dkreadstats(void)
(name = strsep(, ",")) != NULL; i++)
dk_name[i] = name;
for (i = 0; i < dk_ndrive; i++) {
-   char *p = strchr(dk_name[i], ':');
-   if (p)
-   *p = '\0';
+   char *ep = strchr(dk_name[i], ':');
+   if (ep)
+   *ep = '\0';
}
disknames = cur.dk_name[0]; /* To free old names. */
 
@@ -534,9 +534,9 @@ dkinit(int sel)
cur.dk_select[i] = sel;
}
for (i = 0; i < dk_ndrive; i++) {
-   char *p = strchr(cur.dk_name[i], ':');
-   if (p)
-   *p = '\0';
+   char *ep = strchr(cur.dk_name[i], ':');
+   if (ep)
+   *ep = '\0';
}
} else {
 #if !defined(NOKVM)



Re: Fix some ps(1) warnings

2017-05-29 Thread Brian Callahan
Hi Ingo --

On 5/29/2017 5:30 PM, Ingo Schwarze wrote:
> Hi Brian,
>
> Brian Callahan wrote on Mon, May 29, 2017 at 04:44:01PM -0400:
>
>> This diff fixes some warnings for ps(1) found with WARNINGS=yes.
>> mbwsprint() was missing a prototype in utf8.c, so add it to
>> extern.h with every other function. This lets us remove the
>> prototype from print.c
> I intentionally designed that as it is.
>
> The function mbswprint() is not intended to be called from just
> anywhere, but only from print.c.  So it should *not* be in extern.h.
>
> The file utf8.c is not intended to call just anything, but only
> to provide mbswprint().  So it should *not* include ps.h.
>
> Sure, the file utf8.c could simply be part of print.c and the function
> could be static.  But UTF-8 is such an odd beast that i deemed it
> better for it to have its own file to rear its ugly head in.
>
> Another header "utf8.h" for just one prototype seemed excessive.
>
> If people think the warning ought to be fixed, i'll simply add
> a copy of the prototype to utf8.c, like this:
>
>   int mbswprint(const char *, int, int);  /* for use by print.c */
>
> Yours,
>   Ingo

Thanks for the explanation!

~Brian

>
>> Index: extern.h
>> ===
>> RCS file: /cvs/src/bin/ps/extern.h,v
>> retrieving revision 1.20
>> diff -u -p -u -p -r1.20 extern.h
>> --- extern.h 8 Sep 2016 15:11:29 -   1.20
>> +++ extern.h 29 May 2017 19:44:43 -
>> @@ -56,6 +56,7 @@ voidlogname(const struct kinfo_proc *,
>>  void longtname(const struct kinfo_proc *, VARENT *);
>>  void lstarted(const struct kinfo_proc *, VARENT *);
>>  void maxrss(const struct kinfo_proc *, VARENT *);
>> +int  mbswprint(const char *, int, int);
>>  void nlisterr(struct nlist *);
>>  void p_rssize(const struct kinfo_proc *, VARENT *);
>>  void pagein(const struct kinfo_proc *, VARENT *);
>> Index: print.c
>> ===
>> RCS file: /cvs/src/bin/ps/print.c,v
>> retrieving revision 1.69
>> diff -u -p -u -p -r1.69 print.c
>> --- print.c  8 Sep 2016 15:11:29 -   1.69
>> +++ print.c  29 May 2017 19:44:43 -
>> @@ -55,8 +55,6 @@
>>  extern kvm_t *kd;
>>  extern int needenv, needcomm, neednlist, commandonly;
>>  
>> -int mbswprint(const char *, int, int);  /* utf8.c */
>> -
>>  static char *cmdpart(char *);
>>  
>>  #define min(a,b)((a) < (b) ? (a) : (b))
>> Index: utf8.c
>> ===
>> RCS file: /cvs/src/bin/ps/utf8.c,v
>> retrieving revision 1.1
>> diff -u -p -u -p -r1.1 utf8.c
>> --- utf8.c   10 Jan 2016 14:04:16 -  1.1
>> +++ utf8.c   29 May 2017 19:44:43 -
>> @@ -23,6 +23,8 @@
>>  #include 
>>  #include 
>>  
>> +#include "ps.h"
>> +
>>  int
>>  mbswprint(const char *mbs, int maxwidth, int trail)
>>  {



Re: Prevent NET_LOCK() vs if_get() deadlock

2017-05-29 Thread David Gwynne
i came up with what is effectively the same diff. ok by me.

> On 29 May 2017, at 20:37, Martin Pieuchot  wrote:
> 
> As explained recently, calling refcnt_finalize() for ifp references and
> sleeping while holding the NET_LOCK() creates a deadlock situation.
> 
> However we can simply fix that by not calling if_idxmap_remove() under
> the NET_LOCK().  This is safe since the KERNEL_LOCK() is what is needed
> to serialize access to ``if_map''.
> 
> ok?
> 
> Index: net/if.c
> ===
> RCS file: /cvs/src/sys/net/if.c,v
> retrieving revision 1.500
> diff -u -p -r1.500 if.c
> --- net/if.c  29 May 2017 06:08:21 -  1.500
> +++ net/if.c  29 May 2017 10:32:12 -
> @@ -1014,11 +1014,11 @@ if_detach(struct ifnet *ifp)
> 
>   ifq_clr_oactive(>if_snd);
> 
> - NET_LOCK(s);
> - s2 = splnet();
>   /* Other CPUs must not have a reference before we start destroying. */
>   if_idxmap_remove(ifp);
> 
> + NET_LOCK(s);
> + s2 = splnet();
>   ifp->if_qstart = if_detached_qstart;
>   ifp->if_ioctl = if_detached_ioctl;
>   ifp->if_watchdog = NULL;
> 



Re: tcpdump: fix some clang warnings

2017-05-29 Thread Alexander Bluhm
On Mon, May 29, 2017 at 12:13:25PM +0200, Michal Mazurek wrote:
> --- usr.sbin/tcpdump/print-bgp.c  24 Apr 2017 20:35:35 -  1.21
> +++ usr.sbin/tcpdump/print-bgp.c  29 May 2017 10:08:40 -
> @@ -356,7 +356,7 @@ decode_prefix4(const u_char *pd, char *b
>  * enough bytes of address to contain this many bits
>  */
>   plen = pd[0];
> - if (plen < 0 || 32 < plen)
> + if (32 < plen)
>   return -1;
>   memset(, 0, sizeof(addr));
>   TCHECK2(pd[1], (plen + 7) / 8);
> @@ -385,7 +385,7 @@ decode_prefix6(const u_char *pd, char *b
>  
>   TCHECK(pd[0]);
>   plen = pd[0];
> - if (plen < 0 || 128 < plen)
> + if (128 < plen)
>   return -1;
>  
>   memset(, 0, sizeof(addr));

These two are OK bluhm@

> --- usr.sbin/tcpdump/print-wb.c   16 Nov 2015 00:16:39 -  1.9
> +++ usr.sbin/tcpdump/print-wb.c   29 May 2017 10:08:40 -
> @@ -180,7 +180,7 @@ wb_id(const struct pkt_id *id, u_int len
>  
>   printf(" wb-id:");
>   len -= sizeof(*id);
> - if (len < 0 || (u_char *)(id + 1) > snapend)
> + if ((u_char *)(id + 1) > snapend)
>   return (-1);
>  
>   printf(" %u/%s:%u (max %u/%s:%u) ",

You should check len < sizeof(*id) before doing the len -= sizeof(*id).

bluhm



Re: Make clang accept and use relative filenames for tools

2017-05-29 Thread Joerg Sonnenberger
On Mon, May 29, 2017 at 06:54:52PM +0100, Stuart Henderson wrote:
> On 2017/05/29 20:26, Vadim Zhukov wrote:
> > The clang and gcc behave differently regarding executing tools.
> > While gcc simply runs what he said to, clang tries to be clever
> > and always find absolute path for a tool, refusing start otherwise.
> > 
> > The actual problem is starting a linker: ports infrastructure
> > expects tools are called by name, not by path, and thus could be
> > overriden via stuff in ${WRKDIR}/bin. This functionality is used,
> > e.g., to implement USE_WXNEEDED port option.
> > 
> > But clang calls "/usr/bin/ld", not "ld", and thus ${WRKDIR}/bin/ld
> > misses a chance to do its magic, and binaries are built without
> > OPENBSD_WXNEEDED, and some ports blow up (when compiled using clang).
> 
> One thing we _could_ do is pass -fuse-ld=${WRKDIR}/bin/ld when linking ..

Just -B ${WRKDIR}/bin should be enough and cover other tools like as as
needed.

Joerg



ip_input() in pr_input style

2017-05-29 Thread Alexander Bluhm
Hi,

Convert ip_input(), ip_our(), ip_deliver() functions to pr_input
parameter passing and protocol return style.  Reset mp to NULL in
a few places to fail at mbuf use after free.  Rename ipv4_input()
to ip_input().

Goal is to prepare the code that both mpi@'s and bluhm@'s diff
apply.

ok?

bluhm

Index: netinet/ip_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.306
diff -u -p -r1.306 ip_input.c
--- netinet/ip_input.c  28 May 2017 12:22:54 -  1.306
+++ netinet/ip_input.c  29 May 2017 21:38:51 -
@@ -126,7 +126,7 @@ int ip_sysctl_ipstat(void *, size_t *, v
 
 static struct mbuf_queue   ipsend_mq;
 
-void   ip_ours(struct mbuf *);
+intip_ours(struct mbuf **, int *, int, int);
 intip_dooptions(struct mbuf *, struct ifnet *);
 intin_ouraddr(struct mbuf *, struct ifnet *, struct rtentry **);
 
@@ -211,6 +211,7 @@ void
 ipintr(void)
 {
struct mbuf *m;
+   int off;
 
/*
 * Get next datagram off input queue and get IP header
@@ -221,7 +222,8 @@ ipintr(void)
if ((m->m_flags & M_PKTHDR) == 0)
panic("ipintr no HDR");
 #endif
-   ipv4_input(m);
+   off = 0;
+   ip_input(, , IPPROTO_IPV4, AF_UNSPEC);
}
 }
 
@@ -230,39 +232,42 @@ ipintr(void)
  *
  * Checksum and byte swap header.  Process options. Forward or deliver.
  */
-void
-ipv4_input(struct mbuf *m)
+int
+ip_input(struct mbuf **mp, int *offp, int nxt, int af)
 {
+   struct mbuf *m = *mp;
struct ifnet*ifp;
struct rtentry  *rt = NULL;
struct ip   *ip;
int hlen, len;
in_addr_t pfrdr = 0;
 
+   KASSERT(*offp == 0);
+
ifp = if_get(m->m_pkthdr.ph_ifidx);
if (ifp == NULL)
-   goto bad;
+   goto done;
 
ipstat_inc(ips_total);
if (m->m_len < sizeof (struct ip) &&
-   (m = m_pullup(m, sizeof (struct ip))) == NULL) {
+   (m = *mp = m_pullup(m, sizeof (struct ip))) == NULL) {
ipstat_inc(ips_toosmall);
-   goto out;
+   goto done;
}
ip = mtod(m, struct ip *);
if (ip->ip_v != IPVERSION) {
ipstat_inc(ips_badvers);
-   goto bad;
+   goto done;
}
hlen = ip->ip_hl << 2;
if (hlen < sizeof(struct ip)) { /* minimum header length */
ipstat_inc(ips_badhlen);
-   goto bad;
+   goto done;
}
if (hlen > m->m_len) {
-   if ((m = m_pullup(m, hlen)) == NULL) {
+   if ((m = *mp = m_pullup(m, hlen)) == NULL) {
ipstat_inc(ips_badhlen);
-   goto out;
+   goto done;
}
ip = mtod(m, struct ip *);
}
@@ -272,20 +277,20 @@ ipv4_input(struct mbuf *m)
(ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) {
if ((ifp->if_flags & IFF_LOOPBACK) == 0) {
ipstat_inc(ips_badaddr);
-   goto bad;
+   goto done;
}
}
 
if ((m->m_pkthdr.csum_flags & M_IPV4_CSUM_IN_OK) == 0) {
if (m->m_pkthdr.csum_flags & M_IPV4_CSUM_IN_BAD) {
ipstat_inc(ips_badsum);
-   goto bad;
+   goto done;
}
 
ipstat_inc(ips_inswcsum);
if (in_cksum(m, hlen) != 0) {
ipstat_inc(ips_badsum);
-   goto bad;
+   goto done;
}
}
 
@@ -297,7 +302,7 @@ ipv4_input(struct mbuf *m)
 */
if (len < hlen) {
ipstat_inc(ips_badlen);
-   goto bad;
+   goto done;
}
 
/*
@@ -308,7 +313,7 @@ ipv4_input(struct mbuf *m)
 */
if (m->m_pkthdr.len < len) {
ipstat_inc(ips_tooshort);
-   goto bad;
+   goto done;
}
if (m->m_pkthdr.len > len) {
if (m->m_len == m->m_pkthdr.len) {
@@ -321,7 +326,7 @@ ipv4_input(struct mbuf *m)
 #if NCARP > 0
if (ifp->if_type == IFT_CARP && ip->ip_p != IPPROTO_ICMP &&
carp_lsdrop(m, AF_INET, >ip_src.s_addr, >ip_dst.s_addr))
-   goto bad;
+   goto done;
 #endif
 
 #if NPF > 0
@@ -329,10 +334,11 @@ ipv4_input(struct mbuf *m)
 * Packet filter
 */
pfrdr = ip->ip_dst.s_addr;
-   if (pf_test(AF_INET, PF_IN, ifp, ) != PF_PASS)
-   goto bad;
+   if (pf_test(AF_INET, PF_IN, ifp, mp) != PF_PASS)
+   goto done;
+   m = *mp;
if (m == NULL)
-   goto out;
+   goto done;
 
ip = mtod(m, struct ip *);
hlen = ip->ip_hl << 2;
@@ 

fortune(6): use proper bool types

2017-05-29 Thread Frederic Cambus
Hi tech@,

Here is a diff to use proper bool types for fortune(6).

Comments? OK?

Index: games/fortune/fortune/fortune.c
===
RCS file: /cvs/src/games/fortune/fortune/fortune.c,v
retrieving revision 1.55
diff -u -p -r1.55 fortune.c
--- games/fortune/fortune/fortune.c 7 Mar 2016 22:49:45 -   1.55
+++ games/fortune/fortune/fortune.c 29 May 2017 21:40:40 -
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -49,8 +50,6 @@
 
 #include "pathnames.h"
 #include "strfile.h"
-
-#defineboolshort
 
 #defineMINW6   /* minimum wait if desired */
 #defineCPERS   20  /* # of chars for each sec */
Index: games/fortune/strfile/strfile.c
===
RCS file: /cvs/src/games/fortune/strfile/strfile.c,v
retrieving revision 1.28
diff -u -p -r1.28 strfile.c
--- games/fortune/strfile/strfile.c 7 Mar 2016 12:07:56 -   1.28
+++ games/fortune/strfile/strfile.c 29 May 2017 21:40:40 -
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -66,9 +67,6 @@
  * Added ordering options.
  */
 
-#defineTRUE1
-#defineFALSE   0
-
 #defineSTORING_PTRS(Oflag || Rflag)
 #defineCHUNKSIZE   512
 
@@ -92,11 +90,11 @@ char*Infile = NULL, /* input file 
nam
Outfile[PATH_MAX] = "", /* output file name */
Delimch = '%';  /* delimiting character */
 
-intSflag   = FALSE;/* silent run flag */
-intOflag   = FALSE;/* ordering flag */
-intIflag   = FALSE;/* ignore case flag */
-intRflag   = FALSE;/* randomize order flag */
-intXflag   = FALSE;/* set rotated bit */
+intSflag   = false;/* silent run flag */
+intOflag   = false;/* ordering flag */
+intIflag   = false;/* ignore case flag */
+intRflag   = false;/* randomize order flag */
+intXflag   = false;/* set rotated bit */
 long   Num_pts = 0;/* number of pointers/strings */
 
 int32_t*Seekpts;
@@ -189,7 +187,7 @@ main(int ac, char *av[])
else
fp->first = *nsp;
fp->pos = Seekpts[Num_pts - 1];
-   first = FALSE;
+   first = false;
}
} while (sp != NULL);
 
@@ -394,8 +392,8 @@ cmp_str(const void *p1, const void *p2)
(void) fseek(Sort_1, ((STR *)p1)->pos, SEEK_SET);
(void) fseek(Sort_2, ((STR *)p2)->pos, SEEK_SET);
 
-   n1 = FALSE;
-   n2 = FALSE;
+   n1 = false;
+   n2 = false;
while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0')
SET_N(n1, c1);
while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0')



Re: Fix some ps(1) warnings

2017-05-29 Thread Ingo Schwarze
Hi Brian,

Brian Callahan wrote on Mon, May 29, 2017 at 04:44:01PM -0400:

> This diff fixes some warnings for ps(1) found with WARNINGS=yes.
> mbwsprint() was missing a prototype in utf8.c, so add it to
> extern.h with every other function. This lets us remove the
> prototype from print.c

I intentionally designed that as it is.

The function mbswprint() is not intended to be called from just
anywhere, but only from print.c.  So it should *not* be in extern.h.

The file utf8.c is not intended to call just anything, but only
to provide mbswprint().  So it should *not* include ps.h.

Sure, the file utf8.c could simply be part of print.c and the function
could be static.  But UTF-8 is such an odd beast that i deemed it
better for it to have its own file to rear its ugly head in.

Another header "utf8.h" for just one prototype seemed excessive.

If people think the warning ought to be fixed, i'll simply add
a copy of the prototype to utf8.c, like this:

  int mbswprint(const char *, int, int);  /* for use by print.c */

Yours,
  Ingo


> Index: extern.h
> ===
> RCS file: /cvs/src/bin/ps/extern.h,v
> retrieving revision 1.20
> diff -u -p -u -p -r1.20 extern.h
> --- extern.h  8 Sep 2016 15:11:29 -   1.20
> +++ extern.h  29 May 2017 19:44:43 -
> @@ -56,6 +56,7 @@ void logname(const struct kinfo_proc *,
>  void  longtname(const struct kinfo_proc *, VARENT *);
>  void  lstarted(const struct kinfo_proc *, VARENT *);
>  void  maxrss(const struct kinfo_proc *, VARENT *);
> +int   mbswprint(const char *, int, int);
>  void  nlisterr(struct nlist *);
>  void  p_rssize(const struct kinfo_proc *, VARENT *);
>  void  pagein(const struct kinfo_proc *, VARENT *);
> Index: print.c
> ===
> RCS file: /cvs/src/bin/ps/print.c,v
> retrieving revision 1.69
> diff -u -p -u -p -r1.69 print.c
> --- print.c   8 Sep 2016 15:11:29 -   1.69
> +++ print.c   29 May 2017 19:44:43 -
> @@ -55,8 +55,6 @@
>  extern kvm_t *kd;
>  extern int needenv, needcomm, neednlist, commandonly;
>  
> -int mbswprint(const char *, int, int);  /* utf8.c */
> -
>  static char *cmdpart(char *);
>  
>  #define  min(a,b)((a) < (b) ? (a) : (b))
> Index: utf8.c
> ===
> RCS file: /cvs/src/bin/ps/utf8.c,v
> retrieving revision 1.1
> diff -u -p -u -p -r1.1 utf8.c
> --- utf8.c10 Jan 2016 14:04:16 -  1.1
> +++ utf8.c29 May 2017 19:44:43 -
> @@ -23,6 +23,8 @@
>  #include 
>  #include 
>  
> +#include "ps.h"
> +
>  int
>  mbswprint(const char *mbs, int maxwidth, int trail)
>  {



pcdisplay(4): remove unused pcdisplay_mapchar_simple function

2017-05-29 Thread Frederic Cambus
Hi tech@,

Here is a diff to remove the unused pcdisplay_mapchar_simple function
in pcdisplay(4).

It has been unused since this code was imported from NetBSD.

Comments? OK?

Index: sys/dev/ic/pcdisplay_subr.c
===
RCS file: /cvs/src/sys/dev/ic/pcdisplay_subr.c,v
retrieving revision 1.11
diff -u -p -r1.11 pcdisplay_subr.c
--- sys/dev/ic/pcdisplay_subr.c 11 Apr 2011 19:11:01 -  1.11
+++ sys/dev/ic/pcdisplay_subr.c 29 May 2017 20:56:31 -
@@ -144,17 +144,6 @@ done:
 #endif /* PCDISPLAY_SOFTCURSOR */
 }
 
-#if 0
-unsigned int
-pcdisplay_mapchar_simple(void *id, int uni)
-{
-   if (uni < 128)
-   return (uni);
-
-   return (1); /* XXX ??? smiley */
-}
-#endif
-
 int
 pcdisplay_putchar(void *id, int row, int col, u_int c, long attr)
 {
Index: sys/dev/ic/pcdisplayvar.h
===
RCS file: /cvs/src/sys/dev/ic/pcdisplayvar.h,v
retrieving revision 1.11
diff -u -p -r1.11 pcdisplayvar.h
--- sys/dev/ic/pcdisplayvar.h   28 Aug 2010 12:48:14 -  1.11
+++ sys/dev/ic/pcdisplayvar.h   29 May 2017 20:56:31 -
@@ -76,9 +76,6 @@ _pcdisplay_6845_write(struct pcdisplay_h
 void   pcdisplay_cursor_init(struct pcdisplayscreen *, int);
 void   pcdisplay_cursor_reset(struct pcdisplayscreen *);
 intpcdisplay_cursor(void *, int, int, int);
-#if 0
-unsigned int pcdisplay_mapchar_simple(void *, int);
-#endif
 intpcdisplay_mapchar(void *, int, unsigned int *);
 intpcdisplay_putchar(void *, int, int, u_int, long);
 struct wsdisplay_charcell;



Fix some w(1) warnings, remove bin/ps/fmt.c

2017-05-29 Thread Brian Callahan
Hi tech --

While building w(1) with WARNINGS=yes, clang complained that there
were missing prototypes for the functions fmt_putc and fmt_puts.
w(1) is doing a reacharound to ps(1) for these functions. And
while putting the prototypes in bin/ps/extern.h silenced the
warnings, that seemed strange.

A grep of the tree shows that the only place these two functions
are used is in usr.bin/w/w.c so I put them in there and made them
static. This lets us finally remove bin/ps/fmt.c since ps(1) was
upgraded by Ingo to be utf8.

~Brian

Index: bin/ps/fmt.c
===
RCS file: bin/ps/fmt.c
diff -N bin/ps/fmt.c
--- bin/ps/fmt.c10 Jan 2016 21:08:01 -  1.15
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,82 +0,0 @@
-/* $OpenBSD: fmt.c,v 1.15 2016/01/10 21:08:01 schwarze Exp $   */
-
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *may be used to endorse or promote products derived from this software
- *without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include "ps.h"
-
-void
-fmt_puts(const char *s, int *leftp)
-{
-   static char *v = NULL;
-   static size_t maxlen = 0;
-   size_t len;
-
-   if (*leftp == 0)
-   return;
-   len = strlen(s) * 4 + 1;
-   if (len > maxlen) {
-   free(v);
-   maxlen = 0;
-   if (len < getpagesize())
-   len = getpagesize();
-   v = malloc(len);
-   if (v == NULL)
-   return;
-   maxlen = len;
-   }
-   strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE);
-   if (*leftp != -1) {
-   len = strlen(v);
-   if (len > *leftp) {
-   v[*leftp] = '\0';
-   *leftp = 0;
-   } else
-   *leftp -= len;
-   }
-   printf("%s", v);
-}
-
-void
-fmt_putc(int c, int *leftp)
-{
-
-   if (*leftp == 0)
-   return;
-   if (*leftp != -1)
-   *leftp -= 1;
-   putchar(c);
-}
Index: usr.bin/w/Makefile
===
RCS file: /cvs/src/usr.bin/w/Makefile,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 Makefile
--- usr.bin/w/Makefile  16 Jul 2014 20:06:27 -  1.7
+++ usr.bin/w/Makefile  29 May 2017 20:33:35 -
@@ -1,12 +1,10 @@
 #  $OpenBSD: Makefile,v 1.7 2014/07/16 20:06:27 okan Exp $
 
 PROG=  w
-SRCS=  fmt.c pr_time.c proc_compare.c w.c
+SRCS=  pr_time.c proc_compare.c w.c
 MAN=   w.1 uptime.1
 DPADD= ${LIBKVM}
 LDADD= -lkvm
 LINKS= ${BINDIR}/w ${BINDIR}/uptime
-
-.PATH: ${.CURDIR}/../../bin/ps
 
 .include 
Index: usr.bin/w/extern.h
===
RCS file: /cvs/src/usr.bin/w/extern.h,v
retrieving revision 1.9
diff -u -p -u -p -r1.9 extern.h
--- usr.bin/w/extern.h  15 Mar 2015 00:41:28 -  1.9
+++ usr.bin/w/extern.h  29 May 2017 20:33:35 -
@@ -32,8 +32,6 @@
  */
 
 struct kinfo_proc;
-void   fmt_puts(const char *, int *);
-void   fmt_putc(int, int *);
 void   pr_attime(time_t *, time_t *);
 void   pr_idle(time_t);
 intproc_compare(const struct kinfo_proc *, const struct kinfo_proc *);
Index: usr.bin/w/w.c
===
RCS file: /cvs/src/usr.bin/w/w.c,v
retrieving revision 1.61
diff -u -p -u -p -r1.61 w.c
--- usr.bin/w/w.c   19 Mar 2016 00:11:49 

Fix some ps(1) warnings

2017-05-29 Thread Brian Callahan
Hi tech --

This diff fixes some warnings for ps(1) found with WARNINGS=yes.
mbwsprint() was missing a prototype in utf8.c, so add it to
extern.h with every other function. This lets us remove the
prototype from print.c

~Brian

Index: extern.h
===
RCS file: /cvs/src/bin/ps/extern.h,v
retrieving revision 1.20
diff -u -p -u -p -r1.20 extern.h
--- extern.h8 Sep 2016 15:11:29 -   1.20
+++ extern.h29 May 2017 19:44:43 -
@@ -56,6 +56,7 @@ void   logname(const struct kinfo_proc *,
 voidlongtname(const struct kinfo_proc *, VARENT *);
 voidlstarted(const struct kinfo_proc *, VARENT *);
 voidmaxrss(const struct kinfo_proc *, VARENT *);
+int mbswprint(const char *, int, int);
 voidnlisterr(struct nlist *);
 voidp_rssize(const struct kinfo_proc *, VARENT *);
 voidpagein(const struct kinfo_proc *, VARENT *);
Index: print.c
===
RCS file: /cvs/src/bin/ps/print.c,v
retrieving revision 1.69
diff -u -p -u -p -r1.69 print.c
--- print.c 8 Sep 2016 15:11:29 -   1.69
+++ print.c 29 May 2017 19:44:43 -
@@ -55,8 +55,6 @@
 extern kvm_t *kd;
 extern int needenv, needcomm, neednlist, commandonly;
 
-int mbswprint(const char *, int, int);  /* utf8.c */
-
 static char *cmdpart(char *);
 
 #definemin(a,b)((a) < (b) ? (a) : (b))
Index: utf8.c
===
RCS file: /cvs/src/bin/ps/utf8.c,v
retrieving revision 1.1
diff -u -p -u -p -r1.1 utf8.c
--- utf8.c  10 Jan 2016 14:04:16 -  1.1
+++ utf8.c  29 May 2017 19:44:43 -
@@ -23,6 +23,8 @@
 #include 
 #include 
 
+#include "ps.h"
+
 int
 mbswprint(const char *mbs, int maxwidth, int trail)
 {



Makefile.cross tweaks

2017-05-29 Thread Miod Vallat
The following diff attempts to cross-build more things, in particular
gnu/lib (except for libiberty). It also passes the proper optimization
flags so that libstdc++-v3 gets built with optimization.

Index: Makefile.cross
===
RCS file: /OpenBSD/src/Makefile.cross,v
retrieving revision 1.94
diff -u -p -r1.94 Makefile.cross
--- Makefile.cross  23 May 2017 14:57:30 -  1.94
+++ Makefile.cross  29 May 2017 20:15:01 -
@@ -43,8 +43,9 @@ MACHINE_IS_LP64 =
 
 #CROSSCPPFLAGS?=   -nostdinc -I${CROSSDIR}/usr/include
 #CROSSLDFLAGS?=-nostdlib -L${CROSSDIR}/usr/lib -static
+DEBUG?=-g
 CROSSCFLAGS?=  ${CROSSCPPFLAGS} -O2 ${PIPE} ${DEBUG}
-CROSSCXXFLAGS?=${CROSSCPPFLAGS}
+CROSSCXXFLAGS?=${CROSSCPPFLAGS} -O2 ${PIPE} ${DEBUG}
 #LDSTATIC?=-static
 
 CROSSDIR=  ${DESTDIR}/usr/cross/${TARGET}
@@ -75,7 +76,7 @@ CROSSOBJ= ${CROSSDIR}/.obj_done
 CROSSINCLUDES= ${CROSSDIR}/.includes_done
 CROSSBINUTILS= ${CROSSDIR}/.binutils_done
 CROSSGCC=  ${CROSSDIR}/.gcc_done
-#NO_CROSS= isakmpd keynote ssh
+NO_CROSS=  libiberty
 
 .include 
 
@@ -307,6 +308,7 @@ ${CROSSGCC}:${CROSSBINUTILS}
cp -f ${CROSSDIR}/usr/libexec/cpp 
${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-libexeccpp
cp -f ${CROSSDIR}/usr/bin/gcc 
${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc
ln -sf ${TARGET_CANON}-cc ${CROSSDIR}/usr/${TARGET_CANON}/bin/cc
+   ln -sf ${TARGET_CANON}-c++ ${CROSSDIR}/usr/${TARGET_CANON}/bin/c++
 
cp -f ${CROSSDIR}/usr/bin/gcc 
${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc
rm -f ${CROSSDIR}/usr/bin/gcc  ${CROSSDIR}/usr/bin/g++  
${CROSSDIR}/usr/bin/cc ${CROSSDIR}/usr/libexec/cpp 
@@ -343,6 +345,13 @@ cross-lib: ${CROSSGCC}
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} 
DESTDIR=${CROSSDIR} \
SKIPDIR=\"${NO_CROSS}\" \
${MAKE} install)
+   (cd ${.CURDIR}/gnu/lib; \
+   eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
+   SKIPDIR=\"${NO_CROSS}\" \
+   ${MAKE} depend all ; \
+   eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} 
DESTDIR=${CROSSDIR} \
+   SKIPDIR=\"${NO_CROSS}\" \
+   ${MAKE} install)
 
 cross-bin: ${CROSSOBJ}
MACHINE=${TARGET} \
@@ -351,10 +360,10 @@ cross-bin:${CROSSOBJ}
for i in libexec bin sbin usr.bin usr.sbin; do \
(cd ${.CURDIR}/$$i; \
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
-   SKIPDIR=\"${BINUTILS} ${NO_CROSS}\" \
+   SKIPDIR=\"${NO_CROSS}\" \
${MAKE} depend all ; \
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} 
DESTDIR=${CROSSDIR} \
-   SKIPDIR=\"${BINUTILS} ${NO_CROSS}\" \
+   SKIPDIR=\"${NO_CROSS}\" \
${MAKE} install); \
done
 
@@ -362,7 +371,7 @@ cross-gnu:  ${CROSSOBJ}
MACHINE=${TARGET} \
MACHINE_ARCH=${TARGET_ARCH} MACHINE_CPU=${TARGET_CPU}; \
export MACHINE MACHINE_ARCH MACHINE_CPU; \
-   for i in gnu/lib gnu/usr.sbin gnu/usr.bin ; do \
+   for i in gnu/usr.sbin gnu/usr.bin ; do \
(cd ${.CURDIR}/$$i; \
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
SKIPDIR=\"${NO_CROSS}\" \



Use LIST in PF_KEY

2017-05-29 Thread Claudio Jeker
Use LIST macros in PF_KEY code instead of the hand rolled one.
Seems to work for me.

-- 
:wq Claudio

Index: net/pfkeyv2.c
===
RCS file: /cvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.159
diff -u -p -r1.159 pfkeyv2.c
--- net/pfkeyv2.c   29 May 2017 14:28:01 -  1.159
+++ net/pfkeyv2.c   29 May 2017 14:44:42 -
@@ -96,11 +96,6 @@
 #include 
 #endif
 
-/* Static globals */
-static struct pfkeyv2_socket *pfkeyv2_sockets = NULL;
-static uint32_t pfkeyv2_seq = 1;
-static int nregistered = 0;
-static int npromisc = 0;
 
 static const struct sadb_alg ealgs[] = {
{ SADB_EALG_NULL, 0, 0, 0 },
@@ -137,7 +132,7 @@ struct sockaddr pfkey_addr = { 2, PF_KEY
 struct domain pfkeydomain;
 
 struct pfkeyv2_socket {
-   struct pfkeyv2_socket *next;
+   LIST_ENTRY(pfkeyv2_socket)  kcb_list;
struct socket *socket;
int flags;
uint32_t pid;
@@ -150,6 +145,13 @@ struct dump_state {
struct socket *socket;
 };
 
+/* Static globals */
+static LIST_HEAD(, pfkeyv2_socket) pfkeyv2_sockets =
+LIST_HEAD_INITIALIZER(pfkeyv2_sockets);
+static uint32_t pfkeyv2_seq = 1;
+static int nregistered = 0;
+static int npromisc = 0;
+
 void pfkey_init(void);
 
 int pfkeyv2_attach(struct socket *, int);
@@ -230,7 +232,7 @@ pfkeyv2_attach(struct socket *so, int pr
M_PFKEY, M_NOWAIT | M_ZERO)))
return (ENOMEM);
 
-   pfkeyv2_socket->next = pfkeyv2_sockets;
+   LIST_INSERT_HEAD(_sockets, pfkeyv2_socket, kcb_list);
pfkeyv2_socket->socket = so;
pfkeyv2_socket->pid = curproc->p_p->ps_pid;
 
@@ -240,8 +242,6 @@ pfkeyv2_attach(struct socket *so, int pr
 */
pfkeyv2_socket->rdomain = rtable_l2(curproc->p_p->ps_rtableid);
 
-   pfkeyv2_sockets = pfkeyv2_socket;
-
so->so_options |= SO_USELOOPBACK;
soisconnected(so);
 
@@ -257,26 +257,23 @@ ret:
 int
 pfkeyv2_detach(struct socket *socket, struct proc *p)
 {
-   struct pfkeyv2_socket **pp;
+   struct pfkeyv2_socket *pp;
int error;
 
-   for (pp = _sockets; *pp && ((*pp)->socket != socket);
-   pp = &((*pp)->next))
-   /*EMPTY*/;
-
-   if (*pp) {
-   struct pfkeyv2_socket *pfkeyv2_socket;
+   LIST_FOREACH(pp, _sockets, kcb_list)
+   if (pp->socket == socket)
+   break;
 
-   pfkeyv2_socket = *pp;
-   *pp = (*pp)->next;
+   if (pp) {
+   LIST_REMOVE(pp, kcb_list);
 
-   if (pfkeyv2_socket->flags & PFKEYV2_SOCKETFLAGS_REGISTERED)
+   if (pp->flags & PFKEYV2_SOCKETFLAGS_REGISTERED)
nregistered--;
 
-   if (pfkeyv2_socket->flags & PFKEYV2_SOCKETFLAGS_PROMISC)
+   if (pp->flags & PFKEYV2_SOCKETFLAGS_PROMISC)
npromisc--;
 
-   free(pfkeyv2_socket, M_PFKEY, 0);
+   free(pp, M_PFKEY, 0);
}
 
error = raw_usrreq(socket, PRU_DETACH, NULL, NULL, NULL, p);
@@ -427,12 +424,12 @@ pfkeyv2_sendmessage(void **headers, int 
 * Search for promiscuous listeners, skipping the
 * original destination.
 */
-   for (s = pfkeyv2_sockets; s; s = s->next)
+   LIST_FOREACH(s, _sockets, kcb_list) {
if ((s->flags & PFKEYV2_SOCKETFLAGS_PROMISC) &&
(s->socket != socket) &&
(s->rdomain == rdomain))
pfkey_sendup(s->socket, packet, 1);
-
+   }
m_freem(packet);
break;
 
@@ -441,7 +438,7 @@ pfkeyv2_sendmessage(void **headers, int 
 * Send the message to all registered sockets that match
 * the specified satype (e.g., all IPSEC-ESP negotiators)
 */
-   for (s = pfkeyv2_sockets; s; s = s->next)
+   LIST_FOREACH(s, _sockets, kcb_list) {
if ((s->flags & PFKEYV2_SOCKETFLAGS_REGISTERED) &&
(s->rdomain == rdomain)) {
if (!satype)/* Just send to everyone 
registered */
@@ -452,7 +449,7 @@ pfkeyv2_sendmessage(void **headers, int 
pfkey_sendup(s->socket, packet, 
1);
}
}
-
+   }
/* Free last/original copy of the packet */
m_freem(packet);
 
@@ -471,18 +468,18 @@ pfkeyv2_sendmessage(void **headers, int 
goto ret;
 
/* Send to all registered promiscuous listeners */
-   for (s = pfkeyv2_sockets; s; s = s->next)
+   LIST_FOREACH(s, _sockets, kcb_list) {
if ((s->flags & PFKEYV2_SOCKETFLAGS_PROMISC) &&
!(s->flags & 

Re: ksh(1): vi mode UTF-8 bug

2017-05-29 Thread Theo de Raadt
> Sure, you can rewrite the complete shell to use wchar_t * rather
> than char *, and if you do that, you can use the new code to handle
> ASCII as well, no need to have two copies.  But that would be a
> huge effort, even more error-prone than the small, careful adjustments
> we are doing now, and would have a number of additional downsides;
> among others, losing the ability to handle arbitrary bytes, while
> in UTF-8 mode.

yes, that's the situation.

Code which only uses "char" is less error prone, since there is no
smaller C type.  As a result a whole class of errors occur less often.
Move to a multi-char or larger integer type, and down-conversion
errors silently and subtly show up, causing damage.  It could be managed.
It isn't easy.



Fix some mg(1) warnings

2017-05-29 Thread Brian Callahan
Hi tech --

This diff cleans up some warnings found with WARNINGS=yes and
compiling with both cc and clang. I ignored the -Wsign-compare
and -Wmissing-prototypes warnings.

~Brian

Index: dir.c
===
RCS file: /cvs/src/usr.bin/mg/dir.c,v
retrieving revision 1.29
diff -u -p -u -p -r1.29 dir.c
--- dir.c   12 Sep 2016 18:32:54 -  1.29
+++ dir.c   29 May 2017 19:08:39 -
@@ -117,7 +117,7 @@ do_makedir(char *path)
 {
struct stat  sb;
int  finished, ishere;
-   mode_t   dir_mode, mode, oumask;
+   mode_t   dir_mode, f_mode, oumask;
char*slash;
 
if ((path = adjustname(path, TRUE)) == NULL)
@@ -131,8 +131,8 @@ do_makedir(char *path)
slash = path;
 
oumask = umask(0);
-   mode = 0777 & ~oumask;
-   dir_mode = mode | S_IWUSR | S_IXUSR;
+   f_mode = 0777 & ~oumask;
+   dir_mode = f_mode | S_IWUSR | S_IXUSR;
 
for (;;) {
slash += strspn(slash, "/");
@@ -152,8 +152,8 @@ do_makedir(char *path)
continue;
}
 
-   if (mkdir(path, finished ? mode : dir_mode) == 0) {
-   if (mode > 0777 && chmod(path, mode) < 0) {
+   if (mkdir(path, finished ? f_mode : dir_mode) == 0) {
+   if (f_mode > 0777 && chmod(path, f_mode) < 0) {
umask(oumask);
return (ABORT);
}
Index: fileio.c
===
RCS file: /cvs/src/usr.bin/mg/fileio.c,v
retrieving revision 1.103
diff -u -p -u -p -r1.103 fileio.c
--- fileio.c28 Jul 2016 21:40:25 -  1.103
+++ fileio.c29 May 2017 19:08:39 -
@@ -215,6 +215,7 @@ int
 fbackupfile(const char *fn)
 {
struct stat  sb;
+   struct timespec  new_times[2];
int  from, to, serrno;
ssize_t  nread;
char buf[BUFSIZ];
@@ -268,7 +269,6 @@ fbackupfile(const char *fn)
(void) fchmod(to, (sb.st_mode & 0777));
 
/* copy the mtime to the backupfile */
-   struct timespec new_times[2];
new_times[0] = sb.st_atim;
new_times[1] = sb.st_mtim;
futimens(to, new_times);
Index: modes.c
===
RCS file: /cvs/src/usr.bin/mg/modes.c,v
retrieving revision 1.20
diff -u -p -u -p -r1.20 modes.c
--- modes.c 19 Mar 2015 21:22:15 -  1.20
+++ modes.c 29 May 2017 19:08:39 -
@@ -23,14 +23,14 @@ struct maps_s   *defb_modes[PBMODES] = { &
 int defb_flag = 0;
 
 int
-changemode(int f, int n, char *mode)
+changemode(int f, int n, char *newmode)
 {
int  i;
struct maps_s   *m;
 
-   if ((m = name_mode(mode)) == NULL) {
+   if ((m = name_mode(newmode)) == NULL) {
dobeep();
-   ewprintf("Can't find mode %s", mode);
+   ewprintf("Can't find mode %s", newmode);
return (FALSE);
}
if (!(f & FFARG)) {
Index: re_search.c
===
RCS file: /cvs/src/usr.bin/mg/re_search.c,v
retrieving revision 1.31
diff -u -p -u -p -r1.31 re_search.c
--- re_search.c 19 Mar 2015 21:22:15 -  1.31
+++ re_search.c 29 May 2017 19:08:40 -
@@ -420,17 +420,17 @@ re_backsrch(void)
  * some do-it-yourself control expansion.
  */
 static int
-re_readpattern(char *prompt)
+re_readpattern(char *re_prompt)
 {
static int  dofree = 0;
int flags, error, s;
chartpat[NPAT], *rep;
 
if (re_pat[0] == '\0')
-   rep = eread("%s: ", tpat, NPAT, EFNEW | EFCR, prompt);
+   rep = eread("%s: ", tpat, NPAT, EFNEW | EFCR, re_prompt);
else
rep = eread("%s: (default %s) ", tpat, NPAT,
-   EFNUL | EFNEW | EFCR, prompt, re_pat);
+   EFNUL | EFNEW | EFCR, re_prompt, re_pat);
if (rep == NULL)
return (ABORT);
if (rep[0] != '\0') {
Index: search.c
===
RCS file: /cvs/src/usr.bin/mg/search.c,v
retrieving revision 1.44
diff -u -p -u -p -r1.44 search.c
--- search.c19 Mar 2015 21:22:15 -  1.44
+++ search.c29 May 2017 19:08:40 -
@@ -542,16 +542,16 @@ is_prompt(int dir, int flag, int success
 }
 
 /*
- * Prompt writing routine for the incremental search.  The "prompt" is just
+ * Prompt writing routine for the incremental search.  The "i_prompt" is just
  * a string. The "flag" determines whether pat should be printed.
  */
 static void
-is_dspl(char *prompt, int flag)
+is_dspl(char *i_prompt, int flag)
 {
if (flag != FALSE)
-   ewprintf("%s: ", prompt);
+   ewprintf("%s: ", i_prompt);

Re: Make clang accept and use relative filenames for tools

2017-05-29 Thread Vadim Zhukov
2017-05-29 21:14 GMT+03:00 Mark Kettenis :
>> From: Vadim Zhukov 
>> Date: Mon, 29 May 2017 20:29:20 +0300
>>
>> 2017-05-29 20:26 GMT+03:00 Vadim Zhukov :
>> > The clang and gcc behave differently regarding executing tools.
>> > While gcc simply runs what he said to, clang tries to be clever
>> > and always find absolute path for a tool, refusing start otherwise.
>> >
>> > The actual problem is starting a linker: ports infrastructure
>> > expects tools are called by name, not by path, and thus could be
>> > overriden via stuff in ${WRKDIR}/bin. This functionality is used,
>> > e.g., to implement USE_WXNEEDED port option.
>> >
>> > But clang calls "/usr/bin/ld", not "ld", and thus ${WRKDIR}/bin/ld
>> > misses a chance to do its magic, and binaries are built without
>> > OPENBSD_WXNEEDED, and some ports blow up (when compiled using clang).
>> >
>> > The patch below is enough to make clang accept and use non-absolute
>> > tool file names and make lang/mono and lang/libv8 happy (more likely
>> > to follow, there is much work to be done).
>> >
>> > So I'm asking compiler gurus and base maintainers, if a patch like
>> > that would be acceptable? And if yes, how do you want it look like
>> > to make supporting it easier?
>> >
>> > Thank you in advance.
>>
>> P.S.: The Program.inc file is not picked up as dependency, so you'll
>> need to touch gnu/llvm/lib/Support/Program.cpp manually before
>> building clang.
>
> I'm not in favour of this approach.  I'm pretty sure it'll break the
> cross-compilation toolchain.  And it makes us deviate from how clang
> behaves on other platforms quite a bit.

OK, understood, thank you.

--
  WBR,
  Vadim Zhukov



Re: Make clang accept and use relative filenames for tools

2017-05-29 Thread Vadim Zhukov
2017-05-29 20:54 GMT+03:00 Stuart Henderson :
> On 2017/05/29 20:26, Vadim Zhukov wrote:
>> The clang and gcc behave differently regarding executing tools.
>> While gcc simply runs what he said to, clang tries to be clever
>> and always find absolute path for a tool, refusing start otherwise.
>>
>> The actual problem is starting a linker: ports infrastructure
>> expects tools are called by name, not by path, and thus could be
>> overriden via stuff in ${WRKDIR}/bin. This functionality is used,
>> e.g., to implement USE_WXNEEDED port option.
>>
>> But clang calls "/usr/bin/ld", not "ld", and thus ${WRKDIR}/bin/ld
>> misses a chance to do its magic, and binaries are built without
>> OPENBSD_WXNEEDED, and some ports blow up (when compiled using clang).
>
> One thing we _could_ do is pass -fuse-ld=${WRKDIR}/bin/ld when linking ..

This requires: 1) linker not being called directly; 2) LDFLAGS being
passed. I'm not sure if all 50 (or so) USE_WXNEEDED ports behave like
this. The reason we have USE_WXNEEDED implemented the current way was
to catch such situations, IIUC

 Yes, we could tweak ${WRKDIR}/bin/{cc,cxx} to force always passing
-fuse-ld=${WRKDIR}/bin/ld. That'll require combining gcc4.port.mk and
clang.port.mk, though; otherwise they'll become unmaintaineable,
because they already have to respect USE_CCACHE. Maybe we'll have a
${PORTSDIR}/mk/compiler.mk that's called from modules.port.mk and
implements all the logic we want from different compilers... Until
that the dirty hacks in mono, libv8 and whatever else will stay.

--
  WBR,
  Vadim Zhukov



Re: Make clang accept and use relative filenames for tools

2017-05-29 Thread Mark Kettenis
> From: Vadim Zhukov 
> Date: Mon, 29 May 2017 20:29:20 +0300
> 
> 2017-05-29 20:26 GMT+03:00 Vadim Zhukov :
> > The clang and gcc behave differently regarding executing tools.
> > While gcc simply runs what he said to, clang tries to be clever
> > and always find absolute path for a tool, refusing start otherwise.
> >
> > The actual problem is starting a linker: ports infrastructure
> > expects tools are called by name, not by path, and thus could be
> > overriden via stuff in ${WRKDIR}/bin. This functionality is used,
> > e.g., to implement USE_WXNEEDED port option.
> >
> > But clang calls "/usr/bin/ld", not "ld", and thus ${WRKDIR}/bin/ld
> > misses a chance to do its magic, and binaries are built without
> > OPENBSD_WXNEEDED, and some ports blow up (when compiled using clang).
> >
> > The patch below is enough to make clang accept and use non-absolute
> > tool file names and make lang/mono and lang/libv8 happy (more likely
> > to follow, there is much work to be done).
> >
> > So I'm asking compiler gurus and base maintainers, if a patch like
> > that would be acceptable? And if yes, how do you want it look like
> > to make supporting it easier?
> >
> > Thank you in advance.
> 
> P.S.: The Program.inc file is not picked up as dependency, so you'll
> need to touch gnu/llvm/lib/Support/Program.cpp manually before
> building clang.

I'm not in favour of this approach.  I'm pretty sure it'll break the
cross-compilation toolchain.  And it makes us deviate from how clang
behaves on other platforms quite a bit.



Re: ksh(1): vi mode UTF-8 bug

2017-05-29 Thread Walter Alejandro Iglesias
On Mon, May 29, 2017 at 07:28:37PM +0200, Ingo Schwarze wrote:
> Hi Walter,
> 
> Walter Alejandro Iglesias wrote on Mon, May 29, 2017 at 06:44:40PM +0200:
> 
> > Are those wide char versions of C functions consistent enough to write
> > a separate implementation to be loaded when LC_TYPE is set to utf-8?
> 
> Sure, you can rewrite the complete shell to use wchar_t * rather
> than char *, and if you do that, you can use the new code to handle
> ASCII as well, no need to have two copies.  But that would be a
> huge effort, even more error-prone than the small, careful adjustments
> we are doing now, and would have a number of additional downsides;
> among others, losing the ability to handle arbitrary bytes, while
> in UTF-8 mode.
> 
> For an editor, going wchar_t might be better because having substantial
> amounts of UTF-8 in user input is a common case in some files that
> people edit.
> 
> For a shell, editing strings that contain non-ASCII is not the main
> purpose.  Sure, it is nice if the command line is able to handle
> strings containing an occasional UTF-8 character.  But the main
> purpose of the shell remains to safely input and execute Unix-style
> command lines, where non-ASCII characters are a non-essential addition
> at best.

I totally agree with you and that's exactly why I value you're
preserving the ascii version, not only ksh, even the editor, I mostly
use vi and have nvi from packages at hand just for when I want to send
mail to family or edit my web site.

Thanks for your kind explanation.


> 
> Yours,
>   Ingo
> 
> 
> For more details, see
> https://www.openbsd.org/papers/eurobsdcon2016-utf8.pdf



Re: Make clang accept and use relative filenames for tools

2017-05-29 Thread Stuart Henderson
On 2017/05/29 20:26, Vadim Zhukov wrote:
> The clang and gcc behave differently regarding executing tools.
> While gcc simply runs what he said to, clang tries to be clever
> and always find absolute path for a tool, refusing start otherwise.
> 
> The actual problem is starting a linker: ports infrastructure
> expects tools are called by name, not by path, and thus could be
> overriden via stuff in ${WRKDIR}/bin. This functionality is used,
> e.g., to implement USE_WXNEEDED port option.
> 
> But clang calls "/usr/bin/ld", not "ld", and thus ${WRKDIR}/bin/ld
> misses a chance to do its magic, and binaries are built without
> OPENBSD_WXNEEDED, and some ports blow up (when compiled using clang).

One thing we _could_ do is pass -fuse-ld=${WRKDIR}/bin/ld when linking ..



Re: Make clang accept and use relative filenames for tools

2017-05-29 Thread Vadim Zhukov
2017-05-29 20:26 GMT+03:00 Vadim Zhukov :
> The clang and gcc behave differently regarding executing tools.
> While gcc simply runs what he said to, clang tries to be clever
> and always find absolute path for a tool, refusing start otherwise.
>
> The actual problem is starting a linker: ports infrastructure
> expects tools are called by name, not by path, and thus could be
> overriden via stuff in ${WRKDIR}/bin. This functionality is used,
> e.g., to implement USE_WXNEEDED port option.
>
> But clang calls "/usr/bin/ld", not "ld", and thus ${WRKDIR}/bin/ld
> misses a chance to do its magic, and binaries are built without
> OPENBSD_WXNEEDED, and some ports blow up (when compiled using clang).
>
> The patch below is enough to make clang accept and use non-absolute
> tool file names and make lang/mono and lang/libv8 happy (more likely
> to follow, there is much work to be done).
>
> So I'm asking compiler gurus and base maintainers, if a patch like
> that would be acceptable? And if yes, how do you want it look like
> to make supporting it easier?
>
> Thank you in advance.

P.S.: The Program.inc file is not picked up as dependency, so you'll
need to touch gnu/llvm/lib/Support/Program.cpp manually before
building clang.

--
  WBR,
  Vadim Zhukov



Re: ksh(1): vi mode UTF-8 bug

2017-05-29 Thread Ingo Schwarze
Hi Walter,

Walter Alejandro Iglesias wrote on Mon, May 29, 2017 at 06:44:40PM +0200:

> Are those wide char versions of C functions consistent enough to write
> a separate implementation to be loaded when LC_TYPE is set to utf-8?

Sure, you can rewrite the complete shell to use wchar_t * rather
than char *, and if you do that, you can use the new code to handle
ASCII as well, no need to have two copies.  But that would be a
huge effort, even more error-prone than the small, careful adjustments
we are doing now, and would have a number of additional downsides;
among others, losing the ability to handle arbitrary bytes, while
in UTF-8 mode.

For an editor, going wchar_t might be better because having substantial
amounts of UTF-8 in user input is a common case in some files that
people edit.

For a shell, editing strings that contain non-ASCII is not the main
purpose.  Sure, it is nice if the command line is able to handle
strings containing an occasional UTF-8 character.  But the main
purpose of the shell remains to safely input and execute Unix-style
command lines, where non-ASCII characters are a non-essential addition
at best.

Yours,
  Ingo


For more details, see
https://www.openbsd.org/papers/eurobsdcon2016-utf8.pdf



Make clang accept and use relative filenames for tools

2017-05-29 Thread Vadim Zhukov
The clang and gcc behave differently regarding executing tools.
While gcc simply runs what he said to, clang tries to be clever
and always find absolute path for a tool, refusing start otherwise.

The actual problem is starting a linker: ports infrastructure
expects tools are called by name, not by path, and thus could be
overriden via stuff in ${WRKDIR}/bin. This functionality is used,
e.g., to implement USE_WXNEEDED port option.

But clang calls "/usr/bin/ld", not "ld", and thus ${WRKDIR}/bin/ld
misses a chance to do its magic, and binaries are built without
OPENBSD_WXNEEDED, and some ports blow up (when compiled using clang).

The patch below is enough to make clang accept and use non-absolute
tool file names and make lang/mono and lang/libv8 happy (more likely
to follow, there is much work to be done).

So I'm asking compiler gurus and base maintainers, if a patch like
that would be acceptable? And if yes, how do you want it look like
to make supporting it easier?

Thank you in advance.

--
WBR,
  Vadim Zhukov


Index: tools/clang/lib/Driver/ToolChain.cpp
===
RCS file: /cvs/src/gnu/llvm/tools/clang/lib/Driver/ToolChain.cpp,v
retrieving revision 1.1.1.3
diff -u -p -r1.1.1.3 ToolChain.cpp
--- tools/clang/lib/Driver/ToolChain.cpp24 Jan 2017 08:33:12 -  
1.1.1.3
+++ tools/clang/lib/Driver/ToolChain.cpp29 May 2017 17:17:19 -
@@ -357,17 +357,17 @@ std::string ToolChain::GetLinkerPath() c
   if (llvm::sys::path::is_absolute(UseLinker)) {
 // If we're passed what looks like an absolute path, don't attempt to
 // second-guess that.
-if (llvm::sys::fs::exists(UseLinker))
+//FOOif (llvm::sys::fs::exists(UseLinker))
   return UseLinker;
   } else if (UseLinker.empty() || UseLinker == "ld") {
 // If we're passed -fuse-ld= with no argument, or with the argument ld,
 // then use whatever the default system linker is.
-return GetProgramPath(getDefaultLinker());
+return /*FOO GetProgramPath(*/ getDefaultLinker() /*)*/;
   } else {
 llvm::SmallString<8> LinkerName("ld.");
 LinkerName.append(UseLinker);
 
-std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
+std::string LinkerPath(/*FOO GetProgramPath(*/ LinkerName.c_str() /*)*/ );
 if (llvm::sys::fs::exists(LinkerPath))
   return LinkerPath;
   }
@@ -375,7 +375,7 @@ std::string ToolChain::GetLinkerPath() c
   if (A)
 getDriver().Diag(diag::err_drv_invalid_linker_name) << 
A->getAsString(Args);
 
-  return GetProgramPath(getDefaultLinker());
+  return /*FOO GetProgramPath(*/ getDefaultLinker() /*)*/;
 }
 
 types::ID ToolChain::LookupTypeForExtension(StringRef Ext) const {
Index: lib/Support/Unix/Program.inc
===
RCS file: /cvs/src/gnu/llvm/lib/Support/Unix/Program.inc,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Program.inc
--- lib/Support/Unix/Program.inc3 Sep 2016 22:47:02 -   1.1.1.1
+++ lib/Support/Unix/Program.inc29 May 2017 17:17:19 -
@@ -181,12 +181,14 @@ static void SetMemoryLimits (unsigned si
 static bool Execute(ProcessInfo , StringRef Program, const char **args,
 const char **envp, const StringRef **redirects,
 unsigned memoryLimit, std::string *ErrMsg) {
+/* let the OS decides if the executable exists
   if (!llvm::sys::fs::exists(Program)) {
 if (ErrMsg)
   *ErrMsg = std::string("Executable \"") + Program.str() +
 std::string("\" doesn't exist!");
 return false;
   }
+*/
 
   // If this OS has posix_spawn and there is no memory limit being implied, use
   // posix_spawn.  It is more efficient than fork/exec.
@@ -240,7 +242,7 @@ static bool Execute(ProcessInfo , Str
 // Explicitly initialized to prevent what appears to be a valgrind false
 // positive.
 pid_t PID = 0;
-int Err = posix_spawn(, Program.str().c_str(), FileActions,
+int Err = posix_spawnp(, Program.str().c_str(), FileActions,
   /*attrp*/nullptr, const_cast(args),
   const_cast(envp));
 



Re: ksh(1): vi mode UTF-8 bug

2017-05-29 Thread Walter Alejandro Iglesias
On Mon, May 29, 2017 at 05:59:34PM +0200, Ingo Schwarze wrote:
> So handling multi-byte "r" should probably be treated as a separate
> issue.
> 

I'm just a beginner with C, what I'm about to say is purely intuitive.

As far as I can understand you're trying to adapt the code that works
with ascii to handle utf-8, what requires to *guess* how to deal with
the next character the user will type at any time.

Are those wide char versions of C functions consistent enough to write a
separate implementation to be loaded when LC_TYPE is set to utf-8?

If I'm telling nonsense just ignore me. :)



Re: ksh(1): vi mode UTF-8 bug

2017-05-29 Thread Ingo Schwarze
Hi,

ooops, correcting myself...

Ingo Schwarze wrote on Mon, May 29, 2017 at 04:16:06PM +0200:

> It seems that here, you may need to measure the length of the character
> to insert in bytes and then call something like
> 
>   putbuf(cmd + 1, #bytes, 0);

It isn't that simple.  At this point, only the first byte of the
character has been read, so we don't even know the number of bytes
yet, and the subsequent ones are *not* available in cmd+2.

Implementing "r" looks like a major undertaking, in particular
since "r" uses the same state machine that is also used for "@", "F", "T",
"f", "t", and none of those have support for dealing with more than
one byte yet.

So handling multi-byte "r" should probably be treated as a separate
issue.

Yours,
  Ingo



Properly serialize pflow's sc_outputqueue

2017-05-29 Thread Visa Hankala
Currently, access to pflow's sc_outputqueue is not serialized properly.
The producer has the NET_LOCK(), while the consumer does not.
mpi@ suggested using mbuf_queue to solve the issue.

OK?

Index: net/if_pflow.c
===
RCS file: src/sys/net/if_pflow.c,v
retrieving revision 1.78
diff -u -p -r1.78 if_pflow.c
--- net/if_pflow.c  27 May 2017 21:44:22 -  1.78
+++ net/if_pflow.c  29 May 2017 15:26:58 -
@@ -132,7 +132,7 @@ pflow_output_process(void *arg)
struct mbuf *m;
 
KERNEL_LOCK();
-   while ((m = ml_dequeue(>sc_outputqueue)) != NULL) {
+   while ((m = mq_dequeue(>sc_outputqueue)) != NULL) {
pflow_sendout_mbuf(sc, m);
}
KERNEL_UNLOCK();
@@ -256,7 +256,7 @@ pflow_clone_create(struct if_clone *ifc,
ifp->if_hdrlen = PFLOW_HDRLEN;
ifp->if_flags = IFF_UP;
ifp->if_flags &= ~IFF_RUNNING;  /* not running, need receiver */
-   ml_init(>sc_outputqueue);
+   mq_init(>sc_outputqueue, IFQ_MAXLEN, IPL_SOFTNET);
pflow_setmtu(pflowif, ETHERMTU);
pflow_init_timeouts(pflowif);
if_attach(ifp);
@@ -288,7 +288,7 @@ pflow_clone_destroy(struct ifnet *ifp)
timeout_del(>sc_tmo_tmpl);
pflow_flush(sc);
task_del(softnettq, >sc_outputtask);
-   ml_purge(>sc_outputqueue);
+   mq_purge(>sc_outputqueue);
m_freem(sc->send_nam);
if (sc->so != NULL) {
error = soclose(sc->so);
@@ -1089,7 +1089,7 @@ pflow_sendout_v5(struct pflow_softc *sc)
getnanotime();
h->time_sec = htonl(tv.tv_sec); /* XXX 2038 */
h->time_nanosec = htonl(tv.tv_nsec);
-   ml_enqueue(>sc_outputqueue, m);
+   mq_enqueue(>sc_outputqueue, m);
task_add(softnettq, >sc_outputtask);
return (0);
 }
@@ -1151,7 +1151,7 @@ pflow_sendout_ipfix(struct pflow_softc *
h10->flow_sequence = htonl(sc->sc_sequence);
sc->sc_sequence += count;
h10->observation_dom = htonl(PFLOW_ENGINE_TYPE);
-   ml_enqueue(>sc_outputqueue, m);
+   mq_enqueue(>sc_outputqueue, m);
task_add(softnettq, >sc_outputtask);
return (0);
 }
@@ -1193,7 +1193,7 @@ pflow_sendout_ipfix_tmpl(struct pflow_so
h10->observation_dom = htonl(PFLOW_ENGINE_TYPE);
 
timeout_add_sec(>sc_tmo_tmpl, PFLOW_TMPL_TIMEOUT);
-   ml_enqueue(>sc_outputqueue, m);
+   mq_enqueue(>sc_outputqueue, m);
task_add(softnettq, >sc_outputtask);
return (0);
 }
Index: net/if_pflow.h
===
RCS file: src/sys/net/if_pflow.h,v
retrieving revision 1.16
diff -u -p -r1.16 if_pflow.h
--- net/if_pflow.h  27 May 2017 21:06:06 -  1.16
+++ net/if_pflow.h  29 May 2017 15:26:58 -
@@ -184,7 +184,7 @@ struct pflow_softc {
struct timeout   sc_tmo;
struct timeout   sc_tmo6;
struct timeout   sc_tmo_tmpl;
-   struct mbuf_list sc_outputqueue;
+   struct mbuf_queuesc_outputqueue;
struct task  sc_outputtask;
struct socket   *so;
struct mbuf *send_nam;



Re: PF + pflow and NET_LOCK() recursion

2017-05-29 Thread Alexandr Nedvedicky
Hello,


On Mon, May 29, 2017 at 02:32:06PM +0200, Martin Pieuchot wrote:
> Now that packets are queued the recursion is gone and we can keep
> the lock.

makes sense. please commit this diff so I can pull back your
change from tree to my patch.

OK sashan@



Re: Remove unused function from compress(1)

2017-05-29 Thread Frederic Cambus
On Tue, May 23, 2017 at 12:12:11PM -0400, Brian Callahan wrote:

> clang says zclose is an unused function. Seems to check out.

Commited, thanks!



Re: wsfont: remove lucida16x29.h and omron12x20?

2017-05-29 Thread Mike Larkin
On Mon, May 29, 2017 at 04:30:26PM +0200, Frederic Cambus wrote:
> Hi,
> 
> Those fonts are not compiled in by default, and I see no reason
> to keep them:
> 
> lucida16x29 is a bad conversion from a truetype font, it is too bold
> which makes it unreadable and unusable.
> 
> omron12x20 is a serif font, and is very difficult to read due to
> inconsistencies in character spacing, alignement, and width.
> 
> Moreover, both fonts only have 96 glyphs.
> 
> Comments? OK to remove them?
> 

no objection



wsfont: remove lucida16x29.h and omron12x20?

2017-05-29 Thread Frederic Cambus
Hi,

Those fonts are not compiled in by default, and I see no reason
to keep them:

lucida16x29 is a bad conversion from a truetype font, it is too bold
which makes it unreadable and unusable.

omron12x20 is a serif font, and is very difficult to read due to
inconsistencies in character spacing, alignement, and width.

Moreover, both fonts only have 96 glyphs.

Comments? OK to remove them?



Re: ksh(1): vi mode UTF-8 bug

2017-05-29 Thread Ingo Schwarze
Hi,

Anton Lindqvist wrote on Sun, May 28, 2017 at 06:07:00PM +0200:
> On Sun, May 28, 2017 at 10:56:19AM +0200, Walter Alejandro Iglesias wrote:

>> There is still a similar issue when you try to "replace" a utf-8
>> character (in command mode press 'r' to replace a single character or
>> 'R' to replace a string).

> Thanks for the report, please try out the diff below.
> As I understand the problem: the current code assumes that the character
> to replace consists of a single byte, which is not true for Unicode
> characters.

Correct.  That needs to be improved.

> When replacing such a character, delete the continuation
> bytes and then replace the start byte with the replacement.
> This ensures no continuation bytes are left behind.
> I made use of putbuf() since it has the side-effect of advancing the
> cursor.
> Lastly, adjust the cursor to be positioned on the last replaced
> character.
> 
> NUL-terminating the line buffer is necessary in order for the following
> to work:
> 
> 1. Insert ö
> 
> 2. Press esc, h (back one char), ro (replace with o), ax (append x)
> 
> Note that replacing a character with a Unicode character does not work
> either.
> 
> Comments? OK?
> 
> Index: bin/ksh/vi.c
> ===
> RCS file: /cvs/src/bin/ksh/vi.c,v
> retrieving revision 1.45
> diff -u -p -r1.45 vi.c
> --- bin/ksh/vi.c  28 May 2017 07:27:01 -  1.45
> +++ bin/ksh/vi.c  28 May 2017 15:59:59 -
> @@ -926,13 +926,22 @@ vi_cmd(int argcnt, const char *cmd)
>   if (cmd[1] == 0)
>   vi_error();
>   else {
> - int n;
> -
>   if (es->cursor + argcnt > es->linelen)
>   return -1;

These two lines are no longer accurate.  They try to make sure there
are enough characters under and to the right of the cursor to match
the number you want to replace (for example, with "2r"), and beep
otherwise - but they count bytes, which is wrong.

To catch the error condition of an excessive argument, i think you
first need to iterate to the right, using the c1 variable and isu8cont(),
and return -1 if you hit the end prematurely.  Do not change anything
in that case.

If so far, you succeed, you know you have to replace the range
[es->cursor, c1].

> - for (n = 0; n < argcnt; ++n)
> - es->cbuf[es->cursor + n] = cmd[1];
> - es->cursor += n - 1;
> +
> + while (argcnt-- > 0) {
> + for (cur = es->cursor + 1;
> + cur < es->linelen; cur++)
> + if (!isu8cont(es->cbuf[cur]))
> + break;
> + if (cur > 1)
> + del_range(es->cursor, cur - 1);

Given that you don't know the length (in bytes) of the character
to insert yet, i think it may be simpler to delete the byte under the
cursor as well, even though that is slightly inefficient for the ASCII
case.

> + putbuf([1], 1, 1);

It seems that here, you may need to measure the length of the character
to insert in bytes and then call something like

  putbuf(cmd + 1, #bytes, 0);


My impression is that the 's' command is likely also affected, but that
can be fixed in a separate patch.

Yours,
  Ingo



Re: CVS: cvs.openbsd.org: src - removal of sys/scanio.h

2017-05-29 Thread Sebastien Marie
On Mon, May 29, 2017 at 03:40:59PM +0200, Sebastien Marie wrote:
> On Mon, May 29, 2017 at 06:10:51AM -0600, Ted Unangst wrote:
> > CVSROOT:/cvs
> > Module name:src
> > Changes by: t...@cvs.openbsd.org2017/05/29 06:10:51
> > 
> > Removed files:
> > sys/sys: scanio.h 
> > 
> > Log message:
> > scanner support died some time ago, the header can be removed too.
> > a gift from miod
> > 
> 
> The remove of sys/scanio.h broke usr.bin/kdump.
> 

correction was just commited. sorry for the noise :)
-- 
Sebastien Marie



Re: CVS: cvs.openbsd.org: src - removal of sys/scanio.h

2017-05-29 Thread Ted Unangst
Sebastien Marie wrote:
> On Mon, May 29, 2017 at 06:10:51AM -0600, Ted Unangst wrote:
> > CVSROOT:/cvs
> > Module name:src
> > Changes by: t...@cvs.openbsd.org2017/05/29 06:10:51
> > 
> > Removed files:
> > sys/sys: scanio.h 
> > 
> > Log message:
> > scanner support died some time ago, the header can be removed too.
> > a gift from miod
> > 
> 
> The remove of sys/scanio.h broke usr.bin/kdump.

yes, sorry, it's fixed now.



Re: CVS: cvs.openbsd.org: src - removal of sys/scanio.h

2017-05-29 Thread Sebastien Marie
On Mon, May 29, 2017 at 06:10:51AM -0600, Ted Unangst wrote:
> CVSROOT:  /cvs
> Module name:  src
> Changes by:   t...@cvs.openbsd.org2017/05/29 06:10:51
> 
> Removed files:
>   sys/sys: scanio.h 
> 
> Log message:
> scanner support died some time ago, the header can be removed too.
> a gift from miod
> 

The remove of sys/scanio.h broke usr.bin/kdump.

Below a diff to unbreak it.

Thanks.
-- 
Sebastien Marie


Index: usr.bin/kdump/Makefile
===
RCS file: /cvs/src/usr.bin/kdump/Makefile,v
retrieving revision 1.33
diff -u -p -r1.33 Makefile
--- usr.bin/kdump/Makefile  25 Apr 2016 19:18:41 -  1.33
+++ usr.bin/kdump/Makefile  29 May 2017 13:39:52 -
@@ -43,7 +43,6 @@ ioctl.c: ${.CURDIR}/Makefile ${.CURDIR}/
${SYS_DIR}/sys/mtio.h \
${SYS_DIR}/sys/pciio.h \
${SYS_DIR}/sys/radioio.h \
-   ${SYS_DIR}/sys/scanio.h \
${SYS_DIR}/sys/scsiio.h \
${SYS_DIR}/sys/sockio.h \
${SYS_DIR}/sys/videoio.h \
Index: usr.bin/kdump/mkioctls
===
RCS file: /cvs/src/usr.bin/kdump/mkioctls,v
retrieving revision 1.37
diff -u -p -r1.37 mkioctls
--- usr.bin/kdump/mkioctls  25 Apr 2016 19:18:41 -  1.37
+++ usr.bin/kdump/mkioctls  29 May 2017 13:39:52 -
@@ -73,7 +73,6 @@ BEGIN {
print "#include "
print "#include "
print "#include "
-   print "#include "
print "#include "
print "#include "
print "#include "



Re: Fewer KERNEL_LOCK() for IPsec

2017-05-29 Thread Alexander Bluhm
On Sun, May 28, 2017 at 04:06:22PM +0200, Martin Pieuchot wrote:
> Our original plan was to unlock the forwarding path without taking any
> lock.  That's why I added some KERNEL_LOCK()/KERNEL_UNLOCK() around non
> MP-safe data structures.
> 
> Now we're going to rely on the NET_LOCK() for the interface address and
> multicast list.  So replace the KERNEL_LOCK()/KERNEL_UNLOCK() their.
> 
> IPsec will still need the KERNEL_LOCK().  But taking and releasing it
> doesn't make sense.  It's also wrong since tdb are not refcounted.  So
> assert that the KERNEL_LOCK() is held.  The idea is to run the softnet
> task under KERNEL_LOCK() if ipsec_in_use is true.
> 
> ok?

OK bluhm@

> 
> Index: netinet/in.c
> ===
> RCS file: /cvs/src/sys/netinet/in.c,v
> retrieving revision 1.138
> diff -u -p -u -4 -r1.138 in.c
> --- netinet/in.c  16 May 2017 12:24:01 -  1.138
> +++ netinet/in.c  28 May 2017 14:00:12 -
> @@ -797,10 +797,8 @@ in_addmulti(struct in_addr *ap, struct i
>  {
>   struct in_multi *inm;
>   struct ifreq ifr;
>  
> - NET_ASSERT_LOCKED();
> -
>   /*
>* See if address already in list.
>*/
>   IN_LOOKUP_MULTI(*ap, ifp, inm);
> @@ -900,12 +898,10 @@ in_hasmulti(struct in_addr *ap, struct i
>  {
>   struct in_multi *inm;
>   int joined;
>  
> - KERNEL_LOCK();
>   IN_LOOKUP_MULTI(*ap, ifp, inm);
>   joined = (inm != NULL);
> - KERNEL_UNLOCK();
>  
>   return (joined);
>  }
>  
> Index: netinet/in_var.h
> ===
> RCS file: /cvs/src/sys/netinet/in_var.h,v
> retrieving revision 1.39
> diff -u -p -u -4 -r1.39 in_var.h
> --- netinet/in_var.h  15 Jun 2016 19:39:34 -  1.39
> +++ netinet/in_var.h  28 May 2017 14:01:33 -
> @@ -85,8 +85,9 @@ struct  in_aliasreq {
>   /* struct ifnet *ifp; */\
>   /* struct in_ifaddr *ia; */ \
>  do { \
>   struct ifaddr *ifa; \
> + NET_ASSERT_LOCKED();\
>   TAILQ_FOREACH(ifa, &(ifp)->if_addrlist, ifa_list) { \
>   if (ifa->ifa_addr->sa_family == AF_INET)\
>   break;  \
>   }   \
> @@ -141,8 +142,9 @@ ifmatoinm(struct ifmaddr *ifma)
>  do { \
>   struct ifmaddr *ifma;   \
>   \
>   (inm) = NULL;   \
> + NET_ASSERT_LOCKED();\
>   TAILQ_FOREACH(ifma, &(ifp)->if_maddrlist, ifma_list)\
>   if (ifma->ifma_addr->sa_family == AF_INET &&\
>   ifmatoinm(ifma)->inm_addr.s_addr == (addr).s_addr) {\
>   (inm) = ifmatoinm(ifma);\
> Index: netinet/ip_input.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_input.c,v
> retrieving revision 1.306
> diff -u -p -u -4 -r1.306 ip_input.c
> --- netinet/ip_input.c28 May 2017 12:22:54 -  1.306
> +++ netinet/ip_input.c28 May 2017 13:56:09 -
> @@ -440,11 +440,11 @@ ipv4_input(struct mbuf *m)
>  #ifdef IPSEC
>   if (ipsec_in_use) {
>   int rv;
>  
> - KERNEL_LOCK();
> + KERNEL_ASSERT_LOCKED();
> +
>   rv = ipsec_forward_check(m, hlen, AF_INET);
> - KERNEL_UNLOCK();
>   if (rv != 0) {
>   ipstat_inc(ips_cantforward);
>   goto bad;
>   }
> @@ -666,9 +666,9 @@ in_ouraddr(struct mbuf *m, struct ifnet 
>* The check in the loop assumes you only rx a packet on an UP
>* interface, and that M_BCAST will only be set on a BROADCAST
>* interface.
>*/
> - KERNEL_LOCK();
> + NET_ASSERT_LOCKED();
>   TAILQ_FOREACH(ifa, >if_addrlist, ifa_list) {
>   if (ifa->ifa_addr->sa_family != AF_INET)
>   continue;
>  
> @@ -677,9 +677,8 @@ in_ouraddr(struct mbuf *m, struct ifnet 
>   match = 1;
>   break;
>   }
>   }
> - KERNEL_UNLOCK();
>   }
>  
>   return (match);
>  }
> Index: netinet/ip_output.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_output.c,v
> retrieving revision 

Re: Fix for "Implement VFS read clustering for MSDOSFS"

2017-05-29 Thread Martin Pieuchot
On 29/05/17(Mon) 14:30, Stefan Fritsch wrote:
> On Mon, 29 May 2017, Martin Pieuchot wrote:
> 
> > A complete diff would be easier to review.
> 
> ok, here it comes.
> 
> The original commit message was this:
> 
>   Implement VFS read clustering for MSDOSFS.
> 
>   The logic used in msdosfs_bmap() to loop calling pcbmap() comes from
>   FreeBSD and is not really efficient but it is good enough since it is
>   only called when generating I/O.
> 
>   With this diff I get a 100% improvement when reading big files from a
>   crappy USB stick.
> 
>   With this and bread_cluster(9) modified to not re-fetch B_CACHED 
> buffers,
>   reading large contiguous files with chunk sizes of MAXPHYS is almost as
>   fast as physio(9) on the same device.
> 
>   For a 'real world' example, when copying music files from a USB stick I
>   see a speed jump from 15MB/s on -current to 24Mb/s with this diff.
> 
>   While here rename some 'lbn' variables into 'cn' to better reflect what
>   we're dealing with.
> 
>   Tested by Mathieu, with support from deraadt@

ok mpi@

Now I understood why I got confused between block & cluster, the current
msdosfs_bmap() function has a bug.  ``ap->a_bn'' is representing a
cluster, not a block.  Diff below fixes that, for the archives.

Index: msdosfs/msdosfs_vnops.c
===
RCS file: /cvs/src/sys/msdosfs/msdosfs_vnops.c,v
retrieving revision 1.113
diff -u -p -r1.113 msdosfs_vnops.c
--- msdosfs/msdosfs_vnops.c 30 Aug 2016 19:47:23 -  1.113
+++ msdosfs/msdosfs_vnops.c 29 May 2017 13:24:11 -
@@ -1765,7 +1765,6 @@ msdosfs_bmap(void *v)
 {
struct vop_bmap_args *ap = v;
struct denode *dep = VTODE(ap->a_vp);
-   struct msdosfsmount *pmp = dep->de_pmp;
 
if (ap->a_vpp != NULL)
*ap->a_vpp = dep->de_devvp;
@@ -1777,7 +1776,7 @@ msdosfs_bmap(void *v)
 */
*ap->a_runp = 0;
}
-   return (pcbmap(dep, de_bn2cn(pmp, ap->a_bn), ap->a_bnp, 0, 0));
+   return (pcbmap(dep, ap->a_bn, ap->a_bnp, 0, 0));
 }
 
 int



PF + pflow and NET_LOCK() recursion

2017-05-29 Thread Martin Pieuchot
Now that packets are queued the recursion is gone and we can keep
the lock.

ok?

Index: net/pf.c
===
RCS file: /cvs/src/sys/net/pf.c,v
retrieving revision 1.1030
diff -u -p -r1.1030 pf.c
--- net/pf.c28 May 2017 16:55:54 -  1.1030
+++ net/pf.c29 May 2017 12:31:01 -
@@ -1320,12 +1320,8 @@ pf_remove_state(struct pf_state *cur)
}
RB_REMOVE(pf_state_tree_id, _id, cur);
 #if NPFLOW > 0
-   if (cur->state_flags & PFSTATE_PFLOW) {
-   /* XXXSMP breaks atomicity */
-   rw_exit_write();
+   if (cur->state_flags & PFSTATE_PFLOW)
export_pflow(cur);
-   rw_enter_write();
-   }
 #endif /* NPFLOW > 0 */
 #if NPFSYNC > 0
pfsync_delete_state(cur);



Re: [PATCH] ntpd: allow to specify a source IP address for outgoing queries

2017-05-29 Thread Stuart Henderson
On 2017/05/29 10:04, Henning Brauer wrote:
> * Sebastian Benoit  [2017-05-28 22:52]:
> > which makes me think:
> > would a global local-address be good enough?
> 
> I think so. This is a kinda weird/rare case.

I agree. There's always NAT for special cases.



Re: Fix for "Implement VFS read clustering for MSDOSFS"

2017-05-29 Thread Stefan Fritsch
On Mon, 29 May 2017, Martin Pieuchot wrote:

> A complete diff would be easier to review.

ok, here it comes.

The original commit message was this:

  Implement VFS read clustering for MSDOSFS.

  The logic used in msdosfs_bmap() to loop calling pcbmap() comes from
  FreeBSD and is not really efficient but it is good enough since it is
  only called when generating I/O.

  With this diff I get a 100% improvement when reading big files from a
  crappy USB stick.

  With this and bread_cluster(9) modified to not re-fetch B_CACHED buffers,
  reading large contiguous files with chunk sizes of MAXPHYS is almost as
  fast as physio(9) on the same device.

  For a 'real world' example, when copying music files from a USB stick I
  see a speed jump from 15MB/s on -current to 24Mb/s with this diff.

  While here rename some 'lbn' variables into 'cn' to better reflect what
  we're dealing with.

  Tested by Mathieu, with support from deraadt@

diff --git sys/msdosfs/denode.h sys/msdosfs/denode.h
index cdca90500ab..c3a413313c1 100644
--- sys/msdosfs/denode.h
+++ sys/msdosfs/denode.h
@@ -142,7 +142,6 @@ struct denode {
struct vnode *de_devvp; /* vnode of blk dev we live on */
uint32_t de_flag;   /* flag bits */
dev_t de_dev;   /* device where direntry lives */
-   daddr_t de_lastr;
uint32_t de_dirclust;   /* cluster of the directory file containing 
this entry */
uint32_t de_diroffset;  /* offset of this entry in the directory 
cluster */
uint32_t de_fndoffset;  /* offset of found dir entry */
diff --git sys/msdosfs/msdosfs_vnops.c sys/msdosfs/msdosfs_vnops.c
index 39c60044df5..783bd0d1d31 100644
--- sys/msdosfs/msdosfs_vnops.c
+++ sys/msdosfs/msdosfs_vnops.c
@@ -77,13 +77,13 @@
 
 static uint32_t fileidhash(uint64_t);
 
+int msdosfs_bmaparray(struct vnode *, daddr_t, daddr_t *, int *);
 int msdosfs_kqfilter(void *);
 int filt_msdosfsread(struct knote *, long);
 int filt_msdosfswrite(struct knote *, long);
 int filt_msdosfsvnode(struct knote *, long);
 void filt_msdosfsdetach(struct knote *);
 
-
 /*
  * Some general notes:
  *
@@ -509,18 +509,14 @@ int
 msdosfs_read(void *v)
 {
struct vop_read_args *ap = v;
-   int error = 0;
-   uint32_t diff;
-   int blsize;
-   int isadir;
-   uint32_t n;
-   long on;
-   daddr_t lbn, rablock, rablkno;
-   struct buf *bp;
struct vnode *vp = ap->a_vp;
struct denode *dep = VTODE(vp);
struct msdosfsmount *pmp = dep->de_pmp;
struct uio *uio = ap->a_uio;
+   int isadir, error = 0;
+   uint32_t n, diff, size, on;
+   struct buf *bp;
+   daddr_t cn, bn;
 
/*
 * If they didn't ask for any data, then we are done.
@@ -535,7 +531,8 @@ msdosfs_read(void *v)
if (uio->uio_offset >= dep->de_FileSize)
return (0);
 
-   lbn = de_cluster(pmp, uio->uio_offset);
+   cn = de_cluster(pmp, uio->uio_offset);
+   size = pmp->pm_bpcluster;
on = uio->uio_offset & pmp->pm_crbomask;
n = ulmin(pmp->pm_bpcluster - on, uio->uio_resid);
 
@@ -548,31 +545,22 @@ msdosfs_read(void *v)
if (diff < n)
n = diff;
 
-   /* convert cluster # to block # if a directory */
-   if (isadir) {
-   error = pcbmap(dep, lbn, , 0, );
-   if (error)
-   return (error);
-   }
/*
 * If we are operating on a directory file then be sure to
 * do i/o with the vnode for the filesystem instead of the
 * vnode for the directory.
 */
if (isadir) {
-   error = bread(pmp->pm_devvp, lbn, blsize, );
+   error = pcbmap(dep, cn, , 0, );
+   if (error)
+   return (error);
+   error = bread(pmp->pm_devvp, cn, size, );
} else {
-   rablock = lbn + 1;
-   rablkno = de_cn2bn(pmp, rablock);
-   if (dep->de_lastr + 1 == lbn &&
-   de_cn2off(pmp, rablock) < dep->de_FileSize)
-   error = breadn(vp, de_cn2bn(pmp, lbn),
-   pmp->pm_bpcluster, ,
-   >pm_bpcluster, 1, );
+   bn = de_cn2bn(pmp, cn);
+   if (de_cn2off(pmp, cn + 1) >= dep->de_FileSize)
+   error = bread(vp, bn, size, );
else
-   error = bread(vp, de_cn2bn(pmp, lbn),
-   pmp->pm_bpcluster, );
-   dep->de_lastr = lbn;
+

Re: Fix for "Implement VFS read clustering for MSDOSFS"

2017-05-29 Thread Martin Pieuchot
On 29/05/17(Mon) 14:15, Stefan Fritsch wrote:
> Last year, mpi@ implemented VFS read clustering for MSDOSFS in
> 
> sys/msdosfs/denode.h 1.28
> sys/msdosfs/msdosfs_vnops.c 1.105
> 
> This caused regressions when doing seeks past the end of the file and had 
> to be reverted.
> 
> I have now written a test that catches the bug (committed in 
> regress/sys/fileops) and got a fix that does not break the test:
> 
> There was some confusion as to what block sizes are used in file
> operations. Openbsd seems to be more like netbsd than like freebsd.
> 
> See msdosfs_vnops.c 1.62 in freebsd:
> 
> Author: msmith 
> Date:   Sun Mar 1 21:26:09 1998 +
> 
> Fix mmap() on msdosfs.  In the words of the submitter:
> 
> |In the process of evaluating the getpages/putpages issues I discovered
> |that mmap on MSDOSFS does not work. This is because I blindly merged
> |NetBSD changes in msdosfs_bmap and msdosfs_strategy. Apparently, their
> |blocksize is always DEV_BSIZE (even in files), while in FreeBSD
> |blocksize in files is v_mount->mnt_stat.f_iosize (i.e. clustersize in
> |MSDOSFS case). The patch is below.
> 
> Submitted by:   Dmitrij Tejblum 
> 
> The diff is meant to be on top of mpi's diff (or on top of a revert of the 
> revert 1.113). I can send the complete diff if that's preferred.

A complete diff would be easier to review.

> 
> diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c
> index 45a479fb646..46ff2736ca4 100644
> --- sys/msdosfs/msdosfs_vnops.c
> +++ sys/msdosfs/msdosfs_vnops.c
> @@ -516,7 +516,7 @@ msdosfs_read(void *v)
>   int isadir, error = 0;
>   uint32_t n, diff, size, on;
>   struct buf *bp;
> - daddr_t cn;
> + daddr_t cn, bn;
>  
>   /*
>* If they didn't ask for any data, then we are done.
> @@ -556,10 +556,11 @@ msdosfs_read(void *v)
>   return (error);
>   error = bread(pmp->pm_devvp, cn, size, );
>   } else {
> + bn = de_cn2bn(pmp, cn);
>   if (de_cn2off(pmp, cn + 1) >= dep->de_FileSize)
> - error = bread(vp, cn, size, );
> + error = bread(vp, bn, size, );
>   else
> - error = bread_cluster(vp, cn, size, );
> + error = bread_cluster(vp, bn, size, );
>   }
>   n = min(n, pmp->pm_bpcluster - bp->b_resid);
>   if (error) {
> @@ -588,7 +589,7 @@ msdosfs_write(void *v)
>   uint32_t osize;
>   int error = 0;
>   uint32_t count, lastcn;
> - daddr_t cn;
> + daddr_t cn, bn;
>   struct buf *bp;
>   int ioflag = ap->a_ioflag;
>   struct uio *uio = ap->a_uio;
> @@ -681,18 +682,19 @@ msdosfs_write(void *v)
>* or we write the cluster from its start beyond EOF,
>* then no need to read data from disk.
>*/
> - bp = getblk(thisvp, cn, pmp->pm_bpcluster, 0, 0);
> + bn = de_cn2bn(pmp, cn);
> + bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0);
>   clrbuf(bp);
>   /*
>* Do the bmap now, since pcbmap needs buffers
>* for the fat table. (see msdosfs_strategy)
>*/
>   if (bp->b_blkno == bp->b_lblkno) {
> - error = pcbmap(dep, bp->b_lblkno, , 0, 0);
> + error = pcbmap(dep,
> +de_bn2cn(pmp, bp->b_lblkno),
> +>b_blkno, 0, 0);
>   if (error)
>   bp->b_blkno = -1;
> - else
> - bp->b_blkno = cn;
>   }
>   if (bp->b_blkno == -1) {
>   brelse(bp);
> @@ -705,7 +707,8 @@ msdosfs_write(void *v)
>* The block we need to write into exists, so
>* read it in.
>*/
> - error = bread(thisvp, cn, pmp->pm_bpcluster, );
> + bn = de_cn2bn(pmp, cn);
> + error = bread(thisvp, bn, pmp->pm_bpcluster, );
>   if (error) {
>   brelse(bp);
>   break;
> @@ -1820,7 +1823,8 @@ msdosfs_strategy(void *v)
>* don't allow files with holes, so we shouldn't ever see this.
>*/
>   if (bp->b_blkno == bp->b_lblkno) {
> - error = pcbmap(dep, bp->b_lblkno, >b_blkno, 0, 0);
> + error = pcbmap(dep, de_bn2cn(dep->de_pmp, bp->b_lblkno),
> + 

Fix for "Implement VFS read clustering for MSDOSFS"

2017-05-29 Thread Stefan Fritsch
Last year, mpi@ implemented VFS read clustering for MSDOSFS in

sys/msdosfs/denode.h 1.28
sys/msdosfs/msdosfs_vnops.c 1.105

This caused regressions when doing seeks past the end of the file and had 
to be reverted.

I have now written a test that catches the bug (committed in 
regress/sys/fileops) and got a fix that does not break the test:

There was some confusion as to what block sizes are used in file
operations. Openbsd seems to be more like netbsd than like freebsd.

See msdosfs_vnops.c 1.62 in freebsd:

Author: msmith 
Date:   Sun Mar 1 21:26:09 1998 +

Fix mmap() on msdosfs.  In the words of the submitter:

|In the process of evaluating the getpages/putpages issues I discovered
|that mmap on MSDOSFS does not work. This is because I blindly merged
|NetBSD changes in msdosfs_bmap and msdosfs_strategy. Apparently, their
|blocksize is always DEV_BSIZE (even in files), while in FreeBSD
|blocksize in files is v_mount->mnt_stat.f_iosize (i.e. clustersize in
|MSDOSFS case). The patch is below.

Submitted by:   Dmitrij Tejblum 

The diff is meant to be on top of mpi's diff (or on top of a revert of the 
revert 1.113). I can send the complete diff if that's preferred.

diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c
index 45a479fb646..46ff2736ca4 100644
--- sys/msdosfs/msdosfs_vnops.c
+++ sys/msdosfs/msdosfs_vnops.c
@@ -516,7 +516,7 @@ msdosfs_read(void *v)
int isadir, error = 0;
uint32_t n, diff, size, on;
struct buf *bp;
-   daddr_t cn;
+   daddr_t cn, bn;
 
/*
 * If they didn't ask for any data, then we are done.
@@ -556,10 +556,11 @@ msdosfs_read(void *v)
return (error);
error = bread(pmp->pm_devvp, cn, size, );
} else {
+   bn = de_cn2bn(pmp, cn);
if (de_cn2off(pmp, cn + 1) >= dep->de_FileSize)
-   error = bread(vp, cn, size, );
+   error = bread(vp, bn, size, );
else
-   error = bread_cluster(vp, cn, size, );
+   error = bread_cluster(vp, bn, size, );
}
n = min(n, pmp->pm_bpcluster - bp->b_resid);
if (error) {
@@ -588,7 +589,7 @@ msdosfs_write(void *v)
uint32_t osize;
int error = 0;
uint32_t count, lastcn;
-   daddr_t cn;
+   daddr_t cn, bn;
struct buf *bp;
int ioflag = ap->a_ioflag;
struct uio *uio = ap->a_uio;
@@ -681,18 +682,19 @@ msdosfs_write(void *v)
 * or we write the cluster from its start beyond EOF,
 * then no need to read data from disk.
 */
-   bp = getblk(thisvp, cn, pmp->pm_bpcluster, 0, 0);
+   bn = de_cn2bn(pmp, cn);
+   bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0);
clrbuf(bp);
/*
 * Do the bmap now, since pcbmap needs buffers
 * for the fat table. (see msdosfs_strategy)
 */
if (bp->b_blkno == bp->b_lblkno) {
-   error = pcbmap(dep, bp->b_lblkno, , 0, 0);
+   error = pcbmap(dep,
+  de_bn2cn(pmp, bp->b_lblkno),
+  >b_blkno, 0, 0);
if (error)
bp->b_blkno = -1;
-   else
-   bp->b_blkno = cn;
}
if (bp->b_blkno == -1) {
brelse(bp);
@@ -705,7 +707,8 @@ msdosfs_write(void *v)
 * The block we need to write into exists, so
 * read it in.
 */
-   error = bread(thisvp, cn, pmp->pm_bpcluster, );
+   bn = de_cn2bn(pmp, cn);
+   error = bread(thisvp, bn, pmp->pm_bpcluster, );
if (error) {
brelse(bp);
break;
@@ -1820,7 +1823,8 @@ msdosfs_strategy(void *v)
 * don't allow files with holes, so we shouldn't ever see this.
 */
if (bp->b_blkno == bp->b_lblkno) {
-   error = pcbmap(dep, bp->b_lblkno, >b_blkno, 0, 0);
+   error = pcbmap(dep, de_bn2cn(dep->de_pmp, bp->b_lblkno),
+  >b_blkno, 0, 0);
if (error)
bp->b_blkno = -1;
if (bp->b_blkno == -1)



Prevent NET_LOCK() vs if_get() deadlock

2017-05-29 Thread Martin Pieuchot
As explained recently, calling refcnt_finalize() for ifp references and
sleeping while holding the NET_LOCK() creates a deadlock situation.

However we can simply fix that by not calling if_idxmap_remove() under
the NET_LOCK().  This is safe since the KERNEL_LOCK() is what is needed
to serialize access to ``if_map''.

ok?

Index: net/if.c
===
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.500
diff -u -p -r1.500 if.c
--- net/if.c29 May 2017 06:08:21 -  1.500
+++ net/if.c29 May 2017 10:32:12 -
@@ -1014,11 +1014,11 @@ if_detach(struct ifnet *ifp)
 
ifq_clr_oactive(>if_snd);
 
-   NET_LOCK(s);
-   s2 = splnet();
/* Other CPUs must not have a reference before we start destroying. */
if_idxmap_remove(ifp);
 
+   NET_LOCK(s);
+   s2 = splnet();
ifp->if_qstart = if_detached_qstart;
ifp->if_ioctl = if_detached_ioctl;
ifp->if_watchdog = NULL;



Re: tcpdump: enable some more bgp info

2017-05-29 Thread Job Snijders
On Mon, May 29, 2017 at 12:02:33PM +0200, Michal Mazurek wrote:
> The error information for bgp was commited in 2009
> (bgpnotify_minor_cease, bgpnotify_minor_cap) but never enabled, so do
> that here. Also add FSM error codes.

perhaps add a comment like /* RFC 6608 */ above the below:

> +static const char *bgpnotify_minor_fsm[] = {
> + NULL, "In OpenSent State", "In OpenConfirm State",
> + "In Established State",
> +};

and maybe s/NULL/"Unspecified Error"/

Kind regards,

Job



tcpdump: fix some clang warnings

2017-05-29 Thread Michal Mazurek
"plen" and "len" are of type "u_int" and never negative.

Index: usr.sbin/tcpdump/print-bgp.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/print-bgp.c,v
retrieving revision 1.21
diff -u -p -r1.21 print-bgp.c
--- usr.sbin/tcpdump/print-bgp.c24 Apr 2017 20:35:35 -  1.21
+++ usr.sbin/tcpdump/print-bgp.c29 May 2017 10:08:40 -
@@ -356,7 +356,7 @@ decode_prefix4(const u_char *pd, char *b
   * enough bytes of address to contain this many bits
   */
plen = pd[0];
-   if (plen < 0 || 32 < plen)
+   if (32 < plen)
return -1;
memset(, 0, sizeof(addr));
TCHECK2(pd[1], (plen + 7) / 8);
@@ -385,7 +385,7 @@ decode_prefix6(const u_char *pd, char *b
 
TCHECK(pd[0]);
plen = pd[0];
-   if (plen < 0 || 128 < plen)
+   if (128 < plen)
return -1;
 
memset(, 0, sizeof(addr));
Index: usr.sbin/tcpdump/print-wb.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/print-wb.c,v
retrieving revision 1.9
diff -u -p -r1.9 print-wb.c
--- usr.sbin/tcpdump/print-wb.c 16 Nov 2015 00:16:39 -  1.9
+++ usr.sbin/tcpdump/print-wb.c 29 May 2017 10:08:40 -
@@ -180,7 +180,7 @@ wb_id(const struct pkt_id *id, u_int len
 
printf(" wb-id:");
len -= sizeof(*id);
-   if (len < 0 || (u_char *)(id + 1) > snapend)
+   if ((u_char *)(id + 1) > snapend)
return (-1);
 
printf(" %u/%s:%u (max %u/%s:%u) ",
@@ -336,7 +336,7 @@ wb_rrep(const struct pkt_rrep *rrep, u_i
 
printf(" wb-rrep:");
len -= sizeof(*rrep);
-   if (len < 0 || (u_char *)(rrep + 1) > snapend)
+   if ((u_char *)(rrep + 1) > snapend)
return (-1);
 
printf(" for %s %s:%u<%u:%u>",
@@ -357,7 +357,7 @@ wb_drawop(const struct pkt_dop *dop, u_i
 {
printf(" wb-dop:");
len -= sizeof(*dop);
-   if (len < 0 || (u_char *)(dop + 1) > snapend)
+   if ((u_char *)(dop + 1) > snapend)
return (-1);
 
printf(" %s:%u<%u:%u>",
@@ -382,7 +382,7 @@ wb_print(const void *hdr, u_int len)
 
ph = (const struct pkt_hdr *)hdr;
len -= sizeof(*ph);
-   if (len < 0 || (u_char *)(ph + 1) <= snapend) {
+   if ((u_char *)(ph + 1) <= snapend) {
if (ph->ph_flags)
printf("*");
switch (ph->ph_type) {

-- 
Michal Mazurek



tcpdump: enable some more bgp info

2017-05-29 Thread Michal Mazurek
The error information for bgp was commited in 2009 (bgpnotify_minor_cease,
bgpnotify_minor_cap) but never enabled, so do that here. Also add FSM error
codes.

Index: print-bgp.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/print-bgp.c,v
retrieving revision 1.21
diff -u -p -r1.21 print-bgp.c
--- print-bgp.c 24 Apr 2017 20:35:35 -  1.21
+++ print-bgp.c 29 May 2017 09:20:34 -
@@ -226,6 +226,15 @@ static const char *bgpnotify_minor_updat
"Invalid Network Field", "Malformed AS_PATH",
 };
 
+static const char *bgpnotify_minor_holdtime[] = {
+   NULL,
+};
+
+static const char *bgpnotify_minor_fsm[] = {
+   NULL, "In OpenSent State", "In OpenConfirm State",
+   "In Established State",
+};
+
 /* RFC 4486 */
 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX  1
 /* draft-ietf-idr-shutdown-07 */
@@ -246,14 +255,16 @@ static const char *bgpnotify_minor_cap[]
 
 static const char **bgpnotify_minor[] = {
NULL, bgpnotify_minor_msg, bgpnotify_minor_open, bgpnotify_minor_update,
+   bgpnotify_minor_holdtime, bgpnotify_minor_fsm, bgpnotify_minor_cease,
+   bgpnotify_minor_cap,
 };
 static const int bgpnotify_minor_siz[] = {
0,
sizeof(bgpnotify_minor_msg)/sizeof(bgpnotify_minor_msg[0]),
sizeof(bgpnotify_minor_open)/sizeof(bgpnotify_minor_open[0]),
sizeof(bgpnotify_minor_update)/sizeof(bgpnotify_minor_update[0]),
-   0,
-   0,
+   sizeof(bgpnotify_minor_holdtime)/sizeof(bgpnotify_minor_holdtime[0]),
+   sizeof(bgpnotify_minor_fsm)/sizeof(bgpnotify_minor_fsm[0]),
sizeof(bgpnotify_minor_cease)/sizeof(bgpnotify_minor_cease[0]),
sizeof(bgpnotify_minor_cap)/sizeof(bgpnotify_minor_cap[0]),
 };

-- 
Michal Mazurek



Re: marco's plaintext history patch

2017-05-29 Thread Theo Buehler
On Fri, Apr 28, 2017 at 10:01:06AM +0200, Theo Buehler wrote:
> This is an updated version of an old patch by marco [1], including some
> improvements and fixes by natano and me. Here's marco's description:
> 
> > I have had enough of corrupt ksh history so I had a look at the code to
> > try to fix it.  The magical code was very magical so I basically deleted
> > most of it and made ksh history into a flat text file.  It handles
> > multiple ksh instances writing to the same text file with locks just
> > like the current ksh does.  I haven't noticed any differences in
> > behavior running this.
> 
> If you wish to retain your current ksh history, you can create a
> plaintext version of it using a command like this (assuming HISTFILE and
> HISTSIZE are set):
> 
> cp $HISTFILE $HISTFILE.old
> fc -ln 1 | sed 's/^ //' > ~/ksh_hist.txt
> 
> Then apply the patch and install the new ksh.
> 
> Once you've exited all interactive sessions with the old ksh (a reboot is
> probably your safest bet), you can use ksh_hist.txt as your history file.
> 
> Note that the old ksh recklessly truncates a history file that it
> doesn't understand, so be careful not to run old and new interactive ksh
> processes in parallel.
> 
> [1]: https://marc.info/?l=openbsd-tech=131490865525379=2

I had no feedback on this. Here's the patch again with the extra cast
(pointed out by Michael W. Bombardieri) removed.

Index: bin/ksh/alloc.c
===
RCS file: /cvs/src/bin/ksh/alloc.c,v
retrieving revision 1.15
diff -u -p -r1.15 alloc.c
--- bin/ksh/alloc.c 1 Jun 2016 10:29:20 -   1.15
+++ bin/ksh/alloc.c 29 May 2017 09:47:43 -
@@ -47,7 +47,7 @@ alloc(size_t size, Area *ap)
if (size > SIZE_MAX - sizeof(struct link))
internal_errorf(1, "unable to allocate memory");
 
-   l = malloc(sizeof(struct link) + size);
+   l = calloc(1, sizeof(struct link) + size);
if (l == NULL)
internal_errorf(1, "unable to allocate memory");
l->next = ap->freelist;
Index: bin/ksh/history.c
===
RCS file: /cvs/src/bin/ksh/history.c,v
retrieving revision 1.58
diff -u -p -r1.58 history.c
--- bin/ksh/history.c   24 Aug 2016 16:09:40 -  1.58
+++ bin/ksh/history.c   29 May 2017 09:47:43 -
@@ -9,8 +9,7 @@
  * a)  the original in-memory history  mechanism
  * b)  a more complicated mechanism done by  p...@hillside.co.uk
  * that more closely follows the real ksh way of doing
- * things. You need to have the mmap system call for this
- * to work on your system
+ * things.
  */
 
 #include 
@@ -22,25 +21,16 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "sh.h"
 
 #ifdef HISTORY
-# include 
 
-/*
- * variables for handling the data file
- */
-static int histfd;
-static int hsize;
-
-static int hist_count_lines(unsigned char *, int);
-static int hist_shrink(unsigned char *, int);
-static unsigned char *hist_skip_back(unsigned char *,int *,int);
-static void histload(Source *, unsigned char *, int);
-static void histinsert(Source *, int, unsigned char *);
-static void writehistfile(int, char *);
-static int sprinkle(int);
+static voidwritehistfile(void);
+static FILE*history_open(void);
+static int history_load(Source *);
+static voidhistory_close(void);
 
 static int hist_execute(char *);
 static int hist_replace(char **, const char *, const char *, int);
@@ -48,11 +38,14 @@ static char   **hist_get(const char *, i
 static char   **hist_get_oldest(void);
 static voidhistbackup(void);
 
+static FILE*histfd;
 static char   **current;   /* current position in history[] */
 static char*hname; /* current name of history file */
 static int hstarted;   /* set after hist_init() called */
 static Source  *hist_source;
+static uint32_tline_co;
 
+static struct stat last_sb;
 
 int
 c_fc(char **wp)
@@ -546,15 +539,10 @@ sethistfile(const char *name)
/* if the name is the same as the name we have */
if (hname && strcmp(hname, name) == 0)
return;
-
/*
 * its a new name - possibly
 */
-   if (histfd) {
-   /* yes the file is open */
-   (void) close(histfd);
-   histfd = 0;
-   hsize = 0;
+   if (hname) {
afree(hname, APERM);
hname = NULL;
/* let's reset the history */
@@ -562,6 +550,7 @@ sethistfile(const char *name)
hist_source->line = 0;
}
 
+   history_close();
hist_init(hist_source);
 }
 
@@ -578,6 +567,16 @@ init_histvec(void)
}
 }
 
+static void
+history_lock(int operation)
+{
+   while (flock(fileno(histfd), operation) != 0) {
+   if (errno == EINTR || errno == EAGAIN)
+ 

Re: nvme hibernate

2017-05-29 Thread Jonathan Matthew
On Sun, May 28, 2017 at 06:49:53PM +1000, Jonathan Matthew wrote:
> This adds a side effect free io path to nvme(4) allowing it to be used for
> hibernate.  I've only tested this in a qemu vm, which successfully hibernates
> but falls over weirdly trying to resume.

This version has survived contact with actual hardware, which cares about the
io queue being page aligned (as required by the nvme spec), whereas qemu 
doesn't.
I got around this by preallocating the queue during nvme_attach.

Once this is in, I'll make get_hibernate_io_function a bit more readable.

Index: conf/files
===
RCS file: /cvs/src/sys/conf/files,v
retrieving revision 1.645
diff -u -p -r1.645 files
--- conf/files  15 May 2017 11:23:25 -  1.645
+++ conf/files  29 May 2017 09:47:30 -
@@ -193,7 +193,7 @@ filedev/ic/ahci.c   ahci | 
(ahci_pci | 
 
 # NVM Express Controller
 device nvme: scsi
-file   dev/ic/nvme.c   nvme
+file   dev/ic/nvme.c   nvme needs-flag
 
 # LSI Logic Fusion-MPT Message Passing Interface
 device mpi: scsi
Index: arch/amd64/amd64/hibernate_machdep.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/hibernate_machdep.c,v
retrieving revision 1.38
diff -u -p -r1.38 hibernate_machdep.c
--- arch/amd64/amd64/hibernate_machdep.c21 Aug 2015 07:01:38 -  
1.38
+++ arch/amd64/amd64/hibernate_machdep.c29 May 2017 09:47:30 -
@@ -47,6 +47,7 @@
 #include "ahci.h"
 #include "softraid.h"
 #include "sd.h"
+#include "nvme.h"
 
 /* Hibernate support */
 voidhibernate_enter_resume_4k_pte(vaddr_t, paddr_t);
@@ -89,6 +90,8 @@ get_hibernate_io_function(dev_t dev)
extern struct cfdriver sd_cd;
extern int ahci_hibernate_io(dev_t dev, daddr_t blkno,
vaddr_t addr, size_t size, int op, void *page);
+   extern int nvme_hibernate_io(dev_t dev, daddr_t blkno,
+   vaddr_t addr, size_t size, int op, void *page);
extern int sr_hibernate_io(dev_t dev, daddr_t blkno,
vaddr_t addr, size_t size, int op, void *page);
struct device *dv = disk_lookup(_cd, DISKUNIT(dev));
@@ -98,6 +101,12 @@ get_hibernate_io_function(dev_t dev)

strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
"ahci") == 0)
return ahci_hibernate_io;
+#endif
+#if NNVME > 0
+   if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
+   
strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
+   "nvme") == 0)
+   return nvme_hibernate_io;
 #endif
 #if NSOFTRAID > 0
if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
Index: dev/ic/nvmevar.h
===
RCS file: /cvs/src/sys/dev/ic/nvmevar.h,v
retrieving revision 1.10
diff -u -p -r1.10 nvmevar.h
--- dev/ic/nvmevar.h27 May 2017 12:40:51 -  1.10
+++ dev/ic/nvmevar.h29 May 2017 09:47:30 -
@@ -16,6 +16,9 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#define NVME_IO_Q  1
+#define NVME_HIB_Q 2
+
 struct nvme_dmamem {
bus_dmamap_tndm_map;
bus_dma_segment_t   ndm_seg;
@@ -90,6 +93,7 @@ struct nvme_softc {
 
struct nvme_queue   *sc_admin_q;
struct nvme_queue   *sc_q;
+   struct nvme_queue   *sc_hib_q;
 
struct mutexsc_ccb_mtx;
struct nvme_ccb *sc_ccbs;
Index: dev/ic/nvme.c
===
RCS file: /cvs/src/sys/dev/ic/nvme.c,v
retrieving revision 1.56
diff -u -p -r1.56 nvme.c
--- dev/ic/nvme.c   27 May 2017 12:40:51 -  1.56
+++ dev/ic/nvme.c   29 May 2017 09:47:30 -
@@ -26,6 +26,8 @@
 #include 
 #include 
 
+#include 
+
 #include 
 
 #include 
@@ -86,6 +88,15 @@ void nvme_scsi_cmd(struct scsi_xfer *);
 intnvme_scsi_probe(struct scsi_link *);
 void   nvme_scsi_free(struct scsi_link *);
 
+#ifdef HIBERNATE
+#include 
+#include 
+#include 
+#include 
+
+intnvme_hibernate_io(dev_t, daddr_t, vaddr_t, size_t, int, void *);
+#endif
+
 struct scsi_adapter nvme_switch = {
nvme_scsi_cmd,  /* cmd */
scsi_minphys,   /* minphys */
@@ -332,7 +343,7 @@ nvme_attach(struct nvme_softc *sc)
goto free_admin_q;
}
 
-   sc->sc_q = nvme_q_alloc(sc, 1, 128, sc->sc_dstrd);
+   sc->sc_q = nvme_q_alloc(sc, NVME_IO_Q, 128, sc->sc_dstrd);
if (sc->sc_q == NULL) {
printf("%s: unable to allocate io q\n", DEVNAME(sc));
goto disable;
@@ -343,6 +354,12 @@ nvme_attach(struct nvme_softc *sc)
goto free_q;
}
 
+   sc->sc_hib_q = nvme_q_alloc(sc, NVME_HIB_Q, 

There is only one PFKEY version, kill pfkey.c

2017-05-29 Thread Claudio Jeker
Reduce the abstraction of pfkey a bit by admitting that we will only ever
do v2 of the pfkey protocol. This will make it easier to make the pcb
layer more like the one of the rtsock.c

Would also be possible to keep pfkey.c with the pcb layer in it and have
pfkeyv2 only do the protocol handling...
-- 
:wq Claudio

Index: conf/files
===
RCS file: /cvs/src/sys/conf/files,v
retrieving revision 1.645
diff -u -p -r1.645 files
--- conf/files  15 May 2017 11:23:25 -  1.645
+++ conf/files  29 May 2017 09:26:27 -
@@ -979,10 +979,9 @@ file netinet6/raw_ip6.cinet6
 file netinet6/udp6_output.cinet6
 
 # ... PF_KEY
-file net/pfkey.c   key | ipsec | tcp_signature
-file net/pfkeyv2.c key | ipsec | tcp_signature
-file net/pfkeyv2_parsemessage.ckey | ipsec | tcp_signature
-file net/pfkeyv2_convert.c key | ipsec | tcp_signature
+file net/pfkeyv2.c ipsec | tcp_signature
+file net/pfkeyv2_parsemessage.cipsec | tcp_signature
+file net/pfkeyv2_convert.c ipsec | tcp_signature
 
 # libx86emu
 file dev/x86emu/x86emu.c   x86emu
Index: net/pfkey.c
===
RCS file: net/pfkey.c
diff -N net/pfkey.c
--- net/pfkey.c 26 May 2017 19:11:20 -  1.42
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,241 +0,0 @@
-/* $OpenBSD: pfkey.c,v 1.42 2017/05/26 19:11:20 claudio Exp $  */
-
-/*
- * @(#)COPYRIGHT   1.1 (NRL) 17 January 1995
- *
- * NRL grants permission for redistribution and use in source and binary
- * forms, with or without modification, of the software and documentation
- * created at NRL provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *must display the following acknowledgements:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * This product includes software developed at the Information
- * Technology Division, US Naval Research Laboratory.
- * 4. Neither the name of the NRL nor the names of its contributors
- *may be used to endorse or promote products derived from this software
- *without specific prior written permission.
- *
- * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
- * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL NRL OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation
- * are those of the authors and should not be interpreted as representing
- * official policies, either expressed or implied, of the US Naval
- * Research Laboratory (NRL).
- */
-
-/*
- * Copyright (c) 1995, 1996, 1997, 1998, 1999 Craig Metz. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the author nor the names of any contributors
- *may be used to endorse or promote products derived from this software
- *without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 

Re: [patch] ND_COMPUTER_RTIME is not uniformly distributed

2017-05-29 Thread Theo Buehler
On Fri, May 19, 2017 at 09:05:38AM +0200, Theo Buehler wrote:
> On Mon, May 15, 2017 at 03:49:55PM +0200, Mike Belopuhov wrote:
> > On Sun, May 07, 2017 at 18:59 -0500, Matthew Martin wrote:
> > > RFC 4861 specifies ReachableTime "should be a uniformly distributed
> > > random value between MIN_RANDOM_FACTOR and MAX_RANDOM_FACTOR times
> > > BaseReachableTime milliseconds." I think the author intended to do the
> > > multiplication by (x>>10) outside the mask, but it's still missing a -1.
> > > 
> > > - Matthew Martin
> > > 
> > > 
> > > 
> > > diff --git nd6.h nd6.h
> > > index 4274cd4dd07..8eea089a40c 100644
> > > --- nd6.h
> > > +++ nd6.h
> > > @@ -162,8 +162,8 @@ structllinfo_nd6 {
> > >  #define MIN_RANDOM_FACTOR512 /* 1024 * 0.5 */
> > >  #define MAX_RANDOM_FACTOR1536/* 1024 * 1.5 */
> > >  #define ND_COMPUTE_RTIME(x) \
> > > - (((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \
> > > - ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10 /1000)
> > > + (((arc4random() & (MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR - 1)) \
> > > + + MIN_RANDOM_FACTOR) * (x >> 10) / 1000)
> > >  
> > >  TAILQ_HEAD(nd_drhead, nd_defrouter);
> > >  struct   nd_defrouter {
> > > 
> > 
> > Hmm, how about we use an arc4random_uniform here?  It will generate
> > numbers less than the upper bound specified as an argument so I don't
> > need to -1 there.
> > 
> > I don't think they wanted to do a multiplication by (x>>10) outside
> > the mask and in this case as well we want arc4random_uniform to operate
> > on an extended range.
> > 
> > Does this look good?
> 
> Your version is better than what's currently there and would seem to
> match the intention of the code as it was written. Sine there was no
> objection:
> 
> ok tb

Are you going to commit this or should I?

> 
> 
> However, for whatever that's worth, I initially read the cited passage
> the same way as Matthew, but the more I look at it, the more unclear it
> becomes what is actually meant. Your interpretation is definitely
> possible.
> 
> DragonFly, FreeBSD and NetBSD all have versions of what we currently
> have, while Linux does something that looks suspiciously like the analog of
> 
>   arc4random() % (x >> 10) + (x >> 10).
> 



remove router solicitation sending and router advertisement processing from kernel

2017-05-29 Thread Florian Obser
This is more for krautbackup purposes. Not going to ask for OKs any
time soon. But if you are sufficiently bored you might want to run with
this and slaacd.
I would also be interested if this breaks anything on v6 routers or hosts
that do not use autoconfiguration.

 net/if.c|   10 -
 netinet6/icmp6.c|9 +-
 netinet6/in6.c  |   16 -
 netinet6/in6_ifattach.c |7 +-
 netinet6/in6_var.h  |3 -
 netinet6/nd6.c  |  372 +-
 netinet6/nd6.h  |   62 --
 netinet6/nd6_nbr.c  |   25 +-
 netinet6/nd6_rtr.c  | 1849 ---
 9 files changed, 13 insertions(+), 2340 deletions(-)

diff --git net/if.c net/if.c
index d519ddcfeba..3a134a545f5 100644
--- net/if.c
+++ net/if.c
@@ -1924,16 +1924,6 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, 
struct proc *p)
if (error != 0)
return (error);
}
-
-   if ((ifr->ifr_flags & IFXF_AUTOCONF6) &&
-   !(ifp->if_xflags & IFXF_AUTOCONF6)) {
-   nd6_rs_attach(ifp);
-   }
-
-   if ((ifp->if_xflags & IFXF_AUTOCONF6) &&
-   !(ifr->ifr_flags & IFXF_AUTOCONF6)) {
-   nd6_rs_detach(ifp);
-   }
 #endif /* INET6 */
 
 #ifdef MPLS
diff --git netinet6/icmp6.c netinet6/icmp6.c
index c7a5566076b..36b6b783f55 100644
--- netinet6/icmp6.c
+++ netinet6/icmp6.c
@@ -662,14 +662,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto, int af)
goto badcode;
if (icmp6len < sizeof(struct nd_router_advert))
goto badlen;
-   if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
-   /* give up local */
-   nd6_ra_input(m, off, icmp6len);
-   m = NULL;
-   goto freeit;
-   }
-   nd6_ra_input(n, off, icmp6len);
-   /* m stays. */
+
break;
 
case ND_NEIGHBOR_SOLICIT:
diff --git netinet6/in6.c netinet6/in6.c
index a378671a8bb..2f2eb4f75f6 100644
--- netinet6/in6.c
+++ netinet6/in6.c
@@ -898,25 +898,9 @@ in6_unlink_ifa(struct in6_ifaddr *ia6, struct ifnet *ifp)
 {
struct ifaddr *ifa = >ia_ifa;
extern int ifatrash;
-   int plen;
 
NET_ASSERT_LOCKED();
 
-   /* Release the reference to the base prefix. */
-   if (ia6->ia6_ndpr == NULL) {
-   plen = in6_mask2len(>ia_prefixmask.sin6_addr, NULL);
-   if ((ifp->if_flags & IFF_LOOPBACK) == 0 && plen != 128) {
-   rt_ifa_del(ifa, RTF_CLONING | RTF_CONNECTED,
-   ifa->ifa_addr);
-   }
-   } else {
-   KASSERT(ia6->ia6_flags & IN6_IFF_AUTOCONF);
-   ia6->ia6_flags &= ~IN6_IFF_AUTOCONF;
-   if (--ia6->ia6_ndpr->ndpr_refcnt == 0)
-   prelist_remove(ia6->ia6_ndpr);
-   ia6->ia6_ndpr = NULL;
-   }
-
rt_ifa_purge(ifa);
ifa_del(ifp, ifa);
 
diff --git netinet6/in6_ifattach.c netinet6/in6_ifattach.c
index fad1eb130b6..7d93f0805fe 100644
--- netinet6/in6_ifattach.c
+++ netinet6/in6_ifattach.c
@@ -504,9 +504,6 @@ in6_ifattach(struct ifnet *ifp)
}
}
 
-   if (ifp->if_xflags & IFXF_AUTOCONF6)
-   nd6_rs_attach(ifp);
-
return (0);
 }
 
@@ -563,8 +560,6 @@ in6_ifdetach(struct ifnet *ifp)
rtfree(rt);
}
 
-   if (ifp->if_xflags & IFXF_AUTOCONF6) {
-   nd6_rs_detach(ifp);
+   if (ifp->if_xflags & IFXF_AUTOCONF6)
ifp->if_xflags &= ~IFXF_AUTOCONF6;
-   }
 }
diff --git netinet6/in6_var.h netinet6/in6_var.h
index a193e2df396..2501729da86 100644
--- netinet6/in6_var.h
+++ netinet6/in6_var.h
@@ -112,9 +112,6 @@ struct  in6_ifaddr {
 */
time_t  ia6_updatetime;
 
-   /* back pointer to the prefix (for autoconf) */
-   struct nd_prefix *ia6_ndpr;
-
/* multicast addresses joined from the kernel */
LIST_HEAD(, in6_multi_mship) ia6_memberships;
 };
diff --git netinet6/nd6.c netinet6/nd6.c
index 7b32caec770..773e8e12b1f 100644
--- netinet6/nd6.c
+++ netinet6/nd6.c
@@ -87,9 +87,6 @@ TAILQ_HEAD(llinfo_nd6_head, llinfo_nd6) nd6_list;
 struct pool nd6_pool;  /* pool for llinfo_nd6 structures */
 intnd6_inuse, nd6_allocated;
 
-struct nd_drhead nd_defrouter;
-struct nd_prhead nd_prefix = { 0 };
-
 int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL;
 
 void nd6_slowtimo(void *);
@@ -103,9 +100,6 @@ struct timeout nd6_slowtimo_ch;
 struct timeout nd6_timer_ch;
 struct task nd6_timer_task;
 
-int fill_drlist(void *, size_t *, size_t);
-int fill_prlist(void *, size_t *, size_t);
-
 void
 nd6_init(void)
 {
@@ -121,7 +115,6 @@ nd6_init(void)
IPL_SOFTNET, 0, "nd6", NULL);
 
   

Re: making rtsock more MP save using SRP list for pcbs

2017-05-29 Thread Claudio Jeker
On Sun, May 28, 2017 at 04:22:20PM +0200, Claudio Jeker wrote:
> This is a start at pushing locking down into the socket layer.  Use a
> SRPL list to manage the route PCBs and start running stuff without the
> kernel lock where save. Includes some cleanup since rawcb was removed in
> along the way.
> 
> The goal is to make the block running without the kernel lock larger and
> larger.

Better diff. Keeping an extra reference (refcnt_take) in the SRPL_FOREACH
loop since both the current and previous (last) element are used in the loop.
Also release the rw_lock before calling refcnt_finalize() since sleeping
with that lock set could lead to a deadlock.

-- 
:wq Claudio

Index: net/raw_cb.c
===
RCS file: /cvs/src/sys/net/raw_cb.c,v
retrieving revision 1.11
diff -u -p -r1.11 raw_cb.c
--- net/raw_cb.c24 Jan 2017 10:08:30 -  1.11
+++ net/raw_cb.c28 May 2017 07:34:19 -
@@ -46,16 +46,10 @@
 
 /*
  * Routines to manage the raw protocol control blocks.
- *
- * TODO:
- * hash lookups by protocol family/protocol + address family
- * take care of unique address problems per AF?
- * redo address binding to allow wildcards
  */
 
 u_long raw_sendspace = RAWSNDQ;
 u_long raw_recvspace = RAWRCVQ;
-struct rawcbhead rawcb;
 
 /*
  * Allocate a control block and a nominal amount
@@ -72,14 +66,13 @@ raw_attach(struct socket *so, int proto)
 * after space has been allocated for the
 * rawcb.
 */
-   if (rp == 0)
+   if (rp == NULL)
return (ENOBUFS);
if ((error = soreserve(so, raw_sendspace, raw_recvspace)) != 0)
return (error);
rp->rcb_socket = so;
rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
rp->rcb_proto.sp_protocol = proto;
-   LIST_INSERT_HEAD(, rp, rcb_list);
return (0);
 }
 
@@ -94,7 +87,6 @@ raw_detach(struct rawcb *rp)
 
so->so_pcb = 0;
sofree(so);
-   LIST_REMOVE(rp, rcb_list);
free((caddr_t)(rp), M_PCB, 0);
 }
 
@@ -104,7 +96,6 @@ raw_detach(struct rawcb *rp)
 void
 raw_disconnect(struct rawcb *rp)
 {
-
if (rp->rcb_socket->so_state & SS_NOFDREF)
raw_detach(rp);
 }
Index: net/raw_cb.h
===
RCS file: /cvs/src/sys/net/raw_cb.h,v
retrieving revision 1.11
diff -u -p -r1.11 raw_cb.h
--- net/raw_cb.h23 Jan 2017 16:31:24 -  1.11
+++ net/raw_cb.h27 May 2017 19:36:17 -
@@ -40,7 +40,6 @@
  * to tie a socket to the generic raw interface.
  */
 struct rawcb {
-   LIST_ENTRY(rawcb) rcb_list; /* doubly linked list */
struct  socket *rcb_socket; /* back pointer to socket */
struct  sockaddr *rcb_faddr;/* destination address */
struct  sockaddr *rcb_laddr;/* socket's address */
@@ -54,8 +53,6 @@ struct rawcb {
 #defineRAWRCVQ 8192
 
 #ifdef _KERNEL
-
-extern LIST_HEAD(rawcbhead, rawcb) rawcb;  /* head of list */
 
 #definesotorawcb(so)   ((struct rawcb *)(so)->so_pcb)
 int raw_attach(struct socket *, int);
Index: net/raw_usrreq.c
===
RCS file: /cvs/src/sys/net/raw_usrreq.c,v
retrieving revision 1.31
diff -u -p -r1.31 raw_usrreq.c
--- net/raw_usrreq.c13 Mar 2017 20:18:21 -  1.31
+++ net/raw_usrreq.c28 May 2017 07:32:16 -
@@ -45,15 +45,6 @@
 #include 
 
 #include 
-/*
- * Initialize raw connection block q.
- */
-void
-raw_init(void)
-{
-
-   LIST_INIT();
-}
 
 int
 raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
@@ -71,7 +62,7 @@ raw_usrreq(struct socket *so, int req, s
m_freem(m);
return (EOPNOTSUPP);
}
-   if (rp == 0) {
+   if (rp == NULL) {
m_freem(m);
return (EINVAL);
}
@@ -81,10 +72,6 @@ raw_usrreq(struct socket *so, int req, s
 * Flush data or not depending on the options.
 */
case PRU_DETACH:
-   if (rp == 0) {
-   error = ENOTCONN;
-   break;
-   }
raw_detach(rp);
break;
 
Index: net/rtsock.c
===
RCS file: /cvs/src/sys/net/rtsock.c,v
retrieving revision 1.237
diff -u -p -r1.237 rtsock.c
--- net/rtsock.c19 Apr 2017 15:21:54 -  1.237
+++ net/rtsock.c29 May 2017 08:41:01 -
@@ -70,6 +70,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -98,6 +99,9 @@ struct walkarg {
caddr_t w_where, w_tmem;
 };
 
+void   route_prinit(void);
+void   route_ref(void *, void *);
+void   route_unref(void *, void *);
 introute_output(struct mbuf *, struct socket *, struct sockaddr *,
struct mbuf *);
 introute_ctloutput(int, struct socket 

Re: shorten ifconfig output for vnetids and parent interfaces

2017-05-29 Thread Theo de Raadt
> > -   vnetid: 7
> > -   parent: ix1
> > +   encap: vnetid: 7 parent: ix1
> >=20
> 
> The repeated colons for keys after encap: are unusual for ifconfig output, c=
> ould you just skip them like the following:
> 
> encap: vnetid 7 parent ix1

true



Re: shorten ifconfig output for vnetids and parent interfaces

2017-05-29 Thread Reyk Floeter

> Am 29.05.2017 um 07:34 schrieb David Gwynne :
> 
> this rolls vnetid and parent into a single encap line in ifconfig.
> 
> eg:
> 
> -   vnetid: 7
> -   parent: ix1
> +   encap: vnetid: 7 parent: ix1
> 

The repeated colons for keys after encap: are unusual for ifconfig output, 
could you just skip them like the following:

encap: vnetid 7 parent ix1

Reyk

> after this i would like to get rid of the vlan compat goo.
> 
> ok?
> 
> Index: ifconfig.c
> ===
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.340
> diff -u -p -r1.340 ifconfig.c
> --- ifconfig.c21 Mar 2017 07:24:36 -1.340
> +++ ifconfig.c29 May 2017 03:29:09 -
> @@ -153,6 +153,8 @@ intshownet80211chans;
> intshownet80211nodes;
> intshowclasses;
> 
> +struct ifencap;
> +
> voidnotealias(const char *, int);
> voidsetifaddr(const char *, int);
> voidsetifrtlabel(const char *, int);
> @@ -186,10 +188,11 @@ voidsettunnelinst(const char *, int);
> voidsettunnelttl(const char *, int);
> voidsetvnetid(const char *, int);
> voiddelvnetid(const char *, int);
> -voidgetvnetid(void);
> +voidgetvnetid(struct ifencap *);
> voidsetifparent(const char *, int);
> voiddelifparent(const char *, int);
> -voidgetifparent(void);
> +voidgetifparent(struct ifencap *);
> +voidgetencap(void);
> voidsetia6flags(const char *, int);
> voidsetia6pltime(const char *, int);
> voidsetia6vltime(const char *, int);
> @@ -2999,8 +3002,7 @@ status(int link, struct sockaddr_dl *sdl
>printf("\tpatch: %s\n", ifname);
> #endif
>vlan_status();
> -getvnetid();
> -getifparent();
> +getencap();
> #ifndef SMALL
>carp_status();
>pfsync_status();
> @@ -3617,6 +3619,22 @@ setmpwcontrolword(const char *value, int
> }
> #endif /* SMALL */
> 
> +struct ifencap {
> +unsigned int ife_flags;
> +#define IFE_VNETID_MASK0xf
> +#define IFE_VNETID_NOPE0x0
> +#define IFE_VNETID_NONE0x1
> +#define IFE_VNETID_ANY0x2
> +#define IFE_VNETID_SET0x3
> +int64_t ife_vnetid;
> +
> +#define IFE_PARENT_MASK0xf0
> +#define IFE_PARENT_NOPE0x00
> +#define IFE_PARENT_NONE0x10
> +#define IFE_PARENT_SET0x20
> +charife_parent[IFNAMSIZ];
> +};
> +
> void
> setvnetid(const char *id, int param)
> {
> @@ -3647,7 +3665,7 @@ delvnetid(const char *ignored, int alsoi
> }
> 
> void
> -getvnetid(void)
> +getvnetid(struct ifencap *ife)
> {
>if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >=
>sizeof(ifr.ifr_name))
> @@ -3657,17 +3675,17 @@ getvnetid(void)
>if (errno != EADDRNOTAVAIL)
>return;
> 
> -printf("\tvnetid: none\n");
> -
> +ife->ife_flags |= IFE_VNETID_NONE;
>return;
>}
> 
>if (ifr.ifr_vnetid < 0) {
> -printf("\tvnetid: any\n");
> +ife->ife_flags |= IFE_VNETID_ANY;
>return;
>}
> 
> -printf("\tvnetid: %lld\n", ifr.ifr_vnetid);
> +ife->ife_flags |= IFE_VNETID_SET;
> +ife->ife_vnetid = ifr.ifr_vnetid;
> }
> 
> void
> @@ -3696,10 +3714,9 @@ delifparent(const char *ignored, int als
> }
> 
> void
> -getifparent(void)
> +getifparent(struct ifencap *ife)
> {
>struct if_parent ifp;
> -const char *parent = "none";
> 
>memset(, 0, sizeof(ifp));
>if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >=
> @@ -3709,10 +3726,50 @@ getifparent(void)
>if (ioctl(s, SIOCGIFPARENT, (caddr_t)) == -1) {
>if (errno != EADDRNOTAVAIL)
>return;
> -} else
> -parent = ifp.ifp_parent;
> 
> -printf("\tparent: %s\n", parent);
> +ife->ife_flags |= IFE_PARENT_NONE;
> +} else {
> +memcpy(ife->ife_parent, ifp.ifp_parent,
> +sizeof(ife->ife_parent));
> +ife->ife_flags |= IFE_PARENT_SET;
> +}
> +}
> +
> +void
> +getencap(void)
> +{
> +struct ifencap ife = { .ife_flags = 0 };
> +
> +getvnetid();
> +getifparent();
> +
> +if (ife.ife_flags == 0)
> +return;
> +
> +printf("\tencap:");
> +
> +switch (ife.ife_flags & IFE_VNETID_MASK) {
> +case IFE_VNETID_NONE:
> +printf(" vnetid: none");
> +break;
> +case IFE_VNETID_ANY:
> +printf(" vnetid: any");
> +break;
> +case IFE_VNETID_SET:
> +printf(" vnetid: %lld", ife.ife_vnetid);
> +break;
> +}
> +
> +switch (ife.ife_flags & IFE_PARENT_MASK) {
> +case IFE_PARENT_NONE:
> +printf(" parent: none");
> +break;
> +case IFE_PARENT_SET:
> +printf(" parent: %s", ife.ife_parent);
> +break;
> +}
> +
> +printf("\n");
> }
> 
> static int __tag = 0;
> 



Re: shorten ifconfig output for vnetids and parent interfaces

2017-05-29 Thread Sebastian Benoit
David Gwynne(da...@gwynne.id.au) on 2017.05.29 15:34:51 +1000:
> this rolls vnetid and parent into a single encap line in ifconfig.
> 
> eg:
> 
> -   vnetid: 7
> -   parent: ix1
> +   encap: vnetid: 7 parent: ix1
> 
> after this i would like to get rid of the vlan compat goo.
> 
> ok?

yes, one whitespace below

> 
> Index: ifconfig.c
> ===
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.340
> diff -u -p -r1.340 ifconfig.c
> --- ifconfig.c21 Mar 2017 07:24:36 -  1.340
> +++ ifconfig.c29 May 2017 03:29:09 -
> @@ -153,6 +153,8 @@ int   shownet80211chans;
>  int  shownet80211nodes;
>  int  showclasses;
>  
> +struct ifencap;
> +
>  void notealias(const char *, int);
>  void setifaddr(const char *, int);
>  void setifrtlabel(const char *, int);
> @@ -186,10 +188,11 @@ voidsettunnelinst(const char *, int);
>  void settunnelttl(const char *, int);
>  void setvnetid(const char *, int);
>  void delvnetid(const char *, int);
> -void getvnetid(void);
> +void getvnetid(struct ifencap *);
>  void setifparent(const char *, int);
>  void delifparent(const char *, int);
> -void getifparent(void);
> +void getifparent(struct ifencap *);
> +void getencap(void);
>  void setia6flags(const char *, int);
>  void setia6pltime(const char *, int);
>  void setia6vltime(const char *, int);
> @@ -2999,8 +3002,7 @@ status(int link, struct sockaddr_dl *sdl
>   printf("\tpatch: %s\n", ifname);
>  #endif
>   vlan_status();
> - getvnetid();
> - getifparent();
> + getencap();
>  #ifndef SMALL
>   carp_status();
>   pfsync_status();
> @@ -3617,6 +3619,22 @@ setmpwcontrolword(const char *value, int
>  }
>  #endif /* SMALL */
>  
> +struct ifencap {
> +unsigned int  ife_flags;

spaces up front

> +#define IFE_VNETID_MASK  0xf
> +#define IFE_VNETID_NOPE  0x0
> +#define IFE_VNETID_NONE  0x1
> +#define IFE_VNETID_ANY   0x2
> +#define IFE_VNETID_SET   0x3
> + int64_t  ife_vnetid;
> +
> +#define IFE_PARENT_MASK  0xf0
> +#define IFE_PARENT_NOPE  0x00
> +#define IFE_PARENT_NONE  0x10
> +#define IFE_PARENT_SET   0x20
> + charife_parent[IFNAMSIZ];
> +};
> +
>  void
>  setvnetid(const char *id, int param)
>  {
> @@ -3647,7 +3665,7 @@ delvnetid(const char *ignored, int alsoi
>  }
>  
>  void
> -getvnetid(void)
> +getvnetid(struct ifencap *ife)
>  {
>   if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >=
>   sizeof(ifr.ifr_name))
> @@ -3657,17 +3675,17 @@ getvnetid(void)
>   if (errno != EADDRNOTAVAIL)
>   return;
>  
> - printf("\tvnetid: none\n");
> -
> + ife->ife_flags |= IFE_VNETID_NONE;
>   return;
>   }
>  
>   if (ifr.ifr_vnetid < 0) {
> - printf("\tvnetid: any\n");
> + ife->ife_flags |= IFE_VNETID_ANY;
>   return;
>   }
>  
> - printf("\tvnetid: %lld\n", ifr.ifr_vnetid);
> + ife->ife_flags |= IFE_VNETID_SET;
> + ife->ife_vnetid = ifr.ifr_vnetid;
>  }
>  
>  void
> @@ -3696,10 +3714,9 @@ delifparent(const char *ignored, int als
>  }
>  
>  void
> -getifparent(void)
> +getifparent(struct ifencap *ife)
>  {
>   struct if_parent ifp;
> - const char *parent = "none";
>  
>   memset(, 0, sizeof(ifp));
>   if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >=
> @@ -3709,10 +3726,50 @@ getifparent(void)
>   if (ioctl(s, SIOCGIFPARENT, (caddr_t)) == -1) {
>   if (errno != EADDRNOTAVAIL)
>   return;
> - } else
> - parent = ifp.ifp_parent;
>  
> - printf("\tparent: %s\n", parent);
> + ife->ife_flags |= IFE_PARENT_NONE;
> + } else {
> + memcpy(ife->ife_parent, ifp.ifp_parent,
> + sizeof(ife->ife_parent));
> + ife->ife_flags |= IFE_PARENT_SET;
> + }
> +}
> +
> +void
> +getencap(void)
> +{
> + struct ifencap ife = { .ife_flags = 0 };
> +
> + getvnetid();
> + getifparent();
> +
> + if (ife.ife_flags == 0)
> + return;
> +
> + printf("\tencap:");
> +
> + switch (ife.ife_flags & IFE_VNETID_MASK) {
> + case IFE_VNETID_NONE:
> + printf(" vnetid: none");
> + break;
> + case IFE_VNETID_ANY:
> + printf(" vnetid: any");
> + break;
> + case IFE_VNETID_SET:
> + printf(" vnetid: %lld", ife.ife_vnetid);
> + break;
> + }
> +
> + switch (ife.ife_flags & IFE_PARENT_MASK) {
> + case IFE_PARENT_NONE:
> + printf(" parent: none");
> + break;
> + case IFE_PARENT_SET:
> + printf(" parent: %s", ife.ife_parent);
> + break;
> + }
> +
> + printf("\n");
>  }
>  
>  static int __tag = 0;
> 



Re: [PATCH] ntpd: allow to specify a source IP address for outgoing queries

2017-05-29 Thread Henning Brauer
* Sebastian Benoit  [2017-05-28 22:52]:
> which makes me think:
> would a global local-address be good enough?

I think so. This is a kinda weird/rare case.

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services GmbH, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS. Virtual & Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/



Re: slaacd(8): early testing now possible

2017-05-29 Thread Florian Obser
as naddy found out the hard way we also need to stop the kernel from
sending router solicitations or things get confused rather quickly,
this is better:

diff --git sys/netinet6/nd6_rtr.c sys/netinet6/nd6_rtr.c
index 7fc1e36e0ec..89c6d1dd078 100644
--- sys/netinet6/nd6_rtr.c
+++ sys/netinet6/nd6_rtr.c
@@ -282,6 +282,7 @@ nd6_rs_output(struct ifnet* ifp, struct in6_ifaddr *ia6)
 void
 nd6_rs_output_set_timo(int timeout)
 {
+   return;
nd6_rs_output_timeout = timeout;
timeout_add_sec(_rs_output_timer, nd6_rs_output_timeout);
 }
@@ -381,6 +382,8 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len)
if (ifp == NULL)
goto freeit;
 
+   goto freeit;
+
/* We accept RAs only if inet6 autoconf is enabled  */
if (!(ifp->if_xflags & IFXF_AUTOCONF6))
goto freeit;


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