<?xml version="1.0" encoding="US-ASCII"?>
<!-- This template is for creating an Internet Draft using xml2rfc,
    which is available here: http://xml.resource.org. -->
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<!-- For a complete list and description of processing instructions (PIs),
    please see http://xml.resource.org/authoring/README.html. -->
<!-- Below are generally applicable Processing Instructions (PIs) that most I-Ds might want to use.
    (Here they are set differently than their defaults in xml2rfc v1.32) -->
<?rfc strict="yes" ?>
<!-- give errors regarding ID-nits and DTD validation -->
<!-- control the table of contents (ToC) -->
<?rfc toc="yes"?>
<!-- generate a ToC -->
<?rfc tocdepth="4"?>
<!-- the number of levels of subsections in ToC. default: 3 -->
<!-- control references -->
<?rfc symrefs="yes"?>
<!-- use symbolic references tags, i.e, [RFC2119] instead of [1] -->
<?rfc sortrefs="yes" ?>
<!-- sort the reference entries alphabetically -->
<!-- control vertical white space
    (using these PIs as follows is recommended by the RFC Editor) -->
<?rfc compact="yes" ?>
<!-- do not start each main section on a new page -->
<?rfc subcompact="no" ?>
<!-- keep one blank line between list items -->
<!-- end of list of popular I-D processing instructions -->
<rfc category="std" docName="draft-khare-idr-bgp-flowspec-payload-match-07"
     ipr="trust200902" submissionType="IETF">
  <!-- ***** FRONT MATTER ***** -->

  <front>
    <!-- The abbreviated title is used in the page header - it is only necessary if the
        full title is longer than 39 characters -->

    <title abbrev="BGP FlowSpec Payload Matching">BGP FlowSpec Payload
    Matching</title>

    <author fullname="Anurag Khare" initials="A." role="editor"
            surname="Khare">
      <organization>Ciena Corporation</organization>

      <address>
        <email>ak@ciena.com</email>
      </address>
    </author>

    <author fullname="Philippe Bergeon" initials="P." role="editor"
            surname="Bergeon">
      <organization>Nokia</organization>
      <address>
        <postal>
          <street>600 March Road</street>

          <city>Ottawa</city>

          <region>Ontario</region>

          <code>K2K2E6</code>

          <country>CA</country>
        </postal>
        <email>philippe.bergeon@nokia.com</email>
      </address>
    </author>

    <author fullname="John Scudder" initials="J." surname="Scudder">
      <organization>Juniper Networks, Inc.</organization>

      <address>
        <postal>
          <street>1133 Innovation Way</street>

          <city>Sunnyvale</city>

          <region>CA</region>

          <code>94089</code>

          <country>US</country>
        </postal>

        <email>jgs@juniper.net</email>
      </address>
    </author>

    <author fullname="Luay Jalil" initials="L." surname="Jalil">
      <organization>Verizon</organization>

      <address>
        <email>luay.jalil@one.verizon.com</email>
      </address>
    </author>

    <author fullname="Michael Gallagher" initials="M." surname="Gallagher">
      <organization>Verizon</organization>

      <address>
        <email>michael.gallagher@verizon.com</email>
      </address>
    </author>

    <author fullname="Kirill Kasavchenko" initials="K." surname="Kasavchenko">
      <organization>NetScout</organization>

      <address>
        <email>Kirill.Kasavchenko@netscout.com</email>
      </address>
    </author>

    <date day="31" month="August" year="2020"/>

    <area>RTG</area>

    <workgroup>Internet Engineering Task Force</workgroup>

    <!-- WG name at the upperleft corner of the doc,
        IETF is fine for individual submissions.
   If this element is not present, the default is "Network Working Group",
        which is used by the RFC Editor as a nod to the history of the IETF. -->

    <keyword>BGP</keyword>

    <keyword>Flowspec</keyword>

    <keyword>DDoS</keyword>

    <keyword>filter</keyword>

    <abstract>
      <t>The rise in frequency, volume, and pernicious effects of DDoS attacks
      has elevated them from fare for the specialist to generalist press.
      Numerous reports detail the taxonomy of DDoS attacks, the varying
      motivations of their attackers, as well as the resulting impact for their targets ranging from internet or business services to network infrastrutures.</t>

      <t>BGP FlowSpec (RFC 5575, "Dissemination of Flow Specification Rules")
      can be used to rapidly disseminate filtering rules to mitigate (distributed) denial-of-service (DoS) attacks. Operators can use existing FlowSpec components to match typical n-tuple criteria in pre-defined packet header fields such as IP protocol, IP prefix or port number. Recent enhancements to IP Router forwarding plane filter implementations also allow matches at arbitrary locations within the packet header or payload. This capability can be used to essentially match a signature for the attack traffic and can be combined with traditional n-tuple filter criteria to mitigate volumetric DDoS attacks and reduce false positive to a minimum.</t>

      <t>To support this new filtering capability we define a new FlowSpec component, "Flexible Match Conditions", with similar matching semantics to those of existing components. This component will allow the operator to define a new match condition using a combination of offset and pattern values.</t>
    </abstract>
  </front>

  <middle>
    <section title="Introduction">
      <t>BGP FlowSpec <xref target="RFC5575"/> can be used to rapidly disseminate filtering rules to mitigate (distributed) denial-of-service (DoS) attacks. Operators can use existing FlowSpec components to match typical n-tuple criteria in pre-defined packet header fields such as IP protocol, IP prefix and port number.</t>

      <t>Recent enhancements to IP Router forwarding plane filter implementations also allow matches at arbitrary locations within the packet header or payload. This capability can be used to essentially match a signature for the attack traffic and can be combined with traditional n-tuple filter criteria to mitigate volumetric DDoS attacks and reduce false positive to a minimum.</t>

      <t>To support this new filtering capability we define a new FlowSpec component, "Flexible Match Conditions", with similar matching semantics to those of existing components. This component will allow the operator to define a new match condition using a combination of offset and pattern values.</t>

    </section>

    <section anchor="terminology" title="Definitions of Terms Used in This Memo">
      <t>
        <list hangIndent="4" style="hanging">
          <t hangText="AFI - ">Address Family Identifier.</t>

          <t hangText="SAFI - ">Subsequent Address Family Identifier.</t>

          <t hangText="NLRI - ">Network Layer Reachability Information.</t>

          <t hangText="Flow specification controller - ">BGP speaker sending the flow specification rules to the IP edge routers (e.g. DDoS controllers).</t>

          <t hangText="Maximum Readable Length - ">The packet length in bits that a forwarding implementation can parse and make available for filtering. Abbreviated as MRL.</t>

          <t hangText="Maximum Pattern Length - ">The pattern length in bits that a forwarding implementation can match against the packet header or payload. Abbreviated as MPL.</t>
        </list>
      </t>

          <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
          "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
          document are to be interpreted as described in <xref
          target="RFC2119">RFC 2119</xref>.</t>

    </section>

    <section title="Motivation">
      <t>BGP FlowSpec couples both the advertisement of NLRI-specific match
      conditions, as well as the forwarding instance to which the filter is
      attached. This makes sense since BGP FlowSpec advertisements are most
      commonly generated, or at least verified, by human operators. The
      operator finds it intuitive to configure match conditions as
      human-readable values, native to each address family.</t>

      <t>It is much friendlier, for instance, to define a filter that matches
      a source address of 192.168.1.1/32, than it is to work with the
      equivalent binary representation of that IPv4 address. Further, it is
      easier to use field names such as 'IPv4 source address' as part of the
      match condition, than it is to demarc that field using byte and bit
      offsets.</t>

      <t>However, there are a number of use cases that benefit from the
      latter, more machine-readable approach.</t>

      <section title="Machine analysis of DDoS attacks">

        <t>Volumetric DDoS attacks can severely impact services and network operator infrastrutures but are also easily mitigated once identified. The challenge lies in fishing out a generally
        unvarying attack signature from a data stream. Machine analysis can be particularly useful here given the size of input involved in order to identify a pattern within the attack traffic flows.</t>

        <t>Below we illustrate the need for the suggested approach with two
        use cases.</t>

        <section title="Matching based on payload">
          <t>Volumetric DDoS attacks can either directly send traffic to a target or use
          reflection/amplification protocols to overload that target.</t>
          <t>Reflection/amplification attacks are often identified by the
          UDP source port of a service that reflects and amplifies the attack
          traffic. However, blocking traffic based on source port can lead to further service
          interruption and eventually complete the attack especially in case of essential protocols
          such as NTP.
          There alo exist DDoS attack methodologies such as SSDP
          Diffraction or Bittorent amplification where values in most of layer
          3 and layer 4 header fields, including source and destination UDP
          ports, are varied. That makes it challenging to mitigate based on existing Flow
          Specification components. At the same time these attacks often
          have a constant pattern in payload. Using the pattern in payload as
          a matching criteria would help in mitigating such DDoS attacks.</t>
          <t>Direct attacks may also use a constant pattern in payload which can be used as a match criteria in filtering rules.</t>
        </section>

        <section title="Matching based on any protocol header field or across fields">
          <t>BGP FlowSpec <xref target="RFC5575"/> defines 12 Flow
          Specification component types that can be used to match traffic.
          However, a DDoS attack might result in illegitimate traffic with a
          specific pattern in a layer 3 or layer 4 header, and this pattern
          may not have a respective FlowSpec component type defined. Examples of this are the Time to
          Live field of IP header or Window field of TCP header. The flexible match patterns defined in this document avoid extending BGP FlowSpec <xref target="RFC5575"/> with all
          theoretically possible header fields and also allow matching accross fields for any bitmask
          combinations.</t>
        </section>
      </section>

      <section title="Tunneled traffic">
        <t>Tunnels continue to proliferate due to the benefits they provide.
        They can help reduce state in the underlay network. Tunnels allow
        bypassing routing decisions of the transit network. Traffic that is
        tunneled is often done so to obscure or secure. Common tunnel types
        include IPsec <xref target="RFC4301"/>, Generic Routing Encapsulation
        (GRE) <xref target="RFC2890"/>, et al.</t>

        <t>By definition, transit nodes that are not the endpoints of the
        tunnel hold no attendant control or management plane state. These very
        qualities make it challenging to filter tunneled traffic at
        non-endpoints and it is
        usually infeasible to filter based on the content of this passenger
        protocol's header since BGP FlowSpec does not provide the operator a
        way to address arbitrary locations within a packet.</t>
      </section>

      <section title="Non-IP traffic">
        <t>Not all traffic is forwarded as IP packets. Layer 2 services
        abound, including flavors of BGP-signaled Ethernet VPNs such as
        BGP-EVPN, BGP-VPLS, FEC 129 VPWS (LDP-signaled VPWS with BGP
        Auto-Discovery).</t>

        <t>Ongoing efforts such as <xref
        target="I-D.ietf-idr-flowspec-l2vpn"/> offer one approach, which is to
        add layer 2 fields as additional match conditions. This may suffice if
        a filter needs to be applied only to layer 2, or only to layer 3
        header fields.</t>
      </section>
    </section>

    <section title="Specification">
      <t> We define a new FlowSpec component, Type TBD, named "Flexible Match Conditions". </t>

      <t>Encoding: &lt;type (1 octet), length (1 octet), value&gt;</t>

      <t>The length is a one octet unsigned interger field that contains the length of the Value field in octets.</t>

      <t>The Value field itself is encoded using offset-type, offset-value, pattern-type and pattern-value.</t>
      <t> Encoding: &lt;offset-type (4 bits), offset-value (2 octets), pattern-type (4 bits), pattern-value (variable)&gt;</t>
      <t>The value field is 0 padded for byte alignement.</t>

      <section title="Offset-type">
        <t>The combination of offset-type and offset-value defines where the match should begin for the pattern-value. This document defines the following offset types:</t>
        <texttable title="Offset Types">
          <ttcol align="center">Value</ttcol>
          <ttcol>Offset Type</ttcol>
          <c>0</c>
          <c>Layer 3 - IP Header</c>
          <c>1</c>
          <c>Layer 4 - IP Header Data</c>
          <c>2</c>
          <c>Payload - TCP/UDP Data</c>
        </texttable>
      <t>The offset-type 0 for 'layer 3' is defined as the start of the IP header.</t>
      <t>The offset-type 1 for 'layer 4' is defined as the start of the data portion of the IP header after the IP options.</t>
      <t>The offset-type 2 for 'payload' is defined as start of the TCP or UDP data. For TCP, the offset-type payload represents the beginning of the TCP data after any TCP options. Note that Flow Specification NLRI using the Flexible Match Condition component with offset-type 2 will result in not matching the pattern value in this component in case of non-first fragmented packet or in case it is combined with component type 2 IP Protocol other than 6 (TCP) and 17 (UDP).</t>

      </section>
      <section title="Offset-value">

        <t>The offset-value is a 2 octets unsigned integer field defining the number of bytes to ignore from the earlier offset-type to match the pattern value.</t>
        <t>Examples:</t>
        <t>- The combination of offset-type 0 (Layer 3) and offset-value 0 defines an offset at the very beginning of the IP header.</t>
        <t>- The combination of offset-type 1 (Layer 4) and offset-value 2 defines an offset two bytes after the beginning of the data portion of the IP header (after any IP options). Example, in the case of a UDP packet, this offset defines the beginning of the destination port header field.</t>
        <t>- The combination of offset-type 2 (Payload) and offset-value 10 defines an offset ten bytes after the beginning of the TCP/UDP data payload.</t>

      </section>
      <section title="Pattern-type">
        <t>The pattern-type defines how the pattern value is matched. The following pattern-types are defined:</t>

        <texttable title="Pattern Types">
          <ttcol align="center">Value</ttcol>

          <ttcol>Pattern Type</ttcol>
          <c>0</c>
          <c>Bitmask match</c>

          <c>1</c>
          <c>POSIX Regular expression (regex) string match</c>

          <c>2</c>
          <c>PCRE Regular expression (regex) string match</c>
        </texttable>

        <t>Pattern-type 0 MUST be implemented.</t>

        <t>Pattern-type 1 and 2 for regular expressions are typically dedicated to hardware-accelerated and software-only forwarding planes or appliances that may be able to filter on more complex criteria. There is a plethora of regular expression engines and their supported flavor. The two flavors introduced in this document are:</t>

        <t><list style="symbols">
         <t>POSIX regular expression string match: This type refers to extended regular expression (ERE) as defined by <xref target="IEEE.1003-2.1992"/>.</t>
         <t>PCRE regular expression string match: This type refers to Perl compatible regular expression as defined by <eref target="https://www.pcre.org/original/pcre.txt">PCRE documentation</eref>.</t>
        </list>
      </t>

      </section>
      <section title="Pattern-value">
        <section title="Bitmask match">
          <t>If the pattern-type bitmask is selected, the pattern-value is encoded as {prefix, mask}, of equal length.</t>

          <t>
            <list hangIndent="4" style="hanging">
              <t hangText="prefix -">Provides a bit string to be matched. The prefix and mask fields are bitwise AND'ed to create a resulting pattern.</t>

              <t hangText="mask -">Paired with the prefix field to create a bit string match. An unset bit is treated as a 'do not care'
              bit in the corresponding position in the prefix field. When a bit is set in the mask, the value of the bit in the corresponding location in the prefix field must match exactly.</t>
            </list>
          </t>
        </section>
        <section title="Regular expression string match">
          <t>If a regular expression pattern-type is selected, the pattern-value is encoded following the appropriate regular expression string match.</t>
        </section>
      </section>
    </section>

    <section title="Flexible Match Conditions boundaries and additional considerations">
        <t>The beginning of the match boundary is aligned with the FlowSpec AFI/SAFI to which the flexible match rule belongs. For instance, with FlowSpec for IPv4 traffic, the smallest offset can only start at the first bit of the IPv4 header.</t>

        <t> The end of the match boundary MUST be the lesser of either the last bit in a packet or the <xref
        target="terminology">Maximum Readable Length</xref> that a forwarding implementation can parse from a packet and make available for filtering. As the MRL will be implementation-dependent, it needs to be known to the Flow Specification controller. That can be communicated out-of-band via configuration or signaled using future BGP or IGP extensions. </t>

        <t> The <xref target="terminology">Maximum Pattern Length</xref> for the pattern-value can also be forwarding implementation dependant and may need to be known to the Flow Specification controller or communicated out-of-band. </t>

        <t>It is not required that all nodes in a filtering domain have a common or minimum MRL and MPL. This does not remove the need for a Flow Specification controller to take MRL and MPL into account when creating flexible filters. This can be useful if the Flow Specification controller does not have direct BGP peering with all FlowSpec enforcers and may not receive a BGP Notification if it advertises a flexible match that exceeds the MRL or MPL of a given node.</t>
    </section>

    <section title="Error Handling">
      <t>Malicious, misbehaving, or misunderstanding implementations could advertise semantically incorrect values. Care must be taken to minimize fallout from attempting to parse such data. Any well-behaved implementation SHOULD verify that the minimum packet length undergoing a match equals (match from the offset + pattern-value length).</t>
    </section>

    <section anchor="Security" title="Security Considerations">
      <t>This document introduces no additional security considerations beyond those already covered in <xref target="RFC5575"/> .</t>

      <!-- jgs - I am skeptical this will suffice. I'll think about if and
     how to elaborate -->
    </section>

    <section anchor="IANA" title="IANA Considerations">
      <t>IANA <!-- --> is requested to assign <!-- when procedure is
    done, update this to "has assigned", and update the various TBD
    accordingly --> a type from the First Come First Served range of the "Flow
      Spec Component Types" registry:</t>

      <texttable>
        <ttcol align="center">Type Value</ttcol>

        <ttcol align="center">Name</ttcol>

        <ttcol align="center">Reference</ttcol>

        <c>TBD</c>

        <c>Flexible Match Conditions</c>

        <c>this document</c>
      </texttable>

      <t>Reference: this document</t>

      <t>Registry Owner/Change Controller: IESG</t>

      <t>Registration procedures:</t>

      <texttable>
        <ttcol align="center">Range</ttcol>

        <ttcol align="left">Registration Procedures</ttcol>

        <c>0-127</c>

        <c>IETF Review</c>

        <c>128-249</c>

        <c>First Come First Served</c>

        <c>250-254</c>

        <c>Experimental</c>

        <c>255</c>

        <c>Reserved</c>
      </texttable>

      <t>Note: a separate "owner" column is not provided because the owner of
      all registrations, once made, is "IESG". </t>

    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>We wish to thank Ron Bonica, Jeff Haas, Sudipto Nandi, Brian St Pierre and Rafal Jan Szarecki for their valuable comments and suggestions on this document.</t>
    </section>
  </middle>

  <!--  *****BACK MATTER ***** -->

  <back>
    <references title="Normative References">
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?>

      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5575.xml"?>
    </references>

    <references title="Informative References">

      <?rfc include="http://xml.resource.org/public/rfc/bibxml-ids/reference.I-D.ietf-idr-flowspec-l2vpn.xml"?>

      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2890.xml"?>

      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.4301.xml"?>

      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml6/reference.IEEE.1003-2.1992.xml"?>

    </references>
  </back>
</rfc>
