From e70f55a9cf522ebb419f710866acf2e781f84e93 Mon Sep 17 00:00:00 2001 From: Marcel Greter Date: Wed, 28 Feb 2018 22:23:44 +0100 Subject: [PATCH] Fix hexadecimal qdisc/class id matching Ids from tc are parsed hexadecimal where as tc names in config user rules are parsed as regular integers. --- lib/parser.go | 2 +- lib/parser_test.go | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/parser.go b/lib/parser.go index f3f2e36..61cc10e 100644 --- a/lib/parser.go +++ b/lib/parser.go @@ -353,7 +353,7 @@ func (t *tcParser) parseData(cmdOutput string, ifaceName string, reHeader, reDat haveData = false // tcName is the internal name for this Qdisc / Class on an interface. Example: "eth0:2:3" is Class 3, Qdisc 2 on interface eth0. - tcName := fmt.Sprintf("%s:%s:%s", ifaceName, strconv.FormatInt(qdiscHandle, 10), strconv.FormatInt(classHandle, 10)) + tcName := fmt.Sprintf("%s:%s:%s", ifaceName, strconv.FormatInt(qdiscHandle, 16), strconv.FormatInt(classHandle, 16)) data := &parsedData{ name: tcName, sentBytes: sentBytes, diff --git a/lib/parser_test.go b/lib/parser_test.go index f2ad277..dc385b4 100644 --- a/lib/parser_test.go +++ b/lib/parser_test.go @@ -390,13 +390,13 @@ func TestTcParserParse(t *testing.T) { []parsedData{ {"eth0:1:0", 12548819, 124105, 13, 25, nil}, {"eth0:2:0", 12548819, 24106, 128, 29, nil}, - {"eth0:10:0", 123432, 1027, 11, 2048, nil}, - {"eth0:110:0", 9397865, 102745, 0, 0, nil}, + {"eth0:a:0", 123432, 1027, 11, 2048, nil}, + {"eth0:6e:0", 9397865, 102745, 0, 0, nil}, {"eth0:2:1", 931528, 9571, 127, 25, nil}, {"eth0:2:2", 11630676, 114607, 13, 5211, nil}, {"eth0:4:1", 11601665, 114364, 0, 0, nil}, - {"eth0:4:10", 1096857, 7059, 0, 0, nil}, - {"eth0:4:110", 256, 13, 7, 0, nil}, + {"eth0:4:a", 1096857, 7059, 0, 0, nil}, + {"eth0:4:6e", 256, 13, 7, 0, nil}, }, 1, 1, @@ -410,22 +410,22 @@ func TestTcParserParse(t *testing.T) { nil, nil, map[string]userClass{ - "eth0:4:1": {0, "username"}, - "eth0:4:10": {1, "username"}, + "eth0:4:1": {0, "username"}, + "eth0:4:a": {1, "username"}, }, "", []parsedData{ {"eth0:1:0", 12548819, 124105, 13, 25, nil}, {"eth0:2:0", 12548819, 24106, 128, 29, nil}, - {"eth0:10:0", 123432, 1027, 11, 2048, nil}, - {"eth0:110:0", 9397865, 102745, 0, 0, nil}, + {"eth0:a:0", 123432, 1027, 11, 2048, nil}, + {"eth0:6e:0", 9397865, 102745, 0, 0, nil}, {"eth0:2:1", 931528, 9571, 127, 25, nil}, {"eth0:2:2", 11630676, 114607, 13, 5211, nil}, {"eth0:4:1", 11601665, 114364, 0, 0, nil}, {"eth0:4:1", 11601665, 114364, 0, 0, &userClass{0, "username"}}, - {"eth0:4:10", 1096857, 7059, 0, 0, nil}, - {"eth0:4:10", 1096857, 7059, 0, 0, &userClass{1, "username"}}, - {"eth0:4:110", 256, 13, 7, 0, nil}, + {"eth0:4:a", 1096857, 7059, 0, 0, nil}, + {"eth0:4:a", 1096857, 7059, 0, 0, &userClass{1, "username"}}, + {"eth0:4:6e", 256, 13, 7, 0, nil}, }, 1, 1,