From e6d58c2f7161e270929f8e5f0c980d5caff1bf52 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 24 Aug 2021 14:55:16 +0900 Subject: sd-netlink: rename several type systems for generic netlink --- src/libsystemd/sd-netlink/netlink-genl.c | 2 +- src/libsystemd/sd-netlink/netlink-types-genl.c | 183 +++++++++++-------------- src/libsystemd/sd-netlink/netlink-types.h | 2 +- 3 files changed, 84 insertions(+), 103 deletions(-) diff --git a/src/libsystemd/sd-netlink/netlink-genl.c b/src/libsystemd/sd-netlink/netlink-genl.c index 401f263d97..9330d66fe2 100644 --- a/src/libsystemd/sd-netlink/netlink-genl.c +++ b/src/libsystemd/sd-netlink/netlink-genl.c @@ -38,7 +38,7 @@ static int genl_message_new(sd_netlink *nl, sd_genl_family_t family, uint16_t nl assert(nl->protocol == NETLINK_GENERIC); assert(ret); - r = type_system_get_type(&genl_family_type_system_root, &genl_cmd_type, family); + r = type_system_get_type(&genl_family_type_system, &genl_cmd_type, family); if (r < 0) return r; diff --git a/src/libsystemd/sd-netlink/netlink-types-genl.c b/src/libsystemd/sd-netlink/netlink-types-genl.c index 3dfe47a7f3..a88609c0be 100644 --- a/src/libsystemd/sd-netlink/netlink-types-genl.c +++ b/src/libsystemd/sd-netlink/netlink-types-genl.c @@ -15,34 +15,34 @@ #include "netlink-types-internal.h" /***************** genl ctrl type systems *****************/ -static const NLType genl_mcast_group_types[] = { +static const NLType genl_ctrl_mcast_group_types[] = { [CTRL_ATTR_MCAST_GRP_NAME] = { .type = NETLINK_TYPE_STRING }, [CTRL_ATTR_MCAST_GRP_ID] = { .type = NETLINK_TYPE_U32 }, }; -static const NLTypeSystem genl_mcast_group_type_system = { - .count = ELEMENTSOF(genl_mcast_group_types), - .types = genl_mcast_group_types, +static const NLTypeSystem genl_ctrl_mcast_group_type_system = { + .count = ELEMENTSOF(genl_ctrl_mcast_group_types), + .types = genl_ctrl_mcast_group_types, }; -static const NLType genl_get_family_types[] = { - [CTRL_ATTR_FAMILY_NAME] = { .type = NETLINK_TYPE_STRING }, +static const NLType genl_ctrl_types[] = { [CTRL_ATTR_FAMILY_ID] = { .type = NETLINK_TYPE_U16 }, - [CTRL_ATTR_MCAST_GROUPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_mcast_group_type_system }, + [CTRL_ATTR_FAMILY_NAME] = { .type = NETLINK_TYPE_STRING }, + [CTRL_ATTR_MCAST_GROUPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_mcast_group_type_system }, }; -static const NLTypeSystem genl_get_family_type_system = { - .count = ELEMENTSOF(genl_get_family_types), - .types = genl_get_family_types, +static const NLTypeSystem genl_ctrl_type_system = { + .count = ELEMENTSOF(genl_ctrl_types), + .types = genl_ctrl_types, }; -static const NLType genl_ctrl_id_ctrl_cmds[] = { - [CTRL_CMD_GETFAMILY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system }, +static const NLType genl_ctrl_cmd_types[] = { + [CTRL_CMD_GETFAMILY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_type_system, }, }; -static const NLTypeSystem genl_ctrl_id_ctrl_type_system = { - .count = ELEMENTSOF(genl_ctrl_id_ctrl_cmds), - .types = genl_ctrl_id_ctrl_cmds, +static const NLTypeSystem genl_ctrl_cmd_type_system = { + .count = ELEMENTSOF(genl_ctrl_cmd_types), + .types = genl_ctrl_cmd_types, }; /***************** genl batadv type systems *****************/ @@ -114,13 +114,13 @@ static const NLTypeSystem genl_batadv_type_system = { .types = genl_batadv_types, }; -static const NLType genl_batadv_cmds[] = { +static const NLType genl_batadv_cmd_types[] = { [BATADV_CMD_SET_MESH] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_batadv_type_system }, }; -static const NLTypeSystem genl_batadv_cmds_type_system = { - .count = ELEMENTSOF(genl_batadv_cmds), - .types = genl_batadv_cmds, +static const NLTypeSystem genl_batadv_cmd_type_system = { + .count = ELEMENTSOF(genl_batadv_cmd_types), + .types = genl_batadv_cmd_types, }; /***************** genl fou type systems *****************/ @@ -143,15 +143,15 @@ static const NLTypeSystem genl_fou_type_system = { .types = genl_fou_types, }; -static const NLType genl_fou_cmds[] = { +static const NLType genl_fou_cmd_types[] = { [FOU_CMD_ADD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system }, [FOU_CMD_DEL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system }, [FOU_CMD_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_type_system }, }; -static const NLTypeSystem genl_fou_cmds_type_system = { - .count = ELEMENTSOF(genl_fou_cmds), - .types = genl_fou_cmds, +static const NLTypeSystem genl_fou_cmd_type_system = { + .count = ELEMENTSOF(genl_fou_cmd_types), + .types = genl_fou_cmd_types, }; /***************** genl l2tp type systems *****************/ @@ -190,7 +190,7 @@ static const NLTypeSystem genl_l2tp_type_system = { .types = genl_l2tp_types, }; -static const NLType genl_l2tp[] = { +static const NLType genl_l2tp_cmd_types[] = { [L2TP_CMD_TUNNEL_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, [L2TP_CMD_TUNNEL_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, [L2TP_CMD_TUNNEL_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, @@ -201,24 +201,14 @@ static const NLType genl_l2tp[] = { [L2TP_CMD_SESSION_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system }, }; -static const NLTypeSystem genl_l2tp_tunnel_session_type_system = { - .count = ELEMENTSOF(genl_l2tp), - .types = genl_l2tp, +static const NLTypeSystem genl_l2tp_cmd_type_system = { + .count = ELEMENTSOF(genl_l2tp_cmd_types), + .types = genl_l2tp_cmd_types, }; /***************** genl macsec type systems *****************/ -static const NLType genl_rxsc_types[] = { - [MACSEC_RXSC_ATTR_SCI] = { .type = NETLINK_TYPE_U64 }, -}; - -static const NLTypeSystem genl_rxsc_config_type_system = { - .count = ELEMENTSOF(genl_rxsc_types), - .types = genl_rxsc_types, -}; - static const NLType genl_macsec_rxsc_types[] = { - [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 }, - [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system }, + [MACSEC_RXSC_ATTR_SCI] = { .type = NETLINK_TYPE_U64 }, }; static const NLTypeSystem genl_macsec_rxsc_type_system = { @@ -226,7 +216,7 @@ static const NLTypeSystem genl_macsec_rxsc_type_system = { .types = genl_macsec_rxsc_types, }; -static const NLType genl_macsec_sa_config_types[] = { +static const NLType genl_macsec_sa_types[] = { [MACSEC_SA_ATTR_AN] = { .type = NETLINK_TYPE_U8 }, [MACSEC_SA_ATTR_ACTIVE] = { .type = NETLINK_TYPE_U8 }, [MACSEC_SA_ATTR_PN] = { .type = NETLINK_TYPE_U32 }, @@ -234,41 +224,31 @@ static const NLType genl_macsec_sa_config_types[] = { [MACSEC_SA_ATTR_KEY] = { .size = MACSEC_MAX_KEY_LEN }, }; -static const NLTypeSystem genl_macsec_sa_config_type_system = { - .count = ELEMENTSOF(genl_macsec_sa_config_types), - .types = genl_macsec_sa_config_types, -}; - -static const NLType genl_macsec_rxsa_types[] = { - [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 }, - [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system }, -}; - -static const NLTypeSystem genl_macsec_rxsa_type_system = { - .count = ELEMENTSOF(genl_macsec_rxsa_types), - .types = genl_macsec_rxsa_types, +static const NLTypeSystem genl_macsec_sa_type_system = { + .count = ELEMENTSOF(genl_macsec_sa_types), + .types = genl_macsec_sa_types, }; -static const NLType genl_macsec_sa_types[] = { +static const NLType genl_macsec_types[] = { [MACSEC_ATTR_IFINDEX] = { .type = NETLINK_TYPE_U32 }, - [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_rxsc_config_type_system }, - [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_config_type_system }, + [MACSEC_ATTR_RXSC_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsc_type_system }, + [MACSEC_ATTR_SA_CONFIG] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_type_system }, }; -static const NLTypeSystem genl_macsec_sa_type_system = { - .count = ELEMENTSOF(genl_macsec_sa_types), - .types = genl_macsec_sa_types, +static const NLTypeSystem genl_macsec_type_system = { + .count = ELEMENTSOF(genl_macsec_types), + .types = genl_macsec_types, }; -static const NLType genl_macsec[] = { - [MACSEC_CMD_ADD_RXSC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsc_type_system }, - [MACSEC_CMD_ADD_TXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_rxsa_type_system}, - [MACSEC_CMD_ADD_RXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_sa_type_system }, +static const NLType genl_macsec_cmd_types[] = { + [MACSEC_CMD_ADD_RXSC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_type_system }, + [MACSEC_CMD_ADD_TXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_type_system }, + [MACSEC_CMD_ADD_RXSA] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_type_system }, }; -static const NLTypeSystem genl_macsec_device_type_system = { - .count = ELEMENTSOF(genl_macsec), - .types = genl_macsec, +static const NLTypeSystem genl_macsec_cmd_type_system = { + .count = ELEMENTSOF(genl_macsec_cmd_types), + .types = genl_macsec_cmd_types, }; /***************** genl nl80211 type systems *****************/ @@ -284,7 +264,7 @@ static const NLTypeSystem genl_nl80211_type_system = { .types = genl_nl80211_types, }; -static const NLType genl_nl80211_cmds[] = { +static const NLType genl_nl80211_cmd_types[] = { [NL80211_CMD_GET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system }, [NL80211_CMD_SET_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system }, [NL80211_CMD_NEW_WIPHY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system }, @@ -299,15 +279,15 @@ static const NLType genl_nl80211_cmds[] = { [NL80211_CMD_DEL_STATION] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system }, }; -static const NLTypeSystem genl_nl80211_cmds_type_system = { - .count = ELEMENTSOF(genl_nl80211_cmds), - .types = genl_nl80211_cmds, +static const NLTypeSystem genl_nl80211_cmd_type_system = { + .count = ELEMENTSOF(genl_nl80211_cmd_types), + .types = genl_nl80211_cmd_types, }; /***************** genl wireguard type systems *****************/ static const NLType genl_wireguard_allowedip_types[] = { - [WGALLOWEDIP_A_FAMILY] = { .type = NETLINK_TYPE_U16 }, - [WGALLOWEDIP_A_IPADDR] = { .type = NETLINK_TYPE_IN_ADDR }, + [WGALLOWEDIP_A_FAMILY] = { .type = NETLINK_TYPE_U16 }, + [WGALLOWEDIP_A_IPADDR] = { .type = NETLINK_TYPE_IN_ADDR }, [WGALLOWEDIP_A_CIDR_MASK] = { .type = NETLINK_TYPE_U8 }, }; @@ -317,12 +297,12 @@ static const NLTypeSystem genl_wireguard_allowedip_type_system = { }; static const NLType genl_wireguard_peer_types[] = { - [WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN }, - [WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 }, - [WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN }, + [WGPEER_A_PUBLIC_KEY] = { .size = WG_KEY_LEN }, + [WGPEER_A_FLAGS] = { .type = NETLINK_TYPE_U32 }, + [WGPEER_A_PRESHARED_KEY] = { .size = WG_KEY_LEN }, [WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NETLINK_TYPE_U16 }, - [WGPEER_A_ENDPOINT] = { .type = NETLINK_TYPE_SOCKADDR }, - [WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system }, + [WGPEER_A_ENDPOINT] = { .type = NETLINK_TYPE_SOCKADDR }, + [WGPEER_A_ALLOWEDIPS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_allowedip_type_system }, }; static const NLTypeSystem genl_wireguard_peer_type_system = { @@ -330,51 +310,52 @@ static const NLTypeSystem genl_wireguard_peer_type_system = { .types = genl_wireguard_peer_types, }; -static const NLType genl_wireguard_set_device_types[] = { - [WGDEVICE_A_IFINDEX] = { .type = NETLINK_TYPE_U32 }, - [WGDEVICE_A_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ-1 }, - [WGDEVICE_A_FLAGS] = { .type = NETLINK_TYPE_U32 }, +static const NLType genl_wireguard_types[] = { + [WGDEVICE_A_IFINDEX] = { .type = NETLINK_TYPE_U32 }, + [WGDEVICE_A_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = IFNAMSIZ-1 }, + [WGDEVICE_A_FLAGS] = { .type = NETLINK_TYPE_U32 }, [WGDEVICE_A_PRIVATE_KEY] = { .size = WG_KEY_LEN }, [WGDEVICE_A_LISTEN_PORT] = { .type = NETLINK_TYPE_U16 }, - [WGDEVICE_A_FWMARK] = { .type = NETLINK_TYPE_U32 }, - [WGDEVICE_A_PEERS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_peer_type_system }, + [WGDEVICE_A_FWMARK] = { .type = NETLINK_TYPE_U32 }, + [WGDEVICE_A_PEERS] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_peer_type_system }, }; -static const NLTypeSystem genl_wireguard_set_device_type_system = { - .count = ELEMENTSOF(genl_wireguard_set_device_types), - .types = genl_wireguard_set_device_types, +static const NLTypeSystem genl_wireguard_type_system = { + .count = ELEMENTSOF(genl_wireguard_types), + .types = genl_wireguard_types, }; -static const NLType genl_wireguard_cmds[] = { - [WG_CMD_SET_DEVICE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_set_device_type_system }, +static const NLType genl_wireguard_cmd_types[] = { + [WG_CMD_SET_DEVICE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system }, }; -static const NLTypeSystem genl_wireguard_type_system = { - .count = ELEMENTSOF(genl_wireguard_cmds), - .types = genl_wireguard_cmds, +static const NLTypeSystem genl_wireguard_cmd_type_system = { + .count = ELEMENTSOF(genl_wireguard_cmd_types), + .types = genl_wireguard_cmd_types, }; +/***************** genl families *****************/ static const NLType genl_families[] = { - [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_id_ctrl_type_system }, - [SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system }, - [SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmds_type_system }, - [SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_tunnel_session_type_system }, - [SD_GENL_MACSEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_device_type_system }, - [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_cmds_type_system }, - [SD_GENL_BATADV] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_batadv_cmds_type_system }, + [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_cmd_type_system }, + [SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_cmd_type_system }, + [SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmd_type_system }, + [SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_cmd_type_system }, + [SD_GENL_MACSEC] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_macsec_cmd_type_system }, + [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_cmd_type_system }, + [SD_GENL_BATADV] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_batadv_cmd_type_system }, }; /* Mainly used when sending message */ -const NLTypeSystem genl_family_type_system_root = { +const NLTypeSystem genl_family_type_system = { .count = ELEMENTSOF(genl_families), .types = genl_families, }; static const NLType genl_types[] = { - [SD_GENL_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) }, [SD_GENL_DONE] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system }, - [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system, .size = sizeof(struct genlmsghdr) }, - [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_type_system, .size = sizeof(struct genlmsghdr) }, + [SD_GENL_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &error_type_system, .size = sizeof(struct nlmsgerr) }, + [SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_type_system, .size = sizeof(struct genlmsghdr) }, + [SD_GENL_NL80211] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_nl80211_cmd_type_system, .size = sizeof(struct genlmsghdr) }, }; /* Mainly used when message received */ diff --git a/src/libsystemd/sd-netlink/netlink-types.h b/src/libsystemd/sd-netlink/netlink-types.h index 14a3c7417a..5e2a0efee9 100644 --- a/src/libsystemd/sd-netlink/netlink-types.h +++ b/src/libsystemd/sd-netlink/netlink-types.h @@ -35,7 +35,7 @@ typedef struct NLTypeSystemUnion NLTypeSystemUnion; typedef struct NLTypeSystem NLTypeSystem; typedef struct NLType NLType; -extern const NLTypeSystem genl_family_type_system_root; +extern const NLTypeSystem genl_family_type_system; int rtnl_get_type(uint16_t nlmsg_type, const NLType **ret); int nfnl_get_type(uint16_t nlmsg_type, const NLType **ret); -- cgit v1.2.1