Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Bremgartner committed Jan 13, 2017
1 parent 5e4cc81 commit 85ba2a0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c ChainType) String() string {
// if a packet would be returned after the first block (register a > 0)
// * OR-case: only evaluate second block,
// if the packet would not be returned after the first block (register a == 0)
func ChainFilter(a, b []bpf.Instruction, ct ChainType) ([]bpf.Instruction) {
func ChainFilter(a, b []bpf.Instruction, ct ChainType) []bpf.Instruction {
bpfChained := make([]bpf.Instruction, 0, len(a)+len(b)+10)
offset := len(a)

Expand Down
10 changes: 5 additions & 5 deletions chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ import (

func TestChainTypeString(t *testing.T) {
cases := []struct {
input ChainType
input ChainType
output string
}{
{
input: 0,
input: 0,
output: "undefined",
},
{
input: 1,
input: 1,
output: "and",
},
{
input: 2,
input: 2,
output: "or",
},
{
input: 3,
input: 3,
output: "undefined",
},
}
Expand Down
31 changes: 15 additions & 16 deletions convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ func TestToPcapBPFInstruction(t *testing.T) {
cases := []struct {
raw []bpf.RawInstruction
pcap []pcap.BPFInstruction
bpf []bpf.Instruction
bpf []bpf.Instruction
}{
{
/*
# get a random uint32 number
ld rand
# if rand is greater than 4294967 (maxuint32 / 1000), drop the package
jgt #4294967, drop
capture:
# ret > 0 -> capture number of byte of the packets
ret #1024
drop:
# ret = 0 -> do not capture the packet
ret #0
# get a random uint32 number
ld rand
# if rand is greater than 4294967 (maxuint32 / 1000), drop the package
jgt #4294967, drop
capture:
# ret > 0 -> capture number of byte of the packets
ret #1024
drop:
# ret = 0 -> do not capture the packet
ret #0
*/
raw: []bpf.RawInstruction{
{Op: 0x20, Jt: 0, Jf: 0, K: 0xfffff038},
Expand All @@ -44,7 +44,7 @@ func TestToPcapBPFInstruction(t *testing.T) {
bpf.LoadExtension{Num: bpf.ExtRand},
bpf.JumpIf{Cond: bpf.JumpGreaterThan, Val: 4294967, SkipTrue: 1},
bpf.RetConstant{Val: 1024},
bpf.RetConstant{Val:0},
bpf.RetConstant{Val: 0},
},
},
}
Expand All @@ -57,7 +57,7 @@ func TestToPcapBPFInstruction(t *testing.T) {

for i, inst := range test.raw {
got := ToPcapBPFInstruction(inst)
if !reflect.DeepEqual(test.pcap[i], got) {
if !reflect.DeepEqual(test.pcap[i], got) {
t.Errorf("ToPcapBPFInstruction failed, got: %#v, expected: %#v", got, test.pcap[i])
}
}
Expand All @@ -69,7 +69,7 @@ func TestToPcapBPFInstruction(t *testing.T) {

for i, inst := range test.pcap {
got := ToBpfRawInstruction(inst)
if !reflect.DeepEqual(test.raw[i], got) {
if !reflect.DeepEqual(test.raw[i], got) {
t.Errorf("ToRawBPFInstruction failed, got: %#v, expected: %#v", got, test.raw[i])
}
}
Expand All @@ -81,11 +81,10 @@ func TestToPcapBPFInstruction(t *testing.T) {

for i, inst := range test.pcap {
got := ToBpfInstruction(inst)
if !reflect.DeepEqual(test.bpf[i], got) {
if !reflect.DeepEqual(test.bpf[i], got) {
t.Errorf("ToBPFInstruction failed, got: %#v, expected: %#v", got, test.bpf[i])
}
}


}
}
18 changes: 9 additions & 9 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"strings"
"testing"

"golang.org/x/net/bpf"
"fmt"

"github.com/google/gopacket/pcap"
"golang.org/x/net/bpf"
)

type InvalidInstruction struct{}
func (a InvalidInstruction) Assemble()(bpf.RawInstruction, error) {

func (a InvalidInstruction) Assemble() (bpf.RawInstruction, error) {
return bpf.RawInstruction{}, fmt.Errorf("Invalid Instruction")
}

func TestAsmString(t *testing.T) {


cases := []struct {
input bpf.Instruction
expect string
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestAsmString(t *testing.T) {
expect: "ld #rand",
},
{
input: bpf.LoadAbsolute{Off:0xfffff038, Size:4},
input: bpf.LoadAbsolute{Off: 0xfffff038, Size: 4},
expect: "ld #rand",
},
{
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestAsmString(t *testing.T) {
},
// Invalid instruction
{
input: InvalidInstruction{},
input: InvalidInstruction{},
expect: "!! unknown instruction: bpfutils.InvalidInstruction{}",
},
}
Expand All @@ -297,8 +297,8 @@ func TestAsmString(t *testing.T) {
}

func TestString(t *testing.T) {
cases := []struct{
input []pcap.BPFInstruction
cases := []struct {
input []pcap.BPFInstruction
output string
}{
{
Expand All @@ -322,4 +322,4 @@ bpf.RetConstant{Val:0x0}
}
}

}
}

0 comments on commit 85ba2a0

Please sign in to comment.