Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-12-07 Thread Eelco Chaudron



On 7 Dec 2021, at 16:31, Ilya Maximets wrote:

> On 12/7/21 15:34, Eelco Chaudron wrote:
>>
>>
>> On 7 Dec 2021, at 15:17, Mike Pattrick wrote:
>>
>>> On Tue, Dec 7, 2021 at 8:54 AM Ilya Maximets  wrote:

 On 11/19/21 15:35, Mike Pattrick wrote:
> This commit adds a basic packet metadata macro to the already existing
> macros in ovs_gdb.py, ovs_dump_packets will print out information about
> one or more packets. It feeds packets into tcpdump, and the user can
> pass in tcpdump options to modify how packets are parsed or even write
> out packets to a pcap file.
>
> Example usage:
> (gdb) break fast_path_processing
> (gdb) commands
>  ovs_dump_packets packets_
>  continue
>  end
> (gdb) continue
>
> Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
> 12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 
> 10.1.1.1 tell 10.1.1.2, length 28
> Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
> 12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
> a6:0f:c3:f0:5f:bd (oui Unknown), length 28

 Hey, Mike.  Thanks for working on this!

 Could you, please, wrap some lines here in the commit message and
 in the code?

 I mean, I think, that ideally we need to do this:

 diff --git a/utilities/automake.mk b/utilities/automake.mk
 index e2e22c39a..7808c0ead 100644
 --- a/utilities/automake.mk
 +++ b/utilities/automake.mk
 @@ -126,6 +126,7 @@ endif

  FLAKE8_PYFILES += utilities/ovs-pcap.in \
 utilities/checkpatch.py utilities/ovs-dev.py \
 +   utilities/gdb/ovs_gdb.py \
 utilities/ovs-check-dead-ifs.in \
 utilities/ovs-tcpdump.in \
 utilities/ovs-pipegen.py
 ---

 But the file currently has some pep8 issues, so we can't.
 At least, we can try to not add more warnings in a new code.

 What do you think?
>>>
>>> The change to make it fully PEP8 would be pretty small, I think only
>>> long lines remain. I'll resubmit with that taken care of.
>>
>> I think the long lines in the python script should remain as those are 
>> console outputs which are displayed as part of the GDB help, and wrapping 
>> them does not make it look good inside GDB.
>
> There should be a way to wrap most of them without harming the looks.
> I mean, in some examples where lots of addresses is printed, it's
> enough to shorten these addresses to meet the line length limit.
> E.g. by keeping only 4 hex digits and, probably, changing them to
> something like 0x, 0x.
>
> Usage examples could probably be moved to the next line from the
> 'Usage:' line and maybe split by the arguments to several lines.

Sounds good to me, as long as the output still makes sense.
Maybe do this for the existing output as well so the file is clean ;)

//Eelco

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


Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-12-07 Thread Ilya Maximets
On 12/7/21 15:34, Eelco Chaudron wrote:
> 
> 
> On 7 Dec 2021, at 15:17, Mike Pattrick wrote:
> 
>> On Tue, Dec 7, 2021 at 8:54 AM Ilya Maximets  wrote:
>>>
>>> On 11/19/21 15:35, Mike Pattrick wrote:
 This commit adds a basic packet metadata macro to the already existing
 macros in ovs_gdb.py, ovs_dump_packets will print out information about
 one or more packets. It feeds packets into tcpdump, and the user can
 pass in tcpdump options to modify how packets are parsed or even write
 out packets to a pcap file.

 Example usage:
 (gdb) break fast_path_processing
 (gdb) commands
  ovs_dump_packets packets_
  continue
  end
 (gdb) continue

 Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
 12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 
 10.1.1.1 tell 10.1.1.2, length 28
 Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
 12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
 a6:0f:c3:f0:5f:bd (oui Unknown), length 28
>>>
>>> Hey, Mike.  Thanks for working on this!
>>>
>>> Could you, please, wrap some lines here in the commit message and
>>> in the code?
>>>
>>> I mean, I think, that ideally we need to do this:
>>>
>>> diff --git a/utilities/automake.mk b/utilities/automake.mk
>>> index e2e22c39a..7808c0ead 100644
>>> --- a/utilities/automake.mk
>>> +++ b/utilities/automake.mk
>>> @@ -126,6 +126,7 @@ endif
>>>
>>>  FLAKE8_PYFILES += utilities/ovs-pcap.in \
>>> utilities/checkpatch.py utilities/ovs-dev.py \
>>> +   utilities/gdb/ovs_gdb.py \
>>> utilities/ovs-check-dead-ifs.in \
>>> utilities/ovs-tcpdump.in \
>>> utilities/ovs-pipegen.py
>>> ---
>>>
>>> But the file currently has some pep8 issues, so we can't.
>>> At least, we can try to not add more warnings in a new code.
>>>
>>> What do you think?
>>
>> The change to make it fully PEP8 would be pretty small, I think only
>> long lines remain. I'll resubmit with that taken care of.
> 
> I think the long lines in the python script should remain as those are 
> console outputs which are displayed as part of the GDB help, and wrapping 
> them does not make it look good inside GDB.

There should be a way to wrap most of them without harming the looks.
I mean, in some examples where lots of addresses is printed, it's
enough to shorten these addresses to meet the line length limit.
E.g. by keeping only 4 hex digits and, probably, changing them to
something like 0x, 0x.

Usage examples could probably be moved to the next line from the
'Usage:' line and maybe split by the arguments to several lines.

> 
> This was one of my previous comments on an earlier patchset.
> 
> //Eelco
> 
> 

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


Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-12-07 Thread Eelco Chaudron



On 7 Dec 2021, at 15:17, Mike Pattrick wrote:

> On Tue, Dec 7, 2021 at 8:54 AM Ilya Maximets  wrote:
>>
>> On 11/19/21 15:35, Mike Pattrick wrote:
>>> This commit adds a basic packet metadata macro to the already existing
>>> macros in ovs_gdb.py, ovs_dump_packets will print out information about
>>> one or more packets. It feeds packets into tcpdump, and the user can
>>> pass in tcpdump options to modify how packets are parsed or even write
>>> out packets to a pcap file.
>>>
>>> Example usage:
>>> (gdb) break fast_path_processing
>>> (gdb) commands
>>>  ovs_dump_packets packets_
>>>  continue
>>>  end
>>> (gdb) continue
>>>
>>> Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
>>> 12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 
>>> 10.1.1.1 tell 10.1.1.2, length 28
>>> Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
>>> 12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
>>> a6:0f:c3:f0:5f:bd (oui Unknown), length 28
>>
>> Hey, Mike.  Thanks for working on this!
>>
>> Could you, please, wrap some lines here in the commit message and
>> in the code?
>>
>> I mean, I think, that ideally we need to do this:
>>
>> diff --git a/utilities/automake.mk b/utilities/automake.mk
>> index e2e22c39a..7808c0ead 100644
>> --- a/utilities/automake.mk
>> +++ b/utilities/automake.mk
>> @@ -126,6 +126,7 @@ endif
>>
>>  FLAKE8_PYFILES += utilities/ovs-pcap.in \
>> utilities/checkpatch.py utilities/ovs-dev.py \
>> +   utilities/gdb/ovs_gdb.py \
>> utilities/ovs-check-dead-ifs.in \
>> utilities/ovs-tcpdump.in \
>> utilities/ovs-pipegen.py
>> ---
>>
>> But the file currently has some pep8 issues, so we can't.
>> At least, we can try to not add more warnings in a new code.
>>
>> What do you think?
>
> The change to make it fully PEP8 would be pretty small, I think only
> long lines remain. I'll resubmit with that taken care of.

I think the long lines in the python script should remain as those are console 
outputs which are displayed as part of the GDB help, and wrapping them does not 
make it look good inside GDB.

This was one of my previous comments on an earlier patchset.

//Eelco


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


Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-12-07 Thread Mike Pattrick
On Tue, Dec 7, 2021 at 8:54 AM Ilya Maximets  wrote:
>
> On 11/19/21 15:35, Mike Pattrick wrote:
> > This commit adds a basic packet metadata macro to the already existing
> > macros in ovs_gdb.py, ovs_dump_packets will print out information about
> > one or more packets. It feeds packets into tcpdump, and the user can
> > pass in tcpdump options to modify how packets are parsed or even write
> > out packets to a pcap file.
> >
> > Example usage:
> > (gdb) break fast_path_processing
> > (gdb) commands
> >  ovs_dump_packets packets_
> >  continue
> >  end
> > (gdb) continue
> >
> > Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
> > 12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 
> > 10.1.1.1 tell 10.1.1.2, length 28
> > Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
> > 12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
> > a6:0f:c3:f0:5f:bd (oui Unknown), length 28
>
> Hey, Mike.  Thanks for working on this!
>
> Could you, please, wrap some lines here in the commit message and
> in the code?
>
> I mean, I think, that ideally we need to do this:
>
> diff --git a/utilities/automake.mk b/utilities/automake.mk
> index e2e22c39a..7808c0ead 100644
> --- a/utilities/automake.mk
> +++ b/utilities/automake.mk
> @@ -126,6 +126,7 @@ endif
>
>  FLAKE8_PYFILES += utilities/ovs-pcap.in \
> utilities/checkpatch.py utilities/ovs-dev.py \
> +   utilities/gdb/ovs_gdb.py \
> utilities/ovs-check-dead-ifs.in \
> utilities/ovs-tcpdump.in \
> utilities/ovs-pipegen.py
> ---
>
> But the file currently has some pep8 issues, so we can't.
> At least, we can try to not add more warnings in a new code.
>
> What do you think?

The change to make it fully PEP8 would be pretty small, I think only
long lines remain. I'll resubmit with that taken care of.

-M

>
> Best regards, Ilya Maximets.
>

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


Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-12-07 Thread Ilya Maximets
On 11/19/21 15:35, Mike Pattrick wrote:
> This commit adds a basic packet metadata macro to the already existing
> macros in ovs_gdb.py, ovs_dump_packets will print out information about
> one or more packets. It feeds packets into tcpdump, and the user can
> pass in tcpdump options to modify how packets are parsed or even write
> out packets to a pcap file.
> 
> Example usage:
> (gdb) break fast_path_processing
> (gdb) commands
>  ovs_dump_packets packets_
>  continue
>  end
> (gdb) continue
> 
> Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
> 12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 10.1.1.1 
> tell 10.1.1.2, length 28
> Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
> 12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
> a6:0f:c3:f0:5f:bd (oui Unknown), length 28

Hey, Mike.  Thanks for working on this!

Could you, please, wrap some lines here in the commit message and
in the code?

I mean, I think, that ideally we need to do this:

diff --git a/utilities/automake.mk b/utilities/automake.mk
index e2e22c39a..7808c0ead 100644
--- a/utilities/automake.mk
+++ b/utilities/automake.mk
@@ -126,6 +126,7 @@ endif
 
 FLAKE8_PYFILES += utilities/ovs-pcap.in \
utilities/checkpatch.py utilities/ovs-dev.py \
+   utilities/gdb/ovs_gdb.py \
utilities/ovs-check-dead-ifs.in \
utilities/ovs-tcpdump.in \
utilities/ovs-pipegen.py
---

But the file currently has some pep8 issues, so we can't.
At least, we can try to not add more warnings in a new code.

What do you think?

Best regards, Ilya Maximets.
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-11-24 Thread Eelco Chaudron


On 19 Nov 2021, at 15:35, Mike Pattrick wrote:

> This commit adds a basic packet metadata macro to the already existing
> macros in ovs_gdb.py, ovs_dump_packets will print out information about
> one or more packets. It feeds packets into tcpdump, and the user can
> pass in tcpdump options to modify how packets are parsed or even write
> out packets to a pcap file.
>
> Example usage:
> (gdb) break fast_path_processing
> (gdb) commands
>  ovs_dump_packets packets_
>  continue
>  end

Guess you removed the > before the commands from the previous commit, guess 
another mail client issue.
However should not matter, it’s just a commit message.

Rest looks good to me (one small nit below, maybe can be fixed on commit)

Acked-by: Eelco Chaudron 

> (gdb) continue
>
> Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
> 12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 10.1.1.1 
> tell 10.1.1.2, length 28
> Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
> 12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
> a6:0f:c3:f0:5f:bd (oui Unknown), length 28
>
> Signed-off-by: Mike Pattrick 
> ---
>  utilities/gdb/ovs_gdb.py | 114 ++-
>  1 file changed, 112 insertions(+), 2 deletions(-)
>
> diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
> index 0b2ecb81b..9da83920b 100644
> --- a/utilities/gdb/ovs_gdb.py
> +++ b/utilities/gdb/ovs_gdb.py
> @@ -29,6 +29,7 @@
>  #- ovs_dump_netdev
>  #- ovs_dump_netdev_provider
>  #- ovs_dump_ovs_list  {[] [] 
> {dump}]}
> +#- ovs_dump_packets  [tcpdump 
> options]
>  #- ovs_dump_simap 
>  #- ovs_dump_smap 
>  #- ovs_dump_udpif_keys {|} {short}
> @@ -56,8 +57,15 @@
>  #...
>  #
>  import gdb
> +import struct
>  import sys
>  import uuid
> +try:
> +from scapy.layers.l2 import Ether
> +from scapy.utils import tcpdump
> +except ModuleNotFoundError:
> +Ether = None
> +tcpdump = None
>
>
>  #
> @@ -138,7 +146,7 @@ def get_time_msec():
>
>  def get_time_now():
>  # See get_time_msec() above
> -return int(get_global_variable("coverage_run_time"))/1000, -5
> +return int(get_global_variable("coverage_run_time")) / 1000, -5
>
>
>  def eth_addr_to_string(eth_addr):
> @@ -156,7 +164,7 @@ def eth_addr_to_string(eth_addr):
>  #
>  class ProgressIndicator(object):
>  def __init__(self, message=None):
> -self.spinner = "/-\|"
> +self.spinner = "/-\\|"
>  self.spinner_index = 0
>  self.message = message
>
> @@ -1306,6 +1314,107 @@ class CmdDumpOfpacts(gdb.Command):
>  print("(struct ofpact *) {}: {}".format(node, 
> node.dereference()))
>
>
> +#
> +# Implements the GDB "ovs_dump_packets" command
> +#
> +class CmdDumpPackets(gdb.Command):
> +"""Dump metadata about dp_packets
> +Usage: ovs_dump_packets  
> [tcpdump options]
> +
> +This command can take either a dp_packet_batch struct and print out
> +metadata about all packets in this batch, or a single dp_packet struct 
> and
> +print out metadata about a single packet.
> +
> +Everything after the struct reference is passed into tcpdump. If nothing
> +is passed in as a tcpdump option, the default is "-n".
> +
> +(gdb) ovs_dump_packets packets_
> +12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 
> is-at a6:0f:c3:f0:5f:bd (oui Unknown), length 28
> +"""
> +def __init__(self):
> +super().__init__("ovs_dump_packets", gdb.COMMAND_DATA)
> +
> +def invoke(self, arg, from_tty):
> +if Ether is None:
> +print("ERROR: This command requires scapy to be installed.")
> +
> +arg_list = gdb.string_to_argv(arg)
> +if len(arg_list) == 0:
> +print("Usage: ovs_dump_packets  +  "struct dp_packet> [tcpdump options]")
> +return
> +
> +symb_name = arg_list[0]
> +tcpdump_args = arg_list[1:]
> +
> +if not tcpdump_args:
> +# Add a sane default
> +tcpdump_args = ["-n"]
> +
> +val = gdb.parse_and_eval(symb_name)
> +while val.type.code == gdb.TYPE_CODE_PTR:
> +val = val.dereference()
> +
> +pkt_list = []
> +if str(val.type).startswith("struct dp_packet_batch"):
> +for idx in range(val['count']):
> +pkt_struct = val['packets'][idx].dereference()
> +pkt = self.extract_pkt(pkt_struct)
> +if pkt is None:
> +continue
> +pkt_list.append(pkt)
> +elif str(val.type) == "struct dp_packet":
> +pkt = self.extract_pkt(val)
> +if pkt is None:
> +return
> +pkt_list.append(pkt)
> +else:
> +print("Error, unsupported argument type: 
> {}".format(str(val.type)))

Guess you format to fix the general ERROR format, i.e.:

print(“ERROR: Unsupported argument 

[ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-11-19 Thread Mike Pattrick
This commit adds a basic packet metadata macro to the already existing
macros in ovs_gdb.py, ovs_dump_packets will print out information about
one or more packets. It feeds packets into tcpdump, and the user can
pass in tcpdump options to modify how packets are parsed or even write
out packets to a pcap file.

Example usage:
(gdb) break fast_path_processing
(gdb) commands
 ovs_dump_packets packets_
 continue
 end
(gdb) continue

Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 10.1.1.1 
tell 10.1.1.2, length 28
Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
a6:0f:c3:f0:5f:bd (oui Unknown), length 28

Signed-off-by: Mike Pattrick 
---
 utilities/gdb/ovs_gdb.py | 114 ++-
 1 file changed, 112 insertions(+), 2 deletions(-)

diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
index 0b2ecb81b..9da83920b 100644
--- a/utilities/gdb/ovs_gdb.py
+++ b/utilities/gdb/ovs_gdb.py
@@ -29,6 +29,7 @@
 #- ovs_dump_netdev
 #- ovs_dump_netdev_provider
 #- ovs_dump_ovs_list  {[] [] {dump}]}
+#- ovs_dump_packets  [tcpdump 
options]
 #- ovs_dump_simap 
 #- ovs_dump_smap 
 #- ovs_dump_udpif_keys {|} {short}
@@ -56,8 +57,15 @@
 #...
 #
 import gdb
+import struct
 import sys
 import uuid
+try:
+from scapy.layers.l2 import Ether
+from scapy.utils import tcpdump
+except ModuleNotFoundError:
+Ether = None
+tcpdump = None
 
 
 #
@@ -138,7 +146,7 @@ def get_time_msec():
 
 def get_time_now():
 # See get_time_msec() above
-return int(get_global_variable("coverage_run_time"))/1000, -5
+return int(get_global_variable("coverage_run_time")) / 1000, -5
 
 
 def eth_addr_to_string(eth_addr):
@@ -156,7 +164,7 @@ def eth_addr_to_string(eth_addr):
 #
 class ProgressIndicator(object):
 def __init__(self, message=None):
-self.spinner = "/-\|"
+self.spinner = "/-\\|"
 self.spinner_index = 0
 self.message = message
 
@@ -1306,6 +1314,107 @@ class CmdDumpOfpacts(gdb.Command):
 print("(struct ofpact *) {}: {}".format(node, node.dereference()))
 
 
+#
+# Implements the GDB "ovs_dump_packets" command
+#
+class CmdDumpPackets(gdb.Command):
+"""Dump metadata about dp_packets
+Usage: ovs_dump_packets  [tcpdump 
options]
+
+This command can take either a dp_packet_batch struct and print out
+metadata about all packets in this batch, or a single dp_packet struct and
+print out metadata about a single packet.
+
+Everything after the struct reference is passed into tcpdump. If nothing
+is passed in as a tcpdump option, the default is "-n".
+
+(gdb) ovs_dump_packets packets_
+12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-at 
a6:0f:c3:f0:5f:bd (oui Unknown), length 28
+"""
+def __init__(self):
+super().__init__("ovs_dump_packets", gdb.COMMAND_DATA)
+
+def invoke(self, arg, from_tty):
+if Ether is None:
+print("ERROR: This command requires scapy to be installed.")
+
+arg_list = gdb.string_to_argv(arg)
+if len(arg_list) == 0:
+print("Usage: ovs_dump_packets  [tcpdump options]")
+return
+
+symb_name = arg_list[0]
+tcpdump_args = arg_list[1:]
+
+if not tcpdump_args:
+# Add a sane default
+tcpdump_args = ["-n"]
+
+val = gdb.parse_and_eval(symb_name)
+while val.type.code == gdb.TYPE_CODE_PTR:
+val = val.dereference()
+
+pkt_list = []
+if str(val.type).startswith("struct dp_packet_batch"):
+for idx in range(val['count']):
+pkt_struct = val['packets'][idx].dereference()
+pkt = self.extract_pkt(pkt_struct)
+if pkt is None:
+continue
+pkt_list.append(pkt)
+elif str(val.type) == "struct dp_packet":
+pkt = self.extract_pkt(val)
+if pkt is None:
+return
+pkt_list.append(pkt)
+else:
+print("Error, unsupported argument type: {}".format(str(val.type)))
+return
+
+tcpdump(pkt_list, args=tcpdump_args)
+
+def extract_pkt(self, pkt):
+pkt_fields = pkt.type.keys()
+if pkt['packet_type'] != 0:
+return
+if pkt['l3_ofs'] == 0x:
+return
+
+if "mbuf" in pkt_fields:
+if pkt['mbuf']['data_off'] == 0x:
+return
+eth_ptr = pkt['mbuf']['buf_addr']
+eth_off = int(pkt['mbuf']['data_off'])
+eth_len = int(pkt['mbuf']['pkt_len'])
+else:
+if pkt['data_ofs'] == 0x:
+return
+eth_ptr = pkt['base_']
+eth_off = int(pkt['data_ofs'])
+eth_len = 

Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-11-19 Thread Eelco Chaudron
Hi Mike,

I tried to apply this patch, but for some reason, it’s messed up, guess some 
longer lines are truncated?

Patchwork also does not understand it.

Maybe you can check and send a v5?

Cheers,

Eelco


On 12 Nov 2021, at 18:38, Mike Pattrick wrote:

> This commit adds a basic packet metadata macro to the already existing
> macros in ovs_gdb.py, ovs_dump_packets will print out information about
> one or more packets. It feeds packets into tcpdump, and the user can
> pass in tcpdump options to modify how packets are parsed or even write
> out packets to a pcap file.
>
> Example usage:
> (gdb) break fast_path_processing
> (gdb) commands
>> ovs_dump_packets packets_
>> continue
>> end
> (gdb) continue
>
> Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
> 12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has
> 10.1.1.1 tell 10.1.1.2, length 28
> Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
> 12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-
> at a6:0f:c3:f0:5f:bd (oui Unknown), length 28
>
> Signed-off-by: Mike Pattrick 
> ---
>  utilities/gdb/ovs_gdb.py | 114 ++-
>  1 file changed, 112 insertions(+), 2 deletions(-)
>
> diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
> index 0b2ecb81b..9da83920b 100644
> --- a/utilities/gdb/ovs_gdb.py
> +++ b/utilities/gdb/ovs_gdb.py
> @@ -29,6 +29,7 @@
>  #- ovs_dump_netdev
>  #- ovs_dump_netdev_provider
>  #- ovs_dump_ovs_list  {[] []
> {dump}]}
> +#- ovs_dump_packets 
> [tcpdump options]
>  #- ovs_dump_simap 
>  #- ovs_dump_smap 
>  #- ovs_dump_udpif_keys {|} {short}
> @@ -56,8 +57,15 @@
>  #...
>  #
>  import gdb
> +import struct
>  import sys
>  import uuid
> +try:
> +from scapy.layers.l2 import Ether
> +from scapy.utils import tcpdump
> +except ModuleNotFoundError:
> +Ether = None
> +tcpdump = None
>
>
>  #
> @@ -138,7 +146,7 @@ def get_time_msec():
>
>  def get_time_now():
>  # See get_time_msec() above
> -return int(get_global_variable("coverage_run_time"))/1000, -5
> +return int(get_global_variable("coverage_run_time")) / 1000, -5
>
>
>  def eth_addr_to_string(eth_addr):
> @@ -156,7 +164,7 @@ def eth_addr_to_string(eth_addr):
>  #
>  class ProgressIndicator(object):
>  def __init__(self, message=None):
> -self.spinner = "/-\|"
> +self.spinner = "/-\\|"
>  self.spinner_index = 0
>  self.message = message
>
> @@ -1306,6 +1314,107 @@ class CmdDumpOfpacts(gdb.Command):
>  print("(struct ofpact *) {}: {}".format(node,
> node.dereference()))
>
>
> +#
> +# Implements the GDB "ovs_dump_packets" command
> +#
> +class CmdDumpPackets(gdb.Command):
> +"""Dump metadata about dp_packets
> +Usage: ovs_dump_packets 
> [tcpdump options]
> +
> +This command can take either a dp_packet_batch struct and print
> out
> +metadata about all packets in this batch, or a single dp_packet
> struct and
> +print out metadata about a single packet.
> +
> +Everything after the struct reference is passed into tcpdump. If
> nothing
> +is passed in as a tcpdump option, the default is "-n".
> +
> +(gdb) ovs_dump_packets packets_
> +12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply
> 10.1.1.1 is-at a6:0f:c3:f0:5f:bd (oui Unknown), length 28
> +"""
> +def __init__(self):
> +super().__init__("ovs_dump_packets", gdb.COMMAND_DATA)
> +
> +def invoke(self, arg, from_tty):
> +if Ether is None:
> +print("ERROR: This command requires scapy to be
> installed.")
> +
> +arg_list = gdb.string_to_argv(arg)
> +if len(arg_list) == 0:
> +print("Usage: ovs_dump_packets  +  "struct dp_packet> [tcpdump options]")
> +return
> +
> +symb_name = arg_list[0]
> +tcpdump_args = arg_list[1:]
> +
> +if not tcpdump_args:
> +# Add a sane default
> +tcpdump_args = ["-n"]
> +
> +val = gdb.parse_and_eval(symb_name)
> +while val.type.code == gdb.TYPE_CODE_PTR:
> +val = val.dereference()
> +
> +pkt_list = []
> +if str(val.type).startswith("struct dp_packet_batch"):
> +for idx in range(val['count']):
> +pkt_struct = val['packets'][idx].dereference()
> +pkt = self.extract_pkt(pkt_struct)
> +if pkt is None:
> +continue
> +pkt_list.append(pkt)
> +elif str(val.type) == "struct dp_packet":
> +pkt = self.extract_pkt(val)
> +if pkt is None:
> +return
> +pkt_list.append(pkt)
> +else:
> +print("Error, unsupported argument type:
> {}".format(str(val.type)))
> +return
> +
> +tcpdump(pkt_list, args=tcpdump_args)
> +
> +def extract_pkt(self, pkt):
> +pkt_fields = pkt.type.keys()

Re: [ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-11-12 Thread 0-day Robot
Bleep bloop.  Greetings Mike Pattrick, I am a robot and I have tried out your 
patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


git-am:
error: patch fragment without header at line 7: @@ -56,8 +57,15 @@
error: could not build fake ancestor
hint: Use 'git am --show-current-patch' to see the failed patch
Patch failed at 0001 utilities: Add another GDB macro for ovs-vswitchd
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".


Patch skipped due to previous failure.

Please check this out.  If you feel there has been an error, please email 
acon...@redhat.com

Thanks,
0-day Robot
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH v4] utilities: Add another GDB macro for ovs-vswitchd

2021-11-12 Thread Mike Pattrick
This commit adds a basic packet metadata macro to the already existing
macros in ovs_gdb.py, ovs_dump_packets will print out information about
one or more packets. It feeds packets into tcpdump, and the user can
pass in tcpdump options to modify how packets are parsed or even write
out packets to a pcap file.

Example usage:
(gdb) break fast_path_processing
(gdb) commands
>ovs_dump_packets packets_
>continue
>end
(gdb) continue

Thread 1 "ovs-vswitchd" hit Breakpoint 2, fast_path_processing ...
12:01:05.962485 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has
10.1.1.1 tell 10.1.1.2, length 28
Thread 1 "ovs-vswitchd" hit Breakpoint 1, fast_path_processing ...
12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.1.1.1 is-
at a6:0f:c3:f0:5f:bd (oui Unknown), length 28

Signed-off-by: Mike Pattrick 
---
 utilities/gdb/ovs_gdb.py | 114 ++-
 1 file changed, 112 insertions(+), 2 deletions(-)

diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
index 0b2ecb81b..9da83920b 100644
--- a/utilities/gdb/ovs_gdb.py
+++ b/utilities/gdb/ovs_gdb.py
@@ -29,6 +29,7 @@
 #- ovs_dump_netdev
 #- ovs_dump_netdev_provider
 #- ovs_dump_ovs_list  {[] []
{dump}]}
+#- ovs_dump_packets 
[tcpdump options]
 #- ovs_dump_simap 
 #- ovs_dump_smap 
 #- ovs_dump_udpif_keys {|} {short}
@@ -56,8 +57,15 @@
 #...
 #
 import gdb
+import struct
 import sys
 import uuid
+try:
+from scapy.layers.l2 import Ether
+from scapy.utils import tcpdump
+except ModuleNotFoundError:
+Ether = None
+tcpdump = None
 
 
 #
@@ -138,7 +146,7 @@ def get_time_msec():
 
 def get_time_now():
 # See get_time_msec() above
-return int(get_global_variable("coverage_run_time"))/1000, -5
+return int(get_global_variable("coverage_run_time")) / 1000, -5
 
 
 def eth_addr_to_string(eth_addr):
@@ -156,7 +164,7 @@ def eth_addr_to_string(eth_addr):
 #
 class ProgressIndicator(object):
 def __init__(self, message=None):
-self.spinner = "/-\|"
+self.spinner = "/-\\|"
 self.spinner_index = 0
 self.message = message
 
@@ -1306,6 +1314,107 @@ class CmdDumpOfpacts(gdb.Command):
 print("(struct ofpact *) {}: {}".format(node,
node.dereference()))
 
 
+#
+# Implements the GDB "ovs_dump_packets" command
+#
+class CmdDumpPackets(gdb.Command):
+"""Dump metadata about dp_packets
+Usage: ovs_dump_packets 
[tcpdump options]
+
+This command can take either a dp_packet_batch struct and print
out
+metadata about all packets in this batch, or a single dp_packet
struct and
+print out metadata about a single packet.
+
+Everything after the struct reference is passed into tcpdump. If
nothing
+is passed in as a tcpdump option, the default is "-n".
+
+(gdb) ovs_dump_packets packets_
+12:01:05.981214 ARP, Ethernet (len 6), IPv4 (len 4), Reply
10.1.1.1 is-at a6:0f:c3:f0:5f:bd (oui Unknown), length 28
+"""
+def __init__(self):
+super().__init__("ovs_dump_packets", gdb.COMMAND_DATA)
+
+def invoke(self, arg, from_tty):
+if Ether is None:
+print("ERROR: This command requires scapy to be
installed.")
+
+arg_list = gdb.string_to_argv(arg)
+if len(arg_list) == 0:
+print("Usage: ovs_dump_packets  [tcpdump options]")
+return
+
+symb_name = arg_list[0]
+tcpdump_args = arg_list[1:]
+
+if not tcpdump_args:
+# Add a sane default
+tcpdump_args = ["-n"]
+
+val = gdb.parse_and_eval(symb_name)
+while val.type.code == gdb.TYPE_CODE_PTR:
+val = val.dereference()
+
+pkt_list = []
+if str(val.type).startswith("struct dp_packet_batch"):
+for idx in range(val['count']):
+pkt_struct = val['packets'][idx].dereference()
+pkt = self.extract_pkt(pkt_struct)
+if pkt is None:
+continue
+pkt_list.append(pkt)
+elif str(val.type) == "struct dp_packet":
+pkt = self.extract_pkt(val)
+if pkt is None:
+return
+pkt_list.append(pkt)
+else:
+print("Error, unsupported argument type:
{}".format(str(val.type)))
+return
+
+tcpdump(pkt_list, args=tcpdump_args)
+
+def extract_pkt(self, pkt):
+pkt_fields = pkt.type.keys()
+if pkt['packet_type'] != 0:
+return
+if pkt['l3_ofs'] == 0x:
+return
+
+if "mbuf" in pkt_fields:
+if pkt['mbuf']['data_off'] == 0x:
+return
+eth_ptr = pkt['mbuf']['buf_addr']
+eth_off = int(pkt['mbuf']['data_off'])
+eth_len = int(pkt['mbuf']['pkt_len'])
+else:
+if pkt['data_ofs'] == 0x:
+return
+eth_ptr = pkt['base_']
+eth_off = int(pkt['data_ofs'])
+eth_len =