Routing Policy and Firewall Filters · Topic 2 of 4

Routing Policy Structure, Match Criteria and Actions

Learn Junos policy-statement terms, from and then, route filter match types such as exact, orlonger and upto, prefix lists and policy actions for JN0-106.

  • 6 min
In a nutshell
  • Policy: policy-statement > term > from (conditions) > then (actions).
  • Terms run in order; no from means match all.
  • Different conditions are AND; multiple values of one condition are OR.

What it is

A Junos routing policy is a policy-statement made of one or more terms. Each term has a from section with match conditions and a then section with actions. A route that meets all the conditions in from gets the actions in then.

Match types tell a route filter how a route's prefix must relate to the prefix you configured: exactly the same, longer, or within a range of lengths.

RouteTerm 1from conditionsmatchTerm 1then actionsTerm 1from conditionsno matchTerm 2Next policyor default

How it works

Policy structure

policy-options {
    policy-statement BGP-IN {
        term REJECT-PRIVATE {
            from {
                route-filter 10.0.0.0/8 orlonger;
                route-filter 172.16.0.0/12 orlonger;
                route-filter 192.168.0.0/16 orlonger;
            }
            then reject;
        }
        term SET-LP {
            from {
                protocol bgp;
                neighbor 192.0.2.1;
            }
            then {
                local-preference 200;
                accept;
            }
        }
    }
}

Rules for terms:

  • Terms are evaluated in the order they appear. Use insert in configuration mode to move one, for example insert policy-options policy-statement BGP-IN term SET-LP before term REJECT-PRIVATE.
  • A term with no from matches every route.
  • A term with no terminating action lets a matching route carry on to the next term, keeping any changes already made.

Match conditions

ConditionMatches
protocolSource of the route: static, direct, ospf, bgp, aggregate and others
route-filterThe prefix and its length, with a match type
prefix-listA named list of prefixes, matched exactly
prefix-list-filterA named prefix list with a match type such as orlonger
neighborThe neighbor that sent the route
interfaceThe interface the route was learned on
areaThe OSPF area
as-pathA BGP AS path regular expression
communityA BGP community
tag, metricRoute tag or metric values

Logic inside from: different conditions are combined with AND. Several values of the same condition, such as two route filters, are combined with OR. In the example above, term SET-LP needs protocol bgp AND neighbor 192.0.2.1.

There is also a to section, used less often, that matches on where the route is going, such as the neighbor it is advertised to.

Route filter match types

All examples use route-filter 192.168.0.0/16 with the given match type.

Match typeMatchesExample that matches
exactOnly 192.168.0.0/16192.168.0.0/16
orlongerThe /16 and any more specific prefix inside it192.168.0.0/16, 192.168.5.0/24
longerOnly more specific prefixes, not the /16 itself192.168.5.0/24
upto /24Prefix lengths /16 to /24 inside it192.168.5.0/24, but not a /25
prefix-length-range /20-/24Prefix lengths /20 to /24 inside it192.168.16.0/20, but not the /16
through 192.168.16.0/20Routes on the direct path from the /16 to that prefix192.168.0.0/16, 192.168.16.0/20
Route filter192.168.0.0/16exactOnly the /16Route filter192.168.0.0/16orlongerThe /16 and more specificRoute filter192.168.0.0/16longerMore specific only

How route filters are evaluated

When a term has several route filters, Junos OS first finds the route filter whose prefix is the longest match for the route, then checks that filter's match type. If the match type fails, the term does not match, even if a shorter route filter in the same term would have matched.

Example: a term has route-filter 10.0.0.0/8 orlonger and route-filter 10.1.0.0/16 exact. The route 10.1.1.0/24 has 10.1.0.0/16 as its longest matching filter. That filter needs an exact /16, so the term does not match the route, although the /8 orlonger filter alone would have matched it.

A route filter can also carry its own action, which applies only when that filter matches:

user@router# set policy-options policy-statement BGP-IN term T1 from route-filter 10.0.0.0/8 orlonger reject

Prefix lists

A prefix list is a reusable named set of prefixes, defined under [edit policy-options prefix-list]. Used with from prefix-list, each entry matches only exactly. Use prefix-list-filter NAME orlonger (or exact, longer) when you need a match type.

user@router# set policy-options prefix-list CUSTOMERS 203.0.113.0/24
user@router# set policy-options policy-statement OUT term 1 from prefix-list CUSTOMERS
user@router# set policy-options policy-statement OUT term 1 then accept

Actions

KindActionsEffect
Terminatingaccept, rejectFinal decision; evaluation stops
Flow controlnext term, next policySkip to the next term or the next policy
Modifyinglocal-preference, metric, preference, community add, community set, community delete, next-hop, tag, as-path-prependChange route attributes; evaluation carries on unless a terminating action follows
Exam tip

A term that only modifies attributes, with no accept or reject, changes the route and passes it on. If nothing later accepts or rejects it, the protocol default policy decides.

Common mistakes

Assuming longer includes the configured prefix. longer excludes it; orlonger includes it.

Expecting a shorter route filter to rescue a route. Only the longest matching route filter in the term is checked.

Using prefix-list for a range of lengths. A prefix list matches exactly. Use prefix-list-filter or a route filter for ranges.

Watch out

A final term with no from and then accept accepts everything left. Put it last, or every term after it is useless.

What to remember for the exam

  • Policy: policy-statement > term > from (conditions) > then (actions).
  • Terms run in order; no from means match all.
  • Different conditions are AND; multiple values of one condition are OR.
  • Match types: exact, orlonger, longer, upto, prefix-length-range, through.
  • The longest matching route filter is chosen first, then its match type is checked.
  • prefix-list matches exactly; prefix-list-filter adds a match type.
  • Terminating: accept, reject. Flow control: next term, next policy.

Check yourself

  • Does route-filter 172.16.0.0/16 longer match the route 172.16.0.0/16?

    No. longer matches only prefixes more specific than /16; use orlonger to include the /16 itself.

  • A term has from protocol static and from route-filter 10.0.0.0/8 orlonger. Which routes match?

    Only static routes inside 10.0.0.0/8, because different conditions are combined with AND.

  • What happens to a route matched by a term whose only action is metric 10?

    Its metric is set to 10 and evaluation continues with the next term or policy.

Topic 2 of 4 in Routing Policy and Firewall Filters

Test yourself on Routing Policy and Firewall Filters

The full Juniper JNCIA-Junos JN0-106 question bank has 1,155 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.