TC-POLICE(8)

โœจ NAME โœจ

Okay bestie, this page is all about the police action, the Policing action in tc(8) ๐Ÿ’–. It's basically police - policing action ๐ŸŽ€

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

tc ... action police [ rate RATE burst BYTES[/BYTES] ] [ pkts_rate RATE
        pkts_burst PACKETS] [ mtu BYTES[/BYTES] ] [ peakrate RATE ] [
        overhead BYTES ] [ linklayer TYPE ] [ CONTROL ]

tc ... filter ... [ estimator SAMPLE AVERAGE ] action police avrate RATE
        [ CONTROL ]

CONTROL := conform-exceed EXCEEDACT[/NOTEXCEEDACT

EXCEEDACT/NOTEXCEEDACT := { pipe | ok | reclassify | drop | continue |
        goto chain CHAIN_INDEX }

๐ŸŒธ DESCRIPTION ๐ŸŒธ

Okay so the police action lets you cap how many bytes or packets per second get through the filter it's attached to. It's giving speed limit, but for your network ๐Ÿšฆโœจ

There are two ways to measure the byte rate, and honestly both are iconic. The first one uses an internal dual token bucket, and you set it up with the rate, burst, mtu, peakrate, overhead and linklayer parameters. The second one uses an in-kernel sampling mechanism, and you can fine-tune it with the estimator filter parameter ๐Ÿ’…

There's also one packet-rate algorithm, and it's basically a cousin of the first byte-rate one. You configure it with the pkt_rate and pkt_burst parameters ๐Ÿงš

Also, no cap: you have to set at least one of rate and pkt_rate ๐Ÿซถ

๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

  • rate RATE โ€” The max byte rate for packets passing this action. Anything over it gets treated however your conform-exceed option says ๐Ÿ’–
  • burst BYTES[/BYTES] โ€” Sets the max allowed burst in bytes. You can optionally add a slash (/) and a cell size, which has to be a power of 2 ๐Ÿ“
  • pkt_rate RATE โ€” The max packet rate for packets passing this action. Anything over it gets treated however your conform-exceed option says ๐ŸŒˆ
  • pkt_burst PACKETS โ€” Sets the max allowed burst in packets โœจ
  • mtu BYTES[/BYTES] โ€” The biggest packet size the policer will handle. Anything larger gets handled like it exceeded the configured rate ๐Ÿ˜ญ Setting this correctly helps the scheduler be more precise. The value formatting is the same as burst above. It defaults to unlimited ๐Ÿฆ‹
  • peakrate RATE โ€” Sets the max bucket depletion rate, which is the rate you're not allowed to go over ๐Ÿ”ฅ
  • avrate RATE โ€” Uses an in-kernel bandwidth rate estimator and matches the given RATE against it ๐ŸŽ€
  • overhead BYTES โ€” Accounts for the protocol overhead of encapsulating output devices when computing rate and peakrate ๐Ÿ’œ
  • linklayer TYPE โ€” Specifies the link layer type. TYPE can be ethernet (the default), atm or adsl, which are synonyms for each other. It's used to line up the precomputed rate tables with ATM cell sizes. For ethernet, nothing gets done ๐Ÿงš
  • estimator SAMPLE AVERAGE โ€” Fine-tunes the in-kernel packet rate estimator. SAMPLE and AVERAGE are time values. They control how often samples get taken and over what timespan the average gets built ๐Ÿซง
  • conform-exceed EXCEEDACT[/NOTEXCEEDACT] โ€” Decides what happens to packets that exceed or conform to the bandwidth limit. The possible values are:
    • continue โ€” Does nothing, just moves on to the next action in line ๐ŸŒธ
    • drop โ€” Drops the packet immediately ๐Ÿ’€
    • shot โ€” A synonym for drop ๐Ÿ™ˆ
    • ok โ€” Accepts the packet. This is the default for conforming packets ๐Ÿ’…
    • pass โ€” A synonym for ok ๐Ÿซถ
    • reclassify โ€” Treats the packet as not matching the filter this action is attached to, then continues with the next filter in line (if there is one). This is the default for exceeding packets ๐ŸŒˆ
    • pipe โ€” Passes the packet to the next action in line โœจ

๐Ÿ“ EXAMPLES ๐Ÿ“

A super typical use of the police action is enforcing your ingress traffic rate by dropping the packets that go over. Ideally you'd do this on the sender's side, especially when you don't have control over the peer (like with dial-up providers). But honestly, when latencies need to stay low under heavy load, this is often the best you can do ๐Ÿ˜ญ The following sets input bandwidth policing to 1mbit/s using the ingress qdisc and a u32 filter:

# tc qdisc add dev eth0 handle ffff: ingress
# tc filter add dev eth0 parent ffff: u32 \
     match u32 0 0 \
     police rate 1mbit burst 100k

Here's the tea: an action can't live on its own. There always has to be a filter involved as the link between the qdisc and the action. The example above uses u32 for that, and it's set up to match basically any packet, which sends it into the police action ๐Ÿงš๐Ÿ’–

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

tc(8) ๐Ÿฆ‹


Okay that's the whole tea, bestie ๐Ÿ’œ This page came from iproute2, dated 20 Jan 2015, and the manual name is Policing action in tc(8). Go forth and police responsibly ๐Ÿซถโœจ

๐Ÿ“ฆ where this page comes from