Skip to content

Added geneve header options#3329

Merged
guedou merged 1 commit intosecdev:masterfrom
HareshKhandelwal:geneve_options
Mar 1, 2022
Merged

Added geneve header options#3329
guedou merged 1 commit intosecdev:masterfrom
HareshKhandelwal:geneve_options

Conversation

@HareshKhandelwal
Copy link
Copy Markdown
Contributor

@HareshKhandelwal HareshKhandelwal commented Aug 10, 2021

currently, we dont have geneve options working.
This patch aims to fix them.

Unit test cases:

With Options:

sendp(Ether(dst='0c:42:a1:d1:da:98',src='40:a6:b7:0b:e9:b1')/Dot1Q(vlan=304,type='IPv4')/IP(proto=17,src='172.17.2.161',dst='172.17.2.32')/UDP(sport=57025,dport=6081)/GENEVE(proto=0x6558,vni=4,options=GeneveOptions(classid=0x0102,type=0x80,data=b'\x00\x01\x00\x02'))/Ether(dst='fa:16:3e:81:fa:0f',src='fa:16:3e:e7:a9:8a',type=0x0800)/IP(proto=1,dst='192.168.2.181',src='192.168.2.92')/ICMP(type=8),iface="wlp0s20f3")


16:19:54.952429 40:a6:b7:0b:e9:b1 > 0c:42:a1:d1:da:98, ethertype 802.1Q (0x8100), length 104: vlan 304, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 86)
    172.17.2.161.57025 > 172.17.2.32.6081: [udp sum ok] Geneve, Flags [none], vni 0x4, proto TEB (0x6558), options [class Open Virtual Networking (OVN) (0x102) type 0x80(C) len 8 data 00010002]
	fa:16:3e:e7:a9:8a > fa:16:3e:81:fa:0f, ethertype IPv4 (0x0800), length 42: (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto ICMP (1), length 28)
    192.168.2.92 > 192.168.2.181: ICMP echo request, id 0, seq 0, length 8

Without options:

sendp(Ether(dst='0c:42:a1:d1:da:98',src='40:a6:b7:0b:e9:b1')/Dot1Q(vlan=304,type='IPv4')/IP(proto=17,src='172.17.2.161',dst='172.17.2.32')/UDP(sport=57025,dport=6081)/GENEVE(proto=0x6558,vni=4)/Ether(dst='fa:16:3e:81:fa:0f',src='fa:16:3e:e7:a9:8a',type=0x0800)/IP(proto=1,dst='192.168.2.181',src='192.168.2.92')/ICMP(type=8),iface="wlp0s20f3")

16:21:08.305638 40:a6:b7:0b:e9:b1 > 0c:42:a1:d1:da:98, ethertype 802.1Q (0x8100), length 96: vlan 304, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 78)
    172.17.2.161.57025 > 172.17.2.32.6081: [udp sum ok] Geneve, Flags [none], vni 0x4, proto TEB (0x6558)
	fa:16:3e:e7:a9:8a > fa:16:3e:81:fa:0f, ethertype IPv4 (0x0800), length 42: (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto ICMP (1), length 28)
    192.168.2.92 > 192.168.2.181: ICMP echo request, id 0, seq 0, length 8

>>> packet = GeneveOptions(classid=0x0102,type=0x80,data=b'\x00\x01\x00\x02')
>>> packet.show()
###[ Geneve Options ]### 
  classid   = Open Virtual Networking (OVN)
  type      = 0x80
  reserved  = 0
  length    = None
  data      = '\x00\x01\x00\x02'

>>> packet.show2()
###[ Geneve Options ]### 
  classid   = Open Virtual Networking (OVN)
  type      = 0x80
  reserved  = 0
  length    = 1
  data      = '\x00\x01\x00\x02'

>>> 

>>> packet = GENEVE(proto=0x6558,vni=4,options=GeneveOptions(classid=0x0102,type=0x80,data=b'\x00\x04\x00\x05'))
>>> packet.show()
###[ GENEVE ]### 
  version   = 0
  optionlen = None
  oam       = 0
  critical  = 0
  reserved  = 0
  proto     = TEB
  vni       = 0x4
  reserved2 = 0x0
  \options   \
   |###[ Geneve Options ]### 
   |  classid   = Open Virtual Networking (OVN)
   |  type      = 0x80
   |  reserved  = 0
   |  length    = None
   |  data      = '\x00\x04\x00\x05'

>>> packet.show2()
###[ GENEVE ]### 
  version   = 0
  optionlen = 2
  oam       = 0
  critical  = 0
  reserved  = 0
  proto     = TEB
  vni       = 0x4
  reserved2 = 0x0
  \options   \
   |###[ Geneve Options ]### 
   |  classid   = Open Virtual Networking (OVN)
   |  type      = 0x80
   |  reserved  = 0
   |  length    = 1
   |  data      = '\x00\x04\x00\x05'

>>> 

Checklist:

  • If you are new to Scapy: I have checked CONTRIBUTING.md (esp. section submitting-pull-requests)
  • I squashed commits belonging together
  • I added unit tests or explained why they are not relevant
  • I executed the regression tests for Python2 and Python3 (using tox or, cd test && ./run_tests_py2, cd test && ./run_tests_py3)
  • If the PR is still not finished, please create a Draft Pull Request

fixes #xxx

@HareshKhandelwal
Copy link
Copy Markdown
Contributor Author

Hi @guedou , Mistakenly pull request#3287 got closed. Raised this new one.
Addressed your comments on re add author name, named options variable as you suggested. Provided unit test cases.
Please have a review.

Thanks

Copy link
Copy Markdown
Member

@guedou guedou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

Would you mind adding some simple unit tests such as https://github.com/secdev/scapy/blob/master/test/contrib/geneve.uts#L8 ?

Copy link
Copy Markdown

@Yarboa Yarboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HareshKhandelwal
Copy link
Copy Markdown
Contributor Author

Hi @guedou

I am writing the unit test cases and got stuck at one place. Can you please provide your opinion where i am going wrong!

Unit test case is

s = Ether(dst='0c:42:a1:d1:da:98',src='40:a6:b7:0b:e9:b1')/Dot1Q(vlan=304,type='IPv4')/IP(proto=17,src='172.17.2.161',dst='172.17.2.32')/UDP(sport=57025,dport=6081)/GENEVE()/Ether(dst='fa:16:3e:81:fa:0f',src='fa:16:3e:e7:a9:8a',type=0x0800)/IP(proto=1,dst='192.168.2.181',src='192.168.2.92')/ICMP(type=8)

While i am able to send proper packet with above packet construct, s.show2() doesnt show any other Encap post Geneve.

s.show2()
###[ Ethernet ]###
dst = 0c:42:a1:d1:da:98
src = 40:a6:b7:0b:e9:b1
type = n_802_1Q
###[ 802.1Q ]###
prio = 0
id = 0
vlan = 304
type = IPv4
###[ IP ]###
version = 4
ihl = 5
tos = 0x0
len = 78
id = 1
flags =
frag = 0
ttl = 64
proto = udp
chksum = 0x1dbb
src = 172.17.2.161
dst = 172.17.2.32
\options
###[ UDP ]###
sport = 57025
dport = geneve
len = 58
chksum = 0x298a
###[ GENEVE ]###
version = 0
optionlen = 0
oam = 0
critical = 0
reserved = 0
proto = TEB
vni = 0x0
reserved2 = 0x0
\options
|###[ Geneve Options ]###
| classid = 0xfa16
| type = 0x3e
| reserved = 4
| length = 1
| data = '\xfa\x0f\xfa\x16>穊\x08\x00E\x00\x00\x1c\x00\x01\x00\x00@\x01\xf4~\xc0\xa8\x02\\xc0\xa8\x02\xb5\x08\x00\xf7\xff\x00\x00\x00\x00'

This makes existing unit test case fail (Which check further encap of Ether). I have checked packet length but didn't find any issue, may be missing anything. Can you please help to identify the issue?

Thanks

@guedou
Copy link
Copy Markdown
Member

guedou commented Jan 26, 2022

It seens that GeneveOptions is consuming all the remaining data. You likely need to define extract_padding as done in

class EDNS0TLV(Packet):

@HareshKhandelwal
Copy link
Copy Markdown
Contributor Author

Hi @guedou

I did rework on clean up and updated unit cases as well. All unit cases passing now.

Thanks
-Haresh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgotten debug print

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad..removed now

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 3, 2022

Codecov Report

Merging #3329 (237fde2) into master (6508907) will increase coverage by 86.30%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           master    #3329       +/-   ##
===========================================
+ Coverage        0   86.30%   +86.30%     
===========================================
  Files           0      282      +282     
  Lines           0    64044    +64044     
===========================================
+ Hits            0    55275    +55275     
- Misses          0     8769     +8769     
Impacted Files Coverage Δ
scapy/contrib/geneve.py 97.29% <100.00%> (ø)
scapy/contrib/automotive/ecu.py 94.13% <0.00%> (ø)
scapy/contrib/automotive/obd/iid/__init__.py 100.00% <0.00%> (ø)
scapy/layers/tls/crypto/suites.py 100.00% <0.00%> (ø)
scapy/contrib/ldp.py 86.06% <0.00%> (ø)
scapy/layers/mobileip.py 100.00% <0.00%> (ø)
scapy/layers/tls/automaton_srv.py 60.90% <0.00%> (ø)
scapy/contrib/igmp.py 100.00% <0.00%> (ø)
scapy/layers/zigbee.py 79.85% <0.00%> (ø)
scapy/contrib/automotive/ccp.py 97.05% <0.00%> (ø)
... and 273 more

currently, we dont have geneve options working.
This patch aims to fix them.
@HareshKhandelwal
Copy link
Copy Markdown
Contributor Author

@gpotter2 @guedou can you please help with your reviews? Thanks

@polydroi
Copy link
Copy Markdown

LGTM

@guedou guedou merged commit 2d4091d into secdev:master Mar 1, 2022
@HareshKhandelwal HareshKhandelwal deleted the geneve_options branch March 1, 2022 10:28
@gpotter2 gpotter2 added this to the 2.5.0 milestone Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants