Sub topic 8
Filtering: when the frame is not forwarded at all
Prerequisites and scope
This chapter assumes you know the following:
- An Ethernet frame carries a destination MAC, a source MAC, and an EtherType.
- A switch keeps a MAC address table that maps addresses to ports.
- The switch learns from the source address and looks up the destination address.
Here the focus is on one outcome of the forwarding decision. The switch can forward a frame to one port, flood it to many ports, or filter it. Filtering means the switch receives the frame and then sends it nowhere.
What filtering means
A switch filters a frame when the destination MAC address is known and the table says that address lives behind the same port the frame arrived on. That port is the ingress port. The switch drops the frame instead of sending it back out.
This is correct behavior. The destination already received the frame. Both stations sit on the same network segment, so they hear each other directly. Sending the frame back out the ingress port would only waste bandwidth and could confuse the sender.
The switch applies one rule for every unicast frame:
- Learn the source address on the ingress port.
- Look up the destination address.
- If the entry is missing, flood.
- If the entry points to a different port, forward to that port only.
- If the entry points to the ingress port, filter.
Filtering is not an error and it is not a drop caused by congestion. It is a deliberate decision that the frame has no work left to do.
When can two stations share one port?
A single host on an access port never triggers filtering. If the destination were the sender itself, you would not normally see traffic like that. Filtering appears when more than one MAC address is learned on the same port. Three common cases:
- A hub or an unmanaged downstream device. Several hosts connect to a hub, and the hub connects to one switch port. The hosts reach each other through the hub, and the switch sees both MAC addresses on that single port.
- A downstream switch. Hosts connected to a second switch all appear behind the uplink port of the first switch. Traffic between two of those hosts is already handled by the second switch. If a copy reaches the first switch, it is filtered. Chapter content on multiple switches covers this in more detail.
- A virtualization host or bridge. A server runs virtual machines behind a software bridge. Several MAC addresses appear on the server's one switch port.
The diagram shows the third case in a simple form. Host A and Host B are behind the same hub, so the hub repeats the frame to both and to the switch. The switch knows B is on port 1 and filters the frame.
Filtering in the code
The learning switch from the earlier chapters implements filtering in its final lines:
import time
AGING_SECONDS = 300
def is_group(mac):
# The least significant bit of the first octet marks multicast/broadcast.
return int(mac.split(':')[0], 16) & 1 == 1
class LearningSwitch:
def __init__(self, ports, aging=AGING_SECONDS):
self.ports = set(ports)
self.aging = aging
self.table = {} # mac -> (port, last_seen)
def handle(self, in_port, src, dst, now=None):
"""Return the list of ports the frame is sent out of."""
now = time.monotonic() if now is None else now
# 1. Learn or refresh the source address (this also handles host moves).
if not is_group(src):
self.table[src] = (in_port, now)
# 2. Look up the destination.
entry = None if is_group(dst) else self.table.get(dst)
if entry is not None and now - entry[1] > self.aging:
del self.table[dst] # expired entry
entry = None
if entry is None:
# Unknown unicast, broadcast or multicast: flood.
return sorted(self.ports - {in_port})
out_port = entry[0]
# Destination is behind the ingress port: filter the frame.
return [] if out_port == in_port else [out_port]Look at the last line. The method returns a list of output ports. For forwarding the list has one port. For flooding it has every port except the ingress. For filtering it is empty. An empty list is the whole implementation of filtering.
Now run a scenario in which two hosts, A and B, share port 1 and a third host, C, is on port 2.
sw = LearningSwitch(ports=[1, 2, 3])
A = '00:00:00:00:00:0a'
B = '00:00:00:00:00:0b'
C = '00:00:00:00:00:0c'
print(sw.handle(1, A, B, now=0)) # B unknown: flood -> [2, 3]
print(sw.handle(1, B, A, now=1)) # A is on port 1, same as ingress -> []
print(sw.handle(1, A, B, now=2)) # B is on port 1, same as ingress -> []
print(sw.handle(2, C, A, now=3)) # A is on port 1 -> [1]The first frame floods because B is not yet known. After B sends a frame from port 1, both A and B are known on port 1. From then on, traffic between them is filtered, and only the traffic to C or from C crosses the switch.
Notice the order of operations in the second call. The switch learns B on port 1 first, then looks up A. A points to port 1, which equals the ingress port, so the result is an empty list.
Filtering versus flooding versus forwarding
The three outcomes depend on the table lookup and the frame type.
| Destination | Table result | Outcome |
|---|---|---|
| Unicast, known | Different port | Forward to that port |
| Unicast, known | Same as ingress port | Filter |
| Unicast, unknown | No entry | Flood to all other ports |
| Broadcast | Not looked up | Flood to all other ports |
| Multicast | Not looked up | Flood to all other ports (without snooping) |
Broadcast and multicast frames are never filtered by this rule. They have no table entry because group addresses are never learned, since they cannot appear as a source. A broadcast always goes to every other port.
Filtering also does not mean the frame disappears for everyone. The hosts on the shared segment still receive it. Only the other ports of the switch are spared.
Why filtering matters
Filtering keeps traffic local. If a downstream hub has twenty hosts and they talk mostly to each other, none of that traffic crosses into the rest of the switched network. Each port of a switch is its own collision domain, so filtering is what makes a switch more efficient than a repeater that copies every frame everywhere.
It also has a security and troubleshooting side effect. A packet capture on another port will not show traffic that the switch filtered. If you connect an analyzer to port 2 to watch A and B talk, you will see nothing once the switch has learned both on port 1. To watch such traffic you need a mirror (SPAN) port or a capture on the shared segment itself.
Filtering and stale or wrong entries
Filtering depends on the table being right. Two problems follow.
- A stale entry. Host B moves from port 1 to port 3, but the table still says port 1. A frame from A arriving on port 1 for B is filtered, and B never receives it. The entry heals when B sends any frame from port 3, because learning overwrites the old port. Aging removes it otherwise.
- A wrong entry from a loop. If a loop makes the same source address arrive on two ports, the entry changes back and forth. This is MAC flapping, and filtering and forwarding decisions flip with it.
In both cases the symptom is traffic that vanishes without any error message, because filtering is silent. Nothing counts as an error. Counters on the ports and the table itself are the main clues.
Checking it on a real device
You can confirm that two addresses share a port by reading the table. On a Cisco IOS-style switch:
Switch# show mac address-table
Mac Address Table
-------------------------------------------
Vlan Mac Address Type Ports
---- ----------- -------- -----
1 0011.2233.4455 DYNAMIC Gi0/1
1 0011.2233.4466 DYNAMIC Gi0/1
1 0011.2233.4477 DYNAMIC Gi0/2
Total Mac Addresses for this criterion: 3Two addresses appear on Gi0/1. Frames between them are filtered. On a Linux bridge, the same view comes from:
bridge fdb show br br0Each line lists a MAC address and the port (dev) where it was learned. Two lines with the same dev mean the bridge filters traffic between those addresses.
Summary of the rule
The forwarding decision compares two ports: the port in the table for the destination, and the port the frame came in on. If they differ, forward. If they match, filter. If the table has no answer, flood.
Exercise
A switch has learned host X and host Y on port 4, and host Z on port 7. Host X sends a unicast frame to Y, and a few seconds later host Z sends a unicast frame to X. What does the switch do with each frame, and why?
Show answer
The frame from X to Y is filtered. The destination Y is known and is behind port 4, which is the ingress port, so the switch sends it nowhere. The frame from Z to X is forwarded out port 4 only. X is known on port 4, which differs from the ingress port 7, so the switch forwards it to that single port.
Exercise
You connect a packet analyzer to switch port 2 to watch traffic between hosts A and B, which share port 1 through a hub. The switch has already learned both. Why do you see no frames from A to B, and what could you do?
Show answer
The switch filters the frames because the destination is behind the ingress port, so it never sends them to port 2. To see them, configure a mirror (SPAN) port that copies traffic from port 1, or capture on the shared segment between the hub and the hosts.