Configuring a Filter Action Statement
In a firewall filter term, you can specify the action to take if the packet matches the conditions you have configured in the term. To configure a filter action, include the
thenstatement:then {action;action-modifiers;}For IPv4 traffic, configure the filter action at the
[edit firewall family inet filterfilter-nametermterm-name]hierarchy level. For IPv6 traffic, configure the filter action at the[edit firewall family inet6 filterfilter-nametermterm-name]hierarchy level. For MPLS traffic, configure the filter terms at the[edit firewall family mpls filterfilter-nametermterm-name]hierarchy level.You can specify zero or one
thenstatement in a filter term. If you omit thethenstatement or do not specify an action, the packets that match the conditions in thefromstatement are accepted.
NOTE: We strongly recommend that you always explicitly configure an action in the
thenstatement.
You can specify one of the following filter actions:
accept—The packet is accepted and is sent to its destination.discard—The packet is not accepted and is not processed further.next term—Evaluate the next term in the firewall filter.reject—The packet is not accepted and a rejection message is returned. Rejected packets can be logged or sampled.routing-instance—The packet is accepted and routed by the specified routing instance. For more information, see Configuring Filter-Based Forwarding.In the filter action statement, you can also specify one or more of the following action modifiers:
count—Add packet to a count total.forwarding-class—Specify the packet forwarding class name.log—The packet's header information is stored on the Routing Engine or sent to a server.
NOTE: The firewall filter stops logging discard and reject actions at a high traffic rate.
loss-priority—Set the packet loss priority (PLP) tolow,medium, orhigh.
NOTE: You must configure tricolor marking policer to set PLP to
medium.
policer—Apply rate-limiting procedures to the traffic. For more information, see Policer Configuration.sample—Sample the packet traffic. Apply this option only if you have enabled traffic sampling. For more information, see Traffic Sampling and Forwarding Configuration.syslog—Log an alert for the packet.ipsec-sasa-name—Specify an IP Security (IPSec) security association (SA) for the packet. This is used with thesource-addressanddestination-addressmatch conditions.You can include zero or one action statement, but any combination of action modifiers. For the action or action modifier to take effect, all conditions in the
fromstatement must match. If you specifylogas one of the actions in a term, this constitutes a termination action; whether any additional terms in the filter are processed depends on the traffic through the filter.The action modifier operations carry a default accept action. For example, if you specify an action modifier and do not specify an action, the specified action modifier is implemented and the packet is accepted.
Policing uses a specific type of action, known as a policer action. For more information, see Policer Configuration.
For more information about forwarding classes and loss priority, see the JUNOS Class of Service Configuration Guide.
Table 26 shows the complete list of filter actions and action modifiers.
Set the IPv4 or the IPv6 Differentiated Services code point (DSCP) bit to 0.
Discard a packet silently, without sending an Internet Control Message Protocol (ICMP) message. Discarded packets are available for logging and sampling.
Classify packet to one of the following forwarding classes:
as,assured-forwarding,best-effort, expedited-forwarding, ornetwork-control.Use the specified logical router. This action is supported for both IPv4 and IPv6 firewall filters.
Indicate that the upper or lower bound of a policer has been met and starvation of queues is possible. The packets are marked as out of the profile of the policer. This action is supported on the J-series Services Router only as part of strict priority queuing. Out-of-profile packets are queued only if the port is not congested.
Discard a packet, sending an ICMPv4 or an ICMP v6 destination unreachable message. Rejected packets can be logged or sampled if you configure either of those action modifiers. You can specify one of the following message codes:
administratively-prohibited(default),bad-host-tos,bad-network-tos,host-prohibited,host-unknown,host-unreachable,network-prohibited,network-unknown,network-unreachable,port-unreachable,precedence-cutoff,precedence-violation,protocol-unreachable,source-host-isolated,source-route-failed, ortcp-reset. If you specifytcp-reset, a Transmission Control Protocol (TCP) reset is returned if the packet is a TCP packet. Otherwise, nothing is returned.The number of the packets passing this filter/term/policer. The name can contain letters, numbers, and hyphens (-), and can be up to 24 characters long. A counter name is specific to the filter that uses it, so all interfaces that use the same filter increment the same counter.
An IPSec SA for the packet. Used with the
source-addressanddestination-addressmatch conditions.Log the packet's header information in the Routing Engine. You can access this information by issuing the
show logcommand at the command-line interface (CLI).Sample the traffic on the interface. Use this modifier only when traffic sampling is enabled. For more information, see Traffic Sampling and Forwarding Configuration.
Log an alert for this packet. The log can be sent to a server for storage and analysis.
Apply rate limits to the traffic using the tricolor marking policer.
Example: Configure a Filter Action Statement
Count, sample, and accept the traffic:
term all {then {count sam-1;sample; # default action is accept}}user@host>show firewall filter samFilter:Counters:Name Bytes Packetssamsam-1 98 8028Display the firewall log output:
user@host>show firewall logTime Filter A Interface Pro Source address Destination address23:09:09 - A at-2/0/0.301 TCP 10.2.0.25 10.211.211.1:8023:09:07 - A at-2/0/0.301 TCP 10.2.0.25 10.211.211.1:5623:09:07 - A at-2/0/0.301 ICM 10.2.0.25 10.211.211.1:4955223:02:27 - A at-2/0/0.301 TCP 10.2.0.25 10.211.211.1:5623:02:25 - A at-2/0/0.301 TCP 10.2.0.25 10.211.211.1:8023:01:22 - A at-2/0/0.301 ICM 10.2.2.101 10.211.211.1:2325123:01:21 - A at-2/0/0.301 ICM 10.2.2.101 10.211.211.1:1655723:01:20 - A at-2/0/0.301 ICM 10.2.2.101 10.211.211.1:2947123:01:19 - A at-2/0/0.301 ICM 10.2.2.101 10.211.211.1:26873This output file contains the following fields:
Time—Time at which the packet was received (not shown in the default).Filter—Name of a filter that has been configured with thefilterstatement at the[edit firewall]hierarchy level. A hyphen (-) or the abbreviationpfeindicates that it was handled by the Packet Forwarding Engine. A space (no hyphen) indicates that the packet was handled by the Routing Engine.A—Filter action:
Interface—Interface on which the filter is configured.
NOTE: We strongly recommend that you always explicitly configure an action in the
thenstatement.
Pro—Packet's protocol name or number.Source address—Source IP address in the packet.Destination address—Destination IP address in the packet.Display the sampling output:
user@host>show log /var/tmp/sam# Apr 7 15:48:50Time Dest Src Dest Src Proto TOS Pkt Intf IP TCPaddr addr port port len num frag flagsApr 7 15:48:54 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0Apr 7 15:48:55 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0Apr 7 15:48:56 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0For more information about sampling output, see Configuring a Forwarding Table Filter.
Example: Set the DSCP bit to 0
Set the DSCP bit to 0 using a firewall filter:
firewall {filter filter1 {term 1 {from {dscp 2;}then {dscp 0;forwarding-class best-effort;}}term 2 {from {dscp 3;}then {forwarding-class best-effort;}}}Apply this filter to the logical interface corresponding to the VRF:
interfaces so-0/1/0 {unit 0 {family inet {filter input filter1;}}}