Skip to content

build, unit tests, misc fixes#6

Open
perennialmind wants to merge 13 commits intoquinot:masterfrom
perennialmind:master
Open

build, unit tests, misc fixes#6
perennialmind wants to merge 13 commits intoquinot:masterfrom
perennialmind:master

Conversation

@perennialmind
Copy link

I'm not sure whether you are still actively maintaining this project, but I have some changes you might find useful if you do.

I am afraid that my attempt to carry my quilt patch series into github went slightly awry: please pardon the mess.

Commit/patch Description
01-add-autotools.patch Autoconf/automake boilerplate
02-add-tests.patch Unit tests using linux unshare and veth
03-string-bounds-checking.patch Pedantic nit-picking ;-)
04-integer-conversion.patch Fix sscanf mismatch
05-input-validation.patch Strict input checking
06-error-handling.patch Additional error checking and reporting
07-getopt-parsing.patch Fix getopt(3) usage errors
08-update-manual.patch Update manual page choparp(8)
09-runtime-diagnostics.patch Make compile-time diagnostics available at run time (avoid dead code)

Aaron Hope and others added 11 commits March 13, 2017 16:44
Minimal autotools build system

Added basic autoconf and automake (but not libtool) build support.
Generated files not included. To use, one should first run "autoreconf -is".
Add unit tests

Add tests for core functionality as automake TAP tests. To execute, run "make
check". Requires support for the linux "veth" virtual ethernet tunnel and
permissions required to manipulate such.

Effort has been made to make these safe to run on a live system. Tests will
only be executed in a private network namespace. In theory, this means that all
changes will be properly issolated, but as always, buyer beware. Systems with
support for unprivileged containers (unprivileged_userns_clone=1) will allow
tests to be run as non-root. Otherwise, root will be required.
More rigorous string manipulation

Fix improper use of bounds-checked strncpy and snprintf (return values were
ignored).  Replace wth input validation and classic strcpy as needed.

Replace hand-written buffer management with asprintf(3) appends.

Fix off-by-one error in vhid parsing.
Fix erroneous and non-compliant integer conversions

Replace improper pointer cast between integer types of differing width. This
fixes a bug affecting LP64 64-bit big-endian architectures.

Replace BSD legacy integer type aliases with C prmitives, to comply with scanf
requirements.
Input validation enhancements

Make sure the interface link type is ethernet, since that's all we support.

Add bounds-checking for integer values.

Add checks for trailing characters on input parameters.

Documentation calls for vhid: mac address to be followed by a hexadecimal
number, but implementation parsed it as decimal. Split the difference and
support hexadecimal when preceded by "0x" and decimal otherwise.
Additional error checking and reporting

Treat and report pidfile creation as a fatal error.

Report fatal pcap errors.

Check for memory allocation failures.

Distinguish general runtime errors from invalid user input using exit codes 1 and 2
respectively, in accordance with the LSB init script conventions.
Fix getopt(3) usage errors

Since IP addresses/ranges are excluded with the same character as standard
options (dash, '-'), GNU getopt(3) will erroneously interpret these as invalid
options, unless the user sets the POSIXLY_CORRECT environment variable.
Specifying a '+' prefix ensures that these will be treated as regular
arguments.

With POSIX getopt, option arguments may or may not be in separate argv[] elements.
If the user bundles the option argument, such as -p/run/choparp.pid, the option
parsing code would skip over the first non-option argument.
Update manual page choparp(8)

Document new pidfile feature.

Fix misleading vhid: number format mismatch.

Replace IP and MAC addresses under assigned prefixes with RFC5737 "TEST-NET"
and RFC7042 reserved values for documentation.

General attempts at clarification.
Make compile-time diagnostics available at run time.

Uses a conventional accumulating "-v" option.

Add a conventional "-h" option to print usage.
OpenBSD getopt can return ':' in cases where other implementations
would return '?'. Add a default case as a catch-all to avoid
undefined behavior (i.e. bugs).
Run test script using shell selected by autoconf instead of /bin/sh
Fix recursion check
@quinot
Copy link
Owner

quinot commented Apr 18, 2017

I see you closed this pull request, but the patches have not been merged yet. Do you plan to resubmit it?

@perennialmind
Copy link
Author

I closed the pull request when I saw the implications of using "master" on my side and didn't see an obvious way to change it to something more sensible. I'd like to make a few more tweaks before resubmitting. I wasn't quite sure you were still interested, actually :-)

@quinot
Copy link
Owner

quinot commented Apr 23, 2017 via email

Test diagnostics improved.

Split linux namespace sanbox setup into distinct stages each in separate files.
Multiple logical stages are required and coercing them into one souce file
required obscure shell features and compromised comprehension. Keep it simple
instead.
@perennialmind perennialmind reopened this May 22, 2017
@perennialmind
Copy link
Author

I finally got around to tidying up the tests. I wasn't happy with the contortions put in place to keep the linux-veth tests in one file and decided it didn't make sense anyway. The tests are still linux-only, but since all the linux-specific bits are restricted to the utility functions, it'd be pretty easy to split those out too. I don't know enough about BSD and MacOS network and isolation tools to tackle those platforms.

My next set of changes will pull in the LGPL library libdaemon - not sure if you'd want those. I will avoid adding any LGPL source to the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants