Skip to content

Commit

Permalink
structs fields reorganized
Browse files Browse the repository at this point in the history
Structs' fields reorganized based on fieldalignment tool feedback.
  • Loading branch information
gustavo-iniguez-goya committed Jan 13, 2024
1 parent 60c6ac4 commit fdba19c
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 157 deletions.
11 changes: 5 additions & 6 deletions daemon/conman/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import (

// Connection represents an outgoing connection.
type Connection struct {
Entry *netstat.Entry
Process *procmon.Process
Pkt *netfilter.Packet
Protocol string
DstHost string
SrcIP net.IP
SrcPort uint
DstIP net.IP
SrcPort uint
DstPort uint
DstHost string
Entry *netstat.Entry
Process *procmon.Process

Pkt *netfilter.Packet
}

var showUnknownCons = false
Expand Down
10 changes: 5 additions & 5 deletions daemon/dns/systemd/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const (
// QuestionMonitorResponse represents a DNS query
// "question": [{"class": 1, "type": 28,"name": "images.site.com"}],
type QuestionMonitorResponse struct {
Name string `json:"name"`
Class int `json:"class"`
Type int `json:"type"`
Name string `json:"name"`
}

// KeyType holds question that generated the answer
Expand All @@ -67,9 +67,9 @@ type QuestionMonitorResponse struct {
"ifindex": 3
}]*/
type KeyType struct {
Name string `json:"name"`
Class int `json:"class"`
Type int `json:"type"`
Name string `json:"name"`
}

// RRType represents a DNS answer
Expand Down Expand Up @@ -100,13 +100,13 @@ type MonitorResponse struct {

// ResolvedMonitor represents a systemd-resolved monitor
type ResolvedMonitor struct {
mu *sync.RWMutex
Ctx context.Context
Cancel context.CancelFunc

// connection with the systemd-resolved unix socket:
// /run/systemd/resolve/io.systemd.Resolve.Monitor
Conn *varlink.Connection
connected bool
Conn *varlink.Connection

// channel where all the DNS respones will be sent
ChanResponse chan *MonitorResponse
Expand All @@ -117,7 +117,7 @@ type ResolvedMonitor struct {
// callback that is emited when systemd-resolved resolves a domain name.
receiverCb resolvedCallback

mu *sync.RWMutex
connected bool
}

// NewResolvedMonitor returns a new ResolvedMonitor object.
Expand Down
38 changes: 16 additions & 22 deletions daemon/firewall/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// The firewall rules defined by the user are reloaded in these cases:
// - When the file system-fw.json changes.
// - When the firewall rules are not present when listing them.
//
package config

import (
Expand Down Expand Up @@ -59,21 +58,18 @@ type Expressions struct {

// FwRule holds the fields of a rule
type FwRule struct {
*sync.RWMutex
// we need to keep old fields in the struct. Otherwise when receiving a conf from the GUI, the legacy rules would be deleted.
Chain string // TODO: deprecated, remove
Table string // TODO: deprecated, remove
Parameters string // TODO: deprecated: remove

Chain string // TODO: deprecated, remove
Table string // TODO: deprecated, remove
Parameters string // TODO: deprecated, remove
UUID string
Description string
Expressions []*Expressions
Target string
TargetParameters string

Position uint64 `json:",string"`
Enabled bool

*sync.RWMutex
Expressions []*Expressions
Position uint64 `json:",string"`
Enabled bool
}

// FwChain holds the information that defines a firewall chain.
Expand Down Expand Up @@ -102,33 +98,31 @@ type rulesList struct {
}

type chainsList struct {
Chains []*FwChain
Rule *FwRule // TODO: deprecated, remove
Chains []*FwChain
}

// SystemConfig holds the list of rules to be added to the system
type SystemConfig struct {
sync.RWMutex
SystemRules []*chainsList
Version uint32
Enabled bool
sync.RWMutex
Version uint32
Enabled bool
}

// Config holds the functionality to re/load the firewall configuration from disk.
// This is the configuration to manage the system firewall (iptables, nftables).
type Config struct {
sync.Mutex
file string
watcher *fsnotify.Watcher
monitorExitChan chan bool
SysConfig SystemConfig

// preloadCallback is called before reloading the configuration,
// in order to delete old fw rules.
// preload will be called after daemon startup, whilst reload when a modification is performed.
preloadCallback func()
// reloadCallback is called after the configuration is written.
reloadCallback func()
// preload will be called after daemon startup, whilst reload when a modification is performed.
file string
SysConfig SystemConfig

sync.Mutex
}

// NewSystemFwConfig initializes config fields
Expand Down
16 changes: 6 additions & 10 deletions daemon/firewall/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const (

// SystemRule blabla
type SystemRule struct {
Rule *config.FwRule
Table string
Chain string
Rule *config.FwRule
}

// SystemChains keeps track of the fw rules that have been added to the system.
Expand All @@ -54,17 +54,13 @@ type SystemChains struct {

// Iptables struct holds the fields of the iptables fw
type Iptables struct {
config.Config
common.Common

bin string
bin6 string

regexRulesQuery *regexp.Regexp
regexSystemRulesQuery *regexp.Regexp

chains SystemChains

bin string
bin6 string
chains SystemChains
common.Common
config.Config
sync.Mutex
}

Expand Down
8 changes: 4 additions & 4 deletions daemon/firewall/nftables/nftables.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ var (

// Nft holds the fields of our nftables firewall
type Nft struct {
sync.Mutex
config.Config
common.Common

Conn *nftables.Conn
chains iptables.SystemChains
common.Common
config.Config

sync.Mutex
}

// NewNft creates a new nftables object
Expand Down
2 changes: 1 addition & 1 deletion daemon/log/formats/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const (
// JSONEventFormat object to be sent to the remote service.
// TODO: Expand as needed: ebpf events, etc.
type JSONEventFormat struct {
Event interface{} `json:"Event"`
Rule string `json:"Rule"`
Action string `json:"Action"`
Event interface{} `json:"Event"`
Type uint8 `json:"Type"`
}

Expand Down
8 changes: 4 additions & 4 deletions daemon/netfilter/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ type Verdict C.uint

// VerdictContainer struct
type VerdictContainer struct {
Verdict Verdict
Mark uint32
Verdict Verdict
Packet []byte
}

// Packet holds the data of a network packet
type Packet struct {
Packet gopacket.Packet
Mark uint32
verdictChannel chan VerdictContainer
UID uint32
NetworkProtocol uint8
IfaceInIdx int
IfaceOutIdx int
Mark uint32
UID uint32
NetworkProtocol uint8
}

// SetVerdict emits a veredict on a packet
Expand Down
2 changes: 1 addition & 1 deletion daemon/netfilter/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type VerdictContainerC C.verdictContainer
type Queue struct {
h *C.struct_nfq_handle
qh *C.struct_nfq_q_handle
fd C.int
packets chan Packet
fd C.int
idx uint32
}

Expand Down
4 changes: 2 additions & 2 deletions daemon/netstat/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
type Entry struct {
Proto string
SrcIP net.IP
SrcPort uint
DstIP net.IP
DstPort uint
UserId int
INode int
SrcPort uint
DstPort uint
}

// NewEntry creates a new entry with values from /proc/net/
Expand Down
16 changes: 8 additions & 8 deletions daemon/procmon/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ import (

// InodeItem represents an item of the InodesCache.
type InodeItem struct {
sync.RWMutex

Pid int
FdPath string
LastSeen int64
Pid int

sync.RWMutex
}

// ProcItem represents an item of the pidsCache
type ProcItem struct {
sync.RWMutex

Pid int
FdPath string
Descriptors []string
LastSeen int64
Pid int

sync.RWMutex
}

// CacheProcs holds the cache of processes that have established connections.
type CacheProcs struct {
sync.RWMutex
items []*ProcItem
sync.RWMutex
}

// CacheInodes holds the cache of Inodes.
// The key is formed as follow:
// inode+srcip+srcport+dstip+dstport
type CacheInodes struct {
sync.RWMutex
items map[string]*InodeItem
sync.RWMutex
}

var (
Expand Down
2 changes: 1 addition & 1 deletion daemon/procmon/ebpf/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (e *eventsStore) DeleteOldItems() {
//-----------------------------------------------------------------------------

type ebpfCacheItem struct {
Proc procmon.Process
Key []byte
Proc procmon.Process
LastSeen int64
}

Expand Down
Loading

0 comments on commit fdba19c

Please sign in to comment.