Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | /*- |
michael@0 | 2 | * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved. |
michael@0 | 3 | * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. |
michael@0 | 4 | * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. |
michael@0 | 5 | * |
michael@0 | 6 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | * modification, are permitted provided that the following conditions are met: |
michael@0 | 8 | * |
michael@0 | 9 | * a) Redistributions of source code must retain the above copyright notice, |
michael@0 | 10 | * this list of conditions and the following disclaimer. |
michael@0 | 11 | * |
michael@0 | 12 | * b) Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer in |
michael@0 | 14 | * the documentation and/or other materials provided with the distribution. |
michael@0 | 15 | * |
michael@0 | 16 | * c) Neither the name of Cisco Systems, Inc. nor the names of its |
michael@0 | 17 | * contributors may be used to endorse or promote products derived |
michael@0 | 18 | * from this software without specific prior written permission. |
michael@0 | 19 | * |
michael@0 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 22 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
michael@0 | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
michael@0 | 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
michael@0 | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
michael@0 | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
michael@0 | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
michael@0 | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
michael@0 | 30 | * THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | #ifdef __FreeBSD__ |
michael@0 | 34 | #include <sys/cdefs.h> |
michael@0 | 35 | __FBSDID("$FreeBSD: head/sys/netinet/sctp_output.c 262252 2014-02-20 20:14:43Z tuexen $"); |
michael@0 | 36 | #endif |
michael@0 | 37 | |
michael@0 | 38 | #include <netinet/sctp_os.h> |
michael@0 | 39 | #ifdef __FreeBSD__ |
michael@0 | 40 | #include <sys/proc.h> |
michael@0 | 41 | #endif |
michael@0 | 42 | #include <netinet/sctp_var.h> |
michael@0 | 43 | #include <netinet/sctp_sysctl.h> |
michael@0 | 44 | #include <netinet/sctp_header.h> |
michael@0 | 45 | #include <netinet/sctp_pcb.h> |
michael@0 | 46 | #include <netinet/sctputil.h> |
michael@0 | 47 | #include <netinet/sctp_output.h> |
michael@0 | 48 | #include <netinet/sctp_uio.h> |
michael@0 | 49 | #include <netinet/sctputil.h> |
michael@0 | 50 | #include <netinet/sctp_auth.h> |
michael@0 | 51 | #include <netinet/sctp_timer.h> |
michael@0 | 52 | #include <netinet/sctp_asconf.h> |
michael@0 | 53 | #include <netinet/sctp_indata.h> |
michael@0 | 54 | #include <netinet/sctp_bsd_addr.h> |
michael@0 | 55 | #include <netinet/sctp_input.h> |
michael@0 | 56 | #include <netinet/sctp_crc32.h> |
michael@0 | 57 | #if defined(__Userspace_os_Linux) |
michael@0 | 58 | #define __FAVOR_BSD /* (on Ubuntu at least) enables UDP header field names like BSD in RFC 768 */ |
michael@0 | 59 | #endif |
michael@0 | 60 | #if !defined(__Userspace_os_Windows) |
michael@0 | 61 | #include <netinet/udp.h> |
michael@0 | 62 | #endif |
michael@0 | 63 | #if defined(__APPLE__) |
michael@0 | 64 | #include <netinet/in.h> |
michael@0 | 65 | #endif |
michael@0 | 66 | #if defined(__FreeBSD__) |
michael@0 | 67 | #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 |
michael@0 | 68 | #include <netinet/udp_var.h> |
michael@0 | 69 | #endif |
michael@0 | 70 | #include <machine/in_cksum.h> |
michael@0 | 71 | #endif |
michael@0 | 72 | #if defined(__Userspace__) && defined(INET6) |
michael@0 | 73 | #include <netinet6/sctp6_var.h> |
michael@0 | 74 | #endif |
michael@0 | 75 | |
michael@0 | 76 | #if defined(__APPLE__) |
michael@0 | 77 | #define APPLE_FILE_NO 3 |
michael@0 | 78 | #endif |
michael@0 | 79 | |
michael@0 | 80 | #if defined(__APPLE__) |
michael@0 | 81 | #if !(defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD)) |
michael@0 | 82 | #define SCTP_MAX_LINKHDR 16 |
michael@0 | 83 | #endif |
michael@0 | 84 | #endif |
michael@0 | 85 | |
michael@0 | 86 | #define SCTP_MAX_GAPS_INARRAY 4 |
michael@0 | 87 | struct sack_track { |
michael@0 | 88 | uint8_t right_edge; /* mergable on the right edge */ |
michael@0 | 89 | uint8_t left_edge; /* mergable on the left edge */ |
michael@0 | 90 | uint8_t num_entries; |
michael@0 | 91 | uint8_t spare; |
michael@0 | 92 | struct sctp_gap_ack_block gaps[SCTP_MAX_GAPS_INARRAY]; |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | struct sack_track sack_array[256] = { |
michael@0 | 96 | {0, 0, 0, 0, /* 0x00 */ |
michael@0 | 97 | {{0, 0}, |
michael@0 | 98 | {0, 0}, |
michael@0 | 99 | {0, 0}, |
michael@0 | 100 | {0, 0} |
michael@0 | 101 | } |
michael@0 | 102 | }, |
michael@0 | 103 | {1, 0, 1, 0, /* 0x01 */ |
michael@0 | 104 | {{0, 0}, |
michael@0 | 105 | {0, 0}, |
michael@0 | 106 | {0, 0}, |
michael@0 | 107 | {0, 0} |
michael@0 | 108 | } |
michael@0 | 109 | }, |
michael@0 | 110 | {0, 0, 1, 0, /* 0x02 */ |
michael@0 | 111 | {{1, 1}, |
michael@0 | 112 | {0, 0}, |
michael@0 | 113 | {0, 0}, |
michael@0 | 114 | {0, 0} |
michael@0 | 115 | } |
michael@0 | 116 | }, |
michael@0 | 117 | {1, 0, 1, 0, /* 0x03 */ |
michael@0 | 118 | {{0, 1}, |
michael@0 | 119 | {0, 0}, |
michael@0 | 120 | {0, 0}, |
michael@0 | 121 | {0, 0} |
michael@0 | 122 | } |
michael@0 | 123 | }, |
michael@0 | 124 | {0, 0, 1, 0, /* 0x04 */ |
michael@0 | 125 | {{2, 2}, |
michael@0 | 126 | {0, 0}, |
michael@0 | 127 | {0, 0}, |
michael@0 | 128 | {0, 0} |
michael@0 | 129 | } |
michael@0 | 130 | }, |
michael@0 | 131 | {1, 0, 2, 0, /* 0x05 */ |
michael@0 | 132 | {{0, 0}, |
michael@0 | 133 | {2, 2}, |
michael@0 | 134 | {0, 0}, |
michael@0 | 135 | {0, 0} |
michael@0 | 136 | } |
michael@0 | 137 | }, |
michael@0 | 138 | {0, 0, 1, 0, /* 0x06 */ |
michael@0 | 139 | {{1, 2}, |
michael@0 | 140 | {0, 0}, |
michael@0 | 141 | {0, 0}, |
michael@0 | 142 | {0, 0} |
michael@0 | 143 | } |
michael@0 | 144 | }, |
michael@0 | 145 | {1, 0, 1, 0, /* 0x07 */ |
michael@0 | 146 | {{0, 2}, |
michael@0 | 147 | {0, 0}, |
michael@0 | 148 | {0, 0}, |
michael@0 | 149 | {0, 0} |
michael@0 | 150 | } |
michael@0 | 151 | }, |
michael@0 | 152 | {0, 0, 1, 0, /* 0x08 */ |
michael@0 | 153 | {{3, 3}, |
michael@0 | 154 | {0, 0}, |
michael@0 | 155 | {0, 0}, |
michael@0 | 156 | {0, 0} |
michael@0 | 157 | } |
michael@0 | 158 | }, |
michael@0 | 159 | {1, 0, 2, 0, /* 0x09 */ |
michael@0 | 160 | {{0, 0}, |
michael@0 | 161 | {3, 3}, |
michael@0 | 162 | {0, 0}, |
michael@0 | 163 | {0, 0} |
michael@0 | 164 | } |
michael@0 | 165 | }, |
michael@0 | 166 | {0, 0, 2, 0, /* 0x0a */ |
michael@0 | 167 | {{1, 1}, |
michael@0 | 168 | {3, 3}, |
michael@0 | 169 | {0, 0}, |
michael@0 | 170 | {0, 0} |
michael@0 | 171 | } |
michael@0 | 172 | }, |
michael@0 | 173 | {1, 0, 2, 0, /* 0x0b */ |
michael@0 | 174 | {{0, 1}, |
michael@0 | 175 | {3, 3}, |
michael@0 | 176 | {0, 0}, |
michael@0 | 177 | {0, 0} |
michael@0 | 178 | } |
michael@0 | 179 | }, |
michael@0 | 180 | {0, 0, 1, 0, /* 0x0c */ |
michael@0 | 181 | {{2, 3}, |
michael@0 | 182 | {0, 0}, |
michael@0 | 183 | {0, 0}, |
michael@0 | 184 | {0, 0} |
michael@0 | 185 | } |
michael@0 | 186 | }, |
michael@0 | 187 | {1, 0, 2, 0, /* 0x0d */ |
michael@0 | 188 | {{0, 0}, |
michael@0 | 189 | {2, 3}, |
michael@0 | 190 | {0, 0}, |
michael@0 | 191 | {0, 0} |
michael@0 | 192 | } |
michael@0 | 193 | }, |
michael@0 | 194 | {0, 0, 1, 0, /* 0x0e */ |
michael@0 | 195 | {{1, 3}, |
michael@0 | 196 | {0, 0}, |
michael@0 | 197 | {0, 0}, |
michael@0 | 198 | {0, 0} |
michael@0 | 199 | } |
michael@0 | 200 | }, |
michael@0 | 201 | {1, 0, 1, 0, /* 0x0f */ |
michael@0 | 202 | {{0, 3}, |
michael@0 | 203 | {0, 0}, |
michael@0 | 204 | {0, 0}, |
michael@0 | 205 | {0, 0} |
michael@0 | 206 | } |
michael@0 | 207 | }, |
michael@0 | 208 | {0, 0, 1, 0, /* 0x10 */ |
michael@0 | 209 | {{4, 4}, |
michael@0 | 210 | {0, 0}, |
michael@0 | 211 | {0, 0}, |
michael@0 | 212 | {0, 0} |
michael@0 | 213 | } |
michael@0 | 214 | }, |
michael@0 | 215 | {1, 0, 2, 0, /* 0x11 */ |
michael@0 | 216 | {{0, 0}, |
michael@0 | 217 | {4, 4}, |
michael@0 | 218 | {0, 0}, |
michael@0 | 219 | {0, 0} |
michael@0 | 220 | } |
michael@0 | 221 | }, |
michael@0 | 222 | {0, 0, 2, 0, /* 0x12 */ |
michael@0 | 223 | {{1, 1}, |
michael@0 | 224 | {4, 4}, |
michael@0 | 225 | {0, 0}, |
michael@0 | 226 | {0, 0} |
michael@0 | 227 | } |
michael@0 | 228 | }, |
michael@0 | 229 | {1, 0, 2, 0, /* 0x13 */ |
michael@0 | 230 | {{0, 1}, |
michael@0 | 231 | {4, 4}, |
michael@0 | 232 | {0, 0}, |
michael@0 | 233 | {0, 0} |
michael@0 | 234 | } |
michael@0 | 235 | }, |
michael@0 | 236 | {0, 0, 2, 0, /* 0x14 */ |
michael@0 | 237 | {{2, 2}, |
michael@0 | 238 | {4, 4}, |
michael@0 | 239 | {0, 0}, |
michael@0 | 240 | {0, 0} |
michael@0 | 241 | } |
michael@0 | 242 | }, |
michael@0 | 243 | {1, 0, 3, 0, /* 0x15 */ |
michael@0 | 244 | {{0, 0}, |
michael@0 | 245 | {2, 2}, |
michael@0 | 246 | {4, 4}, |
michael@0 | 247 | {0, 0} |
michael@0 | 248 | } |
michael@0 | 249 | }, |
michael@0 | 250 | {0, 0, 2, 0, /* 0x16 */ |
michael@0 | 251 | {{1, 2}, |
michael@0 | 252 | {4, 4}, |
michael@0 | 253 | {0, 0}, |
michael@0 | 254 | {0, 0} |
michael@0 | 255 | } |
michael@0 | 256 | }, |
michael@0 | 257 | {1, 0, 2, 0, /* 0x17 */ |
michael@0 | 258 | {{0, 2}, |
michael@0 | 259 | {4, 4}, |
michael@0 | 260 | {0, 0}, |
michael@0 | 261 | {0, 0} |
michael@0 | 262 | } |
michael@0 | 263 | }, |
michael@0 | 264 | {0, 0, 1, 0, /* 0x18 */ |
michael@0 | 265 | {{3, 4}, |
michael@0 | 266 | {0, 0}, |
michael@0 | 267 | {0, 0}, |
michael@0 | 268 | {0, 0} |
michael@0 | 269 | } |
michael@0 | 270 | }, |
michael@0 | 271 | {1, 0, 2, 0, /* 0x19 */ |
michael@0 | 272 | {{0, 0}, |
michael@0 | 273 | {3, 4}, |
michael@0 | 274 | {0, 0}, |
michael@0 | 275 | {0, 0} |
michael@0 | 276 | } |
michael@0 | 277 | }, |
michael@0 | 278 | {0, 0, 2, 0, /* 0x1a */ |
michael@0 | 279 | {{1, 1}, |
michael@0 | 280 | {3, 4}, |
michael@0 | 281 | {0, 0}, |
michael@0 | 282 | {0, 0} |
michael@0 | 283 | } |
michael@0 | 284 | }, |
michael@0 | 285 | {1, 0, 2, 0, /* 0x1b */ |
michael@0 | 286 | {{0, 1}, |
michael@0 | 287 | {3, 4}, |
michael@0 | 288 | {0, 0}, |
michael@0 | 289 | {0, 0} |
michael@0 | 290 | } |
michael@0 | 291 | }, |
michael@0 | 292 | {0, 0, 1, 0, /* 0x1c */ |
michael@0 | 293 | {{2, 4}, |
michael@0 | 294 | {0, 0}, |
michael@0 | 295 | {0, 0}, |
michael@0 | 296 | {0, 0} |
michael@0 | 297 | } |
michael@0 | 298 | }, |
michael@0 | 299 | {1, 0, 2, 0, /* 0x1d */ |
michael@0 | 300 | {{0, 0}, |
michael@0 | 301 | {2, 4}, |
michael@0 | 302 | {0, 0}, |
michael@0 | 303 | {0, 0} |
michael@0 | 304 | } |
michael@0 | 305 | }, |
michael@0 | 306 | {0, 0, 1, 0, /* 0x1e */ |
michael@0 | 307 | {{1, 4}, |
michael@0 | 308 | {0, 0}, |
michael@0 | 309 | {0, 0}, |
michael@0 | 310 | {0, 0} |
michael@0 | 311 | } |
michael@0 | 312 | }, |
michael@0 | 313 | {1, 0, 1, 0, /* 0x1f */ |
michael@0 | 314 | {{0, 4}, |
michael@0 | 315 | {0, 0}, |
michael@0 | 316 | {0, 0}, |
michael@0 | 317 | {0, 0} |
michael@0 | 318 | } |
michael@0 | 319 | }, |
michael@0 | 320 | {0, 0, 1, 0, /* 0x20 */ |
michael@0 | 321 | {{5, 5}, |
michael@0 | 322 | {0, 0}, |
michael@0 | 323 | {0, 0}, |
michael@0 | 324 | {0, 0} |
michael@0 | 325 | } |
michael@0 | 326 | }, |
michael@0 | 327 | {1, 0, 2, 0, /* 0x21 */ |
michael@0 | 328 | {{0, 0}, |
michael@0 | 329 | {5, 5}, |
michael@0 | 330 | {0, 0}, |
michael@0 | 331 | {0, 0} |
michael@0 | 332 | } |
michael@0 | 333 | }, |
michael@0 | 334 | {0, 0, 2, 0, /* 0x22 */ |
michael@0 | 335 | {{1, 1}, |
michael@0 | 336 | {5, 5}, |
michael@0 | 337 | {0, 0}, |
michael@0 | 338 | {0, 0} |
michael@0 | 339 | } |
michael@0 | 340 | }, |
michael@0 | 341 | {1, 0, 2, 0, /* 0x23 */ |
michael@0 | 342 | {{0, 1}, |
michael@0 | 343 | {5, 5}, |
michael@0 | 344 | {0, 0}, |
michael@0 | 345 | {0, 0} |
michael@0 | 346 | } |
michael@0 | 347 | }, |
michael@0 | 348 | {0, 0, 2, 0, /* 0x24 */ |
michael@0 | 349 | {{2, 2}, |
michael@0 | 350 | {5, 5}, |
michael@0 | 351 | {0, 0}, |
michael@0 | 352 | {0, 0} |
michael@0 | 353 | } |
michael@0 | 354 | }, |
michael@0 | 355 | {1, 0, 3, 0, /* 0x25 */ |
michael@0 | 356 | {{0, 0}, |
michael@0 | 357 | {2, 2}, |
michael@0 | 358 | {5, 5}, |
michael@0 | 359 | {0, 0} |
michael@0 | 360 | } |
michael@0 | 361 | }, |
michael@0 | 362 | {0, 0, 2, 0, /* 0x26 */ |
michael@0 | 363 | {{1, 2}, |
michael@0 | 364 | {5, 5}, |
michael@0 | 365 | {0, 0}, |
michael@0 | 366 | {0, 0} |
michael@0 | 367 | } |
michael@0 | 368 | }, |
michael@0 | 369 | {1, 0, 2, 0, /* 0x27 */ |
michael@0 | 370 | {{0, 2}, |
michael@0 | 371 | {5, 5}, |
michael@0 | 372 | {0, 0}, |
michael@0 | 373 | {0, 0} |
michael@0 | 374 | } |
michael@0 | 375 | }, |
michael@0 | 376 | {0, 0, 2, 0, /* 0x28 */ |
michael@0 | 377 | {{3, 3}, |
michael@0 | 378 | {5, 5}, |
michael@0 | 379 | {0, 0}, |
michael@0 | 380 | {0, 0} |
michael@0 | 381 | } |
michael@0 | 382 | }, |
michael@0 | 383 | {1, 0, 3, 0, /* 0x29 */ |
michael@0 | 384 | {{0, 0}, |
michael@0 | 385 | {3, 3}, |
michael@0 | 386 | {5, 5}, |
michael@0 | 387 | {0, 0} |
michael@0 | 388 | } |
michael@0 | 389 | }, |
michael@0 | 390 | {0, 0, 3, 0, /* 0x2a */ |
michael@0 | 391 | {{1, 1}, |
michael@0 | 392 | {3, 3}, |
michael@0 | 393 | {5, 5}, |
michael@0 | 394 | {0, 0} |
michael@0 | 395 | } |
michael@0 | 396 | }, |
michael@0 | 397 | {1, 0, 3, 0, /* 0x2b */ |
michael@0 | 398 | {{0, 1}, |
michael@0 | 399 | {3, 3}, |
michael@0 | 400 | {5, 5}, |
michael@0 | 401 | {0, 0} |
michael@0 | 402 | } |
michael@0 | 403 | }, |
michael@0 | 404 | {0, 0, 2, 0, /* 0x2c */ |
michael@0 | 405 | {{2, 3}, |
michael@0 | 406 | {5, 5}, |
michael@0 | 407 | {0, 0}, |
michael@0 | 408 | {0, 0} |
michael@0 | 409 | } |
michael@0 | 410 | }, |
michael@0 | 411 | {1, 0, 3, 0, /* 0x2d */ |
michael@0 | 412 | {{0, 0}, |
michael@0 | 413 | {2, 3}, |
michael@0 | 414 | {5, 5}, |
michael@0 | 415 | {0, 0} |
michael@0 | 416 | } |
michael@0 | 417 | }, |
michael@0 | 418 | {0, 0, 2, 0, /* 0x2e */ |
michael@0 | 419 | {{1, 3}, |
michael@0 | 420 | {5, 5}, |
michael@0 | 421 | {0, 0}, |
michael@0 | 422 | {0, 0} |
michael@0 | 423 | } |
michael@0 | 424 | }, |
michael@0 | 425 | {1, 0, 2, 0, /* 0x2f */ |
michael@0 | 426 | {{0, 3}, |
michael@0 | 427 | {5, 5}, |
michael@0 | 428 | {0, 0}, |
michael@0 | 429 | {0, 0} |
michael@0 | 430 | } |
michael@0 | 431 | }, |
michael@0 | 432 | {0, 0, 1, 0, /* 0x30 */ |
michael@0 | 433 | {{4, 5}, |
michael@0 | 434 | {0, 0}, |
michael@0 | 435 | {0, 0}, |
michael@0 | 436 | {0, 0} |
michael@0 | 437 | } |
michael@0 | 438 | }, |
michael@0 | 439 | {1, 0, 2, 0, /* 0x31 */ |
michael@0 | 440 | {{0, 0}, |
michael@0 | 441 | {4, 5}, |
michael@0 | 442 | {0, 0}, |
michael@0 | 443 | {0, 0} |
michael@0 | 444 | } |
michael@0 | 445 | }, |
michael@0 | 446 | {0, 0, 2, 0, /* 0x32 */ |
michael@0 | 447 | {{1, 1}, |
michael@0 | 448 | {4, 5}, |
michael@0 | 449 | {0, 0}, |
michael@0 | 450 | {0, 0} |
michael@0 | 451 | } |
michael@0 | 452 | }, |
michael@0 | 453 | {1, 0, 2, 0, /* 0x33 */ |
michael@0 | 454 | {{0, 1}, |
michael@0 | 455 | {4, 5}, |
michael@0 | 456 | {0, 0}, |
michael@0 | 457 | {0, 0} |
michael@0 | 458 | } |
michael@0 | 459 | }, |
michael@0 | 460 | {0, 0, 2, 0, /* 0x34 */ |
michael@0 | 461 | {{2, 2}, |
michael@0 | 462 | {4, 5}, |
michael@0 | 463 | {0, 0}, |
michael@0 | 464 | {0, 0} |
michael@0 | 465 | } |
michael@0 | 466 | }, |
michael@0 | 467 | {1, 0, 3, 0, /* 0x35 */ |
michael@0 | 468 | {{0, 0}, |
michael@0 | 469 | {2, 2}, |
michael@0 | 470 | {4, 5}, |
michael@0 | 471 | {0, 0} |
michael@0 | 472 | } |
michael@0 | 473 | }, |
michael@0 | 474 | {0, 0, 2, 0, /* 0x36 */ |
michael@0 | 475 | {{1, 2}, |
michael@0 | 476 | {4, 5}, |
michael@0 | 477 | {0, 0}, |
michael@0 | 478 | {0, 0} |
michael@0 | 479 | } |
michael@0 | 480 | }, |
michael@0 | 481 | {1, 0, 2, 0, /* 0x37 */ |
michael@0 | 482 | {{0, 2}, |
michael@0 | 483 | {4, 5}, |
michael@0 | 484 | {0, 0}, |
michael@0 | 485 | {0, 0} |
michael@0 | 486 | } |
michael@0 | 487 | }, |
michael@0 | 488 | {0, 0, 1, 0, /* 0x38 */ |
michael@0 | 489 | {{3, 5}, |
michael@0 | 490 | {0, 0}, |
michael@0 | 491 | {0, 0}, |
michael@0 | 492 | {0, 0} |
michael@0 | 493 | } |
michael@0 | 494 | }, |
michael@0 | 495 | {1, 0, 2, 0, /* 0x39 */ |
michael@0 | 496 | {{0, 0}, |
michael@0 | 497 | {3, 5}, |
michael@0 | 498 | {0, 0}, |
michael@0 | 499 | {0, 0} |
michael@0 | 500 | } |
michael@0 | 501 | }, |
michael@0 | 502 | {0, 0, 2, 0, /* 0x3a */ |
michael@0 | 503 | {{1, 1}, |
michael@0 | 504 | {3, 5}, |
michael@0 | 505 | {0, 0}, |
michael@0 | 506 | {0, 0} |
michael@0 | 507 | } |
michael@0 | 508 | }, |
michael@0 | 509 | {1, 0, 2, 0, /* 0x3b */ |
michael@0 | 510 | {{0, 1}, |
michael@0 | 511 | {3, 5}, |
michael@0 | 512 | {0, 0}, |
michael@0 | 513 | {0, 0} |
michael@0 | 514 | } |
michael@0 | 515 | }, |
michael@0 | 516 | {0, 0, 1, 0, /* 0x3c */ |
michael@0 | 517 | {{2, 5}, |
michael@0 | 518 | {0, 0}, |
michael@0 | 519 | {0, 0}, |
michael@0 | 520 | {0, 0} |
michael@0 | 521 | } |
michael@0 | 522 | }, |
michael@0 | 523 | {1, 0, 2, 0, /* 0x3d */ |
michael@0 | 524 | {{0, 0}, |
michael@0 | 525 | {2, 5}, |
michael@0 | 526 | {0, 0}, |
michael@0 | 527 | {0, 0} |
michael@0 | 528 | } |
michael@0 | 529 | }, |
michael@0 | 530 | {0, 0, 1, 0, /* 0x3e */ |
michael@0 | 531 | {{1, 5}, |
michael@0 | 532 | {0, 0}, |
michael@0 | 533 | {0, 0}, |
michael@0 | 534 | {0, 0} |
michael@0 | 535 | } |
michael@0 | 536 | }, |
michael@0 | 537 | {1, 0, 1, 0, /* 0x3f */ |
michael@0 | 538 | {{0, 5}, |
michael@0 | 539 | {0, 0}, |
michael@0 | 540 | {0, 0}, |
michael@0 | 541 | {0, 0} |
michael@0 | 542 | } |
michael@0 | 543 | }, |
michael@0 | 544 | {0, 0, 1, 0, /* 0x40 */ |
michael@0 | 545 | {{6, 6}, |
michael@0 | 546 | {0, 0}, |
michael@0 | 547 | {0, 0}, |
michael@0 | 548 | {0, 0} |
michael@0 | 549 | } |
michael@0 | 550 | }, |
michael@0 | 551 | {1, 0, 2, 0, /* 0x41 */ |
michael@0 | 552 | {{0, 0}, |
michael@0 | 553 | {6, 6}, |
michael@0 | 554 | {0, 0}, |
michael@0 | 555 | {0, 0} |
michael@0 | 556 | } |
michael@0 | 557 | }, |
michael@0 | 558 | {0, 0, 2, 0, /* 0x42 */ |
michael@0 | 559 | {{1, 1}, |
michael@0 | 560 | {6, 6}, |
michael@0 | 561 | {0, 0}, |
michael@0 | 562 | {0, 0} |
michael@0 | 563 | } |
michael@0 | 564 | }, |
michael@0 | 565 | {1, 0, 2, 0, /* 0x43 */ |
michael@0 | 566 | {{0, 1}, |
michael@0 | 567 | {6, 6}, |
michael@0 | 568 | {0, 0}, |
michael@0 | 569 | {0, 0} |
michael@0 | 570 | } |
michael@0 | 571 | }, |
michael@0 | 572 | {0, 0, 2, 0, /* 0x44 */ |
michael@0 | 573 | {{2, 2}, |
michael@0 | 574 | {6, 6}, |
michael@0 | 575 | {0, 0}, |
michael@0 | 576 | {0, 0} |
michael@0 | 577 | } |
michael@0 | 578 | }, |
michael@0 | 579 | {1, 0, 3, 0, /* 0x45 */ |
michael@0 | 580 | {{0, 0}, |
michael@0 | 581 | {2, 2}, |
michael@0 | 582 | {6, 6}, |
michael@0 | 583 | {0, 0} |
michael@0 | 584 | } |
michael@0 | 585 | }, |
michael@0 | 586 | {0, 0, 2, 0, /* 0x46 */ |
michael@0 | 587 | {{1, 2}, |
michael@0 | 588 | {6, 6}, |
michael@0 | 589 | {0, 0}, |
michael@0 | 590 | {0, 0} |
michael@0 | 591 | } |
michael@0 | 592 | }, |
michael@0 | 593 | {1, 0, 2, 0, /* 0x47 */ |
michael@0 | 594 | {{0, 2}, |
michael@0 | 595 | {6, 6}, |
michael@0 | 596 | {0, 0}, |
michael@0 | 597 | {0, 0} |
michael@0 | 598 | } |
michael@0 | 599 | }, |
michael@0 | 600 | {0, 0, 2, 0, /* 0x48 */ |
michael@0 | 601 | {{3, 3}, |
michael@0 | 602 | {6, 6}, |
michael@0 | 603 | {0, 0}, |
michael@0 | 604 | {0, 0} |
michael@0 | 605 | } |
michael@0 | 606 | }, |
michael@0 | 607 | {1, 0, 3, 0, /* 0x49 */ |
michael@0 | 608 | {{0, 0}, |
michael@0 | 609 | {3, 3}, |
michael@0 | 610 | {6, 6}, |
michael@0 | 611 | {0, 0} |
michael@0 | 612 | } |
michael@0 | 613 | }, |
michael@0 | 614 | {0, 0, 3, 0, /* 0x4a */ |
michael@0 | 615 | {{1, 1}, |
michael@0 | 616 | {3, 3}, |
michael@0 | 617 | {6, 6}, |
michael@0 | 618 | {0, 0} |
michael@0 | 619 | } |
michael@0 | 620 | }, |
michael@0 | 621 | {1, 0, 3, 0, /* 0x4b */ |
michael@0 | 622 | {{0, 1}, |
michael@0 | 623 | {3, 3}, |
michael@0 | 624 | {6, 6}, |
michael@0 | 625 | {0, 0} |
michael@0 | 626 | } |
michael@0 | 627 | }, |
michael@0 | 628 | {0, 0, 2, 0, /* 0x4c */ |
michael@0 | 629 | {{2, 3}, |
michael@0 | 630 | {6, 6}, |
michael@0 | 631 | {0, 0}, |
michael@0 | 632 | {0, 0} |
michael@0 | 633 | } |
michael@0 | 634 | }, |
michael@0 | 635 | {1, 0, 3, 0, /* 0x4d */ |
michael@0 | 636 | {{0, 0}, |
michael@0 | 637 | {2, 3}, |
michael@0 | 638 | {6, 6}, |
michael@0 | 639 | {0, 0} |
michael@0 | 640 | } |
michael@0 | 641 | }, |
michael@0 | 642 | {0, 0, 2, 0, /* 0x4e */ |
michael@0 | 643 | {{1, 3}, |
michael@0 | 644 | {6, 6}, |
michael@0 | 645 | {0, 0}, |
michael@0 | 646 | {0, 0} |
michael@0 | 647 | } |
michael@0 | 648 | }, |
michael@0 | 649 | {1, 0, 2, 0, /* 0x4f */ |
michael@0 | 650 | {{0, 3}, |
michael@0 | 651 | {6, 6}, |
michael@0 | 652 | {0, 0}, |
michael@0 | 653 | {0, 0} |
michael@0 | 654 | } |
michael@0 | 655 | }, |
michael@0 | 656 | {0, 0, 2, 0, /* 0x50 */ |
michael@0 | 657 | {{4, 4}, |
michael@0 | 658 | {6, 6}, |
michael@0 | 659 | {0, 0}, |
michael@0 | 660 | {0, 0} |
michael@0 | 661 | } |
michael@0 | 662 | }, |
michael@0 | 663 | {1, 0, 3, 0, /* 0x51 */ |
michael@0 | 664 | {{0, 0}, |
michael@0 | 665 | {4, 4}, |
michael@0 | 666 | {6, 6}, |
michael@0 | 667 | {0, 0} |
michael@0 | 668 | } |
michael@0 | 669 | }, |
michael@0 | 670 | {0, 0, 3, 0, /* 0x52 */ |
michael@0 | 671 | {{1, 1}, |
michael@0 | 672 | {4, 4}, |
michael@0 | 673 | {6, 6}, |
michael@0 | 674 | {0, 0} |
michael@0 | 675 | } |
michael@0 | 676 | }, |
michael@0 | 677 | {1, 0, 3, 0, /* 0x53 */ |
michael@0 | 678 | {{0, 1}, |
michael@0 | 679 | {4, 4}, |
michael@0 | 680 | {6, 6}, |
michael@0 | 681 | {0, 0} |
michael@0 | 682 | } |
michael@0 | 683 | }, |
michael@0 | 684 | {0, 0, 3, 0, /* 0x54 */ |
michael@0 | 685 | {{2, 2}, |
michael@0 | 686 | {4, 4}, |
michael@0 | 687 | {6, 6}, |
michael@0 | 688 | {0, 0} |
michael@0 | 689 | } |
michael@0 | 690 | }, |
michael@0 | 691 | {1, 0, 4, 0, /* 0x55 */ |
michael@0 | 692 | {{0, 0}, |
michael@0 | 693 | {2, 2}, |
michael@0 | 694 | {4, 4}, |
michael@0 | 695 | {6, 6} |
michael@0 | 696 | } |
michael@0 | 697 | }, |
michael@0 | 698 | {0, 0, 3, 0, /* 0x56 */ |
michael@0 | 699 | {{1, 2}, |
michael@0 | 700 | {4, 4}, |
michael@0 | 701 | {6, 6}, |
michael@0 | 702 | {0, 0} |
michael@0 | 703 | } |
michael@0 | 704 | }, |
michael@0 | 705 | {1, 0, 3, 0, /* 0x57 */ |
michael@0 | 706 | {{0, 2}, |
michael@0 | 707 | {4, 4}, |
michael@0 | 708 | {6, 6}, |
michael@0 | 709 | {0, 0} |
michael@0 | 710 | } |
michael@0 | 711 | }, |
michael@0 | 712 | {0, 0, 2, 0, /* 0x58 */ |
michael@0 | 713 | {{3, 4}, |
michael@0 | 714 | {6, 6}, |
michael@0 | 715 | {0, 0}, |
michael@0 | 716 | {0, 0} |
michael@0 | 717 | } |
michael@0 | 718 | }, |
michael@0 | 719 | {1, 0, 3, 0, /* 0x59 */ |
michael@0 | 720 | {{0, 0}, |
michael@0 | 721 | {3, 4}, |
michael@0 | 722 | {6, 6}, |
michael@0 | 723 | {0, 0} |
michael@0 | 724 | } |
michael@0 | 725 | }, |
michael@0 | 726 | {0, 0, 3, 0, /* 0x5a */ |
michael@0 | 727 | {{1, 1}, |
michael@0 | 728 | {3, 4}, |
michael@0 | 729 | {6, 6}, |
michael@0 | 730 | {0, 0} |
michael@0 | 731 | } |
michael@0 | 732 | }, |
michael@0 | 733 | {1, 0, 3, 0, /* 0x5b */ |
michael@0 | 734 | {{0, 1}, |
michael@0 | 735 | {3, 4}, |
michael@0 | 736 | {6, 6}, |
michael@0 | 737 | {0, 0} |
michael@0 | 738 | } |
michael@0 | 739 | }, |
michael@0 | 740 | {0, 0, 2, 0, /* 0x5c */ |
michael@0 | 741 | {{2, 4}, |
michael@0 | 742 | {6, 6}, |
michael@0 | 743 | {0, 0}, |
michael@0 | 744 | {0, 0} |
michael@0 | 745 | } |
michael@0 | 746 | }, |
michael@0 | 747 | {1, 0, 3, 0, /* 0x5d */ |
michael@0 | 748 | {{0, 0}, |
michael@0 | 749 | {2, 4}, |
michael@0 | 750 | {6, 6}, |
michael@0 | 751 | {0, 0} |
michael@0 | 752 | } |
michael@0 | 753 | }, |
michael@0 | 754 | {0, 0, 2, 0, /* 0x5e */ |
michael@0 | 755 | {{1, 4}, |
michael@0 | 756 | {6, 6}, |
michael@0 | 757 | {0, 0}, |
michael@0 | 758 | {0, 0} |
michael@0 | 759 | } |
michael@0 | 760 | }, |
michael@0 | 761 | {1, 0, 2, 0, /* 0x5f */ |
michael@0 | 762 | {{0, 4}, |
michael@0 | 763 | {6, 6}, |
michael@0 | 764 | {0, 0}, |
michael@0 | 765 | {0, 0} |
michael@0 | 766 | } |
michael@0 | 767 | }, |
michael@0 | 768 | {0, 0, 1, 0, /* 0x60 */ |
michael@0 | 769 | {{5, 6}, |
michael@0 | 770 | {0, 0}, |
michael@0 | 771 | {0, 0}, |
michael@0 | 772 | {0, 0} |
michael@0 | 773 | } |
michael@0 | 774 | }, |
michael@0 | 775 | {1, 0, 2, 0, /* 0x61 */ |
michael@0 | 776 | {{0, 0}, |
michael@0 | 777 | {5, 6}, |
michael@0 | 778 | {0, 0}, |
michael@0 | 779 | {0, 0} |
michael@0 | 780 | } |
michael@0 | 781 | }, |
michael@0 | 782 | {0, 0, 2, 0, /* 0x62 */ |
michael@0 | 783 | {{1, 1}, |
michael@0 | 784 | {5, 6}, |
michael@0 | 785 | {0, 0}, |
michael@0 | 786 | {0, 0} |
michael@0 | 787 | } |
michael@0 | 788 | }, |
michael@0 | 789 | {1, 0, 2, 0, /* 0x63 */ |
michael@0 | 790 | {{0, 1}, |
michael@0 | 791 | {5, 6}, |
michael@0 | 792 | {0, 0}, |
michael@0 | 793 | {0, 0} |
michael@0 | 794 | } |
michael@0 | 795 | }, |
michael@0 | 796 | {0, 0, 2, 0, /* 0x64 */ |
michael@0 | 797 | {{2, 2}, |
michael@0 | 798 | {5, 6}, |
michael@0 | 799 | {0, 0}, |
michael@0 | 800 | {0, 0} |
michael@0 | 801 | } |
michael@0 | 802 | }, |
michael@0 | 803 | {1, 0, 3, 0, /* 0x65 */ |
michael@0 | 804 | {{0, 0}, |
michael@0 | 805 | {2, 2}, |
michael@0 | 806 | {5, 6}, |
michael@0 | 807 | {0, 0} |
michael@0 | 808 | } |
michael@0 | 809 | }, |
michael@0 | 810 | {0, 0, 2, 0, /* 0x66 */ |
michael@0 | 811 | {{1, 2}, |
michael@0 | 812 | {5, 6}, |
michael@0 | 813 | {0, 0}, |
michael@0 | 814 | {0, 0} |
michael@0 | 815 | } |
michael@0 | 816 | }, |
michael@0 | 817 | {1, 0, 2, 0, /* 0x67 */ |
michael@0 | 818 | {{0, 2}, |
michael@0 | 819 | {5, 6}, |
michael@0 | 820 | {0, 0}, |
michael@0 | 821 | {0, 0} |
michael@0 | 822 | } |
michael@0 | 823 | }, |
michael@0 | 824 | {0, 0, 2, 0, /* 0x68 */ |
michael@0 | 825 | {{3, 3}, |
michael@0 | 826 | {5, 6}, |
michael@0 | 827 | {0, 0}, |
michael@0 | 828 | {0, 0} |
michael@0 | 829 | } |
michael@0 | 830 | }, |
michael@0 | 831 | {1, 0, 3, 0, /* 0x69 */ |
michael@0 | 832 | {{0, 0}, |
michael@0 | 833 | {3, 3}, |
michael@0 | 834 | {5, 6}, |
michael@0 | 835 | {0, 0} |
michael@0 | 836 | } |
michael@0 | 837 | }, |
michael@0 | 838 | {0, 0, 3, 0, /* 0x6a */ |
michael@0 | 839 | {{1, 1}, |
michael@0 | 840 | {3, 3}, |
michael@0 | 841 | {5, 6}, |
michael@0 | 842 | {0, 0} |
michael@0 | 843 | } |
michael@0 | 844 | }, |
michael@0 | 845 | {1, 0, 3, 0, /* 0x6b */ |
michael@0 | 846 | {{0, 1}, |
michael@0 | 847 | {3, 3}, |
michael@0 | 848 | {5, 6}, |
michael@0 | 849 | {0, 0} |
michael@0 | 850 | } |
michael@0 | 851 | }, |
michael@0 | 852 | {0, 0, 2, 0, /* 0x6c */ |
michael@0 | 853 | {{2, 3}, |
michael@0 | 854 | {5, 6}, |
michael@0 | 855 | {0, 0}, |
michael@0 | 856 | {0, 0} |
michael@0 | 857 | } |
michael@0 | 858 | }, |
michael@0 | 859 | {1, 0, 3, 0, /* 0x6d */ |
michael@0 | 860 | {{0, 0}, |
michael@0 | 861 | {2, 3}, |
michael@0 | 862 | {5, 6}, |
michael@0 | 863 | {0, 0} |
michael@0 | 864 | } |
michael@0 | 865 | }, |
michael@0 | 866 | {0, 0, 2, 0, /* 0x6e */ |
michael@0 | 867 | {{1, 3}, |
michael@0 | 868 | {5, 6}, |
michael@0 | 869 | {0, 0}, |
michael@0 | 870 | {0, 0} |
michael@0 | 871 | } |
michael@0 | 872 | }, |
michael@0 | 873 | {1, 0, 2, 0, /* 0x6f */ |
michael@0 | 874 | {{0, 3}, |
michael@0 | 875 | {5, 6}, |
michael@0 | 876 | {0, 0}, |
michael@0 | 877 | {0, 0} |
michael@0 | 878 | } |
michael@0 | 879 | }, |
michael@0 | 880 | {0, 0, 1, 0, /* 0x70 */ |
michael@0 | 881 | {{4, 6}, |
michael@0 | 882 | {0, 0}, |
michael@0 | 883 | {0, 0}, |
michael@0 | 884 | {0, 0} |
michael@0 | 885 | } |
michael@0 | 886 | }, |
michael@0 | 887 | {1, 0, 2, 0, /* 0x71 */ |
michael@0 | 888 | {{0, 0}, |
michael@0 | 889 | {4, 6}, |
michael@0 | 890 | {0, 0}, |
michael@0 | 891 | {0, 0} |
michael@0 | 892 | } |
michael@0 | 893 | }, |
michael@0 | 894 | {0, 0, 2, 0, /* 0x72 */ |
michael@0 | 895 | {{1, 1}, |
michael@0 | 896 | {4, 6}, |
michael@0 | 897 | {0, 0}, |
michael@0 | 898 | {0, 0} |
michael@0 | 899 | } |
michael@0 | 900 | }, |
michael@0 | 901 | {1, 0, 2, 0, /* 0x73 */ |
michael@0 | 902 | {{0, 1}, |
michael@0 | 903 | {4, 6}, |
michael@0 | 904 | {0, 0}, |
michael@0 | 905 | {0, 0} |
michael@0 | 906 | } |
michael@0 | 907 | }, |
michael@0 | 908 | {0, 0, 2, 0, /* 0x74 */ |
michael@0 | 909 | {{2, 2}, |
michael@0 | 910 | {4, 6}, |
michael@0 | 911 | {0, 0}, |
michael@0 | 912 | {0, 0} |
michael@0 | 913 | } |
michael@0 | 914 | }, |
michael@0 | 915 | {1, 0, 3, 0, /* 0x75 */ |
michael@0 | 916 | {{0, 0}, |
michael@0 | 917 | {2, 2}, |
michael@0 | 918 | {4, 6}, |
michael@0 | 919 | {0, 0} |
michael@0 | 920 | } |
michael@0 | 921 | }, |
michael@0 | 922 | {0, 0, 2, 0, /* 0x76 */ |
michael@0 | 923 | {{1, 2}, |
michael@0 | 924 | {4, 6}, |
michael@0 | 925 | {0, 0}, |
michael@0 | 926 | {0, 0} |
michael@0 | 927 | } |
michael@0 | 928 | }, |
michael@0 | 929 | {1, 0, 2, 0, /* 0x77 */ |
michael@0 | 930 | {{0, 2}, |
michael@0 | 931 | {4, 6}, |
michael@0 | 932 | {0, 0}, |
michael@0 | 933 | {0, 0} |
michael@0 | 934 | } |
michael@0 | 935 | }, |
michael@0 | 936 | {0, 0, 1, 0, /* 0x78 */ |
michael@0 | 937 | {{3, 6}, |
michael@0 | 938 | {0, 0}, |
michael@0 | 939 | {0, 0}, |
michael@0 | 940 | {0, 0} |
michael@0 | 941 | } |
michael@0 | 942 | }, |
michael@0 | 943 | {1, 0, 2, 0, /* 0x79 */ |
michael@0 | 944 | {{0, 0}, |
michael@0 | 945 | {3, 6}, |
michael@0 | 946 | {0, 0}, |
michael@0 | 947 | {0, 0} |
michael@0 | 948 | } |
michael@0 | 949 | }, |
michael@0 | 950 | {0, 0, 2, 0, /* 0x7a */ |
michael@0 | 951 | {{1, 1}, |
michael@0 | 952 | {3, 6}, |
michael@0 | 953 | {0, 0}, |
michael@0 | 954 | {0, 0} |
michael@0 | 955 | } |
michael@0 | 956 | }, |
michael@0 | 957 | {1, 0, 2, 0, /* 0x7b */ |
michael@0 | 958 | {{0, 1}, |
michael@0 | 959 | {3, 6}, |
michael@0 | 960 | {0, 0}, |
michael@0 | 961 | {0, 0} |
michael@0 | 962 | } |
michael@0 | 963 | }, |
michael@0 | 964 | {0, 0, 1, 0, /* 0x7c */ |
michael@0 | 965 | {{2, 6}, |
michael@0 | 966 | {0, 0}, |
michael@0 | 967 | {0, 0}, |
michael@0 | 968 | {0, 0} |
michael@0 | 969 | } |
michael@0 | 970 | }, |
michael@0 | 971 | {1, 0, 2, 0, /* 0x7d */ |
michael@0 | 972 | {{0, 0}, |
michael@0 | 973 | {2, 6}, |
michael@0 | 974 | {0, 0}, |
michael@0 | 975 | {0, 0} |
michael@0 | 976 | } |
michael@0 | 977 | }, |
michael@0 | 978 | {0, 0, 1, 0, /* 0x7e */ |
michael@0 | 979 | {{1, 6}, |
michael@0 | 980 | {0, 0}, |
michael@0 | 981 | {0, 0}, |
michael@0 | 982 | {0, 0} |
michael@0 | 983 | } |
michael@0 | 984 | }, |
michael@0 | 985 | {1, 0, 1, 0, /* 0x7f */ |
michael@0 | 986 | {{0, 6}, |
michael@0 | 987 | {0, 0}, |
michael@0 | 988 | {0, 0}, |
michael@0 | 989 | {0, 0} |
michael@0 | 990 | } |
michael@0 | 991 | }, |
michael@0 | 992 | {0, 1, 1, 0, /* 0x80 */ |
michael@0 | 993 | {{7, 7}, |
michael@0 | 994 | {0, 0}, |
michael@0 | 995 | {0, 0}, |
michael@0 | 996 | {0, 0} |
michael@0 | 997 | } |
michael@0 | 998 | }, |
michael@0 | 999 | {1, 1, 2, 0, /* 0x81 */ |
michael@0 | 1000 | {{0, 0}, |
michael@0 | 1001 | {7, 7}, |
michael@0 | 1002 | {0, 0}, |
michael@0 | 1003 | {0, 0} |
michael@0 | 1004 | } |
michael@0 | 1005 | }, |
michael@0 | 1006 | {0, 1, 2, 0, /* 0x82 */ |
michael@0 | 1007 | {{1, 1}, |
michael@0 | 1008 | {7, 7}, |
michael@0 | 1009 | {0, 0}, |
michael@0 | 1010 | {0, 0} |
michael@0 | 1011 | } |
michael@0 | 1012 | }, |
michael@0 | 1013 | {1, 1, 2, 0, /* 0x83 */ |
michael@0 | 1014 | {{0, 1}, |
michael@0 | 1015 | {7, 7}, |
michael@0 | 1016 | {0, 0}, |
michael@0 | 1017 | {0, 0} |
michael@0 | 1018 | } |
michael@0 | 1019 | }, |
michael@0 | 1020 | {0, 1, 2, 0, /* 0x84 */ |
michael@0 | 1021 | {{2, 2}, |
michael@0 | 1022 | {7, 7}, |
michael@0 | 1023 | {0, 0}, |
michael@0 | 1024 | {0, 0} |
michael@0 | 1025 | } |
michael@0 | 1026 | }, |
michael@0 | 1027 | {1, 1, 3, 0, /* 0x85 */ |
michael@0 | 1028 | {{0, 0}, |
michael@0 | 1029 | {2, 2}, |
michael@0 | 1030 | {7, 7}, |
michael@0 | 1031 | {0, 0} |
michael@0 | 1032 | } |
michael@0 | 1033 | }, |
michael@0 | 1034 | {0, 1, 2, 0, /* 0x86 */ |
michael@0 | 1035 | {{1, 2}, |
michael@0 | 1036 | {7, 7}, |
michael@0 | 1037 | {0, 0}, |
michael@0 | 1038 | {0, 0} |
michael@0 | 1039 | } |
michael@0 | 1040 | }, |
michael@0 | 1041 | {1, 1, 2, 0, /* 0x87 */ |
michael@0 | 1042 | {{0, 2}, |
michael@0 | 1043 | {7, 7}, |
michael@0 | 1044 | {0, 0}, |
michael@0 | 1045 | {0, 0} |
michael@0 | 1046 | } |
michael@0 | 1047 | }, |
michael@0 | 1048 | {0, 1, 2, 0, /* 0x88 */ |
michael@0 | 1049 | {{3, 3}, |
michael@0 | 1050 | {7, 7}, |
michael@0 | 1051 | {0, 0}, |
michael@0 | 1052 | {0, 0} |
michael@0 | 1053 | } |
michael@0 | 1054 | }, |
michael@0 | 1055 | {1, 1, 3, 0, /* 0x89 */ |
michael@0 | 1056 | {{0, 0}, |
michael@0 | 1057 | {3, 3}, |
michael@0 | 1058 | {7, 7}, |
michael@0 | 1059 | {0, 0} |
michael@0 | 1060 | } |
michael@0 | 1061 | }, |
michael@0 | 1062 | {0, 1, 3, 0, /* 0x8a */ |
michael@0 | 1063 | {{1, 1}, |
michael@0 | 1064 | {3, 3}, |
michael@0 | 1065 | {7, 7}, |
michael@0 | 1066 | {0, 0} |
michael@0 | 1067 | } |
michael@0 | 1068 | }, |
michael@0 | 1069 | {1, 1, 3, 0, /* 0x8b */ |
michael@0 | 1070 | {{0, 1}, |
michael@0 | 1071 | {3, 3}, |
michael@0 | 1072 | {7, 7}, |
michael@0 | 1073 | {0, 0} |
michael@0 | 1074 | } |
michael@0 | 1075 | }, |
michael@0 | 1076 | {0, 1, 2, 0, /* 0x8c */ |
michael@0 | 1077 | {{2, 3}, |
michael@0 | 1078 | {7, 7}, |
michael@0 | 1079 | {0, 0}, |
michael@0 | 1080 | {0, 0} |
michael@0 | 1081 | } |
michael@0 | 1082 | }, |
michael@0 | 1083 | {1, 1, 3, 0, /* 0x8d */ |
michael@0 | 1084 | {{0, 0}, |
michael@0 | 1085 | {2, 3}, |
michael@0 | 1086 | {7, 7}, |
michael@0 | 1087 | {0, 0} |
michael@0 | 1088 | } |
michael@0 | 1089 | }, |
michael@0 | 1090 | {0, 1, 2, 0, /* 0x8e */ |
michael@0 | 1091 | {{1, 3}, |
michael@0 | 1092 | {7, 7}, |
michael@0 | 1093 | {0, 0}, |
michael@0 | 1094 | {0, 0} |
michael@0 | 1095 | } |
michael@0 | 1096 | }, |
michael@0 | 1097 | {1, 1, 2, 0, /* 0x8f */ |
michael@0 | 1098 | {{0, 3}, |
michael@0 | 1099 | {7, 7}, |
michael@0 | 1100 | {0, 0}, |
michael@0 | 1101 | {0, 0} |
michael@0 | 1102 | } |
michael@0 | 1103 | }, |
michael@0 | 1104 | {0, 1, 2, 0, /* 0x90 */ |
michael@0 | 1105 | {{4, 4}, |
michael@0 | 1106 | {7, 7}, |
michael@0 | 1107 | {0, 0}, |
michael@0 | 1108 | {0, 0} |
michael@0 | 1109 | } |
michael@0 | 1110 | }, |
michael@0 | 1111 | {1, 1, 3, 0, /* 0x91 */ |
michael@0 | 1112 | {{0, 0}, |
michael@0 | 1113 | {4, 4}, |
michael@0 | 1114 | {7, 7}, |
michael@0 | 1115 | {0, 0} |
michael@0 | 1116 | } |
michael@0 | 1117 | }, |
michael@0 | 1118 | {0, 1, 3, 0, /* 0x92 */ |
michael@0 | 1119 | {{1, 1}, |
michael@0 | 1120 | {4, 4}, |
michael@0 | 1121 | {7, 7}, |
michael@0 | 1122 | {0, 0} |
michael@0 | 1123 | } |
michael@0 | 1124 | }, |
michael@0 | 1125 | {1, 1, 3, 0, /* 0x93 */ |
michael@0 | 1126 | {{0, 1}, |
michael@0 | 1127 | {4, 4}, |
michael@0 | 1128 | {7, 7}, |
michael@0 | 1129 | {0, 0} |
michael@0 | 1130 | } |
michael@0 | 1131 | }, |
michael@0 | 1132 | {0, 1, 3, 0, /* 0x94 */ |
michael@0 | 1133 | {{2, 2}, |
michael@0 | 1134 | {4, 4}, |
michael@0 | 1135 | {7, 7}, |
michael@0 | 1136 | {0, 0} |
michael@0 | 1137 | } |
michael@0 | 1138 | }, |
michael@0 | 1139 | {1, 1, 4, 0, /* 0x95 */ |
michael@0 | 1140 | {{0, 0}, |
michael@0 | 1141 | {2, 2}, |
michael@0 | 1142 | {4, 4}, |
michael@0 | 1143 | {7, 7} |
michael@0 | 1144 | } |
michael@0 | 1145 | }, |
michael@0 | 1146 | {0, 1, 3, 0, /* 0x96 */ |
michael@0 | 1147 | {{1, 2}, |
michael@0 | 1148 | {4, 4}, |
michael@0 | 1149 | {7, 7}, |
michael@0 | 1150 | {0, 0} |
michael@0 | 1151 | } |
michael@0 | 1152 | }, |
michael@0 | 1153 | {1, 1, 3, 0, /* 0x97 */ |
michael@0 | 1154 | {{0, 2}, |
michael@0 | 1155 | {4, 4}, |
michael@0 | 1156 | {7, 7}, |
michael@0 | 1157 | {0, 0} |
michael@0 | 1158 | } |
michael@0 | 1159 | }, |
michael@0 | 1160 | {0, 1, 2, 0, /* 0x98 */ |
michael@0 | 1161 | {{3, 4}, |
michael@0 | 1162 | {7, 7}, |
michael@0 | 1163 | {0, 0}, |
michael@0 | 1164 | {0, 0} |
michael@0 | 1165 | } |
michael@0 | 1166 | }, |
michael@0 | 1167 | {1, 1, 3, 0, /* 0x99 */ |
michael@0 | 1168 | {{0, 0}, |
michael@0 | 1169 | {3, 4}, |
michael@0 | 1170 | {7, 7}, |
michael@0 | 1171 | {0, 0} |
michael@0 | 1172 | } |
michael@0 | 1173 | }, |
michael@0 | 1174 | {0, 1, 3, 0, /* 0x9a */ |
michael@0 | 1175 | {{1, 1}, |
michael@0 | 1176 | {3, 4}, |
michael@0 | 1177 | {7, 7}, |
michael@0 | 1178 | {0, 0} |
michael@0 | 1179 | } |
michael@0 | 1180 | }, |
michael@0 | 1181 | {1, 1, 3, 0, /* 0x9b */ |
michael@0 | 1182 | {{0, 1}, |
michael@0 | 1183 | {3, 4}, |
michael@0 | 1184 | {7, 7}, |
michael@0 | 1185 | {0, 0} |
michael@0 | 1186 | } |
michael@0 | 1187 | }, |
michael@0 | 1188 | {0, 1, 2, 0, /* 0x9c */ |
michael@0 | 1189 | {{2, 4}, |
michael@0 | 1190 | {7, 7}, |
michael@0 | 1191 | {0, 0}, |
michael@0 | 1192 | {0, 0} |
michael@0 | 1193 | } |
michael@0 | 1194 | }, |
michael@0 | 1195 | {1, 1, 3, 0, /* 0x9d */ |
michael@0 | 1196 | {{0, 0}, |
michael@0 | 1197 | {2, 4}, |
michael@0 | 1198 | {7, 7}, |
michael@0 | 1199 | {0, 0} |
michael@0 | 1200 | } |
michael@0 | 1201 | }, |
michael@0 | 1202 | {0, 1, 2, 0, /* 0x9e */ |
michael@0 | 1203 | {{1, 4}, |
michael@0 | 1204 | {7, 7}, |
michael@0 | 1205 | {0, 0}, |
michael@0 | 1206 | {0, 0} |
michael@0 | 1207 | } |
michael@0 | 1208 | }, |
michael@0 | 1209 | {1, 1, 2, 0, /* 0x9f */ |
michael@0 | 1210 | {{0, 4}, |
michael@0 | 1211 | {7, 7}, |
michael@0 | 1212 | {0, 0}, |
michael@0 | 1213 | {0, 0} |
michael@0 | 1214 | } |
michael@0 | 1215 | }, |
michael@0 | 1216 | {0, 1, 2, 0, /* 0xa0 */ |
michael@0 | 1217 | {{5, 5}, |
michael@0 | 1218 | {7, 7}, |
michael@0 | 1219 | {0, 0}, |
michael@0 | 1220 | {0, 0} |
michael@0 | 1221 | } |
michael@0 | 1222 | }, |
michael@0 | 1223 | {1, 1, 3, 0, /* 0xa1 */ |
michael@0 | 1224 | {{0, 0}, |
michael@0 | 1225 | {5, 5}, |
michael@0 | 1226 | {7, 7}, |
michael@0 | 1227 | {0, 0} |
michael@0 | 1228 | } |
michael@0 | 1229 | }, |
michael@0 | 1230 | {0, 1, 3, 0, /* 0xa2 */ |
michael@0 | 1231 | {{1, 1}, |
michael@0 | 1232 | {5, 5}, |
michael@0 | 1233 | {7, 7}, |
michael@0 | 1234 | {0, 0} |
michael@0 | 1235 | } |
michael@0 | 1236 | }, |
michael@0 | 1237 | {1, 1, 3, 0, /* 0xa3 */ |
michael@0 | 1238 | {{0, 1}, |
michael@0 | 1239 | {5, 5}, |
michael@0 | 1240 | {7, 7}, |
michael@0 | 1241 | {0, 0} |
michael@0 | 1242 | } |
michael@0 | 1243 | }, |
michael@0 | 1244 | {0, 1, 3, 0, /* 0xa4 */ |
michael@0 | 1245 | {{2, 2}, |
michael@0 | 1246 | {5, 5}, |
michael@0 | 1247 | {7, 7}, |
michael@0 | 1248 | {0, 0} |
michael@0 | 1249 | } |
michael@0 | 1250 | }, |
michael@0 | 1251 | {1, 1, 4, 0, /* 0xa5 */ |
michael@0 | 1252 | {{0, 0}, |
michael@0 | 1253 | {2, 2}, |
michael@0 | 1254 | {5, 5}, |
michael@0 | 1255 | {7, 7} |
michael@0 | 1256 | } |
michael@0 | 1257 | }, |
michael@0 | 1258 | {0, 1, 3, 0, /* 0xa6 */ |
michael@0 | 1259 | {{1, 2}, |
michael@0 | 1260 | {5, 5}, |
michael@0 | 1261 | {7, 7}, |
michael@0 | 1262 | {0, 0} |
michael@0 | 1263 | } |
michael@0 | 1264 | }, |
michael@0 | 1265 | {1, 1, 3, 0, /* 0xa7 */ |
michael@0 | 1266 | {{0, 2}, |
michael@0 | 1267 | {5, 5}, |
michael@0 | 1268 | {7, 7}, |
michael@0 | 1269 | {0, 0} |
michael@0 | 1270 | } |
michael@0 | 1271 | }, |
michael@0 | 1272 | {0, 1, 3, 0, /* 0xa8 */ |
michael@0 | 1273 | {{3, 3}, |
michael@0 | 1274 | {5, 5}, |
michael@0 | 1275 | {7, 7}, |
michael@0 | 1276 | {0, 0} |
michael@0 | 1277 | } |
michael@0 | 1278 | }, |
michael@0 | 1279 | {1, 1, 4, 0, /* 0xa9 */ |
michael@0 | 1280 | {{0, 0}, |
michael@0 | 1281 | {3, 3}, |
michael@0 | 1282 | {5, 5}, |
michael@0 | 1283 | {7, 7} |
michael@0 | 1284 | } |
michael@0 | 1285 | }, |
michael@0 | 1286 | {0, 1, 4, 0, /* 0xaa */ |
michael@0 | 1287 | {{1, 1}, |
michael@0 | 1288 | {3, 3}, |
michael@0 | 1289 | {5, 5}, |
michael@0 | 1290 | {7, 7} |
michael@0 | 1291 | } |
michael@0 | 1292 | }, |
michael@0 | 1293 | {1, 1, 4, 0, /* 0xab */ |
michael@0 | 1294 | {{0, 1}, |
michael@0 | 1295 | {3, 3}, |
michael@0 | 1296 | {5, 5}, |
michael@0 | 1297 | {7, 7} |
michael@0 | 1298 | } |
michael@0 | 1299 | }, |
michael@0 | 1300 | {0, 1, 3, 0, /* 0xac */ |
michael@0 | 1301 | {{2, 3}, |
michael@0 | 1302 | {5, 5}, |
michael@0 | 1303 | {7, 7}, |
michael@0 | 1304 | {0, 0} |
michael@0 | 1305 | } |
michael@0 | 1306 | }, |
michael@0 | 1307 | {1, 1, 4, 0, /* 0xad */ |
michael@0 | 1308 | {{0, 0}, |
michael@0 | 1309 | {2, 3}, |
michael@0 | 1310 | {5, 5}, |
michael@0 | 1311 | {7, 7} |
michael@0 | 1312 | } |
michael@0 | 1313 | }, |
michael@0 | 1314 | {0, 1, 3, 0, /* 0xae */ |
michael@0 | 1315 | {{1, 3}, |
michael@0 | 1316 | {5, 5}, |
michael@0 | 1317 | {7, 7}, |
michael@0 | 1318 | {0, 0} |
michael@0 | 1319 | } |
michael@0 | 1320 | }, |
michael@0 | 1321 | {1, 1, 3, 0, /* 0xaf */ |
michael@0 | 1322 | {{0, 3}, |
michael@0 | 1323 | {5, 5}, |
michael@0 | 1324 | {7, 7}, |
michael@0 | 1325 | {0, 0} |
michael@0 | 1326 | } |
michael@0 | 1327 | }, |
michael@0 | 1328 | {0, 1, 2, 0, /* 0xb0 */ |
michael@0 | 1329 | {{4, 5}, |
michael@0 | 1330 | {7, 7}, |
michael@0 | 1331 | {0, 0}, |
michael@0 | 1332 | {0, 0} |
michael@0 | 1333 | } |
michael@0 | 1334 | }, |
michael@0 | 1335 | {1, 1, 3, 0, /* 0xb1 */ |
michael@0 | 1336 | {{0, 0}, |
michael@0 | 1337 | {4, 5}, |
michael@0 | 1338 | {7, 7}, |
michael@0 | 1339 | {0, 0} |
michael@0 | 1340 | } |
michael@0 | 1341 | }, |
michael@0 | 1342 | {0, 1, 3, 0, /* 0xb2 */ |
michael@0 | 1343 | {{1, 1}, |
michael@0 | 1344 | {4, 5}, |
michael@0 | 1345 | {7, 7}, |
michael@0 | 1346 | {0, 0} |
michael@0 | 1347 | } |
michael@0 | 1348 | }, |
michael@0 | 1349 | {1, 1, 3, 0, /* 0xb3 */ |
michael@0 | 1350 | {{0, 1}, |
michael@0 | 1351 | {4, 5}, |
michael@0 | 1352 | {7, 7}, |
michael@0 | 1353 | {0, 0} |
michael@0 | 1354 | } |
michael@0 | 1355 | }, |
michael@0 | 1356 | {0, 1, 3, 0, /* 0xb4 */ |
michael@0 | 1357 | {{2, 2}, |
michael@0 | 1358 | {4, 5}, |
michael@0 | 1359 | {7, 7}, |
michael@0 | 1360 | {0, 0} |
michael@0 | 1361 | } |
michael@0 | 1362 | }, |
michael@0 | 1363 | {1, 1, 4, 0, /* 0xb5 */ |
michael@0 | 1364 | {{0, 0}, |
michael@0 | 1365 | {2, 2}, |
michael@0 | 1366 | {4, 5}, |
michael@0 | 1367 | {7, 7} |
michael@0 | 1368 | } |
michael@0 | 1369 | }, |
michael@0 | 1370 | {0, 1, 3, 0, /* 0xb6 */ |
michael@0 | 1371 | {{1, 2}, |
michael@0 | 1372 | {4, 5}, |
michael@0 | 1373 | {7, 7}, |
michael@0 | 1374 | {0, 0} |
michael@0 | 1375 | } |
michael@0 | 1376 | }, |
michael@0 | 1377 | {1, 1, 3, 0, /* 0xb7 */ |
michael@0 | 1378 | {{0, 2}, |
michael@0 | 1379 | {4, 5}, |
michael@0 | 1380 | {7, 7}, |
michael@0 | 1381 | {0, 0} |
michael@0 | 1382 | } |
michael@0 | 1383 | }, |
michael@0 | 1384 | {0, 1, 2, 0, /* 0xb8 */ |
michael@0 | 1385 | {{3, 5}, |
michael@0 | 1386 | {7, 7}, |
michael@0 | 1387 | {0, 0}, |
michael@0 | 1388 | {0, 0} |
michael@0 | 1389 | } |
michael@0 | 1390 | }, |
michael@0 | 1391 | {1, 1, 3, 0, /* 0xb9 */ |
michael@0 | 1392 | {{0, 0}, |
michael@0 | 1393 | {3, 5}, |
michael@0 | 1394 | {7, 7}, |
michael@0 | 1395 | {0, 0} |
michael@0 | 1396 | } |
michael@0 | 1397 | }, |
michael@0 | 1398 | {0, 1, 3, 0, /* 0xba */ |
michael@0 | 1399 | {{1, 1}, |
michael@0 | 1400 | {3, 5}, |
michael@0 | 1401 | {7, 7}, |
michael@0 | 1402 | {0, 0} |
michael@0 | 1403 | } |
michael@0 | 1404 | }, |
michael@0 | 1405 | {1, 1, 3, 0, /* 0xbb */ |
michael@0 | 1406 | {{0, 1}, |
michael@0 | 1407 | {3, 5}, |
michael@0 | 1408 | {7, 7}, |
michael@0 | 1409 | {0, 0} |
michael@0 | 1410 | } |
michael@0 | 1411 | }, |
michael@0 | 1412 | {0, 1, 2, 0, /* 0xbc */ |
michael@0 | 1413 | {{2, 5}, |
michael@0 | 1414 | {7, 7}, |
michael@0 | 1415 | {0, 0}, |
michael@0 | 1416 | {0, 0} |
michael@0 | 1417 | } |
michael@0 | 1418 | }, |
michael@0 | 1419 | {1, 1, 3, 0, /* 0xbd */ |
michael@0 | 1420 | {{0, 0}, |
michael@0 | 1421 | {2, 5}, |
michael@0 | 1422 | {7, 7}, |
michael@0 | 1423 | {0, 0} |
michael@0 | 1424 | } |
michael@0 | 1425 | }, |
michael@0 | 1426 | {0, 1, 2, 0, /* 0xbe */ |
michael@0 | 1427 | {{1, 5}, |
michael@0 | 1428 | {7, 7}, |
michael@0 | 1429 | {0, 0}, |
michael@0 | 1430 | {0, 0} |
michael@0 | 1431 | } |
michael@0 | 1432 | }, |
michael@0 | 1433 | {1, 1, 2, 0, /* 0xbf */ |
michael@0 | 1434 | {{0, 5}, |
michael@0 | 1435 | {7, 7}, |
michael@0 | 1436 | {0, 0}, |
michael@0 | 1437 | {0, 0} |
michael@0 | 1438 | } |
michael@0 | 1439 | }, |
michael@0 | 1440 | {0, 1, 1, 0, /* 0xc0 */ |
michael@0 | 1441 | {{6, 7}, |
michael@0 | 1442 | {0, 0}, |
michael@0 | 1443 | {0, 0}, |
michael@0 | 1444 | {0, 0} |
michael@0 | 1445 | } |
michael@0 | 1446 | }, |
michael@0 | 1447 | {1, 1, 2, 0, /* 0xc1 */ |
michael@0 | 1448 | {{0, 0}, |
michael@0 | 1449 | {6, 7}, |
michael@0 | 1450 | {0, 0}, |
michael@0 | 1451 | {0, 0} |
michael@0 | 1452 | } |
michael@0 | 1453 | }, |
michael@0 | 1454 | {0, 1, 2, 0, /* 0xc2 */ |
michael@0 | 1455 | {{1, 1}, |
michael@0 | 1456 | {6, 7}, |
michael@0 | 1457 | {0, 0}, |
michael@0 | 1458 | {0, 0} |
michael@0 | 1459 | } |
michael@0 | 1460 | }, |
michael@0 | 1461 | {1, 1, 2, 0, /* 0xc3 */ |
michael@0 | 1462 | {{0, 1}, |
michael@0 | 1463 | {6, 7}, |
michael@0 | 1464 | {0, 0}, |
michael@0 | 1465 | {0, 0} |
michael@0 | 1466 | } |
michael@0 | 1467 | }, |
michael@0 | 1468 | {0, 1, 2, 0, /* 0xc4 */ |
michael@0 | 1469 | {{2, 2}, |
michael@0 | 1470 | {6, 7}, |
michael@0 | 1471 | {0, 0}, |
michael@0 | 1472 | {0, 0} |
michael@0 | 1473 | } |
michael@0 | 1474 | }, |
michael@0 | 1475 | {1, 1, 3, 0, /* 0xc5 */ |
michael@0 | 1476 | {{0, 0}, |
michael@0 | 1477 | {2, 2}, |
michael@0 | 1478 | {6, 7}, |
michael@0 | 1479 | {0, 0} |
michael@0 | 1480 | } |
michael@0 | 1481 | }, |
michael@0 | 1482 | {0, 1, 2, 0, /* 0xc6 */ |
michael@0 | 1483 | {{1, 2}, |
michael@0 | 1484 | {6, 7}, |
michael@0 | 1485 | {0, 0}, |
michael@0 | 1486 | {0, 0} |
michael@0 | 1487 | } |
michael@0 | 1488 | }, |
michael@0 | 1489 | {1, 1, 2, 0, /* 0xc7 */ |
michael@0 | 1490 | {{0, 2}, |
michael@0 | 1491 | {6, 7}, |
michael@0 | 1492 | {0, 0}, |
michael@0 | 1493 | {0, 0} |
michael@0 | 1494 | } |
michael@0 | 1495 | }, |
michael@0 | 1496 | {0, 1, 2, 0, /* 0xc8 */ |
michael@0 | 1497 | {{3, 3}, |
michael@0 | 1498 | {6, 7}, |
michael@0 | 1499 | {0, 0}, |
michael@0 | 1500 | {0, 0} |
michael@0 | 1501 | } |
michael@0 | 1502 | }, |
michael@0 | 1503 | {1, 1, 3, 0, /* 0xc9 */ |
michael@0 | 1504 | {{0, 0}, |
michael@0 | 1505 | {3, 3}, |
michael@0 | 1506 | {6, 7}, |
michael@0 | 1507 | {0, 0} |
michael@0 | 1508 | } |
michael@0 | 1509 | }, |
michael@0 | 1510 | {0, 1, 3, 0, /* 0xca */ |
michael@0 | 1511 | {{1, 1}, |
michael@0 | 1512 | {3, 3}, |
michael@0 | 1513 | {6, 7}, |
michael@0 | 1514 | {0, 0} |
michael@0 | 1515 | } |
michael@0 | 1516 | }, |
michael@0 | 1517 | {1, 1, 3, 0, /* 0xcb */ |
michael@0 | 1518 | {{0, 1}, |
michael@0 | 1519 | {3, 3}, |
michael@0 | 1520 | {6, 7}, |
michael@0 | 1521 | {0, 0} |
michael@0 | 1522 | } |
michael@0 | 1523 | }, |
michael@0 | 1524 | {0, 1, 2, 0, /* 0xcc */ |
michael@0 | 1525 | {{2, 3}, |
michael@0 | 1526 | {6, 7}, |
michael@0 | 1527 | {0, 0}, |
michael@0 | 1528 | {0, 0} |
michael@0 | 1529 | } |
michael@0 | 1530 | }, |
michael@0 | 1531 | {1, 1, 3, 0, /* 0xcd */ |
michael@0 | 1532 | {{0, 0}, |
michael@0 | 1533 | {2, 3}, |
michael@0 | 1534 | {6, 7}, |
michael@0 | 1535 | {0, 0} |
michael@0 | 1536 | } |
michael@0 | 1537 | }, |
michael@0 | 1538 | {0, 1, 2, 0, /* 0xce */ |
michael@0 | 1539 | {{1, 3}, |
michael@0 | 1540 | {6, 7}, |
michael@0 | 1541 | {0, 0}, |
michael@0 | 1542 | {0, 0} |
michael@0 | 1543 | } |
michael@0 | 1544 | }, |
michael@0 | 1545 | {1, 1, 2, 0, /* 0xcf */ |
michael@0 | 1546 | {{0, 3}, |
michael@0 | 1547 | {6, 7}, |
michael@0 | 1548 | {0, 0}, |
michael@0 | 1549 | {0, 0} |
michael@0 | 1550 | } |
michael@0 | 1551 | }, |
michael@0 | 1552 | {0, 1, 2, 0, /* 0xd0 */ |
michael@0 | 1553 | {{4, 4}, |
michael@0 | 1554 | {6, 7}, |
michael@0 | 1555 | {0, 0}, |
michael@0 | 1556 | {0, 0} |
michael@0 | 1557 | } |
michael@0 | 1558 | }, |
michael@0 | 1559 | {1, 1, 3, 0, /* 0xd1 */ |
michael@0 | 1560 | {{0, 0}, |
michael@0 | 1561 | {4, 4}, |
michael@0 | 1562 | {6, 7}, |
michael@0 | 1563 | {0, 0} |
michael@0 | 1564 | } |
michael@0 | 1565 | }, |
michael@0 | 1566 | {0, 1, 3, 0, /* 0xd2 */ |
michael@0 | 1567 | {{1, 1}, |
michael@0 | 1568 | {4, 4}, |
michael@0 | 1569 | {6, 7}, |
michael@0 | 1570 | {0, 0} |
michael@0 | 1571 | } |
michael@0 | 1572 | }, |
michael@0 | 1573 | {1, 1, 3, 0, /* 0xd3 */ |
michael@0 | 1574 | {{0, 1}, |
michael@0 | 1575 | {4, 4}, |
michael@0 | 1576 | {6, 7}, |
michael@0 | 1577 | {0, 0} |
michael@0 | 1578 | } |
michael@0 | 1579 | }, |
michael@0 | 1580 | {0, 1, 3, 0, /* 0xd4 */ |
michael@0 | 1581 | {{2, 2}, |
michael@0 | 1582 | {4, 4}, |
michael@0 | 1583 | {6, 7}, |
michael@0 | 1584 | {0, 0} |
michael@0 | 1585 | } |
michael@0 | 1586 | }, |
michael@0 | 1587 | {1, 1, 4, 0, /* 0xd5 */ |
michael@0 | 1588 | {{0, 0}, |
michael@0 | 1589 | {2, 2}, |
michael@0 | 1590 | {4, 4}, |
michael@0 | 1591 | {6, 7} |
michael@0 | 1592 | } |
michael@0 | 1593 | }, |
michael@0 | 1594 | {0, 1, 3, 0, /* 0xd6 */ |
michael@0 | 1595 | {{1, 2}, |
michael@0 | 1596 | {4, 4}, |
michael@0 | 1597 | {6, 7}, |
michael@0 | 1598 | {0, 0} |
michael@0 | 1599 | } |
michael@0 | 1600 | }, |
michael@0 | 1601 | {1, 1, 3, 0, /* 0xd7 */ |
michael@0 | 1602 | {{0, 2}, |
michael@0 | 1603 | {4, 4}, |
michael@0 | 1604 | {6, 7}, |
michael@0 | 1605 | {0, 0} |
michael@0 | 1606 | } |
michael@0 | 1607 | }, |
michael@0 | 1608 | {0, 1, 2, 0, /* 0xd8 */ |
michael@0 | 1609 | {{3, 4}, |
michael@0 | 1610 | {6, 7}, |
michael@0 | 1611 | {0, 0}, |
michael@0 | 1612 | {0, 0} |
michael@0 | 1613 | } |
michael@0 | 1614 | }, |
michael@0 | 1615 | {1, 1, 3, 0, /* 0xd9 */ |
michael@0 | 1616 | {{0, 0}, |
michael@0 | 1617 | {3, 4}, |
michael@0 | 1618 | {6, 7}, |
michael@0 | 1619 | {0, 0} |
michael@0 | 1620 | } |
michael@0 | 1621 | }, |
michael@0 | 1622 | {0, 1, 3, 0, /* 0xda */ |
michael@0 | 1623 | {{1, 1}, |
michael@0 | 1624 | {3, 4}, |
michael@0 | 1625 | {6, 7}, |
michael@0 | 1626 | {0, 0} |
michael@0 | 1627 | } |
michael@0 | 1628 | }, |
michael@0 | 1629 | {1, 1, 3, 0, /* 0xdb */ |
michael@0 | 1630 | {{0, 1}, |
michael@0 | 1631 | {3, 4}, |
michael@0 | 1632 | {6, 7}, |
michael@0 | 1633 | {0, 0} |
michael@0 | 1634 | } |
michael@0 | 1635 | }, |
michael@0 | 1636 | {0, 1, 2, 0, /* 0xdc */ |
michael@0 | 1637 | {{2, 4}, |
michael@0 | 1638 | {6, 7}, |
michael@0 | 1639 | {0, 0}, |
michael@0 | 1640 | {0, 0} |
michael@0 | 1641 | } |
michael@0 | 1642 | }, |
michael@0 | 1643 | {1, 1, 3, 0, /* 0xdd */ |
michael@0 | 1644 | {{0, 0}, |
michael@0 | 1645 | {2, 4}, |
michael@0 | 1646 | {6, 7}, |
michael@0 | 1647 | {0, 0} |
michael@0 | 1648 | } |
michael@0 | 1649 | }, |
michael@0 | 1650 | {0, 1, 2, 0, /* 0xde */ |
michael@0 | 1651 | {{1, 4}, |
michael@0 | 1652 | {6, 7}, |
michael@0 | 1653 | {0, 0}, |
michael@0 | 1654 | {0, 0} |
michael@0 | 1655 | } |
michael@0 | 1656 | }, |
michael@0 | 1657 | {1, 1, 2, 0, /* 0xdf */ |
michael@0 | 1658 | {{0, 4}, |
michael@0 | 1659 | {6, 7}, |
michael@0 | 1660 | {0, 0}, |
michael@0 | 1661 | {0, 0} |
michael@0 | 1662 | } |
michael@0 | 1663 | }, |
michael@0 | 1664 | {0, 1, 1, 0, /* 0xe0 */ |
michael@0 | 1665 | {{5, 7}, |
michael@0 | 1666 | {0, 0}, |
michael@0 | 1667 | {0, 0}, |
michael@0 | 1668 | {0, 0} |
michael@0 | 1669 | } |
michael@0 | 1670 | }, |
michael@0 | 1671 | {1, 1, 2, 0, /* 0xe1 */ |
michael@0 | 1672 | {{0, 0}, |
michael@0 | 1673 | {5, 7}, |
michael@0 | 1674 | {0, 0}, |
michael@0 | 1675 | {0, 0} |
michael@0 | 1676 | } |
michael@0 | 1677 | }, |
michael@0 | 1678 | {0, 1, 2, 0, /* 0xe2 */ |
michael@0 | 1679 | {{1, 1}, |
michael@0 | 1680 | {5, 7}, |
michael@0 | 1681 | {0, 0}, |
michael@0 | 1682 | {0, 0} |
michael@0 | 1683 | } |
michael@0 | 1684 | }, |
michael@0 | 1685 | {1, 1, 2, 0, /* 0xe3 */ |
michael@0 | 1686 | {{0, 1}, |
michael@0 | 1687 | {5, 7}, |
michael@0 | 1688 | {0, 0}, |
michael@0 | 1689 | {0, 0} |
michael@0 | 1690 | } |
michael@0 | 1691 | }, |
michael@0 | 1692 | {0, 1, 2, 0, /* 0xe4 */ |
michael@0 | 1693 | {{2, 2}, |
michael@0 | 1694 | {5, 7}, |
michael@0 | 1695 | {0, 0}, |
michael@0 | 1696 | {0, 0} |
michael@0 | 1697 | } |
michael@0 | 1698 | }, |
michael@0 | 1699 | {1, 1, 3, 0, /* 0xe5 */ |
michael@0 | 1700 | {{0, 0}, |
michael@0 | 1701 | {2, 2}, |
michael@0 | 1702 | {5, 7}, |
michael@0 | 1703 | {0, 0} |
michael@0 | 1704 | } |
michael@0 | 1705 | }, |
michael@0 | 1706 | {0, 1, 2, 0, /* 0xe6 */ |
michael@0 | 1707 | {{1, 2}, |
michael@0 | 1708 | {5, 7}, |
michael@0 | 1709 | {0, 0}, |
michael@0 | 1710 | {0, 0} |
michael@0 | 1711 | } |
michael@0 | 1712 | }, |
michael@0 | 1713 | {1, 1, 2, 0, /* 0xe7 */ |
michael@0 | 1714 | {{0, 2}, |
michael@0 | 1715 | {5, 7}, |
michael@0 | 1716 | {0, 0}, |
michael@0 | 1717 | {0, 0} |
michael@0 | 1718 | } |
michael@0 | 1719 | }, |
michael@0 | 1720 | {0, 1, 2, 0, /* 0xe8 */ |
michael@0 | 1721 | {{3, 3}, |
michael@0 | 1722 | {5, 7}, |
michael@0 | 1723 | {0, 0}, |
michael@0 | 1724 | {0, 0} |
michael@0 | 1725 | } |
michael@0 | 1726 | }, |
michael@0 | 1727 | {1, 1, 3, 0, /* 0xe9 */ |
michael@0 | 1728 | {{0, 0}, |
michael@0 | 1729 | {3, 3}, |
michael@0 | 1730 | {5, 7}, |
michael@0 | 1731 | {0, 0} |
michael@0 | 1732 | } |
michael@0 | 1733 | }, |
michael@0 | 1734 | {0, 1, 3, 0, /* 0xea */ |
michael@0 | 1735 | {{1, 1}, |
michael@0 | 1736 | {3, 3}, |
michael@0 | 1737 | {5, 7}, |
michael@0 | 1738 | {0, 0} |
michael@0 | 1739 | } |
michael@0 | 1740 | }, |
michael@0 | 1741 | {1, 1, 3, 0, /* 0xeb */ |
michael@0 | 1742 | {{0, 1}, |
michael@0 | 1743 | {3, 3}, |
michael@0 | 1744 | {5, 7}, |
michael@0 | 1745 | {0, 0} |
michael@0 | 1746 | } |
michael@0 | 1747 | }, |
michael@0 | 1748 | {0, 1, 2, 0, /* 0xec */ |
michael@0 | 1749 | {{2, 3}, |
michael@0 | 1750 | {5, 7}, |
michael@0 | 1751 | {0, 0}, |
michael@0 | 1752 | {0, 0} |
michael@0 | 1753 | } |
michael@0 | 1754 | }, |
michael@0 | 1755 | {1, 1, 3, 0, /* 0xed */ |
michael@0 | 1756 | {{0, 0}, |
michael@0 | 1757 | {2, 3}, |
michael@0 | 1758 | {5, 7}, |
michael@0 | 1759 | {0, 0} |
michael@0 | 1760 | } |
michael@0 | 1761 | }, |
michael@0 | 1762 | {0, 1, 2, 0, /* 0xee */ |
michael@0 | 1763 | {{1, 3}, |
michael@0 | 1764 | {5, 7}, |
michael@0 | 1765 | {0, 0}, |
michael@0 | 1766 | {0, 0} |
michael@0 | 1767 | } |
michael@0 | 1768 | }, |
michael@0 | 1769 | {1, 1, 2, 0, /* 0xef */ |
michael@0 | 1770 | {{0, 3}, |
michael@0 | 1771 | {5, 7}, |
michael@0 | 1772 | {0, 0}, |
michael@0 | 1773 | {0, 0} |
michael@0 | 1774 | } |
michael@0 | 1775 | }, |
michael@0 | 1776 | {0, 1, 1, 0, /* 0xf0 */ |
michael@0 | 1777 | {{4, 7}, |
michael@0 | 1778 | {0, 0}, |
michael@0 | 1779 | {0, 0}, |
michael@0 | 1780 | {0, 0} |
michael@0 | 1781 | } |
michael@0 | 1782 | }, |
michael@0 | 1783 | {1, 1, 2, 0, /* 0xf1 */ |
michael@0 | 1784 | {{0, 0}, |
michael@0 | 1785 | {4, 7}, |
michael@0 | 1786 | {0, 0}, |
michael@0 | 1787 | {0, 0} |
michael@0 | 1788 | } |
michael@0 | 1789 | }, |
michael@0 | 1790 | {0, 1, 2, 0, /* 0xf2 */ |
michael@0 | 1791 | {{1, 1}, |
michael@0 | 1792 | {4, 7}, |
michael@0 | 1793 | {0, 0}, |
michael@0 | 1794 | {0, 0} |
michael@0 | 1795 | } |
michael@0 | 1796 | }, |
michael@0 | 1797 | {1, 1, 2, 0, /* 0xf3 */ |
michael@0 | 1798 | {{0, 1}, |
michael@0 | 1799 | {4, 7}, |
michael@0 | 1800 | {0, 0}, |
michael@0 | 1801 | {0, 0} |
michael@0 | 1802 | } |
michael@0 | 1803 | }, |
michael@0 | 1804 | {0, 1, 2, 0, /* 0xf4 */ |
michael@0 | 1805 | {{2, 2}, |
michael@0 | 1806 | {4, 7}, |
michael@0 | 1807 | {0, 0}, |
michael@0 | 1808 | {0, 0} |
michael@0 | 1809 | } |
michael@0 | 1810 | }, |
michael@0 | 1811 | {1, 1, 3, 0, /* 0xf5 */ |
michael@0 | 1812 | {{0, 0}, |
michael@0 | 1813 | {2, 2}, |
michael@0 | 1814 | {4, 7}, |
michael@0 | 1815 | {0, 0} |
michael@0 | 1816 | } |
michael@0 | 1817 | }, |
michael@0 | 1818 | {0, 1, 2, 0, /* 0xf6 */ |
michael@0 | 1819 | {{1, 2}, |
michael@0 | 1820 | {4, 7}, |
michael@0 | 1821 | {0, 0}, |
michael@0 | 1822 | {0, 0} |
michael@0 | 1823 | } |
michael@0 | 1824 | }, |
michael@0 | 1825 | {1, 1, 2, 0, /* 0xf7 */ |
michael@0 | 1826 | {{0, 2}, |
michael@0 | 1827 | {4, 7}, |
michael@0 | 1828 | {0, 0}, |
michael@0 | 1829 | {0, 0} |
michael@0 | 1830 | } |
michael@0 | 1831 | }, |
michael@0 | 1832 | {0, 1, 1, 0, /* 0xf8 */ |
michael@0 | 1833 | {{3, 7}, |
michael@0 | 1834 | {0, 0}, |
michael@0 | 1835 | {0, 0}, |
michael@0 | 1836 | {0, 0} |
michael@0 | 1837 | } |
michael@0 | 1838 | }, |
michael@0 | 1839 | {1, 1, 2, 0, /* 0xf9 */ |
michael@0 | 1840 | {{0, 0}, |
michael@0 | 1841 | {3, 7}, |
michael@0 | 1842 | {0, 0}, |
michael@0 | 1843 | {0, 0} |
michael@0 | 1844 | } |
michael@0 | 1845 | }, |
michael@0 | 1846 | {0, 1, 2, 0, /* 0xfa */ |
michael@0 | 1847 | {{1, 1}, |
michael@0 | 1848 | {3, 7}, |
michael@0 | 1849 | {0, 0}, |
michael@0 | 1850 | {0, 0} |
michael@0 | 1851 | } |
michael@0 | 1852 | }, |
michael@0 | 1853 | {1, 1, 2, 0, /* 0xfb */ |
michael@0 | 1854 | {{0, 1}, |
michael@0 | 1855 | {3, 7}, |
michael@0 | 1856 | {0, 0}, |
michael@0 | 1857 | {0, 0} |
michael@0 | 1858 | } |
michael@0 | 1859 | }, |
michael@0 | 1860 | {0, 1, 1, 0, /* 0xfc */ |
michael@0 | 1861 | {{2, 7}, |
michael@0 | 1862 | {0, 0}, |
michael@0 | 1863 | {0, 0}, |
michael@0 | 1864 | {0, 0} |
michael@0 | 1865 | } |
michael@0 | 1866 | }, |
michael@0 | 1867 | {1, 1, 2, 0, /* 0xfd */ |
michael@0 | 1868 | {{0, 0}, |
michael@0 | 1869 | {2, 7}, |
michael@0 | 1870 | {0, 0}, |
michael@0 | 1871 | {0, 0} |
michael@0 | 1872 | } |
michael@0 | 1873 | }, |
michael@0 | 1874 | {0, 1, 1, 0, /* 0xfe */ |
michael@0 | 1875 | {{1, 7}, |
michael@0 | 1876 | {0, 0}, |
michael@0 | 1877 | {0, 0}, |
michael@0 | 1878 | {0, 0} |
michael@0 | 1879 | } |
michael@0 | 1880 | }, |
michael@0 | 1881 | {1, 1, 1, 0, /* 0xff */ |
michael@0 | 1882 | {{0, 7}, |
michael@0 | 1883 | {0, 0}, |
michael@0 | 1884 | {0, 0}, |
michael@0 | 1885 | {0, 0} |
michael@0 | 1886 | } |
michael@0 | 1887 | } |
michael@0 | 1888 | }; |
michael@0 | 1889 | |
michael@0 | 1890 | |
michael@0 | 1891 | int |
michael@0 | 1892 | sctp_is_address_in_scope(struct sctp_ifa *ifa, |
michael@0 | 1893 | struct sctp_scoping *scope, |
michael@0 | 1894 | int do_update) |
michael@0 | 1895 | { |
michael@0 | 1896 | if ((scope->loopback_scope == 0) && |
michael@0 | 1897 | (ifa->ifn_p) && SCTP_IFN_IS_IFT_LOOP(ifa->ifn_p)) { |
michael@0 | 1898 | /* |
michael@0 | 1899 | * skip loopback if not in scope * |
michael@0 | 1900 | */ |
michael@0 | 1901 | return (0); |
michael@0 | 1902 | } |
michael@0 | 1903 | switch (ifa->address.sa.sa_family) { |
michael@0 | 1904 | #ifdef INET |
michael@0 | 1905 | case AF_INET: |
michael@0 | 1906 | if (scope->ipv4_addr_legal) { |
michael@0 | 1907 | struct sockaddr_in *sin; |
michael@0 | 1908 | |
michael@0 | 1909 | sin = (struct sockaddr_in *)&ifa->address.sin; |
michael@0 | 1910 | if (sin->sin_addr.s_addr == 0) { |
michael@0 | 1911 | /* not in scope , unspecified */ |
michael@0 | 1912 | return (0); |
michael@0 | 1913 | } |
michael@0 | 1914 | if ((scope->ipv4_local_scope == 0) && |
michael@0 | 1915 | (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) { |
michael@0 | 1916 | /* private address not in scope */ |
michael@0 | 1917 | return (0); |
michael@0 | 1918 | } |
michael@0 | 1919 | } else { |
michael@0 | 1920 | return (0); |
michael@0 | 1921 | } |
michael@0 | 1922 | break; |
michael@0 | 1923 | #endif |
michael@0 | 1924 | #ifdef INET6 |
michael@0 | 1925 | case AF_INET6: |
michael@0 | 1926 | if (scope->ipv6_addr_legal) { |
michael@0 | 1927 | struct sockaddr_in6 *sin6; |
michael@0 | 1928 | |
michael@0 | 1929 | #if !defined(__Panda__) |
michael@0 | 1930 | /* Must update the flags, bummer, which |
michael@0 | 1931 | * means any IFA locks must now be applied HERE <-> |
michael@0 | 1932 | */ |
michael@0 | 1933 | if (do_update) { |
michael@0 | 1934 | sctp_gather_internal_ifa_flags(ifa); |
michael@0 | 1935 | } |
michael@0 | 1936 | #endif |
michael@0 | 1937 | if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { |
michael@0 | 1938 | return (0); |
michael@0 | 1939 | } |
michael@0 | 1940 | /* ok to use deprecated addresses? */ |
michael@0 | 1941 | sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; |
michael@0 | 1942 | if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
michael@0 | 1943 | /* skip unspecifed addresses */ |
michael@0 | 1944 | return (0); |
michael@0 | 1945 | } |
michael@0 | 1946 | if ( /* (local_scope == 0) && */ |
michael@0 | 1947 | (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) { |
michael@0 | 1948 | return (0); |
michael@0 | 1949 | } |
michael@0 | 1950 | if ((scope->site_scope == 0) && |
michael@0 | 1951 | (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) { |
michael@0 | 1952 | return (0); |
michael@0 | 1953 | } |
michael@0 | 1954 | } else { |
michael@0 | 1955 | return (0); |
michael@0 | 1956 | } |
michael@0 | 1957 | break; |
michael@0 | 1958 | #endif |
michael@0 | 1959 | #if defined(__Userspace__) |
michael@0 | 1960 | case AF_CONN: |
michael@0 | 1961 | if (!scope->conn_addr_legal) { |
michael@0 | 1962 | return (0); |
michael@0 | 1963 | } |
michael@0 | 1964 | break; |
michael@0 | 1965 | #endif |
michael@0 | 1966 | default: |
michael@0 | 1967 | return (0); |
michael@0 | 1968 | } |
michael@0 | 1969 | return (1); |
michael@0 | 1970 | } |
michael@0 | 1971 | |
michael@0 | 1972 | static struct mbuf * |
michael@0 | 1973 | sctp_add_addr_to_mbuf(struct mbuf *m, struct sctp_ifa *ifa, uint16_t *len) |
michael@0 | 1974 | { |
michael@0 | 1975 | #if defined(INET) || defined(INET6) |
michael@0 | 1976 | struct sctp_paramhdr *parmh; |
michael@0 | 1977 | struct mbuf *mret; |
michael@0 | 1978 | uint16_t plen; |
michael@0 | 1979 | #endif |
michael@0 | 1980 | |
michael@0 | 1981 | switch (ifa->address.sa.sa_family) { |
michael@0 | 1982 | #ifdef INET |
michael@0 | 1983 | case AF_INET: |
michael@0 | 1984 | plen = (uint16_t)sizeof(struct sctp_ipv4addr_param); |
michael@0 | 1985 | break; |
michael@0 | 1986 | #endif |
michael@0 | 1987 | #ifdef INET6 |
michael@0 | 1988 | case AF_INET6: |
michael@0 | 1989 | plen = (uint16_t)sizeof(struct sctp_ipv6addr_param); |
michael@0 | 1990 | break; |
michael@0 | 1991 | #endif |
michael@0 | 1992 | default: |
michael@0 | 1993 | return (m); |
michael@0 | 1994 | } |
michael@0 | 1995 | #if defined(INET) || defined(INET6) |
michael@0 | 1996 | if (M_TRAILINGSPACE(m) >= plen) { |
michael@0 | 1997 | /* easy side we just drop it on the end */ |
michael@0 | 1998 | parmh = (struct sctp_paramhdr *)(SCTP_BUF_AT(m, SCTP_BUF_LEN(m))); |
michael@0 | 1999 | mret = m; |
michael@0 | 2000 | } else { |
michael@0 | 2001 | /* Need more space */ |
michael@0 | 2002 | mret = m; |
michael@0 | 2003 | while (SCTP_BUF_NEXT(mret) != NULL) { |
michael@0 | 2004 | mret = SCTP_BUF_NEXT(mret); |
michael@0 | 2005 | } |
michael@0 | 2006 | SCTP_BUF_NEXT(mret) = sctp_get_mbuf_for_msg(plen, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 2007 | if (SCTP_BUF_NEXT(mret) == NULL) { |
michael@0 | 2008 | /* We are hosed, can't add more addresses */ |
michael@0 | 2009 | return (m); |
michael@0 | 2010 | } |
michael@0 | 2011 | mret = SCTP_BUF_NEXT(mret); |
michael@0 | 2012 | parmh = mtod(mret, struct sctp_paramhdr *); |
michael@0 | 2013 | } |
michael@0 | 2014 | /* now add the parameter */ |
michael@0 | 2015 | switch (ifa->address.sa.sa_family) { |
michael@0 | 2016 | #ifdef INET |
michael@0 | 2017 | case AF_INET: |
michael@0 | 2018 | { |
michael@0 | 2019 | struct sctp_ipv4addr_param *ipv4p; |
michael@0 | 2020 | struct sockaddr_in *sin; |
michael@0 | 2021 | |
michael@0 | 2022 | sin = (struct sockaddr_in *)&ifa->address.sin; |
michael@0 | 2023 | ipv4p = (struct sctp_ipv4addr_param *)parmh; |
michael@0 | 2024 | parmh->param_type = htons(SCTP_IPV4_ADDRESS); |
michael@0 | 2025 | parmh->param_length = htons(plen); |
michael@0 | 2026 | ipv4p->addr = sin->sin_addr.s_addr; |
michael@0 | 2027 | SCTP_BUF_LEN(mret) += plen; |
michael@0 | 2028 | break; |
michael@0 | 2029 | } |
michael@0 | 2030 | #endif |
michael@0 | 2031 | #ifdef INET6 |
michael@0 | 2032 | case AF_INET6: |
michael@0 | 2033 | { |
michael@0 | 2034 | struct sctp_ipv6addr_param *ipv6p; |
michael@0 | 2035 | struct sockaddr_in6 *sin6; |
michael@0 | 2036 | |
michael@0 | 2037 | sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; |
michael@0 | 2038 | ipv6p = (struct sctp_ipv6addr_param *)parmh; |
michael@0 | 2039 | parmh->param_type = htons(SCTP_IPV6_ADDRESS); |
michael@0 | 2040 | parmh->param_length = htons(plen); |
michael@0 | 2041 | memcpy(ipv6p->addr, &sin6->sin6_addr, |
michael@0 | 2042 | sizeof(ipv6p->addr)); |
michael@0 | 2043 | #if defined(SCTP_EMBEDDED_V6_SCOPE) |
michael@0 | 2044 | /* clear embedded scope in the address */ |
michael@0 | 2045 | in6_clearscope((struct in6_addr *)ipv6p->addr); |
michael@0 | 2046 | #endif |
michael@0 | 2047 | SCTP_BUF_LEN(mret) += plen; |
michael@0 | 2048 | break; |
michael@0 | 2049 | } |
michael@0 | 2050 | #endif |
michael@0 | 2051 | default: |
michael@0 | 2052 | return (m); |
michael@0 | 2053 | } |
michael@0 | 2054 | if (len != NULL) { |
michael@0 | 2055 | *len += plen; |
michael@0 | 2056 | } |
michael@0 | 2057 | return (mret); |
michael@0 | 2058 | #endif |
michael@0 | 2059 | } |
michael@0 | 2060 | |
michael@0 | 2061 | |
michael@0 | 2062 | struct mbuf * |
michael@0 | 2063 | sctp_add_addresses_to_i_ia(struct sctp_inpcb *inp, struct sctp_tcb *stcb, |
michael@0 | 2064 | struct sctp_scoping *scope, |
michael@0 | 2065 | struct mbuf *m_at, int cnt_inits_to, |
michael@0 | 2066 | uint16_t *padding_len, uint16_t *chunk_len) |
michael@0 | 2067 | { |
michael@0 | 2068 | struct sctp_vrf *vrf = NULL; |
michael@0 | 2069 | int cnt, limit_out = 0, total_count; |
michael@0 | 2070 | uint32_t vrf_id; |
michael@0 | 2071 | |
michael@0 | 2072 | vrf_id = inp->def_vrf_id; |
michael@0 | 2073 | SCTP_IPI_ADDR_RLOCK(); |
michael@0 | 2074 | vrf = sctp_find_vrf(vrf_id); |
michael@0 | 2075 | if (vrf == NULL) { |
michael@0 | 2076 | SCTP_IPI_ADDR_RUNLOCK(); |
michael@0 | 2077 | return (m_at); |
michael@0 | 2078 | } |
michael@0 | 2079 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { |
michael@0 | 2080 | struct sctp_ifa *sctp_ifap; |
michael@0 | 2081 | struct sctp_ifn *sctp_ifnp; |
michael@0 | 2082 | |
michael@0 | 2083 | cnt = cnt_inits_to; |
michael@0 | 2084 | if (vrf->total_ifa_count > SCTP_COUNT_LIMIT) { |
michael@0 | 2085 | limit_out = 1; |
michael@0 | 2086 | cnt = SCTP_ADDRESS_LIMIT; |
michael@0 | 2087 | goto skip_count; |
michael@0 | 2088 | } |
michael@0 | 2089 | LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { |
michael@0 | 2090 | if ((scope->loopback_scope == 0) && |
michael@0 | 2091 | SCTP_IFN_IS_IFT_LOOP(sctp_ifnp)) { |
michael@0 | 2092 | /* |
michael@0 | 2093 | * Skip loopback devices if loopback_scope |
michael@0 | 2094 | * not set |
michael@0 | 2095 | */ |
michael@0 | 2096 | continue; |
michael@0 | 2097 | } |
michael@0 | 2098 | LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { |
michael@0 | 2099 | if (sctp_is_addr_restricted(stcb, sctp_ifap)) { |
michael@0 | 2100 | continue; |
michael@0 | 2101 | } |
michael@0 | 2102 | #if defined(__Userspace__) |
michael@0 | 2103 | if (sctp_ifap->address.sa.sa_family == AF_CONN) { |
michael@0 | 2104 | continue; |
michael@0 | 2105 | } |
michael@0 | 2106 | #endif |
michael@0 | 2107 | if (sctp_is_address_in_scope(sctp_ifap, scope, 1) == 0) { |
michael@0 | 2108 | continue; |
michael@0 | 2109 | } |
michael@0 | 2110 | cnt++; |
michael@0 | 2111 | if (cnt > SCTP_ADDRESS_LIMIT) { |
michael@0 | 2112 | break; |
michael@0 | 2113 | } |
michael@0 | 2114 | } |
michael@0 | 2115 | if (cnt > SCTP_ADDRESS_LIMIT) { |
michael@0 | 2116 | break; |
michael@0 | 2117 | } |
michael@0 | 2118 | } |
michael@0 | 2119 | skip_count: |
michael@0 | 2120 | if (cnt > 1) { |
michael@0 | 2121 | total_count = 0; |
michael@0 | 2122 | LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { |
michael@0 | 2123 | cnt = 0; |
michael@0 | 2124 | if ((scope->loopback_scope == 0) && |
michael@0 | 2125 | SCTP_IFN_IS_IFT_LOOP(sctp_ifnp)) { |
michael@0 | 2126 | /* |
michael@0 | 2127 | * Skip loopback devices if |
michael@0 | 2128 | * loopback_scope not set |
michael@0 | 2129 | */ |
michael@0 | 2130 | continue; |
michael@0 | 2131 | } |
michael@0 | 2132 | LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { |
michael@0 | 2133 | if (sctp_is_addr_restricted(stcb, sctp_ifap)) { |
michael@0 | 2134 | continue; |
michael@0 | 2135 | } |
michael@0 | 2136 | #if defined(__Userspace__) |
michael@0 | 2137 | if (sctp_ifap->address.sa.sa_family == AF_CONN) { |
michael@0 | 2138 | continue; |
michael@0 | 2139 | } |
michael@0 | 2140 | #endif |
michael@0 | 2141 | if (sctp_is_address_in_scope(sctp_ifap, |
michael@0 | 2142 | scope, 0) == 0) { |
michael@0 | 2143 | continue; |
michael@0 | 2144 | } |
michael@0 | 2145 | if ((chunk_len != NULL) && |
michael@0 | 2146 | (padding_len != NULL) && |
michael@0 | 2147 | (*padding_len > 0)) { |
michael@0 | 2148 | memset(mtod(m_at, caddr_t) + *chunk_len, 0, *padding_len); |
michael@0 | 2149 | SCTP_BUF_LEN(m_at) += *padding_len; |
michael@0 | 2150 | *chunk_len += *padding_len; |
michael@0 | 2151 | *padding_len = 0; |
michael@0 | 2152 | } |
michael@0 | 2153 | m_at = sctp_add_addr_to_mbuf(m_at, sctp_ifap, chunk_len); |
michael@0 | 2154 | if (limit_out) { |
michael@0 | 2155 | cnt++; |
michael@0 | 2156 | total_count++; |
michael@0 | 2157 | if (cnt >= 2) { |
michael@0 | 2158 | /* two from each address */ |
michael@0 | 2159 | break; |
michael@0 | 2160 | } |
michael@0 | 2161 | if (total_count > SCTP_ADDRESS_LIMIT) { |
michael@0 | 2162 | /* No more addresses */ |
michael@0 | 2163 | break; |
michael@0 | 2164 | } |
michael@0 | 2165 | } |
michael@0 | 2166 | } |
michael@0 | 2167 | } |
michael@0 | 2168 | } |
michael@0 | 2169 | } else { |
michael@0 | 2170 | struct sctp_laddr *laddr; |
michael@0 | 2171 | |
michael@0 | 2172 | cnt = cnt_inits_to; |
michael@0 | 2173 | /* First, how many ? */ |
michael@0 | 2174 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
michael@0 | 2175 | if (laddr->ifa == NULL) { |
michael@0 | 2176 | continue; |
michael@0 | 2177 | } |
michael@0 | 2178 | if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) |
michael@0 | 2179 | /* Address being deleted by the system, dont |
michael@0 | 2180 | * list. |
michael@0 | 2181 | */ |
michael@0 | 2182 | continue; |
michael@0 | 2183 | if (laddr->action == SCTP_DEL_IP_ADDRESS) { |
michael@0 | 2184 | /* Address being deleted on this ep |
michael@0 | 2185 | * don't list. |
michael@0 | 2186 | */ |
michael@0 | 2187 | continue; |
michael@0 | 2188 | } |
michael@0 | 2189 | #if defined(__Userspace__) |
michael@0 | 2190 | if (laddr->ifa->address.sa.sa_family == AF_CONN) { |
michael@0 | 2191 | continue; |
michael@0 | 2192 | } |
michael@0 | 2193 | #endif |
michael@0 | 2194 | if (sctp_is_address_in_scope(laddr->ifa, |
michael@0 | 2195 | scope, 1) == 0) { |
michael@0 | 2196 | continue; |
michael@0 | 2197 | } |
michael@0 | 2198 | cnt++; |
michael@0 | 2199 | } |
michael@0 | 2200 | /* |
michael@0 | 2201 | * To get through a NAT we only list addresses if we have |
michael@0 | 2202 | * more than one. That way if you just bind a single address |
michael@0 | 2203 | * we let the source of the init dictate our address. |
michael@0 | 2204 | */ |
michael@0 | 2205 | if (cnt > 1) { |
michael@0 | 2206 | cnt = cnt_inits_to; |
michael@0 | 2207 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
michael@0 | 2208 | if (laddr->ifa == NULL) { |
michael@0 | 2209 | continue; |
michael@0 | 2210 | } |
michael@0 | 2211 | if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) { |
michael@0 | 2212 | continue; |
michael@0 | 2213 | } |
michael@0 | 2214 | #if defined(__Userspace__) |
michael@0 | 2215 | if (laddr->ifa->address.sa.sa_family == AF_CONN) { |
michael@0 | 2216 | continue; |
michael@0 | 2217 | } |
michael@0 | 2218 | #endif |
michael@0 | 2219 | if (sctp_is_address_in_scope(laddr->ifa, |
michael@0 | 2220 | scope, 0) == 0) { |
michael@0 | 2221 | continue; |
michael@0 | 2222 | } |
michael@0 | 2223 | if ((chunk_len != NULL) && |
michael@0 | 2224 | (padding_len != NULL) && |
michael@0 | 2225 | (*padding_len > 0)) { |
michael@0 | 2226 | memset(mtod(m_at, caddr_t) + *chunk_len, 0, *padding_len); |
michael@0 | 2227 | SCTP_BUF_LEN(m_at) += *padding_len; |
michael@0 | 2228 | *chunk_len += *padding_len; |
michael@0 | 2229 | *padding_len = 0; |
michael@0 | 2230 | } |
michael@0 | 2231 | m_at = sctp_add_addr_to_mbuf(m_at, laddr->ifa, chunk_len); |
michael@0 | 2232 | cnt++; |
michael@0 | 2233 | if (cnt >= SCTP_ADDRESS_LIMIT) { |
michael@0 | 2234 | break; |
michael@0 | 2235 | } |
michael@0 | 2236 | } |
michael@0 | 2237 | } |
michael@0 | 2238 | } |
michael@0 | 2239 | SCTP_IPI_ADDR_RUNLOCK(); |
michael@0 | 2240 | return (m_at); |
michael@0 | 2241 | } |
michael@0 | 2242 | |
michael@0 | 2243 | static struct sctp_ifa * |
michael@0 | 2244 | sctp_is_ifa_addr_preferred(struct sctp_ifa *ifa, |
michael@0 | 2245 | uint8_t dest_is_loop, |
michael@0 | 2246 | uint8_t dest_is_priv, |
michael@0 | 2247 | sa_family_t fam) |
michael@0 | 2248 | { |
michael@0 | 2249 | uint8_t dest_is_global = 0; |
michael@0 | 2250 | /* dest_is_priv is true if destination is a private address */ |
michael@0 | 2251 | /* dest_is_loop is true if destination is a loopback addresses */ |
michael@0 | 2252 | |
michael@0 | 2253 | /** |
michael@0 | 2254 | * Here we determine if its a preferred address. A preferred address |
michael@0 | 2255 | * means it is the same scope or higher scope then the destination. |
michael@0 | 2256 | * L = loopback, P = private, G = global |
michael@0 | 2257 | * ----------------------------------------- |
michael@0 | 2258 | * src | dest | result |
michael@0 | 2259 | * ---------------------------------------- |
michael@0 | 2260 | * L | L | yes |
michael@0 | 2261 | * ----------------------------------------- |
michael@0 | 2262 | * P | L | yes-v4 no-v6 |
michael@0 | 2263 | * ----------------------------------------- |
michael@0 | 2264 | * G | L | yes-v4 no-v6 |
michael@0 | 2265 | * ----------------------------------------- |
michael@0 | 2266 | * L | P | no |
michael@0 | 2267 | * ----------------------------------------- |
michael@0 | 2268 | * P | P | yes |
michael@0 | 2269 | * ----------------------------------------- |
michael@0 | 2270 | * G | P | no |
michael@0 | 2271 | * ----------------------------------------- |
michael@0 | 2272 | * L | G | no |
michael@0 | 2273 | * ----------------------------------------- |
michael@0 | 2274 | * P | G | no |
michael@0 | 2275 | * ----------------------------------------- |
michael@0 | 2276 | * G | G | yes |
michael@0 | 2277 | * ----------------------------------------- |
michael@0 | 2278 | */ |
michael@0 | 2279 | |
michael@0 | 2280 | if (ifa->address.sa.sa_family != fam) { |
michael@0 | 2281 | /* forget mis-matched family */ |
michael@0 | 2282 | return (NULL); |
michael@0 | 2283 | } |
michael@0 | 2284 | if ((dest_is_priv == 0) && (dest_is_loop == 0)) { |
michael@0 | 2285 | dest_is_global = 1; |
michael@0 | 2286 | } |
michael@0 | 2287 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Is destination preferred:"); |
michael@0 | 2288 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ifa->address.sa); |
michael@0 | 2289 | /* Ok the address may be ok */ |
michael@0 | 2290 | #ifdef INET6 |
michael@0 | 2291 | if (fam == AF_INET6) { |
michael@0 | 2292 | /* ok to use deprecated addresses? no lets not! */ |
michael@0 | 2293 | if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { |
michael@0 | 2294 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:1\n"); |
michael@0 | 2295 | return (NULL); |
michael@0 | 2296 | } |
michael@0 | 2297 | if (ifa->src_is_priv && !ifa->src_is_loop) { |
michael@0 | 2298 | if (dest_is_loop) { |
michael@0 | 2299 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:2\n"); |
michael@0 | 2300 | return (NULL); |
michael@0 | 2301 | } |
michael@0 | 2302 | } |
michael@0 | 2303 | if (ifa->src_is_glob) { |
michael@0 | 2304 | if (dest_is_loop) { |
michael@0 | 2305 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:3\n"); |
michael@0 | 2306 | return (NULL); |
michael@0 | 2307 | } |
michael@0 | 2308 | } |
michael@0 | 2309 | } |
michael@0 | 2310 | #endif |
michael@0 | 2311 | /* Now that we know what is what, implement or table |
michael@0 | 2312 | * this could in theory be done slicker (it used to be), but this |
michael@0 | 2313 | * is straightforward and easier to validate :-) |
michael@0 | 2314 | */ |
michael@0 | 2315 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "src_loop:%d src_priv:%d src_glob:%d\n", |
michael@0 | 2316 | ifa->src_is_loop, ifa->src_is_priv, ifa->src_is_glob); |
michael@0 | 2317 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "dest_loop:%d dest_priv:%d dest_glob:%d\n", |
michael@0 | 2318 | dest_is_loop, dest_is_priv, dest_is_global); |
michael@0 | 2319 | |
michael@0 | 2320 | if ((ifa->src_is_loop) && (dest_is_priv)) { |
michael@0 | 2321 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:4\n"); |
michael@0 | 2322 | return (NULL); |
michael@0 | 2323 | } |
michael@0 | 2324 | if ((ifa->src_is_glob) && (dest_is_priv)) { |
michael@0 | 2325 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:5\n"); |
michael@0 | 2326 | return (NULL); |
michael@0 | 2327 | } |
michael@0 | 2328 | if ((ifa->src_is_loop) && (dest_is_global)) { |
michael@0 | 2329 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:6\n"); |
michael@0 | 2330 | return (NULL); |
michael@0 | 2331 | } |
michael@0 | 2332 | if ((ifa->src_is_priv) && (dest_is_global)) { |
michael@0 | 2333 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "NO:7\n"); |
michael@0 | 2334 | return (NULL); |
michael@0 | 2335 | } |
michael@0 | 2336 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "YES\n"); |
michael@0 | 2337 | /* its a preferred address */ |
michael@0 | 2338 | return (ifa); |
michael@0 | 2339 | } |
michael@0 | 2340 | |
michael@0 | 2341 | static struct sctp_ifa * |
michael@0 | 2342 | sctp_is_ifa_addr_acceptable(struct sctp_ifa *ifa, |
michael@0 | 2343 | uint8_t dest_is_loop, |
michael@0 | 2344 | uint8_t dest_is_priv, |
michael@0 | 2345 | sa_family_t fam) |
michael@0 | 2346 | { |
michael@0 | 2347 | uint8_t dest_is_global = 0; |
michael@0 | 2348 | |
michael@0 | 2349 | /** |
michael@0 | 2350 | * Here we determine if its a acceptable address. A acceptable |
michael@0 | 2351 | * address means it is the same scope or higher scope but we can |
michael@0 | 2352 | * allow for NAT which means its ok to have a global dest and a |
michael@0 | 2353 | * private src. |
michael@0 | 2354 | * |
michael@0 | 2355 | * L = loopback, P = private, G = global |
michael@0 | 2356 | * ----------------------------------------- |
michael@0 | 2357 | * src | dest | result |
michael@0 | 2358 | * ----------------------------------------- |
michael@0 | 2359 | * L | L | yes |
michael@0 | 2360 | * ----------------------------------------- |
michael@0 | 2361 | * P | L | yes-v4 no-v6 |
michael@0 | 2362 | * ----------------------------------------- |
michael@0 | 2363 | * G | L | yes |
michael@0 | 2364 | * ----------------------------------------- |
michael@0 | 2365 | * L | P | no |
michael@0 | 2366 | * ----------------------------------------- |
michael@0 | 2367 | * P | P | yes |
michael@0 | 2368 | * ----------------------------------------- |
michael@0 | 2369 | * G | P | yes - May not work |
michael@0 | 2370 | * ----------------------------------------- |
michael@0 | 2371 | * L | G | no |
michael@0 | 2372 | * ----------------------------------------- |
michael@0 | 2373 | * P | G | yes - May not work |
michael@0 | 2374 | * ----------------------------------------- |
michael@0 | 2375 | * G | G | yes |
michael@0 | 2376 | * ----------------------------------------- |
michael@0 | 2377 | */ |
michael@0 | 2378 | |
michael@0 | 2379 | if (ifa->address.sa.sa_family != fam) { |
michael@0 | 2380 | /* forget non matching family */ |
michael@0 | 2381 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "ifa_fam:%d fam:%d\n", |
michael@0 | 2382 | ifa->address.sa.sa_family, fam); |
michael@0 | 2383 | return (NULL); |
michael@0 | 2384 | } |
michael@0 | 2385 | /* Ok the address may be ok */ |
michael@0 | 2386 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, &ifa->address.sa); |
michael@0 | 2387 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "dst_is_loop:%d dest_is_priv:%d\n", |
michael@0 | 2388 | dest_is_loop, dest_is_priv); |
michael@0 | 2389 | if ((dest_is_loop == 0) && (dest_is_priv == 0)) { |
michael@0 | 2390 | dest_is_global = 1; |
michael@0 | 2391 | } |
michael@0 | 2392 | #ifdef INET6 |
michael@0 | 2393 | if (fam == AF_INET6) { |
michael@0 | 2394 | /* ok to use deprecated addresses? */ |
michael@0 | 2395 | if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { |
michael@0 | 2396 | return (NULL); |
michael@0 | 2397 | } |
michael@0 | 2398 | if (ifa->src_is_priv) { |
michael@0 | 2399 | /* Special case, linklocal to loop */ |
michael@0 | 2400 | if (dest_is_loop) |
michael@0 | 2401 | return (NULL); |
michael@0 | 2402 | } |
michael@0 | 2403 | } |
michael@0 | 2404 | #endif |
michael@0 | 2405 | /* |
michael@0 | 2406 | * Now that we know what is what, implement our table. |
michael@0 | 2407 | * This could in theory be done slicker (it used to be), but this |
michael@0 | 2408 | * is straightforward and easier to validate :-) |
michael@0 | 2409 | */ |
michael@0 | 2410 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "ifa->src_is_loop:%d dest_is_priv:%d\n", |
michael@0 | 2411 | ifa->src_is_loop, |
michael@0 | 2412 | dest_is_priv); |
michael@0 | 2413 | if ((ifa->src_is_loop == 1) && (dest_is_priv)) { |
michael@0 | 2414 | return (NULL); |
michael@0 | 2415 | } |
michael@0 | 2416 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "ifa->src_is_loop:%d dest_is_glob:%d\n", |
michael@0 | 2417 | ifa->src_is_loop, |
michael@0 | 2418 | dest_is_global); |
michael@0 | 2419 | if ((ifa->src_is_loop == 1) && (dest_is_global)) { |
michael@0 | 2420 | return (NULL); |
michael@0 | 2421 | } |
michael@0 | 2422 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "address is acceptable\n"); |
michael@0 | 2423 | /* its an acceptable address */ |
michael@0 | 2424 | return (ifa); |
michael@0 | 2425 | } |
michael@0 | 2426 | |
michael@0 | 2427 | int |
michael@0 | 2428 | sctp_is_addr_restricted(struct sctp_tcb *stcb, struct sctp_ifa *ifa) |
michael@0 | 2429 | { |
michael@0 | 2430 | struct sctp_laddr *laddr; |
michael@0 | 2431 | |
michael@0 | 2432 | if (stcb == NULL) { |
michael@0 | 2433 | /* There are no restrictions, no TCB :-) */ |
michael@0 | 2434 | return (0); |
michael@0 | 2435 | } |
michael@0 | 2436 | LIST_FOREACH(laddr, &stcb->asoc.sctp_restricted_addrs, sctp_nxt_addr) { |
michael@0 | 2437 | if (laddr->ifa == NULL) { |
michael@0 | 2438 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n", |
michael@0 | 2439 | __FUNCTION__); |
michael@0 | 2440 | continue; |
michael@0 | 2441 | } |
michael@0 | 2442 | if (laddr->ifa == ifa) { |
michael@0 | 2443 | /* Yes it is on the list */ |
michael@0 | 2444 | return (1); |
michael@0 | 2445 | } |
michael@0 | 2446 | } |
michael@0 | 2447 | return (0); |
michael@0 | 2448 | } |
michael@0 | 2449 | |
michael@0 | 2450 | |
michael@0 | 2451 | int |
michael@0 | 2452 | sctp_is_addr_in_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa) |
michael@0 | 2453 | { |
michael@0 | 2454 | struct sctp_laddr *laddr; |
michael@0 | 2455 | |
michael@0 | 2456 | if (ifa == NULL) |
michael@0 | 2457 | return (0); |
michael@0 | 2458 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
michael@0 | 2459 | if (laddr->ifa == NULL) { |
michael@0 | 2460 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n", |
michael@0 | 2461 | __FUNCTION__); |
michael@0 | 2462 | continue; |
michael@0 | 2463 | } |
michael@0 | 2464 | if ((laddr->ifa == ifa) && laddr->action == 0) |
michael@0 | 2465 | /* same pointer */ |
michael@0 | 2466 | return (1); |
michael@0 | 2467 | } |
michael@0 | 2468 | return (0); |
michael@0 | 2469 | } |
michael@0 | 2470 | |
michael@0 | 2471 | |
michael@0 | 2472 | |
michael@0 | 2473 | static struct sctp_ifa * |
michael@0 | 2474 | sctp_choose_boundspecific_inp(struct sctp_inpcb *inp, |
michael@0 | 2475 | sctp_route_t *ro, |
michael@0 | 2476 | uint32_t vrf_id, |
michael@0 | 2477 | int non_asoc_addr_ok, |
michael@0 | 2478 | uint8_t dest_is_priv, |
michael@0 | 2479 | uint8_t dest_is_loop, |
michael@0 | 2480 | sa_family_t fam) |
michael@0 | 2481 | { |
michael@0 | 2482 | struct sctp_laddr *laddr, *starting_point; |
michael@0 | 2483 | void *ifn; |
michael@0 | 2484 | int resettotop = 0; |
michael@0 | 2485 | struct sctp_ifn *sctp_ifn; |
michael@0 | 2486 | struct sctp_ifa *sctp_ifa, *sifa; |
michael@0 | 2487 | struct sctp_vrf *vrf; |
michael@0 | 2488 | uint32_t ifn_index; |
michael@0 | 2489 | |
michael@0 | 2490 | vrf = sctp_find_vrf(vrf_id); |
michael@0 | 2491 | if (vrf == NULL) |
michael@0 | 2492 | return (NULL); |
michael@0 | 2493 | |
michael@0 | 2494 | ifn = SCTP_GET_IFN_VOID_FROM_ROUTE(ro); |
michael@0 | 2495 | ifn_index = SCTP_GET_IF_INDEX_FROM_ROUTE(ro); |
michael@0 | 2496 | sctp_ifn = sctp_find_ifn(ifn, ifn_index); |
michael@0 | 2497 | /* |
michael@0 | 2498 | * first question, is the ifn we will emit on in our list, if so, we |
michael@0 | 2499 | * want such an address. Note that we first looked for a |
michael@0 | 2500 | * preferred address. |
michael@0 | 2501 | */ |
michael@0 | 2502 | if (sctp_ifn) { |
michael@0 | 2503 | /* is a preferred one on the interface we route out? */ |
michael@0 | 2504 | LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { |
michael@0 | 2505 | if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && |
michael@0 | 2506 | (non_asoc_addr_ok == 0)) |
michael@0 | 2507 | continue; |
michael@0 | 2508 | sifa = sctp_is_ifa_addr_preferred(sctp_ifa, |
michael@0 | 2509 | dest_is_loop, |
michael@0 | 2510 | dest_is_priv, fam); |
michael@0 | 2511 | if (sifa == NULL) |
michael@0 | 2512 | continue; |
michael@0 | 2513 | if (sctp_is_addr_in_ep(inp, sifa)) { |
michael@0 | 2514 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 2515 | return (sifa); |
michael@0 | 2516 | } |
michael@0 | 2517 | } |
michael@0 | 2518 | } |
michael@0 | 2519 | /* |
michael@0 | 2520 | * ok, now we now need to find one on the list of the addresses. |
michael@0 | 2521 | * We can't get one on the emitting interface so let's find first |
michael@0 | 2522 | * a preferred one. If not that an acceptable one otherwise... |
michael@0 | 2523 | * we return NULL. |
michael@0 | 2524 | */ |
michael@0 | 2525 | starting_point = inp->next_addr_touse; |
michael@0 | 2526 | once_again: |
michael@0 | 2527 | if (inp->next_addr_touse == NULL) { |
michael@0 | 2528 | inp->next_addr_touse = LIST_FIRST(&inp->sctp_addr_list); |
michael@0 | 2529 | resettotop = 1; |
michael@0 | 2530 | } |
michael@0 | 2531 | for (laddr = inp->next_addr_touse; laddr; |
michael@0 | 2532 | laddr = LIST_NEXT(laddr, sctp_nxt_addr)) { |
michael@0 | 2533 | if (laddr->ifa == NULL) { |
michael@0 | 2534 | /* address has been removed */ |
michael@0 | 2535 | continue; |
michael@0 | 2536 | } |
michael@0 | 2537 | if (laddr->action == SCTP_DEL_IP_ADDRESS) { |
michael@0 | 2538 | /* address is being deleted */ |
michael@0 | 2539 | continue; |
michael@0 | 2540 | } |
michael@0 | 2541 | sifa = sctp_is_ifa_addr_preferred(laddr->ifa, dest_is_loop, |
michael@0 | 2542 | dest_is_priv, fam); |
michael@0 | 2543 | if (sifa == NULL) |
michael@0 | 2544 | continue; |
michael@0 | 2545 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 2546 | return (sifa); |
michael@0 | 2547 | } |
michael@0 | 2548 | if (resettotop == 0) { |
michael@0 | 2549 | inp->next_addr_touse = NULL; |
michael@0 | 2550 | goto once_again; |
michael@0 | 2551 | } |
michael@0 | 2552 | |
michael@0 | 2553 | inp->next_addr_touse = starting_point; |
michael@0 | 2554 | resettotop = 0; |
michael@0 | 2555 | once_again_too: |
michael@0 | 2556 | if (inp->next_addr_touse == NULL) { |
michael@0 | 2557 | inp->next_addr_touse = LIST_FIRST(&inp->sctp_addr_list); |
michael@0 | 2558 | resettotop = 1; |
michael@0 | 2559 | } |
michael@0 | 2560 | |
michael@0 | 2561 | /* ok, what about an acceptable address in the inp */ |
michael@0 | 2562 | for (laddr = inp->next_addr_touse; laddr; |
michael@0 | 2563 | laddr = LIST_NEXT(laddr, sctp_nxt_addr)) { |
michael@0 | 2564 | if (laddr->ifa == NULL) { |
michael@0 | 2565 | /* address has been removed */ |
michael@0 | 2566 | continue; |
michael@0 | 2567 | } |
michael@0 | 2568 | if (laddr->action == SCTP_DEL_IP_ADDRESS) { |
michael@0 | 2569 | /* address is being deleted */ |
michael@0 | 2570 | continue; |
michael@0 | 2571 | } |
michael@0 | 2572 | sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop, |
michael@0 | 2573 | dest_is_priv, fam); |
michael@0 | 2574 | if (sifa == NULL) |
michael@0 | 2575 | continue; |
michael@0 | 2576 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 2577 | return (sifa); |
michael@0 | 2578 | } |
michael@0 | 2579 | if (resettotop == 0) { |
michael@0 | 2580 | inp->next_addr_touse = NULL; |
michael@0 | 2581 | goto once_again_too; |
michael@0 | 2582 | } |
michael@0 | 2583 | |
michael@0 | 2584 | /* |
michael@0 | 2585 | * no address bound can be a source for the destination we are in |
michael@0 | 2586 | * trouble |
michael@0 | 2587 | */ |
michael@0 | 2588 | return (NULL); |
michael@0 | 2589 | } |
michael@0 | 2590 | |
michael@0 | 2591 | |
michael@0 | 2592 | |
michael@0 | 2593 | static struct sctp_ifa * |
michael@0 | 2594 | sctp_choose_boundspecific_stcb(struct sctp_inpcb *inp, |
michael@0 | 2595 | struct sctp_tcb *stcb, |
michael@0 | 2596 | sctp_route_t *ro, |
michael@0 | 2597 | uint32_t vrf_id, |
michael@0 | 2598 | uint8_t dest_is_priv, |
michael@0 | 2599 | uint8_t dest_is_loop, |
michael@0 | 2600 | int non_asoc_addr_ok, |
michael@0 | 2601 | sa_family_t fam) |
michael@0 | 2602 | { |
michael@0 | 2603 | struct sctp_laddr *laddr, *starting_point; |
michael@0 | 2604 | void *ifn; |
michael@0 | 2605 | struct sctp_ifn *sctp_ifn; |
michael@0 | 2606 | struct sctp_ifa *sctp_ifa, *sifa; |
michael@0 | 2607 | uint8_t start_at_beginning = 0; |
michael@0 | 2608 | struct sctp_vrf *vrf; |
michael@0 | 2609 | uint32_t ifn_index; |
michael@0 | 2610 | |
michael@0 | 2611 | /* |
michael@0 | 2612 | * first question, is the ifn we will emit on in our list, if so, we |
michael@0 | 2613 | * want that one. |
michael@0 | 2614 | */ |
michael@0 | 2615 | vrf = sctp_find_vrf(vrf_id); |
michael@0 | 2616 | if (vrf == NULL) |
michael@0 | 2617 | return (NULL); |
michael@0 | 2618 | |
michael@0 | 2619 | ifn = SCTP_GET_IFN_VOID_FROM_ROUTE(ro); |
michael@0 | 2620 | ifn_index = SCTP_GET_IF_INDEX_FROM_ROUTE(ro); |
michael@0 | 2621 | sctp_ifn = sctp_find_ifn( ifn, ifn_index); |
michael@0 | 2622 | |
michael@0 | 2623 | /* |
michael@0 | 2624 | * first question, is the ifn we will emit on in our list? If so, |
michael@0 | 2625 | * we want that one. First we look for a preferred. Second, we go |
michael@0 | 2626 | * for an acceptable. |
michael@0 | 2627 | */ |
michael@0 | 2628 | if (sctp_ifn) { |
michael@0 | 2629 | /* first try for a preferred address on the ep */ |
michael@0 | 2630 | LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { |
michael@0 | 2631 | if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0)) |
michael@0 | 2632 | continue; |
michael@0 | 2633 | if (sctp_is_addr_in_ep(inp, sctp_ifa)) { |
michael@0 | 2634 | sifa = sctp_is_ifa_addr_preferred(sctp_ifa, dest_is_loop, dest_is_priv, fam); |
michael@0 | 2635 | if (sifa == NULL) |
michael@0 | 2636 | continue; |
michael@0 | 2637 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 2638 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 2639 | (non_asoc_addr_ok && |
michael@0 | 2640 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 2641 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 2642 | /* on the no-no list */ |
michael@0 | 2643 | continue; |
michael@0 | 2644 | } |
michael@0 | 2645 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 2646 | return (sifa); |
michael@0 | 2647 | } |
michael@0 | 2648 | } |
michael@0 | 2649 | /* next try for an acceptable address on the ep */ |
michael@0 | 2650 | LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { |
michael@0 | 2651 | if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0)) |
michael@0 | 2652 | continue; |
michael@0 | 2653 | if (sctp_is_addr_in_ep(inp, sctp_ifa)) { |
michael@0 | 2654 | sifa= sctp_is_ifa_addr_acceptable(sctp_ifa, dest_is_loop, dest_is_priv,fam); |
michael@0 | 2655 | if (sifa == NULL) |
michael@0 | 2656 | continue; |
michael@0 | 2657 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 2658 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 2659 | (non_asoc_addr_ok && |
michael@0 | 2660 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 2661 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 2662 | /* on the no-no list */ |
michael@0 | 2663 | continue; |
michael@0 | 2664 | } |
michael@0 | 2665 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 2666 | return (sifa); |
michael@0 | 2667 | } |
michael@0 | 2668 | } |
michael@0 | 2669 | |
michael@0 | 2670 | } |
michael@0 | 2671 | /* |
michael@0 | 2672 | * if we can't find one like that then we must look at all |
michael@0 | 2673 | * addresses bound to pick one at first preferable then |
michael@0 | 2674 | * secondly acceptable. |
michael@0 | 2675 | */ |
michael@0 | 2676 | starting_point = stcb->asoc.last_used_address; |
michael@0 | 2677 | sctp_from_the_top: |
michael@0 | 2678 | if (stcb->asoc.last_used_address == NULL) { |
michael@0 | 2679 | start_at_beginning = 1; |
michael@0 | 2680 | stcb->asoc.last_used_address = LIST_FIRST(&inp->sctp_addr_list); |
michael@0 | 2681 | } |
michael@0 | 2682 | /* search beginning with the last used address */ |
michael@0 | 2683 | for (laddr = stcb->asoc.last_used_address; laddr; |
michael@0 | 2684 | laddr = LIST_NEXT(laddr, sctp_nxt_addr)) { |
michael@0 | 2685 | if (laddr->ifa == NULL) { |
michael@0 | 2686 | /* address has been removed */ |
michael@0 | 2687 | continue; |
michael@0 | 2688 | } |
michael@0 | 2689 | if (laddr->action == SCTP_DEL_IP_ADDRESS) { |
michael@0 | 2690 | /* address is being deleted */ |
michael@0 | 2691 | continue; |
michael@0 | 2692 | } |
michael@0 | 2693 | sifa = sctp_is_ifa_addr_preferred(laddr->ifa, dest_is_loop, dest_is_priv, fam); |
michael@0 | 2694 | if (sifa == NULL) |
michael@0 | 2695 | continue; |
michael@0 | 2696 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 2697 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 2698 | (non_asoc_addr_ok && |
michael@0 | 2699 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 2700 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 2701 | /* on the no-no list */ |
michael@0 | 2702 | continue; |
michael@0 | 2703 | } |
michael@0 | 2704 | stcb->asoc.last_used_address = laddr; |
michael@0 | 2705 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 2706 | return (sifa); |
michael@0 | 2707 | } |
michael@0 | 2708 | if (start_at_beginning == 0) { |
michael@0 | 2709 | stcb->asoc.last_used_address = NULL; |
michael@0 | 2710 | goto sctp_from_the_top; |
michael@0 | 2711 | } |
michael@0 | 2712 | /* now try for any higher scope than the destination */ |
michael@0 | 2713 | stcb->asoc.last_used_address = starting_point; |
michael@0 | 2714 | start_at_beginning = 0; |
michael@0 | 2715 | sctp_from_the_top2: |
michael@0 | 2716 | if (stcb->asoc.last_used_address == NULL) { |
michael@0 | 2717 | start_at_beginning = 1; |
michael@0 | 2718 | stcb->asoc.last_used_address = LIST_FIRST(&inp->sctp_addr_list); |
michael@0 | 2719 | } |
michael@0 | 2720 | /* search beginning with the last used address */ |
michael@0 | 2721 | for (laddr = stcb->asoc.last_used_address; laddr; |
michael@0 | 2722 | laddr = LIST_NEXT(laddr, sctp_nxt_addr)) { |
michael@0 | 2723 | if (laddr->ifa == NULL) { |
michael@0 | 2724 | /* address has been removed */ |
michael@0 | 2725 | continue; |
michael@0 | 2726 | } |
michael@0 | 2727 | if (laddr->action == SCTP_DEL_IP_ADDRESS) { |
michael@0 | 2728 | /* address is being deleted */ |
michael@0 | 2729 | continue; |
michael@0 | 2730 | } |
michael@0 | 2731 | sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop, |
michael@0 | 2732 | dest_is_priv, fam); |
michael@0 | 2733 | if (sifa == NULL) |
michael@0 | 2734 | continue; |
michael@0 | 2735 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 2736 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 2737 | (non_asoc_addr_ok && |
michael@0 | 2738 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 2739 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 2740 | /* on the no-no list */ |
michael@0 | 2741 | continue; |
michael@0 | 2742 | } |
michael@0 | 2743 | stcb->asoc.last_used_address = laddr; |
michael@0 | 2744 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 2745 | return (sifa); |
michael@0 | 2746 | } |
michael@0 | 2747 | if (start_at_beginning == 0) { |
michael@0 | 2748 | stcb->asoc.last_used_address = NULL; |
michael@0 | 2749 | goto sctp_from_the_top2; |
michael@0 | 2750 | } |
michael@0 | 2751 | return (NULL); |
michael@0 | 2752 | } |
michael@0 | 2753 | |
michael@0 | 2754 | static struct sctp_ifa * |
michael@0 | 2755 | sctp_select_nth_preferred_addr_from_ifn_boundall(struct sctp_ifn *ifn, |
michael@0 | 2756 | struct sctp_tcb *stcb, |
michael@0 | 2757 | int non_asoc_addr_ok, |
michael@0 | 2758 | uint8_t dest_is_loop, |
michael@0 | 2759 | uint8_t dest_is_priv, |
michael@0 | 2760 | int addr_wanted, |
michael@0 | 2761 | sa_family_t fam, |
michael@0 | 2762 | sctp_route_t *ro |
michael@0 | 2763 | ) |
michael@0 | 2764 | { |
michael@0 | 2765 | struct sctp_ifa *ifa, *sifa; |
michael@0 | 2766 | int num_eligible_addr = 0; |
michael@0 | 2767 | #ifdef INET6 |
michael@0 | 2768 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 2769 | struct sockaddr_in6 sin6, lsa6; |
michael@0 | 2770 | |
michael@0 | 2771 | if (fam == AF_INET6) { |
michael@0 | 2772 | memcpy(&sin6, &ro->ro_dst, sizeof(struct sockaddr_in6)); |
michael@0 | 2773 | #ifdef SCTP_KAME |
michael@0 | 2774 | (void)sa6_recoverscope(&sin6); |
michael@0 | 2775 | #else |
michael@0 | 2776 | (void)in6_recoverscope(&sin6, &sin6.sin6_addr, NULL); |
michael@0 | 2777 | #endif /* SCTP_KAME */ |
michael@0 | 2778 | } |
michael@0 | 2779 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 2780 | #endif /* INET6 */ |
michael@0 | 2781 | LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) { |
michael@0 | 2782 | if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && |
michael@0 | 2783 | (non_asoc_addr_ok == 0)) |
michael@0 | 2784 | continue; |
michael@0 | 2785 | sifa = sctp_is_ifa_addr_preferred(ifa, dest_is_loop, |
michael@0 | 2786 | dest_is_priv, fam); |
michael@0 | 2787 | if (sifa == NULL) |
michael@0 | 2788 | continue; |
michael@0 | 2789 | #ifdef INET6 |
michael@0 | 2790 | if (fam == AF_INET6 && |
michael@0 | 2791 | dest_is_loop && |
michael@0 | 2792 | sifa->src_is_loop && sifa->src_is_priv) { |
michael@0 | 2793 | /* don't allow fe80::1 to be a src on loop ::1, we don't list it |
michael@0 | 2794 | * to the peer so we will get an abort. |
michael@0 | 2795 | */ |
michael@0 | 2796 | continue; |
michael@0 | 2797 | } |
michael@0 | 2798 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 2799 | if (fam == AF_INET6 && |
michael@0 | 2800 | IN6_IS_ADDR_LINKLOCAL(&sifa->address.sin6.sin6_addr) && |
michael@0 | 2801 | IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr)) { |
michael@0 | 2802 | /* link-local <-> link-local must belong to the same scope. */ |
michael@0 | 2803 | memcpy(&lsa6, &sifa->address.sin6, sizeof(struct sockaddr_in6)); |
michael@0 | 2804 | #ifdef SCTP_KAME |
michael@0 | 2805 | (void)sa6_recoverscope(&lsa6); |
michael@0 | 2806 | #else |
michael@0 | 2807 | (void)in6_recoverscope(&lsa6, &lsa6.sin6_addr, NULL); |
michael@0 | 2808 | #endif /* SCTP_KAME */ |
michael@0 | 2809 | if (sin6.sin6_scope_id != lsa6.sin6_scope_id) { |
michael@0 | 2810 | continue; |
michael@0 | 2811 | } |
michael@0 | 2812 | } |
michael@0 | 2813 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 2814 | #endif /* INET6 */ |
michael@0 | 2815 | |
michael@0 | 2816 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Userspace__) |
michael@0 | 2817 | /* Check if the IPv6 address matches to next-hop. |
michael@0 | 2818 | In the mobile case, old IPv6 address may be not deleted |
michael@0 | 2819 | from the interface. Then, the interface has previous and |
michael@0 | 2820 | new addresses. We should use one corresponding to the |
michael@0 | 2821 | next-hop. (by micchie) |
michael@0 | 2822 | */ |
michael@0 | 2823 | #ifdef INET6 |
michael@0 | 2824 | if (stcb && fam == AF_INET6 && |
michael@0 | 2825 | sctp_is_mobility_feature_on(stcb->sctp_ep, SCTP_MOBILITY_BASE)) { |
michael@0 | 2826 | if (sctp_v6src_match_nexthop(&sifa->address.sin6, ro) |
michael@0 | 2827 | == 0) { |
michael@0 | 2828 | continue; |
michael@0 | 2829 | } |
michael@0 | 2830 | } |
michael@0 | 2831 | #endif |
michael@0 | 2832 | #ifdef INET |
michael@0 | 2833 | /* Avoid topologically incorrect IPv4 address */ |
michael@0 | 2834 | if (stcb && fam == AF_INET && |
michael@0 | 2835 | sctp_is_mobility_feature_on(stcb->sctp_ep, SCTP_MOBILITY_BASE)) { |
michael@0 | 2836 | if (sctp_v4src_match_nexthop(sifa, ro) == 0) { |
michael@0 | 2837 | continue; |
michael@0 | 2838 | } |
michael@0 | 2839 | } |
michael@0 | 2840 | #endif |
michael@0 | 2841 | #endif |
michael@0 | 2842 | if (stcb) { |
michael@0 | 2843 | if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) { |
michael@0 | 2844 | continue; |
michael@0 | 2845 | } |
michael@0 | 2846 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 2847 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 2848 | (non_asoc_addr_ok && |
michael@0 | 2849 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 2850 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 2851 | /* |
michael@0 | 2852 | * It is restricted for some reason.. |
michael@0 | 2853 | * probably not yet added. |
michael@0 | 2854 | */ |
michael@0 | 2855 | continue; |
michael@0 | 2856 | } |
michael@0 | 2857 | } |
michael@0 | 2858 | if (num_eligible_addr >= addr_wanted) { |
michael@0 | 2859 | return (sifa); |
michael@0 | 2860 | } |
michael@0 | 2861 | num_eligible_addr++; |
michael@0 | 2862 | } |
michael@0 | 2863 | return (NULL); |
michael@0 | 2864 | } |
michael@0 | 2865 | |
michael@0 | 2866 | |
michael@0 | 2867 | static int |
michael@0 | 2868 | sctp_count_num_preferred_boundall(struct sctp_ifn *ifn, |
michael@0 | 2869 | struct sctp_tcb *stcb, |
michael@0 | 2870 | int non_asoc_addr_ok, |
michael@0 | 2871 | uint8_t dest_is_loop, |
michael@0 | 2872 | uint8_t dest_is_priv, |
michael@0 | 2873 | sa_family_t fam) |
michael@0 | 2874 | { |
michael@0 | 2875 | struct sctp_ifa *ifa, *sifa; |
michael@0 | 2876 | int num_eligible_addr = 0; |
michael@0 | 2877 | |
michael@0 | 2878 | LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) { |
michael@0 | 2879 | if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && |
michael@0 | 2880 | (non_asoc_addr_ok == 0)) { |
michael@0 | 2881 | continue; |
michael@0 | 2882 | } |
michael@0 | 2883 | sifa = sctp_is_ifa_addr_preferred(ifa, dest_is_loop, |
michael@0 | 2884 | dest_is_priv, fam); |
michael@0 | 2885 | if (sifa == NULL) { |
michael@0 | 2886 | continue; |
michael@0 | 2887 | } |
michael@0 | 2888 | if (stcb) { |
michael@0 | 2889 | if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) { |
michael@0 | 2890 | continue; |
michael@0 | 2891 | } |
michael@0 | 2892 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 2893 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 2894 | (non_asoc_addr_ok && |
michael@0 | 2895 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 2896 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 2897 | /* |
michael@0 | 2898 | * It is restricted for some reason.. |
michael@0 | 2899 | * probably not yet added. |
michael@0 | 2900 | */ |
michael@0 | 2901 | continue; |
michael@0 | 2902 | } |
michael@0 | 2903 | } |
michael@0 | 2904 | num_eligible_addr++; |
michael@0 | 2905 | } |
michael@0 | 2906 | return (num_eligible_addr); |
michael@0 | 2907 | } |
michael@0 | 2908 | |
michael@0 | 2909 | static struct sctp_ifa * |
michael@0 | 2910 | sctp_choose_boundall(struct sctp_tcb *stcb, |
michael@0 | 2911 | struct sctp_nets *net, |
michael@0 | 2912 | sctp_route_t *ro, |
michael@0 | 2913 | uint32_t vrf_id, |
michael@0 | 2914 | uint8_t dest_is_priv, |
michael@0 | 2915 | uint8_t dest_is_loop, |
michael@0 | 2916 | int non_asoc_addr_ok, |
michael@0 | 2917 | sa_family_t fam) |
michael@0 | 2918 | { |
michael@0 | 2919 | int cur_addr_num = 0, num_preferred = 0; |
michael@0 | 2920 | void *ifn; |
michael@0 | 2921 | struct sctp_ifn *sctp_ifn, *looked_at = NULL, *emit_ifn; |
michael@0 | 2922 | struct sctp_ifa *sctp_ifa, *sifa; |
michael@0 | 2923 | uint32_t ifn_index; |
michael@0 | 2924 | struct sctp_vrf *vrf; |
michael@0 | 2925 | #ifdef INET |
michael@0 | 2926 | int retried = 0; |
michael@0 | 2927 | #endif |
michael@0 | 2928 | |
michael@0 | 2929 | /*- |
michael@0 | 2930 | * For boundall we can use any address in the association. |
michael@0 | 2931 | * If non_asoc_addr_ok is set we can use any address (at least in |
michael@0 | 2932 | * theory). So we look for preferred addresses first. If we find one, |
michael@0 | 2933 | * we use it. Otherwise we next try to get an address on the |
michael@0 | 2934 | * interface, which we should be able to do (unless non_asoc_addr_ok |
michael@0 | 2935 | * is false and we are routed out that way). In these cases where we |
michael@0 | 2936 | * can't use the address of the interface we go through all the |
michael@0 | 2937 | * ifn's looking for an address we can use and fill that in. Punting |
michael@0 | 2938 | * means we send back address 0, which will probably cause problems |
michael@0 | 2939 | * actually since then IP will fill in the address of the route ifn, |
michael@0 | 2940 | * which means we probably already rejected it.. i.e. here comes an |
michael@0 | 2941 | * abort :-<. |
michael@0 | 2942 | */ |
michael@0 | 2943 | vrf = sctp_find_vrf(vrf_id); |
michael@0 | 2944 | if (vrf == NULL) |
michael@0 | 2945 | return (NULL); |
michael@0 | 2946 | |
michael@0 | 2947 | ifn = SCTP_GET_IFN_VOID_FROM_ROUTE(ro); |
michael@0 | 2948 | ifn_index = SCTP_GET_IF_INDEX_FROM_ROUTE(ro); |
michael@0 | 2949 | SCTPDBG(SCTP_DEBUG_OUTPUT2,"ifn from route:%p ifn_index:%d\n", ifn, ifn_index); |
michael@0 | 2950 | emit_ifn = looked_at = sctp_ifn = sctp_find_ifn(ifn, ifn_index); |
michael@0 | 2951 | if (sctp_ifn == NULL) { |
michael@0 | 2952 | /* ?? We don't have this guy ?? */ |
michael@0 | 2953 | SCTPDBG(SCTP_DEBUG_OUTPUT2,"No ifn emit interface?\n"); |
michael@0 | 2954 | goto bound_all_plan_b; |
michael@0 | 2955 | } |
michael@0 | 2956 | SCTPDBG(SCTP_DEBUG_OUTPUT2,"ifn_index:%d name:%s is emit interface\n", |
michael@0 | 2957 | ifn_index, sctp_ifn->ifn_name); |
michael@0 | 2958 | |
michael@0 | 2959 | if (net) { |
michael@0 | 2960 | cur_addr_num = net->indx_of_eligible_next_to_use; |
michael@0 | 2961 | } |
michael@0 | 2962 | num_preferred = sctp_count_num_preferred_boundall(sctp_ifn, |
michael@0 | 2963 | stcb, |
michael@0 | 2964 | non_asoc_addr_ok, |
michael@0 | 2965 | dest_is_loop, |
michael@0 | 2966 | dest_is_priv, fam); |
michael@0 | 2967 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Found %d preferred source addresses for intf:%s\n", |
michael@0 | 2968 | num_preferred, sctp_ifn->ifn_name); |
michael@0 | 2969 | if (num_preferred == 0) { |
michael@0 | 2970 | /* |
michael@0 | 2971 | * no eligible addresses, we must use some other interface |
michael@0 | 2972 | * address if we can find one. |
michael@0 | 2973 | */ |
michael@0 | 2974 | goto bound_all_plan_b; |
michael@0 | 2975 | } |
michael@0 | 2976 | /* |
michael@0 | 2977 | * Ok we have num_eligible_addr set with how many we can use, this |
michael@0 | 2978 | * may vary from call to call due to addresses being deprecated |
michael@0 | 2979 | * etc.. |
michael@0 | 2980 | */ |
michael@0 | 2981 | if (cur_addr_num >= num_preferred) { |
michael@0 | 2982 | cur_addr_num = 0; |
michael@0 | 2983 | } |
michael@0 | 2984 | /* |
michael@0 | 2985 | * select the nth address from the list (where cur_addr_num is the |
michael@0 | 2986 | * nth) and 0 is the first one, 1 is the second one etc... |
michael@0 | 2987 | */ |
michael@0 | 2988 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "cur_addr_num:%d\n", cur_addr_num); |
michael@0 | 2989 | |
michael@0 | 2990 | sctp_ifa = sctp_select_nth_preferred_addr_from_ifn_boundall(sctp_ifn, stcb, non_asoc_addr_ok, dest_is_loop, |
michael@0 | 2991 | dest_is_priv, cur_addr_num, fam, ro); |
michael@0 | 2992 | |
michael@0 | 2993 | /* if sctp_ifa is NULL something changed??, fall to plan b. */ |
michael@0 | 2994 | if (sctp_ifa) { |
michael@0 | 2995 | atomic_add_int(&sctp_ifa->refcount, 1); |
michael@0 | 2996 | if (net) { |
michael@0 | 2997 | /* save off where the next one we will want */ |
michael@0 | 2998 | net->indx_of_eligible_next_to_use = cur_addr_num + 1; |
michael@0 | 2999 | } |
michael@0 | 3000 | return (sctp_ifa); |
michael@0 | 3001 | } |
michael@0 | 3002 | /* |
michael@0 | 3003 | * plan_b: Look at all interfaces and find a preferred address. If |
michael@0 | 3004 | * no preferred fall through to plan_c. |
michael@0 | 3005 | */ |
michael@0 | 3006 | bound_all_plan_b: |
michael@0 | 3007 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Trying Plan B\n"); |
michael@0 | 3008 | LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { |
michael@0 | 3009 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Examine interface %s\n", |
michael@0 | 3010 | sctp_ifn->ifn_name); |
michael@0 | 3011 | if (dest_is_loop == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { |
michael@0 | 3012 | /* wrong base scope */ |
michael@0 | 3013 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "skip\n"); |
michael@0 | 3014 | continue; |
michael@0 | 3015 | } |
michael@0 | 3016 | if ((sctp_ifn == looked_at) && looked_at) { |
michael@0 | 3017 | /* already looked at this guy */ |
michael@0 | 3018 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "already seen\n"); |
michael@0 | 3019 | continue; |
michael@0 | 3020 | } |
michael@0 | 3021 | num_preferred = sctp_count_num_preferred_boundall(sctp_ifn, stcb, non_asoc_addr_ok, |
michael@0 | 3022 | dest_is_loop, dest_is_priv, fam); |
michael@0 | 3023 | SCTPDBG(SCTP_DEBUG_OUTPUT2, |
michael@0 | 3024 | "Found ifn:%p %d preferred source addresses\n", |
michael@0 | 3025 | ifn, num_preferred); |
michael@0 | 3026 | if (num_preferred == 0) { |
michael@0 | 3027 | /* None on this interface. */ |
michael@0 | 3028 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "No prefered -- skipping to next\n"); |
michael@0 | 3029 | continue; |
michael@0 | 3030 | } |
michael@0 | 3031 | SCTPDBG(SCTP_DEBUG_OUTPUT2, |
michael@0 | 3032 | "num preferred:%d on interface:%p cur_addr_num:%d\n", |
michael@0 | 3033 | num_preferred, (void *)sctp_ifn, cur_addr_num); |
michael@0 | 3034 | |
michael@0 | 3035 | /* |
michael@0 | 3036 | * Ok we have num_eligible_addr set with how many we can |
michael@0 | 3037 | * use, this may vary from call to call due to addresses |
michael@0 | 3038 | * being deprecated etc.. |
michael@0 | 3039 | */ |
michael@0 | 3040 | if (cur_addr_num >= num_preferred) { |
michael@0 | 3041 | cur_addr_num = 0; |
michael@0 | 3042 | } |
michael@0 | 3043 | sifa = sctp_select_nth_preferred_addr_from_ifn_boundall(sctp_ifn, stcb, non_asoc_addr_ok, dest_is_loop, |
michael@0 | 3044 | dest_is_priv, cur_addr_num, fam, ro); |
michael@0 | 3045 | if (sifa == NULL) |
michael@0 | 3046 | continue; |
michael@0 | 3047 | if (net) { |
michael@0 | 3048 | net->indx_of_eligible_next_to_use = cur_addr_num + 1; |
michael@0 | 3049 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "we selected %d\n", |
michael@0 | 3050 | cur_addr_num); |
michael@0 | 3051 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Source:"); |
michael@0 | 3052 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &sifa->address.sa); |
michael@0 | 3053 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Dest:"); |
michael@0 | 3054 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &net->ro._l_addr.sa); |
michael@0 | 3055 | } |
michael@0 | 3056 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 3057 | return (sifa); |
michael@0 | 3058 | } |
michael@0 | 3059 | #ifdef INET |
michael@0 | 3060 | again_with_private_addresses_allowed: |
michael@0 | 3061 | #endif |
michael@0 | 3062 | /* plan_c: do we have an acceptable address on the emit interface */ |
michael@0 | 3063 | sifa = NULL; |
michael@0 | 3064 | SCTPDBG(SCTP_DEBUG_OUTPUT2,"Trying Plan C: find acceptable on interface\n"); |
michael@0 | 3065 | if (emit_ifn == NULL) { |
michael@0 | 3066 | SCTPDBG(SCTP_DEBUG_OUTPUT2,"Jump to Plan D - no emit_ifn\n"); |
michael@0 | 3067 | goto plan_d; |
michael@0 | 3068 | } |
michael@0 | 3069 | LIST_FOREACH(sctp_ifa, &emit_ifn->ifalist, next_ifa) { |
michael@0 | 3070 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "ifa:%p\n", (void *)sctp_ifa); |
michael@0 | 3071 | if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && |
michael@0 | 3072 | (non_asoc_addr_ok == 0)) { |
michael@0 | 3073 | SCTPDBG(SCTP_DEBUG_OUTPUT2,"Defer\n"); |
michael@0 | 3074 | continue; |
michael@0 | 3075 | } |
michael@0 | 3076 | sifa = sctp_is_ifa_addr_acceptable(sctp_ifa, dest_is_loop, |
michael@0 | 3077 | dest_is_priv, fam); |
michael@0 | 3078 | if (sifa == NULL) { |
michael@0 | 3079 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "IFA not acceptable\n"); |
michael@0 | 3080 | continue; |
michael@0 | 3081 | } |
michael@0 | 3082 | if (stcb) { |
michael@0 | 3083 | if (sctp_is_address_in_scope(sifa, &stcb->asoc.scope, 0) == 0) { |
michael@0 | 3084 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "NOT in scope\n"); |
michael@0 | 3085 | sifa = NULL; |
michael@0 | 3086 | continue; |
michael@0 | 3087 | } |
michael@0 | 3088 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 3089 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 3090 | (non_asoc_addr_ok && |
michael@0 | 3091 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 3092 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 3093 | /* |
michael@0 | 3094 | * It is restricted for some |
michael@0 | 3095 | * reason.. probably not yet added. |
michael@0 | 3096 | */ |
michael@0 | 3097 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Its resticted\n"); |
michael@0 | 3098 | sifa = NULL; |
michael@0 | 3099 | continue; |
michael@0 | 3100 | } |
michael@0 | 3101 | } else { |
michael@0 | 3102 | SCTP_PRINTF("Stcb is null - no print\n"); |
michael@0 | 3103 | } |
michael@0 | 3104 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 3105 | goto out; |
michael@0 | 3106 | } |
michael@0 | 3107 | plan_d: |
michael@0 | 3108 | /* |
michael@0 | 3109 | * plan_d: We are in trouble. No preferred address on the emit |
michael@0 | 3110 | * interface. And not even a preferred address on all interfaces. |
michael@0 | 3111 | * Go out and see if we can find an acceptable address somewhere |
michael@0 | 3112 | * amongst all interfaces. |
michael@0 | 3113 | */ |
michael@0 | 3114 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Trying Plan D looked_at is %p\n", (void *)looked_at); |
michael@0 | 3115 | LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { |
michael@0 | 3116 | if (dest_is_loop == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { |
michael@0 | 3117 | /* wrong base scope */ |
michael@0 | 3118 | continue; |
michael@0 | 3119 | } |
michael@0 | 3120 | LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { |
michael@0 | 3121 | if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && |
michael@0 | 3122 | (non_asoc_addr_ok == 0)) |
michael@0 | 3123 | continue; |
michael@0 | 3124 | sifa = sctp_is_ifa_addr_acceptable(sctp_ifa, |
michael@0 | 3125 | dest_is_loop, |
michael@0 | 3126 | dest_is_priv, fam); |
michael@0 | 3127 | if (sifa == NULL) |
michael@0 | 3128 | continue; |
michael@0 | 3129 | if (stcb) { |
michael@0 | 3130 | if (sctp_is_address_in_scope(sifa, &stcb->asoc.scope, 0) == 0) { |
michael@0 | 3131 | sifa = NULL; |
michael@0 | 3132 | continue; |
michael@0 | 3133 | } |
michael@0 | 3134 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 3135 | (sctp_is_addr_restricted(stcb, sifa))) || |
michael@0 | 3136 | (non_asoc_addr_ok && |
michael@0 | 3137 | (sctp_is_addr_restricted(stcb, sifa)) && |
michael@0 | 3138 | (!sctp_is_addr_pending(stcb, sifa)))) { |
michael@0 | 3139 | /* |
michael@0 | 3140 | * It is restricted for some |
michael@0 | 3141 | * reason.. probably not yet added. |
michael@0 | 3142 | */ |
michael@0 | 3143 | sifa = NULL; |
michael@0 | 3144 | continue; |
michael@0 | 3145 | } |
michael@0 | 3146 | } |
michael@0 | 3147 | goto out; |
michael@0 | 3148 | } |
michael@0 | 3149 | } |
michael@0 | 3150 | #ifdef INET |
michael@0 | 3151 | if ((retried == 0) && (stcb->asoc.scope.ipv4_local_scope == 0)) { |
michael@0 | 3152 | stcb->asoc.scope.ipv4_local_scope = 1; |
michael@0 | 3153 | retried = 1; |
michael@0 | 3154 | goto again_with_private_addresses_allowed; |
michael@0 | 3155 | } else if (retried == 1) { |
michael@0 | 3156 | stcb->asoc.scope.ipv4_local_scope = 0; |
michael@0 | 3157 | } |
michael@0 | 3158 | #endif |
michael@0 | 3159 | out: |
michael@0 | 3160 | #ifdef INET |
michael@0 | 3161 | if (sifa) { |
michael@0 | 3162 | if (retried == 1) { |
michael@0 | 3163 | LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { |
michael@0 | 3164 | if (dest_is_loop == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { |
michael@0 | 3165 | /* wrong base scope */ |
michael@0 | 3166 | continue; |
michael@0 | 3167 | } |
michael@0 | 3168 | LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { |
michael@0 | 3169 | struct sctp_ifa *tmp_sifa; |
michael@0 | 3170 | |
michael@0 | 3171 | if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && |
michael@0 | 3172 | (non_asoc_addr_ok == 0)) |
michael@0 | 3173 | continue; |
michael@0 | 3174 | tmp_sifa = sctp_is_ifa_addr_acceptable(sctp_ifa, |
michael@0 | 3175 | dest_is_loop, |
michael@0 | 3176 | dest_is_priv, fam); |
michael@0 | 3177 | if (tmp_sifa == NULL) { |
michael@0 | 3178 | continue; |
michael@0 | 3179 | } |
michael@0 | 3180 | if (tmp_sifa == sifa) { |
michael@0 | 3181 | continue; |
michael@0 | 3182 | } |
michael@0 | 3183 | if (stcb) { |
michael@0 | 3184 | if (sctp_is_address_in_scope(tmp_sifa, |
michael@0 | 3185 | &stcb->asoc.scope, 0) == 0) { |
michael@0 | 3186 | continue; |
michael@0 | 3187 | } |
michael@0 | 3188 | if (((non_asoc_addr_ok == 0) && |
michael@0 | 3189 | (sctp_is_addr_restricted(stcb, tmp_sifa))) || |
michael@0 | 3190 | (non_asoc_addr_ok && |
michael@0 | 3191 | (sctp_is_addr_restricted(stcb, tmp_sifa)) && |
michael@0 | 3192 | (!sctp_is_addr_pending(stcb, tmp_sifa)))) { |
michael@0 | 3193 | /* |
michael@0 | 3194 | * It is restricted for some |
michael@0 | 3195 | * reason.. probably not yet added. |
michael@0 | 3196 | */ |
michael@0 | 3197 | continue; |
michael@0 | 3198 | } |
michael@0 | 3199 | } |
michael@0 | 3200 | if ((tmp_sifa->address.sin.sin_family == AF_INET) && |
michael@0 | 3201 | (IN4_ISPRIVATE_ADDRESS(&(tmp_sifa->address.sin.sin_addr)))) { |
michael@0 | 3202 | sctp_add_local_addr_restricted(stcb, tmp_sifa); |
michael@0 | 3203 | } |
michael@0 | 3204 | } |
michael@0 | 3205 | } |
michael@0 | 3206 | } |
michael@0 | 3207 | atomic_add_int(&sifa->refcount, 1); |
michael@0 | 3208 | } |
michael@0 | 3209 | #endif |
michael@0 | 3210 | return (sifa); |
michael@0 | 3211 | } |
michael@0 | 3212 | |
michael@0 | 3213 | |
michael@0 | 3214 | |
michael@0 | 3215 | /* tcb may be NULL */ |
michael@0 | 3216 | struct sctp_ifa * |
michael@0 | 3217 | sctp_source_address_selection(struct sctp_inpcb *inp, |
michael@0 | 3218 | struct sctp_tcb *stcb, |
michael@0 | 3219 | sctp_route_t *ro, |
michael@0 | 3220 | struct sctp_nets *net, |
michael@0 | 3221 | int non_asoc_addr_ok, uint32_t vrf_id) |
michael@0 | 3222 | { |
michael@0 | 3223 | struct sctp_ifa *answer; |
michael@0 | 3224 | uint8_t dest_is_priv, dest_is_loop; |
michael@0 | 3225 | sa_family_t fam; |
michael@0 | 3226 | #ifdef INET |
michael@0 | 3227 | struct sockaddr_in *to = (struct sockaddr_in *)&ro->ro_dst; |
michael@0 | 3228 | #endif |
michael@0 | 3229 | #ifdef INET6 |
michael@0 | 3230 | struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&ro->ro_dst; |
michael@0 | 3231 | #endif |
michael@0 | 3232 | |
michael@0 | 3233 | /** |
michael@0 | 3234 | * Rules: - Find the route if needed, cache if I can. - Look at |
michael@0 | 3235 | * interface address in route, Is it in the bound list. If so we |
michael@0 | 3236 | * have the best source. - If not we must rotate amongst the |
michael@0 | 3237 | * addresses. |
michael@0 | 3238 | * |
michael@0 | 3239 | * Cavets and issues |
michael@0 | 3240 | * |
michael@0 | 3241 | * Do we need to pay attention to scope. We can have a private address |
michael@0 | 3242 | * or a global address we are sourcing or sending to. So if we draw |
michael@0 | 3243 | * it out |
michael@0 | 3244 | * zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz |
michael@0 | 3245 | * For V4 |
michael@0 | 3246 | * ------------------------------------------ |
michael@0 | 3247 | * source * dest * result |
michael@0 | 3248 | * ----------------------------------------- |
michael@0 | 3249 | * <a> Private * Global * NAT |
michael@0 | 3250 | * ----------------------------------------- |
michael@0 | 3251 | * <b> Private * Private * No problem |
michael@0 | 3252 | * ----------------------------------------- |
michael@0 | 3253 | * <c> Global * Private * Huh, How will this work? |
michael@0 | 3254 | * ----------------------------------------- |
michael@0 | 3255 | * <d> Global * Global * No Problem |
michael@0 | 3256 | *------------------------------------------ |
michael@0 | 3257 | * zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz |
michael@0 | 3258 | * For V6 |
michael@0 | 3259 | *------------------------------------------ |
michael@0 | 3260 | * source * dest * result |
michael@0 | 3261 | * ----------------------------------------- |
michael@0 | 3262 | * <a> Linklocal * Global * |
michael@0 | 3263 | * ----------------------------------------- |
michael@0 | 3264 | * <b> Linklocal * Linklocal * No problem |
michael@0 | 3265 | * ----------------------------------------- |
michael@0 | 3266 | * <c> Global * Linklocal * Huh, How will this work? |
michael@0 | 3267 | * ----------------------------------------- |
michael@0 | 3268 | * <d> Global * Global * No Problem |
michael@0 | 3269 | *------------------------------------------ |
michael@0 | 3270 | * zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz |
michael@0 | 3271 | * |
michael@0 | 3272 | * And then we add to that what happens if there are multiple addresses |
michael@0 | 3273 | * assigned to an interface. Remember the ifa on a ifn is a linked |
michael@0 | 3274 | * list of addresses. So one interface can have more than one IP |
michael@0 | 3275 | * address. What happens if we have both a private and a global |
michael@0 | 3276 | * address? Do we then use context of destination to sort out which |
michael@0 | 3277 | * one is best? And what about NAT's sending P->G may get you a NAT |
michael@0 | 3278 | * translation, or should you select the G thats on the interface in |
michael@0 | 3279 | * preference. |
michael@0 | 3280 | * |
michael@0 | 3281 | * Decisions: |
michael@0 | 3282 | * |
michael@0 | 3283 | * - count the number of addresses on the interface. |
michael@0 | 3284 | * - if it is one, no problem except case <c>. |
michael@0 | 3285 | * For <a> we will assume a NAT out there. |
michael@0 | 3286 | * - if there are more than one, then we need to worry about scope P |
michael@0 | 3287 | * or G. We should prefer G -> G and P -> P if possible. |
michael@0 | 3288 | * Then as a secondary fall back to mixed types G->P being a last |
michael@0 | 3289 | * ditch one. |
michael@0 | 3290 | * - The above all works for bound all, but bound specific we need to |
michael@0 | 3291 | * use the same concept but instead only consider the bound |
michael@0 | 3292 | * addresses. If the bound set is NOT assigned to the interface then |
michael@0 | 3293 | * we must use rotation amongst the bound addresses.. |
michael@0 | 3294 | */ |
michael@0 | 3295 | if (ro->ro_rt == NULL) { |
michael@0 | 3296 | /* |
michael@0 | 3297 | * Need a route to cache. |
michael@0 | 3298 | */ |
michael@0 | 3299 | SCTP_RTALLOC(ro, vrf_id); |
michael@0 | 3300 | } |
michael@0 | 3301 | if (ro->ro_rt == NULL) { |
michael@0 | 3302 | return (NULL); |
michael@0 | 3303 | } |
michael@0 | 3304 | fam = ro->ro_dst.sa_family; |
michael@0 | 3305 | dest_is_priv = dest_is_loop = 0; |
michael@0 | 3306 | /* Setup our scopes for the destination */ |
michael@0 | 3307 | switch (fam) { |
michael@0 | 3308 | #ifdef INET |
michael@0 | 3309 | case AF_INET: |
michael@0 | 3310 | /* Scope based on outbound address */ |
michael@0 | 3311 | if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { |
michael@0 | 3312 | dest_is_loop = 1; |
michael@0 | 3313 | if (net != NULL) { |
michael@0 | 3314 | /* mark it as local */ |
michael@0 | 3315 | net->addr_is_local = 1; |
michael@0 | 3316 | } |
michael@0 | 3317 | } else if ((IN4_ISPRIVATE_ADDRESS(&to->sin_addr))) { |
michael@0 | 3318 | dest_is_priv = 1; |
michael@0 | 3319 | } |
michael@0 | 3320 | break; |
michael@0 | 3321 | #endif |
michael@0 | 3322 | #ifdef INET6 |
michael@0 | 3323 | case AF_INET6: |
michael@0 | 3324 | /* Scope based on outbound address */ |
michael@0 | 3325 | #if defined(__Userspace_os_Windows) |
michael@0 | 3326 | if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { |
michael@0 | 3327 | #else |
michael@0 | 3328 | if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr) || |
michael@0 | 3329 | SCTP_ROUTE_IS_REAL_LOOP(ro)) { |
michael@0 | 3330 | #endif |
michael@0 | 3331 | /* |
michael@0 | 3332 | * If the address is a loopback address, which |
michael@0 | 3333 | * consists of "::1" OR "fe80::1%lo0", we are loopback |
michael@0 | 3334 | * scope. But we don't use dest_is_priv (link local |
michael@0 | 3335 | * addresses). |
michael@0 | 3336 | */ |
michael@0 | 3337 | dest_is_loop = 1; |
michael@0 | 3338 | if (net != NULL) { |
michael@0 | 3339 | /* mark it as local */ |
michael@0 | 3340 | net->addr_is_local = 1; |
michael@0 | 3341 | } |
michael@0 | 3342 | } else if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { |
michael@0 | 3343 | dest_is_priv = 1; |
michael@0 | 3344 | } |
michael@0 | 3345 | break; |
michael@0 | 3346 | #endif |
michael@0 | 3347 | } |
michael@0 | 3348 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "Select source addr for:"); |
michael@0 | 3349 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)&ro->ro_dst); |
michael@0 | 3350 | SCTP_IPI_ADDR_RLOCK(); |
michael@0 | 3351 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { |
michael@0 | 3352 | /* |
michael@0 | 3353 | * Bound all case |
michael@0 | 3354 | */ |
michael@0 | 3355 | answer = sctp_choose_boundall(stcb, net, ro, vrf_id, |
michael@0 | 3356 | dest_is_priv, dest_is_loop, |
michael@0 | 3357 | non_asoc_addr_ok, fam); |
michael@0 | 3358 | SCTP_IPI_ADDR_RUNLOCK(); |
michael@0 | 3359 | return (answer); |
michael@0 | 3360 | } |
michael@0 | 3361 | /* |
michael@0 | 3362 | * Subset bound case |
michael@0 | 3363 | */ |
michael@0 | 3364 | if (stcb) { |
michael@0 | 3365 | answer = sctp_choose_boundspecific_stcb(inp, stcb, ro, |
michael@0 | 3366 | vrf_id, dest_is_priv, |
michael@0 | 3367 | dest_is_loop, |
michael@0 | 3368 | non_asoc_addr_ok, fam); |
michael@0 | 3369 | } else { |
michael@0 | 3370 | answer = sctp_choose_boundspecific_inp(inp, ro, vrf_id, |
michael@0 | 3371 | non_asoc_addr_ok, |
michael@0 | 3372 | dest_is_priv, |
michael@0 | 3373 | dest_is_loop, fam); |
michael@0 | 3374 | } |
michael@0 | 3375 | SCTP_IPI_ADDR_RUNLOCK(); |
michael@0 | 3376 | return (answer); |
michael@0 | 3377 | } |
michael@0 | 3378 | |
michael@0 | 3379 | static int |
michael@0 | 3380 | sctp_find_cmsg(int c_type, void *data, struct mbuf *control, size_t cpsize) |
michael@0 | 3381 | { |
michael@0 | 3382 | #if defined(__Userspace_os_Windows) |
michael@0 | 3383 | WSACMSGHDR cmh; |
michael@0 | 3384 | #else |
michael@0 | 3385 | struct cmsghdr cmh; |
michael@0 | 3386 | #endif |
michael@0 | 3387 | int tlen, at, found; |
michael@0 | 3388 | struct sctp_sndinfo sndinfo; |
michael@0 | 3389 | struct sctp_prinfo prinfo; |
michael@0 | 3390 | struct sctp_authinfo authinfo; |
michael@0 | 3391 | |
michael@0 | 3392 | tlen = SCTP_BUF_LEN(control); |
michael@0 | 3393 | at = 0; |
michael@0 | 3394 | found = 0; |
michael@0 | 3395 | /* |
michael@0 | 3396 | * Independent of how many mbufs, find the c_type inside the control |
michael@0 | 3397 | * structure and copy out the data. |
michael@0 | 3398 | */ |
michael@0 | 3399 | while (at < tlen) { |
michael@0 | 3400 | if ((tlen - at) < (int)CMSG_ALIGN(sizeof(cmh))) { |
michael@0 | 3401 | /* There is not enough room for one more. */ |
michael@0 | 3402 | return (found); |
michael@0 | 3403 | } |
michael@0 | 3404 | m_copydata(control, at, sizeof(cmh), (caddr_t)&cmh); |
michael@0 | 3405 | if (cmh.cmsg_len < CMSG_ALIGN(sizeof(cmh))) { |
michael@0 | 3406 | /* We dont't have a complete CMSG header. */ |
michael@0 | 3407 | return (found); |
michael@0 | 3408 | } |
michael@0 | 3409 | if (((int)cmh.cmsg_len + at) > tlen) { |
michael@0 | 3410 | /* We don't have the complete CMSG. */ |
michael@0 | 3411 | return (found); |
michael@0 | 3412 | } |
michael@0 | 3413 | if ((cmh.cmsg_level == IPPROTO_SCTP) && |
michael@0 | 3414 | ((c_type == cmh.cmsg_type) || |
michael@0 | 3415 | ((c_type == SCTP_SNDRCV) && |
michael@0 | 3416 | ((cmh.cmsg_type == SCTP_SNDINFO) || |
michael@0 | 3417 | (cmh.cmsg_type == SCTP_PRINFO) || |
michael@0 | 3418 | (cmh.cmsg_type == SCTP_AUTHINFO))))) { |
michael@0 | 3419 | if (c_type == cmh.cmsg_type) { |
michael@0 | 3420 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < cpsize) { |
michael@0 | 3421 | return (found); |
michael@0 | 3422 | } |
michael@0 | 3423 | /* It is exactly what we want. Copy it out. */ |
michael@0 | 3424 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), cpsize, (caddr_t)data); |
michael@0 | 3425 | return (1); |
michael@0 | 3426 | } else { |
michael@0 | 3427 | struct sctp_sndrcvinfo *sndrcvinfo; |
michael@0 | 3428 | |
michael@0 | 3429 | sndrcvinfo = (struct sctp_sndrcvinfo *)data; |
michael@0 | 3430 | if (found == 0) { |
michael@0 | 3431 | if (cpsize < sizeof(struct sctp_sndrcvinfo)) { |
michael@0 | 3432 | return (found); |
michael@0 | 3433 | } |
michael@0 | 3434 | memset(sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo)); |
michael@0 | 3435 | } |
michael@0 | 3436 | switch (cmh.cmsg_type) { |
michael@0 | 3437 | case SCTP_SNDINFO: |
michael@0 | 3438 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct sctp_sndinfo)) { |
michael@0 | 3439 | return (found); |
michael@0 | 3440 | } |
michael@0 | 3441 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct sctp_sndinfo), (caddr_t)&sndinfo); |
michael@0 | 3442 | sndrcvinfo->sinfo_stream = sndinfo.snd_sid; |
michael@0 | 3443 | sndrcvinfo->sinfo_flags = sndinfo.snd_flags; |
michael@0 | 3444 | sndrcvinfo->sinfo_ppid = sndinfo.snd_ppid; |
michael@0 | 3445 | sndrcvinfo->sinfo_context = sndinfo.snd_context; |
michael@0 | 3446 | sndrcvinfo->sinfo_assoc_id = sndinfo.snd_assoc_id; |
michael@0 | 3447 | break; |
michael@0 | 3448 | case SCTP_PRINFO: |
michael@0 | 3449 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct sctp_prinfo)) { |
michael@0 | 3450 | return (found); |
michael@0 | 3451 | } |
michael@0 | 3452 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct sctp_prinfo), (caddr_t)&prinfo); |
michael@0 | 3453 | if (prinfo.pr_policy != SCTP_PR_SCTP_NONE) { |
michael@0 | 3454 | sndrcvinfo->sinfo_timetolive = prinfo.pr_value; |
michael@0 | 3455 | } else { |
michael@0 | 3456 | sndrcvinfo->sinfo_timetolive = 0; |
michael@0 | 3457 | } |
michael@0 | 3458 | sndrcvinfo->sinfo_flags |= prinfo.pr_policy; |
michael@0 | 3459 | break; |
michael@0 | 3460 | case SCTP_AUTHINFO: |
michael@0 | 3461 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct sctp_authinfo)) { |
michael@0 | 3462 | return (found); |
michael@0 | 3463 | } |
michael@0 | 3464 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct sctp_authinfo), (caddr_t)&authinfo); |
michael@0 | 3465 | sndrcvinfo->sinfo_keynumber_valid = 1; |
michael@0 | 3466 | sndrcvinfo->sinfo_keynumber = authinfo.auth_keynumber; |
michael@0 | 3467 | break; |
michael@0 | 3468 | default: |
michael@0 | 3469 | return (found); |
michael@0 | 3470 | } |
michael@0 | 3471 | found = 1; |
michael@0 | 3472 | } |
michael@0 | 3473 | } |
michael@0 | 3474 | at += CMSG_ALIGN(cmh.cmsg_len); |
michael@0 | 3475 | } |
michael@0 | 3476 | return (found); |
michael@0 | 3477 | } |
michael@0 | 3478 | |
michael@0 | 3479 | static int |
michael@0 | 3480 | sctp_process_cmsgs_for_init(struct sctp_tcb *stcb, struct mbuf *control, int *error) |
michael@0 | 3481 | { |
michael@0 | 3482 | #if defined(__Userspace_os_Windows) |
michael@0 | 3483 | WSACMSGHDR cmh; |
michael@0 | 3484 | #else |
michael@0 | 3485 | struct cmsghdr cmh; |
michael@0 | 3486 | #endif |
michael@0 | 3487 | int tlen, at; |
michael@0 | 3488 | struct sctp_initmsg initmsg; |
michael@0 | 3489 | #ifdef INET |
michael@0 | 3490 | struct sockaddr_in sin; |
michael@0 | 3491 | #endif |
michael@0 | 3492 | #ifdef INET6 |
michael@0 | 3493 | struct sockaddr_in6 sin6; |
michael@0 | 3494 | #endif |
michael@0 | 3495 | |
michael@0 | 3496 | tlen = SCTP_BUF_LEN(control); |
michael@0 | 3497 | at = 0; |
michael@0 | 3498 | while (at < tlen) { |
michael@0 | 3499 | if ((tlen - at) < (int)CMSG_ALIGN(sizeof(cmh))) { |
michael@0 | 3500 | /* There is not enough room for one more. */ |
michael@0 | 3501 | *error = EINVAL; |
michael@0 | 3502 | return (1); |
michael@0 | 3503 | } |
michael@0 | 3504 | m_copydata(control, at, sizeof(cmh), (caddr_t)&cmh); |
michael@0 | 3505 | if (cmh.cmsg_len < CMSG_ALIGN(sizeof(cmh))) { |
michael@0 | 3506 | /* We dont't have a complete CMSG header. */ |
michael@0 | 3507 | *error = EINVAL; |
michael@0 | 3508 | return (1); |
michael@0 | 3509 | } |
michael@0 | 3510 | if (((int)cmh.cmsg_len + at) > tlen) { |
michael@0 | 3511 | /* We don't have the complete CMSG. */ |
michael@0 | 3512 | *error = EINVAL; |
michael@0 | 3513 | return (1); |
michael@0 | 3514 | } |
michael@0 | 3515 | if (cmh.cmsg_level == IPPROTO_SCTP) { |
michael@0 | 3516 | switch (cmh.cmsg_type) { |
michael@0 | 3517 | case SCTP_INIT: |
michael@0 | 3518 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct sctp_initmsg)) { |
michael@0 | 3519 | *error = EINVAL; |
michael@0 | 3520 | return (1); |
michael@0 | 3521 | } |
michael@0 | 3522 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct sctp_initmsg), (caddr_t)&initmsg); |
michael@0 | 3523 | if (initmsg.sinit_max_attempts) |
michael@0 | 3524 | stcb->asoc.max_init_times = initmsg.sinit_max_attempts; |
michael@0 | 3525 | if (initmsg.sinit_num_ostreams) |
michael@0 | 3526 | stcb->asoc.pre_open_streams = initmsg.sinit_num_ostreams; |
michael@0 | 3527 | if (initmsg.sinit_max_instreams) |
michael@0 | 3528 | stcb->asoc.max_inbound_streams = initmsg.sinit_max_instreams; |
michael@0 | 3529 | if (initmsg.sinit_max_init_timeo) |
michael@0 | 3530 | stcb->asoc.initial_init_rto_max = initmsg.sinit_max_init_timeo; |
michael@0 | 3531 | if (stcb->asoc.streamoutcnt < stcb->asoc.pre_open_streams) { |
michael@0 | 3532 | struct sctp_stream_out *tmp_str; |
michael@0 | 3533 | unsigned int i; |
michael@0 | 3534 | |
michael@0 | 3535 | /* Default is NOT correct */ |
michael@0 | 3536 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Ok, default:%d pre_open:%d\n", |
michael@0 | 3537 | stcb->asoc.streamoutcnt, stcb->asoc.pre_open_streams); |
michael@0 | 3538 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 3539 | SCTP_MALLOC(tmp_str, |
michael@0 | 3540 | struct sctp_stream_out *, |
michael@0 | 3541 | (stcb->asoc.pre_open_streams * sizeof(struct sctp_stream_out)), |
michael@0 | 3542 | SCTP_M_STRMO); |
michael@0 | 3543 | SCTP_TCB_LOCK(stcb); |
michael@0 | 3544 | if (tmp_str != NULL) { |
michael@0 | 3545 | SCTP_FREE(stcb->asoc.strmout, SCTP_M_STRMO); |
michael@0 | 3546 | stcb->asoc.strmout = tmp_str; |
michael@0 | 3547 | stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt = stcb->asoc.pre_open_streams; |
michael@0 | 3548 | } else { |
michael@0 | 3549 | stcb->asoc.pre_open_streams = stcb->asoc.streamoutcnt; |
michael@0 | 3550 | } |
michael@0 | 3551 | for (i = 0; i < stcb->asoc.streamoutcnt; i++) { |
michael@0 | 3552 | TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); |
michael@0 | 3553 | stcb->asoc.strmout[i].chunks_on_queues = 0; |
michael@0 | 3554 | stcb->asoc.strmout[i].next_sequence_send = 0; |
michael@0 | 3555 | stcb->asoc.strmout[i].stream_no = i; |
michael@0 | 3556 | stcb->asoc.strmout[i].last_msg_incomplete = 0; |
michael@0 | 3557 | stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], NULL); |
michael@0 | 3558 | } |
michael@0 | 3559 | } |
michael@0 | 3560 | break; |
michael@0 | 3561 | #ifdef INET |
michael@0 | 3562 | case SCTP_DSTADDRV4: |
michael@0 | 3563 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct in_addr)) { |
michael@0 | 3564 | *error = EINVAL; |
michael@0 | 3565 | return (1); |
michael@0 | 3566 | } |
michael@0 | 3567 | memset(&sin, 0, sizeof(struct sockaddr_in)); |
michael@0 | 3568 | sin.sin_family = AF_INET; |
michael@0 | 3569 | #ifdef HAVE_SIN_LEN |
michael@0 | 3570 | sin.sin_len = sizeof(struct sockaddr_in); |
michael@0 | 3571 | #endif |
michael@0 | 3572 | sin.sin_port = stcb->rport; |
michael@0 | 3573 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct in_addr), (caddr_t)&sin.sin_addr); |
michael@0 | 3574 | if ((sin.sin_addr.s_addr == INADDR_ANY) || |
michael@0 | 3575 | (sin.sin_addr.s_addr == INADDR_BROADCAST) || |
michael@0 | 3576 | IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) { |
michael@0 | 3577 | *error = EINVAL; |
michael@0 | 3578 | return (1); |
michael@0 | 3579 | } |
michael@0 | 3580 | if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin, NULL, |
michael@0 | 3581 | SCTP_DONOT_SETSCOPE, SCTP_ADDR_IS_CONFIRMED)) { |
michael@0 | 3582 | *error = ENOBUFS; |
michael@0 | 3583 | return (1); |
michael@0 | 3584 | } |
michael@0 | 3585 | break; |
michael@0 | 3586 | #endif |
michael@0 | 3587 | #ifdef INET6 |
michael@0 | 3588 | case SCTP_DSTADDRV6: |
michael@0 | 3589 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct in6_addr)) { |
michael@0 | 3590 | *error = EINVAL; |
michael@0 | 3591 | return (1); |
michael@0 | 3592 | } |
michael@0 | 3593 | memset(&sin6, 0, sizeof(struct sockaddr_in6)); |
michael@0 | 3594 | sin6.sin6_family = AF_INET6; |
michael@0 | 3595 | #ifdef HAVE_SIN6_LEN |
michael@0 | 3596 | sin6.sin6_len = sizeof(struct sockaddr_in6); |
michael@0 | 3597 | #endif |
michael@0 | 3598 | sin6.sin6_port = stcb->rport; |
michael@0 | 3599 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct in6_addr), (caddr_t)&sin6.sin6_addr); |
michael@0 | 3600 | if (IN6_IS_ADDR_UNSPECIFIED(&sin6.sin6_addr) || |
michael@0 | 3601 | IN6_IS_ADDR_MULTICAST(&sin6.sin6_addr)) { |
michael@0 | 3602 | *error = EINVAL; |
michael@0 | 3603 | return (1); |
michael@0 | 3604 | } |
michael@0 | 3605 | #ifdef INET |
michael@0 | 3606 | if (IN6_IS_ADDR_V4MAPPED(&sin6.sin6_addr)) { |
michael@0 | 3607 | in6_sin6_2_sin(&sin, &sin6); |
michael@0 | 3608 | if ((sin.sin_addr.s_addr == INADDR_ANY) || |
michael@0 | 3609 | (sin.sin_addr.s_addr == INADDR_BROADCAST) || |
michael@0 | 3610 | IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) { |
michael@0 | 3611 | *error = EINVAL; |
michael@0 | 3612 | return (1); |
michael@0 | 3613 | } |
michael@0 | 3614 | if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin, NULL, |
michael@0 | 3615 | SCTP_DONOT_SETSCOPE, SCTP_ADDR_IS_CONFIRMED)) { |
michael@0 | 3616 | *error = ENOBUFS; |
michael@0 | 3617 | return (1); |
michael@0 | 3618 | } |
michael@0 | 3619 | } else |
michael@0 | 3620 | #endif |
michael@0 | 3621 | if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin6, NULL, |
michael@0 | 3622 | SCTP_DONOT_SETSCOPE, SCTP_ADDR_IS_CONFIRMED)) { |
michael@0 | 3623 | *error = ENOBUFS; |
michael@0 | 3624 | return (1); |
michael@0 | 3625 | } |
michael@0 | 3626 | break; |
michael@0 | 3627 | #endif |
michael@0 | 3628 | default: |
michael@0 | 3629 | break; |
michael@0 | 3630 | } |
michael@0 | 3631 | } |
michael@0 | 3632 | at += CMSG_ALIGN(cmh.cmsg_len); |
michael@0 | 3633 | } |
michael@0 | 3634 | return (0); |
michael@0 | 3635 | } |
michael@0 | 3636 | |
michael@0 | 3637 | static struct sctp_tcb * |
michael@0 | 3638 | sctp_findassociation_cmsgs(struct sctp_inpcb **inp_p, |
michael@0 | 3639 | uint16_t port, |
michael@0 | 3640 | struct mbuf *control, |
michael@0 | 3641 | struct sctp_nets **net_p, |
michael@0 | 3642 | int *error) |
michael@0 | 3643 | { |
michael@0 | 3644 | #if defined(__Userspace_os_Windows) |
michael@0 | 3645 | WSACMSGHDR cmh; |
michael@0 | 3646 | #else |
michael@0 | 3647 | struct cmsghdr cmh; |
michael@0 | 3648 | #endif |
michael@0 | 3649 | int tlen, at; |
michael@0 | 3650 | struct sctp_tcb *stcb; |
michael@0 | 3651 | struct sockaddr *addr; |
michael@0 | 3652 | #ifdef INET |
michael@0 | 3653 | struct sockaddr_in sin; |
michael@0 | 3654 | #endif |
michael@0 | 3655 | #ifdef INET6 |
michael@0 | 3656 | struct sockaddr_in6 sin6; |
michael@0 | 3657 | #endif |
michael@0 | 3658 | |
michael@0 | 3659 | tlen = SCTP_BUF_LEN(control); |
michael@0 | 3660 | at = 0; |
michael@0 | 3661 | while (at < tlen) { |
michael@0 | 3662 | if ((tlen - at) < (int)CMSG_ALIGN(sizeof(cmh))) { |
michael@0 | 3663 | /* There is not enough room for one more. */ |
michael@0 | 3664 | *error = EINVAL; |
michael@0 | 3665 | return (NULL); |
michael@0 | 3666 | } |
michael@0 | 3667 | m_copydata(control, at, sizeof(cmh), (caddr_t)&cmh); |
michael@0 | 3668 | if (cmh.cmsg_len < CMSG_ALIGN(sizeof(cmh))) { |
michael@0 | 3669 | /* We dont't have a complete CMSG header. */ |
michael@0 | 3670 | *error = EINVAL; |
michael@0 | 3671 | return (NULL); |
michael@0 | 3672 | } |
michael@0 | 3673 | if (((int)cmh.cmsg_len + at) > tlen) { |
michael@0 | 3674 | /* We don't have the complete CMSG. */ |
michael@0 | 3675 | *error = EINVAL; |
michael@0 | 3676 | return (NULL); |
michael@0 | 3677 | } |
michael@0 | 3678 | if (cmh.cmsg_level == IPPROTO_SCTP) { |
michael@0 | 3679 | switch (cmh.cmsg_type) { |
michael@0 | 3680 | #ifdef INET |
michael@0 | 3681 | case SCTP_DSTADDRV4: |
michael@0 | 3682 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct in_addr)) { |
michael@0 | 3683 | *error = EINVAL; |
michael@0 | 3684 | return (NULL); |
michael@0 | 3685 | } |
michael@0 | 3686 | memset(&sin, 0, sizeof(struct sockaddr_in)); |
michael@0 | 3687 | sin.sin_family = AF_INET; |
michael@0 | 3688 | #ifdef HAVE_SIN_LEN |
michael@0 | 3689 | sin.sin_len = sizeof(struct sockaddr_in); |
michael@0 | 3690 | #endif |
michael@0 | 3691 | sin.sin_port = port; |
michael@0 | 3692 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct in_addr), (caddr_t)&sin.sin_addr); |
michael@0 | 3693 | addr = (struct sockaddr *)&sin; |
michael@0 | 3694 | break; |
michael@0 | 3695 | #endif |
michael@0 | 3696 | #ifdef INET6 |
michael@0 | 3697 | case SCTP_DSTADDRV6: |
michael@0 | 3698 | if ((size_t)(cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh))) < sizeof(struct in6_addr)) { |
michael@0 | 3699 | *error = EINVAL; |
michael@0 | 3700 | return (NULL); |
michael@0 | 3701 | } |
michael@0 | 3702 | memset(&sin6, 0, sizeof(struct sockaddr_in6)); |
michael@0 | 3703 | sin6.sin6_family = AF_INET6; |
michael@0 | 3704 | #ifdef HAVE_SIN6_LEN |
michael@0 | 3705 | sin6.sin6_len = sizeof(struct sockaddr_in6); |
michael@0 | 3706 | #endif |
michael@0 | 3707 | sin6.sin6_port = port; |
michael@0 | 3708 | m_copydata(control, at + CMSG_ALIGN(sizeof(cmh)), sizeof(struct in6_addr), (caddr_t)&sin6.sin6_addr); |
michael@0 | 3709 | #ifdef INET |
michael@0 | 3710 | if (IN6_IS_ADDR_V4MAPPED(&sin6.sin6_addr)) { |
michael@0 | 3711 | in6_sin6_2_sin(&sin, &sin6); |
michael@0 | 3712 | addr = (struct sockaddr *)&sin; |
michael@0 | 3713 | } else |
michael@0 | 3714 | #endif |
michael@0 | 3715 | addr = (struct sockaddr *)&sin6; |
michael@0 | 3716 | break; |
michael@0 | 3717 | #endif |
michael@0 | 3718 | default: |
michael@0 | 3719 | addr = NULL; |
michael@0 | 3720 | break; |
michael@0 | 3721 | } |
michael@0 | 3722 | if (addr) { |
michael@0 | 3723 | stcb = sctp_findassociation_ep_addr(inp_p, addr, net_p, NULL, NULL); |
michael@0 | 3724 | if (stcb != NULL) { |
michael@0 | 3725 | return (stcb); |
michael@0 | 3726 | } |
michael@0 | 3727 | } |
michael@0 | 3728 | } |
michael@0 | 3729 | at += CMSG_ALIGN(cmh.cmsg_len); |
michael@0 | 3730 | } |
michael@0 | 3731 | return (NULL); |
michael@0 | 3732 | } |
michael@0 | 3733 | |
michael@0 | 3734 | static struct mbuf * |
michael@0 | 3735 | sctp_add_cookie(struct mbuf *init, int init_offset, |
michael@0 | 3736 | struct mbuf *initack, int initack_offset, struct sctp_state_cookie *stc_in, uint8_t **signature) |
michael@0 | 3737 | { |
michael@0 | 3738 | struct mbuf *copy_init, *copy_initack, *m_at, *sig, *mret; |
michael@0 | 3739 | struct sctp_state_cookie *stc; |
michael@0 | 3740 | struct sctp_paramhdr *ph; |
michael@0 | 3741 | uint8_t *foo; |
michael@0 | 3742 | int sig_offset; |
michael@0 | 3743 | uint16_t cookie_sz; |
michael@0 | 3744 | |
michael@0 | 3745 | mret = sctp_get_mbuf_for_msg((sizeof(struct sctp_state_cookie) + |
michael@0 | 3746 | sizeof(struct sctp_paramhdr)), 0, |
michael@0 | 3747 | M_NOWAIT, 1, MT_DATA); |
michael@0 | 3748 | if (mret == NULL) { |
michael@0 | 3749 | return (NULL); |
michael@0 | 3750 | } |
michael@0 | 3751 | copy_init = SCTP_M_COPYM(init, init_offset, M_COPYALL, M_NOWAIT); |
michael@0 | 3752 | if (copy_init == NULL) { |
michael@0 | 3753 | sctp_m_freem(mret); |
michael@0 | 3754 | return (NULL); |
michael@0 | 3755 | } |
michael@0 | 3756 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 3757 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 3758 | struct mbuf *mat; |
michael@0 | 3759 | |
michael@0 | 3760 | for (mat = copy_init; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 3761 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 3762 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 3763 | } |
michael@0 | 3764 | } |
michael@0 | 3765 | } |
michael@0 | 3766 | #endif |
michael@0 | 3767 | copy_initack = SCTP_M_COPYM(initack, initack_offset, M_COPYALL, |
michael@0 | 3768 | M_NOWAIT); |
michael@0 | 3769 | if (copy_initack == NULL) { |
michael@0 | 3770 | sctp_m_freem(mret); |
michael@0 | 3771 | sctp_m_freem(copy_init); |
michael@0 | 3772 | return (NULL); |
michael@0 | 3773 | } |
michael@0 | 3774 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 3775 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 3776 | struct mbuf *mat; |
michael@0 | 3777 | |
michael@0 | 3778 | for (mat = copy_initack; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 3779 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 3780 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 3781 | } |
michael@0 | 3782 | } |
michael@0 | 3783 | } |
michael@0 | 3784 | #endif |
michael@0 | 3785 | /* easy side we just drop it on the end */ |
michael@0 | 3786 | ph = mtod(mret, struct sctp_paramhdr *); |
michael@0 | 3787 | SCTP_BUF_LEN(mret) = sizeof(struct sctp_state_cookie) + |
michael@0 | 3788 | sizeof(struct sctp_paramhdr); |
michael@0 | 3789 | stc = (struct sctp_state_cookie *)((caddr_t)ph + |
michael@0 | 3790 | sizeof(struct sctp_paramhdr)); |
michael@0 | 3791 | ph->param_type = htons(SCTP_STATE_COOKIE); |
michael@0 | 3792 | ph->param_length = 0; /* fill in at the end */ |
michael@0 | 3793 | /* Fill in the stc cookie data */ |
michael@0 | 3794 | memcpy(stc, stc_in, sizeof(struct sctp_state_cookie)); |
michael@0 | 3795 | |
michael@0 | 3796 | /* tack the INIT and then the INIT-ACK onto the chain */ |
michael@0 | 3797 | cookie_sz = 0; |
michael@0 | 3798 | for (m_at = mret; m_at; m_at = SCTP_BUF_NEXT(m_at)) { |
michael@0 | 3799 | cookie_sz += SCTP_BUF_LEN(m_at); |
michael@0 | 3800 | if (SCTP_BUF_NEXT(m_at) == NULL) { |
michael@0 | 3801 | SCTP_BUF_NEXT(m_at) = copy_init; |
michael@0 | 3802 | break; |
michael@0 | 3803 | } |
michael@0 | 3804 | } |
michael@0 | 3805 | for (m_at = copy_init; m_at; m_at = SCTP_BUF_NEXT(m_at)) { |
michael@0 | 3806 | cookie_sz += SCTP_BUF_LEN(m_at); |
michael@0 | 3807 | if (SCTP_BUF_NEXT(m_at) == NULL) { |
michael@0 | 3808 | SCTP_BUF_NEXT(m_at) = copy_initack; |
michael@0 | 3809 | break; |
michael@0 | 3810 | } |
michael@0 | 3811 | } |
michael@0 | 3812 | for (m_at = copy_initack; m_at; m_at = SCTP_BUF_NEXT(m_at)) { |
michael@0 | 3813 | cookie_sz += SCTP_BUF_LEN(m_at); |
michael@0 | 3814 | if (SCTP_BUF_NEXT(m_at) == NULL) { |
michael@0 | 3815 | break; |
michael@0 | 3816 | } |
michael@0 | 3817 | } |
michael@0 | 3818 | sig = sctp_get_mbuf_for_msg(SCTP_SECRET_SIZE, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 3819 | if (sig == NULL) { |
michael@0 | 3820 | /* no space, so free the entire chain */ |
michael@0 | 3821 | sctp_m_freem(mret); |
michael@0 | 3822 | return (NULL); |
michael@0 | 3823 | } |
michael@0 | 3824 | SCTP_BUF_LEN(sig) = 0; |
michael@0 | 3825 | SCTP_BUF_NEXT(m_at) = sig; |
michael@0 | 3826 | sig_offset = 0; |
michael@0 | 3827 | foo = (uint8_t *) (mtod(sig, caddr_t) + sig_offset); |
michael@0 | 3828 | memset(foo, 0, SCTP_SIGNATURE_SIZE); |
michael@0 | 3829 | *signature = foo; |
michael@0 | 3830 | SCTP_BUF_LEN(sig) += SCTP_SIGNATURE_SIZE; |
michael@0 | 3831 | cookie_sz += SCTP_SIGNATURE_SIZE; |
michael@0 | 3832 | ph->param_length = htons(cookie_sz); |
michael@0 | 3833 | return (mret); |
michael@0 | 3834 | } |
michael@0 | 3835 | |
michael@0 | 3836 | |
michael@0 | 3837 | static uint8_t |
michael@0 | 3838 | sctp_get_ect(struct sctp_tcb *stcb) |
michael@0 | 3839 | { |
michael@0 | 3840 | if ((stcb != NULL) && (stcb->asoc.ecn_allowed == 1)) { |
michael@0 | 3841 | return (SCTP_ECT0_BIT); |
michael@0 | 3842 | } else { |
michael@0 | 3843 | return (0); |
michael@0 | 3844 | } |
michael@0 | 3845 | } |
michael@0 | 3846 | |
michael@0 | 3847 | #if defined(INET) || defined(INET6) |
michael@0 | 3848 | static void |
michael@0 | 3849 | sctp_handle_no_route(struct sctp_tcb *stcb, |
michael@0 | 3850 | struct sctp_nets *net, |
michael@0 | 3851 | int so_locked) |
michael@0 | 3852 | { |
michael@0 | 3853 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "dropped packet - no valid source addr\n"); |
michael@0 | 3854 | |
michael@0 | 3855 | if (net) { |
michael@0 | 3856 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Destination was "); |
michael@0 | 3857 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT1, &net->ro._l_addr.sa); |
michael@0 | 3858 | if (net->dest_state & SCTP_ADDR_CONFIRMED) { |
michael@0 | 3859 | if ((net->dest_state & SCTP_ADDR_REACHABLE) && stcb) { |
michael@0 | 3860 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "no route takes interface %p down\n", (void *)net); |
michael@0 | 3861 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, |
michael@0 | 3862 | stcb, 0, |
michael@0 | 3863 | (void *)net, |
michael@0 | 3864 | so_locked); |
michael@0 | 3865 | net->dest_state &= ~SCTP_ADDR_REACHABLE; |
michael@0 | 3866 | net->dest_state &= ~SCTP_ADDR_PF; |
michael@0 | 3867 | } |
michael@0 | 3868 | } |
michael@0 | 3869 | if (stcb) { |
michael@0 | 3870 | if (net == stcb->asoc.primary_destination) { |
michael@0 | 3871 | /* need a new primary */ |
michael@0 | 3872 | struct sctp_nets *alt; |
michael@0 | 3873 | |
michael@0 | 3874 | alt = sctp_find_alternate_net(stcb, net, 0); |
michael@0 | 3875 | if (alt != net) { |
michael@0 | 3876 | if (stcb->asoc.alternate) { |
michael@0 | 3877 | sctp_free_remote_addr(stcb->asoc.alternate); |
michael@0 | 3878 | } |
michael@0 | 3879 | stcb->asoc.alternate = alt; |
michael@0 | 3880 | atomic_add_int(&stcb->asoc.alternate->ref_count, 1); |
michael@0 | 3881 | if (net->ro._s_addr) { |
michael@0 | 3882 | sctp_free_ifa(net->ro._s_addr); |
michael@0 | 3883 | net->ro._s_addr = NULL; |
michael@0 | 3884 | } |
michael@0 | 3885 | net->src_addr_selected = 0; |
michael@0 | 3886 | } |
michael@0 | 3887 | } |
michael@0 | 3888 | } |
michael@0 | 3889 | } |
michael@0 | 3890 | } |
michael@0 | 3891 | #endif |
michael@0 | 3892 | |
michael@0 | 3893 | static int |
michael@0 | 3894 | sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, |
michael@0 | 3895 | struct sctp_tcb *stcb, /* may be NULL */ |
michael@0 | 3896 | struct sctp_nets *net, |
michael@0 | 3897 | struct sockaddr *to, |
michael@0 | 3898 | struct mbuf *m, |
michael@0 | 3899 | uint32_t auth_offset, |
michael@0 | 3900 | struct sctp_auth_chunk *auth, |
michael@0 | 3901 | uint16_t auth_keyid, |
michael@0 | 3902 | int nofragment_flag, |
michael@0 | 3903 | int ecn_ok, |
michael@0 | 3904 | int out_of_asoc_ok, |
michael@0 | 3905 | uint16_t src_port, |
michael@0 | 3906 | uint16_t dest_port, |
michael@0 | 3907 | uint32_t v_tag, |
michael@0 | 3908 | uint16_t port, |
michael@0 | 3909 | union sctp_sockstore *over_addr, |
michael@0 | 3910 | #if defined(__FreeBSD__) |
michael@0 | 3911 | uint8_t use_mflowid, uint32_t mflowid, |
michael@0 | 3912 | #endif |
michael@0 | 3913 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 3914 | int so_locked SCTP_UNUSED |
michael@0 | 3915 | #else |
michael@0 | 3916 | int so_locked |
michael@0 | 3917 | #endif |
michael@0 | 3918 | ) |
michael@0 | 3919 | /* nofragment_flag to tell if IP_DF should be set (IPv4 only) */ |
michael@0 | 3920 | { |
michael@0 | 3921 | /** |
michael@0 | 3922 | * Given a mbuf chain (via SCTP_BUF_NEXT()) that holds a packet header |
michael@0 | 3923 | * WITH an SCTPHDR but no IP header, endpoint inp and sa structure: |
michael@0 | 3924 | * - fill in the HMAC digest of any AUTH chunk in the packet. |
michael@0 | 3925 | * - calculate and fill in the SCTP checksum. |
michael@0 | 3926 | * - prepend an IP address header. |
michael@0 | 3927 | * - if boundall use INADDR_ANY. |
michael@0 | 3928 | * - if boundspecific do source address selection. |
michael@0 | 3929 | * - set fragmentation option for ipV4. |
michael@0 | 3930 | * - On return from IP output, check/adjust mtu size of output |
michael@0 | 3931 | * interface and smallest_mtu size as well. |
michael@0 | 3932 | */ |
michael@0 | 3933 | /* Will need ifdefs around this */ |
michael@0 | 3934 | #ifdef __Panda__ |
michael@0 | 3935 | pakhandle_type o_pak; |
michael@0 | 3936 | #endif |
michael@0 | 3937 | struct mbuf *newm; |
michael@0 | 3938 | struct sctphdr *sctphdr; |
michael@0 | 3939 | int packet_length; |
michael@0 | 3940 | int ret; |
michael@0 | 3941 | #if defined(INET) || defined(INET6) |
michael@0 | 3942 | uint32_t vrf_id; |
michael@0 | 3943 | #endif |
michael@0 | 3944 | #if defined(INET) || defined(INET6) |
michael@0 | 3945 | #if !defined(__Panda__) |
michael@0 | 3946 | struct mbuf *o_pak; |
michael@0 | 3947 | #endif |
michael@0 | 3948 | sctp_route_t *ro = NULL; |
michael@0 | 3949 | struct udphdr *udp = NULL; |
michael@0 | 3950 | #endif |
michael@0 | 3951 | uint8_t tos_value; |
michael@0 | 3952 | #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 3953 | struct socket *so = NULL; |
michael@0 | 3954 | #endif |
michael@0 | 3955 | |
michael@0 | 3956 | #if defined(__APPLE__) |
michael@0 | 3957 | if (so_locked) { |
michael@0 | 3958 | sctp_lock_assert(SCTP_INP_SO(inp)); |
michael@0 | 3959 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 3960 | } else { |
michael@0 | 3961 | sctp_unlock_assert(SCTP_INP_SO(inp)); |
michael@0 | 3962 | } |
michael@0 | 3963 | #endif |
michael@0 | 3964 | if ((net) && (net->dest_state & SCTP_ADDR_OUT_OF_SCOPE)) { |
michael@0 | 3965 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EFAULT); |
michael@0 | 3966 | sctp_m_freem(m); |
michael@0 | 3967 | return (EFAULT); |
michael@0 | 3968 | } |
michael@0 | 3969 | #if defined(INET) || defined(INET6) |
michael@0 | 3970 | if (stcb) { |
michael@0 | 3971 | vrf_id = stcb->asoc.vrf_id; |
michael@0 | 3972 | } else { |
michael@0 | 3973 | vrf_id = inp->def_vrf_id; |
michael@0 | 3974 | } |
michael@0 | 3975 | #endif |
michael@0 | 3976 | /* fill in the HMAC digest for any AUTH chunk in the packet */ |
michael@0 | 3977 | if ((auth != NULL) && (stcb != NULL)) { |
michael@0 | 3978 | sctp_fill_hmac_digest_m(m, auth_offset, auth, stcb, auth_keyid); |
michael@0 | 3979 | } |
michael@0 | 3980 | |
michael@0 | 3981 | if (net) { |
michael@0 | 3982 | tos_value = net->dscp; |
michael@0 | 3983 | } else if (stcb) { |
michael@0 | 3984 | tos_value = stcb->asoc.default_dscp; |
michael@0 | 3985 | } else { |
michael@0 | 3986 | tos_value = inp->sctp_ep.default_dscp; |
michael@0 | 3987 | } |
michael@0 | 3988 | |
michael@0 | 3989 | switch (to->sa_family) { |
michael@0 | 3990 | #ifdef INET |
michael@0 | 3991 | case AF_INET: |
michael@0 | 3992 | { |
michael@0 | 3993 | struct ip *ip = NULL; |
michael@0 | 3994 | sctp_route_t iproute; |
michael@0 | 3995 | int len; |
michael@0 | 3996 | |
michael@0 | 3997 | len = sizeof(struct ip) + sizeof(struct sctphdr); |
michael@0 | 3998 | if (port) { |
michael@0 | 3999 | len += sizeof(struct udphdr); |
michael@0 | 4000 | } |
michael@0 | 4001 | newm = sctp_get_mbuf_for_msg(len, 1, M_NOWAIT, 1, MT_DATA); |
michael@0 | 4002 | if (newm == NULL) { |
michael@0 | 4003 | sctp_m_freem(m); |
michael@0 | 4004 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 4005 | return (ENOMEM); |
michael@0 | 4006 | } |
michael@0 | 4007 | SCTP_ALIGN_TO_END(newm, len); |
michael@0 | 4008 | SCTP_BUF_LEN(newm) = len; |
michael@0 | 4009 | SCTP_BUF_NEXT(newm) = m; |
michael@0 | 4010 | m = newm; |
michael@0 | 4011 | #if defined(__FreeBSD__) |
michael@0 | 4012 | if (net != NULL) { |
michael@0 | 4013 | #ifdef INVARIANTS |
michael@0 | 4014 | if (net->flowidset == 0) { |
michael@0 | 4015 | panic("Flow ID not set"); |
michael@0 | 4016 | } |
michael@0 | 4017 | #endif |
michael@0 | 4018 | m->m_pkthdr.flowid = net->flowid; |
michael@0 | 4019 | m->m_flags |= M_FLOWID; |
michael@0 | 4020 | } else { |
michael@0 | 4021 | if (use_mflowid != 0) { |
michael@0 | 4022 | m->m_pkthdr.flowid = mflowid; |
michael@0 | 4023 | m->m_flags |= M_FLOWID; |
michael@0 | 4024 | } |
michael@0 | 4025 | } |
michael@0 | 4026 | #endif |
michael@0 | 4027 | packet_length = sctp_calculate_len(m); |
michael@0 | 4028 | ip = mtod(m, struct ip *); |
michael@0 | 4029 | ip->ip_v = IPVERSION; |
michael@0 | 4030 | ip->ip_hl = (sizeof(struct ip) >> 2); |
michael@0 | 4031 | if (tos_value == 0) { |
michael@0 | 4032 | /* |
michael@0 | 4033 | * This means especially, that it is not set at the |
michael@0 | 4034 | * SCTP layer. So use the value from the IP layer. |
michael@0 | 4035 | */ |
michael@0 | 4036 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Panda__) || defined(__Windows__) || defined(__Userspace__) |
michael@0 | 4037 | tos_value = inp->ip_inp.inp.inp_ip_tos; |
michael@0 | 4038 | #else |
michael@0 | 4039 | tos_value = inp->inp_ip_tos; |
michael@0 | 4040 | #endif |
michael@0 | 4041 | } |
michael@0 | 4042 | tos_value &= 0xfc; |
michael@0 | 4043 | if (ecn_ok) { |
michael@0 | 4044 | tos_value |= sctp_get_ect(stcb); |
michael@0 | 4045 | } |
michael@0 | 4046 | if ((nofragment_flag) && (port == 0)) { |
michael@0 | 4047 | #if defined(__FreeBSD__) |
michael@0 | 4048 | #if __FreeBSD_version >= 1000000 |
michael@0 | 4049 | ip->ip_off = htons(IP_DF); |
michael@0 | 4050 | #else |
michael@0 | 4051 | ip->ip_off = IP_DF; |
michael@0 | 4052 | #endif |
michael@0 | 4053 | #elif defined(WITH_CONVERT_IP_OFF) || defined(__APPLE__) || defined(__Userspace__) |
michael@0 | 4054 | ip->ip_off = IP_DF; |
michael@0 | 4055 | #else |
michael@0 | 4056 | ip->ip_off = htons(IP_DF); |
michael@0 | 4057 | #endif |
michael@0 | 4058 | } else { |
michael@0 | 4059 | #if defined(__FreeBSD__) && __FreeBSD_version >= 1000000 |
michael@0 | 4060 | ip->ip_off = htons(0); |
michael@0 | 4061 | #else |
michael@0 | 4062 | ip->ip_off = 0; |
michael@0 | 4063 | #endif |
michael@0 | 4064 | } |
michael@0 | 4065 | #if defined(__FreeBSD__) |
michael@0 | 4066 | /* FreeBSD has a function for ip_id's */ |
michael@0 | 4067 | ip->ip_id = ip_newid(); |
michael@0 | 4068 | #elif defined(RANDOM_IP_ID) |
michael@0 | 4069 | /* Apple has RANDOM_IP_ID switch */ |
michael@0 | 4070 | ip->ip_id = htons(ip_randomid()); |
michael@0 | 4071 | #elif defined(__Userspace__) |
michael@0 | 4072 | ip->ip_id = htons(SCTP_IP_ID(inp)++); |
michael@0 | 4073 | #else |
michael@0 | 4074 | ip->ip_id = SCTP_IP_ID(inp)++; |
michael@0 | 4075 | #endif |
michael@0 | 4076 | |
michael@0 | 4077 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Panda__) || defined(__Windows__) || defined(__Userspace__) |
michael@0 | 4078 | ip->ip_ttl = inp->ip_inp.inp.inp_ip_ttl; |
michael@0 | 4079 | #else |
michael@0 | 4080 | ip->ip_ttl = inp->inp_ip_ttl; |
michael@0 | 4081 | #endif |
michael@0 | 4082 | #if defined(__FreeBSD__) && __FreeBSD_version >= 1000000 |
michael@0 | 4083 | ip->ip_len = htons(packet_length); |
michael@0 | 4084 | #else |
michael@0 | 4085 | ip->ip_len = packet_length; |
michael@0 | 4086 | #endif |
michael@0 | 4087 | ip->ip_tos = tos_value; |
michael@0 | 4088 | if (port) { |
michael@0 | 4089 | ip->ip_p = IPPROTO_UDP; |
michael@0 | 4090 | } else { |
michael@0 | 4091 | ip->ip_p = IPPROTO_SCTP; |
michael@0 | 4092 | } |
michael@0 | 4093 | ip->ip_sum = 0; |
michael@0 | 4094 | if (net == NULL) { |
michael@0 | 4095 | ro = &iproute; |
michael@0 | 4096 | memset(&iproute, 0, sizeof(iproute)); |
michael@0 | 4097 | #ifdef HAVE_SA_LEN |
michael@0 | 4098 | memcpy(&ro->ro_dst, to, to->sa_len); |
michael@0 | 4099 | #else |
michael@0 | 4100 | memcpy(&ro->ro_dst, to, sizeof(struct sockaddr_in)); |
michael@0 | 4101 | #endif |
michael@0 | 4102 | } else { |
michael@0 | 4103 | ro = (sctp_route_t *)&net->ro; |
michael@0 | 4104 | } |
michael@0 | 4105 | /* Now the address selection part */ |
michael@0 | 4106 | ip->ip_dst.s_addr = ((struct sockaddr_in *)to)->sin_addr.s_addr; |
michael@0 | 4107 | |
michael@0 | 4108 | /* call the routine to select the src address */ |
michael@0 | 4109 | if (net && out_of_asoc_ok == 0) { |
michael@0 | 4110 | if (net->ro._s_addr && (net->ro._s_addr->localifa_flags & (SCTP_BEING_DELETED|SCTP_ADDR_IFA_UNUSEABLE))) { |
michael@0 | 4111 | sctp_free_ifa(net->ro._s_addr); |
michael@0 | 4112 | net->ro._s_addr = NULL; |
michael@0 | 4113 | net->src_addr_selected = 0; |
michael@0 | 4114 | if (ro->ro_rt) { |
michael@0 | 4115 | RTFREE(ro->ro_rt); |
michael@0 | 4116 | ro->ro_rt = NULL; |
michael@0 | 4117 | } |
michael@0 | 4118 | } |
michael@0 | 4119 | if (net->src_addr_selected == 0) { |
michael@0 | 4120 | /* Cache the source address */ |
michael@0 | 4121 | net->ro._s_addr = sctp_source_address_selection(inp,stcb, |
michael@0 | 4122 | ro, net, 0, |
michael@0 | 4123 | vrf_id); |
michael@0 | 4124 | net->src_addr_selected = 1; |
michael@0 | 4125 | } |
michael@0 | 4126 | if (net->ro._s_addr == NULL) { |
michael@0 | 4127 | /* No route to host */ |
michael@0 | 4128 | net->src_addr_selected = 0; |
michael@0 | 4129 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4130 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4131 | sctp_m_freem(m); |
michael@0 | 4132 | return (EHOSTUNREACH); |
michael@0 | 4133 | } |
michael@0 | 4134 | ip->ip_src = net->ro._s_addr->address.sin.sin_addr; |
michael@0 | 4135 | } else { |
michael@0 | 4136 | if (over_addr == NULL) { |
michael@0 | 4137 | struct sctp_ifa *_lsrc; |
michael@0 | 4138 | |
michael@0 | 4139 | _lsrc = sctp_source_address_selection(inp, stcb, ro, |
michael@0 | 4140 | net, |
michael@0 | 4141 | out_of_asoc_ok, |
michael@0 | 4142 | vrf_id); |
michael@0 | 4143 | if (_lsrc == NULL) { |
michael@0 | 4144 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4145 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4146 | sctp_m_freem(m); |
michael@0 | 4147 | return (EHOSTUNREACH); |
michael@0 | 4148 | } |
michael@0 | 4149 | ip->ip_src = _lsrc->address.sin.sin_addr; |
michael@0 | 4150 | sctp_free_ifa(_lsrc); |
michael@0 | 4151 | } else { |
michael@0 | 4152 | ip->ip_src = over_addr->sin.sin_addr; |
michael@0 | 4153 | SCTP_RTALLOC(ro, vrf_id); |
michael@0 | 4154 | } |
michael@0 | 4155 | } |
michael@0 | 4156 | if (port) { |
michael@0 | 4157 | if (htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)) == 0) { |
michael@0 | 4158 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4159 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4160 | sctp_m_freem(m); |
michael@0 | 4161 | return (EHOSTUNREACH); |
michael@0 | 4162 | } |
michael@0 | 4163 | udp = (struct udphdr *)((caddr_t)ip + sizeof(struct ip)); |
michael@0 | 4164 | udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); |
michael@0 | 4165 | udp->uh_dport = port; |
michael@0 | 4166 | udp->uh_ulen = htons(packet_length - sizeof(struct ip)); |
michael@0 | 4167 | #if !defined(__Windows__) && !defined(__Userspace__) |
michael@0 | 4168 | #if defined(__FreeBSD__) && ((__FreeBSD_version > 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000) |
michael@0 | 4169 | if (V_udp_cksum) { |
michael@0 | 4170 | udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP)); |
michael@0 | 4171 | } else { |
michael@0 | 4172 | udp->uh_sum = 0; |
michael@0 | 4173 | } |
michael@0 | 4174 | #else |
michael@0 | 4175 | udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP)); |
michael@0 | 4176 | #endif |
michael@0 | 4177 | #else |
michael@0 | 4178 | udp->uh_sum = 0; |
michael@0 | 4179 | #endif |
michael@0 | 4180 | sctphdr = (struct sctphdr *)((caddr_t)udp + sizeof(struct udphdr)); |
michael@0 | 4181 | } else { |
michael@0 | 4182 | sctphdr = (struct sctphdr *)((caddr_t)ip + sizeof(struct ip)); |
michael@0 | 4183 | } |
michael@0 | 4184 | |
michael@0 | 4185 | sctphdr->src_port = src_port; |
michael@0 | 4186 | sctphdr->dest_port = dest_port; |
michael@0 | 4187 | sctphdr->v_tag = v_tag; |
michael@0 | 4188 | sctphdr->checksum = 0; |
michael@0 | 4189 | |
michael@0 | 4190 | /* |
michael@0 | 4191 | * If source address selection fails and we find no route |
michael@0 | 4192 | * then the ip_output should fail as well with a |
michael@0 | 4193 | * NO_ROUTE_TO_HOST type error. We probably should catch |
michael@0 | 4194 | * that somewhere and abort the association right away |
michael@0 | 4195 | * (assuming this is an INIT being sent). |
michael@0 | 4196 | */ |
michael@0 | 4197 | if (ro->ro_rt == NULL) { |
michael@0 | 4198 | /* |
michael@0 | 4199 | * src addr selection failed to find a route (or |
michael@0 | 4200 | * valid source addr), so we can't get there from |
michael@0 | 4201 | * here (yet)! |
michael@0 | 4202 | */ |
michael@0 | 4203 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4204 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4205 | sctp_m_freem(m); |
michael@0 | 4206 | return (EHOSTUNREACH); |
michael@0 | 4207 | } |
michael@0 | 4208 | if (ro != &iproute) { |
michael@0 | 4209 | memcpy(&iproute, ro, sizeof(*ro)); |
michael@0 | 4210 | } |
michael@0 | 4211 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "Calling ipv4 output routine from low level src addr:%x\n", |
michael@0 | 4212 | (uint32_t) (ntohl(ip->ip_src.s_addr))); |
michael@0 | 4213 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "Destination is %x\n", |
michael@0 | 4214 | (uint32_t)(ntohl(ip->ip_dst.s_addr))); |
michael@0 | 4215 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "RTP route is %p through\n", |
michael@0 | 4216 | (void *)ro->ro_rt); |
michael@0 | 4217 | |
michael@0 | 4218 | if (SCTP_GET_HEADER_FOR_OUTPUT(o_pak)) { |
michael@0 | 4219 | /* failed to prepend data, give up */ |
michael@0 | 4220 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 4221 | sctp_m_freem(m); |
michael@0 | 4222 | return (ENOMEM); |
michael@0 | 4223 | } |
michael@0 | 4224 | SCTP_ATTACH_CHAIN(o_pak, m, packet_length); |
michael@0 | 4225 | if (port) { |
michael@0 | 4226 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 4227 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 4228 | #else |
michael@0 | 4229 | sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip) + sizeof(struct udphdr)); |
michael@0 | 4230 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 4231 | #endif |
michael@0 | 4232 | #if defined(__FreeBSD__) && ((__FreeBSD_version > 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000) |
michael@0 | 4233 | if (V_udp_cksum) { |
michael@0 | 4234 | SCTP_ENABLE_UDP_CSUM(o_pak); |
michael@0 | 4235 | } |
michael@0 | 4236 | #else |
michael@0 | 4237 | SCTP_ENABLE_UDP_CSUM(o_pak); |
michael@0 | 4238 | #endif |
michael@0 | 4239 | } else { |
michael@0 | 4240 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 4241 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 4242 | #else |
michael@0 | 4243 | #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 |
michael@0 | 4244 | m->m_pkthdr.csum_flags = CSUM_SCTP; |
michael@0 | 4245 | m->m_pkthdr.csum_data = 0; |
michael@0 | 4246 | SCTP_STAT_INCR(sctps_sendhwcrc); |
michael@0 | 4247 | #else |
michael@0 | 4248 | if (!(SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) && |
michael@0 | 4249 | (stcb) && (stcb->asoc.scope.loopback_scope))) { |
michael@0 | 4250 | sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip)); |
michael@0 | 4251 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 4252 | } else { |
michael@0 | 4253 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 4254 | } |
michael@0 | 4255 | #endif |
michael@0 | 4256 | #endif |
michael@0 | 4257 | } |
michael@0 | 4258 | #ifdef SCTP_PACKET_LOGGING |
michael@0 | 4259 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LAST_PACKET_TRACING) |
michael@0 | 4260 | sctp_packet_log(o_pak); |
michael@0 | 4261 | #endif |
michael@0 | 4262 | /* send it out. table id is taken from stcb */ |
michael@0 | 4263 | #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 4264 | if ((SCTP_BASE_SYSCTL(sctp_output_unlocked)) && (so_locked)) { |
michael@0 | 4265 | so = SCTP_INP_SO(inp); |
michael@0 | 4266 | SCTP_SOCKET_UNLOCK(so, 0); |
michael@0 | 4267 | } |
michael@0 | 4268 | #endif |
michael@0 | 4269 | SCTP_IP_OUTPUT(ret, o_pak, ro, stcb, vrf_id); |
michael@0 | 4270 | #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 4271 | if ((SCTP_BASE_SYSCTL(sctp_output_unlocked)) && (so_locked)) { |
michael@0 | 4272 | atomic_add_int(&stcb->asoc.refcnt, 1); |
michael@0 | 4273 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 4274 | SCTP_SOCKET_LOCK(so, 0); |
michael@0 | 4275 | SCTP_TCB_LOCK(stcb); |
michael@0 | 4276 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
michael@0 | 4277 | } |
michael@0 | 4278 | #endif |
michael@0 | 4279 | SCTP_STAT_INCR(sctps_sendpackets); |
michael@0 | 4280 | SCTP_STAT_INCR_COUNTER64(sctps_outpackets); |
michael@0 | 4281 | if (ret) |
michael@0 | 4282 | SCTP_STAT_INCR(sctps_senderrors); |
michael@0 | 4283 | |
michael@0 | 4284 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "IP output returns %d\n", ret); |
michael@0 | 4285 | if (net == NULL) { |
michael@0 | 4286 | /* free tempy routes */ |
michael@0 | 4287 | #if defined(__FreeBSD__) && __FreeBSD_version > 901000 |
michael@0 | 4288 | RO_RTFREE(ro); |
michael@0 | 4289 | #else |
michael@0 | 4290 | if (ro->ro_rt) { |
michael@0 | 4291 | RTFREE(ro->ro_rt); |
michael@0 | 4292 | ro->ro_rt = NULL; |
michael@0 | 4293 | } |
michael@0 | 4294 | #endif |
michael@0 | 4295 | } else { |
michael@0 | 4296 | /* PMTU check versus smallest asoc MTU goes here */ |
michael@0 | 4297 | if ((ro->ro_rt != NULL) && |
michael@0 | 4298 | (net->ro._s_addr)) { |
michael@0 | 4299 | uint32_t mtu; |
michael@0 | 4300 | mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, ro->ro_rt); |
michael@0 | 4301 | if (net->port) { |
michael@0 | 4302 | mtu -= sizeof(struct udphdr); |
michael@0 | 4303 | } |
michael@0 | 4304 | if (mtu && (stcb->asoc.smallest_mtu > mtu)) { |
michael@0 | 4305 | sctp_mtu_size_reset(inp, &stcb->asoc, mtu); |
michael@0 | 4306 | net->mtu = mtu; |
michael@0 | 4307 | } |
michael@0 | 4308 | } else if (ro->ro_rt == NULL) { |
michael@0 | 4309 | /* route was freed */ |
michael@0 | 4310 | if (net->ro._s_addr && |
michael@0 | 4311 | net->src_addr_selected) { |
michael@0 | 4312 | sctp_free_ifa(net->ro._s_addr); |
michael@0 | 4313 | net->ro._s_addr = NULL; |
michael@0 | 4314 | } |
michael@0 | 4315 | net->src_addr_selected = 0; |
michael@0 | 4316 | } |
michael@0 | 4317 | } |
michael@0 | 4318 | return (ret); |
michael@0 | 4319 | } |
michael@0 | 4320 | #endif |
michael@0 | 4321 | #ifdef INET6 |
michael@0 | 4322 | case AF_INET6: |
michael@0 | 4323 | { |
michael@0 | 4324 | uint32_t flowlabel, flowinfo; |
michael@0 | 4325 | struct ip6_hdr *ip6h; |
michael@0 | 4326 | struct route_in6 ip6route; |
michael@0 | 4327 | #if !(defined(__Panda__) || defined(__Userspace__)) |
michael@0 | 4328 | struct ifnet *ifp; |
michael@0 | 4329 | #endif |
michael@0 | 4330 | struct sockaddr_in6 *sin6, tmp, *lsa6, lsa6_tmp; |
michael@0 | 4331 | int prev_scope = 0; |
michael@0 | 4332 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 4333 | struct sockaddr_in6 lsa6_storage; |
michael@0 | 4334 | int error; |
michael@0 | 4335 | #endif |
michael@0 | 4336 | u_short prev_port = 0; |
michael@0 | 4337 | int len; |
michael@0 | 4338 | |
michael@0 | 4339 | if (net) { |
michael@0 | 4340 | flowlabel = net->flowlabel; |
michael@0 | 4341 | } else if (stcb) { |
michael@0 | 4342 | flowlabel = stcb->asoc.default_flowlabel; |
michael@0 | 4343 | } else { |
michael@0 | 4344 | flowlabel = inp->sctp_ep.default_flowlabel; |
michael@0 | 4345 | } |
michael@0 | 4346 | if (flowlabel == 0) { |
michael@0 | 4347 | /* |
michael@0 | 4348 | * This means especially, that it is not set at the |
michael@0 | 4349 | * SCTP layer. So use the value from the IP layer. |
michael@0 | 4350 | */ |
michael@0 | 4351 | #if defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)) |
michael@0 | 4352 | flowlabel = ntohl(inp->ip_inp.inp.inp_flow); |
michael@0 | 4353 | #else |
michael@0 | 4354 | flowlabel = ntohl(((struct in6pcb *)inp)->in6p_flowinfo); |
michael@0 | 4355 | #endif |
michael@0 | 4356 | } |
michael@0 | 4357 | flowlabel &= 0x000fffff; |
michael@0 | 4358 | len = sizeof(struct ip6_hdr) + sizeof(struct sctphdr); |
michael@0 | 4359 | if (port) { |
michael@0 | 4360 | len += sizeof(struct udphdr); |
michael@0 | 4361 | } |
michael@0 | 4362 | newm = sctp_get_mbuf_for_msg(len, 1, M_NOWAIT, 1, MT_DATA); |
michael@0 | 4363 | if (newm == NULL) { |
michael@0 | 4364 | sctp_m_freem(m); |
michael@0 | 4365 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 4366 | return (ENOMEM); |
michael@0 | 4367 | } |
michael@0 | 4368 | SCTP_ALIGN_TO_END(newm, len); |
michael@0 | 4369 | SCTP_BUF_LEN(newm) = len; |
michael@0 | 4370 | SCTP_BUF_NEXT(newm) = m; |
michael@0 | 4371 | m = newm; |
michael@0 | 4372 | #if defined(__FreeBSD__) |
michael@0 | 4373 | if (net != NULL) { |
michael@0 | 4374 | #ifdef INVARIANTS |
michael@0 | 4375 | if (net->flowidset == 0) { |
michael@0 | 4376 | panic("Flow ID not set"); |
michael@0 | 4377 | } |
michael@0 | 4378 | #endif |
michael@0 | 4379 | m->m_pkthdr.flowid = net->flowid; |
michael@0 | 4380 | m->m_flags |= M_FLOWID; |
michael@0 | 4381 | } else { |
michael@0 | 4382 | if (use_mflowid != 0) { |
michael@0 | 4383 | m->m_pkthdr.flowid = mflowid; |
michael@0 | 4384 | m->m_flags |= M_FLOWID; |
michael@0 | 4385 | } |
michael@0 | 4386 | } |
michael@0 | 4387 | #endif |
michael@0 | 4388 | packet_length = sctp_calculate_len(m); |
michael@0 | 4389 | |
michael@0 | 4390 | ip6h = mtod(m, struct ip6_hdr *); |
michael@0 | 4391 | /* protect *sin6 from overwrite */ |
michael@0 | 4392 | sin6 = (struct sockaddr_in6 *)to; |
michael@0 | 4393 | tmp = *sin6; |
michael@0 | 4394 | sin6 = &tmp; |
michael@0 | 4395 | |
michael@0 | 4396 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 4397 | /* KAME hack: embed scopeid */ |
michael@0 | 4398 | #if defined(__APPLE__) |
michael@0 | 4399 | #if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) |
michael@0 | 4400 | if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL) != 0) |
michael@0 | 4401 | #else |
michael@0 | 4402 | if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL, NULL) != 0) |
michael@0 | 4403 | #endif |
michael@0 | 4404 | #elif defined(SCTP_KAME) |
michael@0 | 4405 | if (sa6_embedscope(sin6, MODULE_GLOBAL(ip6_use_defzone)) != 0) |
michael@0 | 4406 | #else |
michael@0 | 4407 | if (in6_embedscope(&sin6->sin6_addr, sin6) != 0) |
michael@0 | 4408 | #endif |
michael@0 | 4409 | { |
michael@0 | 4410 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 4411 | return (EINVAL); |
michael@0 | 4412 | } |
michael@0 | 4413 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 4414 | if (net == NULL) { |
michael@0 | 4415 | memset(&ip6route, 0, sizeof(ip6route)); |
michael@0 | 4416 | ro = (sctp_route_t *)&ip6route; |
michael@0 | 4417 | #ifdef HAVE_SIN6_LEN |
michael@0 | 4418 | memcpy(&ro->ro_dst, sin6, sin6->sin6_len); |
michael@0 | 4419 | #else |
michael@0 | 4420 | memcpy(&ro->ro_dst, sin6, sizeof(struct sockaddr_in6)); |
michael@0 | 4421 | #endif |
michael@0 | 4422 | } else { |
michael@0 | 4423 | ro = (sctp_route_t *)&net->ro; |
michael@0 | 4424 | } |
michael@0 | 4425 | /* |
michael@0 | 4426 | * We assume here that inp_flow is in host byte order within |
michael@0 | 4427 | * the TCB! |
michael@0 | 4428 | */ |
michael@0 | 4429 | if (tos_value == 0) { |
michael@0 | 4430 | /* |
michael@0 | 4431 | * This means especially, that it is not set at the |
michael@0 | 4432 | * SCTP layer. So use the value from the IP layer. |
michael@0 | 4433 | */ |
michael@0 | 4434 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Panda__) || defined(__Windows__) || defined(__Userspace__) |
michael@0 | 4435 | #if defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)) |
michael@0 | 4436 | tos_value = (ntohl(inp->ip_inp.inp.inp_flow) >> 20) & 0xff; |
michael@0 | 4437 | #else |
michael@0 | 4438 | tos_value = (ntohl(((struct in6pcb *)inp)->in6p_flowinfo) >> 20) & 0xff; |
michael@0 | 4439 | #endif |
michael@0 | 4440 | #endif |
michael@0 | 4441 | } |
michael@0 | 4442 | tos_value &= 0xfc; |
michael@0 | 4443 | if (ecn_ok) { |
michael@0 | 4444 | tos_value |= sctp_get_ect(stcb); |
michael@0 | 4445 | } |
michael@0 | 4446 | flowinfo = 0x06; |
michael@0 | 4447 | flowinfo <<= 8; |
michael@0 | 4448 | flowinfo |= tos_value; |
michael@0 | 4449 | flowinfo <<= 20; |
michael@0 | 4450 | flowinfo |= flowlabel; |
michael@0 | 4451 | ip6h->ip6_flow = htonl(flowinfo); |
michael@0 | 4452 | if (port) { |
michael@0 | 4453 | ip6h->ip6_nxt = IPPROTO_UDP; |
michael@0 | 4454 | } else { |
michael@0 | 4455 | ip6h->ip6_nxt = IPPROTO_SCTP; |
michael@0 | 4456 | } |
michael@0 | 4457 | ip6h->ip6_plen = (packet_length - sizeof(struct ip6_hdr)); |
michael@0 | 4458 | ip6h->ip6_dst = sin6->sin6_addr; |
michael@0 | 4459 | |
michael@0 | 4460 | /* |
michael@0 | 4461 | * Add SRC address selection here: we can only reuse to a |
michael@0 | 4462 | * limited degree the kame src-addr-sel, since we can try |
michael@0 | 4463 | * their selection but it may not be bound. |
michael@0 | 4464 | */ |
michael@0 | 4465 | bzero(&lsa6_tmp, sizeof(lsa6_tmp)); |
michael@0 | 4466 | lsa6_tmp.sin6_family = AF_INET6; |
michael@0 | 4467 | #ifdef HAVE_SIN6_LEN |
michael@0 | 4468 | lsa6_tmp.sin6_len = sizeof(lsa6_tmp); |
michael@0 | 4469 | #endif |
michael@0 | 4470 | lsa6 = &lsa6_tmp; |
michael@0 | 4471 | if (net && out_of_asoc_ok == 0) { |
michael@0 | 4472 | if (net->ro._s_addr && (net->ro._s_addr->localifa_flags & (SCTP_BEING_DELETED|SCTP_ADDR_IFA_UNUSEABLE))) { |
michael@0 | 4473 | sctp_free_ifa(net->ro._s_addr); |
michael@0 | 4474 | net->ro._s_addr = NULL; |
michael@0 | 4475 | net->src_addr_selected = 0; |
michael@0 | 4476 | if (ro->ro_rt) { |
michael@0 | 4477 | RTFREE(ro->ro_rt); |
michael@0 | 4478 | ro->ro_rt = NULL; |
michael@0 | 4479 | } |
michael@0 | 4480 | } |
michael@0 | 4481 | if (net->src_addr_selected == 0) { |
michael@0 | 4482 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 4483 | sin6 = (struct sockaddr_in6 *)&net->ro._l_addr; |
michael@0 | 4484 | /* KAME hack: embed scopeid */ |
michael@0 | 4485 | #if defined(__APPLE__) |
michael@0 | 4486 | #if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) |
michael@0 | 4487 | if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL) != 0) |
michael@0 | 4488 | #else |
michael@0 | 4489 | if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL, NULL) != 0) |
michael@0 | 4490 | #endif |
michael@0 | 4491 | #elif defined(SCTP_KAME) |
michael@0 | 4492 | if (sa6_embedscope(sin6, MODULE_GLOBAL(ip6_use_defzone)) != 0) |
michael@0 | 4493 | #else |
michael@0 | 4494 | if (in6_embedscope(&sin6->sin6_addr, sin6) != 0) |
michael@0 | 4495 | #endif |
michael@0 | 4496 | { |
michael@0 | 4497 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 4498 | return (EINVAL); |
michael@0 | 4499 | } |
michael@0 | 4500 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 4501 | /* Cache the source address */ |
michael@0 | 4502 | net->ro._s_addr = sctp_source_address_selection(inp, |
michael@0 | 4503 | stcb, |
michael@0 | 4504 | ro, |
michael@0 | 4505 | net, |
michael@0 | 4506 | 0, |
michael@0 | 4507 | vrf_id); |
michael@0 | 4508 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 4509 | #ifdef SCTP_KAME |
michael@0 | 4510 | (void)sa6_recoverscope(sin6); |
michael@0 | 4511 | #else |
michael@0 | 4512 | (void)in6_recoverscope(sin6, &sin6->sin6_addr, NULL); |
michael@0 | 4513 | #endif /* SCTP_KAME */ |
michael@0 | 4514 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 4515 | net->src_addr_selected = 1; |
michael@0 | 4516 | } |
michael@0 | 4517 | if (net->ro._s_addr == NULL) { |
michael@0 | 4518 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "V6:No route to host\n"); |
michael@0 | 4519 | net->src_addr_selected = 0; |
michael@0 | 4520 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4521 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4522 | sctp_m_freem(m); |
michael@0 | 4523 | return (EHOSTUNREACH); |
michael@0 | 4524 | } |
michael@0 | 4525 | lsa6->sin6_addr = net->ro._s_addr->address.sin6.sin6_addr; |
michael@0 | 4526 | } else { |
michael@0 | 4527 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 4528 | sin6 = (struct sockaddr_in6 *)&ro->ro_dst; |
michael@0 | 4529 | /* KAME hack: embed scopeid */ |
michael@0 | 4530 | #if defined(__APPLE__) |
michael@0 | 4531 | #if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) |
michael@0 | 4532 | if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL) != 0) |
michael@0 | 4533 | #else |
michael@0 | 4534 | if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL, NULL) != 0) |
michael@0 | 4535 | #endif |
michael@0 | 4536 | #elif defined(SCTP_KAME) |
michael@0 | 4537 | if (sa6_embedscope(sin6, MODULE_GLOBAL(ip6_use_defzone)) != 0) |
michael@0 | 4538 | #else |
michael@0 | 4539 | if (in6_embedscope(&sin6->sin6_addr, sin6) != 0) |
michael@0 | 4540 | #endif |
michael@0 | 4541 | { |
michael@0 | 4542 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 4543 | return (EINVAL); |
michael@0 | 4544 | } |
michael@0 | 4545 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 4546 | if (over_addr == NULL) { |
michael@0 | 4547 | struct sctp_ifa *_lsrc; |
michael@0 | 4548 | |
michael@0 | 4549 | _lsrc = sctp_source_address_selection(inp, stcb, ro, |
michael@0 | 4550 | net, |
michael@0 | 4551 | out_of_asoc_ok, |
michael@0 | 4552 | vrf_id); |
michael@0 | 4553 | if (_lsrc == NULL) { |
michael@0 | 4554 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4555 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4556 | sctp_m_freem(m); |
michael@0 | 4557 | return (EHOSTUNREACH); |
michael@0 | 4558 | } |
michael@0 | 4559 | lsa6->sin6_addr = _lsrc->address.sin6.sin6_addr; |
michael@0 | 4560 | sctp_free_ifa(_lsrc); |
michael@0 | 4561 | } else { |
michael@0 | 4562 | lsa6->sin6_addr = over_addr->sin6.sin6_addr; |
michael@0 | 4563 | SCTP_RTALLOC(ro, vrf_id); |
michael@0 | 4564 | } |
michael@0 | 4565 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 4566 | #ifdef SCTP_KAME |
michael@0 | 4567 | (void)sa6_recoverscope(sin6); |
michael@0 | 4568 | #else |
michael@0 | 4569 | (void)in6_recoverscope(sin6, &sin6->sin6_addr, NULL); |
michael@0 | 4570 | #endif /* SCTP_KAME */ |
michael@0 | 4571 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 4572 | } |
michael@0 | 4573 | lsa6->sin6_port = inp->sctp_lport; |
michael@0 | 4574 | |
michael@0 | 4575 | if (ro->ro_rt == NULL) { |
michael@0 | 4576 | /* |
michael@0 | 4577 | * src addr selection failed to find a route (or |
michael@0 | 4578 | * valid source addr), so we can't get there from |
michael@0 | 4579 | * here! |
michael@0 | 4580 | */ |
michael@0 | 4581 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4582 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4583 | sctp_m_freem(m); |
michael@0 | 4584 | return (EHOSTUNREACH); |
michael@0 | 4585 | } |
michael@0 | 4586 | #ifndef SCOPEDROUTING |
michael@0 | 4587 | #ifdef SCTP_EMBEDDED_V6_SCOPE |
michael@0 | 4588 | /* |
michael@0 | 4589 | * XXX: sa6 may not have a valid sin6_scope_id in the |
michael@0 | 4590 | * non-SCOPEDROUTING case. |
michael@0 | 4591 | */ |
michael@0 | 4592 | bzero(&lsa6_storage, sizeof(lsa6_storage)); |
michael@0 | 4593 | lsa6_storage.sin6_family = AF_INET6; |
michael@0 | 4594 | #ifdef HAVE_SIN6_LEN |
michael@0 | 4595 | lsa6_storage.sin6_len = sizeof(lsa6_storage); |
michael@0 | 4596 | #endif |
michael@0 | 4597 | #ifdef SCTP_KAME |
michael@0 | 4598 | lsa6_storage.sin6_addr = lsa6->sin6_addr; |
michael@0 | 4599 | if ((error = sa6_recoverscope(&lsa6_storage)) != 0) { |
michael@0 | 4600 | #else |
michael@0 | 4601 | if ((error = in6_recoverscope(&lsa6_storage, &lsa6->sin6_addr, |
michael@0 | 4602 | NULL)) != 0) { |
michael@0 | 4603 | #endif /* SCTP_KAME */ |
michael@0 | 4604 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "recover scope fails error %d\n", error); |
michael@0 | 4605 | sctp_m_freem(m); |
michael@0 | 4606 | return (error); |
michael@0 | 4607 | } |
michael@0 | 4608 | /* XXX */ |
michael@0 | 4609 | lsa6_storage.sin6_addr = lsa6->sin6_addr; |
michael@0 | 4610 | lsa6_storage.sin6_port = inp->sctp_lport; |
michael@0 | 4611 | lsa6 = &lsa6_storage; |
michael@0 | 4612 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
michael@0 | 4613 | #endif /* SCOPEDROUTING */ |
michael@0 | 4614 | ip6h->ip6_src = lsa6->sin6_addr; |
michael@0 | 4615 | |
michael@0 | 4616 | if (port) { |
michael@0 | 4617 | if (htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)) == 0) { |
michael@0 | 4618 | sctp_handle_no_route(stcb, net, so_locked); |
michael@0 | 4619 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH); |
michael@0 | 4620 | sctp_m_freem(m); |
michael@0 | 4621 | return (EHOSTUNREACH); |
michael@0 | 4622 | } |
michael@0 | 4623 | udp = (struct udphdr *)((caddr_t)ip6h + sizeof(struct ip6_hdr)); |
michael@0 | 4624 | udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); |
michael@0 | 4625 | udp->uh_dport = port; |
michael@0 | 4626 | udp->uh_ulen = htons(packet_length - sizeof(struct ip6_hdr)); |
michael@0 | 4627 | udp->uh_sum = 0; |
michael@0 | 4628 | sctphdr = (struct sctphdr *)((caddr_t)udp + sizeof(struct udphdr)); |
michael@0 | 4629 | } else { |
michael@0 | 4630 | sctphdr = (struct sctphdr *)((caddr_t)ip6h + sizeof(struct ip6_hdr)); |
michael@0 | 4631 | } |
michael@0 | 4632 | |
michael@0 | 4633 | sctphdr->src_port = src_port; |
michael@0 | 4634 | sctphdr->dest_port = dest_port; |
michael@0 | 4635 | sctphdr->v_tag = v_tag; |
michael@0 | 4636 | sctphdr->checksum = 0; |
michael@0 | 4637 | |
michael@0 | 4638 | /* |
michael@0 | 4639 | * We set the hop limit now since there is a good chance |
michael@0 | 4640 | * that our ro pointer is now filled |
michael@0 | 4641 | */ |
michael@0 | 4642 | ip6h->ip6_hlim = SCTP_GET_HLIM(inp, ro); |
michael@0 | 4643 | #if !(defined(__Panda__) || defined(__Userspace__)) |
michael@0 | 4644 | ifp = SCTP_GET_IFN_VOID_FROM_ROUTE(ro); |
michael@0 | 4645 | #endif |
michael@0 | 4646 | |
michael@0 | 4647 | #ifdef SCTP_DEBUG |
michael@0 | 4648 | /* Copy to be sure something bad is not happening */ |
michael@0 | 4649 | sin6->sin6_addr = ip6h->ip6_dst; |
michael@0 | 4650 | lsa6->sin6_addr = ip6h->ip6_src; |
michael@0 | 4651 | #endif |
michael@0 | 4652 | |
michael@0 | 4653 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "Calling ipv6 output routine from low level\n"); |
michael@0 | 4654 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "src: "); |
michael@0 | 4655 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, (struct sockaddr *)lsa6); |
michael@0 | 4656 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "dst: "); |
michael@0 | 4657 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, (struct sockaddr *)sin6); |
michael@0 | 4658 | if (net) { |
michael@0 | 4659 | sin6 = (struct sockaddr_in6 *)&net->ro._l_addr; |
michael@0 | 4660 | /* preserve the port and scope for link local send */ |
michael@0 | 4661 | prev_scope = sin6->sin6_scope_id; |
michael@0 | 4662 | prev_port = sin6->sin6_port; |
michael@0 | 4663 | } |
michael@0 | 4664 | |
michael@0 | 4665 | if (SCTP_GET_HEADER_FOR_OUTPUT(o_pak)) { |
michael@0 | 4666 | /* failed to prepend data, give up */ |
michael@0 | 4667 | sctp_m_freem(m); |
michael@0 | 4668 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 4669 | return (ENOMEM); |
michael@0 | 4670 | } |
michael@0 | 4671 | SCTP_ATTACH_CHAIN(o_pak, m, packet_length); |
michael@0 | 4672 | if (port) { |
michael@0 | 4673 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 4674 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 4675 | #else |
michael@0 | 4676 | sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr)); |
michael@0 | 4677 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 4678 | #endif |
michael@0 | 4679 | #if defined(__Windows__) |
michael@0 | 4680 | udp->uh_sum = 0; |
michael@0 | 4681 | #elif !defined(__Userspace__) |
michael@0 | 4682 | if ((udp->uh_sum = in6_cksum(o_pak, IPPROTO_UDP, sizeof(struct ip6_hdr), packet_length - sizeof(struct ip6_hdr))) == 0) { |
michael@0 | 4683 | udp->uh_sum = 0xffff; |
michael@0 | 4684 | } |
michael@0 | 4685 | #endif |
michael@0 | 4686 | } else { |
michael@0 | 4687 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 4688 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 4689 | #else |
michael@0 | 4690 | #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 |
michael@0 | 4691 | #if __FreeBSD_version < 900000 |
michael@0 | 4692 | sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip6_hdr)); |
michael@0 | 4693 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 4694 | #else |
michael@0 | 4695 | #if __FreeBSD_version > 901000 |
michael@0 | 4696 | m->m_pkthdr.csum_flags = CSUM_SCTP_IPV6; |
michael@0 | 4697 | #else |
michael@0 | 4698 | m->m_pkthdr.csum_flags = CSUM_SCTP; |
michael@0 | 4699 | #endif |
michael@0 | 4700 | m->m_pkthdr.csum_data = 0; |
michael@0 | 4701 | SCTP_STAT_INCR(sctps_sendhwcrc); |
michael@0 | 4702 | #endif |
michael@0 | 4703 | #else |
michael@0 | 4704 | if (!(SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) && |
michael@0 | 4705 | (stcb) && (stcb->asoc.scope.loopback_scope))) { |
michael@0 | 4706 | sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip6_hdr)); |
michael@0 | 4707 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 4708 | } else { |
michael@0 | 4709 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 4710 | } |
michael@0 | 4711 | #endif |
michael@0 | 4712 | #endif |
michael@0 | 4713 | } |
michael@0 | 4714 | /* send it out. table id is taken from stcb */ |
michael@0 | 4715 | #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 4716 | if ((SCTP_BASE_SYSCTL(sctp_output_unlocked)) && (so_locked)) { |
michael@0 | 4717 | so = SCTP_INP_SO(inp); |
michael@0 | 4718 | SCTP_SOCKET_UNLOCK(so, 0); |
michael@0 | 4719 | } |
michael@0 | 4720 | #endif |
michael@0 | 4721 | #ifdef SCTP_PACKET_LOGGING |
michael@0 | 4722 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LAST_PACKET_TRACING) |
michael@0 | 4723 | sctp_packet_log(o_pak); |
michael@0 | 4724 | #endif |
michael@0 | 4725 | #if !(defined(__Panda__) || defined(__Userspace__)) |
michael@0 | 4726 | SCTP_IP6_OUTPUT(ret, o_pak, (struct route_in6 *)ro, &ifp, stcb, vrf_id); |
michael@0 | 4727 | #else |
michael@0 | 4728 | SCTP_IP6_OUTPUT(ret, o_pak, (struct route_in6 *)ro, NULL, stcb, vrf_id); |
michael@0 | 4729 | #endif |
michael@0 | 4730 | #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 4731 | if ((SCTP_BASE_SYSCTL(sctp_output_unlocked)) && (so_locked)) { |
michael@0 | 4732 | atomic_add_int(&stcb->asoc.refcnt, 1); |
michael@0 | 4733 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 4734 | SCTP_SOCKET_LOCK(so, 0); |
michael@0 | 4735 | SCTP_TCB_LOCK(stcb); |
michael@0 | 4736 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
michael@0 | 4737 | } |
michael@0 | 4738 | #endif |
michael@0 | 4739 | if (net) { |
michael@0 | 4740 | /* for link local this must be done */ |
michael@0 | 4741 | sin6->sin6_scope_id = prev_scope; |
michael@0 | 4742 | sin6->sin6_port = prev_port; |
michael@0 | 4743 | } |
michael@0 | 4744 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "return from send is %d\n", ret); |
michael@0 | 4745 | SCTP_STAT_INCR(sctps_sendpackets); |
michael@0 | 4746 | SCTP_STAT_INCR_COUNTER64(sctps_outpackets); |
michael@0 | 4747 | if (ret) { |
michael@0 | 4748 | SCTP_STAT_INCR(sctps_senderrors); |
michael@0 | 4749 | } |
michael@0 | 4750 | if (net == NULL) { |
michael@0 | 4751 | /* Now if we had a temp route free it */ |
michael@0 | 4752 | #if defined(__FreeBSD__) && __FreeBSD_version > 901000 |
michael@0 | 4753 | RO_RTFREE(ro); |
michael@0 | 4754 | #else |
michael@0 | 4755 | if (ro->ro_rt) { |
michael@0 | 4756 | RTFREE(ro->ro_rt); |
michael@0 | 4757 | ro->ro_rt = NULL; |
michael@0 | 4758 | } |
michael@0 | 4759 | #endif |
michael@0 | 4760 | } else { |
michael@0 | 4761 | /* PMTU check versus smallest asoc MTU goes here */ |
michael@0 | 4762 | if (ro->ro_rt == NULL) { |
michael@0 | 4763 | /* Route was freed */ |
michael@0 | 4764 | if (net->ro._s_addr && |
michael@0 | 4765 | net->src_addr_selected) { |
michael@0 | 4766 | sctp_free_ifa(net->ro._s_addr); |
michael@0 | 4767 | net->ro._s_addr = NULL; |
michael@0 | 4768 | } |
michael@0 | 4769 | net->src_addr_selected = 0; |
michael@0 | 4770 | } |
michael@0 | 4771 | if ((ro->ro_rt != NULL) && |
michael@0 | 4772 | (net->ro._s_addr)) { |
michael@0 | 4773 | uint32_t mtu; |
michael@0 | 4774 | mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, ro->ro_rt); |
michael@0 | 4775 | if (mtu && |
michael@0 | 4776 | (stcb->asoc.smallest_mtu > mtu)) { |
michael@0 | 4777 | sctp_mtu_size_reset(inp, &stcb->asoc, mtu); |
michael@0 | 4778 | net->mtu = mtu; |
michael@0 | 4779 | if (net->port) { |
michael@0 | 4780 | net->mtu -= sizeof(struct udphdr); |
michael@0 | 4781 | } |
michael@0 | 4782 | } |
michael@0 | 4783 | } |
michael@0 | 4784 | #if !defined(__Panda__) && !defined(__Userspace__) |
michael@0 | 4785 | else if (ifp) { |
michael@0 | 4786 | #if defined(__Windows__) |
michael@0 | 4787 | #define ND_IFINFO(ifp) (ifp) |
michael@0 | 4788 | #define linkmtu if_mtu |
michael@0 | 4789 | #endif |
michael@0 | 4790 | if (ND_IFINFO(ifp)->linkmtu && |
michael@0 | 4791 | (stcb->asoc.smallest_mtu > ND_IFINFO(ifp)->linkmtu)) { |
michael@0 | 4792 | sctp_mtu_size_reset(inp, |
michael@0 | 4793 | &stcb->asoc, |
michael@0 | 4794 | ND_IFINFO(ifp)->linkmtu); |
michael@0 | 4795 | } |
michael@0 | 4796 | } |
michael@0 | 4797 | #endif |
michael@0 | 4798 | } |
michael@0 | 4799 | return (ret); |
michael@0 | 4800 | } |
michael@0 | 4801 | #endif |
michael@0 | 4802 | #if defined(__Userspace__) |
michael@0 | 4803 | case AF_CONN: |
michael@0 | 4804 | { |
michael@0 | 4805 | char *buffer; |
michael@0 | 4806 | struct sockaddr_conn *sconn; |
michael@0 | 4807 | int len; |
michael@0 | 4808 | |
michael@0 | 4809 | sconn = (struct sockaddr_conn *)to; |
michael@0 | 4810 | len = sizeof(struct sctphdr); |
michael@0 | 4811 | newm = sctp_get_mbuf_for_msg(len, 1, M_NOWAIT, 1, MT_DATA); |
michael@0 | 4812 | if (newm == NULL) { |
michael@0 | 4813 | sctp_m_freem(m); |
michael@0 | 4814 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 4815 | return (ENOMEM); |
michael@0 | 4816 | } |
michael@0 | 4817 | SCTP_ALIGN_TO_END(newm, len); |
michael@0 | 4818 | SCTP_BUF_LEN(newm) = len; |
michael@0 | 4819 | SCTP_BUF_NEXT(newm) = m; |
michael@0 | 4820 | m = newm; |
michael@0 | 4821 | packet_length = sctp_calculate_len(m); |
michael@0 | 4822 | sctphdr = mtod(m, struct sctphdr *); |
michael@0 | 4823 | sctphdr->src_port = src_port; |
michael@0 | 4824 | sctphdr->dest_port = dest_port; |
michael@0 | 4825 | sctphdr->v_tag = v_tag; |
michael@0 | 4826 | sctphdr->checksum = 0; |
michael@0 | 4827 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 4828 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 4829 | #else |
michael@0 | 4830 | sctphdr->checksum = sctp_calculate_cksum(m, 0); |
michael@0 | 4831 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 4832 | #endif |
michael@0 | 4833 | if (tos_value == 0) { |
michael@0 | 4834 | tos_value = inp->ip_inp.inp.inp_ip_tos; |
michael@0 | 4835 | } |
michael@0 | 4836 | tos_value &= 0xfc; |
michael@0 | 4837 | if (ecn_ok) { |
michael@0 | 4838 | tos_value |= sctp_get_ect(stcb); |
michael@0 | 4839 | } |
michael@0 | 4840 | /* Don't alloc/free for each packet */ |
michael@0 | 4841 | if ((buffer = malloc(packet_length)) != NULL) { |
michael@0 | 4842 | m_copydata(m, 0, packet_length, buffer); |
michael@0 | 4843 | ret = SCTP_BASE_VAR(conn_output)(sconn->sconn_addr, buffer, packet_length, tos_value, nofragment_flag); |
michael@0 | 4844 | free(buffer); |
michael@0 | 4845 | } else { |
michael@0 | 4846 | ret = ENOMEM; |
michael@0 | 4847 | } |
michael@0 | 4848 | sctp_m_freem(m); |
michael@0 | 4849 | return (ret); |
michael@0 | 4850 | } |
michael@0 | 4851 | #endif |
michael@0 | 4852 | default: |
michael@0 | 4853 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Unknown protocol (TSNH) type %d\n", |
michael@0 | 4854 | ((struct sockaddr *)to)->sa_family); |
michael@0 | 4855 | sctp_m_freem(m); |
michael@0 | 4856 | SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EFAULT); |
michael@0 | 4857 | return (EFAULT); |
michael@0 | 4858 | } |
michael@0 | 4859 | } |
michael@0 | 4860 | |
michael@0 | 4861 | |
michael@0 | 4862 | void |
michael@0 | 4863 | sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked |
michael@0 | 4864 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 4865 | SCTP_UNUSED |
michael@0 | 4866 | #endif |
michael@0 | 4867 | ) |
michael@0 | 4868 | { |
michael@0 | 4869 | struct mbuf *m; |
michael@0 | 4870 | struct sctp_nets *net; |
michael@0 | 4871 | struct sctp_init_chunk *init; |
michael@0 | 4872 | struct sctp_supported_addr_param *sup_addr; |
michael@0 | 4873 | struct sctp_adaptation_layer_indication *ali; |
michael@0 | 4874 | struct sctp_supported_chunk_types_param *pr_supported; |
michael@0 | 4875 | struct sctp_paramhdr *ph; |
michael@0 | 4876 | int cnt_inits_to = 0; |
michael@0 | 4877 | int ret; |
michael@0 | 4878 | uint16_t num_ext, chunk_len, padding_len, parameter_len; |
michael@0 | 4879 | |
michael@0 | 4880 | #if defined(__APPLE__) |
michael@0 | 4881 | if (so_locked) { |
michael@0 | 4882 | sctp_lock_assert(SCTP_INP_SO(inp)); |
michael@0 | 4883 | } else { |
michael@0 | 4884 | sctp_unlock_assert(SCTP_INP_SO(inp)); |
michael@0 | 4885 | } |
michael@0 | 4886 | #endif |
michael@0 | 4887 | /* INIT's always go to the primary (and usually ONLY address) */ |
michael@0 | 4888 | net = stcb->asoc.primary_destination; |
michael@0 | 4889 | if (net == NULL) { |
michael@0 | 4890 | net = TAILQ_FIRST(&stcb->asoc.nets); |
michael@0 | 4891 | if (net == NULL) { |
michael@0 | 4892 | /* TSNH */ |
michael@0 | 4893 | return; |
michael@0 | 4894 | } |
michael@0 | 4895 | /* we confirm any address we send an INIT to */ |
michael@0 | 4896 | net->dest_state &= ~SCTP_ADDR_UNCONFIRMED; |
michael@0 | 4897 | (void)sctp_set_primary_addr(stcb, NULL, net); |
michael@0 | 4898 | } else { |
michael@0 | 4899 | /* we confirm any address we send an INIT to */ |
michael@0 | 4900 | net->dest_state &= ~SCTP_ADDR_UNCONFIRMED; |
michael@0 | 4901 | } |
michael@0 | 4902 | SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT\n"); |
michael@0 | 4903 | #ifdef INET6 |
michael@0 | 4904 | if (net->ro._l_addr.sa.sa_family == AF_INET6) { |
michael@0 | 4905 | /* |
michael@0 | 4906 | * special hook, if we are sending to link local it will not |
michael@0 | 4907 | * show up in our private address count. |
michael@0 | 4908 | */ |
michael@0 | 4909 | if (IN6_IS_ADDR_LINKLOCAL(&net->ro._l_addr.sin6.sin6_addr)) |
michael@0 | 4910 | cnt_inits_to = 1; |
michael@0 | 4911 | } |
michael@0 | 4912 | #endif |
michael@0 | 4913 | if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
michael@0 | 4914 | /* This case should not happen */ |
michael@0 | 4915 | SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - failed timer?\n"); |
michael@0 | 4916 | return; |
michael@0 | 4917 | } |
michael@0 | 4918 | /* start the INIT timer */ |
michael@0 | 4919 | sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, net); |
michael@0 | 4920 | |
michael@0 | 4921 | m = sctp_get_mbuf_for_msg(MCLBYTES, 1, M_NOWAIT, 1, MT_DATA); |
michael@0 | 4922 | if (m == NULL) { |
michael@0 | 4923 | /* No memory, INIT timer will re-attempt. */ |
michael@0 | 4924 | SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - mbuf?\n"); |
michael@0 | 4925 | return; |
michael@0 | 4926 | } |
michael@0 | 4927 | chunk_len = (uint16_t)sizeof(struct sctp_init_chunk); |
michael@0 | 4928 | padding_len = 0; |
michael@0 | 4929 | /* |
michael@0 | 4930 | * assume peer supports asconf in order to be able to queue |
michael@0 | 4931 | * local address changes while an INIT is in flight and before |
michael@0 | 4932 | * the assoc is established. |
michael@0 | 4933 | */ |
michael@0 | 4934 | stcb->asoc.peer_supports_asconf = 1; |
michael@0 | 4935 | /* Now lets put the chunk header in place */ |
michael@0 | 4936 | init = mtod(m, struct sctp_init_chunk *); |
michael@0 | 4937 | /* now the chunk header */ |
michael@0 | 4938 | init->ch.chunk_type = SCTP_INITIATION; |
michael@0 | 4939 | init->ch.chunk_flags = 0; |
michael@0 | 4940 | /* fill in later from mbuf we build */ |
michael@0 | 4941 | init->ch.chunk_length = 0; |
michael@0 | 4942 | /* place in my tag */ |
michael@0 | 4943 | init->init.initiate_tag = htonl(stcb->asoc.my_vtag); |
michael@0 | 4944 | /* set up some of the credits. */ |
michael@0 | 4945 | init->init.a_rwnd = htonl(max(inp->sctp_socket?SCTP_SB_LIMIT_RCV(inp->sctp_socket):0, |
michael@0 | 4946 | SCTP_MINIMAL_RWND)); |
michael@0 | 4947 | init->init.num_outbound_streams = htons(stcb->asoc.pre_open_streams); |
michael@0 | 4948 | init->init.num_inbound_streams = htons(stcb->asoc.max_inbound_streams); |
michael@0 | 4949 | init->init.initial_tsn = htonl(stcb->asoc.init_seq_number); |
michael@0 | 4950 | |
michael@0 | 4951 | if (stcb->asoc.scope.ipv4_addr_legal || stcb->asoc.scope.ipv6_addr_legal) { |
michael@0 | 4952 | uint8_t i; |
michael@0 | 4953 | |
michael@0 | 4954 | parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); |
michael@0 | 4955 | if (stcb->asoc.scope.ipv4_addr_legal) { |
michael@0 | 4956 | parameter_len += (uint16_t)sizeof(uint16_t); |
michael@0 | 4957 | } |
michael@0 | 4958 | if (stcb->asoc.scope.ipv6_addr_legal) { |
michael@0 | 4959 | parameter_len += (uint16_t)sizeof(uint16_t); |
michael@0 | 4960 | } |
michael@0 | 4961 | sup_addr = (struct sctp_supported_addr_param *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 4962 | sup_addr->ph.param_type = htons(SCTP_SUPPORTED_ADDRTYPE); |
michael@0 | 4963 | sup_addr->ph.param_length = htons(parameter_len); |
michael@0 | 4964 | i = 0; |
michael@0 | 4965 | if (stcb->asoc.scope.ipv4_addr_legal) { |
michael@0 | 4966 | sup_addr->addr_type[i++] = htons(SCTP_IPV4_ADDRESS); |
michael@0 | 4967 | } |
michael@0 | 4968 | if (stcb->asoc.scope.ipv6_addr_legal) { |
michael@0 | 4969 | sup_addr->addr_type[i++] = htons(SCTP_IPV6_ADDRESS); |
michael@0 | 4970 | } |
michael@0 | 4971 | padding_len = 4 - 2 * i; |
michael@0 | 4972 | chunk_len += parameter_len; |
michael@0 | 4973 | } |
michael@0 | 4974 | |
michael@0 | 4975 | /* Adaptation layer indication parameter */ |
michael@0 | 4976 | if (inp->sctp_ep.adaptation_layer_indicator_provided) { |
michael@0 | 4977 | if (padding_len > 0) { |
michael@0 | 4978 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 4979 | chunk_len += padding_len; |
michael@0 | 4980 | padding_len = 0; |
michael@0 | 4981 | } |
michael@0 | 4982 | parameter_len = (uint16_t)sizeof(struct sctp_adaptation_layer_indication); |
michael@0 | 4983 | ali = (struct sctp_adaptation_layer_indication *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 4984 | ali->ph.param_type = htons(SCTP_ULP_ADAPTATION); |
michael@0 | 4985 | ali->ph.param_length = htons(parameter_len); |
michael@0 | 4986 | ali->indication = ntohl(inp->sctp_ep.adaptation_layer_indicator); |
michael@0 | 4987 | chunk_len += parameter_len; |
michael@0 | 4988 | } |
michael@0 | 4989 | |
michael@0 | 4990 | if (SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly)) { |
michael@0 | 4991 | /* Add NAT friendly parameter. */ |
michael@0 | 4992 | if (padding_len > 0) { |
michael@0 | 4993 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 4994 | chunk_len += padding_len; |
michael@0 | 4995 | padding_len = 0; |
michael@0 | 4996 | } |
michael@0 | 4997 | parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); |
michael@0 | 4998 | ph = (struct sctp_paramhdr *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 4999 | ph->param_type = htons(SCTP_HAS_NAT_SUPPORT); |
michael@0 | 5000 | ph->param_length = htons(parameter_len); |
michael@0 | 5001 | chunk_len += parameter_len; |
michael@0 | 5002 | } |
michael@0 | 5003 | |
michael@0 | 5004 | /* now any cookie time extensions */ |
michael@0 | 5005 | if (stcb->asoc.cookie_preserve_req) { |
michael@0 | 5006 | struct sctp_cookie_perserve_param *cookie_preserve; |
michael@0 | 5007 | |
michael@0 | 5008 | if (padding_len > 0) { |
michael@0 | 5009 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 5010 | chunk_len += padding_len; |
michael@0 | 5011 | padding_len = 0; |
michael@0 | 5012 | } |
michael@0 | 5013 | parameter_len = (uint16_t)sizeof(struct sctp_cookie_perserve_param); |
michael@0 | 5014 | cookie_preserve = (struct sctp_cookie_perserve_param *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 5015 | cookie_preserve->ph.param_type = htons(SCTP_COOKIE_PRESERVE); |
michael@0 | 5016 | cookie_preserve->ph.param_length = htons(parameter_len); |
michael@0 | 5017 | cookie_preserve->time = htonl(stcb->asoc.cookie_preserve_req); |
michael@0 | 5018 | stcb->asoc.cookie_preserve_req = 0; |
michael@0 | 5019 | chunk_len += parameter_len; |
michael@0 | 5020 | } |
michael@0 | 5021 | |
michael@0 | 5022 | /* ECN parameter */ |
michael@0 | 5023 | if (stcb->asoc.ecn_allowed == 1) { |
michael@0 | 5024 | if (padding_len > 0) { |
michael@0 | 5025 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 5026 | chunk_len += padding_len; |
michael@0 | 5027 | padding_len = 0; |
michael@0 | 5028 | } |
michael@0 | 5029 | parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); |
michael@0 | 5030 | ph = (struct sctp_paramhdr *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 5031 | ph->param_type = htons(SCTP_ECN_CAPABLE); |
michael@0 | 5032 | ph->param_length = htons(parameter_len); |
michael@0 | 5033 | chunk_len += parameter_len; |
michael@0 | 5034 | } |
michael@0 | 5035 | |
michael@0 | 5036 | /* And now tell the peer we do support PR-SCTP. */ |
michael@0 | 5037 | if (padding_len > 0) { |
michael@0 | 5038 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 5039 | chunk_len += padding_len; |
michael@0 | 5040 | padding_len = 0; |
michael@0 | 5041 | } |
michael@0 | 5042 | parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); |
michael@0 | 5043 | ph = (struct sctp_paramhdr *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 5044 | ph->param_type = htons(SCTP_PRSCTP_SUPPORTED); |
michael@0 | 5045 | ph->param_length = htons(parameter_len); |
michael@0 | 5046 | chunk_len += parameter_len; |
michael@0 | 5047 | |
michael@0 | 5048 | /* And now tell the peer we do all the extensions */ |
michael@0 | 5049 | pr_supported = (struct sctp_supported_chunk_types_param *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 5050 | pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT); |
michael@0 | 5051 | num_ext = 0; |
michael@0 | 5052 | pr_supported->chunk_types[num_ext++] = SCTP_ASCONF; |
michael@0 | 5053 | pr_supported->chunk_types[num_ext++] = SCTP_ASCONF_ACK; |
michael@0 | 5054 | pr_supported->chunk_types[num_ext++] = SCTP_FORWARD_CUM_TSN; |
michael@0 | 5055 | pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED; |
michael@0 | 5056 | pr_supported->chunk_types[num_ext++] = SCTP_STREAM_RESET; |
michael@0 | 5057 | if (!SCTP_BASE_SYSCTL(sctp_auth_disable)) { |
michael@0 | 5058 | pr_supported->chunk_types[num_ext++] = SCTP_AUTHENTICATION; |
michael@0 | 5059 | } |
michael@0 | 5060 | if (stcb->asoc.sctp_nr_sack_on_off == 1) { |
michael@0 | 5061 | pr_supported->chunk_types[num_ext++] = SCTP_NR_SELECTIVE_ACK; |
michael@0 | 5062 | } |
michael@0 | 5063 | parameter_len = (uint16_t)sizeof(struct sctp_supported_chunk_types_param) + num_ext; |
michael@0 | 5064 | pr_supported->ph.param_length = htons(parameter_len); |
michael@0 | 5065 | padding_len = SCTP_SIZE32(parameter_len) - parameter_len; |
michael@0 | 5066 | chunk_len += parameter_len; |
michael@0 | 5067 | |
michael@0 | 5068 | /* add authentication parameters */ |
michael@0 | 5069 | if (!SCTP_BASE_SYSCTL(sctp_auth_disable)) { |
michael@0 | 5070 | /* attach RANDOM parameter, if available */ |
michael@0 | 5071 | if (stcb->asoc.authinfo.random != NULL) { |
michael@0 | 5072 | struct sctp_auth_random *randp; |
michael@0 | 5073 | |
michael@0 | 5074 | if (padding_len > 0) { |
michael@0 | 5075 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 5076 | chunk_len += padding_len; |
michael@0 | 5077 | padding_len = 0; |
michael@0 | 5078 | } |
michael@0 | 5079 | randp = (struct sctp_auth_random *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 5080 | parameter_len = (uint16_t)sizeof(struct sctp_auth_random) + stcb->asoc.authinfo.random_len; |
michael@0 | 5081 | /* random key already contains the header */ |
michael@0 | 5082 | memcpy(randp, stcb->asoc.authinfo.random->key, parameter_len); |
michael@0 | 5083 | padding_len = SCTP_SIZE32(parameter_len) - parameter_len; |
michael@0 | 5084 | chunk_len += parameter_len; |
michael@0 | 5085 | } |
michael@0 | 5086 | /* add HMAC_ALGO parameter */ |
michael@0 | 5087 | if ((stcb->asoc.local_hmacs != NULL) && |
michael@0 | 5088 | (stcb->asoc.local_hmacs->num_algo > 0)) { |
michael@0 | 5089 | struct sctp_auth_hmac_algo *hmacs; |
michael@0 | 5090 | |
michael@0 | 5091 | if (padding_len > 0) { |
michael@0 | 5092 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 5093 | chunk_len += padding_len; |
michael@0 | 5094 | padding_len = 0; |
michael@0 | 5095 | } |
michael@0 | 5096 | hmacs = (struct sctp_auth_hmac_algo *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 5097 | parameter_len = (uint16_t)(sizeof(struct sctp_auth_hmac_algo) + |
michael@0 | 5098 | stcb->asoc.local_hmacs->num_algo * sizeof(uint16_t)); |
michael@0 | 5099 | hmacs->ph.param_type = htons(SCTP_HMAC_LIST); |
michael@0 | 5100 | hmacs->ph.param_length = htons(parameter_len); |
michael@0 | 5101 | sctp_serialize_hmaclist(stcb->asoc.local_hmacs, (uint8_t *)hmacs->hmac_ids); |
michael@0 | 5102 | padding_len = SCTP_SIZE32(parameter_len) - parameter_len; |
michael@0 | 5103 | chunk_len += parameter_len; |
michael@0 | 5104 | } |
michael@0 | 5105 | /* add CHUNKS parameter */ |
michael@0 | 5106 | if (sctp_auth_get_chklist_size(stcb->asoc.local_auth_chunks) > 0) { |
michael@0 | 5107 | struct sctp_auth_chunk_list *chunks; |
michael@0 | 5108 | |
michael@0 | 5109 | if (padding_len > 0) { |
michael@0 | 5110 | memset(mtod(m, caddr_t) + chunk_len, 0, padding_len); |
michael@0 | 5111 | chunk_len += padding_len; |
michael@0 | 5112 | padding_len = 0; |
michael@0 | 5113 | } |
michael@0 | 5114 | chunks = (struct sctp_auth_chunk_list *)(mtod(m, caddr_t) + chunk_len); |
michael@0 | 5115 | parameter_len = (uint16_t)(sizeof(struct sctp_auth_chunk_list) + |
michael@0 | 5116 | sctp_auth_get_chklist_size(stcb->asoc.local_auth_chunks)); |
michael@0 | 5117 | chunks->ph.param_type = htons(SCTP_CHUNK_LIST); |
michael@0 | 5118 | chunks->ph.param_length = htons(parameter_len); |
michael@0 | 5119 | sctp_serialize_auth_chunks(stcb->asoc.local_auth_chunks, chunks->chunk_types); |
michael@0 | 5120 | padding_len = SCTP_SIZE32(parameter_len) - parameter_len; |
michael@0 | 5121 | chunk_len += parameter_len; |
michael@0 | 5122 | } |
michael@0 | 5123 | } |
michael@0 | 5124 | SCTP_BUF_LEN(m) = chunk_len; |
michael@0 | 5125 | |
michael@0 | 5126 | /* now the addresses */ |
michael@0 | 5127 | /* To optimize this we could put the scoping stuff |
michael@0 | 5128 | * into a structure and remove the individual uint8's from |
michael@0 | 5129 | * the assoc structure. Then we could just sifa in the |
michael@0 | 5130 | * address within the stcb. But for now this is a quick |
michael@0 | 5131 | * hack to get the address stuff teased apart. |
michael@0 | 5132 | */ |
michael@0 | 5133 | sctp_add_addresses_to_i_ia(inp, stcb, &stcb->asoc.scope, m, cnt_inits_to, &padding_len, &chunk_len); |
michael@0 | 5134 | |
michael@0 | 5135 | init->ch.chunk_length = htons(chunk_len); |
michael@0 | 5136 | if (padding_len > 0) { |
michael@0 | 5137 | struct mbuf *m_at, *mp_last; |
michael@0 | 5138 | |
michael@0 | 5139 | mp_last = NULL; |
michael@0 | 5140 | for (m_at = m; m_at; m_at = SCTP_BUF_NEXT(m_at)) { |
michael@0 | 5141 | if (SCTP_BUF_NEXT(m_at) == NULL) |
michael@0 | 5142 | mp_last = m_at; |
michael@0 | 5143 | } |
michael@0 | 5144 | if ((mp_last == NULL) || sctp_add_pad_tombuf(mp_last, padding_len)) { |
michael@0 | 5145 | sctp_m_freem(m); |
michael@0 | 5146 | return; |
michael@0 | 5147 | } |
michael@0 | 5148 | } |
michael@0 | 5149 | SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - calls lowlevel_output\n"); |
michael@0 | 5150 | ret = sctp_lowlevel_chunk_output(inp, stcb, net, |
michael@0 | 5151 | (struct sockaddr *)&net->ro._l_addr, |
michael@0 | 5152 | m, 0, NULL, 0, 0, 0, 0, |
michael@0 | 5153 | inp->sctp_lport, stcb->rport, htonl(0), |
michael@0 | 5154 | net->port, NULL, |
michael@0 | 5155 | #if defined(__FreeBSD__) |
michael@0 | 5156 | 0, 0, |
michael@0 | 5157 | #endif |
michael@0 | 5158 | so_locked); |
michael@0 | 5159 | SCTPDBG(SCTP_DEBUG_OUTPUT4, "lowlevel_output - %d\n", ret); |
michael@0 | 5160 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 5161 | (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); |
michael@0 | 5162 | } |
michael@0 | 5163 | |
michael@0 | 5164 | struct mbuf * |
michael@0 | 5165 | sctp_arethere_unrecognized_parameters(struct mbuf *in_initpkt, |
michael@0 | 5166 | int param_offset, int *abort_processing, struct sctp_chunkhdr *cp, int *nat_friendly) |
michael@0 | 5167 | { |
michael@0 | 5168 | /* |
michael@0 | 5169 | * Given a mbuf containing an INIT or INIT-ACK with the param_offset |
michael@0 | 5170 | * being equal to the beginning of the params i.e. (iphlen + |
michael@0 | 5171 | * sizeof(struct sctp_init_msg) parse through the parameters to the |
michael@0 | 5172 | * end of the mbuf verifying that all parameters are known. |
michael@0 | 5173 | * |
michael@0 | 5174 | * For unknown parameters build and return a mbuf with |
michael@0 | 5175 | * UNRECOGNIZED_PARAMETER errors. If the flags indicate to stop |
michael@0 | 5176 | * processing this chunk stop, and set *abort_processing to 1. |
michael@0 | 5177 | * |
michael@0 | 5178 | * By having param_offset be pre-set to where parameters begin it is |
michael@0 | 5179 | * hoped that this routine may be reused in the future by new |
michael@0 | 5180 | * features. |
michael@0 | 5181 | */ |
michael@0 | 5182 | struct sctp_paramhdr *phdr, params; |
michael@0 | 5183 | |
michael@0 | 5184 | struct mbuf *mat, *op_err; |
michael@0 | 5185 | char tempbuf[SCTP_PARAM_BUFFER_SIZE]; |
michael@0 | 5186 | int at, limit, pad_needed; |
michael@0 | 5187 | uint16_t ptype, plen, padded_size; |
michael@0 | 5188 | int err_at; |
michael@0 | 5189 | |
michael@0 | 5190 | *abort_processing = 0; |
michael@0 | 5191 | mat = in_initpkt; |
michael@0 | 5192 | err_at = 0; |
michael@0 | 5193 | limit = ntohs(cp->chunk_length) - sizeof(struct sctp_init_chunk); |
michael@0 | 5194 | at = param_offset; |
michael@0 | 5195 | op_err = NULL; |
michael@0 | 5196 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Check for unrecognized param's\n"); |
michael@0 | 5197 | phdr = sctp_get_next_param(mat, at, ¶ms, sizeof(params)); |
michael@0 | 5198 | while ((phdr != NULL) && ((size_t)limit >= sizeof(struct sctp_paramhdr))) { |
michael@0 | 5199 | ptype = ntohs(phdr->param_type); |
michael@0 | 5200 | plen = ntohs(phdr->param_length); |
michael@0 | 5201 | if ((plen > limit) || (plen < sizeof(struct sctp_paramhdr))) { |
michael@0 | 5202 | /* wacked parameter */ |
michael@0 | 5203 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error %d\n", plen); |
michael@0 | 5204 | goto invalid_size; |
michael@0 | 5205 | } |
michael@0 | 5206 | limit -= SCTP_SIZE32(plen); |
michael@0 | 5207 | /*- |
michael@0 | 5208 | * All parameters for all chunks that we know/understand are |
michael@0 | 5209 | * listed here. We process them other places and make |
michael@0 | 5210 | * appropriate stop actions per the upper bits. However this |
michael@0 | 5211 | * is the generic routine processor's can call to get back |
michael@0 | 5212 | * an operr.. to either incorporate (init-ack) or send. |
michael@0 | 5213 | */ |
michael@0 | 5214 | padded_size = SCTP_SIZE32(plen); |
michael@0 | 5215 | switch (ptype) { |
michael@0 | 5216 | /* Param's with variable size */ |
michael@0 | 5217 | case SCTP_HEARTBEAT_INFO: |
michael@0 | 5218 | case SCTP_STATE_COOKIE: |
michael@0 | 5219 | case SCTP_UNRECOG_PARAM: |
michael@0 | 5220 | case SCTP_ERROR_CAUSE_IND: |
michael@0 | 5221 | /* ok skip fwd */ |
michael@0 | 5222 | at += padded_size; |
michael@0 | 5223 | break; |
michael@0 | 5224 | /* Param's with variable size within a range */ |
michael@0 | 5225 | case SCTP_CHUNK_LIST: |
michael@0 | 5226 | case SCTP_SUPPORTED_CHUNK_EXT: |
michael@0 | 5227 | if (padded_size > (sizeof(struct sctp_supported_chunk_types_param) + (sizeof(uint8_t) * SCTP_MAX_SUPPORTED_EXT))) { |
michael@0 | 5228 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error chklist %d\n", plen); |
michael@0 | 5229 | goto invalid_size; |
michael@0 | 5230 | } |
michael@0 | 5231 | at += padded_size; |
michael@0 | 5232 | break; |
michael@0 | 5233 | case SCTP_SUPPORTED_ADDRTYPE: |
michael@0 | 5234 | if (padded_size > SCTP_MAX_ADDR_PARAMS_SIZE) { |
michael@0 | 5235 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error supaddrtype %d\n", plen); |
michael@0 | 5236 | goto invalid_size; |
michael@0 | 5237 | } |
michael@0 | 5238 | at += padded_size; |
michael@0 | 5239 | break; |
michael@0 | 5240 | case SCTP_RANDOM: |
michael@0 | 5241 | if (padded_size > (sizeof(struct sctp_auth_random) + SCTP_RANDOM_MAX_SIZE)) { |
michael@0 | 5242 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error random %d\n", plen); |
michael@0 | 5243 | goto invalid_size; |
michael@0 | 5244 | } |
michael@0 | 5245 | at += padded_size; |
michael@0 | 5246 | break; |
michael@0 | 5247 | case SCTP_SET_PRIM_ADDR: |
michael@0 | 5248 | case SCTP_DEL_IP_ADDRESS: |
michael@0 | 5249 | case SCTP_ADD_IP_ADDRESS: |
michael@0 | 5250 | if ((padded_size != sizeof(struct sctp_asconf_addrv4_param)) && |
michael@0 | 5251 | (padded_size != sizeof(struct sctp_asconf_addr_param))) { |
michael@0 | 5252 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error setprim %d\n", plen); |
michael@0 | 5253 | goto invalid_size; |
michael@0 | 5254 | } |
michael@0 | 5255 | at += padded_size; |
michael@0 | 5256 | break; |
michael@0 | 5257 | /* Param's with a fixed size */ |
michael@0 | 5258 | case SCTP_IPV4_ADDRESS: |
michael@0 | 5259 | if (padded_size != sizeof(struct sctp_ipv4addr_param)) { |
michael@0 | 5260 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ipv4 addr %d\n", plen); |
michael@0 | 5261 | goto invalid_size; |
michael@0 | 5262 | } |
michael@0 | 5263 | at += padded_size; |
michael@0 | 5264 | break; |
michael@0 | 5265 | case SCTP_IPV6_ADDRESS: |
michael@0 | 5266 | if (padded_size != sizeof(struct sctp_ipv6addr_param)) { |
michael@0 | 5267 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ipv6 addr %d\n", plen); |
michael@0 | 5268 | goto invalid_size; |
michael@0 | 5269 | } |
michael@0 | 5270 | at += padded_size; |
michael@0 | 5271 | break; |
michael@0 | 5272 | case SCTP_COOKIE_PRESERVE: |
michael@0 | 5273 | if (padded_size != sizeof(struct sctp_cookie_perserve_param)) { |
michael@0 | 5274 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error cookie-preserve %d\n", plen); |
michael@0 | 5275 | goto invalid_size; |
michael@0 | 5276 | } |
michael@0 | 5277 | at += padded_size; |
michael@0 | 5278 | break; |
michael@0 | 5279 | case SCTP_HAS_NAT_SUPPORT: |
michael@0 | 5280 | *nat_friendly = 1; |
michael@0 | 5281 | /* fall through */ |
michael@0 | 5282 | case SCTP_PRSCTP_SUPPORTED: |
michael@0 | 5283 | |
michael@0 | 5284 | if (padded_size != sizeof(struct sctp_paramhdr)) { |
michael@0 | 5285 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error prsctp/nat support %d\n", plen); |
michael@0 | 5286 | goto invalid_size; |
michael@0 | 5287 | } |
michael@0 | 5288 | at += padded_size; |
michael@0 | 5289 | break; |
michael@0 | 5290 | case SCTP_ECN_CAPABLE: |
michael@0 | 5291 | if (padded_size != sizeof(struct sctp_ecn_supported_param)) { |
michael@0 | 5292 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ecn %d\n", plen); |
michael@0 | 5293 | goto invalid_size; |
michael@0 | 5294 | } |
michael@0 | 5295 | at += padded_size; |
michael@0 | 5296 | break; |
michael@0 | 5297 | case SCTP_ULP_ADAPTATION: |
michael@0 | 5298 | if (padded_size != sizeof(struct sctp_adaptation_layer_indication)) { |
michael@0 | 5299 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error adapatation %d\n", plen); |
michael@0 | 5300 | goto invalid_size; |
michael@0 | 5301 | } |
michael@0 | 5302 | at += padded_size; |
michael@0 | 5303 | break; |
michael@0 | 5304 | case SCTP_SUCCESS_REPORT: |
michael@0 | 5305 | if (padded_size != sizeof(struct sctp_asconf_paramhdr)) { |
michael@0 | 5306 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error success %d\n", plen); |
michael@0 | 5307 | goto invalid_size; |
michael@0 | 5308 | } |
michael@0 | 5309 | at += padded_size; |
michael@0 | 5310 | break; |
michael@0 | 5311 | case SCTP_HOSTNAME_ADDRESS: |
michael@0 | 5312 | { |
michael@0 | 5313 | /* We can NOT handle HOST NAME addresses!! */ |
michael@0 | 5314 | int l_len; |
michael@0 | 5315 | |
michael@0 | 5316 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Can't handle hostname addresses.. abort processing\n"); |
michael@0 | 5317 | *abort_processing = 1; |
michael@0 | 5318 | if (op_err == NULL) { |
michael@0 | 5319 | /* Ok need to try to get a mbuf */ |
michael@0 | 5320 | #ifdef INET6 |
michael@0 | 5321 | l_len = sizeof(struct ip6_hdr) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
michael@0 | 5322 | #else |
michael@0 | 5323 | l_len = sizeof(struct ip) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
michael@0 | 5324 | #endif |
michael@0 | 5325 | l_len += plen; |
michael@0 | 5326 | l_len += sizeof(struct sctp_paramhdr); |
michael@0 | 5327 | op_err = sctp_get_mbuf_for_msg(l_len, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 5328 | if (op_err) { |
michael@0 | 5329 | SCTP_BUF_LEN(op_err) = 0; |
michael@0 | 5330 | /* |
michael@0 | 5331 | * pre-reserve space for ip and sctp |
michael@0 | 5332 | * header and chunk hdr |
michael@0 | 5333 | */ |
michael@0 | 5334 | #ifdef INET6 |
michael@0 | 5335 | SCTP_BUF_RESV_UF(op_err, sizeof(struct ip6_hdr)); |
michael@0 | 5336 | #else |
michael@0 | 5337 | SCTP_BUF_RESV_UF(op_err, sizeof(struct ip)); |
michael@0 | 5338 | #endif |
michael@0 | 5339 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctphdr)); |
michael@0 | 5340 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctp_chunkhdr)); |
michael@0 | 5341 | } |
michael@0 | 5342 | } |
michael@0 | 5343 | if (op_err) { |
michael@0 | 5344 | /* If we have space */ |
michael@0 | 5345 | struct sctp_paramhdr s; |
michael@0 | 5346 | |
michael@0 | 5347 | if (err_at % 4) { |
michael@0 | 5348 | uint32_t cpthis = 0; |
michael@0 | 5349 | |
michael@0 | 5350 | pad_needed = 4 - (err_at % 4); |
michael@0 | 5351 | m_copyback(op_err, err_at, pad_needed, (caddr_t)&cpthis); |
michael@0 | 5352 | err_at += pad_needed; |
michael@0 | 5353 | } |
michael@0 | 5354 | s.param_type = htons(SCTP_CAUSE_UNRESOLVABLE_ADDR); |
michael@0 | 5355 | s.param_length = htons(sizeof(s) + plen); |
michael@0 | 5356 | m_copyback(op_err, err_at, sizeof(s), (caddr_t)&s); |
michael@0 | 5357 | err_at += sizeof(s); |
michael@0 | 5358 | phdr = sctp_get_next_param(mat, at, (struct sctp_paramhdr *)tempbuf, min(sizeof(tempbuf),plen)); |
michael@0 | 5359 | if (phdr == NULL) { |
michael@0 | 5360 | sctp_m_freem(op_err); |
michael@0 | 5361 | /* |
michael@0 | 5362 | * we are out of memory but we still |
michael@0 | 5363 | * need to have a look at what to do |
michael@0 | 5364 | * (the system is in trouble |
michael@0 | 5365 | * though). |
michael@0 | 5366 | */ |
michael@0 | 5367 | return (NULL); |
michael@0 | 5368 | } |
michael@0 | 5369 | m_copyback(op_err, err_at, plen, (caddr_t)phdr); |
michael@0 | 5370 | } |
michael@0 | 5371 | return (op_err); |
michael@0 | 5372 | break; |
michael@0 | 5373 | } |
michael@0 | 5374 | default: |
michael@0 | 5375 | /* |
michael@0 | 5376 | * we do not recognize the parameter figure out what |
michael@0 | 5377 | * we do. |
michael@0 | 5378 | */ |
michael@0 | 5379 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Hit default param %x\n", ptype); |
michael@0 | 5380 | if ((ptype & 0x4000) == 0x4000) { |
michael@0 | 5381 | /* Report bit is set?? */ |
michael@0 | 5382 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "report op err\n"); |
michael@0 | 5383 | if (op_err == NULL) { |
michael@0 | 5384 | int l_len; |
michael@0 | 5385 | /* Ok need to try to get an mbuf */ |
michael@0 | 5386 | #ifdef INET6 |
michael@0 | 5387 | l_len = sizeof(struct ip6_hdr) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
michael@0 | 5388 | #else |
michael@0 | 5389 | l_len = sizeof(struct ip) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
michael@0 | 5390 | #endif |
michael@0 | 5391 | l_len += plen; |
michael@0 | 5392 | l_len += sizeof(struct sctp_paramhdr); |
michael@0 | 5393 | op_err = sctp_get_mbuf_for_msg(l_len, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 5394 | if (op_err) { |
michael@0 | 5395 | SCTP_BUF_LEN(op_err) = 0; |
michael@0 | 5396 | #ifdef INET6 |
michael@0 | 5397 | SCTP_BUF_RESV_UF(op_err, sizeof(struct ip6_hdr)); |
michael@0 | 5398 | #else |
michael@0 | 5399 | SCTP_BUF_RESV_UF(op_err, sizeof(struct ip)); |
michael@0 | 5400 | #endif |
michael@0 | 5401 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctphdr)); |
michael@0 | 5402 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctp_chunkhdr)); |
michael@0 | 5403 | } |
michael@0 | 5404 | } |
michael@0 | 5405 | if (op_err) { |
michael@0 | 5406 | /* If we have space */ |
michael@0 | 5407 | struct sctp_paramhdr s; |
michael@0 | 5408 | |
michael@0 | 5409 | if (err_at % 4) { |
michael@0 | 5410 | uint32_t cpthis = 0; |
michael@0 | 5411 | |
michael@0 | 5412 | pad_needed = 4 - (err_at % 4); |
michael@0 | 5413 | m_copyback(op_err, err_at, pad_needed, (caddr_t)&cpthis); |
michael@0 | 5414 | err_at += pad_needed; |
michael@0 | 5415 | } |
michael@0 | 5416 | s.param_type = htons(SCTP_UNRECOG_PARAM); |
michael@0 | 5417 | s.param_length = htons(sizeof(s) + plen); |
michael@0 | 5418 | m_copyback(op_err, err_at, sizeof(s), (caddr_t)&s); |
michael@0 | 5419 | err_at += sizeof(s); |
michael@0 | 5420 | if (plen > sizeof(tempbuf)) { |
michael@0 | 5421 | plen = sizeof(tempbuf); |
michael@0 | 5422 | } |
michael@0 | 5423 | phdr = sctp_get_next_param(mat, at, (struct sctp_paramhdr *)tempbuf, min(sizeof(tempbuf),plen)); |
michael@0 | 5424 | if (phdr == NULL) { |
michael@0 | 5425 | sctp_m_freem(op_err); |
michael@0 | 5426 | /* |
michael@0 | 5427 | * we are out of memory but |
michael@0 | 5428 | * we still need to have a |
michael@0 | 5429 | * look at what to do (the |
michael@0 | 5430 | * system is in trouble |
michael@0 | 5431 | * though). |
michael@0 | 5432 | */ |
michael@0 | 5433 | op_err = NULL; |
michael@0 | 5434 | goto more_processing; |
michael@0 | 5435 | } |
michael@0 | 5436 | m_copyback(op_err, err_at, plen, (caddr_t)phdr); |
michael@0 | 5437 | err_at += plen; |
michael@0 | 5438 | } |
michael@0 | 5439 | } |
michael@0 | 5440 | more_processing: |
michael@0 | 5441 | if ((ptype & 0x8000) == 0x0000) { |
michael@0 | 5442 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "stop proc\n"); |
michael@0 | 5443 | return (op_err); |
michael@0 | 5444 | } else { |
michael@0 | 5445 | /* skip this chunk and continue processing */ |
michael@0 | 5446 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "move on\n"); |
michael@0 | 5447 | at += SCTP_SIZE32(plen); |
michael@0 | 5448 | } |
michael@0 | 5449 | break; |
michael@0 | 5450 | |
michael@0 | 5451 | } |
michael@0 | 5452 | phdr = sctp_get_next_param(mat, at, ¶ms, sizeof(params)); |
michael@0 | 5453 | } |
michael@0 | 5454 | return (op_err); |
michael@0 | 5455 | invalid_size: |
michael@0 | 5456 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "abort flag set\n"); |
michael@0 | 5457 | *abort_processing = 1; |
michael@0 | 5458 | if ((op_err == NULL) && phdr) { |
michael@0 | 5459 | int l_len; |
michael@0 | 5460 | #ifdef INET6 |
michael@0 | 5461 | l_len = sizeof(struct ip6_hdr) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
michael@0 | 5462 | #else |
michael@0 | 5463 | l_len = sizeof(struct ip) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
michael@0 | 5464 | #endif |
michael@0 | 5465 | l_len += (2 * sizeof(struct sctp_paramhdr)); |
michael@0 | 5466 | op_err = sctp_get_mbuf_for_msg(l_len, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 5467 | if (op_err) { |
michael@0 | 5468 | SCTP_BUF_LEN(op_err) = 0; |
michael@0 | 5469 | #ifdef INET6 |
michael@0 | 5470 | SCTP_BUF_RESV_UF(op_err, sizeof(struct ip6_hdr)); |
michael@0 | 5471 | #else |
michael@0 | 5472 | SCTP_BUF_RESV_UF(op_err, sizeof(struct ip)); |
michael@0 | 5473 | #endif |
michael@0 | 5474 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctphdr)); |
michael@0 | 5475 | SCTP_BUF_RESV_UF(op_err, sizeof(struct sctp_chunkhdr)); |
michael@0 | 5476 | } |
michael@0 | 5477 | } |
michael@0 | 5478 | if ((op_err) && phdr) { |
michael@0 | 5479 | struct sctp_paramhdr s; |
michael@0 | 5480 | |
michael@0 | 5481 | if (err_at % 4) { |
michael@0 | 5482 | uint32_t cpthis = 0; |
michael@0 | 5483 | |
michael@0 | 5484 | pad_needed = 4 - (err_at % 4); |
michael@0 | 5485 | m_copyback(op_err, err_at, pad_needed, (caddr_t)&cpthis); |
michael@0 | 5486 | err_at += pad_needed; |
michael@0 | 5487 | } |
michael@0 | 5488 | s.param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); |
michael@0 | 5489 | s.param_length = htons(sizeof(s) + sizeof(struct sctp_paramhdr)); |
michael@0 | 5490 | m_copyback(op_err, err_at, sizeof(s), (caddr_t)&s); |
michael@0 | 5491 | err_at += sizeof(s); |
michael@0 | 5492 | /* Only copy back the p-hdr that caused the issue */ |
michael@0 | 5493 | m_copyback(op_err, err_at, sizeof(struct sctp_paramhdr), (caddr_t)phdr); |
michael@0 | 5494 | } |
michael@0 | 5495 | return (op_err); |
michael@0 | 5496 | } |
michael@0 | 5497 | |
michael@0 | 5498 | static int |
michael@0 | 5499 | sctp_are_there_new_addresses(struct sctp_association *asoc, |
michael@0 | 5500 | struct mbuf *in_initpkt, int offset, struct sockaddr *src) |
michael@0 | 5501 | { |
michael@0 | 5502 | /* |
michael@0 | 5503 | * Given a INIT packet, look through the packet to verify that there |
michael@0 | 5504 | * are NO new addresses. As we go through the parameters add reports |
michael@0 | 5505 | * of any un-understood parameters that require an error. Also we |
michael@0 | 5506 | * must return (1) to drop the packet if we see a un-understood |
michael@0 | 5507 | * parameter that tells us to drop the chunk. |
michael@0 | 5508 | */ |
michael@0 | 5509 | struct sockaddr *sa_touse; |
michael@0 | 5510 | struct sockaddr *sa; |
michael@0 | 5511 | struct sctp_paramhdr *phdr, params; |
michael@0 | 5512 | uint16_t ptype, plen; |
michael@0 | 5513 | uint8_t fnd; |
michael@0 | 5514 | struct sctp_nets *net; |
michael@0 | 5515 | #ifdef INET |
michael@0 | 5516 | struct sockaddr_in sin4, *sa4; |
michael@0 | 5517 | #endif |
michael@0 | 5518 | #ifdef INET6 |
michael@0 | 5519 | struct sockaddr_in6 sin6, *sa6; |
michael@0 | 5520 | #endif |
michael@0 | 5521 | |
michael@0 | 5522 | #ifdef INET |
michael@0 | 5523 | memset(&sin4, 0, sizeof(sin4)); |
michael@0 | 5524 | sin4.sin_family = AF_INET; |
michael@0 | 5525 | #ifdef HAVE_SIN_LEN |
michael@0 | 5526 | sin4.sin_len = sizeof(sin4); |
michael@0 | 5527 | #endif |
michael@0 | 5528 | #endif |
michael@0 | 5529 | #ifdef INET6 |
michael@0 | 5530 | memset(&sin6, 0, sizeof(sin6)); |
michael@0 | 5531 | sin6.sin6_family = AF_INET6; |
michael@0 | 5532 | #ifdef HAVE_SIN6_LEN |
michael@0 | 5533 | sin6.sin6_len = sizeof(sin6); |
michael@0 | 5534 | #endif |
michael@0 | 5535 | #endif |
michael@0 | 5536 | /* First what about the src address of the pkt ? */ |
michael@0 | 5537 | fnd = 0; |
michael@0 | 5538 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 5539 | sa = (struct sockaddr *)&net->ro._l_addr; |
michael@0 | 5540 | if (sa->sa_family == src->sa_family) { |
michael@0 | 5541 | #ifdef INET |
michael@0 | 5542 | if (sa->sa_family == AF_INET) { |
michael@0 | 5543 | struct sockaddr_in *src4; |
michael@0 | 5544 | |
michael@0 | 5545 | sa4 = (struct sockaddr_in *)sa; |
michael@0 | 5546 | src4 = (struct sockaddr_in *)src; |
michael@0 | 5547 | if (sa4->sin_addr.s_addr == src4->sin_addr.s_addr) { |
michael@0 | 5548 | fnd = 1; |
michael@0 | 5549 | break; |
michael@0 | 5550 | } |
michael@0 | 5551 | } |
michael@0 | 5552 | #endif |
michael@0 | 5553 | #ifdef INET6 |
michael@0 | 5554 | if (sa->sa_family == AF_INET6) { |
michael@0 | 5555 | struct sockaddr_in6 *src6; |
michael@0 | 5556 | |
michael@0 | 5557 | sa6 = (struct sockaddr_in6 *)sa; |
michael@0 | 5558 | src6 = (struct sockaddr_in6 *)src; |
michael@0 | 5559 | if (SCTP6_ARE_ADDR_EQUAL(sa6, src6)) { |
michael@0 | 5560 | fnd = 1; |
michael@0 | 5561 | break; |
michael@0 | 5562 | } |
michael@0 | 5563 | } |
michael@0 | 5564 | #endif |
michael@0 | 5565 | } |
michael@0 | 5566 | } |
michael@0 | 5567 | if (fnd == 0) { |
michael@0 | 5568 | /* New address added! no need to look futher. */ |
michael@0 | 5569 | return (1); |
michael@0 | 5570 | } |
michael@0 | 5571 | /* Ok so far lets munge through the rest of the packet */ |
michael@0 | 5572 | offset += sizeof(struct sctp_init_chunk); |
michael@0 | 5573 | phdr = sctp_get_next_param(in_initpkt, offset, ¶ms, sizeof(params)); |
michael@0 | 5574 | while (phdr) { |
michael@0 | 5575 | sa_touse = NULL; |
michael@0 | 5576 | ptype = ntohs(phdr->param_type); |
michael@0 | 5577 | plen = ntohs(phdr->param_length); |
michael@0 | 5578 | switch (ptype) { |
michael@0 | 5579 | #ifdef INET |
michael@0 | 5580 | case SCTP_IPV4_ADDRESS: |
michael@0 | 5581 | { |
michael@0 | 5582 | struct sctp_ipv4addr_param *p4, p4_buf; |
michael@0 | 5583 | |
michael@0 | 5584 | phdr = sctp_get_next_param(in_initpkt, offset, |
michael@0 | 5585 | (struct sctp_paramhdr *)&p4_buf, sizeof(p4_buf)); |
michael@0 | 5586 | if (plen != sizeof(struct sctp_ipv4addr_param) || |
michael@0 | 5587 | phdr == NULL) { |
michael@0 | 5588 | return (1); |
michael@0 | 5589 | } |
michael@0 | 5590 | p4 = (struct sctp_ipv4addr_param *)phdr; |
michael@0 | 5591 | sin4.sin_addr.s_addr = p4->addr; |
michael@0 | 5592 | sa_touse = (struct sockaddr *)&sin4; |
michael@0 | 5593 | break; |
michael@0 | 5594 | } |
michael@0 | 5595 | #endif |
michael@0 | 5596 | #ifdef INET6 |
michael@0 | 5597 | case SCTP_IPV6_ADDRESS: |
michael@0 | 5598 | { |
michael@0 | 5599 | struct sctp_ipv6addr_param *p6, p6_buf; |
michael@0 | 5600 | |
michael@0 | 5601 | phdr = sctp_get_next_param(in_initpkt, offset, |
michael@0 | 5602 | (struct sctp_paramhdr *)&p6_buf, sizeof(p6_buf)); |
michael@0 | 5603 | if (plen != sizeof(struct sctp_ipv6addr_param) || |
michael@0 | 5604 | phdr == NULL) { |
michael@0 | 5605 | return (1); |
michael@0 | 5606 | } |
michael@0 | 5607 | p6 = (struct sctp_ipv6addr_param *)phdr; |
michael@0 | 5608 | memcpy((caddr_t)&sin6.sin6_addr, p6->addr, |
michael@0 | 5609 | sizeof(p6->addr)); |
michael@0 | 5610 | sa_touse = (struct sockaddr *)&sin6; |
michael@0 | 5611 | break; |
michael@0 | 5612 | } |
michael@0 | 5613 | #endif |
michael@0 | 5614 | default: |
michael@0 | 5615 | sa_touse = NULL; |
michael@0 | 5616 | break; |
michael@0 | 5617 | } |
michael@0 | 5618 | if (sa_touse) { |
michael@0 | 5619 | /* ok, sa_touse points to one to check */ |
michael@0 | 5620 | fnd = 0; |
michael@0 | 5621 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 5622 | sa = (struct sockaddr *)&net->ro._l_addr; |
michael@0 | 5623 | if (sa->sa_family != sa_touse->sa_family) { |
michael@0 | 5624 | continue; |
michael@0 | 5625 | } |
michael@0 | 5626 | #ifdef INET |
michael@0 | 5627 | if (sa->sa_family == AF_INET) { |
michael@0 | 5628 | sa4 = (struct sockaddr_in *)sa; |
michael@0 | 5629 | if (sa4->sin_addr.s_addr == |
michael@0 | 5630 | sin4.sin_addr.s_addr) { |
michael@0 | 5631 | fnd = 1; |
michael@0 | 5632 | break; |
michael@0 | 5633 | } |
michael@0 | 5634 | } |
michael@0 | 5635 | #endif |
michael@0 | 5636 | #ifdef INET6 |
michael@0 | 5637 | if (sa->sa_family == AF_INET6) { |
michael@0 | 5638 | sa6 = (struct sockaddr_in6 *)sa; |
michael@0 | 5639 | if (SCTP6_ARE_ADDR_EQUAL( |
michael@0 | 5640 | sa6, &sin6)) { |
michael@0 | 5641 | fnd = 1; |
michael@0 | 5642 | break; |
michael@0 | 5643 | } |
michael@0 | 5644 | } |
michael@0 | 5645 | #endif |
michael@0 | 5646 | } |
michael@0 | 5647 | if (!fnd) { |
michael@0 | 5648 | /* New addr added! no need to look further */ |
michael@0 | 5649 | return (1); |
michael@0 | 5650 | } |
michael@0 | 5651 | } |
michael@0 | 5652 | offset += SCTP_SIZE32(plen); |
michael@0 | 5653 | phdr = sctp_get_next_param(in_initpkt, offset, ¶ms, sizeof(params)); |
michael@0 | 5654 | } |
michael@0 | 5655 | return (0); |
michael@0 | 5656 | } |
michael@0 | 5657 | |
michael@0 | 5658 | /* |
michael@0 | 5659 | * Given a MBUF chain that was sent into us containing an INIT. Build a |
michael@0 | 5660 | * INIT-ACK with COOKIE and send back. We assume that the in_initpkt has done |
michael@0 | 5661 | * a pullup to include IPv6/4header, SCTP header and initial part of INIT |
michael@0 | 5662 | * message (i.e. the struct sctp_init_msg). |
michael@0 | 5663 | */ |
michael@0 | 5664 | void |
michael@0 | 5665 | sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb, |
michael@0 | 5666 | struct mbuf *init_pkt, int iphlen, int offset, |
michael@0 | 5667 | struct sockaddr *src, struct sockaddr *dst, |
michael@0 | 5668 | struct sctphdr *sh, struct sctp_init_chunk *init_chk, |
michael@0 | 5669 | #if defined(__FreeBSD__) |
michael@0 | 5670 | uint8_t use_mflowid, uint32_t mflowid, |
michael@0 | 5671 | #endif |
michael@0 | 5672 | uint32_t vrf_id, uint16_t port, int hold_inp_lock) |
michael@0 | 5673 | { |
michael@0 | 5674 | struct sctp_association *asoc; |
michael@0 | 5675 | struct mbuf *m, *m_at, *m_tmp, *m_cookie, *op_err, *mp_last; |
michael@0 | 5676 | struct sctp_init_ack_chunk *initack; |
michael@0 | 5677 | struct sctp_adaptation_layer_indication *ali; |
michael@0 | 5678 | struct sctp_ecn_supported_param *ecn; |
michael@0 | 5679 | struct sctp_prsctp_supported_param *prsctp; |
michael@0 | 5680 | struct sctp_supported_chunk_types_param *pr_supported; |
michael@0 | 5681 | union sctp_sockstore *over_addr; |
michael@0 | 5682 | #ifdef INET |
michael@0 | 5683 | struct sockaddr_in *dst4 = (struct sockaddr_in *)dst; |
michael@0 | 5684 | struct sockaddr_in *src4 = (struct sockaddr_in *)src; |
michael@0 | 5685 | struct sockaddr_in *sin; |
michael@0 | 5686 | #endif |
michael@0 | 5687 | #ifdef INET6 |
michael@0 | 5688 | struct sockaddr_in6 *dst6 = (struct sockaddr_in6 *)dst; |
michael@0 | 5689 | struct sockaddr_in6 *src6 = (struct sockaddr_in6 *)src; |
michael@0 | 5690 | struct sockaddr_in6 *sin6; |
michael@0 | 5691 | #endif |
michael@0 | 5692 | #if defined(__Userspace__) |
michael@0 | 5693 | struct sockaddr_conn *dstconn = (struct sockaddr_conn *)dst; |
michael@0 | 5694 | struct sockaddr_conn *srcconn = (struct sockaddr_conn *)src; |
michael@0 | 5695 | struct sockaddr_conn *sconn; |
michael@0 | 5696 | #endif |
michael@0 | 5697 | struct sockaddr *to; |
michael@0 | 5698 | struct sctp_state_cookie stc; |
michael@0 | 5699 | struct sctp_nets *net = NULL; |
michael@0 | 5700 | uint8_t *signature = NULL; |
michael@0 | 5701 | int cnt_inits_to = 0; |
michael@0 | 5702 | uint16_t his_limit, i_want; |
michael@0 | 5703 | int abort_flag, padval; |
michael@0 | 5704 | int num_ext; |
michael@0 | 5705 | int p_len; |
michael@0 | 5706 | int nat_friendly = 0; |
michael@0 | 5707 | struct socket *so; |
michael@0 | 5708 | |
michael@0 | 5709 | if (stcb) { |
michael@0 | 5710 | asoc = &stcb->asoc; |
michael@0 | 5711 | } else { |
michael@0 | 5712 | asoc = NULL; |
michael@0 | 5713 | } |
michael@0 | 5714 | mp_last = NULL; |
michael@0 | 5715 | if ((asoc != NULL) && |
michael@0 | 5716 | (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) && |
michael@0 | 5717 | (sctp_are_there_new_addresses(asoc, init_pkt, offset, src))) { |
michael@0 | 5718 | /* new addresses, out of here in non-cookie-wait states */ |
michael@0 | 5719 | /* |
michael@0 | 5720 | * Send a ABORT, we don't add the new address error clause |
michael@0 | 5721 | * though we even set the T bit and copy in the 0 tag.. this |
michael@0 | 5722 | * looks no different than if no listener was present. |
michael@0 | 5723 | */ |
michael@0 | 5724 | sctp_send_abort(init_pkt, iphlen, src, dst, sh, 0, NULL, |
michael@0 | 5725 | #if defined(__FreeBSD__) |
michael@0 | 5726 | use_mflowid, mflowid, |
michael@0 | 5727 | #endif |
michael@0 | 5728 | vrf_id, port); |
michael@0 | 5729 | return; |
michael@0 | 5730 | } |
michael@0 | 5731 | abort_flag = 0; |
michael@0 | 5732 | op_err = sctp_arethere_unrecognized_parameters(init_pkt, |
michael@0 | 5733 | (offset + sizeof(struct sctp_init_chunk)), |
michael@0 | 5734 | &abort_flag, (struct sctp_chunkhdr *)init_chk, &nat_friendly); |
michael@0 | 5735 | if (abort_flag) { |
michael@0 | 5736 | do_a_abort: |
michael@0 | 5737 | sctp_send_abort(init_pkt, iphlen, src, dst, sh, |
michael@0 | 5738 | init_chk->init.initiate_tag, op_err, |
michael@0 | 5739 | #if defined(__FreeBSD__) |
michael@0 | 5740 | use_mflowid, mflowid, |
michael@0 | 5741 | #endif |
michael@0 | 5742 | vrf_id, port); |
michael@0 | 5743 | return; |
michael@0 | 5744 | } |
michael@0 | 5745 | m = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 5746 | if (m == NULL) { |
michael@0 | 5747 | /* No memory, INIT timer will re-attempt. */ |
michael@0 | 5748 | if (op_err) |
michael@0 | 5749 | sctp_m_freem(op_err); |
michael@0 | 5750 | return; |
michael@0 | 5751 | } |
michael@0 | 5752 | SCTP_BUF_LEN(m) = sizeof(struct sctp_init_chunk); |
michael@0 | 5753 | |
michael@0 | 5754 | /* |
michael@0 | 5755 | * We might not overwrite the identification[] completely and on |
michael@0 | 5756 | * some platforms time_entered will contain some padding. |
michael@0 | 5757 | * Therefore zero out the cookie to avoid putting |
michael@0 | 5758 | * uninitialized memory on the wire. |
michael@0 | 5759 | */ |
michael@0 | 5760 | memset(&stc, 0, sizeof(struct sctp_state_cookie)); |
michael@0 | 5761 | |
michael@0 | 5762 | /* the time I built cookie */ |
michael@0 | 5763 | (void)SCTP_GETTIME_TIMEVAL(&stc.time_entered); |
michael@0 | 5764 | |
michael@0 | 5765 | /* populate any tie tags */ |
michael@0 | 5766 | if (asoc != NULL) { |
michael@0 | 5767 | /* unlock before tag selections */ |
michael@0 | 5768 | stc.tie_tag_my_vtag = asoc->my_vtag_nonce; |
michael@0 | 5769 | stc.tie_tag_peer_vtag = asoc->peer_vtag_nonce; |
michael@0 | 5770 | stc.cookie_life = asoc->cookie_life; |
michael@0 | 5771 | net = asoc->primary_destination; |
michael@0 | 5772 | } else { |
michael@0 | 5773 | stc.tie_tag_my_vtag = 0; |
michael@0 | 5774 | stc.tie_tag_peer_vtag = 0; |
michael@0 | 5775 | /* life I will award this cookie */ |
michael@0 | 5776 | stc.cookie_life = inp->sctp_ep.def_cookie_life; |
michael@0 | 5777 | } |
michael@0 | 5778 | |
michael@0 | 5779 | /* copy in the ports for later check */ |
michael@0 | 5780 | stc.myport = sh->dest_port; |
michael@0 | 5781 | stc.peerport = sh->src_port; |
michael@0 | 5782 | |
michael@0 | 5783 | /* |
michael@0 | 5784 | * If we wanted to honor cookie life extentions, we would add to |
michael@0 | 5785 | * stc.cookie_life. For now we should NOT honor any extension |
michael@0 | 5786 | */ |
michael@0 | 5787 | stc.site_scope = stc.local_scope = stc.loopback_scope = 0; |
michael@0 | 5788 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
michael@0 | 5789 | stc.ipv6_addr_legal = 1; |
michael@0 | 5790 | if (SCTP_IPV6_V6ONLY(inp)) { |
michael@0 | 5791 | stc.ipv4_addr_legal = 0; |
michael@0 | 5792 | } else { |
michael@0 | 5793 | stc.ipv4_addr_legal = 1; |
michael@0 | 5794 | } |
michael@0 | 5795 | #if defined(__Userspace__) |
michael@0 | 5796 | stc.conn_addr_legal = 0; |
michael@0 | 5797 | #endif |
michael@0 | 5798 | } else { |
michael@0 | 5799 | stc.ipv6_addr_legal = 0; |
michael@0 | 5800 | #if defined(__Userspace__) |
michael@0 | 5801 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) { |
michael@0 | 5802 | stc.conn_addr_legal = 1; |
michael@0 | 5803 | stc.ipv4_addr_legal = 0; |
michael@0 | 5804 | } else { |
michael@0 | 5805 | stc.conn_addr_legal = 0; |
michael@0 | 5806 | stc.ipv4_addr_legal = 1; |
michael@0 | 5807 | } |
michael@0 | 5808 | #else |
michael@0 | 5809 | stc.ipv4_addr_legal = 1; |
michael@0 | 5810 | #endif |
michael@0 | 5811 | } |
michael@0 | 5812 | #ifdef SCTP_DONT_DO_PRIVADDR_SCOPE |
michael@0 | 5813 | stc.ipv4_scope = 1; |
michael@0 | 5814 | #else |
michael@0 | 5815 | stc.ipv4_scope = 0; |
michael@0 | 5816 | #endif |
michael@0 | 5817 | if (net == NULL) { |
michael@0 | 5818 | to = src; |
michael@0 | 5819 | switch (dst->sa_family) { |
michael@0 | 5820 | #ifdef INET |
michael@0 | 5821 | case AF_INET: |
michael@0 | 5822 | { |
michael@0 | 5823 | /* lookup address */ |
michael@0 | 5824 | stc.address[0] = src4->sin_addr.s_addr; |
michael@0 | 5825 | stc.address[1] = 0; |
michael@0 | 5826 | stc.address[2] = 0; |
michael@0 | 5827 | stc.address[3] = 0; |
michael@0 | 5828 | stc.addr_type = SCTP_IPV4_ADDRESS; |
michael@0 | 5829 | /* local from address */ |
michael@0 | 5830 | stc.laddress[0] = dst4->sin_addr.s_addr; |
michael@0 | 5831 | stc.laddress[1] = 0; |
michael@0 | 5832 | stc.laddress[2] = 0; |
michael@0 | 5833 | stc.laddress[3] = 0; |
michael@0 | 5834 | stc.laddr_type = SCTP_IPV4_ADDRESS; |
michael@0 | 5835 | /* scope_id is only for v6 */ |
michael@0 | 5836 | stc.scope_id = 0; |
michael@0 | 5837 | #ifndef SCTP_DONT_DO_PRIVADDR_SCOPE |
michael@0 | 5838 | if (IN4_ISPRIVATE_ADDRESS(&src4->sin_addr)) { |
michael@0 | 5839 | stc.ipv4_scope = 1; |
michael@0 | 5840 | } |
michael@0 | 5841 | #else |
michael@0 | 5842 | stc.ipv4_scope = 1; |
michael@0 | 5843 | #endif /* SCTP_DONT_DO_PRIVADDR_SCOPE */ |
michael@0 | 5844 | /* Must use the address in this case */ |
michael@0 | 5845 | if (sctp_is_address_on_local_host(src, vrf_id)) { |
michael@0 | 5846 | stc.loopback_scope = 1; |
michael@0 | 5847 | stc.ipv4_scope = 1; |
michael@0 | 5848 | stc.site_scope = 1; |
michael@0 | 5849 | stc.local_scope = 0; |
michael@0 | 5850 | } |
michael@0 | 5851 | break; |
michael@0 | 5852 | } |
michael@0 | 5853 | #endif |
michael@0 | 5854 | #ifdef INET6 |
michael@0 | 5855 | case AF_INET6: |
michael@0 | 5856 | { |
michael@0 | 5857 | stc.addr_type = SCTP_IPV6_ADDRESS; |
michael@0 | 5858 | memcpy(&stc.address, &src6->sin6_addr, sizeof(struct in6_addr)); |
michael@0 | 5859 | #if defined(__FreeBSD__) && (((__FreeBSD_version < 900000) && (__FreeBSD_version >= 804000)) || (__FreeBSD_version > 900000)) |
michael@0 | 5860 | stc.scope_id = in6_getscope(&src6->sin6_addr); |
michael@0 | 5861 | #else |
michael@0 | 5862 | stc.scope_id = 0; |
michael@0 | 5863 | #endif |
michael@0 | 5864 | if (sctp_is_address_on_local_host(src, vrf_id)) { |
michael@0 | 5865 | stc.loopback_scope = 1; |
michael@0 | 5866 | stc.local_scope = 0; |
michael@0 | 5867 | stc.site_scope = 1; |
michael@0 | 5868 | stc.ipv4_scope = 1; |
michael@0 | 5869 | } else if (IN6_IS_ADDR_LINKLOCAL(&src6->sin6_addr)) { |
michael@0 | 5870 | /* |
michael@0 | 5871 | * If the new destination is a LINK_LOCAL we |
michael@0 | 5872 | * must have common both site and local |
michael@0 | 5873 | * scope. Don't set local scope though since |
michael@0 | 5874 | * we must depend on the source to be added |
michael@0 | 5875 | * implicitly. We cannot assure just because |
michael@0 | 5876 | * we share one link that all links are |
michael@0 | 5877 | * common. |
michael@0 | 5878 | */ |
michael@0 | 5879 | #if defined(__APPLE__) |
michael@0 | 5880 | /* Mac OS X currently doesn't have in6_getscope() */ |
michael@0 | 5881 | stc.scope_id = src6->sin6_addr.s6_addr16[1]; |
michael@0 | 5882 | #endif |
michael@0 | 5883 | stc.local_scope = 0; |
michael@0 | 5884 | stc.site_scope = 1; |
michael@0 | 5885 | stc.ipv4_scope = 1; |
michael@0 | 5886 | /* |
michael@0 | 5887 | * we start counting for the private address |
michael@0 | 5888 | * stuff at 1. since the link local we |
michael@0 | 5889 | * source from won't show up in our scoped |
michael@0 | 5890 | * count. |
michael@0 | 5891 | */ |
michael@0 | 5892 | cnt_inits_to = 1; |
michael@0 | 5893 | /* pull out the scope_id from incoming pkt */ |
michael@0 | 5894 | } else if (IN6_IS_ADDR_SITELOCAL(&src6->sin6_addr)) { |
michael@0 | 5895 | /* |
michael@0 | 5896 | * If the new destination is SITE_LOCAL then |
michael@0 | 5897 | * we must have site scope in common. |
michael@0 | 5898 | */ |
michael@0 | 5899 | stc.site_scope = 1; |
michael@0 | 5900 | } |
michael@0 | 5901 | memcpy(&stc.laddress, &dst6->sin6_addr, sizeof(struct in6_addr)); |
michael@0 | 5902 | stc.laddr_type = SCTP_IPV6_ADDRESS; |
michael@0 | 5903 | break; |
michael@0 | 5904 | } |
michael@0 | 5905 | #endif |
michael@0 | 5906 | #if defined(__Userspace__) |
michael@0 | 5907 | case AF_CONN: |
michael@0 | 5908 | { |
michael@0 | 5909 | /* lookup address */ |
michael@0 | 5910 | stc.address[0] = 0; |
michael@0 | 5911 | stc.address[1] = 0; |
michael@0 | 5912 | stc.address[2] = 0; |
michael@0 | 5913 | stc.address[3] = 0; |
michael@0 | 5914 | memcpy(&stc.address, &srcconn->sconn_addr, sizeof(void *)); |
michael@0 | 5915 | stc.addr_type = SCTP_CONN_ADDRESS; |
michael@0 | 5916 | /* local from address */ |
michael@0 | 5917 | stc.laddress[0] = 0; |
michael@0 | 5918 | stc.laddress[1] = 0; |
michael@0 | 5919 | stc.laddress[2] = 0; |
michael@0 | 5920 | stc.laddress[3] = 0; |
michael@0 | 5921 | memcpy(&stc.laddress, &dstconn->sconn_addr, sizeof(void *)); |
michael@0 | 5922 | stc.laddr_type = SCTP_CONN_ADDRESS; |
michael@0 | 5923 | /* scope_id is only for v6 */ |
michael@0 | 5924 | stc.scope_id = 0; |
michael@0 | 5925 | break; |
michael@0 | 5926 | } |
michael@0 | 5927 | #endif |
michael@0 | 5928 | default: |
michael@0 | 5929 | /* TSNH */ |
michael@0 | 5930 | goto do_a_abort; |
michael@0 | 5931 | break; |
michael@0 | 5932 | } |
michael@0 | 5933 | } else { |
michael@0 | 5934 | /* set the scope per the existing tcb */ |
michael@0 | 5935 | |
michael@0 | 5936 | #ifdef INET6 |
michael@0 | 5937 | struct sctp_nets *lnet; |
michael@0 | 5938 | #endif |
michael@0 | 5939 | |
michael@0 | 5940 | stc.loopback_scope = asoc->scope.loopback_scope; |
michael@0 | 5941 | stc.ipv4_scope = asoc->scope.ipv4_local_scope; |
michael@0 | 5942 | stc.site_scope = asoc->scope.site_scope; |
michael@0 | 5943 | stc.local_scope = asoc->scope.local_scope; |
michael@0 | 5944 | #ifdef INET6 |
michael@0 | 5945 | /* Why do we not consider IPv4 LL addresses? */ |
michael@0 | 5946 | TAILQ_FOREACH(lnet, &asoc->nets, sctp_next) { |
michael@0 | 5947 | if (lnet->ro._l_addr.sin6.sin6_family == AF_INET6) { |
michael@0 | 5948 | if (IN6_IS_ADDR_LINKLOCAL(&lnet->ro._l_addr.sin6.sin6_addr)) { |
michael@0 | 5949 | /* |
michael@0 | 5950 | * if we have a LL address, start |
michael@0 | 5951 | * counting at 1. |
michael@0 | 5952 | */ |
michael@0 | 5953 | cnt_inits_to = 1; |
michael@0 | 5954 | } |
michael@0 | 5955 | } |
michael@0 | 5956 | } |
michael@0 | 5957 | #endif |
michael@0 | 5958 | /* use the net pointer */ |
michael@0 | 5959 | to = (struct sockaddr *)&net->ro._l_addr; |
michael@0 | 5960 | switch (to->sa_family) { |
michael@0 | 5961 | #ifdef INET |
michael@0 | 5962 | case AF_INET: |
michael@0 | 5963 | sin = (struct sockaddr_in *)to; |
michael@0 | 5964 | stc.address[0] = sin->sin_addr.s_addr; |
michael@0 | 5965 | stc.address[1] = 0; |
michael@0 | 5966 | stc.address[2] = 0; |
michael@0 | 5967 | stc.address[3] = 0; |
michael@0 | 5968 | stc.addr_type = SCTP_IPV4_ADDRESS; |
michael@0 | 5969 | if (net->src_addr_selected == 0) { |
michael@0 | 5970 | /* |
michael@0 | 5971 | * strange case here, the INIT should have |
michael@0 | 5972 | * did the selection. |
michael@0 | 5973 | */ |
michael@0 | 5974 | net->ro._s_addr = sctp_source_address_selection(inp, |
michael@0 | 5975 | stcb, (sctp_route_t *)&net->ro, |
michael@0 | 5976 | net, 0, vrf_id); |
michael@0 | 5977 | if (net->ro._s_addr == NULL) |
michael@0 | 5978 | return; |
michael@0 | 5979 | |
michael@0 | 5980 | net->src_addr_selected = 1; |
michael@0 | 5981 | |
michael@0 | 5982 | } |
michael@0 | 5983 | stc.laddress[0] = net->ro._s_addr->address.sin.sin_addr.s_addr; |
michael@0 | 5984 | stc.laddress[1] = 0; |
michael@0 | 5985 | stc.laddress[2] = 0; |
michael@0 | 5986 | stc.laddress[3] = 0; |
michael@0 | 5987 | stc.laddr_type = SCTP_IPV4_ADDRESS; |
michael@0 | 5988 | /* scope_id is only for v6 */ |
michael@0 | 5989 | stc.scope_id = 0; |
michael@0 | 5990 | break; |
michael@0 | 5991 | #endif |
michael@0 | 5992 | #ifdef INET6 |
michael@0 | 5993 | case AF_INET6: |
michael@0 | 5994 | sin6 = (struct sockaddr_in6 *)to; |
michael@0 | 5995 | memcpy(&stc.address, &sin6->sin6_addr, |
michael@0 | 5996 | sizeof(struct in6_addr)); |
michael@0 | 5997 | stc.addr_type = SCTP_IPV6_ADDRESS; |
michael@0 | 5998 | stc.scope_id = sin6->sin6_scope_id; |
michael@0 | 5999 | if (net->src_addr_selected == 0) { |
michael@0 | 6000 | /* |
michael@0 | 6001 | * strange case here, the INIT should have |
michael@0 | 6002 | * done the selection. |
michael@0 | 6003 | */ |
michael@0 | 6004 | net->ro._s_addr = sctp_source_address_selection(inp, |
michael@0 | 6005 | stcb, (sctp_route_t *)&net->ro, |
michael@0 | 6006 | net, 0, vrf_id); |
michael@0 | 6007 | if (net->ro._s_addr == NULL) |
michael@0 | 6008 | return; |
michael@0 | 6009 | |
michael@0 | 6010 | net->src_addr_selected = 1; |
michael@0 | 6011 | } |
michael@0 | 6012 | memcpy(&stc.laddress, &net->ro._s_addr->address.sin6.sin6_addr, |
michael@0 | 6013 | sizeof(struct in6_addr)); |
michael@0 | 6014 | stc.laddr_type = SCTP_IPV6_ADDRESS; |
michael@0 | 6015 | break; |
michael@0 | 6016 | #endif |
michael@0 | 6017 | #if defined(__Userspace__) |
michael@0 | 6018 | case AF_CONN: |
michael@0 | 6019 | sconn = (struct sockaddr_conn *)to; |
michael@0 | 6020 | stc.address[0] = 0; |
michael@0 | 6021 | stc.address[1] = 0; |
michael@0 | 6022 | stc.address[2] = 0; |
michael@0 | 6023 | stc.address[3] = 0; |
michael@0 | 6024 | memcpy(&stc.address, &sconn->sconn_addr, sizeof(void *)); |
michael@0 | 6025 | stc.addr_type = SCTP_CONN_ADDRESS; |
michael@0 | 6026 | stc.laddress[0] = 0; |
michael@0 | 6027 | stc.laddress[1] = 0; |
michael@0 | 6028 | stc.laddress[2] = 0; |
michael@0 | 6029 | stc.laddress[3] = 0; |
michael@0 | 6030 | memcpy(&stc.laddress, &sconn->sconn_addr, sizeof(void *)); |
michael@0 | 6031 | stc.laddr_type = SCTP_CONN_ADDRESS; |
michael@0 | 6032 | stc.scope_id = 0; |
michael@0 | 6033 | break; |
michael@0 | 6034 | #endif |
michael@0 | 6035 | } |
michael@0 | 6036 | } |
michael@0 | 6037 | /* Now lets put the SCTP header in place */ |
michael@0 | 6038 | initack = mtod(m, struct sctp_init_ack_chunk *); |
michael@0 | 6039 | /* Save it off for quick ref */ |
michael@0 | 6040 | stc.peers_vtag = init_chk->init.initiate_tag; |
michael@0 | 6041 | /* who are we */ |
michael@0 | 6042 | memcpy(stc.identification, SCTP_VERSION_STRING, |
michael@0 | 6043 | min(strlen(SCTP_VERSION_STRING), sizeof(stc.identification))); |
michael@0 | 6044 | memset(stc.reserved, 0, SCTP_RESERVE_SPACE); |
michael@0 | 6045 | /* now the chunk header */ |
michael@0 | 6046 | initack->ch.chunk_type = SCTP_INITIATION_ACK; |
michael@0 | 6047 | initack->ch.chunk_flags = 0; |
michael@0 | 6048 | /* fill in later from mbuf we build */ |
michael@0 | 6049 | initack->ch.chunk_length = 0; |
michael@0 | 6050 | /* place in my tag */ |
michael@0 | 6051 | if ((asoc != NULL) && |
michael@0 | 6052 | ((SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_WAIT) || |
michael@0 | 6053 | (SCTP_GET_STATE(asoc) == SCTP_STATE_INUSE) || |
michael@0 | 6054 | (SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_ECHOED))) { |
michael@0 | 6055 | /* re-use the v-tags and init-seq here */ |
michael@0 | 6056 | initack->init.initiate_tag = htonl(asoc->my_vtag); |
michael@0 | 6057 | initack->init.initial_tsn = htonl(asoc->init_seq_number); |
michael@0 | 6058 | } else { |
michael@0 | 6059 | uint32_t vtag, itsn; |
michael@0 | 6060 | if (hold_inp_lock) { |
michael@0 | 6061 | SCTP_INP_INCR_REF(inp); |
michael@0 | 6062 | SCTP_INP_RUNLOCK(inp); |
michael@0 | 6063 | } |
michael@0 | 6064 | if (asoc) { |
michael@0 | 6065 | atomic_add_int(&asoc->refcnt, 1); |
michael@0 | 6066 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 6067 | new_tag: |
michael@0 | 6068 | vtag = sctp_select_a_tag(inp, inp->sctp_lport, sh->src_port, 1); |
michael@0 | 6069 | if ((asoc->peer_supports_nat) && (vtag == asoc->my_vtag)) { |
michael@0 | 6070 | /* Got a duplicate vtag on some guy behind a nat |
michael@0 | 6071 | * make sure we don't use it. |
michael@0 | 6072 | */ |
michael@0 | 6073 | goto new_tag; |
michael@0 | 6074 | } |
michael@0 | 6075 | initack->init.initiate_tag = htonl(vtag); |
michael@0 | 6076 | /* get a TSN to use too */ |
michael@0 | 6077 | itsn = sctp_select_initial_TSN(&inp->sctp_ep); |
michael@0 | 6078 | initack->init.initial_tsn = htonl(itsn); |
michael@0 | 6079 | SCTP_TCB_LOCK(stcb); |
michael@0 | 6080 | atomic_add_int(&asoc->refcnt, -1); |
michael@0 | 6081 | } else { |
michael@0 | 6082 | vtag = sctp_select_a_tag(inp, inp->sctp_lport, sh->src_port, 1); |
michael@0 | 6083 | initack->init.initiate_tag = htonl(vtag); |
michael@0 | 6084 | /* get a TSN to use too */ |
michael@0 | 6085 | initack->init.initial_tsn = htonl(sctp_select_initial_TSN(&inp->sctp_ep)); |
michael@0 | 6086 | } |
michael@0 | 6087 | if (hold_inp_lock) { |
michael@0 | 6088 | SCTP_INP_RLOCK(inp); |
michael@0 | 6089 | SCTP_INP_DECR_REF(inp); |
michael@0 | 6090 | } |
michael@0 | 6091 | } |
michael@0 | 6092 | /* save away my tag to */ |
michael@0 | 6093 | stc.my_vtag = initack->init.initiate_tag; |
michael@0 | 6094 | |
michael@0 | 6095 | /* set up some of the credits. */ |
michael@0 | 6096 | so = inp->sctp_socket; |
michael@0 | 6097 | if (so == NULL) { |
michael@0 | 6098 | /* memory problem */ |
michael@0 | 6099 | sctp_m_freem(m); |
michael@0 | 6100 | return; |
michael@0 | 6101 | } else { |
michael@0 | 6102 | initack->init.a_rwnd = htonl(max(SCTP_SB_LIMIT_RCV(so), SCTP_MINIMAL_RWND)); |
michael@0 | 6103 | } |
michael@0 | 6104 | /* set what I want */ |
michael@0 | 6105 | his_limit = ntohs(init_chk->init.num_inbound_streams); |
michael@0 | 6106 | /* choose what I want */ |
michael@0 | 6107 | if (asoc != NULL) { |
michael@0 | 6108 | if (asoc->streamoutcnt > inp->sctp_ep.pre_open_stream_count) { |
michael@0 | 6109 | i_want = asoc->streamoutcnt; |
michael@0 | 6110 | } else { |
michael@0 | 6111 | i_want = inp->sctp_ep.pre_open_stream_count; |
michael@0 | 6112 | } |
michael@0 | 6113 | } else { |
michael@0 | 6114 | i_want = inp->sctp_ep.pre_open_stream_count; |
michael@0 | 6115 | } |
michael@0 | 6116 | if (his_limit < i_want) { |
michael@0 | 6117 | /* I Want more :< */ |
michael@0 | 6118 | initack->init.num_outbound_streams = init_chk->init.num_inbound_streams; |
michael@0 | 6119 | } else { |
michael@0 | 6120 | /* I can have what I want :> */ |
michael@0 | 6121 | initack->init.num_outbound_streams = htons(i_want); |
michael@0 | 6122 | } |
michael@0 | 6123 | /* tell him his limit. */ |
michael@0 | 6124 | initack->init.num_inbound_streams = |
michael@0 | 6125 | htons(inp->sctp_ep.max_open_streams_intome); |
michael@0 | 6126 | |
michael@0 | 6127 | /* adaptation layer indication parameter */ |
michael@0 | 6128 | if (inp->sctp_ep.adaptation_layer_indicator_provided) { |
michael@0 | 6129 | ali = (struct sctp_adaptation_layer_indication *)((caddr_t)initack + sizeof(*initack)); |
michael@0 | 6130 | ali->ph.param_type = htons(SCTP_ULP_ADAPTATION); |
michael@0 | 6131 | ali->ph.param_length = htons(sizeof(*ali)); |
michael@0 | 6132 | ali->indication = ntohl(inp->sctp_ep.adaptation_layer_indicator); |
michael@0 | 6133 | SCTP_BUF_LEN(m) += sizeof(*ali); |
michael@0 | 6134 | ecn = (struct sctp_ecn_supported_param *)((caddr_t)ali + sizeof(*ali)); |
michael@0 | 6135 | } else { |
michael@0 | 6136 | ecn = (struct sctp_ecn_supported_param *)((caddr_t)initack + sizeof(*initack)); |
michael@0 | 6137 | } |
michael@0 | 6138 | |
michael@0 | 6139 | /* ECN parameter */ |
michael@0 | 6140 | if (((asoc != NULL) && (asoc->ecn_allowed == 1)) || |
michael@0 | 6141 | (inp->sctp_ecn_enable == 1)) { |
michael@0 | 6142 | ecn->ph.param_type = htons(SCTP_ECN_CAPABLE); |
michael@0 | 6143 | ecn->ph.param_length = htons(sizeof(*ecn)); |
michael@0 | 6144 | SCTP_BUF_LEN(m) += sizeof(*ecn); |
michael@0 | 6145 | |
michael@0 | 6146 | prsctp = (struct sctp_prsctp_supported_param *)((caddr_t)ecn + |
michael@0 | 6147 | sizeof(*ecn)); |
michael@0 | 6148 | } else { |
michael@0 | 6149 | prsctp = (struct sctp_prsctp_supported_param *)((caddr_t)ecn); |
michael@0 | 6150 | } |
michael@0 | 6151 | /* And now tell the peer we do pr-sctp */ |
michael@0 | 6152 | prsctp->ph.param_type = htons(SCTP_PRSCTP_SUPPORTED); |
michael@0 | 6153 | prsctp->ph.param_length = htons(sizeof(*prsctp)); |
michael@0 | 6154 | SCTP_BUF_LEN(m) += sizeof(*prsctp); |
michael@0 | 6155 | if (nat_friendly) { |
michael@0 | 6156 | /* Add NAT friendly parameter */ |
michael@0 | 6157 | struct sctp_paramhdr *ph; |
michael@0 | 6158 | |
michael@0 | 6159 | ph = (struct sctp_paramhdr *)(mtod(m, caddr_t) + SCTP_BUF_LEN(m)); |
michael@0 | 6160 | ph->param_type = htons(SCTP_HAS_NAT_SUPPORT); |
michael@0 | 6161 | ph->param_length = htons(sizeof(struct sctp_paramhdr)); |
michael@0 | 6162 | SCTP_BUF_LEN(m) += sizeof(struct sctp_paramhdr); |
michael@0 | 6163 | } |
michael@0 | 6164 | /* And now tell the peer we do all the extensions */ |
michael@0 | 6165 | pr_supported = (struct sctp_supported_chunk_types_param *)(mtod(m, caddr_t) + SCTP_BUF_LEN(m)); |
michael@0 | 6166 | pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT); |
michael@0 | 6167 | num_ext = 0; |
michael@0 | 6168 | pr_supported->chunk_types[num_ext++] = SCTP_ASCONF; |
michael@0 | 6169 | pr_supported->chunk_types[num_ext++] = SCTP_ASCONF_ACK; |
michael@0 | 6170 | pr_supported->chunk_types[num_ext++] = SCTP_FORWARD_CUM_TSN; |
michael@0 | 6171 | pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED; |
michael@0 | 6172 | pr_supported->chunk_types[num_ext++] = SCTP_STREAM_RESET; |
michael@0 | 6173 | if (!SCTP_BASE_SYSCTL(sctp_auth_disable)) |
michael@0 | 6174 | pr_supported->chunk_types[num_ext++] = SCTP_AUTHENTICATION; |
michael@0 | 6175 | if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off)) |
michael@0 | 6176 | pr_supported->chunk_types[num_ext++] = SCTP_NR_SELECTIVE_ACK; |
michael@0 | 6177 | p_len = sizeof(*pr_supported) + num_ext; |
michael@0 | 6178 | pr_supported->ph.param_length = htons(p_len); |
michael@0 | 6179 | bzero((caddr_t)pr_supported + p_len, SCTP_SIZE32(p_len) - p_len); |
michael@0 | 6180 | SCTP_BUF_LEN(m) += SCTP_SIZE32(p_len); |
michael@0 | 6181 | |
michael@0 | 6182 | /* add authentication parameters */ |
michael@0 | 6183 | if (!SCTP_BASE_SYSCTL(sctp_auth_disable)) { |
michael@0 | 6184 | struct sctp_auth_random *randp; |
michael@0 | 6185 | struct sctp_auth_hmac_algo *hmacs; |
michael@0 | 6186 | struct sctp_auth_chunk_list *chunks; |
michael@0 | 6187 | uint16_t random_len; |
michael@0 | 6188 | |
michael@0 | 6189 | /* generate and add RANDOM parameter */ |
michael@0 | 6190 | random_len = SCTP_AUTH_RANDOM_SIZE_DEFAULT; |
michael@0 | 6191 | randp = (struct sctp_auth_random *)(mtod(m, caddr_t) + SCTP_BUF_LEN(m)); |
michael@0 | 6192 | randp->ph.param_type = htons(SCTP_RANDOM); |
michael@0 | 6193 | p_len = sizeof(*randp) + random_len; |
michael@0 | 6194 | randp->ph.param_length = htons(p_len); |
michael@0 | 6195 | SCTP_READ_RANDOM(randp->random_data, random_len); |
michael@0 | 6196 | /* zero out any padding required */ |
michael@0 | 6197 | bzero((caddr_t)randp + p_len, SCTP_SIZE32(p_len) - p_len); |
michael@0 | 6198 | SCTP_BUF_LEN(m) += SCTP_SIZE32(p_len); |
michael@0 | 6199 | |
michael@0 | 6200 | /* add HMAC_ALGO parameter */ |
michael@0 | 6201 | hmacs = (struct sctp_auth_hmac_algo *)(mtod(m, caddr_t) + SCTP_BUF_LEN(m)); |
michael@0 | 6202 | p_len = sctp_serialize_hmaclist(inp->sctp_ep.local_hmacs, |
michael@0 | 6203 | (uint8_t *) hmacs->hmac_ids); |
michael@0 | 6204 | if (p_len > 0) { |
michael@0 | 6205 | p_len += sizeof(*hmacs); |
michael@0 | 6206 | hmacs->ph.param_type = htons(SCTP_HMAC_LIST); |
michael@0 | 6207 | hmacs->ph.param_length = htons(p_len); |
michael@0 | 6208 | /* zero out any padding required */ |
michael@0 | 6209 | bzero((caddr_t)hmacs + p_len, SCTP_SIZE32(p_len) - p_len); |
michael@0 | 6210 | SCTP_BUF_LEN(m) += SCTP_SIZE32(p_len); |
michael@0 | 6211 | } |
michael@0 | 6212 | /* add CHUNKS parameter */ |
michael@0 | 6213 | chunks = (struct sctp_auth_chunk_list *)(mtod(m, caddr_t) + SCTP_BUF_LEN(m)); |
michael@0 | 6214 | p_len = sctp_serialize_auth_chunks(inp->sctp_ep.local_auth_chunks, |
michael@0 | 6215 | chunks->chunk_types); |
michael@0 | 6216 | if (p_len > 0) { |
michael@0 | 6217 | p_len += sizeof(*chunks); |
michael@0 | 6218 | chunks->ph.param_type = htons(SCTP_CHUNK_LIST); |
michael@0 | 6219 | chunks->ph.param_length = htons(p_len); |
michael@0 | 6220 | /* zero out any padding required */ |
michael@0 | 6221 | bzero((caddr_t)chunks + p_len, SCTP_SIZE32(p_len) - p_len); |
michael@0 | 6222 | SCTP_BUF_LEN(m) += SCTP_SIZE32(p_len); |
michael@0 | 6223 | } |
michael@0 | 6224 | } |
michael@0 | 6225 | m_at = m; |
michael@0 | 6226 | /* now the addresses */ |
michael@0 | 6227 | { |
michael@0 | 6228 | struct sctp_scoping scp; |
michael@0 | 6229 | /* To optimize this we could put the scoping stuff |
michael@0 | 6230 | * into a structure and remove the individual uint8's from |
michael@0 | 6231 | * the stc structure. Then we could just sifa in the |
michael@0 | 6232 | * address within the stc.. but for now this is a quick |
michael@0 | 6233 | * hack to get the address stuff teased apart. |
michael@0 | 6234 | */ |
michael@0 | 6235 | scp.ipv4_addr_legal = stc.ipv4_addr_legal; |
michael@0 | 6236 | scp.ipv6_addr_legal = stc.ipv6_addr_legal; |
michael@0 | 6237 | #if defined(__Userspace__) |
michael@0 | 6238 | scp.conn_addr_legal = stc.conn_addr_legal; |
michael@0 | 6239 | #endif |
michael@0 | 6240 | scp.loopback_scope = stc.loopback_scope; |
michael@0 | 6241 | scp.ipv4_local_scope = stc.ipv4_scope; |
michael@0 | 6242 | scp.local_scope = stc.local_scope; |
michael@0 | 6243 | scp.site_scope = stc.site_scope; |
michael@0 | 6244 | m_at = sctp_add_addresses_to_i_ia(inp, stcb, &scp, m_at, cnt_inits_to, NULL, NULL); |
michael@0 | 6245 | } |
michael@0 | 6246 | |
michael@0 | 6247 | /* tack on the operational error if present */ |
michael@0 | 6248 | if (op_err) { |
michael@0 | 6249 | struct mbuf *ol; |
michael@0 | 6250 | int llen; |
michael@0 | 6251 | llen = 0; |
michael@0 | 6252 | ol = op_err; |
michael@0 | 6253 | |
michael@0 | 6254 | while (ol) { |
michael@0 | 6255 | llen += SCTP_BUF_LEN(ol); |
michael@0 | 6256 | ol = SCTP_BUF_NEXT(ol); |
michael@0 | 6257 | } |
michael@0 | 6258 | if (llen % 4) { |
michael@0 | 6259 | /* must add a pad to the param */ |
michael@0 | 6260 | uint32_t cpthis = 0; |
michael@0 | 6261 | int padlen; |
michael@0 | 6262 | |
michael@0 | 6263 | padlen = 4 - (llen % 4); |
michael@0 | 6264 | m_copyback(op_err, llen, padlen, (caddr_t)&cpthis); |
michael@0 | 6265 | } |
michael@0 | 6266 | while (SCTP_BUF_NEXT(m_at) != NULL) { |
michael@0 | 6267 | m_at = SCTP_BUF_NEXT(m_at); |
michael@0 | 6268 | } |
michael@0 | 6269 | SCTP_BUF_NEXT(m_at) = op_err; |
michael@0 | 6270 | while (SCTP_BUF_NEXT(m_at) != NULL) { |
michael@0 | 6271 | m_at = SCTP_BUF_NEXT(m_at); |
michael@0 | 6272 | } |
michael@0 | 6273 | } |
michael@0 | 6274 | /* pre-calulate the size and update pkt header and chunk header */ |
michael@0 | 6275 | p_len = 0; |
michael@0 | 6276 | for (m_tmp = m; m_tmp; m_tmp = SCTP_BUF_NEXT(m_tmp)) { |
michael@0 | 6277 | p_len += SCTP_BUF_LEN(m_tmp); |
michael@0 | 6278 | if (SCTP_BUF_NEXT(m_tmp) == NULL) { |
michael@0 | 6279 | /* m_tmp should now point to last one */ |
michael@0 | 6280 | break; |
michael@0 | 6281 | } |
michael@0 | 6282 | } |
michael@0 | 6283 | |
michael@0 | 6284 | /* Now we must build a cookie */ |
michael@0 | 6285 | m_cookie = sctp_add_cookie(init_pkt, offset, m, 0, &stc, &signature); |
michael@0 | 6286 | if (m_cookie == NULL) { |
michael@0 | 6287 | /* memory problem */ |
michael@0 | 6288 | sctp_m_freem(m); |
michael@0 | 6289 | return; |
michael@0 | 6290 | } |
michael@0 | 6291 | /* Now append the cookie to the end and update the space/size */ |
michael@0 | 6292 | SCTP_BUF_NEXT(m_tmp) = m_cookie; |
michael@0 | 6293 | |
michael@0 | 6294 | for (m_tmp = m_cookie; m_tmp; m_tmp = SCTP_BUF_NEXT(m_tmp)) { |
michael@0 | 6295 | p_len += SCTP_BUF_LEN(m_tmp); |
michael@0 | 6296 | if (SCTP_BUF_NEXT(m_tmp) == NULL) { |
michael@0 | 6297 | /* m_tmp should now point to last one */ |
michael@0 | 6298 | mp_last = m_tmp; |
michael@0 | 6299 | break; |
michael@0 | 6300 | } |
michael@0 | 6301 | } |
michael@0 | 6302 | /* Place in the size, but we don't include |
michael@0 | 6303 | * the last pad (if any) in the INIT-ACK. |
michael@0 | 6304 | */ |
michael@0 | 6305 | initack->ch.chunk_length = htons(p_len); |
michael@0 | 6306 | |
michael@0 | 6307 | /* Time to sign the cookie, we don't sign over the cookie |
michael@0 | 6308 | * signature though thus we set trailer. |
michael@0 | 6309 | */ |
michael@0 | 6310 | (void)sctp_hmac_m(SCTP_HMAC, |
michael@0 | 6311 | (uint8_t *)inp->sctp_ep.secret_key[(int)(inp->sctp_ep.current_secret_number)], |
michael@0 | 6312 | SCTP_SECRET_SIZE, m_cookie, sizeof(struct sctp_paramhdr), |
michael@0 | 6313 | (uint8_t *)signature, SCTP_SIGNATURE_SIZE); |
michael@0 | 6314 | /* |
michael@0 | 6315 | * We sifa 0 here to NOT set IP_DF if its IPv4, we ignore the return |
michael@0 | 6316 | * here since the timer will drive a retranmission. |
michael@0 | 6317 | */ |
michael@0 | 6318 | padval = p_len % 4; |
michael@0 | 6319 | if ((padval) && (mp_last)) { |
michael@0 | 6320 | /* see my previous comments on mp_last */ |
michael@0 | 6321 | if (sctp_add_pad_tombuf(mp_last, (4 - padval))) { |
michael@0 | 6322 | /* Houston we have a problem, no space */ |
michael@0 | 6323 | sctp_m_freem(m); |
michael@0 | 6324 | return; |
michael@0 | 6325 | } |
michael@0 | 6326 | } |
michael@0 | 6327 | if (stc.loopback_scope) { |
michael@0 | 6328 | over_addr = (union sctp_sockstore *)dst; |
michael@0 | 6329 | } else { |
michael@0 | 6330 | over_addr = NULL; |
michael@0 | 6331 | } |
michael@0 | 6332 | |
michael@0 | 6333 | (void)sctp_lowlevel_chunk_output(inp, NULL, NULL, to, m, 0, NULL, 0, 0, |
michael@0 | 6334 | 0, 0, |
michael@0 | 6335 | inp->sctp_lport, sh->src_port, init_chk->init.initiate_tag, |
michael@0 | 6336 | port, over_addr, |
michael@0 | 6337 | #if defined(__FreeBSD__) |
michael@0 | 6338 | use_mflowid, mflowid, |
michael@0 | 6339 | #endif |
michael@0 | 6340 | SCTP_SO_NOT_LOCKED); |
michael@0 | 6341 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 6342 | } |
michael@0 | 6343 | |
michael@0 | 6344 | |
michael@0 | 6345 | static void |
michael@0 | 6346 | sctp_prune_prsctp(struct sctp_tcb *stcb, |
michael@0 | 6347 | struct sctp_association *asoc, |
michael@0 | 6348 | struct sctp_sndrcvinfo *srcv, |
michael@0 | 6349 | int dataout) |
michael@0 | 6350 | { |
michael@0 | 6351 | int freed_spc = 0; |
michael@0 | 6352 | struct sctp_tmit_chunk *chk, *nchk; |
michael@0 | 6353 | |
michael@0 | 6354 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 6355 | if ((asoc->peer_supports_prsctp) && |
michael@0 | 6356 | (asoc->sent_queue_cnt_removeable > 0)) { |
michael@0 | 6357 | TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { |
michael@0 | 6358 | /* |
michael@0 | 6359 | * Look for chunks marked with the PR_SCTP flag AND |
michael@0 | 6360 | * the buffer space flag. If the one being sent is |
michael@0 | 6361 | * equal or greater priority then purge the old one |
michael@0 | 6362 | * and free some space. |
michael@0 | 6363 | */ |
michael@0 | 6364 | if (PR_SCTP_BUF_ENABLED(chk->flags)) { |
michael@0 | 6365 | /* |
michael@0 | 6366 | * This one is PR-SCTP AND buffer space |
michael@0 | 6367 | * limited type |
michael@0 | 6368 | */ |
michael@0 | 6369 | if (chk->rec.data.timetodrop.tv_sec >= (long)srcv->sinfo_timetolive) { |
michael@0 | 6370 | /* |
michael@0 | 6371 | * Lower numbers equates to higher |
michael@0 | 6372 | * priority so if the one we are |
michael@0 | 6373 | * looking at has a larger or equal |
michael@0 | 6374 | * priority we want to drop the data |
michael@0 | 6375 | * and NOT retransmit it. |
michael@0 | 6376 | */ |
michael@0 | 6377 | if (chk->data) { |
michael@0 | 6378 | /* |
michael@0 | 6379 | * We release the book_size |
michael@0 | 6380 | * if the mbuf is here |
michael@0 | 6381 | */ |
michael@0 | 6382 | int ret_spc; |
michael@0 | 6383 | uint8_t sent; |
michael@0 | 6384 | |
michael@0 | 6385 | if (chk->sent > SCTP_DATAGRAM_UNSENT) |
michael@0 | 6386 | sent = 1; |
michael@0 | 6387 | else |
michael@0 | 6388 | sent = 0; |
michael@0 | 6389 | ret_spc = sctp_release_pr_sctp_chunk(stcb, chk, |
michael@0 | 6390 | sent, |
michael@0 | 6391 | SCTP_SO_LOCKED); |
michael@0 | 6392 | freed_spc += ret_spc; |
michael@0 | 6393 | if (freed_spc >= dataout) { |
michael@0 | 6394 | return; |
michael@0 | 6395 | } |
michael@0 | 6396 | } /* if chunk was present */ |
michael@0 | 6397 | } /* if of sufficent priority */ |
michael@0 | 6398 | } /* if chunk has enabled */ |
michael@0 | 6399 | } /* tailqforeach */ |
michael@0 | 6400 | |
michael@0 | 6401 | TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) { |
michael@0 | 6402 | /* Here we must move to the sent queue and mark */ |
michael@0 | 6403 | if (PR_SCTP_BUF_ENABLED(chk->flags)) { |
michael@0 | 6404 | if (chk->rec.data.timetodrop.tv_sec >= (long)srcv->sinfo_timetolive) { |
michael@0 | 6405 | if (chk->data) { |
michael@0 | 6406 | /* |
michael@0 | 6407 | * We release the book_size |
michael@0 | 6408 | * if the mbuf is here |
michael@0 | 6409 | */ |
michael@0 | 6410 | int ret_spc; |
michael@0 | 6411 | |
michael@0 | 6412 | ret_spc = sctp_release_pr_sctp_chunk(stcb, chk, |
michael@0 | 6413 | 0, SCTP_SO_LOCKED); |
michael@0 | 6414 | |
michael@0 | 6415 | freed_spc += ret_spc; |
michael@0 | 6416 | if (freed_spc >= dataout) { |
michael@0 | 6417 | return; |
michael@0 | 6418 | } |
michael@0 | 6419 | } /* end if chk->data */ |
michael@0 | 6420 | } /* end if right class */ |
michael@0 | 6421 | } /* end if chk pr-sctp */ |
michael@0 | 6422 | } /* tailqforeachsafe (chk) */ |
michael@0 | 6423 | } /* if enabled in asoc */ |
michael@0 | 6424 | } |
michael@0 | 6425 | |
michael@0 | 6426 | int |
michael@0 | 6427 | sctp_get_frag_point(struct sctp_tcb *stcb, |
michael@0 | 6428 | struct sctp_association *asoc) |
michael@0 | 6429 | { |
michael@0 | 6430 | int siz, ovh; |
michael@0 | 6431 | |
michael@0 | 6432 | /* |
michael@0 | 6433 | * For endpoints that have both v6 and v4 addresses we must reserve |
michael@0 | 6434 | * room for the ipv6 header, for those that are only dealing with V4 |
michael@0 | 6435 | * we use a larger frag point. |
michael@0 | 6436 | */ |
michael@0 | 6437 | if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
michael@0 | 6438 | ovh = SCTP_MED_OVERHEAD; |
michael@0 | 6439 | } else { |
michael@0 | 6440 | ovh = SCTP_MED_V4_OVERHEAD; |
michael@0 | 6441 | } |
michael@0 | 6442 | |
michael@0 | 6443 | if (stcb->asoc.sctp_frag_point > asoc->smallest_mtu) |
michael@0 | 6444 | siz = asoc->smallest_mtu - ovh; |
michael@0 | 6445 | else |
michael@0 | 6446 | siz = (stcb->asoc.sctp_frag_point - ovh); |
michael@0 | 6447 | /* |
michael@0 | 6448 | * if (siz > (MCLBYTES-sizeof(struct sctp_data_chunk))) { |
michael@0 | 6449 | */ |
michael@0 | 6450 | /* A data chunk MUST fit in a cluster */ |
michael@0 | 6451 | /* siz = (MCLBYTES - sizeof(struct sctp_data_chunk)); */ |
michael@0 | 6452 | /* } */ |
michael@0 | 6453 | |
michael@0 | 6454 | /* adjust for an AUTH chunk if DATA requires auth */ |
michael@0 | 6455 | if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) |
michael@0 | 6456 | siz -= sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); |
michael@0 | 6457 | |
michael@0 | 6458 | if (siz % 4) { |
michael@0 | 6459 | /* make it an even word boundary please */ |
michael@0 | 6460 | siz -= (siz % 4); |
michael@0 | 6461 | } |
michael@0 | 6462 | return (siz); |
michael@0 | 6463 | } |
michael@0 | 6464 | |
michael@0 | 6465 | static void |
michael@0 | 6466 | sctp_set_prsctp_policy(struct sctp_stream_queue_pending *sp) |
michael@0 | 6467 | { |
michael@0 | 6468 | /* |
michael@0 | 6469 | * We assume that the user wants PR_SCTP_TTL if the user |
michael@0 | 6470 | * provides a positive lifetime but does not specify any |
michael@0 | 6471 | * PR_SCTP policy. |
michael@0 | 6472 | */ |
michael@0 | 6473 | if (PR_SCTP_ENABLED(sp->sinfo_flags)) { |
michael@0 | 6474 | sp->act_flags |= PR_SCTP_POLICY(sp->sinfo_flags); |
michael@0 | 6475 | } else if (sp->timetolive > 0) { |
michael@0 | 6476 | sp->sinfo_flags |= SCTP_PR_SCTP_TTL; |
michael@0 | 6477 | sp->act_flags |= PR_SCTP_POLICY(sp->sinfo_flags); |
michael@0 | 6478 | } else { |
michael@0 | 6479 | return; |
michael@0 | 6480 | } |
michael@0 | 6481 | switch (PR_SCTP_POLICY(sp->sinfo_flags)) { |
michael@0 | 6482 | case CHUNK_FLAGS_PR_SCTP_BUF: |
michael@0 | 6483 | /* |
michael@0 | 6484 | * Time to live is a priority stored in tv_sec when |
michael@0 | 6485 | * doing the buffer drop thing. |
michael@0 | 6486 | */ |
michael@0 | 6487 | sp->ts.tv_sec = sp->timetolive; |
michael@0 | 6488 | sp->ts.tv_usec = 0; |
michael@0 | 6489 | break; |
michael@0 | 6490 | case CHUNK_FLAGS_PR_SCTP_TTL: |
michael@0 | 6491 | { |
michael@0 | 6492 | struct timeval tv; |
michael@0 | 6493 | (void)SCTP_GETTIME_TIMEVAL(&sp->ts); |
michael@0 | 6494 | tv.tv_sec = sp->timetolive / 1000; |
michael@0 | 6495 | tv.tv_usec = (sp->timetolive * 1000) % 1000000; |
michael@0 | 6496 | /* TODO sctp_constants.h needs alternative time macros when |
michael@0 | 6497 | * _KERNEL is undefined. |
michael@0 | 6498 | */ |
michael@0 | 6499 | #ifndef __FreeBSD__ |
michael@0 | 6500 | timeradd(&sp->ts, &tv, &sp->ts); |
michael@0 | 6501 | #else |
michael@0 | 6502 | timevaladd(&sp->ts, &tv); |
michael@0 | 6503 | #endif |
michael@0 | 6504 | } |
michael@0 | 6505 | break; |
michael@0 | 6506 | case CHUNK_FLAGS_PR_SCTP_RTX: |
michael@0 | 6507 | /* |
michael@0 | 6508 | * Time to live is a the number or retransmissions |
michael@0 | 6509 | * stored in tv_sec. |
michael@0 | 6510 | */ |
michael@0 | 6511 | sp->ts.tv_sec = sp->timetolive; |
michael@0 | 6512 | sp->ts.tv_usec = 0; |
michael@0 | 6513 | break; |
michael@0 | 6514 | default: |
michael@0 | 6515 | SCTPDBG(SCTP_DEBUG_USRREQ1, |
michael@0 | 6516 | "Unknown PR_SCTP policy %u.\n", |
michael@0 | 6517 | PR_SCTP_POLICY(sp->sinfo_flags)); |
michael@0 | 6518 | break; |
michael@0 | 6519 | } |
michael@0 | 6520 | } |
michael@0 | 6521 | |
michael@0 | 6522 | static int |
michael@0 | 6523 | sctp_msg_append(struct sctp_tcb *stcb, |
michael@0 | 6524 | struct sctp_nets *net, |
michael@0 | 6525 | struct mbuf *m, |
michael@0 | 6526 | struct sctp_sndrcvinfo *srcv, int hold_stcb_lock) |
michael@0 | 6527 | { |
michael@0 | 6528 | int error = 0; |
michael@0 | 6529 | struct mbuf *at; |
michael@0 | 6530 | struct sctp_stream_queue_pending *sp = NULL; |
michael@0 | 6531 | struct sctp_stream_out *strm; |
michael@0 | 6532 | |
michael@0 | 6533 | /* Given an mbuf chain, put it |
michael@0 | 6534 | * into the association send queue and |
michael@0 | 6535 | * place it on the wheel |
michael@0 | 6536 | */ |
michael@0 | 6537 | if (srcv->sinfo_stream >= stcb->asoc.streamoutcnt) { |
michael@0 | 6538 | /* Invalid stream number */ |
michael@0 | 6539 | SCTP_LTRACE_ERR_RET_PKT(m, NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 6540 | error = EINVAL; |
michael@0 | 6541 | goto out_now; |
michael@0 | 6542 | } |
michael@0 | 6543 | if ((stcb->asoc.stream_locked) && |
michael@0 | 6544 | (stcb->asoc.stream_locked_on != srcv->sinfo_stream)) { |
michael@0 | 6545 | SCTP_LTRACE_ERR_RET_PKT(m, NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 6546 | error = EINVAL; |
michael@0 | 6547 | goto out_now; |
michael@0 | 6548 | } |
michael@0 | 6549 | strm = &stcb->asoc.strmout[srcv->sinfo_stream]; |
michael@0 | 6550 | /* Now can we send this? */ |
michael@0 | 6551 | if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_SENT) || |
michael@0 | 6552 | (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_ACK_SENT) || |
michael@0 | 6553 | (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) || |
michael@0 | 6554 | (stcb->asoc.state & SCTP_STATE_SHUTDOWN_PENDING)) { |
michael@0 | 6555 | /* got data while shutting down */ |
michael@0 | 6556 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ECONNRESET); |
michael@0 | 6557 | error = ECONNRESET; |
michael@0 | 6558 | goto out_now; |
michael@0 | 6559 | } |
michael@0 | 6560 | sctp_alloc_a_strmoq(stcb, sp); |
michael@0 | 6561 | if (sp == NULL) { |
michael@0 | 6562 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 6563 | error = ENOMEM; |
michael@0 | 6564 | goto out_now; |
michael@0 | 6565 | } |
michael@0 | 6566 | sp->sinfo_flags = srcv->sinfo_flags; |
michael@0 | 6567 | sp->timetolive = srcv->sinfo_timetolive; |
michael@0 | 6568 | sp->ppid = srcv->sinfo_ppid; |
michael@0 | 6569 | sp->context = srcv->sinfo_context; |
michael@0 | 6570 | if (sp->sinfo_flags & SCTP_ADDR_OVER) { |
michael@0 | 6571 | sp->net = net; |
michael@0 | 6572 | atomic_add_int(&sp->net->ref_count, 1); |
michael@0 | 6573 | } else { |
michael@0 | 6574 | sp->net = NULL; |
michael@0 | 6575 | } |
michael@0 | 6576 | (void)SCTP_GETTIME_TIMEVAL(&sp->ts); |
michael@0 | 6577 | sp->stream = srcv->sinfo_stream; |
michael@0 | 6578 | sp->msg_is_complete = 1; |
michael@0 | 6579 | sp->sender_all_done = 1; |
michael@0 | 6580 | sp->some_taken = 0; |
michael@0 | 6581 | sp->data = m; |
michael@0 | 6582 | sp->tail_mbuf = NULL; |
michael@0 | 6583 | sctp_set_prsctp_policy(sp); |
michael@0 | 6584 | /* We could in theory (for sendall) sifa the length |
michael@0 | 6585 | * in, but we would still have to hunt through the |
michael@0 | 6586 | * chain since we need to setup the tail_mbuf |
michael@0 | 6587 | */ |
michael@0 | 6588 | sp->length = 0; |
michael@0 | 6589 | for (at = m; at; at = SCTP_BUF_NEXT(at)) { |
michael@0 | 6590 | if (SCTP_BUF_NEXT(at) == NULL) |
michael@0 | 6591 | sp->tail_mbuf = at; |
michael@0 | 6592 | sp->length += SCTP_BUF_LEN(at); |
michael@0 | 6593 | } |
michael@0 | 6594 | if (srcv->sinfo_keynumber_valid) { |
michael@0 | 6595 | sp->auth_keyid = srcv->sinfo_keynumber; |
michael@0 | 6596 | } else { |
michael@0 | 6597 | sp->auth_keyid = stcb->asoc.authinfo.active_keyid; |
michael@0 | 6598 | } |
michael@0 | 6599 | if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) { |
michael@0 | 6600 | sctp_auth_key_acquire(stcb, sp->auth_keyid); |
michael@0 | 6601 | sp->holds_key_ref = 1; |
michael@0 | 6602 | } |
michael@0 | 6603 | if (hold_stcb_lock == 0) { |
michael@0 | 6604 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 6605 | } |
michael@0 | 6606 | sctp_snd_sb_alloc(stcb, sp->length); |
michael@0 | 6607 | atomic_add_int(&stcb->asoc.stream_queue_cnt, 1); |
michael@0 | 6608 | TAILQ_INSERT_TAIL(&strm->outqueue, sp, next); |
michael@0 | 6609 | stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc, strm, sp, 1); |
michael@0 | 6610 | m = NULL; |
michael@0 | 6611 | if (hold_stcb_lock == 0) { |
michael@0 | 6612 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 6613 | } |
michael@0 | 6614 | out_now: |
michael@0 | 6615 | if (m) { |
michael@0 | 6616 | sctp_m_freem(m); |
michael@0 | 6617 | } |
michael@0 | 6618 | return (error); |
michael@0 | 6619 | } |
michael@0 | 6620 | |
michael@0 | 6621 | |
michael@0 | 6622 | static struct mbuf * |
michael@0 | 6623 | sctp_copy_mbufchain(struct mbuf *clonechain, |
michael@0 | 6624 | struct mbuf *outchain, |
michael@0 | 6625 | struct mbuf **endofchain, |
michael@0 | 6626 | int can_take_mbuf, |
michael@0 | 6627 | int sizeofcpy, |
michael@0 | 6628 | uint8_t copy_by_ref) |
michael@0 | 6629 | { |
michael@0 | 6630 | struct mbuf *m; |
michael@0 | 6631 | struct mbuf *appendchain; |
michael@0 | 6632 | caddr_t cp; |
michael@0 | 6633 | int len; |
michael@0 | 6634 | |
michael@0 | 6635 | if (endofchain == NULL) { |
michael@0 | 6636 | /* error */ |
michael@0 | 6637 | error_out: |
michael@0 | 6638 | if (outchain) |
michael@0 | 6639 | sctp_m_freem(outchain); |
michael@0 | 6640 | return (NULL); |
michael@0 | 6641 | } |
michael@0 | 6642 | if (can_take_mbuf) { |
michael@0 | 6643 | appendchain = clonechain; |
michael@0 | 6644 | } else { |
michael@0 | 6645 | if (!copy_by_ref && |
michael@0 | 6646 | #if defined(__Panda__) |
michael@0 | 6647 | 0 |
michael@0 | 6648 | #else |
michael@0 | 6649 | (sizeofcpy <= (int)((((SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) - 1) * MLEN) + MHLEN))) |
michael@0 | 6650 | #endif |
michael@0 | 6651 | ) { |
michael@0 | 6652 | /* Its not in a cluster */ |
michael@0 | 6653 | if (*endofchain == NULL) { |
michael@0 | 6654 | /* lets get a mbuf cluster */ |
michael@0 | 6655 | if (outchain == NULL) { |
michael@0 | 6656 | /* This is the general case */ |
michael@0 | 6657 | new_mbuf: |
michael@0 | 6658 | outchain = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 6659 | if (outchain == NULL) { |
michael@0 | 6660 | goto error_out; |
michael@0 | 6661 | } |
michael@0 | 6662 | SCTP_BUF_LEN(outchain) = 0; |
michael@0 | 6663 | *endofchain = outchain; |
michael@0 | 6664 | /* get the prepend space */ |
michael@0 | 6665 | SCTP_BUF_RESV_UF(outchain, (SCTP_FIRST_MBUF_RESV+4)); |
michael@0 | 6666 | } else { |
michael@0 | 6667 | /* We really should not get a NULL in endofchain */ |
michael@0 | 6668 | /* find end */ |
michael@0 | 6669 | m = outchain; |
michael@0 | 6670 | while (m) { |
michael@0 | 6671 | if (SCTP_BUF_NEXT(m) == NULL) { |
michael@0 | 6672 | *endofchain = m; |
michael@0 | 6673 | break; |
michael@0 | 6674 | } |
michael@0 | 6675 | m = SCTP_BUF_NEXT(m); |
michael@0 | 6676 | } |
michael@0 | 6677 | /* sanity */ |
michael@0 | 6678 | if (*endofchain == NULL) { |
michael@0 | 6679 | /* huh, TSNH XXX maybe we should panic */ |
michael@0 | 6680 | sctp_m_freem(outchain); |
michael@0 | 6681 | goto new_mbuf; |
michael@0 | 6682 | } |
michael@0 | 6683 | } |
michael@0 | 6684 | /* get the new end of length */ |
michael@0 | 6685 | len = M_TRAILINGSPACE(*endofchain); |
michael@0 | 6686 | } else { |
michael@0 | 6687 | /* how much is left at the end? */ |
michael@0 | 6688 | len = M_TRAILINGSPACE(*endofchain); |
michael@0 | 6689 | } |
michael@0 | 6690 | /* Find the end of the data, for appending */ |
michael@0 | 6691 | cp = (mtod((*endofchain), caddr_t) + SCTP_BUF_LEN((*endofchain))); |
michael@0 | 6692 | |
michael@0 | 6693 | /* Now lets copy it out */ |
michael@0 | 6694 | if (len >= sizeofcpy) { |
michael@0 | 6695 | /* It all fits, copy it in */ |
michael@0 | 6696 | m_copydata(clonechain, 0, sizeofcpy, cp); |
michael@0 | 6697 | SCTP_BUF_LEN((*endofchain)) += sizeofcpy; |
michael@0 | 6698 | } else { |
michael@0 | 6699 | /* fill up the end of the chain */ |
michael@0 | 6700 | if (len > 0) { |
michael@0 | 6701 | m_copydata(clonechain, 0, len, cp); |
michael@0 | 6702 | SCTP_BUF_LEN((*endofchain)) += len; |
michael@0 | 6703 | /* now we need another one */ |
michael@0 | 6704 | sizeofcpy -= len; |
michael@0 | 6705 | } |
michael@0 | 6706 | m = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 6707 | if (m == NULL) { |
michael@0 | 6708 | /* We failed */ |
michael@0 | 6709 | goto error_out; |
michael@0 | 6710 | } |
michael@0 | 6711 | SCTP_BUF_NEXT((*endofchain)) = m; |
michael@0 | 6712 | *endofchain = m; |
michael@0 | 6713 | cp = mtod((*endofchain), caddr_t); |
michael@0 | 6714 | m_copydata(clonechain, len, sizeofcpy, cp); |
michael@0 | 6715 | SCTP_BUF_LEN((*endofchain)) += sizeofcpy; |
michael@0 | 6716 | } |
michael@0 | 6717 | return (outchain); |
michael@0 | 6718 | } else { |
michael@0 | 6719 | /* copy the old fashion way */ |
michael@0 | 6720 | appendchain = SCTP_M_COPYM(clonechain, 0, M_COPYALL, M_NOWAIT); |
michael@0 | 6721 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 6722 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 6723 | struct mbuf *mat; |
michael@0 | 6724 | |
michael@0 | 6725 | for (mat = appendchain; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 6726 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 6727 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 6728 | } |
michael@0 | 6729 | } |
michael@0 | 6730 | } |
michael@0 | 6731 | #endif |
michael@0 | 6732 | } |
michael@0 | 6733 | } |
michael@0 | 6734 | if (appendchain == NULL) { |
michael@0 | 6735 | /* error */ |
michael@0 | 6736 | if (outchain) |
michael@0 | 6737 | sctp_m_freem(outchain); |
michael@0 | 6738 | return (NULL); |
michael@0 | 6739 | } |
michael@0 | 6740 | if (outchain) { |
michael@0 | 6741 | /* tack on to the end */ |
michael@0 | 6742 | if (*endofchain != NULL) { |
michael@0 | 6743 | SCTP_BUF_NEXT(((*endofchain))) = appendchain; |
michael@0 | 6744 | } else { |
michael@0 | 6745 | m = outchain; |
michael@0 | 6746 | while (m) { |
michael@0 | 6747 | if (SCTP_BUF_NEXT(m) == NULL) { |
michael@0 | 6748 | SCTP_BUF_NEXT(m) = appendchain; |
michael@0 | 6749 | break; |
michael@0 | 6750 | } |
michael@0 | 6751 | m = SCTP_BUF_NEXT(m); |
michael@0 | 6752 | } |
michael@0 | 6753 | } |
michael@0 | 6754 | /* |
michael@0 | 6755 | * save off the end and update the end-chain |
michael@0 | 6756 | * postion |
michael@0 | 6757 | */ |
michael@0 | 6758 | m = appendchain; |
michael@0 | 6759 | while (m) { |
michael@0 | 6760 | if (SCTP_BUF_NEXT(m) == NULL) { |
michael@0 | 6761 | *endofchain = m; |
michael@0 | 6762 | break; |
michael@0 | 6763 | } |
michael@0 | 6764 | m = SCTP_BUF_NEXT(m); |
michael@0 | 6765 | } |
michael@0 | 6766 | return (outchain); |
michael@0 | 6767 | } else { |
michael@0 | 6768 | /* save off the end and update the end-chain postion */ |
michael@0 | 6769 | m = appendchain; |
michael@0 | 6770 | while (m) { |
michael@0 | 6771 | if (SCTP_BUF_NEXT(m) == NULL) { |
michael@0 | 6772 | *endofchain = m; |
michael@0 | 6773 | break; |
michael@0 | 6774 | } |
michael@0 | 6775 | m = SCTP_BUF_NEXT(m); |
michael@0 | 6776 | } |
michael@0 | 6777 | return (appendchain); |
michael@0 | 6778 | } |
michael@0 | 6779 | } |
michael@0 | 6780 | |
michael@0 | 6781 | static int |
michael@0 | 6782 | sctp_med_chunk_output(struct sctp_inpcb *inp, |
michael@0 | 6783 | struct sctp_tcb *stcb, |
michael@0 | 6784 | struct sctp_association *asoc, |
michael@0 | 6785 | int *num_out, |
michael@0 | 6786 | int *reason_code, |
michael@0 | 6787 | int control_only, int from_where, |
michael@0 | 6788 | struct timeval *now, int *now_filled, int frag_point, int so_locked |
michael@0 | 6789 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 6790 | SCTP_UNUSED |
michael@0 | 6791 | #endif |
michael@0 | 6792 | ); |
michael@0 | 6793 | |
michael@0 | 6794 | static void |
michael@0 | 6795 | sctp_sendall_iterator(struct sctp_inpcb *inp, struct sctp_tcb *stcb, void *ptr, |
michael@0 | 6796 | uint32_t val SCTP_UNUSED) |
michael@0 | 6797 | { |
michael@0 | 6798 | struct sctp_copy_all *ca; |
michael@0 | 6799 | struct mbuf *m; |
michael@0 | 6800 | int ret = 0; |
michael@0 | 6801 | int added_control = 0; |
michael@0 | 6802 | int un_sent, do_chunk_output = 1; |
michael@0 | 6803 | struct sctp_association *asoc; |
michael@0 | 6804 | struct sctp_nets *net; |
michael@0 | 6805 | |
michael@0 | 6806 | ca = (struct sctp_copy_all *)ptr; |
michael@0 | 6807 | if (ca->m == NULL) { |
michael@0 | 6808 | return; |
michael@0 | 6809 | } |
michael@0 | 6810 | if (ca->inp != inp) { |
michael@0 | 6811 | /* TSNH */ |
michael@0 | 6812 | return; |
michael@0 | 6813 | } |
michael@0 | 6814 | if (ca->sndlen > 0) { |
michael@0 | 6815 | m = SCTP_M_COPYM(ca->m, 0, M_COPYALL, M_NOWAIT); |
michael@0 | 6816 | if (m == NULL) { |
michael@0 | 6817 | /* can't copy so we are done */ |
michael@0 | 6818 | ca->cnt_failed++; |
michael@0 | 6819 | return; |
michael@0 | 6820 | } |
michael@0 | 6821 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 6822 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 6823 | struct mbuf *mat; |
michael@0 | 6824 | |
michael@0 | 6825 | for (mat = m; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 6826 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 6827 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 6828 | } |
michael@0 | 6829 | } |
michael@0 | 6830 | } |
michael@0 | 6831 | #endif |
michael@0 | 6832 | } else { |
michael@0 | 6833 | m = NULL; |
michael@0 | 6834 | } |
michael@0 | 6835 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 6836 | if (stcb->asoc.alternate) { |
michael@0 | 6837 | net = stcb->asoc.alternate; |
michael@0 | 6838 | } else { |
michael@0 | 6839 | net = stcb->asoc.primary_destination; |
michael@0 | 6840 | } |
michael@0 | 6841 | if (ca->sndrcv.sinfo_flags & SCTP_ABORT) { |
michael@0 | 6842 | /* Abort this assoc with m as the user defined reason */ |
michael@0 | 6843 | if (m != NULL) { |
michael@0 | 6844 | SCTP_BUF_PREPEND(m, sizeof(struct sctp_paramhdr), M_NOWAIT); |
michael@0 | 6845 | } else { |
michael@0 | 6846 | m = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), |
michael@0 | 6847 | 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 6848 | SCTP_BUF_LEN(m) = sizeof(struct sctp_paramhdr); |
michael@0 | 6849 | } |
michael@0 | 6850 | if (m != NULL) { |
michael@0 | 6851 | struct sctp_paramhdr *ph; |
michael@0 | 6852 | |
michael@0 | 6853 | ph = mtod(m, struct sctp_paramhdr *); |
michael@0 | 6854 | ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); |
michael@0 | 6855 | ph->param_length = htons(sizeof(struct sctp_paramhdr) + ca->sndlen); |
michael@0 | 6856 | } |
michael@0 | 6857 | /* We add one here to keep the assoc from |
michael@0 | 6858 | * dis-appearing on us. |
michael@0 | 6859 | */ |
michael@0 | 6860 | atomic_add_int(&stcb->asoc.refcnt, 1); |
michael@0 | 6861 | sctp_abort_an_association(inp, stcb, m, SCTP_SO_NOT_LOCKED); |
michael@0 | 6862 | /* sctp_abort_an_association calls sctp_free_asoc() |
michael@0 | 6863 | * free association will NOT free it since we |
michael@0 | 6864 | * incremented the refcnt .. we do this to prevent |
michael@0 | 6865 | * it being freed and things getting tricky since |
michael@0 | 6866 | * we could end up (from free_asoc) calling inpcb_free |
michael@0 | 6867 | * which would get a recursive lock call to the |
michael@0 | 6868 | * iterator lock.. But as a consequence of that the |
michael@0 | 6869 | * stcb will return to us un-locked.. since free_asoc |
michael@0 | 6870 | * returns with either no TCB or the TCB unlocked, we |
michael@0 | 6871 | * must relock.. to unlock in the iterator timer :-0 |
michael@0 | 6872 | */ |
michael@0 | 6873 | SCTP_TCB_LOCK(stcb); |
michael@0 | 6874 | atomic_add_int(&stcb->asoc.refcnt, -1); |
michael@0 | 6875 | goto no_chunk_output; |
michael@0 | 6876 | } else { |
michael@0 | 6877 | if (m) { |
michael@0 | 6878 | ret = sctp_msg_append(stcb, net, m, |
michael@0 | 6879 | &ca->sndrcv, 1); |
michael@0 | 6880 | } |
michael@0 | 6881 | asoc = &stcb->asoc; |
michael@0 | 6882 | if (ca->sndrcv.sinfo_flags & SCTP_EOF) { |
michael@0 | 6883 | /* shutdown this assoc */ |
michael@0 | 6884 | int cnt; |
michael@0 | 6885 | cnt = sctp_is_there_unsent_data(stcb, SCTP_SO_NOT_LOCKED); |
michael@0 | 6886 | |
michael@0 | 6887 | if (TAILQ_EMPTY(&asoc->send_queue) && |
michael@0 | 6888 | TAILQ_EMPTY(&asoc->sent_queue) && |
michael@0 | 6889 | (cnt == 0)) { |
michael@0 | 6890 | if (asoc->locked_on_sending) { |
michael@0 | 6891 | goto abort_anyway; |
michael@0 | 6892 | } |
michael@0 | 6893 | /* there is nothing queued to send, so I'm done... */ |
michael@0 | 6894 | if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) && |
michael@0 | 6895 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_RECEIVED) && |
michael@0 | 6896 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) { |
michael@0 | 6897 | /* only send SHUTDOWN the first time through */ |
michael@0 | 6898 | if (SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) { |
michael@0 | 6899 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
michael@0 | 6900 | } |
michael@0 | 6901 | SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); |
michael@0 | 6902 | SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); |
michael@0 | 6903 | sctp_stop_timers_for_shutdown(stcb); |
michael@0 | 6904 | sctp_send_shutdown(stcb, net); |
michael@0 | 6905 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb, |
michael@0 | 6906 | net); |
michael@0 | 6907 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, |
michael@0 | 6908 | asoc->primary_destination); |
michael@0 | 6909 | added_control = 1; |
michael@0 | 6910 | do_chunk_output = 0; |
michael@0 | 6911 | } |
michael@0 | 6912 | } else { |
michael@0 | 6913 | /* |
michael@0 | 6914 | * we still got (or just got) data to send, so set |
michael@0 | 6915 | * SHUTDOWN_PENDING |
michael@0 | 6916 | */ |
michael@0 | 6917 | /* |
michael@0 | 6918 | * XXX sockets draft says that SCTP_EOF should be |
michael@0 | 6919 | * sent with no data. currently, we will allow user |
michael@0 | 6920 | * data to be sent first and move to |
michael@0 | 6921 | * SHUTDOWN-PENDING |
michael@0 | 6922 | */ |
michael@0 | 6923 | if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) && |
michael@0 | 6924 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_RECEIVED) && |
michael@0 | 6925 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) { |
michael@0 | 6926 | if (asoc->locked_on_sending) { |
michael@0 | 6927 | /* Locked to send out the data */ |
michael@0 | 6928 | struct sctp_stream_queue_pending *sp; |
michael@0 | 6929 | sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead); |
michael@0 | 6930 | if (sp) { |
michael@0 | 6931 | if ((sp->length == 0) && (sp->msg_is_complete == 0)) |
michael@0 | 6932 | asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; |
michael@0 | 6933 | } |
michael@0 | 6934 | } |
michael@0 | 6935 | asoc->state |= SCTP_STATE_SHUTDOWN_PENDING; |
michael@0 | 6936 | if (TAILQ_EMPTY(&asoc->send_queue) && |
michael@0 | 6937 | TAILQ_EMPTY(&asoc->sent_queue) && |
michael@0 | 6938 | (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { |
michael@0 | 6939 | abort_anyway: |
michael@0 | 6940 | atomic_add_int(&stcb->asoc.refcnt, 1); |
michael@0 | 6941 | sctp_abort_an_association(stcb->sctp_ep, stcb, |
michael@0 | 6942 | NULL, SCTP_SO_NOT_LOCKED); |
michael@0 | 6943 | atomic_add_int(&stcb->asoc.refcnt, -1); |
michael@0 | 6944 | goto no_chunk_output; |
michael@0 | 6945 | } |
michael@0 | 6946 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, |
michael@0 | 6947 | asoc->primary_destination); |
michael@0 | 6948 | } |
michael@0 | 6949 | } |
michael@0 | 6950 | |
michael@0 | 6951 | } |
michael@0 | 6952 | } |
michael@0 | 6953 | un_sent = ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) + |
michael@0 | 6954 | (stcb->asoc.stream_queue_cnt * sizeof(struct sctp_data_chunk))); |
michael@0 | 6955 | |
michael@0 | 6956 | if ((sctp_is_feature_off(inp, SCTP_PCB_FLAGS_NODELAY)) && |
michael@0 | 6957 | (stcb->asoc.total_flight > 0) && |
michael@0 | 6958 | (un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD))) { |
michael@0 | 6959 | do_chunk_output = 0; |
michael@0 | 6960 | } |
michael@0 | 6961 | if (do_chunk_output) |
michael@0 | 6962 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_NOT_LOCKED); |
michael@0 | 6963 | else if (added_control) { |
michael@0 | 6964 | int num_out = 0, reason = 0, now_filled = 0; |
michael@0 | 6965 | struct timeval now; |
michael@0 | 6966 | int frag_point; |
michael@0 | 6967 | frag_point = sctp_get_frag_point(stcb, &stcb->asoc); |
michael@0 | 6968 | (void)sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out, |
michael@0 | 6969 | &reason, 1, 1, &now, &now_filled, frag_point, SCTP_SO_NOT_LOCKED); |
michael@0 | 6970 | } |
michael@0 | 6971 | no_chunk_output: |
michael@0 | 6972 | if (ret) { |
michael@0 | 6973 | ca->cnt_failed++; |
michael@0 | 6974 | } else { |
michael@0 | 6975 | ca->cnt_sent++; |
michael@0 | 6976 | } |
michael@0 | 6977 | } |
michael@0 | 6978 | |
michael@0 | 6979 | static void |
michael@0 | 6980 | sctp_sendall_completes(void *ptr, uint32_t val SCTP_UNUSED) |
michael@0 | 6981 | { |
michael@0 | 6982 | struct sctp_copy_all *ca; |
michael@0 | 6983 | |
michael@0 | 6984 | ca = (struct sctp_copy_all *)ptr; |
michael@0 | 6985 | /* |
michael@0 | 6986 | * Do a notify here? Kacheong suggests that the notify be done at |
michael@0 | 6987 | * the send time.. so you would push up a notification if any send |
michael@0 | 6988 | * failed. Don't know if this is feasable since the only failures we |
michael@0 | 6989 | * have is "memory" related and if you cannot get an mbuf to send |
michael@0 | 6990 | * the data you surely can't get an mbuf to send up to notify the |
michael@0 | 6991 | * user you can't send the data :-> |
michael@0 | 6992 | */ |
michael@0 | 6993 | |
michael@0 | 6994 | /* now free everything */ |
michael@0 | 6995 | sctp_m_freem(ca->m); |
michael@0 | 6996 | SCTP_FREE(ca, SCTP_M_COPYAL); |
michael@0 | 6997 | } |
michael@0 | 6998 | |
michael@0 | 6999 | |
michael@0 | 7000 | #define MC_ALIGN(m, len) do { \ |
michael@0 | 7001 | SCTP_BUF_RESV_UF(m, ((MCLBYTES - (len)) & ~(sizeof(long) - 1)); \ |
michael@0 | 7002 | } while (0) |
michael@0 | 7003 | |
michael@0 | 7004 | |
michael@0 | 7005 | |
michael@0 | 7006 | static struct mbuf * |
michael@0 | 7007 | sctp_copy_out_all(struct uio *uio, int len) |
michael@0 | 7008 | { |
michael@0 | 7009 | struct mbuf *ret, *at; |
michael@0 | 7010 | int left, willcpy, cancpy, error; |
michael@0 | 7011 | |
michael@0 | 7012 | ret = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_WAITOK, 1, MT_DATA); |
michael@0 | 7013 | if (ret == NULL) { |
michael@0 | 7014 | /* TSNH */ |
michael@0 | 7015 | return (NULL); |
michael@0 | 7016 | } |
michael@0 | 7017 | left = len; |
michael@0 | 7018 | SCTP_BUF_LEN(ret) = 0; |
michael@0 | 7019 | /* save space for the data chunk header */ |
michael@0 | 7020 | cancpy = M_TRAILINGSPACE(ret); |
michael@0 | 7021 | willcpy = min(cancpy, left); |
michael@0 | 7022 | at = ret; |
michael@0 | 7023 | while (left > 0) { |
michael@0 | 7024 | /* Align data to the end */ |
michael@0 | 7025 | error = uiomove(mtod(at, caddr_t), willcpy, uio); |
michael@0 | 7026 | if (error) { |
michael@0 | 7027 | err_out_now: |
michael@0 | 7028 | sctp_m_freem(at); |
michael@0 | 7029 | return (NULL); |
michael@0 | 7030 | } |
michael@0 | 7031 | SCTP_BUF_LEN(at) = willcpy; |
michael@0 | 7032 | SCTP_BUF_NEXT_PKT(at) = SCTP_BUF_NEXT(at) = 0; |
michael@0 | 7033 | left -= willcpy; |
michael@0 | 7034 | if (left > 0) { |
michael@0 | 7035 | SCTP_BUF_NEXT(at) = sctp_get_mbuf_for_msg(left, 0, M_WAITOK, 1, MT_DATA); |
michael@0 | 7036 | if (SCTP_BUF_NEXT(at) == NULL) { |
michael@0 | 7037 | goto err_out_now; |
michael@0 | 7038 | } |
michael@0 | 7039 | at = SCTP_BUF_NEXT(at); |
michael@0 | 7040 | SCTP_BUF_LEN(at) = 0; |
michael@0 | 7041 | cancpy = M_TRAILINGSPACE(at); |
michael@0 | 7042 | willcpy = min(cancpy, left); |
michael@0 | 7043 | } |
michael@0 | 7044 | } |
michael@0 | 7045 | return (ret); |
michael@0 | 7046 | } |
michael@0 | 7047 | |
michael@0 | 7048 | static int |
michael@0 | 7049 | sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m, |
michael@0 | 7050 | struct sctp_sndrcvinfo *srcv) |
michael@0 | 7051 | { |
michael@0 | 7052 | int ret; |
michael@0 | 7053 | struct sctp_copy_all *ca; |
michael@0 | 7054 | |
michael@0 | 7055 | SCTP_MALLOC(ca, struct sctp_copy_all *, sizeof(struct sctp_copy_all), |
michael@0 | 7056 | SCTP_M_COPYAL); |
michael@0 | 7057 | if (ca == NULL) { |
michael@0 | 7058 | sctp_m_freem(m); |
michael@0 | 7059 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 7060 | return (ENOMEM); |
michael@0 | 7061 | } |
michael@0 | 7062 | memset(ca, 0, sizeof(struct sctp_copy_all)); |
michael@0 | 7063 | |
michael@0 | 7064 | ca->inp = inp; |
michael@0 | 7065 | if (srcv) { |
michael@0 | 7066 | memcpy(&ca->sndrcv, srcv, sizeof(struct sctp_nonpad_sndrcvinfo)); |
michael@0 | 7067 | } |
michael@0 | 7068 | /* |
michael@0 | 7069 | * take off the sendall flag, it would be bad if we failed to do |
michael@0 | 7070 | * this :-0 |
michael@0 | 7071 | */ |
michael@0 | 7072 | ca->sndrcv.sinfo_flags &= ~SCTP_SENDALL; |
michael@0 | 7073 | /* get length and mbuf chain */ |
michael@0 | 7074 | if (uio) { |
michael@0 | 7075 | #if defined(__APPLE__) |
michael@0 | 7076 | #if defined(APPLE_LEOPARD) |
michael@0 | 7077 | ca->sndlen = uio->uio_resid; |
michael@0 | 7078 | #else |
michael@0 | 7079 | ca->sndlen = uio_resid(uio); |
michael@0 | 7080 | #endif |
michael@0 | 7081 | #else |
michael@0 | 7082 | ca->sndlen = uio->uio_resid; |
michael@0 | 7083 | #endif |
michael@0 | 7084 | #if defined(__APPLE__) |
michael@0 | 7085 | SCTP_SOCKET_UNLOCK(SCTP_INP_SO(inp), 0); |
michael@0 | 7086 | #endif |
michael@0 | 7087 | ca->m = sctp_copy_out_all(uio, ca->sndlen); |
michael@0 | 7088 | #if defined(__APPLE__) |
michael@0 | 7089 | SCTP_SOCKET_LOCK(SCTP_INP_SO(inp), 0); |
michael@0 | 7090 | #endif |
michael@0 | 7091 | if (ca->m == NULL) { |
michael@0 | 7092 | SCTP_FREE(ca, SCTP_M_COPYAL); |
michael@0 | 7093 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 7094 | return (ENOMEM); |
michael@0 | 7095 | } |
michael@0 | 7096 | } else { |
michael@0 | 7097 | /* Gather the length of the send */ |
michael@0 | 7098 | struct mbuf *mat; |
michael@0 | 7099 | |
michael@0 | 7100 | ca->sndlen = 0; |
michael@0 | 7101 | for (mat = m; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 7102 | ca->sndlen += SCTP_BUF_LEN(mat); |
michael@0 | 7103 | } |
michael@0 | 7104 | } |
michael@0 | 7105 | ret = sctp_initiate_iterator(NULL, sctp_sendall_iterator, NULL, |
michael@0 | 7106 | SCTP_PCB_ANY_FLAGS, SCTP_PCB_ANY_FEATURES, |
michael@0 | 7107 | SCTP_ASOC_ANY_STATE, |
michael@0 | 7108 | (void *)ca, 0, |
michael@0 | 7109 | sctp_sendall_completes, inp, 1); |
michael@0 | 7110 | if (ret) { |
michael@0 | 7111 | SCTP_PRINTF("Failed to initiate iterator for sendall\n"); |
michael@0 | 7112 | SCTP_FREE(ca, SCTP_M_COPYAL); |
michael@0 | 7113 | SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, EFAULT); |
michael@0 | 7114 | return (EFAULT); |
michael@0 | 7115 | } |
michael@0 | 7116 | return (0); |
michael@0 | 7117 | } |
michael@0 | 7118 | |
michael@0 | 7119 | |
michael@0 | 7120 | void |
michael@0 | 7121 | sctp_toss_old_cookies(struct sctp_tcb *stcb, struct sctp_association *asoc) |
michael@0 | 7122 | { |
michael@0 | 7123 | struct sctp_tmit_chunk *chk, *nchk; |
michael@0 | 7124 | |
michael@0 | 7125 | TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) { |
michael@0 | 7126 | if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) { |
michael@0 | 7127 | TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next); |
michael@0 | 7128 | if (chk->data) { |
michael@0 | 7129 | sctp_m_freem(chk->data); |
michael@0 | 7130 | chk->data = NULL; |
michael@0 | 7131 | } |
michael@0 | 7132 | asoc->ctrl_queue_cnt--; |
michael@0 | 7133 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 7134 | } |
michael@0 | 7135 | } |
michael@0 | 7136 | } |
michael@0 | 7137 | |
michael@0 | 7138 | void |
michael@0 | 7139 | sctp_toss_old_asconf(struct sctp_tcb *stcb) |
michael@0 | 7140 | { |
michael@0 | 7141 | struct sctp_association *asoc; |
michael@0 | 7142 | struct sctp_tmit_chunk *chk, *nchk; |
michael@0 | 7143 | struct sctp_asconf_chunk *acp; |
michael@0 | 7144 | |
michael@0 | 7145 | asoc = &stcb->asoc; |
michael@0 | 7146 | TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) { |
michael@0 | 7147 | /* find SCTP_ASCONF chunk in queue */ |
michael@0 | 7148 | if (chk->rec.chunk_id.id == SCTP_ASCONF) { |
michael@0 | 7149 | if (chk->data) { |
michael@0 | 7150 | acp = mtod(chk->data, struct sctp_asconf_chunk *); |
michael@0 | 7151 | if (SCTP_TSN_GT(ntohl(acp->serial_number), asoc->asconf_seq_out_acked)) { |
michael@0 | 7152 | /* Not Acked yet */ |
michael@0 | 7153 | break; |
michael@0 | 7154 | } |
michael@0 | 7155 | } |
michael@0 | 7156 | TAILQ_REMOVE(&asoc->asconf_send_queue, chk, sctp_next); |
michael@0 | 7157 | if (chk->data) { |
michael@0 | 7158 | sctp_m_freem(chk->data); |
michael@0 | 7159 | chk->data = NULL; |
michael@0 | 7160 | } |
michael@0 | 7161 | asoc->ctrl_queue_cnt--; |
michael@0 | 7162 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 7163 | } |
michael@0 | 7164 | } |
michael@0 | 7165 | } |
michael@0 | 7166 | |
michael@0 | 7167 | |
michael@0 | 7168 | static void |
michael@0 | 7169 | sctp_clean_up_datalist(struct sctp_tcb *stcb, |
michael@0 | 7170 | struct sctp_association *asoc, |
michael@0 | 7171 | struct sctp_tmit_chunk **data_list, |
michael@0 | 7172 | int bundle_at, |
michael@0 | 7173 | struct sctp_nets *net) |
michael@0 | 7174 | { |
michael@0 | 7175 | int i; |
michael@0 | 7176 | struct sctp_tmit_chunk *tp1; |
michael@0 | 7177 | |
michael@0 | 7178 | for (i = 0; i < bundle_at; i++) { |
michael@0 | 7179 | /* off of the send queue */ |
michael@0 | 7180 | TAILQ_REMOVE(&asoc->send_queue, data_list[i], sctp_next); |
michael@0 | 7181 | asoc->send_queue_cnt--; |
michael@0 | 7182 | if (i > 0) { |
michael@0 | 7183 | /* |
michael@0 | 7184 | * Any chunk NOT 0 you zap the time chunk 0 gets |
michael@0 | 7185 | * zapped or set based on if a RTO measurment is |
michael@0 | 7186 | * needed. |
michael@0 | 7187 | */ |
michael@0 | 7188 | data_list[i]->do_rtt = 0; |
michael@0 | 7189 | } |
michael@0 | 7190 | /* record time */ |
michael@0 | 7191 | data_list[i]->sent_rcv_time = net->last_sent_time; |
michael@0 | 7192 | data_list[i]->rec.data.cwnd_at_send = net->cwnd; |
michael@0 | 7193 | data_list[i]->rec.data.fast_retran_tsn = data_list[i]->rec.data.TSN_seq; |
michael@0 | 7194 | if (data_list[i]->whoTo == NULL) { |
michael@0 | 7195 | data_list[i]->whoTo = net; |
michael@0 | 7196 | atomic_add_int(&net->ref_count, 1); |
michael@0 | 7197 | } |
michael@0 | 7198 | /* on to the sent queue */ |
michael@0 | 7199 | tp1 = TAILQ_LAST(&asoc->sent_queue, sctpchunk_listhead); |
michael@0 | 7200 | if ((tp1) && SCTP_TSN_GT(tp1->rec.data.TSN_seq, data_list[i]->rec.data.TSN_seq)) { |
michael@0 | 7201 | struct sctp_tmit_chunk *tpp; |
michael@0 | 7202 | |
michael@0 | 7203 | /* need to move back */ |
michael@0 | 7204 | back_up_more: |
michael@0 | 7205 | tpp = TAILQ_PREV(tp1, sctpchunk_listhead, sctp_next); |
michael@0 | 7206 | if (tpp == NULL) { |
michael@0 | 7207 | TAILQ_INSERT_BEFORE(tp1, data_list[i], sctp_next); |
michael@0 | 7208 | goto all_done; |
michael@0 | 7209 | } |
michael@0 | 7210 | tp1 = tpp; |
michael@0 | 7211 | if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, data_list[i]->rec.data.TSN_seq)) { |
michael@0 | 7212 | goto back_up_more; |
michael@0 | 7213 | } |
michael@0 | 7214 | TAILQ_INSERT_AFTER(&asoc->sent_queue, tp1, data_list[i], sctp_next); |
michael@0 | 7215 | } else { |
michael@0 | 7216 | TAILQ_INSERT_TAIL(&asoc->sent_queue, |
michael@0 | 7217 | data_list[i], |
michael@0 | 7218 | sctp_next); |
michael@0 | 7219 | } |
michael@0 | 7220 | all_done: |
michael@0 | 7221 | /* This does not lower until the cum-ack passes it */ |
michael@0 | 7222 | asoc->sent_queue_cnt++; |
michael@0 | 7223 | if ((asoc->peers_rwnd <= 0) && |
michael@0 | 7224 | (asoc->total_flight == 0) && |
michael@0 | 7225 | (bundle_at == 1)) { |
michael@0 | 7226 | /* Mark the chunk as being a window probe */ |
michael@0 | 7227 | SCTP_STAT_INCR(sctps_windowprobed); |
michael@0 | 7228 | } |
michael@0 | 7229 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 7230 | sctp_audit_log(0xC2, 3); |
michael@0 | 7231 | #endif |
michael@0 | 7232 | data_list[i]->sent = SCTP_DATAGRAM_SENT; |
michael@0 | 7233 | data_list[i]->snd_count = 1; |
michael@0 | 7234 | data_list[i]->rec.data.chunk_was_revoked = 0; |
michael@0 | 7235 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
michael@0 | 7236 | sctp_misc_ints(SCTP_FLIGHT_LOG_UP, |
michael@0 | 7237 | data_list[i]->whoTo->flight_size, |
michael@0 | 7238 | data_list[i]->book_size, |
michael@0 | 7239 | (uintptr_t)data_list[i]->whoTo, |
michael@0 | 7240 | data_list[i]->rec.data.TSN_seq); |
michael@0 | 7241 | } |
michael@0 | 7242 | sctp_flight_size_increase(data_list[i]); |
michael@0 | 7243 | sctp_total_flight_increase(stcb, data_list[i]); |
michael@0 | 7244 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { |
michael@0 | 7245 | sctp_log_rwnd(SCTP_DECREASE_PEER_RWND, |
michael@0 | 7246 | asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); |
michael@0 | 7247 | } |
michael@0 | 7248 | asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd, |
michael@0 | 7249 | (uint32_t) (data_list[i]->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh))); |
michael@0 | 7250 | if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { |
michael@0 | 7251 | /* SWS sender side engages */ |
michael@0 | 7252 | asoc->peers_rwnd = 0; |
michael@0 | 7253 | } |
michael@0 | 7254 | } |
michael@0 | 7255 | if (asoc->cc_functions.sctp_cwnd_update_packet_transmitted) { |
michael@0 | 7256 | (*asoc->cc_functions.sctp_cwnd_update_packet_transmitted)(stcb, net); |
michael@0 | 7257 | } |
michael@0 | 7258 | } |
michael@0 | 7259 | |
michael@0 | 7260 | static void |
michael@0 | 7261 | sctp_clean_up_ctl(struct sctp_tcb *stcb, struct sctp_association *asoc, int so_locked |
michael@0 | 7262 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 7263 | SCTP_UNUSED |
michael@0 | 7264 | #endif |
michael@0 | 7265 | ) |
michael@0 | 7266 | { |
michael@0 | 7267 | struct sctp_tmit_chunk *chk, *nchk; |
michael@0 | 7268 | |
michael@0 | 7269 | TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) { |
michael@0 | 7270 | if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || |
michael@0 | 7271 | (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK) || /* EY */ |
michael@0 | 7272 | (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) || |
michael@0 | 7273 | (chk->rec.chunk_id.id == SCTP_HEARTBEAT_ACK) || |
michael@0 | 7274 | (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) || |
michael@0 | 7275 | (chk->rec.chunk_id.id == SCTP_SHUTDOWN) || |
michael@0 | 7276 | (chk->rec.chunk_id.id == SCTP_SHUTDOWN_ACK) || |
michael@0 | 7277 | (chk->rec.chunk_id.id == SCTP_OPERATION_ERROR) || |
michael@0 | 7278 | (chk->rec.chunk_id.id == SCTP_PACKET_DROPPED) || |
michael@0 | 7279 | (chk->rec.chunk_id.id == SCTP_COOKIE_ACK) || |
michael@0 | 7280 | (chk->rec.chunk_id.id == SCTP_ECN_CWR) || |
michael@0 | 7281 | (chk->rec.chunk_id.id == SCTP_ASCONF_ACK)) { |
michael@0 | 7282 | /* Stray chunks must be cleaned up */ |
michael@0 | 7283 | clean_up_anyway: |
michael@0 | 7284 | TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next); |
michael@0 | 7285 | if (chk->data) { |
michael@0 | 7286 | sctp_m_freem(chk->data); |
michael@0 | 7287 | chk->data = NULL; |
michael@0 | 7288 | } |
michael@0 | 7289 | asoc->ctrl_queue_cnt--; |
michael@0 | 7290 | if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) |
michael@0 | 7291 | asoc->fwd_tsn_cnt--; |
michael@0 | 7292 | sctp_free_a_chunk(stcb, chk, so_locked); |
michael@0 | 7293 | } else if (chk->rec.chunk_id.id == SCTP_STREAM_RESET) { |
michael@0 | 7294 | /* special handling, we must look into the param */ |
michael@0 | 7295 | if (chk != asoc->str_reset) { |
michael@0 | 7296 | goto clean_up_anyway; |
michael@0 | 7297 | } |
michael@0 | 7298 | } |
michael@0 | 7299 | } |
michael@0 | 7300 | } |
michael@0 | 7301 | |
michael@0 | 7302 | |
michael@0 | 7303 | static int |
michael@0 | 7304 | sctp_can_we_split_this(struct sctp_tcb *stcb, |
michael@0 | 7305 | uint32_t length, |
michael@0 | 7306 | uint32_t goal_mtu, uint32_t frag_point, int eeor_on) |
michael@0 | 7307 | { |
michael@0 | 7308 | /* Make a decision on if I should split a |
michael@0 | 7309 | * msg into multiple parts. This is only asked of |
michael@0 | 7310 | * incomplete messages. |
michael@0 | 7311 | */ |
michael@0 | 7312 | if (eeor_on) { |
michael@0 | 7313 | /* If we are doing EEOR we need to always send |
michael@0 | 7314 | * it if its the entire thing, since it might |
michael@0 | 7315 | * be all the guy is putting in the hopper. |
michael@0 | 7316 | */ |
michael@0 | 7317 | if (goal_mtu >= length) { |
michael@0 | 7318 | /*- |
michael@0 | 7319 | * If we have data outstanding, |
michael@0 | 7320 | * we get another chance when the sack |
michael@0 | 7321 | * arrives to transmit - wait for more data |
michael@0 | 7322 | */ |
michael@0 | 7323 | if (stcb->asoc.total_flight == 0) { |
michael@0 | 7324 | /* If nothing is in flight, we zero |
michael@0 | 7325 | * the packet counter. |
michael@0 | 7326 | */ |
michael@0 | 7327 | return (length); |
michael@0 | 7328 | } |
michael@0 | 7329 | return (0); |
michael@0 | 7330 | |
michael@0 | 7331 | } else { |
michael@0 | 7332 | /* You can fill the rest */ |
michael@0 | 7333 | return (goal_mtu); |
michael@0 | 7334 | } |
michael@0 | 7335 | } |
michael@0 | 7336 | /*- |
michael@0 | 7337 | * For those strange folk that make the send buffer |
michael@0 | 7338 | * smaller than our fragmentation point, we can't |
michael@0 | 7339 | * get a full msg in so we have to allow splitting. |
michael@0 | 7340 | */ |
michael@0 | 7341 | if (SCTP_SB_LIMIT_SND(stcb->sctp_socket) < frag_point) { |
michael@0 | 7342 | return (length); |
michael@0 | 7343 | } |
michael@0 | 7344 | |
michael@0 | 7345 | if ((length <= goal_mtu) || |
michael@0 | 7346 | ((length - goal_mtu) < SCTP_BASE_SYSCTL(sctp_min_residual))) { |
michael@0 | 7347 | /* Sub-optimial residual don't split in non-eeor mode. */ |
michael@0 | 7348 | return (0); |
michael@0 | 7349 | } |
michael@0 | 7350 | /* If we reach here length is larger |
michael@0 | 7351 | * than the goal_mtu. Do we wish to split |
michael@0 | 7352 | * it for the sake of packet putting together? |
michael@0 | 7353 | */ |
michael@0 | 7354 | if (goal_mtu >= min(SCTP_BASE_SYSCTL(sctp_min_split_point), frag_point)) { |
michael@0 | 7355 | /* Its ok to split it */ |
michael@0 | 7356 | return (min(goal_mtu, frag_point)); |
michael@0 | 7357 | } |
michael@0 | 7358 | /* Nope, can't split */ |
michael@0 | 7359 | return (0); |
michael@0 | 7360 | |
michael@0 | 7361 | } |
michael@0 | 7362 | |
michael@0 | 7363 | static uint32_t |
michael@0 | 7364 | sctp_move_to_outqueue(struct sctp_tcb *stcb, |
michael@0 | 7365 | struct sctp_stream_out *strq, |
michael@0 | 7366 | uint32_t goal_mtu, |
michael@0 | 7367 | uint32_t frag_point, |
michael@0 | 7368 | int *locked, |
michael@0 | 7369 | int *giveup, |
michael@0 | 7370 | int eeor_mode, |
michael@0 | 7371 | int *bail, |
michael@0 | 7372 | int so_locked |
michael@0 | 7373 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 7374 | SCTP_UNUSED |
michael@0 | 7375 | #endif |
michael@0 | 7376 | ) |
michael@0 | 7377 | { |
michael@0 | 7378 | /* Move from the stream to the send_queue keeping track of the total */ |
michael@0 | 7379 | struct sctp_association *asoc; |
michael@0 | 7380 | struct sctp_stream_queue_pending *sp; |
michael@0 | 7381 | struct sctp_tmit_chunk *chk; |
michael@0 | 7382 | struct sctp_data_chunk *dchkh; |
michael@0 | 7383 | uint32_t to_move, length; |
michael@0 | 7384 | uint8_t rcv_flags = 0; |
michael@0 | 7385 | uint8_t some_taken; |
michael@0 | 7386 | uint8_t send_lock_up = 0; |
michael@0 | 7387 | |
michael@0 | 7388 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 7389 | asoc = &stcb->asoc; |
michael@0 | 7390 | one_more_time: |
michael@0 | 7391 | /*sa_ignore FREED_MEMORY*/ |
michael@0 | 7392 | sp = TAILQ_FIRST(&strq->outqueue); |
michael@0 | 7393 | if (sp == NULL) { |
michael@0 | 7394 | *locked = 0; |
michael@0 | 7395 | if (send_lock_up == 0) { |
michael@0 | 7396 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 7397 | send_lock_up = 1; |
michael@0 | 7398 | } |
michael@0 | 7399 | sp = TAILQ_FIRST(&strq->outqueue); |
michael@0 | 7400 | if (sp) { |
michael@0 | 7401 | goto one_more_time; |
michael@0 | 7402 | } |
michael@0 | 7403 | if (strq->last_msg_incomplete) { |
michael@0 | 7404 | SCTP_PRINTF("Huh? Stream:%d lm_in_c=%d but queue is NULL\n", |
michael@0 | 7405 | strq->stream_no, |
michael@0 | 7406 | strq->last_msg_incomplete); |
michael@0 | 7407 | strq->last_msg_incomplete = 0; |
michael@0 | 7408 | } |
michael@0 | 7409 | to_move = 0; |
michael@0 | 7410 | if (send_lock_up) { |
michael@0 | 7411 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 7412 | send_lock_up = 0; |
michael@0 | 7413 | } |
michael@0 | 7414 | goto out_of; |
michael@0 | 7415 | } |
michael@0 | 7416 | if ((sp->msg_is_complete) && (sp->length == 0)) { |
michael@0 | 7417 | if (sp->sender_all_done) { |
michael@0 | 7418 | /* We are doing differed cleanup. Last |
michael@0 | 7419 | * time through when we took all the data |
michael@0 | 7420 | * the sender_all_done was not set. |
michael@0 | 7421 | */ |
michael@0 | 7422 | if ((sp->put_last_out == 0) && (sp->discard_rest == 0)) { |
michael@0 | 7423 | SCTP_PRINTF("Gak, put out entire msg with NO end!-1\n"); |
michael@0 | 7424 | SCTP_PRINTF("sender_done:%d len:%d msg_comp:%d put_last_out:%d send_lock:%d\n", |
michael@0 | 7425 | sp->sender_all_done, |
michael@0 | 7426 | sp->length, |
michael@0 | 7427 | sp->msg_is_complete, |
michael@0 | 7428 | sp->put_last_out, |
michael@0 | 7429 | send_lock_up); |
michael@0 | 7430 | } |
michael@0 | 7431 | if ((TAILQ_NEXT(sp, next) == NULL) && (send_lock_up == 0)) { |
michael@0 | 7432 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 7433 | send_lock_up = 1; |
michael@0 | 7434 | } |
michael@0 | 7435 | atomic_subtract_int(&asoc->stream_queue_cnt, 1); |
michael@0 | 7436 | TAILQ_REMOVE(&strq->outqueue, sp, next); |
michael@0 | 7437 | stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp, send_lock_up); |
michael@0 | 7438 | if (sp->net) { |
michael@0 | 7439 | sctp_free_remote_addr(sp->net); |
michael@0 | 7440 | sp->net = NULL; |
michael@0 | 7441 | } |
michael@0 | 7442 | if (sp->data) { |
michael@0 | 7443 | sctp_m_freem(sp->data); |
michael@0 | 7444 | sp->data = NULL; |
michael@0 | 7445 | } |
michael@0 | 7446 | sctp_free_a_strmoq(stcb, sp, so_locked); |
michael@0 | 7447 | /* we can't be locked to it */ |
michael@0 | 7448 | *locked = 0; |
michael@0 | 7449 | stcb->asoc.locked_on_sending = NULL; |
michael@0 | 7450 | if (send_lock_up) { |
michael@0 | 7451 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 7452 | send_lock_up = 0; |
michael@0 | 7453 | } |
michael@0 | 7454 | /* back to get the next msg */ |
michael@0 | 7455 | goto one_more_time; |
michael@0 | 7456 | } else { |
michael@0 | 7457 | /* sender just finished this but |
michael@0 | 7458 | * still holds a reference |
michael@0 | 7459 | */ |
michael@0 | 7460 | *locked = 1; |
michael@0 | 7461 | *giveup = 1; |
michael@0 | 7462 | to_move = 0; |
michael@0 | 7463 | goto out_of; |
michael@0 | 7464 | } |
michael@0 | 7465 | } else { |
michael@0 | 7466 | /* is there some to get */ |
michael@0 | 7467 | if (sp->length == 0) { |
michael@0 | 7468 | /* no */ |
michael@0 | 7469 | *locked = 1; |
michael@0 | 7470 | *giveup = 1; |
michael@0 | 7471 | to_move = 0; |
michael@0 | 7472 | goto out_of; |
michael@0 | 7473 | } else if (sp->discard_rest) { |
michael@0 | 7474 | if (send_lock_up == 0) { |
michael@0 | 7475 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 7476 | send_lock_up = 1; |
michael@0 | 7477 | } |
michael@0 | 7478 | /* Whack down the size */ |
michael@0 | 7479 | atomic_subtract_int(&stcb->asoc.total_output_queue_size, sp->length); |
michael@0 | 7480 | if ((stcb->sctp_socket != NULL) && \ |
michael@0 | 7481 | ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
michael@0 | 7482 | (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { |
michael@0 | 7483 | atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc, sp->length); |
michael@0 | 7484 | } |
michael@0 | 7485 | if (sp->data) { |
michael@0 | 7486 | sctp_m_freem(sp->data); |
michael@0 | 7487 | sp->data = NULL; |
michael@0 | 7488 | sp->tail_mbuf = NULL; |
michael@0 | 7489 | } |
michael@0 | 7490 | sp->length = 0; |
michael@0 | 7491 | sp->some_taken = 1; |
michael@0 | 7492 | *locked = 1; |
michael@0 | 7493 | *giveup = 1; |
michael@0 | 7494 | to_move = 0; |
michael@0 | 7495 | goto out_of; |
michael@0 | 7496 | } |
michael@0 | 7497 | } |
michael@0 | 7498 | some_taken = sp->some_taken; |
michael@0 | 7499 | if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { |
michael@0 | 7500 | sp->msg_is_complete = 1; |
michael@0 | 7501 | } |
michael@0 | 7502 | re_look: |
michael@0 | 7503 | length = sp->length; |
michael@0 | 7504 | if (sp->msg_is_complete) { |
michael@0 | 7505 | /* The message is complete */ |
michael@0 | 7506 | to_move = min(length, frag_point); |
michael@0 | 7507 | if (to_move == length) { |
michael@0 | 7508 | /* All of it fits in the MTU */ |
michael@0 | 7509 | if (sp->some_taken) { |
michael@0 | 7510 | rcv_flags |= SCTP_DATA_LAST_FRAG; |
michael@0 | 7511 | sp->put_last_out = 1; |
michael@0 | 7512 | } else { |
michael@0 | 7513 | rcv_flags |= SCTP_DATA_NOT_FRAG; |
michael@0 | 7514 | sp->put_last_out = 1; |
michael@0 | 7515 | } |
michael@0 | 7516 | } else { |
michael@0 | 7517 | /* Not all of it fits, we fragment */ |
michael@0 | 7518 | if (sp->some_taken == 0) { |
michael@0 | 7519 | rcv_flags |= SCTP_DATA_FIRST_FRAG; |
michael@0 | 7520 | } |
michael@0 | 7521 | sp->some_taken = 1; |
michael@0 | 7522 | } |
michael@0 | 7523 | } else { |
michael@0 | 7524 | to_move = sctp_can_we_split_this(stcb, length, goal_mtu, frag_point, eeor_mode); |
michael@0 | 7525 | if (to_move) { |
michael@0 | 7526 | /*- |
michael@0 | 7527 | * We use a snapshot of length in case it |
michael@0 | 7528 | * is expanding during the compare. |
michael@0 | 7529 | */ |
michael@0 | 7530 | uint32_t llen; |
michael@0 | 7531 | |
michael@0 | 7532 | llen = length; |
michael@0 | 7533 | if (to_move >= llen) { |
michael@0 | 7534 | to_move = llen; |
michael@0 | 7535 | if (send_lock_up == 0) { |
michael@0 | 7536 | /*- |
michael@0 | 7537 | * We are taking all of an incomplete msg |
michael@0 | 7538 | * thus we need a send lock. |
michael@0 | 7539 | */ |
michael@0 | 7540 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 7541 | send_lock_up = 1; |
michael@0 | 7542 | if (sp->msg_is_complete) { |
michael@0 | 7543 | /* the sender finished the msg */ |
michael@0 | 7544 | goto re_look; |
michael@0 | 7545 | } |
michael@0 | 7546 | } |
michael@0 | 7547 | } |
michael@0 | 7548 | if (sp->some_taken == 0) { |
michael@0 | 7549 | rcv_flags |= SCTP_DATA_FIRST_FRAG; |
michael@0 | 7550 | sp->some_taken = 1; |
michael@0 | 7551 | } |
michael@0 | 7552 | } else { |
michael@0 | 7553 | /* Nothing to take. */ |
michael@0 | 7554 | if (sp->some_taken) { |
michael@0 | 7555 | *locked = 1; |
michael@0 | 7556 | } |
michael@0 | 7557 | *giveup = 1; |
michael@0 | 7558 | to_move = 0; |
michael@0 | 7559 | goto out_of; |
michael@0 | 7560 | } |
michael@0 | 7561 | } |
michael@0 | 7562 | |
michael@0 | 7563 | /* If we reach here, we can copy out a chunk */ |
michael@0 | 7564 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 7565 | if (chk == NULL) { |
michael@0 | 7566 | /* No chunk memory */ |
michael@0 | 7567 | *giveup = 1; |
michael@0 | 7568 | to_move = 0; |
michael@0 | 7569 | goto out_of; |
michael@0 | 7570 | } |
michael@0 | 7571 | /* Setup for unordered if needed by looking |
michael@0 | 7572 | * at the user sent info flags. |
michael@0 | 7573 | */ |
michael@0 | 7574 | if (sp->sinfo_flags & SCTP_UNORDERED) { |
michael@0 | 7575 | rcv_flags |= SCTP_DATA_UNORDERED; |
michael@0 | 7576 | } |
michael@0 | 7577 | if ((SCTP_BASE_SYSCTL(sctp_enable_sack_immediately) && ((sp->sinfo_flags & SCTP_EOF) == SCTP_EOF)) || |
michael@0 | 7578 | ((sp->sinfo_flags & SCTP_SACK_IMMEDIATELY) == SCTP_SACK_IMMEDIATELY)) { |
michael@0 | 7579 | rcv_flags |= SCTP_DATA_SACK_IMMEDIATELY; |
michael@0 | 7580 | } |
michael@0 | 7581 | /* clear out the chunk before setting up */ |
michael@0 | 7582 | memset(chk, 0, sizeof(*chk)); |
michael@0 | 7583 | chk->rec.data.rcv_flags = rcv_flags; |
michael@0 | 7584 | |
michael@0 | 7585 | if (to_move >= length) { |
michael@0 | 7586 | /* we think we can steal the whole thing */ |
michael@0 | 7587 | if ((sp->sender_all_done == 0) && (send_lock_up == 0)) { |
michael@0 | 7588 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 7589 | send_lock_up = 1; |
michael@0 | 7590 | } |
michael@0 | 7591 | if (to_move < sp->length) { |
michael@0 | 7592 | /* bail, it changed */ |
michael@0 | 7593 | goto dont_do_it; |
michael@0 | 7594 | } |
michael@0 | 7595 | chk->data = sp->data; |
michael@0 | 7596 | chk->last_mbuf = sp->tail_mbuf; |
michael@0 | 7597 | /* register the stealing */ |
michael@0 | 7598 | sp->data = sp->tail_mbuf = NULL; |
michael@0 | 7599 | } else { |
michael@0 | 7600 | struct mbuf *m; |
michael@0 | 7601 | dont_do_it: |
michael@0 | 7602 | chk->data = SCTP_M_COPYM(sp->data, 0, to_move, M_NOWAIT); |
michael@0 | 7603 | chk->last_mbuf = NULL; |
michael@0 | 7604 | if (chk->data == NULL) { |
michael@0 | 7605 | sp->some_taken = some_taken; |
michael@0 | 7606 | sctp_free_a_chunk(stcb, chk, so_locked); |
michael@0 | 7607 | *bail = 1; |
michael@0 | 7608 | to_move = 0; |
michael@0 | 7609 | goto out_of; |
michael@0 | 7610 | } |
michael@0 | 7611 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 7612 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 7613 | struct mbuf *mat; |
michael@0 | 7614 | |
michael@0 | 7615 | for (mat = chk->data; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 7616 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 7617 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 7618 | } |
michael@0 | 7619 | } |
michael@0 | 7620 | } |
michael@0 | 7621 | #endif |
michael@0 | 7622 | /* Pull off the data */ |
michael@0 | 7623 | m_adj(sp->data, to_move); |
michael@0 | 7624 | /* Now lets work our way down and compact it */ |
michael@0 | 7625 | m = sp->data; |
michael@0 | 7626 | while (m && (SCTP_BUF_LEN(m) == 0)) { |
michael@0 | 7627 | sp->data = SCTP_BUF_NEXT(m); |
michael@0 | 7628 | SCTP_BUF_NEXT(m) = NULL; |
michael@0 | 7629 | if (sp->tail_mbuf == m) { |
michael@0 | 7630 | /*- |
michael@0 | 7631 | * Freeing tail? TSNH since |
michael@0 | 7632 | * we supposedly were taking less |
michael@0 | 7633 | * than the sp->length. |
michael@0 | 7634 | */ |
michael@0 | 7635 | #ifdef INVARIANTS |
michael@0 | 7636 | panic("Huh, freing tail? - TSNH"); |
michael@0 | 7637 | #else |
michael@0 | 7638 | SCTP_PRINTF("Huh, freeing tail? - TSNH\n"); |
michael@0 | 7639 | sp->tail_mbuf = sp->data = NULL; |
michael@0 | 7640 | sp->length = 0; |
michael@0 | 7641 | #endif |
michael@0 | 7642 | |
michael@0 | 7643 | } |
michael@0 | 7644 | sctp_m_free(m); |
michael@0 | 7645 | m = sp->data; |
michael@0 | 7646 | } |
michael@0 | 7647 | } |
michael@0 | 7648 | if (SCTP_BUF_IS_EXTENDED(chk->data)) { |
michael@0 | 7649 | chk->copy_by_ref = 1; |
michael@0 | 7650 | } else { |
michael@0 | 7651 | chk->copy_by_ref = 0; |
michael@0 | 7652 | } |
michael@0 | 7653 | /* get last_mbuf and counts of mb useage |
michael@0 | 7654 | * This is ugly but hopefully its only one mbuf. |
michael@0 | 7655 | */ |
michael@0 | 7656 | if (chk->last_mbuf == NULL) { |
michael@0 | 7657 | chk->last_mbuf = chk->data; |
michael@0 | 7658 | while (SCTP_BUF_NEXT(chk->last_mbuf) != NULL) { |
michael@0 | 7659 | chk->last_mbuf = SCTP_BUF_NEXT(chk->last_mbuf); |
michael@0 | 7660 | } |
michael@0 | 7661 | } |
michael@0 | 7662 | |
michael@0 | 7663 | if (to_move > length) { |
michael@0 | 7664 | /*- This should not happen either |
michael@0 | 7665 | * since we always lower to_move to the size |
michael@0 | 7666 | * of sp->length if its larger. |
michael@0 | 7667 | */ |
michael@0 | 7668 | #ifdef INVARIANTS |
michael@0 | 7669 | panic("Huh, how can to_move be larger?"); |
michael@0 | 7670 | #else |
michael@0 | 7671 | SCTP_PRINTF("Huh, how can to_move be larger?\n"); |
michael@0 | 7672 | sp->length = 0; |
michael@0 | 7673 | #endif |
michael@0 | 7674 | } else { |
michael@0 | 7675 | atomic_subtract_int(&sp->length, to_move); |
michael@0 | 7676 | } |
michael@0 | 7677 | if (M_LEADINGSPACE(chk->data) < (int)sizeof(struct sctp_data_chunk)) { |
michael@0 | 7678 | /* Not enough room for a chunk header, get some */ |
michael@0 | 7679 | struct mbuf *m; |
michael@0 | 7680 | m = sctp_get_mbuf_for_msg(1, 0, M_NOWAIT, 0, MT_DATA); |
michael@0 | 7681 | if (m == NULL) { |
michael@0 | 7682 | /* |
michael@0 | 7683 | * we're in trouble here. _PREPEND below will free |
michael@0 | 7684 | * all the data if there is no leading space, so we |
michael@0 | 7685 | * must put the data back and restore. |
michael@0 | 7686 | */ |
michael@0 | 7687 | if (send_lock_up == 0) { |
michael@0 | 7688 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 7689 | send_lock_up = 1; |
michael@0 | 7690 | } |
michael@0 | 7691 | if (chk->data == NULL) { |
michael@0 | 7692 | /* unsteal the data */ |
michael@0 | 7693 | sp->data = chk->data; |
michael@0 | 7694 | sp->tail_mbuf = chk->last_mbuf; |
michael@0 | 7695 | } else { |
michael@0 | 7696 | struct mbuf *m_tmp; |
michael@0 | 7697 | /* reassemble the data */ |
michael@0 | 7698 | m_tmp = sp->data; |
michael@0 | 7699 | sp->data = chk->data; |
michael@0 | 7700 | SCTP_BUF_NEXT(chk->last_mbuf) = m_tmp; |
michael@0 | 7701 | } |
michael@0 | 7702 | sp->some_taken = some_taken; |
michael@0 | 7703 | atomic_add_int(&sp->length, to_move); |
michael@0 | 7704 | chk->data = NULL; |
michael@0 | 7705 | *bail = 1; |
michael@0 | 7706 | sctp_free_a_chunk(stcb, chk, so_locked); |
michael@0 | 7707 | to_move = 0; |
michael@0 | 7708 | goto out_of; |
michael@0 | 7709 | } else { |
michael@0 | 7710 | SCTP_BUF_LEN(m) = 0; |
michael@0 | 7711 | SCTP_BUF_NEXT(m) = chk->data; |
michael@0 | 7712 | chk->data = m; |
michael@0 | 7713 | M_ALIGN(chk->data, 4); |
michael@0 | 7714 | } |
michael@0 | 7715 | } |
michael@0 | 7716 | SCTP_BUF_PREPEND(chk->data, sizeof(struct sctp_data_chunk), M_NOWAIT); |
michael@0 | 7717 | if (chk->data == NULL) { |
michael@0 | 7718 | /* HELP, TSNH since we assured it would not above? */ |
michael@0 | 7719 | #ifdef INVARIANTS |
michael@0 | 7720 | panic("prepend failes HELP?"); |
michael@0 | 7721 | #else |
michael@0 | 7722 | SCTP_PRINTF("prepend fails HELP?\n"); |
michael@0 | 7723 | sctp_free_a_chunk(stcb, chk, so_locked); |
michael@0 | 7724 | #endif |
michael@0 | 7725 | *bail = 1; |
michael@0 | 7726 | to_move = 0; |
michael@0 | 7727 | goto out_of; |
michael@0 | 7728 | } |
michael@0 | 7729 | sctp_snd_sb_alloc(stcb, sizeof(struct sctp_data_chunk)); |
michael@0 | 7730 | chk->book_size = chk->send_size = (to_move + sizeof(struct sctp_data_chunk)); |
michael@0 | 7731 | chk->book_size_scale = 0; |
michael@0 | 7732 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 7733 | |
michael@0 | 7734 | chk->flags = 0; |
michael@0 | 7735 | chk->asoc = &stcb->asoc; |
michael@0 | 7736 | chk->pad_inplace = 0; |
michael@0 | 7737 | chk->no_fr_allowed = 0; |
michael@0 | 7738 | chk->rec.data.stream_seq = strq->next_sequence_send; |
michael@0 | 7739 | if (rcv_flags & SCTP_DATA_LAST_FRAG) { |
michael@0 | 7740 | strq->next_sequence_send++; |
michael@0 | 7741 | } |
michael@0 | 7742 | chk->rec.data.stream_number = sp->stream; |
michael@0 | 7743 | chk->rec.data.payloadtype = sp->ppid; |
michael@0 | 7744 | chk->rec.data.context = sp->context; |
michael@0 | 7745 | chk->rec.data.doing_fast_retransmit = 0; |
michael@0 | 7746 | |
michael@0 | 7747 | chk->rec.data.timetodrop = sp->ts; |
michael@0 | 7748 | chk->flags = sp->act_flags; |
michael@0 | 7749 | |
michael@0 | 7750 | if (sp->net) { |
michael@0 | 7751 | chk->whoTo = sp->net; |
michael@0 | 7752 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 7753 | } else |
michael@0 | 7754 | chk->whoTo = NULL; |
michael@0 | 7755 | |
michael@0 | 7756 | if (sp->holds_key_ref) { |
michael@0 | 7757 | chk->auth_keyid = sp->auth_keyid; |
michael@0 | 7758 | sctp_auth_key_acquire(stcb, chk->auth_keyid); |
michael@0 | 7759 | chk->holds_key_ref = 1; |
michael@0 | 7760 | } |
michael@0 | 7761 | |
michael@0 | 7762 | #if defined(__FreeBSD__) || defined(__Panda__) |
michael@0 | 7763 | chk->rec.data.TSN_seq = atomic_fetchadd_int(&asoc->sending_seq, 1); |
michael@0 | 7764 | #else |
michael@0 | 7765 | chk->rec.data.TSN_seq = asoc->sending_seq++; |
michael@0 | 7766 | #endif |
michael@0 | 7767 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_AT_SEND_2_OUTQ) { |
michael@0 | 7768 | sctp_misc_ints(SCTP_STRMOUT_LOG_SEND, |
michael@0 | 7769 | (uintptr_t)stcb, sp->length, |
michael@0 | 7770 | (uint32_t)((chk->rec.data.stream_number << 16) | chk->rec.data.stream_seq), |
michael@0 | 7771 | chk->rec.data.TSN_seq); |
michael@0 | 7772 | } |
michael@0 | 7773 | dchkh = mtod(chk->data, struct sctp_data_chunk *); |
michael@0 | 7774 | /* |
michael@0 | 7775 | * Put the rest of the things in place now. Size was done |
michael@0 | 7776 | * earlier in previous loop prior to padding. |
michael@0 | 7777 | */ |
michael@0 | 7778 | |
michael@0 | 7779 | #ifdef SCTP_ASOCLOG_OF_TSNS |
michael@0 | 7780 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 7781 | if (asoc->tsn_out_at >= SCTP_TSN_LOG_SIZE) { |
michael@0 | 7782 | asoc->tsn_out_at = 0; |
michael@0 | 7783 | asoc->tsn_out_wrapped = 1; |
michael@0 | 7784 | } |
michael@0 | 7785 | asoc->out_tsnlog[asoc->tsn_out_at].tsn = chk->rec.data.TSN_seq; |
michael@0 | 7786 | asoc->out_tsnlog[asoc->tsn_out_at].strm = chk->rec.data.stream_number; |
michael@0 | 7787 | asoc->out_tsnlog[asoc->tsn_out_at].seq = chk->rec.data.stream_seq; |
michael@0 | 7788 | asoc->out_tsnlog[asoc->tsn_out_at].sz = chk->send_size; |
michael@0 | 7789 | asoc->out_tsnlog[asoc->tsn_out_at].flgs = chk->rec.data.rcv_flags; |
michael@0 | 7790 | asoc->out_tsnlog[asoc->tsn_out_at].stcb = (void *)stcb; |
michael@0 | 7791 | asoc->out_tsnlog[asoc->tsn_out_at].in_pos = asoc->tsn_out_at; |
michael@0 | 7792 | asoc->out_tsnlog[asoc->tsn_out_at].in_out = 2; |
michael@0 | 7793 | asoc->tsn_out_at++; |
michael@0 | 7794 | #endif |
michael@0 | 7795 | |
michael@0 | 7796 | dchkh->ch.chunk_type = SCTP_DATA; |
michael@0 | 7797 | dchkh->ch.chunk_flags = chk->rec.data.rcv_flags; |
michael@0 | 7798 | dchkh->dp.tsn = htonl(chk->rec.data.TSN_seq); |
michael@0 | 7799 | dchkh->dp.stream_id = htons(strq->stream_no); |
michael@0 | 7800 | dchkh->dp.stream_sequence = htons(chk->rec.data.stream_seq); |
michael@0 | 7801 | dchkh->dp.protocol_id = chk->rec.data.payloadtype; |
michael@0 | 7802 | dchkh->ch.chunk_length = htons(chk->send_size); |
michael@0 | 7803 | /* Now advance the chk->send_size by the actual pad needed. */ |
michael@0 | 7804 | if (chk->send_size < SCTP_SIZE32(chk->book_size)) { |
michael@0 | 7805 | /* need a pad */ |
michael@0 | 7806 | struct mbuf *lm; |
michael@0 | 7807 | int pads; |
michael@0 | 7808 | |
michael@0 | 7809 | pads = SCTP_SIZE32(chk->book_size) - chk->send_size; |
michael@0 | 7810 | if (sctp_pad_lastmbuf(chk->data, pads, chk->last_mbuf) == 0) { |
michael@0 | 7811 | chk->pad_inplace = 1; |
michael@0 | 7812 | } |
michael@0 | 7813 | if ((lm = SCTP_BUF_NEXT(chk->last_mbuf)) != NULL) { |
michael@0 | 7814 | /* pad added an mbuf */ |
michael@0 | 7815 | chk->last_mbuf = lm; |
michael@0 | 7816 | } |
michael@0 | 7817 | chk->send_size += pads; |
michael@0 | 7818 | } |
michael@0 | 7819 | if (PR_SCTP_ENABLED(chk->flags)) { |
michael@0 | 7820 | asoc->pr_sctp_cnt++; |
michael@0 | 7821 | } |
michael@0 | 7822 | if (sp->msg_is_complete && (sp->length == 0) && (sp->sender_all_done)) { |
michael@0 | 7823 | /* All done pull and kill the message */ |
michael@0 | 7824 | atomic_subtract_int(&asoc->stream_queue_cnt, 1); |
michael@0 | 7825 | if (sp->put_last_out == 0) { |
michael@0 | 7826 | SCTP_PRINTF("Gak, put out entire msg with NO end!-2\n"); |
michael@0 | 7827 | SCTP_PRINTF("sender_done:%d len:%d msg_comp:%d put_last_out:%d send_lock:%d\n", |
michael@0 | 7828 | sp->sender_all_done, |
michael@0 | 7829 | sp->length, |
michael@0 | 7830 | sp->msg_is_complete, |
michael@0 | 7831 | sp->put_last_out, |
michael@0 | 7832 | send_lock_up); |
michael@0 | 7833 | } |
michael@0 | 7834 | if ((send_lock_up == 0) && (TAILQ_NEXT(sp, next) == NULL)) { |
michael@0 | 7835 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 7836 | send_lock_up = 1; |
michael@0 | 7837 | } |
michael@0 | 7838 | TAILQ_REMOVE(&strq->outqueue, sp, next); |
michael@0 | 7839 | stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp, send_lock_up); |
michael@0 | 7840 | if (sp->net) { |
michael@0 | 7841 | sctp_free_remote_addr(sp->net); |
michael@0 | 7842 | sp->net = NULL; |
michael@0 | 7843 | } |
michael@0 | 7844 | if (sp->data) { |
michael@0 | 7845 | sctp_m_freem(sp->data); |
michael@0 | 7846 | sp->data = NULL; |
michael@0 | 7847 | } |
michael@0 | 7848 | sctp_free_a_strmoq(stcb, sp, so_locked); |
michael@0 | 7849 | |
michael@0 | 7850 | /* we can't be locked to it */ |
michael@0 | 7851 | *locked = 0; |
michael@0 | 7852 | stcb->asoc.locked_on_sending = NULL; |
michael@0 | 7853 | } else { |
michael@0 | 7854 | /* more to go, we are locked */ |
michael@0 | 7855 | *locked = 1; |
michael@0 | 7856 | } |
michael@0 | 7857 | asoc->chunks_on_out_queue++; |
michael@0 | 7858 | strq->chunks_on_queues++; |
michael@0 | 7859 | TAILQ_INSERT_TAIL(&asoc->send_queue, chk, sctp_next); |
michael@0 | 7860 | asoc->send_queue_cnt++; |
michael@0 | 7861 | out_of: |
michael@0 | 7862 | if (send_lock_up) { |
michael@0 | 7863 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 7864 | } |
michael@0 | 7865 | return (to_move); |
michael@0 | 7866 | } |
michael@0 | 7867 | |
michael@0 | 7868 | |
michael@0 | 7869 | static void |
michael@0 | 7870 | sctp_fill_outqueue(struct sctp_tcb *stcb, |
michael@0 | 7871 | struct sctp_nets *net, int frag_point, int eeor_mode, int *quit_now, int so_locked |
michael@0 | 7872 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 7873 | SCTP_UNUSED |
michael@0 | 7874 | #endif |
michael@0 | 7875 | ) |
michael@0 | 7876 | { |
michael@0 | 7877 | struct sctp_association *asoc; |
michael@0 | 7878 | struct sctp_stream_out *strq; |
michael@0 | 7879 | int goal_mtu, moved_how_much, total_moved = 0, bail = 0; |
michael@0 | 7880 | int locked, giveup; |
michael@0 | 7881 | |
michael@0 | 7882 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 7883 | asoc = &stcb->asoc; |
michael@0 | 7884 | switch (net->ro._l_addr.sa.sa_family) { |
michael@0 | 7885 | #ifdef INET |
michael@0 | 7886 | case AF_INET: |
michael@0 | 7887 | goal_mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; |
michael@0 | 7888 | break; |
michael@0 | 7889 | #endif |
michael@0 | 7890 | #ifdef INET6 |
michael@0 | 7891 | case AF_INET6: |
michael@0 | 7892 | goal_mtu = net->mtu - SCTP_MIN_OVERHEAD; |
michael@0 | 7893 | break; |
michael@0 | 7894 | #endif |
michael@0 | 7895 | #if defined(__Userspace__) |
michael@0 | 7896 | case AF_CONN: |
michael@0 | 7897 | goal_mtu = net->mtu - sizeof(struct sctphdr); |
michael@0 | 7898 | break; |
michael@0 | 7899 | #endif |
michael@0 | 7900 | default: |
michael@0 | 7901 | /* TSNH */ |
michael@0 | 7902 | goal_mtu = net->mtu; |
michael@0 | 7903 | break; |
michael@0 | 7904 | } |
michael@0 | 7905 | /* Need an allowance for the data chunk header too */ |
michael@0 | 7906 | goal_mtu -= sizeof(struct sctp_data_chunk); |
michael@0 | 7907 | |
michael@0 | 7908 | /* must make even word boundary */ |
michael@0 | 7909 | goal_mtu &= 0xfffffffc; |
michael@0 | 7910 | if (asoc->locked_on_sending) { |
michael@0 | 7911 | /* We are stuck on one stream until the message completes. */ |
michael@0 | 7912 | strq = asoc->locked_on_sending; |
michael@0 | 7913 | locked = 1; |
michael@0 | 7914 | } else { |
michael@0 | 7915 | strq = stcb->asoc.ss_functions.sctp_ss_select_stream(stcb, net, asoc); |
michael@0 | 7916 | locked = 0; |
michael@0 | 7917 | } |
michael@0 | 7918 | while ((goal_mtu > 0) && strq) { |
michael@0 | 7919 | giveup = 0; |
michael@0 | 7920 | bail = 0; |
michael@0 | 7921 | moved_how_much = sctp_move_to_outqueue(stcb, strq, goal_mtu, frag_point, &locked, |
michael@0 | 7922 | &giveup, eeor_mode, &bail, so_locked); |
michael@0 | 7923 | if (moved_how_much) |
michael@0 | 7924 | stcb->asoc.ss_functions.sctp_ss_scheduled(stcb, net, asoc, strq, moved_how_much); |
michael@0 | 7925 | |
michael@0 | 7926 | if (locked) { |
michael@0 | 7927 | asoc->locked_on_sending = strq; |
michael@0 | 7928 | if ((moved_how_much == 0) || (giveup) || bail) |
michael@0 | 7929 | /* no more to move for now */ |
michael@0 | 7930 | break; |
michael@0 | 7931 | } else { |
michael@0 | 7932 | asoc->locked_on_sending = NULL; |
michael@0 | 7933 | if ((giveup) || bail) { |
michael@0 | 7934 | break; |
michael@0 | 7935 | } |
michael@0 | 7936 | strq = stcb->asoc.ss_functions.sctp_ss_select_stream(stcb, net, asoc); |
michael@0 | 7937 | if (strq == NULL) { |
michael@0 | 7938 | break; |
michael@0 | 7939 | } |
michael@0 | 7940 | } |
michael@0 | 7941 | total_moved += moved_how_much; |
michael@0 | 7942 | goal_mtu -= (moved_how_much + sizeof(struct sctp_data_chunk)); |
michael@0 | 7943 | goal_mtu &= 0xfffffffc; |
michael@0 | 7944 | } |
michael@0 | 7945 | if (bail) |
michael@0 | 7946 | *quit_now = 1; |
michael@0 | 7947 | |
michael@0 | 7948 | stcb->asoc.ss_functions.sctp_ss_packet_done(stcb, net, asoc); |
michael@0 | 7949 | |
michael@0 | 7950 | if (total_moved == 0) { |
michael@0 | 7951 | if ((stcb->asoc.sctp_cmt_on_off == 0) && |
michael@0 | 7952 | (net == stcb->asoc.primary_destination)) { |
michael@0 | 7953 | /* ran dry for primary network net */ |
michael@0 | 7954 | SCTP_STAT_INCR(sctps_primary_randry); |
michael@0 | 7955 | } else if (stcb->asoc.sctp_cmt_on_off > 0) { |
michael@0 | 7956 | /* ran dry with CMT on */ |
michael@0 | 7957 | SCTP_STAT_INCR(sctps_cmt_randry); |
michael@0 | 7958 | } |
michael@0 | 7959 | } |
michael@0 | 7960 | } |
michael@0 | 7961 | |
michael@0 | 7962 | void |
michael@0 | 7963 | sctp_fix_ecn_echo(struct sctp_association *asoc) |
michael@0 | 7964 | { |
michael@0 | 7965 | struct sctp_tmit_chunk *chk; |
michael@0 | 7966 | |
michael@0 | 7967 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 7968 | if (chk->rec.chunk_id.id == SCTP_ECN_ECHO) { |
michael@0 | 7969 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 7970 | } |
michael@0 | 7971 | } |
michael@0 | 7972 | } |
michael@0 | 7973 | |
michael@0 | 7974 | void |
michael@0 | 7975 | sctp_move_chunks_from_net(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 7976 | { |
michael@0 | 7977 | struct sctp_association *asoc; |
michael@0 | 7978 | struct sctp_tmit_chunk *chk; |
michael@0 | 7979 | struct sctp_stream_queue_pending *sp; |
michael@0 | 7980 | unsigned int i; |
michael@0 | 7981 | |
michael@0 | 7982 | if (net == NULL) { |
michael@0 | 7983 | return; |
michael@0 | 7984 | } |
michael@0 | 7985 | asoc = &stcb->asoc; |
michael@0 | 7986 | for (i = 0; i < stcb->asoc.streamoutcnt; i++) { |
michael@0 | 7987 | TAILQ_FOREACH(sp, &stcb->asoc.strmout[i].outqueue, next) { |
michael@0 | 7988 | if (sp->net == net) { |
michael@0 | 7989 | sctp_free_remote_addr(sp->net); |
michael@0 | 7990 | sp->net = NULL; |
michael@0 | 7991 | } |
michael@0 | 7992 | } |
michael@0 | 7993 | } |
michael@0 | 7994 | TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) { |
michael@0 | 7995 | if (chk->whoTo == net) { |
michael@0 | 7996 | sctp_free_remote_addr(chk->whoTo); |
michael@0 | 7997 | chk->whoTo = NULL; |
michael@0 | 7998 | } |
michael@0 | 7999 | } |
michael@0 | 8000 | } |
michael@0 | 8001 | |
michael@0 | 8002 | int |
michael@0 | 8003 | sctp_med_chunk_output(struct sctp_inpcb *inp, |
michael@0 | 8004 | struct sctp_tcb *stcb, |
michael@0 | 8005 | struct sctp_association *asoc, |
michael@0 | 8006 | int *num_out, |
michael@0 | 8007 | int *reason_code, |
michael@0 | 8008 | int control_only, int from_where, |
michael@0 | 8009 | struct timeval *now, int *now_filled, int frag_point, int so_locked |
michael@0 | 8010 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 8011 | SCTP_UNUSED |
michael@0 | 8012 | #endif |
michael@0 | 8013 | ) |
michael@0 | 8014 | { |
michael@0 | 8015 | /** |
michael@0 | 8016 | * Ok this is the generic chunk service queue. we must do the |
michael@0 | 8017 | * following: - Service the stream queue that is next, moving any |
michael@0 | 8018 | * message (note I must get a complete message i.e. FIRST/MIDDLE and |
michael@0 | 8019 | * LAST to the out queue in one pass) and assigning TSN's - Check to |
michael@0 | 8020 | * see if the cwnd/rwnd allows any output, if so we go ahead and |
michael@0 | 8021 | * fomulate and send the low level chunks. Making sure to combine |
michael@0 | 8022 | * any control in the control chunk queue also. |
michael@0 | 8023 | */ |
michael@0 | 8024 | struct sctp_nets *net, *start_at, *sack_goes_to = NULL, *old_start_at = NULL; |
michael@0 | 8025 | struct mbuf *outchain, *endoutchain; |
michael@0 | 8026 | struct sctp_tmit_chunk *chk, *nchk; |
michael@0 | 8027 | |
michael@0 | 8028 | /* temp arrays for unlinking */ |
michael@0 | 8029 | struct sctp_tmit_chunk *data_list[SCTP_MAX_DATA_BUNDLING]; |
michael@0 | 8030 | int no_fragmentflg, error; |
michael@0 | 8031 | unsigned int max_rwnd_per_dest, max_send_per_dest; |
michael@0 | 8032 | int one_chunk, hbflag, skip_data_for_this_net; |
michael@0 | 8033 | int asconf, cookie, no_out_cnt; |
michael@0 | 8034 | int bundle_at, ctl_cnt, no_data_chunks, eeor_mode; |
michael@0 | 8035 | unsigned int mtu, r_mtu, omtu, mx_mtu, to_out; |
michael@0 | 8036 | int tsns_sent = 0; |
michael@0 | 8037 | uint32_t auth_offset = 0; |
michael@0 | 8038 | struct sctp_auth_chunk *auth = NULL; |
michael@0 | 8039 | uint16_t auth_keyid; |
michael@0 | 8040 | int override_ok = 1; |
michael@0 | 8041 | int skip_fill_up = 0; |
michael@0 | 8042 | int data_auth_reqd = 0; |
michael@0 | 8043 | /* JRS 5/14/07 - Add flag for whether a heartbeat is sent to |
michael@0 | 8044 | the destination. */ |
michael@0 | 8045 | int quit_now = 0; |
michael@0 | 8046 | |
michael@0 | 8047 | #if defined(__APPLE__) |
michael@0 | 8048 | if (so_locked) { |
michael@0 | 8049 | sctp_lock_assert(SCTP_INP_SO(inp)); |
michael@0 | 8050 | } else { |
michael@0 | 8051 | sctp_unlock_assert(SCTP_INP_SO(inp)); |
michael@0 | 8052 | } |
michael@0 | 8053 | #endif |
michael@0 | 8054 | *num_out = 0; |
michael@0 | 8055 | auth_keyid = stcb->asoc.authinfo.active_keyid; |
michael@0 | 8056 | |
michael@0 | 8057 | if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || |
michael@0 | 8058 | (asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED) || |
michael@0 | 8059 | (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR))) { |
michael@0 | 8060 | eeor_mode = 1; |
michael@0 | 8061 | } else { |
michael@0 | 8062 | eeor_mode = 0; |
michael@0 | 8063 | } |
michael@0 | 8064 | ctl_cnt = no_out_cnt = asconf = cookie = 0; |
michael@0 | 8065 | /* |
michael@0 | 8066 | * First lets prime the pump. For each destination, if there is room |
michael@0 | 8067 | * in the flight size, attempt to pull an MTU's worth out of the |
michael@0 | 8068 | * stream queues into the general send_queue |
michael@0 | 8069 | */ |
michael@0 | 8070 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 8071 | sctp_audit_log(0xC2, 2); |
michael@0 | 8072 | #endif |
michael@0 | 8073 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 8074 | hbflag = 0; |
michael@0 | 8075 | if ((control_only) || (asoc->stream_reset_outstanding)) |
michael@0 | 8076 | no_data_chunks = 1; |
michael@0 | 8077 | else |
michael@0 | 8078 | no_data_chunks = 0; |
michael@0 | 8079 | |
michael@0 | 8080 | /* Nothing to possible to send? */ |
michael@0 | 8081 | if ((TAILQ_EMPTY(&asoc->control_send_queue) || |
michael@0 | 8082 | (asoc->ctrl_queue_cnt == stcb->asoc.ecn_echo_cnt_onq)) && |
michael@0 | 8083 | TAILQ_EMPTY(&asoc->asconf_send_queue) && |
michael@0 | 8084 | TAILQ_EMPTY(&asoc->send_queue) && |
michael@0 | 8085 | stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, asoc)) { |
michael@0 | 8086 | nothing_to_send: |
michael@0 | 8087 | *reason_code = 9; |
michael@0 | 8088 | return (0); |
michael@0 | 8089 | } |
michael@0 | 8090 | if (asoc->peers_rwnd == 0) { |
michael@0 | 8091 | /* No room in peers rwnd */ |
michael@0 | 8092 | *reason_code = 1; |
michael@0 | 8093 | if (asoc->total_flight > 0) { |
michael@0 | 8094 | /* we are allowed one chunk in flight */ |
michael@0 | 8095 | no_data_chunks = 1; |
michael@0 | 8096 | } |
michael@0 | 8097 | } |
michael@0 | 8098 | if (stcb->asoc.ecn_echo_cnt_onq) { |
michael@0 | 8099 | /* Record where a sack goes, if any */ |
michael@0 | 8100 | if (no_data_chunks && |
michael@0 | 8101 | (asoc->ctrl_queue_cnt == stcb->asoc.ecn_echo_cnt_onq)) { |
michael@0 | 8102 | /* Nothing but ECNe to send - we don't do that */ |
michael@0 | 8103 | goto nothing_to_send; |
michael@0 | 8104 | } |
michael@0 | 8105 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 8106 | if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || |
michael@0 | 8107 | (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) { |
michael@0 | 8108 | sack_goes_to = chk->whoTo; |
michael@0 | 8109 | break; |
michael@0 | 8110 | } |
michael@0 | 8111 | } |
michael@0 | 8112 | } |
michael@0 | 8113 | max_rwnd_per_dest = ((asoc->peers_rwnd + asoc->total_flight) / asoc->numnets); |
michael@0 | 8114 | if (stcb->sctp_socket) |
michael@0 | 8115 | max_send_per_dest = SCTP_SB_LIMIT_SND(stcb->sctp_socket) / asoc->numnets; |
michael@0 | 8116 | else |
michael@0 | 8117 | max_send_per_dest = 0; |
michael@0 | 8118 | if (no_data_chunks == 0) { |
michael@0 | 8119 | /* How many non-directed chunks are there? */ |
michael@0 | 8120 | TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) { |
michael@0 | 8121 | if (chk->whoTo == NULL) { |
michael@0 | 8122 | /* We already have non-directed |
michael@0 | 8123 | * chunks on the queue, no need |
michael@0 | 8124 | * to do a fill-up. |
michael@0 | 8125 | */ |
michael@0 | 8126 | skip_fill_up = 1; |
michael@0 | 8127 | break; |
michael@0 | 8128 | } |
michael@0 | 8129 | } |
michael@0 | 8130 | |
michael@0 | 8131 | } |
michael@0 | 8132 | if ((no_data_chunks == 0) && |
michael@0 | 8133 | (skip_fill_up == 0) && |
michael@0 | 8134 | (!stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, asoc))) { |
michael@0 | 8135 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 8136 | /* |
michael@0 | 8137 | * This for loop we are in takes in |
michael@0 | 8138 | * each net, if its's got space in cwnd and |
michael@0 | 8139 | * has data sent to it (when CMT is off) then it |
michael@0 | 8140 | * calls sctp_fill_outqueue for the net. This gets |
michael@0 | 8141 | * data on the send queue for that network. |
michael@0 | 8142 | * |
michael@0 | 8143 | * In sctp_fill_outqueue TSN's are assigned and |
michael@0 | 8144 | * data is copied out of the stream buffers. Note |
michael@0 | 8145 | * mostly copy by reference (we hope). |
michael@0 | 8146 | */ |
michael@0 | 8147 | net->window_probe = 0; |
michael@0 | 8148 | if ((net != stcb->asoc.alternate) && |
michael@0 | 8149 | ((net->dest_state & SCTP_ADDR_PF) || |
michael@0 | 8150 | (!(net->dest_state & SCTP_ADDR_REACHABLE)) || |
michael@0 | 8151 | (net->dest_state & SCTP_ADDR_UNCONFIRMED))) { |
michael@0 | 8152 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 8153 | sctp_log_cwnd(stcb, net, 1, |
michael@0 | 8154 | SCTP_CWND_LOG_FILL_OUTQ_CALLED); |
michael@0 | 8155 | } |
michael@0 | 8156 | continue; |
michael@0 | 8157 | } |
michael@0 | 8158 | if ((stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins) && |
michael@0 | 8159 | (net->flight_size == 0)) { |
michael@0 | 8160 | (*stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins)(stcb, net); |
michael@0 | 8161 | } |
michael@0 | 8162 | if (net->flight_size >= net->cwnd) { |
michael@0 | 8163 | /* skip this network, no room - can't fill */ |
michael@0 | 8164 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 8165 | sctp_log_cwnd(stcb, net, 3, |
michael@0 | 8166 | SCTP_CWND_LOG_FILL_OUTQ_CALLED); |
michael@0 | 8167 | } |
michael@0 | 8168 | continue; |
michael@0 | 8169 | } |
michael@0 | 8170 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 8171 | sctp_log_cwnd(stcb, net, 4, SCTP_CWND_LOG_FILL_OUTQ_CALLED); |
michael@0 | 8172 | } |
michael@0 | 8173 | sctp_fill_outqueue(stcb, net, frag_point, eeor_mode, &quit_now, so_locked); |
michael@0 | 8174 | if (quit_now) { |
michael@0 | 8175 | /* memory alloc failure */ |
michael@0 | 8176 | no_data_chunks = 1; |
michael@0 | 8177 | break; |
michael@0 | 8178 | } |
michael@0 | 8179 | } |
michael@0 | 8180 | } |
michael@0 | 8181 | /* now service each destination and send out what we can for it */ |
michael@0 | 8182 | /* Nothing to send? */ |
michael@0 | 8183 | if (TAILQ_EMPTY(&asoc->control_send_queue) && |
michael@0 | 8184 | TAILQ_EMPTY(&asoc->asconf_send_queue) && |
michael@0 | 8185 | TAILQ_EMPTY(&asoc->send_queue)) { |
michael@0 | 8186 | *reason_code = 8; |
michael@0 | 8187 | return (0); |
michael@0 | 8188 | } |
michael@0 | 8189 | |
michael@0 | 8190 | if (asoc->sctp_cmt_on_off > 0) { |
michael@0 | 8191 | /* get the last start point */ |
michael@0 | 8192 | start_at = asoc->last_net_cmt_send_started; |
michael@0 | 8193 | if (start_at == NULL) { |
michael@0 | 8194 | /* null so to beginning */ |
michael@0 | 8195 | start_at = TAILQ_FIRST(&asoc->nets); |
michael@0 | 8196 | } else { |
michael@0 | 8197 | start_at = TAILQ_NEXT(asoc->last_net_cmt_send_started, sctp_next); |
michael@0 | 8198 | if (start_at == NULL) { |
michael@0 | 8199 | start_at = TAILQ_FIRST(&asoc->nets); |
michael@0 | 8200 | } |
michael@0 | 8201 | } |
michael@0 | 8202 | asoc->last_net_cmt_send_started = start_at; |
michael@0 | 8203 | } else { |
michael@0 | 8204 | start_at = TAILQ_FIRST(&asoc->nets); |
michael@0 | 8205 | } |
michael@0 | 8206 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 8207 | if (chk->whoTo == NULL) { |
michael@0 | 8208 | if (asoc->alternate) { |
michael@0 | 8209 | chk->whoTo = asoc->alternate; |
michael@0 | 8210 | } else { |
michael@0 | 8211 | chk->whoTo = asoc->primary_destination; |
michael@0 | 8212 | } |
michael@0 | 8213 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 8214 | } |
michael@0 | 8215 | } |
michael@0 | 8216 | old_start_at = NULL; |
michael@0 | 8217 | again_one_more_time: |
michael@0 | 8218 | for (net = start_at ; net != NULL; net = TAILQ_NEXT(net, sctp_next)) { |
michael@0 | 8219 | /* how much can we send? */ |
michael@0 | 8220 | /* SCTPDBG("Examine for sending net:%x\n", (uint32_t)net); */ |
michael@0 | 8221 | if (old_start_at && (old_start_at == net)) { |
michael@0 | 8222 | /* through list ocmpletely. */ |
michael@0 | 8223 | break; |
michael@0 | 8224 | } |
michael@0 | 8225 | tsns_sent = 0xa; |
michael@0 | 8226 | if (TAILQ_EMPTY(&asoc->control_send_queue) && |
michael@0 | 8227 | TAILQ_EMPTY(&asoc->asconf_send_queue) && |
michael@0 | 8228 | (net->flight_size >= net->cwnd)) { |
michael@0 | 8229 | /* Nothing on control or asconf and flight is full, we can skip |
michael@0 | 8230 | * even in the CMT case. |
michael@0 | 8231 | */ |
michael@0 | 8232 | continue; |
michael@0 | 8233 | } |
michael@0 | 8234 | bundle_at = 0; |
michael@0 | 8235 | endoutchain = outchain = NULL; |
michael@0 | 8236 | no_fragmentflg = 1; |
michael@0 | 8237 | one_chunk = 0; |
michael@0 | 8238 | if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { |
michael@0 | 8239 | skip_data_for_this_net = 1; |
michael@0 | 8240 | } else { |
michael@0 | 8241 | skip_data_for_this_net = 0; |
michael@0 | 8242 | } |
michael@0 | 8243 | #if !(defined(__Panda__) || defined(__Windows__) || defined(__Userspace__) || defined(__APPLE__)) |
michael@0 | 8244 | if ((net->ro.ro_rt) && (net->ro.ro_rt->rt_ifp)) { |
michael@0 | 8245 | /* |
michael@0 | 8246 | * if we have a route and an ifp check to see if we |
michael@0 | 8247 | * have room to send to this guy |
michael@0 | 8248 | */ |
michael@0 | 8249 | struct ifnet *ifp; |
michael@0 | 8250 | |
michael@0 | 8251 | ifp = net->ro.ro_rt->rt_ifp; |
michael@0 | 8252 | if ((ifp->if_snd.ifq_len + 2) >= ifp->if_snd.ifq_maxlen) { |
michael@0 | 8253 | SCTP_STAT_INCR(sctps_ifnomemqueued); |
michael@0 | 8254 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_MAXBURST_ENABLE) { |
michael@0 | 8255 | sctp_log_maxburst(stcb, net, ifp->if_snd.ifq_len, ifp->if_snd.ifq_maxlen, SCTP_MAX_IFP_APPLIED); |
michael@0 | 8256 | } |
michael@0 | 8257 | continue; |
michael@0 | 8258 | } |
michael@0 | 8259 | } |
michael@0 | 8260 | #endif |
michael@0 | 8261 | switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) { |
michael@0 | 8262 | #ifdef INET |
michael@0 | 8263 | case AF_INET: |
michael@0 | 8264 | mtu = net->mtu - (sizeof(struct ip) + sizeof(struct sctphdr)); |
michael@0 | 8265 | break; |
michael@0 | 8266 | #endif |
michael@0 | 8267 | #ifdef INET6 |
michael@0 | 8268 | case AF_INET6: |
michael@0 | 8269 | mtu = net->mtu - (sizeof(struct ip6_hdr) + sizeof(struct sctphdr)); |
michael@0 | 8270 | break; |
michael@0 | 8271 | #endif |
michael@0 | 8272 | #if defined(__Userspace__) |
michael@0 | 8273 | case AF_CONN: |
michael@0 | 8274 | mtu = net->mtu - sizeof(struct sctphdr); |
michael@0 | 8275 | break; |
michael@0 | 8276 | #endif |
michael@0 | 8277 | default: |
michael@0 | 8278 | /* TSNH */ |
michael@0 | 8279 | mtu = net->mtu; |
michael@0 | 8280 | break; |
michael@0 | 8281 | } |
michael@0 | 8282 | mx_mtu = mtu; |
michael@0 | 8283 | to_out = 0; |
michael@0 | 8284 | if (mtu > asoc->peers_rwnd) { |
michael@0 | 8285 | if (asoc->total_flight > 0) { |
michael@0 | 8286 | /* We have a packet in flight somewhere */ |
michael@0 | 8287 | r_mtu = asoc->peers_rwnd; |
michael@0 | 8288 | } else { |
michael@0 | 8289 | /* We are always allowed to send one MTU out */ |
michael@0 | 8290 | one_chunk = 1; |
michael@0 | 8291 | r_mtu = mtu; |
michael@0 | 8292 | } |
michael@0 | 8293 | } else { |
michael@0 | 8294 | r_mtu = mtu; |
michael@0 | 8295 | } |
michael@0 | 8296 | /************************/ |
michael@0 | 8297 | /* ASCONF transmission */ |
michael@0 | 8298 | /************************/ |
michael@0 | 8299 | /* Now first lets go through the asconf queue */ |
michael@0 | 8300 | TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) { |
michael@0 | 8301 | if (chk->rec.chunk_id.id != SCTP_ASCONF) { |
michael@0 | 8302 | continue; |
michael@0 | 8303 | } |
michael@0 | 8304 | if (chk->whoTo == NULL) { |
michael@0 | 8305 | if (asoc->alternate == NULL) { |
michael@0 | 8306 | if (asoc->primary_destination != net) { |
michael@0 | 8307 | break; |
michael@0 | 8308 | } |
michael@0 | 8309 | } else { |
michael@0 | 8310 | if (asoc->alternate != net) { |
michael@0 | 8311 | break; |
michael@0 | 8312 | } |
michael@0 | 8313 | } |
michael@0 | 8314 | } else { |
michael@0 | 8315 | if (chk->whoTo != net) { |
michael@0 | 8316 | break; |
michael@0 | 8317 | } |
michael@0 | 8318 | } |
michael@0 | 8319 | if (chk->data == NULL) { |
michael@0 | 8320 | break; |
michael@0 | 8321 | } |
michael@0 | 8322 | if (chk->sent != SCTP_DATAGRAM_UNSENT && |
michael@0 | 8323 | chk->sent != SCTP_DATAGRAM_RESEND) { |
michael@0 | 8324 | break; |
michael@0 | 8325 | } |
michael@0 | 8326 | /* |
michael@0 | 8327 | * if no AUTH is yet included and this chunk |
michael@0 | 8328 | * requires it, make sure to account for it. We |
michael@0 | 8329 | * don't apply the size until the AUTH chunk is |
michael@0 | 8330 | * actually added below in case there is no room for |
michael@0 | 8331 | * this chunk. NOTE: we overload the use of "omtu" |
michael@0 | 8332 | * here |
michael@0 | 8333 | */ |
michael@0 | 8334 | if ((auth == NULL) && |
michael@0 | 8335 | sctp_auth_is_required_chunk(chk->rec.chunk_id.id, |
michael@0 | 8336 | stcb->asoc.peer_auth_chunks)) { |
michael@0 | 8337 | omtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); |
michael@0 | 8338 | } else |
michael@0 | 8339 | omtu = 0; |
michael@0 | 8340 | /* Here we do NOT factor the r_mtu */ |
michael@0 | 8341 | if ((chk->send_size < (int)(mtu - omtu)) || |
michael@0 | 8342 | (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) { |
michael@0 | 8343 | /* |
michael@0 | 8344 | * We probably should glom the mbuf chain |
michael@0 | 8345 | * from the chk->data for control but the |
michael@0 | 8346 | * problem is it becomes yet one more level |
michael@0 | 8347 | * of tracking to do if for some reason |
michael@0 | 8348 | * output fails. Then I have got to |
michael@0 | 8349 | * reconstruct the merged control chain.. el |
michael@0 | 8350 | * yucko.. for now we take the easy way and |
michael@0 | 8351 | * do the copy |
michael@0 | 8352 | */ |
michael@0 | 8353 | /* |
michael@0 | 8354 | * Add an AUTH chunk, if chunk requires it |
michael@0 | 8355 | * save the offset into the chain for AUTH |
michael@0 | 8356 | */ |
michael@0 | 8357 | if ((auth == NULL) && |
michael@0 | 8358 | (sctp_auth_is_required_chunk(chk->rec.chunk_id.id, |
michael@0 | 8359 | stcb->asoc.peer_auth_chunks))) { |
michael@0 | 8360 | outchain = sctp_add_auth_chunk(outchain, |
michael@0 | 8361 | &endoutchain, |
michael@0 | 8362 | &auth, |
michael@0 | 8363 | &auth_offset, |
michael@0 | 8364 | stcb, |
michael@0 | 8365 | chk->rec.chunk_id.id); |
michael@0 | 8366 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 8367 | } |
michael@0 | 8368 | outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, |
michael@0 | 8369 | (int)chk->rec.chunk_id.can_take_data, |
michael@0 | 8370 | chk->send_size, chk->copy_by_ref); |
michael@0 | 8371 | if (outchain == NULL) { |
michael@0 | 8372 | *reason_code = 8; |
michael@0 | 8373 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 8374 | return (ENOMEM); |
michael@0 | 8375 | } |
michael@0 | 8376 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 8377 | /* update our MTU size */ |
michael@0 | 8378 | if (mtu > (chk->send_size + omtu)) |
michael@0 | 8379 | mtu -= (chk->send_size + omtu); |
michael@0 | 8380 | else |
michael@0 | 8381 | mtu = 0; |
michael@0 | 8382 | to_out += (chk->send_size + omtu); |
michael@0 | 8383 | /* Do clear IP_DF ? */ |
michael@0 | 8384 | if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { |
michael@0 | 8385 | no_fragmentflg = 0; |
michael@0 | 8386 | } |
michael@0 | 8387 | if (chk->rec.chunk_id.can_take_data) |
michael@0 | 8388 | chk->data = NULL; |
michael@0 | 8389 | /* |
michael@0 | 8390 | * set hb flag since we can |
michael@0 | 8391 | * use these for RTO |
michael@0 | 8392 | */ |
michael@0 | 8393 | hbflag = 1; |
michael@0 | 8394 | asconf = 1; |
michael@0 | 8395 | /* |
michael@0 | 8396 | * should sysctl this: don't |
michael@0 | 8397 | * bundle data with ASCONF |
michael@0 | 8398 | * since it requires AUTH |
michael@0 | 8399 | */ |
michael@0 | 8400 | no_data_chunks = 1; |
michael@0 | 8401 | chk->sent = SCTP_DATAGRAM_SENT; |
michael@0 | 8402 | if (chk->whoTo == NULL) { |
michael@0 | 8403 | chk->whoTo = net; |
michael@0 | 8404 | atomic_add_int(&net->ref_count, 1); |
michael@0 | 8405 | } |
michael@0 | 8406 | chk->snd_count++; |
michael@0 | 8407 | if (mtu == 0) { |
michael@0 | 8408 | /* |
michael@0 | 8409 | * Ok we are out of room but we can |
michael@0 | 8410 | * output without effecting the |
michael@0 | 8411 | * flight size since this little guy |
michael@0 | 8412 | * is a control only packet. |
michael@0 | 8413 | */ |
michael@0 | 8414 | sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, stcb, net); |
michael@0 | 8415 | /* |
michael@0 | 8416 | * do NOT clear the asconf |
michael@0 | 8417 | * flag as it is used to do |
michael@0 | 8418 | * appropriate source address |
michael@0 | 8419 | * selection. |
michael@0 | 8420 | */ |
michael@0 | 8421 | if ((error = sctp_lowlevel_chunk_output(inp, stcb, net, |
michael@0 | 8422 | (struct sockaddr *)&net->ro._l_addr, |
michael@0 | 8423 | outchain, auth_offset, auth, |
michael@0 | 8424 | stcb->asoc.authinfo.active_keyid, |
michael@0 | 8425 | no_fragmentflg, 0, asconf, |
michael@0 | 8426 | inp->sctp_lport, stcb->rport, |
michael@0 | 8427 | htonl(stcb->asoc.peer_vtag), |
michael@0 | 8428 | net->port, NULL, |
michael@0 | 8429 | #if defined(__FreeBSD__) |
michael@0 | 8430 | 0, 0, |
michael@0 | 8431 | #endif |
michael@0 | 8432 | so_locked))) { |
michael@0 | 8433 | if (error == ENOBUFS) { |
michael@0 | 8434 | asoc->ifp_had_enobuf = 1; |
michael@0 | 8435 | SCTP_STAT_INCR(sctps_lowlevelerr); |
michael@0 | 8436 | } |
michael@0 | 8437 | if (from_where == 0) { |
michael@0 | 8438 | SCTP_STAT_INCR(sctps_lowlevelerrusr); |
michael@0 | 8439 | } |
michael@0 | 8440 | if (*now_filled == 0) { |
michael@0 | 8441 | (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); |
michael@0 | 8442 | *now_filled = 1; |
michael@0 | 8443 | *now = net->last_sent_time; |
michael@0 | 8444 | } else { |
michael@0 | 8445 | net->last_sent_time = *now; |
michael@0 | 8446 | } |
michael@0 | 8447 | hbflag = 0; |
michael@0 | 8448 | /* error, could not output */ |
michael@0 | 8449 | if (error == EHOSTUNREACH) { |
michael@0 | 8450 | /* |
michael@0 | 8451 | * Destination went |
michael@0 | 8452 | * unreachable |
michael@0 | 8453 | * during this send |
michael@0 | 8454 | */ |
michael@0 | 8455 | sctp_move_chunks_from_net(stcb, net); |
michael@0 | 8456 | } |
michael@0 | 8457 | *reason_code = 7; |
michael@0 | 8458 | continue; |
michael@0 | 8459 | } else |
michael@0 | 8460 | asoc->ifp_had_enobuf = 0; |
michael@0 | 8461 | if (*now_filled == 0) { |
michael@0 | 8462 | (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); |
michael@0 | 8463 | *now_filled = 1; |
michael@0 | 8464 | *now = net->last_sent_time; |
michael@0 | 8465 | } else { |
michael@0 | 8466 | net->last_sent_time = *now; |
michael@0 | 8467 | } |
michael@0 | 8468 | hbflag = 0; |
michael@0 | 8469 | /* |
michael@0 | 8470 | * increase the number we sent, if a |
michael@0 | 8471 | * cookie is sent we don't tell them |
michael@0 | 8472 | * any was sent out. |
michael@0 | 8473 | */ |
michael@0 | 8474 | outchain = endoutchain = NULL; |
michael@0 | 8475 | auth = NULL; |
michael@0 | 8476 | auth_offset = 0; |
michael@0 | 8477 | if (!no_out_cnt) |
michael@0 | 8478 | *num_out += ctl_cnt; |
michael@0 | 8479 | /* recalc a clean slate and setup */ |
michael@0 | 8480 | switch (net->ro._l_addr.sa.sa_family) { |
michael@0 | 8481 | #ifdef INET |
michael@0 | 8482 | case AF_INET: |
michael@0 | 8483 | mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; |
michael@0 | 8484 | break; |
michael@0 | 8485 | #endif |
michael@0 | 8486 | #ifdef INET6 |
michael@0 | 8487 | case AF_INET6: |
michael@0 | 8488 | mtu = net->mtu - SCTP_MIN_OVERHEAD; |
michael@0 | 8489 | break; |
michael@0 | 8490 | #endif |
michael@0 | 8491 | #if defined(__Userspace__) |
michael@0 | 8492 | case AF_CONN: |
michael@0 | 8493 | mtu = net->mtu - sizeof(struct sctphdr); |
michael@0 | 8494 | break; |
michael@0 | 8495 | #endif |
michael@0 | 8496 | default: |
michael@0 | 8497 | /* TSNH */ |
michael@0 | 8498 | mtu = net->mtu; |
michael@0 | 8499 | break; |
michael@0 | 8500 | } |
michael@0 | 8501 | to_out = 0; |
michael@0 | 8502 | no_fragmentflg = 1; |
michael@0 | 8503 | } |
michael@0 | 8504 | } |
michael@0 | 8505 | } |
michael@0 | 8506 | /************************/ |
michael@0 | 8507 | /* Control transmission */ |
michael@0 | 8508 | /************************/ |
michael@0 | 8509 | /* Now first lets go through the control queue */ |
michael@0 | 8510 | TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) { |
michael@0 | 8511 | if ((sack_goes_to) && |
michael@0 | 8512 | (chk->rec.chunk_id.id == SCTP_ECN_ECHO) && |
michael@0 | 8513 | (chk->whoTo != sack_goes_to)) { |
michael@0 | 8514 | /* |
michael@0 | 8515 | * if we have a sack in queue, and we are looking at an |
michael@0 | 8516 | * ecn echo that is NOT queued to where the sack is going.. |
michael@0 | 8517 | */ |
michael@0 | 8518 | if (chk->whoTo == net) { |
michael@0 | 8519 | /* Don't transmit it to where its going (current net) */ |
michael@0 | 8520 | continue; |
michael@0 | 8521 | } else if (sack_goes_to == net) { |
michael@0 | 8522 | /* But do transmit it to this address */ |
michael@0 | 8523 | goto skip_net_check; |
michael@0 | 8524 | } |
michael@0 | 8525 | } |
michael@0 | 8526 | if (chk->whoTo == NULL) { |
michael@0 | 8527 | if (asoc->alternate == NULL) { |
michael@0 | 8528 | if (asoc->primary_destination != net) { |
michael@0 | 8529 | continue; |
michael@0 | 8530 | } |
michael@0 | 8531 | } else { |
michael@0 | 8532 | if (asoc->alternate != net) { |
michael@0 | 8533 | continue; |
michael@0 | 8534 | } |
michael@0 | 8535 | } |
michael@0 | 8536 | } else { |
michael@0 | 8537 | if (chk->whoTo != net) { |
michael@0 | 8538 | continue; |
michael@0 | 8539 | } |
michael@0 | 8540 | } |
michael@0 | 8541 | skip_net_check: |
michael@0 | 8542 | if (chk->data == NULL) { |
michael@0 | 8543 | continue; |
michael@0 | 8544 | } |
michael@0 | 8545 | if (chk->sent != SCTP_DATAGRAM_UNSENT) { |
michael@0 | 8546 | /* |
michael@0 | 8547 | * It must be unsent. Cookies and ASCONF's |
michael@0 | 8548 | * hang around but there timers will force |
michael@0 | 8549 | * when marked for resend. |
michael@0 | 8550 | */ |
michael@0 | 8551 | continue; |
michael@0 | 8552 | } |
michael@0 | 8553 | /* |
michael@0 | 8554 | * if no AUTH is yet included and this chunk |
michael@0 | 8555 | * requires it, make sure to account for it. We |
michael@0 | 8556 | * don't apply the size until the AUTH chunk is |
michael@0 | 8557 | * actually added below in case there is no room for |
michael@0 | 8558 | * this chunk. NOTE: we overload the use of "omtu" |
michael@0 | 8559 | * here |
michael@0 | 8560 | */ |
michael@0 | 8561 | if ((auth == NULL) && |
michael@0 | 8562 | sctp_auth_is_required_chunk(chk->rec.chunk_id.id, |
michael@0 | 8563 | stcb->asoc.peer_auth_chunks)) { |
michael@0 | 8564 | omtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); |
michael@0 | 8565 | } else |
michael@0 | 8566 | omtu = 0; |
michael@0 | 8567 | /* Here we do NOT factor the r_mtu */ |
michael@0 | 8568 | if ((chk->send_size <= (int)(mtu - omtu)) || |
michael@0 | 8569 | (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) { |
michael@0 | 8570 | /* |
michael@0 | 8571 | * We probably should glom the mbuf chain |
michael@0 | 8572 | * from the chk->data for control but the |
michael@0 | 8573 | * problem is it becomes yet one more level |
michael@0 | 8574 | * of tracking to do if for some reason |
michael@0 | 8575 | * output fails. Then I have got to |
michael@0 | 8576 | * reconstruct the merged control chain.. el |
michael@0 | 8577 | * yucko.. for now we take the easy way and |
michael@0 | 8578 | * do the copy |
michael@0 | 8579 | */ |
michael@0 | 8580 | /* |
michael@0 | 8581 | * Add an AUTH chunk, if chunk requires it |
michael@0 | 8582 | * save the offset into the chain for AUTH |
michael@0 | 8583 | */ |
michael@0 | 8584 | if ((auth == NULL) && |
michael@0 | 8585 | (sctp_auth_is_required_chunk(chk->rec.chunk_id.id, |
michael@0 | 8586 | stcb->asoc.peer_auth_chunks))) { |
michael@0 | 8587 | outchain = sctp_add_auth_chunk(outchain, |
michael@0 | 8588 | &endoutchain, |
michael@0 | 8589 | &auth, |
michael@0 | 8590 | &auth_offset, |
michael@0 | 8591 | stcb, |
michael@0 | 8592 | chk->rec.chunk_id.id); |
michael@0 | 8593 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 8594 | } |
michael@0 | 8595 | outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, |
michael@0 | 8596 | (int)chk->rec.chunk_id.can_take_data, |
michael@0 | 8597 | chk->send_size, chk->copy_by_ref); |
michael@0 | 8598 | if (outchain == NULL) { |
michael@0 | 8599 | *reason_code = 8; |
michael@0 | 8600 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 8601 | return (ENOMEM); |
michael@0 | 8602 | } |
michael@0 | 8603 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 8604 | /* update our MTU size */ |
michael@0 | 8605 | if (mtu > (chk->send_size + omtu)) |
michael@0 | 8606 | mtu -= (chk->send_size + omtu); |
michael@0 | 8607 | else |
michael@0 | 8608 | mtu = 0; |
michael@0 | 8609 | to_out += (chk->send_size + omtu); |
michael@0 | 8610 | /* Do clear IP_DF ? */ |
michael@0 | 8611 | if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { |
michael@0 | 8612 | no_fragmentflg = 0; |
michael@0 | 8613 | } |
michael@0 | 8614 | if (chk->rec.chunk_id.can_take_data) |
michael@0 | 8615 | chk->data = NULL; |
michael@0 | 8616 | /* Mark things to be removed, if needed */ |
michael@0 | 8617 | if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || |
michael@0 | 8618 | (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK) || /* EY */ |
michael@0 | 8619 | (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) || |
michael@0 | 8620 | (chk->rec.chunk_id.id == SCTP_HEARTBEAT_ACK) || |
michael@0 | 8621 | (chk->rec.chunk_id.id == SCTP_SHUTDOWN) || |
michael@0 | 8622 | (chk->rec.chunk_id.id == SCTP_SHUTDOWN_ACK) || |
michael@0 | 8623 | (chk->rec.chunk_id.id == SCTP_OPERATION_ERROR) || |
michael@0 | 8624 | (chk->rec.chunk_id.id == SCTP_COOKIE_ACK) || |
michael@0 | 8625 | (chk->rec.chunk_id.id == SCTP_ECN_CWR) || |
michael@0 | 8626 | (chk->rec.chunk_id.id == SCTP_PACKET_DROPPED) || |
michael@0 | 8627 | (chk->rec.chunk_id.id == SCTP_ASCONF_ACK)) { |
michael@0 | 8628 | if (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) { |
michael@0 | 8629 | hbflag = 1; |
michael@0 | 8630 | } |
michael@0 | 8631 | /* remove these chunks at the end */ |
michael@0 | 8632 | if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || |
michael@0 | 8633 | (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) { |
michael@0 | 8634 | /* turn off the timer */ |
michael@0 | 8635 | if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { |
michael@0 | 8636 | sctp_timer_stop(SCTP_TIMER_TYPE_RECV, |
michael@0 | 8637 | inp, stcb, net, SCTP_FROM_SCTP_OUTPUT+SCTP_LOC_1); |
michael@0 | 8638 | } |
michael@0 | 8639 | } |
michael@0 | 8640 | ctl_cnt++; |
michael@0 | 8641 | } else { |
michael@0 | 8642 | /* |
michael@0 | 8643 | * Other chunks, since they have |
michael@0 | 8644 | * timers running (i.e. COOKIE) |
michael@0 | 8645 | * we just "trust" that it |
michael@0 | 8646 | * gets sent or retransmitted. |
michael@0 | 8647 | */ |
michael@0 | 8648 | ctl_cnt++; |
michael@0 | 8649 | if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) { |
michael@0 | 8650 | cookie = 1; |
michael@0 | 8651 | no_out_cnt = 1; |
michael@0 | 8652 | } else if (chk->rec.chunk_id.id == SCTP_ECN_ECHO) { |
michael@0 | 8653 | /* |
michael@0 | 8654 | * Increment ecne send count here |
michael@0 | 8655 | * this means we may be over-zealous in |
michael@0 | 8656 | * our counting if the send fails, but its |
michael@0 | 8657 | * the best place to do it (we used to do |
michael@0 | 8658 | * it in the queue of the chunk, but that did |
michael@0 | 8659 | * not tell how many times it was sent. |
michael@0 | 8660 | */ |
michael@0 | 8661 | SCTP_STAT_INCR(sctps_sendecne); |
michael@0 | 8662 | } |
michael@0 | 8663 | chk->sent = SCTP_DATAGRAM_SENT; |
michael@0 | 8664 | if (chk->whoTo == NULL) { |
michael@0 | 8665 | chk->whoTo = net; |
michael@0 | 8666 | atomic_add_int(&net->ref_count, 1); |
michael@0 | 8667 | } |
michael@0 | 8668 | chk->snd_count++; |
michael@0 | 8669 | } |
michael@0 | 8670 | if (mtu == 0) { |
michael@0 | 8671 | /* |
michael@0 | 8672 | * Ok we are out of room but we can |
michael@0 | 8673 | * output without effecting the |
michael@0 | 8674 | * flight size since this little guy |
michael@0 | 8675 | * is a control only packet. |
michael@0 | 8676 | */ |
michael@0 | 8677 | if (asconf) { |
michael@0 | 8678 | sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, stcb, net); |
michael@0 | 8679 | /* |
michael@0 | 8680 | * do NOT clear the asconf |
michael@0 | 8681 | * flag as it is used to do |
michael@0 | 8682 | * appropriate source address |
michael@0 | 8683 | * selection. |
michael@0 | 8684 | */ |
michael@0 | 8685 | } |
michael@0 | 8686 | if (cookie) { |
michael@0 | 8687 | sctp_timer_start(SCTP_TIMER_TYPE_COOKIE, inp, stcb, net); |
michael@0 | 8688 | cookie = 0; |
michael@0 | 8689 | } |
michael@0 | 8690 | if ((error = sctp_lowlevel_chunk_output(inp, stcb, net, |
michael@0 | 8691 | (struct sockaddr *)&net->ro._l_addr, |
michael@0 | 8692 | outchain, |
michael@0 | 8693 | auth_offset, auth, |
michael@0 | 8694 | stcb->asoc.authinfo.active_keyid, |
michael@0 | 8695 | no_fragmentflg, 0, asconf, |
michael@0 | 8696 | inp->sctp_lport, stcb->rport, |
michael@0 | 8697 | htonl(stcb->asoc.peer_vtag), |
michael@0 | 8698 | net->port, NULL, |
michael@0 | 8699 | #if defined(__FreeBSD__) |
michael@0 | 8700 | 0, 0, |
michael@0 | 8701 | #endif |
michael@0 | 8702 | so_locked))) { |
michael@0 | 8703 | if (error == ENOBUFS) { |
michael@0 | 8704 | asoc->ifp_had_enobuf = 1; |
michael@0 | 8705 | SCTP_STAT_INCR(sctps_lowlevelerr); |
michael@0 | 8706 | } |
michael@0 | 8707 | if (from_where == 0) { |
michael@0 | 8708 | SCTP_STAT_INCR(sctps_lowlevelerrusr); |
michael@0 | 8709 | } |
michael@0 | 8710 | /* error, could not output */ |
michael@0 | 8711 | if (hbflag) { |
michael@0 | 8712 | if (*now_filled == 0) { |
michael@0 | 8713 | (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); |
michael@0 | 8714 | *now_filled = 1; |
michael@0 | 8715 | *now = net->last_sent_time; |
michael@0 | 8716 | } else { |
michael@0 | 8717 | net->last_sent_time = *now; |
michael@0 | 8718 | } |
michael@0 | 8719 | hbflag = 0; |
michael@0 | 8720 | } |
michael@0 | 8721 | if (error == EHOSTUNREACH) { |
michael@0 | 8722 | /* |
michael@0 | 8723 | * Destination went |
michael@0 | 8724 | * unreachable |
michael@0 | 8725 | * during this send |
michael@0 | 8726 | */ |
michael@0 | 8727 | sctp_move_chunks_from_net(stcb, net); |
michael@0 | 8728 | } |
michael@0 | 8729 | *reason_code = 7; |
michael@0 | 8730 | continue; |
michael@0 | 8731 | } else |
michael@0 | 8732 | asoc->ifp_had_enobuf = 0; |
michael@0 | 8733 | /* Only HB or ASCONF advances time */ |
michael@0 | 8734 | if (hbflag) { |
michael@0 | 8735 | if (*now_filled == 0) { |
michael@0 | 8736 | (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); |
michael@0 | 8737 | *now_filled = 1; |
michael@0 | 8738 | *now = net->last_sent_time; |
michael@0 | 8739 | } else { |
michael@0 | 8740 | net->last_sent_time = *now; |
michael@0 | 8741 | } |
michael@0 | 8742 | hbflag = 0; |
michael@0 | 8743 | } |
michael@0 | 8744 | /* |
michael@0 | 8745 | * increase the number we sent, if a |
michael@0 | 8746 | * cookie is sent we don't tell them |
michael@0 | 8747 | * any was sent out. |
michael@0 | 8748 | */ |
michael@0 | 8749 | outchain = endoutchain = NULL; |
michael@0 | 8750 | auth = NULL; |
michael@0 | 8751 | auth_offset = 0; |
michael@0 | 8752 | if (!no_out_cnt) |
michael@0 | 8753 | *num_out += ctl_cnt; |
michael@0 | 8754 | /* recalc a clean slate and setup */ |
michael@0 | 8755 | switch (net->ro._l_addr.sa.sa_family) { |
michael@0 | 8756 | #ifdef INET |
michael@0 | 8757 | case AF_INET: |
michael@0 | 8758 | mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; |
michael@0 | 8759 | break; |
michael@0 | 8760 | #endif |
michael@0 | 8761 | #ifdef INET6 |
michael@0 | 8762 | case AF_INET6: |
michael@0 | 8763 | mtu = net->mtu - SCTP_MIN_OVERHEAD; |
michael@0 | 8764 | break; |
michael@0 | 8765 | #endif |
michael@0 | 8766 | #if defined(__Userspace__) |
michael@0 | 8767 | case AF_CONN: |
michael@0 | 8768 | mtu = net->mtu - sizeof(struct sctphdr); |
michael@0 | 8769 | break; |
michael@0 | 8770 | #endif |
michael@0 | 8771 | default: |
michael@0 | 8772 | /* TSNH */ |
michael@0 | 8773 | mtu = net->mtu; |
michael@0 | 8774 | break; |
michael@0 | 8775 | } |
michael@0 | 8776 | to_out = 0; |
michael@0 | 8777 | no_fragmentflg = 1; |
michael@0 | 8778 | } |
michael@0 | 8779 | } |
michael@0 | 8780 | } |
michael@0 | 8781 | /* JRI: if dest is in PF state, do not send data to it */ |
michael@0 | 8782 | if ((asoc->sctp_cmt_on_off > 0) && |
michael@0 | 8783 | (net != stcb->asoc.alternate) && |
michael@0 | 8784 | (net->dest_state & SCTP_ADDR_PF)) { |
michael@0 | 8785 | goto no_data_fill; |
michael@0 | 8786 | } |
michael@0 | 8787 | if (net->flight_size >= net->cwnd) { |
michael@0 | 8788 | goto no_data_fill; |
michael@0 | 8789 | } |
michael@0 | 8790 | if ((asoc->sctp_cmt_on_off > 0) && |
michael@0 | 8791 | (SCTP_BASE_SYSCTL(sctp_buffer_splitting) & SCTP_RECV_BUFFER_SPLITTING) && |
michael@0 | 8792 | (net->flight_size > max_rwnd_per_dest)) { |
michael@0 | 8793 | goto no_data_fill; |
michael@0 | 8794 | } |
michael@0 | 8795 | /* |
michael@0 | 8796 | * We need a specific accounting for the usage of the |
michael@0 | 8797 | * send buffer. We also need to check the number of messages |
michael@0 | 8798 | * per net. For now, this is better than nothing and it |
michael@0 | 8799 | * disabled by default... |
michael@0 | 8800 | */ |
michael@0 | 8801 | if ((asoc->sctp_cmt_on_off > 0) && |
michael@0 | 8802 | (SCTP_BASE_SYSCTL(sctp_buffer_splitting) & SCTP_SEND_BUFFER_SPLITTING) && |
michael@0 | 8803 | (max_send_per_dest > 0) && |
michael@0 | 8804 | (net->flight_size > max_send_per_dest)) { |
michael@0 | 8805 | goto no_data_fill; |
michael@0 | 8806 | } |
michael@0 | 8807 | /*********************/ |
michael@0 | 8808 | /* Data transmission */ |
michael@0 | 8809 | /*********************/ |
michael@0 | 8810 | /* |
michael@0 | 8811 | * if AUTH for DATA is required and no AUTH has been added |
michael@0 | 8812 | * yet, account for this in the mtu now... if no data can be |
michael@0 | 8813 | * bundled, this adjustment won't matter anyways since the |
michael@0 | 8814 | * packet will be going out... |
michael@0 | 8815 | */ |
michael@0 | 8816 | data_auth_reqd = sctp_auth_is_required_chunk(SCTP_DATA, |
michael@0 | 8817 | stcb->asoc.peer_auth_chunks); |
michael@0 | 8818 | if (data_auth_reqd && (auth == NULL)) { |
michael@0 | 8819 | mtu -= sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); |
michael@0 | 8820 | } |
michael@0 | 8821 | /* now lets add any data within the MTU constraints */ |
michael@0 | 8822 | switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) { |
michael@0 | 8823 | #ifdef INET |
michael@0 | 8824 | case AF_INET: |
michael@0 | 8825 | if (net->mtu > (sizeof(struct ip) + sizeof(struct sctphdr))) |
michael@0 | 8826 | omtu = net->mtu - (sizeof(struct ip) + sizeof(struct sctphdr)); |
michael@0 | 8827 | else |
michael@0 | 8828 | omtu = 0; |
michael@0 | 8829 | break; |
michael@0 | 8830 | #endif |
michael@0 | 8831 | #ifdef INET6 |
michael@0 | 8832 | case AF_INET6: |
michael@0 | 8833 | if (net->mtu > (sizeof(struct ip6_hdr) + sizeof(struct sctphdr))) |
michael@0 | 8834 | omtu = net->mtu - (sizeof(struct ip6_hdr) + sizeof(struct sctphdr)); |
michael@0 | 8835 | else |
michael@0 | 8836 | omtu = 0; |
michael@0 | 8837 | break; |
michael@0 | 8838 | #endif |
michael@0 | 8839 | #if defined(__Userspace__) |
michael@0 | 8840 | case AF_CONN: |
michael@0 | 8841 | if (net->mtu > sizeof(struct sctphdr)) { |
michael@0 | 8842 | omtu = net->mtu - sizeof(struct sctphdr); |
michael@0 | 8843 | } else { |
michael@0 | 8844 | omtu = 0; |
michael@0 | 8845 | } |
michael@0 | 8846 | break; |
michael@0 | 8847 | #endif |
michael@0 | 8848 | default: |
michael@0 | 8849 | /* TSNH */ |
michael@0 | 8850 | omtu = 0; |
michael@0 | 8851 | break; |
michael@0 | 8852 | } |
michael@0 | 8853 | if ((((asoc->state & SCTP_STATE_OPEN) == SCTP_STATE_OPEN) && |
michael@0 | 8854 | (skip_data_for_this_net == 0)) || |
michael@0 | 8855 | (cookie)) { |
michael@0 | 8856 | TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) { |
michael@0 | 8857 | if (no_data_chunks) { |
michael@0 | 8858 | /* let only control go out */ |
michael@0 | 8859 | *reason_code = 1; |
michael@0 | 8860 | break; |
michael@0 | 8861 | } |
michael@0 | 8862 | if (net->flight_size >= net->cwnd) { |
michael@0 | 8863 | /* skip this net, no room for data */ |
michael@0 | 8864 | *reason_code = 2; |
michael@0 | 8865 | break; |
michael@0 | 8866 | } |
michael@0 | 8867 | if ((chk->whoTo != NULL) && |
michael@0 | 8868 | (chk->whoTo != net)) { |
michael@0 | 8869 | /* Don't send the chunk on this net */ |
michael@0 | 8870 | continue; |
michael@0 | 8871 | } |
michael@0 | 8872 | |
michael@0 | 8873 | if (asoc->sctp_cmt_on_off == 0) { |
michael@0 | 8874 | if ((asoc->alternate) && |
michael@0 | 8875 | (asoc->alternate != net) && |
michael@0 | 8876 | (chk->whoTo == NULL)) { |
michael@0 | 8877 | continue; |
michael@0 | 8878 | } else if ((net != asoc->primary_destination) && |
michael@0 | 8879 | (asoc->alternate == NULL) && |
michael@0 | 8880 | (chk->whoTo == NULL)) { |
michael@0 | 8881 | continue; |
michael@0 | 8882 | } |
michael@0 | 8883 | } |
michael@0 | 8884 | if ((chk->send_size > omtu) && ((chk->flags & CHUNK_FLAGS_FRAGMENT_OK) == 0)) { |
michael@0 | 8885 | /*- |
michael@0 | 8886 | * strange, we have a chunk that is |
michael@0 | 8887 | * to big for its destination and |
michael@0 | 8888 | * yet no fragment ok flag. |
michael@0 | 8889 | * Something went wrong when the |
michael@0 | 8890 | * PMTU changed...we did not mark |
michael@0 | 8891 | * this chunk for some reason?? I |
michael@0 | 8892 | * will fix it here by letting IP |
michael@0 | 8893 | * fragment it for now and printing |
michael@0 | 8894 | * a warning. This really should not |
michael@0 | 8895 | * happen ... |
michael@0 | 8896 | */ |
michael@0 | 8897 | SCTP_PRINTF("Warning chunk of %d bytes > mtu:%d and yet PMTU disc missed\n", |
michael@0 | 8898 | chk->send_size, mtu); |
michael@0 | 8899 | chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; |
michael@0 | 8900 | } |
michael@0 | 8901 | if (SCTP_BASE_SYSCTL(sctp_enable_sack_immediately) && |
michael@0 | 8902 | ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) == SCTP_STATE_SHUTDOWN_PENDING)) { |
michael@0 | 8903 | struct sctp_data_chunk *dchkh; |
michael@0 | 8904 | |
michael@0 | 8905 | dchkh = mtod(chk->data, struct sctp_data_chunk *); |
michael@0 | 8906 | dchkh->ch.chunk_flags |= SCTP_DATA_SACK_IMMEDIATELY; |
michael@0 | 8907 | } |
michael@0 | 8908 | if (((chk->send_size <= mtu) && (chk->send_size <= r_mtu)) || |
michael@0 | 8909 | ((chk->flags & CHUNK_FLAGS_FRAGMENT_OK) && (chk->send_size <= asoc->peers_rwnd))) { |
michael@0 | 8910 | /* ok we will add this one */ |
michael@0 | 8911 | |
michael@0 | 8912 | /* |
michael@0 | 8913 | * Add an AUTH chunk, if chunk |
michael@0 | 8914 | * requires it, save the offset into |
michael@0 | 8915 | * the chain for AUTH |
michael@0 | 8916 | */ |
michael@0 | 8917 | if (data_auth_reqd) { |
michael@0 | 8918 | if (auth == NULL) { |
michael@0 | 8919 | outchain = sctp_add_auth_chunk(outchain, |
michael@0 | 8920 | &endoutchain, |
michael@0 | 8921 | &auth, |
michael@0 | 8922 | &auth_offset, |
michael@0 | 8923 | stcb, |
michael@0 | 8924 | SCTP_DATA); |
michael@0 | 8925 | auth_keyid = chk->auth_keyid; |
michael@0 | 8926 | override_ok = 0; |
michael@0 | 8927 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 8928 | } else if (override_ok) { |
michael@0 | 8929 | /* use this data's keyid */ |
michael@0 | 8930 | auth_keyid = chk->auth_keyid; |
michael@0 | 8931 | override_ok = 0; |
michael@0 | 8932 | } else if (auth_keyid != chk->auth_keyid) { |
michael@0 | 8933 | /* different keyid, so done bundling */ |
michael@0 | 8934 | break; |
michael@0 | 8935 | } |
michael@0 | 8936 | } |
michael@0 | 8937 | outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, 0, |
michael@0 | 8938 | chk->send_size, chk->copy_by_ref); |
michael@0 | 8939 | if (outchain == NULL) { |
michael@0 | 8940 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "No memory?\n"); |
michael@0 | 8941 | if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
michael@0 | 8942 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net); |
michael@0 | 8943 | } |
michael@0 | 8944 | *reason_code = 3; |
michael@0 | 8945 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 8946 | return (ENOMEM); |
michael@0 | 8947 | } |
michael@0 | 8948 | /* upate our MTU size */ |
michael@0 | 8949 | /* Do clear IP_DF ? */ |
michael@0 | 8950 | if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { |
michael@0 | 8951 | no_fragmentflg = 0; |
michael@0 | 8952 | } |
michael@0 | 8953 | /* unsigned subtraction of mtu */ |
michael@0 | 8954 | if (mtu > chk->send_size) |
michael@0 | 8955 | mtu -= chk->send_size; |
michael@0 | 8956 | else |
michael@0 | 8957 | mtu = 0; |
michael@0 | 8958 | /* unsigned subtraction of r_mtu */ |
michael@0 | 8959 | if (r_mtu > chk->send_size) |
michael@0 | 8960 | r_mtu -= chk->send_size; |
michael@0 | 8961 | else |
michael@0 | 8962 | r_mtu = 0; |
michael@0 | 8963 | |
michael@0 | 8964 | to_out += chk->send_size; |
michael@0 | 8965 | if ((to_out > mx_mtu) && no_fragmentflg) { |
michael@0 | 8966 | #ifdef INVARIANTS |
michael@0 | 8967 | panic("Exceeding mtu of %d out size is %d", mx_mtu, to_out); |
michael@0 | 8968 | #else |
michael@0 | 8969 | SCTP_PRINTF("Exceeding mtu of %d out size is %d\n", |
michael@0 | 8970 | mx_mtu, to_out); |
michael@0 | 8971 | #endif |
michael@0 | 8972 | } |
michael@0 | 8973 | chk->window_probe = 0; |
michael@0 | 8974 | data_list[bundle_at++] = chk; |
michael@0 | 8975 | if (bundle_at >= SCTP_MAX_DATA_BUNDLING) { |
michael@0 | 8976 | break; |
michael@0 | 8977 | } |
michael@0 | 8978 | if (chk->sent == SCTP_DATAGRAM_UNSENT) { |
michael@0 | 8979 | if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { |
michael@0 | 8980 | SCTP_STAT_INCR_COUNTER64(sctps_outorderchunks); |
michael@0 | 8981 | } else { |
michael@0 | 8982 | SCTP_STAT_INCR_COUNTER64(sctps_outunorderchunks); |
michael@0 | 8983 | } |
michael@0 | 8984 | if (((chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) && |
michael@0 | 8985 | ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0)) |
michael@0 | 8986 | /* Count number of user msg's that were fragmented |
michael@0 | 8987 | * we do this by counting when we see a LAST fragment |
michael@0 | 8988 | * only. |
michael@0 | 8989 | */ |
michael@0 | 8990 | SCTP_STAT_INCR_COUNTER64(sctps_fragusrmsgs); |
michael@0 | 8991 | } |
michael@0 | 8992 | if ((mtu == 0) || (r_mtu == 0) || (one_chunk)) { |
michael@0 | 8993 | if ((one_chunk) && (stcb->asoc.total_flight == 0)) { |
michael@0 | 8994 | data_list[0]->window_probe = 1; |
michael@0 | 8995 | net->window_probe = 1; |
michael@0 | 8996 | } |
michael@0 | 8997 | break; |
michael@0 | 8998 | } |
michael@0 | 8999 | } else { |
michael@0 | 9000 | /* |
michael@0 | 9001 | * Must be sent in order of the |
michael@0 | 9002 | * TSN's (on a network) |
michael@0 | 9003 | */ |
michael@0 | 9004 | break; |
michael@0 | 9005 | } |
michael@0 | 9006 | } /* for (chunk gather loop for this net) */ |
michael@0 | 9007 | } /* if asoc.state OPEN */ |
michael@0 | 9008 | no_data_fill: |
michael@0 | 9009 | /* Is there something to send for this destination? */ |
michael@0 | 9010 | if (outchain) { |
michael@0 | 9011 | /* We may need to start a control timer or two */ |
michael@0 | 9012 | if (asconf) { |
michael@0 | 9013 | sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, |
michael@0 | 9014 | stcb, net); |
michael@0 | 9015 | /* |
michael@0 | 9016 | * do NOT clear the asconf flag as it is used |
michael@0 | 9017 | * to do appropriate source address selection. |
michael@0 | 9018 | */ |
michael@0 | 9019 | } |
michael@0 | 9020 | if (cookie) { |
michael@0 | 9021 | sctp_timer_start(SCTP_TIMER_TYPE_COOKIE, inp, stcb, net); |
michael@0 | 9022 | cookie = 0; |
michael@0 | 9023 | } |
michael@0 | 9024 | /* must start a send timer if data is being sent */ |
michael@0 | 9025 | if (bundle_at && (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer))) { |
michael@0 | 9026 | /* |
michael@0 | 9027 | * no timer running on this destination |
michael@0 | 9028 | * restart it. |
michael@0 | 9029 | */ |
michael@0 | 9030 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net); |
michael@0 | 9031 | } |
michael@0 | 9032 | /* Now send it, if there is anything to send :> */ |
michael@0 | 9033 | if ((error = sctp_lowlevel_chunk_output(inp, |
michael@0 | 9034 | stcb, |
michael@0 | 9035 | net, |
michael@0 | 9036 | (struct sockaddr *)&net->ro._l_addr, |
michael@0 | 9037 | outchain, |
michael@0 | 9038 | auth_offset, |
michael@0 | 9039 | auth, |
michael@0 | 9040 | auth_keyid, |
michael@0 | 9041 | no_fragmentflg, |
michael@0 | 9042 | bundle_at, |
michael@0 | 9043 | asconf, |
michael@0 | 9044 | inp->sctp_lport, stcb->rport, |
michael@0 | 9045 | htonl(stcb->asoc.peer_vtag), |
michael@0 | 9046 | net->port, NULL, |
michael@0 | 9047 | #if defined(__FreeBSD__) |
michael@0 | 9048 | 0, 0, |
michael@0 | 9049 | #endif |
michael@0 | 9050 | so_locked))) { |
michael@0 | 9051 | /* error, we could not output */ |
michael@0 | 9052 | if (error == ENOBUFS) { |
michael@0 | 9053 | SCTP_STAT_INCR(sctps_lowlevelerr); |
michael@0 | 9054 | asoc->ifp_had_enobuf = 1; |
michael@0 | 9055 | } |
michael@0 | 9056 | if (from_where == 0) { |
michael@0 | 9057 | SCTP_STAT_INCR(sctps_lowlevelerrusr); |
michael@0 | 9058 | } |
michael@0 | 9059 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error); |
michael@0 | 9060 | if (hbflag) { |
michael@0 | 9061 | if (*now_filled == 0) { |
michael@0 | 9062 | (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); |
michael@0 | 9063 | *now_filled = 1; |
michael@0 | 9064 | *now = net->last_sent_time; |
michael@0 | 9065 | } else { |
michael@0 | 9066 | net->last_sent_time = *now; |
michael@0 | 9067 | } |
michael@0 | 9068 | hbflag = 0; |
michael@0 | 9069 | } |
michael@0 | 9070 | if (error == EHOSTUNREACH) { |
michael@0 | 9071 | /* |
michael@0 | 9072 | * Destination went unreachable |
michael@0 | 9073 | * during this send |
michael@0 | 9074 | */ |
michael@0 | 9075 | sctp_move_chunks_from_net(stcb, net); |
michael@0 | 9076 | } |
michael@0 | 9077 | *reason_code = 6; |
michael@0 | 9078 | /*- |
michael@0 | 9079 | * I add this line to be paranoid. As far as |
michael@0 | 9080 | * I can tell the continue, takes us back to |
michael@0 | 9081 | * the top of the for, but just to make sure |
michael@0 | 9082 | * I will reset these again here. |
michael@0 | 9083 | */ |
michael@0 | 9084 | ctl_cnt = bundle_at = 0; |
michael@0 | 9085 | continue; /* This takes us back to the for() for the nets. */ |
michael@0 | 9086 | } else { |
michael@0 | 9087 | asoc->ifp_had_enobuf = 0; |
michael@0 | 9088 | } |
michael@0 | 9089 | endoutchain = NULL; |
michael@0 | 9090 | auth = NULL; |
michael@0 | 9091 | auth_offset = 0; |
michael@0 | 9092 | if (bundle_at || hbflag) { |
michael@0 | 9093 | /* For data/asconf and hb set time */ |
michael@0 | 9094 | if (*now_filled == 0) { |
michael@0 | 9095 | (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); |
michael@0 | 9096 | *now_filled = 1; |
michael@0 | 9097 | *now = net->last_sent_time; |
michael@0 | 9098 | } else { |
michael@0 | 9099 | net->last_sent_time = *now; |
michael@0 | 9100 | } |
michael@0 | 9101 | } |
michael@0 | 9102 | if (!no_out_cnt) { |
michael@0 | 9103 | *num_out += (ctl_cnt + bundle_at); |
michael@0 | 9104 | } |
michael@0 | 9105 | if (bundle_at) { |
michael@0 | 9106 | /* setup for a RTO measurement */ |
michael@0 | 9107 | tsns_sent = data_list[0]->rec.data.TSN_seq; |
michael@0 | 9108 | /* fill time if not already filled */ |
michael@0 | 9109 | if (*now_filled == 0) { |
michael@0 | 9110 | (void)SCTP_GETTIME_TIMEVAL(&asoc->time_last_sent); |
michael@0 | 9111 | *now_filled = 1; |
michael@0 | 9112 | *now = asoc->time_last_sent; |
michael@0 | 9113 | } else { |
michael@0 | 9114 | asoc->time_last_sent = *now; |
michael@0 | 9115 | } |
michael@0 | 9116 | if (net->rto_needed) { |
michael@0 | 9117 | data_list[0]->do_rtt = 1; |
michael@0 | 9118 | net->rto_needed = 0; |
michael@0 | 9119 | } |
michael@0 | 9120 | SCTP_STAT_INCR_BY(sctps_senddata, bundle_at); |
michael@0 | 9121 | sctp_clean_up_datalist(stcb, asoc, data_list, bundle_at, net); |
michael@0 | 9122 | } |
michael@0 | 9123 | if (one_chunk) { |
michael@0 | 9124 | break; |
michael@0 | 9125 | } |
michael@0 | 9126 | } |
michael@0 | 9127 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 9128 | sctp_log_cwnd(stcb, net, tsns_sent, SCTP_CWND_LOG_FROM_SEND); |
michael@0 | 9129 | } |
michael@0 | 9130 | } |
michael@0 | 9131 | if (old_start_at == NULL) { |
michael@0 | 9132 | old_start_at = start_at; |
michael@0 | 9133 | start_at = TAILQ_FIRST(&asoc->nets); |
michael@0 | 9134 | if (old_start_at) |
michael@0 | 9135 | goto again_one_more_time; |
michael@0 | 9136 | } |
michael@0 | 9137 | |
michael@0 | 9138 | /* |
michael@0 | 9139 | * At the end there should be no NON timed chunks hanging on this |
michael@0 | 9140 | * queue. |
michael@0 | 9141 | */ |
michael@0 | 9142 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 9143 | sctp_log_cwnd(stcb, net, *num_out, SCTP_CWND_LOG_FROM_SEND); |
michael@0 | 9144 | } |
michael@0 | 9145 | if ((*num_out == 0) && (*reason_code == 0)) { |
michael@0 | 9146 | *reason_code = 4; |
michael@0 | 9147 | } else { |
michael@0 | 9148 | *reason_code = 5; |
michael@0 | 9149 | } |
michael@0 | 9150 | sctp_clean_up_ctl(stcb, asoc, so_locked); |
michael@0 | 9151 | return (0); |
michael@0 | 9152 | } |
michael@0 | 9153 | |
michael@0 | 9154 | void |
michael@0 | 9155 | sctp_queue_op_err(struct sctp_tcb *stcb, struct mbuf *op_err) |
michael@0 | 9156 | { |
michael@0 | 9157 | /*- |
michael@0 | 9158 | * Prepend a OPERATIONAL_ERROR chunk header and put on the end of |
michael@0 | 9159 | * the control chunk queue. |
michael@0 | 9160 | */ |
michael@0 | 9161 | struct sctp_chunkhdr *hdr; |
michael@0 | 9162 | struct sctp_tmit_chunk *chk; |
michael@0 | 9163 | struct mbuf *mat; |
michael@0 | 9164 | |
michael@0 | 9165 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 9166 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9167 | if (chk == NULL) { |
michael@0 | 9168 | /* no memory */ |
michael@0 | 9169 | sctp_m_freem(op_err); |
michael@0 | 9170 | return; |
michael@0 | 9171 | } |
michael@0 | 9172 | chk->copy_by_ref = 0; |
michael@0 | 9173 | SCTP_BUF_PREPEND(op_err, sizeof(struct sctp_chunkhdr), M_NOWAIT); |
michael@0 | 9174 | if (op_err == NULL) { |
michael@0 | 9175 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 9176 | return; |
michael@0 | 9177 | } |
michael@0 | 9178 | chk->send_size = 0; |
michael@0 | 9179 | mat = op_err; |
michael@0 | 9180 | while (mat != NULL) { |
michael@0 | 9181 | chk->send_size += SCTP_BUF_LEN(mat); |
michael@0 | 9182 | mat = SCTP_BUF_NEXT(mat); |
michael@0 | 9183 | } |
michael@0 | 9184 | chk->rec.chunk_id.id = SCTP_OPERATION_ERROR; |
michael@0 | 9185 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 9186 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9187 | chk->snd_count = 0; |
michael@0 | 9188 | chk->flags = 0; |
michael@0 | 9189 | chk->asoc = &stcb->asoc; |
michael@0 | 9190 | chk->data = op_err; |
michael@0 | 9191 | chk->whoTo = NULL; |
michael@0 | 9192 | hdr = mtod(op_err, struct sctp_chunkhdr *); |
michael@0 | 9193 | hdr->chunk_type = SCTP_OPERATION_ERROR; |
michael@0 | 9194 | hdr->chunk_flags = 0; |
michael@0 | 9195 | hdr->chunk_length = htons(chk->send_size); |
michael@0 | 9196 | TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, |
michael@0 | 9197 | chk, |
michael@0 | 9198 | sctp_next); |
michael@0 | 9199 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9200 | } |
michael@0 | 9201 | |
michael@0 | 9202 | int |
michael@0 | 9203 | sctp_send_cookie_echo(struct mbuf *m, |
michael@0 | 9204 | int offset, |
michael@0 | 9205 | struct sctp_tcb *stcb, |
michael@0 | 9206 | struct sctp_nets *net) |
michael@0 | 9207 | { |
michael@0 | 9208 | /*- |
michael@0 | 9209 | * pull out the cookie and put it at the front of the control chunk |
michael@0 | 9210 | * queue. |
michael@0 | 9211 | */ |
michael@0 | 9212 | int at; |
michael@0 | 9213 | struct mbuf *cookie; |
michael@0 | 9214 | struct sctp_paramhdr parm, *phdr; |
michael@0 | 9215 | struct sctp_chunkhdr *hdr; |
michael@0 | 9216 | struct sctp_tmit_chunk *chk; |
michael@0 | 9217 | uint16_t ptype, plen; |
michael@0 | 9218 | |
michael@0 | 9219 | /* First find the cookie in the param area */ |
michael@0 | 9220 | cookie = NULL; |
michael@0 | 9221 | at = offset + sizeof(struct sctp_init_chunk); |
michael@0 | 9222 | |
michael@0 | 9223 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 9224 | do { |
michael@0 | 9225 | phdr = sctp_get_next_param(m, at, &parm, sizeof(parm)); |
michael@0 | 9226 | if (phdr == NULL) { |
michael@0 | 9227 | return (-3); |
michael@0 | 9228 | } |
michael@0 | 9229 | ptype = ntohs(phdr->param_type); |
michael@0 | 9230 | plen = ntohs(phdr->param_length); |
michael@0 | 9231 | if (ptype == SCTP_STATE_COOKIE) { |
michael@0 | 9232 | int pad; |
michael@0 | 9233 | |
michael@0 | 9234 | /* found the cookie */ |
michael@0 | 9235 | if ((pad = (plen % 4))) { |
michael@0 | 9236 | plen += 4 - pad; |
michael@0 | 9237 | } |
michael@0 | 9238 | cookie = SCTP_M_COPYM(m, at, plen, M_NOWAIT); |
michael@0 | 9239 | if (cookie == NULL) { |
michael@0 | 9240 | /* No memory */ |
michael@0 | 9241 | return (-2); |
michael@0 | 9242 | } |
michael@0 | 9243 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 9244 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 9245 | struct mbuf *mat; |
michael@0 | 9246 | |
michael@0 | 9247 | for (mat = cookie; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 9248 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 9249 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 9250 | } |
michael@0 | 9251 | } |
michael@0 | 9252 | } |
michael@0 | 9253 | #endif |
michael@0 | 9254 | break; |
michael@0 | 9255 | } |
michael@0 | 9256 | at += SCTP_SIZE32(plen); |
michael@0 | 9257 | } while (phdr); |
michael@0 | 9258 | if (cookie == NULL) { |
michael@0 | 9259 | /* Did not find the cookie */ |
michael@0 | 9260 | return (-3); |
michael@0 | 9261 | } |
michael@0 | 9262 | /* ok, we got the cookie lets change it into a cookie echo chunk */ |
michael@0 | 9263 | |
michael@0 | 9264 | /* first the change from param to cookie */ |
michael@0 | 9265 | hdr = mtod(cookie, struct sctp_chunkhdr *); |
michael@0 | 9266 | hdr->chunk_type = SCTP_COOKIE_ECHO; |
michael@0 | 9267 | hdr->chunk_flags = 0; |
michael@0 | 9268 | /* get the chunk stuff now and place it in the FRONT of the queue */ |
michael@0 | 9269 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9270 | if (chk == NULL) { |
michael@0 | 9271 | /* no memory */ |
michael@0 | 9272 | sctp_m_freem(cookie); |
michael@0 | 9273 | return (-5); |
michael@0 | 9274 | } |
michael@0 | 9275 | chk->copy_by_ref = 0; |
michael@0 | 9276 | chk->send_size = plen; |
michael@0 | 9277 | chk->rec.chunk_id.id = SCTP_COOKIE_ECHO; |
michael@0 | 9278 | chk->rec.chunk_id.can_take_data = 0; |
michael@0 | 9279 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9280 | chk->snd_count = 0; |
michael@0 | 9281 | chk->flags = CHUNK_FLAGS_FRAGMENT_OK; |
michael@0 | 9282 | chk->asoc = &stcb->asoc; |
michael@0 | 9283 | chk->data = cookie; |
michael@0 | 9284 | chk->whoTo = net; |
michael@0 | 9285 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 9286 | TAILQ_INSERT_HEAD(&chk->asoc->control_send_queue, chk, sctp_next); |
michael@0 | 9287 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9288 | return (0); |
michael@0 | 9289 | } |
michael@0 | 9290 | |
michael@0 | 9291 | void |
michael@0 | 9292 | sctp_send_heartbeat_ack(struct sctp_tcb *stcb, |
michael@0 | 9293 | struct mbuf *m, |
michael@0 | 9294 | int offset, |
michael@0 | 9295 | int chk_length, |
michael@0 | 9296 | struct sctp_nets *net) |
michael@0 | 9297 | { |
michael@0 | 9298 | /* |
michael@0 | 9299 | * take a HB request and make it into a HB ack and send it. |
michael@0 | 9300 | */ |
michael@0 | 9301 | struct mbuf *outchain; |
michael@0 | 9302 | struct sctp_chunkhdr *chdr; |
michael@0 | 9303 | struct sctp_tmit_chunk *chk; |
michael@0 | 9304 | |
michael@0 | 9305 | |
michael@0 | 9306 | if (net == NULL) |
michael@0 | 9307 | /* must have a net pointer */ |
michael@0 | 9308 | return; |
michael@0 | 9309 | |
michael@0 | 9310 | outchain = SCTP_M_COPYM(m, offset, chk_length, M_NOWAIT); |
michael@0 | 9311 | if (outchain == NULL) { |
michael@0 | 9312 | /* gak out of memory */ |
michael@0 | 9313 | return; |
michael@0 | 9314 | } |
michael@0 | 9315 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 9316 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 9317 | struct mbuf *mat; |
michael@0 | 9318 | |
michael@0 | 9319 | for (mat = outchain; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 9320 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 9321 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 9322 | } |
michael@0 | 9323 | } |
michael@0 | 9324 | } |
michael@0 | 9325 | #endif |
michael@0 | 9326 | chdr = mtod(outchain, struct sctp_chunkhdr *); |
michael@0 | 9327 | chdr->chunk_type = SCTP_HEARTBEAT_ACK; |
michael@0 | 9328 | chdr->chunk_flags = 0; |
michael@0 | 9329 | if (chk_length % 4) { |
michael@0 | 9330 | /* need pad */ |
michael@0 | 9331 | uint32_t cpthis = 0; |
michael@0 | 9332 | int padlen; |
michael@0 | 9333 | |
michael@0 | 9334 | padlen = 4 - (chk_length % 4); |
michael@0 | 9335 | m_copyback(outchain, chk_length, padlen, (caddr_t)&cpthis); |
michael@0 | 9336 | } |
michael@0 | 9337 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9338 | if (chk == NULL) { |
michael@0 | 9339 | /* no memory */ |
michael@0 | 9340 | sctp_m_freem(outchain); |
michael@0 | 9341 | return; |
michael@0 | 9342 | } |
michael@0 | 9343 | chk->copy_by_ref = 0; |
michael@0 | 9344 | chk->send_size = chk_length; |
michael@0 | 9345 | chk->rec.chunk_id.id = SCTP_HEARTBEAT_ACK; |
michael@0 | 9346 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 9347 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9348 | chk->snd_count = 0; |
michael@0 | 9349 | chk->flags = 0; |
michael@0 | 9350 | chk->asoc = &stcb->asoc; |
michael@0 | 9351 | chk->data = outchain; |
michael@0 | 9352 | chk->whoTo = net; |
michael@0 | 9353 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 9354 | TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); |
michael@0 | 9355 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9356 | } |
michael@0 | 9357 | |
michael@0 | 9358 | void |
michael@0 | 9359 | sctp_send_cookie_ack(struct sctp_tcb *stcb) |
michael@0 | 9360 | { |
michael@0 | 9361 | /* formulate and queue a cookie-ack back to sender */ |
michael@0 | 9362 | struct mbuf *cookie_ack; |
michael@0 | 9363 | struct sctp_chunkhdr *hdr; |
michael@0 | 9364 | struct sctp_tmit_chunk *chk; |
michael@0 | 9365 | |
michael@0 | 9366 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 9367 | |
michael@0 | 9368 | cookie_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_chunkhdr), 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 9369 | if (cookie_ack == NULL) { |
michael@0 | 9370 | /* no mbuf's */ |
michael@0 | 9371 | return; |
michael@0 | 9372 | } |
michael@0 | 9373 | SCTP_BUF_RESV_UF(cookie_ack, SCTP_MIN_OVERHEAD); |
michael@0 | 9374 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9375 | if (chk == NULL) { |
michael@0 | 9376 | /* no memory */ |
michael@0 | 9377 | sctp_m_freem(cookie_ack); |
michael@0 | 9378 | return; |
michael@0 | 9379 | } |
michael@0 | 9380 | chk->copy_by_ref = 0; |
michael@0 | 9381 | chk->send_size = sizeof(struct sctp_chunkhdr); |
michael@0 | 9382 | chk->rec.chunk_id.id = SCTP_COOKIE_ACK; |
michael@0 | 9383 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 9384 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9385 | chk->snd_count = 0; |
michael@0 | 9386 | chk->flags = 0; |
michael@0 | 9387 | chk->asoc = &stcb->asoc; |
michael@0 | 9388 | chk->data = cookie_ack; |
michael@0 | 9389 | if (chk->asoc->last_control_chunk_from != NULL) { |
michael@0 | 9390 | chk->whoTo = chk->asoc->last_control_chunk_from; |
michael@0 | 9391 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 9392 | } else { |
michael@0 | 9393 | chk->whoTo = NULL; |
michael@0 | 9394 | } |
michael@0 | 9395 | hdr = mtod(cookie_ack, struct sctp_chunkhdr *); |
michael@0 | 9396 | hdr->chunk_type = SCTP_COOKIE_ACK; |
michael@0 | 9397 | hdr->chunk_flags = 0; |
michael@0 | 9398 | hdr->chunk_length = htons(chk->send_size); |
michael@0 | 9399 | SCTP_BUF_LEN(cookie_ack) = chk->send_size; |
michael@0 | 9400 | TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); |
michael@0 | 9401 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9402 | return; |
michael@0 | 9403 | } |
michael@0 | 9404 | |
michael@0 | 9405 | |
michael@0 | 9406 | void |
michael@0 | 9407 | sctp_send_shutdown_ack(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 9408 | { |
michael@0 | 9409 | /* formulate and queue a SHUTDOWN-ACK back to the sender */ |
michael@0 | 9410 | struct mbuf *m_shutdown_ack; |
michael@0 | 9411 | struct sctp_shutdown_ack_chunk *ack_cp; |
michael@0 | 9412 | struct sctp_tmit_chunk *chk; |
michael@0 | 9413 | |
michael@0 | 9414 | m_shutdown_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_shutdown_ack_chunk), 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 9415 | if (m_shutdown_ack == NULL) { |
michael@0 | 9416 | /* no mbuf's */ |
michael@0 | 9417 | return; |
michael@0 | 9418 | } |
michael@0 | 9419 | SCTP_BUF_RESV_UF(m_shutdown_ack, SCTP_MIN_OVERHEAD); |
michael@0 | 9420 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9421 | if (chk == NULL) { |
michael@0 | 9422 | /* no memory */ |
michael@0 | 9423 | sctp_m_freem(m_shutdown_ack); |
michael@0 | 9424 | return; |
michael@0 | 9425 | } |
michael@0 | 9426 | chk->copy_by_ref = 0; |
michael@0 | 9427 | chk->send_size = sizeof(struct sctp_chunkhdr); |
michael@0 | 9428 | chk->rec.chunk_id.id = SCTP_SHUTDOWN_ACK; |
michael@0 | 9429 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 9430 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9431 | chk->snd_count = 0; |
michael@0 | 9432 | chk->flags = 0; |
michael@0 | 9433 | chk->asoc = &stcb->asoc; |
michael@0 | 9434 | chk->data = m_shutdown_ack; |
michael@0 | 9435 | chk->whoTo = net; |
michael@0 | 9436 | if (chk->whoTo) { |
michael@0 | 9437 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 9438 | } |
michael@0 | 9439 | ack_cp = mtod(m_shutdown_ack, struct sctp_shutdown_ack_chunk *); |
michael@0 | 9440 | ack_cp->ch.chunk_type = SCTP_SHUTDOWN_ACK; |
michael@0 | 9441 | ack_cp->ch.chunk_flags = 0; |
michael@0 | 9442 | ack_cp->ch.chunk_length = htons(chk->send_size); |
michael@0 | 9443 | SCTP_BUF_LEN(m_shutdown_ack) = chk->send_size; |
michael@0 | 9444 | TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); |
michael@0 | 9445 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9446 | return; |
michael@0 | 9447 | } |
michael@0 | 9448 | |
michael@0 | 9449 | void |
michael@0 | 9450 | sctp_send_shutdown(struct sctp_tcb *stcb, struct sctp_nets *net) |
michael@0 | 9451 | { |
michael@0 | 9452 | /* formulate and queue a SHUTDOWN to the sender */ |
michael@0 | 9453 | struct mbuf *m_shutdown; |
michael@0 | 9454 | struct sctp_shutdown_chunk *shutdown_cp; |
michael@0 | 9455 | struct sctp_tmit_chunk *chk; |
michael@0 | 9456 | |
michael@0 | 9457 | m_shutdown = sctp_get_mbuf_for_msg(sizeof(struct sctp_shutdown_chunk), 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 9458 | if (m_shutdown == NULL) { |
michael@0 | 9459 | /* no mbuf's */ |
michael@0 | 9460 | return; |
michael@0 | 9461 | } |
michael@0 | 9462 | SCTP_BUF_RESV_UF(m_shutdown, SCTP_MIN_OVERHEAD); |
michael@0 | 9463 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9464 | if (chk == NULL) { |
michael@0 | 9465 | /* no memory */ |
michael@0 | 9466 | sctp_m_freem(m_shutdown); |
michael@0 | 9467 | return; |
michael@0 | 9468 | } |
michael@0 | 9469 | chk->copy_by_ref = 0; |
michael@0 | 9470 | chk->send_size = sizeof(struct sctp_shutdown_chunk); |
michael@0 | 9471 | chk->rec.chunk_id.id = SCTP_SHUTDOWN; |
michael@0 | 9472 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 9473 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9474 | chk->snd_count = 0; |
michael@0 | 9475 | chk->flags = 0; |
michael@0 | 9476 | chk->asoc = &stcb->asoc; |
michael@0 | 9477 | chk->data = m_shutdown; |
michael@0 | 9478 | chk->whoTo = net; |
michael@0 | 9479 | if (chk->whoTo) { |
michael@0 | 9480 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 9481 | } |
michael@0 | 9482 | shutdown_cp = mtod(m_shutdown, struct sctp_shutdown_chunk *); |
michael@0 | 9483 | shutdown_cp->ch.chunk_type = SCTP_SHUTDOWN; |
michael@0 | 9484 | shutdown_cp->ch.chunk_flags = 0; |
michael@0 | 9485 | shutdown_cp->ch.chunk_length = htons(chk->send_size); |
michael@0 | 9486 | shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn); |
michael@0 | 9487 | SCTP_BUF_LEN(m_shutdown) = chk->send_size; |
michael@0 | 9488 | TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); |
michael@0 | 9489 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9490 | return; |
michael@0 | 9491 | } |
michael@0 | 9492 | |
michael@0 | 9493 | void |
michael@0 | 9494 | sctp_send_asconf(struct sctp_tcb *stcb, struct sctp_nets *net, int addr_locked) |
michael@0 | 9495 | { |
michael@0 | 9496 | /* |
michael@0 | 9497 | * formulate and queue an ASCONF to the peer. |
michael@0 | 9498 | * ASCONF parameters should be queued on the assoc queue. |
michael@0 | 9499 | */ |
michael@0 | 9500 | struct sctp_tmit_chunk *chk; |
michael@0 | 9501 | struct mbuf *m_asconf; |
michael@0 | 9502 | int len; |
michael@0 | 9503 | |
michael@0 | 9504 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 9505 | |
michael@0 | 9506 | if ((!TAILQ_EMPTY(&stcb->asoc.asconf_send_queue)) && |
michael@0 | 9507 | (!sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_MULTIPLE_ASCONFS))) { |
michael@0 | 9508 | /* can't send a new one if there is one in flight already */ |
michael@0 | 9509 | return; |
michael@0 | 9510 | } |
michael@0 | 9511 | |
michael@0 | 9512 | /* compose an ASCONF chunk, maximum length is PMTU */ |
michael@0 | 9513 | m_asconf = sctp_compose_asconf(stcb, &len, addr_locked); |
michael@0 | 9514 | if (m_asconf == NULL) { |
michael@0 | 9515 | return; |
michael@0 | 9516 | } |
michael@0 | 9517 | |
michael@0 | 9518 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9519 | if (chk == NULL) { |
michael@0 | 9520 | /* no memory */ |
michael@0 | 9521 | sctp_m_freem(m_asconf); |
michael@0 | 9522 | return; |
michael@0 | 9523 | } |
michael@0 | 9524 | |
michael@0 | 9525 | chk->copy_by_ref = 0; |
michael@0 | 9526 | chk->data = m_asconf; |
michael@0 | 9527 | chk->send_size = len; |
michael@0 | 9528 | chk->rec.chunk_id.id = SCTP_ASCONF; |
michael@0 | 9529 | chk->rec.chunk_id.can_take_data = 0; |
michael@0 | 9530 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9531 | chk->snd_count = 0; |
michael@0 | 9532 | chk->flags = CHUNK_FLAGS_FRAGMENT_OK; |
michael@0 | 9533 | chk->asoc = &stcb->asoc; |
michael@0 | 9534 | chk->whoTo = net; |
michael@0 | 9535 | if (chk->whoTo) { |
michael@0 | 9536 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 9537 | } |
michael@0 | 9538 | TAILQ_INSERT_TAIL(&chk->asoc->asconf_send_queue, chk, sctp_next); |
michael@0 | 9539 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9540 | return; |
michael@0 | 9541 | } |
michael@0 | 9542 | |
michael@0 | 9543 | void |
michael@0 | 9544 | sctp_send_asconf_ack(struct sctp_tcb *stcb) |
michael@0 | 9545 | { |
michael@0 | 9546 | /* |
michael@0 | 9547 | * formulate and queue a asconf-ack back to sender. |
michael@0 | 9548 | * the asconf-ack must be stored in the tcb. |
michael@0 | 9549 | */ |
michael@0 | 9550 | struct sctp_tmit_chunk *chk; |
michael@0 | 9551 | struct sctp_asconf_ack *ack, *latest_ack; |
michael@0 | 9552 | struct mbuf *m_ack; |
michael@0 | 9553 | struct sctp_nets *net = NULL; |
michael@0 | 9554 | |
michael@0 | 9555 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 9556 | /* Get the latest ASCONF-ACK */ |
michael@0 | 9557 | latest_ack = TAILQ_LAST(&stcb->asoc.asconf_ack_sent, sctp_asconf_ackhead); |
michael@0 | 9558 | if (latest_ack == NULL) { |
michael@0 | 9559 | return; |
michael@0 | 9560 | } |
michael@0 | 9561 | if (latest_ack->last_sent_to != NULL && |
michael@0 | 9562 | latest_ack->last_sent_to == stcb->asoc.last_control_chunk_from) { |
michael@0 | 9563 | /* we're doing a retransmission */ |
michael@0 | 9564 | net = sctp_find_alternate_net(stcb, stcb->asoc.last_control_chunk_from, 0); |
michael@0 | 9565 | if (net == NULL) { |
michael@0 | 9566 | /* no alternate */ |
michael@0 | 9567 | if (stcb->asoc.last_control_chunk_from == NULL) { |
michael@0 | 9568 | if (stcb->asoc.alternate) { |
michael@0 | 9569 | net = stcb->asoc.alternate; |
michael@0 | 9570 | } else { |
michael@0 | 9571 | net = stcb->asoc.primary_destination; |
michael@0 | 9572 | } |
michael@0 | 9573 | } else { |
michael@0 | 9574 | net = stcb->asoc.last_control_chunk_from; |
michael@0 | 9575 | } |
michael@0 | 9576 | } |
michael@0 | 9577 | } else { |
michael@0 | 9578 | /* normal case */ |
michael@0 | 9579 | if (stcb->asoc.last_control_chunk_from == NULL) { |
michael@0 | 9580 | if (stcb->asoc.alternate) { |
michael@0 | 9581 | net = stcb->asoc.alternate; |
michael@0 | 9582 | } else { |
michael@0 | 9583 | net = stcb->asoc.primary_destination; |
michael@0 | 9584 | } |
michael@0 | 9585 | } else { |
michael@0 | 9586 | net = stcb->asoc.last_control_chunk_from; |
michael@0 | 9587 | } |
michael@0 | 9588 | } |
michael@0 | 9589 | latest_ack->last_sent_to = net; |
michael@0 | 9590 | |
michael@0 | 9591 | TAILQ_FOREACH(ack, &stcb->asoc.asconf_ack_sent, next) { |
michael@0 | 9592 | if (ack->data == NULL) { |
michael@0 | 9593 | continue; |
michael@0 | 9594 | } |
michael@0 | 9595 | |
michael@0 | 9596 | /* copy the asconf_ack */ |
michael@0 | 9597 | m_ack = SCTP_M_COPYM(ack->data, 0, M_COPYALL, M_NOWAIT); |
michael@0 | 9598 | if (m_ack == NULL) { |
michael@0 | 9599 | /* couldn't copy it */ |
michael@0 | 9600 | return; |
michael@0 | 9601 | } |
michael@0 | 9602 | #ifdef SCTP_MBUF_LOGGING |
michael@0 | 9603 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
michael@0 | 9604 | struct mbuf *mat; |
michael@0 | 9605 | |
michael@0 | 9606 | for (mat = m_ack; mat; mat = SCTP_BUF_NEXT(mat)) { |
michael@0 | 9607 | if (SCTP_BUF_IS_EXTENDED(mat)) { |
michael@0 | 9608 | sctp_log_mb(mat, SCTP_MBUF_ICOPY); |
michael@0 | 9609 | } |
michael@0 | 9610 | } |
michael@0 | 9611 | } |
michael@0 | 9612 | #endif |
michael@0 | 9613 | |
michael@0 | 9614 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 9615 | if (chk == NULL) { |
michael@0 | 9616 | /* no memory */ |
michael@0 | 9617 | if (m_ack) |
michael@0 | 9618 | sctp_m_freem(m_ack); |
michael@0 | 9619 | return; |
michael@0 | 9620 | } |
michael@0 | 9621 | chk->copy_by_ref = 0; |
michael@0 | 9622 | |
michael@0 | 9623 | chk->whoTo = net; |
michael@0 | 9624 | if (chk->whoTo) { |
michael@0 | 9625 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 9626 | } |
michael@0 | 9627 | chk->data = m_ack; |
michael@0 | 9628 | chk->send_size = 0; |
michael@0 | 9629 | /* Get size */ |
michael@0 | 9630 | chk->send_size = ack->len; |
michael@0 | 9631 | chk->rec.chunk_id.id = SCTP_ASCONF_ACK; |
michael@0 | 9632 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 9633 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 9634 | chk->snd_count = 0; |
michael@0 | 9635 | chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; /* XXX */ |
michael@0 | 9636 | chk->asoc = &stcb->asoc; |
michael@0 | 9637 | |
michael@0 | 9638 | TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); |
michael@0 | 9639 | chk->asoc->ctrl_queue_cnt++; |
michael@0 | 9640 | } |
michael@0 | 9641 | return; |
michael@0 | 9642 | } |
michael@0 | 9643 | |
michael@0 | 9644 | |
michael@0 | 9645 | static int |
michael@0 | 9646 | sctp_chunk_retransmission(struct sctp_inpcb *inp, |
michael@0 | 9647 | struct sctp_tcb *stcb, |
michael@0 | 9648 | struct sctp_association *asoc, |
michael@0 | 9649 | int *cnt_out, struct timeval *now, int *now_filled, int *fr_done, int so_locked |
michael@0 | 9650 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 9651 | SCTP_UNUSED |
michael@0 | 9652 | #endif |
michael@0 | 9653 | ) |
michael@0 | 9654 | { |
michael@0 | 9655 | /*- |
michael@0 | 9656 | * send out one MTU of retransmission. If fast_retransmit is |
michael@0 | 9657 | * happening we ignore the cwnd. Otherwise we obey the cwnd and |
michael@0 | 9658 | * rwnd. For a Cookie or Asconf in the control chunk queue we |
michael@0 | 9659 | * retransmit them by themselves. |
michael@0 | 9660 | * |
michael@0 | 9661 | * For data chunks we will pick out the lowest TSN's in the sent_queue |
michael@0 | 9662 | * marked for resend and bundle them all together (up to a MTU of |
michael@0 | 9663 | * destination). The address to send to should have been |
michael@0 | 9664 | * selected/changed where the retransmission was marked (i.e. in FR |
michael@0 | 9665 | * or t3-timeout routines). |
michael@0 | 9666 | */ |
michael@0 | 9667 | struct sctp_tmit_chunk *data_list[SCTP_MAX_DATA_BUNDLING]; |
michael@0 | 9668 | struct sctp_tmit_chunk *chk, *fwd; |
michael@0 | 9669 | struct mbuf *m, *endofchain; |
michael@0 | 9670 | struct sctp_nets *net = NULL; |
michael@0 | 9671 | uint32_t tsns_sent = 0; |
michael@0 | 9672 | int no_fragmentflg, bundle_at, cnt_thru; |
michael@0 | 9673 | unsigned int mtu; |
michael@0 | 9674 | int error, i, one_chunk, fwd_tsn, ctl_cnt, tmr_started; |
michael@0 | 9675 | struct sctp_auth_chunk *auth = NULL; |
michael@0 | 9676 | uint32_t auth_offset = 0; |
michael@0 | 9677 | uint16_t auth_keyid; |
michael@0 | 9678 | int override_ok = 1; |
michael@0 | 9679 | int data_auth_reqd = 0; |
michael@0 | 9680 | uint32_t dmtu = 0; |
michael@0 | 9681 | |
michael@0 | 9682 | #if defined(__APPLE__) |
michael@0 | 9683 | if (so_locked) { |
michael@0 | 9684 | sctp_lock_assert(SCTP_INP_SO(inp)); |
michael@0 | 9685 | } else { |
michael@0 | 9686 | sctp_unlock_assert(SCTP_INP_SO(inp)); |
michael@0 | 9687 | } |
michael@0 | 9688 | #endif |
michael@0 | 9689 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 9690 | tmr_started = ctl_cnt = bundle_at = error = 0; |
michael@0 | 9691 | no_fragmentflg = 1; |
michael@0 | 9692 | fwd_tsn = 0; |
michael@0 | 9693 | *cnt_out = 0; |
michael@0 | 9694 | fwd = NULL; |
michael@0 | 9695 | endofchain = m = NULL; |
michael@0 | 9696 | auth_keyid = stcb->asoc.authinfo.active_keyid; |
michael@0 | 9697 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 9698 | sctp_audit_log(0xC3, 1); |
michael@0 | 9699 | #endif |
michael@0 | 9700 | if ((TAILQ_EMPTY(&asoc->sent_queue)) && |
michael@0 | 9701 | (TAILQ_EMPTY(&asoc->control_send_queue))) { |
michael@0 | 9702 | SCTPDBG(SCTP_DEBUG_OUTPUT1,"SCTP hits empty queue with cnt set to %d?\n", |
michael@0 | 9703 | asoc->sent_queue_retran_cnt); |
michael@0 | 9704 | asoc->sent_queue_cnt = 0; |
michael@0 | 9705 | asoc->sent_queue_cnt_removeable = 0; |
michael@0 | 9706 | /* send back 0/0 so we enter normal transmission */ |
michael@0 | 9707 | *cnt_out = 0; |
michael@0 | 9708 | return (0); |
michael@0 | 9709 | } |
michael@0 | 9710 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 9711 | if ((chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) || |
michael@0 | 9712 | (chk->rec.chunk_id.id == SCTP_STREAM_RESET) || |
michael@0 | 9713 | (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN)) { |
michael@0 | 9714 | if (chk->sent != SCTP_DATAGRAM_RESEND) { |
michael@0 | 9715 | continue; |
michael@0 | 9716 | } |
michael@0 | 9717 | if (chk->rec.chunk_id.id == SCTP_STREAM_RESET) { |
michael@0 | 9718 | if (chk != asoc->str_reset) { |
michael@0 | 9719 | /* |
michael@0 | 9720 | * not eligible for retran if its |
michael@0 | 9721 | * not ours |
michael@0 | 9722 | */ |
michael@0 | 9723 | continue; |
michael@0 | 9724 | } |
michael@0 | 9725 | } |
michael@0 | 9726 | ctl_cnt++; |
michael@0 | 9727 | if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) { |
michael@0 | 9728 | fwd_tsn = 1; |
michael@0 | 9729 | } |
michael@0 | 9730 | /* |
michael@0 | 9731 | * Add an AUTH chunk, if chunk requires it save the |
michael@0 | 9732 | * offset into the chain for AUTH |
michael@0 | 9733 | */ |
michael@0 | 9734 | if ((auth == NULL) && |
michael@0 | 9735 | (sctp_auth_is_required_chunk(chk->rec.chunk_id.id, |
michael@0 | 9736 | stcb->asoc.peer_auth_chunks))) { |
michael@0 | 9737 | m = sctp_add_auth_chunk(m, &endofchain, |
michael@0 | 9738 | &auth, &auth_offset, |
michael@0 | 9739 | stcb, |
michael@0 | 9740 | chk->rec.chunk_id.id); |
michael@0 | 9741 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 9742 | } |
michael@0 | 9743 | m = sctp_copy_mbufchain(chk->data, m, &endofchain, 0, chk->send_size, chk->copy_by_ref); |
michael@0 | 9744 | break; |
michael@0 | 9745 | } |
michael@0 | 9746 | } |
michael@0 | 9747 | one_chunk = 0; |
michael@0 | 9748 | cnt_thru = 0; |
michael@0 | 9749 | /* do we have control chunks to retransmit? */ |
michael@0 | 9750 | if (m != NULL) { |
michael@0 | 9751 | /* Start a timer no matter if we suceed or fail */ |
michael@0 | 9752 | if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) { |
michael@0 | 9753 | sctp_timer_start(SCTP_TIMER_TYPE_COOKIE, inp, stcb, chk->whoTo); |
michael@0 | 9754 | } else if (chk->rec.chunk_id.id == SCTP_ASCONF) |
michael@0 | 9755 | sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, stcb, chk->whoTo); |
michael@0 | 9756 | chk->snd_count++; /* update our count */ |
michael@0 | 9757 | if ((error = sctp_lowlevel_chunk_output(inp, stcb, chk->whoTo, |
michael@0 | 9758 | (struct sockaddr *)&chk->whoTo->ro._l_addr, m, |
michael@0 | 9759 | auth_offset, auth, stcb->asoc.authinfo.active_keyid, |
michael@0 | 9760 | no_fragmentflg, 0, 0, |
michael@0 | 9761 | inp->sctp_lport, stcb->rport, htonl(stcb->asoc.peer_vtag), |
michael@0 | 9762 | chk->whoTo->port, NULL, |
michael@0 | 9763 | #if defined(__FreeBSD__) |
michael@0 | 9764 | 0, 0, |
michael@0 | 9765 | #endif |
michael@0 | 9766 | so_locked))) { |
michael@0 | 9767 | SCTP_STAT_INCR(sctps_lowlevelerr); |
michael@0 | 9768 | return (error); |
michael@0 | 9769 | } |
michael@0 | 9770 | endofchain = NULL; |
michael@0 | 9771 | auth = NULL; |
michael@0 | 9772 | auth_offset = 0; |
michael@0 | 9773 | /* |
michael@0 | 9774 | * We don't want to mark the net->sent time here since this |
michael@0 | 9775 | * we use this for HB and retrans cannot measure RTT |
michael@0 | 9776 | */ |
michael@0 | 9777 | /* (void)SCTP_GETTIME_TIMEVAL(&chk->whoTo->last_sent_time); */ |
michael@0 | 9778 | *cnt_out += 1; |
michael@0 | 9779 | chk->sent = SCTP_DATAGRAM_SENT; |
michael@0 | 9780 | sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt); |
michael@0 | 9781 | if (fwd_tsn == 0) { |
michael@0 | 9782 | return (0); |
michael@0 | 9783 | } else { |
michael@0 | 9784 | /* Clean up the fwd-tsn list */ |
michael@0 | 9785 | sctp_clean_up_ctl(stcb, asoc, so_locked); |
michael@0 | 9786 | return (0); |
michael@0 | 9787 | } |
michael@0 | 9788 | } |
michael@0 | 9789 | /* |
michael@0 | 9790 | * Ok, it is just data retransmission we need to do or that and a |
michael@0 | 9791 | * fwd-tsn with it all. |
michael@0 | 9792 | */ |
michael@0 | 9793 | if (TAILQ_EMPTY(&asoc->sent_queue)) { |
michael@0 | 9794 | return (SCTP_RETRAN_DONE); |
michael@0 | 9795 | } |
michael@0 | 9796 | if ((SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_ECHOED) || |
michael@0 | 9797 | (SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_WAIT)) { |
michael@0 | 9798 | /* not yet open, resend the cookie and that is it */ |
michael@0 | 9799 | return (1); |
michael@0 | 9800 | } |
michael@0 | 9801 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 9802 | sctp_auditing(20, inp, stcb, NULL); |
michael@0 | 9803 | #endif |
michael@0 | 9804 | data_auth_reqd = sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks); |
michael@0 | 9805 | TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { |
michael@0 | 9806 | if (chk->sent != SCTP_DATAGRAM_RESEND) { |
michael@0 | 9807 | /* No, not sent to this net or not ready for rtx */ |
michael@0 | 9808 | continue; |
michael@0 | 9809 | } |
michael@0 | 9810 | if (chk->data == NULL) { |
michael@0 | 9811 | SCTP_PRINTF("TSN:%x chk->snd_count:%d chk->sent:%d can't retran - no data\n", |
michael@0 | 9812 | chk->rec.data.TSN_seq, chk->snd_count, chk->sent); |
michael@0 | 9813 | continue; |
michael@0 | 9814 | } |
michael@0 | 9815 | if ((SCTP_BASE_SYSCTL(sctp_max_retran_chunk)) && |
michael@0 | 9816 | (chk->snd_count >= SCTP_BASE_SYSCTL(sctp_max_retran_chunk))) { |
michael@0 | 9817 | /* Gak, we have exceeded max unlucky retran, abort! */ |
michael@0 | 9818 | SCTP_PRINTF("Gak, chk->snd_count:%d >= max:%d - send abort\n", |
michael@0 | 9819 | chk->snd_count, |
michael@0 | 9820 | SCTP_BASE_SYSCTL(sctp_max_retran_chunk)); |
michael@0 | 9821 | atomic_add_int(&stcb->asoc.refcnt, 1); |
michael@0 | 9822 | sctp_abort_an_association(stcb->sctp_ep, stcb, NULL, so_locked); |
michael@0 | 9823 | SCTP_TCB_LOCK(stcb); |
michael@0 | 9824 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
michael@0 | 9825 | return (SCTP_RETRAN_EXIT); |
michael@0 | 9826 | } |
michael@0 | 9827 | /* pick up the net */ |
michael@0 | 9828 | net = chk->whoTo; |
michael@0 | 9829 | switch (net->ro._l_addr.sa.sa_family) { |
michael@0 | 9830 | #ifdef INET |
michael@0 | 9831 | case AF_INET: |
michael@0 | 9832 | mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; |
michael@0 | 9833 | break; |
michael@0 | 9834 | #endif |
michael@0 | 9835 | #ifdef INET6 |
michael@0 | 9836 | case AF_INET6: |
michael@0 | 9837 | mtu = net->mtu - SCTP_MIN_OVERHEAD; |
michael@0 | 9838 | break; |
michael@0 | 9839 | #endif |
michael@0 | 9840 | #if defined(__Userspace__) |
michael@0 | 9841 | case AF_CONN: |
michael@0 | 9842 | mtu = net->mtu - sizeof(struct sctphdr); |
michael@0 | 9843 | break; |
michael@0 | 9844 | #endif |
michael@0 | 9845 | default: |
michael@0 | 9846 | /* TSNH */ |
michael@0 | 9847 | mtu = net->mtu; |
michael@0 | 9848 | break; |
michael@0 | 9849 | } |
michael@0 | 9850 | |
michael@0 | 9851 | if ((asoc->peers_rwnd < mtu) && (asoc->total_flight > 0)) { |
michael@0 | 9852 | /* No room in peers rwnd */ |
michael@0 | 9853 | uint32_t tsn; |
michael@0 | 9854 | |
michael@0 | 9855 | tsn = asoc->last_acked_seq + 1; |
michael@0 | 9856 | if (tsn == chk->rec.data.TSN_seq) { |
michael@0 | 9857 | /* |
michael@0 | 9858 | * we make a special exception for this |
michael@0 | 9859 | * case. The peer has no rwnd but is missing |
michael@0 | 9860 | * the lowest chunk.. which is probably what |
michael@0 | 9861 | * is holding up the rwnd. |
michael@0 | 9862 | */ |
michael@0 | 9863 | goto one_chunk_around; |
michael@0 | 9864 | } |
michael@0 | 9865 | return (1); |
michael@0 | 9866 | } |
michael@0 | 9867 | one_chunk_around: |
michael@0 | 9868 | if (asoc->peers_rwnd < mtu) { |
michael@0 | 9869 | one_chunk = 1; |
michael@0 | 9870 | if ((asoc->peers_rwnd == 0) && |
michael@0 | 9871 | (asoc->total_flight == 0)) { |
michael@0 | 9872 | chk->window_probe = 1; |
michael@0 | 9873 | chk->whoTo->window_probe = 1; |
michael@0 | 9874 | } |
michael@0 | 9875 | } |
michael@0 | 9876 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 9877 | sctp_audit_log(0xC3, 2); |
michael@0 | 9878 | #endif |
michael@0 | 9879 | bundle_at = 0; |
michael@0 | 9880 | m = NULL; |
michael@0 | 9881 | net->fast_retran_ip = 0; |
michael@0 | 9882 | if (chk->rec.data.doing_fast_retransmit == 0) { |
michael@0 | 9883 | /* |
michael@0 | 9884 | * if no FR in progress skip destination that have |
michael@0 | 9885 | * flight_size > cwnd. |
michael@0 | 9886 | */ |
michael@0 | 9887 | if (net->flight_size >= net->cwnd) { |
michael@0 | 9888 | continue; |
michael@0 | 9889 | } |
michael@0 | 9890 | } else { |
michael@0 | 9891 | /* |
michael@0 | 9892 | * Mark the destination net to have FR recovery |
michael@0 | 9893 | * limits put on it. |
michael@0 | 9894 | */ |
michael@0 | 9895 | *fr_done = 1; |
michael@0 | 9896 | net->fast_retran_ip = 1; |
michael@0 | 9897 | } |
michael@0 | 9898 | |
michael@0 | 9899 | /* |
michael@0 | 9900 | * if no AUTH is yet included and this chunk requires it, |
michael@0 | 9901 | * make sure to account for it. We don't apply the size |
michael@0 | 9902 | * until the AUTH chunk is actually added below in case |
michael@0 | 9903 | * there is no room for this chunk. |
michael@0 | 9904 | */ |
michael@0 | 9905 | if (data_auth_reqd && (auth == NULL)) { |
michael@0 | 9906 | dmtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); |
michael@0 | 9907 | } else |
michael@0 | 9908 | dmtu = 0; |
michael@0 | 9909 | |
michael@0 | 9910 | if ((chk->send_size <= (mtu - dmtu)) || |
michael@0 | 9911 | (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) { |
michael@0 | 9912 | /* ok we will add this one */ |
michael@0 | 9913 | if (data_auth_reqd) { |
michael@0 | 9914 | if (auth == NULL) { |
michael@0 | 9915 | m = sctp_add_auth_chunk(m, |
michael@0 | 9916 | &endofchain, |
michael@0 | 9917 | &auth, |
michael@0 | 9918 | &auth_offset, |
michael@0 | 9919 | stcb, |
michael@0 | 9920 | SCTP_DATA); |
michael@0 | 9921 | auth_keyid = chk->auth_keyid; |
michael@0 | 9922 | override_ok = 0; |
michael@0 | 9923 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 9924 | } else if (override_ok) { |
michael@0 | 9925 | auth_keyid = chk->auth_keyid; |
michael@0 | 9926 | override_ok = 0; |
michael@0 | 9927 | } else if (chk->auth_keyid != auth_keyid) { |
michael@0 | 9928 | /* different keyid, so done bundling */ |
michael@0 | 9929 | break; |
michael@0 | 9930 | } |
michael@0 | 9931 | } |
michael@0 | 9932 | m = sctp_copy_mbufchain(chk->data, m, &endofchain, 0, chk->send_size, chk->copy_by_ref); |
michael@0 | 9933 | if (m == NULL) { |
michael@0 | 9934 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 9935 | return (ENOMEM); |
michael@0 | 9936 | } |
michael@0 | 9937 | /* Do clear IP_DF ? */ |
michael@0 | 9938 | if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { |
michael@0 | 9939 | no_fragmentflg = 0; |
michael@0 | 9940 | } |
michael@0 | 9941 | /* upate our MTU size */ |
michael@0 | 9942 | if (mtu > (chk->send_size + dmtu)) |
michael@0 | 9943 | mtu -= (chk->send_size + dmtu); |
michael@0 | 9944 | else |
michael@0 | 9945 | mtu = 0; |
michael@0 | 9946 | data_list[bundle_at++] = chk; |
michael@0 | 9947 | if (one_chunk && (asoc->total_flight <= 0)) { |
michael@0 | 9948 | SCTP_STAT_INCR(sctps_windowprobed); |
michael@0 | 9949 | } |
michael@0 | 9950 | } |
michael@0 | 9951 | if (one_chunk == 0) { |
michael@0 | 9952 | /* |
michael@0 | 9953 | * now are there anymore forward from chk to pick |
michael@0 | 9954 | * up? |
michael@0 | 9955 | */ |
michael@0 | 9956 | for (fwd = TAILQ_NEXT(chk, sctp_next); fwd != NULL; fwd = TAILQ_NEXT(fwd, sctp_next)) { |
michael@0 | 9957 | if (fwd->sent != SCTP_DATAGRAM_RESEND) { |
michael@0 | 9958 | /* Nope, not for retran */ |
michael@0 | 9959 | continue; |
michael@0 | 9960 | } |
michael@0 | 9961 | if (fwd->whoTo != net) { |
michael@0 | 9962 | /* Nope, not the net in question */ |
michael@0 | 9963 | continue; |
michael@0 | 9964 | } |
michael@0 | 9965 | if (data_auth_reqd && (auth == NULL)) { |
michael@0 | 9966 | dmtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); |
michael@0 | 9967 | } else |
michael@0 | 9968 | dmtu = 0; |
michael@0 | 9969 | if (fwd->send_size <= (mtu - dmtu)) { |
michael@0 | 9970 | if (data_auth_reqd) { |
michael@0 | 9971 | if (auth == NULL) { |
michael@0 | 9972 | m = sctp_add_auth_chunk(m, |
michael@0 | 9973 | &endofchain, |
michael@0 | 9974 | &auth, |
michael@0 | 9975 | &auth_offset, |
michael@0 | 9976 | stcb, |
michael@0 | 9977 | SCTP_DATA); |
michael@0 | 9978 | auth_keyid = fwd->auth_keyid; |
michael@0 | 9979 | override_ok = 0; |
michael@0 | 9980 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 9981 | } else if (override_ok) { |
michael@0 | 9982 | auth_keyid = fwd->auth_keyid; |
michael@0 | 9983 | override_ok = 0; |
michael@0 | 9984 | } else if (fwd->auth_keyid != auth_keyid) { |
michael@0 | 9985 | /* different keyid, so done bundling */ |
michael@0 | 9986 | break; |
michael@0 | 9987 | } |
michael@0 | 9988 | } |
michael@0 | 9989 | m = sctp_copy_mbufchain(fwd->data, m, &endofchain, 0, fwd->send_size, fwd->copy_by_ref); |
michael@0 | 9990 | if (m == NULL) { |
michael@0 | 9991 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 9992 | return (ENOMEM); |
michael@0 | 9993 | } |
michael@0 | 9994 | /* Do clear IP_DF ? */ |
michael@0 | 9995 | if (fwd->flags & CHUNK_FLAGS_FRAGMENT_OK) { |
michael@0 | 9996 | no_fragmentflg = 0; |
michael@0 | 9997 | } |
michael@0 | 9998 | /* upate our MTU size */ |
michael@0 | 9999 | if (mtu > (fwd->send_size + dmtu)) |
michael@0 | 10000 | mtu -= (fwd->send_size + dmtu); |
michael@0 | 10001 | else |
michael@0 | 10002 | mtu = 0; |
michael@0 | 10003 | data_list[bundle_at++] = fwd; |
michael@0 | 10004 | if (bundle_at >= SCTP_MAX_DATA_BUNDLING) { |
michael@0 | 10005 | break; |
michael@0 | 10006 | } |
michael@0 | 10007 | } else { |
michael@0 | 10008 | /* can't fit so we are done */ |
michael@0 | 10009 | break; |
michael@0 | 10010 | } |
michael@0 | 10011 | } |
michael@0 | 10012 | } |
michael@0 | 10013 | /* Is there something to send for this destination? */ |
michael@0 | 10014 | if (m) { |
michael@0 | 10015 | /* |
michael@0 | 10016 | * No matter if we fail/or suceed we should start a |
michael@0 | 10017 | * timer. A failure is like a lost IP packet :-) |
michael@0 | 10018 | */ |
michael@0 | 10019 | if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
michael@0 | 10020 | /* |
michael@0 | 10021 | * no timer running on this destination |
michael@0 | 10022 | * restart it. |
michael@0 | 10023 | */ |
michael@0 | 10024 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net); |
michael@0 | 10025 | tmr_started = 1; |
michael@0 | 10026 | } |
michael@0 | 10027 | /* Now lets send it, if there is anything to send :> */ |
michael@0 | 10028 | if ((error = sctp_lowlevel_chunk_output(inp, stcb, net, |
michael@0 | 10029 | (struct sockaddr *)&net->ro._l_addr, m, |
michael@0 | 10030 | auth_offset, auth, auth_keyid, |
michael@0 | 10031 | no_fragmentflg, 0, 0, |
michael@0 | 10032 | inp->sctp_lport, stcb->rport, htonl(stcb->asoc.peer_vtag), |
michael@0 | 10033 | net->port, NULL, |
michael@0 | 10034 | #if defined(__FreeBSD__) |
michael@0 | 10035 | 0, 0, |
michael@0 | 10036 | #endif |
michael@0 | 10037 | so_locked))) { |
michael@0 | 10038 | /* error, we could not output */ |
michael@0 | 10039 | SCTP_STAT_INCR(sctps_lowlevelerr); |
michael@0 | 10040 | return (error); |
michael@0 | 10041 | } |
michael@0 | 10042 | endofchain = NULL; |
michael@0 | 10043 | auth = NULL; |
michael@0 | 10044 | auth_offset = 0; |
michael@0 | 10045 | /* For HB's */ |
michael@0 | 10046 | /* |
michael@0 | 10047 | * We don't want to mark the net->sent time here |
michael@0 | 10048 | * since this we use this for HB and retrans cannot |
michael@0 | 10049 | * measure RTT |
michael@0 | 10050 | */ |
michael@0 | 10051 | /* (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); */ |
michael@0 | 10052 | |
michael@0 | 10053 | /* For auto-close */ |
michael@0 | 10054 | cnt_thru++; |
michael@0 | 10055 | if (*now_filled == 0) { |
michael@0 | 10056 | (void)SCTP_GETTIME_TIMEVAL(&asoc->time_last_sent); |
michael@0 | 10057 | *now = asoc->time_last_sent; |
michael@0 | 10058 | *now_filled = 1; |
michael@0 | 10059 | } else { |
michael@0 | 10060 | asoc->time_last_sent = *now; |
michael@0 | 10061 | } |
michael@0 | 10062 | *cnt_out += bundle_at; |
michael@0 | 10063 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 10064 | sctp_audit_log(0xC4, bundle_at); |
michael@0 | 10065 | #endif |
michael@0 | 10066 | if (bundle_at) { |
michael@0 | 10067 | tsns_sent = data_list[0]->rec.data.TSN_seq; |
michael@0 | 10068 | } |
michael@0 | 10069 | for (i = 0; i < bundle_at; i++) { |
michael@0 | 10070 | SCTP_STAT_INCR(sctps_sendretransdata); |
michael@0 | 10071 | data_list[i]->sent = SCTP_DATAGRAM_SENT; |
michael@0 | 10072 | /* |
michael@0 | 10073 | * When we have a revoked data, and we |
michael@0 | 10074 | * retransmit it, then we clear the revoked |
michael@0 | 10075 | * flag since this flag dictates if we |
michael@0 | 10076 | * subtracted from the fs |
michael@0 | 10077 | */ |
michael@0 | 10078 | if (data_list[i]->rec.data.chunk_was_revoked) { |
michael@0 | 10079 | /* Deflate the cwnd */ |
michael@0 | 10080 | data_list[i]->whoTo->cwnd -= data_list[i]->book_size; |
michael@0 | 10081 | data_list[i]->rec.data.chunk_was_revoked = 0; |
michael@0 | 10082 | } |
michael@0 | 10083 | data_list[i]->snd_count++; |
michael@0 | 10084 | sctp_ucount_decr(asoc->sent_queue_retran_cnt); |
michael@0 | 10085 | /* record the time */ |
michael@0 | 10086 | data_list[i]->sent_rcv_time = asoc->time_last_sent; |
michael@0 | 10087 | if (data_list[i]->book_size_scale) { |
michael@0 | 10088 | /* |
michael@0 | 10089 | * need to double the book size on |
michael@0 | 10090 | * this one |
michael@0 | 10091 | */ |
michael@0 | 10092 | data_list[i]->book_size_scale = 0; |
michael@0 | 10093 | /* Since we double the booksize, we must |
michael@0 | 10094 | * also double the output queue size, since this |
michael@0 | 10095 | * get shrunk when we free by this amount. |
michael@0 | 10096 | */ |
michael@0 | 10097 | atomic_add_int(&((asoc)->total_output_queue_size),data_list[i]->book_size); |
michael@0 | 10098 | data_list[i]->book_size *= 2; |
michael@0 | 10099 | |
michael@0 | 10100 | |
michael@0 | 10101 | } else { |
michael@0 | 10102 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_RWND_ENABLE) { |
michael@0 | 10103 | sctp_log_rwnd(SCTP_DECREASE_PEER_RWND, |
michael@0 | 10104 | asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); |
michael@0 | 10105 | } |
michael@0 | 10106 | asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd, |
michael@0 | 10107 | (uint32_t) (data_list[i]->send_size + |
michael@0 | 10108 | SCTP_BASE_SYSCTL(sctp_peer_chunk_oh))); |
michael@0 | 10109 | } |
michael@0 | 10110 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
michael@0 | 10111 | sctp_misc_ints(SCTP_FLIGHT_LOG_UP_RSND, |
michael@0 | 10112 | data_list[i]->whoTo->flight_size, |
michael@0 | 10113 | data_list[i]->book_size, |
michael@0 | 10114 | (uintptr_t)data_list[i]->whoTo, |
michael@0 | 10115 | data_list[i]->rec.data.TSN_seq); |
michael@0 | 10116 | } |
michael@0 | 10117 | sctp_flight_size_increase(data_list[i]); |
michael@0 | 10118 | sctp_total_flight_increase(stcb, data_list[i]); |
michael@0 | 10119 | if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { |
michael@0 | 10120 | /* SWS sender side engages */ |
michael@0 | 10121 | asoc->peers_rwnd = 0; |
michael@0 | 10122 | } |
michael@0 | 10123 | if ((i == 0) && |
michael@0 | 10124 | (data_list[i]->rec.data.doing_fast_retransmit)) { |
michael@0 | 10125 | SCTP_STAT_INCR(sctps_sendfastretrans); |
michael@0 | 10126 | if ((data_list[i] == TAILQ_FIRST(&asoc->sent_queue)) && |
michael@0 | 10127 | (tmr_started == 0)) { |
michael@0 | 10128 | /*- |
michael@0 | 10129 | * ok we just fast-retrans'd |
michael@0 | 10130 | * the lowest TSN, i.e the |
michael@0 | 10131 | * first on the list. In |
michael@0 | 10132 | * this case we want to give |
michael@0 | 10133 | * some more time to get a |
michael@0 | 10134 | * SACK back without a |
michael@0 | 10135 | * t3-expiring. |
michael@0 | 10136 | */ |
michael@0 | 10137 | sctp_timer_stop(SCTP_TIMER_TYPE_SEND, inp, stcb, net, |
michael@0 | 10138 | SCTP_FROM_SCTP_OUTPUT+SCTP_LOC_4); |
michael@0 | 10139 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net); |
michael@0 | 10140 | } |
michael@0 | 10141 | } |
michael@0 | 10142 | } |
michael@0 | 10143 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 10144 | sctp_log_cwnd(stcb, net, tsns_sent, SCTP_CWND_LOG_FROM_RESEND); |
michael@0 | 10145 | } |
michael@0 | 10146 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 10147 | sctp_auditing(21, inp, stcb, NULL); |
michael@0 | 10148 | #endif |
michael@0 | 10149 | } else { |
michael@0 | 10150 | /* None will fit */ |
michael@0 | 10151 | return (1); |
michael@0 | 10152 | } |
michael@0 | 10153 | if (asoc->sent_queue_retran_cnt <= 0) { |
michael@0 | 10154 | /* all done we have no more to retran */ |
michael@0 | 10155 | asoc->sent_queue_retran_cnt = 0; |
michael@0 | 10156 | break; |
michael@0 | 10157 | } |
michael@0 | 10158 | if (one_chunk) { |
michael@0 | 10159 | /* No more room in rwnd */ |
michael@0 | 10160 | return (1); |
michael@0 | 10161 | } |
michael@0 | 10162 | /* stop the for loop here. we sent out a packet */ |
michael@0 | 10163 | break; |
michael@0 | 10164 | } |
michael@0 | 10165 | return (0); |
michael@0 | 10166 | } |
michael@0 | 10167 | |
michael@0 | 10168 | static void |
michael@0 | 10169 | sctp_timer_validation(struct sctp_inpcb *inp, |
michael@0 | 10170 | struct sctp_tcb *stcb, |
michael@0 | 10171 | struct sctp_association *asoc) |
michael@0 | 10172 | { |
michael@0 | 10173 | struct sctp_nets *net; |
michael@0 | 10174 | |
michael@0 | 10175 | /* Validate that a timer is running somewhere */ |
michael@0 | 10176 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 10177 | if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { |
michael@0 | 10178 | /* Here is a timer */ |
michael@0 | 10179 | return; |
michael@0 | 10180 | } |
michael@0 | 10181 | } |
michael@0 | 10182 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 10183 | /* Gak, we did not have a timer somewhere */ |
michael@0 | 10184 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "Deadlock avoided starting timer on a dest at retran\n"); |
michael@0 | 10185 | if (asoc->alternate) { |
michael@0 | 10186 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, asoc->alternate); |
michael@0 | 10187 | } else { |
michael@0 | 10188 | sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, asoc->primary_destination); |
michael@0 | 10189 | } |
michael@0 | 10190 | return; |
michael@0 | 10191 | } |
michael@0 | 10192 | |
michael@0 | 10193 | void |
michael@0 | 10194 | sctp_chunk_output (struct sctp_inpcb *inp, |
michael@0 | 10195 | struct sctp_tcb *stcb, |
michael@0 | 10196 | int from_where, |
michael@0 | 10197 | int so_locked |
michael@0 | 10198 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 10199 | SCTP_UNUSED |
michael@0 | 10200 | #endif |
michael@0 | 10201 | ) |
michael@0 | 10202 | { |
michael@0 | 10203 | /*- |
michael@0 | 10204 | * Ok this is the generic chunk service queue. we must do the |
michael@0 | 10205 | * following: |
michael@0 | 10206 | * - See if there are retransmits pending, if so we must |
michael@0 | 10207 | * do these first. |
michael@0 | 10208 | * - Service the stream queue that is next, moving any |
michael@0 | 10209 | * message (note I must get a complete message i.e. |
michael@0 | 10210 | * FIRST/MIDDLE and LAST to the out queue in one pass) and assigning |
michael@0 | 10211 | * TSN's |
michael@0 | 10212 | * - Check to see if the cwnd/rwnd allows any output, if so we |
michael@0 | 10213 | * go ahead and fomulate and send the low level chunks. Making sure |
michael@0 | 10214 | * to combine any control in the control chunk queue also. |
michael@0 | 10215 | */ |
michael@0 | 10216 | struct sctp_association *asoc; |
michael@0 | 10217 | struct sctp_nets *net; |
michael@0 | 10218 | int error = 0, num_out = 0, tot_out = 0, ret = 0, reason_code = 0; |
michael@0 | 10219 | unsigned int burst_cnt = 0; |
michael@0 | 10220 | struct timeval now; |
michael@0 | 10221 | int now_filled = 0; |
michael@0 | 10222 | int nagle_on; |
michael@0 | 10223 | int frag_point = sctp_get_frag_point(stcb, &stcb->asoc); |
michael@0 | 10224 | int un_sent = 0; |
michael@0 | 10225 | int fr_done; |
michael@0 | 10226 | unsigned int tot_frs = 0; |
michael@0 | 10227 | |
michael@0 | 10228 | #if defined(__APPLE__) |
michael@0 | 10229 | if (so_locked) { |
michael@0 | 10230 | sctp_lock_assert(SCTP_INP_SO(inp)); |
michael@0 | 10231 | } else { |
michael@0 | 10232 | sctp_unlock_assert(SCTP_INP_SO(inp)); |
michael@0 | 10233 | } |
michael@0 | 10234 | #endif |
michael@0 | 10235 | asoc = &stcb->asoc; |
michael@0 | 10236 | /* The Nagle algorithm is only applied when handling a send call. */ |
michael@0 | 10237 | if (from_where == SCTP_OUTPUT_FROM_USR_SEND) { |
michael@0 | 10238 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY)) { |
michael@0 | 10239 | nagle_on = 0; |
michael@0 | 10240 | } else { |
michael@0 | 10241 | nagle_on = 1; |
michael@0 | 10242 | } |
michael@0 | 10243 | } else { |
michael@0 | 10244 | nagle_on = 0; |
michael@0 | 10245 | } |
michael@0 | 10246 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 10247 | |
michael@0 | 10248 | un_sent = (stcb->asoc.total_output_queue_size - stcb->asoc.total_flight); |
michael@0 | 10249 | |
michael@0 | 10250 | if ((un_sent <= 0) && |
michael@0 | 10251 | (TAILQ_EMPTY(&asoc->control_send_queue)) && |
michael@0 | 10252 | (TAILQ_EMPTY(&asoc->asconf_send_queue)) && |
michael@0 | 10253 | (asoc->sent_queue_retran_cnt == 0)) { |
michael@0 | 10254 | /* Nothing to do unless there is something to be sent left */ |
michael@0 | 10255 | return; |
michael@0 | 10256 | } |
michael@0 | 10257 | /* Do we have something to send, data or control AND |
michael@0 | 10258 | * a sack timer running, if so piggy-back the sack. |
michael@0 | 10259 | */ |
michael@0 | 10260 | if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { |
michael@0 | 10261 | sctp_send_sack(stcb, so_locked); |
michael@0 | 10262 | (void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer); |
michael@0 | 10263 | } |
michael@0 | 10264 | while (asoc->sent_queue_retran_cnt) { |
michael@0 | 10265 | /*- |
michael@0 | 10266 | * Ok, it is retransmission time only, we send out only ONE |
michael@0 | 10267 | * packet with a single call off to the retran code. |
michael@0 | 10268 | */ |
michael@0 | 10269 | if (from_where == SCTP_OUTPUT_FROM_COOKIE_ACK) { |
michael@0 | 10270 | /*- |
michael@0 | 10271 | * Special hook for handling cookiess discarded |
michael@0 | 10272 | * by peer that carried data. Send cookie-ack only |
michael@0 | 10273 | * and then the next call with get the retran's. |
michael@0 | 10274 | */ |
michael@0 | 10275 | (void)sctp_med_chunk_output(inp, stcb, asoc, &num_out, &reason_code, 1, |
michael@0 | 10276 | from_where, |
michael@0 | 10277 | &now, &now_filled, frag_point, so_locked); |
michael@0 | 10278 | return; |
michael@0 | 10279 | } else if (from_where != SCTP_OUTPUT_FROM_HB_TMR) { |
michael@0 | 10280 | /* if its not from a HB then do it */ |
michael@0 | 10281 | fr_done = 0; |
michael@0 | 10282 | ret = sctp_chunk_retransmission(inp, stcb, asoc, &num_out, &now, &now_filled, &fr_done, so_locked); |
michael@0 | 10283 | if (fr_done) { |
michael@0 | 10284 | tot_frs++; |
michael@0 | 10285 | } |
michael@0 | 10286 | } else { |
michael@0 | 10287 | /* |
michael@0 | 10288 | * its from any other place, we don't allow retran |
michael@0 | 10289 | * output (only control) |
michael@0 | 10290 | */ |
michael@0 | 10291 | ret = 1; |
michael@0 | 10292 | } |
michael@0 | 10293 | if (ret > 0) { |
michael@0 | 10294 | /* Can't send anymore */ |
michael@0 | 10295 | /*- |
michael@0 | 10296 | * now lets push out control by calling med-level |
michael@0 | 10297 | * output once. this assures that we WILL send HB's |
michael@0 | 10298 | * if queued too. |
michael@0 | 10299 | */ |
michael@0 | 10300 | (void)sctp_med_chunk_output(inp, stcb, asoc, &num_out, &reason_code, 1, |
michael@0 | 10301 | from_where, |
michael@0 | 10302 | &now, &now_filled, frag_point, so_locked); |
michael@0 | 10303 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 10304 | sctp_auditing(8, inp, stcb, NULL); |
michael@0 | 10305 | #endif |
michael@0 | 10306 | sctp_timer_validation(inp, stcb, asoc); |
michael@0 | 10307 | return; |
michael@0 | 10308 | } |
michael@0 | 10309 | if (ret < 0) { |
michael@0 | 10310 | /*- |
michael@0 | 10311 | * The count was off.. retran is not happening so do |
michael@0 | 10312 | * the normal retransmission. |
michael@0 | 10313 | */ |
michael@0 | 10314 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 10315 | sctp_auditing(9, inp, stcb, NULL); |
michael@0 | 10316 | #endif |
michael@0 | 10317 | if (ret == SCTP_RETRAN_EXIT) { |
michael@0 | 10318 | return; |
michael@0 | 10319 | } |
michael@0 | 10320 | break; |
michael@0 | 10321 | } |
michael@0 | 10322 | if (from_where == SCTP_OUTPUT_FROM_T3) { |
michael@0 | 10323 | /* Only one transmission allowed out of a timeout */ |
michael@0 | 10324 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 10325 | sctp_auditing(10, inp, stcb, NULL); |
michael@0 | 10326 | #endif |
michael@0 | 10327 | /* Push out any control */ |
michael@0 | 10328 | (void)sctp_med_chunk_output(inp, stcb, asoc, &num_out, &reason_code, 1, from_where, |
michael@0 | 10329 | &now, &now_filled, frag_point, so_locked); |
michael@0 | 10330 | return; |
michael@0 | 10331 | } |
michael@0 | 10332 | if ((asoc->fr_max_burst > 0) && (tot_frs >= asoc->fr_max_burst)) { |
michael@0 | 10333 | /* Hit FR burst limit */ |
michael@0 | 10334 | return; |
michael@0 | 10335 | } |
michael@0 | 10336 | if ((num_out == 0) && (ret == 0)) { |
michael@0 | 10337 | /* No more retrans to send */ |
michael@0 | 10338 | break; |
michael@0 | 10339 | } |
michael@0 | 10340 | } |
michael@0 | 10341 | #ifdef SCTP_AUDITING_ENABLED |
michael@0 | 10342 | sctp_auditing(12, inp, stcb, NULL); |
michael@0 | 10343 | #endif |
michael@0 | 10344 | /* Check for bad destinations, if they exist move chunks around. */ |
michael@0 | 10345 | TAILQ_FOREACH(net, &asoc->nets, sctp_next) { |
michael@0 | 10346 | if (!(net->dest_state & SCTP_ADDR_REACHABLE)) { |
michael@0 | 10347 | /*- |
michael@0 | 10348 | * if possible move things off of this address we |
michael@0 | 10349 | * still may send below due to the dormant state but |
michael@0 | 10350 | * we try to find an alternate address to send to |
michael@0 | 10351 | * and if we have one we move all queued data on the |
michael@0 | 10352 | * out wheel to this alternate address. |
michael@0 | 10353 | */ |
michael@0 | 10354 | if (net->ref_count > 1) |
michael@0 | 10355 | sctp_move_chunks_from_net(stcb, net); |
michael@0 | 10356 | } else { |
michael@0 | 10357 | /*- |
michael@0 | 10358 | * if ((asoc->sat_network) || (net->addr_is_local)) |
michael@0 | 10359 | * { burst_limit = asoc->max_burst * |
michael@0 | 10360 | * SCTP_SAT_NETWORK_BURST_INCR; } |
michael@0 | 10361 | */ |
michael@0 | 10362 | if (asoc->max_burst > 0) { |
michael@0 | 10363 | if (SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst)) { |
michael@0 | 10364 | if ((net->flight_size + (asoc->max_burst * net->mtu)) < net->cwnd) { |
michael@0 | 10365 | /* JRS - Use the congestion control given in the congestion control module */ |
michael@0 | 10366 | asoc->cc_functions.sctp_cwnd_update_after_output(stcb, net, asoc->max_burst); |
michael@0 | 10367 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_MAXBURST_ENABLE) { |
michael@0 | 10368 | sctp_log_maxburst(stcb, net, 0, asoc->max_burst, SCTP_MAX_BURST_APPLIED); |
michael@0 | 10369 | } |
michael@0 | 10370 | SCTP_STAT_INCR(sctps_maxburstqueued); |
michael@0 | 10371 | } |
michael@0 | 10372 | net->fast_retran_ip = 0; |
michael@0 | 10373 | } else { |
michael@0 | 10374 | if (net->flight_size == 0) { |
michael@0 | 10375 | /* Should be decaying the cwnd here */ |
michael@0 | 10376 | ; |
michael@0 | 10377 | } |
michael@0 | 10378 | } |
michael@0 | 10379 | } |
michael@0 | 10380 | } |
michael@0 | 10381 | |
michael@0 | 10382 | } |
michael@0 | 10383 | burst_cnt = 0; |
michael@0 | 10384 | do { |
michael@0 | 10385 | error = sctp_med_chunk_output(inp, stcb, asoc, &num_out, |
michael@0 | 10386 | &reason_code, 0, from_where, |
michael@0 | 10387 | &now, &now_filled, frag_point, so_locked); |
michael@0 | 10388 | if (error) { |
michael@0 | 10389 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Error %d was returned from med-c-op\n", error); |
michael@0 | 10390 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_MAXBURST_ENABLE) { |
michael@0 | 10391 | sctp_log_maxburst(stcb, asoc->primary_destination, error, burst_cnt, SCTP_MAX_BURST_ERROR_STOP); |
michael@0 | 10392 | } |
michael@0 | 10393 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 10394 | sctp_log_cwnd(stcb, NULL, error, SCTP_SEND_NOW_COMPLETES); |
michael@0 | 10395 | sctp_log_cwnd(stcb, NULL, 0xdeadbeef, SCTP_SEND_NOW_COMPLETES); |
michael@0 | 10396 | } |
michael@0 | 10397 | break; |
michael@0 | 10398 | } |
michael@0 | 10399 | SCTPDBG(SCTP_DEBUG_OUTPUT3, "m-c-o put out %d\n", num_out); |
michael@0 | 10400 | |
michael@0 | 10401 | tot_out += num_out; |
michael@0 | 10402 | burst_cnt++; |
michael@0 | 10403 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 10404 | sctp_log_cwnd(stcb, NULL, num_out, SCTP_SEND_NOW_COMPLETES); |
michael@0 | 10405 | if (num_out == 0) { |
michael@0 | 10406 | sctp_log_cwnd(stcb, NULL, reason_code, SCTP_SEND_NOW_COMPLETES); |
michael@0 | 10407 | } |
michael@0 | 10408 | } |
michael@0 | 10409 | if (nagle_on) { |
michael@0 | 10410 | /* |
michael@0 | 10411 | * When the Nagle algorithm is used, look at how much |
michael@0 | 10412 | * is unsent, then if its smaller than an MTU and we |
michael@0 | 10413 | * have data in flight we stop, except if we are |
michael@0 | 10414 | * handling a fragmented user message. |
michael@0 | 10415 | */ |
michael@0 | 10416 | un_sent = ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) + |
michael@0 | 10417 | (stcb->asoc.stream_queue_cnt * sizeof(struct sctp_data_chunk))); |
michael@0 | 10418 | if ((un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD)) && |
michael@0 | 10419 | (stcb->asoc.total_flight > 0) && |
michael@0 | 10420 | ((stcb->asoc.locked_on_sending == NULL) || |
michael@0 | 10421 | sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR))) { |
michael@0 | 10422 | break; |
michael@0 | 10423 | } |
michael@0 | 10424 | } |
michael@0 | 10425 | if (TAILQ_EMPTY(&asoc->control_send_queue) && |
michael@0 | 10426 | TAILQ_EMPTY(&asoc->send_queue) && |
michael@0 | 10427 | stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, asoc)) { |
michael@0 | 10428 | /* Nothing left to send */ |
michael@0 | 10429 | break; |
michael@0 | 10430 | } |
michael@0 | 10431 | if ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) <= 0) { |
michael@0 | 10432 | /* Nothing left to send */ |
michael@0 | 10433 | break; |
michael@0 | 10434 | } |
michael@0 | 10435 | } while (num_out && |
michael@0 | 10436 | ((asoc->max_burst == 0) || |
michael@0 | 10437 | SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst) || |
michael@0 | 10438 | (burst_cnt < asoc->max_burst))); |
michael@0 | 10439 | |
michael@0 | 10440 | if (SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst) == 0) { |
michael@0 | 10441 | if ((asoc->max_burst > 0) && (burst_cnt >= asoc->max_burst)) { |
michael@0 | 10442 | SCTP_STAT_INCR(sctps_maxburstqueued); |
michael@0 | 10443 | asoc->burst_limit_applied = 1; |
michael@0 | 10444 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_MAXBURST_ENABLE) { |
michael@0 | 10445 | sctp_log_maxburst(stcb, asoc->primary_destination, 0, burst_cnt, SCTP_MAX_BURST_APPLIED); |
michael@0 | 10446 | } |
michael@0 | 10447 | } else { |
michael@0 | 10448 | asoc->burst_limit_applied = 0; |
michael@0 | 10449 | } |
michael@0 | 10450 | } |
michael@0 | 10451 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { |
michael@0 | 10452 | sctp_log_cwnd(stcb, NULL, tot_out, SCTP_SEND_NOW_COMPLETES); |
michael@0 | 10453 | } |
michael@0 | 10454 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Ok, we have put out %d chunks\n", |
michael@0 | 10455 | tot_out); |
michael@0 | 10456 | |
michael@0 | 10457 | /*- |
michael@0 | 10458 | * Now we need to clean up the control chunk chain if a ECNE is on |
michael@0 | 10459 | * it. It must be marked as UNSENT again so next call will continue |
michael@0 | 10460 | * to send it until such time that we get a CWR, to remove it. |
michael@0 | 10461 | */ |
michael@0 | 10462 | if (stcb->asoc.ecn_echo_cnt_onq) |
michael@0 | 10463 | sctp_fix_ecn_echo(asoc); |
michael@0 | 10464 | return; |
michael@0 | 10465 | } |
michael@0 | 10466 | |
michael@0 | 10467 | |
michael@0 | 10468 | int |
michael@0 | 10469 | sctp_output( |
michael@0 | 10470 | struct sctp_inpcb *inp, |
michael@0 | 10471 | #if defined(__Panda__) |
michael@0 | 10472 | pakhandle_type m, |
michael@0 | 10473 | #else |
michael@0 | 10474 | struct mbuf *m, |
michael@0 | 10475 | #endif |
michael@0 | 10476 | struct sockaddr *addr, |
michael@0 | 10477 | #if defined(__Panda__) |
michael@0 | 10478 | pakhandle_type control, |
michael@0 | 10479 | #else |
michael@0 | 10480 | struct mbuf *control, |
michael@0 | 10481 | #endif |
michael@0 | 10482 | #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 |
michael@0 | 10483 | struct thread *p, |
michael@0 | 10484 | #elif defined(__Windows__) |
michael@0 | 10485 | PKTHREAD p, |
michael@0 | 10486 | #else |
michael@0 | 10487 | #if defined(__APPLE__) |
michael@0 | 10488 | struct proc *p SCTP_UNUSED, |
michael@0 | 10489 | #else |
michael@0 | 10490 | struct proc *p, |
michael@0 | 10491 | #endif |
michael@0 | 10492 | #endif |
michael@0 | 10493 | int flags) |
michael@0 | 10494 | { |
michael@0 | 10495 | if (inp == NULL) { |
michael@0 | 10496 | SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 10497 | return (EINVAL); |
michael@0 | 10498 | } |
michael@0 | 10499 | |
michael@0 | 10500 | if (inp->sctp_socket == NULL) { |
michael@0 | 10501 | SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 10502 | return (EINVAL); |
michael@0 | 10503 | } |
michael@0 | 10504 | return (sctp_sosend(inp->sctp_socket, |
michael@0 | 10505 | addr, |
michael@0 | 10506 | (struct uio *)NULL, |
michael@0 | 10507 | m, |
michael@0 | 10508 | control, |
michael@0 | 10509 | #if defined(__APPLE__) || defined(__Panda__) |
michael@0 | 10510 | flags |
michael@0 | 10511 | #else |
michael@0 | 10512 | flags, p |
michael@0 | 10513 | #endif |
michael@0 | 10514 | )); |
michael@0 | 10515 | } |
michael@0 | 10516 | |
michael@0 | 10517 | void |
michael@0 | 10518 | send_forward_tsn(struct sctp_tcb *stcb, |
michael@0 | 10519 | struct sctp_association *asoc) |
michael@0 | 10520 | { |
michael@0 | 10521 | struct sctp_tmit_chunk *chk; |
michael@0 | 10522 | struct sctp_forward_tsn_chunk *fwdtsn; |
michael@0 | 10523 | uint32_t advance_peer_ack_point; |
michael@0 | 10524 | |
michael@0 | 10525 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 10526 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 10527 | if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) { |
michael@0 | 10528 | /* mark it to unsent */ |
michael@0 | 10529 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 10530 | chk->snd_count = 0; |
michael@0 | 10531 | /* Do we correct its output location? */ |
michael@0 | 10532 | if (chk->whoTo) { |
michael@0 | 10533 | sctp_free_remote_addr(chk->whoTo); |
michael@0 | 10534 | chk->whoTo = NULL; |
michael@0 | 10535 | } |
michael@0 | 10536 | goto sctp_fill_in_rest; |
michael@0 | 10537 | } |
michael@0 | 10538 | } |
michael@0 | 10539 | /* Ok if we reach here we must build one */ |
michael@0 | 10540 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 10541 | if (chk == NULL) { |
michael@0 | 10542 | return; |
michael@0 | 10543 | } |
michael@0 | 10544 | asoc->fwd_tsn_cnt++; |
michael@0 | 10545 | chk->copy_by_ref = 0; |
michael@0 | 10546 | chk->rec.chunk_id.id = SCTP_FORWARD_CUM_TSN; |
michael@0 | 10547 | chk->rec.chunk_id.can_take_data = 0; |
michael@0 | 10548 | chk->asoc = asoc; |
michael@0 | 10549 | chk->whoTo = NULL; |
michael@0 | 10550 | chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 10551 | if (chk->data == NULL) { |
michael@0 | 10552 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 10553 | return; |
michael@0 | 10554 | } |
michael@0 | 10555 | SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); |
michael@0 | 10556 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 10557 | chk->snd_count = 0; |
michael@0 | 10558 | TAILQ_INSERT_TAIL(&asoc->control_send_queue, chk, sctp_next); |
michael@0 | 10559 | asoc->ctrl_queue_cnt++; |
michael@0 | 10560 | sctp_fill_in_rest: |
michael@0 | 10561 | /*- |
michael@0 | 10562 | * Here we go through and fill out the part that deals with |
michael@0 | 10563 | * stream/seq of the ones we skip. |
michael@0 | 10564 | */ |
michael@0 | 10565 | SCTP_BUF_LEN(chk->data) = 0; |
michael@0 | 10566 | { |
michael@0 | 10567 | struct sctp_tmit_chunk *at, *tp1, *last; |
michael@0 | 10568 | struct sctp_strseq *strseq; |
michael@0 | 10569 | unsigned int cnt_of_space, i, ovh; |
michael@0 | 10570 | unsigned int space_needed; |
michael@0 | 10571 | unsigned int cnt_of_skipped = 0; |
michael@0 | 10572 | |
michael@0 | 10573 | TAILQ_FOREACH(at, &asoc->sent_queue, sctp_next) { |
michael@0 | 10574 | if ((at->sent != SCTP_FORWARD_TSN_SKIP) && |
michael@0 | 10575 | (at->sent != SCTP_DATAGRAM_NR_ACKED)) { |
michael@0 | 10576 | /* no more to look at */ |
michael@0 | 10577 | break; |
michael@0 | 10578 | } |
michael@0 | 10579 | if (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED) { |
michael@0 | 10580 | /* We don't report these */ |
michael@0 | 10581 | continue; |
michael@0 | 10582 | } |
michael@0 | 10583 | cnt_of_skipped++; |
michael@0 | 10584 | } |
michael@0 | 10585 | space_needed = (sizeof(struct sctp_forward_tsn_chunk) + |
michael@0 | 10586 | (cnt_of_skipped * sizeof(struct sctp_strseq))); |
michael@0 | 10587 | |
michael@0 | 10588 | cnt_of_space = M_TRAILINGSPACE(chk->data); |
michael@0 | 10589 | |
michael@0 | 10590 | if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
michael@0 | 10591 | ovh = SCTP_MIN_OVERHEAD; |
michael@0 | 10592 | } else { |
michael@0 | 10593 | ovh = SCTP_MIN_V4_OVERHEAD; |
michael@0 | 10594 | } |
michael@0 | 10595 | if (cnt_of_space > (asoc->smallest_mtu - ovh)) { |
michael@0 | 10596 | /* trim to a mtu size */ |
michael@0 | 10597 | cnt_of_space = asoc->smallest_mtu - ovh; |
michael@0 | 10598 | } |
michael@0 | 10599 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { |
michael@0 | 10600 | sctp_misc_ints(SCTP_FWD_TSN_CHECK, |
michael@0 | 10601 | 0xff, 0, cnt_of_skipped, |
michael@0 | 10602 | asoc->advanced_peer_ack_point); |
michael@0 | 10603 | |
michael@0 | 10604 | } |
michael@0 | 10605 | advance_peer_ack_point = asoc->advanced_peer_ack_point; |
michael@0 | 10606 | if (cnt_of_space < space_needed) { |
michael@0 | 10607 | /*- |
michael@0 | 10608 | * ok we must trim down the chunk by lowering the |
michael@0 | 10609 | * advance peer ack point. |
michael@0 | 10610 | */ |
michael@0 | 10611 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { |
michael@0 | 10612 | sctp_misc_ints(SCTP_FWD_TSN_CHECK, |
michael@0 | 10613 | 0xff, 0xff, cnt_of_space, |
michael@0 | 10614 | space_needed); |
michael@0 | 10615 | } |
michael@0 | 10616 | cnt_of_skipped = cnt_of_space - sizeof(struct sctp_forward_tsn_chunk); |
michael@0 | 10617 | cnt_of_skipped /= sizeof(struct sctp_strseq); |
michael@0 | 10618 | /*- |
michael@0 | 10619 | * Go through and find the TSN that will be the one |
michael@0 | 10620 | * we report. |
michael@0 | 10621 | */ |
michael@0 | 10622 | at = TAILQ_FIRST(&asoc->sent_queue); |
michael@0 | 10623 | if (at != NULL) { |
michael@0 | 10624 | for (i = 0; i < cnt_of_skipped; i++) { |
michael@0 | 10625 | tp1 = TAILQ_NEXT(at, sctp_next); |
michael@0 | 10626 | if (tp1 == NULL) { |
michael@0 | 10627 | break; |
michael@0 | 10628 | } |
michael@0 | 10629 | at = tp1; |
michael@0 | 10630 | } |
michael@0 | 10631 | } |
michael@0 | 10632 | if (at && SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) { |
michael@0 | 10633 | sctp_misc_ints(SCTP_FWD_TSN_CHECK, |
michael@0 | 10634 | 0xff, cnt_of_skipped, at->rec.data.TSN_seq, |
michael@0 | 10635 | asoc->advanced_peer_ack_point); |
michael@0 | 10636 | } |
michael@0 | 10637 | last = at; |
michael@0 | 10638 | /*- |
michael@0 | 10639 | * last now points to last one I can report, update |
michael@0 | 10640 | * peer ack point |
michael@0 | 10641 | */ |
michael@0 | 10642 | if (last) |
michael@0 | 10643 | advance_peer_ack_point = last->rec.data.TSN_seq; |
michael@0 | 10644 | space_needed = sizeof(struct sctp_forward_tsn_chunk) + |
michael@0 | 10645 | cnt_of_skipped * sizeof(struct sctp_strseq); |
michael@0 | 10646 | } |
michael@0 | 10647 | chk->send_size = space_needed; |
michael@0 | 10648 | /* Setup the chunk */ |
michael@0 | 10649 | fwdtsn = mtod(chk->data, struct sctp_forward_tsn_chunk *); |
michael@0 | 10650 | fwdtsn->ch.chunk_length = htons(chk->send_size); |
michael@0 | 10651 | fwdtsn->ch.chunk_flags = 0; |
michael@0 | 10652 | fwdtsn->ch.chunk_type = SCTP_FORWARD_CUM_TSN; |
michael@0 | 10653 | fwdtsn->new_cumulative_tsn = htonl(advance_peer_ack_point); |
michael@0 | 10654 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 10655 | fwdtsn++; |
michael@0 | 10656 | /*- |
michael@0 | 10657 | * Move pointer to after the fwdtsn and transfer to the |
michael@0 | 10658 | * strseq pointer. |
michael@0 | 10659 | */ |
michael@0 | 10660 | strseq = (struct sctp_strseq *)fwdtsn; |
michael@0 | 10661 | /*- |
michael@0 | 10662 | * Now populate the strseq list. This is done blindly |
michael@0 | 10663 | * without pulling out duplicate stream info. This is |
michael@0 | 10664 | * inefficent but won't harm the process since the peer will |
michael@0 | 10665 | * look at these in sequence and will thus release anything. |
michael@0 | 10666 | * It could mean we exceed the PMTU and chop off some that |
michael@0 | 10667 | * we could have included.. but this is unlikely (aka 1432/4 |
michael@0 | 10668 | * would mean 300+ stream seq's would have to be reported in |
michael@0 | 10669 | * one FWD-TSN. With a bit of work we can later FIX this to |
michael@0 | 10670 | * optimize and pull out duplcates.. but it does add more |
michael@0 | 10671 | * overhead. So for now... not! |
michael@0 | 10672 | */ |
michael@0 | 10673 | at = TAILQ_FIRST(&asoc->sent_queue); |
michael@0 | 10674 | for (i = 0; i < cnt_of_skipped; i++) { |
michael@0 | 10675 | tp1 = TAILQ_NEXT(at, sctp_next); |
michael@0 | 10676 | if (tp1 == NULL) |
michael@0 | 10677 | break; |
michael@0 | 10678 | if (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED) { |
michael@0 | 10679 | /* We don't report these */ |
michael@0 | 10680 | i--; |
michael@0 | 10681 | at = tp1; |
michael@0 | 10682 | continue; |
michael@0 | 10683 | } |
michael@0 | 10684 | if (at->rec.data.TSN_seq == advance_peer_ack_point) { |
michael@0 | 10685 | at->rec.data.fwd_tsn_cnt = 0; |
michael@0 | 10686 | } |
michael@0 | 10687 | strseq->stream = ntohs(at->rec.data.stream_number); |
michael@0 | 10688 | strseq->sequence = ntohs(at->rec.data.stream_seq); |
michael@0 | 10689 | strseq++; |
michael@0 | 10690 | at = tp1; |
michael@0 | 10691 | } |
michael@0 | 10692 | } |
michael@0 | 10693 | return; |
michael@0 | 10694 | } |
michael@0 | 10695 | |
michael@0 | 10696 | void |
michael@0 | 10697 | sctp_send_sack(struct sctp_tcb *stcb, int so_locked |
michael@0 | 10698 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 10699 | SCTP_UNUSED |
michael@0 | 10700 | #endif |
michael@0 | 10701 | ) |
michael@0 | 10702 | { |
michael@0 | 10703 | /*- |
michael@0 | 10704 | * Queue up a SACK or NR-SACK in the control queue. |
michael@0 | 10705 | * We must first check to see if a SACK or NR-SACK is |
michael@0 | 10706 | * somehow on the control queue. |
michael@0 | 10707 | * If so, we will take and and remove the old one. |
michael@0 | 10708 | */ |
michael@0 | 10709 | struct sctp_association *asoc; |
michael@0 | 10710 | struct sctp_tmit_chunk *chk, *a_chk; |
michael@0 | 10711 | struct sctp_sack_chunk *sack; |
michael@0 | 10712 | struct sctp_nr_sack_chunk *nr_sack; |
michael@0 | 10713 | struct sctp_gap_ack_block *gap_descriptor; |
michael@0 | 10714 | struct sack_track *selector; |
michael@0 | 10715 | int mergeable = 0; |
michael@0 | 10716 | int offset; |
michael@0 | 10717 | caddr_t limit; |
michael@0 | 10718 | uint32_t *dup; |
michael@0 | 10719 | int limit_reached = 0; |
michael@0 | 10720 | unsigned int i, siz, j; |
michael@0 | 10721 | unsigned int num_gap_blocks = 0, num_nr_gap_blocks = 0, space; |
michael@0 | 10722 | int num_dups = 0; |
michael@0 | 10723 | int space_req; |
michael@0 | 10724 | uint32_t highest_tsn; |
michael@0 | 10725 | uint8_t flags; |
michael@0 | 10726 | uint8_t type; |
michael@0 | 10727 | uint8_t tsn_map; |
michael@0 | 10728 | |
michael@0 | 10729 | if ((stcb->asoc.sctp_nr_sack_on_off == 1) && |
michael@0 | 10730 | (stcb->asoc.peer_supports_nr_sack == 1)) { |
michael@0 | 10731 | type = SCTP_NR_SELECTIVE_ACK; |
michael@0 | 10732 | } else { |
michael@0 | 10733 | type = SCTP_SELECTIVE_ACK; |
michael@0 | 10734 | } |
michael@0 | 10735 | a_chk = NULL; |
michael@0 | 10736 | asoc = &stcb->asoc; |
michael@0 | 10737 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 10738 | if (asoc->last_data_chunk_from == NULL) { |
michael@0 | 10739 | /* Hmm we never received anything */ |
michael@0 | 10740 | return; |
michael@0 | 10741 | } |
michael@0 | 10742 | sctp_slide_mapping_arrays(stcb); |
michael@0 | 10743 | sctp_set_rwnd(stcb, asoc); |
michael@0 | 10744 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 10745 | if (chk->rec.chunk_id.id == type) { |
michael@0 | 10746 | /* Hmm, found a sack already on queue, remove it */ |
michael@0 | 10747 | TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next); |
michael@0 | 10748 | asoc->ctrl_queue_cnt--; |
michael@0 | 10749 | a_chk = chk; |
michael@0 | 10750 | if (a_chk->data) { |
michael@0 | 10751 | sctp_m_freem(a_chk->data); |
michael@0 | 10752 | a_chk->data = NULL; |
michael@0 | 10753 | } |
michael@0 | 10754 | if (a_chk->whoTo) { |
michael@0 | 10755 | sctp_free_remote_addr(a_chk->whoTo); |
michael@0 | 10756 | a_chk->whoTo = NULL; |
michael@0 | 10757 | } |
michael@0 | 10758 | break; |
michael@0 | 10759 | } |
michael@0 | 10760 | } |
michael@0 | 10761 | if (a_chk == NULL) { |
michael@0 | 10762 | sctp_alloc_a_chunk(stcb, a_chk); |
michael@0 | 10763 | if (a_chk == NULL) { |
michael@0 | 10764 | /* No memory so we drop the idea, and set a timer */ |
michael@0 | 10765 | if (stcb->asoc.delayed_ack) { |
michael@0 | 10766 | sctp_timer_stop(SCTP_TIMER_TYPE_RECV, |
michael@0 | 10767 | stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_OUTPUT + SCTP_LOC_5); |
michael@0 | 10768 | sctp_timer_start(SCTP_TIMER_TYPE_RECV, |
michael@0 | 10769 | stcb->sctp_ep, stcb, NULL); |
michael@0 | 10770 | } else { |
michael@0 | 10771 | stcb->asoc.send_sack = 1; |
michael@0 | 10772 | } |
michael@0 | 10773 | return; |
michael@0 | 10774 | } |
michael@0 | 10775 | a_chk->copy_by_ref = 0; |
michael@0 | 10776 | a_chk->rec.chunk_id.id = type; |
michael@0 | 10777 | a_chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 10778 | } |
michael@0 | 10779 | /* Clear our pkt counts */ |
michael@0 | 10780 | asoc->data_pkts_seen = 0; |
michael@0 | 10781 | |
michael@0 | 10782 | a_chk->asoc = asoc; |
michael@0 | 10783 | a_chk->snd_count = 0; |
michael@0 | 10784 | a_chk->send_size = 0; /* fill in later */ |
michael@0 | 10785 | a_chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 10786 | a_chk->whoTo = NULL; |
michael@0 | 10787 | |
michael@0 | 10788 | if ((asoc->numduptsns) || |
michael@0 | 10789 | (!(asoc->last_data_chunk_from->dest_state & SCTP_ADDR_REACHABLE))) { |
michael@0 | 10790 | /*- |
michael@0 | 10791 | * Ok, we have some duplicates or the destination for the |
michael@0 | 10792 | * sack is unreachable, lets see if we can select an |
michael@0 | 10793 | * alternate than asoc->last_data_chunk_from |
michael@0 | 10794 | */ |
michael@0 | 10795 | if ((asoc->last_data_chunk_from->dest_state & SCTP_ADDR_REACHABLE) && |
michael@0 | 10796 | (asoc->used_alt_onsack > asoc->numnets)) { |
michael@0 | 10797 | /* We used an alt last time, don't this time */ |
michael@0 | 10798 | a_chk->whoTo = NULL; |
michael@0 | 10799 | } else { |
michael@0 | 10800 | asoc->used_alt_onsack++; |
michael@0 | 10801 | a_chk->whoTo = sctp_find_alternate_net(stcb, asoc->last_data_chunk_from, 0); |
michael@0 | 10802 | } |
michael@0 | 10803 | if (a_chk->whoTo == NULL) { |
michael@0 | 10804 | /* Nope, no alternate */ |
michael@0 | 10805 | a_chk->whoTo = asoc->last_data_chunk_from; |
michael@0 | 10806 | asoc->used_alt_onsack = 0; |
michael@0 | 10807 | } |
michael@0 | 10808 | } else { |
michael@0 | 10809 | /* |
michael@0 | 10810 | * No duplicates so we use the last place we received data |
michael@0 | 10811 | * from. |
michael@0 | 10812 | */ |
michael@0 | 10813 | asoc->used_alt_onsack = 0; |
michael@0 | 10814 | a_chk->whoTo = asoc->last_data_chunk_from; |
michael@0 | 10815 | } |
michael@0 | 10816 | if (a_chk->whoTo) { |
michael@0 | 10817 | atomic_add_int(&a_chk->whoTo->ref_count, 1); |
michael@0 | 10818 | } |
michael@0 | 10819 | if (SCTP_TSN_GT(asoc->highest_tsn_inside_map, asoc->highest_tsn_inside_nr_map)) { |
michael@0 | 10820 | highest_tsn = asoc->highest_tsn_inside_map; |
michael@0 | 10821 | } else { |
michael@0 | 10822 | highest_tsn = asoc->highest_tsn_inside_nr_map; |
michael@0 | 10823 | } |
michael@0 | 10824 | if (highest_tsn == asoc->cumulative_tsn) { |
michael@0 | 10825 | /* no gaps */ |
michael@0 | 10826 | if (type == SCTP_SELECTIVE_ACK) { |
michael@0 | 10827 | space_req = sizeof(struct sctp_sack_chunk); |
michael@0 | 10828 | } else { |
michael@0 | 10829 | space_req = sizeof(struct sctp_nr_sack_chunk); |
michael@0 | 10830 | } |
michael@0 | 10831 | } else { |
michael@0 | 10832 | /* gaps get a cluster */ |
michael@0 | 10833 | space_req = MCLBYTES; |
michael@0 | 10834 | } |
michael@0 | 10835 | /* Ok now lets formulate a MBUF with our sack */ |
michael@0 | 10836 | a_chk->data = sctp_get_mbuf_for_msg(space_req, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 10837 | if ((a_chk->data == NULL) || |
michael@0 | 10838 | (a_chk->whoTo == NULL)) { |
michael@0 | 10839 | /* rats, no mbuf memory */ |
michael@0 | 10840 | if (a_chk->data) { |
michael@0 | 10841 | /* was a problem with the destination */ |
michael@0 | 10842 | sctp_m_freem(a_chk->data); |
michael@0 | 10843 | a_chk->data = NULL; |
michael@0 | 10844 | } |
michael@0 | 10845 | sctp_free_a_chunk(stcb, a_chk, so_locked); |
michael@0 | 10846 | /* sa_ignore NO_NULL_CHK */ |
michael@0 | 10847 | if (stcb->asoc.delayed_ack) { |
michael@0 | 10848 | sctp_timer_stop(SCTP_TIMER_TYPE_RECV, |
michael@0 | 10849 | stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_OUTPUT + SCTP_LOC_6); |
michael@0 | 10850 | sctp_timer_start(SCTP_TIMER_TYPE_RECV, |
michael@0 | 10851 | stcb->sctp_ep, stcb, NULL); |
michael@0 | 10852 | } else { |
michael@0 | 10853 | stcb->asoc.send_sack = 1; |
michael@0 | 10854 | } |
michael@0 | 10855 | return; |
michael@0 | 10856 | } |
michael@0 | 10857 | /* ok, lets go through and fill it in */ |
michael@0 | 10858 | SCTP_BUF_RESV_UF(a_chk->data, SCTP_MIN_OVERHEAD); |
michael@0 | 10859 | space = M_TRAILINGSPACE(a_chk->data); |
michael@0 | 10860 | if (space > (a_chk->whoTo->mtu - SCTP_MIN_OVERHEAD)) { |
michael@0 | 10861 | space = (a_chk->whoTo->mtu - SCTP_MIN_OVERHEAD); |
michael@0 | 10862 | } |
michael@0 | 10863 | limit = mtod(a_chk->data, caddr_t); |
michael@0 | 10864 | limit += space; |
michael@0 | 10865 | |
michael@0 | 10866 | flags = 0; |
michael@0 | 10867 | |
michael@0 | 10868 | if ((asoc->sctp_cmt_on_off > 0) && |
michael@0 | 10869 | SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) { |
michael@0 | 10870 | /*- |
michael@0 | 10871 | * CMT DAC algorithm: If 2 (i.e., 0x10) packets have been |
michael@0 | 10872 | * received, then set high bit to 1, else 0. Reset |
michael@0 | 10873 | * pkts_rcvd. |
michael@0 | 10874 | */ |
michael@0 | 10875 | flags |= (asoc->cmt_dac_pkts_rcvd << 6); |
michael@0 | 10876 | asoc->cmt_dac_pkts_rcvd = 0; |
michael@0 | 10877 | } |
michael@0 | 10878 | #ifdef SCTP_ASOCLOG_OF_TSNS |
michael@0 | 10879 | stcb->asoc.cumack_logsnt[stcb->asoc.cumack_log_atsnt] = asoc->cumulative_tsn; |
michael@0 | 10880 | stcb->asoc.cumack_log_atsnt++; |
michael@0 | 10881 | if (stcb->asoc.cumack_log_atsnt >= SCTP_TSN_LOG_SIZE) { |
michael@0 | 10882 | stcb->asoc.cumack_log_atsnt = 0; |
michael@0 | 10883 | } |
michael@0 | 10884 | #endif |
michael@0 | 10885 | /* reset the readers interpretation */ |
michael@0 | 10886 | stcb->freed_by_sorcv_sincelast = 0; |
michael@0 | 10887 | |
michael@0 | 10888 | if (type == SCTP_SELECTIVE_ACK) { |
michael@0 | 10889 | sack = mtod(a_chk->data, struct sctp_sack_chunk *); |
michael@0 | 10890 | nr_sack = NULL; |
michael@0 | 10891 | gap_descriptor = (struct sctp_gap_ack_block *)((caddr_t)sack + sizeof(struct sctp_sack_chunk)); |
michael@0 | 10892 | if (highest_tsn > asoc->mapping_array_base_tsn) { |
michael@0 | 10893 | siz = (((highest_tsn - asoc->mapping_array_base_tsn) + 1) + 7) / 8; |
michael@0 | 10894 | } else { |
michael@0 | 10895 | siz = (((MAX_TSN - highest_tsn) + 1) + highest_tsn + 7) / 8; |
michael@0 | 10896 | } |
michael@0 | 10897 | } else { |
michael@0 | 10898 | sack = NULL; |
michael@0 | 10899 | nr_sack = mtod(a_chk->data, struct sctp_nr_sack_chunk *); |
michael@0 | 10900 | gap_descriptor = (struct sctp_gap_ack_block *)((caddr_t)nr_sack + sizeof(struct sctp_nr_sack_chunk)); |
michael@0 | 10901 | if (asoc->highest_tsn_inside_map > asoc->mapping_array_base_tsn) { |
michael@0 | 10902 | siz = (((asoc->highest_tsn_inside_map - asoc->mapping_array_base_tsn) + 1) + 7) / 8; |
michael@0 | 10903 | } else { |
michael@0 | 10904 | siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_map + 7) / 8; |
michael@0 | 10905 | } |
michael@0 | 10906 | } |
michael@0 | 10907 | |
michael@0 | 10908 | if (SCTP_TSN_GT(asoc->mapping_array_base_tsn, asoc->cumulative_tsn)) { |
michael@0 | 10909 | offset = 1; |
michael@0 | 10910 | } else { |
michael@0 | 10911 | offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn; |
michael@0 | 10912 | } |
michael@0 | 10913 | if (((type == SCTP_SELECTIVE_ACK) && |
michael@0 | 10914 | SCTP_TSN_GT(highest_tsn, asoc->cumulative_tsn)) || |
michael@0 | 10915 | ((type == SCTP_NR_SELECTIVE_ACK) && |
michael@0 | 10916 | SCTP_TSN_GT(asoc->highest_tsn_inside_map, asoc->cumulative_tsn))) { |
michael@0 | 10917 | /* we have a gap .. maybe */ |
michael@0 | 10918 | for (i = 0; i < siz; i++) { |
michael@0 | 10919 | tsn_map = asoc->mapping_array[i]; |
michael@0 | 10920 | if (type == SCTP_SELECTIVE_ACK) { |
michael@0 | 10921 | tsn_map |= asoc->nr_mapping_array[i]; |
michael@0 | 10922 | } |
michael@0 | 10923 | if (i == 0) { |
michael@0 | 10924 | /* |
michael@0 | 10925 | * Clear all bits corresponding to TSNs |
michael@0 | 10926 | * smaller or equal to the cumulative TSN. |
michael@0 | 10927 | */ |
michael@0 | 10928 | tsn_map &= (~0 << (1 - offset)); |
michael@0 | 10929 | } |
michael@0 | 10930 | selector = &sack_array[tsn_map]; |
michael@0 | 10931 | if (mergeable && selector->right_edge) { |
michael@0 | 10932 | /* |
michael@0 | 10933 | * Backup, left and right edges were ok to |
michael@0 | 10934 | * merge. |
michael@0 | 10935 | */ |
michael@0 | 10936 | num_gap_blocks--; |
michael@0 | 10937 | gap_descriptor--; |
michael@0 | 10938 | } |
michael@0 | 10939 | if (selector->num_entries == 0) |
michael@0 | 10940 | mergeable = 0; |
michael@0 | 10941 | else { |
michael@0 | 10942 | for (j = 0; j < selector->num_entries; j++) { |
michael@0 | 10943 | if (mergeable && selector->right_edge) { |
michael@0 | 10944 | /* |
michael@0 | 10945 | * do a merge by NOT setting |
michael@0 | 10946 | * the left side |
michael@0 | 10947 | */ |
michael@0 | 10948 | mergeable = 0; |
michael@0 | 10949 | } else { |
michael@0 | 10950 | /* |
michael@0 | 10951 | * no merge, set the left |
michael@0 | 10952 | * side |
michael@0 | 10953 | */ |
michael@0 | 10954 | mergeable = 0; |
michael@0 | 10955 | gap_descriptor->start = htons((selector->gaps[j].start + offset)); |
michael@0 | 10956 | } |
michael@0 | 10957 | gap_descriptor->end = htons((selector->gaps[j].end + offset)); |
michael@0 | 10958 | num_gap_blocks++; |
michael@0 | 10959 | gap_descriptor++; |
michael@0 | 10960 | if (((caddr_t)gap_descriptor + sizeof(struct sctp_gap_ack_block)) > limit) { |
michael@0 | 10961 | /* no more room */ |
michael@0 | 10962 | limit_reached = 1; |
michael@0 | 10963 | break; |
michael@0 | 10964 | } |
michael@0 | 10965 | } |
michael@0 | 10966 | if (selector->left_edge) { |
michael@0 | 10967 | mergeable = 1; |
michael@0 | 10968 | } |
michael@0 | 10969 | } |
michael@0 | 10970 | if (limit_reached) { |
michael@0 | 10971 | /* Reached the limit stop */ |
michael@0 | 10972 | break; |
michael@0 | 10973 | } |
michael@0 | 10974 | offset += 8; |
michael@0 | 10975 | } |
michael@0 | 10976 | } |
michael@0 | 10977 | if ((type == SCTP_NR_SELECTIVE_ACK) && |
michael@0 | 10978 | (limit_reached == 0)) { |
michael@0 | 10979 | |
michael@0 | 10980 | mergeable = 0; |
michael@0 | 10981 | |
michael@0 | 10982 | if (asoc->highest_tsn_inside_nr_map > asoc->mapping_array_base_tsn) { |
michael@0 | 10983 | siz = (((asoc->highest_tsn_inside_nr_map - asoc->mapping_array_base_tsn) + 1) + 7) / 8; |
michael@0 | 10984 | } else { |
michael@0 | 10985 | siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_nr_map + 7) / 8; |
michael@0 | 10986 | } |
michael@0 | 10987 | |
michael@0 | 10988 | if (SCTP_TSN_GT(asoc->mapping_array_base_tsn, asoc->cumulative_tsn)) { |
michael@0 | 10989 | offset = 1; |
michael@0 | 10990 | } else { |
michael@0 | 10991 | offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn; |
michael@0 | 10992 | } |
michael@0 | 10993 | if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->cumulative_tsn)) { |
michael@0 | 10994 | /* we have a gap .. maybe */ |
michael@0 | 10995 | for (i = 0; i < siz; i++) { |
michael@0 | 10996 | tsn_map = asoc->nr_mapping_array[i]; |
michael@0 | 10997 | if (i == 0) { |
michael@0 | 10998 | /* |
michael@0 | 10999 | * Clear all bits corresponding to TSNs |
michael@0 | 11000 | * smaller or equal to the cumulative TSN. |
michael@0 | 11001 | */ |
michael@0 | 11002 | tsn_map &= (~0 << (1 - offset)); |
michael@0 | 11003 | } |
michael@0 | 11004 | selector = &sack_array[tsn_map]; |
michael@0 | 11005 | if (mergeable && selector->right_edge) { |
michael@0 | 11006 | /* |
michael@0 | 11007 | * Backup, left and right edges were ok to |
michael@0 | 11008 | * merge. |
michael@0 | 11009 | */ |
michael@0 | 11010 | num_nr_gap_blocks--; |
michael@0 | 11011 | gap_descriptor--; |
michael@0 | 11012 | } |
michael@0 | 11013 | if (selector->num_entries == 0) |
michael@0 | 11014 | mergeable = 0; |
michael@0 | 11015 | else { |
michael@0 | 11016 | for (j = 0; j < selector->num_entries; j++) { |
michael@0 | 11017 | if (mergeable && selector->right_edge) { |
michael@0 | 11018 | /* |
michael@0 | 11019 | * do a merge by NOT setting |
michael@0 | 11020 | * the left side |
michael@0 | 11021 | */ |
michael@0 | 11022 | mergeable = 0; |
michael@0 | 11023 | } else { |
michael@0 | 11024 | /* |
michael@0 | 11025 | * no merge, set the left |
michael@0 | 11026 | * side |
michael@0 | 11027 | */ |
michael@0 | 11028 | mergeable = 0; |
michael@0 | 11029 | gap_descriptor->start = htons((selector->gaps[j].start + offset)); |
michael@0 | 11030 | } |
michael@0 | 11031 | gap_descriptor->end = htons((selector->gaps[j].end + offset)); |
michael@0 | 11032 | num_nr_gap_blocks++; |
michael@0 | 11033 | gap_descriptor++; |
michael@0 | 11034 | if (((caddr_t)gap_descriptor + sizeof(struct sctp_gap_ack_block)) > limit) { |
michael@0 | 11035 | /* no more room */ |
michael@0 | 11036 | limit_reached = 1; |
michael@0 | 11037 | break; |
michael@0 | 11038 | } |
michael@0 | 11039 | } |
michael@0 | 11040 | if (selector->left_edge) { |
michael@0 | 11041 | mergeable = 1; |
michael@0 | 11042 | } |
michael@0 | 11043 | } |
michael@0 | 11044 | if (limit_reached) { |
michael@0 | 11045 | /* Reached the limit stop */ |
michael@0 | 11046 | break; |
michael@0 | 11047 | } |
michael@0 | 11048 | offset += 8; |
michael@0 | 11049 | } |
michael@0 | 11050 | } |
michael@0 | 11051 | } |
michael@0 | 11052 | /* now we must add any dups we are going to report. */ |
michael@0 | 11053 | if ((limit_reached == 0) && (asoc->numduptsns)) { |
michael@0 | 11054 | dup = (uint32_t *) gap_descriptor; |
michael@0 | 11055 | for (i = 0; i < asoc->numduptsns; i++) { |
michael@0 | 11056 | *dup = htonl(asoc->dup_tsns[i]); |
michael@0 | 11057 | dup++; |
michael@0 | 11058 | num_dups++; |
michael@0 | 11059 | if (((caddr_t)dup + sizeof(uint32_t)) > limit) { |
michael@0 | 11060 | /* no more room */ |
michael@0 | 11061 | break; |
michael@0 | 11062 | } |
michael@0 | 11063 | } |
michael@0 | 11064 | asoc->numduptsns = 0; |
michael@0 | 11065 | } |
michael@0 | 11066 | /* |
michael@0 | 11067 | * now that the chunk is prepared queue it to the control chunk |
michael@0 | 11068 | * queue. |
michael@0 | 11069 | */ |
michael@0 | 11070 | if (type == SCTP_SELECTIVE_ACK) { |
michael@0 | 11071 | a_chk->send_size = sizeof(struct sctp_sack_chunk) + |
michael@0 | 11072 | (num_gap_blocks + num_nr_gap_blocks) * sizeof(struct sctp_gap_ack_block) + |
michael@0 | 11073 | num_dups * sizeof(int32_t); |
michael@0 | 11074 | SCTP_BUF_LEN(a_chk->data) = a_chk->send_size; |
michael@0 | 11075 | sack->sack.cum_tsn_ack = htonl(asoc->cumulative_tsn); |
michael@0 | 11076 | sack->sack.a_rwnd = htonl(asoc->my_rwnd); |
michael@0 | 11077 | sack->sack.num_gap_ack_blks = htons(num_gap_blocks); |
michael@0 | 11078 | sack->sack.num_dup_tsns = htons(num_dups); |
michael@0 | 11079 | sack->ch.chunk_type = type; |
michael@0 | 11080 | sack->ch.chunk_flags = flags; |
michael@0 | 11081 | sack->ch.chunk_length = htons(a_chk->send_size); |
michael@0 | 11082 | } else { |
michael@0 | 11083 | a_chk->send_size = sizeof(struct sctp_nr_sack_chunk) + |
michael@0 | 11084 | (num_gap_blocks + num_nr_gap_blocks) * sizeof(struct sctp_gap_ack_block) + |
michael@0 | 11085 | num_dups * sizeof(int32_t); |
michael@0 | 11086 | SCTP_BUF_LEN(a_chk->data) = a_chk->send_size; |
michael@0 | 11087 | nr_sack->nr_sack.cum_tsn_ack = htonl(asoc->cumulative_tsn); |
michael@0 | 11088 | nr_sack->nr_sack.a_rwnd = htonl(asoc->my_rwnd); |
michael@0 | 11089 | nr_sack->nr_sack.num_gap_ack_blks = htons(num_gap_blocks); |
michael@0 | 11090 | nr_sack->nr_sack.num_nr_gap_ack_blks = htons(num_nr_gap_blocks); |
michael@0 | 11091 | nr_sack->nr_sack.num_dup_tsns = htons(num_dups); |
michael@0 | 11092 | nr_sack->nr_sack.reserved = 0; |
michael@0 | 11093 | nr_sack->ch.chunk_type = type; |
michael@0 | 11094 | nr_sack->ch.chunk_flags = flags; |
michael@0 | 11095 | nr_sack->ch.chunk_length = htons(a_chk->send_size); |
michael@0 | 11096 | } |
michael@0 | 11097 | TAILQ_INSERT_TAIL(&asoc->control_send_queue, a_chk, sctp_next); |
michael@0 | 11098 | asoc->my_last_reported_rwnd = asoc->my_rwnd; |
michael@0 | 11099 | asoc->ctrl_queue_cnt++; |
michael@0 | 11100 | asoc->send_sack = 0; |
michael@0 | 11101 | SCTP_STAT_INCR(sctps_sendsacks); |
michael@0 | 11102 | return; |
michael@0 | 11103 | } |
michael@0 | 11104 | |
michael@0 | 11105 | void |
michael@0 | 11106 | sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr, int so_locked |
michael@0 | 11107 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 11108 | SCTP_UNUSED |
michael@0 | 11109 | #endif |
michael@0 | 11110 | ) |
michael@0 | 11111 | { |
michael@0 | 11112 | struct mbuf *m_abort, *m, *m_last; |
michael@0 | 11113 | struct mbuf *m_out, *m_end = NULL; |
michael@0 | 11114 | struct sctp_abort_chunk *abort; |
michael@0 | 11115 | struct sctp_auth_chunk *auth = NULL; |
michael@0 | 11116 | struct sctp_nets *net; |
michael@0 | 11117 | uint32_t vtag; |
michael@0 | 11118 | uint32_t auth_offset = 0; |
michael@0 | 11119 | uint16_t cause_len, chunk_len, padding_len; |
michael@0 | 11120 | |
michael@0 | 11121 | #if defined(__APPLE__) |
michael@0 | 11122 | if (so_locked) { |
michael@0 | 11123 | sctp_lock_assert(SCTP_INP_SO(stcb->sctp_ep)); |
michael@0 | 11124 | } else { |
michael@0 | 11125 | sctp_unlock_assert(SCTP_INP_SO(stcb->sctp_ep)); |
michael@0 | 11126 | } |
michael@0 | 11127 | #endif |
michael@0 | 11128 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 11129 | /*- |
michael@0 | 11130 | * Add an AUTH chunk, if chunk requires it and save the offset into |
michael@0 | 11131 | * the chain for AUTH |
michael@0 | 11132 | */ |
michael@0 | 11133 | if (sctp_auth_is_required_chunk(SCTP_ABORT_ASSOCIATION, |
michael@0 | 11134 | stcb->asoc.peer_auth_chunks)) { |
michael@0 | 11135 | m_out = sctp_add_auth_chunk(NULL, &m_end, &auth, &auth_offset, |
michael@0 | 11136 | stcb, SCTP_ABORT_ASSOCIATION); |
michael@0 | 11137 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 11138 | } else { |
michael@0 | 11139 | m_out = NULL; |
michael@0 | 11140 | } |
michael@0 | 11141 | m_abort = sctp_get_mbuf_for_msg(sizeof(struct sctp_abort_chunk), 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 11142 | if (m_abort == NULL) { |
michael@0 | 11143 | if (m_out) { |
michael@0 | 11144 | sctp_m_freem(m_out); |
michael@0 | 11145 | } |
michael@0 | 11146 | if (operr) { |
michael@0 | 11147 | sctp_m_freem(operr); |
michael@0 | 11148 | } |
michael@0 | 11149 | return; |
michael@0 | 11150 | } |
michael@0 | 11151 | /* link in any error */ |
michael@0 | 11152 | SCTP_BUF_NEXT(m_abort) = operr; |
michael@0 | 11153 | cause_len = 0; |
michael@0 | 11154 | m_last = NULL; |
michael@0 | 11155 | for (m = operr; m; m = SCTP_BUF_NEXT(m)) { |
michael@0 | 11156 | cause_len += (uint16_t)SCTP_BUF_LEN(m); |
michael@0 | 11157 | if (SCTP_BUF_NEXT(m) == NULL) { |
michael@0 | 11158 | m_last = m; |
michael@0 | 11159 | } |
michael@0 | 11160 | } |
michael@0 | 11161 | SCTP_BUF_LEN(m_abort) = sizeof(struct sctp_abort_chunk); |
michael@0 | 11162 | chunk_len = (uint16_t)sizeof(struct sctp_abort_chunk) + cause_len; |
michael@0 | 11163 | padding_len = SCTP_SIZE32(chunk_len) - chunk_len; |
michael@0 | 11164 | if (m_out == NULL) { |
michael@0 | 11165 | /* NO Auth chunk prepended, so reserve space in front */ |
michael@0 | 11166 | SCTP_BUF_RESV_UF(m_abort, SCTP_MIN_OVERHEAD); |
michael@0 | 11167 | m_out = m_abort; |
michael@0 | 11168 | } else { |
michael@0 | 11169 | /* Put AUTH chunk at the front of the chain */ |
michael@0 | 11170 | SCTP_BUF_NEXT(m_end) = m_abort; |
michael@0 | 11171 | } |
michael@0 | 11172 | if (stcb->asoc.alternate) { |
michael@0 | 11173 | net = stcb->asoc.alternate; |
michael@0 | 11174 | } else { |
michael@0 | 11175 | net = stcb->asoc.primary_destination; |
michael@0 | 11176 | } |
michael@0 | 11177 | /* Fill in the ABORT chunk header. */ |
michael@0 | 11178 | abort = mtod(m_abort, struct sctp_abort_chunk *); |
michael@0 | 11179 | abort->ch.chunk_type = SCTP_ABORT_ASSOCIATION; |
michael@0 | 11180 | if (stcb->asoc.peer_vtag == 0) { |
michael@0 | 11181 | /* This happens iff the assoc is in COOKIE-WAIT state. */ |
michael@0 | 11182 | vtag = stcb->asoc.my_vtag; |
michael@0 | 11183 | abort->ch.chunk_flags = SCTP_HAD_NO_TCB; |
michael@0 | 11184 | } else { |
michael@0 | 11185 | vtag = stcb->asoc.peer_vtag; |
michael@0 | 11186 | abort->ch.chunk_flags = 0; |
michael@0 | 11187 | } |
michael@0 | 11188 | abort->ch.chunk_length = htons(chunk_len); |
michael@0 | 11189 | /* Add padding, if necessary. */ |
michael@0 | 11190 | if (padding_len > 0) { |
michael@0 | 11191 | if ((m_last == NULL) || sctp_add_pad_tombuf(m_last, padding_len)) { |
michael@0 | 11192 | sctp_m_freem(m_out); |
michael@0 | 11193 | return; |
michael@0 | 11194 | } |
michael@0 | 11195 | } |
michael@0 | 11196 | (void)sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, |
michael@0 | 11197 | (struct sockaddr *)&net->ro._l_addr, |
michael@0 | 11198 | m_out, auth_offset, auth, stcb->asoc.authinfo.active_keyid, 1, 0, 0, |
michael@0 | 11199 | stcb->sctp_ep->sctp_lport, stcb->rport, htonl(vtag), |
michael@0 | 11200 | stcb->asoc.primary_destination->port, NULL, |
michael@0 | 11201 | #if defined(__FreeBSD__) |
michael@0 | 11202 | 0, 0, |
michael@0 | 11203 | #endif |
michael@0 | 11204 | so_locked); |
michael@0 | 11205 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 11206 | } |
michael@0 | 11207 | |
michael@0 | 11208 | void |
michael@0 | 11209 | sctp_send_shutdown_complete(struct sctp_tcb *stcb, |
michael@0 | 11210 | struct sctp_nets *net, |
michael@0 | 11211 | int reflect_vtag) |
michael@0 | 11212 | { |
michael@0 | 11213 | /* formulate and SEND a SHUTDOWN-COMPLETE */ |
michael@0 | 11214 | struct mbuf *m_shutdown_comp; |
michael@0 | 11215 | struct sctp_shutdown_complete_chunk *shutdown_complete; |
michael@0 | 11216 | uint32_t vtag; |
michael@0 | 11217 | uint8_t flags; |
michael@0 | 11218 | |
michael@0 | 11219 | m_shutdown_comp = sctp_get_mbuf_for_msg(sizeof(struct sctp_chunkhdr), 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 11220 | if (m_shutdown_comp == NULL) { |
michael@0 | 11221 | /* no mbuf's */ |
michael@0 | 11222 | return; |
michael@0 | 11223 | } |
michael@0 | 11224 | if (reflect_vtag) { |
michael@0 | 11225 | flags = SCTP_HAD_NO_TCB; |
michael@0 | 11226 | vtag = stcb->asoc.my_vtag; |
michael@0 | 11227 | } else { |
michael@0 | 11228 | flags = 0; |
michael@0 | 11229 | vtag = stcb->asoc.peer_vtag; |
michael@0 | 11230 | } |
michael@0 | 11231 | shutdown_complete = mtod(m_shutdown_comp, struct sctp_shutdown_complete_chunk *); |
michael@0 | 11232 | shutdown_complete->ch.chunk_type = SCTP_SHUTDOWN_COMPLETE; |
michael@0 | 11233 | shutdown_complete->ch.chunk_flags = flags; |
michael@0 | 11234 | shutdown_complete->ch.chunk_length = htons(sizeof(struct sctp_shutdown_complete_chunk)); |
michael@0 | 11235 | SCTP_BUF_LEN(m_shutdown_comp) = sizeof(struct sctp_shutdown_complete_chunk); |
michael@0 | 11236 | (void)sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, |
michael@0 | 11237 | (struct sockaddr *)&net->ro._l_addr, |
michael@0 | 11238 | m_shutdown_comp, 0, NULL, 0, 1, 0, 0, |
michael@0 | 11239 | stcb->sctp_ep->sctp_lport, stcb->rport, |
michael@0 | 11240 | htonl(vtag), |
michael@0 | 11241 | net->port, NULL, |
michael@0 | 11242 | #if defined(__FreeBSD__) |
michael@0 | 11243 | 0, 0, |
michael@0 | 11244 | #endif |
michael@0 | 11245 | SCTP_SO_NOT_LOCKED); |
michael@0 | 11246 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 11247 | return; |
michael@0 | 11248 | } |
michael@0 | 11249 | |
michael@0 | 11250 | #if defined(__FreeBSD__) |
michael@0 | 11251 | static void |
michael@0 | 11252 | sctp_send_resp_msg(struct sockaddr *src, struct sockaddr *dst, |
michael@0 | 11253 | struct sctphdr *sh, uint32_t vtag, |
michael@0 | 11254 | uint8_t type, struct mbuf *cause, |
michael@0 | 11255 | uint8_t use_mflowid, uint32_t mflowid, |
michael@0 | 11256 | uint32_t vrf_id, uint16_t port) |
michael@0 | 11257 | #else |
michael@0 | 11258 | static void |
michael@0 | 11259 | sctp_send_resp_msg(struct sockaddr *src, struct sockaddr *dst, |
michael@0 | 11260 | struct sctphdr *sh, uint32_t vtag, |
michael@0 | 11261 | uint8_t type, struct mbuf *cause, |
michael@0 | 11262 | uint32_t vrf_id SCTP_UNUSED, uint16_t port) |
michael@0 | 11263 | #endif |
michael@0 | 11264 | { |
michael@0 | 11265 | #ifdef __Panda__ |
michael@0 | 11266 | pakhandle_type o_pak; |
michael@0 | 11267 | #else |
michael@0 | 11268 | struct mbuf *o_pak; |
michael@0 | 11269 | #endif |
michael@0 | 11270 | struct mbuf *mout; |
michael@0 | 11271 | struct sctphdr *shout; |
michael@0 | 11272 | struct sctp_chunkhdr *ch; |
michael@0 | 11273 | struct udphdr *udp; |
michael@0 | 11274 | int len, cause_len, padding_len; |
michael@0 | 11275 | #if defined(INET) || defined(INET6) |
michael@0 | 11276 | int ret; |
michael@0 | 11277 | #endif |
michael@0 | 11278 | #ifdef INET |
michael@0 | 11279 | #if defined(__APPLE__) || defined(__Panda__) |
michael@0 | 11280 | sctp_route_t ro; |
michael@0 | 11281 | #endif |
michael@0 | 11282 | struct sockaddr_in *src_sin, *dst_sin; |
michael@0 | 11283 | struct ip *ip; |
michael@0 | 11284 | #endif |
michael@0 | 11285 | #ifdef INET6 |
michael@0 | 11286 | struct sockaddr_in6 *src_sin6, *dst_sin6; |
michael@0 | 11287 | struct ip6_hdr *ip6; |
michael@0 | 11288 | #endif |
michael@0 | 11289 | |
michael@0 | 11290 | /* Compute the length of the cause and add final padding. */ |
michael@0 | 11291 | cause_len = 0; |
michael@0 | 11292 | if (cause != NULL) { |
michael@0 | 11293 | struct mbuf *m_at, *m_last = NULL; |
michael@0 | 11294 | |
michael@0 | 11295 | for (m_at = cause; m_at; m_at = SCTP_BUF_NEXT(m_at)) { |
michael@0 | 11296 | if (SCTP_BUF_NEXT(m_at) == NULL) |
michael@0 | 11297 | m_last = m_at; |
michael@0 | 11298 | cause_len += SCTP_BUF_LEN(m_at); |
michael@0 | 11299 | } |
michael@0 | 11300 | padding_len = cause_len % 4; |
michael@0 | 11301 | if (padding_len != 0) { |
michael@0 | 11302 | padding_len = 4 - padding_len; |
michael@0 | 11303 | } |
michael@0 | 11304 | if (padding_len != 0) { |
michael@0 | 11305 | if (sctp_add_pad_tombuf(m_last, padding_len)) { |
michael@0 | 11306 | sctp_m_freem(cause); |
michael@0 | 11307 | return; |
michael@0 | 11308 | } |
michael@0 | 11309 | } |
michael@0 | 11310 | } else { |
michael@0 | 11311 | padding_len = 0; |
michael@0 | 11312 | } |
michael@0 | 11313 | /* Get an mbuf for the header. */ |
michael@0 | 11314 | len = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
michael@0 | 11315 | switch (dst->sa_family) { |
michael@0 | 11316 | #ifdef INET |
michael@0 | 11317 | case AF_INET: |
michael@0 | 11318 | len += sizeof(struct ip); |
michael@0 | 11319 | break; |
michael@0 | 11320 | #endif |
michael@0 | 11321 | #ifdef INET6 |
michael@0 | 11322 | case AF_INET6: |
michael@0 | 11323 | len += sizeof(struct ip6_hdr); |
michael@0 | 11324 | break; |
michael@0 | 11325 | #endif |
michael@0 | 11326 | default: |
michael@0 | 11327 | break; |
michael@0 | 11328 | } |
michael@0 | 11329 | if (port) { |
michael@0 | 11330 | len += sizeof(struct udphdr); |
michael@0 | 11331 | } |
michael@0 | 11332 | #if defined(__APPLE__) |
michael@0 | 11333 | #if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) |
michael@0 | 11334 | mout = sctp_get_mbuf_for_msg(len + max_linkhdr, 1, M_NOWAIT, 1, MT_DATA); |
michael@0 | 11335 | #else |
michael@0 | 11336 | mout = sctp_get_mbuf_for_msg(len + SCTP_MAX_LINKHDR, 1, M_NOWAIT, 1, MT_DATA); |
michael@0 | 11337 | #endif |
michael@0 | 11338 | #else |
michael@0 | 11339 | mout = sctp_get_mbuf_for_msg(len + max_linkhdr, 1, M_NOWAIT, 1, MT_DATA); |
michael@0 | 11340 | #endif |
michael@0 | 11341 | if (mout == NULL) { |
michael@0 | 11342 | if (cause) { |
michael@0 | 11343 | sctp_m_freem(cause); |
michael@0 | 11344 | } |
michael@0 | 11345 | return; |
michael@0 | 11346 | } |
michael@0 | 11347 | #if defined(__APPLE__) |
michael@0 | 11348 | #if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) |
michael@0 | 11349 | SCTP_BUF_RESV_UF(mout, max_linkhdr); |
michael@0 | 11350 | #else |
michael@0 | 11351 | SCTP_BUF_RESV_UF(mout, SCTP_MAX_LINKHDR); |
michael@0 | 11352 | #endif |
michael@0 | 11353 | #else |
michael@0 | 11354 | SCTP_BUF_RESV_UF(mout, max_linkhdr); |
michael@0 | 11355 | #endif |
michael@0 | 11356 | SCTP_BUF_LEN(mout) = len; |
michael@0 | 11357 | SCTP_BUF_NEXT(mout) = cause; |
michael@0 | 11358 | #if defined(__FreeBSD__) |
michael@0 | 11359 | if (use_mflowid != 0) { |
michael@0 | 11360 | mout->m_pkthdr.flowid = mflowid; |
michael@0 | 11361 | mout->m_flags |= M_FLOWID; |
michael@0 | 11362 | } |
michael@0 | 11363 | #endif |
michael@0 | 11364 | #ifdef INET |
michael@0 | 11365 | ip = NULL; |
michael@0 | 11366 | #endif |
michael@0 | 11367 | #ifdef INET6 |
michael@0 | 11368 | ip6 = NULL; |
michael@0 | 11369 | #endif |
michael@0 | 11370 | switch (dst->sa_family) { |
michael@0 | 11371 | #ifdef INET |
michael@0 | 11372 | case AF_INET: |
michael@0 | 11373 | src_sin = (struct sockaddr_in *)src; |
michael@0 | 11374 | dst_sin = (struct sockaddr_in *)dst; |
michael@0 | 11375 | ip = mtod(mout, struct ip *); |
michael@0 | 11376 | ip->ip_v = IPVERSION; |
michael@0 | 11377 | ip->ip_hl = (sizeof(struct ip) >> 2); |
michael@0 | 11378 | ip->ip_tos = 0; |
michael@0 | 11379 | #if defined(__FreeBSD__) |
michael@0 | 11380 | ip->ip_id = ip_newid(); |
michael@0 | 11381 | #elif defined(__APPLE__) |
michael@0 | 11382 | #if RANDOM_IP_ID |
michael@0 | 11383 | ip->ip_id = ip_randomid(); |
michael@0 | 11384 | #else |
michael@0 | 11385 | ip->ip_id = htons(ip_id++); |
michael@0 | 11386 | #endif |
michael@0 | 11387 | #else |
michael@0 | 11388 | ip->ip_id = htons(ip_id++); |
michael@0 | 11389 | #endif |
michael@0 | 11390 | ip->ip_off = 0; |
michael@0 | 11391 | ip->ip_ttl = MODULE_GLOBAL(ip_defttl); |
michael@0 | 11392 | if (port) { |
michael@0 | 11393 | ip->ip_p = IPPROTO_UDP; |
michael@0 | 11394 | } else { |
michael@0 | 11395 | ip->ip_p = IPPROTO_SCTP; |
michael@0 | 11396 | } |
michael@0 | 11397 | ip->ip_src.s_addr = dst_sin->sin_addr.s_addr; |
michael@0 | 11398 | ip->ip_dst.s_addr = src_sin->sin_addr.s_addr; |
michael@0 | 11399 | ip->ip_sum = 0; |
michael@0 | 11400 | len = sizeof(struct ip); |
michael@0 | 11401 | shout = (struct sctphdr *)((caddr_t)ip + len); |
michael@0 | 11402 | break; |
michael@0 | 11403 | #endif |
michael@0 | 11404 | #ifdef INET6 |
michael@0 | 11405 | case AF_INET6: |
michael@0 | 11406 | src_sin6 = (struct sockaddr_in6 *)src; |
michael@0 | 11407 | dst_sin6 = (struct sockaddr_in6 *)dst; |
michael@0 | 11408 | ip6 = mtod(mout, struct ip6_hdr *); |
michael@0 | 11409 | ip6->ip6_flow = htonl(0x60000000); |
michael@0 | 11410 | #if defined(__FreeBSD__) |
michael@0 | 11411 | if (V_ip6_auto_flowlabel) { |
michael@0 | 11412 | ip6->ip6_flow |= (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK); |
michael@0 | 11413 | } |
michael@0 | 11414 | #endif |
michael@0 | 11415 | #if defined(__Userspace__) |
michael@0 | 11416 | ip6->ip6_hlim = IPv6_HOP_LIMIT; |
michael@0 | 11417 | #else |
michael@0 | 11418 | ip6->ip6_hlim = MODULE_GLOBAL(ip6_defhlim); |
michael@0 | 11419 | #endif |
michael@0 | 11420 | if (port) { |
michael@0 | 11421 | ip6->ip6_nxt = IPPROTO_UDP; |
michael@0 | 11422 | } else { |
michael@0 | 11423 | ip6->ip6_nxt = IPPROTO_SCTP; |
michael@0 | 11424 | } |
michael@0 | 11425 | ip6->ip6_src = dst_sin6->sin6_addr; |
michael@0 | 11426 | ip6->ip6_dst = src_sin6->sin6_addr; |
michael@0 | 11427 | len = sizeof(struct ip6_hdr); |
michael@0 | 11428 | shout = (struct sctphdr *)((caddr_t)ip6 + len); |
michael@0 | 11429 | break; |
michael@0 | 11430 | #endif |
michael@0 | 11431 | default: |
michael@0 | 11432 | len = 0; |
michael@0 | 11433 | shout = mtod(mout, struct sctphdr *); |
michael@0 | 11434 | break; |
michael@0 | 11435 | } |
michael@0 | 11436 | if (port) { |
michael@0 | 11437 | if (htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)) == 0) { |
michael@0 | 11438 | sctp_m_freem(mout); |
michael@0 | 11439 | return; |
michael@0 | 11440 | } |
michael@0 | 11441 | udp = (struct udphdr *)shout; |
michael@0 | 11442 | udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); |
michael@0 | 11443 | udp->uh_dport = port; |
michael@0 | 11444 | udp->uh_sum = 0; |
michael@0 | 11445 | udp->uh_ulen = htons(sizeof(struct udphdr) + |
michael@0 | 11446 | sizeof(struct sctphdr) + |
michael@0 | 11447 | sizeof(struct sctp_chunkhdr) + |
michael@0 | 11448 | cause_len + padding_len); |
michael@0 | 11449 | len += sizeof(struct udphdr); |
michael@0 | 11450 | shout = (struct sctphdr *)((caddr_t)shout + sizeof(struct udphdr)); |
michael@0 | 11451 | } else { |
michael@0 | 11452 | udp = NULL; |
michael@0 | 11453 | } |
michael@0 | 11454 | shout->src_port = sh->dest_port; |
michael@0 | 11455 | shout->dest_port = sh->src_port; |
michael@0 | 11456 | shout->checksum = 0; |
michael@0 | 11457 | if (vtag) { |
michael@0 | 11458 | shout->v_tag = htonl(vtag); |
michael@0 | 11459 | } else { |
michael@0 | 11460 | shout->v_tag = sh->v_tag; |
michael@0 | 11461 | } |
michael@0 | 11462 | len += sizeof(struct sctphdr); |
michael@0 | 11463 | ch = (struct sctp_chunkhdr *)((caddr_t)shout + sizeof(struct sctphdr)); |
michael@0 | 11464 | ch->chunk_type = type; |
michael@0 | 11465 | if (vtag) { |
michael@0 | 11466 | ch->chunk_flags = 0; |
michael@0 | 11467 | } else { |
michael@0 | 11468 | ch->chunk_flags = SCTP_HAD_NO_TCB; |
michael@0 | 11469 | } |
michael@0 | 11470 | ch->chunk_length = htons(sizeof(struct sctp_chunkhdr) + cause_len); |
michael@0 | 11471 | len += sizeof(struct sctp_chunkhdr); |
michael@0 | 11472 | len += cause_len + padding_len; |
michael@0 | 11473 | |
michael@0 | 11474 | if (SCTP_GET_HEADER_FOR_OUTPUT(o_pak)) { |
michael@0 | 11475 | sctp_m_freem(mout); |
michael@0 | 11476 | return; |
michael@0 | 11477 | } |
michael@0 | 11478 | SCTP_ATTACH_CHAIN(o_pak, mout, len); |
michael@0 | 11479 | switch (dst->sa_family) { |
michael@0 | 11480 | #ifdef INET |
michael@0 | 11481 | case AF_INET: |
michael@0 | 11482 | #if defined(__APPLE__) || defined(__Panda__) |
michael@0 | 11483 | /* zap the stack pointer to the route */ |
michael@0 | 11484 | bzero(&ro, sizeof(sctp_route_t)); |
michael@0 | 11485 | #if defined(__Panda__) |
michael@0 | 11486 | ro._l_addr.sa.sa_family = AF_INET; |
michael@0 | 11487 | #endif |
michael@0 | 11488 | #endif |
michael@0 | 11489 | if (port) { |
michael@0 | 11490 | #if !defined(__Windows__) && !defined(__Userspace__) |
michael@0 | 11491 | #if defined(__FreeBSD__) && ((__FreeBSD_version > 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000) |
michael@0 | 11492 | if (V_udp_cksum) { |
michael@0 | 11493 | udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP)); |
michael@0 | 11494 | } else { |
michael@0 | 11495 | udp->uh_sum = 0; |
michael@0 | 11496 | } |
michael@0 | 11497 | #else |
michael@0 | 11498 | udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP)); |
michael@0 | 11499 | #endif |
michael@0 | 11500 | #else |
michael@0 | 11501 | udp->uh_sum = 0; |
michael@0 | 11502 | #endif |
michael@0 | 11503 | } |
michael@0 | 11504 | #if defined(__FreeBSD__) |
michael@0 | 11505 | #if __FreeBSD_version >= 1000000 |
michael@0 | 11506 | ip->ip_len = htons(len); |
michael@0 | 11507 | #else |
michael@0 | 11508 | ip->ip_len = len; |
michael@0 | 11509 | #endif |
michael@0 | 11510 | #elif defined(__APPLE__) || defined(__Userspace__) |
michael@0 | 11511 | ip->ip_len = len; |
michael@0 | 11512 | #else |
michael@0 | 11513 | ip->ip_len = htons(len); |
michael@0 | 11514 | #endif |
michael@0 | 11515 | if (port) { |
michael@0 | 11516 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 11517 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 11518 | #else |
michael@0 | 11519 | shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip) + sizeof(struct udphdr)); |
michael@0 | 11520 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 11521 | #endif |
michael@0 | 11522 | #if defined(__FreeBSD__) && ((__FreeBSD_version > 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000) |
michael@0 | 11523 | if (V_udp_cksum) { |
michael@0 | 11524 | SCTP_ENABLE_UDP_CSUM(o_pak); |
michael@0 | 11525 | } |
michael@0 | 11526 | #else |
michael@0 | 11527 | SCTP_ENABLE_UDP_CSUM(o_pak); |
michael@0 | 11528 | #endif |
michael@0 | 11529 | } else { |
michael@0 | 11530 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 11531 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 11532 | #else |
michael@0 | 11533 | #if defined(__FreeBSD__) && __FreeBSD_version >= 800000 |
michael@0 | 11534 | mout->m_pkthdr.csum_flags = CSUM_SCTP; |
michael@0 | 11535 | mout->m_pkthdr.csum_data = 0; |
michael@0 | 11536 | SCTP_STAT_INCR(sctps_sendhwcrc); |
michael@0 | 11537 | #else |
michael@0 | 11538 | shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip)); |
michael@0 | 11539 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 11540 | #endif |
michael@0 | 11541 | #endif |
michael@0 | 11542 | } |
michael@0 | 11543 | #ifdef SCTP_PACKET_LOGGING |
michael@0 | 11544 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LAST_PACKET_TRACING) { |
michael@0 | 11545 | sctp_packet_log(o_pak); |
michael@0 | 11546 | } |
michael@0 | 11547 | #endif |
michael@0 | 11548 | #if defined(__APPLE__) || defined(__Panda__) |
michael@0 | 11549 | SCTP_IP_OUTPUT(ret, o_pak, &ro, NULL, vrf_id); |
michael@0 | 11550 | /* Free the route if we got one back */ |
michael@0 | 11551 | if (ro.ro_rt) { |
michael@0 | 11552 | RTFREE(ro.ro_rt); |
michael@0 | 11553 | ro.ro_rt = NULL; |
michael@0 | 11554 | } |
michael@0 | 11555 | #else |
michael@0 | 11556 | SCTP_IP_OUTPUT(ret, o_pak, NULL, NULL, vrf_id); |
michael@0 | 11557 | #endif |
michael@0 | 11558 | break; |
michael@0 | 11559 | #endif |
michael@0 | 11560 | #ifdef INET6 |
michael@0 | 11561 | case AF_INET6: |
michael@0 | 11562 | ip6->ip6_plen = len - sizeof(struct ip6_hdr); |
michael@0 | 11563 | if (port) { |
michael@0 | 11564 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 11565 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 11566 | #else |
michael@0 | 11567 | shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip6_hdr) + sizeof(struct udphdr)); |
michael@0 | 11568 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 11569 | #endif |
michael@0 | 11570 | #if defined(__Windows__) |
michael@0 | 11571 | udp->uh_sum = 0; |
michael@0 | 11572 | #elif !defined(__Userspace__) |
michael@0 | 11573 | if ((udp->uh_sum = in6_cksum(o_pak, IPPROTO_UDP, sizeof(struct ip6_hdr), len - sizeof(struct ip6_hdr))) == 0) { |
michael@0 | 11574 | udp->uh_sum = 0xffff; |
michael@0 | 11575 | } |
michael@0 | 11576 | #endif |
michael@0 | 11577 | } else { |
michael@0 | 11578 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 11579 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 11580 | #else |
michael@0 | 11581 | #if defined(__FreeBSD__) && __FreeBSD_version >= 900000 |
michael@0 | 11582 | #if __FreeBSD_version > 901000 |
michael@0 | 11583 | mout->m_pkthdr.csum_flags = CSUM_SCTP_IPV6; |
michael@0 | 11584 | #else |
michael@0 | 11585 | mout->m_pkthdr.csum_flags = CSUM_SCTP; |
michael@0 | 11586 | #endif |
michael@0 | 11587 | mout->m_pkthdr.csum_data = 0; |
michael@0 | 11588 | SCTP_STAT_INCR(sctps_sendhwcrc); |
michael@0 | 11589 | #else |
michael@0 | 11590 | shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip6_hdr)); |
michael@0 | 11591 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 11592 | #endif |
michael@0 | 11593 | #endif |
michael@0 | 11594 | } |
michael@0 | 11595 | #ifdef SCTP_PACKET_LOGGING |
michael@0 | 11596 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LAST_PACKET_TRACING) { |
michael@0 | 11597 | sctp_packet_log(o_pak); |
michael@0 | 11598 | } |
michael@0 | 11599 | #endif |
michael@0 | 11600 | SCTP_IP6_OUTPUT(ret, o_pak, NULL, NULL, NULL, vrf_id); |
michael@0 | 11601 | break; |
michael@0 | 11602 | #endif |
michael@0 | 11603 | #if defined(__Userspace__) |
michael@0 | 11604 | case AF_CONN: |
michael@0 | 11605 | { |
michael@0 | 11606 | char *buffer; |
michael@0 | 11607 | struct sockaddr_conn *sconn; |
michael@0 | 11608 | |
michael@0 | 11609 | sconn = (struct sockaddr_conn *)src; |
michael@0 | 11610 | #if defined(SCTP_WITH_NO_CSUM) |
michael@0 | 11611 | SCTP_STAT_INCR(sctps_sendnocrc); |
michael@0 | 11612 | #else |
michael@0 | 11613 | shout->checksum = sctp_calculate_cksum(mout, 0); |
michael@0 | 11614 | SCTP_STAT_INCR(sctps_sendswcrc); |
michael@0 | 11615 | #endif |
michael@0 | 11616 | #ifdef SCTP_PACKET_LOGGING |
michael@0 | 11617 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LAST_PACKET_TRACING) { |
michael@0 | 11618 | sctp_packet_log(mout); |
michael@0 | 11619 | } |
michael@0 | 11620 | #endif |
michael@0 | 11621 | /* Don't alloc/free for each packet */ |
michael@0 | 11622 | if ((buffer = malloc(len)) != NULL) { |
michael@0 | 11623 | m_copydata(mout, 0, len, buffer); |
michael@0 | 11624 | SCTP_BASE_VAR(conn_output)(sconn->sconn_addr, buffer, len, 0, 0); |
michael@0 | 11625 | free(buffer); |
michael@0 | 11626 | } |
michael@0 | 11627 | sctp_m_freem(mout); |
michael@0 | 11628 | break; |
michael@0 | 11629 | } |
michael@0 | 11630 | #endif |
michael@0 | 11631 | default: |
michael@0 | 11632 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Unknown protocol (TSNH) type %d\n", |
michael@0 | 11633 | dst->sa_family); |
michael@0 | 11634 | sctp_m_freem(mout); |
michael@0 | 11635 | SCTP_LTRACE_ERR_RET_PKT(mout, NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, EFAULT); |
michael@0 | 11636 | return; |
michael@0 | 11637 | } |
michael@0 | 11638 | SCTP_STAT_INCR(sctps_sendpackets); |
michael@0 | 11639 | SCTP_STAT_INCR_COUNTER64(sctps_outpackets); |
michael@0 | 11640 | SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); |
michael@0 | 11641 | return; |
michael@0 | 11642 | } |
michael@0 | 11643 | |
michael@0 | 11644 | void |
michael@0 | 11645 | sctp_send_shutdown_complete2(struct sockaddr *src, struct sockaddr *dst, |
michael@0 | 11646 | struct sctphdr *sh, |
michael@0 | 11647 | #if defined(__FreeBSD__) |
michael@0 | 11648 | uint8_t use_mflowid, uint32_t mflowid, |
michael@0 | 11649 | #endif |
michael@0 | 11650 | uint32_t vrf_id, uint16_t port) |
michael@0 | 11651 | { |
michael@0 | 11652 | sctp_send_resp_msg(src, dst, sh, 0, SCTP_SHUTDOWN_COMPLETE, NULL, |
michael@0 | 11653 | #if defined(__FreeBSD__) |
michael@0 | 11654 | use_mflowid, mflowid, |
michael@0 | 11655 | #endif |
michael@0 | 11656 | vrf_id, port); |
michael@0 | 11657 | } |
michael@0 | 11658 | |
michael@0 | 11659 | void |
michael@0 | 11660 | sctp_send_hb(struct sctp_tcb *stcb, struct sctp_nets *net,int so_locked |
michael@0 | 11661 | #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) |
michael@0 | 11662 | SCTP_UNUSED |
michael@0 | 11663 | #endif |
michael@0 | 11664 | ) |
michael@0 | 11665 | { |
michael@0 | 11666 | struct sctp_tmit_chunk *chk; |
michael@0 | 11667 | struct sctp_heartbeat_chunk *hb; |
michael@0 | 11668 | struct timeval now; |
michael@0 | 11669 | |
michael@0 | 11670 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 11671 | if (net == NULL) { |
michael@0 | 11672 | return; |
michael@0 | 11673 | } |
michael@0 | 11674 | (void)SCTP_GETTIME_TIMEVAL(&now); |
michael@0 | 11675 | switch (net->ro._l_addr.sa.sa_family) { |
michael@0 | 11676 | #ifdef INET |
michael@0 | 11677 | case AF_INET: |
michael@0 | 11678 | break; |
michael@0 | 11679 | #endif |
michael@0 | 11680 | #ifdef INET6 |
michael@0 | 11681 | case AF_INET6: |
michael@0 | 11682 | break; |
michael@0 | 11683 | #endif |
michael@0 | 11684 | #if defined(__Userspace__) |
michael@0 | 11685 | case AF_CONN: |
michael@0 | 11686 | break; |
michael@0 | 11687 | #endif |
michael@0 | 11688 | default: |
michael@0 | 11689 | return; |
michael@0 | 11690 | } |
michael@0 | 11691 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 11692 | if (chk == NULL) { |
michael@0 | 11693 | SCTPDBG(SCTP_DEBUG_OUTPUT4, "Gak, can't get a chunk for hb\n"); |
michael@0 | 11694 | return; |
michael@0 | 11695 | } |
michael@0 | 11696 | |
michael@0 | 11697 | chk->copy_by_ref = 0; |
michael@0 | 11698 | chk->rec.chunk_id.id = SCTP_HEARTBEAT_REQUEST; |
michael@0 | 11699 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 11700 | chk->asoc = &stcb->asoc; |
michael@0 | 11701 | chk->send_size = sizeof(struct sctp_heartbeat_chunk); |
michael@0 | 11702 | |
michael@0 | 11703 | chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 11704 | if (chk->data == NULL) { |
michael@0 | 11705 | sctp_free_a_chunk(stcb, chk, so_locked); |
michael@0 | 11706 | return; |
michael@0 | 11707 | } |
michael@0 | 11708 | SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); |
michael@0 | 11709 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 11710 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 11711 | chk->snd_count = 0; |
michael@0 | 11712 | chk->whoTo = net; |
michael@0 | 11713 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 11714 | /* Now we have a mbuf that we can fill in with the details */ |
michael@0 | 11715 | hb = mtod(chk->data, struct sctp_heartbeat_chunk *); |
michael@0 | 11716 | memset(hb, 0, sizeof(struct sctp_heartbeat_chunk)); |
michael@0 | 11717 | /* fill out chunk header */ |
michael@0 | 11718 | hb->ch.chunk_type = SCTP_HEARTBEAT_REQUEST; |
michael@0 | 11719 | hb->ch.chunk_flags = 0; |
michael@0 | 11720 | hb->ch.chunk_length = htons(chk->send_size); |
michael@0 | 11721 | /* Fill out hb parameter */ |
michael@0 | 11722 | hb->heartbeat.hb_info.ph.param_type = htons(SCTP_HEARTBEAT_INFO); |
michael@0 | 11723 | hb->heartbeat.hb_info.ph.param_length = htons(sizeof(struct sctp_heartbeat_info_param)); |
michael@0 | 11724 | hb->heartbeat.hb_info.time_value_1 = now.tv_sec; |
michael@0 | 11725 | hb->heartbeat.hb_info.time_value_2 = now.tv_usec; |
michael@0 | 11726 | /* Did our user request this one, put it in */ |
michael@0 | 11727 | hb->heartbeat.hb_info.addr_family = net->ro._l_addr.sa.sa_family; |
michael@0 | 11728 | #ifdef HAVE_SA_LEN |
michael@0 | 11729 | hb->heartbeat.hb_info.addr_len = net->ro._l_addr.sa.sa_len; |
michael@0 | 11730 | #else |
michael@0 | 11731 | switch (net->ro._l_addr.sa.sa_family) { |
michael@0 | 11732 | #ifdef INET |
michael@0 | 11733 | case AF_INET: |
michael@0 | 11734 | hb->heartbeat.hb_info.addr_len = sizeof(struct sockaddr_in); |
michael@0 | 11735 | break; |
michael@0 | 11736 | #endif |
michael@0 | 11737 | #ifdef INET6 |
michael@0 | 11738 | case AF_INET6: |
michael@0 | 11739 | hb->heartbeat.hb_info.addr_len = sizeof(struct sockaddr_in6); |
michael@0 | 11740 | break; |
michael@0 | 11741 | #endif |
michael@0 | 11742 | #if defined(__Userspace__) |
michael@0 | 11743 | case AF_CONN: |
michael@0 | 11744 | hb->heartbeat.hb_info.addr_len = sizeof(struct sockaddr_conn); |
michael@0 | 11745 | break; |
michael@0 | 11746 | #endif |
michael@0 | 11747 | default: |
michael@0 | 11748 | hb->heartbeat.hb_info.addr_len = 0; |
michael@0 | 11749 | break; |
michael@0 | 11750 | } |
michael@0 | 11751 | #endif |
michael@0 | 11752 | if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { |
michael@0 | 11753 | /* |
michael@0 | 11754 | * we only take from the entropy pool if the address is not |
michael@0 | 11755 | * confirmed. |
michael@0 | 11756 | */ |
michael@0 | 11757 | net->heartbeat_random1 = hb->heartbeat.hb_info.random_value1 = sctp_select_initial_TSN(&stcb->sctp_ep->sctp_ep); |
michael@0 | 11758 | net->heartbeat_random2 = hb->heartbeat.hb_info.random_value2 = sctp_select_initial_TSN(&stcb->sctp_ep->sctp_ep); |
michael@0 | 11759 | } else { |
michael@0 | 11760 | net->heartbeat_random1 = hb->heartbeat.hb_info.random_value1 = 0; |
michael@0 | 11761 | net->heartbeat_random2 = hb->heartbeat.hb_info.random_value2 = 0; |
michael@0 | 11762 | } |
michael@0 | 11763 | switch (net->ro._l_addr.sa.sa_family) { |
michael@0 | 11764 | #ifdef INET |
michael@0 | 11765 | case AF_INET: |
michael@0 | 11766 | memcpy(hb->heartbeat.hb_info.address, |
michael@0 | 11767 | &net->ro._l_addr.sin.sin_addr, |
michael@0 | 11768 | sizeof(net->ro._l_addr.sin.sin_addr)); |
michael@0 | 11769 | break; |
michael@0 | 11770 | #endif |
michael@0 | 11771 | #ifdef INET6 |
michael@0 | 11772 | case AF_INET6: |
michael@0 | 11773 | memcpy(hb->heartbeat.hb_info.address, |
michael@0 | 11774 | &net->ro._l_addr.sin6.sin6_addr, |
michael@0 | 11775 | sizeof(net->ro._l_addr.sin6.sin6_addr)); |
michael@0 | 11776 | break; |
michael@0 | 11777 | #endif |
michael@0 | 11778 | #if defined(__Userspace__) |
michael@0 | 11779 | case AF_CONN: |
michael@0 | 11780 | memcpy(hb->heartbeat.hb_info.address, |
michael@0 | 11781 | &net->ro._l_addr.sconn.sconn_addr, |
michael@0 | 11782 | sizeof(net->ro._l_addr.sconn.sconn_addr)); |
michael@0 | 11783 | break; |
michael@0 | 11784 | #endif |
michael@0 | 11785 | default: |
michael@0 | 11786 | return; |
michael@0 | 11787 | break; |
michael@0 | 11788 | } |
michael@0 | 11789 | net->hb_responded = 0; |
michael@0 | 11790 | TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next); |
michael@0 | 11791 | stcb->asoc.ctrl_queue_cnt++; |
michael@0 | 11792 | SCTP_STAT_INCR(sctps_sendheartbeat); |
michael@0 | 11793 | return; |
michael@0 | 11794 | } |
michael@0 | 11795 | |
michael@0 | 11796 | void |
michael@0 | 11797 | sctp_send_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, |
michael@0 | 11798 | uint32_t high_tsn) |
michael@0 | 11799 | { |
michael@0 | 11800 | struct sctp_association *asoc; |
michael@0 | 11801 | struct sctp_ecne_chunk *ecne; |
michael@0 | 11802 | struct sctp_tmit_chunk *chk; |
michael@0 | 11803 | |
michael@0 | 11804 | if (net == NULL) { |
michael@0 | 11805 | return; |
michael@0 | 11806 | } |
michael@0 | 11807 | asoc = &stcb->asoc; |
michael@0 | 11808 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 11809 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 11810 | if ((chk->rec.chunk_id.id == SCTP_ECN_ECHO) && (net == chk->whoTo)) { |
michael@0 | 11811 | /* found a previous ECN_ECHO update it if needed */ |
michael@0 | 11812 | uint32_t cnt, ctsn; |
michael@0 | 11813 | ecne = mtod(chk->data, struct sctp_ecne_chunk *); |
michael@0 | 11814 | ctsn = ntohl(ecne->tsn); |
michael@0 | 11815 | if (SCTP_TSN_GT(high_tsn, ctsn)) { |
michael@0 | 11816 | ecne->tsn = htonl(high_tsn); |
michael@0 | 11817 | SCTP_STAT_INCR(sctps_queue_upd_ecne); |
michael@0 | 11818 | } |
michael@0 | 11819 | cnt = ntohl(ecne->num_pkts_since_cwr); |
michael@0 | 11820 | cnt++; |
michael@0 | 11821 | ecne->num_pkts_since_cwr = htonl(cnt); |
michael@0 | 11822 | return; |
michael@0 | 11823 | } |
michael@0 | 11824 | } |
michael@0 | 11825 | /* nope could not find one to update so we must build one */ |
michael@0 | 11826 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 11827 | if (chk == NULL) { |
michael@0 | 11828 | return; |
michael@0 | 11829 | } |
michael@0 | 11830 | chk->copy_by_ref = 0; |
michael@0 | 11831 | SCTP_STAT_INCR(sctps_queue_upd_ecne); |
michael@0 | 11832 | chk->rec.chunk_id.id = SCTP_ECN_ECHO; |
michael@0 | 11833 | chk->rec.chunk_id.can_take_data = 0; |
michael@0 | 11834 | chk->asoc = &stcb->asoc; |
michael@0 | 11835 | chk->send_size = sizeof(struct sctp_ecne_chunk); |
michael@0 | 11836 | chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 11837 | if (chk->data == NULL) { |
michael@0 | 11838 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 11839 | return; |
michael@0 | 11840 | } |
michael@0 | 11841 | SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); |
michael@0 | 11842 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 11843 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 11844 | chk->snd_count = 0; |
michael@0 | 11845 | chk->whoTo = net; |
michael@0 | 11846 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 11847 | |
michael@0 | 11848 | stcb->asoc.ecn_echo_cnt_onq++; |
michael@0 | 11849 | ecne = mtod(chk->data, struct sctp_ecne_chunk *); |
michael@0 | 11850 | ecne->ch.chunk_type = SCTP_ECN_ECHO; |
michael@0 | 11851 | ecne->ch.chunk_flags = 0; |
michael@0 | 11852 | ecne->ch.chunk_length = htons(sizeof(struct sctp_ecne_chunk)); |
michael@0 | 11853 | ecne->tsn = htonl(high_tsn); |
michael@0 | 11854 | ecne->num_pkts_since_cwr = htonl(1); |
michael@0 | 11855 | TAILQ_INSERT_HEAD(&stcb->asoc.control_send_queue, chk, sctp_next); |
michael@0 | 11856 | asoc->ctrl_queue_cnt++; |
michael@0 | 11857 | } |
michael@0 | 11858 | |
michael@0 | 11859 | void |
michael@0 | 11860 | sctp_send_packet_dropped(struct sctp_tcb *stcb, struct sctp_nets *net, |
michael@0 | 11861 | struct mbuf *m, int len, int iphlen, int bad_crc) |
michael@0 | 11862 | { |
michael@0 | 11863 | struct sctp_association *asoc; |
michael@0 | 11864 | struct sctp_pktdrop_chunk *drp; |
michael@0 | 11865 | struct sctp_tmit_chunk *chk; |
michael@0 | 11866 | uint8_t *datap; |
michael@0 | 11867 | int was_trunc = 0; |
michael@0 | 11868 | int fullsz = 0; |
michael@0 | 11869 | long spc; |
michael@0 | 11870 | int offset; |
michael@0 | 11871 | struct sctp_chunkhdr *ch, chunk_buf; |
michael@0 | 11872 | unsigned int chk_length; |
michael@0 | 11873 | |
michael@0 | 11874 | if (!stcb) { |
michael@0 | 11875 | return; |
michael@0 | 11876 | } |
michael@0 | 11877 | asoc = &stcb->asoc; |
michael@0 | 11878 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 11879 | if (asoc->peer_supports_pktdrop == 0) { |
michael@0 | 11880 | /*- |
michael@0 | 11881 | * peer must declare support before I send one. |
michael@0 | 11882 | */ |
michael@0 | 11883 | return; |
michael@0 | 11884 | } |
michael@0 | 11885 | if (stcb->sctp_socket == NULL) { |
michael@0 | 11886 | return; |
michael@0 | 11887 | } |
michael@0 | 11888 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 11889 | if (chk == NULL) { |
michael@0 | 11890 | return; |
michael@0 | 11891 | } |
michael@0 | 11892 | chk->copy_by_ref = 0; |
michael@0 | 11893 | len -= iphlen; |
michael@0 | 11894 | chk->send_size = len; |
michael@0 | 11895 | /* Validate that we do not have an ABORT in here. */ |
michael@0 | 11896 | offset = iphlen + sizeof(struct sctphdr); |
michael@0 | 11897 | ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, |
michael@0 | 11898 | sizeof(*ch), (uint8_t *) & chunk_buf); |
michael@0 | 11899 | while (ch != NULL) { |
michael@0 | 11900 | chk_length = ntohs(ch->chunk_length); |
michael@0 | 11901 | if (chk_length < sizeof(*ch)) { |
michael@0 | 11902 | /* break to abort land */ |
michael@0 | 11903 | break; |
michael@0 | 11904 | } |
michael@0 | 11905 | switch (ch->chunk_type) { |
michael@0 | 11906 | case SCTP_PACKET_DROPPED: |
michael@0 | 11907 | case SCTP_ABORT_ASSOCIATION: |
michael@0 | 11908 | case SCTP_INITIATION_ACK: |
michael@0 | 11909 | /** |
michael@0 | 11910 | * We don't respond with an PKT-DROP to an ABORT |
michael@0 | 11911 | * or PKT-DROP. We also do not respond to an |
michael@0 | 11912 | * INIT-ACK, because we can't know if the initiation |
michael@0 | 11913 | * tag is correct or not. |
michael@0 | 11914 | */ |
michael@0 | 11915 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 11916 | return; |
michael@0 | 11917 | default: |
michael@0 | 11918 | break; |
michael@0 | 11919 | } |
michael@0 | 11920 | offset += SCTP_SIZE32(chk_length); |
michael@0 | 11921 | ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, |
michael@0 | 11922 | sizeof(*ch), (uint8_t *) & chunk_buf); |
michael@0 | 11923 | } |
michael@0 | 11924 | |
michael@0 | 11925 | if ((len + SCTP_MAX_OVERHEAD + sizeof(struct sctp_pktdrop_chunk)) > |
michael@0 | 11926 | min(stcb->asoc.smallest_mtu, MCLBYTES)) { |
michael@0 | 11927 | /* only send 1 mtu worth, trim off the |
michael@0 | 11928 | * excess on the end. |
michael@0 | 11929 | */ |
michael@0 | 11930 | fullsz = len; |
michael@0 | 11931 | len = min(stcb->asoc.smallest_mtu, MCLBYTES) - SCTP_MAX_OVERHEAD; |
michael@0 | 11932 | was_trunc = 1; |
michael@0 | 11933 | } |
michael@0 | 11934 | chk->asoc = &stcb->asoc; |
michael@0 | 11935 | chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 11936 | if (chk->data == NULL) { |
michael@0 | 11937 | jump_out: |
michael@0 | 11938 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 11939 | return; |
michael@0 | 11940 | } |
michael@0 | 11941 | SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); |
michael@0 | 11942 | drp = mtod(chk->data, struct sctp_pktdrop_chunk *); |
michael@0 | 11943 | if (drp == NULL) { |
michael@0 | 11944 | sctp_m_freem(chk->data); |
michael@0 | 11945 | chk->data = NULL; |
michael@0 | 11946 | goto jump_out; |
michael@0 | 11947 | } |
michael@0 | 11948 | chk->book_size = SCTP_SIZE32((chk->send_size + sizeof(struct sctp_pktdrop_chunk) + |
michael@0 | 11949 | sizeof(struct sctphdr) + SCTP_MED_OVERHEAD)); |
michael@0 | 11950 | chk->book_size_scale = 0; |
michael@0 | 11951 | if (was_trunc) { |
michael@0 | 11952 | drp->ch.chunk_flags = SCTP_PACKET_TRUNCATED; |
michael@0 | 11953 | drp->trunc_len = htons(fullsz); |
michael@0 | 11954 | /* Len is already adjusted to size minus overhead above |
michael@0 | 11955 | * take out the pkt_drop chunk itself from it. |
michael@0 | 11956 | */ |
michael@0 | 11957 | chk->send_size = len - sizeof(struct sctp_pktdrop_chunk); |
michael@0 | 11958 | len = chk->send_size; |
michael@0 | 11959 | } else { |
michael@0 | 11960 | /* no truncation needed */ |
michael@0 | 11961 | drp->ch.chunk_flags = 0; |
michael@0 | 11962 | drp->trunc_len = htons(0); |
michael@0 | 11963 | } |
michael@0 | 11964 | if (bad_crc) { |
michael@0 | 11965 | drp->ch.chunk_flags |= SCTP_BADCRC; |
michael@0 | 11966 | } |
michael@0 | 11967 | chk->send_size += sizeof(struct sctp_pktdrop_chunk); |
michael@0 | 11968 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 11969 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 11970 | chk->snd_count = 0; |
michael@0 | 11971 | if (net) { |
michael@0 | 11972 | /* we should hit here */ |
michael@0 | 11973 | chk->whoTo = net; |
michael@0 | 11974 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 11975 | } else { |
michael@0 | 11976 | chk->whoTo = NULL; |
michael@0 | 11977 | } |
michael@0 | 11978 | chk->rec.chunk_id.id = SCTP_PACKET_DROPPED; |
michael@0 | 11979 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 11980 | drp->ch.chunk_type = SCTP_PACKET_DROPPED; |
michael@0 | 11981 | drp->ch.chunk_length = htons(chk->send_size); |
michael@0 | 11982 | spc = SCTP_SB_LIMIT_RCV(stcb->sctp_socket); |
michael@0 | 11983 | if (spc < 0) { |
michael@0 | 11984 | spc = 0; |
michael@0 | 11985 | } |
michael@0 | 11986 | drp->bottle_bw = htonl(spc); |
michael@0 | 11987 | if (asoc->my_rwnd) { |
michael@0 | 11988 | drp->current_onq = htonl(asoc->size_on_reasm_queue + |
michael@0 | 11989 | asoc->size_on_all_streams + |
michael@0 | 11990 | asoc->my_rwnd_control_len + |
michael@0 | 11991 | stcb->sctp_socket->so_rcv.sb_cc); |
michael@0 | 11992 | } else { |
michael@0 | 11993 | /*- |
michael@0 | 11994 | * If my rwnd is 0, possibly from mbuf depletion as well as |
michael@0 | 11995 | * space used, tell the peer there is NO space aka onq == bw |
michael@0 | 11996 | */ |
michael@0 | 11997 | drp->current_onq = htonl(spc); |
michael@0 | 11998 | } |
michael@0 | 11999 | drp->reserved = 0; |
michael@0 | 12000 | datap = drp->data; |
michael@0 | 12001 | m_copydata(m, iphlen, len, (caddr_t)datap); |
michael@0 | 12002 | TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next); |
michael@0 | 12003 | asoc->ctrl_queue_cnt++; |
michael@0 | 12004 | } |
michael@0 | 12005 | |
michael@0 | 12006 | void |
michael@0 | 12007 | sctp_send_cwr(struct sctp_tcb *stcb, struct sctp_nets *net, uint32_t high_tsn, uint8_t override) |
michael@0 | 12008 | { |
michael@0 | 12009 | struct sctp_association *asoc; |
michael@0 | 12010 | struct sctp_cwr_chunk *cwr; |
michael@0 | 12011 | struct sctp_tmit_chunk *chk; |
michael@0 | 12012 | |
michael@0 | 12013 | SCTP_TCB_LOCK_ASSERT(stcb); |
michael@0 | 12014 | if (net == NULL) { |
michael@0 | 12015 | return; |
michael@0 | 12016 | } |
michael@0 | 12017 | asoc = &stcb->asoc; |
michael@0 | 12018 | TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { |
michael@0 | 12019 | if ((chk->rec.chunk_id.id == SCTP_ECN_CWR) && (net == chk->whoTo)) { |
michael@0 | 12020 | /* found a previous CWR queued to same destination update it if needed */ |
michael@0 | 12021 | uint32_t ctsn; |
michael@0 | 12022 | cwr = mtod(chk->data, struct sctp_cwr_chunk *); |
michael@0 | 12023 | ctsn = ntohl(cwr->tsn); |
michael@0 | 12024 | if (SCTP_TSN_GT(high_tsn, ctsn)) { |
michael@0 | 12025 | cwr->tsn = htonl(high_tsn); |
michael@0 | 12026 | } |
michael@0 | 12027 | if (override & SCTP_CWR_REDUCE_OVERRIDE) { |
michael@0 | 12028 | /* Make sure override is carried */ |
michael@0 | 12029 | cwr->ch.chunk_flags |= SCTP_CWR_REDUCE_OVERRIDE; |
michael@0 | 12030 | } |
michael@0 | 12031 | return; |
michael@0 | 12032 | } |
michael@0 | 12033 | } |
michael@0 | 12034 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 12035 | if (chk == NULL) { |
michael@0 | 12036 | return; |
michael@0 | 12037 | } |
michael@0 | 12038 | chk->copy_by_ref = 0; |
michael@0 | 12039 | chk->rec.chunk_id.id = SCTP_ECN_CWR; |
michael@0 | 12040 | chk->rec.chunk_id.can_take_data = 1; |
michael@0 | 12041 | chk->asoc = &stcb->asoc; |
michael@0 | 12042 | chk->send_size = sizeof(struct sctp_cwr_chunk); |
michael@0 | 12043 | chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 12044 | if (chk->data == NULL) { |
michael@0 | 12045 | sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); |
michael@0 | 12046 | return; |
michael@0 | 12047 | } |
michael@0 | 12048 | SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); |
michael@0 | 12049 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 12050 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 12051 | chk->snd_count = 0; |
michael@0 | 12052 | chk->whoTo = net; |
michael@0 | 12053 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 12054 | cwr = mtod(chk->data, struct sctp_cwr_chunk *); |
michael@0 | 12055 | cwr->ch.chunk_type = SCTP_ECN_CWR; |
michael@0 | 12056 | cwr->ch.chunk_flags = override; |
michael@0 | 12057 | cwr->ch.chunk_length = htons(sizeof(struct sctp_cwr_chunk)); |
michael@0 | 12058 | cwr->tsn = htonl(high_tsn); |
michael@0 | 12059 | TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next); |
michael@0 | 12060 | asoc->ctrl_queue_cnt++; |
michael@0 | 12061 | } |
michael@0 | 12062 | |
michael@0 | 12063 | void |
michael@0 | 12064 | sctp_add_stream_reset_out(struct sctp_tmit_chunk *chk, |
michael@0 | 12065 | int number_entries, uint16_t * list, |
michael@0 | 12066 | uint32_t seq, uint32_t resp_seq, uint32_t last_sent) |
michael@0 | 12067 | { |
michael@0 | 12068 | uint16_t len, old_len, i; |
michael@0 | 12069 | struct sctp_stream_reset_out_request *req_out; |
michael@0 | 12070 | struct sctp_chunkhdr *ch; |
michael@0 | 12071 | |
michael@0 | 12072 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12073 | old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); |
michael@0 | 12074 | |
michael@0 | 12075 | /* get to new offset for the param. */ |
michael@0 | 12076 | req_out = (struct sctp_stream_reset_out_request *)((caddr_t)ch + len); |
michael@0 | 12077 | /* now how long will this param be? */ |
michael@0 | 12078 | len = (sizeof(struct sctp_stream_reset_out_request) + (sizeof(uint16_t) * number_entries)); |
michael@0 | 12079 | req_out->ph.param_type = htons(SCTP_STR_RESET_OUT_REQUEST); |
michael@0 | 12080 | req_out->ph.param_length = htons(len); |
michael@0 | 12081 | req_out->request_seq = htonl(seq); |
michael@0 | 12082 | req_out->response_seq = htonl(resp_seq); |
michael@0 | 12083 | req_out->send_reset_at_tsn = htonl(last_sent); |
michael@0 | 12084 | if (number_entries) { |
michael@0 | 12085 | for (i = 0; i < number_entries; i++) { |
michael@0 | 12086 | req_out->list_of_streams[i] = htons(list[i]); |
michael@0 | 12087 | } |
michael@0 | 12088 | } |
michael@0 | 12089 | if (SCTP_SIZE32(len) > len) { |
michael@0 | 12090 | /*- |
michael@0 | 12091 | * Need to worry about the pad we may end up adding to the |
michael@0 | 12092 | * end. This is easy since the struct is either aligned to 4 |
michael@0 | 12093 | * bytes or 2 bytes off. |
michael@0 | 12094 | */ |
michael@0 | 12095 | req_out->list_of_streams[number_entries] = 0; |
michael@0 | 12096 | } |
michael@0 | 12097 | /* now fix the chunk length */ |
michael@0 | 12098 | ch->chunk_length = htons(len + old_len); |
michael@0 | 12099 | chk->book_size = len + old_len; |
michael@0 | 12100 | chk->book_size_scale = 0; |
michael@0 | 12101 | chk->send_size = SCTP_SIZE32(chk->book_size); |
michael@0 | 12102 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 12103 | return; |
michael@0 | 12104 | } |
michael@0 | 12105 | |
michael@0 | 12106 | static void |
michael@0 | 12107 | sctp_add_stream_reset_in(struct sctp_tmit_chunk *chk, |
michael@0 | 12108 | int number_entries, uint16_t *list, |
michael@0 | 12109 | uint32_t seq) |
michael@0 | 12110 | { |
michael@0 | 12111 | uint16_t len, old_len, i; |
michael@0 | 12112 | struct sctp_stream_reset_in_request *req_in; |
michael@0 | 12113 | struct sctp_chunkhdr *ch; |
michael@0 | 12114 | |
michael@0 | 12115 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12116 | old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); |
michael@0 | 12117 | |
michael@0 | 12118 | /* get to new offset for the param. */ |
michael@0 | 12119 | req_in = (struct sctp_stream_reset_in_request *)((caddr_t)ch + len); |
michael@0 | 12120 | /* now how long will this param be? */ |
michael@0 | 12121 | len = (sizeof(struct sctp_stream_reset_in_request) + (sizeof(uint16_t) * number_entries)); |
michael@0 | 12122 | req_in->ph.param_type = htons(SCTP_STR_RESET_IN_REQUEST); |
michael@0 | 12123 | req_in->ph.param_length = htons(len); |
michael@0 | 12124 | req_in->request_seq = htonl(seq); |
michael@0 | 12125 | if (number_entries) { |
michael@0 | 12126 | for (i = 0; i < number_entries; i++) { |
michael@0 | 12127 | req_in->list_of_streams[i] = htons(list[i]); |
michael@0 | 12128 | } |
michael@0 | 12129 | } |
michael@0 | 12130 | if (SCTP_SIZE32(len) > len) { |
michael@0 | 12131 | /*- |
michael@0 | 12132 | * Need to worry about the pad we may end up adding to the |
michael@0 | 12133 | * end. This is easy since the struct is either aligned to 4 |
michael@0 | 12134 | * bytes or 2 bytes off. |
michael@0 | 12135 | */ |
michael@0 | 12136 | req_in->list_of_streams[number_entries] = 0; |
michael@0 | 12137 | } |
michael@0 | 12138 | /* now fix the chunk length */ |
michael@0 | 12139 | ch->chunk_length = htons(len + old_len); |
michael@0 | 12140 | chk->book_size = len + old_len; |
michael@0 | 12141 | chk->book_size_scale = 0; |
michael@0 | 12142 | chk->send_size = SCTP_SIZE32(chk->book_size); |
michael@0 | 12143 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 12144 | return; |
michael@0 | 12145 | } |
michael@0 | 12146 | |
michael@0 | 12147 | static void |
michael@0 | 12148 | sctp_add_stream_reset_tsn(struct sctp_tmit_chunk *chk, |
michael@0 | 12149 | uint32_t seq) |
michael@0 | 12150 | { |
michael@0 | 12151 | uint16_t len, old_len; |
michael@0 | 12152 | struct sctp_stream_reset_tsn_request *req_tsn; |
michael@0 | 12153 | struct sctp_chunkhdr *ch; |
michael@0 | 12154 | |
michael@0 | 12155 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12156 | old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); |
michael@0 | 12157 | |
michael@0 | 12158 | /* get to new offset for the param. */ |
michael@0 | 12159 | req_tsn = (struct sctp_stream_reset_tsn_request *)((caddr_t)ch + len); |
michael@0 | 12160 | /* now how long will this param be? */ |
michael@0 | 12161 | len = sizeof(struct sctp_stream_reset_tsn_request); |
michael@0 | 12162 | req_tsn->ph.param_type = htons(SCTP_STR_RESET_TSN_REQUEST); |
michael@0 | 12163 | req_tsn->ph.param_length = htons(len); |
michael@0 | 12164 | req_tsn->request_seq = htonl(seq); |
michael@0 | 12165 | |
michael@0 | 12166 | /* now fix the chunk length */ |
michael@0 | 12167 | ch->chunk_length = htons(len + old_len); |
michael@0 | 12168 | chk->send_size = len + old_len; |
michael@0 | 12169 | chk->book_size = SCTP_SIZE32(chk->send_size); |
michael@0 | 12170 | chk->book_size_scale = 0; |
michael@0 | 12171 | SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size); |
michael@0 | 12172 | return; |
michael@0 | 12173 | } |
michael@0 | 12174 | |
michael@0 | 12175 | void |
michael@0 | 12176 | sctp_add_stream_reset_result(struct sctp_tmit_chunk *chk, |
michael@0 | 12177 | uint32_t resp_seq, uint32_t result) |
michael@0 | 12178 | { |
michael@0 | 12179 | uint16_t len, old_len; |
michael@0 | 12180 | struct sctp_stream_reset_response *resp; |
michael@0 | 12181 | struct sctp_chunkhdr *ch; |
michael@0 | 12182 | |
michael@0 | 12183 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12184 | old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); |
michael@0 | 12185 | |
michael@0 | 12186 | /* get to new offset for the param. */ |
michael@0 | 12187 | resp = (struct sctp_stream_reset_response *)((caddr_t)ch + len); |
michael@0 | 12188 | /* now how long will this param be? */ |
michael@0 | 12189 | len = sizeof(struct sctp_stream_reset_response); |
michael@0 | 12190 | resp->ph.param_type = htons(SCTP_STR_RESET_RESPONSE); |
michael@0 | 12191 | resp->ph.param_length = htons(len); |
michael@0 | 12192 | resp->response_seq = htonl(resp_seq); |
michael@0 | 12193 | resp->result = ntohl(result); |
michael@0 | 12194 | |
michael@0 | 12195 | /* now fix the chunk length */ |
michael@0 | 12196 | ch->chunk_length = htons(len + old_len); |
michael@0 | 12197 | chk->book_size = len + old_len; |
michael@0 | 12198 | chk->book_size_scale = 0; |
michael@0 | 12199 | chk->send_size = SCTP_SIZE32(chk->book_size); |
michael@0 | 12200 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 12201 | return; |
michael@0 | 12202 | } |
michael@0 | 12203 | |
michael@0 | 12204 | void |
michael@0 | 12205 | sctp_add_stream_reset_result_tsn(struct sctp_tmit_chunk *chk, |
michael@0 | 12206 | uint32_t resp_seq, uint32_t result, |
michael@0 | 12207 | uint32_t send_una, uint32_t recv_next) |
michael@0 | 12208 | { |
michael@0 | 12209 | uint16_t len, old_len; |
michael@0 | 12210 | struct sctp_stream_reset_response_tsn *resp; |
michael@0 | 12211 | struct sctp_chunkhdr *ch; |
michael@0 | 12212 | |
michael@0 | 12213 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12214 | old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); |
michael@0 | 12215 | |
michael@0 | 12216 | /* get to new offset for the param. */ |
michael@0 | 12217 | resp = (struct sctp_stream_reset_response_tsn *)((caddr_t)ch + len); |
michael@0 | 12218 | /* now how long will this param be? */ |
michael@0 | 12219 | len = sizeof(struct sctp_stream_reset_response_tsn); |
michael@0 | 12220 | resp->ph.param_type = htons(SCTP_STR_RESET_RESPONSE); |
michael@0 | 12221 | resp->ph.param_length = htons(len); |
michael@0 | 12222 | resp->response_seq = htonl(resp_seq); |
michael@0 | 12223 | resp->result = htonl(result); |
michael@0 | 12224 | resp->senders_next_tsn = htonl(send_una); |
michael@0 | 12225 | resp->receivers_next_tsn = htonl(recv_next); |
michael@0 | 12226 | |
michael@0 | 12227 | /* now fix the chunk length */ |
michael@0 | 12228 | ch->chunk_length = htons(len + old_len); |
michael@0 | 12229 | chk->book_size = len + old_len; |
michael@0 | 12230 | chk->send_size = SCTP_SIZE32(chk->book_size); |
michael@0 | 12231 | chk->book_size_scale = 0; |
michael@0 | 12232 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 12233 | return; |
michael@0 | 12234 | } |
michael@0 | 12235 | |
michael@0 | 12236 | static void |
michael@0 | 12237 | sctp_add_an_out_stream(struct sctp_tmit_chunk *chk, |
michael@0 | 12238 | uint32_t seq, |
michael@0 | 12239 | uint16_t adding) |
michael@0 | 12240 | { |
michael@0 | 12241 | uint16_t len, old_len; |
michael@0 | 12242 | struct sctp_chunkhdr *ch; |
michael@0 | 12243 | struct sctp_stream_reset_add_strm *addstr; |
michael@0 | 12244 | |
michael@0 | 12245 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12246 | old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); |
michael@0 | 12247 | |
michael@0 | 12248 | /* get to new offset for the param. */ |
michael@0 | 12249 | addstr = (struct sctp_stream_reset_add_strm *)((caddr_t)ch + len); |
michael@0 | 12250 | /* now how long will this param be? */ |
michael@0 | 12251 | len = sizeof(struct sctp_stream_reset_add_strm); |
michael@0 | 12252 | |
michael@0 | 12253 | /* Fill it out. */ |
michael@0 | 12254 | addstr->ph.param_type = htons(SCTP_STR_RESET_ADD_OUT_STREAMS); |
michael@0 | 12255 | addstr->ph.param_length = htons(len); |
michael@0 | 12256 | addstr->request_seq = htonl(seq); |
michael@0 | 12257 | addstr->number_of_streams = htons(adding); |
michael@0 | 12258 | addstr->reserved = 0; |
michael@0 | 12259 | |
michael@0 | 12260 | /* now fix the chunk length */ |
michael@0 | 12261 | ch->chunk_length = htons(len + old_len); |
michael@0 | 12262 | chk->send_size = len + old_len; |
michael@0 | 12263 | chk->book_size = SCTP_SIZE32(chk->send_size); |
michael@0 | 12264 | chk->book_size_scale = 0; |
michael@0 | 12265 | SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size); |
michael@0 | 12266 | return; |
michael@0 | 12267 | } |
michael@0 | 12268 | |
michael@0 | 12269 | static void |
michael@0 | 12270 | sctp_add_an_in_stream(struct sctp_tmit_chunk *chk, |
michael@0 | 12271 | uint32_t seq, |
michael@0 | 12272 | uint16_t adding) |
michael@0 | 12273 | { |
michael@0 | 12274 | uint16_t len, old_len; |
michael@0 | 12275 | struct sctp_chunkhdr *ch; |
michael@0 | 12276 | struct sctp_stream_reset_add_strm *addstr; |
michael@0 | 12277 | |
michael@0 | 12278 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12279 | old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); |
michael@0 | 12280 | |
michael@0 | 12281 | /* get to new offset for the param. */ |
michael@0 | 12282 | addstr = (struct sctp_stream_reset_add_strm *)((caddr_t)ch + len); |
michael@0 | 12283 | /* now how long will this param be? */ |
michael@0 | 12284 | len = sizeof(struct sctp_stream_reset_add_strm); |
michael@0 | 12285 | /* Fill it out. */ |
michael@0 | 12286 | addstr->ph.param_type = htons(SCTP_STR_RESET_ADD_IN_STREAMS); |
michael@0 | 12287 | addstr->ph.param_length = htons(len); |
michael@0 | 12288 | addstr->request_seq = htonl(seq); |
michael@0 | 12289 | addstr->number_of_streams = htons(adding); |
michael@0 | 12290 | addstr->reserved = 0; |
michael@0 | 12291 | |
michael@0 | 12292 | /* now fix the chunk length */ |
michael@0 | 12293 | ch->chunk_length = htons(len + old_len); |
michael@0 | 12294 | chk->send_size = len + old_len; |
michael@0 | 12295 | chk->book_size = SCTP_SIZE32(chk->send_size); |
michael@0 | 12296 | chk->book_size_scale = 0; |
michael@0 | 12297 | SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size); |
michael@0 | 12298 | return; |
michael@0 | 12299 | } |
michael@0 | 12300 | |
michael@0 | 12301 | int |
michael@0 | 12302 | sctp_send_str_reset_req(struct sctp_tcb *stcb, |
michael@0 | 12303 | int number_entries, uint16_t *list, |
michael@0 | 12304 | uint8_t send_out_req, |
michael@0 | 12305 | uint8_t send_in_req, |
michael@0 | 12306 | uint8_t send_tsn_req, |
michael@0 | 12307 | uint8_t add_stream, |
michael@0 | 12308 | uint16_t adding_o, |
michael@0 | 12309 | uint16_t adding_i, uint8_t peer_asked) |
michael@0 | 12310 | { |
michael@0 | 12311 | |
michael@0 | 12312 | struct sctp_association *asoc; |
michael@0 | 12313 | struct sctp_tmit_chunk *chk; |
michael@0 | 12314 | struct sctp_chunkhdr *ch; |
michael@0 | 12315 | uint32_t seq; |
michael@0 | 12316 | |
michael@0 | 12317 | asoc = &stcb->asoc; |
michael@0 | 12318 | if (asoc->stream_reset_outstanding) { |
michael@0 | 12319 | /*- |
michael@0 | 12320 | * Already one pending, must get ACK back to clear the flag. |
michael@0 | 12321 | */ |
michael@0 | 12322 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EBUSY); |
michael@0 | 12323 | return (EBUSY); |
michael@0 | 12324 | } |
michael@0 | 12325 | if ((send_out_req == 0) && (send_in_req == 0) && (send_tsn_req == 0) && |
michael@0 | 12326 | (add_stream == 0)) { |
michael@0 | 12327 | /* nothing to do */ |
michael@0 | 12328 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 12329 | return (EINVAL); |
michael@0 | 12330 | } |
michael@0 | 12331 | if (send_tsn_req && (send_out_req || send_in_req)) { |
michael@0 | 12332 | /* error, can't do that */ |
michael@0 | 12333 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 12334 | return (EINVAL); |
michael@0 | 12335 | } |
michael@0 | 12336 | sctp_alloc_a_chunk(stcb, chk); |
michael@0 | 12337 | if (chk == NULL) { |
michael@0 | 12338 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12339 | return (ENOMEM); |
michael@0 | 12340 | } |
michael@0 | 12341 | chk->copy_by_ref = 0; |
michael@0 | 12342 | chk->rec.chunk_id.id = SCTP_STREAM_RESET; |
michael@0 | 12343 | chk->rec.chunk_id.can_take_data = 0; |
michael@0 | 12344 | chk->asoc = &stcb->asoc; |
michael@0 | 12345 | chk->book_size = sizeof(struct sctp_chunkhdr); |
michael@0 | 12346 | chk->send_size = SCTP_SIZE32(chk->book_size); |
michael@0 | 12347 | chk->book_size_scale = 0; |
michael@0 | 12348 | |
michael@0 | 12349 | chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); |
michael@0 | 12350 | if (chk->data == NULL) { |
michael@0 | 12351 | sctp_free_a_chunk(stcb, chk, SCTP_SO_LOCKED); |
michael@0 | 12352 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12353 | return (ENOMEM); |
michael@0 | 12354 | } |
michael@0 | 12355 | SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); |
michael@0 | 12356 | |
michael@0 | 12357 | /* setup chunk parameters */ |
michael@0 | 12358 | chk->sent = SCTP_DATAGRAM_UNSENT; |
michael@0 | 12359 | chk->snd_count = 0; |
michael@0 | 12360 | if (stcb->asoc.alternate) { |
michael@0 | 12361 | chk->whoTo = stcb->asoc.alternate; |
michael@0 | 12362 | } else { |
michael@0 | 12363 | chk->whoTo = stcb->asoc.primary_destination; |
michael@0 | 12364 | } |
michael@0 | 12365 | atomic_add_int(&chk->whoTo->ref_count, 1); |
michael@0 | 12366 | ch = mtod(chk->data, struct sctp_chunkhdr *); |
michael@0 | 12367 | ch->chunk_type = SCTP_STREAM_RESET; |
michael@0 | 12368 | ch->chunk_flags = 0; |
michael@0 | 12369 | ch->chunk_length = htons(chk->book_size); |
michael@0 | 12370 | SCTP_BUF_LEN(chk->data) = chk->send_size; |
michael@0 | 12371 | |
michael@0 | 12372 | seq = stcb->asoc.str_reset_seq_out; |
michael@0 | 12373 | if (send_out_req) { |
michael@0 | 12374 | sctp_add_stream_reset_out(chk, number_entries, list, |
michael@0 | 12375 | seq, (stcb->asoc.str_reset_seq_in - 1), (stcb->asoc.sending_seq - 1)); |
michael@0 | 12376 | asoc->stream_reset_out_is_outstanding = 1; |
michael@0 | 12377 | seq++; |
michael@0 | 12378 | asoc->stream_reset_outstanding++; |
michael@0 | 12379 | } |
michael@0 | 12380 | if ((add_stream & 1) && |
michael@0 | 12381 | ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < adding_o)) { |
michael@0 | 12382 | /* Need to allocate more */ |
michael@0 | 12383 | struct sctp_stream_out *oldstream; |
michael@0 | 12384 | struct sctp_stream_queue_pending *sp, *nsp; |
michael@0 | 12385 | int i; |
michael@0 | 12386 | |
michael@0 | 12387 | oldstream = stcb->asoc.strmout; |
michael@0 | 12388 | /* get some more */ |
michael@0 | 12389 | SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *, |
michael@0 | 12390 | ((stcb->asoc.streamoutcnt+adding_o) * sizeof(struct sctp_stream_out)), |
michael@0 | 12391 | SCTP_M_STRMO); |
michael@0 | 12392 | if (stcb->asoc.strmout == NULL) { |
michael@0 | 12393 | uint8_t x; |
michael@0 | 12394 | stcb->asoc.strmout = oldstream; |
michael@0 | 12395 | /* Turn off the bit */ |
michael@0 | 12396 | x = add_stream & 0xfe; |
michael@0 | 12397 | add_stream = x; |
michael@0 | 12398 | goto skip_stuff; |
michael@0 | 12399 | } |
michael@0 | 12400 | /* Ok now we proceed with copying the old out stuff and |
michael@0 | 12401 | * initializing the new stuff. |
michael@0 | 12402 | */ |
michael@0 | 12403 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 12404 | stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0, 1); |
michael@0 | 12405 | for (i = 0; i < stcb->asoc.streamoutcnt; i++) { |
michael@0 | 12406 | TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); |
michael@0 | 12407 | stcb->asoc.strmout[i].chunks_on_queues = oldstream[i].chunks_on_queues; |
michael@0 | 12408 | stcb->asoc.strmout[i].next_sequence_send = oldstream[i].next_sequence_send; |
michael@0 | 12409 | stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete; |
michael@0 | 12410 | stcb->asoc.strmout[i].stream_no = i; |
michael@0 | 12411 | stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], &oldstream[i]); |
michael@0 | 12412 | /* now anything on those queues? */ |
michael@0 | 12413 | TAILQ_FOREACH_SAFE(sp, &oldstream[i].outqueue, next, nsp) { |
michael@0 | 12414 | TAILQ_REMOVE(&oldstream[i].outqueue, sp, next); |
michael@0 | 12415 | TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next); |
michael@0 | 12416 | } |
michael@0 | 12417 | /* Now move assoc pointers too */ |
michael@0 | 12418 | if (stcb->asoc.last_out_stream == &oldstream[i]) { |
michael@0 | 12419 | stcb->asoc.last_out_stream = &stcb->asoc.strmout[i]; |
michael@0 | 12420 | } |
michael@0 | 12421 | if (stcb->asoc.locked_on_sending == &oldstream[i]) { |
michael@0 | 12422 | stcb->asoc.locked_on_sending = &stcb->asoc.strmout[i]; |
michael@0 | 12423 | } |
michael@0 | 12424 | } |
michael@0 | 12425 | /* now the new streams */ |
michael@0 | 12426 | stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); |
michael@0 | 12427 | for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + adding_o); i++) { |
michael@0 | 12428 | TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); |
michael@0 | 12429 | stcb->asoc.strmout[i].chunks_on_queues = 0; |
michael@0 | 12430 | stcb->asoc.strmout[i].next_sequence_send = 0x0; |
michael@0 | 12431 | stcb->asoc.strmout[i].stream_no = i; |
michael@0 | 12432 | stcb->asoc.strmout[i].last_msg_incomplete = 0; |
michael@0 | 12433 | stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], NULL); |
michael@0 | 12434 | } |
michael@0 | 12435 | stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + adding_o; |
michael@0 | 12436 | SCTP_FREE(oldstream, SCTP_M_STRMO); |
michael@0 | 12437 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 12438 | } |
michael@0 | 12439 | skip_stuff: |
michael@0 | 12440 | if ((add_stream & 1) && (adding_o > 0)) { |
michael@0 | 12441 | asoc->strm_pending_add_size = adding_o; |
michael@0 | 12442 | asoc->peer_req_out = peer_asked; |
michael@0 | 12443 | sctp_add_an_out_stream(chk, seq, adding_o); |
michael@0 | 12444 | seq++; |
michael@0 | 12445 | asoc->stream_reset_outstanding++; |
michael@0 | 12446 | } |
michael@0 | 12447 | if ((add_stream & 2) && (adding_i > 0)) { |
michael@0 | 12448 | sctp_add_an_in_stream(chk, seq, adding_i); |
michael@0 | 12449 | seq++; |
michael@0 | 12450 | asoc->stream_reset_outstanding++; |
michael@0 | 12451 | } |
michael@0 | 12452 | if (send_in_req) { |
michael@0 | 12453 | sctp_add_stream_reset_in(chk, number_entries, list, seq); |
michael@0 | 12454 | seq++; |
michael@0 | 12455 | asoc->stream_reset_outstanding++; |
michael@0 | 12456 | } |
michael@0 | 12457 | if (send_tsn_req) { |
michael@0 | 12458 | sctp_add_stream_reset_tsn(chk, seq); |
michael@0 | 12459 | asoc->stream_reset_outstanding++; |
michael@0 | 12460 | } |
michael@0 | 12461 | asoc->str_reset = chk; |
michael@0 | 12462 | /* insert the chunk for sending */ |
michael@0 | 12463 | TAILQ_INSERT_TAIL(&asoc->control_send_queue, |
michael@0 | 12464 | chk, |
michael@0 | 12465 | sctp_next); |
michael@0 | 12466 | asoc->ctrl_queue_cnt++; |
michael@0 | 12467 | sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo); |
michael@0 | 12468 | return (0); |
michael@0 | 12469 | } |
michael@0 | 12470 | |
michael@0 | 12471 | void |
michael@0 | 12472 | sctp_send_abort(struct mbuf *m, int iphlen, struct sockaddr *src, struct sockaddr *dst, |
michael@0 | 12473 | struct sctphdr *sh, uint32_t vtag, struct mbuf *cause, |
michael@0 | 12474 | #if defined(__FreeBSD__) |
michael@0 | 12475 | uint8_t use_mflowid, uint32_t mflowid, |
michael@0 | 12476 | #endif |
michael@0 | 12477 | uint32_t vrf_id, uint16_t port) |
michael@0 | 12478 | { |
michael@0 | 12479 | /* Don't respond to an ABORT with an ABORT. */ |
michael@0 | 12480 | if (sctp_is_there_an_abort_here(m, iphlen, &vtag)) { |
michael@0 | 12481 | if (cause) |
michael@0 | 12482 | sctp_m_freem(cause); |
michael@0 | 12483 | return; |
michael@0 | 12484 | } |
michael@0 | 12485 | sctp_send_resp_msg(src, dst, sh, vtag, SCTP_ABORT_ASSOCIATION, cause, |
michael@0 | 12486 | #if defined(__FreeBSD__) |
michael@0 | 12487 | use_mflowid, mflowid, |
michael@0 | 12488 | #endif |
michael@0 | 12489 | vrf_id, port); |
michael@0 | 12490 | return; |
michael@0 | 12491 | } |
michael@0 | 12492 | |
michael@0 | 12493 | void |
michael@0 | 12494 | sctp_send_operr_to(struct sockaddr *src, struct sockaddr *dst, |
michael@0 | 12495 | struct sctphdr *sh, uint32_t vtag, struct mbuf *cause, |
michael@0 | 12496 | #if defined(__FreeBSD__) |
michael@0 | 12497 | uint8_t use_mflowid, uint32_t mflowid, |
michael@0 | 12498 | #endif |
michael@0 | 12499 | uint32_t vrf_id, uint16_t port) |
michael@0 | 12500 | { |
michael@0 | 12501 | sctp_send_resp_msg(src, dst, sh, vtag, SCTP_OPERATION_ERROR, cause, |
michael@0 | 12502 | #if defined(__FreeBSD__) |
michael@0 | 12503 | use_mflowid, mflowid, |
michael@0 | 12504 | #endif |
michael@0 | 12505 | vrf_id, port); |
michael@0 | 12506 | return; |
michael@0 | 12507 | } |
michael@0 | 12508 | |
michael@0 | 12509 | static struct mbuf * |
michael@0 | 12510 | sctp_copy_resume(struct uio *uio, |
michael@0 | 12511 | int max_send_len, |
michael@0 | 12512 | #if defined(__FreeBSD__) && __FreeBSD_version > 602000 |
michael@0 | 12513 | int user_marks_eor, |
michael@0 | 12514 | #endif |
michael@0 | 12515 | int *error, |
michael@0 | 12516 | uint32_t *sndout, |
michael@0 | 12517 | struct mbuf **new_tail) |
michael@0 | 12518 | { |
michael@0 | 12519 | #if defined(__Panda__) |
michael@0 | 12520 | struct mbuf *m; |
michael@0 | 12521 | |
michael@0 | 12522 | m = m_uiotombuf(uio, M_WAITOK, max_send_len, 0, |
michael@0 | 12523 | (user_marks_eor ? M_EOR : 0)); |
michael@0 | 12524 | if (m == NULL) { |
michael@0 | 12525 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12526 | *error = ENOMEM; |
michael@0 | 12527 | } else { |
michael@0 | 12528 | *sndout = m_length(m, NULL); |
michael@0 | 12529 | *new_tail = m_last(m); |
michael@0 | 12530 | } |
michael@0 | 12531 | return (m); |
michael@0 | 12532 | #elif defined(__FreeBSD__) && __FreeBSD_version > 602000 |
michael@0 | 12533 | struct mbuf *m; |
michael@0 | 12534 | |
michael@0 | 12535 | m = m_uiotombuf(uio, M_WAITOK, max_send_len, 0, |
michael@0 | 12536 | (M_PKTHDR | (user_marks_eor ? M_EOR : 0))); |
michael@0 | 12537 | if (m == NULL) { |
michael@0 | 12538 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12539 | *error = ENOMEM; |
michael@0 | 12540 | } else { |
michael@0 | 12541 | *sndout = m_length(m, NULL); |
michael@0 | 12542 | *new_tail = m_last(m); |
michael@0 | 12543 | } |
michael@0 | 12544 | return (m); |
michael@0 | 12545 | #else |
michael@0 | 12546 | int left, cancpy, willcpy; |
michael@0 | 12547 | struct mbuf *m, *head; |
michael@0 | 12548 | |
michael@0 | 12549 | #if defined(__APPLE__) |
michael@0 | 12550 | #if defined(APPLE_LEOPARD) |
michael@0 | 12551 | left = min(uio->uio_resid, max_send_len); |
michael@0 | 12552 | #else |
michael@0 | 12553 | left = min(uio_resid(uio), max_send_len); |
michael@0 | 12554 | #endif |
michael@0 | 12555 | #else |
michael@0 | 12556 | left = min(uio->uio_resid, max_send_len); |
michael@0 | 12557 | #endif |
michael@0 | 12558 | /* Always get a header just in case */ |
michael@0 | 12559 | head = sctp_get_mbuf_for_msg(left, 0, M_WAITOK, 0, MT_DATA); |
michael@0 | 12560 | if (head == NULL) { |
michael@0 | 12561 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12562 | *error = ENOMEM; |
michael@0 | 12563 | return (NULL); |
michael@0 | 12564 | } |
michael@0 | 12565 | cancpy = M_TRAILINGSPACE(head); |
michael@0 | 12566 | willcpy = min(cancpy, left); |
michael@0 | 12567 | *error = uiomove(mtod(head, caddr_t), willcpy, uio); |
michael@0 | 12568 | if (*error) { |
michael@0 | 12569 | sctp_m_freem(head); |
michael@0 | 12570 | return (NULL); |
michael@0 | 12571 | } |
michael@0 | 12572 | *sndout += willcpy; |
michael@0 | 12573 | left -= willcpy; |
michael@0 | 12574 | SCTP_BUF_LEN(head) = willcpy; |
michael@0 | 12575 | m = head; |
michael@0 | 12576 | *new_tail = head; |
michael@0 | 12577 | while (left > 0) { |
michael@0 | 12578 | /* move in user data */ |
michael@0 | 12579 | SCTP_BUF_NEXT(m) = sctp_get_mbuf_for_msg(left, 0, M_WAITOK, 0, MT_DATA); |
michael@0 | 12580 | if (SCTP_BUF_NEXT(m) == NULL) { |
michael@0 | 12581 | sctp_m_freem(head); |
michael@0 | 12582 | *new_tail = NULL; |
michael@0 | 12583 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12584 | *error = ENOMEM; |
michael@0 | 12585 | return (NULL); |
michael@0 | 12586 | } |
michael@0 | 12587 | m = SCTP_BUF_NEXT(m); |
michael@0 | 12588 | cancpy = M_TRAILINGSPACE(m); |
michael@0 | 12589 | willcpy = min(cancpy, left); |
michael@0 | 12590 | *error = uiomove(mtod(m, caddr_t), willcpy, uio); |
michael@0 | 12591 | if (*error) { |
michael@0 | 12592 | sctp_m_freem(head); |
michael@0 | 12593 | *new_tail = NULL; |
michael@0 | 12594 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, EFAULT); |
michael@0 | 12595 | *error = EFAULT; |
michael@0 | 12596 | return (NULL); |
michael@0 | 12597 | } |
michael@0 | 12598 | SCTP_BUF_LEN(m) = willcpy; |
michael@0 | 12599 | left -= willcpy; |
michael@0 | 12600 | *sndout += willcpy; |
michael@0 | 12601 | *new_tail = m; |
michael@0 | 12602 | if (left == 0) { |
michael@0 | 12603 | SCTP_BUF_NEXT(m) = NULL; |
michael@0 | 12604 | } |
michael@0 | 12605 | } |
michael@0 | 12606 | return (head); |
michael@0 | 12607 | #endif |
michael@0 | 12608 | } |
michael@0 | 12609 | |
michael@0 | 12610 | static int |
michael@0 | 12611 | sctp_copy_one(struct sctp_stream_queue_pending *sp, |
michael@0 | 12612 | struct uio *uio, |
michael@0 | 12613 | int resv_upfront) |
michael@0 | 12614 | { |
michael@0 | 12615 | int left; |
michael@0 | 12616 | #if defined(__Panda__) |
michael@0 | 12617 | left = sp->length; |
michael@0 | 12618 | sp->data = m_uiotombuf(uio, M_WAITOK, sp->length, |
michael@0 | 12619 | resv_upfront, 0); |
michael@0 | 12620 | if (sp->data == NULL) { |
michael@0 | 12621 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12622 | return (ENOMEM); |
michael@0 | 12623 | } |
michael@0 | 12624 | |
michael@0 | 12625 | sp->tail_mbuf = m_last(sp->data); |
michael@0 | 12626 | return (0); |
michael@0 | 12627 | |
michael@0 | 12628 | #elif defined(__FreeBSD__) && __FreeBSD_version > 602000 |
michael@0 | 12629 | left = sp->length; |
michael@0 | 12630 | sp->data = m_uiotombuf(uio, M_WAITOK, sp->length, |
michael@0 | 12631 | resv_upfront, 0); |
michael@0 | 12632 | if (sp->data == NULL) { |
michael@0 | 12633 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12634 | return (ENOMEM); |
michael@0 | 12635 | } |
michael@0 | 12636 | |
michael@0 | 12637 | sp->tail_mbuf = m_last(sp->data); |
michael@0 | 12638 | return (0); |
michael@0 | 12639 | #else |
michael@0 | 12640 | int cancpy, willcpy, error; |
michael@0 | 12641 | struct mbuf *m, *head; |
michael@0 | 12642 | int cpsz = 0; |
michael@0 | 12643 | |
michael@0 | 12644 | /* First one gets a header */ |
michael@0 | 12645 | left = sp->length; |
michael@0 | 12646 | head = m = sctp_get_mbuf_for_msg((left + resv_upfront), 0, M_WAITOK, 0, MT_DATA); |
michael@0 | 12647 | if (m == NULL) { |
michael@0 | 12648 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12649 | return (ENOMEM); |
michael@0 | 12650 | } |
michael@0 | 12651 | /*- |
michael@0 | 12652 | * Add this one for m in now, that way if the alloc fails we won't |
michael@0 | 12653 | * have a bad cnt. |
michael@0 | 12654 | */ |
michael@0 | 12655 | SCTP_BUF_RESV_UF(m, resv_upfront); |
michael@0 | 12656 | cancpy = M_TRAILINGSPACE(m); |
michael@0 | 12657 | willcpy = min(cancpy, left); |
michael@0 | 12658 | while (left > 0) { |
michael@0 | 12659 | /* move in user data */ |
michael@0 | 12660 | error = uiomove(mtod(m, caddr_t), willcpy, uio); |
michael@0 | 12661 | if (error) { |
michael@0 | 12662 | sctp_m_freem(head); |
michael@0 | 12663 | return (error); |
michael@0 | 12664 | } |
michael@0 | 12665 | SCTP_BUF_LEN(m) = willcpy; |
michael@0 | 12666 | left -= willcpy; |
michael@0 | 12667 | cpsz += willcpy; |
michael@0 | 12668 | if (left > 0) { |
michael@0 | 12669 | SCTP_BUF_NEXT(m) = sctp_get_mbuf_for_msg(left, 0, M_WAITOK, 0, MT_DATA); |
michael@0 | 12670 | if (SCTP_BUF_NEXT(m) == NULL) { |
michael@0 | 12671 | /* |
michael@0 | 12672 | * the head goes back to caller, he can free |
michael@0 | 12673 | * the rest |
michael@0 | 12674 | */ |
michael@0 | 12675 | sctp_m_freem(head); |
michael@0 | 12676 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12677 | return (ENOMEM); |
michael@0 | 12678 | } |
michael@0 | 12679 | m = SCTP_BUF_NEXT(m); |
michael@0 | 12680 | cancpy = M_TRAILINGSPACE(m); |
michael@0 | 12681 | willcpy = min(cancpy, left); |
michael@0 | 12682 | } else { |
michael@0 | 12683 | sp->tail_mbuf = m; |
michael@0 | 12684 | SCTP_BUF_NEXT(m) = NULL; |
michael@0 | 12685 | } |
michael@0 | 12686 | } |
michael@0 | 12687 | sp->data = head; |
michael@0 | 12688 | sp->length = cpsz; |
michael@0 | 12689 | return (0); |
michael@0 | 12690 | #endif |
michael@0 | 12691 | } |
michael@0 | 12692 | |
michael@0 | 12693 | |
michael@0 | 12694 | |
michael@0 | 12695 | static struct sctp_stream_queue_pending * |
michael@0 | 12696 | sctp_copy_it_in(struct sctp_tcb *stcb, |
michael@0 | 12697 | struct sctp_association *asoc, |
michael@0 | 12698 | struct sctp_sndrcvinfo *srcv, |
michael@0 | 12699 | struct uio *uio, |
michael@0 | 12700 | struct sctp_nets *net, |
michael@0 | 12701 | int max_send_len, |
michael@0 | 12702 | int user_marks_eor, |
michael@0 | 12703 | int *error) |
michael@0 | 12704 | |
michael@0 | 12705 | { |
michael@0 | 12706 | /*- |
michael@0 | 12707 | * This routine must be very careful in its work. Protocol |
michael@0 | 12708 | * processing is up and running so care must be taken to spl...() |
michael@0 | 12709 | * when you need to do something that may effect the stcb/asoc. The |
michael@0 | 12710 | * sb is locked however. When data is copied the protocol processing |
michael@0 | 12711 | * should be enabled since this is a slower operation... |
michael@0 | 12712 | */ |
michael@0 | 12713 | struct sctp_stream_queue_pending *sp = NULL; |
michael@0 | 12714 | int resv_in_first; |
michael@0 | 12715 | |
michael@0 | 12716 | *error = 0; |
michael@0 | 12717 | /* Now can we send this? */ |
michael@0 | 12718 | if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) || |
michael@0 | 12719 | (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_ACK_SENT) || |
michael@0 | 12720 | (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) || |
michael@0 | 12721 | (asoc->state & SCTP_STATE_SHUTDOWN_PENDING)) { |
michael@0 | 12722 | /* got data while shutting down */ |
michael@0 | 12723 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ECONNRESET); |
michael@0 | 12724 | *error = ECONNRESET; |
michael@0 | 12725 | goto out_now; |
michael@0 | 12726 | } |
michael@0 | 12727 | sctp_alloc_a_strmoq(stcb, sp); |
michael@0 | 12728 | if (sp == NULL) { |
michael@0 | 12729 | SCTP_LTRACE_ERR_RET(NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 12730 | *error = ENOMEM; |
michael@0 | 12731 | goto out_now; |
michael@0 | 12732 | } |
michael@0 | 12733 | sp->act_flags = 0; |
michael@0 | 12734 | sp->sender_all_done = 0; |
michael@0 | 12735 | sp->sinfo_flags = srcv->sinfo_flags; |
michael@0 | 12736 | sp->timetolive = srcv->sinfo_timetolive; |
michael@0 | 12737 | sp->ppid = srcv->sinfo_ppid; |
michael@0 | 12738 | sp->context = srcv->sinfo_context; |
michael@0 | 12739 | (void)SCTP_GETTIME_TIMEVAL(&sp->ts); |
michael@0 | 12740 | |
michael@0 | 12741 | sp->stream = srcv->sinfo_stream; |
michael@0 | 12742 | #if defined(__APPLE__) |
michael@0 | 12743 | #if defined(APPLE_LEOPARD) |
michael@0 | 12744 | sp->length = min(uio->uio_resid, max_send_len); |
michael@0 | 12745 | #else |
michael@0 | 12746 | sp->length = min(uio_resid(uio), max_send_len); |
michael@0 | 12747 | #endif |
michael@0 | 12748 | #else |
michael@0 | 12749 | sp->length = min(uio->uio_resid, max_send_len); |
michael@0 | 12750 | #endif |
michael@0 | 12751 | #if defined(__APPLE__) |
michael@0 | 12752 | #if defined(APPLE_LEOPARD) |
michael@0 | 12753 | if ((sp->length == (uint32_t)uio->uio_resid) && |
michael@0 | 12754 | #else |
michael@0 | 12755 | if ((sp->length == (uint32_t)uio_resid(uio)) && |
michael@0 | 12756 | #endif |
michael@0 | 12757 | #else |
michael@0 | 12758 | if ((sp->length == (uint32_t)uio->uio_resid) && |
michael@0 | 12759 | #endif |
michael@0 | 12760 | ((user_marks_eor == 0) || |
michael@0 | 12761 | (srcv->sinfo_flags & SCTP_EOF) || |
michael@0 | 12762 | (user_marks_eor && (srcv->sinfo_flags & SCTP_EOR)))) { |
michael@0 | 12763 | sp->msg_is_complete = 1; |
michael@0 | 12764 | } else { |
michael@0 | 12765 | sp->msg_is_complete = 0; |
michael@0 | 12766 | } |
michael@0 | 12767 | sp->sender_all_done = 0; |
michael@0 | 12768 | sp->some_taken = 0; |
michael@0 | 12769 | sp->put_last_out = 0; |
michael@0 | 12770 | resv_in_first = sizeof(struct sctp_data_chunk); |
michael@0 | 12771 | sp->data = sp->tail_mbuf = NULL; |
michael@0 | 12772 | if (sp->length == 0) { |
michael@0 | 12773 | *error = 0; |
michael@0 | 12774 | goto skip_copy; |
michael@0 | 12775 | } |
michael@0 | 12776 | if (srcv->sinfo_keynumber_valid) { |
michael@0 | 12777 | sp->auth_keyid = srcv->sinfo_keynumber; |
michael@0 | 12778 | } else { |
michael@0 | 12779 | sp->auth_keyid = stcb->asoc.authinfo.active_keyid; |
michael@0 | 12780 | } |
michael@0 | 12781 | if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) { |
michael@0 | 12782 | sctp_auth_key_acquire(stcb, sp->auth_keyid); |
michael@0 | 12783 | sp->holds_key_ref = 1; |
michael@0 | 12784 | } |
michael@0 | 12785 | #if defined(__APPLE__) |
michael@0 | 12786 | SCTP_SOCKET_UNLOCK(SCTP_INP_SO(stcb->sctp_ep), 0); |
michael@0 | 12787 | #endif |
michael@0 | 12788 | *error = sctp_copy_one(sp, uio, resv_in_first); |
michael@0 | 12789 | #if defined(__APPLE__) |
michael@0 | 12790 | SCTP_SOCKET_LOCK(SCTP_INP_SO(stcb->sctp_ep), 0); |
michael@0 | 12791 | #endif |
michael@0 | 12792 | skip_copy: |
michael@0 | 12793 | if (*error) { |
michael@0 | 12794 | sctp_free_a_strmoq(stcb, sp, SCTP_SO_LOCKED); |
michael@0 | 12795 | sp = NULL; |
michael@0 | 12796 | } else { |
michael@0 | 12797 | if (sp->sinfo_flags & SCTP_ADDR_OVER) { |
michael@0 | 12798 | sp->net = net; |
michael@0 | 12799 | atomic_add_int(&sp->net->ref_count, 1); |
michael@0 | 12800 | } else { |
michael@0 | 12801 | sp->net = NULL; |
michael@0 | 12802 | } |
michael@0 | 12803 | sctp_set_prsctp_policy(sp); |
michael@0 | 12804 | } |
michael@0 | 12805 | out_now: |
michael@0 | 12806 | return (sp); |
michael@0 | 12807 | } |
michael@0 | 12808 | |
michael@0 | 12809 | |
michael@0 | 12810 | int |
michael@0 | 12811 | sctp_sosend(struct socket *so, |
michael@0 | 12812 | struct sockaddr *addr, |
michael@0 | 12813 | struct uio *uio, |
michael@0 | 12814 | #ifdef __Panda__ |
michael@0 | 12815 | pakhandle_type top, |
michael@0 | 12816 | pakhandle_type icontrol, |
michael@0 | 12817 | #else |
michael@0 | 12818 | struct mbuf *top, |
michael@0 | 12819 | struct mbuf *control, |
michael@0 | 12820 | #endif |
michael@0 | 12821 | #if defined(__APPLE__) || defined(__Panda__) |
michael@0 | 12822 | int flags |
michael@0 | 12823 | #else |
michael@0 | 12824 | int flags, |
michael@0 | 12825 | #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 |
michael@0 | 12826 | struct thread *p |
michael@0 | 12827 | #elif defined(__Windows__) |
michael@0 | 12828 | PKTHREAD p |
michael@0 | 12829 | #else |
michael@0 | 12830 | #if defined(__Userspace__) |
michael@0 | 12831 | /* |
michael@0 | 12832 | * proc is a dummy in __Userspace__ and will not be passed |
michael@0 | 12833 | * to sctp_lower_sosend |
michael@0 | 12834 | */ |
michael@0 | 12835 | #endif |
michael@0 | 12836 | struct proc *p |
michael@0 | 12837 | #endif |
michael@0 | 12838 | #endif |
michael@0 | 12839 | ) |
michael@0 | 12840 | { |
michael@0 | 12841 | #ifdef __Panda__ |
michael@0 | 12842 | struct mbuf *control = NULL; |
michael@0 | 12843 | #endif |
michael@0 | 12844 | #if defined(__APPLE__) |
michael@0 | 12845 | struct proc *p = current_proc(); |
michael@0 | 12846 | #endif |
michael@0 | 12847 | int error, use_sndinfo = 0; |
michael@0 | 12848 | struct sctp_sndrcvinfo sndrcvninfo; |
michael@0 | 12849 | struct sockaddr *addr_to_use; |
michael@0 | 12850 | #if defined(INET) && defined(INET6) |
michael@0 | 12851 | struct sockaddr_in sin; |
michael@0 | 12852 | #endif |
michael@0 | 12853 | |
michael@0 | 12854 | #if defined(__APPLE__) |
michael@0 | 12855 | SCTP_SOCKET_LOCK(so, 1); |
michael@0 | 12856 | #endif |
michael@0 | 12857 | #ifdef __Panda__ |
michael@0 | 12858 | control = SCTP_HEADER_TO_CHAIN(icontrol); |
michael@0 | 12859 | #endif |
michael@0 | 12860 | if (control) { |
michael@0 | 12861 | /* process cmsg snd/rcv info (maybe a assoc-id) */ |
michael@0 | 12862 | if (sctp_find_cmsg(SCTP_SNDRCV, (void *)&sndrcvninfo, control, |
michael@0 | 12863 | sizeof(sndrcvninfo))) { |
michael@0 | 12864 | /* got one */ |
michael@0 | 12865 | use_sndinfo = 1; |
michael@0 | 12866 | } |
michael@0 | 12867 | } |
michael@0 | 12868 | addr_to_use = addr; |
michael@0 | 12869 | #if defined(INET) && defined(INET6) |
michael@0 | 12870 | if ((addr) && (addr->sa_family == AF_INET6)) { |
michael@0 | 12871 | struct sockaddr_in6 *sin6; |
michael@0 | 12872 | |
michael@0 | 12873 | sin6 = (struct sockaddr_in6 *)addr; |
michael@0 | 12874 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
michael@0 | 12875 | in6_sin6_2_sin(&sin, sin6); |
michael@0 | 12876 | addr_to_use = (struct sockaddr *)&sin; |
michael@0 | 12877 | } |
michael@0 | 12878 | } |
michael@0 | 12879 | #endif |
michael@0 | 12880 | error = sctp_lower_sosend(so, addr_to_use, uio, top, |
michael@0 | 12881 | #ifdef __Panda__ |
michael@0 | 12882 | icontrol, |
michael@0 | 12883 | #else |
michael@0 | 12884 | control, |
michael@0 | 12885 | #endif |
michael@0 | 12886 | flags, |
michael@0 | 12887 | use_sndinfo ? &sndrcvninfo: NULL |
michael@0 | 12888 | #if !(defined(__Panda__) || defined(__Userspace__)) |
michael@0 | 12889 | , p |
michael@0 | 12890 | #endif |
michael@0 | 12891 | ); |
michael@0 | 12892 | #if defined(__APPLE__) |
michael@0 | 12893 | SCTP_SOCKET_UNLOCK(so, 1); |
michael@0 | 12894 | #endif |
michael@0 | 12895 | return (error); |
michael@0 | 12896 | } |
michael@0 | 12897 | |
michael@0 | 12898 | |
michael@0 | 12899 | int |
michael@0 | 12900 | sctp_lower_sosend(struct socket *so, |
michael@0 | 12901 | struct sockaddr *addr, |
michael@0 | 12902 | struct uio *uio, |
michael@0 | 12903 | #ifdef __Panda__ |
michael@0 | 12904 | pakhandle_type i_pak, |
michael@0 | 12905 | pakhandle_type i_control, |
michael@0 | 12906 | #else |
michael@0 | 12907 | struct mbuf *i_pak, |
michael@0 | 12908 | struct mbuf *control, |
michael@0 | 12909 | #endif |
michael@0 | 12910 | int flags, |
michael@0 | 12911 | struct sctp_sndrcvinfo *srcv |
michael@0 | 12912 | #if !(defined( __Panda__) || defined(__Userspace__)) |
michael@0 | 12913 | , |
michael@0 | 12914 | #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 |
michael@0 | 12915 | struct thread *p |
michael@0 | 12916 | #elif defined(__Windows__) |
michael@0 | 12917 | PKTHREAD p |
michael@0 | 12918 | #else |
michael@0 | 12919 | struct proc *p |
michael@0 | 12920 | #endif |
michael@0 | 12921 | #endif |
michael@0 | 12922 | ) |
michael@0 | 12923 | { |
michael@0 | 12924 | unsigned int sndlen = 0, max_len; |
michael@0 | 12925 | int error, len; |
michael@0 | 12926 | struct mbuf *top = NULL; |
michael@0 | 12927 | #ifdef __Panda__ |
michael@0 | 12928 | struct mbuf *control = NULL; |
michael@0 | 12929 | #endif |
michael@0 | 12930 | int queue_only = 0, queue_only_for_init = 0; |
michael@0 | 12931 | int free_cnt_applied = 0; |
michael@0 | 12932 | int un_sent; |
michael@0 | 12933 | int now_filled = 0; |
michael@0 | 12934 | unsigned int inqueue_bytes = 0; |
michael@0 | 12935 | struct sctp_block_entry be; |
michael@0 | 12936 | struct sctp_inpcb *inp; |
michael@0 | 12937 | struct sctp_tcb *stcb = NULL; |
michael@0 | 12938 | struct timeval now; |
michael@0 | 12939 | struct sctp_nets *net; |
michael@0 | 12940 | struct sctp_association *asoc; |
michael@0 | 12941 | struct sctp_inpcb *t_inp; |
michael@0 | 12942 | int user_marks_eor; |
michael@0 | 12943 | int create_lock_applied = 0; |
michael@0 | 12944 | int nagle_applies = 0; |
michael@0 | 12945 | int some_on_control = 0; |
michael@0 | 12946 | int got_all_of_the_send = 0; |
michael@0 | 12947 | int hold_tcblock = 0; |
michael@0 | 12948 | int non_blocking = 0; |
michael@0 | 12949 | uint32_t local_add_more, local_soresv = 0; |
michael@0 | 12950 | uint16_t port; |
michael@0 | 12951 | uint16_t sinfo_flags; |
michael@0 | 12952 | sctp_assoc_t sinfo_assoc_id; |
michael@0 | 12953 | |
michael@0 | 12954 | error = 0; |
michael@0 | 12955 | net = NULL; |
michael@0 | 12956 | stcb = NULL; |
michael@0 | 12957 | asoc = NULL; |
michael@0 | 12958 | |
michael@0 | 12959 | #if defined(__APPLE__) |
michael@0 | 12960 | sctp_lock_assert(so); |
michael@0 | 12961 | #endif |
michael@0 | 12962 | t_inp = inp = (struct sctp_inpcb *)so->so_pcb; |
michael@0 | 12963 | if (inp == NULL) { |
michael@0 | 12964 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 12965 | error = EINVAL; |
michael@0 | 12966 | if (i_pak) { |
michael@0 | 12967 | SCTP_RELEASE_PKT(i_pak); |
michael@0 | 12968 | } |
michael@0 | 12969 | return (error); |
michael@0 | 12970 | } |
michael@0 | 12971 | if ((uio == NULL) && (i_pak == NULL)) { |
michael@0 | 12972 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 12973 | return (EINVAL); |
michael@0 | 12974 | } |
michael@0 | 12975 | user_marks_eor = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR); |
michael@0 | 12976 | atomic_add_int(&inp->total_sends, 1); |
michael@0 | 12977 | if (uio) { |
michael@0 | 12978 | #if defined(__APPLE__) |
michael@0 | 12979 | #if defined(APPLE_LEOPARD) |
michael@0 | 12980 | if (uio->uio_resid < 0) { |
michael@0 | 12981 | #else |
michael@0 | 12982 | if (uio_resid(uio) < 0) { |
michael@0 | 12983 | #endif |
michael@0 | 12984 | #else |
michael@0 | 12985 | if (uio->uio_resid < 0) { |
michael@0 | 12986 | #endif |
michael@0 | 12987 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 12988 | return (EINVAL); |
michael@0 | 12989 | } |
michael@0 | 12990 | #if defined(__APPLE__) |
michael@0 | 12991 | #if defined(APPLE_LEOPARD) |
michael@0 | 12992 | sndlen = uio->uio_resid; |
michael@0 | 12993 | #else |
michael@0 | 12994 | sndlen = uio_resid(uio); |
michael@0 | 12995 | #endif |
michael@0 | 12996 | #else |
michael@0 | 12997 | sndlen = uio->uio_resid; |
michael@0 | 12998 | #endif |
michael@0 | 12999 | } else { |
michael@0 | 13000 | top = SCTP_HEADER_TO_CHAIN(i_pak); |
michael@0 | 13001 | #ifdef __Panda__ |
michael@0 | 13002 | /*- |
michael@0 | 13003 | * app len indicates the datalen, dgsize for cases |
michael@0 | 13004 | * of SCTP_EOF/ABORT will not have the right len |
michael@0 | 13005 | */ |
michael@0 | 13006 | sndlen = SCTP_APP_DATA_LEN(i_pak); |
michael@0 | 13007 | /*- |
michael@0 | 13008 | * Set the particle len also to zero to match |
michael@0 | 13009 | * up with app len. We only have one particle |
michael@0 | 13010 | * if app len is zero for Panda. This is ensured |
michael@0 | 13011 | * in the socket lib |
michael@0 | 13012 | */ |
michael@0 | 13013 | if (sndlen == 0) { |
michael@0 | 13014 | SCTP_BUF_LEN(top) = 0; |
michael@0 | 13015 | } |
michael@0 | 13016 | /*- |
michael@0 | 13017 | * We delink the chain from header, but keep |
michael@0 | 13018 | * the header around as we will need it in |
michael@0 | 13019 | * EAGAIN case |
michael@0 | 13020 | */ |
michael@0 | 13021 | SCTP_DETACH_HEADER_FROM_CHAIN(i_pak); |
michael@0 | 13022 | #else |
michael@0 | 13023 | sndlen = SCTP_HEADER_LEN(i_pak); |
michael@0 | 13024 | #endif |
michael@0 | 13025 | } |
michael@0 | 13026 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "Send called addr:%p send length %d\n", |
michael@0 | 13027 | (void *)addr, |
michael@0 | 13028 | sndlen); |
michael@0 | 13029 | #ifdef __Panda__ |
michael@0 | 13030 | if (i_control) { |
michael@0 | 13031 | control = SCTP_HEADER_TO_CHAIN(i_control); |
michael@0 | 13032 | } |
michael@0 | 13033 | #endif |
michael@0 | 13034 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && |
michael@0 | 13035 | (inp->sctp_socket->so_qlimit)) { |
michael@0 | 13036 | /* The listener can NOT send */ |
michael@0 | 13037 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, ENOTCONN); |
michael@0 | 13038 | error = ENOTCONN; |
michael@0 | 13039 | goto out_unlocked; |
michael@0 | 13040 | } |
michael@0 | 13041 | /** |
michael@0 | 13042 | * Pre-screen address, if one is given the sin-len |
michael@0 | 13043 | * must be set correctly! |
michael@0 | 13044 | */ |
michael@0 | 13045 | if (addr) { |
michael@0 | 13046 | union sctp_sockstore *raddr = (union sctp_sockstore *)addr; |
michael@0 | 13047 | switch (raddr->sa.sa_family) { |
michael@0 | 13048 | #ifdef INET |
michael@0 | 13049 | case AF_INET: |
michael@0 | 13050 | #ifdef HAVE_SIN_LEN |
michael@0 | 13051 | if (raddr->sin.sin_len != sizeof(struct sockaddr_in)) { |
michael@0 | 13052 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13053 | error = EINVAL; |
michael@0 | 13054 | goto out_unlocked; |
michael@0 | 13055 | } |
michael@0 | 13056 | #endif |
michael@0 | 13057 | port = raddr->sin.sin_port; |
michael@0 | 13058 | break; |
michael@0 | 13059 | #endif |
michael@0 | 13060 | #ifdef INET6 |
michael@0 | 13061 | case AF_INET6: |
michael@0 | 13062 | #ifdef HAVE_SIN6_LEN |
michael@0 | 13063 | if (raddr->sin6.sin6_len != sizeof(struct sockaddr_in6)) { |
michael@0 | 13064 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13065 | error = EINVAL; |
michael@0 | 13066 | goto out_unlocked; |
michael@0 | 13067 | } |
michael@0 | 13068 | #endif |
michael@0 | 13069 | port = raddr->sin6.sin6_port; |
michael@0 | 13070 | break; |
michael@0 | 13071 | #endif |
michael@0 | 13072 | #if defined(__Userspace__) |
michael@0 | 13073 | case AF_CONN: |
michael@0 | 13074 | #ifdef HAVE_SCONN_LEN |
michael@0 | 13075 | if (raddr->sconn.sconn_len != sizeof(struct sockaddr_conn)) { |
michael@0 | 13076 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13077 | error = EINVAL; |
michael@0 | 13078 | goto out_unlocked; |
michael@0 | 13079 | } |
michael@0 | 13080 | #endif |
michael@0 | 13081 | port = raddr->sconn.sconn_port; |
michael@0 | 13082 | break; |
michael@0 | 13083 | #endif |
michael@0 | 13084 | default: |
michael@0 | 13085 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EAFNOSUPPORT); |
michael@0 | 13086 | error = EAFNOSUPPORT; |
michael@0 | 13087 | goto out_unlocked; |
michael@0 | 13088 | } |
michael@0 | 13089 | } else |
michael@0 | 13090 | port = 0; |
michael@0 | 13091 | |
michael@0 | 13092 | if (srcv) { |
michael@0 | 13093 | sinfo_flags = srcv->sinfo_flags; |
michael@0 | 13094 | sinfo_assoc_id = srcv->sinfo_assoc_id; |
michael@0 | 13095 | if (INVALID_SINFO_FLAG(sinfo_flags) || |
michael@0 | 13096 | PR_SCTP_INVALID_POLICY(sinfo_flags)) { |
michael@0 | 13097 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13098 | error = EINVAL; |
michael@0 | 13099 | goto out_unlocked; |
michael@0 | 13100 | } |
michael@0 | 13101 | if (srcv->sinfo_flags) |
michael@0 | 13102 | SCTP_STAT_INCR(sctps_sends_with_flags); |
michael@0 | 13103 | } else { |
michael@0 | 13104 | sinfo_flags = inp->def_send.sinfo_flags; |
michael@0 | 13105 | sinfo_assoc_id = inp->def_send.sinfo_assoc_id; |
michael@0 | 13106 | } |
michael@0 | 13107 | if (sinfo_flags & SCTP_SENDALL) { |
michael@0 | 13108 | /* its a sendall */ |
michael@0 | 13109 | error = sctp_sendall(inp, uio, top, srcv); |
michael@0 | 13110 | top = NULL; |
michael@0 | 13111 | goto out_unlocked; |
michael@0 | 13112 | } |
michael@0 | 13113 | if ((sinfo_flags & SCTP_ADDR_OVER) && (addr == NULL)) { |
michael@0 | 13114 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13115 | error = EINVAL; |
michael@0 | 13116 | goto out_unlocked; |
michael@0 | 13117 | } |
michael@0 | 13118 | /* now we must find the assoc */ |
michael@0 | 13119 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) || |
michael@0 | 13120 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
michael@0 | 13121 | SCTP_INP_RLOCK(inp); |
michael@0 | 13122 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
michael@0 | 13123 | if (stcb) { |
michael@0 | 13124 | SCTP_TCB_LOCK(stcb); |
michael@0 | 13125 | hold_tcblock = 1; |
michael@0 | 13126 | } |
michael@0 | 13127 | SCTP_INP_RUNLOCK(inp); |
michael@0 | 13128 | } else if (sinfo_assoc_id) { |
michael@0 | 13129 | stcb = sctp_findassociation_ep_asocid(inp, sinfo_assoc_id, 0); |
michael@0 | 13130 | } else if (addr) { |
michael@0 | 13131 | /*- |
michael@0 | 13132 | * Since we did not use findep we must |
michael@0 | 13133 | * increment it, and if we don't find a tcb |
michael@0 | 13134 | * decrement it. |
michael@0 | 13135 | */ |
michael@0 | 13136 | SCTP_INP_WLOCK(inp); |
michael@0 | 13137 | SCTP_INP_INCR_REF(inp); |
michael@0 | 13138 | SCTP_INP_WUNLOCK(inp); |
michael@0 | 13139 | stcb = sctp_findassociation_ep_addr(&t_inp, addr, &net, NULL, NULL); |
michael@0 | 13140 | if (stcb == NULL) { |
michael@0 | 13141 | SCTP_INP_WLOCK(inp); |
michael@0 | 13142 | SCTP_INP_DECR_REF(inp); |
michael@0 | 13143 | SCTP_INP_WUNLOCK(inp); |
michael@0 | 13144 | } else { |
michael@0 | 13145 | hold_tcblock = 1; |
michael@0 | 13146 | } |
michael@0 | 13147 | } |
michael@0 | 13148 | if ((stcb == NULL) && (addr)) { |
michael@0 | 13149 | /* Possible implicit send? */ |
michael@0 | 13150 | SCTP_ASOC_CREATE_LOCK(inp); |
michael@0 | 13151 | create_lock_applied = 1; |
michael@0 | 13152 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || |
michael@0 | 13153 | (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE)) { |
michael@0 | 13154 | /* Should I really unlock ? */ |
michael@0 | 13155 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13156 | error = EINVAL; |
michael@0 | 13157 | goto out_unlocked; |
michael@0 | 13158 | |
michael@0 | 13159 | } |
michael@0 | 13160 | if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && |
michael@0 | 13161 | (addr->sa_family == AF_INET6)) { |
michael@0 | 13162 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13163 | error = EINVAL; |
michael@0 | 13164 | goto out_unlocked; |
michael@0 | 13165 | } |
michael@0 | 13166 | SCTP_INP_WLOCK(inp); |
michael@0 | 13167 | SCTP_INP_INCR_REF(inp); |
michael@0 | 13168 | SCTP_INP_WUNLOCK(inp); |
michael@0 | 13169 | /* With the lock applied look again */ |
michael@0 | 13170 | stcb = sctp_findassociation_ep_addr(&t_inp, addr, &net, NULL, NULL); |
michael@0 | 13171 | if ((stcb == NULL) && (control != NULL) && (port > 0)) { |
michael@0 | 13172 | stcb = sctp_findassociation_cmsgs(&t_inp, port, control, &net, &error); |
michael@0 | 13173 | } |
michael@0 | 13174 | if (stcb == NULL) { |
michael@0 | 13175 | SCTP_INP_WLOCK(inp); |
michael@0 | 13176 | SCTP_INP_DECR_REF(inp); |
michael@0 | 13177 | SCTP_INP_WUNLOCK(inp); |
michael@0 | 13178 | } else { |
michael@0 | 13179 | hold_tcblock = 1; |
michael@0 | 13180 | } |
michael@0 | 13181 | if (error) { |
michael@0 | 13182 | goto out_unlocked; |
michael@0 | 13183 | } |
michael@0 | 13184 | if (t_inp != inp) { |
michael@0 | 13185 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, ENOTCONN); |
michael@0 | 13186 | error = ENOTCONN; |
michael@0 | 13187 | goto out_unlocked; |
michael@0 | 13188 | } |
michael@0 | 13189 | } |
michael@0 | 13190 | if (stcb == NULL) { |
michael@0 | 13191 | if (addr == NULL) { |
michael@0 | 13192 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, ENOENT); |
michael@0 | 13193 | error = ENOENT; |
michael@0 | 13194 | goto out_unlocked; |
michael@0 | 13195 | } else { |
michael@0 | 13196 | /* We must go ahead and start the INIT process */ |
michael@0 | 13197 | uint32_t vrf_id; |
michael@0 | 13198 | |
michael@0 | 13199 | if ((sinfo_flags & SCTP_ABORT) || |
michael@0 | 13200 | ((sinfo_flags & SCTP_EOF) && (sndlen == 0))) { |
michael@0 | 13201 | /*- |
michael@0 | 13202 | * User asks to abort a non-existant assoc, |
michael@0 | 13203 | * or EOF a non-existant assoc with no data |
michael@0 | 13204 | */ |
michael@0 | 13205 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, ENOENT); |
michael@0 | 13206 | error = ENOENT; |
michael@0 | 13207 | goto out_unlocked; |
michael@0 | 13208 | } |
michael@0 | 13209 | /* get an asoc/stcb struct */ |
michael@0 | 13210 | vrf_id = inp->def_vrf_id; |
michael@0 | 13211 | #ifdef INVARIANTS |
michael@0 | 13212 | if (create_lock_applied == 0) { |
michael@0 | 13213 | panic("Error, should hold create lock and I don't?"); |
michael@0 | 13214 | } |
michael@0 | 13215 | #endif |
michael@0 | 13216 | stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, |
michael@0 | 13217 | #if !(defined( __Panda__) || defined(__Userspace__)) |
michael@0 | 13218 | p |
michael@0 | 13219 | #else |
michael@0 | 13220 | (struct proc *)NULL |
michael@0 | 13221 | #endif |
michael@0 | 13222 | ); |
michael@0 | 13223 | if (stcb == NULL) { |
michael@0 | 13224 | /* Error is setup for us in the call */ |
michael@0 | 13225 | goto out_unlocked; |
michael@0 | 13226 | } |
michael@0 | 13227 | if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { |
michael@0 | 13228 | stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; |
michael@0 | 13229 | /* Set the connected flag so we can queue data */ |
michael@0 | 13230 | soisconnecting(so); |
michael@0 | 13231 | } |
michael@0 | 13232 | hold_tcblock = 1; |
michael@0 | 13233 | if (create_lock_applied) { |
michael@0 | 13234 | SCTP_ASOC_CREATE_UNLOCK(inp); |
michael@0 | 13235 | create_lock_applied = 0; |
michael@0 | 13236 | } else { |
michael@0 | 13237 | SCTP_PRINTF("Huh-3? create lock should have been on??\n"); |
michael@0 | 13238 | } |
michael@0 | 13239 | /* Turn on queue only flag to prevent data from being sent */ |
michael@0 | 13240 | queue_only = 1; |
michael@0 | 13241 | asoc = &stcb->asoc; |
michael@0 | 13242 | SCTP_SET_STATE(asoc, SCTP_STATE_COOKIE_WAIT); |
michael@0 | 13243 | (void)SCTP_GETTIME_TIMEVAL(&asoc->time_entered); |
michael@0 | 13244 | |
michael@0 | 13245 | /* initialize authentication params for the assoc */ |
michael@0 | 13246 | sctp_initialize_auth_params(inp, stcb); |
michael@0 | 13247 | |
michael@0 | 13248 | if (control) { |
michael@0 | 13249 | if (sctp_process_cmsgs_for_init(stcb, control, &error)) { |
michael@0 | 13250 | sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_OUTPUT + SCTP_LOC_7); |
michael@0 | 13251 | hold_tcblock = 0; |
michael@0 | 13252 | stcb = NULL; |
michael@0 | 13253 | goto out_unlocked; |
michael@0 | 13254 | } |
michael@0 | 13255 | } |
michael@0 | 13256 | /* out with the INIT */ |
michael@0 | 13257 | queue_only_for_init = 1; |
michael@0 | 13258 | /*- |
michael@0 | 13259 | * we may want to dig in after this call and adjust the MTU |
michael@0 | 13260 | * value. It defaulted to 1500 (constant) but the ro |
michael@0 | 13261 | * structure may now have an update and thus we may need to |
michael@0 | 13262 | * change it BEFORE we append the message. |
michael@0 | 13263 | */ |
michael@0 | 13264 | } |
michael@0 | 13265 | } else |
michael@0 | 13266 | asoc = &stcb->asoc; |
michael@0 | 13267 | if (srcv == NULL) |
michael@0 | 13268 | srcv = (struct sctp_sndrcvinfo *)&asoc->def_send; |
michael@0 | 13269 | if (srcv->sinfo_flags & SCTP_ADDR_OVER) { |
michael@0 | 13270 | if (addr) |
michael@0 | 13271 | net = sctp_findnet(stcb, addr); |
michael@0 | 13272 | else |
michael@0 | 13273 | net = NULL; |
michael@0 | 13274 | if ((net == NULL) || |
michael@0 | 13275 | ((port != 0) && (port != stcb->rport))) { |
michael@0 | 13276 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13277 | error = EINVAL; |
michael@0 | 13278 | goto out_unlocked; |
michael@0 | 13279 | } |
michael@0 | 13280 | } else { |
michael@0 | 13281 | if (stcb->asoc.alternate) { |
michael@0 | 13282 | net = stcb->asoc.alternate; |
michael@0 | 13283 | } else { |
michael@0 | 13284 | net = stcb->asoc.primary_destination; |
michael@0 | 13285 | } |
michael@0 | 13286 | } |
michael@0 | 13287 | atomic_add_int(&stcb->total_sends, 1); |
michael@0 | 13288 | /* Keep the stcb from being freed under our feet */ |
michael@0 | 13289 | atomic_add_int(&asoc->refcnt, 1); |
michael@0 | 13290 | free_cnt_applied = 1; |
michael@0 | 13291 | |
michael@0 | 13292 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT)) { |
michael@0 | 13293 | if (sndlen > asoc->smallest_mtu) { |
michael@0 | 13294 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EMSGSIZE); |
michael@0 | 13295 | error = EMSGSIZE; |
michael@0 | 13296 | goto out_unlocked; |
michael@0 | 13297 | } |
michael@0 | 13298 | } |
michael@0 | 13299 | #if defined(__Userspace__) |
michael@0 | 13300 | if (inp->recv_callback) { |
michael@0 | 13301 | non_blocking = 1; |
michael@0 | 13302 | } |
michael@0 | 13303 | #else |
michael@0 | 13304 | if (SCTP_SO_IS_NBIO(so) |
michael@0 | 13305 | #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 |
michael@0 | 13306 | || (flags & MSG_NBIO) |
michael@0 | 13307 | #endif |
michael@0 | 13308 | ) { |
michael@0 | 13309 | non_blocking = 1; |
michael@0 | 13310 | } |
michael@0 | 13311 | #endif |
michael@0 | 13312 | /* would we block? */ |
michael@0 | 13313 | if (non_blocking) { |
michael@0 | 13314 | if (hold_tcblock == 0) { |
michael@0 | 13315 | SCTP_TCB_LOCK(stcb); |
michael@0 | 13316 | hold_tcblock = 1; |
michael@0 | 13317 | } |
michael@0 | 13318 | inqueue_bytes = stcb->asoc.total_output_queue_size - (stcb->asoc.chunks_on_out_queue * sizeof(struct sctp_data_chunk)); |
michael@0 | 13319 | if ((SCTP_SB_LIMIT_SND(so) < (sndlen + inqueue_bytes + stcb->asoc.sb_send_resv)) || |
michael@0 | 13320 | (stcb->asoc.chunks_on_out_queue >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) { |
michael@0 | 13321 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EWOULDBLOCK); |
michael@0 | 13322 | if (sndlen > SCTP_SB_LIMIT_SND(so)) |
michael@0 | 13323 | error = EMSGSIZE; |
michael@0 | 13324 | else |
michael@0 | 13325 | error = EWOULDBLOCK; |
michael@0 | 13326 | goto out_unlocked; |
michael@0 | 13327 | } |
michael@0 | 13328 | stcb->asoc.sb_send_resv += sndlen; |
michael@0 | 13329 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 13330 | hold_tcblock = 0; |
michael@0 | 13331 | } else { |
michael@0 | 13332 | atomic_add_int(&stcb->asoc.sb_send_resv, sndlen); |
michael@0 | 13333 | } |
michael@0 | 13334 | local_soresv = sndlen; |
michael@0 | 13335 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
michael@0 | 13336 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ECONNRESET); |
michael@0 | 13337 | error = ECONNRESET; |
michael@0 | 13338 | goto out_unlocked; |
michael@0 | 13339 | } |
michael@0 | 13340 | if (create_lock_applied) { |
michael@0 | 13341 | SCTP_ASOC_CREATE_UNLOCK(inp); |
michael@0 | 13342 | create_lock_applied = 0; |
michael@0 | 13343 | } |
michael@0 | 13344 | if (asoc->stream_reset_outstanding) { |
michael@0 | 13345 | /* |
michael@0 | 13346 | * Can't queue any data while stream reset is underway. |
michael@0 | 13347 | */ |
michael@0 | 13348 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EAGAIN); |
michael@0 | 13349 | error = EAGAIN; |
michael@0 | 13350 | goto out_unlocked; |
michael@0 | 13351 | } |
michael@0 | 13352 | if ((SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_WAIT) || |
michael@0 | 13353 | (SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_ECHOED)) { |
michael@0 | 13354 | queue_only = 1; |
michael@0 | 13355 | } |
michael@0 | 13356 | /* we are now done with all control */ |
michael@0 | 13357 | if (control) { |
michael@0 | 13358 | sctp_m_freem(control); |
michael@0 | 13359 | control = NULL; |
michael@0 | 13360 | } |
michael@0 | 13361 | if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) || |
michael@0 | 13362 | (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) || |
michael@0 | 13363 | (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_ACK_SENT) || |
michael@0 | 13364 | (asoc->state & SCTP_STATE_SHUTDOWN_PENDING)) { |
michael@0 | 13365 | if (srcv->sinfo_flags & SCTP_ABORT) { |
michael@0 | 13366 | ; |
michael@0 | 13367 | } else { |
michael@0 | 13368 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ECONNRESET); |
michael@0 | 13369 | error = ECONNRESET; |
michael@0 | 13370 | goto out_unlocked; |
michael@0 | 13371 | } |
michael@0 | 13372 | } |
michael@0 | 13373 | /* Ok, we will attempt a msgsnd :> */ |
michael@0 | 13374 | #if !(defined(__Panda__) || defined(__Windows__) || defined(__Userspace__)) |
michael@0 | 13375 | if (p) { |
michael@0 | 13376 | #if defined(__FreeBSD__) && __FreeBSD_version >= 603000 |
michael@0 | 13377 | p->td_ru.ru_msgsnd++; |
michael@0 | 13378 | #elif defined(__FreeBSD__) && __FreeBSD_version >= 500000 |
michael@0 | 13379 | p->td_proc->p_stats->p_ru.ru_msgsnd++; |
michael@0 | 13380 | #else |
michael@0 | 13381 | p->p_stats->p_ru.ru_msgsnd++; |
michael@0 | 13382 | #endif |
michael@0 | 13383 | } |
michael@0 | 13384 | #endif |
michael@0 | 13385 | /* Are we aborting? */ |
michael@0 | 13386 | if (srcv->sinfo_flags & SCTP_ABORT) { |
michael@0 | 13387 | struct mbuf *mm; |
michael@0 | 13388 | int tot_demand, tot_out = 0, max_out; |
michael@0 | 13389 | |
michael@0 | 13390 | SCTP_STAT_INCR(sctps_sends_with_abort); |
michael@0 | 13391 | if ((SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_WAIT) || |
michael@0 | 13392 | (SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_ECHOED)) { |
michael@0 | 13393 | /* It has to be up before we abort */ |
michael@0 | 13394 | /* how big is the user initiated abort? */ |
michael@0 | 13395 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13396 | error = EINVAL; |
michael@0 | 13397 | goto out; |
michael@0 | 13398 | } |
michael@0 | 13399 | if (hold_tcblock) { |
michael@0 | 13400 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 13401 | hold_tcblock = 0; |
michael@0 | 13402 | } |
michael@0 | 13403 | if (top) { |
michael@0 | 13404 | struct mbuf *cntm = NULL; |
michael@0 | 13405 | |
michael@0 | 13406 | mm = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_WAITOK, 1, MT_DATA); |
michael@0 | 13407 | if (sndlen != 0) { |
michael@0 | 13408 | for (cntm = top; cntm; cntm = SCTP_BUF_NEXT(cntm)) { |
michael@0 | 13409 | tot_out += SCTP_BUF_LEN(cntm); |
michael@0 | 13410 | } |
michael@0 | 13411 | } |
michael@0 | 13412 | } else { |
michael@0 | 13413 | /* Must fit in a MTU */ |
michael@0 | 13414 | tot_out = sndlen; |
michael@0 | 13415 | tot_demand = (tot_out + sizeof(struct sctp_paramhdr)); |
michael@0 | 13416 | if (tot_demand > SCTP_DEFAULT_ADD_MORE) { |
michael@0 | 13417 | /* To big */ |
michael@0 | 13418 | SCTP_LTRACE_ERR_RET(NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, EMSGSIZE); |
michael@0 | 13419 | error = EMSGSIZE; |
michael@0 | 13420 | goto out; |
michael@0 | 13421 | } |
michael@0 | 13422 | mm = sctp_get_mbuf_for_msg(tot_demand, 0, M_WAITOK, 1, MT_DATA); |
michael@0 | 13423 | } |
michael@0 | 13424 | if (mm == NULL) { |
michael@0 | 13425 | SCTP_LTRACE_ERR_RET(NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, ENOMEM); |
michael@0 | 13426 | error = ENOMEM; |
michael@0 | 13427 | goto out; |
michael@0 | 13428 | } |
michael@0 | 13429 | max_out = asoc->smallest_mtu - sizeof(struct sctp_paramhdr); |
michael@0 | 13430 | max_out -= sizeof(struct sctp_abort_msg); |
michael@0 | 13431 | if (tot_out > max_out) { |
michael@0 | 13432 | tot_out = max_out; |
michael@0 | 13433 | } |
michael@0 | 13434 | if (mm) { |
michael@0 | 13435 | struct sctp_paramhdr *ph; |
michael@0 | 13436 | |
michael@0 | 13437 | /* now move forward the data pointer */ |
michael@0 | 13438 | ph = mtod(mm, struct sctp_paramhdr *); |
michael@0 | 13439 | ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); |
michael@0 | 13440 | ph->param_length = htons(sizeof(struct sctp_paramhdr) + tot_out); |
michael@0 | 13441 | ph++; |
michael@0 | 13442 | SCTP_BUF_LEN(mm) = tot_out + sizeof(struct sctp_paramhdr); |
michael@0 | 13443 | if (top == NULL) { |
michael@0 | 13444 | #if defined(__APPLE__) |
michael@0 | 13445 | SCTP_SOCKET_UNLOCK(so, 0); |
michael@0 | 13446 | #endif |
michael@0 | 13447 | error = uiomove((caddr_t)ph, (int)tot_out, uio); |
michael@0 | 13448 | #if defined(__APPLE__) |
michael@0 | 13449 | SCTP_SOCKET_LOCK(so, 0); |
michael@0 | 13450 | #endif |
michael@0 | 13451 | if (error) { |
michael@0 | 13452 | /*- |
michael@0 | 13453 | * Here if we can't get his data we |
michael@0 | 13454 | * still abort we just don't get to |
michael@0 | 13455 | * send the users note :-0 |
michael@0 | 13456 | */ |
michael@0 | 13457 | sctp_m_freem(mm); |
michael@0 | 13458 | mm = NULL; |
michael@0 | 13459 | } |
michael@0 | 13460 | } else { |
michael@0 | 13461 | if (sndlen != 0) { |
michael@0 | 13462 | SCTP_BUF_NEXT(mm) = top; |
michael@0 | 13463 | } |
michael@0 | 13464 | } |
michael@0 | 13465 | } |
michael@0 | 13466 | if (hold_tcblock == 0) { |
michael@0 | 13467 | SCTP_TCB_LOCK(stcb); |
michael@0 | 13468 | } |
michael@0 | 13469 | atomic_add_int(&stcb->asoc.refcnt, -1); |
michael@0 | 13470 | free_cnt_applied = 0; |
michael@0 | 13471 | /* release this lock, otherwise we hang on ourselves */ |
michael@0 | 13472 | sctp_abort_an_association(stcb->sctp_ep, stcb, mm, SCTP_SO_LOCKED); |
michael@0 | 13473 | /* now relock the stcb so everything is sane */ |
michael@0 | 13474 | hold_tcblock = 0; |
michael@0 | 13475 | stcb = NULL; |
michael@0 | 13476 | /* In this case top is already chained to mm |
michael@0 | 13477 | * avoid double free, since we free it below if |
michael@0 | 13478 | * top != NULL and driver would free it after sending |
michael@0 | 13479 | * the packet out |
michael@0 | 13480 | */ |
michael@0 | 13481 | if (sndlen != 0) { |
michael@0 | 13482 | top = NULL; |
michael@0 | 13483 | } |
michael@0 | 13484 | goto out_unlocked; |
michael@0 | 13485 | } |
michael@0 | 13486 | /* Calculate the maximum we can send */ |
michael@0 | 13487 | inqueue_bytes = stcb->asoc.total_output_queue_size - (stcb->asoc.chunks_on_out_queue * sizeof(struct sctp_data_chunk)); |
michael@0 | 13488 | if (SCTP_SB_LIMIT_SND(so) > inqueue_bytes) { |
michael@0 | 13489 | if (non_blocking) { |
michael@0 | 13490 | /* we already checked for non-blocking above. */ |
michael@0 | 13491 | max_len = sndlen; |
michael@0 | 13492 | } else { |
michael@0 | 13493 | max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes; |
michael@0 | 13494 | } |
michael@0 | 13495 | } else { |
michael@0 | 13496 | max_len = 0; |
michael@0 | 13497 | } |
michael@0 | 13498 | if (hold_tcblock) { |
michael@0 | 13499 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 13500 | hold_tcblock = 0; |
michael@0 | 13501 | } |
michael@0 | 13502 | /* Is the stream no. valid? */ |
michael@0 | 13503 | if (srcv->sinfo_stream >= asoc->streamoutcnt) { |
michael@0 | 13504 | /* Invalid stream number */ |
michael@0 | 13505 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13506 | error = EINVAL; |
michael@0 | 13507 | goto out_unlocked; |
michael@0 | 13508 | } |
michael@0 | 13509 | if (asoc->strmout == NULL) { |
michael@0 | 13510 | /* huh? software error */ |
michael@0 | 13511 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EFAULT); |
michael@0 | 13512 | error = EFAULT; |
michael@0 | 13513 | goto out_unlocked; |
michael@0 | 13514 | } |
michael@0 | 13515 | |
michael@0 | 13516 | /* Unless E_EOR mode is on, we must make a send FIT in one call. */ |
michael@0 | 13517 | if ((user_marks_eor == 0) && |
michael@0 | 13518 | (sndlen > SCTP_SB_LIMIT_SND(stcb->sctp_socket))) { |
michael@0 | 13519 | /* It will NEVER fit */ |
michael@0 | 13520 | SCTP_LTRACE_ERR_RET(NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, EMSGSIZE); |
michael@0 | 13521 | error = EMSGSIZE; |
michael@0 | 13522 | goto out_unlocked; |
michael@0 | 13523 | } |
michael@0 | 13524 | if ((uio == NULL) && user_marks_eor) { |
michael@0 | 13525 | /*- |
michael@0 | 13526 | * We do not support eeor mode for |
michael@0 | 13527 | * sending with mbuf chains (like sendfile). |
michael@0 | 13528 | */ |
michael@0 | 13529 | SCTP_LTRACE_ERR_RET(NULL, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13530 | error = EINVAL; |
michael@0 | 13531 | goto out_unlocked; |
michael@0 | 13532 | } |
michael@0 | 13533 | |
michael@0 | 13534 | if (user_marks_eor) { |
michael@0 | 13535 | local_add_more = min(SCTP_SB_LIMIT_SND(so), SCTP_BASE_SYSCTL(sctp_add_more_threshold)); |
michael@0 | 13536 | } else { |
michael@0 | 13537 | /*- |
michael@0 | 13538 | * For non-eeor the whole message must fit in |
michael@0 | 13539 | * the socket send buffer. |
michael@0 | 13540 | */ |
michael@0 | 13541 | local_add_more = sndlen; |
michael@0 | 13542 | } |
michael@0 | 13543 | len = 0; |
michael@0 | 13544 | if (non_blocking) { |
michael@0 | 13545 | goto skip_preblock; |
michael@0 | 13546 | } |
michael@0 | 13547 | if (((max_len <= local_add_more) && |
michael@0 | 13548 | (SCTP_SB_LIMIT_SND(so) >= local_add_more)) || |
michael@0 | 13549 | (max_len == 0) || |
michael@0 | 13550 | ((stcb->asoc.chunks_on_out_queue+stcb->asoc.stream_queue_cnt) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) { |
michael@0 | 13551 | /* No room right now ! */ |
michael@0 | 13552 | SOCKBUF_LOCK(&so->so_snd); |
michael@0 | 13553 | inqueue_bytes = stcb->asoc.total_output_queue_size - (stcb->asoc.chunks_on_out_queue * sizeof(struct sctp_data_chunk)); |
michael@0 | 13554 | while ((SCTP_SB_LIMIT_SND(so) < (inqueue_bytes + local_add_more)) || |
michael@0 | 13555 | ((stcb->asoc.stream_queue_cnt+stcb->asoc.chunks_on_out_queue) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) { |
michael@0 | 13556 | SCTPDBG(SCTP_DEBUG_OUTPUT1,"pre_block limit:%u <(inq:%d + %d) || (%d+%d > %d)\n", |
michael@0 | 13557 | (unsigned int)SCTP_SB_LIMIT_SND(so), |
michael@0 | 13558 | inqueue_bytes, |
michael@0 | 13559 | local_add_more, |
michael@0 | 13560 | stcb->asoc.stream_queue_cnt, |
michael@0 | 13561 | stcb->asoc.chunks_on_out_queue, |
michael@0 | 13562 | SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)); |
michael@0 | 13563 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_BLK_LOGGING_ENABLE) { |
michael@0 | 13564 | sctp_log_block(SCTP_BLOCK_LOG_INTO_BLKA, asoc, sndlen); |
michael@0 | 13565 | } |
michael@0 | 13566 | be.error = 0; |
michael@0 | 13567 | #if !defined(__Panda__) && !defined(__Windows__) |
michael@0 | 13568 | stcb->block_entry = &be; |
michael@0 | 13569 | #endif |
michael@0 | 13570 | error = sbwait(&so->so_snd); |
michael@0 | 13571 | stcb->block_entry = NULL; |
michael@0 | 13572 | if (error || so->so_error || be.error) { |
michael@0 | 13573 | if (error == 0) { |
michael@0 | 13574 | if (so->so_error) |
michael@0 | 13575 | error = so->so_error; |
michael@0 | 13576 | if (be.error) { |
michael@0 | 13577 | error = be.error; |
michael@0 | 13578 | } |
michael@0 | 13579 | } |
michael@0 | 13580 | SOCKBUF_UNLOCK(&so->so_snd); |
michael@0 | 13581 | goto out_unlocked; |
michael@0 | 13582 | } |
michael@0 | 13583 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_BLK_LOGGING_ENABLE) { |
michael@0 | 13584 | sctp_log_block(SCTP_BLOCK_LOG_OUTOF_BLK, |
michael@0 | 13585 | asoc, stcb->asoc.total_output_queue_size); |
michael@0 | 13586 | } |
michael@0 | 13587 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
michael@0 | 13588 | goto out_unlocked; |
michael@0 | 13589 | } |
michael@0 | 13590 | inqueue_bytes = stcb->asoc.total_output_queue_size - (stcb->asoc.chunks_on_out_queue * sizeof(struct sctp_data_chunk)); |
michael@0 | 13591 | } |
michael@0 | 13592 | if (SCTP_SB_LIMIT_SND(so) > inqueue_bytes) { |
michael@0 | 13593 | max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes; |
michael@0 | 13594 | } else { |
michael@0 | 13595 | max_len = 0; |
michael@0 | 13596 | } |
michael@0 | 13597 | SOCKBUF_UNLOCK(&so->so_snd); |
michael@0 | 13598 | } |
michael@0 | 13599 | |
michael@0 | 13600 | skip_preblock: |
michael@0 | 13601 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
michael@0 | 13602 | goto out_unlocked; |
michael@0 | 13603 | } |
michael@0 | 13604 | #if defined(__APPLE__) |
michael@0 | 13605 | error = sblock(&so->so_snd, SBLOCKWAIT(flags)); |
michael@0 | 13606 | #endif |
michael@0 | 13607 | /* sndlen covers for mbuf case |
michael@0 | 13608 | * uio_resid covers for the non-mbuf case |
michael@0 | 13609 | * NOTE: uio will be null when top/mbuf is passed |
michael@0 | 13610 | */ |
michael@0 | 13611 | if (sndlen == 0) { |
michael@0 | 13612 | if (srcv->sinfo_flags & SCTP_EOF) { |
michael@0 | 13613 | got_all_of_the_send = 1; |
michael@0 | 13614 | goto dataless_eof; |
michael@0 | 13615 | } else { |
michael@0 | 13616 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13617 | error = EINVAL; |
michael@0 | 13618 | goto out; |
michael@0 | 13619 | } |
michael@0 | 13620 | } |
michael@0 | 13621 | if (top == NULL) { |
michael@0 | 13622 | struct sctp_stream_queue_pending *sp; |
michael@0 | 13623 | struct sctp_stream_out *strm; |
michael@0 | 13624 | uint32_t sndout; |
michael@0 | 13625 | |
michael@0 | 13626 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 13627 | if ((asoc->stream_locked) && |
michael@0 | 13628 | (asoc->stream_locked_on != srcv->sinfo_stream)) { |
michael@0 | 13629 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 13630 | SCTP_LTRACE_ERR_RET(inp, stcb, net, SCTP_FROM_SCTP_OUTPUT, EINVAL); |
michael@0 | 13631 | error = EINVAL; |
michael@0 | 13632 | goto out; |
michael@0 | 13633 | } |
michael@0 | 13634 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 13635 | |
michael@0 | 13636 | strm = &stcb->asoc.strmout[srcv->sinfo_stream]; |
michael@0 | 13637 | if (strm->last_msg_incomplete == 0) { |
michael@0 | 13638 | do_a_copy_in: |
michael@0 | 13639 | sp = sctp_copy_it_in(stcb, asoc, srcv, uio, net, max_len, user_marks_eor, &error); |
michael@0 | 13640 | if ((sp == NULL) || (error)) { |
michael@0 | 13641 | goto out; |
michael@0 | 13642 | } |
michael@0 | 13643 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 13644 | if (sp->msg_is_complete) { |
michael@0 | 13645 | strm->last_msg_incomplete = 0; |
michael@0 | 13646 | asoc->stream_locked = 0; |
michael@0 | 13647 | } else { |
michael@0 | 13648 | /* Just got locked to this guy in |
michael@0 | 13649 | * case of an interrupt. |
michael@0 | 13650 | */ |
michael@0 | 13651 | strm->last_msg_incomplete = 1; |
michael@0 | 13652 | asoc->stream_locked = 1; |
michael@0 | 13653 | asoc->stream_locked_on = srcv->sinfo_stream; |
michael@0 | 13654 | sp->sender_all_done = 0; |
michael@0 | 13655 | } |
michael@0 | 13656 | sctp_snd_sb_alloc(stcb, sp->length); |
michael@0 | 13657 | atomic_add_int(&asoc->stream_queue_cnt, 1); |
michael@0 | 13658 | if (srcv->sinfo_flags & SCTP_UNORDERED) { |
michael@0 | 13659 | SCTP_STAT_INCR(sctps_sends_with_unord); |
michael@0 | 13660 | } |
michael@0 | 13661 | TAILQ_INSERT_TAIL(&strm->outqueue, sp, next); |
michael@0 | 13662 | stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, asoc, strm, sp, 1); |
michael@0 | 13663 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 13664 | } else { |
michael@0 | 13665 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 13666 | sp = TAILQ_LAST(&strm->outqueue, sctp_streamhead); |
michael@0 | 13667 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 13668 | if (sp == NULL) { |
michael@0 | 13669 | /* ???? Huh ??? last msg is gone */ |
michael@0 | 13670 | #ifdef INVARIANTS |
michael@0 | 13671 | panic("Warning: Last msg marked incomplete, yet nothing left?"); |
michael@0 | 13672 | #else |
michael@0 | 13673 | SCTP_PRINTF("Warning: Last msg marked incomplete, yet nothing left?\n"); |
michael@0 | 13674 | strm->last_msg_incomplete = 0; |
michael@0 | 13675 | #endif |
michael@0 | 13676 | goto do_a_copy_in; |
michael@0 | 13677 | |
michael@0 | 13678 | } |
michael@0 | 13679 | } |
michael@0 | 13680 | #if defined(__APPLE__) |
michael@0 | 13681 | #if defined(APPLE_LEOPARD) |
michael@0 | 13682 | while (uio->uio_resid > 0) { |
michael@0 | 13683 | #else |
michael@0 | 13684 | while (uio_resid(uio) > 0) { |
michael@0 | 13685 | #endif |
michael@0 | 13686 | #else |
michael@0 | 13687 | while (uio->uio_resid > 0) { |
michael@0 | 13688 | #endif |
michael@0 | 13689 | /* How much room do we have? */ |
michael@0 | 13690 | struct mbuf *new_tail, *mm; |
michael@0 | 13691 | |
michael@0 | 13692 | if (SCTP_SB_LIMIT_SND(so) > stcb->asoc.total_output_queue_size) |
michael@0 | 13693 | max_len = SCTP_SB_LIMIT_SND(so) - stcb->asoc.total_output_queue_size; |
michael@0 | 13694 | else |
michael@0 | 13695 | max_len = 0; |
michael@0 | 13696 | |
michael@0 | 13697 | if ((max_len > SCTP_BASE_SYSCTL(sctp_add_more_threshold)) || |
michael@0 | 13698 | (max_len && (SCTP_SB_LIMIT_SND(so) < SCTP_BASE_SYSCTL(sctp_add_more_threshold))) || |
michael@0 | 13699 | #if defined(__APPLE__) |
michael@0 | 13700 | #if defined(APPLE_LEOPARD) |
michael@0 | 13701 | (uio->uio_resid && (uio->uio_resid <= (int)max_len))) { |
michael@0 | 13702 | #else |
michael@0 | 13703 | (uio_resid(uio) && (uio_resid(uio) <= (int)max_len))) { |
michael@0 | 13704 | #endif |
michael@0 | 13705 | #else |
michael@0 | 13706 | (uio->uio_resid && (uio->uio_resid <= (int)max_len))) { |
michael@0 | 13707 | #endif |
michael@0 | 13708 | sndout = 0; |
michael@0 | 13709 | new_tail = NULL; |
michael@0 | 13710 | if (hold_tcblock) { |
michael@0 | 13711 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 13712 | hold_tcblock = 0; |
michael@0 | 13713 | } |
michael@0 | 13714 | #if defined(__APPLE__) |
michael@0 | 13715 | SCTP_SOCKET_UNLOCK(so, 0); |
michael@0 | 13716 | #endif |
michael@0 | 13717 | #if defined(__FreeBSD__) && __FreeBSD_version > 602000 |
michael@0 | 13718 | mm = sctp_copy_resume(uio, max_len, user_marks_eor, &error, &sndout, &new_tail); |
michael@0 | 13719 | #else |
michael@0 | 13720 | mm = sctp_copy_resume(uio, max_len, &error, &sndout, &new_tail); |
michael@0 | 13721 | #endif |
michael@0 | 13722 | #if defined(__APPLE__) |
michael@0 | 13723 | SCTP_SOCKET_LOCK(so, 0); |
michael@0 | 13724 | #endif |
michael@0 | 13725 | if ((mm == NULL) || error) { |
michael@0 | 13726 | if (mm) { |
michael@0 | 13727 | sctp_m_freem(mm); |
michael@0 | 13728 | } |
michael@0 | 13729 | goto out; |
michael@0 | 13730 | } |
michael@0 | 13731 | /* Update the mbuf and count */ |
michael@0 | 13732 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 13733 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
michael@0 | 13734 | /* we need to get out. |
michael@0 | 13735 | * Peer probably aborted. |
michael@0 | 13736 | */ |
michael@0 | 13737 | sctp_m_freem(mm); |
michael@0 | 13738 | if (stcb->asoc.state & SCTP_PCB_FLAGS_WAS_ABORTED) { |
michael@0 | 13739 | SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ECONNRESET); |
michael@0 | 13740 | error = ECONNRESET; |
michael@0 | 13741 | } |
michael@0 | 13742 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 13743 | goto out; |
michael@0 | 13744 | } |
michael@0 | 13745 | if (sp->tail_mbuf) { |
michael@0 | 13746 | /* tack it to the end */ |
michael@0 | 13747 | SCTP_BUF_NEXT(sp->tail_mbuf) = mm; |
michael@0 | 13748 | sp->tail_mbuf = new_tail; |
michael@0 | 13749 | } else { |
michael@0 | 13750 | /* A stolen mbuf */ |
michael@0 | 13751 | sp->data = mm; |
michael@0 | 13752 | sp->tail_mbuf = new_tail; |
michael@0 | 13753 | } |
michael@0 | 13754 | sctp_snd_sb_alloc(stcb, sndout); |
michael@0 | 13755 | atomic_add_int(&sp->length,sndout); |
michael@0 | 13756 | len += sndout; |
michael@0 | 13757 | |
michael@0 | 13758 | /* Did we reach EOR? */ |
michael@0 | 13759 | #if defined(__APPLE__) |
michael@0 | 13760 | #if defined(APPLE_LEOPARD) |
michael@0 | 13761 | if ((uio->uio_resid == 0) && |
michael@0 | 13762 | #else |
michael@0 | 13763 | if ((uio_resid(uio) == 0) && |
michael@0 | 13764 | #endif |
michael@0 | 13765 | #else |
michael@0 | 13766 | if ((uio->uio_resid == 0) && |
michael@0 | 13767 | #endif |
michael@0 | 13768 | ((user_marks_eor == 0) || |
michael@0 | 13769 | (srcv->sinfo_flags & SCTP_EOF) || |
michael@0 | 13770 | (user_marks_eor && (srcv->sinfo_flags & SCTP_EOR)))) { |
michael@0 | 13771 | sp->msg_is_complete = 1; |
michael@0 | 13772 | } else { |
michael@0 | 13773 | sp->msg_is_complete = 0; |
michael@0 | 13774 | } |
michael@0 | 13775 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 13776 | } |
michael@0 | 13777 | #if defined(__APPLE__) |
michael@0 | 13778 | #if defined(APPLE_LEOPARD) |
michael@0 | 13779 | if (uio->uio_resid == 0) { |
michael@0 | 13780 | #else |
michael@0 | 13781 | if (uio_resid(uio) == 0) { |
michael@0 | 13782 | #endif |
michael@0 | 13783 | #else |
michael@0 | 13784 | if (uio->uio_resid == 0) { |
michael@0 | 13785 | #endif |
michael@0 | 13786 | /* got it all? */ |
michael@0 | 13787 | continue; |
michael@0 | 13788 | } |
michael@0 | 13789 | /* PR-SCTP? */ |
michael@0 | 13790 | if ((asoc->peer_supports_prsctp) && (asoc->sent_queue_cnt_removeable > 0)) { |
michael@0 | 13791 | /* This is ugly but we must assure locking order */ |
michael@0 | 13792 | if (hold_tcblock == 0) { |
michael@0 | 13793 | SCTP_TCB_LOCK(stcb); |
michael@0 | 13794 | hold_tcblock = 1; |
michael@0 | 13795 | } |
michael@0 | 13796 | sctp_prune_prsctp(stcb, asoc, srcv, sndlen); |
michael@0 | 13797 | inqueue_bytes = stcb->asoc.total_output_queue_size - (stcb->asoc.chunks_on_out_queue * sizeof(struct sctp_data_chunk)); |
michael@0 | 13798 | if (SCTP_SB_LIMIT_SND(so) > stcb->asoc.total_output_queue_size) |
michael@0 | 13799 | max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes; |
michael@0 | 13800 | else |
michael@0 | 13801 | max_len = 0; |
michael@0 | 13802 | if (max_len > 0) { |
michael@0 | 13803 | continue; |
michael@0 | 13804 | } |
michael@0 | 13805 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 13806 | hold_tcblock = 0; |
michael@0 | 13807 | } |
michael@0 | 13808 | /* wait for space now */ |
michael@0 | 13809 | if (non_blocking) { |
michael@0 | 13810 | /* Non-blocking io in place out */ |
michael@0 | 13811 | goto skip_out_eof; |
michael@0 | 13812 | } |
michael@0 | 13813 | /* What about the INIT, send it maybe */ |
michael@0 | 13814 | if (queue_only_for_init) { |
michael@0 | 13815 | if (hold_tcblock == 0) { |
michael@0 | 13816 | SCTP_TCB_LOCK(stcb); |
michael@0 | 13817 | hold_tcblock = 1; |
michael@0 | 13818 | } |
michael@0 | 13819 | if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { |
michael@0 | 13820 | /* a collision took us forward? */ |
michael@0 | 13821 | queue_only = 0; |
michael@0 | 13822 | } else { |
michael@0 | 13823 | sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); |
michael@0 | 13824 | SCTP_SET_STATE(asoc, SCTP_STATE_COOKIE_WAIT); |
michael@0 | 13825 | queue_only = 1; |
michael@0 | 13826 | } |
michael@0 | 13827 | } |
michael@0 | 13828 | if ((net->flight_size > net->cwnd) && |
michael@0 | 13829 | (asoc->sctp_cmt_on_off == 0)) { |
michael@0 | 13830 | SCTP_STAT_INCR(sctps_send_cwnd_avoid); |
michael@0 | 13831 | queue_only = 1; |
michael@0 | 13832 | } else if (asoc->ifp_had_enobuf) { |
michael@0 | 13833 | SCTP_STAT_INCR(sctps_ifnomemqueued); |
michael@0 | 13834 | if (net->flight_size > (2 * net->mtu)) { |
michael@0 | 13835 | queue_only = 1; |
michael@0 | 13836 | } |
michael@0 | 13837 | asoc->ifp_had_enobuf = 0; |
michael@0 | 13838 | } |
michael@0 | 13839 | un_sent = ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) + |
michael@0 | 13840 | (stcb->asoc.stream_queue_cnt * sizeof(struct sctp_data_chunk))); |
michael@0 | 13841 | if ((sctp_is_feature_off(inp, SCTP_PCB_FLAGS_NODELAY)) && |
michael@0 | 13842 | (stcb->asoc.total_flight > 0) && |
michael@0 | 13843 | (stcb->asoc.stream_queue_cnt < SCTP_MAX_DATA_BUNDLING) && |
michael@0 | 13844 | (un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD))) { |
michael@0 | 13845 | |
michael@0 | 13846 | /*- |
michael@0 | 13847 | * Ok, Nagle is set on and we have data outstanding. |
michael@0 | 13848 | * Don't send anything and let SACKs drive out the |
michael@0 | 13849 | * data unless wen have a "full" segment to send. |
michael@0 | 13850 | */ |
michael@0 | 13851 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_NAGLE_LOGGING_ENABLE) { |
michael@0 | 13852 | sctp_log_nagle_event(stcb, SCTP_NAGLE_APPLIED); |
michael@0 | 13853 | } |
michael@0 | 13854 | SCTP_STAT_INCR(sctps_naglequeued); |
michael@0 | 13855 | nagle_applies = 1; |
michael@0 | 13856 | } else { |
michael@0 | 13857 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_NAGLE_LOGGING_ENABLE) { |
michael@0 | 13858 | if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_NODELAY)) |
michael@0 | 13859 | sctp_log_nagle_event(stcb, SCTP_NAGLE_SKIPPED); |
michael@0 | 13860 | } |
michael@0 | 13861 | SCTP_STAT_INCR(sctps_naglesent); |
michael@0 | 13862 | nagle_applies = 0; |
michael@0 | 13863 | } |
michael@0 | 13864 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_BLK_LOGGING_ENABLE) { |
michael@0 | 13865 | |
michael@0 | 13866 | sctp_misc_ints(SCTP_CWNDLOG_PRESEND, queue_only_for_init, queue_only, |
michael@0 | 13867 | nagle_applies, un_sent); |
michael@0 | 13868 | sctp_misc_ints(SCTP_CWNDLOG_PRESEND, stcb->asoc.total_output_queue_size, |
michael@0 | 13869 | stcb->asoc.total_flight, |
michael@0 | 13870 | stcb->asoc.chunks_on_out_queue, stcb->asoc.total_flight_count); |
michael@0 | 13871 | } |
michael@0 | 13872 | if (queue_only_for_init) |
michael@0 | 13873 | queue_only_for_init = 0; |
michael@0 | 13874 | if ((queue_only == 0) && (nagle_applies == 0)) { |
michael@0 | 13875 | /*- |
michael@0 | 13876 | * need to start chunk output |
michael@0 | 13877 | * before blocking.. note that if |
michael@0 | 13878 | * a lock is already applied, then |
michael@0 | 13879 | * the input via the net is happening |
michael@0 | 13880 | * and I don't need to start output :-D |
michael@0 | 13881 | */ |
michael@0 | 13882 | if (hold_tcblock == 0) { |
michael@0 | 13883 | if (SCTP_TCB_TRYLOCK(stcb)) { |
michael@0 | 13884 | hold_tcblock = 1; |
michael@0 | 13885 | sctp_chunk_output(inp, |
michael@0 | 13886 | stcb, |
michael@0 | 13887 | SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_LOCKED); |
michael@0 | 13888 | } |
michael@0 | 13889 | } else { |
michael@0 | 13890 | sctp_chunk_output(inp, |
michael@0 | 13891 | stcb, |
michael@0 | 13892 | SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_LOCKED); |
michael@0 | 13893 | } |
michael@0 | 13894 | if (hold_tcblock == 1) { |
michael@0 | 13895 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 13896 | hold_tcblock = 0; |
michael@0 | 13897 | } |
michael@0 | 13898 | } |
michael@0 | 13899 | SOCKBUF_LOCK(&so->so_snd); |
michael@0 | 13900 | /*- |
michael@0 | 13901 | * This is a bit strange, but I think it will |
michael@0 | 13902 | * work. The total_output_queue_size is locked and |
michael@0 | 13903 | * protected by the TCB_LOCK, which we just released. |
michael@0 | 13904 | * There is a race that can occur between releasing it |
michael@0 | 13905 | * above, and me getting the socket lock, where sacks |
michael@0 | 13906 | * come in but we have not put the SB_WAIT on the |
michael@0 | 13907 | * so_snd buffer to get the wakeup. After the LOCK |
michael@0 | 13908 | * is applied the sack_processing will also need to |
michael@0 | 13909 | * LOCK the so->so_snd to do the actual sowwakeup(). So |
michael@0 | 13910 | * once we have the socket buffer lock if we recheck the |
michael@0 | 13911 | * size we KNOW we will get to sleep safely with the |
michael@0 | 13912 | * wakeup flag in place. |
michael@0 | 13913 | */ |
michael@0 | 13914 | if (SCTP_SB_LIMIT_SND(so) <= (stcb->asoc.total_output_queue_size + |
michael@0 | 13915 | min(SCTP_BASE_SYSCTL(sctp_add_more_threshold), SCTP_SB_LIMIT_SND(so)))) { |
michael@0 | 13916 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_BLK_LOGGING_ENABLE) { |
michael@0 | 13917 | #if defined(__APPLE__) |
michael@0 | 13918 | #if defined(APPLE_LEOPARD) |
michael@0 | 13919 | sctp_log_block(SCTP_BLOCK_LOG_INTO_BLK, |
michael@0 | 13920 | asoc, uio->uio_resid); |
michael@0 | 13921 | #else |
michael@0 | 13922 | sctp_log_block(SCTP_BLOCK_LOG_INTO_BLK, |
michael@0 | 13923 | asoc, uio_resid(uio)); |
michael@0 | 13924 | #endif |
michael@0 | 13925 | #else |
michael@0 | 13926 | sctp_log_block(SCTP_BLOCK_LOG_INTO_BLK, |
michael@0 | 13927 | asoc, uio->uio_resid); |
michael@0 | 13928 | #endif |
michael@0 | 13929 | } |
michael@0 | 13930 | be.error = 0; |
michael@0 | 13931 | #if !defined(__Panda__) && !defined(__Windows__) |
michael@0 | 13932 | stcb->block_entry = &be; |
michael@0 | 13933 | #endif |
michael@0 | 13934 | #if defined(__APPLE__) |
michael@0 | 13935 | sbunlock(&so->so_snd, 1); |
michael@0 | 13936 | #endif |
michael@0 | 13937 | error = sbwait(&so->so_snd); |
michael@0 | 13938 | stcb->block_entry = NULL; |
michael@0 | 13939 | |
michael@0 | 13940 | if (error || so->so_error || be.error) { |
michael@0 | 13941 | if (error == 0) { |
michael@0 | 13942 | if (so->so_error) |
michael@0 | 13943 | error = so->so_error; |
michael@0 | 13944 | if (be.error) { |
michael@0 | 13945 | error = be.error; |
michael@0 | 13946 | } |
michael@0 | 13947 | } |
michael@0 | 13948 | SOCKBUF_UNLOCK(&so->so_snd); |
michael@0 | 13949 | goto out_unlocked; |
michael@0 | 13950 | } |
michael@0 | 13951 | |
michael@0 | 13952 | #if defined(__APPLE__) |
michael@0 | 13953 | error = sblock(&so->so_snd, SBLOCKWAIT(flags)); |
michael@0 | 13954 | #endif |
michael@0 | 13955 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_BLK_LOGGING_ENABLE) { |
michael@0 | 13956 | sctp_log_block(SCTP_BLOCK_LOG_OUTOF_BLK, |
michael@0 | 13957 | asoc, stcb->asoc.total_output_queue_size); |
michael@0 | 13958 | } |
michael@0 | 13959 | } |
michael@0 | 13960 | SOCKBUF_UNLOCK(&so->so_snd); |
michael@0 | 13961 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
michael@0 | 13962 | goto out_unlocked; |
michael@0 | 13963 | } |
michael@0 | 13964 | } |
michael@0 | 13965 | SCTP_TCB_SEND_LOCK(stcb); |
michael@0 | 13966 | if (sp) { |
michael@0 | 13967 | if (sp->msg_is_complete == 0) { |
michael@0 | 13968 | strm->last_msg_incomplete = 1; |
michael@0 | 13969 | asoc->stream_locked = 1; |
michael@0 | 13970 | asoc->stream_locked_on = srcv->sinfo_stream; |
michael@0 | 13971 | } else { |
michael@0 | 13972 | sp->sender_all_done = 1; |
michael@0 | 13973 | strm->last_msg_incomplete = 0; |
michael@0 | 13974 | asoc->stream_locked = 0; |
michael@0 | 13975 | } |
michael@0 | 13976 | } else { |
michael@0 | 13977 | SCTP_PRINTF("Huh no sp TSNH?\n"); |
michael@0 | 13978 | strm->last_msg_incomplete = 0; |
michael@0 | 13979 | asoc->stream_locked = 0; |
michael@0 | 13980 | } |
michael@0 | 13981 | SCTP_TCB_SEND_UNLOCK(stcb); |
michael@0 | 13982 | #if defined(__APPLE__) |
michael@0 | 13983 | #if defined(APPLE_LEOPARD) |
michael@0 | 13984 | if (uio->uio_resid == 0) { |
michael@0 | 13985 | #else |
michael@0 | 13986 | if (uio_resid(uio) == 0) { |
michael@0 | 13987 | #endif |
michael@0 | 13988 | #else |
michael@0 | 13989 | if (uio->uio_resid == 0) { |
michael@0 | 13990 | #endif |
michael@0 | 13991 | got_all_of_the_send = 1; |
michael@0 | 13992 | } |
michael@0 | 13993 | } else { |
michael@0 | 13994 | /* We send in a 0, since we do NOT have any locks */ |
michael@0 | 13995 | error = sctp_msg_append(stcb, net, top, srcv, 0); |
michael@0 | 13996 | top = NULL; |
michael@0 | 13997 | if (srcv->sinfo_flags & SCTP_EOF) { |
michael@0 | 13998 | /* |
michael@0 | 13999 | * This should only happen for Panda for the mbuf |
michael@0 | 14000 | * send case, which does NOT yet support EEOR mode. |
michael@0 | 14001 | * Thus, we can just set this flag to do the proper |
michael@0 | 14002 | * EOF handling. |
michael@0 | 14003 | */ |
michael@0 | 14004 | got_all_of_the_send = 1; |
michael@0 | 14005 | } |
michael@0 | 14006 | } |
michael@0 | 14007 | if (error) { |
michael@0 | 14008 | goto out; |
michael@0 | 14009 | } |
michael@0 | 14010 | dataless_eof: |
michael@0 | 14011 | /* EOF thing ? */ |
michael@0 | 14012 | if ((srcv->sinfo_flags & SCTP_EOF) && |
michael@0 | 14013 | (got_all_of_the_send == 1)) { |
michael@0 | 14014 | int cnt; |
michael@0 | 14015 | SCTP_STAT_INCR(sctps_sends_with_eof); |
michael@0 | 14016 | error = 0; |
michael@0 | 14017 | if (hold_tcblock == 0) { |
michael@0 | 14018 | SCTP_TCB_LOCK(stcb); |
michael@0 | 14019 | hold_tcblock = 1; |
michael@0 | 14020 | } |
michael@0 | 14021 | cnt = sctp_is_there_unsent_data(stcb, SCTP_SO_LOCKED); |
michael@0 | 14022 | if (TAILQ_EMPTY(&asoc->send_queue) && |
michael@0 | 14023 | TAILQ_EMPTY(&asoc->sent_queue) && |
michael@0 | 14024 | (cnt == 0)) { |
michael@0 | 14025 | if (asoc->locked_on_sending) { |
michael@0 | 14026 | goto abort_anyway; |
michael@0 | 14027 | } |
michael@0 | 14028 | /* there is nothing queued to send, so I'm done... */ |
michael@0 | 14029 | if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) && |
michael@0 | 14030 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_RECEIVED) && |
michael@0 | 14031 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) { |
michael@0 | 14032 | struct sctp_nets *netp; |
michael@0 | 14033 | |
michael@0 | 14034 | /* only send SHUTDOWN the first time through */ |
michael@0 | 14035 | if (SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) { |
michael@0 | 14036 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
michael@0 | 14037 | } |
michael@0 | 14038 | SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); |
michael@0 | 14039 | SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); |
michael@0 | 14040 | sctp_stop_timers_for_shutdown(stcb); |
michael@0 | 14041 | if (stcb->asoc.alternate) { |
michael@0 | 14042 | netp = stcb->asoc.alternate; |
michael@0 | 14043 | } else { |
michael@0 | 14044 | netp = stcb->asoc.primary_destination; |
michael@0 | 14045 | } |
michael@0 | 14046 | sctp_send_shutdown(stcb, netp); |
michael@0 | 14047 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb, |
michael@0 | 14048 | netp); |
michael@0 | 14049 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, |
michael@0 | 14050 | asoc->primary_destination); |
michael@0 | 14051 | } |
michael@0 | 14052 | } else { |
michael@0 | 14053 | /*- |
michael@0 | 14054 | * we still got (or just got) data to send, so set |
michael@0 | 14055 | * SHUTDOWN_PENDING |
michael@0 | 14056 | */ |
michael@0 | 14057 | /*- |
michael@0 | 14058 | * XXX sockets draft says that SCTP_EOF should be |
michael@0 | 14059 | * sent with no data. currently, we will allow user |
michael@0 | 14060 | * data to be sent first and move to |
michael@0 | 14061 | * SHUTDOWN-PENDING |
michael@0 | 14062 | */ |
michael@0 | 14063 | if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) && |
michael@0 | 14064 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_RECEIVED) && |
michael@0 | 14065 | (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) { |
michael@0 | 14066 | if (hold_tcblock == 0) { |
michael@0 | 14067 | SCTP_TCB_LOCK(stcb); |
michael@0 | 14068 | hold_tcblock = 1; |
michael@0 | 14069 | } |
michael@0 | 14070 | if (asoc->locked_on_sending) { |
michael@0 | 14071 | /* Locked to send out the data */ |
michael@0 | 14072 | struct sctp_stream_queue_pending *sp; |
michael@0 | 14073 | sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead); |
michael@0 | 14074 | if (sp) { |
michael@0 | 14075 | if ((sp->length == 0) && (sp->msg_is_complete == 0)) |
michael@0 | 14076 | asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT; |
michael@0 | 14077 | } |
michael@0 | 14078 | } |
michael@0 | 14079 | asoc->state |= SCTP_STATE_SHUTDOWN_PENDING; |
michael@0 | 14080 | if (TAILQ_EMPTY(&asoc->send_queue) && |
michael@0 | 14081 | TAILQ_EMPTY(&asoc->sent_queue) && |
michael@0 | 14082 | (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { |
michael@0 | 14083 | abort_anyway: |
michael@0 | 14084 | if (free_cnt_applied) { |
michael@0 | 14085 | atomic_add_int(&stcb->asoc.refcnt, -1); |
michael@0 | 14086 | free_cnt_applied = 0; |
michael@0 | 14087 | } |
michael@0 | 14088 | sctp_abort_an_association(stcb->sctp_ep, stcb, |
michael@0 | 14089 | NULL, SCTP_SO_LOCKED); |
michael@0 | 14090 | /* now relock the stcb so everything is sane */ |
michael@0 | 14091 | hold_tcblock = 0; |
michael@0 | 14092 | stcb = NULL; |
michael@0 | 14093 | goto out; |
michael@0 | 14094 | } |
michael@0 | 14095 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, |
michael@0 | 14096 | asoc->primary_destination); |
michael@0 | 14097 | sctp_feature_off(inp, SCTP_PCB_FLAGS_NODELAY); |
michael@0 | 14098 | } |
michael@0 | 14099 | } |
michael@0 | 14100 | } |
michael@0 | 14101 | skip_out_eof: |
michael@0 | 14102 | if (!TAILQ_EMPTY(&stcb->asoc.control_send_queue)) { |
michael@0 | 14103 | some_on_control = 1; |
michael@0 | 14104 | } |
michael@0 | 14105 | if (queue_only_for_init) { |
michael@0 | 14106 | if (hold_tcblock == 0) { |
michael@0 | 14107 | SCTP_TCB_LOCK(stcb); |
michael@0 | 14108 | hold_tcblock = 1; |
michael@0 | 14109 | } |
michael@0 | 14110 | if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { |
michael@0 | 14111 | /* a collision took us forward? */ |
michael@0 | 14112 | queue_only = 0; |
michael@0 | 14113 | } else { |
michael@0 | 14114 | sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); |
michael@0 | 14115 | SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT); |
michael@0 | 14116 | queue_only = 1; |
michael@0 | 14117 | } |
michael@0 | 14118 | } |
michael@0 | 14119 | if ((net->flight_size > net->cwnd) && |
michael@0 | 14120 | (stcb->asoc.sctp_cmt_on_off == 0)) { |
michael@0 | 14121 | SCTP_STAT_INCR(sctps_send_cwnd_avoid); |
michael@0 | 14122 | queue_only = 1; |
michael@0 | 14123 | } else if (asoc->ifp_had_enobuf) { |
michael@0 | 14124 | SCTP_STAT_INCR(sctps_ifnomemqueued); |
michael@0 | 14125 | if (net->flight_size > (2 * net->mtu)) { |
michael@0 | 14126 | queue_only = 1; |
michael@0 | 14127 | } |
michael@0 | 14128 | asoc->ifp_had_enobuf = 0; |
michael@0 | 14129 | } |
michael@0 | 14130 | un_sent = ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) + |
michael@0 | 14131 | (stcb->asoc.stream_queue_cnt * sizeof(struct sctp_data_chunk))); |
michael@0 | 14132 | if ((sctp_is_feature_off(inp, SCTP_PCB_FLAGS_NODELAY)) && |
michael@0 | 14133 | (stcb->asoc.total_flight > 0) && |
michael@0 | 14134 | (stcb->asoc.stream_queue_cnt < SCTP_MAX_DATA_BUNDLING) && |
michael@0 | 14135 | (un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD))) { |
michael@0 | 14136 | /*- |
michael@0 | 14137 | * Ok, Nagle is set on and we have data outstanding. |
michael@0 | 14138 | * Don't send anything and let SACKs drive out the |
michael@0 | 14139 | * data unless wen have a "full" segment to send. |
michael@0 | 14140 | */ |
michael@0 | 14141 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_NAGLE_LOGGING_ENABLE) { |
michael@0 | 14142 | sctp_log_nagle_event(stcb, SCTP_NAGLE_APPLIED); |
michael@0 | 14143 | } |
michael@0 | 14144 | SCTP_STAT_INCR(sctps_naglequeued); |
michael@0 | 14145 | nagle_applies = 1; |
michael@0 | 14146 | } else { |
michael@0 | 14147 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_NAGLE_LOGGING_ENABLE) { |
michael@0 | 14148 | if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_NODELAY)) |
michael@0 | 14149 | sctp_log_nagle_event(stcb, SCTP_NAGLE_SKIPPED); |
michael@0 | 14150 | } |
michael@0 | 14151 | SCTP_STAT_INCR(sctps_naglesent); |
michael@0 | 14152 | nagle_applies = 0; |
michael@0 | 14153 | } |
michael@0 | 14154 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_BLK_LOGGING_ENABLE) { |
michael@0 | 14155 | sctp_misc_ints(SCTP_CWNDLOG_PRESEND, queue_only_for_init, queue_only, |
michael@0 | 14156 | nagle_applies, un_sent); |
michael@0 | 14157 | sctp_misc_ints(SCTP_CWNDLOG_PRESEND, stcb->asoc.total_output_queue_size, |
michael@0 | 14158 | stcb->asoc.total_flight, |
michael@0 | 14159 | stcb->asoc.chunks_on_out_queue, stcb->asoc.total_flight_count); |
michael@0 | 14160 | } |
michael@0 | 14161 | if ((queue_only == 0) && (nagle_applies == 0) && (stcb->asoc.peers_rwnd && un_sent)) { |
michael@0 | 14162 | /* we can attempt to send too. */ |
michael@0 | 14163 | if (hold_tcblock == 0) { |
michael@0 | 14164 | /* If there is activity recv'ing sacks no need to send */ |
michael@0 | 14165 | if (SCTP_TCB_TRYLOCK(stcb)) { |
michael@0 | 14166 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_LOCKED); |
michael@0 | 14167 | hold_tcblock = 1; |
michael@0 | 14168 | } |
michael@0 | 14169 | } else { |
michael@0 | 14170 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_LOCKED); |
michael@0 | 14171 | } |
michael@0 | 14172 | } else if ((queue_only == 0) && |
michael@0 | 14173 | (stcb->asoc.peers_rwnd == 0) && |
michael@0 | 14174 | (stcb->asoc.total_flight == 0)) { |
michael@0 | 14175 | /* We get to have a probe outstanding */ |
michael@0 | 14176 | if (hold_tcblock == 0) { |
michael@0 | 14177 | hold_tcblock = 1; |
michael@0 | 14178 | SCTP_TCB_LOCK(stcb); |
michael@0 | 14179 | } |
michael@0 | 14180 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_LOCKED); |
michael@0 | 14181 | } else if (some_on_control) { |
michael@0 | 14182 | int num_out, reason, frag_point; |
michael@0 | 14183 | |
michael@0 | 14184 | /* Here we do control only */ |
michael@0 | 14185 | if (hold_tcblock == 0) { |
michael@0 | 14186 | hold_tcblock = 1; |
michael@0 | 14187 | SCTP_TCB_LOCK(stcb); |
michael@0 | 14188 | } |
michael@0 | 14189 | frag_point = sctp_get_frag_point(stcb, &stcb->asoc); |
michael@0 | 14190 | (void)sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out, |
michael@0 | 14191 | &reason, 1, 1, &now, &now_filled, frag_point, SCTP_SO_LOCKED); |
michael@0 | 14192 | } |
michael@0 | 14193 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "USR Send complete qo:%d prw:%d unsent:%d tf:%d cooq:%d toqs:%d err:%d\n", |
michael@0 | 14194 | queue_only, stcb->asoc.peers_rwnd, un_sent, |
michael@0 | 14195 | stcb->asoc.total_flight, stcb->asoc.chunks_on_out_queue, |
michael@0 | 14196 | stcb->asoc.total_output_queue_size, error); |
michael@0 | 14197 | |
michael@0 | 14198 | out: |
michael@0 | 14199 | #if defined(__APPLE__) |
michael@0 | 14200 | sbunlock(&so->so_snd, 1); |
michael@0 | 14201 | #endif |
michael@0 | 14202 | out_unlocked: |
michael@0 | 14203 | |
michael@0 | 14204 | if (local_soresv && stcb) { |
michael@0 | 14205 | atomic_subtract_int(&stcb->asoc.sb_send_resv, sndlen); |
michael@0 | 14206 | } |
michael@0 | 14207 | if (create_lock_applied) { |
michael@0 | 14208 | SCTP_ASOC_CREATE_UNLOCK(inp); |
michael@0 | 14209 | } |
michael@0 | 14210 | if ((stcb) && hold_tcblock) { |
michael@0 | 14211 | SCTP_TCB_UNLOCK(stcb); |
michael@0 | 14212 | } |
michael@0 | 14213 | if (stcb && free_cnt_applied) { |
michael@0 | 14214 | atomic_add_int(&stcb->asoc.refcnt, -1); |
michael@0 | 14215 | } |
michael@0 | 14216 | #ifdef INVARIANTS |
michael@0 | 14217 | #if !defined(__APPLE__) |
michael@0 | 14218 | if (stcb) { |
michael@0 | 14219 | if (mtx_owned(&stcb->tcb_mtx)) { |
michael@0 | 14220 | panic("Leaving with tcb mtx owned?"); |
michael@0 | 14221 | } |
michael@0 | 14222 | if (mtx_owned(&stcb->tcb_send_mtx)) { |
michael@0 | 14223 | panic("Leaving with tcb send mtx owned?"); |
michael@0 | 14224 | } |
michael@0 | 14225 | } |
michael@0 | 14226 | #endif |
michael@0 | 14227 | #endif |
michael@0 | 14228 | #ifdef __Panda__ |
michael@0 | 14229 | /* |
michael@0 | 14230 | * Handle the EAGAIN/ENOMEM cases to reattach the pak header |
michael@0 | 14231 | * to particle when pak is passed in, so that caller |
michael@0 | 14232 | * can try again with this pak |
michael@0 | 14233 | * |
michael@0 | 14234 | * NOTE: For other cases, including success case, |
michael@0 | 14235 | * we simply want to return the header back to free |
michael@0 | 14236 | * pool |
michael@0 | 14237 | */ |
michael@0 | 14238 | if (top) { |
michael@0 | 14239 | if ((error == EAGAIN) || (error == ENOMEM)) { |
michael@0 | 14240 | SCTP_ATTACH_CHAIN(i_pak, top, sndlen); |
michael@0 | 14241 | top = NULL; |
michael@0 | 14242 | } else { |
michael@0 | 14243 | (void)SCTP_RELEASE_HEADER(i_pak); |
michael@0 | 14244 | } |
michael@0 | 14245 | } else { |
michael@0 | 14246 | /* This is to handle cases when top has |
michael@0 | 14247 | * been reset to NULL but pak might not |
michael@0 | 14248 | * be freed |
michael@0 | 14249 | */ |
michael@0 | 14250 | if (i_pak) { |
michael@0 | 14251 | (void)SCTP_RELEASE_HEADER(i_pak); |
michael@0 | 14252 | } |
michael@0 | 14253 | } |
michael@0 | 14254 | #endif |
michael@0 | 14255 | #ifdef INVARIANTS |
michael@0 | 14256 | if (inp) { |
michael@0 | 14257 | sctp_validate_no_locks(inp); |
michael@0 | 14258 | } else { |
michael@0 | 14259 | SCTP_PRINTF("Warning - inp is NULL so cant validate locks\n"); |
michael@0 | 14260 | } |
michael@0 | 14261 | #endif |
michael@0 | 14262 | if (top) { |
michael@0 | 14263 | sctp_m_freem(top); |
michael@0 | 14264 | } |
michael@0 | 14265 | if (control) { |
michael@0 | 14266 | sctp_m_freem(control); |
michael@0 | 14267 | } |
michael@0 | 14268 | return (error); |
michael@0 | 14269 | } |
michael@0 | 14270 | |
michael@0 | 14271 | |
michael@0 | 14272 | /* |
michael@0 | 14273 | * generate an AUTHentication chunk, if required |
michael@0 | 14274 | */ |
michael@0 | 14275 | struct mbuf * |
michael@0 | 14276 | sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, |
michael@0 | 14277 | struct sctp_auth_chunk **auth_ret, uint32_t * offset, |
michael@0 | 14278 | struct sctp_tcb *stcb, uint8_t chunk) |
michael@0 | 14279 | { |
michael@0 | 14280 | struct mbuf *m_auth; |
michael@0 | 14281 | struct sctp_auth_chunk *auth; |
michael@0 | 14282 | int chunk_len; |
michael@0 | 14283 | struct mbuf *cn; |
michael@0 | 14284 | |
michael@0 | 14285 | if ((m_end == NULL) || (auth_ret == NULL) || (offset == NULL) || |
michael@0 | 14286 | (stcb == NULL)) |
michael@0 | 14287 | return (m); |
michael@0 | 14288 | |
michael@0 | 14289 | /* sysctl disabled auth? */ |
michael@0 | 14290 | if (SCTP_BASE_SYSCTL(sctp_auth_disable)) |
michael@0 | 14291 | return (m); |
michael@0 | 14292 | |
michael@0 | 14293 | /* peer doesn't do auth... */ |
michael@0 | 14294 | if (!stcb->asoc.peer_supports_auth) { |
michael@0 | 14295 | return (m); |
michael@0 | 14296 | } |
michael@0 | 14297 | /* does the requested chunk require auth? */ |
michael@0 | 14298 | if (!sctp_auth_is_required_chunk(chunk, stcb->asoc.peer_auth_chunks)) { |
michael@0 | 14299 | return (m); |
michael@0 | 14300 | } |
michael@0 | 14301 | m_auth = sctp_get_mbuf_for_msg(sizeof(*auth), 0, M_NOWAIT, 1, MT_HEADER); |
michael@0 | 14302 | if (m_auth == NULL) { |
michael@0 | 14303 | /* no mbuf's */ |
michael@0 | 14304 | return (m); |
michael@0 | 14305 | } |
michael@0 | 14306 | /* reserve some space if this will be the first mbuf */ |
michael@0 | 14307 | if (m == NULL) |
michael@0 | 14308 | SCTP_BUF_RESV_UF(m_auth, SCTP_MIN_OVERHEAD); |
michael@0 | 14309 | /* fill in the AUTH chunk details */ |
michael@0 | 14310 | auth = mtod(m_auth, struct sctp_auth_chunk *); |
michael@0 | 14311 | bzero(auth, sizeof(*auth)); |
michael@0 | 14312 | auth->ch.chunk_type = SCTP_AUTHENTICATION; |
michael@0 | 14313 | auth->ch.chunk_flags = 0; |
michael@0 | 14314 | chunk_len = sizeof(*auth) + |
michael@0 | 14315 | sctp_get_hmac_digest_len(stcb->asoc.peer_hmac_id); |
michael@0 | 14316 | auth->ch.chunk_length = htons(chunk_len); |
michael@0 | 14317 | auth->hmac_id = htons(stcb->asoc.peer_hmac_id); |
michael@0 | 14318 | /* key id and hmac digest will be computed and filled in upon send */ |
michael@0 | 14319 | |
michael@0 | 14320 | /* save the offset where the auth was inserted into the chain */ |
michael@0 | 14321 | *offset = 0; |
michael@0 | 14322 | for (cn = m; cn; cn = SCTP_BUF_NEXT(cn)) { |
michael@0 | 14323 | *offset += SCTP_BUF_LEN(cn); |
michael@0 | 14324 | } |
michael@0 | 14325 | |
michael@0 | 14326 | /* update length and return pointer to the auth chunk */ |
michael@0 | 14327 | SCTP_BUF_LEN(m_auth) = chunk_len; |
michael@0 | 14328 | m = sctp_copy_mbufchain(m_auth, m, m_end, 1, chunk_len, 0); |
michael@0 | 14329 | if (auth_ret != NULL) |
michael@0 | 14330 | *auth_ret = auth; |
michael@0 | 14331 | |
michael@0 | 14332 | return (m); |
michael@0 | 14333 | } |
michael@0 | 14334 | |
michael@0 | 14335 | #if defined(__FreeBSD__) || defined(__APPLE__) |
michael@0 | 14336 | #ifdef INET6 |
michael@0 | 14337 | int |
michael@0 | 14338 | sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro) |
michael@0 | 14339 | { |
michael@0 | 14340 | struct nd_prefix *pfx = NULL; |
michael@0 | 14341 | struct nd_pfxrouter *pfxrtr = NULL; |
michael@0 | 14342 | struct sockaddr_in6 gw6; |
michael@0 | 14343 | |
michael@0 | 14344 | if (ro == NULL || ro->ro_rt == NULL || src6->sin6_family != AF_INET6) |
michael@0 | 14345 | return (0); |
michael@0 | 14346 | |
michael@0 | 14347 | /* get prefix entry of address */ |
michael@0 | 14348 | LIST_FOREACH(pfx, &MODULE_GLOBAL(nd_prefix), ndpr_entry) { |
michael@0 | 14349 | if (pfx->ndpr_stateflags & NDPRF_DETACHED) |
michael@0 | 14350 | continue; |
michael@0 | 14351 | if (IN6_ARE_MASKED_ADDR_EQUAL(&pfx->ndpr_prefix.sin6_addr, |
michael@0 | 14352 | &src6->sin6_addr, &pfx->ndpr_mask)) |
michael@0 | 14353 | break; |
michael@0 | 14354 | } |
michael@0 | 14355 | /* no prefix entry in the prefix list */ |
michael@0 | 14356 | if (pfx == NULL) { |
michael@0 | 14357 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "No prefix entry for "); |
michael@0 | 14358 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)src6); |
michael@0 | 14359 | return (0); |
michael@0 | 14360 | } |
michael@0 | 14361 | |
michael@0 | 14362 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "v6src_match_nexthop(), Prefix entry is "); |
michael@0 | 14363 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)src6); |
michael@0 | 14364 | |
michael@0 | 14365 | /* search installed gateway from prefix entry */ |
michael@0 | 14366 | LIST_FOREACH(pfxrtr, &pfx->ndpr_advrtrs, pfr_entry) { |
michael@0 | 14367 | memset(&gw6, 0, sizeof(struct sockaddr_in6)); |
michael@0 | 14368 | gw6.sin6_family = AF_INET6; |
michael@0 | 14369 | #ifdef HAVE_SIN6_LEN |
michael@0 | 14370 | gw6.sin6_len = sizeof(struct sockaddr_in6); |
michael@0 | 14371 | #endif |
michael@0 | 14372 | memcpy(&gw6.sin6_addr, &pfxrtr->router->rtaddr, |
michael@0 | 14373 | sizeof(struct in6_addr)); |
michael@0 | 14374 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "prefix router is "); |
michael@0 | 14375 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)&gw6); |
michael@0 | 14376 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "installed router is "); |
michael@0 | 14377 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, ro->ro_rt->rt_gateway); |
michael@0 | 14378 | if (sctp_cmpaddr((struct sockaddr *)&gw6, |
michael@0 | 14379 | ro->ro_rt->rt_gateway)) { |
michael@0 | 14380 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "pfxrouter is installed\n"); |
michael@0 | 14381 | return (1); |
michael@0 | 14382 | } |
michael@0 | 14383 | } |
michael@0 | 14384 | SCTPDBG(SCTP_DEBUG_OUTPUT2, "pfxrouter is not installed\n"); |
michael@0 | 14385 | return (0); |
michael@0 | 14386 | } |
michael@0 | 14387 | #endif |
michael@0 | 14388 | |
michael@0 | 14389 | int |
michael@0 | 14390 | sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro) |
michael@0 | 14391 | { |
michael@0 | 14392 | #ifdef INET |
michael@0 | 14393 | struct sockaddr_in *sin, *mask; |
michael@0 | 14394 | struct ifaddr *ifa; |
michael@0 | 14395 | struct in_addr srcnetaddr, gwnetaddr; |
michael@0 | 14396 | |
michael@0 | 14397 | if (ro == NULL || ro->ro_rt == NULL || |
michael@0 | 14398 | sifa->address.sa.sa_family != AF_INET) { |
michael@0 | 14399 | return (0); |
michael@0 | 14400 | } |
michael@0 | 14401 | ifa = (struct ifaddr *)sifa->ifa; |
michael@0 | 14402 | mask = (struct sockaddr_in *)(ifa->ifa_netmask); |
michael@0 | 14403 | sin = (struct sockaddr_in *)&sifa->address.sin; |
michael@0 | 14404 | srcnetaddr.s_addr = (sin->sin_addr.s_addr & mask->sin_addr.s_addr); |
michael@0 | 14405 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "match_nexthop4: src address is "); |
michael@0 | 14406 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &sifa->address.sa); |
michael@0 | 14407 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "network address is %x\n", srcnetaddr.s_addr); |
michael@0 | 14408 | |
michael@0 | 14409 | sin = (struct sockaddr_in *)ro->ro_rt->rt_gateway; |
michael@0 | 14410 | gwnetaddr.s_addr = (sin->sin_addr.s_addr & mask->sin_addr.s_addr); |
michael@0 | 14411 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "match_nexthop4: nexthop is "); |
michael@0 | 14412 | SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, ro->ro_rt->rt_gateway); |
michael@0 | 14413 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "network address is %x\n", gwnetaddr.s_addr); |
michael@0 | 14414 | if (srcnetaddr.s_addr == gwnetaddr.s_addr) { |
michael@0 | 14415 | return (1); |
michael@0 | 14416 | } |
michael@0 | 14417 | #endif |
michael@0 | 14418 | return (0); |
michael@0 | 14419 | } |
michael@0 | 14420 | #elif defined(__Userspace__) |
michael@0 | 14421 | /* TODO __Userspace__ versions of sctp_vXsrc_match_nexthop(). */ |
michael@0 | 14422 | int |
michael@0 | 14423 | sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro) |
michael@0 | 14424 | { |
michael@0 | 14425 | return (0); |
michael@0 | 14426 | } |
michael@0 | 14427 | int |
michael@0 | 14428 | sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro) |
michael@0 | 14429 | { |
michael@0 | 14430 | return (0); |
michael@0 | 14431 | } |
michael@0 | 14432 | |
michael@0 | 14433 | #endif |