mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
console: move ethertypes for IPv4/IPv6 to helpers package
This commit is contained in:
11
common/helpers/ether.go
Normal file
11
common/helpers/ether.go
Normal file
@@ -0,0 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 2022 Free Mobile
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package helpers
|
||||
|
||||
const (
|
||||
// ETypeIPv4 is the ether type for IPv4
|
||||
ETypeIPv4 = 0x800
|
||||
// ETypeIPv6 is the ether type for IPv6
|
||||
ETypeIPv6 = 0x86dd
|
||||
)
|
||||
@@ -6,6 +6,8 @@
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"akvorado/common/helpers"
|
||||
)
|
||||
|
||||
func quote(v interface{}) string {
|
||||
@@ -139,8 +141,8 @@ ConditionETypeExpr "condition on Ethernet type" ←
|
||||
column:("EType"i { return "EType", nil }) _
|
||||
operator:("=" / "!=") _ value:("IPv4"i / "IPv6"i) {
|
||||
etypes := map[string]uint16{
|
||||
"ipv4": 0x0800,
|
||||
"ipv6": 0x86dd,
|
||||
"ipv4": helpers.ETypeIPv4,
|
||||
"ipv6": helpers.ETypeIPv6,
|
||||
}
|
||||
etype := etypes[strings.ToLower(toString(value))]
|
||||
return fmt.Sprintf("%s %s %d", toString(column), toString(operator), etype), nil
|
||||
|
||||
@@ -128,7 +128,8 @@ func (gc queryColumn) toSQLSelect() string {
|
||||
strValue = fmt.Sprintf(`concat(toString(%s), ': ', dictGetOrDefault('asns', 'name', %s, '???'))`,
|
||||
gc, gc)
|
||||
case queryColumnEType:
|
||||
strValue = `if(EType = 0x800, 'IPv4', if(EType = 0x86dd, 'IPv6', '???'))`
|
||||
strValue = fmt.Sprintf(`if(EType = %d, 'IPv4', if(EType = %d, 'IPv6', '???'))`,
|
||||
helpers.ETypeIPv4, helpers.ETypeIPv6)
|
||||
case queryColumnProto:
|
||||
strValue = `dictGetOrDefault('protocols', 'name', Proto, '???')`
|
||||
case queryColumnInIfSpeed, queryColumnOutIfSpeed, queryColumnSrcPort, queryColumnDstPort, queryColumnForwardingStatus:
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestQueryColumnSQLSelect(t *testing.T) {
|
||||
Expected: `dictGetOrDefault('protocols', 'name', Proto, '???')`,
|
||||
}, {
|
||||
Input: queryColumnEType,
|
||||
Expected: `if(EType = 0x800, 'IPv4', if(EType = 0x86dd, 'IPv6', '???'))`,
|
||||
Expected: `if(EType = 2048, 'IPv4', if(EType = 34525, 'IPv6', '???'))`,
|
||||
}, {
|
||||
Input: queryColumnOutIfSpeed,
|
||||
Expected: `toString(OutIfSpeed)`,
|
||||
|
||||
@@ -15,15 +15,15 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"akvorado/common/clickhousedb"
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/http"
|
||||
"akvorado/common/reporter"
|
||||
"akvorado/console/authentication"
|
||||
"akvorado/console/database"
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
"gopkg.in/tomb.v2"
|
||||
)
|
||||
|
||||
// Component represents the console component.
|
||||
|
||||
Reference in New Issue
Block a user