idnits 2.17.1 draft-ietf-idr-flow-spec-v6-16.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- == The 'Updates: ' line in the draft header should list only the _numbers_ of the RFCs which will be updated by this document (if approved); it should not include the word 'RFC' in the list. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (October 12, 2020) is 1263 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '1' on line 640 == Unused Reference: 'RFC8126' is defined on line 624, but no explicit reference was found in the text == Outdated reference: A later version (-27) exists of draft-ietf-idr-rfc5575bis-26 Summary: 0 errors (**), 0 flaws (~~), 4 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 IDR Working Group C. Loibl, Ed. 3 Internet-Draft next layer Telekom GmbH 4 Updates: I-D.ietf-idr-rfc5575bis (if R. Raszuk, Ed. 5 approved) Bloomberg LP 6 Intended status: Standards Track S. Hares, Ed. 7 Expires: April 15, 2021 Huawei 8 October 12, 2020 10 Dissemination of Flow Specification Rules for IPv6 11 draft-ietf-idr-flow-spec-v6-16 13 Abstract 15 Dissemination of Flow Specification Rules provides a Border Gateway 16 Protocol extension for the propagation of traffic flow information 17 for the purpose of rate limiting or filtering IPv4 protocol data 18 packets. 20 This document extends I-D.ietf-idr-rfc5575bis with IPv6 21 functionality. It also updates I-D.ietf-idr-rfc5575bis by changing 22 the IANA Flow Spec Component Types registry. 24 Status of This Memo 26 This Internet-Draft is submitted in full conformance with the 27 provisions of BCP 78 and BCP 79. 29 Internet-Drafts are working documents of the Internet Engineering 30 Task Force (IETF). Note that other groups may also distribute 31 working documents as Internet-Drafts. The list of current Internet- 32 Drafts is at https://datatracker.ietf.org/drafts/current/. 34 Internet-Drafts are draft documents valid for a maximum of six months 35 and may be updated, replaced, or obsoleted by other documents at any 36 time. It is inappropriate to use Internet-Drafts as reference 37 material or to cite them other than as "work in progress." 39 This Internet-Draft will expire on April 15, 2021. 41 Copyright Notice 43 Copyright (c) 2020 IETF Trust and the persons identified as the 44 document authors. All rights reserved. 46 This document is subject to BCP 78 and the IETF Trust's Legal 47 Provisions Relating to IETF Documents 48 (https://trustee.ietf.org/license-info) in effect on the date of 49 publication of this document. Please review these documents 50 carefully, as they describe your rights and restrictions with respect 51 to this document. Code Components extracted from this document must 52 include Simplified BSD License text as described in Section 4.e of 53 the Trust Legal Provisions and are provided without warranty as 54 described in the Simplified BSD License. 56 Table of Contents 58 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 59 1.1. Definitions of Terms Used in This Memo . . . . . . . . . 3 60 2. IPv6 Flow Specification encoding in BGP . . . . . . . . . . . 3 61 3. IPv6 Flow Specification components . . . . . . . . . . . . . 3 62 3.1. Type 1 - Destination IPv6 Prefix . . . . . . . . . . . . 4 63 3.2. Type 2 - Source IPv6 Prefix . . . . . . . . . . . . . . . 4 64 3.3. Type 3 - Upper-Layer Protocol . . . . . . . . . . . . . . 4 65 3.4. Type 7 - ICMPv6 Type . . . . . . . . . . . . . . . . . . 5 66 3.5. Type 8 - ICMPv6 Code . . . . . . . . . . . . . . . . . . 5 67 3.6. Type 12 - Fragment . . . . . . . . . . . . . . . . . . . 6 68 3.7. Type 13 - Flow Label (new) . . . . . . . . . . . . . . . 6 69 3.8. Encoding Example . . . . . . . . . . . . . . . . . . . . 7 70 4. Ordering of Flow Specifications . . . . . . . . . . . . . . . 8 71 5. Validation Procedure . . . . . . . . . . . . . . . . . . . . 9 72 6. IPv6 Traffic Filtering Action changes . . . . . . . . . . . . 9 73 6.1. Redirect IPv6 (rt-redirect-ipv6) Type/Sub-Type 0x80/TBD . 9 74 7. Security Considerations . . . . . . . . . . . . . . . . . . . 9 75 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 10 76 8.1. Flow Spec IPv6 Component Types . . . . . . . . . . . . . 10 77 8.1.1. Registry Template . . . . . . . . . . . . . . . . . . 10 78 8.1.2. Registry Contents . . . . . . . . . . . . . . . . . . 10 79 8.2. Extended Community Flow Spec IPv6 Actions . . . . . . . . 12 80 9. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 13 81 10. Contributors . . . . . . . . . . . . . . . . . . . . . . . . 13 82 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 13 83 11.1. Normative References . . . . . . . . . . . . . . . . . . 13 84 11.2. URIs . . . . . . . . . . . . . . . . . . . . . . . . . . 14 85 Appendix A. Example python code: flow_rule_cmp_v6 . . . . . . . 15 86 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 18 88 1. Introduction 90 The growing amount of IPv6 traffic in private and public networks 91 requires the extension of tools used in IPv4-only networks to be also 92 capable of supporting IPv6 data packets. 94 This document analyzes the differences of IPv6 [RFC8200] flows 95 description from those of traditional IPv4 packets and propose a 96 subset of new Border Gateway Protocol [RFC4271] encoding formats to 97 enable Dissemination of Flow Specification Rules 98 [I-D.ietf-idr-rfc5575bis] for IPv6. 100 This specification is an extension of the base 101 [I-D.ietf-idr-rfc5575bis]. It only defines the delta changes 102 required to support IPv6 while all other definitions and operation 103 mechanisms of Dissemination of Flow Specification Rules will remain 104 in the main specification and will not be repeated here. 106 1.1. Definitions of Terms Used in This Memo 108 AFI - Address Family Identifier. 110 AS - Autonomous System. 112 NLRI - Network Layer Reachability Information. 114 SAFI - Subsequent Address Family Identifier. 116 VRF - Virtual Routing and Forwarding instance. 118 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 119 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 120 "OPTIONAL" in this document are to be interpreted as described in BCP 121 14 [RFC2119] [RFC8174] when, and only when, they appear in all 122 capitals, as shown here. 124 2. IPv6 Flow Specification encoding in BGP 126 [I-D.ietf-idr-rfc5575bis] defines SAFIs 133 (Dissemination of Flow 127 Specification) and 134 (L3VPN Dissemination of Flow Specification) in 128 order to carry the corresponding Flow Specification. 130 Implementations wishing to exchange IPv6 Flow Specifications MUST use 131 BGP's Capability Advertisement facility to exchange the Multiprotocol 132 Extension Capability Code (Code 1) as defined in [RFC4760]. The 133 (AFI, SAFI) pair carried in the Multiprotocol Extension Capability 134 MUST be: (AFI=2, SAFI=133) for IPv6 Flow Specification, and (AFI=2, 135 SAFI=134) for VPNv6 Flow Specification. 137 3. IPv6 Flow Specification components 139 The encoding of each of the components begins with a type field (1 140 octet) followed by a variable length parameter. The following 141 sections define component types and parameter encodings for IPv6. 143 Types 4, 5, 6, 9, 10 and 11, as defined in [I-D.ietf-idr-rfc5575bis], 144 also apply to IPv6. Note that even if the definitions are the same 145 (and not repeated here), the number space is managed separately 146 (Section 8). 148 3.1. Type 1 - Destination IPv6 Prefix 150 Encoding: 153 Defines the destination prefix to match. The offset has been defined 154 to allow for flexible matching on part of the IPv6 address where it 155 is required to skip (don't care) of N first bits of the address. 156 This can be especially useful where part of the IPv6 address consists 157 of an embedded IPv4 address and matching needs to happen only on the 158 embedded IPv4 address. The encoded pattern contains enough octets 159 for the bits used in matching (length minus offset bits). 161 length - The length field indicates the N-th most significant bit in 162 the address where bitwise pattern matching stops. 164 offset - The offset field indicates the number of most significant 165 address bits to skip before bitwise pattern matching starts. 167 pattern - Contains the matching pattern. The length of the pattern 168 is defined by the number of bits needed for pattern matching 169 (length minus offset). 171 padding - The minimum number of bits required to pad the component 172 to an octet boundary. Padding bits MUST be 0 on encoding and MUST 173 be ignored on decoding. 175 In the case Length minus Offset is 0 every address matches. Length 176 MUST always be in the range 0-128 and Length minus Offset MUST always 177 be 0 or more, otherwise this component is malformed. 179 3.2. Type 2 - Source IPv6 Prefix 181 Encoding: 184 Defines the source prefix to match. The length, offset, pattern and 185 padding are the same as in Section 3.1 187 3.3. Type 3 - Upper-Layer Protocol 189 Encoding: 191 Contains a list of {numeric_op, value} pairs that are used to match 192 the first Next Header value octet in IPv6 packets that is not an 193 extension header and thus indicates that the next item in the packet 194 is the corresponding upper-layer header (see [RFC8200] Section 4). 196 This component uses the Numeric Operator (numeric_op) described in 197 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 3 component values 198 SHOULD be encoded as single octet (numeric_op len=00). 200 Note: While IPv6 allows for more than one Next Header field in the 201 packet, the main goal of the Type 3 Flow Specification component is 202 to match on the first upper-layer IP protocol value. Therefore the 203 definition is limited to match only on this specific Next Header 204 field in the packet. 206 3.4. Type 7 - ICMPv6 Type 208 Encoding: 210 Defines a list of {numeric_op, value} pairs used to match the type 211 field of an ICMPv6 packet (see also [RFC4443] Section 2.1). 213 This component uses the Numeric Operator (numeric_op) described in 214 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 7 component values 215 SHOULD be encoded as single octet (numeric_op len=00). 217 In case of the presence of the ICMPv6 Type component only ICMPv6 218 packets can match the entire Flow Specification. The ICMPv6 Type 219 component, if present, never matches when the packet's upper-layer IP 220 protocol value is not 58 (ICMPv6), if the packet is fragmented and 221 this is not the first fragment, or if the system is unable to locate 222 the transport header. Different implementations may or may not be 223 able to decode the transport header. 225 3.5. Type 8 - ICMPv6 Code 227 Encoding: 229 Defines a list of {numeric_op, value} pairs used to match the code 230 field of an ICMPv6 packet (see also [RFC4443] Section 2.1). 232 This component uses the Numeric Operator (numeric_op) described in 233 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 8 component values 234 SHOULD be encoded as single octet (numeric_op len=00). 236 In case of the presence of the ICMPv6 Code component only ICMPv6 237 packets can match the entire Flow Specification. The ICMPv6 code 238 component, if present, never matches when the packet's upper-layer IP 239 protocol value is not 58 (ICMPv6), if the packet is fragmented and 240 this is not the first fragment, or if the system is unable to locate 241 the transport header. Different implementations may or may not be 242 able to decode the transport header. 244 3.6. Type 12 - Fragment 246 Encoding: 248 Defines a list of {bitmask_op, bitmask} pairs used to match specific 249 IP fragments. 251 This component uses the Bitmask Operator (bitmask_op) described in 252 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.2. The Type 12 component 253 bitmask MUST be encoded as single octet bitmask (bitmask_op len=00). 255 0 1 2 3 4 5 6 7 256 +---+---+---+---+---+---+---+---+ 257 | 0 | 0 | 0 | 0 |LF |FF |IsF| 0 | 258 +---+---+---+---+---+---+---+---+ 260 Figure 1: Fragment Bitmask Operand 262 Bitmask values: 264 IsF - Is a fragment - match if IPv6 Fragment Header ([RFC8200] 265 Section 4.5) Fragment Offset is not 0 267 FF - First fragment - match if IPv6 Fragment Header ([RFC8200] 268 Section 4.5) Fragment Offset is 0 AND M flag is 1 270 LF - Last fragment - match if IPv6 Fragment Header ([RFC8200] 271 Section 4.5) Fragment Offset is not 0 AND M flag is 0 273 0 - MUST be set to 0 on NLRI encoding, and MUST be ignored during 274 decoding 276 3.7. Type 13 - Flow Label (new) 278 Encoding: 280 Contains a list of {numeric_op, value} pairs that are used to match 281 the 20-bit Flow Label IPv6 header field ([RFC8200] Section 3). 283 This component uses the Numeric Operator (numeric_op) described in 284 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 13 component values 285 SHOULD be encoded as 1-, 2-, or 4-byte quantities (numeric_op len=00, 286 len=01 or len=10). 288 3.8. Encoding Example 290 3.8.1. Example 1 292 The following example demonstrates the prefix encoding for: "packets 293 from ::1234:5678:9A00:0/64-104 to 2001:DB8::/32 and upper-layer- 294 protocol tcp". 296 +--------+----------------------+-------------------------+----------+ 297 | length | destination | source | ul-proto | 298 +--------+----------------------+-------------------------+----------+ 299 | 0x12 | 01 20 00 20 01 0D B8 | 02 68 40 12 34 56 78 9A | 03 81 06 | 300 +--------+----------------------+-------------------------+----------+ 302 Decoded: 304 +-------+------------+-------------------------------+ 305 | Value | | | 306 +-------+------------+-------------------------------+ 307 | 0x12 | length | 18 octets (len<240 1-octet) | 308 | 0x01 | type | Type 1 - Dest. IPv6 Prefix | 309 | 0x20 | length | 32 bit | 310 | 0x00 | offset | 0 bit | 311 | 0x20 | pattern | | 312 | 0x01 | pattern | | 313 | 0x0D | pattern | | 314 | 0xB8 | pattern | (no padding needed) | 315 | 0x02 | type | Type 2 - Source IPv6 Prefix | 316 | 0x68 | length | 104 bit | 317 | 0x40 | offset | 64 bit | 318 | 0x12 | pattern | | 319 | 0x34 | pattern | | 320 | 0x56 | pattern | | 321 | 0x78 | pattern | | 322 | 0x9A | pattern | (no padding needed) | 323 | 0x03 | type | Type 3 - upper-layer-proto | 324 | 0x81 | numeric_op | end-of-list, value size=1, == | 325 | 0x06 | value | 06 | 326 +-------+------------+-------------------------------+ 328 This constitutes a NLRI with a NLRI length of 18 octets. 330 Neither for the destination prefix pattern (length - offset = 32 bit) 331 nor for the source prefix pattern (length - offset = 40 bit) any 332 padding is needed (both patterns end on a octet boundary). 334 3.8.2. Example 2 336 The following example demonstrates the prefix encoding for: "all 337 packets from ::1234:5678:9A00:0/65-104 to 2001:DB8::/32". 339 +--------+----------------------+-------------------------+ 340 | length | destination | source | 341 +--------+----------------------+-------------------------+ 342 | 0x0f | 01 20 00 20 01 0D B8 | 02 68 41 24 68 ac f1 34 | 343 +--------+----------------------+-------------------------+ 345 Decoded: 347 +-------+-------------+-------------------------------+ 348 | Value | | | 349 +-------+-------------+-------------------------------+ 350 | 0x0f | length | 15 octets (len<240 1-octet) | 351 | 0x01 | type | Type 1 - Dest. IPv6 Prefix | 352 | 0x20 | length | 32 bit | 353 | 0x00 | offset | 0 bit | 354 | 0x20 | pattern | | 355 | 0x01 | pattern | | 356 | 0x0D | pattern | | 357 | 0xB8 | pattern | (no padding needed) | 358 | 0x02 | type | Type 2 - Source IPv6 Prefix | 359 | 0x68 | length | 104 bit | 360 | 0x41 | offset | 65 bit | 361 | 0x24 | pattern | | 362 | 0x68 | pattern | | 363 | 0xac | pattern | | 364 | 0xf1 | pattern | | 365 | 0x34 | pattern/pad | (contains 1 bit padding) | 366 +-------+-------------+-------------------------------+ 368 This constitutes a NLRI with a NLRI length of 15 octets. 370 The source prefix pattern is 104 - 65 = 39 bits in length. After the 371 pattern one bit of padding needs to be added so that the component 372 ends on a octet boundary. However, only the first 39 bits are 373 actually used for bitwise pattern matching starting with a 65 bit 374 offset from the topmost bit of the address. 376 4. Ordering of Flow Specifications 378 The definition for the order of traffic filtering rules from 379 [I-D.ietf-idr-rfc5575bis] Section 5.1 is reused with new 380 consideration for the IPv6 prefix offset. As long as the offsets are 381 equal, the comparison is the same, retaining longest-prefix-match 382 semantics. If the offsets are not equal, the lowest offset has 383 precedence, as this flow matches the most significant bit. 385 The code in Appendix A shows a Python3 implementation of the 386 resulting comparison algorithm. The full code was tested with Python 387 3.7.2 and can be obtained at https://github.com/stoffi92/draft-ietf- 388 idr-flow-spec-v6/tree/master/flowspec-cmp [1]. 390 5. Validation Procedure 392 The validation procedure is the same as specified in 393 [I-D.ietf-idr-rfc5575bis] Section 6 with the exception that item a) 394 of the validation procedure should now read as follows: 396 a) A destination prefix component with offset=0 is embedded in the 397 Flow Specification 399 6. IPv6 Traffic Filtering Action changes 401 Traffic Filtering Actions from [I-D.ietf-idr-rfc5575bis] Section 7 402 can also be applied to IPv6 Flow Specifications. To allow an IPv6 403 address specific route-target, a new Traffic Filtering Action IPv6 404 address specific extended community is specified in Section 6.1 405 below. 407 6.1. Redirect IPv6 (rt-redirect-ipv6) Type/Sub-Type 0x80/TBD 409 The redirect IPv6 address specific extended community allows the 410 traffic to be redirected to a VRF routing instance that lists the 411 specified IPv6 address specific route-target in its import policy. 412 If several local instances match this criteria, the choice between 413 them is a local matter (for example, the instance with the lowest 414 Route Distinguisher value can be elected). 416 This extended community uses the same encoding as the IPv6 address 417 specific Route Target extended community [RFC5701] Section 2 with the 418 high-order octet of the Type always set to 0x80 and the Sub-Type 419 always TBD. 421 Interferes with: All BGP Flow Specification redirect Traffic 422 Filtering Actions (with itself and those specified in 423 [I-D.ietf-idr-rfc5575bis] Section 7.4). 425 7. Security Considerations 427 This document extends the functionality in [I-D.ietf-idr-rfc5575bis] 428 to be applicable to IPv6 data packets. The same Security 429 Considerations from [I-D.ietf-idr-rfc5575bis] now also apply to IPv6 430 networks. Otherwise, no new security issues are added to the BGP 431 protocol. 433 8. IANA Considerations 435 This section complies with [RFC7153]. 437 8.1. Flow Spec IPv6 Component Types 439 IANA has created and maintains a registry entitled "Flow Spec 440 Component Types". IANA is requested to add [this document] to the 441 reference for this registry. Furthermore the registry should be 442 rewritten to also contain the IPv6 Flow Specification Component Types 443 as described below. The registration procedure should remain 444 unchanged. 446 8.1.1. Registry Template 448 Type Value: 449 Contains the assigned Flow Specification component type value. 451 IPv4 Name: 452 Contains the associated IPv4 Flow Specification component name 453 as specified in [I-D.ietf-idr-rfc5575bis]. 455 IPv6 Name: 456 Contains the associated IPv6 Flow Specification component name 457 as specified in this document. 459 Reference: 460 Contains referenced to the specifications. 462 8.1.2. Registry Contents 464 + Type Value: 0 465 + IPv4 Name: Reserved 466 + IPv6 Name: Reserved 467 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 469 + Type Value: 1 470 + IPv4 Name: Destination Prefix 471 + IPv6 Name: Destination IPv6 Prefix 472 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 474 + Type Value: 2 475 + IPv4 Name: Source Prefix 476 + IPv6 Name: Source IPv6 Prefix 477 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 479 + Type Value: 3 480 + IPv4 Name: IP Protocol 481 + IPv6 Name: Upper-Layer Protocol 482 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 484 + Type Value: 4 485 + IPv4 Name: Port 486 + IPv6 Name: Port 487 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 489 + Type Value: 5 490 + IPv4 Name: Destination Port 491 + IPv6 Name: Destination Port 492 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 494 + Type Value: 6 495 + IPv4 Name: Source Port 496 + IPv6 Name: Source Port 497 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 499 + Type Value: 7 500 + IPv4 Name: ICMP Type 501 + IPv6 Name: ICMPv6 Type 502 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 504 + Type Value: 8 505 + IPv4 Name: ICMP Code 506 + IPv6 Name: ICMPv6 Code 507 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 509 + Type Value: 9 510 + IPv4 Name: TCP flags 511 + IPv6 Name: TCP flags 512 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 514 + Type Value: 10 515 + IPv4 Name: Packet length 516 + IPv6 Name: Packet length 517 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 519 + Type Value: 11 520 + IPv4 Name: DSCP 521 + IPv6 Name: DSCP 522 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 524 + Type Value: 12 525 + IPv4 Name: Fragment 526 + IPv6 Name: Fragment 527 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 529 + Type Value: 13 530 + IPv4 Name: Unassigned 531 + IPv6 Name: Flow Label 532 + Reference: [this document] 534 + Type Value: 14-254 535 + IPv4 Name: Unassigned 536 + IPv6 Name: Unassigned 537 + Reference: 539 + Type Value: 255 540 + IPv4 Name: Reserved 541 + IPv6 Name: Reserved 542 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 544 8.2. Extended Community Flow Spec IPv6 Actions 546 IANA maintains a registry entitled "Generic Transitive Experimental 547 Use Extended Community Sub-Types". For the purpose of this work, 548 IANA is requested to assign a new value: 550 +----------------+--------------------------------+-----------------+ 551 | Sub-Type Value | Name | Reference | 552 +----------------+--------------------------------+-----------------+ 553 | TBD | Flow spec rt-redirect-ipv6 | [this document] | 554 | | format | | 555 +----------------+--------------------------------+-----------------+ 557 Table 1: Registry: Generic Transitive Experimental Use Extended 558 Community Sub-Types 560 9. Acknowledgements 562 Authors would like to thank Pedro Marques, Hannes Gredler, Bruno 563 Rijsman, Brian Carpenter, and Thomas Mangin for their valuable input. 565 10. Contributors 567 Danny McPherson 568 Verisign, Inc. 570 Email: dmcpherson@verisign.com 572 Burjiz Pithawala 573 Individual 575 Email: burjizp@gmail.com 577 Andy Karch 578 Cisco Systems 579 170 West Tasman Drive 580 San Jose, CA 95134 581 USA 583 Email: akarch@cisco.com 585 11. References 587 11.1. Normative References 589 [I-D.ietf-idr-rfc5575bis] 590 Loibl, C., Hares, S., Raszuk, R., McPherson, D., and M. 591 Bacher, "Dissemination of Flow Specification Rules", 592 draft-ietf-idr-rfc5575bis-26 (work in progress), August 593 2020. 595 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 596 Requirement Levels", BCP 14, RFC 2119, 597 DOI 10.17487/RFC2119, March 1997, 598 . 600 [RFC4271] Rekhter, Y., Ed., Li, T., Ed., and S. Hares, Ed., "A 601 Border Gateway Protocol 4 (BGP-4)", RFC 4271, 602 DOI 10.17487/RFC4271, January 2006, 603 . 605 [RFC4443] Conta, A., Deering, S., and M. Gupta, Ed., "Internet 606 Control Message Protocol (ICMPv6) for the Internet 607 Protocol Version 6 (IPv6) Specification", STD 89, 608 RFC 4443, DOI 10.17487/RFC4443, March 2006, 609 . 611 [RFC4760] Bates, T., Chandra, R., Katz, D., and Y. Rekhter, 612 "Multiprotocol Extensions for BGP-4", RFC 4760, 613 DOI 10.17487/RFC4760, January 2007, 614 . 616 [RFC5701] Rekhter, Y., "IPv6 Address Specific BGP Extended Community 617 Attribute", RFC 5701, DOI 10.17487/RFC5701, November 2009, 618 . 620 [RFC7153] Rosen, E. and Y. Rekhter, "IANA Registries for BGP 621 Extended Communities", RFC 7153, DOI 10.17487/RFC7153, 622 March 2014, . 624 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 625 Writing an IANA Considerations Section in RFCs", BCP 26, 626 RFC 8126, DOI 10.17487/RFC8126, June 2017, 627 . 629 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 630 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 631 May 2017, . 633 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 634 (IPv6) Specification", STD 86, RFC 8200, 635 DOI 10.17487/RFC8200, July 2017, 636 . 638 11.2. URIs 640 [1] https://github.com/stoffi92/draft-ietf-idr-flow-spec- 641 v6/tree/master/flowspec-cmp 643 Appendix A. Example python code: flow_rule_cmp_v6 645 646 """ 647 Copyright (c) 2020 IETF Trust and the persons identified as authors 648 of draft-ietf-idr-flow-spec-v6. All rights reserved. 650 Redistribution and use in source and binary forms, with or without 651 modification, is permitted pursuant to, and subject to the license 652 terms contained in, the Simplified BSD License set forth in Section 653 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents 654 (http://trustee.ietf.org/license-info). 655 """ 657 import itertools 658 import collections 659 import ipaddress 661 EQUAL = 0 662 A_HAS_PRECEDENCE = 1 663 B_HAS_PRECEDENCE = 2 664 IP_DESTINATION = 1 665 IP_SOURCE = 2 667 FS_component = collections.namedtuple('FS_component', 668 'component_type value') 670 class FS_IPv6_prefix_component: 671 def __init__(self, prefix, offset=0, 672 component_type=IP_DESTINATION): 673 self.offset = offset 674 self.component_type = component_type 675 # make sure if offset != 0 that non of the 676 # first offset bits are set in the prefix 677 self.value = prefix 678 if offset != 0: 679 i = ipaddress.IPv6Interface( 680 (self.value.network_address, offset)) 681 if i.network.network_address != \ 682 ipaddress.ip_address('0::0'): 683 raise ValueError('Bits set in the offset') 685 class FS_nlri(object): 686 """ 687 FS_nlri class implementation that allows sorting. 689 By calling .sort() on a array of FS_nlri objects these 690 will be sorted according to the flow_rule_cmp algorithm. 692 Example: 693 nlri = [ FS_nlri(components=[ 694 FS_component(component_type=4, 695 value=bytearray([0,1,2,3,4,5,6])), 696 ]), 697 FS_nlri(components=[ 698 FS_component(component_type=5, 699 value=bytearray([0,1,2,3,4,5,6])), 700 FS_component(component_type=6, 701 value=bytearray([0,1,2,3,4,5,6])), 702 ]), 703 ] 704 nlri.sort() # sorts the array accorinding to the algorithm 705 """ 706 def __init__(self, components = None): 707 """ 708 components: list of type FS_component 709 """ 710 self.components = components 712 def __lt__(self, other): 713 # use the below algorithm for sorting 714 result = flow_rule_cmp_v6(self, other) 715 if result == B_HAS_PRECEDENCE: 716 return True 717 else: 718 return False 720 def flow_rule_cmp_v6(a, b): 721 """ 722 Implementation of the flowspec sorting algorithm in 723 draft-ietf-idr-flow-spec-v6. 724 """ 725 for comp_a, comp_b in itertools.zip_longest(a.components, 726 b.components): 727 # If a component type does not exist in one rule 728 # this rule has lower precedence 729 if not comp_a: 730 return B_HAS_PRECEDENCE 731 if not comp_b: 732 return A_HAS_PRECEDENCE 733 # Higher precedence for lower component type 734 if comp_a.component_type < comp_b.component_type: 735 return A_HAS_PRECEDENCE 737 if comp_a.component_type > comp_b.component_type: 738 return B_HAS_PRECEDENCE 739 # component types are equal -> type specific comparison 740 if comp_a.component_type in (IP_DESTINATION, IP_SOURCE): 741 if comp_a.offset < comp_b.offset: 742 return A_HAS_PRECEDENCE 743 if comp_a.offset < comp_b.offset: 744 return B_HAS_PRECEDENCE 745 # both components have the same offset 746 # assuming comp_a.value, comp_b.value of type 747 # ipaddress.IPv6Network 748 # and the offset bits are reset to 0 (since they are 749 # not represented in the NLRI) 750 if comp_a.value.overlaps(comp_b.value): 751 # longest prefixlen has precedence 752 if comp_a.value.prefixlen > \ 753 comp_b.value.prefixlen: 754 return A_HAS_PRECEDENCE 755 if comp_a.value.prefixlen < \ 756 comp_b.value.prefixlen: 757 return B_HAS_PRECEDENCE 758 # components equal -> continue with next 759 # component 760 elif comp_a.value > comp_b.value: 761 return B_HAS_PRECEDENCE 762 elif comp_a.value < comp_b.value: 763 return A_HAS_PRECEDENCE 764 else: 765 # assuming comp_a.value, comp_b.value of type 766 # bytearray 767 if len(comp_a.value) == len(comp_b.value): 768 if comp_a.value > comp_b.value: 769 return B_HAS_PRECEDENCE 770 if comp_a.value < comp_b.value: 771 return A_HAS_PRECEDENCE 772 # components equal -> continue with next 773 # component 774 else: 775 common = min(len(comp_a.value), 776 len(comp_b.value)) 777 if comp_a.value[:common] > \ 778 comp_b.value[:common]: 779 return B_HAS_PRECEDENCE 780 elif comp_a.value[:common] < \ 781 comp_b.value[:common]: 782 return A_HAS_PRECEDENCE 783 # the first common bytes match 784 elif len(comp_a.value) > len(comp_b.value): 786 return A_HAS_PRECEDENCE 787 else: 788 return B_HAS_PRECEDENCE 789 return EQUAL 790 792 Authors' Addresses 794 Christoph Loibl (editor) 795 next layer Telekom GmbH 796 Mariahilfer Guertel 37/7 797 Vienna 1150 798 AT 800 Phone: +43 664 1176414 801 Email: cl@tix.at 803 Robert Raszuk (editor) 804 Bloomberg LP 805 731 Lexington Ave 806 New York City, NY 10022 807 USA 809 Email: robert@raszuk.net 811 Susan Hares (editor) 812 Huawei 813 7453 Hickory Hill 814 Saline, MI 48176 815 USA 817 Email: shares@ndzh.com