Re: cvs admin for commitids

2014-06-30 Thread Otto Moerbeek
On Sun, Jun 29, 2014 at 07:37:18PM -0500, joshua stein wrote:

> This adds a -C option to cvs's admin command which can add, change,
> or delete a revision's commitid.  I couldn't find any similar
> functionality in any other CVS implementations, nor any using 'admin
> -C'.
> 
> Add or change a commitid:
> 
> cd /usr/src/bin/cat
> cvs admin -C 1.1:abcdef123456 cat.c
> 
> Delete a commitid (ends up removing the commitid line from the RCS
> file):
> 
> cd /usr/src/bin/cat
> cvs admin -C 1.1: cat.c

I tried to find out how to use commitids with cvs status, cvs log or
cvs diff and others, but no luck. I cannot specify commitids to select
revs. I hope you find time to add selection of revs based on
commitids, because without them commitids sound pretty useless to me. 

-Otto

> 
> Index: gnu/usr.bin/cvs/src/admin.c
> ===
> RCS file: /cvs/src/gnu/usr.bin/cvs/src/admin.c,v
> retrieving revision 1.2
> diff -u -p -u -p -r1.2 admin.c
> --- gnu/usr.bin/cvs/src/admin.c   11 May 2008 12:16:00 -  1.2
> +++ gnu/usr.bin/cvs/src/admin.c   30 Jun 2014 00:20:58 -
> @@ -27,6 +27,7 @@ static const char *const admin_usage[] =
>  "\t-A fileAppend another file's access list.\n",
>  "\t-b[rev]Set default branch (highest branch on trunk if 
> omitted).\n",
>  "\t-c string  Set comment leader.\n",
> +"\t-C rev:id  Replace revision's commit id.\n",
>  "\t-e[users]  Remove (comma-separated) user names from access list\n",
>  "\t   (all names if omitted).\n",
>  "\t-I Run interactively.\n",
> @@ -167,7 +168,7 @@ admin (argc, argv)
>  optind = 0;
>  only_k_option = 1;
>  while ((c = getopt (argc, argv,
> - "+ib::c:a:A:e::l::u::LUn:N:m:o:s:t::IqxV:k:")) != -1)
> + "+ib::c:C:a:A:e::l::u::LUn:N:m:o:s:t::IqxV:k:")) != -1)
>  {
>   if (c != 'k')
>   only_k_option = 0;
> @@ -209,6 +210,11 @@ admin (argc, argv)
>   strcat (admin_data.comment, optarg);
>   break;
>  
> + case 'C':
> + /* Change or add commitid. */
> + arg_add (&admin_data, 'C', optarg);
> + break;
> +
>   case 'a':
>   arg_add (&admin_data, 'a', optarg);
>   break;
> @@ -689,7 +695,7 @@ admin_fileproc (callerdat, finfo)
>  for (i = 0; i < admin_data->ac; ++i)
>  {
>   char *arg;
> - char *p, *rev, *revnum, *tag, *msg;
> + char *p, *rev, *revnum, *tag, *msg, *commitid;
>   char **users;
>   int argc, u;
>   Node *n;
> @@ -736,6 +742,45 @@ admin_fileproc (callerdat, finfo)
>   for (u = 0; u < argc; ++u)
>   RCS_addaccess (rcs, users[u]);
>   free_names (&argc, users);
> + break;
> + case 'C':
> + p = strchr (arg, ':');
> + if (p == NULL)
> + {
> + error (0, 0, "%s: -C option lacks commitid", rcs->path);
> + status = 1;
> + continue;
> + }
> + *p = '\0';
> + rev = RCS_gettag (rcs, arg + 2, 0, NULL);
> + if (rev == NULL)
> + {
> + error (0, 0, "%s: no such revision %s", rcs->path, rev);
> + status = 1;
> + continue;
> + }
> + *p++ = ':';
> + commitid = p;
> +
> + n = findnode (rcs->versions, rev);
> + free (rev);
> + delta = (RCSVers *) n->data;
> +
> + if (delta->other_delta == NULL)
> + delta->other_delta = getlist();
> +
> + n = findnode (delta->other_delta, "commitid");
> + if (n == NULL) {
> + n = getnode();
> + n->type = RCSFIELD;
> + n->key = xstrdup ("commitid");
> + n->data = xstrdup(commitid);
> + addnode (delta->other_delta, n);
> + } else {
> + free (n->data);
> + n->data = xstrdup(commitid);
> + }
> +
>   break;
>   case 'n': /* fall through */
>   case 'N':



Re: cvs admin for commitids

2014-06-30 Thread patrick keshishian
On Sun, Jun 29, 2014 at 07:39:59PM -0500, joshua stein wrote:
> On Sun, 29 Jun 2014 at 19:37:18 -0500, joshua stein wrote:
> > This adds a -C option to cvs's admin command which can add, change,
> > or delete a revision's commitid.  I couldn't find any similar
> > functionality in any other CVS implementations, nor any using 'admin
> > -C'.
> 
> Oops, here's the proper diff that actually deletes empty commitids.

This may be a silly question, but how do commitids get
set/generated/applied?

only one paragraph in cvs man page mentions it, but does
not indicate how they are gotten.

--patrick


> 
> 
> Index: gnu/usr.bin/cvs/src/admin.c
> ===
> RCS file: /cvs/src/gnu/usr.bin/cvs/src/admin.c,v
> retrieving revision 1.2
> diff -u -p -u -p -r1.2 admin.c
> --- gnu/usr.bin/cvs/src/admin.c   11 May 2008 12:16:00 -  1.2
> +++ gnu/usr.bin/cvs/src/admin.c   30 Jun 2014 00:39:08 -
> @@ -27,6 +27,7 @@ static const char *const admin_usage[] =
>  "\t-A fileAppend another file's access list.\n",
>  "\t-b[rev]Set default branch (highest branch on trunk if 
> omitted).\n",
>  "\t-c string  Set comment leader.\n",
> +"\t-C rev:id  Replace revision's commit id.\n",
>  "\t-e[users]  Remove (comma-separated) user names from access list\n",
>  "\t   (all names if omitted).\n",
>  "\t-I Run interactively.\n",
> @@ -167,7 +168,7 @@ admin (argc, argv)
>  optind = 0;
>  only_k_option = 1;
>  while ((c = getopt (argc, argv,
> - "+ib::c:a:A:e::l::u::LUn:N:m:o:s:t::IqxV:k:")) != -1)
> + "+ib::c:C:a:A:e::l::u::LUn:N:m:o:s:t::IqxV:k:")) != -1)
>  {
>   if (c != 'k')
>   only_k_option = 0;
> @@ -209,6 +210,11 @@ admin (argc, argv)
>   strcat (admin_data.comment, optarg);
>   break;
>  
> + case 'C':
> + /* Change or add commitid. */
> + arg_add (&admin_data, 'C', optarg);
> + break;
> +
>   case 'a':
>   arg_add (&admin_data, 'a', optarg);
>   break;
> @@ -689,7 +695,7 @@ admin_fileproc (callerdat, finfo)
>  for (i = 0; i < admin_data->ac; ++i)
>  {
>   char *arg;
> - char *p, *rev, *revnum, *tag, *msg;
> + char *p, *rev, *revnum, *tag, *msg, *commitid;
>   char **users;
>   int argc, u;
>   Node *n;
> @@ -736,6 +742,50 @@ admin_fileproc (callerdat, finfo)
>   for (u = 0; u < argc; ++u)
>   RCS_addaccess (rcs, users[u]);
>   free_names (&argc, users);
> + break;
> + case 'C':
> + p = strchr (arg, ':');
> + if (p == NULL)
> + {
> + error (0, 0, "%s: -C option lacks commitid", rcs->path);
> + status = 1;
> + continue;
> + }
> + *p = '\0';
> + rev = RCS_gettag (rcs, arg + 2, 0, NULL);
> + if (rev == NULL)
> + {
> + error (0, 0, "%s: no such revision %s", rcs->path, rev);
> + status = 1;
> + continue;
> + }
> + *p++ = ':';
> + commitid = p;
> +
> + n = findnode (rcs->versions, rev);
> + free (rev);
> + delta = (RCSVers *) n->data;
> +
> + if (delta->other_delta == NULL)
> + delta->other_delta = getlist();
> +
> + n = findnode (delta->other_delta, "commitid");
> + if (n == NULL) {
> + if (strlen(commitid)) {
> + n = getnode();
> + n->type = RCSFIELD;
> + n->key = xstrdup ("commitid");
> + n->data = xstrdup(commitid);
> + addnode (delta->other_delta, n);
> + }
> + } else {
> + if (strlen(commitid)) {
> + free (n->data);
> + n->data = xstrdup(commitid);
> + } else
> + delnode(n);
> + }
> +
>   break;
>   case 'n': /* fall through */
>   case 'N':
> 



Re: Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Theo de Raadt
>I don't think MAP_ANONYMOUS is being proposed for standardization
>because it's perceived to be of older origin than MAP_ANON or
>anything.  I'm pretty sure the focus is instead because it's perceived
>to have greater 'market share' among present day systems and
>applications.

Oh come on, the pussy footing is ridiculous.

Let's call it what it is.  The group is run a handful of Linux
proxies.  They do not care if incompatibilities are introduced,
as long as they are not introduced for Linux.



Re: Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Matthew Dempsky
On Mon, Jun 30, 2014 at 2:47 PM, Ingo Schwarze  wrote:
>> mmap() "first appeared" in 4.1cBSD [mmap.2] and was scheduled for
>> inclusion in 4.2BSD (1983) [UVM thesis, p36], but didn't "actually
>> appear" until the 1993 4.4BSD release [UVM thesis, p36].
>
> At least MAP_ANON is definitely a lot older than 1993.
>
> The original CSRG commit introducing it looks like this:
>
>   sys/sys/SCCS/s.mman.h:
>   As 00038/00013/00010
>   Ad D 7.2 90/12/05 15:28:56 mckusick 6 5
>   Ac update for new VM
>
> And that commit did make it into the 4.3BSD Net/2 release,
> published on August 20, 1991 (as seen on Kirk's CSRG archive CD).

Thanks.  I think that's generally consistent with the years I quoted
above, though I suppose the UVM thesis's "actually appear" wording is
arguable.

Maybe CDC was referring to how 4.3BSD was a development release,
whereas 4.4BSD was a production release?  ("This release represents an
intermediate point in the development of 4.4BSD; [...] This
distribution is NOT intended to be used on production systems"
http://ftp.netbsd.org/pub/NetBSD/misc/release/BSD/BSD-Net1)

> So i'd challenge anybody arguing for MAP_ANONYMOUS to show
> a published  header file containing that spelling
> where it was introduced before December 5, 1990.

I don't think MAP_ANONYMOUS is being proposed for standardization
because it's perceived to be of older origin than MAP_ANON or
anything.  I'm pretty sure the focus is instead because it's perceived
to have greater 'market share' among present day systems and
applications.



Re: Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Ingo Schwarze
Hi Matthew,

so in a nutshell, mmap(2) was originally a BSD idea and first implemented
in SunOS?  And there is no doubt that *BSD always had MAP_ANON and never
MAP_ANONYMOUS and that SunOS primarily defines MAP_ANON and MAP_ANONYMOUS
only for "/* (source compatibility) */", right?  And that the earliest
occurence of MAP_ANONYMOUS we found so far is Linux (1994)?  And that
4.4BSD was released with MAP_ANON before that (1993)...

That does look like a bunch of arguments for the POSIX crowd to swallow,
i think.

Besides, i dug up some more.

Matthew Dempsky wrote on Mon, Jun 30, 2014 at 01:57:20PM -0700:

> mmap() "first appeared" in 4.1cBSD [mmap.2] and was scheduled for
> inclusion in 4.2BSD (1983) [UVM thesis, p36], but didn't "actually
> appear" until the 1993 4.4BSD release [UVM thesis, p36].

At least MAP_ANON is definitely a lot older than 1993.

The original CSRG commit introducing it looks like this:

  sys/sys/SCCS/s.mman.h:
  As 00038/00013/00010
  Ad D 7.2 90/12/05 15:28:56 mckusick 6 5
  Ac update for new VM

And that commit did make it into the 4.3BSD Net/2 release,
published on August 20, 1991 (as seen on Kirk's CSRG archive CD).

So i'd challenge anybody arguing for MAP_ANONYMOUS to show
a published  header file containing that spelling
where it was introduced before December 5, 1990.

Yours,
  Ingo


Here is version 6 of BSD  as of December 5, 1990:

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 *
 * %sccs.include.redist.c%
 *
 *  %W% (Berkeley) %G%
 */

/*
 * Protections are chosen from these bits, or-ed together
 */
#define PROT_READ   0x04/* pages can be read */
#define PROT_WRITE  0x02/* pages can be written */
#define PROT_EXEC   0x01/* pages can be executed */

/*
 * Flags contain mapping type, sharing type and options.
 * Mapping type; choose one
 */
#define MAP_FILE0x0001  /* mapped from a file or device */
#define MAP_ANON0x0002  /* allocated from memory, swap space */
#define MAP_TYPE0x000f  /* mask for type field */

/*
 * Sharing types; choose one
 */
#define MAP_COPY0x0020  /* "copy" region at mmap time */
#define MAP_SHARED  0x0010  /* share changes */
#define MAP_PRIVATE 0x  /* changes are private */

/*
 * Other flags
 */
#define MAP_FIXED   0x0100  /* map addr must be exactly as requested */
#define MAP_NOEXTEND0x0200  /* for MAP_FILE, don't change file size */
#define MAP_HASSEMPHORE 0x0400  /* region may contain semaphores */
#define MAP_INHERIT 0x0800  /* region is retained after exec */

/*
 * Advice to madvise
 */
#define MADV_NORMAL 0   /* no further special treatment */
#define MADV_RANDOM 1   /* expect random page references */
#define MADV_SEQUENTIAL 2   /* expect sequential page references */
#define MADV_WILLNEED   3   /* will need these pages */
#define MADV_DONTNEED   4   /* dont need these pages */



Re: Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Matthew Dempsky
On Mon, Jun 30, 2014 at 11:31 AM, Mark Kettenis  wrote:
> Yes, I'm saying that this should affect POSIX's standardization.
> Solaris is where mmap(2) came from.

The full history is a bit more complicated though.  From what I've
managed to uncover over the past few days so far:

mmap() "first appeared" in 4.1cBSD [mmap.2] and was scheduled for
inclusion in 4.2BSD (1983) [UVM thesis, p36], but didn't "actually
appear" until the 1993 4.4BSD release [UVM thesis, p36].

In the mean time, it was independently reimplemented for SunOS 4 [UVM
thesis, p36], and released in 1988 [Wikipedia].  However, SunOS didn't
implement MAP_ANON, and instead required users to pass a file
descriptor for /dev/zero.

In 1994 (prior to Linux's 1.0 release), Linus added support for
MAP_ANONYMOUS 
[https://kernel.googlesource.com/pub/scm/linux/kernel/git/nico/archive/+/0b5e8609bf7e6899c1fea30aa467812d488b6c11%5E%21/#F3].

SunOS 5.8 (Feb 2000) added support for MAP_ANON
[http://www.freebsd.org/cgi/man.cgi?query=mmap&apropos=0&sektion=0&manpath=SunOS+5.8&arch=default&format=html].
I'm not sure when it added MAP_ANONYMOUS support.

Also according to Wikipedia, HP-UX is an SVR2 derivative and AIX is an
SVR3 derivative.  SVR2 and SVR3 were released in 1984 and 1986,
respectively, so neither should have inherited MAP_ANON/MAP_ANONYMOUS
from SVR/SunOS.  I'm not sure when they picked them up.

> Also, look at:
>
>   

Yeah, I've seen that, though despite the comment pointing out MAP_ANON
is more common, it instead adds a "#define MAP_ANONYMOUS MAP_ANON" if
it notices MAP_ANONYMOUS isn't provided.  So ironically, that macro
package's widespread use is indicative of code that uses MAP_ANONYMOUS
instead of MAP_ANON.  :-/



fsck_msdos: memleak merge with NetBSD

2014-06-30 Thread Tobias Stoeckmann
Hi,

this diff merges NetBSD's revision 1.20 into our tree:  There are
some memory leaks in resetDosDirSection.

This is not a simple merge, I have added some things:

- rootDir was not properly freed in NetBSD's commit
  (actually it's put into a "free dir entry queue")
- also free memory if root directory checks fail
- I use goto's instead of rewriting the code every single time
- kept our local styles (like xperror vs perr)
- after free, set values to NULL;  better safe than sorry and also
  in sync with other functions


Tobias

Index: dir.c
===
RCS file: /cvs/src/sbin/fsck_msdos/dir.c,v
retrieving revision 1.23
diff -u -p -r1.23 dir.c
--- dir.c   18 Jun 2014 17:29:07 -  1.23
+++ dir.c   30 Jun 2014 19:19:26 -
@@ -219,18 +219,27 @@ resetDosDirSection(struct bootblock *boo
b1 = boot->RootDirEnts * 32;
b2 = boot->SecPerClust * boot->BytesPerSec;
 
-   if (!(buffer = malloc(b1 > b2 ? b1 : b2))
-   || !(delbuf = malloc(b2))
-   || !(rootDir = newDosDirEntry())) {
+   if ((buffer = malloc(b1 > b2 ? b1 : b2)) == NULL) {
xperror("No space for directory");
return (FSFATAL);
}
+
+   if ((delbuf = malloc(b2)) == NULL) {
+   xperror("No space for directory delbuf");
+   goto fail_delbuf;
+   }
+
+   if ((rootDir = newDosDirEntry()) == NULL) {
+   xperror("No space for directory entry");
+   goto fail_root;
+   }
+
(void)memset(rootDir, 0, sizeof *rootDir);
if (boot->flags & FAT32) {
if (boot->RootCl < CLUST_FIRST || boot->RootCl >= 
boot->NumClusters) {
pfatal("Root directory starts with cluster out of 
range(%u)\n",
   boot->RootCl);
-   return (FSFATAL);
+   goto fail;
}
cl = fat[boot->RootCl].next;
if (cl < CLUST_FIRST
@@ -243,7 +252,7 @@ resetDosDirSection(struct bootblock *boo
  rsrvdcltype(cl));
else {
pfatal("Root directory doesn't start a cluster 
chain\n");
-   return (FSFATAL);
+   goto fail;
}
if (ask(1, "Fix")) {
fat[boot->RootCl].next = CLUST_FREE;
@@ -257,6 +266,16 @@ resetDosDirSection(struct bootblock *boo
}
 
return (ret);
+fail:
+   freeDosDirEntry(rootDir);
+   rootDir = NULL;
+fail_root:
+   free(delbuf);
+   delbuf = NULL;
+fail_delbuf:
+   free(buffer);
+   buffer = NULL;
+   return (FSFATAL);
 }
 
 /*



Re: Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Mark Kettenis
> Date: Mon, 30 Jun 2014 10:53:00 -0700
> From: Matthew Dempsky 
> 
> On Mon, Jun 30, 2014 at 10:42 AM, Mark Kettenis  
> wrote:
> > Solaris documents MAP_ANON in its man page, and defines MAP_ANONYMOUS
> > as MAP_ANON for source compatibility.
> 
> Yep, but what about it?  Are you suggesting that should affect POSIX's
> standardization, or that we should do the same thing?  I suspect if
> POSIX standardizes MAP_ANONYMOUS, that Solaris would switch to
> documenting MAP_ANONYMOUS and providing MAP_ANON for source compat,
> no?

Yes, I'm saying that this should affect POSIX's standardization.
Solaris is where mmap(2) came from.

Also, look at:

  

which contains the following comment:

# Detect how mmap can be used to create anonymous (not file-backed) memory
# mappings.
# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
# and MAP_ANON exist and have the same value.
# - On HP-UX, only MAP_ANONYMOUS exists.
# - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists.
# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
# used.

This suggests that there is actually a clear majority of systems where
only MAP_ANON exists.  OK, UnixWare isn't listed here, and perhaps it
doesn't provide MAP_ANON for compatibility.  But frankly, UnixWare is
long dead.  Perhaps a few more systems in the "only MAP_ANON exists"
category have moved up to the the "both MAP_ANONYMOUS and MAP_ANON"
exist category.  But MacOS X 10.6 is still firmly in the "only
MAP_ANON exists" category.  And I'd say MacOS X has a much larger
installed base than HP-UX.

Regardless of what POSIX decides, I think we should add MAP_ANONYMOUS,
but stay true to our heritage and keep MAP_ANON as the primary #define
and in the man page.



Re: Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Matthew Dempsky
On Mon, Jun 30, 2014 at 10:42 AM, Mark Kettenis  wrote:
> Solaris documents MAP_ANON in its man page, and defines MAP_ANONYMOUS
> as MAP_ANON for source compatibility.

Yep, but what about it?  Are you suggesting that should affect POSIX's
standardization, or that we should do the same thing?  I suspect if
POSIX standardizes MAP_ANONYMOUS, that Solaris would switch to
documenting MAP_ANONYMOUS and providing MAP_ANON for source compat,
no?



Re: Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Mark Kettenis
> Date: Mon, 30 Jun 2014 10:22:08 -0700
> From: Matthew Dempsky 
> 
> I filed an enhancement request with the Austin Group to standardize an
> mmap() flag for mapping anonymous memory.  I proposed standardizing
> MAP_ANON, but the current proposal is to standardize MAP_ANONYMOUS
> instead, as that seems to be the more common definition and usage:
> 
> http://austingroupbugs.net/view.php?id=850
> 
> All else equal, I prefer MAP_ANON as it's shorter and it's also the
> original BSD name; but I prefer having a standardized name even more.
> If anyone objects and has convincing arguments for why POSIX should
> standardize MAP_ANON instead, feel free to either comment on the above
> bug, or just express them here and I'll proxy them appropriately.

Solaris documents MAP_ANON in its man page, and defines MAP_ANONYMOUS
as MAP_ANON for source compatibility.



[Patch] Update the ifconfig(8) manpage

2014-06-30 Thread Gregor Best
Hi people,

the attached patch fixes two minor issues with the ifconfig(8) manpage.

The first part makes the operation of the `delete' option without an
argument a bit more obvious.

The second is a simple fix for the range of the `priority' option.

-- 
Gregor Best
Index: ifconfig.8
===
RCS file: /usr/src/cvs/src/sbin/ifconfig/ifconfig.8,v
retrieving revision 1.242
diff -u -p -u -r1.242 ifconfig.8
--- ifconfig.8  23 Jun 2014 18:55:29 -  1.242
+++ ifconfig.8  30 Jun 2014 17:28:08 -
@@ -185,6 +185,9 @@ Disable driver-dependent debugging code.
 .It Cm delete
 Remove the specified network address,
 including any netmask or destination address configured with this address.
+If no address is specified, the inet(4) address of the interface is assumed
+if it exists.
+If the interface has no inet(4) address, this option is a no-op.
 .It Cm description Ar value
 Specify a description of the interface.
 This can be used to label interfaces in situations where they may
@@ -403,7 +406,7 @@ Set the interface routing priority to
 This will influence the default routing priority of new static routes added to
 the kernel.
 .Ar n
-is in the range of 0 to 16 with smaller numbers being better.
+is in the range of 0 to 15 with smaller numbers being better.
 .It Cm rdomain Ar rdomainid
 Attach the interface to the routing domain with the specified
 .Ar rdomainid .


Rename MAP_ANON to MAP_ANONYMOUS

2014-06-30 Thread Matthew Dempsky
I filed an enhancement request with the Austin Group to standardize an
mmap() flag for mapping anonymous memory.  I proposed standardizing
MAP_ANON, but the current proposal is to standardize MAP_ANONYMOUS
instead, as that seems to be the more common definition and usage:

http://austingroupbugs.net/view.php?id=850

All else equal, I prefer MAP_ANON as it's shorter and it's also the
original BSD name; but I prefer having a standardized name even more.
If anyone objects and has convincing arguments for why POSIX should
standardize MAP_ANON instead, feel free to either comment on the above
bug, or just express them here and I'll proxy them appropriately.

Otherwise, diff below renames MAP_ANON to MAP_ANONYMOUS, and redefines
MAP_ANON as an alias for MAP_ANONYMOUS.


Index: sys/sys/mman.h
===
RCS file: /home/matthew/cvs-mirror/cvs/src/sys/sys/mman.h,v
retrieving revision 1.25
diff -u -p -r1.25 mman.h
--- sys/sys/mman.h  27 Jun 2014 20:50:43 -  1.25
+++ sys/sys/mman.h  27 Jun 2014 21:35:47 -
@@ -56,7 +56,8 @@
  */
 #defineMAP_FIXED   0x0010  /* map addr must be exactly as 
requested */
 #define__MAP_NOREPLACE 0x0800  /* fail if address not available */
-#defineMAP_ANON0x1000  /* allocated from memory, swap space */
+#defineMAP_ANONYMOUS   0x1000  /* allocated from memory, swap space */
+#defineMAP_ANONMAP_ANONYMOUS   /* original BSD spelling */
 
 #defineMAP_FLAGMASK0x1ff7
 
Index: lib/libc/sys/mmap.2
===
RCS file: /home/matthew/cvs-mirror/cvs/src/lib/libc/sys/mmap.2,v
retrieving revision 1.48
diff -u -p -r1.48 mmap.2
--- lib/libc/sys/mmap.2 27 Jun 2014 22:51:20 -  1.48
+++ lib/libc/sys/mmap.2 28 Jun 2014 00:01:25 -
@@ -120,7 +120,7 @@ Sharing, mapping type, and options are s
 .Fa flags
 argument by OR'ing the following values.
 Exactly one of the first two values must be specified:
-.Bl -tag -width MAP_PRIVATE -offset indent
+.Bl -tag -width MAP_ANONYMOUS -offset indent
 .It Dv MAP_PRIVATE
 Modifications are private.
 .It Dv MAP_SHARED
@@ -128,11 +128,11 @@ Modifications are shared.
 .El
 .Pp
 Any combination of the following flags may additionally be used:
-.Bl -tag -width MAP_PRIVATE -offset indent
-.It Dv MAP_ANON
+.Bl -tag -width MAP_ANONYMOUS -offset indent
+.It Dv MAP_ANONYMOUS
 Map anonymous memory not associated with any specific file.
 The file descriptor used for creating
-.Dv MAP_ANON
+.Dv MAP_ANONYMOUS
 must currently be \-1 indicating no name is associated with the
 region.
 .It Dv MAP_FIXED
@@ -156,7 +156,16 @@ source compatibility with code written f
 but are not recommended for use in new
 .Ox
 code:
-.Bl -tag -width MAP_PRIVATE -offset indent
+.Bl -tag -width MAP_ANONYMOUS -offset indent
+.It Dv MAP_ANON
+Original name for
+.Dv MAP_ANONYMOUS ,
+as introduced by
+.Bx .
+On
+.Ox
+this is an alias for
+.Dv MAP_ANONYMOUS .
 .It Dv MAP_COPY
 Modifications are private and, unlike
 .Dv MAP_PRIVATE ,



Re: boot/zboot: cmd.c merge

2014-06-30 Thread Tobias Stoeckmann
On Sun, Jun 29, 2014 at 08:40:53PM +0200, Tobias Stoeckmann wrote:
> Greatly reduces diff-Output between these files:  Just "clear" command,
> the same way it was back then.

After feedback from Theo, just kill clear command and therefore use
cmd.c from stand/boot in zboot.

Any zaurus user around to test-build this?


Tobias

Index: arch/zaurus/stand/zboot/Makefile
===
RCS file: /cvs/src/sys/arch/zaurus/stand/zboot/Makefile,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile
--- arch/zaurus/stand/zboot/Makefile10 Sep 2013 21:00:26 -  1.13
+++ arch/zaurus/stand/zboot/Makefile30 Jun 2014 17:05:01 -
@@ -21,7 +21,7 @@ CLEANFILES+= arm machine
 .endif
 
 # stand/boot
-SRCS+= boot.c vars.c bootarg.c conf.c
+SRCS+= boot.c cmd.c vars.c bootarg.c conf.c
 
 # libsa
 SRCS+= close.c closeall.c cons.c ctime.c disklabel.c dkcksum.c fstat.c \
Index: arch/zaurus/stand/zboot/boot.8
===
RCS file: /cvs/src/sys/arch/zaurus/stand/zboot/boot.8,v
retrieving revision 1.10
diff -u -p -r1.10 boot.8
--- arch/zaurus/stand/zboot/boot.8  27 Sep 2012 12:26:28 -  1.10
+++ arch/zaurus/stand/zboot/boot.8  30 Jun 2014 17:05:01 -
@@ -103,6 +103,12 @@ This file may contain any commands
 .Nm
 accepts at the interactive prompt.
 Though default settings usually suffice, they can be changed here.
+.\" XXX CHECK_SKIP_CONF is not defined...
+.\" .Pp
+.\" .Pa boot.conf
+.\" processing can be skipped by holding down either Control key as
+.\" .Nm
+.\" starts.
 .It
 The header line
 .Pp
Index: arch/zaurus/stand/zboot/cmd.c
===
RCS file: arch/zaurus/stand/zboot/cmd.c
diff -N arch/zaurus/stand/zboot/cmd.c
--- arch/zaurus/stand/zboot/cmd.c   21 Mar 2007 03:29:05 -  1.3
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,532 +0,0 @@
-/* $OpenBSD: cmd.c,v 1.3 2007/03/21 03:29:05 tedu Exp $*/
-
-/*
- * Copyright (c) 1997-1999 Michael Shalayeff
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include 
-#include 
-
-#ifdef REGRESS
-#include 
-#include 
-#else
-#include 
-#include 
-#endif
-
-#include 
-
-#define CTRL(c)((c)&0x1f)
-
-static int Xboot(void);
-static int Xclear(void);
-static int Xecho(void);
-static int Xhelp(void);
-static int Xls(void);
-static int Xnop(void);
-static int Xreboot(void);
-static int Xstty(void);
-static int Xtime(void);
-#ifdef MACHINE_CMD
-static int Xmachine(void);
-extern const struct cmd_table MACHINE_CMD[];
-#endif
-extern int Xset(void);
-extern int Xenv(void);
-
-extern const struct cmd_table cmd_set[];
-const struct cmd_table cmd_table[] = {
-   {"#",  CMDT_CMD, Xnop},  /* XXX must be first */
-   {"boot",   CMDT_CMD, Xboot},
-   {"clear",  CMDT_CMD, Xclear},
-   {"echo",   CMDT_CMD, Xecho},
-   {"env",CMDT_CMD, Xenv},
-   {"help",   CMDT_CMD, Xhelp},
-   {"ls", CMDT_CMD, Xls},
-#ifdef MACHINE_CMD
-   {"machine",CMDT_MDC, Xmachine},
-#endif
-   {"reboot", CMDT_CMD, Xreboot},
-   {"set",CMDT_SET, Xset},
-   {"stty",   CMDT_CMD, Xstty},
-   {"time",   CMDT_CMD, Xtime},
-   {NULL, 0},
-};
-
-static void ls(char *, struct stat *);
-static int readline(char *, size_t, int);
-char *nextword(char *);
-static char *whatcmd(const struct cmd_table **ct, char *);
-static char *qualify(char *);
-
-char cmd_buf[CMD_BUFF_SIZE];
-
-int
-getcmd(void)
-{
-   cmd.cmd = NULL;
-
-   if (!readline(cmd_buf, sizeof(cmd_buf), cmd.timeout))
-   cmd.cmd = cmd_table;
-
-   return docmd();
-}
-
-int
-read_conf(void)
-{
-#ifndef INSECURE
-   struc

Re: exec_elf.c: mistake ?

2014-06-30 Thread Maxime Villard
Well, at the time I didn't really know these stuff - this bug was found by my
home-made code scanner, in an area I was not particularly familiar with. 
However,
I did try to help as far as I could, but despite my pings, it has remained
unfixed so far, and 5.5 was released with no care taken about that.

I vaguely remember that I later ended up with a working patch, but apparently
I've lost it since. This bug crashed binaries, and I had told myself it was
annoying enough to be worth an Erratum.

Anyway, it ain't that bad, and I'm glad to see people waking up one year later.
(it won't be necessary to cc' me again for this issue)

Regards,
Maxime


Le 17/06/2014 00:29, Matthew Dempsky a écrit :
> 
> Reading through exec_elf.c, I just noticed the uninitialized bdiff
> variable myself, and remembered this thread.
> 
> Tangentially, the code for worrying about zero-filling the last page
> is overzealous.  We only need to zero-fill the page if memsz > filesz
> (accounting for alignment and page boundaries).  In the common case
> (at least on amd64), we always have either memsz==filesz (most
> segments) or filesz==0 (segment for .bss), so we shouldn't need
> zero-filling.
> 
> And actually, I think the logic for only doing zero-fill for writable
> segments is wrong.  It looks to me like the ELF gABI specifies
> zero-fill semantics for memsz > filesz even for read-only segments.
> 
> On Sat, Oct 5, 2013 at 4:27 PM, Philip Guenther  wrote:
>> On Thu, 15 Aug 2013, Maxime Villard wrote:
>>> Hum hum, after investigating a bit, and from what I understood - if I'm
>>> not mistaken, I think it would make sense if bdiff was set to
>>>
>>>   bdiff = ph->p_vaddr - trunc_page(ph->p_vaddr);
>>
>> Yep.
>>
>>> Since we are supposed to align only on 2^n boundaries, if we get 0 or 1
>>> we do not align on p_align. But p_vaddr still has to be aligned on
>>> PAGE_MASK (with trunc_page()); I read somewhere that ELF loaders are
>>> smart enough to adjust the address when it does not exactly fit a page
>>> boundary. So bdiff should be the difference with the original p_vaddr.
>>> Actually, bdiff is already set to this value in the other conditions.
>>>
>>> There's another problem, 'base' should also be initialized here. I would
>>> say that is should be set to the truncated p_vaddr plus the address at
>>> which we want to load:
>>>
>>>   base = *addr + trunc_page(ph->p_vaddr);
>>>
>>> but I'm not sure at all.
>>
>> By the logic of the "ph->p_align > 1" case, it should be
>> base = *addr + trunc_page(ph->p_vaddr) - ph->p_vaddr;
>>
>> (I think the only reason the 'if' is necessary is that p_align==0 must be
>> treated the same as p_align==1.  The ELF_TRUNC() macro handles an
>> alignment of 1 correctly, but it'll barf on 0.)
>>
>>
>> Philip Guenther
>>
> 
> 



Re: idea to block some scanners

2014-06-30 Thread Leclerc, Sebastien
> De : mxb [mailto:m...@alumni.chalmers.se], 30 juin 2014 03:26
> Could you please, post updated version to the list?

Sure!

--- /dev/null   Mon Jun 30 07:57:57 2014
+++ tarpitd.c   Fri Jun 27 14:01:35 2014
@@ -0,0 +1,525 @@
+/*
+ * Copyright (c) 2014 Sebastien Leclerc. All rights reserved.
+ * Copyright (c) 2002-2007 Bob Beck. All rights reserved.
+ * Copyright (c) 2002 Theo de Raadt. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct con {
+   int fd;
+   int af;
+   struct sockaddr_storage ss;
+   void *ia;
+   char addr[32];
+   char caddr[32];
+   char cport[6];
+   time_t r;
+   time_t s;
+   char ibuf[8192];
+   char *ip;
+   int il;
+} *con;
+
+void usage(void);
+void initcon(struct con *, int, struct sockaddr *);
+void closecon(struct con *);
+void handler(struct con *);
+void getcaddr(struct con *);
+int  blockhost(char *);
+int  blocklistener(void);
+
+struct syslog_data sdata = SYSLOG_DATA_INIT;
+struct passwd *pw;
+
+time_t t;
+
+#define MAXCON 800
+int maxfiles;
+int maxcon = MAXCON;
+int clients;
+int debug;
+int window = 0;
+int autoblock = 1;
+int pipel[2] = { -1, -1 };
+pid_t pidl = -1;
+#define MAXIDLETIME 30
+#define MAXTIME 120
+#define PATH_PFCTL "/sbin/pfctl"
+
+void
+usage(void)
+{
+   extern char *__progname;
+
+   fprintf(stderr,
+   "usage: %s [-d] [-c maxcon] [-l address] "
+   "[-p port] [-w window]\n",
+   __progname);
+
+   exit(1);
+}
+
+int
+blockhost(char *ip)
+{
+   switch(fork()) {
+   case -1:
+   syslog_r(LOG_WARNING, &sdata, "child cannot fork (%m)");
+   return (-1);
+   case 0:
+   /* child */
+   if (-1 == execl(PATH_PFCTL, "pfctl", "-q", "-t", "badguys", 
"-T", "add", ip, NULL)) {
+   syslog_r(LOG_WARNING, &sdata, "cannot exec pfctl (%m)");
+   return (-2);
+   }
+   }
+
+   /* parent */
+   return (0);
+}
+
+int blocklistener(void)
+{
+   int ret = 0;
+   ssize_t len;
+   size_t lsize = 0;
+   char *buf = NULL;
+   FILE *pf;
+
+   fcntl(pipel[0], F_SETFD, FD_CLOEXEC);
+
+   pf = fdopen(pipel[0], "r");
+   if (pf == NULL) {
+   syslog_r(LOG_WARNING, &sdata, "cannot open pipe (%m)");
+   close(pipel[0]);
+   return(-1);
+   }
+
+   while (-1 != (len = getline(&buf, &lsize, pf))) {
+   buf[len - 1] = '\0';
+   blockhost(buf);
+   memset(buf, 0, sizeof buf);
+   }
+
+   if (ferror(pf)) {
+   syslog_r(LOG_ERR, &sdata, "child listener aborted (%m)");
+   ret = 2;
+   }
+   else if (feof(pf)) {
+   syslog_r(LOG_INFO, &sdata, "child listener terminated 
normally.");
+   }
+
+   fclose(pf);
+   return(ret);
+}
+
+void
+getcaddr(struct con *cp)
+{
+   struct sockaddr_storage spamd_end;
+   struct sockaddr *sep = (struct sockaddr *) &spamd_end;
+   socklen_t len = sizeof(struct sockaddr_storage);
+   int error;
+
+   cp->caddr[0] = '\0';
+   cp->cport[0] = '\0';
+   if (getsockname(cp->fd, sep, &len) == -1)
+   return;
+   error = getnameinfo(sep, sep->sa_len, cp->caddr, sizeof(cp->caddr),
+   cp->cport, sizeof(cp->cport), NI_NUMERICHOST | NI_NUMERICSERV);
+   if (error) {
+   syslog_r(LOG_WARNING, &sdata, "cannot get original destination 
address.");
+   cp->caddr[0] = '\0';
+   cp->cport[0] = '\0';
+   }
+}
+
+void
+initcon(struct con *cp, int fd, struct sockaddr *sa)
+{
+   socklen_t len = sa->sa_len;
+   time_t tt;
+   int error;
+
+   time(&tt);
+   bzero(cp, sizeof(struct con));
+   cp->fd = fd;
+   if (len > sizeof(cp->ss))
+   errx(1, "sockaddr size");
+   if (sa->sa_family != AF_INET)
+   errx(1, "not supported yet");
+   memcpy(&cp->ss, sa, sa->sa_len)

Re: sort(1) updates

2014-06-30 Thread Otto Moerbeek
On Sun, Jun 29, 2014 at 06:48:32PM -0400, Jared Yanovich wrote:

> Hi,
> 
> sort(1) does some funky things and isn't hard to break:
> 
>   $ perl -e 'print "\n"x117000,"x\n"' | sort | sort -c
> 
> This patch contains a few changes from NetBSD to correct the behavior 
> regarding
> ordering of appending bins to output in certain circumstances which helps pass
> more of our own regress tests and improves performance (e.g. regress suite
> runtime is <40% with new code compared to old/current code on my box).  The 
> new
> code is also much easier to understand..
> 
> NetBSD logs:
> 
>   msort.c -r 1.9
> merge(): use array of buffers instead of one big buffer for all records, 
> and
>enlarge them as necessary to read records from merged files; the 
> buffers
>are allocated once per program run, so there shouldn't be any
>performance difference
> This makes sort(1) pass also regression 40B and should make it
> fully arbitrary long record capable.
> XXX the buffer array could probably be freed on end of fmerge() to save 
> memory
> 
>   fsort.c -r 1.37
> The code that attempted to sort large files by sorting each chunk by the
> first key byte and writing to a temp file, then sorting the records from
> each temp file that had the same first key byte (and repeating for upto
> 4 key bytes) was a nice idea, but completely doomed to failure.
> Eg PR/9308 where a 70MB file has all but one record the same and short 
> keys.
> Not only does the code not work, it is rather guaranteed to be slow.
> Instead always use a merge sort for fully sorted chunk of records (each
> temporary file contains one lot of sorted records).
> The -H option already did this, so just rip out all the code and variables
> that can't be used when -H was specified.

Hi Jared, good to see you active again ;-)

This indeed solves some problems, but I have a test file on which it cores.

The testfile is available at http://www.drijf.net/openbsd/test4.gz

-Otto


> 
> Index: append.c
> ===
> RCS file: /cvs/src/usr.bin/sort/append.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 append.c
> --- append.c  27 Oct 2009 23:59:43 -  1.10
> +++ append.c  29 Jun 2014 22:17:16 -
> @@ -148,37 +148,3 @@ append(u_char **keylist, int nelem, int 
>   put(crec, fp);
>   }
>  }
> -
> -/*
> - * output the already sorted eol bin.
> - */
> -void
> -rd_append(int binno, union f_handle infl0, int nfiles, FILE *outfp,
> -u_char *buffer, u_char *bufend)
> -{
> - RECHEADER *rec;
> -
> - rec = (RECHEADER *) buffer;
> - if (!getnext(binno, infl0, nfiles, (RECHEADER *) buffer, bufend, 0)) {
> - putline(rec, outfp);
> - while (getnext(binno, infl0, nfiles, (RECHEADER *) buffer,
> - bufend, 0) == 0) {
> - if (!UNIQUE)
> - putline(rec, outfp);
> - }
> - }
> -}
> -
> -/*
> - * append plain text--used after sorting the biggest bin.
> - */
> -void
> -concat(FILE *a, FILE *b)
> -{
> -int nread;
> -char buffer[4096];
> -
> - rewind(b);
> -while ((nread = fread(buffer, 1, 4096, b)) > 0)
> -EWRITE(buffer, 1, nread, a);
> -}
> Index: extern.h
> ===
> RCS file: /cvs/src/usr.bin/sort/extern.h,v
> retrieving revision 1.8
> diff -u -p -r1.8 extern.h
> --- extern.h  22 Dec 2009 19:47:02 -  1.8
> +++ extern.h  29 Jun 2014 22:17:16 -
> @@ -36,7 +36,6 @@
>  
>  void  append(u_char **, int, int, FILE *, void (*)(RECHEADER *, FILE *),
>   struct field *);
> -void  concat(FILE *, FILE *);
>  length_t enterkey(RECHEADER *, DBT *, int, struct field *);
>  void  fixit(int *, char **);
>  void  fldreset(struct field *);
> @@ -44,11 +43,9 @@ FILE   *ftmp(void);
>  void  fmerge(int, union f_handle, int,
>   int (*)(int, union f_handle, int, RECHEADER *, u_char *, struct 
> field *),
>   FILE *, void (*)(RECHEADER *, FILE *), struct field *);
> -void  fsort(int, int, union f_handle, int, FILE *, struct field *);
> +void  fsort(union f_handle, int, FILE *, struct field *);
>  int   geteasy(int, union f_handle,
>   int, RECHEADER *, u_char *, struct field *);
> -int   getnext(int, union f_handle,
> - int, RECHEADER *, u_char *, struct field *);
>  int   makekey(int, union f_handle,
>   int, RECHEADER *, u_char *, struct field *);
>  int   makeline(int, union f_handle,
> @@ -57,7 +54,6 @@ void merge(int, int,
>   int (*)(int, union f_handle, int, RECHEADER *, u_char *, struct 
> field *),
>   FILE *, void (*)(RECHEADER *, FILE *), struct field *);
>  void  num_init(void);
> -void  onepass(u_char **, int, long, long *, u_char *, FILE *);
>  int   optval(int, int);
>  void  order(union f_handle,
>  

Re: sort(1) updates

2014-06-30 Thread Stuart Henderson
On 2014/06/29 18:48, Jared Yanovich wrote:
> Hi,
> 
> sort(1) does some funky things and isn't hard to break:
> 
>   $ perl -e 'print "\n"x117000,"x\n"' | sort | sort -c
> 
> This patch contains a few changes from NetBSD to correct the behavior 
> regarding
> ordering of appending bins to output in certain circumstances which helps pass
> more of our own regress tests and improves performance (e.g. regress suite
> runtime is <40% with new code compared to old/current code on my box).  The 
> new
> code is also much easier to understand..

Nice, this fixes a crash bug I reported about 5 years ago :)



Re: idea to block some scanners

2014-06-30 Thread mxb

Could you please, post updated version to the list?

//mxb

On 27 jun 2014, at 20:09, Leclerc, Sebastien 
 wrote:

>> Stuart Henderson , 2014-06-27 11:00 
>> 
>>> +/* Stolen from ftp-proxy */
>> 
>> Old version of ftp-proxy I guess. It hasn't used DIOCNATLOOK for several
>> releases, it has switched to the much easier-to-use divert-to / 
>> getsockname().
> 
> And also :
> 
>> Henning Brauer , 2014-06-27 14:07
>> no
>> 
>> DIOCNATLOOK is stupid. I'll celebrate the day when I can kill it.
>> Please look at less ancient ftp-proxy/*-proxy code for inspiration.
> 
> Way simpler, indeed!
> Thank you
> 
> 
> --- tarpitd.c.bak   Fri Jun 27 13:25:06 2014
> +++ tarpitd.c   Fri Jun 27 14:01:35 2014
> @@ -56,21 +56,11 @@ struct con {
>int il;
> } *con;
> 
> -/* From netinet/in.h, but only _KERNEL_ gets them. */
> -#define satosin(sa)((struct sockaddr_in *)(sa))
> -#define satosin6(sa)   ((struct sockaddr_in6 *)(sa))
> -int server_lookup4(struct sockaddr_in *, struct sockaddr_in *,
> -struct sockaddr_in *);
> -int server_lookup6(struct sockaddr_in6 *, struct sockaddr_in6 *,
> -struct sockaddr_in6 *);
> -
> void usage(void);
> void initcon(struct con *, int, struct sockaddr *);
> void closecon(struct con *);
> void handler(struct con *);
> void getcaddr(struct con *);
> -int  server_lookup(struct sockaddr *, struct sockaddr *,
> -struct sockaddr *);
> int  blockhost(char *);
> int  blocklistener(void);
> 
> @@ -84,7 +74,6 @@ int maxfiles;
> int maxcon = MAXCON;
> int clients;
> int debug;
> -int pfdev;
> int window = 0;
> int autoblock = 1;
> int pipel[2] = { -1, -1 };
> @@ -160,90 +149,11 @@ int blocklistener(void)
>return(ret);
> }
> 
> -/* Stolen from ftp-proxy */
> -int
> -server_lookup(struct sockaddr *client, struct sockaddr *proxy,
> -struct sockaddr *server)
> -{
> -   if (client->sa_family == AF_INET)
> -   return (server_lookup4(satosin(client), satosin(proxy),
> -   satosin(server)));
> -
> -   if (client->sa_family == AF_INET6)
> -   return (server_lookup6(satosin6(client), satosin6(proxy),
> -   satosin6(server)));
> -
> -   errno = EPROTONOSUPPORT;
> -   return (-1);
> -}
> -
> -int
> -server_lookup4(struct sockaddr_in *client, struct sockaddr_in *proxy,
> -struct sockaddr_in *server)
> -{
> -   struct pfioc_natlook pnl;
> -
> -   memset(&pnl, 0, sizeof pnl);
> -   pnl.direction = PF_OUT;
> -   pnl.af = AF_INET;
> -   pnl.proto = IPPROTO_TCP;
> -   memcpy(&pnl.saddr.v4, &client->sin_addr.s_addr, sizeof pnl.saddr.v4);
> -   memcpy(&pnl.daddr.v4, &proxy->sin_addr.s_addr, sizeof pnl.daddr.v4);
> -   pnl.sport = client->sin_port;
> -   pnl.dport = proxy->sin_port;
> -
> -   if (ioctl(pfdev, DIOCNATLOOK, &pnl) == -1)
> -   return (-1);
> -
> -   memset(server, 0, sizeof(struct sockaddr_in));
> -   server->sin_len = sizeof(struct sockaddr_in);
> -   server->sin_family = AF_INET;
> -   memcpy(&server->sin_addr.s_addr, &pnl.rdaddr.v4,
> -   sizeof server->sin_addr.s_addr);
> -   server->sin_port = pnl.rdport;
> -
> -   return (0);
> -}
> -
> -int
> -server_lookup6(struct sockaddr_in6 *client, struct sockaddr_in6 *proxy,
> -struct sockaddr_in6 *server)
> -{
> -   struct pfioc_natlook pnl;
> -
> -   memset(&pnl, 0, sizeof pnl);
> -   pnl.direction = PF_OUT;
> -   pnl.af = AF_INET6;
> -   pnl.proto = IPPROTO_TCP;
> -   memcpy(&pnl.saddr.v6, &client->sin6_addr.s6_addr, sizeof 
> pnl.saddr.v6);
> -   memcpy(&pnl.daddr.v6, &proxy->sin6_addr.s6_addr, sizeof pnl.daddr.v6);
> -   pnl.sport = client->sin6_port;
> -   pnl.dport = proxy->sin6_port;
> -
> -   if (ioctl(pfdev, DIOCNATLOOK, &pnl) == -1)
> -   return (-1);
> -
> -   memset(server, 0, sizeof(struct sockaddr_in6));
> -   server->sin6_len = sizeof(struct sockaddr_in6);
> -   server->sin6_family = AF_INET6;
> -   memcpy(&server->sin6_addr.s6_addr, &pnl.rdaddr.v6,
> -   sizeof server->sin6_addr);
> -   server->sin6_port = pnl.rdport;
> -
> -   return (0);
> -}
> -
> -/*
> - * Get address client connected to, by doing a DIOCNATLOOK call.
> - * Uses server_lookup code from ftp-proxy.
> - */
> void
> getcaddr(struct con *cp)
> {
>struct sockaddr_storage spamd_end;
>struct sockaddr *sep = (struct sockaddr *) &spamd_end;
> -   struct sockaddr_storage original_destination;
> -   struct sockaddr *odp = (struct sockaddr *) &original_destination;
>socklen_t len = sizeof(struct sockaddr_storage);
>int error;
> 
> @@ -251,9 +161,7 @@ getcaddr(struct con *cp)
>cp->cport[0] = '\0';
>if (getsockname(cp->fd, sep, &len) == -1)
>return;
> -   if (server_lookup((struct sockaddr *)&cp->ss, sep, odp) != 0)
> -   return;
>