From nobody Thu Oct 31 00:20:10 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E55AD523 for ; Tue, 5 Sep 2023 13:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693922085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uIM25AmWAXKCvTu5rBr/1RxppRmhrRvuhFnJ1iHN+uc=; b=HQTLQDJoY8rhEI6+Dft0LNyjlL0qktzz8+WFtGXGDHC7jO87eBJhyEvcO3qhRxADgY+38Z gAoSSgSKZwRmopa466VDJO85y6D73LFHnkJBkmnH+UCxWEFjuLssb8oG8Xhk+Lt7LbiWYL r3v1pp4Zlu9topey7aQOjba7BRdIXjs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-262-TXEcKah5N4SlO2ioluqEXA-1; Tue, 05 Sep 2023 09:54:40 -0400 X-MC-Unique: TXEcKah5N4SlO2ioluqEXA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8977B92B981; Tue, 5 Sep 2023 13:54:40 +0000 (UTC) Received: from dcaratti.users.ipa.redhat.com (unknown [10.32.181.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E46C040C84A7; Tue, 5 Sep 2023 13:54:39 +0000 (UTC) From: Davide Caratti To: mptcp@lists.linux.dev Cc: pabeni@redhat.com, Matthieu Baerts Subject: [PATCH mptcp-next v3 2/6] net: mptcp: convert netlink from small_ops to ops Date: Tue, 5 Sep 2023 15:53:07 +0200 Message-Id: <0377d42be507e4ce289235ddd8ab924683b77247.1693921470.git.dcaratti@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8"; x-default="true" in the current MPTCP control plane, all operations use a netlink attribute of the same type "MPTCP_PM_ATTR". However, add/del/get/flush operations only parse the first element in the message _ the one that describes MPTCP endpoints (that was named MPTCP_PM_ATTR_ADDR and mostly used in ADD_ADDR operations _ probably the similarity of "attr", "addr" and "add" might cause some confusion to human readers). Convert MPTCP from 'small_ops' to 'ops', thus allowing different attributes for each single operation, hopefully makes all this clearer to human readers. - use a separate attribute set for add/del/get/flush address operation, binary compatible with the existing one, to store the endpoint address. MPTCP_PM_ENDPOINT_ADDR is added to the uAPI (with the same value as MPTCP_PM_ATTR_ADDR) for these operations. - convert mptcp_pm_ops[] and add policy files accordingly. this prepares MPTCP control plane to be described as YAML spec. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/340 Signed-off-by: Davide Caratti --- include/uapi/linux/mptcp.h | 8 ++ net/mptcp/pm_netlink.c | 191 ++++++++++++++++++++++++------------- 2 files changed, 135 insertions(+), 64 deletions(-) diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h index ee9c49f949a2..34082c14c89b 100644 --- a/include/uapi/linux/mptcp.h +++ b/include/uapi/linux/mptcp.h @@ -65,6 +65,14 @@ enum { =20 #define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1) =20 +enum { + MPTCP_PM_ENDPOINT_ADDR =3D 1, + + __MPTCP_PM_ENDPOINT_MAX +}; + +#define MPTCP_PM_ENDPOINT_MAX (__MPTCP_PM_ENDPOINT_MAX - 1) + enum { MPTCP_PM_ADDR_ATTR_UNSPEC, =20 diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 9661f3812682..cf9a4d8b4cca 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -48,6 +48,60 @@ struct pm_nl_pernet { #define MPTCP_PM_ADDR_MAX 8 #define ADD_ADDR_RETRANS_MAX 3 =20 +static +const struct nla_policy mptcp_pm_address_nl_policy[MPTCP_PM_ADDR_ATTR_IF_I= DX + 1] =3D { + [MPTCP_PM_ADDR_ATTR_FAMILY] =3D { .type =3D NLA_U16, }, + [MPTCP_PM_ADDR_ATTR_ID] =3D { .type =3D NLA_U8, }, + [MPTCP_PM_ADDR_ATTR_ADDR4] =3D { .type =3D NLA_U32, }, + [MPTCP_PM_ADDR_ATTR_ADDR6] =3D { .len =3D 16, }, + [MPTCP_PM_ADDR_ATTR_PORT] =3D { .type =3D NLA_U16, }, + [MPTCP_PM_ADDR_ATTR_FLAGS] =3D { .type =3D NLA_U32, }, + [MPTCP_PM_ADDR_ATTR_IF_IDX] =3D { .type =3D NLA_S32, }, +}; + +/* MPTCP_PM_CMD_ADD_ADDR / DEL / GET / FLUSH - do */ +static +const struct nla_policy mptcp_pm_endpoint_nl_policy[MPTCP_PM_ENDPOINT_ADDR= + 1] =3D { + [MPTCP_PM_ENDPOINT_ADDR] =3D NLA_POLICY_NESTED(mptcp_pm_address_nl_policy= ), +}; + +/* MPTCP_PM_CMD_SET_LIMITS - do */ +static +const struct nla_policy mptcp_pm_set_limits_nl_policy[MPTCP_PM_ATTR_SUBFLO= WS + 1] =3D { + [MPTCP_PM_ATTR_RCV_ADD_ADDRS] =3D { .type =3D NLA_U32, }, + [MPTCP_PM_ATTR_SUBFLOWS] =3D { .type =3D NLA_U32, }, +}; + +/* MPTCP_PM_CMD_SET_FLAGS - do */ +static +const struct nla_policy mptcp_pm_set_flags_nl_policy[MPTCP_PM_ATTR_ADDR_RE= MOTE + 1] =3D { + [MPTCP_PM_ATTR_ADDR] =3D NLA_POLICY_NESTED(mptcp_pm_address_nl_pol= icy), + [MPTCP_PM_ATTR_TOKEN] =3D { .type =3D NLA_U32, }, + [MPTCP_PM_ATTR_ADDR_REMOTE] =3D NLA_POLICY_NESTED(mptcp_pm_address= _nl_policy), +}; + +/* MPTCP_PM_CMD_ANNOUNCE - do */ +static +const struct nla_policy mptcp_pm_announce_nl_policy[MPTCP_PM_ATTR_TOKEN + = 1] =3D { + [MPTCP_PM_ATTR_ADDR] =3D NLA_POLICY_NESTED(mptcp_pm_address_nl_policy), + [MPTCP_PM_ATTR_TOKEN] =3D { .type =3D NLA_U32, }, +}; + +/* MPTCP_PM_CMD_REMOVE - do */ +static +const struct nla_policy mptcp_pm_remove_nl_policy[MPTCP_PM_ATTR_LOC_ID + 1= ] =3D { + [MPTCP_PM_ATTR_TOKEN] =3D { .type =3D NLA_U32, }, + [MPTCP_PM_ATTR_LOC_ID] =3D { .type =3D NLA_U8, }, +}; + +/* MPTCP_PM_CMD_SUBFLOW_CREATE / DESTROY - do */ +static +const struct nla_policy mptcp_pm_subflow_create_nl_policy[MPTCP_PM_ATTR_AD= DR_REMOTE + 1] =3D { + [MPTCP_PM_ATTR_ADDR] =3D NLA_POLICY_NESTED(mptcp_pm_address_nl_policy), + [MPTCP_PM_ATTR_TOKEN] =3D { .type =3D NLA_U32, }, + [MPTCP_PM_ATTR_ADDR_REMOTE] =3D NLA_POLICY_NESTED(mptcp_pm_address_nl_pol= icy), +}; + static struct pm_nl_pernet *pm_nl_get_pernet(const struct net *net) { return net_generic(net, pm_nl_pernet_id); @@ -1104,29 +1158,6 @@ static const struct genl_multicast_group mptcp_pm_mc= grps[] =3D { }, }; =20 -static const struct nla_policy -mptcp_pm_addr_policy[MPTCP_PM_ADDR_ATTR_MAX + 1] =3D { - [MPTCP_PM_ADDR_ATTR_FAMILY] =3D { .type =3D NLA_U16, }, - [MPTCP_PM_ADDR_ATTR_ID] =3D { .type =3D NLA_U8, }, - [MPTCP_PM_ADDR_ATTR_ADDR4] =3D { .type =3D NLA_U32, }, - [MPTCP_PM_ADDR_ATTR_ADDR6] =3D - NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)), - [MPTCP_PM_ADDR_ATTR_PORT] =3D { .type =3D NLA_U16 }, - [MPTCP_PM_ADDR_ATTR_FLAGS] =3D { .type =3D NLA_U32 }, - [MPTCP_PM_ADDR_ATTR_IF_IDX] =3D { .type =3D NLA_S32 }, -}; - -static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] =3D { - [MPTCP_PM_ATTR_ADDR] =3D - NLA_POLICY_NESTED(mptcp_pm_addr_policy), - [MPTCP_PM_ATTR_RCV_ADD_ADDRS] =3D { .type =3D NLA_U32, }, - [MPTCP_PM_ATTR_SUBFLOWS] =3D { .type =3D NLA_U32, }, - [MPTCP_PM_ATTR_TOKEN] =3D { .type =3D NLA_U32, }, - [MPTCP_PM_ATTR_LOC_ID] =3D { .type =3D NLA_U8, }, - [MPTCP_PM_ATTR_ADDR_REMOTE] =3D - NLA_POLICY_NESTED(mptcp_pm_addr_policy), -}; - void mptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct so= ck *ssk) { struct mptcp_subflow_context *iter, *subflow =3D mptcp_subflow_ctx(ssk); @@ -1188,7 +1219,7 @@ static int mptcp_pm_parse_pm_addr_attr(struct nlattr = *tb[], =20 /* no validation needed - was already done via nested policy */ err =3D nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr, - mptcp_pm_addr_policy, info->extack); + mptcp_pm_address_nl_policy, info->extack); if (err) return err; =20 @@ -1305,7 +1336,7 @@ static int mptcp_nl_add_subflow_or_signal_addr(struct= net *net) =20 static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *in= fo) { - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; + struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry addr, *entry; int ret; @@ -1486,7 +1517,7 @@ static int mptcp_nl_remove_id_zero_address(struct net= *net, =20 static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *in= fo) { - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; + struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry addr, *entry; unsigned int addr_max; @@ -1677,7 +1708,7 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb, =20 static int mptcp_nl_cmd_get_addr(struct sk_buff *skb, struct genl_info *in= fo) { - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; + struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry addr, *entry; struct sk_buff *msg; @@ -2283,72 +2314,104 @@ void mptcp_event(enum mptcp_event_type type, const= struct mptcp_sock *msk, nlmsg_free(skb); } =20 -static const struct genl_small_ops mptcp_pm_ops[] =3D { +static const struct genl_ops mptcp_pm_ops[] =3D { { - .cmd =3D MPTCP_PM_CMD_ADD_ADDR, - .doit =3D mptcp_nl_cmd_add_addr, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_ADD_ADDR, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_add_addr, + .policy =3D mptcp_pm_endpoint_nl_policy, + .maxattr =3D MPTCP_PM_ENDPOINT_ADDR, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_DEL_ADDR, - .doit =3D mptcp_nl_cmd_del_addr, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_DEL_ADDR, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_del_addr, + .policy =3D mptcp_pm_endpoint_nl_policy, + .maxattr =3D MPTCP_PM_ENDPOINT_ADDR, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_FLUSH_ADDRS, - .doit =3D mptcp_nl_cmd_flush_addrs, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_GET_ADDR, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_get_addr, + .dumpit =3D mptcp_nl_cmd_dump_addrs, + .policy =3D mptcp_pm_endpoint_nl_policy, + .maxattr =3D MPTCP_PM_ENDPOINT_ADDR, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_GET_ADDR, - .doit =3D mptcp_nl_cmd_get_addr, - .dumpit =3D mptcp_nl_cmd_dump_addrs, + .cmd =3D MPTCP_PM_CMD_FLUSH_ADDRS, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_flush_addrs, + .policy =3D mptcp_pm_endpoint_nl_policy, + .maxattr =3D MPTCP_PM_ENDPOINT_ADDR, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_SET_LIMITS, - .doit =3D mptcp_nl_cmd_set_limits, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_SET_LIMITS, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_set_limits, + .policy =3D mptcp_pm_set_limits_nl_policy, + .maxattr =3D MPTCP_PM_ATTR_SUBFLOWS, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_GET_LIMITS, - .doit =3D mptcp_nl_cmd_get_limits, + .cmd =3D MPTCP_PM_CMD_GET_LIMITS, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_get_limits, + .policy =3D mptcp_pm_set_limits_nl_policy, + .maxattr =3D MPTCP_PM_ATTR_SUBFLOWS, }, { - .cmd =3D MPTCP_PM_CMD_SET_FLAGS, - .doit =3D mptcp_nl_cmd_set_flags, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_SET_FLAGS, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_set_flags, + .policy =3D mptcp_pm_set_flags_nl_policy, + .maxattr =3D MPTCP_PM_ATTR_ADDR_REMOTE, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_ANNOUNCE, - .doit =3D mptcp_nl_cmd_announce, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_ANNOUNCE, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_announce, + .policy =3D mptcp_pm_announce_nl_policy, + .maxattr =3D MPTCP_PM_ATTR_TOKEN, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_REMOVE, - .doit =3D mptcp_nl_cmd_remove, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_REMOVE, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_remove, + .policy =3D mptcp_pm_remove_nl_policy, + .maxattr =3D MPTCP_PM_ATTR_LOC_ID, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_SUBFLOW_CREATE, - .doit =3D mptcp_nl_cmd_sf_create, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_SUBFLOW_CREATE, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_sf_create, + .policy =3D mptcp_pm_subflow_create_nl_policy, + .maxattr =3D MPTCP_PM_ATTR_ADDR_REMOTE, + .flags =3D GENL_UNS_ADMIN_PERM, }, { - .cmd =3D MPTCP_PM_CMD_SUBFLOW_DESTROY, - .doit =3D mptcp_nl_cmd_sf_destroy, - .flags =3D GENL_UNS_ADMIN_PERM, + .cmd =3D MPTCP_PM_CMD_SUBFLOW_DESTROY, + .validate =3D GENL_DONT_VALIDATE_STRICT, + .doit =3D mptcp_nl_cmd_sf_destroy, + .policy =3D mptcp_pm_subflow_create_nl_policy, + .maxattr =3D MPTCP_PM_ATTR_ADDR_REMOTE, + .flags =3D GENL_UNS_ADMIN_PERM, }, }; =20 static struct genl_family mptcp_genl_family __ro_after_init =3D { .name =3D MPTCP_PM_NAME, .version =3D MPTCP_PM_VER, - .maxattr =3D MPTCP_PM_ATTR_MAX, - .policy =3D mptcp_pm_policy, .netnsok =3D true, .module =3D THIS_MODULE, - .small_ops =3D mptcp_pm_ops, - .n_small_ops =3D ARRAY_SIZE(mptcp_pm_ops), + .ops =3D mptcp_pm_ops, + .n_ops =3D ARRAY_SIZE(mptcp_pm_ops), .resv_start_op =3D MPTCP_PM_CMD_SUBFLOW_DESTROY + 1, .mcgrps =3D mptcp_pm_mcgrps, .n_mcgrps =3D ARRAY_SIZE(mptcp_pm_mcgrps), --=20 2.40.1