Using API¶
The network extension must be installed on target system as described in Installation topic.
API library has two interfaces for using from C++ and C code, switched by defining the symbol _C_API.
By default the extension allows all network activity and bypasses the data packets without filtering. The attached application must create one or more rules using the API to specify what network activity must be filtered. For example it is possible to create a rule with all zeros except filteringFlag set to NF_FILTER, and the driver will indicate the transmitted data for all TCP connections except local.
The extension aborts all filtered TCP connections and returns back to “bypass all” mode after expected or unexpected close of the attached process.
Only one process can use the extension at the same time. It is possible to register additional instances of the extension with different names in case if several processes must be able to filter the network activity on the same system. See Installation section for details.
By default the process requires root rights for attaching to extension, because it works in a security container. It is possible to run the extension as a generic process by modifying the project settings. In this case the Unix sockets used for interprocess communications can be created in any folder to support access from an unprivileged account.
Usage scenarios¶
C++
Implement the methods of NF_EventHandler by defining a class derived from this interface.
Initialize API with a call to
nf_init(), specifying the driver name and the pointer to an object of class derived from NF_EventHandler.Add the filtering rules using
nf_addRule(),nf_addRuleEx(),nf_setRules(),nf_setRulesEx().Handle API notifications in overridden NF_EventHandler methods. The library calls these methods from a separate thread, so synchronization is required in case if the same data are simultaneously accessed from the other threads. It is possible to save the copies of indicated data buffers and send the filtered data back to destination from any thread later.
To remove the rules and disable filtering new connections call
nf_deleteRules(). The library continues indicating events for active TCP connections in this case until they close, because the filtering flag is assigned when a connection is establishing, and remains active during the connection lifetime.Call
nf_free()to detach from extension.
C
Define the symbol _C_API before including nfapi_macos.h and build nfproxy using “”make C_API=1””.
For C projects NF_EventHandler is defined as a structure with the pointers to event handler functions.
Everything else is the same as for C++.