Packet Flow in RouterOS
Packet Flow in RouterOS
Section titled “Packet Flow in RouterOS”Understanding packet flow is essential for configuring advanced firewall setups, traffic prioritization, and routing policies in MikroTik RouterOS. This document explains how packets are processed through the router, covering routed packets, bridged packets, firewall chains, and hardware offloading.
Overview
Section titled “Overview”RouterOS packet processing involves multiple facilities that packets traverse in a specific order. Understanding this flow helps when configuring firewall rules, NAT, traffic shaping, and other network features. The packet flow diagram is divided into three main parts: the overall diagram, detailed bridging/routing/MPLS flow, and the chain processing diagram showing which facilities are applied at each stage.
When a packet arrives at the router, it goes through several decision points: first determining if it’s destined for the router itself (local delivery), needs to be routed to another network (forward), or needs to be bridged (same broadcast domain). Each of these paths involves different processing chains and firewall rules.
Firewall Chains
Section titled “Firewall Chains”RouterOS uses five default chains that allow filtering packets at various points in the processing pipeline:
| Chain | Table | Purpose |
|---|---|---|
| PREROUTING | raw, mangle, nat | Applies to packets as they arrive on the interface |
| INPUT | mangle, filter | Applies to packets just before delivery to local processes |
| OUTPUT | raw, mangle, nat, filter | Applies to packets generated by the router |
| FORWARD | mangle, filter | Applies to packets routed through the router |
| POSTROUTING | mangle, nat | Applies to packets as they leave the interface |
Chain Processing Order
Section titled “Chain Processing Order”The complete processing order for a routed packet follows this sequence:
- Packet arrives at physical in-interface
- Goes through logical in-interface (for tunneled packets)
- Prerouting processing (RAW → Connection Tracking → Mangle → DNAT)
- Routing decision (determines if packet is local or forwarded)
- Input or Forward processing depending on destination
- Postrouting processing (Mangle → SNAT → Queues)
- Exits through physical out-interface
Viewing Current Chain Processing
Section titled “Viewing Current Chain Processing”You can verify packet flow using the packet flow diagram in RouterOS:
/packet-flow printFlow of Routed Packet
Section titled “Flow of Routed Packet”Forward Path
Section titled “Forward Path”The forward path processes packets that are being routed through the router to another network. This is the most common scenario for firewall rule configuration.
The packet goes through these stages:
- Prerouting: Hotspot check → RAW prerouting → Connection tracking → Mangle prerouting → DNAT
- Routing Decision: Router looks up destination in routing table
- Forward: TTL check → Mangle forward → Filter forward → Accounting
- Postrouting: Mangle postrouting → SNAT → Hotspot undo → Queue tree → Simple queues
- IPsec: Policy check and processing
Forward Path Firewall Configuration
Section titled “Forward Path Firewall Configuration”/ip firewall filteradd chain=forward action=accept connection-state=established,related comment="Allow established connections"add chain=forward action=drop connection-state=invalid comment="Drop invalid connections"add chain=forward action=accept in-interface=LAN out-interface=WAN comment="Allow LAN to WAN"Input Path
Section titled “Input Path”The input path processes packets destined for the router itself, such as management access, DHCP requests, or services running on the router.
Processing stages:
- Prerouting: Hotspot check → RAW prerouting → Connection tracking → Mangle prerouting → DNAT
- Routing Decision: Router determines packet is local
- Input: Mangle input → Filter input → Queue tree → Simple queues
- IPsec: Policy check and processing
Input Path Firewall Configuration
Section titled “Input Path Firewall Configuration”/ip firewall filteradd chain=input action=accept connection-state=established,related comment="Allow established"add chain=input action=accept protocol=icmp comment="Allow ICMP"add chain=input action=accept in-interface=LAN comment="Allow LAN access"add chain=input action=drop comment="Drop all other input"Output Path
Section titled “Output Path”The output path handles packets originated by the router itself, such as ping responses, routing updates, or traffic generated by router services.
Processing stages:
- Local Process: Router generates the packet
- Routing Decision: Route lookup for the packet
- Output: Bridge decision → Connection tracking → Mangle output → Filter output → Routing adjustment
- Postrouting: Mangle postrouting → SNAT → Hotspot undo → Queue tree → Simple queues
- IPsec: Policy check and processing
Flow of Bridged Packet
Section titled “Flow of Bridged Packet”Bridging connects devices on the same network without routing. Packets forwarded through a bridge follow a different processing path than routed packets.
Bridge Forward
Section titled “Bridge Forward”Bridge forward occurs when a packet enters one bridge port and exits through another:
- Bridge NAT dst-nat (MAC destination, priority can be changed)
- Check use-ip-firewall option
- Bridge host table lookup (flood if unknown destination)
- Bridge filter forward chain
- Check use-ip-firewall option
- Bridge NAT src-nat (MAC source, priority can be changed)
- Check use-ip-firewall option
Basic Bridge Configuration
Section titled “Basic Bridge Configuration”/interface bridgeadd name=bridge1/interface bridge portadd bridge=bridge1 interface=ether1add bridge=bridge1 interface=ether2Bridge Input
Section titled “Bridge Input”Bridge input processes packets destined for the bridge interface itself (to reach services on the bridge):
- Bridge NAT dst-nat
- Check use-ip-firewall option
- Bridge host table lookup (MAC matching bridge address goes to input)
- Bridge filter input chain
Bridge Output
Section titled “Bridge Output”Bridge output handles packets exiting through bridge ports:
- Bridge host table lookup
- Bridge filter output chain
- Bridge NAT src-nat
- Check use-ip-firewall option
Forward With IP Firewall Enabled
Section titled “Forward With IP Firewall Enabled”When use-ip-firewall=yes is enabled on the bridge, bridged packets also go through routing chains:
/interface bridge set bridge1 use-ip-firewall=yesThis enables IP-level filtering on bridged traffic but increases CPU usage.
Enabling use-ip-firewall on bridges significantly increases CPU load since packets must go through both bridge and routing processing.
Flow of Hardware Offloaded Packet
Section titled “Flow of Hardware Offloaded Packet”Most MikroTik devices have dedicated switching hardware (switch chip) that can handle bridging without CPU involvement. This is called Bridge Hardware Offloading.
Switch Forward
Section titled “Switch Forward”When hardware offloading is enabled and packets move between switch ports:
- Switch checks if in-interface is hardware offloaded
- Switch host table lookup (forward to destination port or flood)
- Packets never reach the CPU
Enable Hardware Offloading
Section titled “Enable Hardware Offloading”/interface bridgeadd name=bridge1 hw=yes/interface bridge portadd bridge=bridge1 interface=ether1 hw=yesadd bridge=bridge1 interface=ether2 hw=yesSwitch to CPU
Section titled “Switch to CPU”When hardware-offloaded packets need CPU processing:
- Switch checks hardware offloading status
- Switch host table lookup
- Packet forwarded to switch-cpu port for software processing
This occurs when:
- Destination MAC matches the bridge interface (local delivery)
- Packet is flooded (broadcast, multicast, unknown unicast)
- Special processing required (DHCP, IGMP snooping)
Hardware Offloading Requirements
Section titled “Hardware Offloading Requirements”Hardware offloading requires:
- No bridge firewall, filter, or NAT rules
use-ip-firewalldisabled- No mesh or metarouter interfaces
- Bridge VLAN filtering and DHCP snooping disabled (RouterOS 7.1 and earlier)
Viewing Offload Status
Section titled “Viewing Offload Status”/interface bridge port printLook for the hw column showing yes for hardware-offloaded ports.
FastPath and FastTrack
Section titled “FastPath and FastTrack”FastPath and FastTrack are performance optimization features that bypass normal packet processing.
FastPath
Section titled “FastPath”FastPath skips most CPU processing by handling packets directly in the network driver. It’s automatic when conditions are met:
/interface print stats-detailFastPath is active when:
- No firewall rules configured
- No simple queues or queue trees with parent=global
- No connection tracking needed
- No IPsec policies
- No VRF configuration
FastTrack
Section titled “FastTrack”FastTrack combines FastPath with connection tracking. It marks connections for accelerated processing:
/ip firewall filteradd chain=forward action=fasttrack-connection connection-state=established,relatedadd chain=forward action=accept connection-state=established,relatedFastTrack packets bypass firewall, connection tracking, queues, and IPsec. Ensure you understand the security implications before enabling.
FastTrack requirements:
- Only TCP and UDP connections
- Must use main routing table
- No VRF configuration
- No active packet sniffing
Practical Examples
Section titled “Practical Examples”Example 1: Basic Firewall for Routed Traffic
Section titled “Example 1: Basic Firewall for Routed Traffic”This configuration secures a simple router with LAN behind it:
/ip firewall filter# Input chain - protect the routeradd chain=input action=accept connection-state=established,relatedadd chain=input action=accept protocol=icmpadd chain=input action=accept in-interface=LANadd chain=input action=drop
# Forward chain - protect LAN devicesadd chain=forward action=accept connection-state=established,relatedadd chain=forward action=accept connection-state=related in-interface=LAN out-interface=WANadd chain=forward action=drop connection-state=invalidadd chain=forward action=drop in-interface=WAN out-interface=LANExample 2: Bridge with VLAN Filtering
Section titled “Example 2: Bridge with VLAN Filtering”/interface bridgeadd name=bridge1 vlan-filtering=yes
/interface bridge vlanadd bridge=bridge1 tagged=bridge1 vlan-ids=10,20
/interface bridge portadd bridge=bridge1 interface=ether1 vlan-mode=secureadd bridge=bridge1 interface=ether2 vlan-mode=secureadd bridge=bridge1 interface=ether3 vlan-mode=secureExample 3: Performance Tuning with FastTrack
Section titled “Example 3: Performance Tuning with FastTrack”For high-performance networks, use FastTrack for established connections:
/ip firewall filteradd chain=forward action=fasttrack-connection connection-state=established,relatedadd chain=forward action=accept connection-state=established,relatedadd chain=forward action=accept connection-state=related in-interface=LANadd chain=forward action=drop connection-state=invalidTroubleshooting Packet Flow
Section titled “Troubleshooting Packet Flow”Check Which Chain a Packet Traverses
Section titled “Check Which Chain a Packet Traverses”Use packet flow monitoring:
/tool packet-flow printView Connection Tracking Entries
Section titled “View Connection Tracking Entries”/ip firewall connection printMonitor FastPath Statistics
Section titled “Monitor FastPath Statistics”/interface print stats-detailLook for packets passing through FastPath vs slow path in the statistics.
Debug with Firewall Logs
Section titled “Debug with Firewall Logs”/ip firewall filteradd chain=forward action=log log-prefix="forward-drop: " connection-state=invalid
/log printRelated Topics
Section titled “Related Topics”- Firewall - Firewall filter, NAT, and raw rules
- Bridging and Switching - Bridge configuration and VLAN filtering
- Queues - Traffic shaping and QoS
- IPsec - VPN tunnel processing