-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Update DHCPv4 protocol to use ECS fields #10089
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,9 @@ import ( | |
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/monitoring" | ||
"github.com/elastic/beats/packetbeat/pb" | ||
"github.com/elastic/beats/packetbeat/protos" | ||
"github.com/elastic/ecs/code/go/ecs" | ||
) | ||
|
||
var ( | ||
|
@@ -86,10 +88,38 @@ func (p *dhcpv4Plugin) parseDHCPv4(pkt *protos.Packet) *beat.Event { | |
v4, err := dhcpv4.FromBytes(pkt.Payload) | ||
if err != nil { | ||
metricParseFailures.Inc() | ||
p.log.Warnw("dropping packet: failed parsing DHCP data", "error", err) | ||
p.log.Warnw("Dropping packet: failed parsing DHCP data", "error", err) | ||
return nil | ||
} | ||
|
||
evt, pbf := pb.NewBeatEvent(pkt.Ts) | ||
|
||
// source/destination (note: this protocol does not produce a bi-flow.) | ||
src, dst := common.MakeEndpointPair(pkt.Tuple.BaseTuple, nil) | ||
pbf.SetSource(&src) | ||
pbf.SetDestination(&dst) | ||
pbf.Source.Bytes = int64(len(pkt.Payload)) | ||
|
||
if v4.Opcode() == dhcpv4.OpcodeBootReply { | ||
// Reverse | ||
client, server := ecs.Client(*pbf.Destination), ecs.Server(*pbf.Source) | ||
pbf.Client = &client | ||
pbf.Server = &server | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for filling out src/dst, even if the cli/srv pair makes more sense at a conceptual level. 👍 |
||
} else { | ||
client, server := ecs.Client(*pbf.Source), ecs.Server(*pbf.Destination) | ||
pbf.Client = &client | ||
pbf.Server = &server | ||
} | ||
|
||
pbf.Event.Start = pkt.Ts | ||
pbf.Event.Dataset = "dhcpv4" | ||
pbf.Network.Transport = "udp" | ||
pbf.Network.Protocol = pbf.Event.Dataset | ||
|
||
fields := evt.Fields | ||
fields["type"] = pbf.Event.Dataset | ||
fields["status"] = "OK" | ||
|
||
dhcpData := common.MapStr{ | ||
"op_code": strings.ToLower(v4.OpcodeToString()), | ||
"hardware_type": v4.HwTypeToString(), | ||
|
@@ -99,6 +129,7 @@ func (p *dhcpv4Plugin) parseDHCPv4(pkt *protos.Packet) *beat.Event { | |
"flags": strings.ToLower(v4.FlagsToString()), | ||
"client_mac": v4.ClientHwAddrToString(), | ||
} | ||
fields["dhcpv4"] = dhcpData | ||
|
||
if !v4.ClientIPAddr().IsUnspecified() { | ||
dhcpData.Put("client_ip", v4.ClientIPAddr().String()) | ||
|
@@ -117,33 +148,11 @@ func (p *dhcpv4Plugin) parseDHCPv4(pkt *protos.Packet) *beat.Event { | |
} | ||
|
||
if opts, err := optionsToMap(v4.StrippedOptions()); err != nil { | ||
p.log.Warnw("failed converting DHCP options to map", | ||
p.log.Warnw("Failed converting DHCP options to map", | ||
"dhcpv4", v4, "error", err) | ||
} else if len(opts) > 0 { | ||
dhcpData.Put("option", opts) | ||
} | ||
|
||
event := &beat.Event{ | ||
Timestamp: pkt.Ts, | ||
Fields: common.MapStr{ | ||
"transport": "udp", | ||
"type": "dhcpv4", | ||
"status": "OK", | ||
"dhcpv4": dhcpData, | ||
}, | ||
} | ||
|
||
src, dst := common.MakeEndpointPair(pkt.Tuple.BaseTuple, nil) | ||
if v4.Opcode() == dhcpv4.OpcodeBootReply { | ||
// Reverse | ||
event.PutValue("src", &dst) | ||
event.PutValue("dst", &src) | ||
event.PutValue("bytes_out", len(pkt.Payload)) | ||
} else { | ||
event.PutValue("src", &src) | ||
event.PutValue("dst", &dst) | ||
event.PutValue("bytes_in", len(pkt.Payload)) | ||
} | ||
|
||
return event | ||
return &evt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: shouldn't you use
client.ip
andserver.ip
here, to be better aligned with past naming, and the "data transfer" visualization?Unless it's semantically important to use those because of the mapping src/dst vs cli/srv flipping around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using source/destination makes more sense to me because this dataset produces unidirectional flows. The table essentially shows the traffic at a packet level so with
source
anddestination
you can see that A sent this message to B and then know that B responded to A. When I use client/server for a uni-flow I'm not 100% which direction the communication is going since the client/server fields remain the same for all events.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Would it make sense to align the "Data transfer" visualization to use source and destination, then?
In any case, I'm all good with this. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it wouldn't because for a uni-flow only the
source
hasbytes
. I had the same thought.