Skip to content

Commit

Permalink
Update BytesReceived/Sent field names
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Jul 21, 2023
1 parent e70fd9a commit f0ebc6e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
8 changes: 4 additions & 4 deletions firewall/interception/ebpf/bandwidth/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ func reportBandwidth(ctx context.Context, objs bpfObjects, bandwidthUpdates chan
false,
)
update := &packet.BandwidthUpdate{
ConnID: connID,
RecvBytes: skInfo.Rx,
SentBytes: skInfo.Tx,
Method: packet.Absolute,
ConnID: connID,
BytesReceived: skInfo.Rx,
BytesSent: skInfo.Tx,
Method: packet.Absolute,
}
select {
case bandwidthUpdates <- update:
Expand Down
8 changes: 4 additions & 4 deletions firewall/interception/windowskext/bandwidth_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func reportBandwidth(ctx context.Context, bandwidthUpdates chan *packet.Bandwidt
false,
)
update := &packet.BandwidthUpdate{
ConnID: connID,
RecvBytes: stat.receivedBytes,
SentBytes: stat.transmittedBytes,
Method: packet.Additive,
ConnID: connID,
BytesReceived: stat.receivedBytes,
BytesSent: stat.transmittedBytes,
Method: packet.Additive,
}
select {
case bandwidthUpdates <- update:
Expand Down
14 changes: 7 additions & 7 deletions firewall/packet_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func bandwidthUpdateHandler(ctx context.Context) error {

func updateBandwidth(ctx context.Context, bwUpdate *packet.BandwidthUpdate) {
// Check if update makes sense.
if bwUpdate.RecvBytes == 0 && bwUpdate.SentBytes == 0 {
if bwUpdate.BytesReceived == 0 && bwUpdate.BytesSent == 0 {
return
}

Expand All @@ -649,11 +649,11 @@ func updateBandwidth(ctx context.Context, bwUpdate *packet.BandwidthUpdate) {
// Update stats according to method.
switch bwUpdate.Method {
case packet.Absolute:
conn.RecvBytes = bwUpdate.RecvBytes
conn.SentBytes = bwUpdate.SentBytes
conn.BytesReceived = bwUpdate.BytesReceived
conn.BytesSent = bwUpdate.BytesSent
case packet.Additive:
conn.RecvBytes += bwUpdate.RecvBytes
conn.SentBytes += bwUpdate.SentBytes
conn.BytesReceived += bwUpdate.BytesReceived
conn.BytesSent += bwUpdate.BytesSent
default:
log.Warningf("filter: unsupported bandwidth update method: %d", bwUpdate.Method)
}
Expand All @@ -664,8 +664,8 @@ func updateBandwidth(ctx context.Context, bwUpdate *packet.BandwidthUpdate) {
conn.HistoryEnabled,
conn.Process().GetID(),
conn.ID,
&conn.RecvBytes,
&conn.SentBytes,
conn.BytesReceived,
conn.BytesSent,
); err != nil {
log.Errorf("firewall: failed to persist bandwidth data: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions netquery/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,14 @@ func (db *Database) UpdateBandwidth(ctx context.Context, enableHistory bool, pro
}

parts := []string{}
if incoming != nil {
if bytesReceived != 0 {
parts = append(parts, "bytes_received = :bytes_received")
params[":bytes_received"] = *incoming
params[":bytes_received"] = bytesReceived
}

if outgoing != nil {
if bytesSent != 0 {
parts = append(parts, "bytes_sent = :bytes_sent")
params[":bytes_sent"] = *outgoing
params[":bytes_sent"] = bytesSent
}

updateSet := strings.Join(parts, ", ")
Expand Down
5 changes: 5 additions & 0 deletions network/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ type Connection struct { //nolint:maligned // TODO: fix alignment
RecvBytes uint64
SentBytes uint64

// BytesReceived holds the observed received bytes of the connection.
BytesReceived uint64
// BytesSent holds the observed sent bytes of the connection.
BytesSent uint64

// pkgQueue is used to serialize packet handling for a single
// connection and is served by the connections packetHandler.
pktQueue chan packet.Packet
Expand Down
10 changes: 5 additions & 5 deletions network/packet/bandwidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import "fmt"

// BandwidthUpdate holds an update to the seen bandwidth of a connection.
type BandwidthUpdate struct {
ConnID string
RecvBytes uint64
SentBytes uint64
Method BandwidthUpdateMethod
ConnID string
BytesReceived uint64
BytesSent uint64
Method BandwidthUpdateMethod
}

// BandwidthUpdateMethod defines how the bandwidth data of a bandwidth update should be interpreted.
Expand All @@ -20,7 +20,7 @@ const (
)

func (bu *BandwidthUpdate) String() string {
return fmt.Sprintf("%s: %dB recv | %dB sent [%s]", bu.ConnID, bu.RecvBytes, bu.SentBytes, bu.Method)
return fmt.Sprintf("%s: %dB recv | %dB sent [%s]", bu.ConnID, bu.BytesReceived, bu.BytesSent, bu.Method)
}

func (bum BandwidthUpdateMethod) String() string {
Expand Down

0 comments on commit f0ebc6e

Please sign in to comment.