]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: rename several type systems for generic netlink
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 24 Aug 2021 05:55:16 +0000 (14:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 29 Aug 2021 09:01:26 +0000 (18:01 +0900)
src/libsystemd/sd-netlink/netlink-genl.c
src/libsystemd/sd-netlink/netlink-types-genl.c
src/libsystemd/sd-netlink/netlink-types.h

index 401f263d97767d25283e92ef95c5c206168e3113..9330d66fe268b1ad61cec3f4762b97dbfdba9cac 100644 (file)
@@ -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;
 
index 3dfe47a7f33c33175b4085f095fcb31c0209d7fd..a88609c0bec771097dcc0aa13fc6714f1da3f0a9 100644 (file)
 #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 */
index 14a3c7417ab34675f4113e5b7a782a96fd53ad21..5e2a0efee97f9c9f9ecfc38138f81cc64661e2e0 100644 (file)
@@ -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);