intercept's global constructor is called which sets up a hidden pipe which is used to communicate remote procedure calls (RPC) to the host Netcon service running in the background.
When an RPC for a socket() is received by the Netcon service from the intercepted application, the Netcon service will ask the lwIP stack for a new PCB structure (used to represent a connection), if the system permits its allocation, it will be passed to Netcon where a PCB/socket table entry will be created. The table is used for mapping [callbacks from lwIP] and [RPCs from the intercept] to the correct connections.
Upon the first call to a intercept-overriden system call, a Unix-domain socket is opened between the Netcon service and the application's intercept. This socket provides us the ability to pass file descriptors of newly-created socketpairs to the intercept (used as the read/write buffer). More specifically, after the socketpair creation, one end is kept in a table entry in Netcon and one end is sent to the intercept.
### Building from Source (and Installing)
Build zerotier-intercept library:
make -f make-intercept.mk
Install:
make -f make-intercept.mk install
Build LWIP library:
make -f make-liblwip.mk
Run automated tests (from netcon/docker-test/ directory):
./build.sh
./test.sh
### Running
To intercept a specific application (requires an already running instance of Zerotier-One with Network Containers enabled):
zerotier-intercept my_app
### Unit Tests
To run unit tests:
1) Set up your own network, use its network id as follows:
2) Place a blank network config file in this directory (e.g. "e5cd7a9e1c5311ab.conf")
- This will be used to inform test-specific scripts what network to use for testing
3) run build.sh
- Builds ZeroTier-One with Network Containers enabled
- Builds LWIP library
- Builds intercept library
- Copies all aformentioned files into unit test directory to be used for building docker files
4) run test.sh
- Will execute each unit test's (test.sh) one at a time and populate _results/
### Anatomy of a unit test
A) Each unit test's test.sh will:
- temporarily copy all built files into local directory
- build test container
- build monitor container
- remove temporary files
- run each container and perform test and monitoring specified in netcon_entrypoint.sh and monitor_entrypoint.sh