Overview
Policy-based Routing (PBR) is an extension to the standard routing described previously. It offers administrators significant flexibility in implementing routing decision policies by being able to use different routing tables according to specified criteria.Normal routing forwards packets according to destination IP address information derived from static routes or from a dynamic routing protocol. For example, using OSPF, the route chosen for packets will be the least-cost (shortest) path derived from an SPF calculation. Policy-based routing means that routes chosen for traffic can be based on specific traffic parameters.
Policy-based routing allows the following to be possible:
Source-based Routing
A different routing table may need to be chosen based on the source of traffic. When more than one ISP is used to provide Internet services, policy-based routing can route traffic originating from different sets of users through different routes.
For example, traffic from one address range might be routed through one ISP, whilst traffic from another address range might be through a second ISP.
Service-based Routing
A different routing table might need to be chosen based on the service. Policy-based routing can route a given protocol such as HTTP, through proxies such as Web caches. Specific services might also be routed to a specific ISP so that one ISP handles all HTTP traffic.
User-based Routing
A different routing table might need to be chosen based on the user identity or the group to which the user belongs.
This is particularly useful in provider-independent metropolitan area networks where all users share a common active backbone but each can use different ISPs and subscribe to different providers.
PBR Components
Policy-based routing implementation in cOS Core is implemented using two components:Additional Routing Tables
One or more user-defined alternate Routing Tables are created in addition to the standard default main routing table.
Routing Rules
One or more Routing Rules are created to determine which routing table to use for which traffic.
Without routing rules, the main routing table is the default. However, an alternate routing table can also be explicitly assigned as the default table for a given interface without the use of rules.
Routing Tables
cOS Core, as standard, has one default routing table called main. In addition to the main table, it is possible to define one or more, additional routing tables for policy-based routing. (these will sometimes be referred to as alternate routing tables).Alternate routing tables contain the same information for describing routes as main, except that there is an extra property defined for each of them which is called ordering. The ordering property decides how route lookup is done using alternate tables in conjunction with the main table. This is described further below.
Note: The number of tables is limited by the license | |
---|---|
The maximum number of routing tables that can be created is determined by the cOS Core license At minimum, there is a limit of 5 alternate tables in addition to the main table. |
Example 4.5. Creating a Routing Table
In this example, a new routing table called MyPBRTable is created with the Ordering property set to First.
Command-Line Interface
To see the configured routing table:
Device:/>
add RoutingTable MyPBRTable Ordering=First
InControl
Follow similar steps to those used for the Web Interface below.
Web Interface
Example 4.6. Adding Routes
After defining the routing table MyPBRTable, routes can be added to the table. Assume that the route to a network my_network is to be defined for the lan interface.
Command-Line Interface
Change the context to be the routing table:
Device:/>
cc RoutingTable MyPBRTable
Add the route
Device:/main>
add Route Interface=lan Network=my_network
InControl
Follow similar steps to those used for the Web Interface below.
Web Interface
Routing Rules
A rule in the routing rule set can decide which routing table is selected. A routing rule has a number of filtering properties that are similar to those used in IP rule set entries. A rule can trigger on a type of service (HTTP for example) in combination with the specified Source/Destination Interface and Source/Destination Network.When looking up routing rules, it is the first matching rule found that is triggered, so the rule position can be important. In addition, it should be noted that the destination interface used in the filter should be the original destination interface of the traffic before the interface is potentially changed by the new routing table that the rule selects.
Example 4.7. Creating a Routing Rule
In this example, a routing rule called my_routing_rule is created. This will select the routing table MyPBRTable for any http traffic destined for the network my_network.
Command-Line Interface
Device:/>
add RoutingRule
SourceInterface=any
SourceNetwork=all-nets
DestinationInterface=any
DestinationNetwork=my_network
Service=http
ForwardRoutingTable=MyPBRTable
ReturnRoutingTable=MyPBRTable
Name=my_routing_rule
InControl
Follow similar steps to those used for the Web Interface below.
Web Interface
Routing Rules can use IPv4 or IPv6 Addresses
Routing rules support either IPv4 or IPv6 addresses as the source and destination network for a rule's filtering properties.However both the source and destination network must be either IPv4 or IPv6. It is not permissible to combine IPv4 and IPv6 addresses in a single rule. For further discussion of this topic, see Section 3.2, IPv6 Support.
The Forward and Return Routing Table can be Different
In most cases, the routing table for forward and return traffic will be the same. In some cases it can be advantageous to have different values so that outgoing (forward) traffic uses one routing table, and incoming (return) traffic uses another table.Consider the example of a system with two hypothetical interfaces, wan1 and wan2, connected to two ISPs. There is also a protected network If1_net on the If1 interface. There are two routing tables, the main routing table and an isp2 routing table. These tables have the following contents:
The main routing table
Index # | Interface | Network | Gateway |
---|---|---|---|
1 | If1 | If1_net | |
2 | wan1 | all-nets | isp1_ip |
The isp2 routing table
Index # | Interface | Destination | Gateway |
---|---|---|---|
1 | wan2 | all-nets | isp2_ip |
If traffic coming through wan2 is to have access to If1_net then a routing rule needs to constructed as follows:
Source Interface |
Source Network |
Destination Interface |
Destination Network |
Forward Routing Table |
Return Routing Table |
---|---|---|---|---|---|
wan2 | all-nets | any | If1_net | main | isp2 |
This rule allows the forward traffic through the wan2 table to find the route for If1_net in the main routing table. The return traffic will use the isp2 table so it can reach the initiator of the connection.
This example should also have some address translation rules since If1_net will probably be a private IP network. For simplicity, that has been omitted.
Explicit Interface/Routing Table Association
If a particular routing table is to be always used for traffic from a given source interface, regardless of the service, it is possible to associate the source interface explicitly with a particular table using the Routing Table Membership property of the interface.The difference with this method of explicit association is that the administrator cannot specify the service, such as HTTP, for which the lookup will apply. Routing rules allow a more fine-grained approach to routing table selection by being able to also select a specific service and interface/network filter.
The Routing Table Selection Process
When a packet corresponding to a new connection first arrives, these are the processing steps taken to determine which routing table to use:The routing rules are looked up first. To allow this, the packet’s destination interface must be determined using an initial route lookup that is always performed in the main routing table. It is therefore important that a match for the destination network is found. To ensure this, it is recommended to at least have a default all-nets route which can catch anything not explicitly matched.
A search is now made for a routing rule that matches the packet's source/destination interface/network as well as service. If a matching rule is found then this determines the routing table to use.
If no matching routing rule is found, a check is made to see if the receiving interface is a member of a specific routing table. If the interface is associated with a particular routing table through its Routing Table Membership property, that routing table will be used. If there is no membership then the main table will be used.
Once the correct routing table has been located, a check is made to make sure that the source IP address in fact belongs on the receiving interface. The Access Rules are first examined to see if they can provide this check (see Section 7.1, Access Rules for more details of this feature). If there are no Access Rules or a match with the rules cannot be found, a reverse lookup in the previously selected routing table is done using the source IP address. If the check fails then a default access rule log error message is generated.
At this point, using the routing table selected, the actual route lookup is done to find the packet's destination interface. Note that the routing table's Ordering property is used to determine how the actual lookup is done and the options for this are described in the next section. To implement virtual systems, the property should be set to the value Only.
The connection is then subject to the IP rule set. If a SAT rule set entry is encountered, address translation will be performed. The decision of which routing table to use is made before carrying out address translation but the actual route lookup is performed on the altered address. Note that the original route lookup to find the destination interface used for all rule lookups was done with the original, untranslated address.
If allowed by the IP rule set, the new connection is opened in the cOS Core state table and the packet forwarded through this connection.
The sequence described above is also illustrated as a flowchart in Figure 1.4, “Expanded Apply Rules Logic”.
Once the routing table for a new connection is chosen and that table is an alternate routing table, the Ordering parameter associated with the table is used to decide how the alternate table is combined with the main table to lookup the appropriate route. The three available options are:Default
The default behavior is to first look up the route in the main table. If no matching route is found, or a default route is found (a route with the destination all-nets), a lookup for a matching route in the alternate table is performed. If no match is found in the alternate table then the default route in the main table will be used.
First
This behavior is to first look up the connection's route in the alternate table. If no matching route is found there then the main table is used for the lookup. The default all-nets route will be counted as a match in the alternate table if it is found there.
Only
This option ignores the existence of any other table except the alternate table so that is the only one used for the lookup.
One application of this option is to give the administrator a way to dedicate a single routing table to one set of interfaces. The Only option should be used when creating virtual systems since it can dedicate a routing table to a set of interfaces.
The first two options can be regarded as combining the alternate table with the main table and assigning one route if there is a match in both tables.
Important: Ensure an all-nets route appears in the main table | |
---|---|
A common mistake when setting up policy-based routing is the absence of a default all-nets route in the main routing table. If there is no matching route in main, the traffic will be dropped, unless the receiving interface is a member of a specific routing table. This is explained further under the heading “The Routing Table Selection Process” above. |
Policy-based Routing with Multiple ISPs
A common application of the policy-based routing feature is when traffic is being sent to the Internet using multiple Internet Service Providers (ISPs). The setup for this is described below in Example 4.8, “Policy-based Routing with Multiple ISPs”. This topic is also discussed in a Clavister Knowledge Base Article at the following link:https://kb.clavister.com/324736086
Example 4.8. Policy-based Routing with Multiple ISPs
This example illustrates a scenario where Internet traffic is going to be sent to multiple ISPs. The following will be assumed:
In a provider-independent network, clients will likely have a single IP address, belonging to one of the ISPs. In a single-organization scenario, publicly accessible servers will be configured with two separate IP addresses: one from each ISP. However, this difference does not matter for the policy routing setup itself.
Note that, for a single organization, Internet connectivity through multiple ISPs is normally best done with the BGP protocol, which means not worrying about different IP spans or about policy routing. Unfortunately, this is not always possible, and this is where Policy Based Routing becomes a necessity.
We will set up the main routing table to use ISP A and add a named routing table called r2 that uses the default gateway of ISP B.
Interface | Network | Gateway | ProxyARP |
---|---|---|---|
lan1 | 10.10.10.0/24 | wan1 | |
lan1 | 20.20.20.0/24 | wan2 | |
wan1 | 10.10.10.1/32 | lan1 | |
wan2 | 20.20.20.1/32 | lan1 | |
wan1 | all-nets | 10.10.10.1 |
Contents of the named Policy-based Routing table r2:
Interface | Network | Gateway |
---|---|---|
wan2 | all-nets | 20.20.20.1 |
The table r2 has its Ordering property set to Default, which means that it will only be consulted if the main routing table lookup matches the default route (all-nets).
Contents of the Policy-based Routing Policy:
Source Interface |
Source Range |
Destination Interface |
Destination Range |
Selected/ Service |
Forward VR table |
Return VR table |
---|---|---|---|---|---|---|
lan1 | 10.10.10.0/24 | wan1 | all-nets | all_services | r2 | r2 |
wan2 | all-nets | lan1 | 20.20.20.0/24 | all_services | r2 | r2 |
To configure this example scenario:
InControl
Follow similar steps to those used for the Web Interface below.
Web Interface
Note: Separate routing rules should be added for the inbound and outbound connections.