[PATCH 1/4] rtnl_mdb: decode br_port_msg netlink attributes
JingPiao Chen
chenjingpiao at gmail.com
Sun Sep 10 02:37:04 UTC 2017
* configure.ac (AC_CHECK_TYPES): Check for struct br_mdb_entry
in <linux/if_bridge.h>.
(AC_CHECK_MEMBERS): Check for state, flags and vid fields
in struct br_mdb_entry.
* rtnl_mdb.c: Include "xlat/mdb_flags.h", "xlat/mdb_states.h",
"xlat/rtnl_mdba_mdb_attrs.h", "xlat/rtnl_mdba_mdb_eattr_attrs.h",
"xlat/rtnl_mdba_mdb_entry_attrs.h" and "xlat/rtnl_mdba_router_attrs.h".
(decode_mdba_mdb_entry_info, decode_mdba_mdb_entry,
decode_mdba_mdb, decode_mdba_router_port,
decode_mdba_router): New functions.
(mdba_mdb_eattr_nla_decoders, mdba_mdb_entry_nla_decoders,
mdba_mdb_nla_decoders, mdba_router_nla_decoders,
br_port_msg_nla_decoders): New arrays.
(decode_br_port_msg): Use br_port_msg_nla_decoders.
* xlat/mdb_flags.in: New file.
* xlat/mdb_states.in: Likewise.
* xlat/rtnl_mdba_mdb_attrs.in: Likewise.
* xlat/rtnl_mdba_mdb_eattr_attrs.in: Likewise.
* xlat/rtnl_mdba_mdb_entry_attrs.in: Likewise.
* xlat/rtnl_mdba_router_attrs.in: Likewise.
---
configure.ac | 11 ++-
rtnl_mdb.c | 151 +++++++++++++++++++++++++++++++++++++-
xlat/mdb_flags.in | 1 +
xlat/mdb_states.in | 2 +
xlat/rtnl_mdba_mdb_attrs.in | 2 +
xlat/rtnl_mdba_mdb_eattr_attrs.in | 2 +
xlat/rtnl_mdba_mdb_entry_attrs.in | 2 +
xlat/rtnl_mdba_router_attrs.in | 2 +
8 files changed, 171 insertions(+), 2 deletions(-)
create mode 100644 xlat/mdb_flags.in
create mode 100644 xlat/mdb_states.in
create mode 100644 xlat/rtnl_mdba_mdb_attrs.in
create mode 100644 xlat/rtnl_mdba_mdb_eattr_attrs.in
create mode 100644 xlat/rtnl_mdba_mdb_entry_attrs.in
create mode 100644 xlat/rtnl_mdba_router_attrs.in
diff --git a/configure.ac b/configure.ac
index cb6571a..2990a03 100644
--- a/configure.ac
+++ b/configure.ac
@@ -448,7 +448,16 @@ AC_CHECK_HEADERS([linux/bpf.h], [
st_CHECK_UNION_BPF_ATTR([prog_flags])
])
-AC_CHECK_TYPES([struct br_port_msg],,, [#include <linux/if_bridge.h>])
+AC_CHECK_TYPES(m4_normalize([
+ struct br_mdb_entry,
+ struct br_port_msg
+]),,, [#include <linux/if_bridge.h>])
+AC_CHECK_MEMBERS(m4_normalize([
+ struct br_mdb_entry.flags,
+ struct br_mdb_entry.state,
+ struct br_mdb_entry.vid
+]),,, [#include <linux/if_bridge.h>])
+
AC_CHECK_TYPES([struct dcbmsg],,, [#include <linux/dcbnl.h>])
AC_CHECK_TYPES([struct ifaddrlblmsg],,, [#include <linux/if_addrlabel.h>])
AC_CHECK_TYPES([struct netconfmsg],,, [#include <linux/netconf.h>])
diff --git a/rtnl_mdb.c b/rtnl_mdb.c
index ebe737d..7ec3c86 100644
--- a/rtnl_mdb.c
+++ b/rtnl_mdb.c
@@ -39,7 +39,154 @@
# include <linux/if_bridge.h>
# include "netlink.h"
+# ifdef HAVE_STRUCT_BR_MDB_ENTRY_FLAGS
+# include "xlat/mdb_flags.h"
+# endif
+# ifdef HAVE_STRUCT_BR_MDB_ENTRY_STATE
+# include "xlat/mdb_states.h"
+# endif
# include "xlat/rtnl_mdb_attrs.h"
+# include "xlat/rtnl_mdba_mdb_attrs.h"
+# include "xlat/rtnl_mdba_mdb_eattr_attrs.h"
+# include "xlat/rtnl_mdba_mdb_entry_attrs.h"
+# include "xlat/rtnl_mdba_router_attrs.h"
+
+static const nla_decoder_t mdba_mdb_eattr_nla_decoders[] = {
+ [MDBA_MDB_EATTR_TIMER] = decode_nla_u32
+};
+
+static bool
+decode_mdba_mdb_entry_info(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+# ifdef HAVE_STRUCT_BR_MDB_ENTRY
+ struct br_mdb_entry entry;
+
+ if (len < sizeof(entry))
+ return false;
+ else if (!umove_or_printaddr(tcp, addr, &entry)) {
+ PRINT_FIELD_IFINDEX("{", entry, ifindex);
+# ifdef HAVE_STRUCT_BR_MDB_ENTRY_STATE
+ PRINT_FIELD_XVAL(", ", entry, state, mdb_states, "MDB_???");
+# endif
+# ifdef HAVE_STRUCT_BR_MDB_ENTRY_FLAGS
+ PRINT_FIELD_FLAGS(", ", entry, flags,
+ mdb_flags, "MDB_FLAGS_???");
+# endif
+# ifdef HAVE_STRUCT_BR_MDB_ENTRY_VID
+ PRINT_FIELD_U(", ", entry, vid);
+# endif
+
+ const int proto = ntohs(entry.addr.proto);
+ const char *const str = proto == AF_INET || proto == AF_INET6
+ ? (proto == AF_INET ? "ip4" : "ip6")
+ : "u";
+
+ tprints(", addr={");
+ print_inet_addr(proto, &entry.addr.u,
+ sizeof(entry.addr.u), str);
+ tprints(", proto=htons(");
+ printxval(addrfams, proto, "AF_???");
+ tprints(")}}");
+ }
+
+ const size_t offset = NLMSG_ALIGN(sizeof(entry));
+ if (len > offset) {
+ tprints(", ");
+ decode_nlattr(tcp, addr + offset, len - offset,
+ rtnl_mdba_mdb_eattr_attrs, "MDBA_MDB_EATTR_???",
+ mdba_mdb_eattr_nla_decoders,
+ ARRAY_SIZE(mdba_mdb_eattr_nla_decoders), NULL);
+ }
+
+ return true;
+# else
+ return false;
+# endif /* HAVE_STRUCT_BR_MDB_ENTRY */
+}
+
+static const nla_decoder_t mdba_mdb_entry_nla_decoders[] = {
+ [MDBA_MDB_ENTRY_INFO] = decode_mdba_mdb_entry_info
+};
+
+static bool
+decode_mdba_mdb_entry(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_entry_attrs,
+ "MDBA_MDB_ENTRY_???", mdba_mdb_entry_nla_decoders,
+ ARRAY_SIZE(mdba_mdb_entry_nla_decoders), NULL);
+
+ return true;
+}
+
+static const nla_decoder_t mdba_mdb_nla_decoders[] = {
+ [MDBA_MDB_ENTRY] = decode_mdba_mdb_entry
+};
+
+static bool
+decode_mdba_mdb(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_attrs, "MDBA_MDB_???",
+ mdba_mdb_nla_decoders,
+ ARRAY_SIZE(mdba_mdb_nla_decoders), NULL);
+
+ return true;
+}
+
+static bool
+decode_mdba_router_port(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ uint32_t ifindex;
+
+ if (len < sizeof(ifindex))
+ return false;
+ else if (!umove_or_printaddr(tcp, addr, &ifindex))
+ print_ifindex(ifindex);
+
+ const size_t offset = NLMSG_ALIGN(sizeof(ifindex));
+ if (len > offset) {
+ tprints(", ");
+ decode_nlattr(tcp, addr + offset, len - offset,
+ rtnl_mdba_mdb_eattr_attrs, "MDBA_MDB_EATTR_???",
+ mdba_mdb_eattr_nla_decoders,
+ ARRAY_SIZE(mdba_mdb_eattr_nla_decoders), NULL);
+ }
+
+ return true;
+}
+
+static const nla_decoder_t mdba_router_nla_decoders[] = {
+ [MDBA_ROUTER_PORT] = decode_mdba_router_port
+};
+
+static bool
+decode_mdba_router(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ decode_nlattr(tcp, addr, len, rtnl_mdba_router_attrs, "MDBA_ROUTER_???",
+ mdba_router_nla_decoders,
+ ARRAY_SIZE(mdba_router_nla_decoders), NULL);
+
+ return true;
+}
+
+static const nla_decoder_t br_port_msg_nla_decoders[] = {
+ [MDBA_MDB] = decode_mdba_mdb,
+ [MDBA_ROUTER] = decode_mdba_router
+};
DECL_NETLINK_ROUTE_DECODER(decode_br_port_msg)
{
@@ -65,7 +212,9 @@ DECL_NETLINK_ROUTE_DECODER(decode_br_port_msg)
if (decode_nla && len > offset) {
tprints(", ");
decode_nlattr(tcp, addr + offset, len - offset,
- rtnl_mdb_attrs, "MDBA_???", NULL, 0, NULL);
+ rtnl_mdb_attrs, "MDBA_???",
+ br_port_msg_nla_decoders,
+ ARRAY_SIZE(br_port_msg_nla_decoders), NULL);
}
}
diff --git a/xlat/mdb_flags.in b/xlat/mdb_flags.in
new file mode 100644
index 0000000..4c2f1ed
--- /dev/null
+++ b/xlat/mdb_flags.in
@@ -0,0 +1 @@
+MDB_FLAGS_OFFLOAD
diff --git a/xlat/mdb_states.in b/xlat/mdb_states.in
new file mode 100644
index 0000000..7a580b9
--- /dev/null
+++ b/xlat/mdb_states.in
@@ -0,0 +1,2 @@
+MDB_TEMPORARY
+MDB_PERMANENT
diff --git a/xlat/rtnl_mdba_mdb_attrs.in b/xlat/rtnl_mdba_mdb_attrs.in
new file mode 100644
index 0000000..7ff5cce
--- /dev/null
+++ b/xlat/rtnl_mdba_mdb_attrs.in
@@ -0,0 +1,2 @@
+MDBA_MDB_UNSPEC 0
+MDBA_MDB_ENTRY 1
diff --git a/xlat/rtnl_mdba_mdb_eattr_attrs.in b/xlat/rtnl_mdba_mdb_eattr_attrs.in
new file mode 100644
index 0000000..c7c1b7b
--- /dev/null
+++ b/xlat/rtnl_mdba_mdb_eattr_attrs.in
@@ -0,0 +1,2 @@
+MDBA_MDB_EATTR_UNSPEC 0
+MDBA_MDB_EATTR_TIMER 1
diff --git a/xlat/rtnl_mdba_mdb_entry_attrs.in b/xlat/rtnl_mdba_mdb_entry_attrs.in
new file mode 100644
index 0000000..52b18d6
--- /dev/null
+++ b/xlat/rtnl_mdba_mdb_entry_attrs.in
@@ -0,0 +1,2 @@
+MDBA_MDB_ENTRY_UNSPEC 0
+MDBA_MDB_ENTRY_INFO 1
diff --git a/xlat/rtnl_mdba_router_attrs.in b/xlat/rtnl_mdba_router_attrs.in
new file mode 100644
index 0000000..21dfeaa
--- /dev/null
+++ b/xlat/rtnl_mdba_router_attrs.in
@@ -0,0 +1,2 @@
+MDBA_ROUTER_UNSPEC 0
+MDBA_ROUTER_PORT 1
--
2.7.4
More information about the Strace-devel
mailing list