summaryrefslogtreecommitdiffstats
path: root/src/attr.c
Commit message (Collapse)AuthorAgeFilesLines
* libmnl: zero attribute paddingFlorian Westphal2018-03-201-0/+5
| | | | | | | | | | | | | | | | | | | | | | 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>
* src: cleanup function definitionsPablo Neira Ayuso2016-07-011-41/+28
| | | | | | | 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-35/+35
| | | | | | | | | | | | | | | | | | | | 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>
* attr: minor doc fix in mnl_attr_next()Hisao Tanabe2015-01-101-1/+0
| | | | | | | mnl_attr_next(): remove unused param - len Signed-off-by: Hisao Tanabe <xtanabe@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* doc: minor fixKen-ichirou MATSUZAWA2014-10-241-3/+1
| | | | | | | | | | | 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>
* attr: validate MNL_TYPE_MSEC same as MNL_TYPE_U64Ken-ichirou MATSUZAWA2013-12-071-0/+1
| | | | | Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp> Signed-off-by: Florian Westphal <fw@strlen.de>
* parse: add mnl_attr_for_each_payloadlibmnl-1.0.3Pablo Neira Ayuso2012-05-181-1/+34
| | | | | | | | | | | | This function allows you to parse the payload of the Netlink message. Thus, you can skip the headers and go down to the part of the message you want to parse. This patch has updated the LIBVERSION and it also bumps the version to 1.0.3, in case that someone wants to package some snapshot, not to mess with the new symbol we have added. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: use limits.h headerJan Engelhardt2011-03-051-2/+1
| | | | | | | | values.h is not present on other systems, and the glibc copy reads right away: Old compatibility names for <limits.h> and <float.h> constants. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* doc: don't show up EXPORT_SYMBOL in doxygenPablo Neira Ayuso2011-02-031-42/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* attr: add put function that allows to check buffer sizePablo Neira Ayuso2010-12-171-0/+174
| | | | | | | | | | This patch adds a set of function that allows to check the size of the buffer. This is useful for attribute batching. This is strongly based on a patch from Jozsef. Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* attr: add mnl_attr_nest_cancel()Pablo Neira Ayuso2010-11-221-0/+13
| | | | | | | This patch adds mnl_attr_nest_cancel() that allows to cancel the current nest that we are building. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* build: tag function headers rather than decls as exportedJan Engelhardt2010-11-191-29/+42
| | | | 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>
* attr: avoid multiple definition of hidden variableJan Engelhardt2010-11-161-12/+5
| | | | | | | | | | When nesting two mnl_attr_for_each loops, the __len__ variable will be declared twice, eliciting a warning when -Wshadow is turned on. There can also be warnings in pre-C99 because declarations and code are mixed. Do without any temporaries that are not explicitly specified as macro parameters. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* attr: remove redundant check for NULLJan Engelhardt2010-11-111-2/+2
| | | | | | | | Calling mnl_attr_parse with cb==NULL is pointless, because the function will do nothing else. Signed-off-by: Jan Engelhardt <jengelh@medozas.de> 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>
* attr: rename str_null from NULL awayJan Engelhardt2010-10-251-4/+4
| | | | | | | | | | A small little pedantism: NULL (as in, the pointer) isn't NUL (as in, the character with value zero, '\0'). I propose to rename it to strz, for the zero-terminated string (sometimes referred to as ASCIZ string, but of course C isn't tied to ASCII). Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* attr: string functions should take char *Jan Engelhardt2010-10-221-2/+2
| | | | | | | | I do not quite see the point of using strlen in conjunction with non-string data; so let's use char * as argument types to catch misuses. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* doc: documentation updatesJan Engelhardt2010-10-221-8/+9
| | | | | | Spelling, grammer, and synchronization of the readme. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* src: remove redundant castsJan Engelhardt2010-10-221-1/+1
| | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* src: add const qualifiersJan Engelhardt2010-10-221-4/+4
| | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* doxygen documentationPablo Neira Ayuso2010-09-081-69/+77
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* relax mnl_attr_type_valid() checkings and change errno valuePablo Neira Ayuso2010-05-091-1/+6
| | | | | | | | This patch relaxes strict attribute checkings in the example files. I have also changed the errno value, now it's EOPNOTSUPP instead of EINVAL. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* add helpers to nest attributesPablo Neira Ayuso2010-04-301-0/+32
| | | | | | Based on code from Jozsef Kadlecsik and its ipset-5 implementation. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* review data types for input parameters of mnl_attr_*() functionsPablo Neira Ayuso2010-04-221-12/+13
| | | | | | | | | | This patch includes the following changes: * use uint16_t for attribute types in mnl_attr_put_*() function * use uint16_t for maximun type in mnl_attr_type_valid(...) * use size_t for attribute size validation in mnl_attr_validate2(...) * use unsigned int for offset in mnl_attr_parse(...) instead of int Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* fix mnl_attr_parse()Jozsef Kadlecsik2010-04-221-1/+1
| | | | | | | | | | mnl_attr_parse does not take into account the length of the netlink message header and the offset. Thus when validating attributes, it goes over the end of the real attribute stream and catches invalid data areas. Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org
* remove mnl_nlmsg_get_len() functionPablo Neira Ayuso2010-04-121-1/+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>
* review documentation on netlink attribute helpersPablo Neira Ayuso2010-04-121-32/+68
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* more consistency name issues: rename get_data*() to get_payload*()Pablo Neira Ayuso2010-04-051-12/+12
| | | | | | This includes renaming get_tail() to get_payload_tail() Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* xPablo Neira Ayuso2010-04-051-1/+5
|
* rename mnl_attr_type_ok() by mnl_attr_type_valid() for consistencyPablo Neira Ayuso2010-04-051-4/+4
| | | | | | | better to rename this function since its return value is not similar to other _ok() functions, for consistency. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* fix warning in compilation due to different signessPablo Neira Ayuso2010-04-051-2/+5
| | | | | | | | | | | 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 attr.c: In function ‘mnl_attr_ok’: attr.c:79: warning: comparison between signed and unsigned Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* remove bogus checking in mnl_attr_validate() and mnl_attr_validate2()Pablo Neira Ayuso2010-04-041-2/+2
| | | | | | | | | attr.c: In function ‘mnl_attr_validate’: attr.c:189: warning: comparison of unsigned expression < 0 is always false attr.c: In function ‘mnl_attr_validate2’: attr.c:210: warning: comparison of unsigned expression < 0 is always false Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* rename mnl_attr_type_invalid() by mnl_attr_type_ok()Pablo Neira Ayuso2010-04-041-2/+2
| | | | | | And include the prototype in libmnl.h, since it was missing Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* remove mnl_align() as it's been replaced by MNL_ALIGN()Pablo Neira Ayuso2010-04-041-4/+4
| | | | | | | | We remove mnl_align() since it has been replaced by the macro MNL_ALIGN(). The macro allows its use in static arrays and such. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* add validation infrastructure and rework attribute parsingPablo Neira Ayuso2010-04-031-47/+141
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch includes the new validation infrastructure which is decoupled from the attribute parsing. It is composed of: - mnl_attr_type_invalid: that allows to check if the attribute type is valid (ie. the type is not higher than WXYZ_MAX). - mnl_attr_validate: that allows to validate that there's enough room for the attribute data. The patch includes the rework of the attribute parsers. Now, you don't have to use an array of pointer to store the result of the parsing, you can use whatever data structure instead. The prototype as it follows: typedef int (*mnl_attr_cb_t)(const struct nlattr *attr, void *data); extern int mnl_attr_parse(const struct nlmsghdr *nlh, int offset, mnl_attr_cb_t cb, void *data) There are three versions of rtnl-link-dump.c that show how attribute parsing can be done now. Probably that many examples are not good idea, I may remove some of them from the tree in the future. This patch also merges mnl_attr_parse_at_offset into mnl_attr_parse. This patch modifies MNL_ALIGN so that we can use it in static arrays (the use of mnl_align() is not allowed in compilation time to initialize an array field). I have added the mnl_attr_for_each() macro and I have changed mnl_attr_for_each_nested() to declare the length variable internally. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* use C99 types uintXX_t instead of POSIX u_intXX_tPablo Neira Ayuso2010-04-031-19/+19
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* add COPYING filePablo Neira Ayuso2010-03-261-2/+4
| | | | | | This library is distributed under GPLv2+. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* finish API documentationPablo Neira Ayuso2010-03-221-18/+122
| | | | | | This patch may contain errors but we can review them and fix them later, better to have it in the tree (to allow others to contribute) to keep it in my local tree.
* initial libmnl importPablo Neira Ayuso2010-03-191-0/+212