Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IP fragmentation features #17

Merged
merged 2 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions modules/features/custom/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package custom

import (
"github.com/google/gopacket/layers"

"github.com/CN-TU/go-flows/flows"
"github.com/CN-TU/go-flows/packet"
ipfix "github.com/CN-TU/go-ipfix"
)

////////////////////////////////////////////////////////////////////////////////

type _ipChecksum struct {
flows.BaseFeature
}

func (f *_ipChecksum) Event(new interface{}, context *flows.EventContext, src interface{}) {
network := new.(packet.Buffer).NetworkLayer()
if ip, ok := network.(*layers.IPv4); ok {
f.SetValue(ip.Checksum, context, f)
}
}

func init() {
flows.RegisterTemporaryFeature("_ipChecksum", "returns a textual representation of the ipchecksum", ipfix.StringType, 1, flows.PacketFeature, func() flows.Feature { return &_ipChecksum{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////
16 changes: 16 additions & 0 deletions modules/features/custom/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,19 @@ func init() {
}

////////////////////////////////////////////////////////////////////////////////

type _tcpChecksum struct {
flows.BaseFeature
}

func (f *_tcpChecksum) Event(new interface{}, context *flows.EventContext, src interface{}) {
tcp := features.GetTCP(new)
if tcp == nil {
return
}
f.SetValue(tcp.Checksum, context, f)
}

func init() {
flows.RegisterTemporaryFeature("_tcpChecksum", "returns a textual representation of the tcpchecksum", ipfix.StringType, 1, flows.PacketFeature, func() flows.Feature { return &_tcpChecksum{} }, flows.RawPacket)
}
85 changes: 85 additions & 0 deletions modules/features/iana/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,88 @@ func init() {
}

////////////////////////////////////////////////////////////////////////////////

type fragmentFlags struct {
flows.BaseFeature
}

func (f *fragmentFlags) Event(new interface{}, context *flows.EventContext, src interface{}) {
network := new.(packet.Buffer).NetworkLayer()
if ip, ok := network.(*layers.IPv4); ok {
f.SetValue(ip.Flags, context, f)
}
}

func init() {
flows.RegisterStandardFeature("fragmentFlags", flows.PacketFeature, func() flows.Feature { return &fragmentFlags{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type fragmentIdentification struct {
flows.BaseFeature
}

func (f *fragmentIdentification) Event(new interface{}, context *flows.EventContext, src interface{}) {
network := new.(packet.Buffer).NetworkLayer()
if ip, ok := network.(*layers.IPv4); ok {
f.SetValue(ip.Id, context, f)
}
}

func init() {
flows.RegisterStandardFeature("fragmentIdentification", flows.PacketFeature, func() flows.Feature { return &fragmentIdentification{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type fragmentOffset struct {
flows.BaseFeature
}

func (f *fragmentOffset) Event(new interface{}, context *flows.EventContext, src interface{}) {
network := new.(packet.Buffer).NetworkLayer()
if ip, ok := network.(*layers.IPv4); ok {
f.SetValue(ip.FragOffset, context, f)
}
}

func init() {
flows.RegisterStandardFeature("fragmentOffset", flows.PacketFeature, func() flows.Feature { return &fragmentOffset{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type ipVersion struct {
flows.BaseFeature
}

func (f *ipVersion) Event(new interface{}, context *flows.EventContext, src interface{}) {
network := new.(packet.Buffer).NetworkLayer()
if ip, ok := network.(*layers.IPv4); ok {
f.SetValue(ip.Version, context, f)
}
}

func init() {
flows.RegisterStandardFeature("ipVersion", flows.PacketFeature, func() flows.Feature { return &ipVersion{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type ipHeaderLength struct {
flows.BaseFeature
}

func (f *ipHeaderLength) Event(new interface{}, context *flows.EventContext, src interface{}) {
network := new.(packet.Buffer).NetworkLayer()
if ip, ok := network.(*layers.IPv4); ok {
f.SetValue(ip.IHL, context, f)
}
}

func init() {
flows.RegisterStandardFeature("ipHeaderLength", flows.PacketFeature, func() flows.Feature { return &ipHeaderLength{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////
90 changes: 89 additions & 1 deletion modules/features/iana/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,92 @@ func init() {
flows.RegisterStandardReverseFeature("tcpSequenceNumber", flows.FlowFeature, func() flows.Feature { return &reverseTCPSequenceNumber{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

type tcpWindowSize struct {
flows.BaseFeature
}

func (f *tcpWindowSize) Event(new interface{}, context *flows.EventContext, src interface{}) {
tcp := features.GetTCP(new)
if tcp == nil {
return
}
f.SetValue(tcp.Window, context, f)
}

func init() {
flows.RegisterStandardFeature("tcpWindowSize", flows.PacketFeature, func() flows.Feature { return &tcpWindowSize{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type tcpUrgentPointer struct {
flows.BaseFeature
}

func (f *tcpUrgentPointer) Event(new interface{}, context *flows.EventContext, src interface{}) {
tcp := features.GetTCP(new)
if tcp == nil {
return
}
f.SetValue(tcp.Urgent, context, f)
}

func init() {
flows.RegisterStandardFeature("tcpUrgentPointer", flows.PacketFeature, func() flows.Feature { return &tcpUrgentPointer{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type tcpOptions struct {
flows.BaseFeature
}

func (f *tcpOptions) Event(new interface{}, context *flows.EventContext, src interface{}) {
tcp := features.GetTCP(new)
if tcp == nil {
return
}
f.SetValue(tcp.Options, context, f)
}

func init() {
flows.RegisterStandardFeature("tcpOptions", flows.PacketFeature, func() flows.Feature { return &tcpOptions{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type tcpAcknowledgementNumber struct {
flows.BaseFeature
}

func (f *tcpAcknowledgementNumber) Event(new interface{}, context *flows.EventContext, src interface{}) {
tcp := features.GetTCP(new)
if tcp == nil {
return
}
f.SetValue(tcp.Ack, context, f)
}

func init() {
flows.RegisterStandardFeature("tcpAcknowledgementNumber", flows.PacketFeature, func() flows.Feature { return &tcpAcknowledgementNumber{} }, flows.RawPacket)
}

////////////////////////////////////////////////////////////////////////////////

type tcpHeaderLength struct {
flows.BaseFeature
}

func (f *tcpHeaderLength) Event(new interface{}, context *flows.EventContext, src interface{}) {
tcp := features.GetTCP(new)
if tcp == nil {
return
}
f.SetValue(tcp.DataOffset, context, f)
}

func init() {
flows.RegisterStandardFeature("tcpHeaderLength", flows.PacketFeature, func() flows.Feature { return &tcpHeaderLength{} }, flows.RawPacket)
}