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=B3O0d1RY; 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 3B5A45A0626 for ; Fri, 11 Apr 2025 15:11:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744377064; 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=OssFGmXfLhjf3X9eYoM7NHlaXhXXSP0fXaQKhej9dRY=; b=B3O0d1RYZt49eOtrSbM8pxKMPULEI/JJiQW+pLGvRBUa+pCRnatsa/qPDbzSsxexQ9d3aV lquJCuFEiPRtyOga92edmimQaF86esINWaPNBPTZhqPEf/fInV8qFUu/FcDZyfrCJW6lbd gEiOT+yky7ZCR+na91EEo9KmyFy9Nd0= 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-350-xKUozXkaPVKox_rOGBN8Dg-1; Fri, 11 Apr 2025 09:11:00 -0400 X-MC-Unique: xKUozXkaPVKox_rOGBN8Dg-1 X-Mimecast-MFC-AGG-ID: xKUozXkaPVKox_rOGBN8Dg_1744377060 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 1A1E01955DCD for ; Fri, 11 Apr 2025 13:11:00 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.165]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DEDCC1955BF6; Fri, 11 Apr 2025 13:10:58 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2 14/20] dhcpv6: Extract sending of NotOnLink status Date: Fri, 11 Apr 2025 15:10:24 +0200 Message-ID: <20250411131031.1398006-15-lvivier@redhat.com> In-Reply-To: <20250411131031.1398006-1-lvivier@redhat.com> References: <20250411131031.1398006-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: pDL00dnmLMZtt0yFzX8C76R6J68lOBa0FjusKcDmQR8_1744377060 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: DZL7Q7IP3SERP2Z37K565HVLTF2ADTLG X-Message-ID-Hash: DZL7Q7IP3SERP2Z37K565HVLTF2ADTLG 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 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 --- dhcpv6.c | 60 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/dhcpv6.c b/dhcpv6.c index be51c278af7a..549ddbbea735 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -355,6 +355,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 @@ -547,28 +585,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