Lines Matching +full:always +full:- +full:wait +full:- +full:for +full:- +full:ack
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2005-2014 Sandvine Incorporated. All rights reserved.
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
106 * Simple accessors for opaque PCB.
112 pcb->dp_state >= DN_STATE_HAVE_GW_MAC); in debugnet_get_gw_mac()
113 return (pcb->dp_gw_mac.octet); in debugnet_get_gw_mac()
120 pcb->dp_state >= DN_STATE_GOT_HERALD_PORT); in debugnet_get_server_addr()
121 return (&pcb->dp_server); in debugnet_get_server_addr()
128 pcb->dp_state >= DN_STATE_GOT_HERALD_PORT); in debugnet_get_server_port()
129 return (pcb->dp_server_port); in debugnet_get_server_port()
138 * the tx buffer for the NIC
146 * etype The ETHERTYPE_* value for the protocol that is being sent
149 * int see errno.h, 0 for success
157 if (((ifp->if_flags & (IFF_MONITOR | IFF_UP)) != IFF_UP) || in debugnet_ether_output()
158 (ifp->if_drv_flags & IFF_DRV_RUNNING) != IFF_DRV_RUNNING) { in debugnet_ether_output()
171 memcpy(eh->ether_shost, IF_LLADDR(ifp), ETHER_ADDR_LEN); in debugnet_ether_output()
172 memcpy(eh->ether_dhost, dst.octet, ETHER_ADDR_LEN); in debugnet_ether_output()
173 eh->ether_type = htons(etype); in debugnet_ether_output()
174 return (ifp->if_debugnet_methods->dn_transmit(ifp, m)); in debugnet_ether_output()
180 * ifp->if_mtu after adding the UDP/IP headers
187 * int see errno.h, 0 for success
194 MPASS(pcb->dp_state >= DN_STATE_HAVE_GW_MAC); in debugnet_udp_output()
203 udp->uh_ulen = htons(m->m_pkthdr.len); in debugnet_udp_output()
205 udp->uh_sport = htons(pcb->dp_client_port); in debugnet_udp_output()
206 udp->uh_dport = htons(pcb->dp_server_port); in debugnet_udp_output()
207 /* Computed later (protocol-dependent). */ in debugnet_udp_output()
208 udp->uh_sum = 0; in debugnet_udp_output()
226 m->m_len = sizeof(*dn_ack); in debugnet_ack_output()
227 m->m_pkthdr.len = sizeof(*dn_ack); in debugnet_ack_output()
230 dn_ack->da_seqno = seqno; in debugnet_ack_output()
236 * Dummy free function for debugnet clusters.
245 * shortage or extreme number of unacknowledged retransmissions. Wait for
256 * int see errno.h, 0 for success
268 if (pcb->dp_state == DN_STATE_REMOTE_CLOSED) in debugnet_send()
272 pcb->dp_rcvd_acks = 0; in debugnet_send()
277 for (i = sent_so_far = 0; sent_so_far < datalen || in debugnet_send()
279 pktlen = datalen - sent_so_far; in debugnet_send()
282 pktlen = min(pktlen, pcb->dp_ifp->if_mtu - in debugnet_send()
283 sizeof(struct udpiphdr) - sizeof(struct debugnet_msg_hdr)); in debugnet_send()
289 if ((pcb->dp_rcvd_acks & (1 << i)) != 0) { in debugnet_send()
303 m->m_len = sizeof(struct debugnet_msg_hdr); in debugnet_send()
304 m->m_pkthdr.len = sizeof(struct debugnet_msg_hdr); in debugnet_send()
307 dn_msg_hdr->mh_seqno = htonl(pcb->dp_seqno + i); in debugnet_send()
308 dn_msg_hdr->mh_type = htonl(type); in debugnet_send()
309 dn_msg_hdr->mh_len = htonl(pktlen); in debugnet_send()
312 dn_msg_hdr->mh_offset = in debugnet_send()
313 htobe64(auxdata->dp_offset_start + sent_so_far); in debugnet_send()
314 dn_msg_hdr->mh_aux2 = htobe32(auxdata->dp_aux2); in debugnet_send()
316 dn_msg_hdr->mh_offset = htobe64(sent_so_far); in debugnet_send()
317 dn_msg_hdr->mh_aux2 = 0; in debugnet_send()
330 m2->m_len = pktlen; in debugnet_send()
333 m->m_pkthdr.len += pktlen; in debugnet_send()
339 /* Note that we're waiting for this packet in the bitfield. */ in debugnet_send()
350 * Wait for acks. A *real* window would speed things up considerably. in debugnet_send()
353 while (pcb->dp_rcvd_acks != want_acks) { in debugnet_send()
362 if (pcb->dp_state == DN_STATE_REMOTE_CLOSED) in debugnet_send()
365 pcb->dp_seqno += i; in debugnet_send()
374 * Just introspect the header enough to fire off a seqno ack and validate
388 if (m->m_pkthdr.len < sizeof(*dnh)) { in debugnet_handle_rx_msg()
394 if (m->m_len < sizeof(*dnh)) { in debugnet_handle_rx_msg()
404 if (ntohl(dnh->mh_len) + sizeof(*dnh) > m->m_pkthdr.len) { in debugnet_handle_rx_msg()
409 hdr_type = ntohl(dnh->mh_type); in debugnet_handle_rx_msg()
413 pcb->dp_state = DN_STATE_REMOTE_CLOSED; in debugnet_handle_rx_msg()
414 if (pcb->dp_finish_handler != NULL) { in debugnet_handle_rx_msg()
415 pcb->dp_finish_handler(); in debugnet_handle_rx_msg()
425 * non-transient (like driver objecting to rx -> tx from the same in debugnet_handle_rx_msg()
428 seqno = dnh->mh_seqno; /* net endian */ in debugnet_handle_rx_msg()
431 error = pcb->dp_rx_handler(m); in debugnet_handle_rx_msg()
434 "Skipping ack.\n", error); in debugnet_handle_rx_msg()
440 DNETDEBUG("Couldn't ACK rx packet %u; %d\n", ntohl(seqno), error); in debugnet_handle_rx_msg()
453 /* Get Ack. */ in debugnet_handle_ack()
454 if (m->m_len < sizeof(*dn_ack)) { in debugnet_handle_ack()
466 * Packet is meant for us. Extract the ack sequence number and the in debugnet_handle_ack()
469 rcv_ackno = ntohl(dn_ack->da_seqno); in debugnet_handle_ack()
470 if (pcb->dp_state < DN_STATE_GOT_HERALD_PORT) { in debugnet_handle_ack()
471 pcb->dp_server_port = sport; in debugnet_handle_ack()
472 pcb->dp_state = DN_STATE_GOT_HERALD_PORT; in debugnet_handle_ack()
474 if (rcv_ackno >= pcb->dp_seqno + DEBUGNET_MAX_IN_FLIGHT) in debugnet_handle_ack()
475 printf("%s: ACK %u too far in future!\n", __func__, rcv_ackno); in debugnet_handle_ack()
476 else if (rcv_ackno >= pcb->dp_seqno) { in debugnet_handle_ack()
477 /* We're interested in this ack. Record it. */ in debugnet_handle_ack()
478 pcb->dp_rcvd_acks |= 1 << (rcv_ackno - pcb->dp_seqno); in debugnet_handle_ack()
492 if (m->m_pkthdr.len < sizeof(*udp)) { in debugnet_handle_udp()
498 if (m->m_len < sizeof(*udp)) { in debugnet_handle_udp()
509 if (ntohs(udp->uh_dport) != pcb->dp_client_port) { in debugnet_handle_udp()
515 ulen = ntohs(udp->uh_ulen); in debugnet_handle_udp()
516 if (m->m_pkthdr.len < ulen) { in debugnet_handle_udp()
521 sport = ntohs(udp->uh_sport); in debugnet_handle_udp()
524 ulen -= sizeof(*udp); in debugnet_handle_udp()
531 if (pcb->dp_rx_handler == NULL) { in debugnet_handle_udp()
533 DNETDEBUG("ignoring small ACK packet\n"); in debugnet_handle_udp()
535 DNETDEBUG("ignoring unexpected non-ACK packet on " in debugnet_handle_udp()
536 "half-duplex connection.\n"); in debugnet_handle_udp()
544 * Handler for incoming packets directly from the network adapter
563 if ((m->m_flags & M_PKTHDR) == 0) { in debugnet_input_one()
567 if (m->m_len < ETHER_HDR_LEN) { in debugnet_input_one()
570 m->m_len, m->m_pkthdr.len); in debugnet_input_one()
574 etype = ntohs(eh->ether_type); in debugnet_input_one()
575 if ((m->m_flags & M_VLANTAG) != 0 || etype == ETHERTYPE_VLAN) { in debugnet_input_one()
580 DNETDEBUG_IF(ifp, "failed to get hw addr for interface\n"); in debugnet_input_one()
583 if (memcmp(ifr.ifr_addr.sa_data, eh->ether_dhost, in debugnet_input_one()
585 (etype != ETHERTYPE_ARP || !ETHER_IS_BROADCAST(eh->ether_dhost))) { in debugnet_input_one()
617 n = m->m_nextpkt; in debugnet_input()
618 m->m_nextpkt = NULL; in debugnet_input()
628 * driver directly for packets.
635 ifp = pcb->dp_ifp; in debugnet_network_poll()
636 ifp->if_debugnet_methods->dn_poll(ifp, 1000); in debugnet_network_poll()
648 MPASS(pcb->dp_drv_input == NULL || g_debugnet_pcb_inuse); in debugnet_free()
650 ifp = pcb->dp_ifp; in debugnet_free()
652 if (pcb->dp_drv_input != NULL) in debugnet_free()
653 ifp->if_input = pcb->dp_drv_input; in debugnet_free()
654 if (pcb->dp_event_started) in debugnet_free()
655 ifp->if_debugnet_methods->dn_event(ifp, DEBUGNET_END); in debugnet_free()
680 .dp_client = dcp->dc_client, in debugnet_connect()
681 .dp_server = dcp->dc_server, in debugnet_connect()
682 .dp_gateway = dcp->dc_gateway, in debugnet_connect()
683 .dp_server_port = dcp->dc_herald_port, /* Initially */ in debugnet_connect()
684 .dp_client_port = dcp->dc_client_port, in debugnet_connect()
686 .dp_ifp = dcp->dc_ifp, in debugnet_connect()
687 .dp_rx_handler = dcp->dc_rx_handler, in debugnet_connect()
695 if (pcb->dp_client == INADDR_ANY || pcb->dp_gateway == INADDR_ANY || in debugnet_connect()
696 pcb->dp_ifp == NULL) { in debugnet_connect()
705 .sin_addr.s_addr = pcb->dp_server, in debugnet_connect()
714 printf("%s: Could not get route for that server.\n", in debugnet_connect()
721 if (nh->gw_sa.sa_family == AF_INET) in debugnet_connect()
722 gw_sin = &nh->gw4_sa; in debugnet_connect()
724 if (nh->gw_sa.sa_family == AF_LINK) in debugnet_connect()
729 MPASS(nh->nh_ifa->ifa_addr->sa_family == AF_INET); in debugnet_connect()
730 local_sin = (struct sockaddr_in *)nh->nh_ifa->ifa_addr; in debugnet_connect()
732 rt_ifp = nh->nh_ifp; in debugnet_connect()
734 if (pcb->dp_client == INADDR_ANY) in debugnet_connect()
735 pcb->dp_client = local_sin->sin_addr.s_addr; in debugnet_connect()
736 if (pcb->dp_gateway == INADDR_ANY && gw_sin != NULL) in debugnet_connect()
737 pcb->dp_gateway = gw_sin->sin_addr.s_addr; in debugnet_connect()
738 if (pcb->dp_ifp == NULL) in debugnet_connect()
739 pcb->dp_ifp = rt_ifp; in debugnet_connect()
742 ifp = pcb->dp_ifp; in debugnet_connect()
747 inet_ntop(AF_INET, &pcb->dp_server, serbuf, sizeof(serbuf)); in debugnet_connect()
748 inet_ntop(AF_INET, &pcb->dp_client, clibuf, sizeof(clibuf)); in debugnet_connect()
749 if (pcb->dp_gateway != INADDR_ANY) in debugnet_connect()
750 inet_ntop(AF_INET, &pcb->dp_gateway, gwbuf, sizeof(gwbuf)); in debugnet_connect()
752 serbuf, pcb->dp_server_port, in debugnet_connect()
753 (pcb->dp_gateway == INADDR_ANY) ? "" : " via ", in debugnet_connect()
754 (pcb->dp_gateway == INADDR_ANY) ? "" : gwbuf, in debugnet_connect()
755 clibuf, pcb->dp_client_port, if_name(ifp)); in debugnet_connect()
772 ifp->if_debugnet_methods->dn_event(ifp, DEBUGNET_START); in debugnet_connect()
773 pcb->dp_event_started = true; in debugnet_connect()
776 * We maintain the invariant that g_debugnet_pcb_inuse is always true in debugnet_connect()
783 pcb->dp_drv_input = ifp->if_input; in debugnet_connect()
784 ifp->if_input = debugnet_input; in debugnet_connect()
786 printf("%s: searching for %s MAC...\n", __func__, in debugnet_connect()
787 (dcp->dc_gateway == INADDR_ANY) ? "server" : "gateway"); in debugnet_connect()
794 MPASS(pcb->dp_state == DN_STATE_HAVE_GW_MAC); in debugnet_connect()
797 .dp_offset_start = dcp->dc_herald_offset, in debugnet_connect()
798 .dp_aux2 = dcp->dc_herald_aux2, in debugnet_connect()
800 error = debugnet_send(pcb, DEBUGNET_HERALD, dcp->dc_herald_data, in debugnet_connect()
801 dcp->dc_herald_datalen, &herald_auxdata); in debugnet_connect()
816 * Pre-allocated dump-time mbuf tracking.
819 * for that iface/mtu combo.
869 ifp->if_debugnet_methods->dn_init(ifp, &nrxr, &ncl, &clsize); in debugnet_any_ifnet_update()
880 * Bandaid for drivers that (incorrectly) advertise LinkUp before their in debugnet_any_ifnet_update()
896 * for us because drivers tend to if_attach before invoking DEBUGNET_SET().
923 * DDB parsing helpers for debugnet(4) consumers.
940 for (octet = 0; octet < 4; octet++) { in dn_parse_optarg_ipv4()
944 __func__, opt->printname, octet, t); in dn_parse_optarg_ipv4()
948 * db_lex lexes '-' distinctly from the number itself, but in dn_parse_optarg_ipv4()
955 opt->printname, octet, (intmax_t)db_tok_number); in dn_parse_optarg_ipv4()
959 /* Constructed host-endian and converted to network later. */ in dn_parse_optarg_ipv4()
966 " %d\n", __func__, opt->printname, octet, in dn_parse_optarg_ipv4()
973 *opt->result = htonl(tmp); in dn_parse_optarg_ipv4()
974 opt->has_opt = true; in dn_parse_optarg_ipv4()
988 .result = &result->dd_client, in debugnet_parse_ddb_cmd()
992 .result = &result->dd_server, in debugnet_parse_ddb_cmd()
996 .result = &result->dd_gateway, in debugnet_parse_ddb_cmd()
1004 * command [space] [-] [opt] [[space] [optarg]] ... in debugnet_parse_ddb_cmd()
1006 * db_command has already lexed 'command' for us. in debugnet_parse_ddb_cmd()
1014 db_printf("%s: Bad syntax; expected '-', got %d\n", in debugnet_parse_ddb_cmd()
1074 * re-lookups the ifp, and takes its own reference. in debugnet_parse_ddb_cmd()
1086 /* Assume IPv4 for now. */ in debugnet_parse_ddb_cmd()
1109 result->dd_has_client = opt_client.has_opt; in debugnet_parse_ddb_cmd()
1110 result->dd_has_gateway = opt_gateway.has_opt; in debugnet_parse_ddb_cmd()
1111 result->dd_ifp = ifp; in debugnet_parse_ddb_cmd()
1117 db_printf("Usage: %s -s <server> [-g <gateway> -c <localip> " in debugnet_parse_ddb_cmd()
1118 "-i <interface>]\n", cmd); in debugnet_parse_ddb_cmd()