99"""
1010Geneve: Generic Network Virtualization Encapsulation
1111
12- draft- ietf-nvo3-geneve-16
12+ https://datatracker. ietf.org/doc/html/rfc8926
1313"""
1414
1515import struct
1919from scapy .layers .inet import IP , UDP
2020from scapy .layers .inet6 import IPv6
2121from scapy .layers .l2 import Ether , ETHER_TYPES
22- from scapy .compat import chb , orb
2322
2423CLASS_IDS = {0x0100 : "Linux" ,
2524 0x0101 : "Open vSwitch" ,
@@ -42,12 +41,12 @@ class GeneveOptions(Packet):
4241 XByteField ("type" , 0x00 ),
4342 BitField ("reserved" , 0 , 3 ),
4443 BitField ("length" , None , 5 ),
45- StrLenField ('data' , '' , length_from = lambda x :x .length * 4 )]
44+ StrLenField ('data' , '' , length_from = lambda x : x .length * 4 )]
4645
4746 def post_build (self , p , pay ):
4847 if self .length is None :
4948 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 :]
5150 return p + pay
5251
5352
@@ -61,12 +60,13 @@ class GENEVE(Packet):
6160 XShortEnumField ("proto" , 0x0000 , ETHER_TYPES ),
6261 X3BytesField ("vni" , 0 ),
6362 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 )]
6565
6666 def post_build (self , p , pay ):
6767 if self .optionlen is None :
6868 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 :]
7070 return p + pay
7171
7272 def answers (self , other ):
0 commit comments