idnits 2.17.1 draft-ietf-core-block-06.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 : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (January 21, 2012) is 4471 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) == Missing Reference: 'RFCXXXX' is mentioned on line 791, but not defined == Outdated reference: A later version (-18) exists of draft-ietf-core-coap-08 ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) Summary: 1 error (**), 0 flaws (~~), 3 warnings (==), 1 comment (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 CoRE Working Group C. Bormann 3 Internet-Draft Universitaet Bremen TZI 4 Intended status: Standards Track Z. Shelby, Ed. 5 Expires: July 24, 2012 Sensinode 6 January 21, 2012 8 Blockwise transfers in CoAP 9 draft-ietf-core-block-06 11 Abstract 13 CoAP is a RESTful transfer protocol for constrained nodes and 14 networks. Basic CoAP messages work well for the small payloads we 15 expect from temperature sensors, light switches, and similar 16 building-automation devices. Occasionally, however, applications 17 will need to transfer larger payloads -- for instance, for firmware 18 updates. With HTTP, TCP does the grunt work of slicing large 19 payloads up into multiple packets and ensuring that they all arrive 20 and are handled in the right order. 22 CoAP is based on datagram transports such as UDP or DTLS, which 23 limits the maximum size of resource representations that can be 24 transferred without too much fragmentation. Although UDP supports 25 larger payloads through IP fragmentation, it is limited to 64 KiB 26 and, more importantly, doesn't really work well for constrained 27 applications and networks. 29 Instead of relying on IP fragmentation, this specification extends 30 basic CoAP with a pair of "Block" options, for transferring multiple 31 blocks of information from a resource representation in multiple 32 request-response pairs. In many important cases, the Block options 33 enable a server to be truly stateless: the server can handle each 34 block transfer separately, with no need for a connection setup or 35 other server-side memory of previous block transfers. 37 In summary, the Block options provide a minimal way to transfer 38 larger representations in a block-wise fashion. 40 Status of this Memo 42 This Internet-Draft is submitted in full conformance with the 43 provisions of BCP 78 and BCP 79. 45 Internet-Drafts are working documents of the Internet Engineering 46 Task Force (IETF). Note that other groups may also distribute 47 working documents as Internet-Drafts. The list of current Internet- 48 Drafts is at http://datatracker.ietf.org/drafts/current/. 50 Internet-Drafts are draft documents valid for a maximum of six months 51 and may be updated, replaced, or obsoleted by other documents at any 52 time. It is inappropriate to use Internet-Drafts as reference 53 material or to cite them other than as "work in progress." 55 This Internet-Draft will expire on July 24, 2012. 57 Copyright Notice 59 Copyright (c) 2012 IETF Trust and the persons identified as the 60 document authors. All rights reserved. 62 This document is subject to BCP 78 and the IETF Trust's Legal 63 Provisions Relating to IETF Documents 64 (http://trustee.ietf.org/license-info) in effect on the date of 65 publication of this document. Please review these documents 66 carefully, as they describe your rights and restrictions with respect 67 to this document. Code Components extracted from this document must 68 include Simplified BSD License text as described in Section 4.e of 69 the Trust Legal Provisions and are provided without warranty as 70 described in the Simplified BSD License. 72 Table of Contents 74 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 75 2. Block-wise transfers . . . . . . . . . . . . . . . . . . . . . 6 76 2.1. The Block Options . . . . . . . . . . . . . . . . . . . . 6 77 2.2. Using the Block Options . . . . . . . . . . . . . . . . . 10 78 3. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 79 4. HTTP Mapping Considerations . . . . . . . . . . . . . . . . . 19 80 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 21 81 6. Security Considerations . . . . . . . . . . . . . . . . . . . 22 82 6.1. Mitigating Resource Exhaustion Attacks . . . . . . . . . . 22 83 6.2. Mitigating Amplification Attacks . . . . . . . . . . . . . 23 84 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 24 85 8. References . . . . . . . . . . . . . . . . . . . . . . . . . . 25 86 8.1. Normative References . . . . . . . . . . . . . . . . . . . 25 87 8.2. Informative References . . . . . . . . . . . . . . . . . . 25 88 Appendix A. Historical Note . . . . . . . . . . . . . . . . . . . 26 89 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 27 91 1. Introduction 93 The CoRE WG is tasked with standardizing an Application Protocol for 94 Constrained Networks/Nodes, CoAP. This protocol is intended to 95 provide RESTful [REST] services not unlike HTTP [RFC2616], while 96 reducing the complexity of implementation as well as the size of 97 packets exchanged in order to make these services useful in a highly 98 constrained network of themselves highly constrained nodes. 100 This objective requires restraint in a number of sometimes 101 conflicting ways: 103 o reducing implementation complexity in order to minimize code size, 105 o reducing message sizes in order to minimize the number of 106 fragments needed for each message (in turn to maximize the 107 probability of delivery of the message), the amount of 108 transmission power needed and the loading of the limited-bandwidth 109 channel, 111 o reducing requirements on the environment such as stable storage, 112 good sources of randomness or user interaction capabilities. 114 CoAP is based on datagram transports such as UDP, which limit the 115 maximum size of resource representations that can be transferred 116 without creating unreasonable levels of IP fragmentation. In 117 addition, not all resource representations will fit into a single 118 link layer packet of a constrained network, which may cause 119 adaptation layer fragmentation even if IP layer fragmentation is not 120 required. Using fragmentation (either at the adaptation layer or at 121 the IP layer) to enable the transport of larger representations is 122 possible up to the maximum size of the underlying datagram protocol 123 (such as UDP), but the fragmentation/reassembly process burdens the 124 lower layers with conversation state that is better managed in the 125 application layer. 127 This specification defines a pair of CoAP options to enable _block- 128 wise_ access to resource representations. The Block options provide 129 a minimal way to transfer larger resource representations in a block- 130 wise fashion. The overriding objective is to avoid creating 131 conversation state at the server for block-wise GET requests. (It is 132 impossible to fully avoid creating conversation state for POST/PUT, 133 if the creation/replacement of resources is to be atomic; where that 134 property is not needed, there is no need to create server 135 conversation state in this case, either.) 137 In summary, this specification adds a pair of Block options to CoAP 138 that can be used for block-wise transfers. Benefits of using these 139 options include: 141 o Transfers larger than can be accommodated in constrained-network 142 link-layer packets can be performed in smaller blocks. 144 o No hard-to-manage conversation state is created at the adaptation 145 layer or IP layer for fragmentation. 147 o The transfer of each block is acknowledged, enabling 148 retransmission if required. 150 o Both sides have a say in the block size that actually will be 151 used. 153 o The resulting exchanges are easy to understand using packet 154 analyzer tools and thus quite accessible to debugging. 156 o If needed, the Block options can also be used as is to provide 157 random access to power-of-two sized blocks within a resource 158 representation. 160 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 161 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 162 document are to be interpreted as described in RFC 2119, BCP 14 163 [RFC2119] and indicate requirement levels for compliant CoAP 164 implementations. 166 In this document, the term "byte" is used in its now customary sense 167 as a synonym for "octet". 169 Where bit arithmetic is explained, this document uses the notation 170 familiar from the programming language C, except that the operator 171 "**" stands for exponentiation. 173 2. Block-wise transfers 175 As discussed in the introduction, there are good reasons to limit the 176 size of datagrams in constrained networks: 178 o by the maximum datagram size (~ 64 KiB for UDP) 180 o by the desire to avoid IP fragmentation (MTU of 1280 for IPv6) 182 o by the desire to avoid adaptation layer fragmentation (60-80 bytes 183 for 6LoWPAN [RFC4919]) 185 When a resource representation is larger than can be comfortably 186 transferred in the payload of a single CoAP datagram, a Block option 187 can be used to indicate a block-wise transfer. As payloads can be 188 sent both with requests and with responses, this specification 189 provides two separate options for each direction of payload transfer. 191 In the following, the term "payload" will be used for the actual 192 content of a single CoAP message, i.e. a single block being 193 transferred, while the term "body" will be used for the entire 194 resource representation that is being transferred in a block-wise 195 fashion. 197 In most cases, all blocks being transferred for a body will be of the 198 same size. The block size is not fixed by the protocol. To keep the 199 implementation as simple as possible, the Block options support only 200 a small range of power-of-two block sizes, from 2**4 (16) to 2**10 201 (1024) bytes. As bodies often will not evenly divide into the power- 202 of-two block size chosen, the size need not be reached in the final 203 block (but even for the final block, the chosen power-of-two size 204 will still be indicated in the block size field of the Block option). 206 2.1. The Block Options 208 +------+----------+--------+--------+--------+---------------+ 209 | Type | C/E | Name | Format | Length | Default | 210 +------+----------+--------+--------+--------+---------------+ 211 | 19 | Critical | Block1 | uint | 1-3 B | 0 (see below) | 212 | | | | | | | 213 | 17 | Critical | Block2 | uint | 1-3 B | 0 (see below) | 214 +------+----------+--------+--------+--------+---------------+ 216 Table 1: Block Option Numbers 218 Both Block1 and Block2 options can be present both in request and 219 response messages. In either case, the Block1 Option pertains to the 220 request payload, and the Block2 Option pertains to the response 221 payload. 223 Hence, for the methods defined in [I-D.ietf-core-coap], Block1 is 224 useful with the payload-bearing POST and PUT requests and their 225 responses. Block2 is useful with GET, POST, and PUT requests and 226 their payload-bearing responses (2.01, 2.02, 2.04, 2.05 -- see 227 section "Payload" of [I-D.ietf-core-coap]). 229 (As a memory aid: Block_1_ pertains to the payload of the _1st_ part 230 of the request-response exchange, i.e. the request, and Block_2_ 231 pertains to the payload of the _2nd_ part of the request-response 232 exchange, i.e. the response.) 234 Where Block1 is present in a request or Block2 in a response (i.e., 235 in that message to the payload of which it pertains) it indicates a 236 block-wise transfer and describes how this block-wise payload forms 237 part of the entire body being transferred ("descriptive usage"). 238 Where it is present in the opposite direction, it provides additional 239 control on how that payload will be formed or was processed ("control 240 usage"). 242 Implementation of either Block option is intended to be optional. 243 However, when it is present in a CoAP message, it MUST be processed 244 (or the message rejected); therefore it is identified as a critical 245 option. 247 Three items of information may need to be transferred in a Block 248 option: 250 o The size of the block (SZX); 252 o whether more blocks are following (M); 254 o the relative number of the block (NUM) within a sequence of blocks 255 with the given size. 257 The value of the option is a 1-, 2- or 3-byte integer which encodes 258 these three fields, see Figure 1. 260 0 261 0 1 2 3 4 5 6 7 262 +-+-+-+-+-+-+-+-+ 263 | NUM |M| SZX | 264 +-+-+-+-+-+-+-+-+ 266 0 1 267 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 268 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 269 | NUM |M| SZX | 270 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 272 0 1 2 273 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 274 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 275 | NUM |M| SZX | 276 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 278 Figure 1: Block option value 280 The block size is encoded as a three-bit unsigned integer (0 for 2**4 281 to 6 for 2**10 bytes), which we call the "SZX" (size exponent); the 282 actual block size is then "2**(SZX + 4)". SZX is transferred in the 283 three least significant bits of the option value (i.e., "val & 7" 284 where "val" is the value of the option). 286 The fourth least significant bit, the M or "more" bit ("val & 8"), 287 indicates whether more blocks are following or the current block-wise 288 transfer is the last block being transferred. 290 The option value divided by sixteen (the NUM field) is the sequence 291 number of the block currently being transferred, starting from zero. 292 The current transfer is therefore about the "size" bytes starting at 293 byte "NUM << (SZX + 4)". (Note that, as an implementation 294 convenience, "(val & ~0xF) << (val & 7)", i.e. the option value with 295 the last 4 bits masked out, shifted to the left by the value of SZX, 296 gives the byte position of the block.) 298 The default value of both the Block1 and the Block2 Option is zero, 299 indicating that the current block is the first and only block of the 300 transfer (block number 0, M bit not set); however, there is no 301 explicit size implied by this default value. 303 More specifically, within the option value of a Block1 or Block2 304 Option, the meaning of the option fields is defined as follows: 306 NUM: Block Number. The block number is a variable-size (4, 12, or 307 20 bit) unsigned integer (uint, see Appendix A of 308 [I-D.ietf-core-coap]) indicating the block number being requested 309 or provided. Block number 0 indicates the first block of a body. 311 M: More Flag (not last block). For descriptive usage, this flag, if 312 unset, indicates that the payload in this message is the last 313 block in the body; when set it indicates that there are one or 314 more additional blocks available. When a Block2 Option is used in 315 a request to retrieve a specific block number ("control usage"), 316 the M bit MUST be sent as zero and ignored on reception. (In a 317 Block1 Option in a response, the M flag is used to indicate 318 atomicity, see below.) 320 SZX: Block Size. The block size is a three-bit unsigned integer 321 indicating the size of a block to the power of two. Thus block 322 size = 2**(SZX + 4). The allowed values of SZX are 0 to 6, i.e., 323 the minimum block size is 2**(0+4) = 16 and the maximum is 324 2**(6+4) = 1024. The value 7 for SZX (which would indicate a 325 block size of 2048) is reserved, i.e. MUST NOT be sent and MUST 326 lead to a 4.00 Bad Request response code upon reception in a 327 request. 329 The Block options are used in one of three roles: 331 o In descriptive usage, i.e. a Block2 Option in a response (e.g., a 332 2.05 response for GET), or a Block1 Option in a request (e.g., PUT 333 or POST): 335 * The NUM field in the option value describes what block number 336 is contained in the payload of this message. 338 * The M bit indicates whether further blocks are required to 339 complete the transfer of that body. 341 * The block size given by SZX MUST match the size of the payload 342 in bytes, if the M bit is set. (SZX does not govern the 343 payload size if M is unset). For Block2, if the request 344 suggested a larger value of SZX, the next request MUST move SZX 345 down to the size given here. (The effect is that, if the 346 server uses the smaller of its preferred block size and the one 347 requested, all blocks for a body use the same block size.) 349 o A Block2 Option in control usage in a request (e.g., GET): 351 * The NUM field in the Block2 Option gives the block number of 352 the payload that is being requested to be returned in the 353 response. 355 * In this case, the M bit has no function and MUST be set to 356 zero. 358 * The block size given (SZX) suggests a block size (in the case 359 of block number 0) or repeats the block size of previous blocks 360 received (in the case of block numbers other than 0). 362 o A Block1 Option in control usage in a response (e.g., a 2.xx 363 response for a PUT or POST request): 365 * The NUM field of the Block1 Option indicates what block number 366 is being acknowledged. 368 * If the M bit was set in the request, the server can choose 369 whether to act on each block separately, with no memory, or 370 whether to handle the request for the entire body atomically, 371 or any mix of the two. If the M bit is also set in the 372 response, it indicates that this response does not carry the 373 final response code to the request, i.e. the server collects 374 further blocks and plans to implement the request atomically 375 (e.g., acts only upon reception of the last block of payload). 376 Conversely, if the M bit is unset even though it was set in the 377 request, it indicates the block-wise request was enacted now 378 specifically for this block, and the response carries the final 379 response to this request (and to any previous ones with the M 380 bit set in the response's Block1 Option in this sequence of 381 block-wise transfers); the client is still expected to continue 382 sending further blocks, the request method for which may or may 383 not also be enacted per-block. 385 * Finally, the SZX block size given in a control Block1 Option 386 indicates the largest block size preferred by the server for 387 transfers toward the resource that is the same or smaller than 388 the one used in the initial exchange; the client SHOULD use 389 this block size or a smaller one in all further requests in the 390 transfer sequence, even if that means changing the block size 391 (and possibly scaling the block number accordingly) from now 392 on. 394 2.2. Using the Block Options 396 Using one or both Block options, a single REST operation can be split 397 into multiple CoAP message exchanges. As specified in 398 [I-D.ietf-core-coap], each of these message exchanges uses their own 399 CoAP Message ID. 401 When a request is answered with a response carrying a Block2 Option 402 with the M bit set, the requester may retrieve additional blocks of 403 the resource representation by sending further requests with the same 404 options and a Block2 Option giving the block number and block size 405 desired. In a request, the client MUST set the M bit of a Block2 406 Option to zero and the server MUST ignore it on reception. 408 To influence the block size used in a response, the requester also 409 uses the Block2 Option, giving the desired size, a block number of 410 zero and an M bit of zero. A server MUST use the block size 411 indicated or a smaller size. Any further block-wise requests for 412 blocks beyond the first one MUST indicate the same block size that 413 was used by the server in the response for the first request that 414 gave a desired size using a Block2 Option. 416 Once the Block2 Option is used by the requester, all requests in a 417 single block-wise transfer MUST ultimately use the same size, except 418 that there may not be enough content to fill the last block (the one 419 returned with the M bit not set). (Note that the client may start 420 using the Block2 Option in a second request after a first request 421 without a Block2 Option resulted in a Block option in the response.) 422 The server SHOULD use the block size indicated in the request option 423 or a smaller size, but the requester MUST take note of the actual 424 block size used in the response it receives to its initial request 425 and proceed to use it in subsequent requests. The server behavior 426 MUST ensure that this client behavior results in the same block size 427 for all responses in a sequence (except for the last one with the M 428 bit not set, and possibly the first one if the initial request did 429 not contain a Block2 Option). 431 Block-wise transfers can be used to GET resources the representations 432 of which are entirely static (not changing over time at all, such as 433 in a schema describing a device), or for dynamically changing 434 resources. In the latter case, the Block2 Option SHOULD be used in 435 conjunction with the ETag Option, to ensure that the blocks being 436 reassembled are from the same version of the representation: The 437 server SHOULD include an ETag option in each response. If an ETag 438 option is available, the client's reassembler, when reassembling the 439 representation from the blocks being exchanged, MUST compare ETag 440 Options. If the ETag Options do not match in a GET transfer, the 441 requester has the option of attempting to retrieve fresh values for 442 the blocks it retrieved first. To minimize the resulting 443 inefficiency, the server MAY cache the current value of a 444 representation for an ongoing sequence of requests. The client MAY 445 facilitate identifying the sequence by using the Token Option with a 446 non-default value. Note well that this specification makes no 447 requirement for the server to establish any state; however, servers 448 that offer quickly changing resources may thereby make it impossible 449 for a client to ever retrieve a consistent set of blocks. 451 In a request with a request payload (e.g., PUT or POST), the Block1 452 Option refers to the payload in the request (descriptive usage). 454 In response to a request with a payload (e.g., a PUT or POST 455 transfer), the block size given in the Block1 Option indicates the 456 block size preference of the server for this resource (control 457 usage). Obviously, at this point the first block has already been 458 transferred by the client without benefit of this knowledge. Still, 459 the client SHOULD heed the preference and, for all further blocks, 460 use the block size preferred by the server or a smaller one. Note 461 that any reduction in the block size may mean that the second request 462 starts with a block number larger than one, as the first request 463 already transferred multiple blocks as counted in the smaller size. 465 To counter the effects of adaptation layer fragmentation on packet 466 delivery probability, a client may want to give up retransmitting a 467 request with a relatively large payload even before MAX_RETRANSMIT 468 has been reached, and try restating the request as a block-wise 469 transfer with a smaller payload. Note that this new attempt is then 470 a new message-layer transaction and requires a new Message ID. 471 (Because of the uncertainty whether the request or the 472 acknowledgement was lost, this strategy is useful mostly for 473 idempotent requests.) 475 In a blockwise transfer of a request payload (e.g., a PUT or POST) 476 that is intended to be implemented in an atomic fashion at the 477 server, the actual creation/replacement takes place at the time the 478 final block, i.e. a block with the M bit unset in the Block1 Option, 479 is received. If not all previous blocks are available at the server 480 at this time, the transfer fails and error code 4.08 (Request Entity 481 Incomplete) MUST be returned. The error code 4.13 (Request Entity 482 Too Large) can be returned at any time by a server that does not 483 currently have the resources to store blocks for a block-wise request 484 payload transfer that it would intend to implement in an atomic 485 fashion. 487 If multiple concurrently proceeding block-wise request payload 488 transfer (e.g., PUT or POST) operations are possible, the requester 489 SHOULD use the Token Option to clearly separate the different 490 sequences. In this case, when reassembling the representation from 491 the blocks being exchanged to enable atomic processing, the 492 reassembler MUST compare any Token Options present (and, as usual, 493 taking an absent Token Option to default to the empty Token). If 494 atomic processing is not desired, there is no need to process the 495 Token Option (but it is still returned in the response as usual). 497 3. Examples 499 This section gives a number of short examples with message flows for 500 a block-wise GET, and for a PUT or POST. These examples demonstrate 501 the basic operation, the operation in the presence of 502 retransmissions, and examples for the operation of the block size 503 negotiation. 505 In all these examples, a Block option is shown in a decomposed way 506 separating the kind of Block option (1 or 2), block number (NUM), 507 more bit (M), and block size exponent (2**(SZX+4)) by slashes. E.g., 508 a Block2 Option value of 33 would be shown as 2/2/0/32), or a Block1 509 Option value of 59 would be shown as 1/3/1/128. 511 The first example (Figure 2) shows a GET request that is split into 512 three blocks. The server proposes a block size of 128, and the 513 client agrees. The first two ACKs contain 128 bytes of payload each, 514 and third ACK contains between 1 and 128 bytes. 516 CLIENT SERVER 517 | | 518 | CON [MID=1234], GET, /status ------> | 519 | | 520 | <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | 521 | | 522 | CON [MID=1235], GET, /status, 2/1/0/128 ------> | 523 | | 524 | <------ ACK [MID=1235], 2.05 Content, 2/1/1/128 | 525 | | 526 | CON [MID=1236], GET, /status, 2/2/0/128 ------> | 527 | | 528 | <------ ACK [MID=1236], 2.05 Content, 2/2/0/128 | 530 Figure 2: Simple blockwise GET 532 In the second example (Figure 3), the client anticipates the 533 blockwise transfer (e.g., because of a size indication in the link- 534 format description) and sends a size proposal. All ACK messages 535 except for the last carry 64 bytes of payload; the last one carries 536 between 1 and 64 bytes. 538 CLIENT SERVER 539 | | 540 | CON [MID=1234], GET, /status, 2/0/0/64 ------> | 541 | | 542 | <------ ACK [MID=1234], 2.05 Content, 2/0/1/64 | 543 | | 544 | CON [MID=1235], GET, /status, 2/1/0/64 ------> | 545 | | 546 | <------ ACK [MID=1235], 2.05 Content, 2/1/1/64 | 547 : : 548 : ... : 549 : : 550 | CON [MID=1238], GET, /status, 2/4/0/64 ------> | 551 | | 552 | <------ ACK [MID=1238], 2.05 Content, 2/4/1/64 | 553 | | 554 | CON [MID=1239], GET, /status, 2/5/0/64 ------> | 555 | | 556 | <------ ACK [MID=1239], 2.05 Content, 2/5/0/64 | 558 Figure 3: Blockwise GET with early negotiation 560 In the third example (Figure 4), the client is surprised by the need 561 for a blockwise transfer, and unhappy with the size chosen 562 unilaterally by the server. As it did not send a size proposal 563 initially, the negotiation only influences the size from the second 564 message exchange onward. Since the client already obtained both the 565 first and second 64-byte block in the first 128-byte exchange, it 566 goes on requesting the third 64-byte block ("2/0/64"). None of this 567 is (or needs to be) understood by the server, which simply responds 568 to the requests as it best can. 570 CLIENT SERVER 571 | | 572 | CON [MID=1234], GET, /status ------> | 573 | | 574 | <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | 575 | | 576 | CON [MID=1235], GET, /status, 2/2/0/64 ------> | 577 | | 578 | <------ ACK [MID=1235], 2.05 Content, 2/2/1/64 | 579 | | 580 | CON [MID=1236], GET, /status, 2/3/0/64 ------> | 581 | | 582 | <------ ACK [MID=1236], 2.05 Content, 2/3/1/64 | 583 | | 584 | CON [MID=1237], GET, /status, 2/4/0/64 ------> | 585 | | 586 | <------ ACK [MID=1237], 2.05 Content, 2/4/1/64 | 587 | | 588 | CON [MID=1238], GET, /status, 2/5/0/64 ------> | 589 | | 590 | <------ ACK [MID=1238], 2.05 Content, 2/5/0/64 | 592 Figure 4: Blockwise GET with late negotiation 594 In all these (and the following) cases, retransmissions are handled 595 by the CoAP message exchange layer, so they don't influence the block 596 operations (Figure 5, Figure 6). 598 CLIENT SERVER 599 | | 600 | CON [MID=1234], GET, /status ------> | 601 | | 602 | <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | 603 | | 604 | CON [MID=1235], GE///////////////////////// | 605 | | 606 | (timeout) | 607 | | 608 | CON [MID=1235], GET, /status, 2/2/0/64 ------> | 609 | | 610 | <------ ACK [MID=1235], 2.05 Content, 2/2/1/64 | 611 : : 612 : ... : 613 : : 614 | CON [MID=1238], GET, /status, 2/5/0/64 ------> | 615 | | 616 | <------ ACK [MID=1238], 2.05 Content, 2/5/0/64 | 617 Figure 5: Blockwise GET with late negotiation and lost CON 619 CLIENT SERVER 620 | | 621 | CON [MID=1234], GET, /status ------> | 622 | | 623 | <------ ACK [MID=1234], 2.05 Content, 2/0/1/128 | 624 | | 625 | CON [MID=1235], GET, /status, 2/2/0/64 ------> | 626 | | 627 | //////////////////////////////////tent, 2/2/1/64 | 628 | | 629 | (timeout) | 630 | | 631 | CON [MID=1235], GET, /status, 2/2/0/64 ------> | 632 | | 633 | <------ ACK [MID=1235], 2.05 Content, 2/2/1/64 | 634 : : 635 : ... : 636 : : 637 | CON [MID=1238], GET, /status, 2/5/0/64 ------> | 638 | | 639 | <------ ACK [MID=1238], 2.05 Content, 2/5/0/64 | 641 Figure 6: Blockwise GET with late negotiation and lost ACK 643 The following examples demonstrate a PUT exchange; a POST exchange 644 looks the same, with different requirements on atomicity/idempotence. 645 To ensure that the blocks relate to the same version of the resource 646 representation carried in the request, the client in Figure 7 sets 647 the Token to "v17" in all requests. Note that, as with the GET, the 648 responses to the requests that have a more bit in the request Block2 649 Option are provisional; only the final response tells the client that 650 the PUT succeeded. 652 CLIENT SERVER 653 | | 654 | CON [MID=1234], PUT, /options, v17, 1/0/1/128 ------> | 655 | | 656 | <------ ACK [MID=1234], 2.04 Changed, 1/0/1/128 | 657 | | 658 | CON [MID=1235], PUT, /options, v17, 1/1/1/128 ------> | 659 | | 660 | <------ ACK [MID=1235], 2.04 Changed, 1/1/1/128 | 661 | | 662 | CON [MID=1236], PUT, /options, v17, 1/2/0/128 ------> | 663 | | 664 | <------ ACK [MID=1236], 2.04 Changed, 1/2/0/128 | 666 Figure 7: Simple atomic blockwise PUT 668 A stateless server that simply builds/updates the resource in place 669 (statelessly) may indicate this by not setting the more bit in the 670 response (Figure 8); in this case, the response codes are valid 671 separately for each block being updated. This is of course only an 672 acceptable behavior of the server if the potential inconsistency 673 present during the run of the message exchange sequence does not lead 674 to problems, e.g. because the resource being created or changed is 675 not yet or not currently in use. 677 CLIENT SERVER 678 | | 679 | CON [MID=1234], PUT, /options, v17, 1/0/1/128 ------> | 680 | | 681 | <------ ACK [MID=1234], 2.04 Changed, 1/0/0/128 | 682 | | 683 | CON [MID=1235], PUT, /options, v17, 1/1/1/128 ------> | 684 | | 685 | <------ ACK [MID=1235], 2.04 Changed, 1/1/0/128 | 686 | | 687 | CON [MID=1236], PUT, /options, v17, 1/2/0/128 ------> | 688 | | 689 | <------ ACK [MID=1236], 2.04 Changed, 1/2/0/128 | 691 Figure 8: Simple stateless blockwise PUT 693 Finally, a server receiving a blockwise PUT or POST may want to 694 indicate a smaller block size preference (Figure 9). In this case, 695 the client SHOULD continue with a smaller block size; if it does, it 696 MUST adjust the block number to properly count in that smaller size. 698 CLIENT SERVER 699 | | 700 | CON [MID=1234], PUT, /options, v17, 1/0/1/128 ------> | 701 | | 702 | <------ ACK [MID=1234], 2.04 Changed, 1/0/1/32 | 703 | | 704 | CON [MID=1235], PUT, /options, v17, 1/4/1/32 ------> | 705 | | 706 | <------ ACK [MID=1235], 2.04 Changed, 1/4/1/32 | 707 | | 708 | CON [MID=1236], PUT, /options, v17, 1/5/1/32 ------> | 709 | | 710 | <------ ACK [MID=1235], 2.04 Changed, 1/5/1/32 | 711 | | 712 | CON [MID=1237], PUT, /options, v17, 1/6/0/32 ------> | 713 | | 714 | <------ ACK [MID=1236], 2.04 Changed, 1/6/0/32 | 716 Figure 9: Simple atomic blockwise PUT with negotiation 718 4. HTTP Mapping Considerations 720 In this subsection, we give some brief examples for the influence the 721 Block options might have on intermediaries that map between CoAP and 722 HTTP. 724 For mapping CoAP requests to HTTP, the intermediary may want to map 725 the sequence of block-wise transfers into a single HTTP transfer. 726 E.g., for a GET request, the intermediary could perform the HTTP 727 request once the first block has been requested and could then 728 fulfill all further block requests out of its cache. A constrained 729 implementation may not be able to cache the entire object and may use 730 a combination of TCP flow control and (in particular if timeouts 731 occur) HTTP range requests to obtain the information necessary for 732 the next block transfer at the right time. 734 For PUT or POST requests, there is more variation in how HTTP servers 735 might implement ranges. Some WebDAV servers do, but in general the 736 CoAP-to-HTTP intermediary will have to try sending the payload of all 737 the blocks of a block-wise transfer within one HTTP request. If 738 enough buffering is available, this request can be started when the 739 last CoAP block is received. A constrained implementation may want 740 to relieve its buffering by already starting to send the HTTP request 741 at the time the first CoAP block is received; any HTTP 408 status 742 code that indicates that the HTTP server became impatient with the 743 resulting transfer can then be mapped into a CoAP 4.08 response code 744 (similarly, 413 maps to 4.13). 746 For mapping HTTP to CoAP, the intermediary may want to map a single 747 HTTP transfer into a sequence of block-wise transfers. If the HTTP 748 client is too slow delivering a request body on a PUT or POST, the 749 CoAP server might time out and return a 4.08 response code, which in 750 turn maps well to an HTTP 408 status code (again, 4.13 maps to 413). 751 HTTP range requests received on the HTTP side may be served out of a 752 cache and/or mapped to GET requests that request a sequence of blocks 753 overlapping the range. 755 (Note that, while the semantics of CoAP 4.08 and HTTP 408 differ, 756 this difference is largely due to the different way the two protocols 757 are mapped to transport. HTTP has an underlying TCP connection, 758 which supplies connection state, so a HTTP 408 status code can 759 immediately be used to indicate that a timeout occurred during 760 transmitting a request through that active TCP connection. The CoAP 761 4.08 response code indicates one or more missing blocks, which may be 762 due to timeouts or resource constraints; as there is no connection 763 state, there is no way to deliver such a response immediately; 764 instead, it is delivered on the next block transfer. Still, HTTP 408 765 is probably the best mapping back to HTTP, as the timeout is the most 766 likely cause for a CoAP 4.08. Note that there is no way to 767 distinguish a timeout from a missing block for a server without 768 creating additional state, the need for which we want to avoid.) 770 5. IANA Considerations 772 This draft adds the following option numbers to the CoAP Option 773 Numbers registry of [I-D.ietf-core-coap]: 775 +--------+--------+-----------+ 776 | Number | Name | Reference | 777 +--------+--------+-----------+ 778 | 17 | Block2 | [RFCXXXX] | 779 | | | | 780 | 19 | Block1 | [RFCXXXX] | 781 +--------+--------+-----------+ 783 Table 2: CoAP Option Numbers 785 This draft adds the following response code to the CoAP Response 786 Codes registry of [I-D.ietf-core-coap]: 788 +------+--------------------------------+-----------+ 789 | Code | Description | Reference | 790 +------+--------------------------------+-----------+ 791 | 136 | 4.08 Request Entity Incomplete | [RFCXXXX] | 792 +------+--------------------------------+-----------+ 794 Table 3: CoAP Response Codes 796 6. Security Considerations 798 Providing access to blocks within a resource may lead to surprising 799 vulnerabilities. Where requests are not implemented atomically, an 800 attacker may be able to exploit a race condition or confuse a server 801 by inducing it to use a partially updated resource representation. 802 Partial transfers may also make certain problematic data invisible to 803 intrusion detection systems; it is RECOMMENDED that an intrusion 804 detection system (IDS) that analyzes resource representations 805 transferred by CoAP implement the Block options to gain access to 806 entire resource representations. Still, approaches such as 807 transferring even-numbered blocks on one path and odd-numbered blocks 808 on another path, or even transferring blocks multiple times with 809 different content and obtaining a different interpretation of 810 temporal order at the IDS than at the server, may prevent an IDS from 811 seeing the whole picture. These kinds of attacks are well understood 812 from IP fragmentation and TCP segmentation; CoAP does not add 813 fundamentally new considerations. 815 Where access to a resource is only granted to clients making use of a 816 specific security association, all blocks of that resource MUST be 817 subject to the same security checks; it MUST NOT be possible for 818 unprotected exchanges to influence blocks of an otherwise protected 819 resource. As a related consideration, where object security is 820 employed, PUT/POST should be implemented in the atomic fashion, 821 unless the object security operation is performed on each access and 822 the creation of unusable resources can be tolerated. 824 6.1. Mitigating Resource Exhaustion Attacks 826 Certain blockwise requests may induce the server to create state, 827 e.g. to create a snapshot for the blockwise GET of a fast-changing 828 resource to enable consistent access to the same version of a 829 resource for all blocks, or to create temporary resource 830 representations that are collected until pressed into service by a 831 final PUT or POST with the more bit unset. All mechanisms that 832 induce a server to create state that cannot simply be cleaned up 833 create opportunities for denial-of-service attacks. Servers SHOULD 834 avoid being subject to resource exhaustion based on state created by 835 untrusted sources. But even if this is done, the mitigation may 836 cause a denial-of-service to a legitimate request when it is drowned 837 out by other state-creating requests. Wherever possible, servers 838 should therefore minimize the opportunities to create state for 839 untrusted sources, e.g. by using stateless approaches. 841 Performing segmentation at the application layer is almost always 842 better in this respect than at the transport layer or lower (IP 843 fragmentation, adaptation layer fragmentation), e.g. because there is 844 application layer semantics that can be used for mitigation or 845 because lower layers provide security associations that can prevent 846 attacks. However, it is less common to apply timeouts and keepalive 847 mechanisms at the application layer than at lower layers. Servers 848 MAY want to clean up accumulated state by timing it out (cf. response 849 code 4.08), and clients SHOULD be prepared to run blockwise transfers 850 in an expedient way to minimize the likelihood of running into such a 851 timeout. 853 6.2. Mitigating Amplification Attacks 855 [I-D.ietf-core-coap] discusses the susceptibility of CoAP end-points 856 for use in amplification attacks. 858 A CoAP server can reduce the amount of amplification it provides to 859 an attacker by offering large resource representations only in 860 relatively small blocks. With this, e.g., for a 1000 byte resource, 861 a 10-byte request might result in an 80-byte response (with a 64-byte 862 block) instead of a 1016-byte response, considerably reducing the 863 amplification provided. 865 7. Acknowledgements 867 Much of the content of this draft is the result of discussions with 868 the [I-D.ietf-core-coap] authors, and via many CoRE WG discussions. 869 Tokens were suggested by Gilman Tolle and refined by Klaus Hartke. 871 Charles Palmer provided extensive editorial comments to a previous 872 version of this draft, some of which the authors hope to have covered 873 in this version. Esko Dijk reviewed a more recent version, leading 874 to a number of further editorial improvements. 876 8. References 878 8.1. Normative References 880 [I-D.ietf-core-coap] 881 Shelby, Z., Hartke, K., Bormann, C., and B. Frank, 882 "Constrained Application Protocol (CoAP)", 883 draft-ietf-core-coap-08 (work in progress), October 2011. 885 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 886 Requirement Levels", BCP 14, RFC 2119, March 1997. 888 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 889 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 890 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 892 8.2. Informative References 894 [REST] Fielding, R., "Architectural Styles and the Design of 895 Network-based Software Architectures", 2000. 897 [RFC4919] Kushalnagar, N., Montenegro, G., and C. Schumacher, "IPv6 898 over Low-Power Wireless Personal Area Networks (6LoWPANs): 899 Overview, Assumptions, Problem Statement, and Goals", 900 RFC 4919, August 2007. 902 Appendix A. Historical Note 904 (This appendix to be deleted by the RFC editor.) 906 An earlier version of this draft used a single option: 908 +------+----------+-------+--------+--------+---------------+ 909 | Type | C/E | Name | Format | Length | Default | 910 +------+----------+-------+--------+--------+---------------+ 911 | 13 | Critical | Block | uint | 1-3 B | 0 (see below) | 912 +------+----------+-------+--------+--------+---------------+ 914 Note that this option number has since been reallocated in 915 [I-D.ietf-core-coap]; no backwards compatibility is provided after 916 July 1st, 2011. 918 Authors' Addresses 920 Carsten Bormann 921 Universitaet Bremen TZI 922 Postfach 330440 923 Bremen D-28359 924 Germany 926 Phone: +49-421-218-63921 927 Fax: +49-421-218-7000 928 Email: cabo@tzi.org 930 Zach Shelby (editor) 931 Sensinode 932 Kidekuja 2 933 Vuokatti 88600 934 Finland 936 Phone: +358407796297 937 Email: zach@sensinode.com