1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-03 13:47:04 +03:00

sd-netlink: drop redundant string table lookup functions to handle type system union

This commit is contained in:
Yu Watanabe 2021-08-24 16:39:38 +09:00
parent fae9ee25a4
commit e6dd298935
4 changed files with 201 additions and 297 deletions

View File

@ -16,89 +16,17 @@ struct NLTypeSystem {
const NLType *types; const NLType *types;
}; };
typedef struct NLTypeSystemUnionElement {
union {
int protocol;
const char *name;
};
NLTypeSystem type_system;
} NLTypeSystemUnionElement;
struct NLTypeSystemUnion { struct NLTypeSystemUnion {
int num; size_t count;
const NLTypeSystemUnionElement *elements;
NLMatchType match_type; NLMatchType match_type;
uint16_t match_attribute; uint16_t match_attribute;
int (*lookup)(const char *);
const NLTypeSystem *type_systems;
}; };
typedef enum NLUnionLinkInfoData {
NL_UNION_LINK_INFO_DATA_BOND,
NL_UNION_LINK_INFO_DATA_BRIDGE,
NL_UNION_LINK_INFO_DATA_VLAN,
NL_UNION_LINK_INFO_DATA_VETH,
NL_UNION_LINK_INFO_DATA_DUMMY,
NL_UNION_LINK_INFO_DATA_MACVLAN,
NL_UNION_LINK_INFO_DATA_MACVTAP,
NL_UNION_LINK_INFO_DATA_IPVLAN,
NL_UNION_LINK_INFO_DATA_IPVTAP,
NL_UNION_LINK_INFO_DATA_VXLAN,
NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL,
NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL,
NL_UNION_LINK_INFO_DATA_ERSPAN,
NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL,
NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL,
NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL,
NL_UNION_LINK_INFO_DATA_SIT_TUNNEL,
NL_UNION_LINK_INFO_DATA_VTI_TUNNEL,
NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL,
NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL,
NL_UNION_LINK_INFO_DATA_VRF,
NL_UNION_LINK_INFO_DATA_VCAN,
NL_UNION_LINK_INFO_DATA_GENEVE,
NL_UNION_LINK_INFO_DATA_VXCAN,
NL_UNION_LINK_INFO_DATA_WIREGUARD,
NL_UNION_LINK_INFO_DATA_NETDEVSIM,
NL_UNION_LINK_INFO_DATA_CAN,
NL_UNION_LINK_INFO_DATA_MACSEC,
NL_UNION_LINK_INFO_DATA_NLMON,
NL_UNION_LINK_INFO_DATA_XFRM,
NL_UNION_LINK_INFO_DATA_IFB,
NL_UNION_LINK_INFO_DATA_BAREUDP,
NL_UNION_LINK_INFO_DATA_BATADV,
_NL_UNION_LINK_INFO_DATA_MAX,
_NL_UNION_LINK_INFO_DATA_INVALID = -EINVAL,
} NLUnionLinkInfoData;
const char *nl_union_link_info_data_to_string(NLUnionLinkInfoData p) _const_;
NLUnionLinkInfoData nl_union_link_info_data_from_string(const char *p) _pure_;
typedef enum NLUnionTCAOptionData {
NL_UNION_TCA_OPTION_DATA_CAKE,
NL_UNION_TCA_OPTION_DATA_CODEL,
NL_UNION_TCA_OPTION_DATA_DRR,
NL_UNION_TCA_OPTION_DATA_ETS,
NL_UNION_TCA_OPTION_DATA_FQ,
NL_UNION_TCA_OPTION_DATA_FQ_CODEL,
NL_UNION_TCA_OPTION_DATA_FQ_PIE,
NL_UNION_TCA_OPTION_DATA_GRED,
NL_UNION_TCA_OPTION_DATA_HHF,
NL_UNION_TCA_OPTION_DATA_HTB,
NL_UNION_TCA_OPTION_DATA_PIE,
NL_UNION_TCA_OPTION_DATA_QFQ,
NL_UNION_TCA_OPTION_DATA_SFB,
NL_UNION_TCA_OPTION_DATA_TBF,
_NL_UNION_TCA_OPTION_DATA_MAX,
_NL_UNION_TCA_OPTION_DATA_INVALID = -EINVAL,
} NLUnionTCAOptionData;
const char *nl_union_tca_option_data_to_string(NLUnionTCAOptionData p) _const_;
NLUnionTCAOptionData nl_union_tca_option_data_from_string(const char *p) _pure_;
typedef enum NLUnionNFTExprData {
NL_UNION_NFT_EXPR_DATA_BITWISE,
NL_UNION_NFT_EXPR_DATA_CMP,
NL_UNION_NFT_EXPR_DATA_FIB,
NL_UNION_NFT_EXPR_DATA_LOOKUP,
NL_UNION_NFT_EXPR_DATA_PAYLOAD,
NL_UNION_NFT_EXPR_DATA_MASQ,
NL_UNION_NFT_EXPR_DATA_META,
NL_UNION_NFT_EXPR_DATA_NAT,
_NL_UNION_NFT_EXPR_DATA_MAX,
_NL_UNION_NFT_EXPR_DATA_INVALID = -EINVAL,
} NLUnionNFTExprData;
const char *nl_union_nft_expr_data_to_string(NLUnionNFTExprData p) _const_;
NLUnionNFTExprData nl_union_nft_expr_data_from_string(const char *p) _pure_;

View File

@ -108,42 +108,36 @@ static const NLType nfnl_nft_expr_masq_types[] = {
[NFTA_MASQ_REG_PROTO_MAX] = { .type = NETLINK_TYPE_U32 }, [NFTA_MASQ_REG_PROTO_MAX] = { .type = NETLINK_TYPE_U32 },
}; };
static const NLTypeSystem nfnl_expr_data_type_systems[] = { static const NLTypeSystemUnionElement nfnl_expr_data_type_systems[] = {
[NL_UNION_NFT_EXPR_DATA_BITWISE] = { .count = ELEMENTSOF(nfnl_nft_expr_bitwise_types), { .name = "bitwise", .type_system = {
.types = nfnl_nft_expr_bitwise_types }, .count = ELEMENTSOF(nfnl_nft_expr_bitwise_types),
[NL_UNION_NFT_EXPR_DATA_CMP] = { .count = ELEMENTSOF(nfnl_nft_expr_cmp_types), .types = nfnl_nft_expr_bitwise_types } },
.types = nfnl_nft_expr_cmp_types }, { .name = "cmp", .type_system = {
[NL_UNION_NFT_EXPR_DATA_FIB] = { .count = ELEMENTSOF(nfnl_nft_expr_fib_types), .count = ELEMENTSOF(nfnl_nft_expr_cmp_types),
.types = nfnl_nft_expr_fib_types }, .types = nfnl_nft_expr_cmp_types } },
[NL_UNION_NFT_EXPR_DATA_LOOKUP] = { .count = ELEMENTSOF(nfnl_nft_expr_lookup_types), { .name = "fib", .type_system = {
.types = nfnl_nft_expr_lookup_types }, .count = ELEMENTSOF(nfnl_nft_expr_fib_types),
[NL_UNION_NFT_EXPR_DATA_MASQ] = { .count = ELEMENTSOF(nfnl_nft_expr_masq_types), .types = nfnl_nft_expr_fib_types } },
.types = nfnl_nft_expr_masq_types }, { .name = "lookup", .type_system = {
[NL_UNION_NFT_EXPR_DATA_META] = { .count = ELEMENTSOF(nfnl_nft_expr_meta_types), .count = ELEMENTSOF(nfnl_nft_expr_lookup_types),
.types = nfnl_nft_expr_meta_types }, .types = nfnl_nft_expr_lookup_types } },
[NL_UNION_NFT_EXPR_DATA_NAT] = { .count = ELEMENTSOF(nfnl_nft_expr_nat_types), { .name = "masq", .type_system = {
.types = nfnl_nft_expr_nat_types }, .count = ELEMENTSOF(nfnl_nft_expr_masq_types),
[NL_UNION_NFT_EXPR_DATA_PAYLOAD] = { .count = ELEMENTSOF(nfnl_nft_expr_payload_types), .types = nfnl_nft_expr_masq_types } },
.types = nfnl_nft_expr_payload_types }, { .name = "meta", .type_system = {
.count = ELEMENTSOF(nfnl_nft_expr_meta_types),
.types = nfnl_nft_expr_meta_types } },
{ .name = "nat", .type_system = {
.count = ELEMENTSOF(nfnl_nft_expr_nat_types),
.types = nfnl_nft_expr_nat_types } },
{ .name = "payload", .type_system = {
.count = ELEMENTSOF(nfnl_nft_expr_payload_types),
.types = nfnl_nft_expr_payload_types } },
}; };
static const char* const nl_union_nft_expr_data_table[] = {
[NL_UNION_NFT_EXPR_DATA_BITWISE] = "bitwise",
[NL_UNION_NFT_EXPR_DATA_CMP] = "cmp",
[NL_UNION_NFT_EXPR_DATA_LOOKUP] = "lookup",
[NL_UNION_NFT_EXPR_DATA_META] = "meta",
[NL_UNION_NFT_EXPR_DATA_FIB] = "fib",
[NL_UNION_NFT_EXPR_DATA_MASQ] = "masq",
[NL_UNION_NFT_EXPR_DATA_NAT] = "nat",
[NL_UNION_NFT_EXPR_DATA_PAYLOAD] = "payload",
};
DEFINE_STRING_TABLE_LOOKUP(nl_union_nft_expr_data, NLUnionNFTExprData);
static const NLTypeSystemUnion nfnl_nft_data_expr_type_system_union = { static const NLTypeSystemUnion nfnl_nft_data_expr_type_system_union = {
.num = _NL_UNION_NFT_EXPR_DATA_MAX, .count = ELEMENTSOF(nfnl_expr_data_type_systems),
.lookup = nl_union_nft_expr_data_from_string, .elements = nfnl_expr_data_type_systems,
.type_systems = nfnl_expr_data_type_systems,
.match_type = NL_MATCH_SIBLING, .match_type = NL_MATCH_SIBLING,
.match_attribute = NFTA_EXPR_NAME, .match_attribute = NFTA_EXPR_NAME,
}; };

View File

@ -345,106 +345,99 @@ static const NLType rtnl_link_info_data_bareudp_types[] = {
[IFLA_BAREUDP_MULTIPROTO_MODE] = { .type = NETLINK_TYPE_FLAG }, [IFLA_BAREUDP_MULTIPROTO_MODE] = { .type = NETLINK_TYPE_FLAG },
}; };
/* these strings must match the .kind entries in the kernel */ static const NLTypeSystemUnionElement rtnl_link_info_data_type_systems[] = {
static const char* const nl_union_link_info_data_table[] = { { .name = "bareudp", .type_system = {
[NL_UNION_LINK_INFO_DATA_BOND] = "bond", .count = ELEMENTSOF(rtnl_link_info_data_bareudp_types),
[NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge", .types = rtnl_link_info_data_bareudp_types } },
[NL_UNION_LINK_INFO_DATA_VLAN] = "vlan", { .name = "batadv", .type_system = {
[NL_UNION_LINK_INFO_DATA_VETH] = "veth", .count = ELEMENTSOF(rtnl_link_info_data_batadv_types),
[NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy", .types = rtnl_link_info_data_batadv_types } },
[NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan", { .name = "bond", .type_system = {
[NL_UNION_LINK_INFO_DATA_MACVTAP] = "macvtap", .count = ELEMENTSOF(rtnl_link_info_data_bond_types),
[NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan", .types = rtnl_link_info_data_bond_types } },
[NL_UNION_LINK_INFO_DATA_IPVTAP] = "ipvtap", { .name = "bridge", .type_system = {
[NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan", .count = ELEMENTSOF(rtnl_link_info_data_bridge_types),
[NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip", .types = rtnl_link_info_data_bridge_types } },
[NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre", { .name = "can", .type_system = {
[NL_UNION_LINK_INFO_DATA_ERSPAN] = "erspan", .count = ELEMENTSOF(rtnl_link_info_data_can_types),
[NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap", .types = rtnl_link_info_data_can_types } },
[NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre", { .name = "dummy", },
[NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap", { .name = "erspan", .type_system = {
[NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit", .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
[NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti", .types = rtnl_link_info_data_ipgre_types } },
[NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6", { .name = "geneve", .type_system = {
[NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl", .count = ELEMENTSOF(rtnl_link_info_data_geneve_types),
[NL_UNION_LINK_INFO_DATA_VRF] = "vrf", .types = rtnl_link_info_data_geneve_types } },
[NL_UNION_LINK_INFO_DATA_VCAN] = "vcan", { .name = "gre", .type_system = {
[NL_UNION_LINK_INFO_DATA_GENEVE] = "geneve", .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
[NL_UNION_LINK_INFO_DATA_VXCAN] = "vxcan", .types = rtnl_link_info_data_ipgre_types } },
[NL_UNION_LINK_INFO_DATA_WIREGUARD] = "wireguard", { .name = "gretap", .type_system = {
[NL_UNION_LINK_INFO_DATA_NETDEVSIM] = "netdevsim", .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
[NL_UNION_LINK_INFO_DATA_CAN] = "can", .types = rtnl_link_info_data_ipgre_types } },
[NL_UNION_LINK_INFO_DATA_MACSEC] = "macsec", { .name = "ifb", },
[NL_UNION_LINK_INFO_DATA_NLMON] = "nlmon", { .name = "ip6gre", .type_system = {
[NL_UNION_LINK_INFO_DATA_XFRM] = "xfrm", .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
[NL_UNION_LINK_INFO_DATA_IFB] = "ifb", .types = rtnl_link_info_data_ipgre_types } },
[NL_UNION_LINK_INFO_DATA_BAREUDP] = "bareudp", { .name = "ip6gretap", .type_system = {
[NL_UNION_LINK_INFO_DATA_BATADV] = "batadv", .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types),
}; .types = rtnl_link_info_data_ipgre_types } },
{ .name = "ip6tnl", .type_system = {
DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData); .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types),
.types = rtnl_link_info_data_ip6tnl_types } },
static const NLTypeSystem rtnl_link_info_data_type_systems[] = { { .name = "ipip", .type_system = {
[NL_UNION_LINK_INFO_DATA_BOND] = { .count = ELEMENTSOF(rtnl_link_info_data_bond_types), .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
.types = rtnl_link_info_data_bond_types }, .types = rtnl_link_info_data_iptun_types } },
[NL_UNION_LINK_INFO_DATA_BRIDGE] = { .count = ELEMENTSOF(rtnl_link_info_data_bridge_types), { .name = "ipvlan", .type_system = {
.types = rtnl_link_info_data_bridge_types }, .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
[NL_UNION_LINK_INFO_DATA_VLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vlan_types), .types = rtnl_link_info_data_ipvlan_types } },
.types = rtnl_link_info_data_vlan_types }, { .name = "ipvtap", .type_system = {
[NL_UNION_LINK_INFO_DATA_VETH] = { .count = ELEMENTSOF(rtnl_link_info_data_veth_types), .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types),
.types = rtnl_link_info_data_veth_types }, .types = rtnl_link_info_data_ipvlan_types } },
[NL_UNION_LINK_INFO_DATA_MACVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), { .name = "macsec", .type_system = {
.types = rtnl_link_info_data_macvlan_types }, .count = ELEMENTSOF(rtnl_link_info_data_macsec_types),
[NL_UNION_LINK_INFO_DATA_MACVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types), .types = rtnl_link_info_data_macsec_types } },
.types = rtnl_link_info_data_macvlan_types }, { .name = "macvlan", .type_system = {
[NL_UNION_LINK_INFO_DATA_IPVLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types), .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
.types = rtnl_link_info_data_ipvlan_types }, .types = rtnl_link_info_data_macvlan_types } },
[NL_UNION_LINK_INFO_DATA_IPVTAP] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvlan_types), { .name = "macvtap", .type_system = {
.types = rtnl_link_info_data_ipvlan_types }, .count = ELEMENTSOF(rtnl_link_info_data_macvlan_types),
[NL_UNION_LINK_INFO_DATA_VXLAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types), .types = rtnl_link_info_data_macvlan_types } },
.types = rtnl_link_info_data_vxlan_types }, { .name = "netdevsim", },
[NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), { .name = "nlmon", },
.types = rtnl_link_info_data_iptun_types }, { .name = "sit", .type_system = {
[NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), .count = ELEMENTSOF(rtnl_link_info_data_iptun_types),
.types = rtnl_link_info_data_ipgre_types }, .types = rtnl_link_info_data_iptun_types } },
[NL_UNION_LINK_INFO_DATA_ERSPAN] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), { .name = "vcan", },
.types = rtnl_link_info_data_ipgre_types }, { .name = "veth", .type_system = {
[NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), .count = ELEMENTSOF(rtnl_link_info_data_veth_types),
.types = rtnl_link_info_data_ipgre_types }, .types = rtnl_link_info_data_veth_types } },
[NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), { .name = "vlan", .type_system = {
.types = rtnl_link_info_data_ipgre_types }, .count = ELEMENTSOF(rtnl_link_info_data_vlan_types),
[NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipgre_types), .types = rtnl_link_info_data_vlan_types } },
.types = rtnl_link_info_data_ipgre_types }, { .name = "vrf", .type_system = {
[NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_iptun_types), .count = ELEMENTSOF(rtnl_link_info_data_vrf_types),
.types = rtnl_link_info_data_iptun_types }, .types = rtnl_link_info_data_vrf_types } },
[NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), { .name = "vti", .type_system = {
.types = rtnl_link_info_data_ipvti_types }, .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
[NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types), .types = rtnl_link_info_data_ipvti_types } },
.types = rtnl_link_info_data_ipvti_types }, { .name = "vti6", .type_system = {
[NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .count = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types), .count = ELEMENTSOF(rtnl_link_info_data_ipvti_types),
.types = rtnl_link_info_data_ip6tnl_types }, .types = rtnl_link_info_data_ipvti_types } },
[NL_UNION_LINK_INFO_DATA_VRF] = { .count = ELEMENTSOF(rtnl_link_info_data_vrf_types), { .name = "vxcan", .type_system = {
.types = rtnl_link_info_data_vrf_types }, .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types),
[NL_UNION_LINK_INFO_DATA_GENEVE] = { .count = ELEMENTSOF(rtnl_link_info_data_geneve_types), .types = rtnl_link_info_data_vxcan_types } },
.types = rtnl_link_info_data_geneve_types }, { .name = "vxlan", .type_system = {
[NL_UNION_LINK_INFO_DATA_VXCAN] = { .count = ELEMENTSOF(rtnl_link_info_data_vxcan_types), .count = ELEMENTSOF(rtnl_link_info_data_vxlan_types),
.types = rtnl_link_info_data_vxcan_types }, .types = rtnl_link_info_data_vxlan_types } },
[NL_UNION_LINK_INFO_DATA_CAN] = { .count = ELEMENTSOF(rtnl_link_info_data_can_types), { .name = "wireguard", },
.types = rtnl_link_info_data_can_types }, { .name = "xfrm", .type_system = {
[NL_UNION_LINK_INFO_DATA_MACSEC] = { .count = ELEMENTSOF(rtnl_link_info_data_macsec_types), .count = ELEMENTSOF(rtnl_link_info_data_xfrm_types),
.types = rtnl_link_info_data_macsec_types }, .types = rtnl_link_info_data_xfrm_types } },
[NL_UNION_LINK_INFO_DATA_XFRM] = { .count = ELEMENTSOF(rtnl_link_info_data_xfrm_types),
.types = rtnl_link_info_data_xfrm_types },
[NL_UNION_LINK_INFO_DATA_BAREUDP] = { .count = ELEMENTSOF(rtnl_link_info_data_bareudp_types),
.types = rtnl_link_info_data_bareudp_types },
[NL_UNION_LINK_INFO_DATA_BATADV] = { .count = ELEMENTSOF(rtnl_link_info_data_batadv_types),
.types = rtnl_link_info_data_batadv_types },
}; };
static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = { static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
.num = _NL_UNION_LINK_INFO_DATA_MAX, .count = ELEMENTSOF(rtnl_link_info_data_type_systems),
.lookup = nl_union_link_info_data_from_string, .elements = rtnl_link_info_data_type_systems,
.type_systems = rtnl_link_info_data_type_systems,
.match_type = NL_MATCH_SIBLING, .match_type = NL_MATCH_SIBLING,
.match_attribute = IFLA_INFO_KIND, .match_attribute = IFLA_INFO_KIND,
}; };
@ -501,14 +494,15 @@ static const struct NLType rtnl_prot_info_bridge_port_types[] = {
[IFLA_BRPORT_BACKUP_PORT] = { .type = NETLINK_TYPE_U32 }, [IFLA_BRPORT_BACKUP_PORT] = { .type = NETLINK_TYPE_U32 },
}; };
static const NLTypeSystem rtnl_prot_info_type_systems[] = { static const NLTypeSystemUnionElement rtnl_prot_info_type_systems[] = {
[AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types), { .protocol = AF_BRIDGE, .type_system = {
.types = rtnl_prot_info_bridge_port_types }, .count = ELEMENTSOF(rtnl_prot_info_bridge_port_types),
.types = rtnl_prot_info_bridge_port_types } },
}; };
static const NLTypeSystemUnion rtnl_prot_info_type_system_union = { static const NLTypeSystemUnion rtnl_prot_info_type_system_union = {
.num = AF_MAX, .count = ELEMENTSOF(rtnl_prot_info_type_systems),
.type_systems = rtnl_prot_info_type_systems, .elements = rtnl_prot_info_type_systems,
.match_type = NL_MATCH_PROTOCOL, .match_type = NL_MATCH_PROTOCOL,
}; };
@ -539,16 +533,18 @@ static const NLType rtnl_af_spec_bridge_types[] = {
[IFLA_BRIDGE_VLAN_INFO] = { .size = sizeof(struct bridge_vlan_info) }, [IFLA_BRIDGE_VLAN_INFO] = { .size = sizeof(struct bridge_vlan_info) },
}; };
static const NLTypeSystem rtnl_af_spec_type_systems[] = { static const NLTypeSystemUnionElement rtnl_af_spec_type_systems[] = {
[AF_UNSPEC] = { .count = ELEMENTSOF(rtnl_af_spec_unspec_types), { .protocol = AF_UNSPEC, .type_system = {
.types = rtnl_af_spec_unspec_types }, .count = ELEMENTSOF(rtnl_af_spec_unspec_types),
[AF_BRIDGE] = { .count = ELEMENTSOF(rtnl_af_spec_bridge_types), .types = rtnl_af_spec_unspec_types } },
.types = rtnl_af_spec_bridge_types }, { .protocol = AF_BRIDGE, .type_system = {
.count = ELEMENTSOF(rtnl_af_spec_bridge_types),
.types = rtnl_af_spec_bridge_types } },
}; };
static const NLTypeSystemUnion rtnl_af_spec_type_system_union = { static const NLTypeSystemUnion rtnl_af_spec_type_system_union = {
.num = AF_MAX, .count = ELEMENTSOF(rtnl_af_spec_type_systems),
.type_systems = rtnl_af_spec_type_systems, .elements = rtnl_af_spec_type_systems,
.match_type = NL_MATCH_PROTOCOL, .match_type = NL_MATCH_PROTOCOL,
}; };
@ -928,60 +924,54 @@ static const NLType rtnl_tca_option_data_tbf_types[] = {
[TCA_TBF_PBURST] = { .type = NETLINK_TYPE_U32 }, [TCA_TBF_PBURST] = { .type = NETLINK_TYPE_U32 },
}; };
static const char* const nl_union_tca_option_data_table[] = { static const NLTypeSystemUnionElement rtnl_tca_option_data_type_systems[] = {
[NL_UNION_TCA_OPTION_DATA_CAKE] = "cake", { .name = "cake", .type_system = {
[NL_UNION_TCA_OPTION_DATA_CODEL] = "codel", .count = ELEMENTSOF(rtnl_tca_option_data_cake_types),
[NL_UNION_TCA_OPTION_DATA_DRR] = "drr", .types = rtnl_tca_option_data_cake_types } },
[NL_UNION_TCA_OPTION_DATA_ETS] = "ets", { .name = "codel", .type_system = {
[NL_UNION_TCA_OPTION_DATA_FQ] = "fq", .count = ELEMENTSOF(rtnl_tca_option_data_codel_types),
[NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = "fq_codel", .types = rtnl_tca_option_data_codel_types } },
[NL_UNION_TCA_OPTION_DATA_FQ_PIE] = "fq_pie", { .name = "drr", .type_system = {
[NL_UNION_TCA_OPTION_DATA_GRED] = "gred", .count = ELEMENTSOF(rtnl_tca_option_data_drr_types),
[NL_UNION_TCA_OPTION_DATA_HHF] = "hhf", .types = rtnl_tca_option_data_drr_types } },
[NL_UNION_TCA_OPTION_DATA_HTB] = "htb", { .name = "ets", .type_system = {
[NL_UNION_TCA_OPTION_DATA_PIE] = "pie", .count = ELEMENTSOF(rtnl_tca_option_data_ets_types),
[NL_UNION_TCA_OPTION_DATA_QFQ] = "qfq", .types = rtnl_tca_option_data_ets_types } },
[NL_UNION_TCA_OPTION_DATA_SFB] = "sfb", { .name = "fq", .type_system = {
[NL_UNION_TCA_OPTION_DATA_TBF] = "tbf", .count = ELEMENTSOF(rtnl_tca_option_data_fq_types),
}; .types = rtnl_tca_option_data_fq_types } },
{ .name = "fq_codel", .type_system = {
DEFINE_STRING_TABLE_LOOKUP(nl_union_tca_option_data, NLUnionTCAOptionData); .count = ELEMENTSOF(rtnl_tca_option_data_fq_codel_types),
.types = rtnl_tca_option_data_fq_codel_types } },
static const NLTypeSystem rtnl_tca_option_data_type_systems[] = { { .name = "fq_pie", .type_system = {
[NL_UNION_TCA_OPTION_DATA_CAKE] = { .count = ELEMENTSOF(rtnl_tca_option_data_cake_types), .count = ELEMENTSOF(rtnl_tca_option_data_fq_pie_types),
.types = rtnl_tca_option_data_cake_types }, .types = rtnl_tca_option_data_fq_pie_types } },
[NL_UNION_TCA_OPTION_DATA_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_codel_types), { .name = "gred", .type_system = {
.types = rtnl_tca_option_data_codel_types }, .count = ELEMENTSOF(rtnl_tca_option_data_gred_types),
[NL_UNION_TCA_OPTION_DATA_DRR] = { .count = ELEMENTSOF(rtnl_tca_option_data_drr_types), .types = rtnl_tca_option_data_gred_types } },
.types = rtnl_tca_option_data_drr_types }, { .name = "hhf", .type_system = {
[NL_UNION_TCA_OPTION_DATA_ETS] = { .count = ELEMENTSOF(rtnl_tca_option_data_ets_types), .count = ELEMENTSOF(rtnl_tca_option_data_hhf_types),
.types = rtnl_tca_option_data_ets_types }, .types = rtnl_tca_option_data_hhf_types } },
[NL_UNION_TCA_OPTION_DATA_FQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_types), { .name = "htb", .type_system = {
.types = rtnl_tca_option_data_fq_types }, .count = ELEMENTSOF(rtnl_tca_option_data_htb_types),
[NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_codel_types), .types = rtnl_tca_option_data_htb_types } },
.types = rtnl_tca_option_data_fq_codel_types }, { .name = "pie", .type_system = {
[NL_UNION_TCA_OPTION_DATA_FQ_PIE] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_pie_types), .count = ELEMENTSOF(rtnl_tca_option_data_pie_types),
.types = rtnl_tca_option_data_fq_pie_types }, .types = rtnl_tca_option_data_pie_types } },
[NL_UNION_TCA_OPTION_DATA_GRED] = { .count = ELEMENTSOF(rtnl_tca_option_data_gred_types), { .name = "qfq", .type_system = {
.types = rtnl_tca_option_data_gred_types }, .count = ELEMENTSOF(rtnl_tca_option_data_qfq_types),
[NL_UNION_TCA_OPTION_DATA_HHF] = { .count = ELEMENTSOF(rtnl_tca_option_data_hhf_types), .types = rtnl_tca_option_data_qfq_types } },
.types = rtnl_tca_option_data_hhf_types }, { .name = "sfb", .type_system = {
[NL_UNION_TCA_OPTION_DATA_HTB] = { .count = ELEMENTSOF(rtnl_tca_option_data_htb_types), .count = ELEMENTSOF(rtnl_tca_option_data_sfb_types),
.types = rtnl_tca_option_data_htb_types }, .types = rtnl_tca_option_data_sfb_types } },
[NL_UNION_TCA_OPTION_DATA_PIE] = { .count = ELEMENTSOF(rtnl_tca_option_data_pie_types), { .name = "tbf", .type_system = {
.types = rtnl_tca_option_data_pie_types }, .count = ELEMENTSOF(rtnl_tca_option_data_tbf_types),
[NL_UNION_TCA_OPTION_DATA_QFQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_qfq_types), .types = rtnl_tca_option_data_tbf_types } },
.types = rtnl_tca_option_data_qfq_types },
[NL_UNION_TCA_OPTION_DATA_SFB] = { .count = ELEMENTSOF(rtnl_tca_option_data_sfb_types),
.types = rtnl_tca_option_data_sfb_types },
[NL_UNION_TCA_OPTION_DATA_TBF] = { .count = ELEMENTSOF(rtnl_tca_option_data_tbf_types),
.types = rtnl_tca_option_data_tbf_types },
}; };
static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union = { static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union = {
.num = _NL_UNION_TCA_OPTION_DATA_MAX, .count = ELEMENTSOF(rtnl_tca_option_data_type_systems),
.lookup = nl_union_tca_option_data_from_string, .elements = rtnl_tca_option_data_type_systems,
.type_systems = rtnl_tca_option_data_type_systems,
.match_type = NL_MATCH_SIBLING, .match_type = NL_MATCH_SIBLING,
.match_attribute = TCA_KIND, .match_attribute = TCA_KIND,
}; };

View File

@ -138,40 +138,32 @@ uint16_t type_system_union_get_match_attribute(const NLTypeSystemUnion *type_sys
} }
int type_system_union_get_type_system_by_string(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) { int type_system_union_get_type_system_by_string(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) {
int type;
assert(type_system_union); assert(type_system_union);
assert(type_system_union->elements);
assert(type_system_union->match_type == NL_MATCH_SIBLING); assert(type_system_union->match_type == NL_MATCH_SIBLING);
assert(type_system_union->lookup);
assert(type_system_union->type_systems);
assert(ret); assert(ret);
assert(key); assert(key);
type = type_system_union->lookup(key); for (size_t i = 0; i < type_system_union->count; i++)
if (type < 0) if (streq(type_system_union->elements[i].name, key)) {
return -EOPNOTSUPP; *ret = &type_system_union->elements[i].type_system;
assert(type < type_system_union->num);
*ret = &type_system_union->type_systems[type];
return 0; return 0;
} }
return -EOPNOTSUPP;
}
int type_system_union_get_type_system_by_protocol(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) { int type_system_union_get_type_system_by_protocol(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) {
const NLTypeSystem *type_system;
assert(type_system_union); assert(type_system_union);
assert(type_system_union->type_systems); assert(type_system_union->elements);
assert(type_system_union->match_type == NL_MATCH_PROTOCOL); assert(type_system_union->match_type == NL_MATCH_PROTOCOL);
assert(ret); assert(ret);
if (protocol >= type_system_union->num) for (size_t i = 0; i < type_system_union->count; i++)
return -EOPNOTSUPP; if (type_system_union->elements[i].protocol == protocol) {
*ret = &type_system_union->elements[i].type_system;
type_system = &type_system_union->type_systems[protocol];
if (!type_system->types)
return -EOPNOTSUPP;
*ret = type_system;
return 0; return 0;
} }
return -EOPNOTSUPP;
}