Skip to contentSkip to conversation

tc: mirred target: do not report non-existing devices

PATCH In review Dan Kenigsberg 4 participants 5 messages Aug 30, 2012 – Sep 4, 2012 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tc: mirred target: do not report non-existing devices

Currently, if a mirred target device is removed, tc filter show does not reveal the fact. Instead, it replaces the original name of the device with the default output of ll_map:ll_idx_n2a().

This is unfortunate, since one cannot differ between this case and a valid mirroring target device named 'if17'.

It seems that the original code meant to report an error message in this case, but it does not, since ll_index_to_name() never returns 0. I would not like to bail out in case of an error, since the user would still be interested to know what are the other details of the action.

---
 lib/ll_map.c  |   13 +++++++++++++
 tc/m_mirred.c |   10 ++++------
 2 files changed, 17 insertions(+), 6 deletions(-)
lib/ll_map.c +13 -0
index 1ca781e..8ceef41 100644
@@ -108,6 +108,19 @@ const char *ll_idx_n2a(unsigned idx, char *buf)
 	return buf;
 }
 
+char *ll_index_exists(unsigned idx)
+{
+	const struct ll_cache *im;
+
+	if (idx == 0)
+		return 0;
+
+	for (im = idxhead(idx); im; im = im->idx_next)
+		if (im->index == idx)
+			return 1;
+
+	return 0;
+}
 
 const char *ll_index_to_name(unsigned idx)
 {
tc/m_mirred.c +4 -6
index 0d771bc..eba1240 100644
@@ -268,13 +268,11 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
 	ll_init_map(&rth);
 	*/
 
+	dev = ll_index_to_name(p->ifindex);
 
-	if ((dev = ll_index_to_name(p->ifindex)) == 0) {
-		fprintf(stderr, "Cannot find device %d\n", p->ifindex);
-		return -1;
-	}
-
-	fprintf(f, "mirred (%s to device %s) %s", mirred_n2a(p->eaction), dev,action_n2a(p->action, b1, sizeof (b1)));
+	fprintf(f, "mirred (%s to %sdevice %s) %s", mirred_n2a(p->eaction),
+                ll_index_exists(p->ifindex) ? "" : "missing-",
+                dev, action_n2a(p->action, b1, sizeof (b1)));
 
 	fprintf(f, "\n ");
 	fprintf(f, "\tindex %d ref %d bind %d",p->index,p->refcnt,p->bindcnt);
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 30 lines · Dan Kenigsberg

Currently, if a mirred target device is removed, tc filter show does not reveal the fact. Instead, it replaces the original name of the device with the default output of ll_map:ll_idx_n2a().

This is unfortunate, since one cannot differ between this case and a valid mirroring target device named 'if17'.

It seems that the original code meant to report an error message in this case, but it does not, since ll_index_to_name() never returns 0. I would not like to bail out in case of an error, since the user would still be interested to know what are the other details of the action.

---
 lib/ll_map.c  |   13 +++++++++++++
 tc/m_mirred.c |   10 ++++------
 2 files changed, 17 insertions(+), 6 deletions(-)
lib/ll_map.c +4 -0
index 1ca781e..8ceef41 100644
@@ -108,6 +108,19 @@ const char *ll_idx_n2a(unsigned idx, char *buf)
 	return buf;
 }
 
+char *ll_index_exists(unsigned idx)
+{
+	const struct ll_cache *im;
+

lib/ll_map.c const char *ll_idx_n2a(unsigned idx, char *buf) · line 124

Quoted 10 lines
lib/ll_map.c +9 -0
+	if (idx == 0)
+		return 0;
+
+	for (im = idxhead(idx); im; im = im->idx_next)
+		if (im->index == idx)
+			return 1;
+
+	return 0;
+}
 

I am curious to know what compiler accepted this.

return type should be a "int", not a "char *"

Quoted 14 lines
lib/ll_map.c +0 -0
 const char *ll_index_to_name(unsigned idx)
 {
tc/m_mirred.c +1 -2
index 0d771bc..eba1240 100644
@@ -268,13 +268,11 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
 	ll_init_map(&rth);
 	*/
 
+	dev = ll_index_to_name(p->ifindex);
 
-	if ((dev = ll_index_to_name(p->ifindex)) == 0) {
-		fprintf(stderr, "Cannot find device %d\n", p->ifindex);

tc/m_mirred.c print_mirred(struct action_util *au,FILE * f, struct rtattr *arg) · line 278

Quoted 10 lines
tc/m_mirred.c +3 -4
-		return -1;
-	}
-
-	fprintf(f, "mirred (%s to device %s) %s", mirred_n2a(p->eaction), dev,action_n2a(p->action, b1, sizeof (b1)));
+	fprintf(f, "mirred (%s to %sdevice %s) %s", mirred_n2a(p->eaction),
+                ll_index_exists(p->ifindex) ? "" : "missing-",
+                dev, action_n2a(p->action, b1, sizeof (b1)));
 
 	fprintf(f, "\n ");
 	fprintf(f, "\tindex %d ref %d bind %d",p->index,p->refcnt,p->bindcnt);

How this can compile without triggering a warning, as the ll_index_exists() is not in an include file ?

#2 lore raw
Quoted 27 lines · Eric Dumazet
Quoted 26 lines · Dan Kenigsberg

Currently, if a mirred target device is removed, tc filter show does not reveal the fact. Instead, it replaces the original name of the device with the default output of ll_map:ll_idx_n2a().

This is unfortunate, since one cannot differ between this case and a valid mirroring target device named 'if17'.

It seems that the original code meant to report an error message in this case, but it does not, since ll_index_to_name() never returns 0. I would not like to bail out in case of an error, since the user would still be interested to know what are the other details of the action.

---
 lib/ll_map.c  |   13 +++++++++++++
 tc/m_mirred.c |   10 ++++------
 2 files changed, 17 insertions(+), 6 deletions(-)
lib/ll_map.c +0 -0
index 1ca781e..8ceef41 100644
@@ -108,6 +108,19 @@ const char *ll_idx_n2a(unsigned idx, char *buf)
 	return buf;
 }
 
Quoted 16 lines
Quoted 4 lines
lib/ll_map.c +4 -0
+char *ll_index_exists(unsigned idx)
+{
+	const struct ll_cache *im;
+

lib/ll_map.c const char *ll_idx_n2a(unsigned idx, char *buf) · line 124

Quoted 10 lines
lib/ll_map.c +9 -0
+	if (idx == 0)
+		return 0;
+
+	for (im = idxhead(idx); im; im = im->idx_next)
+		if (im->index == idx)
+			return 1;
+
+	return 0;
+}
 

I am curious to know what compiler accepted this.

It was gcc. gcc 2> /dev/null || :, to be exact.

Sorry, fixed patch follows.

#3 lore raw

PATCH v2 1/1 tc: mirred target: do not report non-existing devices

From: Dan Kenigsberg <[email protected]>

Currently, if a mirred target device is removed, tc filter show does not reveal the fact. Instead, it replaces the original name of the device with the default output of ll_map:ll_idx_n2a().

This is unfortunate, since one cannot differ between this case and a valid mirroring target device named 'if17'.

It seems that the original code meant to report an error message in this case, but it does not, since ll_index_to_name() never returns 0. I would not like to bail out in case of an error, since the user would still be interested to know what are the other details of the action.

v2: properly declare the new function ll_index_exsits()

---
 include/ll_map.h |    1 +
 lib/ll_map.c     |   13 +++++++++++++
 tc/m_mirred.c    |   10 ++++------
 3 files changed, 18 insertions(+), 6 deletions(-)
include/ll_map.h +1 -0
index 752b827..16509af 100644
@@ -6,6 +6,7 @@ extern int ll_remember_index(const struct sockaddr_nl *who,
 extern int ll_init_map(struct rtnl_handle *rth);
 extern unsigned ll_name_to_index(const char *name);
 extern const char *ll_index_to_name(unsigned idx);
+extern int ll_index_exists(unsigned idx);
 extern const char *ll_idx_n2a(unsigned idx, char *buf);
 extern int ll_index_to_type(unsigned idx);
 extern unsigned ll_index_to_flags(unsigned idx);
lib/ll_map.c +13 -0
index 1ca781e..d6f1339 100644
@@ -108,6 +108,19 @@ const char *ll_idx_n2a(unsigned idx, char *buf)
 	return buf;
 }
 
+int ll_index_exists(unsigned idx)
+{
+	const struct ll_cache *im;
+
+	if (idx == 0)
+		return 0;
+
+	for (im = idxhead(idx); im; im = im->idx_next)
+		if (im->index == idx)
+			return 1;
+
+	return 0;
+}
 
 const char *ll_index_to_name(unsigned idx)
 {
tc/m_mirred.c +4 -6
index 0d771bc..eba1240 100644
@@ -268,13 +268,11 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
 	ll_init_map(&rth);
 	*/
 
+	dev = ll_index_to_name(p->ifindex);
 
-	if ((dev = ll_index_to_name(p->ifindex)) == 0) {
-		fprintf(stderr, "Cannot find device %d\n", p->ifindex);
-		return -1;
-	}
-
-	fprintf(f, "mirred (%s to device %s) %s", mirred_n2a(p->eaction), dev,action_n2a(p->action, b1, sizeof (b1)));
+	fprintf(f, "mirred (%s to %sdevice %s) %s", mirred_n2a(p->eaction),
+                ll_index_exists(p->ifindex) ? "" : "missing-",
+                dev, action_n2a(p->action, b1, sizeof (b1)));
 
 	fprintf(f, "\n ");
 	fprintf(f, "\tindex %d ref %d bind %d",p->index,p->refcnt,p->bindcnt);
Signature · 1 line
1.7.7.6

A message that is not in the archive (sent off-list or not yet received): 1346582882-14568-1-git-send-email-y

#5 lore raw
Quoted 9 lines · On Sun, 2 Sep 2012 13:48:02 +0300 [email protected] wrote:

From: Dan Kenigsberg <[email protected]>

Currently, if a mirred target device is removed, tc filter show does not reveal the fact. Instead, it replaces the original name of the device with the default output of ll_map:ll_idx_n2a().

This is unfortunate, since one cannot differ between this case and a valid mirroring target device named 'if17'.

Quoted 6 lines

It seems that the original code meant to report an error message in this case, but it does not, since ll_index_to_name() never returns 0. I would not like to bail out in case of an error, since the user would still be interested to know what are the other details of the action.

v2: properly declare the new function ll_index_exsits()

I am okay with the concept but "missing-if1" is still a possible but unlikely name for a device. Maybe better to use something more obvious like [unknown-1] or UNKNOWN?