This document defines a Flow Specification NLRI type (
Figure 1) that may include several components, such as destination prefix, source prefix, protocol, ports, and others (see
Section 4.2 below).
This NLRI information is encoded using MP_REACH_NLRI and MP_UNREACH_NLRI attributes, as defined in [
RFC 4760]. When advertising Flow Specifications, the Length of the Next-Hop Network Address
MUST be set to 0. The Network Address of the Next-Hop field
MUST be ignored.
The NLRI field of the MP_REACH_NLRI and MP_UNREACH_NLRI is encoded as one or more 2-tuples of the form <length, NLRI value>. It consists of a 1- or 2-octet length field followed by a variable-length NLRI value. The length is expressed in octets.
+-------------------------------+
| length (0xnn or 0xfnnn) |
+-------------------------------+
| NLRI value (variable) |
+-------------------------------+
Implementations wishing to exchange Flow Specification
MUST use BGP's Capability Advertisement facility to exchange the Multiprotocol Extension Capability Code (Code 1), as defined in [
RFC 4760]. The (AFI, SAFI) pair carried in the Multiprotocol Extension Capability
MUST be (AFI=1, SAFI=133) for IPv4 Flow Specification and (AFI=1, SAFI=134) for VPNv4 Flow Specification.
The length field indicates the length in octets of the variable NLRI value:
-
If the NLRI length is smaller than 240 (0xf0 hex) octets, the length field can be encoded as a single octet.
-
Otherwise, it is encoded as an extended-length 2-octet value in which the most significant nibble has the hex value 0xf.
In
Figure 1 above, values less than 240 are encoded using two hex digits (0xnn). Values above 239 are encoded using 3 hex digits (0xfnnn). The highest value that can be represented with this encoding is 4095. For example, the length value of 239 is encoded as 0xef (single octet), while 240 is encoded as 0xf0f0 (2 octets).
The Flow Specification NLRI value consists of a list of optional components and is encoded as follows:
Encoding: <[component]+>
A specific packet is considered to match the Flow Specification when it matches the intersection (AND) of all the components present in the Flow Specification.
Components
MUST follow strict type ordering by increasing numerical order. A given component type
MAY (exactly once) be present in the Flow Specification. If present, it
MUST precede any component of higher numeric type value.
All combinations of components within a single Flow Specification are allowed. However, some combinations cannot match any packets (e.g., "ICMP Type AND Port" will never match any packets) and thus
SHOULD NOT be propagated by BGP.
An NLRI value not encoded as specified here, including an NLRI that contains an unknown component type, is considered malformed and error handling according to
Section 10 is performed.
Most of the components described below make use of comparison operators. Which of the two operators is used is defined by the components in
Section 4.2.2. The operators are encoded as a single octet.
This operator is encoded as shown in
Figure 2.
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| e | a | len | 0 |lt |gt |eq |
+---+---+---+---+---+---+---+---+
-
e (end-of-list bit):
-
Set in the last {op, value} pair in the list
-
a (AND bit):
-
If unset, the result of the previous {op, value} pair is logically ORed with the current one. If set, the operation is a logical AND. In the first operator octet of a sequence, it MUST be encoded as unset and MUST be treated as always unset on decoding. The AND operator has higher priority than OR for the purposes of evaluating logical expressions.
-
len (length):
-
The length of the value field for this operator given as (1 << len). This encodes 1 (len=00), 2 (len=01), 4 (len=10), and 8 (len=11) octets.
-
0:
-
MUST be set to 0 on NLRI encoding and MUST be ignored during decoding
-
lt:
-
less-than comparison between data and value
-
gt:
-
greater-than comparison between data and value
-
eq:
-
equality between data and value
The bits lt, gt, and eq can be combined to produce common relational operators, such as "less or equal", "greater or equal", and "not equal to", as shown in
Table 1.
lt |
gt |
eq |
Resulting operation |
0 |
0 |
0 |
false (independent of the value) |
0 |
0 |
1 |
== (equal) |
0 |
1 |
0 |
> (greater than) |
0 |
1 |
1 |
>= (greater than or equal) |
1 |
0 |
0 |
< (less than) |
1 |
0 |
1 |
<= (less than or equal) |
1 |
1 |
0 |
!= (not equal value) |
1 |
1 |
1 |
true (independent of the value) |
Table 1: Comparison Operation Combinations
This operator is encoded as shown in
Figure 3.
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| e | a | len | 0 | 0 |not| m |
+---+---+---+---+---+---+---+---+
-
e, a, len (end-of-list bit, AND bit, and length field):
-
Most significant nibble; defined in the Numeric Operator format in Section 4.2.1.1.
-
not (NOT bit):
-
If set, logical negation of operation.
-
m (Match bit):
-
If set, this is a bitwise match operation defined as "(data AND value) == value"; if unset, (data AND value) evaluates to TRUE if any of the bits in the value mask are set in the data.
-
0 (all 0 bits):
-
MUST be set to 0 on NLRI encoding and MUST be ignored during decoding
The encoding of each of the components begins with a type field (1 octet) followed by a variable length parameter. The following sections define component types and parameter encodings for the IPv4 IP layer and transport layer headers. IPv6 NLRI component types are described in [
RFC 8956].
Encoding: <type (1 octet), length (1 octet), prefix (variable)>
Defines the destination prefix to match. The length and prefix fields are encoded as in BGP UPDATE messages [
RFC 4271].
Encoding: <type (1 octet), length (1 octet), prefix (variable)>
Defines the source prefix to match. The length and prefix fields are encoded as in BGP UPDATE messages [
RFC 4271].
Encoding: <type (1 octet), [numeric_op, value]+>
Contains a list of {numeric_op, value} pairs that are used to match the IP protocol value octet in IP packet header (see
Section 3.1 of
RFC 0791).
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 3 component values
SHOULD be encoded as single octet (numeric_op len=00).
Encoding: <type (1 octet), [numeric_op, value]+>
Defines a list of {numeric_op, value} pairs that match source OR destination TCP/UDP ports (see
Section 3.1 of
RFC 0793 and the "Format" section of [
RFC 0768]). This component matches if either the destination port OR the source port of an IP packet matches the value.
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 4 component values
SHOULD be encoded as 1- or 2-octet quantities (numeric_op len=00 or len=01).
In case of the presence of the port (destination-port (
Section 4.2.2.5), source-port (
Section 4.2.2.6)) component, only TCP or UDP packets can match the entire Flow Specification. The port component, if present, never matches when the packet's IP protocol value is not 6 (TCP) or 17 (UDP), if the packet is fragmented and this is not the first fragment, or if the system is unable to locate the transport header. Different implementations may or may not be able to decode the transport header in the presence of IP options or Encapsulating Security Payload (ESP) NULL [
RFC 4303] encryption.
Encoding: <type (1 octet), [numeric_op, value]+>
Defines a list of {numeric_op, value} pairs used to match the destination port of a TCP or UDP packet (see also
Section 3.1 of
RFC 0793 and the "Format" section of [
RFC 0768].
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 5 component values
SHOULD be encoded as 1- or 2-octet quantities (numeric_op len=00 or len=01).
The last paragraph of
Section 4.2.2.4 also applies to this component.
Encoding: <type (1 octet), [numeric_op, value]+>
Defines a list of {numeric_op, value} pairs used to match the source port of a TCP or UDP packet (see also
Section 3.1 of
RFC 0793 and the "Format" section of [
RFC 0768].
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 6 component values
SHOULD be encoded as 1- or 2-octet quantities (numeric_op len=00 or len=01).
The last paragraph of
Section 4.2.2.4 also applies to this component.
Encoding: <type (1 octet), [numeric_op, value]+>
Defines a list of {numeric_op, value} pairs used to match the type field of an ICMP packet (see also the "Message Formats" section of [
RFC 0792]).
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 7 component values
SHOULD be encoded as single octet (numeric_op len=00).
In case of the presence of the ICMP type component, only ICMP packets can match the entire Flow Specification. The ICMP type component, if present, never matches when the packet's IP protocol value is not 1 (ICMP), if the packet is fragmented and this is not the first fragment, or if the system is unable to locate the transport header. Different implementations may or may not be able to decode the transport header in the presence of IP options or Encapsulating Security Payload (ESP) NULL [
RFC 4303] encryption.
Encoding: <type (1 octet), [numeric_op, value]+>
Defines a list of {numeric_op, value} pairs used to match the code field of an ICMP packet (see also the "Message Formats" section of [
RFC 0792]).
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 8 component values
SHOULD be encoded as single octet (numeric_op len=00).
In case of the presence of the ICMP code component, only ICMP packets can match the entire Flow Specification. The ICMP code component, if present, never matches when the packet's IP protocol value is not 1 (ICMP), if the packet is fragmented and this is not the first fragment, or if the system is unable to locate the transport header. Different implementations may or may not be able to decode the transport header in the presence of IP options or Encapsulating Security Payload (ESP) NULL [
RFC 4303] encryption.
Encoding: <type (1 octet), [bitmask_op, bitmask]+>
Defines a list of {bitmask_op, bitmask} pairs used to match TCP control bits (see also
Section 3.1 of
RFC 0793).
This component uses the Bitmask Operator (bitmask_op) described in
Section 4.2.1.2. Type 9 component bitmasks
MUST be encoded as 1- or 2-octet bitmask (bitmask_op len=00 or len=01).
When a single octet (bitmask_op len=00) is specified, it matches octet 14 of the TCP header (see also
Section 3.1 of
RFC 0793), which contains the TCP control bits. When a 2-octet (bitmask_op len=01) encoding is used, it matches octets 13 and 14 of the TCP header with the data offset (leftmost 4 bits) always treated as 0.
In case of the presence of the TCP flags component, only TCP packets can match the entire Flow Specification. The TCP flags component, if present, never matches when the packet's IP protocol value is not 6 (TCP), if the packet is fragmented and this is not the first fragment, or if the system is unable to locate the transport header. Different implementations may or may not be able to decode the transport header in the presence of IP options or Encapsulating Security Payload (ESP) NULL [
RFC 4303] encryption.
Encoding: <type (1 octet), [numeric_op, value]+>
Defines a list of {numeric_op, value} pairs used to match on the total IP packet length (excluding Layer 2 but including IP header).
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 10 component values
SHOULD be encoded as 1- or 2-octet quantities (numeric_op len=00 or len=01).
Encoding: <type (1 octet), [numeric_op, value]+>
Defines a list of {numeric_op, value} pairs used to match the 6-bit DSCP field (see also [
RFC 2474]).
This component uses the Numeric Operator (numeric_op) described in
Section 4.2.1.1. Type 11 component values
MUST be encoded as single octet (numeric_op len=00).
The six least significant bits contain the DSCP value. All other bits
SHOULD be treated as 0.
Encoding: <type (1 octet), [bitmask_op, bitmask]+>
Defines a list of {bitmask_op, bitmask} pairs used to match specific IP fragments.
This component uses the Bitmask Operator (bitmask_op) described in
Section 4.2.1.2. The Type 12 component bitmask
MUST be encoded as single octet bitmask (bitmask_op len=00).
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 0 |LF |FF |IsF|DF |
+---+---+---+---+---+---+---+---+
Bitmask values:
-
DF (Don't Fragment):
-
match if IP Header Flags Bit-1 (DF) [RFC 0791] is 1
-
IsF (Is a fragment other than the first):
-
match if the [RFC 0791] IP Header Fragment Offset is not 0
-
FF (First Fragment):
-
match if the [RFC 0791] IP Header Fragment Offset is 0 AND Flags Bit-2 (MF) is 1
-
LF (Last Fragment):
-
match if the [RFC 0791] IP Header Fragment Offset is not 0 AND Flags Bit-2 (MF) is 0
-
0:
-
MUST be set to 0 on NLRI encoding and MUST be ignored during decoding
An example of a Flow Specification NLRI encoding for: "all packets to 192.0.2.0/24 and TCP port 25".
length |
destination |
protocol |
port |
0x0b |
01 18 c0 00 02 |
03 81 06 |
04 81 19 |
Table 2
Decoded:
Value |
|
0x0b |
length |
11 octets (if len<240, 1 octet) |
0x01 |
type |
Type 1 - Destination Prefix |
0x18 |
length |
24 bit |
0xc0 |
prefix |
192 |
0x00 |
prefix |
0 |
0x02 |
prefix |
2 |
0x03 |
type |
Type 3 - IP Protocol |
0x81 |
numeric_op |
end-of-list, value size=1, == |
0x06 |
value |
6 (TCP) |
0x04 |
type |
Type 4 - Port |
0x81 |
numeric_op |
end-of-list, value size=1, == |
0x19 |
value |
25 |
Table 3
This constitutes an NLRI with an NLRI length of 11 octets.
An example of a Flow Specification NLRI encoding for: "all packets to 192.0.2.0/24 from 203.0.113.0/24 and port {range [137, 139] or 8080}".
length |
destination |
source |
port |
0x12 |
01 18 c0 00 02 |
02 18 cb 00 71 |
04 03 89 45 8b 91 1f 90 |
Table 4
Decoded:
Value |
|
0x12 |
length |
18 octets (if len<240, 1 octet) |
0x01 |
type |
Type 1 - Destination Prefix |
0x18 |
length |
24 bit |
0xc0 |
prefix |
192 |
0x00 |
prefix |
0 |
0x02 |
prefix |
2 |
0x02 |
type |
Type 2 - Source Prefix |
0x18 |
length |
24 bit |
0xcb |
prefix |
203 |
0x00 |
prefix |
0 |
0x71 |
prefix |
113 |
0x04 |
type |
Type 4 - Port |
0x03 |
numeric_op |
value size=1, >= |
0x89 |
value |
137 |
0x45 |
numeric_op |
"AND", value size=1, <= |
0x8b |
value |
139 |
0x91 |
numeric_op |
end-of-list, value size=2, == |
0x1f90 |
value |
8080 |
Table 5
This constitutes an NLRI with an NLRI length of 18 octets.
An example of a Flow Specification NLRI encoding for: "all packets to 192.0.2.1/32 and fragment { DF or FF } (matching packet with DF bit set or First Fragments)
length |
destination |
fragment |
0x09 |
01 20 c0 00 02 01 |
0c 80 05 |
Table 6
Decoded:
Value |
|
0x09 |
length |
9 octets (if len<240, 1 octet) |
0x01 |
type |
Type 1 - Destination Prefix |
0x20 |
length |
32 bit |
0xc0 |
prefix |
192 |
0x00 |
prefix |
0 |
0x02 |
prefix |
2 |
0x01 |
prefix |
1 |
0x0c |
type |
Type 12 - Fragment |
0x80 |
bitmask_op |
end-of-list, value size=1 |
0x05 |
bitmask |
DF=1, FF=1 |
Table 7
This constitutes an NLRI with an NLRI length of 9 octets.