Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_basic(self):
""" basic reassembly """
payload_len = 1000
payload = ""
counter = 0
while len(payload) < payload_len:
payload += "%u " % counter
counter += 1
p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) /
IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6) /
UDP(sport=1234, dport=5678) /
Raw(payload))
fragments = fragment_rfc8200(p, 1, payload_len/4)
# send fragment #2 - should be cached inside reassembly
self.pg_enable_capture()
self.src_if.add_stream(fragments[1])
self.pg_start()
self.logger.debug(self.vapi.ppcli("show ip6-sv-reassembly details"))
self.logger.debug(self.vapi.ppcli("show buffers"))
self.logger.debug(self.vapi.ppcli("show trace"))
self.dst_if.assert_nothing_captured()
# send fragment #1 - reassembly is finished now and both fragments
# forwarded
self.pg_enable_capture()
self.src_if.add_stream(fragments[0])
self.pg_start()
self.pkts = []
if packets is None:
packets = random.randint(1, self.max_number_of_packets)
pkt_size = size
for p in range(0, packets):
if size is None:
pkt_size = random.choice(self.pg_if_packet_sizes)
info = self.create_packet_info(src_if, dst_if)
payload = self.info_to_payload(info)
p = Ether(src=src_if.remote_mac, dst=src_if.local_mac)
if ip_ver == 'v4':
p /= IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4)
else:
p /= IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6)
p /= UDP(sport=1234, dport=4321)
p /= Raw(payload)
info.data = p.copy()
self.extend_packet(p, pkt_size)
self.pkts.append(p)
table_id=10,
paths=[VppMRoutePath(self.pg1.sw_if_index,
MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
route_eg_232_1_1_2.add_vpp_config()
route_eg_232_1_1_2.update_rpf_id(8193)
#
# inject a packet in VRF-0. We expect it to be BIER encapped,
# replicated, then hit the disposition and be forwarded
# out of VRF 10, i.e. on pg1
#
p = (Ether(dst=self.pg0.local_mac,
src=self.pg0.remote_mac) /
IP(src="1.1.1.1", dst="232.1.1.1") /
UDP(sport=1234, dport=1234) /
Raw(scapy.compat.chb(5) * 32))
rx = self.send_and_expect(self.pg0, p*NUM_PKTS, self.pg1)
self.assertEqual(rx[0][IP].src, "1.1.1.1")
self.assertEqual(rx[0][IP].dst, "232.1.1.1")
p = (Ether(dst=self.pg0.local_mac,
src=self.pg0.remote_mac) /
IP(src="1.1.1.1", dst="232.1.1.2") /
UDP(sport=1234, dport=1234) /
Raw(scapy.compat.chb(5) * 512))
rx = self.send_and_expect(self.pg0, p*NUM_PKTS, self.pg1)
self.assertEqual(rx[0][IP].src, "1.1.1.1")
self.assertEqual(rx[0][IP].dst, "232.1.1.2")
def m2i(self, pkt, m):
"""
Try to parse one of the TLS subprotocols (ccs, alert, handshake or
application_data). This is used inside a loop managed by .getfield().
"""
cls = Raw
if pkt.type == 22:
if len(m) >= 1:
msgtype = orb(m[0])
if ((pkt.tls_session.advertised_tls_version == 0x0304) or
(pkt.tls_session.tls_version and
pkt.tls_session.tls_version == 0x0304)):
cls = _tls13_handshake_cls.get(msgtype, Raw)
else:
cls = _tls_handshake_cls.get(msgtype, Raw)
elif pkt.type == 20:
cls = TLSChangeCipherSpec
elif pkt.type == 21:
cls = TLSAlert
elif pkt.type == 23:
cls = TLSApplicationData
# Util
def _tls_version_check(version, min):
"""Returns if version >= min, or False if version == None"""
if version is None:
return False
return version >= min
###############################################################################
# TLS Record Protocol #
###############################################################################
class _TLSEncryptedContent(Raw):
"""
When the content of a TLS record (more precisely, a TLSCiphertext) could
not be deciphered, we use this class to represent the encrypted data.
The MAC will still be parsed from the whole message, even though it could
not been verified. When present (depending on cipher type and protocol
version), the nonce_explicit, IV and/or padding will also be parsed.
"""
name = "Encrypted Content"
class _TLSMsgListField(PacketListField):
"""
This is the actual content of the TLS record. As a TLS record may pack
multiple sublayer messages (notably, several handshake messages),
we inherit from PacketListField.
"""
addr1=dest,
addr2=self.mac,
addr3=self.mac,
FCfield="+".join(['wep'] + additionnal_flag),
SC=(next(self.seq_num) << 4),
subtype=0,
type="Data",
)
# Assume packet is send by our AP -> use self.mac as source
# Encapsule in TKIP with MIC Michael and ICV
data_to_enc = build_MIC_ICV(raw(data), mic_key, self.mac, dest)
# Header TKIP + payload
rep /= Raw(build_TKIP_payload(data_to_enc, iv, self.mac, encrypt_key))
self.send(rep)
return rep
def __kb_send(kb, x, channel = None, inter = 0, loop = 0, count = None, verbose = None, realtime = None, *args, **kargs):
if type(x) is str:
x = Raw(load=x)
if not isinstance(x, Gen):
x = SetGen(x)
if verbose is None:
verbose = conf.verb
n = 0
if count is not None:
loop = -count
elif not loop:
loop=-1
dt0 = None
try:
while loop:
for p in x:
if realtime:
ct = time.time()
:param ip_src: the source IP address of the IP header
:param ip_dst the destination IP address of the IP header
:param mac_src: the source MAC address of the MAC header
:param ttl: the ttl value of the packet
:param mac_dst: the destination MAC address of the MAC header
:param port_src: the source port of the UDP header
:param port_dst: the destination port of the UDP header
:param payload: the payload of the packet
:return: the corresponding UDP packet
"""
ether = Ether(src=mac_src, dst=mac_dst)
ip = IP(src=ip_src, dst=ip_dst, ttl=ttl)
udp = UDP(sport=port_src, dport=port_dst)
packet = ether / ip / udp / Raw(load=payload)
return packet
def build(self, *args, **kargs):
fval = self.getfieldval("exchkeys")
if fval is None:
s = self.tls_session
if s.prcs:
cls = s.prcs.key_exchange.client_kx_msg_cls
cls = cls(tls_session=s)
else:
cls = Raw()
self.exchkeys = cls
return _TLSHandshake.build(self, *args, **kargs)
def m2i(self, pkt, m):
"""
Try to parse one of the TLS subprotocols (ccs, alert, handshake or
application_data). This is used inside a loop managed by .getfield().
"""
cls = Raw
if pkt.type == 22:
if len(m) >= 1:
msgtype = orb(m[0])
if ((pkt.tls_session.advertised_tls_version == 0x0304) or
(pkt.tls_session.tls_version and
pkt.tls_session.tls_version == 0x0304)):
cls = _tls13_handshake_cls.get(msgtype, Raw)
else:
cls = _tls_handshake_cls.get(msgtype, Raw)
elif pkt.type == 20:
cls = TLSChangeCipherSpec
elif pkt.type == 21:
cls = TLSAlert
elif pkt.type == 23:
cls = TLSApplicationData
if cls is Raw:
return Raw(m)
else:
try:
return cls(m, tls_session=pkt.tls_session)
except Exception:
if conf.debug_dissector:
raise