| 614 | } |
| 615 | |
| 616 | int |
| 617 | debugnet_connect(const struct debugnet_conn_params *dcp, |
| 618 | struct debugnet_pcb **pcb_out) |
| 619 | { |
| 620 | struct debugnet_proto_aux herald_auxdata; |
| 621 | struct debugnet_pcb *pcb; |
| 622 | struct ifnet *ifp; |
| 623 | int error; |
| 624 | |
| 625 | if (g_debugnet_pcb_inuse) { |
| 626 | printf("%s: Only one connection at a time.\n", __func__); |
| 627 | return (EBUSY); |
| 628 | } |
| 629 | |
| 630 | pcb = &g_dnet_pcb; |
| 631 | *pcb = (struct debugnet_pcb) { |
| 632 | .dp_state = DN_STATE_INIT, |
| 633 | .dp_client = dcp->dc_client, |
| 634 | .dp_server = dcp->dc_server, |
| 635 | .dp_gateway = dcp->dc_gateway, |
| 636 | .dp_server_port = dcp->dc_herald_port, /* Initially */ |
| 637 | .dp_client_port = dcp->dc_client_port, |
| 638 | .dp_seqno = 1, |
| 639 | .dp_ifp = dcp->dc_ifp, |
| 640 | .dp_rx_handler = dcp->dc_rx_handler, |
| 641 | }; |
| 642 | |
| 643 | /* Switch to the debugnet mbuf zones. */ |
| 644 | debugnet_mbuf_start(); |
| 645 | |
| 646 | /* At least one needed parameter is missing; infer it. */ |
| 647 | if (pcb->dp_client == INADDR_ANY || pcb->dp_gateway == INADDR_ANY || |
| 648 | pcb->dp_ifp == NULL) { |
| 649 | struct sockaddr_in dest_sin, *gw_sin, *local_sin; |
| 650 | struct ifnet *rt_ifp; |
| 651 | struct nhop_object *nh; |
| 652 | |
| 653 | memset(&dest_sin, 0, sizeof(dest_sin)); |
| 654 | dest_sin = (struct sockaddr_in) { |
| 655 | .sin_len = sizeof(dest_sin), |
| 656 | .sin_family = AF_INET, |
| 657 | .sin_addr.s_addr = pcb->dp_server, |
| 658 | }; |
| 659 | |
| 660 | CURVNET_SET(vnet0); |
| 661 | nh = fib4_lookup_debugnet(RT_DEFAULT_FIB, dest_sin.sin_addr, 0, |
| 662 | NHR_NONE); |
| 663 | CURVNET_RESTORE(); |
| 664 | |
| 665 | if (nh == NULL) { |
| 666 | printf("%s: Could not get route for that server.\n", |
| 667 | __func__); |
| 668 | error = ENOENT; |
| 669 | goto cleanup; |
| 670 | } |
| 671 | |
| 672 | if (nh->gw_sa.sa_family == AF_INET) |
| 673 | gw_sin = &nh->gw4_sa; |
no test coverage detected