From nobody Wed May 10 09:57:51 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QGVnq4XJhz49fVG; Wed, 10 May 2023 09:57:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QGVnq26dyz4WWc; Wed, 10 May 2023 09:57:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683712671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5D+LEL8AzfYlN4gWjrHrhvEGSrg7e1dYwG5R2NQwtwM=; b=U4ZXh8DrjjzfK+dna1f+qXlUI1vK0GA7MEfrvlPUemddtd17JjDLIQB631YeE+GTbSWFjB WUKTiy97i7Jlo2bxp6VDtMFr5Lmcgz8XkGDhDJghyeU1y9zIUrNsULqRbAf5LtNeFpOOB7 7EPZ3X+rkqhb442wvl33ESYnNWtoB03WhYcErdzYcOeIxa+4ijKZv1fTGCqaKTgOGYzFP3 s3o3waFxKQnEM9aL1RJOveflYrgc2xBEKGX0IlP0OfWlSZYgX1LQf7BbiVMt/WiTvW2RoF sxqRsuv/iURa1DoLWiEPPz51Hs+Y8D9hnv2qKoGFhuPFkeWGHfd+g3E6TOb5Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683712671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5D+LEL8AzfYlN4gWjrHrhvEGSrg7e1dYwG5R2NQwtwM=; b=w6PqCM+YahjdK1BeEiImcA8NHiRYQGSPh8h1bcdjAjTpp7A2y/Xm6BCvEVxB5XS+u/kHba 8UTIbWKuGGxGEhJVcvhzj3ZaO1Wx87YpjiC5Wt7I8AmwIEtgZpQ/2AB+X+WB4XdNRyN9co LqOWobTJgRMCisK/gerjdL+liIZloL/zBd8ZJAtmGWwr8okSVVr2pQoGcToRzEU/+1u+PL Y2V7hXRgH7bjB12isMMq8NwZbY64u8qmsnN7cyHyBwDbyAHP11UQL3UGOy2r0P8kwynuri qu35aKCYoV1iIkP0Ta7EOxlJkfSNllnexKYnXsneb4cBJOmEMMYkKiquqnOfbQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683712671; a=rsa-sha256; cv=none; b=Py2+H66by5jSn8/M0Wzqbmk/Zm8LlEj0ooYLSqkU9UXSDL5jjPUqQX+IrtwxqAFVpGaB+o N3Ep5wy0SI0l27eWHBUqaVxFYUD4mO6/OLK3w2GBpv09M9Gce6+5/yv21YXY47VR8sUKpa AsiHamap6aqbp8nu8FUgFxq6cjQUSctpYSSrviOBSSW3zOu54Td2aCfdM2lViGt1LIm9lh 4Bt+5wj354yOIaDV/AK8aq4Tpdtewn+LL5U6PoKJbwt8JX18D36yjgzCe28S4JQIlG0zd4 r3NbYuh/uS8tTRlSifbA+MTXIh9QZLILdR0u2db/hByjTWNWrLljwQl/5gteUA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QGVnq11s8z159L; Wed, 10 May 2023 09:57:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34A9vpxv041738; Wed, 10 May 2023 09:57:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34A9vpqT041737; Wed, 10 May 2023 09:57:51 GMT (envelope-from git) Date: Wed, 10 May 2023 09:57:51 GMT Message-Id: <202305100957.34A9vpqT041737@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 30d0fc6f3391 - main - netlink: export more IPv6 ifa info List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 30d0fc6f339132990da7989bb102b01338b0d749 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=30d0fc6f339132990da7989bb102b01338b0d749 commit 30d0fc6f339132990da7989bb102b01338b0d749 Author: Alexander V. Chernikov AuthorDate: 2023-05-10 08:52:31 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-05-10 09:57:01 +0000 netlink: export more IPv6 ifa info * Fill in IFA_CACHEINFO with prefix lifetime data * Map IPv6 IN6_IFF_ flags to Netlink IFA_F_ flags * Store original ia6_flags in the FreeBSD-specific IFAF_FLAGS field MFC after: 2 weeks --- sys/netlink/netlink_snl_route_parsers.h | 4 ++ sys/netlink/route/iface.c | 68 ++++++++++++++++++++++++++++++++- sys/netlink/route/ifaddrs.h | 9 +++-- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/sys/netlink/netlink_snl_route_parsers.h b/sys/netlink/netlink_snl_route_parsers.h index e50ad717e17f..a4877a4d7939 100644 --- a/sys/netlink/netlink_snl_route_parsers.h +++ b/sys/netlink/netlink_snl_route_parsers.h @@ -302,13 +302,16 @@ struct snl_parsed_addr { struct sockaddr *ifa_address; struct sockaddr *ifa_broadcast; char *ifa_label; + struct ifa_cacheinfo *ifa_cacheinfo; uint32_t ifaf_vhid; + uint32_t ifaf_flags; }; #define _IN(_field) offsetof(struct ifaddrmsg, _field) #define _OUT(_field) offsetof(struct snl_parsed_addr, _field) static const struct snl_attr_parser _nla_p_addr_fbsd[] = { { .type = IFAF_VHID, .off = _OUT(ifaf_vhid), .cb = snl_attr_get_uint32 }, + { .type = IFAF_FLAGS, .off = _OUT(ifaf_flags), .cb = snl_attr_get_uint32 }, }; SNL_DECLARE_ATTR_PARSER(_addr_fbsd_parser, _nla_p_addr_fbsd); @@ -317,6 +320,7 @@ static const struct snl_attr_parser _nla_p_addr_s[] = { { .type = IFA_LOCAL, .off = _OUT(ifa_local), .cb = snl_attr_get_ip }, { .type = IFA_LABEL, .off = _OUT(ifa_label), .cb = snl_attr_dup_string }, { .type = IFA_BROADCAST, .off = _OUT(ifa_broadcast), .cb = snl_attr_get_ip }, + { .type = IFA_CACHEINFO, .off = _OUT(ifa_cacheinfo), .cb = snl_attr_dup_struct }, { .type = IFA_FREEBSD, .arg = &_addr_fbsd_parser, .cb = snl_attr_get_nested }, }; static const struct snl_field_parser _fp_p_addr_s[] = { diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c index cc76410550f4..edcf8b635f50 100644 --- a/sys/netlink/route/iface.c +++ b/sys/netlink/route/iface.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -749,6 +750,52 @@ get_sa_plen(const struct sockaddr *sa) return (0); } +#ifdef INET6 +static uint32_t +in6_flags_to_nl(uint32_t flags) +{ + uint32_t nl_flags = 0; + + if (flags & IN6_IFF_TEMPORARY) + nl_flags |= IFA_F_TEMPORARY; + if (flags & IN6_IFF_NODAD) + nl_flags |= IFA_F_NODAD; + if (flags & IN6_IFF_DEPRECATED) + nl_flags |= IFA_F_DEPRECATED; + if (flags & IN6_IFF_TENTATIVE) + nl_flags |= IFA_F_TENTATIVE; + if ((flags & (IN6_IFF_AUTOCONF|IN6_IFF_TEMPORARY)) == 0) + flags |= IFA_F_PERMANENT; + if (flags & IN6_IFF_DUPLICATED) + flags |= IFA_F_DADFAILED; + return (nl_flags); +} + +static void +export_cache_info6(struct nl_writer *nw, const struct in6_ifaddr *ia) +{ + struct ifa_cacheinfo ci = { + .cstamp = ia->ia6_createtime * 1000, + .tstamp = ia->ia6_updatetime * 1000, + .ifa_prefered = ia->ia6_lifetime.ia6t_pltime, + .ifa_valid = ia->ia6_lifetime.ia6t_vltime, + }; + + nlattr_add(nw, IFA_CACHEINFO, sizeof(ci), &ci); +} +#endif + +static void +export_cache_info(struct nl_writer *nw, struct ifaddr *ifa) +{ + switch (ifa->ifa_addr->sa_family) { +#ifdef INET6 + case AF_INET6: + export_cache_info6(nw, (struct in6_ifaddr *)ifa); + break; +#endif + } +} /* * {'attrs': [('IFA_ADDRESS', '12.0.0.1'), @@ -796,8 +843,17 @@ dump_iface_addr(struct nl_writer *nw, struct ifnet *ifp, struct ifaddr *ifa, nlattr_add_string(nw, IFA_LABEL, if_name(ifp)); - uint32_t val = 0; // ifa->ifa_flags; - nlattr_add_u32(nw, IFA_FLAGS, val); + uint32_t nl_ifa_flags = 0; +#ifdef INET6 + if (sa->sa_family == AF_INET6) { + struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa; + nl_ifa_flags = in6_flags_to_nl(ia->ia6_flags); + } +#endif + nlattr_add_u32(nw, IFA_FLAGS, nl_ifa_flags); + + export_cache_info(nw, ifa); + /* Store FreeBSD-specific attributes */ int off = nlattr_add_nested(nw, IFA_FREEBSD); if (off != 0) { @@ -805,6 +861,14 @@ dump_iface_addr(struct nl_writer *nw, struct ifnet *ifp, struct ifaddr *ifa, uint32_t vhid = (uint32_t)(*carp_get_vhid_p)(ifa); nlattr_add_u32(nw, IFAF_VHID, vhid); } +#ifdef INET6 + if (sa->sa_family == AF_INET6) { + uint32_t ifa_flags = ((struct in6_ifaddr *)ifa)->ia6_flags; + + nlattr_add_u32(nw, IFAF_FLAGS, ifa_flags); + } +#endif + nlattr_set_len(nw, off); } diff --git a/sys/netlink/route/ifaddrs.h b/sys/netlink/route/ifaddrs.h index cbf23fe54197..4122e2c3793c 100644 --- a/sys/netlink/route/ifaddrs.h +++ b/sys/netlink/route/ifaddrs.h @@ -68,6 +68,7 @@ enum { enum { IFAF_UNSPEC, IFAF_VHID = 1, /* u32: carp vhid */ + IFAF_FLAGS = 2, /* u32: FreeBSD-specific ifa flags */ __IFAF_MAX, }; #define IFAF_MAX (__IFAF_MAX - 1) @@ -89,10 +90,10 @@ enum { /* IFA_CACHEINFO value */ struct ifa_cacheinfo { - uint32_t ifa_prefered; - uint32_t ifa_valid; - uint32_t cstamp; - uint32_t tstamp; + uint32_t ifa_prefered; /* seconds till the end of the prefix considered preferred */ + uint32_t ifa_valid; /* seconds till the end of the prefix considered valid */ + uint32_t cstamp; /* creation time in 1ms intervals from the boot time */ + uint32_t tstamp; /* update time in 1ms intervals from the boot time */ }; #endif