From nobody Sat May 27 16:35:44 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QT6q456ytz4V1X2; Sat, 27 May 2023 16:35:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QT6q44Nwvz3lB8; Sat, 27 May 2023 16:35:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685205344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NuOPBmAFBASbqnZPXratVWrYAxQJdR/ExKDvnLGXa7k=; b=llh1ooVJ+bWjqog7W+BZaTa2taslpKwqo3RG40SzIUtPLk08pMFoOpHhK1dbUvDnhtUeV6 hTZK+tF+gucA2kAlaIaV2ohfRlvQhH7pzwFTjTZNd2VV1rfMhMDaWG/MqJuoccXLR5q1Kv FI87IMvmHrl1A/tkxD/zFLpV868gYjOpnYwXEbU9GfWbjGcwUgMuXiNzjRnzZLDLzhVYca KGjBq1kqjQEj9ayYNUnrjsCQyx6zN5ZkOckXjjIJ5lQfmooQJ3Z6BENgOIXJ3TU5VGWLoy g5G841ObqGFpVgza00i2e8TRUf6Ij4ReZcuXzgzNSG4XwpE0B6bktu5mY25Ezg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685205344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NuOPBmAFBASbqnZPXratVWrYAxQJdR/ExKDvnLGXa7k=; b=Dli40rGyTjrVM+YKFrYMpP0f8Wp4FqG46BV34I0RudheRrBzKtK0CsMBXlT9apcajpuGjh eZ63MfdqsqhlHQLzgzN+xuTezznplCIBVfFIvvd9JY2vtpLfUQrKM8gPLrE92BTZlryqpz 6lD3VRJH8fvCsWu8pwht2E7RC94MnIEEm4d1K60msneI9irXTpv5euHYy3oobRXvrVkMgi p37W38PUz54sqahzTe9B0q/8vJx7DzLo7iod+ZYKFv5Nu7CGC0/qsb5h5UqekfUWEECJL4 lO15qAVBnsnUvS45YWVDZ8h3/MYxd55bOPs7oBGytFNv1docJgCm2ee/ylhdyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685205344; a=rsa-sha256; cv=none; b=wt8JRusLn7kqzviTMPiN8MmKM56VzuO6Dpakd3XqWMKabCsRaA+BDhUgKxDoiNFjT8Q3Z2 bkNc1M0GHk7sr4Rnlw//yyCL87uITz68cyNfGZV+rtCxmalWCY5ZMwZjncmGHCzoPZtZYe ZgBEZPHf5aKFvOh8lEPNVGmb44bWDU4U6rYDDNPSMmga9BaozmNpWNdmeWDbbtOFocJpFv wuBoKmJowYlNm2+KVBElc8lJV2cxXAZO3D1Xj61kg/QCC9zU2uLkJ6Z5TLbX+GgH5T41ZR dAlVu0xkn0Y92V5Jt69f5z2DQFMbG+6Q9GyA626XScy0G+bBG1KPDbvqiRPgaA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QT6q4397FzvjJ; Sat, 27 May 2023 16:35:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34RGZiAp032693; Sat, 27 May 2023 16:35:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34RGZi19032692; Sat, 27 May 2023 16:35:44 GMT (envelope-from git) Date: Sat, 27 May 2023 16:35:44 GMT Message-Id: <202305271635.34RGZi19032692@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bryan Drewery Subject: git: b498331b037f - main - netgdb: Fix netgdb double ack, print proxy address List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bdrewery X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b498331b037f20bde90b46fc37678fbd421dcf09 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bdrewery: URL: https://cgit.FreeBSD.org/src/commit/?id=b498331b037f20bde90b46fc37678fbd421dcf09 commit b498331b037f20bde90b46fc37678fbd421dcf09 Author: John Reimer AuthorDate: 2023-05-27 02:48:14 +0000 Commit: Bryan Drewery CommitDate: 2023-05-27 16:34:17 +0000 netgdb: Fix netgdb double ack, print proxy address - Fixes netgdb's double ack - Moving ack responsibility to debugnet, decision to ack made by netdump/netgdb. - Finish responsibility moved to debugnet, new finish handler. - netgdb now prints the address to connect to in case the user doesn't have access to the proxy machine. Sponsored by: Dell EMC Reviewed By: markj, bdrewery (earlier version) Differential Revision: https://reviews.freebsd.org/D40064 --- sys/gdb/netgdb.c | 76 ++++++++++++++++++++------------------------------ sys/net/debugnet.c | 57 ++++++++++++++++++++++++++++--------- sys/net/debugnet.h | 15 +++++++++- sys/net/debugnet_int.h | 6 ++-- 4 files changed, 93 insertions(+), 61 deletions(-) diff --git a/sys/gdb/netgdb.c b/sys/gdb/netgdb.c index dc426adea766..58e02bb97d28 100644 --- a/sys/gdb/netgdb.c +++ b/sys/gdb/netgdb.c @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$"); #error "NetGDB cannot be used without DDB at this time" #endif +#include #include #include #include @@ -110,64 +111,27 @@ static int *netgdb_prev_kdb_inactive; /* TODO(CEM) disable ack mode */ /* - * Receive non-TX ACK packets on the client port. + * Attempt to accept the incoming packet. If we run into ENOBUFS or another + * error, return it. * - * The mbuf chain will have all non-debugnet framing headers removed - * (ethernet, inet, udp). It will start with a debugnet_msg_hdr, of - * which the header is guaranteed to be contiguous. If m_pullup is - * used, the supplied in-out mbuf pointer should be updated - * appropriately. - * - * If the handler frees the mbuf chain, it should set the mbuf pointer - * to NULL. Otherwise, the debugnet input framework will free the - * chain. + * The mbuf chain will have all framing headers removed (ethernet, inet, udp, + * debugnet). */ -static void -netgdb_rx(struct debugnet_pcb *pcb, struct mbuf **mb) +static int +netgdb_rx(struct mbuf *m) { - const struct debugnet_msg_hdr *dnh; - struct mbuf *m; uint32_t rlen, count; - int error; - - m = *mb; - dnh = mtod(m, const void *); - - if (ntohl(dnh->mh_type) == DEBUGNET_FINISHED) { - sbuf_putc(&netgdb_rxsb, CTRL('C')); - return; - } - - if (ntohl(dnh->mh_type) != DEBUGNET_DATA) { - printf("%s: Got unexpected debugnet message %u\n", - __func__, ntohl(dnh->mh_type)); - return; - } - rlen = ntohl(dnh->mh_len); + rlen = m->m_pkthdr.len; #define _SBUF_FREESPACE(s) ((s)->s_size - ((s)->s_len + 1)) if (_SBUF_FREESPACE(&netgdb_rxsb) < rlen) { NETGDB_DEBUG("Backpressure: Not ACKing RX of packet that " "would overflow our buffer (%zd/%zd used).\n", netgdb_rxsb.s_len, netgdb_rxsb.s_size); - return; + return (ENOBUFS); } #undef _SBUF_FREESPACE - error = debugnet_ack_output(pcb, dnh->mh_seqno); - if (error != 0) { - printf("%s: Couldn't ACK rx packet %u; %d\n", __func__, - ntohl(dnh->mh_seqno), error); - /* - * Sender will re-xmit, and assuming the condition is - * transient, we'll process the packet's contentss later. - */ - return; - } - - m_adj(m, sizeof(*dnh)); - dnh = NULL; - /* * Inlined m_apply -- why isn't there a macro or inline function * version? @@ -181,6 +145,13 @@ netgdb_rx(struct debugnet_pcb *pcb, struct mbuf **mb) rlen -= count; m = m->m_next; } + return (0); +} + +static void +netgdb_finish(void) +{ + sbuf_putc(&netgdb_rxsb, CTRL('C')); } /* @@ -338,6 +309,7 @@ DB_COMMAND_FLAGS(netgdb, db_netgdb_cmd, CS_OWN) struct debugnet_ddb_config params; struct debugnet_conn_params dcp; struct debugnet_pcb *pcb; + char proxy_buf[INET_ADDRSTRLEN]; int error; if (!KERNEL_PANICKED()) { @@ -374,6 +346,7 @@ DB_COMMAND_FLAGS(netgdb, db_netgdb_cmd, CS_OWN) .dc_client_port = NETGDB_CLIENTPORT, .dc_herald_aux2 = NETGDB_PROTO_V1, .dc_rx_handler = netgdb_rx, + .dc_finish_handler = netgdb_finish, }; error = debugnet_connect(&dcp, &pcb); @@ -398,6 +371,19 @@ DB_COMMAND_FLAGS(netgdb, db_netgdb_cmd, CS_OWN) db_cmd_loop_done = 1; gdb_return_to_ddb = true; db_printf("(detaching GDB will return control to DDB)\n"); + + const in_addr_t *proxy_addr = debugnet_get_server_addr(netgdb_conn); + const uint16_t proxy_port = debugnet_get_server_port(netgdb_conn) + 1; + inet_ntop(AF_INET, proxy_addr, proxy_buf, sizeof(proxy_buf)); + if (inet_ntop(AF_INET, proxy_addr, proxy_buf, sizeof(proxy_buf)) == NULL) { + db_printf("Connected to proxy. " + "Use target remote :%hu to begin debugging.\n", + proxy_port); + } else { + db_printf("Connected to proxy. " + "Use target remote %s:%hu to begin debugging.\n", + proxy_buf, proxy_port); + } #if 0 /* Aspirational, but does not work reliably. */ db_printf("(ctrl-c will return control to ddb)\n"); diff --git a/sys/net/debugnet.c b/sys/net/debugnet.c index 96cd61b4dd10..cefdd4f582ce 100644 --- a/sys/net/debugnet.c +++ b/sys/net/debugnet.c @@ -115,6 +115,22 @@ debugnet_get_gw_mac(const struct debugnet_pcb *pcb) return (pcb->dp_gw_mac.octet); } +const in_addr_t * +debugnet_get_server_addr(const struct debugnet_pcb *pcb) +{ + MPASS(g_debugnet_pcb_inuse && pcb == &g_dnet_pcb && + pcb->dp_state >= DN_STATE_GOT_HERALD_PORT); + return (&pcb->dp_server); +} + +const uint16_t +debugnet_get_server_port(const struct debugnet_pcb *pcb) +{ + MPASS(g_debugnet_pcb_inuse && pcb == &g_dnet_pcb && + pcb->dp_state >= DN_STATE_GOT_HERALD_PORT); + return (pcb->dp_server_port); +} + /* * Start of network primitives, beginning with output primitives. */ @@ -365,6 +381,8 @@ debugnet_handle_rx_msg(struct debugnet_pcb *pcb, struct mbuf **mb) { const struct debugnet_msg_hdr *dnh; struct mbuf *m; + uint32_t hdr_type; + uint32_t seqno; int error; m = *mb; @@ -383,33 +401,46 @@ debugnet_handle_rx_msg(struct debugnet_pcb *pcb, struct mbuf **mb) return; } } - dnh = mtod(m, const void *); + dnh = mtod(m, const void *); if (ntohl(dnh->mh_len) + sizeof(*dnh) > m->m_pkthdr.len) { DNETDEBUG("Dropping short packet.\n"); return; } + hdr_type = ntohl(dnh->mh_type); + if (hdr_type != DEBUGNET_DATA) { + if (hdr_type == DEBUGNET_FINISHED) { + printf("Remote shut down the connection on us!\n"); + pcb->dp_state = DN_STATE_REMOTE_CLOSED; + if (pcb->dp_finish_handler != NULL) { + pcb->dp_finish_handler(); + } + } else { + DNETDEBUG("Got unexpected debugnet message %u\n", hdr_type); + } + return; + } + /* * If the issue is transient (ENOBUFS), sender should resend. If * non-transient (like driver objecting to rx -> tx from the same * thread), not much else we can do. */ - error = debugnet_ack_output(pcb, dnh->mh_seqno); - if (error != 0) + seqno = dnh->mh_seqno; /* net endian */ + m_adj(m, sizeof(*dnh)); + dnh = NULL; + error = pcb->dp_rx_handler(m); + if (error != 0) { + DNETDEBUG("RX handler was not able to accept message, error %d. " + "Skipping ack.\n", error); return; - - if (ntohl(dnh->mh_type) == DEBUGNET_FINISHED) { - printf("Remote shut down the connection on us!\n"); - pcb->dp_state = DN_STATE_REMOTE_CLOSED; - - /* - * Continue through to the user handler so they are signalled - * not to wait for further rx. - */ } - pcb->dp_rx_handler(pcb, mb); + error = debugnet_ack_output(pcb, seqno); + if (error != 0) { + DNETDEBUG("Couldn't ACK rx packet %u; %d\n", ntohl(seqno), error); + } } static void diff --git a/sys/net/debugnet.h b/sys/net/debugnet.h index 4d209df4cd8b..81962070c9e3 100644 --- a/sys/net/debugnet.h +++ b/sys/net/debugnet.h @@ -134,7 +134,10 @@ struct debugnet_conn_params { * * The handler should ACK receieved packets with debugnet_ack_output. */ - void (*dc_rx_handler)(struct debugnet_pcb *, struct mbuf **); + int (*dc_rx_handler)(struct mbuf *); + + /* Cleanup signal for bidirectional protocols. */ + void (*dc_finish_handler)(void); }; /* @@ -207,6 +210,16 @@ void debugnet_network_poll(struct debugnet_pcb *); */ const unsigned char *debugnet_get_gw_mac(const struct debugnet_pcb *); +/* + * Get the connected server address. + */ +const in_addr_t *debugnet_get_server_addr(const struct debugnet_pcb *); + +/* + * Get the connected server port. + */ +const uint16_t debugnet_get_server_port(const struct debugnet_pcb *); + /* * Callbacks from core mbuf code. */ diff --git a/sys/net/debugnet_int.h b/sys/net/debugnet_int.h index 982000248374..b6c5f2cecff1 100644 --- a/sys/net/debugnet_int.h +++ b/sys/net/debugnet_int.h @@ -69,8 +69,10 @@ struct debugnet_pcb { void (*dp_drv_input)(struct ifnet *, struct mbuf *); /* RX handler for bidirectional protocols. */ - void (*dp_rx_handler)(struct debugnet_pcb *, - struct mbuf **); + int (*dp_rx_handler)(struct mbuf *); + + /* Cleanup signal for bidirectional protocols. */ + void (*dp_finish_handler)(void); enum dnet_pcb_st dp_state; uint16_t dp_client_port;