Code cleanup
This commit is contained in:
parent
338139ad0f
commit
7d876fb290
35
rawsocket.go
35
rawsocket.go
@ -70,9 +70,16 @@ func listen(iface string, responder chan *NDRequest, requestType NDPType) {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
var f Filter
|
||||
var protocolNo uint32
|
||||
if requestType == NDP_SOL {
|
||||
f = []bpf.Instruction{
|
||||
//Neighbor Solicitation
|
||||
protocolNo = 0x87
|
||||
} else {
|
||||
//Neighbor Advertisement
|
||||
protocolNo = 0x88
|
||||
}
|
||||
|
||||
var f Filter = []bpf.Instruction{
|
||||
// Load "EtherType" field from the ethernet header.
|
||||
bpf.LoadAbsolute{Off: 12, Size: 2},
|
||||
// Jump to the drop packet instruction if EtherType is not IPv6.
|
||||
@ -83,33 +90,13 @@ func listen(iface string, responder chan *NDRequest, requestType NDPType) {
|
||||
bpf.JumpIf{Cond: bpf.JumpNotEqual, Val: 0x3a, SkipTrue: 2},
|
||||
// Load "Type" field from ICMPv6 header.
|
||||
bpf.LoadAbsolute{Off: 54, Size: 1},
|
||||
// Jump to the drop packet instruction if Type is not Neighbor Solicitation.
|
||||
bpf.JumpIf{Cond: bpf.JumpNotEqual, Val: 0x87, SkipTrue: 1},
|
||||
// Jump to the drop packet instruction if Type is not Neighbor Solicitation / Advertisement.
|
||||
bpf.JumpIf{Cond: bpf.JumpNotEqual, Val: protocolNo, SkipTrue: 1},
|
||||
// Verdict is "send up to 4k of the packet to userspace."buf
|
||||
bpf.RetConstant{Val: 4096},
|
||||
// Verdict is "ignore packet."
|
||||
bpf.RetConstant{Val: 0},
|
||||
}
|
||||
} else {
|
||||
f = []bpf.Instruction{
|
||||
// Load "EtherType" field from the ethernet header.
|
||||
bpf.LoadAbsolute{Off: 12, Size: 2},
|
||||
// Jump to the drop packet instruction if EtherType is not IPv6.
|
||||
bpf.JumpIf{Cond: bpf.JumpNotEqual, Val: 0x86dd, SkipTrue: 4},
|
||||
// Load "Next Header" field from IPV6 header.
|
||||
bpf.LoadAbsolute{Off: 20, Size: 1},
|
||||
// Jump to the drop packet instruction if Next Header is not ICMPv6.
|
||||
bpf.JumpIf{Cond: bpf.JumpNotEqual, Val: 0x3a, SkipTrue: 2},
|
||||
// Load "Type" field from ICMPv6 header.
|
||||
bpf.LoadAbsolute{Off: 54, Size: 1},
|
||||
// Jump to the drop packet instruction if Type is not Neighbor Advertisement.
|
||||
bpf.JumpIf{Cond: bpf.JumpNotEqual, Val: 0x88, SkipTrue: 1},
|
||||
// Verdict is "send up to 4k of the packet to userspace."
|
||||
bpf.RetConstant{Val: 4096},
|
||||
// Verdict is "ignore packet."
|
||||
bpf.RetConstant{Val: 0},
|
||||
}
|
||||
}
|
||||
|
||||
err = f.ApplyTo(fd)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user