From 8b90a9907ef361a25b55d31c2a8c372f4d632e99 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Wed, 25 Mar 2015 05:14:37 +0200 Subject: [PATCH 1/5] tc class: Ignore if default class name file does not exist If '-nm' specified that do not fail if there is no default class names file in /etc/iproute2. Changed default class name file cls_names -> tc_cls. Signed-off-by: Vadim Kochan --- include/names.h | 3 ++- lib/names.c | 61 +++++++++++++++++++++++++++++++++++-------------- tc/tc_util.c | 19 +++++++++++---- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/include/names.h b/include/names.h index 4123d0b0..6fed5818 100644 --- a/include/names.h +++ b/include/names.h @@ -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); diff --git a/lib/names.c b/lib/names.c index 93933f74..3b5b0b1e 100644 --- a/lib/names.c +++ b/lib/names.c @@ -11,8 +11,10 @@ #include #include #include +#include #include "names.h" +#include "utils.h" #define MAX_ENTRIES 256 #define NAME_MAX_LEN 512 @@ -48,48 +50,65 @@ static int read_id_name(FILE *fp, int *id, char *name) return 0; } -struct db_names *db_names_alloc(const char *path) +struct db_names *db_names_alloc(void) { struct db_names *db; - struct db_entry *entry; - FILE *fp; - int id; - char namebuf[NAME_MAX_LEN] = {0}; - int ret; - - fp = fopen(path, "r"); - if (!fp) { - fprintf(stderr, "Can't open file: %s\n", path); - return NULL; - } db = malloc(sizeof(*db)); + if (!db) + return NULL; + memset(db, 0, sizeof(*db)); db->size = MAX_ENTRIES; db->hash = malloc(sizeof(struct db_entry *) * db->size); memset(db->hash, 0, sizeof(struct db_entry *) * db->size); + return db; +} + +int db_names_load(struct db_names *db, const char *path) +{ + struct db_entry *entry; + FILE *fp; + int id; + char namebuf[NAME_MAX_LEN] = {0}; + int ret = -1; + + fp = fopen(path, "r"); + if (!fp) + return -ENOENT; + while ((ret = read_id_name(fp, &id, &namebuf[0]))) { if (ret == -1) { fprintf(stderr, "Database %s is corrupted at %s\n", path, namebuf); - fclose(fp); - return NULL; + goto Exit; } + ret = -1; if (id < 0) continue; entry = malloc(sizeof(*entry)); - entry->id = id; + if (!entry) + goto Exit; + entry->name = strdup(namebuf); + if (!entry->name) { + free(entry); + goto Exit; + } + + entry->id = id; entry->next = db->hash[id & (db->size - 1)]; db->hash[id & (db->size - 1)] = entry; } + ret = 0; +Exit: fclose(fp); - return db; + return ret; } void db_names_free(struct db_names *db) @@ -117,8 +136,12 @@ void db_names_free(struct db_names *db) char *id_to_name(struct db_names *db, int id, char *name) { - struct db_entry *entry = db->hash[id & (db->size - 1)]; + struct db_entry *entry; + if (!db) + return NULL; + + entry = db->hash[id & (db->size - 1)]; while (entry && entry->id != id) entry = entry->next; @@ -136,6 +159,9 @@ int name_to_id(struct db_names *db, int *id, const char *name) struct db_entry *entry; int i; + if (!db) + return -1; + if (db->cached && strcmp(db->cached->name, name) == 0) { *id = db->cached->id; return 0; @@ -145,6 +171,7 @@ int name_to_id(struct db_names *db, int *id, const char *name) entry = db->hash[i]; while (entry && strcmp(entry->name, name)) entry = entry->next; + if (entry) { db->cached = entry; *id = entry->id; diff --git a/tc/tc_util.c b/tc/tc_util.c index feae4394..1d3153df 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "utils.h" #include "names.h" @@ -33,14 +34,24 @@ 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; + + 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; From bbf2f7c66d84baa1d6c889b449b1cd49f08de725 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Thu, 2 Apr 2015 18:08:03 +0300 Subject: [PATCH 2/5] man ip-netns: Fix shifted layout at bottom of 'ip netns del' Signed-off-by: Vadim Kochan --- man/man8/ip-netns.8 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/man/man8/ip-netns.8 b/man/man8/ip-netns.8 index d34cdfe3..5985be06 100644 --- a/man/man8/ip-netns.8 +++ b/man/man8/ip-netns.8 @@ -116,12 +116,18 @@ $ ip netns exec net0 SOME_PROCESS_IN_BACKGROUND $ ip netns del net0 .RE +.RS and eth0 will appear in the default netns only after SOME_PROCESS_IN_BACKGROUND will exit or will be killed. To prevent this the processes running in net0 should be killed before deleting the netns: - $ ip netns pids net0 | xargs kill - $ ip netns del net0 +.RE +.RS 10 +$ ip netns pids net0 | xargs kill +.RE +.RS 10 +$ ip netns del net0 +.RE .TP .B ip netns set NAME NETNSID - assign an id to a peer network namespace From 21107f52b0d611ada2713890e0effdf0cd1d994b Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Sat, 4 Apr 2015 17:06:19 +0300 Subject: [PATCH 3/5] ip-link: Align usage at [link-netns ID] line Output of the usage was shifted be cause of missing TAB Signed-off-by: Vadim Kochan --- ip/iplink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/iplink.c b/ip/iplink.c index 5893ee40..e6f30e99 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -72,7 +72,7 @@ void iplink_usage(void) fprintf(stderr, " [ mtu MTU ]\n"); fprintf(stderr, " [ netns PID ]\n"); fprintf(stderr, " [ netns NAME ]\n"); - fprintf(stderr, " [ link-netnsid ID ]\n"); + fprintf(stderr, " [ link-netnsid ID ]\n"); fprintf(stderr, " [ alias NAME ]\n"); fprintf(stderr, " [ vf NUM [ mac LLADDR ]\n"); fprintf(stderr, " [ vlan VLANID [ qos VLAN-QOS ] ]\n"); From b6d6b5a1cdd91c878ab2541f38402a44ffb75ee7 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Sat, 4 Apr 2015 19:00:55 +0300 Subject: [PATCH 4/5] man ip-link: Add missing link types - vti,ipvlan,nlmon Signed-off-by: Vadim Kochan --- man/man8/ip-link.8.in | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 0e3bb5e6..642cdb23 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -72,7 +72,10 @@ ip-link \- network device configuration .BR gre " |" .BR gretap " |" .BR ip6gre " |" -.BR ip6gretap " ]" +.BR ip6gretap " |" +.BR vti " |" +.BR nlmon " |" +.BR ipvlan " ]" .ti -8 .BI "ip link delete " DEVICE @@ -228,6 +231,15 @@ Link types: .sp .BR ip6gretap - Virtual L2 tunnel interface GRE over IPv6 +.sp +.BR vti +- Virtual tunnel interface +.sp +.BR nlmon +- Netlink monitoring device +.sp +.BR ipvlan +- Interface for L3 (IPv6/IPv4) based VLANs .in -8 .TP From a89d5329d414c601c220505c5173afecb4438dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Tue, 7 Apr 2015 08:41:36 -0700 Subject: [PATCH 5/5] docs: make spacing consistent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Result of the following command: sed -ri 's/\. /. /g' man/*/* Signed-Off-By: Pavel Šimerda --- man/man8/arpd.8 | 2 +- man/man8/bridge.8 | 60 +++++++++++++++--------------- man/man8/ip-address.8.in | 14 +++---- man/man8/ip-addrlabel.8 | 2 +- man/man8/ip-link.8.in | 12 +++--- man/man8/ip-maddress.8 | 2 +- man/man8/ip-monitor.8 | 4 +- man/man8/ip-mroute.8 | 2 +- man/man8/ip-neighbour.8 | 6 +-- man/man8/ip-netns.8 | 10 ++--- man/man8/ip-route.8.in | 78 +++++++++++++++++++-------------------- man/man8/ip-rule.8 | 26 ++++++------- man/man8/ip-tunnel.8 | 8 ++-- man/man8/ip.8 | 10 ++--- man/man8/rtmon.8 | 2 +- man/man8/tc-cbq-details.8 | 4 +- man/man8/tc-cbq.8 | 4 +- man/man8/tc-choke.8 | 6 +-- man/man8/tc-codel.8 | 4 +- man/man8/tc-drr.8 | 10 ++--- man/man8/tc-fq_codel.8 | 6 +-- man/man8/tc-hfsc.8 | 2 +- man/man8/tc-netem.8 | 2 +- man/man8/tc-pie.8 | 2 +- man/man8/tc-red.8 | 4 +- man/man8/tc-sfb.8 | 26 ++++++------- man/man8/tc-sfq.8 | 2 +- man/man8/tc-tbf.8 | 2 +- 28 files changed, 156 insertions(+), 156 deletions(-) diff --git a/man/man8/arpd.8 b/man/man8/arpd.8 index fc99b97e..5050a98b 100644 --- a/man/man8/arpd.8 +++ b/man/man8/arpd.8 @@ -35,7 +35,7 @@ Suppress sending broadcast queries by the kernel. This option only makes sense t Specifies the timeout of the negative cache. When resolution fails, arpd suppresses further attempts to resolve for this period. This option only makes sense together with option '-k'. This timeout should not be too much longer than the boot time of a typical host not supporting gratuitous ARP. Default value is 60 seconds. .TP -p