This commit adds the ovs_dump_nla GDB command, which allows
dumping Netlink attributes. Here are some examples:

(gdb) ovs_dump_nla 0x7f10e35d8858 172 ovs_check_pkt_len_attr
(struct nlattr *) 0x7f10e35d8858:[OVS_CHECK_PKT_LEN_ATTR_PKT_...
(struct nlattr *) 0x7f10e35d8860:[OVS_CHECK_PKT_LEN_ATTR_...
(struct nlattr *) 0x7f10e35d88b0:[OVS_CHECK_PKT_LEN_ATTR_...

(gdb) ovs_dump_nla 0x7f10e35d8858 172
(struct nlattr *) 0x7f10e35d8858: {nla_len = 6, nla_type ...
(struct nlattr *) 0x7f10e35d8860: {nla_len = 80, nla_type ...
...len = 80, nla_type = 3}, nl_attr_get() = 0x7f10e35d88b4

(gdb)  ovs_dump_nla 0x7f10e35d88b4 80 ovs_action_attr dump
... nla_type = 19}, nl_attr_get() = 0x7f10e35d88b8: 3f 01 00 00
...

Signed-off-by: Eelco Chaudron <echau...@redhat.com>
---
 utilities/gdb/ovs_gdb.py | 67 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
index a8a84dcca..bdabe603d 100644
--- a/utilities/gdb/ovs_gdb.py
+++ b/utilities/gdb/ovs_gdb.py
@@ -28,6 +28,7 @@
 #    - ovs_dump_dp_provider
 #    - ovs_dump_netdev
 #    - ovs_dump_netdev_provider
+#    - ovs_dump_nla <struct nlattr *> <len> {dump} {enum type}
 #    - ovs_dump_ovs_list <struct ovs_list *> {[<structure>] [<member>] {dump}]}
 #    - ovs_dump_packets <struct dp_packet_batch|dp_packet> [tcpdump options]
 #    - ovs_dump_cmap <struct cmap *> {[<structure>] [<member>] {dump}]}
@@ -1614,6 +1615,71 @@ class CmdDumpDpConntrackConn(gdb.Command):
                                      short="short" in arg_list[1:])
 
 
+#
+# Implements the GDB "ovs_dump_nla" command
+#
+class CmdDumpNla(gdb.Command):
+    """Dump all Netlink attributes.
+    Usage:
+      ovs_dump_nla <struct nlattr *> <len> {dump} {enum type}
+
+    This is an example dumping some actions:
+
+    (gdb) ovs_dump_nla 0x7f10e35d88b4 80 ovs_action_attr
+    (struct nlattr *) 0x7f10e35d88b4:[OVS_ACTION_ATTR_METER] {nla_len = 8, ...
+    (struct nlattr *) 0x7f10e35d88bc:[OVS_ACTION_ATTR_SET] {nla_len = 20, ...
+    (struct nlattr *) 0x7f10e35d88d0:[OVS_ACTION_ATTR_SET] {nla_len = 32, ...
+    (struct nlattr *) 0x7f10e35d88f0:[OVS_ACTION_ATTR_PUSH_VLAN] {nla_len ...
+    (struct nlattr *) 0x7f10e35d88f8:[OVS_ACTION_ATTR_OUTPUT] {nla_len = 8, ...
+    """
+    def __init__(self):
+        super(CmdDumpNla, self).__init__("ovs_dump_nla",
+                                         gdb.COMMAND_DATA)
+
+    def invoke(self, arg, from_tty):
+        attr_size = gdb.lookup_type("struct nlattr").sizeof
+        arg_list = gdb.string_to_argv(arg)
+        dump = False
+        enum = None
+
+        if len(arg_list) not in (2, 3, 4):
+            print("ERROR: Invalid arguments!\n")
+            print(self.__doc__)
+            return
+
+        if len(arg_list) >= 3:
+            for i in range(2, len(arg_list)):
+                if arg_list[i] == "dump":
+                    dump = True
+                else:
+                    enum = arg_list[i]
+
+        nla = gdb.parse_and_eval(arg_list[0]).cast(
+            gdb.lookup_type('struct nlattr').pointer())
+
+        length = gdb.parse_and_eval(arg_list[1])
+
+        for attr in ForEachNL(nla, length):
+            if enum is not None:
+                hdr = "[{}] {}, nl_attr_get() = {}". \
+                    format(attr['nla_type'].cast(
+                        gdb.lookup_type('enum ' + arg_list[2])),
+                          attr.dereference(), attr + 1)
+            else:
+                hdr = " {}, nl_attr_get() = {}".format(attr.dereference(),
+                                                      attr + 1)
+
+            if dump:
+                mem = gdb.selected_inferior().read_memory(attr + 1,
+                                                          attr['nla_len']
+                                                          - attr_size)
+                dump = ": " + " ".join('{:02x}'.format(b) for b in bytes(mem))
+            else:
+                dump = ""
+
+            print("(struct nlattr *) {}:{}{}".format(attr, hdr, dump))
+
+
 #
 # Initialize all GDB commands
 #
@@ -1625,6 +1691,7 @@ CmdDumpDpNetdevPorts()
 CmdDumpDpProvider()
 CmdDumpNetdev()
 CmdDumpNetdevProvider()
+CmdDumpNla()
 CmdDumpOfpacts()
 CmdDumpOvsList()
 CmdDumpPackets()
-- 
2.50.0

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to