222 Commits

Author SHA1 Message Date
Florian Westphal
54dea548d7 examples: genl: fix wrong attribute size
This example no longer works on more recent kernels:

genl-family-get
error: Invalid argument

dmesg says:
netlink: 'genl-family-get': attribute type 1 has an invalid length.

Fix this and also zero out the reserved field in the genl header,
while not validated yet for dumps this could change.

Reported-by: Divyanshu Rathore <Divyanshu.Rathore@bmwtechworks.in>
Signed-off-by: Florian Westphal <fw@strlen.de>
2025-09-15 20:17:42 +02:00
Duncan Roe
03da98bcd2 src: remove whitespace irregularities
Two distinct actions:
 1. Remove trailing spaces and tabs.
 2. Remove spaces that are followed by a tab, inserting extra tabs
    as required.
Action 2 is only performed in the indent region of a line.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-11-28 13:26:26 +01:00
Pablo Neira Ayuso
537e7df7cb build: do not build documentation automatically
Make it optional. After this update it is still possible to build the
documentation via:

	./configure --with-doxygen=yes

if ./configure finds doxygen. Update README to include this information.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-10-14 12:14:47 +02:00
Pablo Neira Ayuso
f066fabaa3 attr: expand mnl_attr_get_uint() documentation
This function is modelled after rta_getattr_uint() in libnetlink to fetch the
netlink attribute payload of NLA_UINT, although it was extended to make it
universal for 8-bit, 16-bit, 32-bit or 64-bit integers.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-10-14 12:14:35 +02:00
Duncan Roe
85a18778dd doc: Address warnings emitted by doxygen 1.12.0
Remove now-obsolete DOT_TRANSPARENT.
Add `nstats` to EXCLUDE_SYMBOLS (struct defined in example nfct-daemon.c).
While being about it, remove EXPORT_SYMBOL from EXCLUDE_SYMBOLS:
only INPUT_FILTER can suppress EXPORT_SYMBOL.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Florian Westphal <fw@strlen.de>
2024-09-15 17:40:32 +02:00
Petr Machata
ba6477cf3c README: Document the contribution process
The libmnl patch submission process is currently undocumented. Add a small
paragraph to README that deals with it.

Signed-off-by: Petr Machata <petrm@nvidia.com>
2024-07-31 23:15:14 +02:00
Danielle Ratson
102942be40 src: attr: Add mnl_attr_get_uint() function
NLA_UINT attributes have a 4-byte payload if possible, and an 8-byte one
if necessary.

There are some NLA_UINT attributes that lack an appropriate getter function.

Add a function mnl_attr_get_uint() to cover that extract these. Since we
need to dispatch on length anyway, make the getter truly universal by
supporting also u8 and u16.

Signed-off-by: Danielle Ratson <danieller@nvidia.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2024-07-31 09:12:57 +02:00
Jeremy Sowden
754c9de5ea nlmsg: fix false positives when validating buffer sizes
The `len` parameter of `mnl_nlmsg_ok`, which holds the buffer length and
is compared to the size of the object expected to fit into the buffer,
is signed because the function validates the length, and it can be
negative in the case of malformed messages.  Comparing it to unsigned
operands used to lead to compiler warnings:

  msg.c: In function 'mnl_nlmsg_ok':
  msg.c:136: warning: comparison between signed and unsigned
  msg.c:138: warning: comparison between signed and unsigned

and so commit 73661922bc3b ("fix warning in compilation due to different
signess") added casts of the unsigned operands to `int`.  However, the
comparison to `nlh->nlmsg_len`:

  (int)nlh->nlmsg_len <= len

is problematic, since `nlh->nlmsg_len` is of type `__u32` and so may
hold values greater than `INT_MAX`.  In the case where `len` is positive
and `nlh->nlmsg_len` is greater than `INT_MAX`, the cast will yield a
negative value and `mnl_nlmsg_ok` will incorrectly return true.

Instead, assign `len` to an unsigned local variable, check for a
negative value first, then use the unsigned local for the other
comparisons, and remove the casts.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1691
Fixes: 73661922bc3b ("fix warning in compilation due to different signess")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-11-14 16:01:18 +01:00
Dario Binacchi
0b242d346d include: cache copy of can.h and can/netlink.h
Ensure that rtnl-link-can example compiles in any installation. These
headers are not installed in the system.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-05-28 22:44:25 +02:00
Dario Binacchi
0ef806a0da examples: update .gitignore files
The patch adds and modifies the .gitignore files to hide all the
examples generated by the compilation.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-05-22 08:21:36 +02:00
Dario Binacchi
80442c4e32 examples: add rtnl-link-can
I developed this application to test the Linux kernel series referenced below.
I could not use the iproute2 package since the microcontroller is without MMU.

On suggestion of the Linux CAN subsystem maintainer I decided to upstream it.

Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://marc.info/?l=linux-netdev&m=167999323611710&w=2
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-04-29 17:22:01 +02:00
Jeremy Sowden
ac44797f71 doc: fix some non-native English usages
"allows to" -> "allows ${pronoun} to".  We use "you" if that appears in context,
"one" otherwise.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-12-28 10:53:35 +01:00
Phil Sutter
b923795047 Makefile: Create LZMA-compressed dist-files
Use a more modern alternative to bzip2.

Suggested-by: Jan Engelhardt <jengelh@inai.de>
Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2022-12-09 02:22:42 +01:00
Jeremy Sowden
d9bd111c99 doc: move man-page sym-link shell-script into a separate file
We use `$(SHELL)` to run the script and exec bash if `$(SHELL)` is something
else.  We don't hard-code the path to bash.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
2022-09-21 10:37:52 +02:00
Jeremy Sowden
cd53381591 doc: move doxygen config file into doxygen directory
Now that the `INPUT` directory is correct, we can update `OUTPUT_DIRECTORY` to
`.` and we don't need to cd out of the doxygen directory to run doxygen.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
2022-09-21 10:35:32 +02:00
Jeremy Sowden
23a2298ecf doc: change INPUT doxygen setting to @top_srcdir@
It avoids the need to move src directories in doxygen/Makefile.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
2022-09-21 10:35:31 +02:00
Jeremy Sowden
f79a2193ed doc: add .gitignore for Doxygen artefacts
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
2022-09-21 10:35:30 +02:00
Jeremy Sowden
187550f16b build: add make dist tar-balls to .gitignore
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
2022-09-21 10:35:29 +02:00
Mark Mentovai
4e54f790ed build: doc: refer to bash as bash, not /bin/bash
This locates bash according to its presence in the PATH, not at a
hard-coded path which may not exist or may not be the most suitable bash
to use.

Signed-off-by: Mark Mentovai <mark@mentovai.com>
Acked-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Florian Westphal <fw@strlen.de>
2022-09-21 10:31:24 +02:00
Jacob Keller
a92ea99316 libmnl: update attribute function comments to use \return
Update the function comments in lib/attr.c to use the \return notation,
which produces better man page output.

Suggested-by: Duncan Roe <duncan.roe2@gmail.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Acked-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-08-08 16:11:58 +02:00
Kerin Millar
12024b1c2e nlmsg: Only print ECMA-48 colour sequences to terminals
Check isatty() to skip colors for non-terminals.

Add mnl_fprintf_attr_color() and mnl_fprintf_attr_raw() helper function.

Joint work with Pablo.

Signed-off-by: Kerin Millar <kfm@plushkava.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-06-29 19:03:51 +02:00
Stephen Hemminger
85ef87303d examples: format neigh dump correctly
The request to dump neighbours was attaching a generic route message
header but the proper header (used by iproute2) is to use ndmsg.

The original way works but better to format the message as a
neighbour request.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-04-07 10:40:41 +02:00
Pablo Neira Ayuso
493aacf2ec build: libmnl 1.0.5 release
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
libmnl-1.0.5
2022-04-05 13:14:09 +02:00
Duncan Roe
2a3e927ec7 src: doc: Fix messed-up Netlink message batch diagram
Put the diagram in a *verbatim* block (like all the other diagrams)

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-08-10 17:40:21 +02:00
Duncan Roe
ceab313e36 build: If doxygen is not available, be sure to report "doxygen: no" to ./configure
Also fix bogus "Doxygen not found ..." warning if --without-doxygen given

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-08-10 17:39:33 +02:00
Duncan Roe
6041e3dc83 build: doc: get rid of the need for manual updating of Makefile
There used to be 3 things in doxygen/Makefile.am that developers had to update:

1. The dependency list (i.e. all C sources)

2. The setgroup lines, which renamed each module man page to be the page for the
   first described function. setgroup also set the target for:

3. The add2group lines, which symlinked pages for other documented functions
   in the group.

The new system eliminates all of the above.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-08-01 12:31:06 +02:00
Duncan Roe
cd0cafc7f7 build: doc: "make" builds & installs a full set of man pages
Repeat what we did for libnetfilter_queue:
 - New makefile in doxygen directory. Rebuilds documentation if any sources
   change that contain doxygen comments:
   - Renames each group man page to the first function listed therein
   - Creates symlinks for subsequently listed functions
   - Deletes _* temp files and moves sctruct-describing man pages to man7
 - Update top-level makefile to visit new subdir doxygen
 - Update top-level configure to only build documentation if doxygen installed
 - Add --with/without-doxygen switch
 - Check whether dot is available when configuring doxygen
 - Reduce size of doxygen.cfg and doxygen build o/p
 - `make distcheck` passes with doxygen enabled
Aditionally, exclude opaque structs mnl_nlmsg_batch & mnl_socket

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-06-23 19:05:52 +02:00
igo95862
3a782045c2 doxygen: Fixed link to the git source tree on the website.
Old link no longer worked.
Also upgraded it to https.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-09-22 01:15:33 +02:00
Pablo Neira Ayuso
957dbe6fdc include: add MNL_SOCKET_DUMP_SIZE definition
Add definition to recommend a new buffer size for netlink dumps.
Details are available here:

 commit d35c99ff77ecb2eb239731b799386f3b3637a31e
 Author: Eric Dumazet <edumazet@google.com>
 Date:   Thu Oct 6 04:13:18 2016 +0900

    netlink: do not enter direct reclaim from netlink_dump()

iproute2 is using 32 KBytes buffer in netlink dumps to speed up netlink
dumps for a while. Let's recommend this buffer size through this new
definition. Update examples too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2019-10-14 11:14:26 +02:00
Pablo Neira Ayuso
9d35bd3419 doxygen: remove EXPORT_SYMBOL from the output
Add input filter to remove the internal EXPORT_SYMBOL macro that turns
on the compiler visibility attribute.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Duncan Roe <duncan_roe@optusnet.com.au>
2019-10-07 10:22:21 +02:00
Duncan Roe
0635a93e2f nlmsg: Fix a missing doxygen section trailer
This corrects an oddity in the web doco (and presumably in the man pages as
well) whereby "Netlink message batch helpers" was showing up as a sub-topic of
"Netlink message helpers".

This was included in my original (rejected) patch "Enable doxygen to generate
Function Documentation" with a comment "(didn't think it warrantied an extra
patch)" - clearly wrong

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2019-10-03 12:21:22 +02:00
Fernando Fernandez Mancera
444d6dc902 src: fix doxygen function documentation
Currently clang requires EXPORT_SYMBOL() to be above the function
implementation. At the same time doxygen is not generating the proper
documentation because of that.

This patch solves that problem but EXPORT_SYMBOL looks less like the Linux
kernel way exporting symbols.

Reported-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2019-09-30 16:14:10 +02:00
Petr Vorel
5937dfcb01 examples: Add rtnl-addr-add.c
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2019-05-06 00:03:56 +02:00
Laura Garcia Liebana
f14732339a examples: reduce LOCs during neigh attributes validation
This patch avoids some LOCs duplication.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2018-05-23 09:42:39 +02:00
Laura Garcia Liebana
0b1bad1cfd examples: fix print line format
Use 80 characters per line limit.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2018-05-23 09:42:39 +02:00
Laura Garcia Liebana
17208cb344 examples: fix neigh max attributes
Use NDA_MAX for neigh maximum attributes instead of IFA_MAX,
which is only for interfaces.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2018-05-23 09:42:39 +02:00
Laura Garcia Liebana
e73a16d1e8 examples: add arp cache dump example
Adding ARP example in order to dump the info in the form:

index=<interface> family=<family> dst=<destination ip> lladdr=<mac address> state=<arp status>

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2018-05-18 12:47:52 +02:00
Florian Westphal
37c876b55a libmnl: zero attribute padding
Sergei Trofimovich reports 'uninitialized bytes' warnings from nftables:

Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)
   at 0x55B9EFB: sendmsg (in /lib64/libc-2.25.so)
   by 0x43E658: mnl_nft_socket_sendmsg (mnl.c:239)
   by 0x43E658: mnl_batch_talk (mnl.c:254)
   by 0x407898: nft_netlink (libnftables.c:58)
   by 0x407898: nft_run (libnftables.c:96)
   by 0x407CD5: nft_run_cmd_from_buffer (libnftables.c:291)
   by 0x406EDE: main (main.c:274)

This is harmless, the uninitialized memory is the padding
that sometimes needs to be inserted between end of an attribute
and the beginning of the new attribute.

Zero it to silence memory sanitizer output.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
2018-03-20 13:22:40 +01:00
Stephen Hemminger
577ad36084 examples: rtnl-addr-dump: fix typo
The example about addresses uses link attributes when it meant to use
address attributes.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2018-01-19 03:29:36 +01:00
Guillaume Nault
fbe0f33b45 callback: mark cb_ctl_array 'const' in mnl_cb_run2()
Users of mnl_cb_run2() would typically pass a 'static const' array as
cb_ctl_array parameter. Unfortunately this triggers a compiler warning
because the prototype doesn't declare cb_ctl_array with the 'const'
qualifier.

Since mnl_cb_run2() and __mnl_cb_run() don't modify cb_ctl_array (and
don't have any reason to do so in the future), we can mark this
parameter as 'const'.

There should be no impact on existing users beyond removing the
compiler warning when using a constant array.

Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-08-08 11:32:30 +02:00
Kylie McClain
c0f4276b37 examples: nfct-daemon: Fix test building on musl libc
On musl libc, sys/select.h is where FD_* definitions are located.

Signed-off-by: Kylie McClain <somasis@exherbo.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-07-21 18:26:04 +02:00
Pablo Neira Ayuso
0930a63252 build: libmnl 1.0.4 release
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
libmnl-1.0.4
2016-07-02 10:51:57 +02:00
Pablo Neira Ayuso
ce5c77cc5b src: cleanup function definitions
Place the returned value, function name and parameters (as many as can
fit) in the same line.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-07-01 15:47:36 +02:00
Peter Foley
dcdb47373a Move declaration of visibility attributes before definition.
When compiling with clang, the visibility attributes are ignored
since they are after the definition of the exported function.

Fix this by moving the attribute declaration before the function.

attr.c:439:1: error: attribute declaration must precede definition [-Werror,-Wignored-attributes]
EXPORT_SYMBOL(mnl_attr_put_u8);
^
./internal.h:7:41: note: expanded from macro 'EXPORT_SYMBOL'
                                              ^
./internal.h:6:35: note: expanded from macro '__visible'
                                               ^
attr.c:435:6: note: previous definition is here
void mnl_attr_put_u8(struct nlmsghdr *nlh, uint16_t type, uint8_t data)
     ^

Signed-off-by: Peter Foley <pefoley2@pefoley.com>
2016-07-01 15:33:25 +02:00
Carlos Falgueras García
610b1208a4 nlmsg: Improve payload printing
It makes more sense to use isprint() than isalnum() because we use non
alphanumeric characters like '%', '_', etc. And, in case of non
printable character, print a space is preferable to print a NULL (0) in
order to keep alignment.

Before:
...
|00012|--|00002|	|len |flags| type|
| 5f 5f 73 65  |	|      data      |	   s e
| 74 25 64 00  |	|      data      |	 t  d
...

After:
...
|00012|--|00002|	|len |flags| type|
| 5f 5f 73 65  |	|      data      |	 _ _ s e
| 74 25 64 00  |	|      data      |	 t % d
...

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-06-08 13:54:47 +02:00
Guillaume Nault
1891e0e2ce socket: introduce mnl_socket_open2()
Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
at socket creation time.

Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-10-04 21:15:53 +02:00
Pablo Neira Ayuso
b180a6ee27 example: netfilter: get rid of aligned_be64 definitions
This is defined in <linux/types.h>, which is included by the nfnetlink_* header
files.

Thus, we can get rid of u_int64_t which causes problems to musl according to
Felix Janda.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-05-26 12:03:09 +02:00
Felix Janda
b37ae85d43 examples/netfilter: Include <endian.h> for be64toh
Signed-off-by: Felix Janda <felix.janda@posteo.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-05-25 20:52:01 +02:00
Markus Teich
9ac5b6fb43 header: use sysconf() instead of getpagesize()
The sysconf(_SC_PAGESIZE) call is more portable since it does not need
_BSD_SOURCE defined.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-03-02 12:05:26 +01:00
Hisao Tanabe
c9f19b98cd attr: minor doc fix in mnl_attr_next()
mnl_attr_next(): remove unused param - len

Signed-off-by: Hisao Tanabe <xtanabe@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2015-01-10 18:23:36 +01:00