git: 6cee6af2064a - stable/13 - netlink: add standrard ifaddr/neigh parsers to snl(3).
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 09 Apr 2023 13:53:57 UTC
The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=6cee6af2064ae0c60221238904dd2c6420845128 commit 6cee6af2064ae0c60221238904dd2c6420845128 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-03-26 09:04:41 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-04-09 13:53:39 +0000 netlink: add standrard ifaddr/neigh parsers to snl(3). MFC after: 2 weeks (cherry picked from commit 9a11f3dff991bac89afb5f74a476e765abdbd1d1) --- sys/netlink/netlink_snl_route_parsers.h | 57 ++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/sys/netlink/netlink_snl_route_parsers.h b/sys/netlink/netlink_snl_route_parsers.h index a370f89fb9e3..ba9ead461c80 100644 --- a/sys/netlink/netlink_snl_route_parsers.h +++ b/sys/netlink/netlink_snl_route_parsers.h @@ -198,6 +198,7 @@ struct snl_parsed_link_simple { uint32_t ifi_index; uint32_t ifla_mtu; uint16_t ifi_type; + uint32_t ifi_flags; char *ifla_ifname; }; @@ -210,14 +211,68 @@ static struct snl_attr_parser _nla_p_link_s[] = { static struct snl_field_parser _fp_p_link_s[] = { {.off_in = _IN(ifi_index), .off_out = _OUT(ifi_index), .cb = snl_field_get_uint32 }, {.off_in = _IN(ifi_type), .off_out = _OUT(ifi_type), .cb = snl_field_get_uint16 }, + {.off_in = _IN(ifi_flags), .off_out = _OUT(ifi_flags), .cb = snl_field_get_uint32 }, }; #undef _IN #undef _OUT SNL_DECLARE_PARSER(snl_rtm_link_parser_simple, struct ifinfomsg, _fp_p_link_s, _nla_p_link_s); +struct snl_parsed_neigh { + uint8_t ndm_family; + uint8_t ndm_flags; + uint16_t ndm_state; + uint32_t nda_ifindex; + struct sockaddr *nda_dst; + struct nlattr *nda_lladdr; +}; + +#define _IN(_field) offsetof(struct ndmsg, _field) +#define _OUT(_field) offsetof(struct snl_parsed_neigh, _field) +static struct snl_attr_parser _nla_p_neigh_s[] = { + { .type = NDA_DST, .off = _OUT(nda_dst), .cb = snl_attr_get_ip }, + { .type = NDA_LLADDR , .off = _OUT(nda_lladdr), .cb = snl_attr_get_nla }, + { .type = NDA_IFINDEX, .off = _OUT(nda_ifindex), .cb = snl_attr_get_uint32 }, +}; +static struct snl_field_parser _fp_p_neigh_s[] = { + {.off_in = _IN(ndm_family), .off_out = _OUT(ndm_family), .cb = snl_field_get_uint8 }, + {.off_in = _IN(ndm_flags), .off_out = _OUT(ndm_flags), .cb = snl_field_get_uint8 }, + {.off_in = _IN(ndm_state), .off_out = _OUT(ndm_state), .cb = snl_field_get_uint16 }, +}; +#undef _IN +#undef _OUT +SNL_DECLARE_PARSER(snl_rtm_neigh_parser, struct ndmsg, _fp_p_neigh_s, _nla_p_neigh_s); + +struct snl_parsed_addr { + uint8_t ifa_family; + uint8_t ifa_prefixlen; + uint32_t ifa_index; + struct sockaddr *ifa_local; + struct sockaddr *ifa_address; + struct sockaddr *ifa_broadcast; + char *ifa_label; +}; + +#define _IN(_field) offsetof(struct ifaddrmsg, _field) +#define _OUT(_field) offsetof(struct snl_parsed_addr, _field) +static struct snl_attr_parser _nla_p_addr_s[] = { + { .type = IFA_ADDRESS, .off = _OUT(ifa_address), .cb = snl_attr_get_ip }, + { .type = IFA_LOCAL, .off = _OUT(ifa_local), .cb = snl_attr_get_ip }, + { .type = IFA_LABEL, .off = _OUT(ifa_label), .cb = snl_attr_get_string }, + { .type = IFA_BROADCAST, .off = _OUT(ifa_broadcast), .cb = snl_attr_get_ip }, +}; +static struct snl_field_parser _fp_p_addr_s[] = { + {.off_in = _IN(ifa_family), .off_out = _OUT(ifa_family), .cb = snl_field_get_uint8 }, + {.off_in = _IN(ifa_prefixlen), .off_out = _OUT(ifa_prefixlen), .cb = snl_field_get_uint8 }, + {.off_in = _IN(ifa_index), .off_out = _OUT(ifa_index), .cb = snl_field_get_uint32 }, +}; +#undef _IN +#undef _OUT +SNL_DECLARE_PARSER(snl_rtm_addr_parser, struct ifaddrmsg, _fp_p_addr_s, _nla_p_addr_s); + static const struct snl_hdr_parser *snl_all_route_parsers[] = { &_metrics_mp_nh_parser, &_mpath_nh_parser, &_metrics_parser, &snl_rtm_route_parser, - &snl_rtm_link_parser, &snl_rtm_link_parser_simple, + &snl_rtm_link_parser, &snl_rtm_link_parser_simple, &snl_rtm_neigh_parser, + &snl_rtm_addr_parser, }; #endif