@@ -36,16 +36,19 @@ def __init__(self):
3636 self ._manipulate_cb = None
3737 self ._manipulate_filter = NO_FILTER
3838 self ._manipulate_dup = False
39+ self ._manipulate_inject_raw = False
3940
4041 async def _read_message_queue (self ):
4142 while True :
4243 packet , dev_entry = await self ._message_queue .get ()
4344 await self ._process_packet (packet , dev_entry )
4445
4546 async def _process_packet (self , packet , src_device_entry ):
46- """
47- If `src_device_entry` is None, we're not performing manipulation.
48- """
47+ # In case `src_device_entry` is None, then the packet was queued by the manipulator.
48+ # Therefore, we'll use self._manipulate_inject_raw. Otherwise, set to False
49+ # since the Switch should deal with tagging.
50+ should_inject_raw = self ._manipulate_inject_raw if src_device_entry is None else False
51+
4952 if src_device_entry is not None and self ._manipulate_cb is not None :
5053 # We'll manipulate if there's no filter or if there's
5154 # filter and the packet matches the filter
@@ -67,13 +70,10 @@ async def _process_packet(self, packet, src_device_entry):
6770 if src_vlan is None :
6871 return None
6972
70- # Looking for the destination device
7173 for dst_device in self ._devices :
7274 if dst_device .dev .get_mac == Ether (packet ).dst and dst_device .vlan == src_vlan :
7375
74- # TODO: currently we're taggint packets. Maybe the Device
75- # should state whether we should tag or inject raw.
76- if dst_device .port_type == PortType .TRUNK :
76+ if dst_device .port_type == PortType .TRUNK and not should_inject_raw :
7777 packet = add_vlan_tag (packet , dst_device .vlan )
7878
7979 packet = fix_checksums (packet )
@@ -155,17 +155,22 @@ def _remove_device_entry(self, dev_to_remove):
155155
156156 self ._event_loop .call_soon_threadsafe (_remove_device_entry , self , dev_to_remove )
157157
158- def set_manipulation (self , cb , bpf_filter , duplicate ):
158+ def set_manipulation (self , cb , bpf_filter , duplicate , inject_raw ):
159159 ''' Assumes cb is in valid form '''
160- def __set_manipulation (cb , bpf_filter , duplicate ):
160+ def __set_manipulation (cb , bpf_filter , duplicate , inject_raw ):
161161 self ._manipulate_cb = cb
162162 self ._manipulate_filter = bpf_filter
163163 self ._manipulate_dup = duplicate
164+ self ._manipulate_inject_raw = inject_raw
164165
165166 # set_manipulation is called from the main thread.
166167 # Since we're affecting the event loop thread, we should call_soon_threadsafe,
167168 # so the call will be synchronized.
168- self ._event_loop .call_soon_threadsafe (__set_manipulation , cb , bpf_filter , duplicate )
169+ self ._event_loop .call_soon_threadsafe (__set_manipulation ,
170+ cb ,
171+ bpf_filter ,
172+ duplicate ,
173+ inject_raw )
169174
170175 def manipulator_queue_packet (self , packet ):
171176 self ._message_queue .put_nowait ((packet , None ))
0 commit comments