I’m trying to mark VoIP packets by the method in the Mangle manual page: first marking new connections, then marking packets by the connection mark. I’m doing this separately for SIP packets (port 5060) and RTP packets (ports 16384–32767). The purpose is to put them in queues by the packet marks.
Here are my rules (the IP address is the VoIP server):
/ip firewall mangle
add action=mark-connection chain=forward comment="VoIP control (SIP)" connection-state=new dst-address=111.222.333.444 \
dst-port=5060 new-connection-mark=voip-control out-interface=ether1-gateway protocol=udp
add action=mark-packet chain=forward comment="VoIP control (SIP)" connection-mark=voip-control new-packet-mark=\
voip-control passthrough=no
add action=mark-connection chain=forward comment="VoIP bearer (RTP)" connection-state=new dst-address=111.222.333.444 \
dst-port=16384-32767 new-connection-mark=voip-rtp out-interface=ether1-gateway protocol=udp
add action=mark-packet chain=forward comment="VoIP bearer (RTP)" connection-mark=voip-rtp new-packet-mark=voip-rtp \
passthrough=no
But all that seems to happen is an occasional connection mark for SIP, and then everything else getting packet marked as if it was in that marked connection:
/ip firewall mangle print stats
Flags: X - disabled, I - invalid, D - dynamic
# CHAIN ACTION BYTES PACKETS
0 ;;; VoIP control (SIP)
forward mark-connection 777 1
1 ;;; VoIP control (SIP)
forward mark-packet 2 321 859 11 511
2 ;;; VoIP bearer (RTP)
forward mark-connection 0 0
3 ;;; VoIP bearer (RTP)
forward mark-packet 0 0
And indeed, even the connections to the high port numbers are marked “voip-control” (SIP). See the connections during a phone call across the router (with a few connections from my PC removed):
/ip firewall connection print detail
Flags: S - seen-reply, A - assured
0 SA protocol=udp src-address=66.185.167.133:27857 dst-address=66.185.162.87:2239 reply-src-address=192.168.35.14:2239
reply-dst-address=66.185.167.133:27857 timeout=2m27s connection-mark="voip-control" p2p=none
1 protocol=udp src-address=66.185.167.133:5060 dst-address=66.185.162.87:5060 reply-src-address=66.185.162.87:5060
reply-dst-address=66.185.167.133:5060 connection-type="sip" timeout=48m57s p2p=none
3 SA protocol=udp src-address=66.185.167.133:27856 dst-address=66.185.162.87:2238 reply-src-address=192.168.35.14:2238
reply-dst-address=66.185.167.133:27856 timeout=2m28s connection-mark="voip-control" p2p=none
7 SA protocol=udp src-address=192.168.35.14:5060 dst-address=66.185.167.133:5060 reply-src-address=66.185.167.133:5060
reply-dst-address=66.185.162.87:1024 connection-type="sip" timeout=59m20s connection-mark="voip-control" p2p=none
Well, some of the RTP connections are marked “voip-control.” Some of them are completely unmarked. But nothing is ever marked “voip-rtp.” Why not? All I can think is that the RTP connections are related to the SIP connections, and somehow RouterOS is marking the former automatically, before it hits mangle.