Re: locate(1): small cleanup

2015-10-23 Thread Michael McConville
Michael Reed wrote:
> - mmap support was recently made the default, but the includes were
>   left unsorted; this diff deals with that
> 
> - remove optarg & optind declarations as unistd.h already does this
> 
> - remove `#ifdef sun' block: htohl() isn't used anywhere here, although
>   ntohl() is in util.c (perhaps endian.h should be included there).
>   Besides that ``grep -wR sun /usr/include | grep define'' didn't show
>   that `sun' was being defined.

ok mmcc@

> Index: locate.c
> ===
> RCS file: /cvs/src/usr.bin/locate/locate/locate.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 locate.c
> --- locate.c  23 Oct 2015 14:16:02 -  1.29
> +++ locate.c  23 Oct 2015 20:14:45 -
> @@ -63,26 +63,21 @@
>   * in the standard 'find'.
>   */
>  
> +#include 
> +#include 
> +#include 
> +
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
> -#include 
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -
> -#ifdef sun
> -#include  /* SunOS byteorder(3) htohl(3) */
> -#endif
>  
>  #include "locate.h"
>  #include "pathnames.h"
> @@ -120,9 +115,6 @@ extern int  getwf(FILE *);
>  extern u_char   *tolower_word(u_char *);
>  extern int   check_bigram_char(int);
>  extern char  *patprep(char *);
> -
> -extern char *optarg;
> -extern int  optind;
>  
>  
>  int
> 



syslogd pledge rpath cacert

2015-10-23 Thread Alexander Bluhm
Hi,

When loading the CA certificates at startup fails, the syslogd child
tries to load the default CA file when it connects to a TLS server.
This always fails, as the child is chrooted to /var/empty.  Set the
CA storage to an empty string, to remove the pledge "rpath".

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.200
diff -u -p -r1.200 syslogd.c
--- usr.sbin/syslogd/syslogd.c  23 Oct 2015 16:28:52 -  1.200
+++ usr.sbin/syslogd/syslogd.c  23 Oct 2015 18:29:40 -
@@ -550,6 +550,7 @@ main(int argc, char *argv[])
tls_config_insecure_noverifyname(client_config);
} else {
struct stat sb;
+   int fail = 1;
 
fd = -1;
p = NULL;
@@ -567,9 +568,13 @@ main(int argc, char *argv[])
sb.st_size) == -1) {
logerrorx("tls_config_set_ca_mem");
} else {
+   fail = 0;
logdebug("CAfile %s, size %lld\n",
CAfile, sb.st_size);
}
+   /* avoid reading default certs in chroot */
+   if (fail)
+   tls_config_set_ca_mem(client_config, "", 0);
free(p);
close(fd);
}
@@ -700,7 +705,7 @@ main(int argc, char *argv[])
if (priv_init(ConfFile, NoDNS, lockpipe[1], nullfd, argv) < 0)
errx(1, "unable to privsep");
 
-   if (pledge("stdio rpath unix inet recvfd", NULL) == -1)
+   if (pledge("stdio unix inet recvfd", NULL) == -1)
err(1, "pledge");
 
/* Process is now unprivileged and inside a chroot */



unify errno messages

2015-10-23 Thread Alexander Bluhm
Hi,

Before removig nls, I would like to unify all error messages in
- include comment
- libc comment
- nls C
- man page

The EPROGUNAVAIL change is just beautification.  Any objections
against that?

ok?

bluhm

Index: sys/sys/errno.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/sys/errno.h,v
retrieving revision 1.23
diff -u -p -r1.23 errno.h
--- sys/sys/errno.h 19 Sep 2014 16:50:20 -  1.23
+++ sys/sys/errno.h 23 Oct 2015 21:41:13 -
@@ -142,7 +142,7 @@
 #defineEREMOTE 71  /* Too many levels of remote in 
path */
 #defineEBADRPC 72  /* RPC struct is bad */
 #defineERPCMISMATCH73  /* RPC version wrong */
-#defineEPROGUNAVAIL74  /* RPC prog. not avail */
+#defineEPROGUNAVAIL74  /* RPC program not available */
 #defineEPROGMISMATCH   75  /* Program version wrong */
 #defineEPROCUNAVAIL76  /* Bad procedure for program */
 #endif /* __BSD_VISIBLE */
@@ -160,9 +160,9 @@
 #defineEILSEQ  84  /* Illegal byte sequence */
 #if __BSD_VISIBLE
 #defineENOMEDIUM   85  /* No medium found */
-#defineEMEDIUMTYPE 86  /* Wrong Medium Type */
+#defineEMEDIUMTYPE 86  /* Wrong medium type */
 #endif /* __BSD_VISIBLE */
-#defineEOVERFLOW   87  /* Conversion overflow */
+#defineEOVERFLOW   87  /* Value too large to be stored in data 
type */
 #defineECANCELED   88  /* Operation canceled */
 #defineEIDRM   89  /* Identifier removed */
 #defineENOMSG  90  /* No message of desired type */
Index: lib/libc/gen/errlist.c
===
RCS file: /data/mirror/openbsd/cvs/src/lib/libc/gen/errlist.c,v
retrieving revision 1.17
diff -u -p -r1.17 errlist.c
--- lib/libc/gen/errlist.c  19 Sep 2015 04:02:21 -  1.17
+++ lib/libc/gen/errlist.c  23 Oct 2015 21:20:39 -
@@ -122,7 +122,7 @@ const char *const sys_errlist[] = {
"Too many levels of remote in path",/* 71 - EREMOTE */
"RPC struct is bad",/* 72 - EBADRPC */
"RPC version wrong",/* 73 - ERPCMISMATCH */
-   "RPC prog. not avail",  /* 74 - EPROGUNAVAIL */
+   "RPC program not available",/* 74 - EPROGUNAVAIL */
"Program version wrong",/* 75 - EPROGMISMATCH */
"Bad procedure for program",/* 76 - EPROCUNAVAIL */
 
Index: lib/libc/nls/C.msg
===
RCS file: /data/mirror/openbsd/cvs/src/lib/libc/nls/C.msg,v
retrieving revision 1.2
diff -u -p -r1.2 C.msg
--- lib/libc/nls/C.msg  24 Nov 2009 09:22:22 -  1.2
+++ lib/libc/nls/C.msg  23 Oct 2015 21:22:04 -
@@ -118,7 +118,7 @@ $ ESHUTDOWN
 $ ETOOMANYREFS
 59 Too many references: can't splice
 $ ETIMEDOUT
-60 Connection timed out
+60 Operation timed out
 $ ECONNREFUSED
 61 Connection refused
 $ ELOOP
@@ -136,7 +136,7 @@ $ EPROCLIM
 $ EUSERS
 68 Too many users
 $ EDQUOT
-69 Disc quota exceeded
+69 Disk quota exceeded
 $ ESTALE
 70 Stale NFS file handle
 $ EREMOTE
@@ -146,7 +146,7 @@ $ EBADRPC
 $ ERPCMISMATCH
 73 RPC version wrong
 $ EPROGUNAVAIL
-74 RPC prog. not avail
+74 RPC program not available
 $ EPROGMISMATCH
 75 Program version wrong
 $ EPROCUNAVAIL
Index: lib/libc/sys/intro.2
===
RCS file: /data/mirror/openbsd/cvs/src/lib/libc/sys/intro.2,v
retrieving revision 1.59
diff -u -p -r1.59 intro.2
--- lib/libc/sys/intro.228 Jul 2015 22:48:31 -  1.59
+++ lib/libc/sys/intro.223 Oct 2015 21:23:10 -
@@ -349,7 +349,7 @@ was supplied to a remove directory or re
 .It Er 67 EPROCLIM Em "Too many processes" .
 .It Er 68 EUSERS Em "Too many users" .
 The quota system ran out of table entries.
-.It Er 69 EDQUOT Em "Disc quota exceeded" .
+.It Er 69 EDQUOT Em "Disk quota exceeded" .
 A
 .Xr write 2
 to an ordinary file, the creation of a directory or symbolic link,
@@ -369,7 +369,7 @@ information was unsuccessful.
 The version of
 .Xr rpc 3
 on the remote peer is not compatible with the local version.
-.It Er 74 EPROGUNAVAIL Em "RPC prog. not avail" .
+.It Er 74 EPROGUNAVAIL Em "RPC program not available" .
 The requested
 .Xr rpc 3
 program is not registered on the remote host.



Re: does anoybody use ul?

2015-10-23 Thread Ingo Schwarze
Hi Christian,

Christian Weisgerber wrote on Fri, Oct 23, 2015 at 11:26:00PM +0200:
> Ingo Schwarze:
 
>>  - The FreeBSD change with wchar_t (+70 -44 lines) seems
>>like overkill to me.

> Wait until you've added double-width characters

I tested double-width characters (both bold and underlined),
they work just fine.

> and correct tab handling, which the FreeBSD code supports.

What do you consider broken with respect to tabs?

Yours,
  Ingo



Re: WAPBL implementation

2015-10-23 Thread Ted Unangst
Walter Neto wrote:
> Hi guys, sorry for the inconvenience.
> 
> Once you only have use git at console, cvs is nightmare :(
> 
> But I am learning :)

this indeed looks a lot better. although it's quite the diff to review.

some brave soul testing of this might be appreciated.



Re: does anoybody use ul?

2015-10-23 Thread Christian Weisgerber
Ingo Schwarze:

>  - The FreeBSD change with wchar_t (+70 -44 lines) seems
>like overkill to me.

Wait until you've added double-width characters and correct tab
handling, which the FreeBSD code supports.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: does anoybody use ul?

2015-10-23 Thread Vadim Zhukov
2015-10-23 23:00 GMT+02:00 Ingo Schwarze :
> Hi Ted,
>
> Ted Unangst wrote on Fri, Oct 23, 2015 at 09:38:22AM -0400:
>
>> so that works with the diff below.
>
> I agree with the direction for this kind of tool, at least for now.
> However, your diff has a few issues, so i improved it, see below.
>
> Any OKs or vetos?
>
> Ted, in case you want to commit, the version below is obviously
> OK schwarze@.
>
>> i'm not sure how far down this road we need
>> to travel, but i figure it's worth a little exploration.
>
> I think making any valid sequence of single-codepoint characters
> work is reasonable, in particular if it just takes 15 lines
> of additional code in a utility of 500 lines.
>
>
> Changes with respect to tedu@'s version:
>
>  * chunk 151 and chunk 158: unchanged
>  * chunk 211: new chunk
>Required for the sequence underscore, backspace, multibyte character:
>Mark all the bytes underlined, not just the first one, or the
>multibyte character will be broken.
>  * chunk 237 part 1: new change
>Required such that bytes with the high bit set compare equal
>even on signed char architectures.
>  * chunk 237 part 2: style tweak
>Actually use the shiny new isu8cont() function,
>do not inline a copy of its code.
>
>
> Aspects not solved and other comments:
>
>  - The new code runs always.
>In a POSIX locale, text files are not supposed to contain bytes
>with the high bit set, so it is undefined in the first place
>what ul(1) should do.  Of course, we could artificially add yet
>more code (heavy-weight code with setlocale(3) and nl_langinfo(3),
>actually) to gratuitiously mess the file up, but i consider it
>more useful to treat UTF-8 gracefully even when the locale is
>not set, such that ul(1) output is predictable independently of
>the user's locale.

Well, we could create another helper, like 'isutf8on()', and just call
it when needed. So the actual logic won't be hurt too much... I won't
insist hard on that, though.

>  - character, backspace, different character
>This is not valid backspace encoding for bold or italic,
>so ul(1) is not supposed to handle it.  But at least, it
>no longer produces invalid UTF-8 even in that case.
>  - The FreeBSD change with wchar_t (+70 -44 lines) seems
>like overkill to me.
>  - Nothing changes with respect to tabs.
>To ul(1), tabs just mean "add enough blanks to advance to the
>next character position that is a multiple of eight".  A backspace
>will then remove the last one of them.  The usefulness of this
>feature may be argued, but that's unrelated to UTF-8.
>
>
> Index: ul.c
> ===
> RCS file: /cvs/src/usr.bin/ul/ul.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 ul.c
> --- ul.c10 Oct 2015 16:15:03 -  1.19
> +++ ul.c23 Oct 2015 20:19:17 -
> @@ -151,6 +151,12 @@ main(int argc, char *argv[])
> exit(0);
>  }
>
> +int
> +isu8cont(unsigned char c)
> +{
> +   return (c & (0x80 | 0x40)) == 0x80;
> +}
> +
>  void
>  mfilter(FILE *f)
>  {
> @@ -158,8 +164,11 @@ mfilter(FILE *f)
>
> while ((c = getc(f)) != EOF && col < MAXBUF) switch(c) {
> case '\b':
> -   if (col > 0)
> +   while (col > 0) {
> col--;
> +   if (!isu8cont(obuf[col].c_char))
> +   break;
> +   }
> continue;
> case '\t':
> col = (col+8) & ~07;
> @@ -211,9 +220,13 @@ mfilter(FILE *f)
> continue;
>
> case '_':
> -   if (obuf[col].c_char)
> +   if (obuf[col].c_char != '\0') {
> obuf[col].c_mode |= UNDERL | mode;
> -   else
> +   if (obuf[col].c_char & 0x80)
> +   while (col < maxcol &
> +   isu8cont(obuf[col+1].c_char))
> +   obuf[++col].c_mode |= UNDERL | mode;
> +   } else
> obuf[col].c_char = '_';

Shouldn't the last part be something like that instead?

else {
 while (col < maxcol & isu8cont(obuf[col+1].c_char))
obuf[++col].c_mode |= UNDERL | mode;
obuf[col].c_char = '_';
}

I could be easy wrong, still trying to understand the intention behind
the original code...

> /* FALLTHROUGH */
> case ' ':
> @@ -237,10 +250,12 @@ mfilter(FILE *f)
> } else if (obuf[col].c_char == '_') {
> obuf[col].c_char = c;
> obuf[col].c_mode |= UNDERL|mode;
> -   } else if (obuf[col].c_char == c)
> +   } else if (obuf[col].c_char == (char)c)

Did you actuall wanted "(unsigned char)c" here?

> obuf[col].c_mode |= BOLD|mode;
> else
> obuf[col].c_mode = mode;
> + 

Re: diff tmpdir

2015-10-23 Thread Todd C. Miller
On Fri, 23 Oct 2015 14:22:34 -0400, "Ted Unangst" wrote:

> this burns the tmpdir out of diff, so as to let pledge tmppath work a little
> better.

OK millert@ since POSIX doesn't require TMPDIR.

 - todd



Re: support for malloc allocation canaries

2015-10-23 Thread Daniel Micay
On 23/10/15 07:22 AM, Janne Johansson wrote:
> With this patch on -current and
> ln -sf CJ /etc/malloc.conf
> a lot of things stopped working, like "man ls" and "tmux".
> With only C or only J, the system seems to work ok, but with both it
> doesn't.
> Will check the resulting core files.
> ntpd and tmux both bombed out on memset inside realloc if I read the
> dumps ok:

Thanks for testing it. I oversimplified handling the canary padding in
the orealloc malloc_junk == 2 branch while trying to clean up the code.

This should work properly:

diff --git a/stdlib/malloc.c b/stdlib/malloc.c
index 424dd77..567e56d 100644
--- a/stdlib/malloc.c
+++ b/stdlib/malloc.c
@@ -185,12 +185,14 @@ struct malloc_readonly {
int malloc_move;/* move allocations to end of page? */
int malloc_realloc; /* always realloc? */
int malloc_xmalloc; /* xmalloc behaviour? */
+   size_t  malloc_canaries;/* use canaries after chunks? */
size_t  malloc_guard;   /* use guard pages after allocations? */
u_int   malloc_cache;   /* free pages we cache */
 #ifdef MALLOC_STATS
int malloc_stats;   /* dump statistics at end */
 #endif
u_int32_t malloc_canary;/* Matched against ones in malloc_pool 
*/
+   uintptr_t malloc_chunk_canary;
 };
 
 /* This object is mapped PROT_READ after initialisation to prevent tampering */
@@ -526,6 +528,12 @@ omalloc_init(struct dir_info **dp)
case 'A':
mopts.malloc_abort = 1;
break;
+   case 'c':
+   mopts.malloc_canaries = 0;
+   break;
+   case 'C':
+   mopts.malloc_canaries = sizeof(void *);
+   break;
 #ifdef MALLOC_STATS
case 'd':
mopts.malloc_stats = 0;
@@ -619,6 +627,9 @@ omalloc_init(struct dir_info **dp)
while ((mopts.malloc_canary = arc4random()) == 0)
;
 
+   arc4random_buf(&mopts.malloc_chunk_canary,
+   sizeof(mopts.malloc_chunk_canary));
+
/*
 * Allocate dir_info with a guard page on either side. Also
 * randomise offset inside the page at which the dir_info
@@ -984,8 +995,15 @@ malloc_bytes(struct dir_info *d, size_t size, void *f)
k += (lp - bp->bits) * MALLOC_BITS;
k <<= bp->shift;
 
+   if (mopts.malloc_canaries && bp->size > 0) {
+   char *end = (char *)bp->page + k + bp->size;
+   uintptr_t *canary = (uintptr_t *)(end - mopts.malloc_canaries);
+   *canary = mopts.malloc_chunk_canary ^ hash(canary);
+   }
+
if (mopts.malloc_junk == 2 && bp->size > 0)
-   memset((char *)bp->page + k, SOME_JUNK, bp->size);
+   memset((char *)bp->page + k, SOME_JUNK,
+   bp->size - mopts.malloc_canaries);
return ((char *)bp->page + k);
 }
 
@@ -999,6 +1017,13 @@ find_chunknum(struct dir_info *d, struct region_info *r, 
void *ptr)
if (info->canary != d->canary1)
wrterror("chunk info corrupted", NULL);
 
+   if (mopts.malloc_canaries && info->size > 0) {
+   char *end = (char *)ptr + info->size;
+   uintptr_t *canary = (uintptr_t *)(end - mopts.malloc_canaries);
+   if (*canary != (mopts.malloc_chunk_canary ^ hash(canary)))
+   wrterror("chunk canary corrupted", ptr);
+   }
+
/* Find the chunk number on the page */
chunknum = ((uintptr_t)ptr & MALLOC_PAGEMASK) >> info->shift;
 
@@ -1121,7 +1146,7 @@ omalloc(size_t sz, int zero_fill, void *f)
/* takes care of SOME_JUNK */
p = malloc_bytes(pool, sz, f);
if (zero_fill && p != NULL && sz > 0)
-   memset(p, 0, sz);
+   memset(p, 0, sz - mopts.malloc_canaries);
}
 
return p;
@@ -1176,6 +1201,8 @@ malloc(size_t size)
malloc_recurse();
return NULL;
}
+   if (size > 0 && size <= MALLOC_MAXCHUNK)
+   size += mopts.malloc_canaries;
r = omalloc(size, 0, CALLER);
malloc_active--;
_MALLOC_UNLOCK();
@@ -1242,7 +1269,7 @@ ofree(void *p)
int i;
 
if (mopts.malloc_junk && sz > 0)
-   memset(p, SOME_FREEJUNK, sz);
+   memset(p, SOME_FREEJUNK, sz - mopts.malloc_canaries);
if (!mopts.malloc_freenow) {
if (find_chunknum(pool, r, p) == -1)
return;
@@ -1386,16 +1413,25 @@ gotit:
}
}
if (newsz <= oldsz && newsz > oldsz / 2 && !mopts.malloc_realloc) {
-   if (mopts.malloc_junk == 2 && newsz > 0)
-   

Re: does anoybody use ul?

2015-10-23 Thread Ingo Schwarze
Hi Ted,

Ted Unangst wrote on Fri, Oct 23, 2015 at 09:38:22AM -0400:

> so that works with the diff below.

I agree with the direction for this kind of tool, at least for now.
However, your diff has a few issues, so i improved it, see below.

Any OKs or vetos?

Ted, in case you want to commit, the version below is obviously
OK schwarze@.

> i'm not sure how far down this road we need
> to travel, but i figure it's worth a little exploration.

I think making any valid sequence of single-codepoint characters
work is reasonable, in particular if it just takes 15 lines
of additional code in a utility of 500 lines.


Changes with respect to tedu@'s version:

 * chunk 151 and chunk 158: unchanged
 * chunk 211: new chunk
   Required for the sequence underscore, backspace, multibyte character:
   Mark all the bytes underlined, not just the first one, or the
   multibyte character will be broken.
 * chunk 237 part 1: new change
   Required such that bytes with the high bit set compare equal
   even on signed char architectures.
 * chunk 237 part 2: style tweak
   Actually use the shiny new isu8cont() function,
   do not inline a copy of its code.


Aspects not solved and other comments:

 - The new code runs always.
   In a POSIX locale, text files are not supposed to contain bytes
   with the high bit set, so it is undefined in the first place
   what ul(1) should do.  Of course, we could artificially add yet
   more code (heavy-weight code with setlocale(3) and nl_langinfo(3),
   actually) to gratuitiously mess the file up, but i consider it
   more useful to treat UTF-8 gracefully even when the locale is
   not set, such that ul(1) output is predictable independently of
   the user's locale.
 - character, backspace, different character
   This is not valid backspace encoding for bold or italic,
   so ul(1) is not supposed to handle it.  But at least, it
   no longer produces invalid UTF-8 even in that case.
 - The FreeBSD change with wchar_t (+70 -44 lines) seems
   like overkill to me.
 - Nothing changes with respect to tabs.
   To ul(1), tabs just mean "add enough blanks to advance to the
   next character position that is a multiple of eight".  A backspace
   will then remove the last one of them.  The usefulness of this
   feature may be argued, but that's unrelated to UTF-8.


Index: ul.c
===
RCS file: /cvs/src/usr.bin/ul/ul.c,v
retrieving revision 1.19
diff -u -p -r1.19 ul.c
--- ul.c10 Oct 2015 16:15:03 -  1.19
+++ ul.c23 Oct 2015 20:19:17 -
@@ -151,6 +151,12 @@ main(int argc, char *argv[])
exit(0);
 }
 
+int
+isu8cont(unsigned char c)
+{
+   return (c & (0x80 | 0x40)) == 0x80;
+}
+
 void
 mfilter(FILE *f)
 {
@@ -158,8 +164,11 @@ mfilter(FILE *f)
 
while ((c = getc(f)) != EOF && col < MAXBUF) switch(c) {
case '\b':
-   if (col > 0)
+   while (col > 0) {
col--;
+   if (!isu8cont(obuf[col].c_char))
+   break;
+   }
continue;
case '\t':
col = (col+8) & ~07;
@@ -211,9 +220,13 @@ mfilter(FILE *f)
continue;
 
case '_':
-   if (obuf[col].c_char)
+   if (obuf[col].c_char != '\0') {
obuf[col].c_mode |= UNDERL | mode;
-   else
+   if (obuf[col].c_char & 0x80)
+   while (col < maxcol &
+   isu8cont(obuf[col+1].c_char))
+   obuf[++col].c_mode |= UNDERL | mode;
+   } else
obuf[col].c_char = '_';
/* FALLTHROUGH */
case ' ':
@@ -237,10 +250,12 @@ mfilter(FILE *f)
} else if (obuf[col].c_char == '_') {
obuf[col].c_char = c;
obuf[col].c_mode |= UNDERL|mode;
-   } else if (obuf[col].c_char == c)
+   } else if (obuf[col].c_char == (char)c)
obuf[col].c_mode |= BOLD|mode;
else
obuf[col].c_mode = mode;
+   if (col > 0 && isu8cont(c))
+   obuf[col].c_mode = obuf[col - 1].c_mode;
col++;
if (col > maxcol)
maxcol = col;



locate(1): small cleanup

2015-10-23 Thread Michael Reed
- mmap support was recently made the default, but the includes were
  left unsorted; this diff deals with that

- remove optarg & optind declarations as unistd.h already does this

- remove `#ifdef sun' block: htohl() isn't used anywhere here, although
  ntohl() is in util.c (perhaps endian.h should be included there).
  Besides that ``grep -wR sun /usr/include | grep define'' didn't show
  that `sun' was being defined.



Index: locate.c
===
RCS file: /cvs/src/usr.bin/locate/locate/locate.c,v
retrieving revision 1.29
diff -u -p -r1.29 locate.c
--- locate.c23 Oct 2015 14:16:02 -  1.29
+++ locate.c23 Oct 2015 20:14:45 -
@@ -63,26 +63,21 @@
  * in the standard 'find'.
  */
 
+#include 
+#include 
+#include 
+
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-
-
-#ifdef sun
-#include  /* SunOS byteorder(3) htohl(3) */
-#endif
 
 #include "locate.h"
 #include "pathnames.h"
@@ -120,9 +115,6 @@ extern int  getwf(FILE *);
 extern u_char   *tolower_word(u_char *);
 extern int check_bigram_char(int);
 extern char*patprep(char *);
-
-extern char *optarg;
-extern int  optind;
 
 
 int



Re: catopen/catgets: out of boundary access

2015-10-23 Thread Tobias Stoeckmann
On Fri, Oct 23, 2015 at 09:19:34PM +0200, Stefan Sperling wrote:
> Now that this is committed, do you intend to audit the runes code as
> well? :-)

Hah, yeah that's the next logical step to do. Except you are faster
than me, then I would probably okay it. ;)



Re: does anoybody use ul?

2015-10-23 Thread Vadim Zhukov
2015-10-23 15:38 GMT+02:00 Ted Unangst :
> Christian Weisgerber wrote:
>> Ted Unangst:
>>
>> > --- ul.c10 Oct 2015 16:15:03 -  1.19
>> > +++ ul.c23 Oct 2015 10:29:43 -
>> > @@ -241,6 +241,8 @@ mfilter(FILE *f)
>> > obuf[col].c_mode |= BOLD|mode;
>> > else
>> > obuf[col].c_mode = mode;
>> > +   if ((c & (0x80 | 0x40)) == 0x80 && col > 0)
>> > +   obuf[col].c_mode = obuf[col - 1].c_mode;
>> > col++;
>> > if (col > maxcol)
>> > maxcol = col;
>>
>> That doesn't quite work.  Check out this:
>>
>> mandoc /usr/share/man/man1/ksh.1 | sed -n 1185,1190p | ul
>
> so that works with the diff below. i'm not sure how far down this road we need
> to travel, but i figure it's worth a little exploration.
>
> note that i don't think this handles the case of one character, backspace, a
> different character correctly, though it can asymptotically approach
> correct with some care.
>
> Index: ul.c
> ===
> RCS file: /cvs/src/usr.bin/ul/ul.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 ul.c
> --- ul.c10 Oct 2015 16:15:03 -  1.19
> +++ ul.c23 Oct 2015 13:31:45 -
> @@ -151,6 +151,12 @@ main(int argc, char *argv[])
> exit(0);
>  }
>
> +int
> +isu8cont(unsigned char c)
> +{
> +   return (c & (0x80 | 0x40)) == 0x80;
> +}
> +
>  void
>  mfilter(FILE *f)
>  {
> @@ -158,8 +164,11 @@ mfilter(FILE *f)
>
> while ((c = getc(f)) != EOF && col < MAXBUF) switch(c) {
> case '\b':
> -   if (col > 0)
> +   while (col > 0) {
> col--;
> +   if (!isu8cont(obuf[col].c_char))
> +   break;

Should this check also be run in case of non-UTF-8 locale (read: "C" one)?

> +   }
> continue;
> case '\t':
> col = (col+8) & ~07;
> @@ -241,6 +250,8 @@ mfilter(FILE *f)
> obuf[col].c_mode |= BOLD|mode;
> else
> obuf[col].c_mode = mode;
> +   if ((c & (0x80 | 0x40)) == 0x80 && col > 0)
> +   obuf[col].c_mode = obuf[col - 1].c_mode;
> col++;
> if (col > maxcol)
> maxcol = col;
>

--
  WBR,
  Vadim Zhukov



Re: catopen/catgets: out of boundary access

2015-10-23 Thread Stefan Sperling
On Tue, Oct 06, 2015 at 12:08:42PM +0200, Tobias Stöckmann wrote:
> > On October 6, 2015 at 11:40 AM Stefan Sperling  wrote:
> > What do you think about a similar treatment for locale/rune.c?
> 
> I think you refer to _Read_RuneMagi function,
> which lacks the same input validation.
> 
> Before supplying a patch for that one, I wanted to get some feedback
> for catopen/catgets. If my approach would be wrong or not efficient
> or violating style guide, it would just double the work to maintain
> multiple patches.

Now that this is committed, do you intend to audit the runes code as
well? :-)



Re: WAPBL implementation

2015-10-23 Thread Janne Johansson
Cool. If possible, also post the diff over http with an URL or something, I
don't know if your or my mailers (and the marc.info email archive) mangled
the diff, but it was line-wrapped in a few places so I had to edit it for
it to apply nicely.


2015-10-23 21:20 GMT+02:00 Walter Neto :

> On Fri, Oct 23, 2015 at 09:06:09PM +0200, Janne Johansson wrote:
> > did you miss sys/wapbl.h ?
> >
> > cc ... -D_KERNEL -MD -MP  -c ../../../../kern/vfs_bio.c
> > ../../../../kern/vfs_bio.c:59:23: error: sys/wapbl.h: No such file or
> > directory
> > ../../../../kern/vfs_bio.c: In function 'bio_doread':
> > ../../../../kern/vfs_bio.c:358: error: 'struct vnode' has no member named
> > 'v_specmountpoint'
> >
>
> So sorry Janne, problems with my repo, I will return with the correction.
>



-- 
May the most significant bit of your life be positive.


Re: WAPBL implementation

2015-10-23 Thread Janne Johansson
did you miss sys/wapbl.h ?

cc ... -D_KERNEL -MD -MP  -c ../../../../kern/vfs_bio.c
../../../../kern/vfs_bio.c:59:23: error: sys/wapbl.h: No such file or
directory
../../../../kern/vfs_bio.c: In function 'bio_doread':
../../../../kern/vfs_bio.c:358: error: 'struct vnode' has no member named
'v_specmountpoint'


2015-10-23 17:19 GMT+02:00 Walter Neto :

> Like recommended from other developers I started developing WAPBL support
> for
> OpenBSD.
>
> Looking at NetBSD and Bitrig I mage a first funcional patch.
>
> Index: sbin/mount/mntopts.h
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount/mntopts.h,v
> retrieving revision 1.16
> diff -u -r1.16 mntopts.h
> --- sbin/mount/mntopts.h13 Jul 2014 12:01:30 -  1.16
> +++ sbin/mount/mntopts.h23 Oct 2015 15:07:07 -
> @@ -66,6 +66,8 @@
> | MFLAG_OPT }
>  #define MOPT_SOFTDEP   { "softdep",MNT_SOFTDEP, MFLAG_SET }
>
> +#define MOPT_LOG   { "log",MNT_LOG, MFLAG_SET }
> +
>  /* Control flags. */
>  #define MOPT_FORCE { "force",  MNT_FORCE, MFLAG_SET }
>  #define MOPT_UPDATE{ "update", MNT_UPDATE, MFLAG_SET }
> Index: sbin/mount/mount.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount/mount.c,v
> retrieving revision 1.60
> diff -u -r1.60 mount.c
> --- sbin/mount/mount.c  16 Jan 2015 06:39:59 -  1.60
> +++ sbin/mount/mount.c  23 Oct 2015 15:07:07 -
> @@ -94,6 +94,7 @@
> { MNT_ROOTFS,   1,  "root file system", "" },
> { MNT_SYNCHRONOUS,  0,  "synchronous",  "sync" },
> { MNT_SOFTDEP,  0,  "softdep",  "softdep"
> },
> +   { MNT_LOG,  0,  "log",  "log" },
> { 0,0,  "", "" }
>  };
>
> Index: sbin/mount_ffs/mount_ffs.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount_ffs/mount_ffs.c,v
> retrieving revision 1.21
> diff -u -r1.21 mount_ffs.c
> --- sbin/mount_ffs/mount_ffs.c  16 Jan 2015 06:39:59 -  1.21
> +++ sbin/mount_ffs/mount_ffs.c  23 Oct 2015 15:07:07 -
> @@ -53,6 +53,7 @@
> MOPT_RELOAD,
> MOPT_FORCE,
> MOPT_SOFTDEP,
> +   MOPT_LOG,
> { NULL }
>  };
>
> Index: sys/conf/GENERIC
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/conf/GENERIC,v
> retrieving revision 1.220
> diff -u -r1.220 GENERIC
> --- sys/conf/GENERIC10 Aug 2015 20:35:36 -  1.220
> +++ sys/conf/GENERIC23 Oct 2015 15:07:07 -
> @@ -43,6 +43,7 @@
>  option FIFO# FIFOs; RECOMMENDED
>  option TMPFS   # efficient memory file system
>  option FUSE# FUSE
> +option WAPBL   # Write Ahead Physical Block Logging
>
>  option SOCKET_SPLICE   # Socket Splicing for TCP and UDP
>  option TCP_SACK# Selective Acknowledgements for TCP
> Index: sys/conf/files
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/conf/files,v
> retrieving revision 1.604
> diff -u -r1.604 files
> --- sys/conf/files  9 Oct 2015 01:17:21 -   1.604
> +++ sys/conf/files  23 Oct 2015 15:07:07 -
> @@ -732,6 +732,7 @@
>  file kern/vfs_vops.c
>  file kern/vfs_vnops.c
>  file kern/vfs_getcwd.c
> +file kern/vfs_wapbl.c  wapbl
>  file kern/spec_vnops.c
>  file miscfs/deadfs/dead_vnops.c
>  file miscfs/fifofs/fifo_vnops.cfifo
> @@ -887,6 +888,7 @@
>  file ufs/ffs/ffs_vfsops.c  ffs | mfs
>  file ufs/ffs/ffs_vnops.c   ffs | mfs
>  file ufs/ffs/ffs_softdep.c ffs_softupdates
> +file ufs/ffs/ffs_wapbl.c   ffs & wapbl
>  file ufs/mfs/mfs_vfsops.c  mfs
>  file ufs/mfs/mfs_vnops.c   mfs
>  file ufs/ufs/ufs_bmap.cffs | mfs | ext2fs
> @@ -898,6 +900,7 @@
>  file ufs/ufs/ufs_quota_stub.c  ffs | mfs
>  file ufs/ufs/ufs_vfsops.c  ffs | mfs | ext2fs
>  file ufs/ufs/ufs_vnops.c   ffs | mfs | ext2fs
> +file ufs/ufs/ufs_wapbl.c   ffs & wapbl
>  file ufs/ext2fs/ext2fs_alloc.c ext2fs
>  file ufs/ext2fs/ext2fs_balloc.cext2fs
>  file ufs/ext2fs/ext2fs_bmap.c  ext2fs
> Index: sys/kern/spec_vnops.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/kern/spec_vnops.c,v
> retrieving revision 1.83
> diff -u -r1.83 spec_vnops.c
> --- sys/kern/spec_vnops.c   10 Feb 2015 21:56:09 -  1.83
> +++ sys/kern/spec_vnops.c   23 Oct 2015 15:07:07 -
> @@ -408,6 +408,10 @@
> return (EOPNOTSUPP);
>  }
>
> +#ifdef WAPBL
> +extern int ffs_wapbl_fsync_vfs(struct v

Re: Further cleanup of Russian calendars

2015-10-23 Thread Mikhail
2015-10-23 14:15 GMT+03:00 Vadim Zhukov :
> Further cleanup in Russian calendars:
>
>   * Fix #ifndef safeguards (rename/add where missing);
>   * Use consistent spelling for year when it's mentioned in day desc;
>   * Tweak some wrong casing cases;
>   * Remove calendar.msk since Moscow doesn't have summer time anymore,
> and that was the only thing this file was about;
>   * A few other corrections.
>
> Still seeking for a way to define a day with fixed shift from the year
> start: the Programmer's Day is official in Russia, happens at 256th
> day of the year, but calendar(1) handles up to 31 days per month max.
>
> Okay?
> --

Hello.

>  07/Sun+3   День металлурга
> -07/Sun+4   День Военно-Морского Флота
> +07/Sun+4   День военно-морского флота

This one should stay capitalized: http://kremlin.ru/acts/bank/23860

>  /* Август */
>  08/02  День воздушно-десантных войск России
>  08/06  Всемирный день борьбы за запрещение ядерного оружия.
>  08/09  Всемирный день коренных народов мира
> -08/22  День Государственного Флага Российской Федерации
> +08/22  День государственного флага Российской Федерации

I think "государственного" should be capitalized too (флаг is okay)

>  08/27  День российского кино
>  08/SunFirstДень железнодорожника
>  08/Sat+2   День физкультурника
>  08/Sun+2   День строителя
> -08/Sun+3   День Воздушного Флота России
> +08/Sun+3   День воздушного флота России

Same thing as with naval forces.


diff tmpdir

2015-10-23 Thread Ted Unangst
this burns the tmpdir out of diff, so as to let pledge tmppath work a little
better.


Index: diff.1
===
RCS file: /cvs/src/usr.bin/diff/diff.1,v
retrieving revision 1.44
diff -u -p -r1.44 diff.1
--- diff.1  5 Oct 2015 20:15:00 -   1.44
+++ diff.1  23 Oct 2015 18:21:27 -
@@ -425,17 +425,6 @@ As in
 identical
 pairs (where num1 = num2) are abbreviated as a single
 number.
-.Sh ENVIRONMENT
-.Bl -tag -width TMPDIR
-.It Ev TMPDIR
-If the environment variable
-.Ev TMPDIR
-exists,
-.Nm
-will use the directory specified by
-.Ev TMPDIR
-as the temporary directory.
-.El
 .Sh FILES
 .Bl -tag -width /tmp/diff. -compact
 .It Pa /tmp/diff. Ns Ar 
Index: diff.c
===
RCS file: /cvs/src/usr.bin/diff/diff.c,v
retrieving revision 1.63
diff -u -p -r1.63 diff.c
--- diff.c  9 Oct 2015 01:37:07 -   1.63
+++ diff.c  23 Oct 2015 18:21:27 -
@@ -211,13 +211,8 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
 
-   if (getenv("TMPDIR")) {
-   if (pledge("stdio rpath wpath cpath", NULL) == -1)
-   err(1, "pledge");
-   } else {
-   if (pledge("stdio rpath tmppath", NULL) == -1)
-   err(1, "pledge");
-   }
+   if (pledge("stdio rpath tmppath", NULL) == -1)
+   err(1, "pledge");
 
/*
 * Do sanity checks, fill in stb1 and stb2 and call the appropriate
Index: diffreg.c
===
RCS file: /cvs/src/usr.bin/diff/diffreg.c,v
retrieving revision 1.89
diff -u -p -r1.89 diffreg.c
--- diffreg.c   13 Oct 2015 16:37:17 -  1.89
+++ diffreg.c   23 Oct 2015 18:21:27 -
@@ -446,7 +446,7 @@ files_differ(FILE *f1, FILE *f2, int fla
 static FILE *
 opentemp(const char *file)
 {
-   char buf[BUFSIZ], *tempdir, tempfile[PATH_MAX];
+   char buf[BUFSIZ], tempfile[PATH_MAX];
ssize_t nread;
int ifd, ofd;
 
@@ -455,16 +455,7 @@ opentemp(const char *file)
else if ((ifd = open(file, O_RDONLY, 0644)) < 0)
return (NULL);
 
-   if ((tempdir = getenv("TMPDIR")) == NULL)
-   tempdir = _PATH_TMP;
-
-   if (strlcpy(tempfile, tempdir, sizeof(tempfile)) >= sizeof(tempfile) ||
-   strlcat(tempfile, "/diff.", sizeof(tempfile)) >=
-   sizeof(tempfile)) {
-   close(ifd);
-   errno = ENAMETOOLONG;
-   return (NULL);
-   }
+   (void)strlcpy(tempfile, _PATH_TMP "/diff.", sizeof(tempfile));
 
if ((ofd = mkstemp(tempfile)) < 0) {
close(ifd);



Re: WAPBL implementation

2015-10-23 Thread Ted Unangst
Pablo Méndez Hernández wrote:
> Hi,
> 
> I would say that some information about the authors is missing...

I would assume that would be included at the top of the new files, but that
does point out they're missing.

cvs add, then diff. (with -N if they still don't show up.)



Re: WAPBL implementation

2015-10-23 Thread Pablo Méndez Hernández
Hi,

I would say that some information about the authors is missing...

Regards.
Pablo
El 23/10/2015 5:25 p. m., "Walter Neto"  escribió:

> Like recommended from other developers I started developing WAPBL support
> for
> OpenBSD.
>
> Looking at NetBSD and Bitrig I mage a first funcional patch.
>
> Index: sbin/mount/mntopts.h
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount/mntopts.h,v
> retrieving revision 1.16
> diff -u -r1.16 mntopts.h
> --- sbin/mount/mntopts.h13 Jul 2014 12:01:30 -  1.16
> +++ sbin/mount/mntopts.h23 Oct 2015 15:07:07 -
> @@ -66,6 +66,8 @@
> | MFLAG_OPT }
>  #define MOPT_SOFTDEP   { "softdep",MNT_SOFTDEP, MFLAG_SET }
>
> +#define MOPT_LOG   { "log",MNT_LOG, MFLAG_SET }
> +
>  /* Control flags. */
>  #define MOPT_FORCE { "force",  MNT_FORCE, MFLAG_SET }
>  #define MOPT_UPDATE{ "update", MNT_UPDATE, MFLAG_SET }
> Index: sbin/mount/mount.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount/mount.c,v
> retrieving revision 1.60
> diff -u -r1.60 mount.c
> --- sbin/mount/mount.c  16 Jan 2015 06:39:59 -  1.60
> +++ sbin/mount/mount.c  23 Oct 2015 15:07:07 -
> @@ -94,6 +94,7 @@
> { MNT_ROOTFS,   1,  "root file system", "" },
> { MNT_SYNCHRONOUS,  0,  "synchronous",  "sync" },
> { MNT_SOFTDEP,  0,  "softdep",  "softdep"
> },
> +   { MNT_LOG,  0,  "log",  "log" },
> { 0,0,  "", "" }
>  };
>
> Index: sbin/mount_ffs/mount_ffs.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount_ffs/mount_ffs.c,v
> retrieving revision 1.21
> diff -u -r1.21 mount_ffs.c
> --- sbin/mount_ffs/mount_ffs.c  16 Jan 2015 06:39:59 -  1.21
> +++ sbin/mount_ffs/mount_ffs.c  23 Oct 2015 15:07:07 -
> @@ -53,6 +53,7 @@
> MOPT_RELOAD,
> MOPT_FORCE,
> MOPT_SOFTDEP,
> +   MOPT_LOG,
> { NULL }
>  };
>
> Index: sys/conf/GENERIC
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/conf/GENERIC,v
> retrieving revision 1.220
> diff -u -r1.220 GENERIC
> --- sys/conf/GENERIC10 Aug 2015 20:35:36 -  1.220
> +++ sys/conf/GENERIC23 Oct 2015 15:07:07 -
> @@ -43,6 +43,7 @@
>  option FIFO# FIFOs; RECOMMENDED
>  option TMPFS   # efficient memory file system
>  option FUSE# FUSE
> +option WAPBL   # Write Ahead Physical Block Logging
>
>  option SOCKET_SPLICE   # Socket Splicing for TCP and UDP
>  option TCP_SACK# Selective Acknowledgements for TCP
> Index: sys/conf/files
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/conf/files,v
> retrieving revision 1.604
> diff -u -r1.604 files
> --- sys/conf/files  9 Oct 2015 01:17:21 -   1.604
> +++ sys/conf/files  23 Oct 2015 15:07:07 -
> @@ -732,6 +732,7 @@
>  file kern/vfs_vops.c
>  file kern/vfs_vnops.c
>  file kern/vfs_getcwd.c
> +file kern/vfs_wapbl.c  wapbl
>  file kern/spec_vnops.c
>  file miscfs/deadfs/dead_vnops.c
>  file miscfs/fifofs/fifo_vnops.cfifo
> @@ -887,6 +888,7 @@
>  file ufs/ffs/ffs_vfsops.c  ffs | mfs
>  file ufs/ffs/ffs_vnops.c   ffs | mfs
>  file ufs/ffs/ffs_softdep.c ffs_softupdates
> +file ufs/ffs/ffs_wapbl.c   ffs & wapbl
>  file ufs/mfs/mfs_vfsops.c  mfs
>  file ufs/mfs/mfs_vnops.c   mfs
>  file ufs/ufs/ufs_bmap.cffs | mfs | ext2fs
> @@ -898,6 +900,7 @@
>  file ufs/ufs/ufs_quota_stub.c  ffs | mfs
>  file ufs/ufs/ufs_vfsops.c  ffs | mfs | ext2fs
>  file ufs/ufs/ufs_vnops.c   ffs | mfs | ext2fs
> +file ufs/ufs/ufs_wapbl.c   ffs & wapbl
>  file ufs/ext2fs/ext2fs_alloc.c ext2fs
>  file ufs/ext2fs/ext2fs_balloc.cext2fs
>  file ufs/ext2fs/ext2fs_bmap.c  ext2fs
> Index: sys/kern/spec_vnops.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/kern/spec_vnops.c,v
> retrieving revision 1.83
> diff -u -r1.83 spec_vnops.c
> --- sys/kern/spec_vnops.c   10 Feb 2015 21:56:09 -  1.83
> +++ sys/kern/spec_vnops.c   23 Oct 2015 15:07:07 -
> @@ -408,6 +408,10 @@
> return (EOPNOTSUPP);
>  }
>
> +#ifdef WAPBL
> +extern int ffs_wapbl_fsync_vfs(struct vnode *, int);
> +#endif
> +
>  /*
>   * Synch buffers associated with a block device
>   */
> @@ -422,6 +426,15 @@
>
> if (vp->v_type == VCHR)
> return (0);
> +
> +
> +#ifdef WAPBL
> +   i

Re: Further cleanup of Russian calendars

2015-10-23 Thread Mike Belopuhov
2015-10-23 13:15 GMT+02:00 Vadim Zhukov :
> Further cleanup in Russian calendars:
>
>   * Fix #ifndef safeguards (rename/add where missing);
>   * Use consistent spelling for year when it's mentioned in day desc;
>   * Tweak some wrong casing cases;
>   * Remove calendar.msk since Moscow doesn't have summer time anymore,
> and that was the only thing this file was about;
>   * A few other corrections.
>
> Still seeking for a way to define a day with fixed shift from the year
> start: the Programmer's Day is official in Russia, happens at 256th
> day of the year, but calendar(1) handles up to 31 days per month max.
>
> Okay?

Looks good to me, except of "+B".

> --
> WBR,
>   Vadim Zhukov
>
>
> Index: calendar.common
> ===
> RCS file: /cvs/src/usr.bin/calendar/calendars/ru_RU.UTF-8/calendar.common,v
> retrieving revision 1.1
> diff -u -p -r1.1 calendar.common
> --- calendar.common 23 Oct 2015 09:32:14 -  1.1
> +++ calendar.common 23 Oct 2015 11:09:26 -
> @@ -1,11 +1,12 @@
> +B

+B?



Re: Interface indexes & route entries

2015-10-23 Thread Alexander Bluhm
On Fri, Oct 23, 2015 at 05:45:31PM +0200, Martin Pieuchot wrote:
> This diff adds a small define to be able to convert code dereferencing
> "rt_ifp" to if_get()+if_put().  This will allows us to guarantee that
> ``ifp'' got from route entries are used with a proper reference count. 
> 
> If the direction is ok I'll commit the .h.

OK with the direction.

> I also accept reviews on the chunks below.

One concern: You call if_get()/if_put() from db_show_rtentry().
When dropped into ddb, the kernel may be in a fragile state.  So I
would not recommend to call SRP locking code.  Could we just print
the interface index?

otherwise OK bluhm@

> 
> Index: net/route.h
> ===
> RCS file: /cvs/src/sys/net/route.h,v
> retrieving revision 1.115
> diff -u -p -r1.115 route.h
> --- net/route.h   7 Oct 2015 10:50:35 -   1.115
> +++ net/route.h   23 Oct 2015 15:13:33 -
> @@ -103,6 +103,7 @@ struct rtentry {
>  #endif
>   struct sockaddr *rt_gateway;/* value */
>   struct ifnet*rt_ifp;/* the answer: interface to use */
> +#define rt_ifidx rt_ifp->if_index
>   struct ifaddr   *rt_ifa;/* the answer: interface addr to use */
>   caddr_t  rt_llinfo; /* pointer to link level info cache or
>  to an MPLS structure */ 
> Index: net/if_spppsubr.c
> ===
> RCS file: /cvs/src/sys/net/if_spppsubr.c,v
> retrieving revision 1.141
> diff -u -p -r1.141 if_spppsubr.c
> --- net/if_spppsubr.c 5 Oct 2015 19:05:09 -   1.141
> +++ net/if_spppsubr.c 23 Oct 2015 14:53:10 -
> @@ -4263,7 +4263,7 @@ sppp_update_gw_walker(struct rtentry *rt
>  {
>   struct ifnet *ifp = arg;
>  
> - if (rt->rt_ifp == ifp) {
> + if (rt->rt_ifidx == ifp->if_index) {
>   if (rt->rt_ifa->ifa_dstaddr->sa_family !=
>   rt->rt_gateway->sa_family ||
>   (rt->rt_flags & RTF_GATEWAY) == 0)
> Index: net/route.c
> ===
> RCS file: /cvs/src/sys/net/route.c,v
> retrieving revision 1.259
> diff -u -p -r1.259 route.c
> --- net/route.c   23 Oct 2015 14:48:22 -  1.259
> +++ net/route.c   23 Oct 2015 15:00:42 -
> @@ -383,20 +383,23 @@ rtfree(struct rtentry *rt)
>  void
>  rt_sendmsg(struct rtentry *rt, int cmd, u_int rtableid)
>  {
> - struct rt_addrinfo info;
> - struct sockaddr_rtlabel sa_rl;
> + struct rt_addrinfo   info;
> + struct ifnet*ifp;
> + struct sockaddr_rtlabel  sa_rl;
>  
>   memset(&info, 0, sizeof(info));
>   info.rti_info[RTAX_DST] = rt_key(rt);
>   info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
>   info.rti_info[RTAX_NETMASK] = rt_mask(rt);
>   info.rti_info[RTAX_LABEL] = rtlabel_id2sa(rt->rt_labelid, &sa_rl);
> - if (rt->rt_ifp != NULL) {
> - info.rti_info[RTAX_IFP] = sdltosa(rt->rt_ifp->if_sadl);
> + ifp = if_get(rt->rt_ifidx);
> + if (ifp != NULL) {
> + info.rti_info[RTAX_IFP] = sdltosa(ifp->if_sadl);
>   info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
>   }
>  
> - rt_missmsg(cmd, &info, rt->rt_flags, rt->rt_ifp, 0, rtableid);
> + rt_missmsg(cmd, &info, rt->rt_flags, ifp, 0, rtableid);
> + if_put(ifp);
>  }
>  
>  void
> @@ -541,11 +544,12 @@ rtdeletemsg(struct rtentry *rt, u_int ta
>   info.rti_info[RTAX_NETMASK] = rt_mask(rt);
>   info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
>   info.rti_flags = rt->rt_flags;
> - ifp = rt->rt_ifp;
> + ifp = if_get(rt->rt_ifidx);
>   error = rtrequest1(RTM_DELETE, &info, rt->rt_priority, &rt, tableid);
>   rt_missmsg(RTM_DELETE, &info, info.rti_flags, ifp, error, tableid);
>   if (error == 0)
>   rtfree(rt);
> + if_put(ifp);
>   return (error);
>  }
>  
> @@ -1061,7 +1065,7 @@ rt_checkgate(struct ifnet *ifp, struct r
>* loops, for example when rt->rt_gwroute points to rt.
>*/
>   if (((rt->rt_gwroute->rt_flags & (RTF_UP|RTF_GATEWAY)) !=
> - RTF_UP) || (rt->rt_gwroute->rt_ifp != ifp)) {
> + RTF_UP) || (rt->rt_gwroute->rt_ifidx != ifp->if_index)) {
>   rtfree(rt->rt_gwroute);
>   rt->rt_gwroute = NULL;
>   return (EHOSTUNREACH);
> @@ -1616,7 +1620,7 @@ rt_if_remove_rtdelete(struct rtentry *rt
>  {
>   struct ifnet*ifp = vifp;
>  
> - if (rt->rt_ifp == ifp) {
> + if (rt->rt_ifidx == ifp->if_index) {
>   int cloning = (rt->rt_flags & RTF_CLONING);
>  
>   if (rtdeletemsg(rt, id) == 0 && cloning)
> @@ -1658,7 +1662,7 @@ rt_if_linkstate_change(struct rtentry *r
>  {
>   struct ifnet *ifp = arg;
>  
> - if (rt->rt_ifp != ifp)
> + if (rt->rt_ifidx != ifp->if_index)
>   return (0);
>  
>

Re: utf8 hack for ls

2015-10-23 Thread Ted Unangst
Christian Weisgerber wrote:
> On 2015-10-23, "Ted Unangst"  wrote:
> 
> >> To what degree should tools like ls protect terminals from escape codes?
> >
> > I think this is beyond the scope of what ls should care about. du doesn't 
> > have
> > such a check. Does the shell perform a check before tab completing?
> 
> Our ksh, bash, and tcsh all escape unprintable characters.

well, if this is a blocking issue, the putchar line is now changed to print ?
instead of any control characters.

putchar(c >= ' ' ? c : '?');



Re: does anoybody use ul?

2015-10-23 Thread Christian Weisgerber
Ted Unangst:

> > mandoc /usr/share/man/man1/ksh.1 | sed -n 1185,1190p | ul
> 
> so that works with the diff below. i'm not sure how far down this road we need
> to travel, but i figure it's worth a little exploration.

That works so far.
Next problem: tabs.

(I think it's reasonable to ignore combinding characters in ul...)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Interface indexes & route entries

2015-10-23 Thread Martin Pieuchot
This diff adds a small define to be able to convert code dereferencing
"rt_ifp" to if_get()+if_put().  This will allows us to guarantee that
``ifp'' got from route entries are used with a proper reference count. 

If the direction is ok I'll commit the .h.  I also accept reviews on
the chunks below.

Index: net/route.h
===
RCS file: /cvs/src/sys/net/route.h,v
retrieving revision 1.115
diff -u -p -r1.115 route.h
--- net/route.h 7 Oct 2015 10:50:35 -   1.115
+++ net/route.h 23 Oct 2015 15:13:33 -
@@ -103,6 +103,7 @@ struct rtentry {
 #endif
struct sockaddr *rt_gateway;/* value */
struct ifnet*rt_ifp;/* the answer: interface to use */
+#define rt_ifidx rt_ifp->if_index
struct ifaddr   *rt_ifa;/* the answer: interface addr to use */
caddr_t  rt_llinfo; /* pointer to link level info cache or
   to an MPLS structure */ 
Index: net/if_spppsubr.c
===
RCS file: /cvs/src/sys/net/if_spppsubr.c,v
retrieving revision 1.141
diff -u -p -r1.141 if_spppsubr.c
--- net/if_spppsubr.c   5 Oct 2015 19:05:09 -   1.141
+++ net/if_spppsubr.c   23 Oct 2015 14:53:10 -
@@ -4263,7 +4263,7 @@ sppp_update_gw_walker(struct rtentry *rt
 {
struct ifnet *ifp = arg;
 
-   if (rt->rt_ifp == ifp) {
+   if (rt->rt_ifidx == ifp->if_index) {
if (rt->rt_ifa->ifa_dstaddr->sa_family !=
rt->rt_gateway->sa_family ||
(rt->rt_flags & RTF_GATEWAY) == 0)
Index: net/route.c
===
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.259
diff -u -p -r1.259 route.c
--- net/route.c 23 Oct 2015 14:48:22 -  1.259
+++ net/route.c 23 Oct 2015 15:00:42 -
@@ -383,20 +383,23 @@ rtfree(struct rtentry *rt)
 void
 rt_sendmsg(struct rtentry *rt, int cmd, u_int rtableid)
 {
-   struct rt_addrinfo info;
-   struct sockaddr_rtlabel sa_rl;
+   struct rt_addrinfo   info;
+   struct ifnet*ifp;
+   struct sockaddr_rtlabel  sa_rl;
 
memset(&info, 0, sizeof(info));
info.rti_info[RTAX_DST] = rt_key(rt);
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
info.rti_info[RTAX_LABEL] = rtlabel_id2sa(rt->rt_labelid, &sa_rl);
-   if (rt->rt_ifp != NULL) {
-   info.rti_info[RTAX_IFP] = sdltosa(rt->rt_ifp->if_sadl);
+   ifp = if_get(rt->rt_ifidx);
+   if (ifp != NULL) {
+   info.rti_info[RTAX_IFP] = sdltosa(ifp->if_sadl);
info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
}
 
-   rt_missmsg(cmd, &info, rt->rt_flags, rt->rt_ifp, 0, rtableid);
+   rt_missmsg(cmd, &info, rt->rt_flags, ifp, 0, rtableid);
+   if_put(ifp);
 }
 
 void
@@ -541,11 +544,12 @@ rtdeletemsg(struct rtentry *rt, u_int ta
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
info.rti_flags = rt->rt_flags;
-   ifp = rt->rt_ifp;
+   ifp = if_get(rt->rt_ifidx);
error = rtrequest1(RTM_DELETE, &info, rt->rt_priority, &rt, tableid);
rt_missmsg(RTM_DELETE, &info, info.rti_flags, ifp, error, tableid);
if (error == 0)
rtfree(rt);
+   if_put(ifp);
return (error);
 }
 
@@ -1061,7 +1065,7 @@ rt_checkgate(struct ifnet *ifp, struct r
 * loops, for example when rt->rt_gwroute points to rt.
 */
if (((rt->rt_gwroute->rt_flags & (RTF_UP|RTF_GATEWAY)) !=
-   RTF_UP) || (rt->rt_gwroute->rt_ifp != ifp)) {
+   RTF_UP) || (rt->rt_gwroute->rt_ifidx != ifp->if_index)) {
rtfree(rt->rt_gwroute);
rt->rt_gwroute = NULL;
return (EHOSTUNREACH);
@@ -1616,7 +1620,7 @@ rt_if_remove_rtdelete(struct rtentry *rt
 {
struct ifnet*ifp = vifp;
 
-   if (rt->rt_ifp == ifp) {
+   if (rt->rt_ifidx == ifp->if_index) {
int cloning = (rt->rt_flags & RTF_CLONING);
 
if (rtdeletemsg(rt, id) == 0 && cloning)
@@ -1658,7 +1662,7 @@ rt_if_linkstate_change(struct rtentry *r
 {
struct ifnet *ifp = arg;
 
-   if (rt->rt_ifp != ifp)
+   if (rt->rt_ifidx != ifp->if_index)
return (0);
 
/* Local routes are always usable. */
@@ -1745,6 +1749,8 @@ db_print_ifa(struct ifaddr *ifa)
 int
 db_show_rtentry(struct rtentry *rt, void *w, unsigned int id)
 {
+   struct ifnet *ifp;
+
db_printf("rtentry=%p", rt);
 
db_printf(" flags=0x%x refcnt=%d use=%llu expire=%lld rtableid=%u\n",
@@ -1754,11 +1760,13 @@ db_show_rtentry(struct rtentry *rt, void
db_printf(" mask="); db_print_sa(rt_mask(rt));
db_printf(" gw="); d

syslogd delayed tty write event

2015-10-23 Thread Alexander Bluhm
Hi,

If writing to a tty blocks, syslogd forks and tries to write again
in a background process.  A potential fork(2) at every message is
bad, so replace this with an event.  As a bonus the syslogd child
process does not need to pledge "proc" anymore.  Also limit the
number of delayed write events.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.199
diff -u -p -r1.199 syslogd.c
--- usr.sbin/syslogd/syslogd.c  21 Oct 2015 14:03:07 -  1.199
+++ usr.sbin/syslogd/syslogd.c  21 Oct 2015 14:26:49 -
@@ -53,7 +53,6 @@
  * IPv6, libevent, syslog over TCP and TLS by Alexander Bluhm
  */
 
-#define MAXLINE8192/* maximum line length */
 #define MAX_UDPMSG 1180/* maximum UDP send size */
 #define MIN_MEMBUF (MAXLINE * 4)   /* Minimum memory buffer size */
 #define MAX_MEMBUF (256 * 1024)/* Maximum memory buffer size */
@@ -701,7 +700,7 @@ main(int argc, char *argv[])
if (priv_init(ConfFile, NoDNS, lockpipe[1], nullfd, argv) < 0)
errx(1, "unable to privsep");
 
-   if (pledge("stdio rpath unix inet proc recvfd", NULL) == -1)
+   if (pledge("stdio rpath unix inet recvfd", NULL) == -1)
err(1, "pledge");
 
/* Process is now unprivileged and inside a chroot */
@@ -1952,8 +1951,7 @@ wallmsg(struct filed *f, struct iovec *i
break;
if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
UT_NAMESIZE)) {
-   if ((p = ttymsg(iov, 6, utline))
-   != NULL)
+   if ((p = ttymsg(iov, 6, utline)) != NULL)
logerrorx(p);
break;
}
Index: usr.sbin/syslogd/syslogd.h
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.h,v
retrieving revision 1.22
diff -u -p -r1.22 syslogd.h
--- usr.sbin/syslogd/syslogd.h  21 Oct 2015 14:03:07 -  1.22
+++ usr.sbin/syslogd/syslogd.h  23 Oct 2015 14:55:20 -
@@ -33,6 +33,7 @@ int   priv_getnameinfo(struct sockaddr *
 
 /* Terminal message */
 #define TTYMSGTIME 1   /* timeout used by ttymsg */
+#define TTYMAXDELAY256 /* max events in ttymsg */
 char *ttymsg(struct iovec *, int, char *);
 
 /* File descriptor send/recv */
@@ -47,6 +48,7 @@ extern char *path_ctlsock;
 extern int fd_ctlsock, fd_ctlconn, fd_klog, fd_sendsys;
 extern int fd_udp, fd_udp6, fd_bind, fd_listen, fd_tls, fd_unix[MAXUNIX];
 
+#define MAXLINE8192/* maximum line length */
 #define ERRBUFSIZE 256
 void logdebug(const char *, ...) __attribute__((__format__ (printf, 1, 2)));
 extern int Debug;
Index: usr.sbin/syslogd/ttymsg.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/ttymsg.c,v
retrieving revision 1.8
diff -u -p -r1.8 ttymsg.c
--- usr.sbin/syslogd/ttymsg.c   21 Oct 2015 14:03:07 -  1.8
+++ usr.sbin/syslogd/ttymsg.c   23 Oct 2015 14:28:22 -
@@ -35,6 +35,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -45,9 +46,17 @@
 
 #include "syslogd.h"
 
+struct tty_delay {
+   struct event td_event;
+   size_t   td_length;
+   char td_line[MAXLINE];
+};
+int tty_delayed = 0;
+void ttycb(int, short, void *);
+
 /*
  * Display the contents of a uio structure on a terminal.
- * Forks and finishes in child if write would block, waiting up to TTYMSGTIME
+ * Schedules an event if write would block, waiting up to TTYMSGTIME
  * seconds.  Returns pointer to error string on unexpected error;
  * string is not newline-terminated.  Various "normal" errors are ignored
  * (exclusive-use, lack of permission, etc.).
@@ -61,8 +70,6 @@ ttymsg(struct iovec *iov, int iovcnt, ch
size_t left;
ssize_t wret;
struct iovec localiov[6];
-   int forked = 0;
-   sigset_t mask;
 
if (iovcnt < 0 || (size_t)iovcnt > nitems(localiov))
return ("too many iov's (change code in syslogd/ttymsg.c)");
@@ -122,34 +129,44 @@ ttymsg(struct iovec *iov, int iovcnt, ch
continue;
}
if (errno == EWOULDBLOCK) {
-   int off = 0;
-   pid_t cpid;
+   struct tty_delay*td;
+   struct timeval   to;
 
-   if (forked) {
-   (void) close(fd);
-   _exit(1);
+   if (tty_delayed >= TTYMAXDELAY) {
+   (void) snprintf(ebuf, sizeof(ebuf),
+  

Re: utf8 hack for ls

2015-10-23 Thread Christian Weisgerber
On 2015-10-23, "Ted Unangst"  wrote:

>> To what degree should tools like ls protect terminals from escape codes?
>
> I think this is beyond the scope of what ls should care about. du doesn't have
> such a check. Does the shell perform a check before tab completing?

Our ksh, bash, and tcsh all escape unprintable characters.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



pair(4) (was: connect routing domains on layer 2)

2015-10-23 Thread Reyk Floeter
Hi,

as requested by Theo and discussed with many, the following diff moves
it into a new driver.  This also allowed to improve the logic of link
states related to the connection (as discussed with Claudio).

The new driver is called pair(4).

# ifconfig pair1 rdomain 1 10.1.1.1/24 up
# ifconfig pair2 rdomain 2 10.1.1.2/24 up
# ifconfig pair1 patch pair2
# route -T 1 exec ping 10.1.1.2
# ifconfig pair1 -patch

manpages and documentation can be improved, but I'd like to continue
in the tree if there are no other serious concerns.

OK?

Reyk

Index: sbin/ifconfig/ifconfig.8
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v
retrieving revision 1.257
diff -u -p -u -p -r1.257 ifconfig.8
--- sbin/ifconfig/ifconfig.86 Oct 2015 17:23:21 -   1.257
+++ sbin/ifconfig/ifconfig.823 Oct 2015 15:44:28 -
@@ -1270,6 +1270,33 @@ The
 is an IPv4 address that will be used to find the nexthop in the MPLS
 network.
 .El
+.\" PAIR
+.Sh PAIR
+.nr nS 1
+.Bk -words
+.Nm ifconfig
+.Ar pair-interface
+.Op Oo Fl Oc Ns Cm patch Ar interface
+.Ek
+.nr nS 0
+.Pp
+The following options are available for a
+.Xr pair 4
+interface:
+.Bl -tag -width Ds
+.It Cm patch Ar interface
+Connect the interface with a second
+.Xr pair 4
+interface.
+Any outgoing packets from the first
+.Ar pair-interface
+will be received by the second
+.Ar interface
+and vice versa.
+This link allows to interconnect two routing domains locally.
+.It Fl patch
+If configured, disconnect the interface pair.
+.El
 .\" PFLOW
 .Sh PFLOW
 .nr nS 1
Index: sbin/ifconfig/ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.302
diff -u -p -u -p -r1.302 ifconfig.c
--- sbin/ifconfig/ifconfig.c3 Oct 2015 10:44:23 -   1.302
+++ sbin/ifconfig/ifconfig.c23 Oct 2015 15:44:29 -
@@ -275,6 +275,8 @@ voidsetifipdst(const char *, int);
 void   setifdesc(const char *, int);
 void   unsetifdesc(const char *, int);
 void   printifhwfeatures(const char *, int);
+void   setpair(const char *, int);
+void   unsetpair(const char *, int);
 #else
 void   setignore(const char *, int);
 #endif
@@ -490,6 +492,8 @@ const structcmd {
{ "-descr", 1,  0,  unsetifdesc },
{ "wol",IFXF_WOL,   0,  setifxflags },
{ "-wol",   -IFXF_WOL,  0,  setifxflags },
+   { "patch",  NEXTARG,0,  setpair },
+   { "-patch", 1,  0,  unsetpair },
 #else /* SMALL */
{ "powersave",  NEXTARG0,   0,  setignore },
{ "priority",   NEXTARG,0,  setignore },
@@ -2917,6 +2921,7 @@ status(int link, struct sockaddr_dl *sdl
struct ifreq ifrdesc;
struct ifkalivereq ikardesc;
char ifdescr[IFDESCRSIZE];
+   char ifname[IF_NAMESIZE];
 #endif
uint64_t *media_list;
int i;
@@ -2955,6 +2960,9 @@ status(int link, struct sockaddr_dl *sdl
(ikardesc.ikar_timeo != 0 || ikardesc.ikar_cnt != 0))
printf("\tkeepalive: timeout %d count %d\n",
ikardesc.ikar_timeo, ikardesc.ikar_cnt);
+   if (ioctl(s, SIOCGIFPAIR, &ifrdesc) == 0 && ifrdesc.ifr_index != 0 &&
+   if_indextoname(ifrdesc.ifr_index, ifname) != NULL)
+   printf("\tpatch: %s\n", ifname);
 #endif
vlan_status();
 #ifndef SMALL
@@ -5199,6 +5207,29 @@ setinstance(const char *id, int param)
ifr.ifr_rdomainid = rdomainid;
if (ioctl(s, SIOCSIFRDOMAIN, (caddr_t)&ifr) < 0)
warn("SIOCSIFRDOMAIN");
+}
+#endif
+
+#ifndef SMALL
+void
+setpair(const char *val, int d)
+{
+   strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+   if ((ifr.ifr_index = if_nametoindex(val)) == 0) {
+   errno = ENOENT;
+   err(1, "patch %s", val);
+   }
+   if (ioctl(s, SIOCSIFPAIR, (caddr_t)&ifr) < 0)
+   warn("SIOCSIFPAIR");
+}
+
+void
+unsetpair(const char *val, int d)
+{
+   ifr.ifr_index = 0;
+   strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+   if (ioctl(s, SIOCSIFPAIR, (caddr_t)&ifr) < 0)
+   warn("SIOCSIFPAIR");
 }
 #endif
 
Index: sys/conf/GENERIC
===
RCS file: /cvs/src/sys/conf/GENERIC,v
retrieving revision 1.220
diff -u -p -u -p -r1.220 GENERIC
--- sys/conf/GENERIC10 Aug 2015 20:35:36 -  1.220
+++ sys/conf/GENERIC23 Oct 2015 15:44:31 -
@@ -96,6 +96,7 @@ pseudo-device gre # GRE encapsulation i
 pseudo-device  loop# network loopback
 pseudo-device  mpe # MPLS PE interface
 pseudo-device  mpw # MPLS pseudowire support
+pseudo-device  pair# Virtual Ethernet interface pair
 pseudo-device  ppp 

Re: WAPBL implementation

2015-10-23 Thread Joerg Jung
On Fri, Oct 23, 2015 at 01:19:15PM -0200, Walter Neto wrote:
> Like recommended from other developers I started developing WAPBL support for
> OpenBSD.
> 
> Looking at NetBSD and Bitrig I mage a first funcional patch.

Wow... that is a big diff :)
Care to elaborate in some more words what "functional" means here?

Thanks,
Regards,
Joerg

> Index: sbin/mount/mntopts.h
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount/mntopts.h,v
> retrieving revision 1.16
> diff -u -r1.16 mntopts.h
> --- sbin/mount/mntopts.h  13 Jul 2014 12:01:30 -  1.16
> +++ sbin/mount/mntopts.h  23 Oct 2015 15:07:07 -
> @@ -66,6 +66,8 @@
>   | MFLAG_OPT }
>  #define MOPT_SOFTDEP { "softdep",MNT_SOFTDEP, MFLAG_SET }
>  
> +#define MOPT_LOG { "log",MNT_LOG, MFLAG_SET }
> +
>  /* Control flags. */
>  #define MOPT_FORCE   { "force",  MNT_FORCE, MFLAG_SET }
>  #define MOPT_UPDATE  { "update", MNT_UPDATE, MFLAG_SET }
> Index: sbin/mount/mount.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount/mount.c,v
> retrieving revision 1.60
> diff -u -r1.60 mount.c
> --- sbin/mount/mount.c16 Jan 2015 06:39:59 -  1.60
> +++ sbin/mount/mount.c23 Oct 2015 15:07:07 -
> @@ -94,6 +94,7 @@
>   { MNT_ROOTFS,   1,  "root file system", "" },
>   { MNT_SYNCHRONOUS,  0,  "synchronous",  "sync" },
>   { MNT_SOFTDEP,  0,  "softdep",  "softdep" },
> + { MNT_LOG,  0,  "log",  "log" },
>   { 0,0,  "", "" }
>  };
>  
> Index: sbin/mount_ffs/mount_ffs.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sbin/mount_ffs/mount_ffs.c,v
> retrieving revision 1.21
> diff -u -r1.21 mount_ffs.c
> --- sbin/mount_ffs/mount_ffs.c16 Jan 2015 06:39:59 -  1.21
> +++ sbin/mount_ffs/mount_ffs.c23 Oct 2015 15:07:07 -
> @@ -53,6 +53,7 @@
>   MOPT_RELOAD,
>   MOPT_FORCE,
>   MOPT_SOFTDEP,
> + MOPT_LOG,
>   { NULL }
>  };
>  
> Index: sys/conf/GENERIC
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/conf/GENERIC,v
> retrieving revision 1.220
> diff -u -r1.220 GENERIC
> --- sys/conf/GENERIC  10 Aug 2015 20:35:36 -  1.220
> +++ sys/conf/GENERIC  23 Oct 2015 15:07:07 -
> @@ -43,6 +43,7 @@
>  option   FIFO# FIFOs; RECOMMENDED
>  option   TMPFS   # efficient memory file system
>  option   FUSE# FUSE
> +option   WAPBL   # Write Ahead Physical Block Logging
>  
>  option   SOCKET_SPLICE   # Socket Splicing for TCP and UDP
>  option   TCP_SACK# Selective Acknowledgements for TCP
> Index: sys/conf/files
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/conf/files,v
> retrieving revision 1.604
> diff -u -r1.604 files
> --- sys/conf/files9 Oct 2015 01:17:21 -   1.604
> +++ sys/conf/files23 Oct 2015 15:07:07 -
> @@ -732,6 +732,7 @@
>  file kern/vfs_vops.c
>  file kern/vfs_vnops.c
>  file kern/vfs_getcwd.c
> +file kern/vfs_wapbl.cwapbl
>  file kern/spec_vnops.c
>  file miscfs/deadfs/dead_vnops.c
>  file miscfs/fifofs/fifo_vnops.c  fifo
> @@ -887,6 +888,7 @@
>  file ufs/ffs/ffs_vfsops.cffs | mfs
>  file ufs/ffs/ffs_vnops.c ffs | mfs
>  file ufs/ffs/ffs_softdep.c   ffs_softupdates
> +file ufs/ffs/ffs_wapbl.c ffs & wapbl
>  file ufs/mfs/mfs_vfsops.cmfs
>  file ufs/mfs/mfs_vnops.c mfs
>  file ufs/ufs/ufs_bmap.c  ffs | mfs | ext2fs
> @@ -898,6 +900,7 @@
>  file ufs/ufs/ufs_quota_stub.cffs | mfs
>  file ufs/ufs/ufs_vfsops.cffs | mfs | ext2fs
>  file ufs/ufs/ufs_vnops.c ffs | mfs | ext2fs
> +file ufs/ufs/ufs_wapbl.c ffs & wapbl
>  file ufs/ext2fs/ext2fs_alloc.c   ext2fs
>  file ufs/ext2fs/ext2fs_balloc.c  ext2fs
>  file ufs/ext2fs/ext2fs_bmap.cext2fs
> Index: sys/kern/spec_vnops.c
> ===
> RCS file: /Volumes/CSP/cvs/src/sys/kern/spec_vnops.c,v
> retrieving revision 1.83
> diff -u -r1.83 spec_vnops.c
> --- sys/kern/spec_vnops.c 10 Feb 2015 21:56:09 -  1.83
> +++ sys/kern/spec_vnops.c 23 Oct 2015 15:07:07 -
> @@ -408,6 +408,10 @@
>   return (EOPNOTSUPP);
>  }
>  
> +#ifdef WAPBL
> +extern int ffs_wapbl_fsync_vfs(struct vnode *, int);
> +#endif
> +
>  /*
>   * Synch buffers associated with a block device
>   */
> @@ -422,6 +426,15 @@
>  
>   if (vp->v_type == VCHR)
>   

Re: connect routing domains on layer 2

2015-10-23 Thread Reyk Floeter
On Fri, Oct 23, 2015 at 01:54:36PM +0200, Martin Pieuchot wrote:
> On 23/10/15(Fri) 13:21, David Gwynne wrote:
> > 
> > > On 23 Oct 2015, at 09:00, Reyk Floeter  wrote:
> > > 
> > > Hi,
> > > 
> > > this diff allows to interconnect routing domains.
> > > 
> > > It is very useful to route traffic from one routing domain to another,
> > > without using the pf "rtable" hack (tested in production for a long
> > > time).
> > > 
> > > eg.,
> > > # ifconfig vether0 10.0.1.1/24
> > > # ifconfig vether1 rdomain 1 10.0.1.2/24
> > > # ping 10.1.1.2
> > > # route -T 1 add default 10.0.1.1
> > > # ifconfig bridge0 add vether0 add em0
> > > 
> > > for hacking/testing, you can do thing like:
> > > # dhcpd vether0
> > > # dhclient vether1
> > > 
> > > It has been discussed in much detail if this is possible with
> > > bridge(4).  It is not.  The bridge is not designed for it and explain
> > > on request.
> > 
> > the diff implements a crossover option, but the example above doesnt use 
> > them. does that mean you can use a bridge to build crossovers without the 
> > extra code, or the example is wrong?
> 
> As said yesterday an alternative would be to use the bridge(4) as below:
> 

no.

You missed the discussion in the morning: your diff is for the receive
path (data received on one interface and received on others) and not
for the transmit path (data sent from one interface and sent out on
one or more others).  The transmit path is bridge_output() ->
bridge_ifenqueue() (TX) only.

I need "data sent on one interface, but received on others". It
doesn't make much sense to tx->rx on the same bridge, I illustrated it
on the board in front of you:

http://arc4random.com/bridge-booom.jpg

I also think doing such a hack on rdomains in bridge(4) would be
another ugly hack in bridge(4).

Updated pair(4) diff follows.

Reyk

> Index: net/if_bridge.c
> ===
> RCS file: /cvs/src/sys/net/if_bridge.c,v
> retrieving revision 1.268
> diff -u -p -r1.268 if_bridge.c
> --- net/if_bridge.c   12 Oct 2015 10:03:25 -  1.268
> +++ net/if_bridge.c   23 Oct 2015 11:52:13 -
> @@ -1218,10 +1218,12 @@ bridgeintr_frame(struct bridge_softc *sc
>   if (m == NULL)
>   return;
>   /*
> -  * If the packet is a multicast or broadcast OR if we don't
> -  * know any better, forward it to all interfaces.
> +  * If the packet is a multicast/broadcast, if we don't know
> +  * any better or if the destination is in a different routing
> +  * domain, forward it to all interfaces.
>*/
> - if ((m->m_flags & (M_BCAST | M_MCAST)) || dst_if == NULL) {
> + if ((m->m_flags & (M_BCAST | M_MCAST)) || dst_if == NULL ||
> + (dst_if->if_rdomain != src_if->if_rdomain)) {
>   sc->sc_if.if_imcasts++;
>   bridge_broadcast(sc, src_if, &eh, m);
>   return;
> 

The transmit path is bridge_output() -> bridge_ifenqueue() (TX) only.
-- 



WAPBL implementation

2015-10-23 Thread Walter Neto
Like recommended from other developers I started developing WAPBL support for
OpenBSD.

Looking at NetBSD and Bitrig I mage a first funcional patch.

Index: sbin/mount/mntopts.h
===
RCS file: /Volumes/CSP/cvs/src/sbin/mount/mntopts.h,v
retrieving revision 1.16
diff -u -r1.16 mntopts.h
--- sbin/mount/mntopts.h13 Jul 2014 12:01:30 -  1.16
+++ sbin/mount/mntopts.h23 Oct 2015 15:07:07 -
@@ -66,6 +66,8 @@
| MFLAG_OPT }
 #define MOPT_SOFTDEP   { "softdep",MNT_SOFTDEP, MFLAG_SET }
 
+#define MOPT_LOG   { "log",MNT_LOG, MFLAG_SET }
+
 /* Control flags. */
 #define MOPT_FORCE { "force",  MNT_FORCE, MFLAG_SET }
 #define MOPT_UPDATE{ "update", MNT_UPDATE, MFLAG_SET }
Index: sbin/mount/mount.c
===
RCS file: /Volumes/CSP/cvs/src/sbin/mount/mount.c,v
retrieving revision 1.60
diff -u -r1.60 mount.c
--- sbin/mount/mount.c  16 Jan 2015 06:39:59 -  1.60
+++ sbin/mount/mount.c  23 Oct 2015 15:07:07 -
@@ -94,6 +94,7 @@
{ MNT_ROOTFS,   1,  "root file system", "" },
{ MNT_SYNCHRONOUS,  0,  "synchronous",  "sync" },
{ MNT_SOFTDEP,  0,  "softdep",  "softdep" },
+   { MNT_LOG,  0,  "log",  "log" },
{ 0,0,  "", "" }
 };
 
Index: sbin/mount_ffs/mount_ffs.c
===
RCS file: /Volumes/CSP/cvs/src/sbin/mount_ffs/mount_ffs.c,v
retrieving revision 1.21
diff -u -r1.21 mount_ffs.c
--- sbin/mount_ffs/mount_ffs.c  16 Jan 2015 06:39:59 -  1.21
+++ sbin/mount_ffs/mount_ffs.c  23 Oct 2015 15:07:07 -
@@ -53,6 +53,7 @@
MOPT_RELOAD,
MOPT_FORCE,
MOPT_SOFTDEP,
+   MOPT_LOG,
{ NULL }
 };
 
Index: sys/conf/GENERIC
===
RCS file: /Volumes/CSP/cvs/src/sys/conf/GENERIC,v
retrieving revision 1.220
diff -u -r1.220 GENERIC
--- sys/conf/GENERIC10 Aug 2015 20:35:36 -  1.220
+++ sys/conf/GENERIC23 Oct 2015 15:07:07 -
@@ -43,6 +43,7 @@
 option FIFO# FIFOs; RECOMMENDED
 option TMPFS   # efficient memory file system
 option FUSE# FUSE
+option WAPBL   # Write Ahead Physical Block Logging
 
 option SOCKET_SPLICE   # Socket Splicing for TCP and UDP
 option TCP_SACK# Selective Acknowledgements for TCP
Index: sys/conf/files
===
RCS file: /Volumes/CSP/cvs/src/sys/conf/files,v
retrieving revision 1.604
diff -u -r1.604 files
--- sys/conf/files  9 Oct 2015 01:17:21 -   1.604
+++ sys/conf/files  23 Oct 2015 15:07:07 -
@@ -732,6 +732,7 @@
 file kern/vfs_vops.c
 file kern/vfs_vnops.c
 file kern/vfs_getcwd.c
+file kern/vfs_wapbl.c  wapbl
 file kern/spec_vnops.c
 file miscfs/deadfs/dead_vnops.c
 file miscfs/fifofs/fifo_vnops.cfifo
@@ -887,6 +888,7 @@
 file ufs/ffs/ffs_vfsops.c  ffs | mfs
 file ufs/ffs/ffs_vnops.c   ffs | mfs
 file ufs/ffs/ffs_softdep.c ffs_softupdates
+file ufs/ffs/ffs_wapbl.c   ffs & wapbl
 file ufs/mfs/mfs_vfsops.c  mfs
 file ufs/mfs/mfs_vnops.c   mfs
 file ufs/ufs/ufs_bmap.cffs | mfs | ext2fs
@@ -898,6 +900,7 @@
 file ufs/ufs/ufs_quota_stub.c  ffs | mfs
 file ufs/ufs/ufs_vfsops.c  ffs | mfs | ext2fs
 file ufs/ufs/ufs_vnops.c   ffs | mfs | ext2fs
+file ufs/ufs/ufs_wapbl.c   ffs & wapbl
 file ufs/ext2fs/ext2fs_alloc.c ext2fs
 file ufs/ext2fs/ext2fs_balloc.cext2fs
 file ufs/ext2fs/ext2fs_bmap.c  ext2fs
Index: sys/kern/spec_vnops.c
===
RCS file: /Volumes/CSP/cvs/src/sys/kern/spec_vnops.c,v
retrieving revision 1.83
diff -u -r1.83 spec_vnops.c
--- sys/kern/spec_vnops.c   10 Feb 2015 21:56:09 -  1.83
+++ sys/kern/spec_vnops.c   23 Oct 2015 15:07:07 -
@@ -408,6 +408,10 @@
return (EOPNOTSUPP);
 }
 
+#ifdef WAPBL
+extern int ffs_wapbl_fsync_vfs(struct vnode *, int);
+#endif
+
 /*
  * Synch buffers associated with a block device
  */
@@ -422,6 +426,15 @@
 
if (vp->v_type == VCHR)
return (0);
+
+
+#ifdef WAPBL
+   if (vp->v_type == VBLK &&
+   vp->v_specmountpoint != NULL &&
+   vp->v_specmountpoint->mnt_wapbl != NULL)
+   return (ffs_wapbl_fsync_vfs(vp, ap->a_waitfor));
+#endif
+   
/*
 * Flush all dirty buffers associated with a block device.
 */
Index: sys/kern/vfs_bio.c
===

Re: utf8 hack for ls

2015-10-23 Thread Nicholas Marriott
Ah right this makes sense to me


On Fri, Oct 23, 2015 at 09:13:02AM -0400, Ted Unangst wrote:
> Nicholas Marriott wrote:
> > Hi
> > 
> > This doesn't account for UTF-8 double width characters, so they will
> > still throw the column widths off?
> 
> right. maybe we will steal some code from tmux for that :). but getting
> u8len() into the right places is the first step.
> 
> i don't think we want a isu8cont() function in every program either, but i'm
> adding it here and there until we see where it's needed. 



Re: does anoybody use ul?

2015-10-23 Thread Ted Unangst
Christian Weisgerber wrote:
> Ted Unangst:
> 
> > --- ul.c10 Oct 2015 16:15:03 -  1.19
> > +++ ul.c23 Oct 2015 10:29:43 -
> > @@ -241,6 +241,8 @@ mfilter(FILE *f)
> > obuf[col].c_mode |= BOLD|mode;
> > else
> > obuf[col].c_mode = mode;
> > +   if ((c & (0x80 | 0x40)) == 0x80 && col > 0)
> > +   obuf[col].c_mode = obuf[col - 1].c_mode;
> > col++;
> > if (col > maxcol)
> > maxcol = col;
> 
> That doesn't quite work.  Check out this:
> 
> mandoc /usr/share/man/man1/ksh.1 | sed -n 1185,1190p | ul

so that works with the diff below. i'm not sure how far down this road we need
to travel, but i figure it's worth a little exploration.

note that i don't think this handles the case of one character, backspace, a
different character correctly, though it can asymptotically approach
correct with some care.

Index: ul.c
===
RCS file: /cvs/src/usr.bin/ul/ul.c,v
retrieving revision 1.19
diff -u -p -r1.19 ul.c
--- ul.c10 Oct 2015 16:15:03 -  1.19
+++ ul.c23 Oct 2015 13:31:45 -
@@ -151,6 +151,12 @@ main(int argc, char *argv[])
exit(0);
 }
 
+int
+isu8cont(unsigned char c)
+{
+   return (c & (0x80 | 0x40)) == 0x80;
+}
+
 void
 mfilter(FILE *f)
 {
@@ -158,8 +164,11 @@ mfilter(FILE *f)
 
while ((c = getc(f)) != EOF && col < MAXBUF) switch(c) {
case '\b':
-   if (col > 0)
+   while (col > 0) {
col--;
+   if (!isu8cont(obuf[col].c_char))
+   break;
+   }
continue;
case '\t':
col = (col+8) & ~07;
@@ -241,6 +250,8 @@ mfilter(FILE *f)
obuf[col].c_mode |= BOLD|mode;
else
obuf[col].c_mode = mode;
+   if ((c & (0x80 | 0x40)) == 0x80 && col > 0)
+   obuf[col].c_mode = obuf[col - 1].c_mode;
col++;
if (col > maxcol)
maxcol = col;



Re: utf8 in rs

2015-10-23 Thread Christian Weisgerber
Ted Unangst:

> I'm very scared to try counting chars vs bytes upfront in such code. However,
> the code that prints spaces to pad the output is much simpler.

I think that's insufficient to cover rs's functionality.  -z will
overestimate the required widths and... yes, -j is completely broken.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: CVS: cvs.openbsd.org: src

2015-10-23 Thread Joerg Jung
On Wed, Sep 30, 2015 at 06:07:54PM +0200, Joerg Jung wrote:
> On Wed, Sep 30, 2015 at 05:13:31PM +0200, Martijn van Duren wrote:
> > On 09/30/15 14:15, Joerg Jung wrote:
> 
> > Thanks! Although it does add about 5-10 seconds to my boot-time, waiting
> > primarily for the temperature sensors.
> 
> Yes, they are probed during startup. That probing is slow, as the SMC is
> slow.  This needs some rethinking/polishing, moving the probing to a
> later point.

tl;dr: please find below a refactoring diff that fixes this.


The -current asmc(4) code suffers from two problems:

I.  The initial sensors read may take several seconds.
II. The update of the sensor values tsleep()s excessively within the
sensor task.

The following suggestions and hints to fix these timing issues were
provided to me:

1. mpi@ and Theo recommended not to tsleep() within the sensor task,
   mpi@ says: "Sleeping in the sensor thread might add latency to others
  sensors discovery."

   -> This is totally right, and matches II. problem statement above.

2. Theo suggested an async model using the sensor task (similar to
   ugold(4)), something like: sensor task comes, some command is issued,
   task returns, comes back later, reads result, next sensor, ...

   -> This sounds promising in theory, but I played a bit with this
  approach and it seems to be impossible to implement with asmc(4).
   -> The problem is that SMC requires several read() and write()
  operations for one command/sensor read, all of them acknowledged
  with waiting for the correct status, the protocol looks like this:
 1. write command, wait for status "accepted",
 2. write key, 4 single byte writes, each wait for status "accepted"
 3. write data length expected to read, wait for status "accepted"
 4. finally read data values, single byte reads each waiting for
status "ready for read"
  Step 1-3 might take in the seldom worst case several seconds 
  (retries + timeout).  I can not see an easy way to do this async
  and step-by-step as waiting too long will result in
  "comm collision" errors or might take ages, as it reads values
  from up to 100 sensors using these steps.

So, I came to the conclusion that solving I.+II. really requires an
additional thread.

3. uebayasi@ suggested to look into sys/dev/ipmi.c, which uses a kthread
   to initially read all sensor values from a slow serial bus.

   -> This was a good hint, related ipmi code is simple and it can be
  easily done in the same way in asmc(4), but according to a quick
  grep it is the ONLY sensor driver which does it in this way, and
  moreover:

4. tedu@ says: "oh, don't make your own thread unless you really need
   the loop. you can create your own taskq as well"

   -> Makes sense, a quick grep revealed, that (again) ONLY one single
  driver does it like this: viomb(4), again using an easy pattern to
  copy into asmc(4).

So, finally the refactoring diff below follows tedu's suggestion and
uses an own taskq to solve I.+II.

Tests, comments and OKs are welcome.

Thanks,
Regards,
Joerg



Index: asmc.c
===
RCS file: /cvs/src/sys/dev/isa/asmc.c,v
retrieving revision 1.11
diff -u -p -r1.11 asmc.c
--- asmc.c  15 Oct 2015 01:14:33 -  1.11
+++ asmc.c  23 Oct 2015 13:24:34 -
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -62,7 +63,13 @@ struct asmc_softc {
bus_space_handle_t   sc_ioh;
 
struct asmc_prod*sc_prod;
-   uint8_t  sc_lightlen;   /* light data len */
+   uint8_t  sc_init;   /* initialization done? */
+   uint8_t  sc_nfans;  /* number of fans */
+   uint8_t  sc_lightlen;   /* light data len */
+
+   struct taskq*sc_taskq;
+   struct task  sc_task_init;
+   struct task  sc_task_refresh;
 
struct ksensor   sc_sensor_temp[ASMC_MAXTEMP];
struct ksensor   sc_sensor_fan[ASMC_MAXFAN];
@@ -72,7 +79,12 @@ struct asmc_softc {
struct sensor_task  *sc_sensor_task;
 };
 
-intasmc_init(struct asmc_softc *);
+uint8_tasmc_status(struct asmc_softc *);
+intasmc_try(struct asmc_softc *, int, const char *, uint8_t *, uint8_t);
+void   asmc_kbdled(struct asmc_softc *, uint8_t);
+
+void   asmc_init(void *);
+void   asmc_refresh(void *);
 void   asmc_update(void *);
 
 intasmc_match(struct device *, void *, void *);
@@ -243,6 +255,8 @@ asmc_attach(struct device *parent, struc
 {
struct asmc_softc *sc = (struct asmc_softc *)self;
struct isa_attach_args *ia = aux;
+   uint8_t buf[6];
+   int i;
 
if (bus_space_map(ia->ia_iot, ia->ia_iobase, ia->ia_iosize, 0,
&sc->sc_ioh)) {
@@ -251,23 +265,64 @@ asmc_attach(struct device *parent, 

Re: utf8 hack for ls

2015-10-23 Thread Ted Unangst
Nicholas Marriott wrote:
> Hi
> 
> This doesn't account for UTF-8 double width characters, so they will
> still throw the column widths off?

right. maybe we will steal some code from tmux for that :). but getting
u8len() into the right places is the first step.

i don't think we want a isu8cont() function in every program either, but i'm
adding it here and there until we see where it's needed. 



Re: utf8 hack for ls

2015-10-23 Thread Stefan Sperling
On Fri, Oct 23, 2015 at 02:52:13PM +0200, Peter Hessler wrote:
> As a different approach to ls, I wrote this a while ago.  This uses the
> wchar_t functions, but only in putname().

That's like the colorls port does it.
I'm not sure if that's the best answer either, this diff would
already be in base ls(1) if it was...

> On 2015 Oct 23 (Fri) at 08:42:52 -0400 (-0400), Ted Unangst wrote:
> :So, third diff to ponder as we evaluate this approach. This one also uses a
> :u8len() function to help get the column widths correct.
> :
> :(Still not dealing with combining or otherwise not 1 width glyphs.)
> :
> 
> Index: ls.c
> ===
> RCS file: /cvs/src/bin/ls/ls.c,v
> retrieving revision 1.43
> diff -u -p -u -p -r1.43 ls.c
> --- ls.c  9 Oct 2015 01:37:06 -   1.43
> +++ ls.c  19 Oct 2015 10:03:04 -
> @@ -50,6 +50,8 @@
>  #include 
>  #include 
>  
> +#include 
> +
>  #include "ls.h"
>  #include "extern.h"
>  
> @@ -102,6 +104,8 @@ ls_main(int argc, char *argv[])
>   int ch, fts_options, notused;
>   int kflag = 0, width = 0;
>   char *p;
> +
> + setlocale(LC_CTYPE, "");
>  
>   /* Terminal defaults to -Cq, non-terminal defaults to -1. */
>   if (isatty(STDOUT_FILENO)) {
> Index: util.c
> ===
> RCS file: /cvs/src/bin/ls/util.c,v
> retrieving revision 1.16
> diff -u -p -u -p -r1.16 util.c
> --- util.c21 Nov 2013 15:54:45 -  1.16
> +++ util.c19 Oct 2015 10:03:04 -
> @@ -42,17 +42,32 @@
>  #include 
>  #include 
>  
> +#include 
> +#include 
> +
>  #include "ls.h"
>  #include "extern.h"
>  
>  int
>  putname(char *name)
>  {
> - int len;
> + wchar_t wname;
> + mbstate_t state;
> + size_t n = strlen(name);
> + int len, wlen = 0;
> +
> + /* initialize the conversion state */
> + memset(&state, 0, sizeof(state));
> +
> + while ((len = mbrtowc(&wname, name, n, &state)) > 0) {
> + wprintf(L"%lc",
> + (!iswprint((wchar_t)wname) && f_nonprint) ? '?' : wname);
> + name += len;
> + if (len == 1)
> + wlen++;
> + }
>  
> - for (len = 0; *name; len++, name++)
> - putchar((!isprint((unsigned char)*name) && f_nonprint) ? '?' : 
> *name);
> - return len;
> + return (wlen);
>  }
>  
>  void
> 
> 
> 
> -- 
> "Do not meddle in the affairs of wizards, for you are crunchy and good
> with ketchup."



Re: utf8 hack for ls

2015-10-23 Thread Ted Unangst
Stefan Sperling wrote:
> This removes the isprint() check entirely. Do we really want that?
> 
> To what degree should tools like ls protect terminals from escape codes?

I think this is beyond the scope of what ls should care about. du doesn't have
such a check. Does the shell perform a check before tab completing?

If there are evil filenames laying about, they are going to hit the terminal
at some point. There's no way we can insulate every program, and insulating
some random selection of programs doesn't offer real security.



Re: utf8 hack for ls

2015-10-23 Thread Ted Unangst
Peter Hessler wrote:
> As a different approach to ls, I wrote this a while ago.  This uses the
> wchar_t functions, but only in putname().

This will correct the alignment of columns, but if you have a filename like
pöp
the columns will be super wide instead of nicely sized.



Re: does anoybody use ul?

2015-10-23 Thread Christian Weisgerber
Ted Unangst:

> --- ul.c  10 Oct 2015 16:15:03 -  1.19
> +++ ul.c  23 Oct 2015 10:29:43 -
> @@ -241,6 +241,8 @@ mfilter(FILE *f)
>   obuf[col].c_mode |= BOLD|mode;
>   else
>   obuf[col].c_mode = mode;
> + if ((c & (0x80 | 0x40)) == 0x80 && col > 0)
> + obuf[col].c_mode = obuf[col - 1].c_mode;
>   col++;
>   if (col > maxcol)
>   maxcol = col;

That doesn't quite work.  Check out this:

mandoc /usr/share/man/man1/ksh.1 | sed -n 1185,1190p | ul

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: utf8 hack for ls

2015-10-23 Thread Nicholas Marriott
Hi

This doesn't account for UTF-8 double width characters, so they will
still throw the column widths off?



On Fri, Oct 23, 2015 at 08:42:52AM -0400, Ted Unangst wrote:
> So, third diff to ponder as we evaluate this approach. This one also uses a
> u8len() function to help get the column widths correct.
> 
> (Still not dealing with combining or otherwise not 1 width glyphs.)
> 
> Index: ls.c
> ===
> RCS file: /cvs/src/bin/ls/ls.c,v
> retrieving revision 1.43
> diff -u -p -r1.43 ls.c
> --- ls.c  9 Oct 2015 01:37:06 -   1.43
> +++ ls.c  23 Oct 2015 12:39:52 -
> @@ -410,6 +410,8 @@ traverse(int argc, char *argv[], int opt
>   fts_close(ftsp);
>  }
>  
> +extern size_t u8len(char *);
> +
>  /*
>   * Display() takes a linked list of FTSENT structures and passes the list
>   * along with any other necessary information to the print function.  P
> @@ -474,8 +476,8 @@ display(FTSENT *p, FTSENT *list)
>   continue;
>   }
>   }
> - if (cur->fts_namelen > maxlen)
> - maxlen = cur->fts_namelen;
> + if (u8len(cur->fts_name) > maxlen)
> + maxlen = u8len(cur->fts_name);
>   if (needstats) {
>   sp = cur->fts_statp;
>   if (sp->st_blocks > maxblock)
> Index: util.c
> ===
> RCS file: /cvs/src/bin/ls/util.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 util.c
> --- util.c21 Nov 2013 15:54:45 -  1.16
> +++ util.c23 Oct 2015 12:39:57 -
> @@ -46,12 +46,31 @@
>  #include "extern.h"
>  
>  int
> +isu8cont(unsigned char c)
> +{
> + return ((c & (0x80 | 0x40)) == 0x80);
> +}
> +size_t
> +u8len(const char *s)
> +{
> + size_t len = 0;
> +
> + for (; *s; s++)
> + if (!isu8cont(*s))
> + len++;
> + return len;
> +}
> +
> +int
>  putname(char *name)
>  {
>   int len;
>  
> - for (len = 0; *name; len++, name++)
> - putchar((!isprint((unsigned char)*name) && f_nonprint) ? '?' : 
> *name);
> + for (len = 0; *name; name++) {
> + if (!isu8cont(*name))
> + len++;
> + putchar(*name);
> + }
>   return len;
>  }
>  
> 



Re: utf8 hack for ls

2015-10-23 Thread Peter Hessler
As a different approach to ls, I wrote this a while ago.  This uses the
wchar_t functions, but only in putname().



On 2015 Oct 23 (Fri) at 08:42:52 -0400 (-0400), Ted Unangst wrote:
:So, third diff to ponder as we evaluate this approach. This one also uses a
:u8len() function to help get the column widths correct.
:
:(Still not dealing with combining or otherwise not 1 width glyphs.)
:

Index: ls.c
===
RCS file: /cvs/src/bin/ls/ls.c,v
retrieving revision 1.43
diff -u -p -u -p -r1.43 ls.c
--- ls.c9 Oct 2015 01:37:06 -   1.43
+++ ls.c19 Oct 2015 10:03:04 -
@@ -50,6 +50,8 @@
 #include 
 #include 
 
+#include 
+
 #include "ls.h"
 #include "extern.h"
 
@@ -102,6 +104,8 @@ ls_main(int argc, char *argv[])
int ch, fts_options, notused;
int kflag = 0, width = 0;
char *p;
+
+   setlocale(LC_CTYPE, "");
 
/* Terminal defaults to -Cq, non-terminal defaults to -1. */
if (isatty(STDOUT_FILENO)) {
Index: util.c
===
RCS file: /cvs/src/bin/ls/util.c,v
retrieving revision 1.16
diff -u -p -u -p -r1.16 util.c
--- util.c  21 Nov 2013 15:54:45 -  1.16
+++ util.c  19 Oct 2015 10:03:04 -
@@ -42,17 +42,32 @@
 #include 
 #include 
 
+#include 
+#include 
+
 #include "ls.h"
 #include "extern.h"
 
 int
 putname(char *name)
 {
-   int len;
+   wchar_t wname;
+   mbstate_t state;
+   size_t n = strlen(name);
+   int len, wlen = 0;
+
+   /* initialize the conversion state */
+   memset(&state, 0, sizeof(state));
+
+   while ((len = mbrtowc(&wname, name, n, &state)) > 0) {
+   wprintf(L"%lc",
+   (!iswprint((wchar_t)wname) && f_nonprint) ? '?' : wname);
+   name += len;
+   if (len == 1)
+   wlen++;
+   }
 
-   for (len = 0; *name; len++, name++)
-   putchar((!isprint((unsigned char)*name) && f_nonprint) ? '?' : 
*name);
-   return len;
+   return (wlen);
 }
 
 void



-- 
"Do not meddle in the affairs of wizards, for you are crunchy and good
with ketchup."



Re: utf8 hack for ls

2015-10-23 Thread Stefan Sperling
On Fri, Oct 23, 2015 at 08:42:52AM -0400, Ted Unangst wrote:
> So, third diff to ponder as we evaluate this approach. This one also uses a
> u8len() function to help get the column widths correct.
> 
> (Still not dealing with combining or otherwise not 1 width glyphs.)
> 
> Index: ls.c
> ===
> RCS file: /cvs/src/bin/ls/ls.c,v
> retrieving revision 1.43
> diff -u -p -r1.43 ls.c
> --- ls.c  9 Oct 2015 01:37:06 -   1.43
> +++ ls.c  23 Oct 2015 12:39:52 -
> @@ -410,6 +410,8 @@ traverse(int argc, char *argv[], int opt
>   fts_close(ftsp);
>  }
>  
> +extern size_t u8len(char *);
> +
>  /*
>   * Display() takes a linked list of FTSENT structures and passes the list
>   * along with any other necessary information to the print function.  P
> @@ -474,8 +476,8 @@ display(FTSENT *p, FTSENT *list)
>   continue;
>   }
>   }
> - if (cur->fts_namelen > maxlen)
> - maxlen = cur->fts_namelen;
> + if (u8len(cur->fts_name) > maxlen)
> + maxlen = u8len(cur->fts_name);
>   if (needstats) {
>   sp = cur->fts_statp;
>   if (sp->st_blocks > maxblock)
> Index: util.c
> ===
> RCS file: /cvs/src/bin/ls/util.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 util.c
> --- util.c21 Nov 2013 15:54:45 -  1.16
> +++ util.c23 Oct 2015 12:39:57 -
> @@ -46,12 +46,31 @@
>  #include "extern.h"
>  
>  int
> +isu8cont(unsigned char c)
> +{
> + return ((c & (0x80 | 0x40)) == 0x80);
> +}
> +size_t
> +u8len(const char *s)
> +{
> + size_t len = 0;
> +
> + for (; *s; s++)
> + if (!isu8cont(*s))
> + len++;
> + return len;
> +}
> +
> +int
>  putname(char *name)
>  {
>   int len;
>  
> - for (len = 0; *name; len++, name++)
> - putchar((!isprint((unsigned char)*name) && f_nonprint) ? '?' : 
> *name);
> + for (len = 0; *name; name++) {
> + if (!isu8cont(*name))
> + len++;
> + putchar(*name);
> + }
>   return len;
>  }
>  

This removes the isprint() check entirely. Do we really want that?

To what degree should tools like ls protect terminals from escape codes?



Re: towards mpsafe rtfree(9)

2015-10-23 Thread Alexander Bluhm
On Fri, Oct 23, 2015 at 02:41:34PM +0200, Martin Pieuchot wrote:
> On 22/10/15(Thu) 19:42, Martin Pieuchot wrote:
> > Now that we have a single refcounting mechanism for route entries, I'd
> > like to use atomic operations and grab the KERNEL_LOCK only if a CPU is
> > dropping the last reference on an entry.
> > 
> > Currently this only matters for MPLS.  I intentionally use atomic_* ops
> > because I'd like to see be able to see if a counter goes negative.
> > 
> > For symmetry reasons I'm also moving the KERNEL_LOCK() inside rtalloc().
> > These two functions are my current targets.
> > 
> > Comments, oks?
> 
> Updated diff after some comments from dlg@ and bluhm@.

OK bluhm@

> 
> Index: net/route.c
> ===
> RCS file: /cvs/src/sys/net/route.c,v
> retrieving revision 1.258
> diff -u -p -r1.258 route.c
> --- net/route.c   22 Oct 2015 17:19:38 -  1.258
> +++ net/route.c   23 Oct 2015 12:38:58 -
> @@ -215,6 +215,7 @@ rtalloc(struct sockaddr *dst, int flags,
>   info.rti_info[RTAX_DST] = dst;
>  
>   s = splsoftnet();
> + KERNEL_LOCK();
>   rt = rtable_match(tableid, dst);
>   if (rt != NULL) {
>   if ((rt->rt_flags & RTF_CLONING) && ISSET(flags, RT_RESOLVE)) {
> @@ -236,6 +237,7 @@ miss:
>   if (ISSET(flags, RT_REPORT))
>   rt_missmsg(RTM_MISS, &info, 0, NULL, error, tableid);
>   }
> + KERNEL_UNLOCK();
>   splx(s);
>   return (rt);
>  }
> @@ -337,25 +339,29 @@ rtalloc_mpath(struct sockaddr *dst, uint
>  void
>  rtref(struct rtentry *rt)
>  {
> - rt->rt_refcnt++;
> + atomic_inc_int(&rt->rt_refcnt);
>  }
>  
>  void
>  rtfree(struct rtentry *rt)
>  {
>   struct ifaddr   *ifa;
> + int  refcnt;
>  
>   if (rt == NULL)
>   return;
>  
> - if (--rt->rt_refcnt <= 0) {
> + refcnt = (int)atomic_dec_int_nv(&rt->rt_refcnt);
> + if (refcnt <= 0) {
>   KASSERT(!ISSET(rt->rt_flags, RTF_UP));
>   KASSERT(!RT_ROOT(rt));
> - rttrash--;
> - if (rt->rt_refcnt < 0) {
> + atomic_dec_int(&rttrash);
> + if (refcnt < 0) {
>   printf("rtfree: %p not freed (neg refs)\n", rt);
>   return;
>   }
> +
> + KERNEL_LOCK();
>   rt_timer_remove_all(rt);
>   ifa = rt->rt_ifa;
>   if (ifa)
> @@ -368,6 +374,8 @@ rtfree(struct rtentry *rt)
>   if (rt->rt_gateway)
>   free(rt->rt_gateway, M_RTABLE, 0);
>   free(rt_key(rt), M_RTABLE, 0);
> + KERNEL_UNLOCK();
> +
>   pool_put(&rtentry_pool, rt);
>   }
>  }
> @@ -773,7 +781,7 @@ rtrequest1(int req, struct rt_addrinfo *
>   rt->rt_flags &= ~RTF_UP;
>   if ((ifa = rt->rt_ifa) && ifa->ifa_rtrequest)
>   ifa->ifa_rtrequest(RTM_DELETE, rt);
> - rttrash++;
> + atomic_inc_int(&rttrash);
>  
>   if (ret_nrt != NULL)
>   *ret_nrt = rt;



rt_ifp is never NULL

2015-10-23 Thread Martin Pieuchot
ok?

Index: netinet/in_pcb.c
===
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.185
diff -u -p -r1.185 in_pcb.c
--- netinet/in_pcb.c20 Oct 2015 18:04:03 -  1.185
+++ netinet/in_pcb.c23 Oct 2015 12:42:18 -
@@ -858,7 +858,7 @@ in_selectsrc(struct in_addr **insrc, str
rtfree(ro->ro_rt);
ro->ro_rt = NULL;
}
-   if ((ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL)) {
+   if ((ro->ro_rt == NULL)) {
/* No route yet, so try to acquire one */
ro->ro_dst.sa_family = AF_INET;
ro->ro_dst.sa_len = sizeof(struct sockaddr_in);
@@ -877,7 +877,7 @@ in_selectsrc(struct in_addr **insrc, str
 * If we found a route, use the address
 * corresponding to the outgoing interface.
 */
-   if (ro->ro_rt && ro->ro_rt->rt_ifp)
+   if (ro->ro_rt != NULL)
ia = ifatoia(ro->ro_rt->rt_ifa);
 
if (ia == NULL)



utf8 hack for ls

2015-10-23 Thread Ted Unangst
So, third diff to ponder as we evaluate this approach. This one also uses a
u8len() function to help get the column widths correct.

(Still not dealing with combining or otherwise not 1 width glyphs.)

Index: ls.c
===
RCS file: /cvs/src/bin/ls/ls.c,v
retrieving revision 1.43
diff -u -p -r1.43 ls.c
--- ls.c9 Oct 2015 01:37:06 -   1.43
+++ ls.c23 Oct 2015 12:39:52 -
@@ -410,6 +410,8 @@ traverse(int argc, char *argv[], int opt
fts_close(ftsp);
 }
 
+extern size_t u8len(char *);
+
 /*
  * Display() takes a linked list of FTSENT structures and passes the list
  * along with any other necessary information to the print function.  P
@@ -474,8 +476,8 @@ display(FTSENT *p, FTSENT *list)
continue;
}
}
-   if (cur->fts_namelen > maxlen)
-   maxlen = cur->fts_namelen;
+   if (u8len(cur->fts_name) > maxlen)
+   maxlen = u8len(cur->fts_name);
if (needstats) {
sp = cur->fts_statp;
if (sp->st_blocks > maxblock)
Index: util.c
===
RCS file: /cvs/src/bin/ls/util.c,v
retrieving revision 1.16
diff -u -p -r1.16 util.c
--- util.c  21 Nov 2013 15:54:45 -  1.16
+++ util.c  23 Oct 2015 12:39:57 -
@@ -46,12 +46,31 @@
 #include "extern.h"
 
 int
+isu8cont(unsigned char c)
+{
+   return ((c & (0x80 | 0x40)) == 0x80);
+}
+size_t
+u8len(const char *s)
+{
+   size_t len = 0;
+
+   for (; *s; s++)
+   if (!isu8cont(*s))
+   len++;
+   return len;
+}
+
+int
 putname(char *name)
 {
int len;
 
-   for (len = 0; *name; len++, name++)
-   putchar((!isprint((unsigned char)*name) && f_nonprint) ? '?' : 
*name);
+   for (len = 0; *name; name++) {
+   if (!isu8cont(*name))
+   len++;
+   putchar(*name);
+   }
return len;
 }
 



Re: towards mpsafe rtfree(9)

2015-10-23 Thread Martin Pieuchot
On 22/10/15(Thu) 19:42, Martin Pieuchot wrote:
> Now that we have a single refcounting mechanism for route entries, I'd
> like to use atomic operations and grab the KERNEL_LOCK only if a CPU is
> dropping the last reference on an entry.
> 
> Currently this only matters for MPLS.  I intentionally use atomic_* ops
> because I'd like to see be able to see if a counter goes negative.
> 
> For symmetry reasons I'm also moving the KERNEL_LOCK() inside rtalloc().
> These two functions are my current targets.
> 
> Comments, oks?

Updated diff after some comments from dlg@ and bluhm@.

Index: net/route.c
===
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.258
diff -u -p -r1.258 route.c
--- net/route.c 22 Oct 2015 17:19:38 -  1.258
+++ net/route.c 23 Oct 2015 12:38:58 -
@@ -215,6 +215,7 @@ rtalloc(struct sockaddr *dst, int flags,
info.rti_info[RTAX_DST] = dst;
 
s = splsoftnet();
+   KERNEL_LOCK();
rt = rtable_match(tableid, dst);
if (rt != NULL) {
if ((rt->rt_flags & RTF_CLONING) && ISSET(flags, RT_RESOLVE)) {
@@ -236,6 +237,7 @@ miss:
if (ISSET(flags, RT_REPORT))
rt_missmsg(RTM_MISS, &info, 0, NULL, error, tableid);
}
+   KERNEL_UNLOCK();
splx(s);
return (rt);
 }
@@ -337,25 +339,29 @@ rtalloc_mpath(struct sockaddr *dst, uint
 void
 rtref(struct rtentry *rt)
 {
-   rt->rt_refcnt++;
+   atomic_inc_int(&rt->rt_refcnt);
 }
 
 void
 rtfree(struct rtentry *rt)
 {
struct ifaddr   *ifa;
+   int  refcnt;
 
if (rt == NULL)
return;
 
-   if (--rt->rt_refcnt <= 0) {
+   refcnt = (int)atomic_dec_int_nv(&rt->rt_refcnt);
+   if (refcnt <= 0) {
KASSERT(!ISSET(rt->rt_flags, RTF_UP));
KASSERT(!RT_ROOT(rt));
-   rttrash--;
-   if (rt->rt_refcnt < 0) {
+   atomic_dec_int(&rttrash);
+   if (refcnt < 0) {
printf("rtfree: %p not freed (neg refs)\n", rt);
return;
}
+
+   KERNEL_LOCK();
rt_timer_remove_all(rt);
ifa = rt->rt_ifa;
if (ifa)
@@ -368,6 +374,8 @@ rtfree(struct rtentry *rt)
if (rt->rt_gateway)
free(rt->rt_gateway, M_RTABLE, 0);
free(rt_key(rt), M_RTABLE, 0);
+   KERNEL_UNLOCK();
+
pool_put(&rtentry_pool, rt);
}
 }
@@ -773,7 +781,7 @@ rtrequest1(int req, struct rt_addrinfo *
rt->rt_flags &= ~RTF_UP;
if ((ifa = rt->rt_ifa) && ifa->ifa_rtrequest)
ifa->ifa_rtrequest(RTM_DELETE, rt);
-   rttrash++;
+   atomic_inc_int(&rttrash);
 
if (ret_nrt != NULL)
*ret_nrt = rt;



Re: connect routing domains on layer 2

2015-10-23 Thread Martin Pieuchot
On 23/10/15(Fri) 13:21, David Gwynne wrote:
> 
> > On 23 Oct 2015, at 09:00, Reyk Floeter  wrote:
> > 
> > Hi,
> > 
> > this diff allows to interconnect routing domains.
> > 
> > It is very useful to route traffic from one routing domain to another,
> > without using the pf "rtable" hack (tested in production for a long
> > time).
> > 
> > eg.,
> > # ifconfig vether0 10.0.1.1/24
> > # ifconfig vether1 rdomain 1 10.0.1.2/24
> > # ping 10.1.1.2
> > # route -T 1 add default 10.0.1.1
> > # ifconfig bridge0 add vether0 add em0
> > 
> > for hacking/testing, you can do thing like:
> > # dhcpd vether0
> > # dhclient vether1
> > 
> > It has been discussed in much detail if this is possible with
> > bridge(4).  It is not.  The bridge is not designed for it and explain
> > on request.
> 
> the diff implements a crossover option, but the example above doesnt use 
> them. does that mean you can use a bridge to build crossovers without the 
> extra code, or the example is wrong?

As said yesterday an alternative would be to use the bridge(4) as below:

Index: net/if_bridge.c
===
RCS file: /cvs/src/sys/net/if_bridge.c,v
retrieving revision 1.268
diff -u -p -r1.268 if_bridge.c
--- net/if_bridge.c 12 Oct 2015 10:03:25 -  1.268
+++ net/if_bridge.c 23 Oct 2015 11:52:13 -
@@ -1218,10 +1218,12 @@ bridgeintr_frame(struct bridge_softc *sc
if (m == NULL)
return;
/*
-* If the packet is a multicast or broadcast OR if we don't
-* know any better, forward it to all interfaces.
+* If the packet is a multicast/broadcast, if we don't know
+* any better or if the destination is in a different routing
+* domain, forward it to all interfaces.
 */
-   if ((m->m_flags & (M_BCAST | M_MCAST)) || dst_if == NULL) {
+   if ((m->m_flags & (M_BCAST | M_MCAST)) || dst_if == NULL ||
+   (dst_if->if_rdomain != src_if->if_rdomain)) {
sc->sc_if.if_imcasts++;
bridge_broadcast(sc, src_if, &eh, m);
return;



utf8 in rs

2015-10-23 Thread Ted Unangst
rs doesn't print nicely aligned columns with utf-8 inputs.
there's a few ways to handle this; here's just one.

note that the source is riddled with lots of code like:
if (maxlen < p - *ep)   /* update maxlen */
maxlen = p - *ep;

I'm very scared to try counting chars vs bytes upfront in such code. However,
the code that prints spaces to pad the output is much simpler.

i'm not settled on this approach, but wanted people to look this and compare
it to other ways of doing things.

Index: rs.c
===
RCS file: /cvs/src/usr.bin/rs/rs.c,v
retrieving revision 1.27
diff -u -p -r1.27 rs.c
--- rs.c9 Oct 2015 01:37:08 -   1.27
+++ rs.c23 Oct 2015 11:40:11 -
@@ -198,6 +198,12 @@ putfile(void)
}
 }
 
+int
+isu8cont(unsigned char c)
+{
+   return ((c & (0x80 | 0x40)) == 0x80);
+}
+
 void
 prints(char *s, int col)
 {
@@ -210,8 +216,11 @@ prints(char *s, int col)
if (flags & RIGHTADJUST)
while (n-- > 0)
putchar(osep);
-   for (p = s; *p; p++)
+   for (p = s; *p; p++) {
+   if (isu8cont(*p))
+   n++;
putchar(*p);
+   }
while (n-- > 0)
putchar(osep);
 }



Re: does anoybody use ul?

2015-10-23 Thread Stefan Sperling
On Fri, Oct 23, 2015 at 06:32:32AM -0400, Ted Unangst wrote:
> Stefan Sperling wrote:
> > On Fri, Oct 23, 2015 at 05:50:53AM -0400, Ted Unangst wrote:
> > > well, it doesn't work with utf-8 because it tries to underline only half 
> > > the
> > > character. i'm aiming for the "quick fix"...
> > 
> > Why not at least try a kind of better fix to see how it would work?
> 
> Is this "better"? It copies the state of the previous letter to the next if
> it's a utf-8 continuation byte.

Nice trick.
Could the application define a macro with a meaningful name for this?

> FreeBSD has full blown multibyte support as well, but it requires switching
> everything to wchar_t. Which way are we going here?

I think we're trying to avoid wchar_t if possible.
 
> Index: ul.c
> ===
> RCS file: /cvs/src/usr.bin/ul/ul.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 ul.c
> --- ul.c  10 Oct 2015 16:15:03 -  1.19
> +++ ul.c  23 Oct 2015 10:29:43 -
> @@ -241,6 +241,8 @@ mfilter(FILE *f)
>   obuf[col].c_mode |= BOLD|mode;
>   else
>   obuf[col].c_mode = mode;
> + if ((c & (0x80 | 0x40)) == 0x80 && col > 0)
> + obuf[col].c_mode = obuf[col - 1].c_mode;
>   col++;
>   if (col > maxcol)
>   maxcol = col;



Re: towards mpsafe rtfree(9)

2015-10-23 Thread Martin Pieuchot
On 22/10/15(Thu) 20:41, Bret Lambert wrote:
> On Thu, Oct 22, 2015 at 07:42:24PM +0200, Martin Pieuchot wrote:
> > Now that we have a single refcounting mechanism for route entries, I'd
> > like to use atomic operations and grab the KERNEL_LOCK only if a CPU is
> > dropping the last reference on an entry.
> > 
> > Currently this only matters for MPLS.  I intentionally use atomic_* ops
> > because I'd like to see be able to see if a counter goes negative.
> > 
> > For symmetry reasons I'm also moving the KERNEL_LOCK() inside rtalloc().
> > These two functions are my current targets.
> > 
> > Comments, oks?
> 
> One comment inline...

Thanks for looking into this.

> >  void
> > @@ -348,14 +350,16 @@ rtfree(struct rtentry *rt)
> > if (rt == NULL)
> > return;
> >  
> > -   if (--rt->rt_refcnt <= 0) {
> > +   if (atomic_dec_int_nv(&rt->rt_refcnt) <= 0) {
> > KASSERT(!ISSET(rt->rt_flags, RTF_UP));
> > KASSERT(!RT_ROOT(rt));
> > -   rttrash--;
> > +   atomic_dec_int(&rttrash);
> 
> Are you using rttrash for debugging? It's unused anywhere else,
> and if it's just incrementing and decrementing a counter only
> used for debugging (or possibly not at all!), it might be
> better to put it in DEBUG kernels, or just remove it entirely.

Yes, I use it for debugging.  I'm all for such cleanup (including
removing rt_use, exporting the real refcnt to userland and using
the refcnt(9) API) once possible bugs are founds.



Re: support for malloc allocation canaries

2015-10-23 Thread Janne Johansson
With this patch on -current and
ln -sf CJ /etc/malloc.conf
a lot of things stopped working, like "man ls" and "tmux".
With only C or only J, the system seems to work ok, but with both it
doesn't.
Will check the resulting core files.
ntpd and tmux both bombed out on memset inside realloc if I read the dumps
ok:

Program terminated with signal 11, Segmentation fault.
(no debugging symbols found)
Loaded symbols for /usr/sbin/ntpd
Reading symbols from /usr/lib/libutil.so.12.1...done.
Loaded symbols for /usr/lib/libutil.so.12.1
Reading symbols from /usr/lib/libtls.so.9.0...done.
Loaded symbols for /usr/lib/libtls.so.9.0
Reading symbols from /usr/lib/libssl.so.37.0...done.
Loaded symbols for /usr/lib/libssl.so.37.0
Reading symbols from /usr/lib/libcrypto.so.36.0...done.
Loaded symbols for /usr/lib/libcrypto.so.36.0
Reading symbols from /usr/lib/libc.so.84.0...done.
Loaded symbols for /usr/lib/libc.so.84.0
Reading symbols from /usr/libexec/ld.so...done.
Loaded symbols for /usr/libexec/ld.so
#0  L1 () at /usr/src/lib/libc/arch/amd64/string/memset.S:51
51  L1: rep
(gdb) bt full
#0  L1 () at /usr/src/lib/libc/arch/amd64/string/memset.S:51
No locals.
#1  0x16e1a67748f2 in realloc (ptr=0x16e22de6fd20, size=28)
at /usr/src/lib/libc/stdlib/malloc.c:1420
r = Variable "r" is not available.



2015-10-23 7:18 GMT+02:00 Daniel Micay :
>
> Hi,
>
> This patch adds an opt-in malloc configuration option placing canaries
after
> small allocations to detect heap overflows on free(...). It's intended to
be
> used alongside guard pages for large allocations. Since it's essentially
> adding extra padding to all small allocations, a small heap overflow will
be
> rendered harmless.
>
> The current implementation uses pointer-size canaries, but it could be
easily
> extended to allow bumping up the size of the canaries by passing the
option
> multiple times. The entry points into malloc account for the canary size
when
> it's enabled and then it's generated on allocation and checked on free.
Small
> allocations without room for a canary are simply turned into large
> allocations. Some care needs to be taken to avoid clobbering the canary
in the
> junk filling code and realloc copying.
>
> The canary is placed at the very end of the memory allocations so there
will
> often be slack space in between the real allocation and the canary
preventing
> small overflows from being detected. It would be much better at detecting
> corruption with finer-grained size classes. The extreme would be every
> multiple of the alignment, but logarithmic growth would be more realistic
(see
> jemalloc's size classes). Finer-grained size classes would also reduce the
> memory overhead caused by allocations being pushed into the next size
class by
> the canary.
>
> The canaries are currently generated with canary_value ^
hash(canary_address).
> It would be best to avoid involving addresses to avoid introducing address
> leaks via read overflows where there were none before, but it's the
easiest
> way to get unique canaries and is a minor issue to improve down the road.
>
> I implemented this feature after porting OpenBSD malloc to Android (in
> CopperheadOS) and it has found a few bugs in the app ecosystem. Note that
I've
> only heavily tested it there, not on OpenBSD itself. I'm not sure if you
want
> this feature but it seemed worth submitting.
>
> Hopefully you don't mind a patch generated with Git. :)
>
> diff --git a/stdlib/malloc.c b/stdlib/malloc.c
> index 424dd77..65b5027 100644
> --- a/stdlib/malloc.c
> +++ b/stdlib/malloc.c
> @@ -185,12 +185,14 @@ struct malloc_readonly {
> int malloc_move;/* move allocations to end of
page? */
> int malloc_realloc; /* always realloc? */
> int malloc_xmalloc; /* xmalloc behaviour? */
> +   size_t  malloc_canaries;/* use canaries after chunks? */
> size_t  malloc_guard;   /* use guard pages after
allocations? */
> u_int   malloc_cache;   /* free pages we cache */
>  #ifdef MALLOC_STATS
> int malloc_stats;   /* dump statistics at end */
>  #endif
> u_int32_t malloc_canary;/* Matched against ones in
malloc_pool */
> +   uintptr_t malloc_chunk_canary;
>  };
>
>  /* This object is mapped PROT_READ after initialisation to prevent
tampering */
> @@ -526,6 +528,12 @@ omalloc_init(struct dir_info **dp)
> case 'A':
> mopts.malloc_abort = 1;
> break;
> +   case 'c':
> +   mopts.malloc_canaries = 0;
> +   break;
> +   case 'C':
> +   mopts.malloc_canaries = sizeof(void *);
> +   break;
>  #ifdef MALLOC_STATS
> case 'd':
> mopts.malloc_stats = 0;
> @@ -619,6 +627,9 @@ oma

Further cleanup of Russian calendars

2015-10-23 Thread Vadim Zhukov
Further cleanup in Russian calendars:

  * Fix #ifndef safeguards (rename/add where missing);
  * Use consistent spelling for year when it's mentioned in day desc;
  * Tweak some wrong casing cases;
  * Remove calendar.msk since Moscow doesn't have summer time anymore,
and that was the only thing this file was about;
  * A few other corrections.

Still seeking for a way to define a day with fixed shift from the year
start: the Programmer's Day is official in Russia, happens at 256th
day of the year, but calendar(1) handles up to 31 days per month max.

Okay?
--
WBR,
  Vadim Zhukov


Index: calendar.all
===
RCS file: /cvs/src/usr.bin/calendar/calendars/ru_RU.UTF-8/calendar.all,v
retrieving revision 1.1
diff -u -p -r1.1 calendar.all
--- calendar.all23 Oct 2015 09:32:14 -  1.1
+++ calendar.all23 Oct 2015 11:09:26 -
@@ -4,14 +4,13 @@
  * $OpenBSD: calendar.all,v 1.1 2015/10/23 09:32:14 tedu Exp $
  */
 
-#ifndef _ru_RU_KOI8_R_all
-#define _ru_RU_KOI8_R_all
+#ifndef _ru_RU_UTF_8_all
+#define _ru_RU_UTF_8_all
 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 
-#endif /* !_ru_RU_KOI8_R_all */
+#endif /* !_ru_RU_UTF_8_all */
Index: calendar.common
===
RCS file: /cvs/src/usr.bin/calendar/calendars/ru_RU.UTF-8/calendar.common,v
retrieving revision 1.1
diff -u -p -r1.1 calendar.common
--- calendar.common 23 Oct 2015 09:32:14 -  1.1
+++ calendar.common 23 Oct 2015 11:09:26 -
@@ -1,11 +1,12 @@
+B
 /*
  * Русские праздники и памятные даты
  *
  * $OpenBSD: calendar.common,v 1.1 2015/10/23 09:32:14 tedu Exp $
  */
 
-#ifndef _ru_RU_KOI8_R_common_
-#define _ru_RU_KOI8_R_common_
+#ifndef _ru_RU_UTF_8_common_
+#define _ru_RU_UTF_8_common_
 
 LANG=ru_RU.UTF-8
 BODUN=Бодун на утро от:
@@ -15,7 +16,7 @@ BODUN=Бодун на утро от:
 01/12  День работников прокуратуры
 01/13  День Российской печати
 01/14  Старый новый год
-01/25  Татьянин день. Студенческий праздник.
+01/25  Татьянин день. Студенческий праздник
 01/27  Всемирный день таможни
 
 /* Февраль */
@@ -61,7 +62,7 @@ BODUN=Бодун на утро от:
 05/27  Общероссийский день библиотек
 05/28  День пограничника
 05/31  День без табака
-05/Sun+2   День Матери (2-ое воскресенье Мая)
+05/Sun+2   День матери
 05/Sun+5   День химика
 
 /* Июнь */
@@ -84,18 +85,18 @@ BODUN=Бодун на утро от:
 07/11  Всемирный день народонаселения
 07/Sun+2   День российской почты
 07/Sun+3   День металлурга
-07/Sun+4   День Военно-Морского Флота
+07/Sun+4   День военно-морского флота
 
 /* Август */
 08/02  День воздушно-десантных войск России
 08/06  Всемирный день борьбы за запрещение 
ядерного оружия.
 08/09  Всемирный день коренных народов мира
-08/22  День Государственного Флага Р
оссийской Федерации
+08/22  День государственного флага Р
оссийской Федерации
 08/27  День российского кино
 08/SunFirstДень железнодорожника
 08/Sat+2   День физкультурника
 08/Sun+2   День строителя
-08/Sun+3   День Воздушного Флота России
+08/Sun+3   День воздушного флота России
 08/SunLast День шахтера
 
 /* Сентябрь */
@@ -106,7 +107,7 @@ BODUN=Бодун на утро от:
 09/27  Международный день туризма
 09/28  Всемирный день моря
 09/SunFirstДень работников нефтяной и 
газовой промышленности
-09/Sun+2   День танкистов
+09/Sun+2   День танкиста
 09/Sun+3   День работников леса
 09/SunLast День машиностроителя
 
@@ -116,9 +117,9 @@ BODUN=Бодун на утро от:
 10/05  Международный день учителя
 10/16  Всемирный день продовольствия
 10/17  Международный день протеста против 
нищеты
-10/24  Несчастливый день на Байконуре, после 
1960,1963гг
+10/24  Несчастливый день на Байконуре
 10/24  День Организации Объединенных Наций
-10/25  День тамоÐ

Re: does anoybody use ul?

2015-10-23 Thread Ingo Schwarze
Hi Stuart,

Stuart Henderson wrote on Fri, Oct 23, 2015 at 11:28:35AM +0100:
> On 2015/10/23 11:52, Ingo Schwarze wrote:

>> I didn't use it so far, but now that you made me look at it, i'm
>> likely to start using it almost daily.  I often felt unhappy that
>> my gmdiff tool (for comparing groff and mandoc output) does not
>> show bold and underline fonts and i always had to pipe the gmdiff
>> output to less, even if it was short.  Calling ul(1) at the end of
>> the gmdiff script elegantly fixes that problem.

> This made me try ul(1) with gmdiff, which led me to trying it with an
> incomplete filename (I used tab-completion and didn't notice that there
> were multiple files). Found this:
> 
> $ mandoc nonexistent
> mandoc: nonexistent: ERROR: No such file or directory
> Segmentation fault 

Reported by czarkoff@ yesterday, and fixed yesterday.

Sorry for the temporary regression,
  Ingo



Re: does anoybody use ul?

2015-10-23 Thread Stuart Henderson
On 2015/10/23 11:52, Ingo Schwarze wrote:
> I didn't use it so far, but now that you made me look at it, i'm
> likely to start using it almost daily.  I often felt unhappy that
> my gmdiff tool (for comparing groff and mandoc output) does not
> show bold and underline fonts and i always had to pipe the gmdiff
> output to less, even if it was short.  Calling ul(1) at the end of
> the gmdiff script elegantly fixes that problem.

This made me try ul(1) with gmdiff, which led me to trying it with an
incomplete filename (I used tab-completion and didn't notice that there
were multiple files). Found this:

$ mandoc nonexistent
mandoc: nonexistent: ERROR: No such file or directory
Segmentation fault 



Re: does anoybody use ul?

2015-10-23 Thread Ted Unangst
Stefan Sperling wrote:
> On Fri, Oct 23, 2015 at 05:50:53AM -0400, Ted Unangst wrote:
> > well, it doesn't work with utf-8 because it tries to underline only half the
> > character. i'm aiming for the "quick fix"...
> 
> Why not at least try a kind of better fix to see how it would work?

Is this "better"? It copies the state of the previous letter to the next if
it's a utf-8 continuation byte.

FreeBSD has full blown multibyte support as well, but it requires switching
everything to wchar_t. Which way are we going here?


Index: ul.c
===
RCS file: /cvs/src/usr.bin/ul/ul.c,v
retrieving revision 1.19
diff -u -p -r1.19 ul.c
--- ul.c10 Oct 2015 16:15:03 -  1.19
+++ ul.c23 Oct 2015 10:29:43 -
@@ -241,6 +241,8 @@ mfilter(FILE *f)
obuf[col].c_mode |= BOLD|mode;
else
obuf[col].c_mode = mode;
+   if ((c & (0x80 | 0x40)) == 0x80 && col > 0)
+   obuf[col].c_mode = obuf[col - 1].c_mode;
col++;
if (col > maxcol)
maxcol = col;



Re: does anoybody use ul?

2015-10-23 Thread Christian Weisgerber
Ted Unangst:

> well, it doesn't work with utf-8 because it tries to underline only half the
> character. i'm aiming for the "quick fix"...

FreeBSD has imported a fix for this, r132858.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: does anoybody use ul?

2015-10-23 Thread Stefan Sperling
On Fri, Oct 23, 2015 at 05:50:53AM -0400, Ted Unangst wrote:
> well, it doesn't work with utf-8 because it tries to underline only half the
> character. i'm aiming for the "quick fix"...

Why not at least try a kind of better fix to see how it would work?



Re: does anoybody use ul?

2015-10-23 Thread Ingo Schwarze
Hi Ted,

Ted Unangst wrote on Fri, Oct 23, 2015 at 03:47:56AM -0400:

> ul appears somewhat useless for its intended purpose.
> 
> echo _xxx_ | ul does not result in underlined text in an xterm,
> so I doubt many people are using this.
> 
> Unlike, say, mandoc, it can't output Greek letters.
> I also imagine most people have moved on to some form
> of markdown for their other text markup needs.

Your sentence sounds a bit like "mandoc can do the same, just better".
That statement would be totally misleading.

Experimenting a bit with ul(1), i just learnt something new:
Actually, mandoc(1) *output* is exactly what ul(1) expects as *input*.

Compare:

  $ echo '.Fl o Ar arg' | mandoc -mdoc

On the terminal, you see no underlining and no bold face.

  $ echo '.Fl o Ar arg' | mandoc -mdoc | ul

Now, the "-o" is bold and the "arg" is underlined.

  $ echo '.Fl o Ar arg' | mandoc -mdoc | less
  $ echo '.Fl o Ar arg' | mandoc -mdoc -l

Again, both of these do show bold and underlined text on the terminal
because less(1) includes functionality similar to ul(1).

> Will anyone miss it?

I didn't use it so far, but now that you made me look at it, i'm
likely to start using it almost daily.  I often felt unhappy that
my gmdiff tool (for comparing groff and mandoc output) does not
show bold and underline fonts and i always had to pipe the gmdiff
output to less, even if it was short.  Calling ul(1) at the end of
the gmdiff script elegantly fixes that problem.

Unless people strongly insist on killing the ul(1) utility, i'm
planning to fix the ul(1) manual page.  I does indead lack essential
information, i RTFS to understand the purpose of the utility.

Thanks for the pointer,
  Ingo



Re: does anoybody use ul?

2015-10-23 Thread Ted Unangst
Christian Weisgerber wrote:
> On 2015-10-23, "Ted Unangst"  wrote:
> 
> > ul appears somewhat useless for its intended purpose.
> 
> mandoc /usr/share/man/man1/ls.1 | ul
> 
> Works fine.  Of course that functionality has been incorporated
> into more/less decades ago.
> 
> > Will anyone miss it?
> 
> Probably not, but what's the benefit of deleting it?

well, it doesn't work with utf-8 because it tries to underline only half the
character. i'm aiming for the "quick fix"...



Re: does anoybody use ul?

2015-10-23 Thread Christian Weisgerber
On 2015-10-23, "Ted Unangst"  wrote:

> ul appears somewhat useless for its intended purpose.

mandoc /usr/share/man/man1/ls.1 | ul

Works fine.  Of course that functionality has been incorporated
into more/less decades ago.

> Will anyone miss it?

Probably not, but what's the benefit of deleting it?
*shrug*

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: enhanced use-after-free detection for malloc

2015-10-23 Thread Daniel Micay
Er, here it is without the screwed up whitespace (whoops):

diff --git a/stdlib/malloc.c b/stdlib/malloc.c
index 424dd77..7c33a7a 100644
--- a/stdlib/malloc.c
+++ b/stdlib/malloc.c
@@ -182,6 +182,7 @@ struct malloc_readonly {
int malloc_freeunmap;   /* mprotect free pages PROT_NONE? */
int malloc_hint;/* call madvice on free pages?  */
int malloc_junk;/* junk fill? */
+   int malloc_validate;/* validate junk */
int malloc_move;/* move allocations to end of page? */
int malloc_realloc; /* always realloc? */
int malloc_xmalloc; /* xmalloc behaviour? */
@@ -560,6 +561,12 @@ omalloc_init(struct dir_info **dp)
case 'J':
mopts.malloc_junk = 2;
break;
+   case 'v':
+   mopts.malloc_validate = 0;
+   break;
+   case 'V':
+   mopts.malloc_validate = 1;
+   break;
case 'n':
case 'N':
break;
@@ -1253,6 +1260,17 @@ ofree(void *p)
wrterror("double free", p);
return;
}
+   if (mopts.malloc_junk && mopts.malloc_validate && p != 
NULL) {
+   size_t byte;
+   r = find(pool, p);
+   REALSIZE(sz, r);
+   for (byte = 0; byte < sz; byte++) {
+   if (((char *)p)[byte] != SOME_FREEJUNK) 
{
+   wrterror("use after free", p);
+   return;
+   }
+   }
+   }
pool->delayed_chunks[i] = tmp;
}
if (p != NULL) {
-- 
2.6.2



Re: does anoybody use ul?

2015-10-23 Thread Nicholas Marriott
On Fri, Oct 23, 2015 at 05:11:42AM -0400, Ted Unangst wrote:
> Nicholas Marriott wrote:
> > Well, it does work:
> > 
> > printf 'A\bA_\bB'|ul
> > 
> > I still think it is not useful, I say kill it.
> 
> Oh! Is that how you use it? The man page doesn't explain, apparently expecting
> that everybody just knows there's only one true way to mark up text.

It's the same markup groff/mandoc/less/etc use:

mandoc /usr/src/usr.bin/ul/ul.1|ul

(Although I didn't remember that and did spend a while looking at the
code trying to figure it out.)

But I don't think ul is terribly useful, you can do it with "more -e".



Re: does anoybody use ul?

2015-10-23 Thread Theo de Raadt
> > From: "Ted Unangst" 
> > Date: Fri, 23 Oct 2015 03:47:56 -0400
> > 
> > ul appears somewhat useless for its intended purpose.
> > 
> > echo _xxx_ | ul does not result in underlined text in an xterm, so I doubt
> > many people are using this.
> > 
> > Unlike, say, mandoc, it can't output Greek letters. I also imagine most 
> > people
> > have moved on to some form of markdown for their other text markup needs.
> > 
> > Will anyone miss it?
> 
> I doubt anybody ever uses it directly, but I've seen it used in
> scripts.  And even though POSIX doesn't mention it, it is present on
> pretty much any UNIX-like OS.  I think removing it would be wrong.

printf '_\bc_\bh_\ba_\bn_\bg_\be_\b _\bi_\bs_\b _\bb_\ba_\bd_\b!\b' | ul

:-)



Re: does anoybody use ul?

2015-10-23 Thread Mark Kettenis
> From: "Ted Unangst" 
> Date: Fri, 23 Oct 2015 03:47:56 -0400
> 
> ul appears somewhat useless for its intended purpose.
> 
> echo _xxx_ | ul does not result in underlined text in an xterm, so I doubt
> many people are using this.
> 
> Unlike, say, mandoc, it can't output Greek letters. I also imagine most people
> have moved on to some form of markdown for their other text markup needs.
> 
> Will anyone miss it?

I doubt anybody ever uses it directly, but I've seen it used in
scripts.  And even though POSIX doesn't mention it, it is present on
pretty much any UNIX-like OS.  I think removing it would be wrong.

> Index: Makefile
> ===
> RCS file: /cvs/src/usr.bin/Makefile,v
> retrieving revision 1.153
> diff -u -p -r1.153 Makefile
> --- Makefile  16 Jul 2015 20:50:40 -  1.153
> +++ Makefile  23 Oct 2015 07:43:25 -
> @@ -25,7 +25,7 @@ SUBDIR= apply arch at aucat audioctl awk
>   sort spell split sqlite3 ssh stat su systat \
>   tail talk tcpbench tee telnet tftp tic time \
>   tmux top touch tput tr true tset tsort tty usbhidaction usbhidctl \
> - ul uname unexpand unifdef uniq units \
> + uname unexpand unifdef uniq units \
>   unvis users uudecode uuencode vacation vi vis vmstat w wall wc \
>   what which who whois write x99token xargs xinstall \
>   yacc yes
> 
> 



Re: does anoybody use ul?

2015-10-23 Thread Alessandro DE LAURENZIS
Hi Ted,

On Fri 23/10/2015 03:47, Ted Unangst wrote:
> ul appears somewhat useless for its intended purpose.
> 
> echo _xxx_ | ul does not result in underlined text in an xterm, so I doubt
> many people are using this.
[...]

I don't use it anymore, but some time ago I needed to quickly highlight
some text in a couple of scripts and found out (see [0]) that ul(1)
requires a rather obscure sequence of backspaces and underscores to
work properly; just try:

echo $'x\b_x\b_x\b_' | ul

which correctly underlines the "xxx" string in xterm.

I'm not against the removal, this is only to say that the command
actually works.

Cheers

[0]: 
http://unix.stackexchange.com/questions/3044/how-to-use-the-ul-command-line-utility

-- 
Alessandro DE LAURENZIS
[mailto:just22@gmail.com]
LinkedIn: http://it.linkedin.com/in/delaurenzis



Re: does anoybody use ul?

2015-10-23 Thread Ted Unangst
Nicholas Marriott wrote:
> Well, it does work:
> 
> printf 'A\bA_\bB'|ul
> 
> I still think it is not useful, I say kill it.

Oh! Is that how you use it? The man page doesn't explain, apparently expecting
that everybody just knows there's only one true way to mark up text.



Re: axphy(4): new dumb driver for axe(4) phys

2015-10-23 Thread Theo de Raadt
> First I added a custom reset function, but it turned out the problem was 
> elsewhere. So the current driver is just pretty printf'ing the model and 
> the phy.
> 
> And you're right, it's not worth getting this in tree so forget about 
> this diff.

correct.  ukphy is named a bit strangely.

 ukphy - generic/unknown IEEE 802.3u Ethernet PHY


It is better to think of this as the "generic" driver, that
handles all the phy's which don't require special handling.
 



Re: does anoybody use ul?

2015-10-23 Thread Nicholas Marriott
Well, it does work:

printf 'A\bA_\bB'|ul

I still think it is not useful, I say kill it.



On Fri, Oct 23, 2015 at 03:47:56AM -0400, Ted Unangst wrote:
> ul appears somewhat useless for its intended purpose.
> 
> echo _xxx_ | ul does not result in underlined text in an xterm, so I doubt
> many people are using this.
> 
> Unlike, say, mandoc, it can't output Greek letters. I also imagine most people
> have moved on to some form of markdown for their other text markup needs.
> 
> Will anyone miss it?
> 
> 
> Index: Makefile
> ===
> RCS file: /cvs/src/usr.bin/Makefile,v
> retrieving revision 1.153
> diff -u -p -r1.153 Makefile
> --- Makefile  16 Jul 2015 20:50:40 -  1.153
> +++ Makefile  23 Oct 2015 07:43:25 -
> @@ -25,7 +25,7 @@ SUBDIR= apply arch at aucat audioctl awk
>   sort spell split sqlite3 ssh stat su systat \
>   tail talk tcpbench tee telnet tftp tic time \
>   tmux top touch tput tr true tset tsort tty usbhidaction usbhidctl \
> - ul uname unexpand unifdef uniq units \
> + uname unexpand unifdef uniq units \
>   unvis users uudecode uuencode vacation vi vis vmstat w wall wc \
>   what which who whois write x99token xargs xinstall \
>   yacc yes
> 



Re: axphy(4): new dumb driver for axe(4) phys

2015-10-23 Thread Paul Irofti

On 23.10.2015 02:44, Jonathan Gray wrote:

What does this do that ukphy doesn't?

I don't see any errata or special handling here.


First I added a custom reset function, but it turned out the problem was 
elsewhere. So the current driver is just pretty printf'ing the model and 
the phy.


And you're right, it's not worth getting this in tree so forget about 
this diff.




enhanced use-after-free detection for malloc

2015-10-23 Thread Daniel Micay
This patch adds a form of use-after-free detection based on validating that
the junk data is still in place when swapping out an allocation from the
delayed chunk cache. It will probably nearly double the cost of the junk free
feature that's enabled by default since it needs to do a whole extra pass over
the data, thus splitting it out into a separate option instead of always doing
it. It can catch UAF issues when Freeguard / Free unmap will not since those
can only kick in when a whole page is cleared out.

This could be extended to also check that the data is *either* zeroed or junk
when handing out a chunk as a new allocation. That would add an additional
pass over the data, so perhaps this should be given 3 levels like the junk
free feature (like this patch by default, disabled with v, also validating the
data when doing allocation with V).

diff --git a/stdlib/malloc.c b/stdlib/malloc.c
index 424dd77..7c33a7a 100644
--- a/stdlib/malloc.c
+++ b/stdlib/malloc.c
@@ -182,6 +182,7 @@ struct malloc_readonly {
int malloc_freeunmap;   /* mprotect free pages PROT_NONE? */
int malloc_hint;/* call madvice on free pages?  */
int malloc_junk;/* junk fill? */
+   int malloc_validate;/* validate junk */
int malloc_move;/* move allocations to end of page? */
int malloc_realloc; /* always realloc? */
int malloc_xmalloc; /* xmalloc behaviour? */
@@ -560,6 +561,12 @@ omalloc_init(struct dir_info **dp)
case 'J':
mopts.malloc_junk = 2;
break;
+   case 'v':
+   mopts.malloc_validate = 0;
+   break;
+   case 'V':
+   mopts.malloc_validate = 1;
+   break;
case 'n':
case 'N':
break;
@@ -1253,6 +1260,17 @@ ofree(void *p)
wrterror("double free", p);
return;
}
+   if (mopts.malloc_junk && mopts.malloc_validate && p != 
NULL) {
+   size_t byte;
+   r = find(pool, p);
+   REALSIZE(sz, r);
+   for (byte = 0; byte < sz; byte++) {
+   if (((char *)p)[byte] != SOME_FREEJUNK) 
{
+   wrterror("use after free", p);
+   return;
+   }
+   }
+   }
pool->delayed_chunks[i] = tmp;
}
if (p != NULL) {



Re: unused macros in ksh

2015-10-23 Thread Nicholas Marriott
The patch is mangled so it doesn't apply, but ok nicm


On Thu, Oct 22, 2015 at 08:53:48PM -0400, Michael McConville wrote:
> Beat me to it. ok mmcc@
> 
> Ilya Kaliman wrote:
> > ===
> > RCS file: /cvs/src/bin/ksh/shf.c,v
> > retrieving revision 1.25
> > diff -u -p -r1.25 shf.c
> > --- shf.c   19 Oct 2015 14:42:16 -  1.25
> > +++ shf.c   23 Oct 2015 00:27:40 -
> > @@ -707,10 +707,6 @@ shf_smprintf(const char *fmt, ...)
> > return shf_sclose(&shf); /* null terminates */
> >  }
> > 
> > -#define BUF_SIZE   128
> > -#define ABIGNUM32000   /* big number that will fit in
> > a short */
> > -#define LOG2_103.321928094887362347870319429   /* log
> > base 2 of 10 */
> > -
> >  #defineFL_HASH 0x001   /* `#' seen */
> >  #define FL_PLUS0x002   /* `+' seen */
> >  #define FL_RIGHT   0x004   /* `-' seen */
> > @@ -722,7 +718,6 @@ shf_smprintf(const char *fmt, ...)
> >  #define FL_DOT 0x100   /* '.' seen */
> >  #define FL_UPPER   0x200   /* format character was uppercase */
> >  #define FL_NUMBER  0x400   /* a number was formated %[douxefg] */
> > -
> > 
> >  int
> >  shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
> > 
> 



does anoybody use ul?

2015-10-23 Thread Ted Unangst
ul appears somewhat useless for its intended purpose.

echo _xxx_ | ul does not result in underlined text in an xterm, so I doubt
many people are using this.

Unlike, say, mandoc, it can't output Greek letters. I also imagine most people
have moved on to some form of markdown for their other text markup needs.

Will anyone miss it?


Index: Makefile
===
RCS file: /cvs/src/usr.bin/Makefile,v
retrieving revision 1.153
diff -u -p -r1.153 Makefile
--- Makefile16 Jul 2015 20:50:40 -  1.153
+++ Makefile23 Oct 2015 07:43:25 -
@@ -25,7 +25,7 @@ SUBDIR= apply arch at aucat audioctl awk
sort spell split sqlite3 ssh stat su systat \
tail talk tcpbench tee telnet tftp tic time \
tmux top touch tput tr true tset tsort tty usbhidaction usbhidctl \
-   ul uname unexpand unifdef uniq units \
+   uname unexpand unifdef uniq units \
unvis users uudecode uuencode vacation vi vis vmstat w wall wc \
what which who whois write x99token xargs xinstall \
yacc yes



Re: connect routing domains on layer 2

2015-10-23 Thread Reyk Floeter
On Fri, Oct 23, 2015 at 01:21:05PM +1000, David Gwynne wrote:
> 
> > On 23 Oct 2015, at 09:00, Reyk Floeter  wrote:
> > 
> > Hi,
> > 
> > this diff allows to interconnect routing domains.
> > 
> > It is very useful to route traffic from one routing domain to another,
> > without using the pf "rtable" hack (tested in production for a long
> > time).
> > 
> > eg.,
> > # ifconfig vether0 10.0.1.1/24
> > # ifconfig vether1 rdomain 1 10.0.1.2/24
> > # ping 10.1.1.2
> > # route -T 1 add default 10.0.1.1
> > # ifconfig bridge0 add vether0 add em0
> > 
> > for hacking/testing, you can do thing like:
> > # dhcpd vether0
> > # dhclient vether1
> > 
> > It has been discussed in much detail if this is possible with
> > bridge(4).  It is not.  The bridge is not designed for it and explain
> > on request.
> 
> the diff implements a crossover option, but the example above doesnt use 
> them. does that mean you can use a bridge to build crossovers without the 
> extra code, or the example is wrong?
> 

The example is missing the relevant bit:
# ifconfig vether0 10.0.1.1/24
# ifconfig vether1 rdomain 1 10.0.1.2/24
# ifconfig vether1 crossover vether0

You can use a bridge to connect multiple rdomains by attaching
multiple virtual ethernet ports to it.  The "crossover" is the cable,
the connection between rdomains; naming is a pure bikeshed - we could
also call it "cable", "connect", "plumb" or whatever.

For example, if rdomain 0 is the "gateway" to the outside or the
service network:

bridge0
em0
vether0 rdomain 0   -> vether10 rdomain 1
vether1 rdomain 0   -> vether11 rdomain 2
vether2 rdomain 0   -> vether12 rdomain 3

Reyk

> > 
> > OK?
> > 
> > Reyk
> > 
> > Index: sbin/ifconfig/ifconfig.8
> > ===
> > RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v
> > retrieving revision 1.257
> > diff -u -p -u -p -r1.257 ifconfig.8
> > --- sbin/ifconfig/ifconfig.86 Oct 2015 17:23:21 -   1.257
> > +++ sbin/ifconfig/ifconfig.822 Oct 2015 22:33:40 -
> > @@ -1560,6 +1560,33 @@ The accepted size of the number depends 
> > it is a 24-bit number for
> > .Xr vxlan 4 .
> > .El
> > +.\" VETHER
> > +.Sh VETHER
> > +.nr nS 1
> > +.Bk -words
> > +.Nm ifconfig
> > +.Ar vether-interface
> > +.Op Oo Fl Oc Ns Cm crossover Ar interface
> > +.Ek
> > +.nr nS 0
> > +.Pp
> > +The following options are available for a
> > +.Xr vether 4
> > +interface:
> > +.Bl -tag -width Ds
> > +.It Cm crossover Ar interface
> > +Create a virtual crossover link with another
> > +.Xr vether 4
> > +interface.
> > +Any outgoing packets from the
> > +.Ar vether-interface
> > +will be received by the crossover
> > +.Ar interface
> > +and vice versa.
> > +This link allows to interconnect two routing domains locally.
> > +.It Fl crossover
> > +If configured, disconnect the virtual crossover link.
> > +.El
> > .\" VLAN
> > .Sh VLAN
> > .nr nS 1
> > Index: sbin/ifconfig/ifconfig.c
> > ===
> > RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> > retrieving revision 1.302
> > diff -u -p -u -p -r1.302 ifconfig.c
> > --- sbin/ifconfig/ifconfig.c3 Oct 2015 10:44:23 -   1.302
> > +++ sbin/ifconfig/ifconfig.c22 Oct 2015 22:33:41 -
> > @@ -275,6 +275,8 @@ voidsetifipdst(const char *, int);
> > voidsetifdesc(const char *, int);
> > voidunsetifdesc(const char *, int);
> > voidprintifhwfeatures(const char *, int);
> > +void   setxover(const char *, int);
> > +void   unsetxover(const char *, int);
> > #else
> > voidsetignore(const char *, int);
> > #endif
> > @@ -490,6 +492,8 @@ const structcmd {
> > { "-descr", 1,  0,  unsetifdesc },
> > { "wol",IFXF_WOL,   0,  setifxflags },
> > { "-wol",   -IFXF_WOL,  0,  setifxflags },
> > +   { "crossover",  NEXTARG,0,  setxover },
> > +   { "-crossover", 1,  0,  unsetxover },
> > #else /* SMALL */
> > { "powersave",  NEXTARG0,   0,  setignore },
> > { "priority",   NEXTARG,0,  setignore },
> > @@ -2917,6 +2921,7 @@ status(int link, struct sockaddr_dl *sdl
> > struct ifreq ifrdesc;
> > struct ifkalivereq ikardesc;
> > char ifdescr[IFDESCRSIZE];
> > +   char ifname[IF_NAMESIZE];
> > #endif
> > uint64_t *media_list;
> > int i;
> > @@ -2955,6 +2960,9 @@ status(int link, struct sockaddr_dl *sdl
> > (ikardesc.ikar_timeo != 0 || ikardesc.ikar_cnt != 0))
> > printf("\tkeepalive: timeout %d count %d\n",
> > ikardesc.ikar_timeo, ikardesc.ikar_cnt);
> > +   if (ioctl(s, SIOCGXOVER, &ifrdesc) == 0 && ifrdesc.ifr_index != 0 &&
> > +   if_indextoname(ifrdesc.ifr_index, ifname) != NULL)
> > +   printf("\tcrossover: %s\n", ifname);
> > #endif
> > vlan_status();
>