Default to comparing all attributes if no oo_id_attrs defined

Since commit: "cache pickup: Avoid duplicates during cache pickup",
nfnl_ct_alloc_cache no longer properly fills the cache, as it doesn't
define oo_id_attrs so all items are considered duplicates.

Instead of adding a ~0 oo_id_attrs to ct_obj, this changes
nl_object_identical to default to comparing all attributes if
neither oo_id_attrs_get or oo_id_attrs are provided.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Handle -NLE_AGAIN in nl_cache_mngr_data_ready

Since commit "nl: Return -NLE_AGAIN if non-blocking socket would block",
nl_cache_mngr_data_ready returns -NLE_AGAIN to callers on non-blocking sockets.
Change it to consider -NLE_AGAIN as a non-error case as it is expected behavior
with the nl_recv changes.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
netfilter/queue: generalize nfnl_queue_msg_build_verdict()

Generalize netfilter/queue to allow sending batched verdicts
later.

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
netfilter/queue: introduce nfnl_queue_msg_send_verdict_batch()

The batched verdict implicitely ACKs all queue packet IDs up to the
one send back, which reduces the number of verdict messages send
to the kernel.

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
msg: Avoid returning a negative value for nlmsg_attrlen()

If a hdrlen was provided that was greather than the actual
message length, a negative attributes length would result.

This was typically happening for RTM_GETLINK requests where
we can get a away with a 4 bytes header on the request side
but the response would use a 16 bytes header.

This resulted in strange -8 bytes leftover debug messages.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
tests: use AM_CFLAGS instead of CFLAGS directly

Signed-off-by: Thomas Graf <tgraf@suug.ch>
socket: Warn via debug message if local port namespace is exhausted

Signed-off-by: Thomas Graf <tgraf@suug.ch>
cache: Return -NLE_PROTO_MISMATCH if socket provided mismatches cache protocol

Signed-off-by: Thomas Graf <tgraf@suug.ch>
handle the case where 0 is passed to nl_size2str

(cherry picked from commit 968ccbe97d476e3a8485b04dbaf469e8d01b8811)
Signed-off-by: Thomas Graf <tgraf@suug.ch>
add support functions for attributes and callback handlers

added support functions to access the netlink attributes and use
custom callback handlers. Most is wrapped as is, but there are
a couple of special cases handled.

1) void *nla_data(struct nlattr *);
The return value is changed to a Python byte array so it includes
the lenght of the data stream.

2) int nla_parse_nested(...);
This returns a tuple (err, dict). 'err' is the error code and 'dict'
is a dictionary with attribute identifier as key and value represents
a struct nlattr object.

3) macro nla_for_each_nested()
Provide nla_get_nested() which returns a Python list of struct nlattr
objects that is iterable.

4) allocate struct nla_policy array
Provide nla_policy_array() function that allocates consecutive space
in memory for struct nla_policy array entries. Each entry is put in
a Python list so the entry fields can be modified in Python. This
array object can be passed to the nla_parse_nested() function.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
add python module for generic netlink library

This commit adds creation of the netlink.genl package. The actual
capi.i will be filled in upcoming commits so the module is rather
dumb for now.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
add generic netlink functions to swig

Provide wrapper function for generic netlink library functions. The
genlmsg_parse() function is handled similar to nla_parse_nested() so
it returns tuple with error code and dictionary of parsed attributes.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Add support for inet diag Netlink protocol.

- Inet diag allows users to gather low-level socket information.
- This library provides a higher-level API for creating inetdiag requests (via
  idiagnl_connect and idiagnl_send_simple) and parsing the replies (via
  idiagnl_msg_parse). A cache is also provided (via idiagnl_msg_alloc_cache).
- Request and message objects provide APIs for accessing and setting the
  various properties of each.
- This library also allows the user to parse the inetdiag response attributes
  which contain information about traffic class, TOS, congestion, socket
  memory info, and more depending on the kernel version used.
- Includes doxygen documentation.
Handle the case where nl_msec2str is passed 0 msecs