Download raw body.
enclose IPv6 address in bracket
On Mon, 01 Jul 2024 09:55:14 +0200
Florian Obser <florian@openbsd.org> wrote:
> Reads correct to me, OK florian
Thanks,
> Would it make sense to always surround an IPv6 address with [], even if
> port == 0?
I'm not sure. When the IPv6 address is used without a port, I feel
surrounding it with [] is not necessary and usually don't do that.
> On 2024-07-01 14:55 +09, YASUOKA Masahiko <yasuoka@openbsd.org> wrote:
>> Hi,
>>
>> When iked(8) represents an IPv6 address with a port number, the port
>> part might be interpreted as a last 2 octets of the address.
>>
>> I'd like to enclose the address in bracket.
>>
>> ok?
>>
>> Index: sbin/iked/util.c
>> ===================================================================
>> RCS file: /cvs/src/sbin/iked/util.c,v
>> diff -u -p -r1.44 util.c
>> --- sbin/iked/util.c 3 Feb 2024 00:38:08 -0000 1.44
>> +++ sbin/iked/util.c 1 Jul 2024 05:39:58 -0000
>> @@ -644,16 +644,16 @@ prefixlen2mask6(uint8_t prefixlen, uint3
>> const char *
>> print_addr(void *addr)
>> {
>> - static char sbuf[IKED_CYCLE_BUFFERS][NI_MAXHOST + 7];
>> + static char sbuf[IKED_CYCLE_BUFFERS][NI_MAXHOST + 9];
>> static int idx;
>> struct sockaddr *sa = addr;
>> - char *buf;
>> - size_t len;
>> + char *buf, *hbuf;
>> + size_t len, hlen;
>> char pbuf[7];
>> in_port_t port;
>>
>> - buf = sbuf[idx];
>> - len = sizeof(sbuf[idx]);
>> + hbuf = buf = sbuf[idx];
>> + hlen = len = sizeof(sbuf[idx]);
>> if (++idx >= IKED_CYCLE_BUFFERS)
>> idx = 0;
>>
>> @@ -662,13 +662,21 @@ print_addr(void *addr)
>> return (buf);
>> }
>>
>> + if ((port = socket_getport(sa)) != 0 && sa->sa_family == AF_INET6) {
>> + /* surround [] */
>> + *(hbuf++) = '[';
>> + hlen--;
>> + }
>> +
>> if (getnameinfo(sa, sa->sa_len,
>> - buf, len, NULL, 0, NI_NUMERICHOST) != 0) {
>> + hbuf, hlen, NULL, 0, NI_NUMERICHOST) != 0) {
>> strlcpy(buf, "unknown", len);
>> return (buf);
>> }
>>
>> - if ((port = socket_getport(sa)) != 0) {
>> + if (port != 0) {
>> + if (sa->sa_family == AF_INET6)
>> + (void)strlcat(buf, "]", len);
>> snprintf(pbuf, sizeof(pbuf), ":%d", port);
>> (void)strlcat(buf, pbuf, len);
>> }
>>
>
> --
> In my defence, I have been left unsupervised.
>
>
enclose IPv6 address in bracket