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=CcJk6S6e; 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 41AB05A027C for ; Thu, 14 Aug 2025 11:49:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755164967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zsqBF5GJR0PFpiiidCxPR6ZBlixg1J0bI+jSUfe1FOE=; b=CcJk6S6eMCEm16XpCleGNh3OgBRHR/DbtXMWFEuJ8EfZ6Q/rmavoXazqSvOYcB1qp7dS7E ii+FPMDWyqAs2umEJwxJzhbbHwHsgbMBaNprYsoxQDLKUpSVXY1pWlltSpW0GGf0HNNE+1 5/u0q9+NIv1rAm+aQCE3Ycg4b6rbP9k= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-186-tT9PkcCeOf2avxNVqzsfRA-1; Thu, 14 Aug 2025 05:49:23 -0400 X-MC-Unique: tT9PkcCeOf2avxNVqzsfRA-1 X-Mimecast-MFC-AGG-ID: tT9PkcCeOf2avxNVqzsfRA_1755164962 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A8A0019560B6; Thu, 14 Aug 2025 09:49:22 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.225.81]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 548661800446; Thu, 14 Aug 2025 09:49:21 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v10 14/30] dhcpv6: Extract sending of NotOnLink status Date: Thu, 14 Aug 2025 11:48:33 +0200 Message-ID: <20250814094849.919709-15-lvivier@redhat.com> In-Reply-To: <20250814094849.919709-1-lvivier@redhat.com> References: <20250814094849.919709-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: fJAI__WoIAVnOhNTkDxpW55lThOcLRAImGg3w3Qkg5M_1755164962 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: OQY7ZHLM6GP2IQZZWSTUTURUDYZNTBY5 X-Message-ID-Hash: OQY7ZHLM6GP2IQZZWSTUTURUDYZNTBY5 X-MailFrom: lvivier@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 CC: Laurent Vivier , David Gibson 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: Extract code from dhcpv6() into a new function, dhcpv6_send_ia_notonlink() Signed-off-by: Laurent Vivier Reviewed-by: David Gibson --- dhcpv6.c | 60 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/dhcpv6.c b/dhcpv6.c index 1e540bb84f0d..8e6c29df205d 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -357,6 +357,44 @@ err: return ia; } +/** + * dhcpv6_send_ia_notonlink() - Send NotOnLink status + * @c: Execution context + * @ia: Pointer to non-appropriate IA_NA or IA_TA + * @client_id: Client ID message option + * xid: Transaction ID for message exchange + */ +static void dhcpv6_send_ia_notonlink(struct ctx *c, struct opt_hdr *ia, + const struct opt_hdr *client_id, + uint32_t xid) +{ + const struct in6_addr *src = &c->ip6.our_tap_ll; + size_t n; + + info("DHCPv6: received CONFIRM with inappropriate IA," + " sending NotOnLink status in REPLY"); + + ia->l = htons(OPT_VSIZE(ia_na) + sizeof(sc_not_on_link)); + + n = sizeof(struct opt_ia_na); + memcpy(resp_not_on_link.var, ia, n); + memcpy(resp_not_on_link.var + n, &sc_not_on_link, + sizeof(sc_not_on_link)); + + n += sizeof(sc_not_on_link); + memcpy(resp_not_on_link.var + n, client_id, + sizeof(struct opt_hdr) + ntohs(client_id->l)); + + n += sizeof(struct opt_hdr) + ntohs(client_id->l); + + n = offsetof(struct resp_not_on_link_t, var) + n; + + resp_not_on_link.hdr.xid = xid; + + tap_udp6_send(c, src, 547, tap_ip6_daddr(c, src), 546, + xid, &resp_not_on_link, n); +} + /** * dhcpv6_dns_fill() - Fill in DNS Servers and Domain Search list options * @c: Execution context @@ -549,28 +587,8 @@ int dhcpv6(struct ctx *c, const struct pool *p, return -1; if ((bad_ia = dhcpv6_ia_notonlink(p, &c->ip6.addr))) { - info("DHCPv6: received CONFIRM with inappropriate IA," - " sending NotOnLink status in REPLY"); - - bad_ia->l = htons(OPT_VSIZE(ia_na) + - sizeof(sc_not_on_link)); - n = sizeof(struct opt_ia_na); - memcpy(resp_not_on_link.var, bad_ia, n); - - memcpy(resp_not_on_link.var + n, - &sc_not_on_link, sizeof(sc_not_on_link)); - n += sizeof(sc_not_on_link); - - memcpy(resp_not_on_link.var + n, client_id, - sizeof(struct opt_hdr) + ntohs(client_id->l)); - n += sizeof(struct opt_hdr) + ntohs(client_id->l); - - n = offsetof(struct resp_not_on_link_t, var) + n; - - resp_not_on_link.hdr.xid = mh->xid; - tap_udp6_send(c, src, 547, tap_ip6_daddr(c, src), 546, - mh->xid, &resp_not_on_link, n); + dhcpv6_send_ia_notonlink(c, bad_ia, client_id, mh->xid); return 1; } -- 2.49.0