summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2010-05-07 12:53:04 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2010-09-08 12:53:42 +0200
commitb7e17c2d7334847230011cfcb3c11b5f33369f41 (patch)
treefa69212e2edbeb450ac7ebe3a80ec99c72ba1b24
parent6fa671f31450210275dee07cdfc94cbe63d9aa88 (diff)
skip PortID and sequence checking if zero
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>
-rw-r--r--src/nlmsg.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/nlmsg.c b/src/nlmsg.c
index 146296a..9b2f457 100644
--- a/src/nlmsg.c
+++ b/src/nlmsg.c
@@ -199,11 +199,15 @@ void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh)
* This functions returns 1 if the sequence tracking is fulfilled, otherwise
* 0 is returned. We skip the tracking for netlink messages whose sequence
* number is zero since it is usually reserved for event-based kernel
- * notifications.
+ * notifications. On the other hand, if seq is set but the message sequence
+ * number is not set (i.e. this is an event message coming from kernel-space),
+ * then we also skip the tracking. This approach is good if we use the same
+ * socket to send commands to kernel-space (that we want to track) and to
+ * listen to events (that we do not track).
*/
int mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq)
{
- return nlh->nlmsg_seq ? nlh->nlmsg_seq == seq : 1;
+ return nlh->nlmsg_seq && seq ? nlh->nlmsg_seq == seq : 1;
}
/**
@@ -213,11 +217,16 @@ int mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq)
*
* This functions return 1 if the origin is fulfilled, otherwise
* 0 is returned. We skip the tracking for netlink message whose portID
- * is zero since it is reserved for event-based kernel notifications.
+ * is zero since it is reserved for event-based kernel notifications. On the
+ * other hand, if portid is set but the message PortID is not set (i.e. this
+ * is an event message coming from kernel-space), then we also skip the
+ * tracking. This approach is good if we use the same socket to send commands
+ * to kernel-space (that we want to track) and to listen to events (that we
+ * do not track).
*/
int mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid)
{
- return nlh->nlmsg_pid ? nlh->nlmsg_pid == portid : 1;
+ return nlh->nlmsg_pid && portid ? nlh->nlmsg_pid == portid : 1;
}
/**