From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Kicinski Subject: [PATCH iproute2/master 09/11] tc_filter: resolve device name before parsing filter Date: Thu, 23 Nov 2017 18:12:06 -0800 Message-ID: <20171124021208.13419-10-jakub.kicinski@netronome.com> References: <20171124021208.13419-1-jakub.kicinski@netronome.com> Cc: oss-drivers@netronome.com, daniel@iogearbox.net, Jakub Kicinski To: netdev@vger.kernel.org Return-path: Received: from mail-pl0-f68.google.com ([209.85.160.68]:38992 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752318AbdKXCM0 (ORCPT ); Thu, 23 Nov 2017 21:12:26 -0500 Received: by mail-pl0-f68.google.com with SMTP id l16so3564759pli.6 for ; Thu, 23 Nov 2017 18:12:25 -0800 (PST) In-Reply-To: <20171124021208.13419-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org List-ID: Move resolving device name into an ifindex before calling filter specific callbacks. This way if filters need the ifindex, they can read it from the request. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Daniel Borkmann --- tc/tc_filter.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/tc/tc_filter.c b/tc/tc_filter.c index d0c967a9633a..0a3f7e696af8 100644 --- a/tc/tc_filter.c +++ b/tc/tc_filter.c @@ -160,6 +160,16 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv) if (k[0]) addattr_l(&req.n, sizeof(req), TCA_KIND, k, strlen(k)+1); + if (d[0]) { + ll_init_map(&rth); + + req.t.tcm_ifindex = ll_name_to_index(d); + if (req.t.tcm_ifindex == 0) { + fprintf(stderr, "Cannot find device \"%s\"\n", d); + return 1; + } + } + if (q) { if (q->parse_fopt(q, fhandle, argc, argv, &req.n)) return 1; @@ -182,17 +192,6 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv) if (est.ewma_log) addattr_l(&req.n, sizeof(req), TCA_RATE, &est, sizeof(est)); - - if (d[0]) { - ll_init_map(&rth); - - req.t.tcm_ifindex = ll_name_to_index(d); - if (req.t.tcm_ifindex == 0) { - fprintf(stderr, "Cannot find device \"%s\"\n", d); - return 1; - } - } - if (rtnl_talk(&rth, &req.n, NULL) < 0) { fprintf(stderr, "We have an error talking to the kernel\n"); return 2; @@ -452,10 +451,23 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) return -1; } + if (d[0]) { + ll_init_map(&rth); + + req.t.tcm_ifindex = ll_name_to_index(d); + if (req.t.tcm_ifindex == 0) { + fprintf(stderr, "Cannot find device \"%s\"\n", d); + return 1; + } + filter_ifindex = req.t.tcm_ifindex; + } else { + fprintf(stderr, "Must specify netdevice \"dev\"\n"); + return -1; + } + if (q->parse_fopt(q, fhandle, argc, argv, &req.n)) return 1; - if (!fhandle) { fprintf(stderr, "Must specify filter \"handle\"\n"); return -1; @@ -470,20 +482,6 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) return -1; } - if (d[0]) { - ll_init_map(&rth); - - req.t.tcm_ifindex = ll_name_to_index(d); - if (req.t.tcm_ifindex == 0) { - fprintf(stderr, "Cannot find device \"%s\"\n", d); - return 1; - } - filter_ifindex = req.t.tcm_ifindex; - } else { - fprintf(stderr, "Must specify netdevice \"dev\"\n"); - return -1; - } - if (rtnl_talk(&rth, &req.n, &answer) < 0) { fprintf(stderr, "We have an error talking to the kernel\n"); return 2; -- 2.14.1