9
9
"""
10
10
Geneve: Generic Network Virtualization Encapsulation
11
11
12
- draft- ietf-nvo3-geneve-16
12
+ https://datatracker. ietf.org/doc/html/rfc8926
13
13
"""
14
14
15
15
import struct
19
19
from scapy .layers .inet import IP , UDP
20
20
from scapy .layers .inet6 import IPv6
21
21
from scapy .layers .l2 import Ether , ETHER_TYPES
22
- from scapy .compat import chb , orb
23
22
24
23
CLASS_IDS = {0x0100 : "Linux" ,
25
24
0x0101 : "Open vSwitch" ,
@@ -42,12 +41,12 @@ class GeneveOptions(Packet):
42
41
XByteField ("type" , 0x00 ),
43
42
BitField ("reserved" , 0 , 3 ),
44
43
BitField ("length" , None , 5 ),
45
- StrLenField ('data' , '' , length_from = lambda x :x .length * 4 )]
44
+ StrLenField ('data' , '' , length_from = lambda x : x .length * 4 )]
46
45
47
46
def post_build (self , p , pay ):
48
47
if self .length is None :
49
48
tmp_len = len (self .data ) // 4
50
- p = p [:3 ] + struct .pack ("!B" , tmp_len ) + p [4 :]
49
+ p = p [:3 ] + struct .pack ("!B" , ( p [ 3 ] & 0x3 ) | ( tmp_len & 0x1f ) ) + p [4 :]
51
50
return p + pay
52
51
53
52
@@ -61,12 +60,13 @@ class GENEVE(Packet):
61
60
XShortEnumField ("proto" , 0x0000 , ETHER_TYPES ),
62
61
X3BytesField ("vni" , 0 ),
63
62
XByteField ("reserved2" , 0x00 ),
64
- PacketListField ("options" , [], GeneveOptions , length_from = lambda pkt :pkt .optionlen * 4 )]
63
+ PacketListField ("options" , [], GeneveOptions ,
64
+ length_from = lambda pkt : pkt .optionlen * 4 )]
65
65
66
66
def post_build (self , p , pay ):
67
67
if self .optionlen is None :
68
68
tmp_len = (len (p ) - 8 ) // 4
69
- p = chb ( tmp_len & 0x3f | orb (p [0 ]) & 0xc0 ) + p [1 :]
69
+ p = struct . pack ( "!B" , (p [0 ] & 0xc0 ) | ( tmp_len & 0x3f ) ) + p [1 :]
70
70
return p + pay
71
71
72
72
def answers (self , other ):
0 commit comments