Skip to content

Commit

Permalink
fix: normalize protocol case (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
luphaz authored Nov 22, 2022
1 parent b453216 commit 4206672
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions network/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@

package network

import "strings"

type Protocol string

const (
TCP Protocol = "tcp"
UDP Protocol = "udp"
ARP Protocol = "arp"
)

func (p Protocol) String() string {
return strings.ToLower(string(p))
}
8 changes: 4 additions & 4 deletions network/tc.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ func (t *tc) AddFilter(ifaces []string, parent string, handle uint32, srcIP, dst
var params, filterProtocol string

// match protocol if specified, default to tcp otherwise
switch protocol {
case TCP, UDP:
switch protocol.String() {
case TCP.String(), UDP.String():
filterProtocol = "ip"
params += fmt.Sprintf("ip_proto %s ", strings.ToLower(string(protocol)))
case ARP:
params += fmt.Sprintf("ip_proto %s ", protocol.String())
case ARP.String():
filterProtocol = "arp"
default:
return 0, fmt.Errorf("unexpected protocol: %s", protocol)
Expand Down
2 changes: 1 addition & 1 deletion network/tc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var _ = Describe("Tc", func() {
}
srcPort = 12345
dstPort = 80
protocol = TCP
protocol = "TCP"
connState = ConnStateNew
flowid = "1:2"
})
Expand Down

0 comments on commit 4206672

Please sign in to comment.