[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1519162649-22449-2-git-send-email-serhe.popovych@gmail.com>
Date: Tue, 20 Feb 2018 23:37:23 +0200
From: Serhey Popovych <serhe.popovych@...il.com>
To: netdev@...r.kernel.org
Cc: dsahern@...il.com
Subject: [PATCH iproute2-next v2 1/7] utils: Introduce and use nodev() helper routine
There is a couple of places where we report error in case of no network
device is found. In all of them we output message in the same format to
stderr and either return -1 or 1 to the caller or exit with -1.
Introduce new helper function nodev() that takes name of the network
device caused error and returns -1 to it's caller. Either call exit()
or return to the caller to preserve behaviour before change.
Use -nodev() in traffic control (tc) code to return 1.
Simplify expression for checking for argument being 0/NULL in @if
statement.
Signed-off-by: Serhey Popovych <serhe.popovych@...il.com>
---
bridge/fdb.c | 17 ++++++-----------
bridge/link.c | 8 +++-----
bridge/mdb.c | 19 ++++++-------------
bridge/vlan.c | 7 ++-----
include/utils.h | 1 +
ip/ip6tunnel.c | 6 ++----
ip/ipaddress.c | 7 +++----
ip/iplink.c | 13 ++++---------
ip/iplink_bond.c | 4 ++--
ip/iplink_bridge.c | 7 ++-----
ip/iplink_vxlan.c | 7 ++-----
ip/ipmroute.c | 7 +++----
ip/ipneigh.c | 15 ++++++++-------
ip/ipntable.c | 6 ++----
ip/iproute.c | 36 ++++++++++++------------------------
ip/iproute_lwtunnel.c | 4 ++--
ip/iptunnel.c | 6 ++----
ip/link_gre.c | 7 ++-----
ip/link_gre6.c | 7 ++-----
ip/link_ip6tnl.c | 4 ++--
ip/link_iptnl.c | 4 ++--
ip/link_vti.c | 7 ++-----
ip/link_vti6.c | 7 ++-----
lib/utils.c | 6 ++++++
tc/m_mirred.c | 6 ++----
tc/tc_class.c | 14 ++++++--------
tc/tc_filter.c | 18 ++++++------------
tc/tc_qdisc.c | 12 ++++--------
28 files changed, 98 insertions(+), 164 deletions(-)
diff --git a/bridge/fdb.c b/bridge/fdb.c
index 8b133f9..2ba1cde 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -375,11 +375,8 @@ static int fdb_show(int argc, char **argv)
/*we'll keep around filter_dev for older kernels */
if (filter_dev) {
filter_index = ll_name_to_index(filter_dev);
- if (filter_index == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- filter_dev);
- return -1;
- }
+ if (!filter_index)
+ return nodev(filter_dev);
req.ifm.ifi_index = filter_index;
}
@@ -464,8 +461,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
} else if (strcmp(*argv, "via") == 0) {
NEXT_ARG();
via = ll_name_to_index(*argv);
- if (via == 0)
- invarg("invalid device\n", *argv);
+ if (!via)
+ exit(nodev(*argv));
} else if (strcmp(*argv, "self") == 0) {
req.ndm.ndm_flags |= NTF_SELF;
} else if (matches(*argv, "master") == 0) {
@@ -540,10 +537,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
addattr32(&req.n, sizeof(req), NDA_IFINDEX, via);
req.ndm.ndm_ifindex = ll_name_to_index(d);
- if (req.ndm.ndm_ifindex == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return -1;
- }
+ if (!req.ndm.ndm_ifindex)
+ return nodev(d);
if (rtnl_talk(&rth, &req.n, NULL) < 0)
return -1;
diff --git a/bridge/link.c b/bridge/link.c
index 90c9734..1ea9c00 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -470,11 +470,9 @@ static int brlink_show(int argc, char **argv)
}
if (filter_dev) {
- if ((filter_index = ll_name_to_index(filter_dev)) == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- filter_dev);
- return -1;
- }
+ filter_index = ll_name_to_index(filter_dev);
+ if (!filter_index)
+ return nodev(filter_dev);
}
if (show_details) {
diff --git a/bridge/mdb.c b/bridge/mdb.c
index 62dc8a0..e3f6978 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -312,11 +312,8 @@ static int mdb_show(int argc, char **argv)
if (filter_dev) {
filter_index = ll_name_to_index(filter_dev);
- if (filter_index == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- filter_dev);
- return -1;
- }
+ if (!filter_index)
+ return nodev(filter_dev);
}
/* get mdb entries*/
@@ -418,16 +415,12 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
}
req.bpm.ifindex = ll_name_to_index(d);
- if (req.bpm.ifindex == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return -1;
- }
+ if (!req.bpm.ifindex)
+ return nodev(d);
entry.ifindex = ll_name_to_index(p);
- if (entry.ifindex == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", p);
- return -1;
- }
+ if (!entry.ifindex)
+ return nodev(p);
if (!inet_pton(AF_INET, grp, &entry.addr.u.ip4)) {
if (!inet_pton(AF_INET6, grp, &entry.addr.u.ip6)) {
diff --git a/bridge/vlan.c b/bridge/vlan.c
index f42d7e6..3304348 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -568,11 +568,8 @@ static int vlan_show(int argc, char **argv)
if (filter_dev) {
filter_index = ll_name_to_index(filter_dev);
- if (filter_index == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- filter_dev);
- return -1;
- }
+ if (!filter_index)
+ return nodev(filter_dev);
}
if (!show_stats) {
diff --git a/include/utils.h b/include/utils.h
index 75ddb4a..50721f2 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -182,6 +182,7 @@ void missarg(const char *) __attribute__((noreturn));
void invarg(const char *, const char *) __attribute__((noreturn));
void duparg(const char *, const char *) __attribute__((noreturn));
void duparg2(const char *, const char *) __attribute__((noreturn));
+int nodev(const char *dev);
int check_ifname(const char *);
int get_ifname(char *, const char *);
const char *get_ifname_rta(int ifindex, const struct rtattr *rta);
diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
index c7fa082..999408e 100644
--- a/ip/ip6tunnel.c
+++ b/ip/ip6tunnel.c
@@ -296,10 +296,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
}
if (medium) {
p->link = ll_name_to_index(medium);
- if (p->link == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", medium);
- return -1;
- }
+ if (!p->link)
+ return nodev(medium);
}
return 0;
}
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 768e2ed..5cf13ef 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -2211,10 +2211,9 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
if (!scoped && cmd != RTM_DELADDR)
req.ifa.ifa_scope = default_scope(&lcl);
- if ((req.ifa.ifa_index = ll_name_to_index(d)) == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return -1;
- }
+ req.ifa.ifa_index = ll_name_to_index(d);
+ if (!req.ifa.ifa_index)
+ return nodev(d);
if (valid_lftp || preferred_lftp) {
struct ifa_cacheinfo cinfo = {};
diff --git a/ip/iplink.c b/ip/iplink.c
index 74c377c..5471626 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -981,10 +981,8 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
}
req.i.ifi_index = ll_name_to_index(dev);
- if (req.i.ifi_index == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", dev);
- return -1;
- }
+ if (!req.i.ifi_index)
+ return nodev(dev);
} else {
/* Allow "ip link add dev" and "ip link add name" */
if (!name)
@@ -994,11 +992,8 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
int ifindex;
ifindex = ll_name_to_index(link);
- if (ifindex == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- link);
- return -1;
- }
+ if (!ifindex)
+ return nodev(link);
addattr_l(&req.n, sizeof(req), IFLA_LINK, &ifindex, 4);
}
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 8e8723a..f906e7f 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -179,7 +179,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
if (!ifindex)
- return -1;
+ return nodev(*argv);
addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
} else if (matches(*argv, "clear_active_slave") == 0) {
addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);
@@ -242,7 +242,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
if (!ifindex)
- return -1;
+ return nodev(*argv);
addattr32(n, 1024, IFLA_BOND_PRIMARY, ifindex);
} else if (matches(*argv, "primary_reselect") == 0) {
NEXT_ARG();
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index 06ec092..3008e44 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -793,11 +793,8 @@ int bridge_parse_xstats(struct link_util *lu, int argc, char **argv)
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
filter_index = ll_name_to_index(*argv);
- if (filter_index == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- *argv);
- return -1;
- }
+ if (!filter_index)
+ return nodev(*argv);
} else if (strcmp(*argv, "help") == 0) {
bridge_print_xstats_help(lu, stdout);
exit(0);
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
index d768c07..be9f35e 100644
--- a/ip/iplink_vxlan.c
+++ b/ip/iplink_vxlan.c
@@ -133,11 +133,8 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
NEXT_ARG();
check_duparg(&attrs, IFLA_VXLAN_LINK, "dev", *argv);
link = ll_name_to_index(*argv);
- if (link == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- *argv);
- exit(-1);
- }
+ if (!link)
+ exit(nodev(*argv));
addattr32(n, 1024, IFLA_VXLAN_LINK, link);
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
diff --git a/ip/ipmroute.c b/ip/ipmroute.c
index aa5029b..5c232e8 100644
--- a/ip/ipmroute.c
+++ b/ip/ipmroute.c
@@ -244,10 +244,9 @@ static int mroute_list(int argc, char **argv)
if (id) {
int idx;
- if ((idx = ll_name_to_index(id)) == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", id);
- return -1;
- }
+ idx = ll_name_to_index(id);
+ if (!idx)
+ return nodev(id);
filter.iif = idx;
}
diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index 0735424..9c9cd23 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -178,11 +178,13 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
ll_init_map(&rth);
- if (dev && (req.ndm.ndm_ifindex = ll_name_to_index(dev)) == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", dev);
- return -1;
+ if (dev) {
+ req.ndm.ndm_ifindex = ll_name_to_index(dev);
+ if (!req.ndm.ndm_ifindex)
+ return nodev(dev);
}
+
if (rtnl_talk(&rth, &req.n, NULL) < 0)
exit(2);
@@ -423,10 +425,9 @@ static int do_show_or_flush(int argc, char **argv, int flush)
ll_init_map(&rth);
if (filter_dev) {
- if ((filter.index = ll_name_to_index(filter_dev)) == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", filter_dev);
- return -1;
- }
+ filter.index = ll_name_to_index(filter_dev);
+ if (!filter.index)
+ return nodev(filter_dev);
addattr32(&req.n, sizeof(req), NDA_IFINDEX, filter.index);
}
diff --git a/ip/ipntable.c b/ip/ipntable.c
index 2f72c98..fbbf232 100644
--- a/ip/ipntable.c
+++ b/ip/ipntable.c
@@ -139,10 +139,8 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv)
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
- if (ifindex == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", *argv);
- return -1;
- }
+ if (!ifindex)
+ return nodev(*argv);
rta_addattr32(parms_rta, sizeof(parms_buf),
NDTPA_IFINDEX, ifindex);
diff --git a/ip/iproute.c b/ip/iproute.c
index e4809a4..1d8fd81 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -973,10 +973,8 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
rtnh->rtnh_ifindex = ll_name_to_index(*argv);
- if (rtnh->rtnh_ifindex == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", *argv);
- return -1;
- }
+ if (!rtnh->rtnh_ifindex)
+ return nodev(*argv);
} else if (strcmp(*argv, "weight") == 0) {
unsigned int w;
@@ -1474,10 +1472,8 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
if (d) {
int idx = ll_name_to_index(d);
- if (idx == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return -1;
- }
+ if (!idx)
+ return nodev(d);
addattr32(&req.n, sizeof(req), RTA_OIF, idx);
}
@@ -1866,19 +1862,15 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if (id) {
idx = ll_name_to_index(id);
- if (idx == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", id);
- return -1;
- }
+ if (!idx)
+ return nodev(id);
filter.iif = idx;
filter.iifmask = -1;
}
if (od) {
idx = ll_name_to_index(od);
- if (idx == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", od);
- return -1;
- }
+ if (!idx)
+ return nodev(od);
filter.oif = idx;
filter.oifmask = -1;
}
@@ -2028,18 +2020,14 @@ static int iproute_get(int argc, char **argv)
if (idev) {
idx = ll_name_to_index(idev);
- if (idx == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", idev);
- return -1;
- }
+ if (!idx)
+ return nodev(idev);
addattr32(&req.n, sizeof(req), RTA_IIF, idx);
}
if (odev) {
idx = ll_name_to_index(odev);
- if (idx == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", odev);
- return -1;
- }
+ if (!idx)
+ return nodev(odev);
addattr32(&req.n, sizeof(req), RTA_OIF, idx);
}
}
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index fa3feae..cde9b3d 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -594,7 +594,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
duparg2("iif", *argv);
iif = ll_name_to_index(*argv);
if (!iif)
- invarg("\"iif\" interface not found\n", *argv);
+ exit(nodev(*argv));
rta_addattr32(rta, len, SEG6_LOCAL_IIF, iif);
} else if (strcmp(*argv, "oif") == 0) {
NEXT_ARG();
@@ -602,7 +602,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp,
duparg2("oif", *argv);
oif = ll_name_to_index(*argv);
if (!oif)
- invarg("\"oif\" interface not found\n", *argv);
+ exit(nodev(*argv));
rta_addattr32(rta, len, SEG6_LOCAL_OIF, oif);
} else if (strcmp(*argv, "srh") == 0) {
NEXT_ARG();
diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index 1f04f95..d597908 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -213,10 +213,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
if (medium) {
p->link = ll_name_to_index(medium);
- if (p->link == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", medium);
- return -1;
- }
+ if (!p->link)
+ return nodev(medium);
}
if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
diff --git a/ip/link_gre.c b/ip/link_gre.c
index 64588d7..bc1cee8 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -245,11 +245,8 @@ get_failed:
} else if (!matches(*argv, "dev")) {
NEXT_ARG();
link = ll_name_to_index(*argv);
- if (link == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- *argv);
- exit(-1);
- }
+ if (!link)
+ exit(nodev(*argv));
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit") ||
!matches(*argv, "hlim")) {
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index 6c77038..83c61e2 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -250,11 +250,8 @@ get_failed:
} else if (!matches(*argv, "dev")) {
NEXT_ARG();
link = ll_name_to_index(*argv);
- if (link == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- *argv);
- exit(-1);
- }
+ if (!link)
+ exit(nodev(*argv));
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit") ||
!matches(*argv, "hlim")) {
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index 77a9090..c7fef2e 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -197,8 +197,8 @@ get_failed:
} else if (matches(*argv, "dev") == 0) {
NEXT_ARG();
link = ll_name_to_index(*argv);
- if (link == 0)
- invarg("\"dev\" is invalid", *argv);
+ if (!link)
+ exit(nodev(*argv));
} else if (strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hoplimit") == 0 ||
strcmp(*argv, "hlim") == 0) {
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index acd9f45..57f4d0c 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -225,8 +225,8 @@ get_failed:
} else if (matches(*argv, "dev") == 0) {
NEXT_ARG();
link = ll_name_to_index(*argv);
- if (link == 0)
- invarg("\"dev\" is invalid", *argv);
+ if (!link)
+ exit(nodev(*argv));
} else if (strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hoplimit") == 0 ||
strcmp(*argv, "hlim") == 0) {
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 99e10e8..6196a1c 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -142,11 +142,8 @@ get_failed:
} else if (!matches(*argv, "dev")) {
NEXT_ARG();
link = ll_name_to_index(*argv);
- if (link == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- *argv);
- exit(-1);
- }
+ if (!link)
+ exit(nodev(*argv));
} else if (strcmp(*argv, "fwmark") == 0) {
NEXT_ARG();
if (get_u32(&fwmark, *argv, 0))
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index 1df6579..4263615 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -144,11 +144,8 @@ get_failed:
} else if (!matches(*argv, "dev")) {
NEXT_ARG();
link = ll_name_to_index(*argv);
- if (link == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n",
- *argv);
- exit(-1);
- }
+ if (!link)
+ exit(nodev(*argv));
} else if (strcmp(*argv, "fwmark") == 0) {
NEXT_ARG();
if (get_u32(&fwmark, *argv, 0))
diff --git a/lib/utils.c b/lib/utils.c
index 61af123..c0535a1 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -845,6 +845,12 @@ void duparg2(const char *key, const char *arg)
exit(-1);
}
+int nodev(const char *dev)
+{
+ fprintf(stderr, "Cannot find device \"%s\"\n", dev);
+ return -1;
+}
+
int check_ifname(const char *name)
{
/* These checks mimic kernel checks in dev_valid_name */
diff --git a/tc/m_mirred.c b/tc/m_mirred.c
index eb42b7c..b25b9ac 100644
--- a/tc/m_mirred.c
+++ b/tc/m_mirred.c
@@ -193,10 +193,8 @@ parse_direction(struct action_util *a, int *argc_p, char ***argv_p,
ll_init_map(&rth);
idx = ll_name_to_index(d);
- if (idx == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return -1;
- }
+ if (!idx)
+ return nodev(d);
p.ifindex = idx;
}
diff --git a/tc/tc_class.c b/tc/tc_class.c
index 1b214b8..e1ca29c 100644
--- a/tc/tc_class.c
+++ b/tc/tc_class.c
@@ -142,10 +142,9 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
if (d[0]) {
ll_init_map(&rth);
- if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return 1;
- }
+ req.t.tcm_ifindex = ll_name_to_index(d);
+ if (!req.t.tcm_ifindex)
+ return -nodev(d);
}
if (rtnl_talk(&rth, &req.n, NULL) < 0)
@@ -440,10 +439,9 @@ static int tc_class_list(int argc, char **argv)
ll_init_map(&rth);
if (d[0]) {
- if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return 1;
- }
+ t.tcm_ifindex = ll_name_to_index(d);
+ if (!t.tcm_ifindex)
+ return -nodev(d);
filter_ifindex = t.tcm_ifindex;
}
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index 5c31a4c..f2313cd 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -198,10 +198,8 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv,
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 (!req->t.tcm_ifindex)
+ return -nodev(d);
} else if (block_index) {
req->t.tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
req->t.tcm_block_index = block_index;
@@ -530,10 +528,8 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)
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 (!req.t.tcm_ifindex)
+ return -nodev(d);
filter_ifindex = req.t.tcm_ifindex;
} else if (block_index) {
req.t.tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
@@ -696,10 +692,8 @@ static int tc_filter_list(int argc, char **argv)
if (d[0]) {
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 (!req.t.tcm_ifindex)
+ return -nodev(d);
filter_ifindex = req.t.tcm_ifindex;
} else if (block_index) {
if (!tc_qdisc_block_exists(block_index)) {
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index 2fcf04c..e9a95a4 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -199,10 +199,8 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
ll_init_map(&rth);
idx = ll_name_to_index(d);
- if (idx == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return 1;
- }
+ if (!idx)
+ return -nodev(d);
req.t.tcm_ifindex = idx;
}
@@ -379,10 +377,8 @@ static int tc_qdisc_list(int argc, char **argv)
if (d[0]) {
t.tcm_ifindex = ll_name_to_index(d);
- if (t.tcm_ifindex == 0) {
- fprintf(stderr, "Cannot find device \"%s\"\n", d);
- return 1;
- }
+ if (!t.tcm_ifindex)
+ return -nodev(d);
filter_ifindex = t.tcm_ifindex;
}
--
1.7.10.4
Powered by blists - more mailing lists