Juniper Junos OS is full of useful tricks. Here is one of them…

Apply-path is a really cool feature in Junos OS. With the apply-path statement you can expand a prefix list to include all prefixes pointed to by a defined path. This give you the ability to create dynamic prefix lists thus facilitates many configuration tasks like firewall filters and policy statements. The following example will give you an idea how this feature works:

matjaz@router> show configuration policy-options
prefix-list pfxListThisRouterIPv6 {
    apply-path  "interfaces <*> unit <*> family inet6 address <2*>";
}
matjaz@router> show configuration policy-options prefix-list pfxListThisRouterIPv6 | display inheritance
##
## apply-path was expanded to:
##     2001:***::/112;
##     2001:***::c/126;
##     2001:***::/64;
##     2001:***::1/128;
##
apply-path "interfaces <*> unit <*> family inet6 address <2*>";

You can see that the prefix list named pfxListThisRouterIPv6 is created dynamically from the existing configuration. Junos OS is looking into the portions of active configuration that match the apply-path expression and lists everything that corresponds to the last expression enclosed in angle brackets, <2*> in our case.


Unfortunately, the support for regular expressions within apply-path is rather poor. In the example above, I could not find a way to extract the interface addresses only without the corresponding prefix lengths.

References:

Advertisements