From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none 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=eIvynoPx; 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 04D205A0271 for ; Fri, 10 Jan 2025 09:39:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736498364; 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=4rVIZDE9ofIbmAt3hkWmsQs47TmEbd6SS/Z+dHgLd7U=; b=eIvynoPxv/hZAw2IhrtnV2bFuSO7GqVodYzZCY0z60iyixFjYgTR/I1yI/w4XoXCQh/pNc s5sXuVp1v/EQPYdA3Uw47+l+i07CrpvTgbDEquv3kzRgSvkedYIplXnYxFu0uCi3f1Wh38 NqPOXKCzNndZZ868vmyFQaHJM32cyEY= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-AgMV-S0-N7GxX_Al5x6jPw-1; Fri, 10 Jan 2025 03:39:23 -0500 X-MC-Unique: AgMV-S0-N7GxX_Al5x6jPw-1 X-Mimecast-MFC-AGG-ID: AgMV-S0-N7GxX_Al5x6jPw Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aaf8f016bb1so152122766b.2 for ; Fri, 10 Jan 2025 00:39:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736498362; x=1737103162; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4rVIZDE9ofIbmAt3hkWmsQs47TmEbd6SS/Z+dHgLd7U=; b=luFLmsrLiDFuYEY13IXaCQgTlNcFjwUjkOO2JML+LbaRSzDQZMB/feSKeNoGu2tSsZ 1IGsb0JdhSrTgUiuOE8Ub8Clu3X4IVLzW1spadLyFaY96VB41G8B2V4kXAnmrGtjHSXq 2bQaL+FIy6rwfbl4/7+7Qlw49MTICGg816ERbZmmFLdsw7P/fs8RS4qo9R8mTVppN5dh qUFhJKjda55l6iLR1izxfY/GxQQwXPPeBWgcJFSWtPQxajFf1/PpfoOJwOMqEEveFiUa qFWg183uLQY0Tm+8Ql/A+dz6aMj5/4QSYr2iBVjSK9+wOyqMquakSLm53ahQQLj+hak7 3yrA== X-Gm-Message-State: AOJu0YyIbTORg0NTIfUMHk7DwFMVSwEldgM9MORh3dAFmqR9FfSVO9y4 4Y6TpWEH/SzAsPx50BH/LDQ9zKvPtxKXQffnP+x1xwc7cQ1dVPgon78u3SOuqWCX3OJ2lEKHQ9O LGAh0JoQlSH2QV67OW65R118E6XL/ig45ysSIYOH9OqNsqIoNO6ds2TQJrk+Q3O7WTf7/C3y4+Q dXGuZSPm9TaBO48hXfoVbsY3gYLax1sKclKY87ZA== X-Gm-Gg: ASbGncsOEUyai4HCQrOLfThxGHyl5S5qcHXevtJ8bzBeYX4nB9Qt60eZ9AfQKvWv8im esDJeThHl4RwmNO+XFgM/F8Z4U73h7AA3XgJORQhk5ZRqV7CrECc++XDJXwL8XuP9s7PXRUPg X-Received: by 2002:a17:907:948b:b0:aa6:7cf3:c6f0 with SMTP id a640c23a62f3a-ab2ab6fd4d0mr829799366b.14.1736498361383; Fri, 10 Jan 2025 00:39:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGo7PwJzUh855nWY0Oj3aznmbFeJw3ALun3Gzm1a4zz8ZYkrUlU+XC8JgQIJtHJGSdnaA9Z/u2JT5BoGQkY9BY= X-Received: by 2002:a17:907:948b:b0:aa6:7cf3:c6f0 with SMTP id a640c23a62f3a-ab2ab6fd4d0mr829796766b.14.1736498360636; Fri, 10 Jan 2025 00:39:20 -0800 (PST) MIME-Version: 1.0 References: <20250108145811.833308-1-ellorent@redhat.com> <20250109091631.03fefb0e@elisabeth> <20250109143358.334ef58a@elisabeth> In-Reply-To: <20250109143358.334ef58a@elisabeth> From: Enrique Llorente Pastora Date: Fri, 10 Jan 2025 09:39:09 +0100 X-Gm-Features: AbW1kvao9U_nKysHWvw8q7YZMRaoTS4eao3LaAuTuN_sV87QJ7RD2X23E4Ac2eM Message-ID: Subject: Re: [PATCH v7] dhcp, dhcpv6: Add hostname and client fqdn ops To: Stefano Brivio X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: gkByKTfUruHBPPezCNW7t5tZz54VehiHn9Nfn5du684_1736498362 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OGR6QBSSMDYUISIBZ776FDDRJEDFLBZ4 X-Message-ID-Hash: OGR6QBSSMDYUISIBZ776FDDRJEDFLBZ4 X-MailFrom: ellorent@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: passt-dev@passt.top 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: On Thu, Jan 9, 2025 at 2:34=E2=80=AFPM Stefano Brivio = wrote: > > On Thu, 9 Jan 2025 13:57:38 +0100 > Enrique Llorente Pastora wrote: > > > On Thu, Jan 9, 2025 at 9:16=E2=80=AFAM Stefano Brivio wrote: > > > > > > Just coding style comments, plus one functional issue, but it should = be > > > relatively contained: > > > > > > On Wed, 8 Jan 2025 15:58:11 +0100 > > > Enrique Llorente wrote: > > > > > > > Both DHCPv4 and DHCPv6 has the capability to pass the hostname to > > > > clients, the DHCPv4 uses option 12 (hostname) while the DHCPv6 uses= option 39 > > > > (client fqdn), for some virt deployments like kubevirt is expected = to > > > > have the VirtualMachine name as the guest hostname. > > > > > > > > This change add the following arguments: > > > > - -H --hostname NAME to configure the hostname DHCPv4 option(12) > > > > - --fqdn NAME to configure client fqdn option for both DHCPv4(81) = and > > > > DHCPv6(39) > > > > > > > > Signed-off-by: Enrique Llorente > > > > --- > > > > conf.c | 20 ++++++++++-- > > > > dhcp.c | 54 ++++++++++++++++++++++++++---- > > > > dhcpv6.c | 85 +++++++++++++++++++++++++++++++++++++++-----= ---- > > > > passt.1 | 10 ++++++ > > > > passt.h | 5 +++ > > > > pasta.c | 17 +++++++--- > > > > test/lib/setup | 10 +++--- > > > > test/passt.mbuto | 6 ++-- > > > > test/passt/dhcp | 15 ++++++++- > > > > util.c | 31 ++++++++++++++++++ > > > > util.h | 6 ++++ > > > > 11 files changed, 222 insertions(+), 37 deletions(-) > > > > > > > > diff --git a/conf.c b/conf.c > > > > index df2b016..554e5c3 100644 > > > > --- a/conf.c > > > > +++ b/conf.c > > > > @@ -854,7 +854,9 @@ static void usage(const char *name, FILE *f, in= t status) > > > > FPRINTF(f, " default: use addresses from /etc/reso= lv.conf\n"); > > > > FPRINTF(f, > > > > " -S, --search LIST Space-separated list, search = domains\n" > > > > - " a single, empty option disables the DNS search l= ist\n"); > > > > + " a single, empty option disables the DNS search l= ist\n" > > > > + " -H, --hostname NAME Hostname to configure client = with\n" > > > > + " --fqdn NAME FQDN to configure client with= \n"); > > > > if (strstr(name, "pasta")) > > > > FPRINTF(f, " default: don't use any search list\n"= ); > > > > else > > > > @@ -1313,6 +1315,7 @@ void conf(struct ctx *c, int argc, char **arg= v) > > > > {"outbound", required_argument, NULL, = 'o' }, > > > > {"dns", required_argument, NULL, = 'D' }, > > > > {"search", required_argument, NULL, = 'S' }, > > > > + {"hostname", required_argument, NULL, = 'H' }, > > > > {"no-tcp", no_argument, &c->no_tcp, = 1 }, > > > > {"no-udp", no_argument, &c->no_udp, = 1 }, > > > > {"no-icmp", no_argument, &c->no_icmp, = 1 }, > > > > @@ -1357,6 +1360,7 @@ void conf(struct ctx *c, int argc, char **arg= v) > > > > /* vhost-user backend program convention */ > > > > {"print-capabilities", no_argument, NULL, = 26 }, > > > > {"socket-path", required_argument, NULL, = 's' }, > > > > + {"fqdn", required_argument, NULL, = 27 }, > > > > { 0 }, > > > > }; > > > > const char *logname =3D (c->mode =3D=3D MODE_PASTA) ? "pasta"= : "passt"; > > > > @@ -1379,9 +1383,9 @@ void conf(struct ctx *c, int argc, char **arg= v) > > > > if (c->mode =3D=3D MODE_PASTA) { > > > > c->no_dhcp_dns =3D c->no_dhcp_dns_search =3D 1; > > > > fwd_default =3D FWD_AUTO; > > > > - optstring =3D "+dqfel:hF:I:p:P:m:a:n:M:g:i:o:D:S:46t:= u:T:U:"; > > > > + optstring =3D "+dqfel:hF:I:p:P:m:a:n:M:g:i:o:D:S:H:46= t:u:T:U:"; > > > > } else { > > > > - optstring =3D "+dqfel:hs:F:p:P:m:a:n:M:g:i:o:D:S:461t= :u:"; > > > > + optstring =3D "+dqfel:hs:F:p:P:m:a:n:M:g:i:o:D:S:H:46= 1t:u:"; > > > > } > > > > > > > > c->tcp.fwd_in.mode =3D c->tcp.fwd_out.mode =3D FWD_UNSET; > > > > @@ -1558,6 +1562,11 @@ void conf(struct ctx *c, int argc, char **ar= gv) > > > > case 26: > > > > vu_print_capabilities(); > > > > break; > > > > + case 27: > > > > + if (snprintf_check(c->fqdn, PASST_MAXDNAME, > > > > + "%s", optarg)) > > > > + die("Invalid FQDN: %s", optarg); > > > > + break; > > > > case 'd': > > > > c->debug =3D 1; > > > > c->quiet =3D 0; > > > > @@ -1727,6 +1736,11 @@ void conf(struct ctx *c, int argc, char **ar= gv) > > > > > > > > die("Cannot use DNS search domain %s", optarg= ); > > > > break; > > > > + case 'H': > > > > + if (snprintf_check(c->hostname, PASST_MAXDNAM= E, > > > > + = "%s", optarg)) > > > > > > Why? This was fine in v6. I'm not sure what happened here. In case yo= ur > > > editor/email client doesn't show this, now it's: > > > > > > tab tab tab tab tab tab tab tab tab tab tab tab space "%s", optarg)= ) > > > > > > that is, twelve tabs and one space. See also: > > > > > > https://archives.passt.top/passt-dev/20250108145811.833308-1-ellore= nt@redhat.com/#Z31conf.c > > > > > > It should be: > > > > > > if (snprintf_check(c->hostname, PASST_MAXDNAM= E, > > > "%s", optarg)) > > > > > > tab tab tab tab tab space space space "%s", optarg)) > > > > > > that is, five tabs and three spaces. > > > > > > > Fixed, no clue how I de-formated it. > > > > > > + die("Invalid hostname: %s", optarg); > > > > + break; > > > > case '4': > > > > v4_only =3D true; > > > > v6_only =3D false; > > > > diff --git a/dhcp.c b/dhcp.c > > > > index d8515aa..50c220d 100644 > > > > --- a/dhcp.c > > > > +++ b/dhcp.c > > > > @@ -63,6 +63,11 @@ static struct opt opts[255]; > > > > > > > > #define OPT_MIN 60 /* RFC 951 */ > > > > > > > > +/* Total option size (excluding end option) is 576 (RFC 2131), min= us > > > > + * offset of options (268), minus end option and its length (2). > > > > + */ > > > > +#define OPT_MAX 306 > > > > + > > > > /** > > > > * dhcp_init() - Initialise DHCP options > > > > */ > > > > @@ -122,7 +127,7 @@ struct msg { > > > > uint8_t sname[64]; > > > > uint8_t file[128]; > > > > uint32_t magic; > > > > - uint8_t o[308]; > > > > + uint8_t o[OPT_MAX + 2/*End option and its length*/]; > > > > > > Same as my comment to v6: > > > > > > "Spaces around /* ... */ wouldn't be bad for readability." > > > > > > > Right, I understood the opposite, fixing. > > > > > > } __attribute__((__packed__)); > > > > > > > > /** > > > > @@ -130,15 +135,28 @@ struct msg { > > > > * @m: Message to fill > > > > * @o: Option number > > > > * @offset: Current offset within options field, updated on inser= tion > > > > + * > > > > + * Return: offset for the next option field or -1 if option do not= fit > > > > > > Same as my comment to v6: > > > > > > "doesn't fit" > > > > > > It's a bit weird, but harmless, that this function updates 'offset', > > > and also returns it (unless there's an error). Maybe it saves a bit o= f > > > typing in callers, though (I would have just returned offset or -1 at > > > this point, without passing a pointer). > > > > Make sense to not pass a pointer to offset, I will change it. > > > > > > */ > > > > -static void fill_one(struct msg *m, int o, int *offset) > > > > +static ssize_t fill_one(struct msg *m, int o, int *offset) > > > > { > > > > + size_t slen =3D opts[o].slen; > > > > + > > > > + /* If we don't have space to write the option, then just skip= */ > > > > + if (*offset + 1 /* length of option */ + slen > OPT_MAX) > > > > + return -1; > > > > + > > > > m->o[*offset] =3D o; > > > > - m->o[*offset + 1] =3D opts[o].slen; > > > > - memcpy(&m->o[*offset + 2], opts[o].s, opts[o].slen); > > > > + m->o[*offset + 1] =3D slen; > > > > + > > > > + /* Move to option */ > > > > + *offset +=3D 2; > > > > + > > > > + memcpy(&m->o[*offset], opts[o].s, slen); > > > > > > > > opts[o].sent =3D 1; > > > > - *offset +=3D 2 + opts[o].slen; > > > > + *offset +=3D slen; > > > > + return *offset; > > > > } > > > > > > > > /** > > > > @@ -171,8 +189,11 @@ static int fill(struct msg *m) > > > > } > > > > > > > > for (o =3D 0; o < 255; o++) { > > > > - if (opts[o].slen !=3D -1 && !opts[o].sent) > > > > - fill_one(m, o, &offset); > > > > + if (opts[o].slen !=3D -1 && !opts[o].sent) { > > > > + if (fill_one(m, o, &offset) =3D=3D -1) { > > > > > > Curly brackets not needed. > > > > > > > Done. > > > > > > + debug("DHCP: skipping option %i", o); > > > > + } > > > > + } > > > > } > > > > > > > > m->o[offset++] =3D 255; > > > > @@ -398,6 +419,25 @@ int dhcp(const struct ctx *c, const struct poo= l *p) > > > > if (!opts[6].slen) > > > > opts[6].slen =3D -1; > > > > > > > > + opt_len =3D strlen(c->hostname); > > > > + if (opt_len > 0) { > > > > + opts[12].slen =3D opt_len; > > > > + memcpy(opts[12].s, &c->hostname, opt_len); > > > > + } > > > > + > > > > + opt_len =3D strlen(c->fqdn); > > > > + if (opt_len > 0) { > > > > + size_t encoded_len; > > > > + encoded_len =3D encode_domain_name((char *)opts[81].s= + 3, sizeof(opts[81].s) - 3, > > > > + c->fqdn, opt_len); > > > > > > Arguments are aligned properly, but it exceeds 80 columns for no > > > compelling reason. It should be: > > > > > > encoded_len =3D encode_domain_name((char *)opts[81].s= + 3, > > > sizeof(opts[81].s) -= 3, > > > c->fqdn, opt_len); > > > > > > > Done. > > > > > > + if (encoded_len > 0 ) { > > > > > > Excess whitespace between 0 and ). > > > > > > > Done. > > > > > > + opts[81].s[0] =3D 0x4; /* flags (E) */ > > > > + opts[81].s[1] =3D 0xff; /* RCODE1 */ > > > > + opts[81].s[2] =3D 0xff; /* RCODE2 */ > > > > + opts[81].slen =3D encoded_len + 3; > > > > + } > > > > + } > > > > + > > > > if (!c->no_dhcp_dns_search) > > > > opt_set_dns_search(c, sizeof(m->o)); > > > > > > > > diff --git a/dhcpv6.c b/dhcpv6.c > > > > index 0523bba..07ce768 100644 > > > > --- a/dhcpv6.c > > > > +++ b/dhcpv6.c > > > > @@ -48,6 +48,7 @@ struct opt_hdr { > > > > # define STATUS_NOTONLINK htons_constant(4) > > > > # define OPT_DNS_SERVERS htons_constant(23) > > > > # define OPT_DNS_SEARCH htons_constant(24) > > > > +# define OPT_CLIENT_FQDN htons_constant(39) > > > > #define STR_NOTONLINK "Prefix not appropriate for l= ink." > > > > > > > > uint16_t l; > > > > @@ -58,6 +59,9 @@ struct opt_hdr { > > > > sizeof(struct opt_hdr)) > > > > #define OPT_VSIZE(x) (sizeof(struct opt_##x) - = \ > > > > sizeof(struct opt_hdr)) > > > > +#define OPT_MAX_SIZE IPV6_MIN_MTU - (sizeof(struct ipv6hdr= ) + \ > > > > + sizeof(struct udphdr)= + \ > > > > + sizeof(struct msg_hdr= )) > > > > > > > > /** > > > > * struct opt_client_id - DHCPv6 Client Identifier option > > > > @@ -163,6 +167,18 @@ struct opt_dns_search { > > > > char list[MAXDNSRCH * NS_MAXDNAME]; > > > > } __attribute__((packed)); > > > > > > > > +/** > > > > + * struct opt_client_fqdn - Client FQDN option (RFC 4704) > > > > + * @hdr: Option header > > > > + * @flags: Flags described by RFC 4704 > > > > + * @domain_name: Client FQDN > > > > + */ > > > > +struct opt_client_fqdn { > > > > + struct opt_hdr hdr; > > > > + uint8_t flags; > > > > + char domain_name[PASST_MAXDNAME]; > > > > +} __attribute__((packed)); > > > > + > > > > /** > > > > * struct msg_hdr - DHCPv6 client/server message header > > > > * @type: DHCP message type > > > > @@ -193,6 +209,7 @@ struct msg_hdr { > > > > * @client_id: Client Identifier, variable length > > > > * @dns_servers: DNS Recursive Name Server, here just for stor= age size > > > > * @dns_search: Domain Search List, here just for sto= rage size > > > > + * @client_fqdn: Client FQDN, variable length > > > > */ > > > > static struct resp_t { > > > > struct msg_hdr hdr; > > > > @@ -203,6 +220,7 @@ static struct resp_t { > > > > struct opt_client_id client_id; > > > > struct opt_dns_servers dns_servers; > > > > struct opt_dns_search dns_search; > > > > + struct opt_client_fqdn client_fqdn; > > > > } __attribute__((__packed__)) resp =3D { > > > > { 0 }, > > > > SERVER_ID, > > > > @@ -228,6 +246,10 @@ static struct resp_t { > > > > { { OPT_DNS_SEARCH, 0, }, > > > > { 0 }, > > > > }, > > > > + > > > > + { { OPT_CLIENT_FQDN, 0, }, > > > > + 0, { 0 }, > > > > + }, > > > > }; > > > > > > > > static const struct opt_status_code sc_not_on_link =3D { > > > > @@ -346,7 +368,6 @@ static size_t dhcpv6_dns_fill(const struct ctx = *c, char *buf, int offset) > > > > { > > > > struct opt_dns_servers *srv =3D NULL; > > > > struct opt_dns_search *srch =3D NULL; > > > > - char *p =3D NULL; > > > > int i; > > > > > > > > if (c->no_dhcp_dns) > > > > @@ -373,6 +394,7 @@ search: > > > > return offset; > > > > > > > > for (i =3D 0; *c->dns_search[i].n; i++) { > > > > + size_t encoded_name_len; > > > > size_t name_len =3D strlen(c->dns_search[i].n); > > > > > > > > /* We already append separators, don't duplicate if p= resent */ > > > > @@ -388,29 +410,61 @@ search: > > > > offset +=3D sizeof(struct opt_hdr); > > > > srch->hdr.t =3D OPT_DNS_SEARCH; > > > > srch->hdr.l =3D 0; > > > > - p =3D srch->list; > > > > } > > > > > > > > - *p =3D '.'; > > > > - p =3D stpncpy(p + 1, c->dns_search[i].n, name_len); > > > > - p++; > > > > - srch->hdr.l +=3D name_len + 2; > > > > - offset +=3D name_len + 2; > > > > + encoded_name_len =3D encode_domain_name(srch->list, N= S_MAXDNAME, > > > > + c->dns_search[i= ].n, > > > > + name_len); > > > > + srch->hdr.l +=3D encoded_name_len; > > > > > > ...not if encoded_name_len is -1. In that case, you could also have a= n > > > integer overflow, other than broken functionality. > > > > > > > Right, I will check -1 and skip on that case. > > > > Also I have to move the list buffer or I will be storing it at the > > first element. > > encoded_name_len =3D encode_domain_name(srch->list + srch->hdr.l, > > NS_MAXDNAME, > > c->dns_search[i].= n, > > name_len); > > Oh, right. I didn't test this. Can't you just follow along where you > are with 'offset'? I'm not sure, I didn't look into it. I cannot use offset since it's initialize with + header offset +=3D sizeof(struct opt_hdr); > > > > > > + offset +=3D encoded_name_len; > > > > } > > > > > > > > - if (srch) { > > > > - for (i =3D 0; i < srch->hdr.l; i++) { > > > > - if (srch->list[i] =3D=3D '.') { > > > > - srch->list[i] =3D strcspn(srch->list = + i + 1, > > > > - "."); > > > > - } > > > > - } > > > > + if (srch) > > > > srch->hdr.l =3D htons(srch->hdr.l); > > > > - } > > > > > > > > return offset; > > > > } > > > > > > > > +/** > > > > + * dhcpv6_client_fqdn_fill() - Fill in client FQDN option > > > > + * @c: Execution context > > > > + * @buf: Response message buffer where options will be appende= d > > > > + * @offset: Offset in message buffer for new options > > > > + * > > > > + * Return: updated length of response message buffer. > > > > + */ > > > > +static size_t dhcpv6_client_fqdn_fill(const struct pool *p, const = struct ctx *c, > > > > + char *buf, int offset) > > > > + > > > > +{ > > > > + ssize_t opt_len; > > > > + struct opt_client_fqdn *o; > > > > + struct opt_client_fqdn const *req_opt; > > > > > > Same as my comment to v6: > > > > > > "These should go from longest to shortest." > > > > > > > Done. > > > > > > + > > > > + opt_len =3D MIN(PASST_MAXDNAME, OPT_MAX_SIZE - (offset + size= of(struct opt_hdr) + 1/*flags*/)); > > > > > > This should be PASST_MAXDNAME + 1, otherwise: > > > > > > ./passt -d -f --fqdn thirtytwocharactersforeachlabel.thirtytwocharact= ersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachl= abel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirty= twocharactersforeachlabel.and_get_to_252_with_this_one > > > > > > 19.4621: DHCPv6: received REQUEST/RENEW/CONFIRM, sending REPLY > > > 19.4621: DHCPv6: client FQDN option does not fit, skipping > > > > > > > Make sense I will change it > > > > > ...but that domain name is 252 characters, and it's accepted > > > (longer domains are not accepted, which makes me think: should > > > PASST_MAXDNAME be 254 instead, as it includes the terminator?). > > > > We are also using that const for validation (and on that case we don't > > count the terminator) so > > we cannot modify it > > > > if (snprintf_check(c->fqdn, PASST_MAXDNAME, > > "%s", optarg)) > > die("Invalid FQDN: %s", optarg); > > Well, no, that was exactly my point. We do count the terminator there: > > $ ./passt -f --fqdn thirtytwocharactersforeachlabel.thirtytwocharactersfo= reachlabel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.= thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwoch= aractersforeachlabel.then_get_to_253_with_this_one > Invalid FQDN: thirtytwocharactersforeachlabel.thirtytwocharactersforeachl= abel.thirtytwocharactersforeachlabel.thirtytwocharactersforeachlabel.thirty= twocharactersforeachlabel.thirtytwocharactersforeachlabel.thirtytwocharacte= rsforeachlabel.then_get_to_253_with_this_one > > because snprintf_check() is snprintf()-like, see snprintf(3): > > The functions snprintf() and vsnprintf() write at most size > bytes (including the terminating null byte ('\0')) to str. > > Back to RFC 1035 (3.1): > > To simplify implementations, the total length of a domain name (i.e., > label octets and label length octets) is restricted to 255 octets or > less. > > which means 253 characters before encoding, because we have two labels, > at start and end. That's why we used 253. > > But that actually includes the terminator, so we should probably size > everything to 254 bytes (either use PASST_MAXDNAME + 1 or define > PASST_MAXDNAME as 254... the first one is more consistent with similar > constants, the second one might be more practical, I'm not sure). > Ahh cool, I will go with defining PASST_MAXDNAME as 254 and explain that it includes the terminator at the const description, so we don't have to "+ 1" around and explain every time. > > > If it's one byte shorter, then it works (254 bytes option > > > size, 253 bytes of encoded domain, 251 of original domain). > > > > > > Once this is fixed, this reveals an issue in encode_domain_name(), mo= re > > > on that below. > > > > > > By the way, this exceeds 80 columns for no particular reason, and > > > "+ 1 /* flags */" is probably a bit more readable. > > > > > > > + > > > > + o =3D (struct opt_client_fqdn *)(buf + offset); > > > > + opt_len =3D encode_domain_name(o->domain_name, opt_len, c->fq= dn, strlen(c->fqdn)); > > > > > > This now exceeds 80 columns. > > > > > > > Done. > > > > > > + if (opt_len =3D=3D -1) { > > > > + debug("DHCPv6: client FQDN option does not fit, skipp= ing"); > > > > + return offset; > > > > + } > > > > + > > > > + req_opt =3D (struct opt_client_fqdn *)dhcpv6_opt(p, &(size_t)= { 0 }, > > > > + OPT_CLIENT_FQD= N); > > > > + if (req_opt && req_opt->flags & 0x01 /* S flag */) > > > > + o->flags =3D 0x02 /* O flag */; > > > > + else > > > > + o->flags =3D 0x00; > > > > + > > > > + opt_len++; > > > > + > > > > + o->hdr.t =3D OPT_CLIENT_FQDN; > > > > + o->hdr.l =3D htons(opt_len); > > > > > > It's much easier to follow now, I think. > > > > > > > + > > > > + return offset + sizeof(struct opt_hdr) + opt_len; > > > > +} > > > > + > > > > /** > > > > * dhcpv6() - Check if this is a DHCPv6 message, reply as needed > > > > * @c: Execution context > > > > @@ -544,6 +598,7 @@ int dhcpv6(struct ctx *c, const struct pool *p, > > > > n =3D offsetof(struct resp_t, client_id) + > > > > sizeof(struct opt_hdr) + ntohs(client_id->l); > > > > n =3D dhcpv6_dns_fill(c, (char *)&resp, n); > > > > + n =3D dhcpv6_client_fqdn_fill(p, c, (char *)&resp, n); > > > > > > > > resp.hdr.xid =3D mh->xid; > > > > > > > > diff --git a/passt.1 b/passt.1 > > > > index d9cd33e..7051fc4 100644 > > > > --- a/passt.1 > > > > +++ b/passt.1 > > > > @@ -401,6 +401,16 @@ Enable IPv6-only operation. IPv4 traffic will = be ignored. > > > > By default, IPv4 operation is enabled as long as at least an IPv4 = route and an > > > > interface address are configured on a given host interface. > > > > > > > > +.TP > > > > +.BR \-H ", " \-\-hostname " " \fIname > > > > +Hostname to configure the client with. > > > > +Send \fIname\fR as DHCP option 12 (hostname). > > > > + > > > > +.TP > > > > +.BR \-\-fqdn " " \fIname > > > > +FQDN to configure the client with. > > > > +Send \fIname\fR as Client FQDN: DHCP option 81 and DHCPv6 option 3= 9. > > > > + > > > > .SS \fBpasst\fR-only options > > > > > > > > .TP > > > > diff --git a/passt.h b/passt.h > > > > index 0dd4efa..f3151f0 100644 > > > > --- a/passt.h > > > > +++ b/passt.h > > > > @@ -209,6 +209,8 @@ struct ip6_ctx { > > > > * @ifi4: Template interface for IPv4, -1: none, 0: IPv= 4 disabled > > > > * @ip: IPv4 configuration > > > > * @dns_search: DNS search list > > > > + * @hostname: Guest hostname > > > > + * @fqdn: Guest FQDN > > > > * @ifi6: Template interface for IPv6, -1: none, 0: IPv= 6 disabled > > > > * @ip6: IPv6 configuration > > > > * @pasta_ifn: Name of namespace interface for pasta > > > > @@ -269,6 +271,9 @@ struct ctx { > > > > > > > > struct fqdn dns_search[MAXDNSRCH]; > > > > > > > > + char hostname[PASST_MAXDNAME]; > > > > + char fqdn[PASST_MAXDNAME]; > > > > + > > > > int ifi6; > > > > struct ip6_ctx ip6; > > > > > > > > diff --git a/pasta.c b/pasta.c > > > > index ff41c95..f3b4cae 100644 > > > > --- a/pasta.c > > > > +++ b/pasta.c > > > > @@ -169,10 +169,12 @@ void pasta_open_ns(struct ctx *c, const char = *netns) > > > > * struct pasta_spawn_cmd_arg - Argument for pasta_spawn_cmd() > > > > * @exe: Executable to run > > > > * @argv: Command and arguments to run > > > > + * @ctx: Context to read config from > > > > */ > > > > struct pasta_spawn_cmd_arg { > > > > const char *exe; > > > > char *const *argv; > > > > + struct ctx *c; > > > > }; > > > > > > > > /** > > > > @@ -186,6 +188,7 @@ static int pasta_spawn_cmd(void *arg) > > > > { > > > > char hostname[HOST_NAME_MAX + 1] =3D HOSTNAME_PREFIX; > > > > const struct pasta_spawn_cmd_arg *a; > > > > + size_t conf_hostname_len; > > > > sigset_t set; > > > > > > > > /* We run in a detached PID and mount namespace: mount /proc = over */ > > > > @@ -195,9 +198,15 @@ static int pasta_spawn_cmd(void *arg) > > > > if (write_file("/proc/sys/net/ipv4/ping_group_range", "0 0")) > > > > warn("Cannot set ping_group_range, ICMP requests migh= t fail"); > > > > > > > > - if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - 1, > > > > - HOST_NAME_MAX + 1 - sizeof(HOSTNAME_PREFIX))= || > > > > - errno =3D=3D ENAMETOOLONG) { > > > > + a =3D (const struct pasta_spawn_cmd_arg *)arg; > > > > + > > > > + conf_hostname_len =3D strlen(a->c->hostname); > > > > + if (conf_hostname_len > 0) { > > > > + if (sethostname(a->c->hostname, conf_hostname_len)) > > > > + warn("Unable to set configured hostname"); > > > > + } else if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - = 1, > > > > + HOST_NAME_MAX + 1 - sizeof(HOSTNAME_PREFIX)) || > > > > + errno =3D=3D ENAMETOOLONG) { > > > > > > Same as my comment to v6, which was the same as my comment to v5...: > > > > > > "Same as for v5: this is an argument to gethostname(), so it should b= e > > > aligned accordingly. ! is a unary operator, it doesn't take two opera= nds. > > > > > > That is: > > > > > > } else if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - = 1, > > > HOST_NAME_MAX + 1 - sizeof(HOSTNAME_P= REFIX)) || > > > > > > see also the version without your patch." > > > > > > > hostname[HOST_NAME_MAX] =3D '\0'; > > > > if (sethostname(hostname, strlen(hostname))) > > > > warn("Unable to set pasta-prefixed hostname")= ; > > > > Done. > > > > > > @@ -208,7 +217,6 @@ static int pasta_spawn_cmd(void *arg) > > > > sigaddset(&set, SIGUSR1); > > > > sigwaitinfo(&set, NULL); > > > > > > > > - a =3D (const struct pasta_spawn_cmd_arg *)arg; > > > > execvp(a->exe, a->argv); > > > > > > > > die_perror("Failed to start command or shell"); > > > > @@ -230,6 +238,7 @@ void pasta_start_ns(struct ctx *c, uid_t uid, g= id_t gid, > > > > struct pasta_spawn_cmd_arg arg =3D { > > > > .exe =3D argv[0], > > > > .argv =3D argv, > > > > + .c =3D c, > > > > }; > > > > char uidmap[BUFSIZ], gidmap[BUFSIZ]; > > > > char *sh_argv[] =3D { NULL, NULL }; > > > > diff --git a/test/lib/setup b/test/lib/setup > > > > index 580825f..ee67152 100755 > > > > --- a/test/lib/setup > > > > +++ b/test/lib/setup > > > > @@ -49,7 +49,7 @@ setup_passt() { > > > > > > > > context_run passt "make clean" > > > > context_run passt "make valgrind" > > > > - context_run_bg passt "valgrind --max-stackframe=3D$((4 * 1024= * 1024)) --trace-children=3Dyes --vgdb=3Dno --error-exitcode=3D1 --suppres= sions=3Dtest/valgrind.supp ./passt ${__opts} -s ${STATESETUP}/passt.socket = -f -t 10001 -u 10001 -P ${STATESETUP}/passt.pid" > > > > + context_run_bg passt "valgrind --max-stackframe=3D$((4 * 1024= * 1024)) --trace-children=3Dyes --vgdb=3Dno --error-exitcode=3D1 --suppres= sions=3Dtest/valgrind.supp ./passt ${__opts} -s ${STATESETUP}/passt.socket = -f -t 10001 -u 10001 -H hostname1 --fqdn fqdn1.passt.test -P ${STATESETUP}/= passt.pid" > > > > > > > > # pidfile isn't created until passt is listening > > > > wait_for [ -f "${STATESETUP}/passt.pid" ] > > > > @@ -160,11 +160,11 @@ setup_passt_in_ns() { > > > > if [ ${VALGRIND} -eq 1 ]; then > > > > context_run passt "make clean" > > > > context_run passt "make valgrind" > > > > - context_run_bg passt "valgrind --max-stackframe=3D$((= 4 * 1024 * 1024)) --trace-children=3Dyes --vgdb=3Dno --error-exitcode=3D1 -= -suppressions=3Dtest/valgrind.supp ./passt -f ${__opts} -s ${STATESETUP}/pa= sst.socket -t 10001,10011,10021,10031 -u 10001,10011,10021,10031 -P ${STATE= SETUP}/passt.pid --map-host-loopback ${__map_ns4} --map-host-loopback ${__m= ap_ns6}" > > > > + context_run_bg passt "valgrind --max-stackframe=3D$((= 4 * 1024 * 1024)) --trace-children=3Dyes --vgdb=3Dno --error-exitcode=3D1 -= -suppressions=3Dtest/valgrind.supp ./passt -f ${__opts} -s ${STATESETUP}/pa= sst.socket -H hostname1 --fqdn fqdn1.passt.test -t 10001,10011,10021,10031 = -u 10001,10011,10021,10031 -P ${STATESETUP}/passt.pid --map-host-loopback $= {__map_ns4} --map-host-loopback ${__map_ns6}" > > > > else > > > > context_run passt "make clean" > > > > context_run passt "make" > > > > - context_run_bg passt "./passt -f ${__opts} -s ${STATE= SETUP}/passt.socket -t 10001,10011,10021,10031 -u 10001,10011,10021,10031 -= P ${STATESETUP}/passt.pid --map-host-loopback ${__map_ns4} --map-host-loopb= ack ${__map_ns6}" > > > > + context_run_bg passt "./passt -f ${__opts} -s ${STATE= SETUP}/passt.socket -H hostname1 --fqdn fqdn1.passt.test -t 10001,10011,100= 21,10031 -u 10001,10011,10021,10031 -P ${STATESETUP}/passt.pid --map-host-l= oopback ${__map_ns4} --map-host-loopback ${__map_ns6}" > > > > fi > > > > wait_for [ -f "${STATESETUP}/passt.pid" ] > > > > > > > > @@ -243,7 +243,7 @@ setup_two_guests() { > > > > [ ${TRACE} -eq 1 ] && __opts=3D"${__opts} --trace" > > > > [ ${VHOST_USER} -eq 1 ] && __opts=3D"${__opts} --vhost-user" > > > > > > > > - context_run_bg passt_1 "./passt -s ${STATESETUP}/passt_1.sock= et -P ${STATESETUP}/passt_1.pid -f ${__opts} -t 10001 -u 10001" > > > > + context_run_bg passt_1 "./passt -s ${STATESETUP}/passt_1.sock= et -P ${STATESETUP}/passt_1.pid -f ${__opts} --fqdn fqdn1.passt.test -H hos= tname1 -t 10001 -u 10001" > > > > wait_for [ -f "${STATESETUP}/passt_1.pid" ] > > > > > > > > __opts=3D > > > > @@ -252,7 +252,7 @@ setup_two_guests() { > > > > [ ${TRACE} -eq 1 ] && __opts=3D"${__opts} --trace" > > > > [ ${VHOST_USER} -eq 1 ] && __opts=3D"${__opts} --vhost-user" > > > > > > > > - context_run_bg passt_2 "./passt -s ${STATESETUP}/passt_2.sock= et -P ${STATESETUP}/passt_2.pid -f ${__opts} -t 10004 -u 10004" > > > > + context_run_bg passt_2 "./passt -s ${STATESETUP}/passt_2.sock= et -P ${STATESETUP}/passt_2.pid -f ${__opts} --hostname hostname2 --fqdn fq= dn2 -t 10004 -u 10004" > > > > wait_for [ -f "${STATESETUP}/passt_2.pid" ] > > > > > > > > __vmem=3D"$((${MEM_KIB} / 1024 / 4))" > > > > diff --git a/test/passt.mbuto b/test/passt.mbuto > > > > index 138d365..1e07693 100755 > > > > --- a/test/passt.mbuto > > > > +++ b/test/passt.mbuto > > > > @@ -13,7 +13,7 @@ > > > > PROGS=3D"${PROGS:-ash,dash,bash ip mount ls insmod mkdir ln cat ch= mod lsmod > > > > modprobe find grep mknod mv rm umount jq iperf3 dhclient ho= stname > > > > sed tr chown sipcalc cut socat dd strace ping tail killall = sleep sysctl > > > > - nproc tcp_rr tcp_crr udp_rr which tee seq bc sshd ssh-keyge= n cmp}" > > > > + nproc tcp_rr tcp_crr udp_rr which tee seq bc sshd ssh-keyge= n cmp env}" > > > > > > > > # OpenSSH 9.8 introduced split binaries, with sshd being the daemo= n, and > > > > # sshd-session the per-session program. We need the latter as well= , and the path > > > > @@ -41,6 +41,7 @@ FIXUP=3D"${FIXUP}"' > > > > #!/bin/sh > > > > LOG=3D/var/log/dhclient-script.log > > > > echo \${reason} \${interface} >> \$LOG > > > > +env >> \$LOG > > > > set >> \$LOG > > > > > > > > [ -n "\${new_interface_mtu}" ] && ip link set dev \${interfa= ce} mtu \${new_interface_mtu} > > > > @@ -54,7 +55,8 @@ set >> \$LOG > > > > [ -n "\${new_ip6_address}" ] && ip addr add \${new_ip6_add= ress}/\${new_ip6_prefixlen} dev \${interface} > > > > [ -n "\${new_dhcp6_name_servers}" ] && for d in \${new_dhcp6_name= _servers}; do echo "nameserver \${d}%\${interface}" >> /etc/resolv.conf; do= ne > > > > [ -n "\${new_dhcp6_domain_search}" ] && (printf "search"; for d in= \${new_dhcp6_domain_search}; do printf " %s" "\${d}"; done; printf "\n") >= > /etc/resolv.conf > > > > -[ -n "\${new_host_name}" ] && hostname "\${new_host_name= }" > > > > +[ -n "\${new_host_name}" ] && echo "\${new_host_name}" >= /tmp/new_host_name > > > > +[ -n "\${new_fqdn_fqdn}" ] && echo "\${new_fqdn_fqdn}" >= /tmp/new_fqdn_fqdn > > > > exit 0 > > > > EOF > > > > chmod 755 /sbin/dhclient-script > > > > diff --git a/test/passt/dhcp b/test/passt/dhcp > > > > index 9925ab9..145f1ba 100644 > > > > --- a/test/passt/dhcp > > > > +++ b/test/passt/dhcp > > > > @@ -11,7 +11,7 @@ > > > > # Copyright (c) 2021 Red Hat GmbH > > > > # Author: Stefano Brivio > > > > > > > > -gtools ip jq dhclient sed tr > > > > +gtools ip jq dhclient sed tr hostname > > > > htools ip jq sed tr head > > > > > > > > test Interface name > > > > @@ -47,7 +47,16 @@ gout SEARCH sed 's/\. / /g' /etc/resolv.co= nf | sed 's/\.$//g' | sed -n 's/^searc > > > > hout HOST_SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g'= | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' > > > > check [ "__SEARCH__" =3D "__HOST_SEARCH__" ] > > > > > > > > +test DHCP: Hostname > > > > +gout NEW_HOST_NAME cat /tmp/new_host_name > > > > +check [ "__NEW_HOST_NAME__" =3D "hostname1" ] > > > > + > > > > +test DHCP: Client FQDN > > > > +gout NEW_FQDN_FQDN cat /tmp/new_fqdn_fqdn > > > > +check [ "__NEW_FQDN_FQDN__" =3D "fqdn1.passt.test" ] > > > > + > > > > test DHCPv6: address > > > > +guest rm /tmp/new_fqdn_fqdn > > > > guest /sbin/dhclient -6 __IFNAME__ > > > > # Wait for DAD to complete > > > > guest while ip -j -6 addr show tentative | jq -e '.[].addr_= info'; do sleep 0.1; done > > > > @@ -70,3 +79,7 @@ test DHCPv6: search list > > > > gout SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | s= ed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' > > > > hout HOST_SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g= ' | sed -n 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' > > > > check [ "__SEARCH6__" =3D "__HOST_SEARCH6__" ] > > > > + > > > > +test DHCPv6: Hostname > > > > +gout NEW_FQDN_FQDN cat /tmp/new_fqdn_fqdn > > > > +check [ "__NEW_FQDN_FQDN__" =3D "fqdn1.passt.test" ] > > > > diff --git a/util.c b/util.c > > > > index 11973c4..ba876ea 100644 > > > > --- a/util.c > > > > +++ b/util.c > > > > @@ -837,3 +837,34 @@ void raw_random(void *buf, size_t buflen) > > > > if (random_read < buflen) > > > > die("Unexpected EOF on random data source"); > > > > } > > > > +/** > > > > + * encode_domain_name() - Encode domain name according to RFC 1035= , section 3.1 > > > > + * @buf: Buffer to fill in with encoded domain name > > > > + * @len Buffer length > > > > > > @len: > > > > > > > Done. > > > > > > + * @domain_name: Input domain name > > > > + * @domain_name_len Domain name length > > > > > > @domain_name_len: > > > > > > > Done. > > > > > > + * > > > > + * Return: encoded domain name length or -1 if it do not fit at bu= ffer > > > > > > "doesn't" > > > > > > "fit in the buffer" (or simply "doesn't fit") > > > > > > > Done. > > > > > > + */ > > > > +ssize_t encode_domain_name(char *buf, size_t len, const char *doma= in_name, size_t domain_name_len) > > > > > > This now exceeds 80 columns for no compelling reason. > > > > > > > Done. > > > > > > +{ > > > > + char *p; > > > > + size_t i; > > > > > > These should go from longest to shortest. > > > > > > > Done. > > > > > > + > > > > + if (domain_name_len + 2 > len) > > > > + return -1; > > > > + > > > > + buf[0] =3D strcspn(domain_name, "."); > > > > + p =3D buf + 1; > > > > + for (i =3D 0; i < len; i++) { > > > > + if (domain_name[i] =3D=3D '.') > > > > > > This overflows the *input* buffer, if len > domain_name_len (which is > > > the intended usage). > > > > > > I understand that if you limit len in the caller (<=3D PASST_MAXDNAME= ), > > > then you avoid the overflow, but this looks extremely fragile (the > > > restriction in the caller is buggy anyway), and it would leak host > > > memory into the guest. > > > > > > I still think that v6 plus my suggestion (ensure adequate buffer size > > > in the caller) would be a bit simpler. > > > > > > If you really want to add a check on the output buffer size here, I > > > would suggest that you iterate over the *input* bytes anyway, and the= n > > > at every byte check that you're not exceeding the output buffer. > > > > So your suggestion is at the caller limiting|check buffer size and not > > pass domain_name len, so function will be: > > size_t encode_domain_name(char* buf, const char *domain_name) > > Yes, just like you had. > > > That means that the caller has to know that the encoded len is len > > (without terminator) + 2, is that fine ? The idea for v7 > > was encapsulating the size check at the function so we don't have to > > repeat len + 2 check at all the callers, but maybe is > > plain overengineering stuff. > > Well, the check is so simple that it's probably the same lines of code > as checking if the return code is -1. > > Sure, it's nice in general to avoid duplication, but at the moment you > have three bugs, which I don't think you introduced on purpose: > > - dhcp() uses encoded_len just as it is, even if it's -1 (I'm not sure > if I reported this) > > - same for dhcpv6_dns_fill() > > - encode_domain_name() itself might overrun the *input* > > so perhaps it's actually less bug prone to have a simple check in the > callers? > > Again, that's not the only way, you can still check the buffer size > here, but it should be used as *check*, not to iterate on the input. > > Maybe implement both (it's a few lines) and see what looks simpler or > more robust? > Let's go with doing the check at the caller, and if in the future we see a lot of duplication there we can refactor and do the check inside at the callee. > > > > + p[i] =3D strcspn(domain_name + i + 1, "."); > > > > + else > > > > + p[i] =3D domain_name[i]; > > > > + } > > > > + > > > > + /* domain name is terminated by a length byte of zero */ > > > > + p[len + 1] =3D 0x00; > > > > + > > > > + return domain_name_len + 2; > > > > +} > > > > diff --git a/util.h b/util.h > > > > index 3fa1d12..b7d5b91 100644 > > > > --- a/util.h > > > > +++ b/util.h > > > > @@ -40,6 +40,9 @@ > > > > #ifndef IP_MAX_MTU > > > > #define IP_MAX_MTU USHRT_MAX > > > > #endif > > > > +#ifndef IPV6_MIN_MTU > > > > +#define IPV6_MIN_MTU 1280 > > > > > > This would need tabs instead of spaces (even better: align it with th= e > > > other values above, so that it becomes some kind of table). > > > > > > > Done. > > > > > > +#endif > > > > > > > > #ifndef MIN > > > > #define MIN(x, y) (((x) < (y)) ? (x) : (y)) > > > > @@ -346,4 +349,7 @@ static inline int wrap_accept4(int sockfd, stru= ct sockaddr *addr, > > > > #define accept4(s, addr, addrlen, flags) \ > > > > wrap_accept4((s), (addr), (addrlen), (flags)) > > > > > > > > +#define PASST_MAXDNAME 253 /* RFC 1035 */ > > > > +ssize_t encode_domain_name(char *buf, size_t len, const char *doma= in_name, size_t domain_name_len); > > > > > > This exceeds 80 columns and can conveniently be wrapped. > > > > > > > + > > > > #endif /* UTIL_H */ > > -- > Stefano > --=20 Quique Llorente CNV networking Senior Software Engineer Red Hat EMEA ellorent@redhat.com @RedHat Red Hat Red Hat