From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3F33C1F55F for ; Sat, 30 Sep 2023 23:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yhbt.net; s=selector1; t=1696116400; bh=12L2FP0VTAknUlmFq1ujGN/3LNQPUUAldeZllfIt5OE=; h=From:To:Subject:Date:From; b=WTUqiSH3Sq0bN5ggT8laVz2ZqB15RtfuS1YJF30kulX+nN1Ez3ss3QGR4BBRXH9pC X8K3xYkaeFQkGsrDl72rgSUWQKEgG0eA4AFwEGJR/L/1nIpB0xgbNzEvz7/XVKbTbw oyU8/66xLf4xJDSZbVWCwfmY5ATxh8xVGcHP9B4U= From: Eric Wong To: raindrops-public@yhbt.net Subject: [PATCH] linux_inet_diag: avoid errors for users compiling w/o assertions Date: Sat, 30 Sep 2023 23:26:40 +0000 Message-ID: <20230930232640.27806-1-bofh@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We should warn gracefully when we hit IPv7+ or whatever... --- ext/raindrops/linux_inet_diag.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c index e4050cb..6d421e7 100644 --- a/ext/raindrops/linux_inet_diag.c +++ b/ext/raindrops/linux_inet_diag.c @@ -235,7 +235,9 @@ static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r) break; } default: - assert(0 && "unsupported address family, could that be IPv7?!"); + fprintf(stderr, "unsupported .idiag_family: %u\n", + (unsigned)r->idiag_family); + return NULL; /* can't raise w/o GVL */ } if (!inet_ntop(r->idiag_family, src, host, hostlen)) { bug_warn_nogvl("BUG: inet_ntop: %s\n", strerror(errno)); @@ -255,7 +257,8 @@ static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r) port = host + hostlen + 2; break; default: - assert(0 && "unsupported address family, could that be IPv7?!"); + assert(0 && "should never get here (returned above)"); + abort(); } n = snprintf(port, portlen, "%u", ntohs(r->id.idiag_sport)); @@ -300,12 +303,14 @@ static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r) static void table_incr_active(st_table *table, struct inet_diag_msg *r) { struct listen_stats *stats = stats_for(table, r); + if (!stats) return; ++stats->active; } static void table_set_queued(st_table *table, struct inet_diag_msg *r) { struct listen_stats *stats = stats_for(table, r); + if (!stats) return; stats->listener_p = 1; stats->queued += r->idiag_rqueue; }