| 431 | } |
| 432 | |
| 433 | void |
| 434 | tcp_switch_back_to_default(struct tcpcb *tp) |
| 435 | { |
| 436 | struct tcp_function_block *tfb; |
| 437 | |
| 438 | KASSERT(tp->t_fb != &tcp_def_funcblk, |
| 439 | ("%s: called by the built-in default stack", __func__)); |
| 440 | |
| 441 | /* |
| 442 | * Release the old stack. This function will either find a new one |
| 443 | * or panic. |
| 444 | */ |
| 445 | if (tp->t_fb->tfb_tcp_fb_fini != NULL) |
| 446 | (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0); |
| 447 | refcount_release(&tp->t_fb->tfb_refcnt); |
| 448 | |
| 449 | /* |
| 450 | * Now, we'll find a new function block to use. |
| 451 | * Start by trying the current user-selected |
| 452 | * default, unless this stack is the user-selected |
| 453 | * default. |
| 454 | */ |
| 455 | tfb = find_and_ref_tcp_default_fb(); |
| 456 | if (tfb == tp->t_fb) { |
| 457 | refcount_release(&tfb->tfb_refcnt); |
| 458 | tfb = NULL; |
| 459 | } |
| 460 | /* Does the stack accept this connection? */ |
| 461 | if (tfb != NULL && tfb->tfb_tcp_handoff_ok != NULL && |
| 462 | (*tfb->tfb_tcp_handoff_ok)(tp)) { |
| 463 | refcount_release(&tfb->tfb_refcnt); |
| 464 | tfb = NULL; |
| 465 | } |
| 466 | /* Try to use that stack. */ |
| 467 | if (tfb != NULL) { |
| 468 | /* Initialize the new stack. If it succeeds, we are done. */ |
| 469 | tp->t_fb = tfb; |
| 470 | if (tp->t_fb->tfb_tcp_fb_init == NULL || |
| 471 | (*tp->t_fb->tfb_tcp_fb_init)(tp) == 0) |
| 472 | return; |
| 473 | |
| 474 | /* |
| 475 | * Initialization failed. Release the reference count on |
| 476 | * the stack. |
| 477 | */ |
| 478 | refcount_release(&tfb->tfb_refcnt); |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * If that wasn't feasible, use the built-in default |
| 483 | * stack which is not allowed to reject anyone. |
| 484 | */ |
| 485 | tfb = find_and_ref_tcp_fb(&tcp_def_funcblk); |
| 486 | if (tfb == NULL) { |
| 487 | /* there always should be a default */ |
| 488 | panic("Can't refer to tcp_def_funcblk"); |
| 489 | } |
| 490 | if (tfb->tfb_tcp_handoff_ok != NULL) { |
no test coverage detected