Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp482564pxb; Tue, 3 Nov 2020 04:59:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHWR3gnqpwb3ZOSwRMVqXfNHJ0Z2oyS+bDgIVlsZqUJaqmmQgbrfWGkziaNpFOyy3rGMeH X-Received: by 2002:a05:6402:31b6:: with SMTP id dj22mr6260648edb.348.1604408381863; Tue, 03 Nov 2020 04:59:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604408381; cv=none; d=google.com; s=arc-20160816; b=c9Ixl4IsKgFXq8+2n5NhsFPfUhvoqtxZnXxR4CebFLLBlwI/zJxxI9tL4KpR4Jc61N UmkWTpfj32nofWqMZ50XlX7v1d8B+YX1aizuHkqMrQl3j/InlgpPw/3CcrYKS92bCYSR X/MHqj7u+ZF4sEuSqCcniow+7rOWWQc7RrWiTHeZATOFSF1i18P1LCVdU4cFEKlCfLEM gnXwJzmZS1gn3zYqfr7aI8KfzUfgp58FyMRvQ34joCNvgejZkHDVfNiZiWsthc9YtXzU 4Rgsfg/6XnWeYNkXr0uzYsPr5CXJzUO5itYU0jzBOqVxE+vKuWoxAwFa7xQ9fwp2Adn0 A9Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Igt7jiSDZTxLjA6R85jXskGAy2HCabJcS42DMbEYjqU=; b=nhBbL9lHQZuRFLdEr69y+5GqykbW51NB4iROYyWdRLkGC1mEps+mX4Pe/SVxFKaiHM rR5tfzwl83E6m5NWqxKA6DOAzjS55qANayOkTkv/5O5PcSTzEQSD4Y1YRxcKWJDZS887 DoKskB5plaIXpH8tIJO39Ry61xG92xI++ApghGk+Lq/vXECKbSxdDhT63dwSFZZXLp7e jOMponLTvFVZ4RsGDwNU7mhX8UB/jwvtXuHhTfNzzQ0aJqHxeKVRovEmThr7uzoGRZgc 1vRgSir15Uo3kD1FN4s/JdfJMYunV31RThZ4AIGh0GNA5Cu1KRXY9dU9RjAEdrLD+eVI 5LnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uniroma2.it Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pw3si9137067ejb.666.2020.11.03.04.59.17; Tue, 03 Nov 2020 04:59:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uniroma2.it Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729032AbgKCMyD (ORCPT + 99 others); Tue, 3 Nov 2020 07:54:03 -0500 Received: from smtp.uniroma2.it ([160.80.6.22]:46050 "EHLO smtp.uniroma2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbgKCMyC (ORCPT ); Tue, 3 Nov 2020 07:54:02 -0500 Received: from localhost.localdomain ([160.80.103.126]) by smtp-2015.uniroma2.it (8.14.4/8.14.4/Debian-8) with ESMTP id 0A3CquXp020392 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 3 Nov 2020 13:52:59 +0100 From: Andrea Mayer To: "David S. Miller" , David Ahern , Alexey Kuznetsov , Hideaki YOSHIFUJI , Jakub Kicinski , Shuah Khan , Shrijeet Mukherjee , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Stefano Salsano , Paolo Lungaroni , Ahmed Abdelsalam , Andrea Mayer Subject: [net-next,v1,3/5] seg6: add callbacks for customizing the creation/destruction of a behavior Date: Tue, 3 Nov 2020 13:52:40 +0100 Message-Id: <20201103125242.11468-4-andrea.mayer@uniroma2.it> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201103125242.11468-1-andrea.mayer@uniroma2.it> References: <20201103125242.11468-1-andrea.mayer@uniroma2.it> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.100.0 at smtp-2015 X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We introduce two callbacks used for customizing the creation/destruction of a SRv6 behavior. Such callbacks are defined in the new struct seg6_local_lwtunnel_ops and hereafter we provide a brief description of them: - build_state(...): used for calling the custom constructor of the behavior during its initialization phase and after all the attributes have been parsed successfully; - destroy_state(...): used for calling the custom destructor of the behavior before it is completely destroyed. Signed-off-by: Andrea Mayer --- net/ipv6/seg6_local.c | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index 63a82e2fdea9..4b0f155d641d 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -33,11 +33,23 @@ struct seg6_local_lwt; +typedef int (*slwt_build_state_t)(struct seg6_local_lwt *slwt, const void *cfg, + struct netlink_ext_ack *extack); +typedef void (*slwt_destroy_state_t)(struct seg6_local_lwt *slwt); + +/* callbacks used for customizing the creation and destruction of a behavior */ +struct seg6_local_lwtunnel_ops { + slwt_build_state_t build_state; + slwt_destroy_state_t destroy_state; +}; + struct seg6_action_desc { int action; unsigned long attrs; int (*input)(struct sk_buff *skb, struct seg6_local_lwt *slwt); int static_headroom; + + struct seg6_local_lwtunnel_ops slwt_ops; }; struct bpf_lwt_prog { @@ -1015,6 +1027,45 @@ static void destroy_attrs(struct seg6_local_lwt *slwt) __destroy_attrs(attrs, 0, SEG6_LOCAL_MAX + 1, slwt); } +/* call the custom constructor of the behavior during its initialization phase + * and after that all its attributes have been parsed successfully. + */ +static int +seg6_local_lwtunnel_build_state(struct seg6_local_lwt *slwt, const void *cfg, + struct netlink_ext_ack *extack) +{ + slwt_build_state_t build_func; + struct seg6_action_desc *desc; + int err = 0; + + desc = slwt->desc; + if (!desc) + return -EINVAL; + + build_func = desc->slwt_ops.build_state; + if (build_func) + err = build_func(slwt, cfg, extack); + + return err; +} + +/* call the custom destructor of the behavior which is invoked before the + * tunnel is going to be destroyed. + */ +static void seg6_local_lwtunnel_destroy_state(struct seg6_local_lwt *slwt) +{ + slwt_destroy_state_t destroy_func; + struct seg6_action_desc *desc; + + desc = slwt->desc; + if (!desc) + return; + + destroy_func = desc->slwt_ops.destroy_state; + if (destroy_func) + destroy_func(slwt); +} + static int parse_nla_action(struct nlattr **attrs, struct seg6_local_lwt *slwt) { struct seg6_action_param *param; @@ -1090,8 +1141,16 @@ static int seg6_local_build_state(struct net *net, struct nlattr *nla, err = parse_nla_action(tb, slwt); if (err < 0) + /* In case of error, the parse_nla_action() takes care of + * releasing resources which have been acquired during the + * processing of attributes. + */ goto out_free; + err = seg6_local_lwtunnel_build_state(slwt, cfg, extack); + if (err < 0) + goto free_attrs; + newts->type = LWTUNNEL_ENCAP_SEG6_LOCAL; newts->flags = LWTUNNEL_STATE_INPUT_REDIRECT; newts->headroom = slwt->headroom; @@ -1100,6 +1159,9 @@ static int seg6_local_build_state(struct net *net, struct nlattr *nla, return 0; +free_attrs: + destroy_attrs(slwt); + out_free: kfree(newts); return err; @@ -1109,6 +1171,8 @@ static void seg6_local_destroy_state(struct lwtunnel_state *lwt) { struct seg6_local_lwt *slwt = seg6_local_lwtunnel(lwt); + seg6_local_lwtunnel_destroy_state(slwt); + destroy_attrs(slwt); return; -- 2.20.1