Skip to content
 

simulating network delay in Linux

At work we are having a problem with OpenWRT, where daemons like wifidog and dnsmasq can’t get information about the wan network interface when they’re started if the wan uses DHCP and it takes too long to get a lease. I was having trouble reproducing the issue, so I decided to force some extra delay with netem. Here are the commands I used to add massive delay to all DHCP traffic going to my DHCP server, which is running on eth3:

tc qdisc add dev eth3 root handle 1: prio
tc qdisc add dev eth3 parent 1:3 handle 30: netem delay 5000ms

# Only the first rule should really be necessary, since we are delaying the outgoing
# traffic from 67 (bootps) to 68 (bootpc).
tc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \
   match ip sport 67 0xfff flowid 1:3
tc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \
   match ip dport 67 0xfff flowid 1:3
tc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \
   match ip sport 68 0xfff flowid 1:3
tc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \
   match ip dport 68 0xfff flowid 1:3

# Also delay pings so we can more easily see it working
tc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \
   match ip protocol 1 0xff flowid 1:3

See also: another blog posttc filters documentation (lartc), tc manual (pdf)

Leave a Reply