summaryrefslogtreecommitdiffstats
path: root/src/nlmsg.c
Commit message (Collapse)AuthorAgeFilesLines
* nlmsg: fix false positives when validating buffer sizesHEADmasterJeremy Sowden2023-11-141-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* doc: fix some non-native English usagesJeremy Sowden2022-12-281-3/+3
| | | | | | | | "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>
* nlmsg: Only print ECMA-48 colour sequences to terminalsKerin Millar2022-06-291-23/+53
| | | | | | | | | | | 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>
* src: doc: Fix messed-up Netlink message batch diagramDuncan Roe2021-08-101-9/+10
| | | | | | | 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>
* nlmsg: Fix a missing doxygen section trailerDuncan Roe2019-10-031-0/+4
| | | | | | | | | | | | 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>
* src: fix doxygen function documentationFernando Fernandez Mancera2019-09-301-41/+27
| | | | | | | | | | | | | 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>
* src: cleanup function definitionsPablo Neira Ayuso2016-07-011-16/+9
| | | | | | | 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>
* Move declaration of visibility attributes before definition.Peter Foley2016-07-011-20/+20
| | | | | | | | | | | | | | | | | | | | 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>
* nlmsg: Improve payload printingCarlos Falgueras García2016-06-081-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* doc: minor fixKen-ichirou MATSUZAWA2014-10-241-2/+2
| | | | | | | | | | | mnl_attr_ok(): fix return value type mnl_attr_put_u8(): remove unused param - len mnl_attr_put_u8_check(): remove unused param - len mnl_nlmsg_ok(): fix return value type mnl_nlmsg_batch_stop(): not return batch size, but release it Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp> Signed-off-by: Florian Westphal <fw@strlen.de>
* doxygen: fix a variable name.Eric Leblond2013-03-141-1/+1
| | | | | | Variable name in doxygen description was not correct. Signed-off-by: Eric Leblond <eric@regit.org>
* nlmsg: fix valgrind warnings about paddingStephen Hemminger2012-04-191-2/+3
| | | | | | | | | When using mnl_nlmsg_put_extra_header() it pads out the addtional header but only zeros the original size not the padded value. Which cause valgrind to complain about sendto() with uninitialized byte. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* doc: fix wrong comment describing mnl_nlmsg_batch_stop()Sean Robinson2011-03-171-3/+3
| | | | | | | | | | | Sean says: "I did find a discrepancy in the comments versus practice in one function and I have attached a patch fixing those comments to this message." Sligtly mangled by myself. Signed-off-by: Sean Robinson <seankrobinson@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* doc: don't show up EXPORT_SYMBOL in doxygenPablo Neira Ayuso2011-02-031-28/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | Patrick reports that the doxygen output shows up EXPORT_SYMBOL and tells how to fix this: > I just noticed the EXPORT_SYMBOLs in libmnl showing up in > the doxygen output. Just in case you want to avoid this, > what I'm doing in libdect is (besides the appopriate linker > flags): > > #define __visible __attribute__((visibility("default"))) > > #define EXPORT_SYMBOL(x) typeof(x) (x) __visible > > > This allows to use EXPORT_SYMBOL as in the kernel, IOW > after the function definition. This patch also removes -Wredundant-decls to avoid a warning in every single use of this new approach. Now, this looks more like the Linux kernel way of exporting symbols. Reported-by: Patrick McHardy <kaber@trash.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* nlmsg: add new message batching infrastructurePablo Neira Ayuso2010-12-171-0/+185
| | | | | | | | | This patch adds the new message batching infrastructure that allows to store several messages into one single datagram. This patch includes an example for ctnetlink. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* nlmsg: remove unused function mnl_nlmsg_aligned_size()Jan Engelhardt2010-11-191-12/+0
| | | | | | | | | | | | | With the new CFLAGS, a notification pops up: nlmsg.c:64:8: warning: no previous prototype for "mnl_nlmsg_aligned_size" Marking it thus as static reveals it can be removed. nlmsg.c:64:15: warning: "mnl_nlmsg_aligned_size" defined but not used Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* build: tag function headers rather than decls as exportedJan Engelhardt2010-11-191-13/+20
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* license: change licensing terms from GPLv2+ to LGPLv2.1+Pablo Neira Ayuso2010-11-191-2/+2
| | | | | | | | | | Existing contributors ACK'ed the license change via email: * Jozsef Kadlecsik * Jan Engelhardt * Cristian Rodríguez Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* nlmsg: use bool for mnl_nlmsg_ok()Jan Engelhardt2010-11-111-1/+1
| | | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* nlmsg: rework mnl_nlmsg_fprintfPablo Neira Ayuso2010-11-071-24/+132
| | | | | | | | This patch reworks mnl_nlmsg_fprintf. It breaks backward compatibility of this function, there was no way to improve it without doing so (and we are still in time to break thing, BTW). Signed-off-bu: Pablo Neira Ayuso <pablo@netfilter.org>
* nlmsg: use bool return type for yes-no functionsJan Engelhardt2010-10-251-9/+9
| | | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* doc: documentation updatesJan Engelhardt2010-10-221-4/+4
| | | | | | Spelling, grammer, and synchronization of the readme. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* build: resolve compiler warningsJan Engelhardt2010-10-191-1/+1
| | | | | | | | nlmsg.c: In function "mnl_nlmsg_fprintf": nlmsg.c:260:4: warning: format "%.3d" expects type "int", but argument 3 has type "size_t" Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* doxygen documentationPablo Neira Ayuso2010-09-081-37/+45
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* skip PortID and sequence checking if zeroPablo Neira Ayuso2010-09-081-4/+13
| | | | | | | | | If the portID/sequence number that we specify is zero, we skip the sequence tracking. This is useful if we use the same socket to listen to events and to send commands and receive their result. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* nlmsg: use size_t instead of int for several input parametersPablo Neira Ayuso2010-05-171-4/+4
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* remove redudant alignment in mnl_nlmsg_size()Pablo Neira Ayuso2010-04-221-1/+1
| | | | | | MNL_NLMSG_HDRLEN already provides the aligned size of the netlink header. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* add mnl_nlmsg_fprintf() function for debugging purposesPablo Neira Ayuso2010-04-191-11/+17
| | | | | | This function is still quite preliminary, comments welcome! Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* remove mnl_nlmsg_get_len() functionPablo Neira Ayuso2010-04-121-16/+1
| | | | | | | | | Remove mnl_nlmsg_get_len() since it returns a field of a structure that is public (struct nlmsghdr). We can directly access the header fields and they are not likely to change in the future (at least for this version of Netlink I think). Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* remove bogus casting in mnl_nlmsg_get_payload_tail()Pablo Neira Ayuso2010-04-121-1/+1
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* improve documentation of netlink message helpersPablo Neira Ayuso2010-04-121-21/+55
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* more consistency name issues: rename get_data*() to get_payload*()Pablo Neira Ayuso2010-04-051-6/+6
| | | | | | This includes renaming get_tail() to get_payload_tail() Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* rename mnl_nlmsg_payload_size() to mnl_nlmsg_get_payload_len() for consistencyPablo Neira Ayuso2010-04-051-2/+2
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* rename msg.c to nlmsg.cPablo Neira Ayuso2010-04-051-0/+230
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>