From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H6Gk3UhO; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 1B91D5A0774 for ; Mon, 15 Dec 2025 02:54:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765763693; 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: in-reply-to:in-reply-to:references:references; bh=/vWrvwjKt4LLUJPRmCgmjpMOMIQw9zps5+ZdycS25cI=; b=H6Gk3UhOnio8uhE77YKnuvOb9ZY1S+pRLbOHq/YLQuhniOJbOOOKyCNYDPB5DYBrmq2mFB acautkM5bOqL5VRGDchts7ITvWQzsIyZ9i9HlT3/Jg2Ouv3S5v+xItddvWvFSj1QPgWDu1 6V4+cmaC/NRWdR0tyT4soShnT2ny/dQ= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-676-x384pUQ2N0yFFNuGtstaBA-1; Sun, 14 Dec 2025 20:54:50 -0500 X-MC-Unique: x384pUQ2N0yFFNuGtstaBA-1 X-Mimecast-MFC-AGG-ID: x384pUQ2N0yFFNuGtstaBA_1765763689 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37F6D180060D; Mon, 15 Dec 2025 01:54:49 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.88.123]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5F1DA30001A2; Mon, 15 Dec 2025 01:54:48 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, dgibson@redhat.com, david@gibson.dropbear.id.au, jmaloy@redhat.com, passt-dev@passt.top Subject: [RFC 04/12] conf: Apply -n/--netmask to most recently added address Date: Sun, 14 Dec 2025 20:54:33 -0500 Message-ID: <20251215015441.887736-5-jmaloy@redhat.com> In-Reply-To: <20251215015441.887736-1-jmaloy@redhat.com> References: <20251215015441.887736-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7U8dppyEtVE9XWmnGNEtznRL4-jXav14hW81Up99UDc_1765763689 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: HE3ALVDVCCKYNFHYHUY4UZTIVFI3TBAA X-Message-ID-Hash: HE3ALVDVCCKYNFHYHUY4UZTIVFI3TBAA X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We allow for multiple -n/--netmask options, and update the handling so that each given prefix length is applied to the most recently added address instead of always to addrs[0]. This allows per-address prefix configuration, such as: -a 10.0.0.1 -n 24 -a 10.0.0.2 -n 16 If no address has been added yet, -n still applies to addrs[0] for backwards compatibility. Signed-off-by: Jon Maloy --- conf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/conf.c b/conf.c index e9f217b..0a4a28a 100644 --- a/conf.c +++ b/conf.c @@ -1528,6 +1528,7 @@ void conf(struct ctx *c, int argc, char **argv) size_t logsize = 0; char *runas = NULL; long fd_tap_opt; + int prefix, idx; int name, ret; uid_t uid; gid_t gid; @@ -1872,10 +1873,14 @@ void conf(struct ctx *c, int argc, char **argv) die("Invalid address: %s", optarg); break; case 'n': - c->ip4.addrs[0].prefix_len = conf_ip4_prefix(optarg); - if (c->ip4.addrs[0].prefix_len < 0) + prefix = conf_ip4_prefix(optarg); + + if (prefix < 0) die("Invalid netmask: %s", optarg); + /* Apply to most recent address, or addrs[0] if none yet */ + idx = c->ip4.addr_count ? c->ip4.addr_count - 1 : 0; + c->ip4.addrs[idx].prefix_len = prefix; break; case 'M': parse_mac(c->our_tap_mac, optarg); -- 2.51.1