+ if num_ip_layers > 0:
+ ip_src_is_unset = "src" not in l3_to_use.fields
+ ip_dst_is_unset = "dst" not in l3_to_use.fields
+ else:
+ ip_src_is_unset = None
+ ip_dst_is_unset = None
- # The packet is routed from TG egress to TG ingress
- # update l3 addresses
- packet.payload.src = self._tg_ip_address_egress.ip.exploded
- packet.payload.dst = self._tg_ip_address_ingress.ip.exploded
- else:
- # The packet leaves TG towards SUT
# update l2 addresses
- packet.src = self._tg_port_egress.mac_address
- packet.dst = self._sut_port_ingress.mac_address
+ # If `expected` is :data:`True`, the packet enters the TG from
SUT, otherwise the
+ # packet leaves the TG towards the SUT
+ if pkt_src_is_unset:
+ packet.src = (
+ self._sut_port_egress.mac_address
+ if expected
+ else self._tg_port_egress.mac_address
+ )
+ if pkt_dst_is_unset:
+ packet.dst = (
+ self._tg_port_ingress.mac_address
+ if expected
+ else self._sut_port_ingress.mac_address
+ )
- # The packet is routed from TG egress to TG ingress
# update l3 addresses
- packet.payload.src = self._tg_ip_address_egress.ip.exploded
- packet.payload.dst = self._tg_ip_address_ingress.ip.exploded
+ # The packet is routed from TG egress to TG ingress regardless of
whether it is
+ # expected or not.
Is this true? This might've been an error in the original
implementation. If it's expected (that is, the returning packet), it
should be routed from TG ingress to TG egress, no?
I guess I'm not completely sure. It would make sense that the L3
addresses should be switched as well based on either expected or not,
but currently it isn't modified, and os_udp still works which makes me
think the addresses aren't switched by the kernel interfaces, which I
believe is the only time these addresses are actually used (since we
use sendp in scapy).
Right, I went too deep in my thinking and confused myself :-). The path
of the packet is:
TG egress -> SUT ingress -> SUT egress -> TG ingress
That is just one way path and I mixed the other direction into my
thinking as well. With just one path, the MAC addresses are going to
change, but not IP addresses.