tcpfw: Fix unwanted sign extension on SOCKS messages

If "buf" is a signed char array, port numbers like 443 (0x01 0xbb) with
bit 7 set will get translated into incorrect "rport" numbers.  Make "buf"
unsigned to remedy this.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
ocvpn: Don't use OpenDNS server

By default, lwIP will set up resolver1.opendns.com (DNS_SERVER_ADDRESS)
as the primary DNS server.  This server typically is not able to look up
hostnames behind the corporate firewall, and will return a bogus answer
for unknown hosts (e.g. hit-nxdomain.opendns.com).

So, we will replace the OpenDNS server with the correct server specified
on the command line.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tcpfw: Fix IP/port in SOCKS connection reply

RFC1928 specifies:

   In the reply to a CONNECT, BND.PORT contains the port number that the
   server assigned to connect to the target host, while BND.ADDR
   contains the associated IP address.

tcpsocks_converse() was populating these fields with the target host
IP/port, not the server IP/port.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tcpfw: SOCKS: Allow "raw" IP addresses

tsocks and socksify can pass in IP addresses with ATYP 0x01 (raw IPv4
address) or 0x03 (ASCII hostname).  Add support for the former ATYP.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tcpfw: Refactor l2r/r2l threads

Several miscellaneous changes to the l2r/r2l code:

1) Poll status on both sides at 100ms intervals, so that the user will
get reasonably quick feedback if a connection drops or if new data is
available from the remote host.

2) Use the lwIP abstraction layer instead of directly invoking pthread
functions.

3) Rename c->alive, and use locking to ensure that the compiler knows
the value can be changed by another thread.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tcpfw: Fix missing return values and subsequent heap corruption

tcpsocks_acceptor() and tcpfw_acceptor() did not return values, and this
occasionally caused tcpfw_listen() to free the tcpfw_t struct while it
was in use.

Make the acceptor functions void, and pass all responsibility for closing
connections and freeing the struct into the acceptor function (or the
threads it creates).

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Enable -Wall and fix new warnings

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sys_arch: Honor stacksize argument in sys_thread_new()

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Reduce default thread stack size to 64KB

By default, thread stacks take up 8MB of virtual address space (if not
physical RAM).  This is far more space than we will ever need, and
since we have two new threads for each TCP connection, it adds up
quickly.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Only enable /tmp/tcpdump log file if "-v" (debug mode) is enabled

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tcpfw: Fix error prints for netconn_connect()

lwIP does not set errno, so perror() will not report the actual problem.
In fact it will often print "Success".

For now just print the numeric error code.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
lwip: Don't use glibc malloc()

The glibc malloc() heap seems to get fragmented too easily under this
workload, causing the process to take up excess RAM.  Use the builtin pool
manager instead.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sys_arch: Hack around memory leak in thread creation

Every call to sys_thread_new() leaks 16 bytes.  No more.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tcpfw: Reinstate tcpfw_close()

Calling netconn_close() before the other thread was done accessing the
connection wasn't such a great idea, and caused intermittent failures.
So once again, the thread that exits last will clean up all open
connections and free the tcpfwc struct.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
ocvpn: Remove tcpecho/udpecho applications.

Not required.
Merge branch 'master' of git://github.com/cernekee/ocproxy

Conflicts:
	contrib/ports/unix/proj/ocvpn/ocvpn.c
Rename the proxy 'ocproxy'.
Add or update licensing information.