1 /* 2 * MINIX 3 specific settings for lwIP. We also define the settings that are 3 * most important to us, even if they do not deviate from their defaults in 4 * lwip/opt.h from the lwIP distribution. 5 */ 6 #ifndef LWIP_LWIPOPTS_H 7 #define LWIP_LWIPOPTS_H 8 9 /* 10 * We use only the core API of lwIP. As such, we do not use any of its 11 * netconn, socket, mailbox, threading, synchronization, protection (etc) 12 * support. We do need lwIP to manage its own timers. 13 */ 14 #define NO_SYS 1 15 #define LWIP_TIMERS 1 16 #define SYS_LIGHTWEIGHT_PROT 0 17 18 /* 19 * The summary of our memory model is that we use lwIP's model of static pool 20 * preallocation for all objects known to lwIP, and a custom memory pool 21 * implementation for all other types of allocations. The custom memory pool 22 * allocates buffers of (up to) a fixed length (currently 512 bytes) from 23 * a small static memory pool and possibly in addition larger dynamically 24 * allocated memory areas. Allocations exceeding that fixed length must be 25 * turned into chains of buffers. Contiguous allocations that exceed the fixed 26 * length are not supported, and (with a single patch to lwIP) should never be 27 * made, either. See the LWIP service's mempool module for more information. 28 */ 29 #define MEM_LIBC_MALLOC 1 30 31 #define mem_clib_malloc mempool_malloc 32 #define mem_clib_calloc mempool_calloc 33 #define mem_clib_free mempool_free 34 35 /* Just in case, as lwIP does not use this definition. Implement if needed. */ 36 #define mem_clib_realloc __NOT_IMPLEMENTED 37 38 /* 39 * Size of a single buffer in the memory pool, in bytes. This definition is 40 * ours, and not used directly by lwIP. However, we need it here because we 41 * derive various limits from this setting. The current setting should provide 42 * a decent trade-off between per-buffer utilization on one hand and the length 43 * of buffer chains and queues on the other. For example, it takes only three 44 * buffers to store a full-sized ethernet packet with the current setting. 45 * While the value could be lowered, it should remain large enough to ensure 46 * that essentially all packet headers fit in a packet's first buffer. Also 47 * note that lowering this value may cause certain other allocations to grow. 48 */ 49 #define MEMPOOL_BUFSIZE 512 50 51 /* 52 * The following value should be sizeof(void *), but lwIP's own #if-based 53 * sanity checks make that impossible. It is crucial that the value is set to 54 * exactly the value of sizeof(void *) though: a value that is too small will 55 * cause problems on alignment-enforcing platforms, and a value that is too 56 * large will cause lwIP to fail on an assertion. TODO: 64-bit support. 57 */ 58 #define MEM_ALIGNMENT 4 59 60 /* 61 * The reason that we use lwIP's pools for its own objects, is that we actually 62 * want the separation of pools to avoid allocating too many objects of one 63 * type, e.g. wasting all memory on IP fragment reassembly. As such, we do not 64 * want to use our memory pool implementation for those pools, especially since 65 * the pool information would be lost if we did. 66 */ 67 #define MEMP_MEM_MALLOC 0 68 69 #define MEMP_OVERFLOW_CHECK 0 70 #define MEMP_SANITY_CHECK 0 71 72 /* We do not use pools for custom allocations. */ 73 #define MEM_USE_POOLS 0 74 #define MEMP_USE_CUSTOM_POOLS 0 75 76 /* 77 * We do not use the standard lwIP pbuf pool at all. The following definitions 78 * would both be zero if that didn't make lwIP fail on a static assertion. 79 */ 80 #define PBUF_POOL_SIZE 0 81 #define PBUF_POOL_BUFSIZE (MEM_ALIGNMENT + 1) 82 83 /* 84 * This definition should override lwIP's internal one, resulting in only pbuf 85 * chains with PBUF_REF buffers being copied when queuing packets during 86 * ARP/NDP queries. In fact, copying nothing should be safe because both lwIP 87 * and our service implementation are zero-copy aware and should never do 88 * something that could violate the requirements for no-copy safety. However, 89 * while PBUF_REF buffers may be generated by the IP fragmentation code in a 90 * safe manner, lwIP itself may in the future be changed to generate PBUF_REF 91 * buffers that are not safe, and it is not very costly to copy them, which is 92 * why we test against PBUF_REF here rather than simply putting in "(0)"--i.e., 93 * just to be on the safe side. For more information, see lwIP patch #9272 and 94 * the references mentioned in lwIP's default definition of PBUF_NEEDS_COPY. 95 */ 96 #define PBUF_NEEDS_COPY(p) ((p)->type == PBUF_REF) 97 98 #define LWIP_ARP 1 99 100 /* 101 * Like many things, the lwIP ARP table is a simple array, with searches using 102 * linear lookups. Thus, while we can afford the memory, increasing this 103 * setting will effectively make sending packets slower. TODO: tune this. 104 */ 105 #define ARP_TABLE_SIZE 16 106 107 #define ARP_QUEUEING 1 108 109 /* No VLAN support just yet. */ 110 #define ETHARP_SUPPORT_VLAN 0 111 112 /* Deliberately disabled; see ETH_PAD_LEN below. */ 113 #define ETH_PAD_SIZE 0 114 115 #define ETHARP_SUPPORT_STATIC_ENTRIES 1 116 117 /* 118 * This setting is enabled mainly for the purpose of allowing dhcpcd(8) to 119 * implement IPv4 AutoIP support in userspace, because that is the main case 120 * where two attached networks may see the same IPv4 addresses. 121 */ 122 #define ETHARP_TABLE_MATCH_NETIF 1 123 124 /* 125 * IPv4 support can not be disabled at any level, and certainly not here. 126 */ 127 #define LWIP_IPV4 1 128 129 /* 130 * We enable support for forwarding at compile time. We patch lwIP so that we 131 * can control this feature with a setting at run time. 132 */ 133 #define IP_FORWARD 1 134 135 #define IP_FRAG 1 136 137 /* 138 * Number of helper structures, one per fragment that may be in the process of 139 * being sent to a network driver. We do not expect a whole lot of fragments 140 * to be sent at any given time, but one large packet may already require a 141 * lot of fragments (e.g. about 44 fragments for one 64K packet fragmented for 142 * ethernet), so do not set this too low either. 143 */ 144 #define MEMP_NUM_FRAG_PBUF 256 145 146 #define IP_REASSEMBLY 1 147 148 /* 149 * Number of helper structures, one per packet that is in the process of being 150 * reassembled. This structure is not the smallest and we do not expect lots 151 * of concurrent reassembly going on, so keep this fairly low. 152 */ 153 #define MEMP_NUM_REASSDATA 16 154 155 /* 156 * The maximum number of pbufs that may be used for reassembly of fragmented 157 * packets. The following value is required for reassembly of one 64K-sized 158 * packet, which is required by one of our tests. 159 */ 160 #define IP_REASS_MAX_PBUFS 129 161 162 /* 163 * We do want to require for sending broadcast packets that the SO_BROADCAST 164 * socket option be set on the socket first (IP_SOF_BROADCAST). We do not want 165 * to filter incoming broadcast packets on sockets that do not have that socket 166 * option set, though (IP_SOF_BROADCAST_RECV). 167 */ 168 #define IP_SOF_BROADCAST 1 169 #define IP_SOF_BROADCAST_RECV 0 170 171 /* 172 * For TCP and UDP, lwIP currently iterates through port numbers sequentially 173 * when selecting a port. This option enables at least randomizing the 174 * starting port number after start-up, but obviously that is not at all useful 175 * for security purposes. Still, it is better than nothing for the case it 176 * aims to cover: likely selection of the same port numbers after each reboot. 177 */ 178 #define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS 1 179 180 #define LWIP_ICMP 1 181 182 #define LWIP_MULTICAST_PING 1 183 184 #define LWIP_RAW 1 185 186 #define MEMP_NUM_RAW_PCB 16 187 188 /* DHCP is handled entirely by dhcpcd(8) in our case. */ 189 #define LWIP_DHCP 0 190 191 /* 192 * We let dhcpcd(8) manage automatic IPv4 assignment, too. We do not support 193 * the relevant flags for locally assigned IPv4 addresses (e.g., 194 * IN_IFF_TENTATIVE): we cannot implement them properly since lwIP's AutoIP 195 * support is all-or-nothing, and dhcpcd(8) can make do without them as well. 196 */ 197 #define LWIP_AUTOIP 0 198 199 #define LWIP_MULTICAST_TX_OPTIONS 1 200 201 #define LWIP_IGMP 1 202 203 /* 204 * Each interface that supports IGMP also joins the all-nodes multicast group. 205 * This is done automatically by lwIP, but there need to be enough entries for 206 * this. The '16' here is the maximum number of interfaces that support 207 * multicast, and may have to be increased in the future. The 208 * NR_IPV4_MCAST_GROUP definition is our own, and determines the maximum number 209 * of IGMP groups that can be joined on sockets. 210 */ 211 #define NR_IPV4_MCAST_GROUP 64 212 213 #define MEMP_NUM_IGMP_GROUP (16 + NR_IPV4_MCAST_GROUP) 214 215 #define LWIP_DNS 0 216 217 #define LWIP_UDP 1 218 219 #define MEMP_NUM_UDP_PCB 256 220 221 #define LWIP_TCP 1 222 223 /* 224 * The maximum number of TCP sockets. This definition is our own, but it is in 225 * effect the main setting that determines how much memory the LWIP service 226 * reserves statically for various pools of TCP-related structures. In all the 227 * settings further below and elsewhere, we provision the LWIP service such 228 * that it can support full-speed two-way communication for each TCP socket, 229 * assuming an application that is built to use sockets efficiently by using 230 * large I/O requests. However, various necessary structures (especially 231 * MEMP_NUM_PBUF and MEMP_NUM_TCP_SEG) cannot be allocated dynamically, so we 232 * have to preallocate them all for the worst case. The result is substantial 233 * memory usage even when few buffers are in use. We currently consider this 234 * an acceptable trade-off. However, should the LWIP service's static memory 235 * usage become an issue, the best start is to lower this value. 236 */ 237 #define NR_TCPSOCK 256 238 239 /* 240 * The maximum number of lwIP TCP PCBs. Each TCP socket (NR_TCPSOCK) needs one 241 * of these. We currently add 50% of them on top of that, for TCP connections 242 * in SYN_RCVD and TIME_WAIT state. 243 */ 244 #define MEMP_NUM_TCP_PCB (NR_TCPSOCK * 3 / 2) 245 246 /* 247 * lwIP uses a separate, smaller PCB for each listening TCP socket. For us, 248 * this is not very convenient, because it means another separate pool of 249 * structures and another parameter to tune. In addition, we have to be 250 * careful not to access certain PCB fields of listening TCP PCBs. 251 */ 252 #define MEMP_NUM_TCP_PCB_LISTEN 64 253 254 /* 255 * Unfortunately, lwIP does not support full path MTU discovery. Therefore, it 256 * is important that this value is not too high. We set it conservatively to 257 * the value that the previous lwIP-based TCP/IP service used as well. 258 */ 259 #define TCP_MSS 1460 260 261 /* 262 * The maximum receive window size for TCP connections. This value must not be 263 * too low, because that would affect TCP performance. It must also not be too 264 * high, because it determines the minimum receive buffer size for TCP 265 * connections. The current setting should be reasonable. 266 */ 267 #define TCP_WND 16384 268 269 /* 270 * The following setting defines the "send window" size, that is, up to how 271 * many bytes lwIP will send without acknowledgment when not constrained by the 272 * receiver's window size. This value should be a multiple of the TCP MSS, or 273 * lwIP will send sub-MSS packets even in ideal circumstances. Unfortunately 274 * this is a static definition and thus cannot be a function of the actual MSS 275 * of any individual connection, so our hope is that the vast majority of TCP 276 * connections end up using the maximum MSS (i.e., the TCP_MSS value), which is 277 * probably usually true. The current definition is as close as possible to 278 * 16KB while still a multiple of the MSS. Note that various memory pool size 279 * settings in this file depend on the TCP_SND_BUF value, so increasing this 280 * value will also make the LWIP service use more memory. 281 */ 282 #define TCP_SND_BUF (11 * TCP_MSS) 283 284 /* 285 * This setting is an artificial limit that can be used to reduce how many 286 * buffers can be used for the send queue of a single TCP connection. We set 287 * it such that an application that uses large writes will never hit the limit, 288 * while an application that uses small writes will not take up more than its 289 * fair share of resources. The formula is as follows: there can be at most 290 * (TCP_SND_BUF / TCP_MSS) maximum-sized segments (11) enqueued, each of which 291 * consists of one header pbuf and (ROUND-UP(TCP_MSS / MEMPOOL_BUFSIZE) + 1) 292 * references to data (4), yielding a total of 55 pbufs for a full queue. 293 * Given that in the very worst case, one single enqueued byte may take two 294 * pbufs (one header, one data pbuf), inefficient applications might find 295 * themselves unable to enqueue more than half of that number in bytes, i.e., 296 * 27 bytes. This is exactly as intended: such inefficient senders can not 297 * negatively affect other TCP connections, while more of their data will be 298 * queued up by the LWIP service, as the default LWIP service send queue (32KB) 299 * is about twice the TCP PCB's send queue size (TCP_SND_BUF, ~16KB). They 300 * will simply experience slow communication as a result. 301 */ 302 #define TCP_SND_QUEUELEN ((TCP_SND_BUF / TCP_MSS) * \ 303 ((TCP_MSS + MEMPOOL_BUFSIZE - 1) / \ 304 MEMPOOL_BUFSIZE + 2)) 305 306 /* 307 * This setting defines the number of pbuf structures that can be used to point 308 * to data elsewhere (PBUF_ROM, PBUF_REF). They are used by the lwIP TCP 309 * module, the lwIP fragmentation code, and by our ethernet interface module. 310 * These structures are small, and we need a lot of them. In particular, we 311 * need one PBUF_ROM structure for each contiguous stretch of data on the send 312 * queue of a lwIP TCP PCB. For this we take the maximum we need to fill a TCP 313 * PCB's send queue, and multiply it by the supported number of TCP sockets. 314 * The maximum we need is the number of references we need per segment, times 315 * the number of segments. For simplicity we base this computation on the 316 * PCB_SND_QUEUELEN computation; see its definition for details. The result 317 * should be 44 references per TCP connection right now. In addition to that, 318 * the ethif module uses PBUF_REF structures for packets enqueued for sending. 319 * For that reason, we add another MEMP_NUM_TCP_PCB structures to be able to 320 * enqueue at least one packet per TCP PCB at all times. 321 */ 322 #define MEMP_NUM_PBUF ((TCP_SND_QUEUELEN - (TCP_SND_BUF / \ 323 TCP_MSS)) * NR_TCPSOCK + \ 324 MEMP_NUM_TCP_PCB) 325 326 /* 327 * The maximum number of TCP segments. Like the PBUF_REF/PBUF_ROM structures, 328 * these are small, but we need a lot of these as well. We allocate as many 329 * segment structures as are needed to fill each TCP socket's send queue, which 330 * is in this case bounded by TCP_SND_QUEUELEN (see above). In theory, there 331 * could be one segment per queued piece of data. Each segment also has a 332 * separate header, thus a segment takes a minimum of two pbufs. This means 333 * that we need (TCP_SND_QUEUELEN / 2) segment structures (27) per TCP socket. 334 * For sane applications this will never be a real limitation: they should use 335 * fewer than half of these at most (11, from TCP_SND_BUF). Less-than-sane 336 * applications can still not eat up more than their fair share. 337 */ 338 #define MEMP_NUM_TCP_SEG ((TCP_SND_QUEUELEN / 2) * NR_TCPSOCK) 339 340 #define TCP_LISTEN_BACKLOG 1 341 342 /* 343 * TCP support for oversized buffers is relevant only for the case that the 344 * core TCP module is made responsible for copying data to its own buffers. We 345 * pass our own buffers to the core TCP API, while retaining their ownership. 346 * Therefore, this option is useless for us. 347 */ 348 #define TCP_OVERSIZE 0 349 350 /* 351 * We are currently using the callback API only because the event API has been 352 * having problems, but these should now be fixed in lwIP. The event API has 353 * the advantage that it saves 20 bytes per TCP PCB. TODO: switch over. 354 */ 355 #define LWIP_EVENT_API 0 356 #define LWIP_CALLBACK_API 1 357 358 /* We do not support TCP window scaling at this time. */ 359 360 /* 361 * We would like to align TCP/IP header field accesses to 32 bits. lwIP offers 362 * ETH_PAD_SIZE to that end. We do not use that however, because it is 363 * inconvenient: it adds the padding to the actual output packets, thus forcing 364 * our ethif module to correct for that by adjusting its headers. That does 365 * not combine well with our approach of simply increasing the reference count 366 * of the output packets so that we can send them later. Instead, we use our 367 * own padding method: we add two bytes to the link header here, and we simply 368 * chip the first two bytes off each packet buffer before receiving an incoming 369 * packet into it. 370 */ 371 /* These two definitions are entirely our own. They are not used by lwIP. */ 372 #define ETH_PAD_LEN 2 373 #define ETH_HDR_LEN 14 374 375 /* Note that VLAN support would require an extra four bytes here. */ 376 #define PBUF_LINK_HLEN (ETH_PAD_LEN + ETH_HDR_LEN) 377 378 #define PBUF_LINK_ENCAPSULATION_LEN 0 379 380 /* 381 * We use the status callback to detect lwIP-initiated state changes on local 382 * IPv6 addresses. 383 */ 384 #define LWIP_NETIF_STATUS_CALLBACK 1 385 386 /* 387 * This setting simply adds a field to the netif structure that can then be 388 * used by lwIP's own modules. It requires no support from us. 389 */ 390 #define LWIP_NETIF_HWADDRHINT 1 391 392 /* 393 * We provide loopback functionality ourselves, so we do not need the netif 394 * layer to duplicate this poorly (e.g., without BPF or statistics support). 395 * Moreover, enabling this setting would force loopback traffic over non- 396 * loopback interfaces in some scenarios, since we do not enable 397 * LWIP_HAVE_LOOPIF either. 398 */ 399 #define LWIP_NETIF_LOOPBACK 0 400 401 #define LWIP_NETCONN 0 402 #define LWIP_SOCKET 0 403 404 #define LWIP_TCP_KEEPALIVE 1 405 406 /* 407 * lwIP's SO_REUSEADDR semantics are somewhat different from BSD's. There is 408 * more work to be done here. 409 */ 410 #define SO_REUSE 1 411 #define SO_REUSE_RXTOALL 1 412 413 /* We maintain our own, simpler statistics. */ 414 #define LWIP_STATS 0 415 416 #define LWIP_CHECKSUM_CTRL_PER_NETIF 1 417 #define CHECKSUM_GEN_IP 1 418 #define CHECKSUM_GEN_UDP 1 419 #define CHECKSUM_GEN_TCP 1 420 #define CHECKSUM_GEN_ICMP 1 421 #define CHECKSUM_GEN_ICMP6 1 422 #define CHECKSUM_CHECK_IP 1 423 #define CHECKSUM_CHECK_UDP 1 424 #define CHECKSUM_CHECK_TCP 1 425 #define CHECKSUM_CHECK_ICMP 1 426 #define CHECKSUM_CHECK_ICMP6 1 427 428 /* 429 * The checksum-on-copy setting is beneficial only when lwIP does most of the 430 * memory copying, and detrimental otherwise. We do most copying ourselves. 431 */ 432 #define LWIP_CHECKSUM_ON_COPY 0 433 434 /* 435 * During testing, checksum algorithm #3 had slightly better performance than 436 * default checksum algorithm #2. 437 */ 438 #define LWIP_CHKSUM_ALGORITHM 3 439 440 /* 441 * IPv6 support is always enabled, even when the system is built with the 442 * USE_INET6 setting disabled. A lot of ugly changes would be required in the 443 * service to support disabling LWIP_IPV6, and it is increasingly unlikely that 444 * anyone would want to disable USE_INET6 at all. 445 */ 446 #define LWIP_IPV6 1 447 448 /* 449 * IPv6 scopes support is absolutely necessary for correctness. Leave the 450 * debugging support enabled too, because the scopes support is one of our 451 * additions to lwIP and so we want to know if it breaks in the future. 452 */ 453 #define LWIP_IPV6_SCOPES 1 454 #define LWIP_IPV6_SCOPES_DEBUG 1 455 456 /* 457 * We need an absolute minimum of three IPv6 addresses per interface in order 458 * to allow the following typical use case: 459 * 460 * - one link-local address; 461 * - one preferred global address; 462 * - one deprecated global address. 463 * 464 * For some use cases, this limit may not be high enough: for example, it 465 * leaves no room for combining permanent and temporary addresses, both of 466 * which may have one preferred and one deprecated address. We currently set 467 * the number to four here for pragmatic reasons though: while the first IPv6 468 * address slot is always reserved for a link-local address, test93 currently 469 * needs to be able to set three global addresses on a single interface for 470 * testing purposes. Setting the number to three will save a bit of memory and 471 * computation, but stop test93 from working. 472 */ 473 #define LWIP_IPV6_NUM_ADDRESSES 4 474 475 /* 476 * We enable support for forwarding at compile time. We patch lwIP so that we 477 * can control this feature with a setting at run time. 478 */ 479 #define LWIP_IPV6_FORWARD 1 480 481 #define LWIP_IPV6_FRAG 1 482 #define LWIP_IPV6_REASS 1 483 484 /* 485 * This setting is required on 64-bit platforms and does not cost all that much 486 * on 32-bit platforms, so we might as well turn it on already. 487 */ 488 #define IPV6_FRAG_COPYHEADER 1 489 490 /* 491 * Since IPv6 address configuration is handled by userland (see below), we do 492 * not need lwIP to send router solicitations itself, either. lwIP will only 493 * passively obtain information from router advertisements as they come in. 494 * Disabling this option is also necessary for the USE_IPV6=0 case. 495 */ 496 #define LWIP_IPV6_SEND_ROUTER_SOLICIT 0 497 498 /* 499 * We only support IPv6 stateless autoconfiguration through external SLAAC or 500 * DHCPv6 clients. In practice, autoconfiguration is and should be handled 501 * excluslvely by dhcpcd(8). This option must therefore be disabled in order 502 * to prevent lwIP from (e.g.) updating address lifetimes on its own. 503 */ 504 #define LWIP_IPV6_AUTOCONFIG 0 505 506 /* 507 * Support for address lifetimes is however absolutely essential for dhcpcd(8) 508 * and also needed to support various ifconfig(8) options. 509 */ 510 #define LWIP_IPV6_ADDRESS_LIFETIMES 1 511 512 /* 513 * For safety, use at least a few DAD probes before deciding an address is not 514 * duplicated. This should also guarantee that at least some of them are sent 515 * after joining the solicited-node multicast group for the address (the fact 516 * that this is not guaranteed is a lwIP bug). This setting does affect the 517 * system startup time, though. 518 */ 519 #define LWIP_IPV6_DUP_DETECT_ATTEMPTS 3 520 521 #define LWIP_ICMP6 1 522 523 /* 524 * MLD is required for IPv6 multicast support. Basic multicast support is 525 * required for IPv6 anyway, and disabling MLD would mean we have to accept all 526 * multicast traffic instead of being able to give a specific list to drivers. 527 */ 528 #define LWIP_IPV6_MLD 1 529 530 /* 531 * Each locally assigned IPv6 address requires joining its corresponding 532 * solicited-node multicast group. This is done automatically by lwIP, but 533 * there need to be enough entries for this. The '16' here is the maximum 534 * number of interfaces that support multicast, and may have to be increased in 535 * the future. The NR_IPV6_MCAST_GROUP definition is our own, and determines 536 * the maximum number of MLD groups that can be joined on sockets. 537 */ 538 #define NR_IPV6_MCAST_GROUP 64 539 540 #define MEMP_NUM_MLD6_GROUP (16 * LWIP_IPV6_NUM_ADDRESSES + \ 541 NR_IPV6_MCAST_GROUP) 542 543 #define LWIP_ND6_QUEUEING 1 544 545 /* Same as with ARP. TODO: tune these. */ 546 #define LWIP_ND6_NUM_NEIGHBORS 16 547 #define LWIP_ND6_NUM_DESTINATIONS 16 548 549 /* 550 * We disable Router Advertisement message processing, so the prefix and 551 * default-router tables are both unused. We cannot set these values to zero, 552 * but we set them to the lowest possible value. Not that it saves much.. 553 */ 554 #define LWIP_ND6_NUM_PREFIXES 1 555 #define LWIP_ND6_NUM_ROUTERS 1 556 557 /* 558 * Hooks are in a separate file, to allow some of their parameter types to be 559 * defined. 560 */ 561 #define LWIP_HOOK_FILENAME "lwiphooks.h" 562 563 #endif /* !LWIP_LWIPOPTS_H */ 564