On Fri, Apr 11, 2025 at 03:10:24PM +0200, Laurent Vivier wrote: > 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 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; > } -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson