idnits 2.17.1 draft-ietf-idr-flow-spec-v6-18.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 1, 2020) is 1270 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 637 == 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 5, 2021 Huawei 8 November 1, 2020 10 Dissemination of Flow Specification Rules for IPv6 11 draft-ietf-idr-flow-spec-v6-18 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 5, 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 . . . . . . . . . . . . . . 5 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 . . . . . . . . . . . . . . . 9 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 . . . . . . . . . . . . . . . . . . . 10 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 In the case Length minus Offset is 0 every address matches. Length 178 MUST always be in the range 0-128 and Length minus Offset MUST always 179 be 0 or more, otherwise this component is malformed. 181 3.2. Type 2 - Source IPv6 Prefix 183 Encoding: 186 Defines the source prefix to match. The length, offset, pattern and 187 padding are the same as in Section 3.1 189 3.3. Type 3 - Upper-Layer Protocol 191 Encoding: 193 Contains a list of {numeric_op, value} pairs that are used to match 194 the first Next Header value octet in IPv6 packets that is not an 195 extension header and thus indicates that the next item in the packet 196 is the corresponding upper-layer header (see [RFC8200] Section 4). 198 This component uses the Numeric Operator (numeric_op) described in 199 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 3 component values 200 SHOULD be encoded as single octet (numeric_op len=00). 202 Note: While IPv6 allows for more than one Next Header field in the 203 packet, the main goal of the Type 3 Flow Specification component is 204 to match on the first upper-layer IP protocol value. Therefore the 205 definition is limited to match only on this specific Next Header 206 field in the packet. 208 3.4. Type 7 - ICMPv6 Type 210 Encoding: 212 Defines a list of {numeric_op, value} pairs used to match the type 213 field of an ICMPv6 packet (see also [RFC4443] Section 2.1). 215 This component uses the Numeric Operator (numeric_op) described in 216 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 7 component values 217 SHOULD be encoded as single octet (numeric_op len=00). 219 In case of the presence of the ICMPv6 Type component only ICMPv6 220 packets can match the entire Flow Specification. The ICMPv6 Type 221 component, if present, never matches when the packet's upper-layer IP 222 protocol value is not 58 (ICMPv6), if the packet is fragmented and 223 this is not the first fragment, or if the system is unable to locate 224 the transport header. Different implementations may or may not be 225 able to decode the transport header. 227 3.5. Type 8 - ICMPv6 Code 229 Encoding: 231 Defines a list of {numeric_op, value} pairs used to match the code 232 field of an ICMPv6 packet (see also [RFC4443] Section 2.1). 234 This component uses the Numeric Operator (numeric_op) described in 235 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 8 component values 236 SHOULD be encoded as single octet (numeric_op len=00). 238 In case of the presence of the ICMPv6 Code component only ICMPv6 239 packets can match the entire Flow Specification. The ICMPv6 code 240 component, if present, never matches when the packet's upper-layer IP 241 protocol value is not 58 (ICMPv6), if the packet is fragmented and 242 this is not the first fragment, or if the system is unable to locate 243 the transport header. Different implementations may or may not be 244 able to decode the transport header. 246 3.6. Type 12 - Fragment 248 Encoding: 250 Defines a list of {bitmask_op, bitmask} pairs used to match specific 251 IP fragments. 253 This component uses the Bitmask Operator (bitmask_op) described in 254 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.2. The Type 12 component 255 bitmask MUST be encoded as single octet bitmask (bitmask_op len=00). 257 0 1 2 3 4 5 6 7 258 +---+---+---+---+---+---+---+---+ 259 | 0 | 0 | 0 | 0 |LF |FF |IsF| 0 | 260 +---+---+---+---+---+---+---+---+ 262 Figure 1: Fragment Bitmask Operand 264 Bitmask values: 266 IsF - Is a fragment other than the first - match if IPv6 Fragment 267 Header ([RFC8200] Section 4.5) Fragment Offset is not 0 269 FF - First fragment - match if IPv6 Fragment Header ([RFC8200] 270 Section 4.5) Fragment Offset is 0 AND M flag is 1 272 LF - Last fragment - match if IPv6 Fragment Header ([RFC8200] 273 Section 4.5) Fragment Offset is not 0 AND M flag is 0 275 0 - MUST be set to 0 on NLRI encoding, and MUST be ignored during 276 decoding 278 3.7. Type 13 - Flow Label (new) 280 Encoding: 282 Contains a list of {numeric_op, value} pairs that are used to match 283 the 20-bit Flow Label IPv6 header field ([RFC8200] Section 3). 285 This component uses the Numeric Operator (numeric_op) described in 286 [I-D.ietf-idr-rfc5575bis] Section 4.2.1.1. Type 13 component values 287 SHOULD be encoded as 1-, 2-, or 4-byte quantities (numeric_op len=00, 288 len=01 or len=10). 290 3.8. Encoding Example 292 3.8.1. Example 1 294 The following example demonstrates the prefix encoding for: "packets 295 from ::1234:5678:9A00:0/64-104 to 2001:DB8::/32 and upper-layer- 296 protocol tcp". 298 +--------+----------------------+-------------------------+----------+ 299 | length | destination | source | ul-proto | 300 +--------+----------------------+-------------------------+----------+ 301 | 0x12 | 01 20 00 20 01 0D B8 | 02 68 40 12 34 56 78 9A | 03 81 06 | 302 +--------+----------------------+-------------------------+----------+ 304 Decoded: 306 +-------+------------+-------------------------------+ 307 | Value | | | 308 +-------+------------+-------------------------------+ 309 | 0x12 | length | 18 octets (len<240 1-octet) | 310 | 0x01 | type | Type 1 - Dest. IPv6 Prefix | 311 | 0x20 | length | 32 bit | 312 | 0x00 | offset | 0 bit | 313 | 0x20 | pattern | | 314 | 0x01 | pattern | | 315 | 0x0D | pattern | | 316 | 0xB8 | pattern | (no padding needed) | 317 | 0x02 | type | Type 2 - Source IPv6 Prefix | 318 | 0x68 | length | 104 bit | 319 | 0x40 | offset | 64 bit | 320 | 0x12 | pattern | | 321 | 0x34 | pattern | | 322 | 0x56 | pattern | | 323 | 0x78 | pattern | | 324 | 0x9A | pattern | (no padding needed) | 325 | 0x03 | type | Type 3 - upper-layer-proto | 326 | 0x81 | numeric_op | end-of-list, value size=1, == | 327 | 0x06 | value | 06 | 328 +-------+------------+-------------------------------+ 330 This constitutes a NLRI with a NLRI length of 18 octets. 332 Padding is not needed either for the destination prefix pattern 333 (length - offset = 32 bit) or for the source prefix pattern (length - 334 offset = 40 bit), as both patterns end on an octet boundary. 336 3.8.2. Example 2 338 The following example demonstrates the prefix encoding for: "all 339 packets from ::1234:5678:9A00:0/65-104 to 2001:DB8::/32". 341 +--------+----------------------+-------------------------+ 342 | length | destination | source | 343 +--------+----------------------+-------------------------+ 344 | 0x0f | 01 20 00 20 01 0D B8 | 02 68 41 24 68 ac f1 34 | 345 +--------+----------------------+-------------------------+ 347 Decoded: 349 +-------+-------------+-------------------------------+ 350 | Value | | | 351 +-------+-------------+-------------------------------+ 352 | 0x0f | length | 15 octets (len<240 1-octet) | 353 | 0x01 | type | Type 1 - Dest. IPv6 Prefix | 354 | 0x20 | length | 32 bit | 355 | 0x00 | offset | 0 bit | 356 | 0x20 | pattern | | 357 | 0x01 | pattern | | 358 | 0x0D | pattern | | 359 | 0xB8 | pattern | (no padding needed) | 360 | 0x02 | type | Type 2 - Source IPv6 Prefix | 361 | 0x68 | length | 104 bit | 362 | 0x41 | offset | 65 bit | 363 | 0x24 | pattern | | 364 | 0x68 | pattern | | 365 | 0xac | pattern | | 366 | 0xf1 | pattern | | 367 | 0x34 | pattern/pad | (contains 1 bit padding) | 368 +-------+-------------+-------------------------------+ 370 This constitutes a NLRI with a NLRI length of 15 octets. 372 The source prefix pattern is 104 - 65 = 39 bits in length. After the 373 pattern one bit of padding needs to be added so that the component 374 ends on a octet boundary. However, only the first 39 bits are 375 actually used for bitwise pattern matching starting with a 65 bit 376 offset from the topmost bit of the address. 378 4. Ordering of Flow Specifications 380 The definition for the order of traffic filtering rules from 381 [I-D.ietf-idr-rfc5575bis] Section 5.1 is reused with new 382 consideration for the IPv6 prefix offset. As long as the offsets are 383 equal, the comparison is the same, retaining longest-prefix-match 384 semantics. If the offsets are not equal, the lowest offset has 385 precedence, as this flow matches the most significant bit. 387 The code in Appendix A shows a Python3 implementation of the 388 resulting comparison algorithm. The full code was tested with Python 389 3.7.2 and can be obtained at https://github.com/stoffi92/draft-ietf- 390 idr-flow-spec-v6/tree/master/flowspec-cmp [1]. 392 5. Validation Procedure 394 The validation procedure is the same as specified in 395 [I-D.ietf-idr-rfc5575bis] Section 6 with the exception that item a) 396 of the validation procedure should now read as follows: 398 a) A destination prefix component with offset=0 is embedded in the 399 Flow Specification 401 6. IPv6 Traffic Filtering Action changes 403 Traffic Filtering Actions from [I-D.ietf-idr-rfc5575bis] Section 7 404 can also be applied to IPv6 Flow Specifications. To allow an IPv6 405 address specific route-target, a new Traffic Filtering Action IPv6 406 address specific extended community is specified in Section 6.1 407 below. 409 6.1. Redirect IPv6 (rt-redirect-ipv6) Type/Sub-Type 0x80/TBD 411 The redirect IPv6 address specific extended community allows the 412 traffic to be redirected to a VRF routing instance that lists the 413 specified IPv6 address specific route-target in its import policy. 414 If several local instances match this criteria, the choice between 415 them is a local matter (for example, the instance with the lowest 416 Route Distinguisher value can be elected). 418 This extended community uses the same encoding as the IPv6 address 419 specific Route Target extended community [RFC5701] Section 2 with the 420 high-order octet of the Type always set to 0x80 and the Sub-Type 421 always TBD. 423 Interferes with: All BGP Flow Specification redirect Traffic 424 Filtering Actions (with itself and those specified in 425 [I-D.ietf-idr-rfc5575bis] Section 7.4). 427 7. Security Considerations 429 This document extends the functionality in [I-D.ietf-idr-rfc5575bis] 430 to be applicable to IPv6 data packets. The same Security 431 Considerations from [I-D.ietf-idr-rfc5575bis] now also apply to IPv6 432 networks. Otherwise, no new security issues are added to the BGP 433 protocol. 435 8. IANA Considerations 437 This section complies with [RFC7153]. 439 8.1. Flow Spec IPv6 Component Types 441 IANA has created and maintains a registry entitled "Flow Spec 442 Component Types". IANA is requested to add [this document] to the 443 reference for this registry. Furthermore the registry should be 444 rewritten to also contain the IPv6 Flow Specification Component Types 445 as described below. The registration procedure should remain 446 unchanged. 448 8.1.1. Registry Template 450 Type Value: 451 Contains the assigned Flow Specification component type value. 453 IPv4 Name: 454 Contains the associated IPv4 Flow Specification component name 455 as specified in [I-D.ietf-idr-rfc5575bis]. 457 IPv6 Name: 458 Contains the associated IPv6 Flow Specification component name 459 as specified in this document. 461 Reference: 462 Contains referenced to the specifications. 464 8.1.2. Registry Contents 466 + Type Value: 0 467 + IPv4 Name: Reserved 468 + IPv6 Name: Reserved 469 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 471 + Type Value: 1 472 + IPv4 Name: Destination Prefix 473 + IPv6 Name: Destination IPv6 Prefix 474 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 476 + Type Value: 2 477 + IPv4 Name: Source Prefix 478 + IPv6 Name: Source IPv6 Prefix 479 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 481 + Type Value: 3 482 + IPv4 Name: IP Protocol 483 + IPv6 Name: Upper-Layer Protocol 484 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 486 + Type Value: 4 487 + IPv4 Name: Port 488 + IPv6 Name: Port 489 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 491 + Type Value: 5 492 + IPv4 Name: Destination Port 493 + IPv6 Name: Destination Port 494 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 496 + Type Value: 6 497 + IPv4 Name: Source Port 498 + IPv6 Name: Source Port 499 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 501 + Type Value: 7 502 + IPv4 Name: ICMP Type 503 + IPv6 Name: ICMPv6 Type 504 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 506 + Type Value: 8 507 + IPv4 Name: ICMP Code 508 + IPv6 Name: ICMPv6 Code 509 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 511 + Type Value: 9 512 + IPv4 Name: TCP flags 513 + IPv6 Name: TCP flags 514 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 516 + Type Value: 10 517 + IPv4 Name: Packet length 518 + IPv6 Name: Packet length 519 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 521 + Type Value: 11 522 + IPv4 Name: DSCP 523 + IPv6 Name: DSCP 524 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 526 + Type Value: 12 527 + IPv4 Name: Fragment 528 + IPv6 Name: Fragment 529 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 531 + Type Value: 13 532 + IPv4 Name: Unassigned 533 + IPv6 Name: Flow Label 534 + Reference: [this document] 536 + Type Value: 14-254 537 + IPv4 Name: Unassigned 538 + IPv6 Name: Unassigned 539 + Reference: 541 + Type Value: 255 542 + IPv4 Name: Reserved 543 + IPv6 Name: Reserved 544 + Reference: [I-D.ietf-idr-rfc5575bis] [this document] 546 8.2. Extended Community Flow Spec IPv6 Actions 548 IANA maintains a registry entitled "Generic Transitive Experimental 549 Use Extended Community Sub-Types". For the purpose of this work, 550 IANA is requested to assign a new value: 552 +----------------+--------------------------------+-----------------+ 553 | Sub-Type Value | Name | Reference | 554 +----------------+--------------------------------+-----------------+ 555 | TBD | Flow spec rt-redirect-ipv6 | [this document] | 556 | | format | | 557 +----------------+--------------------------------+-----------------+ 559 Table 1: Registry: Generic Transitive Experimental Use Extended 560 Community Sub-Types 562 9. Acknowledgements 564 Authors would like to thank Pedro Marques, Hannes Gredler, Bruno 565 Rijsman, Brian Carpenter, and Thomas Mangin for their valuable input. 567 10. Contributors 569 Danny McPherson 570 Verisign, Inc. 572 Email: dmcpherson@verisign.com 574 Burjiz Pithawala 575 Individual 577 Email: burjizp@gmail.com 579 Andy Karch 580 Cisco Systems 581 170 West Tasman Drive 582 San Jose, CA 95134 583 USA 585 Email: akarch@cisco.com 587 11. References 589 11.1. Normative References 591 [I-D.ietf-idr-rfc5575bis] 592 Loibl, C., Hares, S., Raszuk, R., McPherson, D., and M. 593 Bacher, "Dissemination of Flow Specification Rules", 594 draft-ietf-idr-rfc5575bis-26 (work in progress), August 595 2020. 597 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 598 Requirement Levels", BCP 14, RFC 2119, 599 DOI 10.17487/RFC2119, March 1997, 600 . 602 [RFC4271] Rekhter, Y., Ed., Li, T., Ed., and S. Hares, Ed., "A 603 Border Gateway Protocol 4 (BGP-4)", RFC 4271, 604 DOI 10.17487/RFC4271, January 2006, 605 . 607 [RFC4443] Conta, A., Deering, S., and M. Gupta, Ed., "Internet 608 Control Message Protocol (ICMPv6) for the Internet 609 Protocol Version 6 (IPv6) Specification", STD 89, 610 RFC 4443, DOI 10.17487/RFC4443, March 2006, 611 . 613 [RFC4760] Bates, T., Chandra, R., Katz, D., and Y. Rekhter, 614 "Multiprotocol Extensions for BGP-4", RFC 4760, 615 DOI 10.17487/RFC4760, January 2007, 616 . 618 [RFC5701] Rekhter, Y., "IPv6 Address Specific BGP Extended Community 619 Attribute", RFC 5701, DOI 10.17487/RFC5701, November 2009, 620 . 622 [RFC7153] Rosen, E. and Y. Rekhter, "IANA Registries for BGP 623 Extended Communities", RFC 7153, DOI 10.17487/RFC7153, 624 March 2014, . 626 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 627 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 628 May 2017, . 630 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 631 (IPv6) Specification", STD 86, RFC 8200, 632 DOI 10.17487/RFC8200, July 2017, 633 . 635 11.2. URIs 637 [1] https://github.com/stoffi92/draft-ietf-idr-flow-spec- 638 v6/tree/master/flowspec-cmp 640 Appendix A. Example python code: flow_rule_cmp_v6 642 643 """ 644 Copyright (c) 2020 IETF Trust and the persons identified as authors 645 of draft-ietf-idr-flow-spec-v6. All rights reserved. 647 Redistribution and use in source and binary forms, with or without 648 modification, is permitted pursuant to, and subject to the license 649 terms contained in, the Simplified BSD License set forth in Section 650 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents 651 (http://trustee.ietf.org/license-info). 652 """ 654 import itertools 655 import collections 656 import ipaddress 658 EQUAL = 0 659 A_HAS_PRECEDENCE = 1 660 B_HAS_PRECEDENCE = 2 661 IP_DESTINATION = 1 662 IP_SOURCE = 2 664 FS_component = collections.namedtuple('FS_component', 665 'component_type value') 667 class FS_IPv6_prefix_component: 668 def __init__(self, prefix, offset=0, 669 component_type=IP_DESTINATION): 670 self.offset = offset 671 self.component_type = component_type 672 # make sure if offset != 0 that non of the 673 # first offset bits are set in the prefix 674 self.value = prefix 675 if offset != 0: 676 i = ipaddress.IPv6Interface( 677 (self.value.network_address, offset)) 678 if i.network.network_address != \ 679 ipaddress.ip_address('0::0'): 680 raise ValueError('Bits set in the offset') 682 class FS_nlri(object): 683 """ 684 FS_nlri class implementation that allows sorting. 686 By calling .sort() on a array of FS_nlri objects these 687 will be sorted according to the flow_rule_cmp algorithm. 689 Example: 691 nlri = [ FS_nlri(components=[ 692 FS_component(component_type=4, 693 value=bytearray([0,1,2,3,4,5,6])), 694 ]), 695 FS_nlri(components=[ 696 FS_component(component_type=5, 697 value=bytearray([0,1,2,3,4,5,6])), 698 FS_component(component_type=6, 699 value=bytearray([0,1,2,3,4,5,6])), 700 ]), 701 ] 702 nlri.sort() # sorts the array accorinding to the algorithm 703 """ 704 def __init__(self, components = None): 705 """ 706 components: list of type FS_component 707 """ 708 self.components = components 710 def __lt__(self, other): 711 # use the below algorithm for sorting 712 result = flow_rule_cmp_v6(self, other) 713 if result == B_HAS_PRECEDENCE: 714 return True 715 else: 716 return False 718 def flow_rule_cmp_v6(a, b): 719 """ 720 Implementation of the flowspec sorting algorithm in 721 draft-ietf-idr-flow-spec-v6. 722 """ 723 for comp_a, comp_b in itertools.zip_longest(a.components, 724 b.components): 725 # If a component type does not exist in one rule 726 # this rule has lower precedence 727 if not comp_a: 728 return B_HAS_PRECEDENCE 729 if not comp_b: 730 return A_HAS_PRECEDENCE 731 # Higher precedence for lower component type 732 if comp_a.component_type < comp_b.component_type: 733 return A_HAS_PRECEDENCE 734 if comp_a.component_type > comp_b.component_type: 735 return B_HAS_PRECEDENCE 736 # component types are equal -> type specific comparison 737 if comp_a.component_type in (IP_DESTINATION, IP_SOURCE): 739 if comp_a.offset < comp_b.offset: 740 return A_HAS_PRECEDENCE 741 if comp_a.offset < comp_b.offset: 742 return B_HAS_PRECEDENCE 743 # both components have the same offset 744 # assuming comp_a.value, comp_b.value of type 745 # ipaddress.IPv6Network 746 # and the offset bits are reset to 0 (since they are 747 # not represented in the NLRI) 748 if comp_a.value.overlaps(comp_b.value): 749 # longest prefixlen has precedence 750 if comp_a.value.prefixlen > \ 751 comp_b.value.prefixlen: 752 return A_HAS_PRECEDENCE 753 if comp_a.value.prefixlen < \ 754 comp_b.value.prefixlen: 755 return B_HAS_PRECEDENCE 756 # components equal -> continue with next 757 # component 758 elif comp_a.value > comp_b.value: 759 return B_HAS_PRECEDENCE 760 elif comp_a.value < comp_b.value: 761 return A_HAS_PRECEDENCE 762 else: 763 # assuming comp_a.value, comp_b.value of type 764 # bytearray 765 if len(comp_a.value) == len(comp_b.value): 766 if comp_a.value > comp_b.value: 767 return B_HAS_PRECEDENCE 768 if comp_a.value < comp_b.value: 769 return A_HAS_PRECEDENCE 770 # components equal -> continue with next 771 # component 772 else: 773 common = min(len(comp_a.value), 774 len(comp_b.value)) 775 if comp_a.value[:common] > \ 776 comp_b.value[:common]: 777 return B_HAS_PRECEDENCE 778 elif comp_a.value[:common] < \ 779 comp_b.value[:common]: 780 return A_HAS_PRECEDENCE 781 # the first common bytes match 782 elif len(comp_a.value) > len(comp_b.value): 783 return A_HAS_PRECEDENCE 784 else: 785 return B_HAS_PRECEDENCE 786 return EQUAL 788 790 Authors' Addresses 792 Christoph Loibl (editor) 793 next layer Telekom GmbH 794 Mariahilfer Guertel 37/7 795 Vienna 1150 796 AT 798 Phone: +43 664 1176414 799 Email: cl@tix.at 801 Robert Raszuk (editor) 802 Bloomberg LP 803 731 Lexington Ave 804 New York City, NY 10022 805 USA 807 Email: robert@raszuk.net 809 Susan Hares (editor) 810 Huawei 811 7453 Hickory Hill 812 Saline, MI 48176 813 USA 815 Email: shares@ndzh.com