[PATCH 1/2] netlink: implement generic nlmsg_flags decoding
JingPiao Chen
chenjingpiao at gmail.com
Wed Jun 7 15:35:18 UTC 2017
* netlink.c (decode_nlmsg_flags): New function.
(print_nlmsghdr): Use it.
* xlat/netlink_get_flags.in: New file.
* xlat/netlink_new_flags.in: Likewise.
Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
Co-authored-by: Dmitry V. Levin <ldv at altlinux.org>
---
RTM_DELACTION seem use get flags (NLM_F_ROOT)
net/sched/act_api.c:
static int tca_action_flush(struct net *net, struct nlattr *nla,
struct nlmsghdr *n, u32 portid)
{
...
nlh = nlmsg_put(skb, portid, n->nlmsg_seq, RTM_DELACTION,
sizeof(*t), 0);
...
nlh->nlmsg_flags |= NLM_F_ROOT;
module_put(ops->owner);
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
...
}
netlink.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++-
xlat/netlink_get_flags.in | 11 +++++++++++
xlat/netlink_new_flags.in | 11 +++++++++++
3 files changed, 71 insertions(+), 1 deletion(-)
create mode 100644 xlat/netlink_get_flags.in
create mode 100644 xlat/netlink_new_flags.in
diff --git a/netlink.c b/netlink.c
index f9ff465..93f094f 100644
--- a/netlink.c
+++ b/netlink.c
@@ -34,6 +34,8 @@
#include <linux/rtnetlink.h>
#include <linux/xfrm.h>
#include "xlat/netlink_flags.h"
+#include "xlat/netlink_get_flags.h"
+#include "xlat/netlink_new_flags.h"
#include "xlat/netlink_protocols.h"
#include "xlat/netlink_types.h"
#include "xlat/nl_audit_types.h"
@@ -152,6 +154,51 @@ decode_nlmsg_type(const uint16_t type, const unsigned int family)
}
}
+static void
+decode_nlmsg_flags(const uint16_t flags, const uint16_t type, const int family)
+{
+ const struct xlat *table = netlink_flags;
+
+ switch (family) {
+ case NETLINK_SOCK_DIAG:
+ table = netlink_get_flags;
+ break;
+ case NETLINK_ROUTE:
+ switch (type & 3) {
+ case 0:
+ table = netlink_new_flags;
+ break;
+ case 2:
+ table = netlink_get_flags;
+ break;
+ }
+ if (type == RTM_DELACTION)
+ table = netlink_get_flags;
+ break;
+ case NETLINK_XFRM:
+ switch (type) {
+ case XFRM_MSG_NEWSA:
+ case XFRM_MSG_NEWPOLICY:
+ case XFRM_MSG_NEWAE:
+ case XFRM_MSG_NEWSADINFO:
+ case XFRM_MSG_NEWSPDINFO:
+ table = netlink_new_flags;
+ break;
+
+ case XFRM_MSG_GETSA:
+ case XFRM_MSG_GETPOLICY:
+ case XFRM_MSG_GETAE:
+ case XFRM_MSG_GETSADINFO:
+ case XFRM_MSG_GETSPDINFO:
+ table = netlink_get_flags;
+ break;
+ }
+ break;
+ }
+
+ printflags(table, flags, "NLM_F_???");
+}
+
static int
print_nlmsghdr(struct tcb *tcp,
const int fd,
@@ -170,7 +217,8 @@ print_nlmsghdr(struct tcb *tcp,
decode_nlmsg_type(nlmsghdr->nlmsg_type, hdr_family);
tprints(", flags=");
- printflags(netlink_flags, nlmsghdr->nlmsg_flags, "NLM_F_???");
+ decode_nlmsg_flags(nlmsghdr->nlmsg_flags,
+ nlmsghdr->nlmsg_type, hdr_family);
tprintf(", seq=%u, pid=%u}", nlmsghdr->nlmsg_seq,
nlmsghdr->nlmsg_pid);
diff --git a/xlat/netlink_get_flags.in b/xlat/netlink_get_flags.in
new file mode 100644
index 0000000..0b68ba9
--- /dev/null
+++ b/xlat/netlink_get_flags.in
@@ -0,0 +1,11 @@
+NLM_F_REQUEST
+NLM_F_MULTI
+NLM_F_ACK
+NLM_F_ECHO
+NLM_F_DUMP_INTR
+NLM_F_DUMP_FILTERED
+
+NLM_F_DUMP
+NLM_F_ROOT
+NLM_F_MATCH
+NLM_F_ATOMIC
diff --git a/xlat/netlink_new_flags.in b/xlat/netlink_new_flags.in
new file mode 100644
index 0000000..fa0c859
--- /dev/null
+++ b/xlat/netlink_new_flags.in
@@ -0,0 +1,11 @@
+NLM_F_REQUEST
+NLM_F_MULTI
+NLM_F_ACK
+NLM_F_ECHO
+NLM_F_DUMP_INTR
+NLM_F_DUMP_FILTERED
+
+NLM_F_REPLACE
+NLM_F_EXCL
+NLM_F_CREATE
+NLM_F_APPEND
--
2.7.4
More information about the Strace-devel
mailing list