Skip to contentSkip to conversation

tc class names: Ignore if default file does not exist

PATCH Superseded Vadim Kochan 3 participants 7 messages Mar 17, 2015

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover tc class names: Ignore if default file does not exist

1) Split lib/names.c:db_names_alloc to 2 funcs for allocate and load names from file. Also added checking for malloc failing.

2) Ignore if default class names file does not exist if '-nm' option was specified, so it will be possible to create alias:

alias tc='tc -nm'

Changed default class name file cls_names -> tc_cls.

Vadim Kochan (2):
lib names: Split to db_names_alloc and db_names_load tc class: Ignore if default class name file does not exist

 include/names.h |  3 ++-
 lib/names.c     | 59 +++++++++++++++++++++++++++++++++++++++++----------------
 tc/tc_util.c    | 19 +++++++++++++++----
 3 files changed, 60 insertions(+), 21 deletions(-)
Signature · 1 line
2.3.1
#1 lore raw

PATCH 1/2 lib names: Split to db_names_alloc and db_names_load

From: Vadim Kochan <[email protected]>

Also added checking for malloc failing

---
 include/names.h |  3 ++-
 lib/names.c     | 59 +++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 45 insertions(+), 17 deletions(-)
include/names.h +2 -1
index 4123d0b..6fed581 100644
@@ -16,7 +16,8 @@ struct db_names {
 	int max;
 };
 
-struct db_names *db_names_alloc(const char *path);
+struct db_names *db_names_alloc(void);
+int db_names_load(struct db_names *db, const char *path);
 void db_names_free(struct db_names *db);
 
 char *id_to_name(struct db_names *db, int id, char *name);
lib/names.c +43 -16

119 lines not on this page · raw message

Signature · 1 line
2.3.1
#2 lore raw

PATCH 2/2 tc class: Ignore if default class name file does not exist

In reply to Vadim Kochan

From: Vadim Kochan <[email protected]>

If '-nm' specified then do not fail if there is no default class names file in /etc/iproute2.

Changed default class name file cls_names -> tc_cls.

---
 tc/tc_util.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
tc/tc_util.c +15 -4
index feae439..5213e9e 100644
@@ -21,6 +21,7 @@
 #include <arpa/inet.h>
 #include <string.h>
 #include <math.h>
+#include <errno.h>
 
 #include "utils.h"
 #include "names.h"
@@ -33,15 +34,25 @@
 
 static struct db_names *cls_names = NULL;
 
-#define NAMES_DB "/etc/iproute2/cls_names"
+#define NAMES_DB "/etc/iproute2/tc_cls"
 
 int cls_names_init(char *path)
 {
-	cls_names = db_names_alloc(path ?: NAMES_DB);
-	if (!cls_names) {
-		fprintf(stderr, "Error while opening class names file\n");
+	int ret = -1;
+
+	cls_names = db_names_alloc();
+	if (!cls_names)
+		return -1;
+
+	ret = db_names_load(cls_names, path ?: NAMES_DB);
+	if (ret == -ENOENT && path) {
+		fprintf(stderr, "Can't open class names file: %s\n", path);
 		return -1;
 	}
+	if (ret) {
+		db_names_free(cls_names);
+		cls_names = NULL;
+	}
 
 	return 0;
 }
Signature · 1 line
2.3.1
#3 lore raw

Re: [PATCH iproute2 2/2] tc class: Ignore if default class name file does not exist

On 03/17/2015 05:52 PM, Vadim Kochan wrote:
...

Quoted 1 line

Changed default class name file cls_names -> tc_cls.

Why that?

Quoted 9 lines
---
  tc/tc_util.c | 19 +++++++++++++++----
  1 file changed, 15 insertions(+), 4 deletions(-)
tc/tc_util.c +0 -0
index feae439..5213e9e 100644

...

Quoted 9 lines
  static struct db_names *cls_names = NULL;
tc/tc_util.c +1 -3
-#define NAMES_DB "/etc/iproute2/cls_names"
+#define NAMES_DB "/etc/iproute2/tc_cls"
 
  int cls_names_init(char *path)
  {
-	cls_names = db_names_alloc(path ?: NAMES_DB);
-	if (!cls_names) {

tc/tc_util.c line 49

Quoted 10 lines
tc/tc_util.c +9 -1
-		fprintf(stderr, "Error while opening class names file\n");
+	int ret = -1;
+
+	cls_names = db_names_alloc();
+	if (!cls_names)
+		return -1;
+
+	ret = db_names_load(cls_names, path ?: NAMES_DB);
+	if (ret == -ENOENT && path) {
+		fprintf(stderr, "Can't open class names file: %s\n", path);

That would mean that existing users having a /etc/iproute2/cls_names file would suddenly not see class names anymore?

#4 lore raw

Re: [PATCH iproute2 2/2] tc class: Ignore if default class name file does not exist

Quoted 6 lines · Daniel Borkmann

On 03/17/2015 05:52 PM, Vadim Kochan wrote:
...

Quoted 1 line

Changed default class name file cls_names -> tc_cls.

Why that?

tc_cls seems better and shorter.

Quoted 24 lines
Quoted 9 lines
---
 tc/tc_util.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
tc/tc_util.c +0 -0
index feae439..5213e9e 100644

...

Quoted 14 lines

static struct db_names *cls_names = NULL;

tc/tc_util.c +5 -4
-#define NAMES_DB "/etc/iproute2/cls_names"
+#define NAMES_DB "/etc/iproute2/tc_cls"
 
 int cls_names_init(char *path)
 {
-	cls_names = db_names_alloc(path ?: NAMES_DB);
-	if (!cls_names) {
-		fprintf(stderr, "Error while opening class names file\n");
+	int ret = -1;
+
+	cls_names = db_names_alloc();
+	if (!cls_names)
Quoted 8 lines

tc/tc_util.c line 49

Quoted 5 lines
tc/tc_util.c +5 -0
+		return -1;
+
+	ret = db_names_load(cls_names, path ?: NAMES_DB);
+	if (ret == -ENOENT && path) {
+		fprintf(stderr, "Can't open class names file: %s\n", path);

That would mean that existing users having a /etc/iproute2/cls_names file would suddenly not see class names anymore?

Hm, but that was added few days ago.

#5 lore raw

Re: [PATCH iproute2 2/2] tc class: Ignore if default class name file does not exist

Quoted 42 lines · Vadim Kochan
Quoted 5 lines · Daniel Borkmann

On 03/17/2015 05:52 PM, Vadim Kochan wrote:
...

Quoted 1 line

Changed default class name file cls_names -> tc_cls.

Why that?

tc_cls seems better and shorter.

Quoted 24 lines
Quoted 9 lines
---
  tc/tc_util.c | 19 +++++++++++++++----
  1 file changed, 15 insertions(+), 4 deletions(-)
tc/tc_util.c +0 -0
index feae439..5213e9e 100644

...

Quoted 14 lines
  static struct db_names *cls_names = NULL;
tc/tc_util.c +5 -4
-#define NAMES_DB "/etc/iproute2/cls_names"
+#define NAMES_DB "/etc/iproute2/tc_cls"
 
  int cls_names_init(char *path)
  {
-	cls_names = db_names_alloc(path ?: NAMES_DB);
-	if (!cls_names) {
-		fprintf(stderr, "Error while opening class names file\n");
+	int ret = -1;
+
+	cls_names = db_names_alloc();
+	if (!cls_names)
Quoted 8 lines

tc/tc_util.c line 49

Quoted 5 lines
tc/tc_util.c +5 -0
+		return -1;
+
+	ret = db_names_load(cls_names, path ?: NAMES_DB);
+	if (ret == -ENOENT && path) {
+		fprintf(stderr, "Can't open class names file: %s\n", path);

That would mean that existing users having a /etc/iproute2/cls_names file would suddenly not see class names anymore?

Quoted 1 line

Hm, but that was added few days ago.

Ok, my bad, sorry for the noise.

#6 lore raw

Re: [PATCH iproute2 2/2] tc class: Ignore if default class name file does not exist

In reply to Vadim Kochan

Hello.

Quoted 16 lines · Vadim Kochan

From: Vadim Kochan <[email protected]>

If '-nm' specified then do not fail if there is no default class names file in /etc/iproute2.

Changed default class name file cls_names -> tc_cls.

---
  tc/tc_util.c | 19 +++++++++++++++----
  1 file changed, 15 insertions(+), 4 deletions(-)
tc/tc_util.c +0 -0
index feae439..5213e9e 100644

[...]

tc/tc_util.c line 41

Quoted 13 lines
tc/tc_util.c +2 -4
@@ -33,15 +34,25 @@
 
  static struct db_names *cls_names = NULL;
 
-#define NAMES_DB "/etc/iproute2/cls_names"
+#define NAMES_DB "/etc/iproute2/tc_cls"
 
  int cls_names_init(char *path)
  {
-	cls_names = db_names_alloc(path ?: NAMES_DB);
-	if (!cls_names) {
-		fprintf(stderr, "Error while opening class names file\n");
+	int ret = -1;

Pointless initializer.

Quoted 7 lines
tc/tc_util.c +7 -0
+
+	cls_names = db_names_alloc();
+	if (!cls_names)
+		return -1;
+
+	ret = db_names_load(cls_names, path ?: NAMES_DB);
+	if (ret == -ENOENT && path) {

tc/tc_util.c line 58

Quoted 10 lines
tc/tc_util.c +5 -0
+		fprintf(stderr, "Can't open class names file: %s\n", path);
  		return -1;
  	}
+	if (ret) {
+		db_names_free(cls_names);
+		cls_names = NULL;
+	}
 
  	return 0;
  }

WBR, Sergei