summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* socket: use more appropriate types for mnl_socket_bindJan Engelhardt2010-10-221-1/+1
| | | | | | | groups, being a bitmask, should be unsigned; and let's also use pid_t for pid. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* callback: mnl_cb_run should use a void *Jan Engelhardt2010-10-221-3/+3
| | | | | | Because in most cases, it won't be a nul-terminated string :) Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* 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-223-21/+22
| | | | | | Spelling, grammer, and synchronization of the readme. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* socket: remove statement with no effectJan Engelhardt2010-10-221-1/+0
| | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* src: remove redundant castsJan Engelhardt2010-10-222-2/+2
| | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* src: add const qualifiersJan Engelhardt2010-10-222-5/+5
| | | | Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* doc: git tree update (now at netfilter.org) and fix listing in doxygenPablo Neira Ayuso2010-10-211-7/+7
| | | | | | | | This patch update the git tree address (now at netfilter.org) and it also fixes a minor problem with the doxygen output in one of the socket helpers. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: define MNL_SOCKET_BUFFER_SIZE to 8192ULPablo Neira Ayuso2010-10-211-2/+5
| | | | | | | | | | | | | | | | Davem spotted during the Netfilter Workshop that user-space applications should use 8KB buffers for recv(). I accidentally found that NFLOG is not following this approach (in this case we're using 131072 bytes messages), we have to document this. Anyway, according to linux/netlink.h (and to complete this log message): "skb should fit one page. This choice is good for headerless malloc. But we should limit to 8K so that userspace does not have to use enormous buffer sizes on recvmsg() calls just to avoid MSG_TRUNC when PAGE_SIZE is very large." Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* build: remove unneeded -dynamic -ldl -nostartfiles flagsJan Engelhardt2010-10-191-1/+1
| | | | | | | | | Besides that -ldl should be in _LDADD (not _LDFLAGS), I do not see any dlopen calls at all that would make the library a requirement. I also see no reason to use -Wc,-nostartfiles. 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>
* build: run autoupdateJan Engelhardt2010-10-191-2/+0
| | | | | | | | | | | | Macro usage has changed over the last few years. Update it to the current specification using autoupdate(1). Manually update INCLUDES -> CPPFLAGS, because autoupdate did not catch that. Remove $(all_includes) and $(LIBS) because it is not used anywhere. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
* add quote from Thoureau to documentationPablo Neira Ayuso2010-10-101-0/+4
| | | | | | I like this quote. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* doxygen documentationPablo Neira Ayuso2010-09-084-143/+220
| | | | 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>
* socket: remove mnl_socket_sendmsg() and mnl_socket_recvmsg()Pablo Neira Ayuso2010-06-251-30/+0
| | | | | | | | These functions are too simple wrappers that bloat the library. We can use mnl_socket_get_fd() to obtain the file descriptor and invoke message-oriented system call instead. 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>
* 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>
* change errno values for mnl_cb_run[2]()Pablo Neira Ayuso2010-05-071-3/+6
| | | | | | | | | | | | | This patch changes the errno value of mnl_cb_run[2]() in the following two cases: * Invalid expected portID: ESRCH. * Invalid sequence number: EPROTO. I didn't find any better generic errno value. EINVAL is reserved for malformed messages, to avoid confusions. 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>
* add -Wextra -Wall for example filesPablo Neira Ayuso2010-04-221-1/+0
| | | | | | AM_CFLAGS=-fPIC -Wall -Wextra -Wno-unused-parameter Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* fix warning in mnl_cb_run2()Pablo Neira Ayuso2010-04-221-3/+3
| | | | | | | callback.c: In function ‘mnl_cb_run2’: callback.c:106: warning: pointer targets in passing argument 2 of ‘mnl_nlmsg_next’ differ in signednes 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>
* use size_t to indicate the buffer size in mnl_cb_run*()Pablo Neira Ayuso2010-04-221-2/+2
| | | | 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
* 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>
* update socket helper documentationPablo Neira Ayuso2010-04-121-5/+6
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* remove mnl_nlmsg_get_len() functionPablo Neira Ayuso2010-04-122-17/+2
| | | | | | | | | 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>
* 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-053-19/+19
| | | | | | 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_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-052-1/+4
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* 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-052-4/+10
| | | | | | | | | | | 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>
* add -Wextra to spot more errors in compilationPablo Neira Ayuso2010-04-041-1/+1
| | | | 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-042-24/+12
| | | | | | | | 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>
* check source of the netlink message and fix sequence tracking logicPablo Neira Ayuso2010-04-042-9/+30
| | | | | | | | | | | | This patch changes the callback handlers to include netlink portID checking. Thus, we avoid that any malicious process can spoof messages. If portid, sequence number of the message is != 0, we check if the message is what we expect. This allows to use the same netlink channel for dumps (portid, seq != 0) and event-based notifications (portid, seq == 0). 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-032-20/+20
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* constify several mnl_socket_* parameters and use size_t instead of intPablo Neira Ayuso2010-04-031-8/+8
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* fix mnl_socket_bind() to support the selection of the netlink portIDPablo Neira Ayuso2010-03-281-0/+1
|
* partially revert previous commitPablo Neira Ayuso2010-03-281-2/+2
| | | | | the use of unsigned int in the number of bytes affects other message handling helper function, hold on with this.
* use `unsigned int' for number of bytes and array size in callback APIPablo Neira Ayuso2010-03-281-3/+3
|
* add COPYING filePablo Neira Ayuso2010-03-264-8/+16
| | | | | | This library is distributed under GPLv2+. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>