idnits 2.17.1 draft-ietf-idr-flow-spec-v6-19.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 (November 2, 2020) is 1272 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 635 == Outdated reference: A later version (-27) exists of draft-ietf-idr-rfc5575bis-26 Summary: 0 errors (**), 0 flaws (~~), 3 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: May 6, 2021 Huawei 8 November 2, 2020 10 Dissemination of Flow Specification Rules for IPv6 11 draft-ietf-idr-flow-spec-v6-19 13 Abstract 15 Dissemination of Flow Specification Rules I-D.ietf-idr-rfc5575bis 16 provides a Border Gateway Protocol extension for the propagation of 17 traffic flow information for the purpose of rate limiting or 18 filtering IPv4 protocol data 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 May 6, 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 . . . . . . . 14 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 IANA is requested to update the "Flow 145 Spec Component Types" registry in order to contain both IPv4 and IPv6 146 Flow Specification component type numbers in a single registry 147 (Section 8). 149 3.1. Type 1 - Destination IPv6 Prefix 151 Encoding: 154 Defines the destination prefix to match. The offset has been defined 155 to allow for flexible matching to portions of an IPv6 address where 156 one is required to skip over the first N bits of the address (these 157 bits skipped are often indicated as "don't care" bits). This can be 158 especially useful where part of the IPv6 address consists of an 159 embedded IPv4 address and matching needs to happen only on the 160 embedded IPv4 address. The encoded pattern contains enough octets 161 for the bits used in matching (length minus offset bits). 163 length - The length field indicates the N-th most significant bit in 164 the address where bitwise pattern matching stops. 166 offset - The offset field indicates the number of most significant 167 address bits to skip before bitwise pattern matching starts. 169 pattern - Contains the matching pattern. The length of the pattern 170 is defined by the number of bits needed for pattern matching 171 (length minus offset). 173 padding - The minimum number of bits required to pad the component 174 to an octet boundary. Padding bits MUST be 0 on encoding and MUST 175 be ignored on decoding. 177 Length = Offset = 0 matches every address, otherwise Length MUST be 178 in the range Offset < Length < 129 or the component is malformed. 180 3.2. Type 2 - Source IPv6 Prefix 182 Encoding: 185 Defines the source prefix to match. The length, offset, pattern and 186 padding are the same as in Section 3.1 188 3.3. Type 3 - Upper-Layer Protocol 190 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 other than the first - match if IPv6 Fragment 265 Header ([RFC8200] 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 Padding is not needed either for the destination prefix pattern 331 (length - offset = 32 bit) or for the source prefix pattern (length - 332 offset = 40 bit), as both patterns end on an 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 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 625 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 626 May 2017, . 628 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 629 (IPv6) Specification", STD 86, RFC 8200, 630 DOI 10.17487/RFC8200, July 2017, 631 . 633 11.2. URIs 635 [1] https://github.com/stoffi92/draft-ietf-idr-flow-spec- 636 v6/tree/master/flowspec-cmp 638 Appendix A. Example python code: flow_rule_cmp_v6 640 641 """ 642 Copyright (c) 2020 IETF Trust and the persons identified as authors 643 of draft-ietf-idr-flow-spec-v6. All rights reserved. 645 Redistribution and use in source and binary forms, with or without 646 modification, is permitted pursuant to, and subject to the license 647 terms contained in, the Simplified BSD License set forth in Section 648 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents 649 (http://trustee.ietf.org/license-info). 650 """ 652 import itertools 653 import collections 654 import ipaddress 656 EQUAL = 0 657 A_HAS_PRECEDENCE = 1 658 B_HAS_PRECEDENCE = 2 659 IP_DESTINATION = 1 660 IP_SOURCE = 2 662 FS_component = collections.namedtuple('FS_component', 663 'component_type value') 665 class FS_IPv6_prefix_component: 666 def __init__(self, prefix, offset=0, 667 component_type=IP_DESTINATION): 668 self.offset = offset 669 self.component_type = component_type 670 # make sure if offset != 0 that non of the 671 # first offset bits are set in the prefix 672 self.value = prefix 673 if offset != 0: 674 i = ipaddress.IPv6Interface( 675 (self.value.network_address, offset)) 676 if i.network.network_address != \ 677 ipaddress.ip_address('0::0'): 678 raise ValueError('Bits set in the offset') 680 class FS_nlri(object): 681 """ 682 FS_nlri class implementation that allows sorting. 684 By calling .sort() on a array of FS_nlri objects these 685 will be sorted according to the flow_rule_cmp algorithm. 687 Example: 689 nlri = [ FS_nlri(components=[ 690 FS_component(component_type=4, 691 value=bytearray([0,1,2,3,4,5,6])), 692 ]), 693 FS_nlri(components=[ 694 FS_component(component_type=5, 695 value=bytearray([0,1,2,3,4,5,6])), 696 FS_component(component_type=6, 697 value=bytearray([0,1,2,3,4,5,6])), 698 ]), 699 ] 700 nlri.sort() # sorts the array accorinding to the algorithm 701 """ 702 def __init__(self, components = None): 703 """ 704 components: list of type FS_component 705 """ 706 self.components = components 708 def __lt__(self, other): 709 # use the below algorithm for sorting 710 result = flow_rule_cmp_v6(self, other) 711 if result == B_HAS_PRECEDENCE: 712 return True 713 else: 714 return False 716 def flow_rule_cmp_v6(a, b): 717 """ 718 Implementation of the flowspec sorting algorithm in 719 draft-ietf-idr-flow-spec-v6. 720 """ 721 for comp_a, comp_b in itertools.zip_longest(a.components, 722 b.components): 723 # If a component type does not exist in one rule 724 # this rule has lower precedence 725 if not comp_a: 726 return B_HAS_PRECEDENCE 727 if not comp_b: 728 return A_HAS_PRECEDENCE 729 # Higher precedence for lower component type 730 if comp_a.component_type < comp_b.component_type: 731 return A_HAS_PRECEDENCE 732 if comp_a.component_type > comp_b.component_type: 733 return B_HAS_PRECEDENCE 734 # component types are equal -> type specific comparison 735 if comp_a.component_type in (IP_DESTINATION, IP_SOURCE): 737 if comp_a.offset < comp_b.offset: 738 return A_HAS_PRECEDENCE 739 if comp_a.offset < comp_b.offset: 740 return B_HAS_PRECEDENCE 741 # both components have the same offset 742 # assuming comp_a.value, comp_b.value of type 743 # ipaddress.IPv6Network 744 # and the offset bits are reset to 0 (since they are 745 # not represented in the NLRI) 746 if comp_a.value.overlaps(comp_b.value): 747 # longest prefixlen has precedence 748 if comp_a.value.prefixlen > \ 749 comp_b.value.prefixlen: 750 return A_HAS_PRECEDENCE 751 if comp_a.value.prefixlen < \ 752 comp_b.value.prefixlen: 753 return B_HAS_PRECEDENCE 754 # components equal -> continue with next 755 # component 756 elif comp_a.value > comp_b.value: 757 return B_HAS_PRECEDENCE 758 elif comp_a.value < comp_b.value: 759 return A_HAS_PRECEDENCE 760 else: 761 # assuming comp_a.value, comp_b.value of type 762 # bytearray 763 if len(comp_a.value) == len(comp_b.value): 764 if comp_a.value > comp_b.value: 765 return B_HAS_PRECEDENCE 766 if comp_a.value < comp_b.value: 767 return A_HAS_PRECEDENCE 768 # components equal -> continue with next 769 # component 770 else: 771 common = min(len(comp_a.value), 772 len(comp_b.value)) 773 if comp_a.value[:common] > \ 774 comp_b.value[:common]: 775 return B_HAS_PRECEDENCE 776 elif comp_a.value[:common] < \ 777 comp_b.value[:common]: 778 return A_HAS_PRECEDENCE 779 # the first common bytes match 780 elif len(comp_a.value) > len(comp_b.value): 781 return A_HAS_PRECEDENCE 782 else: 783 return B_HAS_PRECEDENCE 784 return EQUAL 786 788 Authors' Addresses 790 Christoph Loibl (editor) 791 next layer Telekom GmbH 792 Mariahilfer Guertel 37/7 793 Vienna 1150 794 AT 796 Phone: +43 664 1176414 797 Email: cl@tix.at 799 Robert Raszuk (editor) 800 Bloomberg LP 801 731 Lexington Ave 802 New York City, NY 10022 803 USA 805 Email: robert@raszuk.net 807 Susan Hares (editor) 808 Huawei 809 7453 Hickory Hill 810 Saline, MI 48176 811 USA 813 Email: shares@ndzh.com