]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc_filter: resolve device name before parsing filter
authorJakub Kicinski <jakub.kicinski@netronome.com>
Fri, 24 Nov 2017 02:12:06 +0000 (18:12 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Sun, 26 Nov 2017 19:57:57 +0000 (11:57 -0800)
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 <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
tc/tc_filter.c

index 276a66cb0b4d47751f15a980f607cec5ba85a00e..73f1781626fdff4e3365e5ea3a45afa1254b1174 100644 (file)
@@ -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;