mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
Seperate Definitions by Sub System
This commit is contained in:
parent
14c8da64cc
commit
72bf96295d
31 changed files with 120 additions and 108 deletions
7
internal/definitions/firewall/destination_nat.go
Normal file
7
internal/definitions/firewall/destination_nat.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package firewall
|
||||
|
||||
type DestinationNATRule struct {
|
||||
Rule
|
||||
Address string `json:"address,omitempty"`
|
||||
Service string `json:"service,omitempty"`
|
||||
}
|
7
internal/definitions/firewall/firewall.go
Normal file
7
internal/definitions/firewall/firewall.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package firewall
|
||||
|
||||
type Firewall struct {
|
||||
ForwardRules []ForwardRule `json:"forward_rules" validate:"required,dive"`
|
||||
DestinationNATRules []DestinationNATRule `json:"destination_nat_rules" validate:"required,dive"`
|
||||
SourceNATRules []SourceNATRule `json:"source_nat_rules" validate:"required,dive"`
|
||||
}
|
8
internal/definitions/firewall/match.go
Normal file
8
internal/definitions/firewall/match.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package firewall
|
||||
|
||||
type Match struct {
|
||||
TCPDestinationPort uint64 `json:"tcp_destination_port,omitempty"`
|
||||
Services []string `json:"services,omitempty"`
|
||||
SourceAddresses []string `json:"source_addresses,omitempty"`
|
||||
DestinationAddresses []string `json:"destination_addresses,omitempty"`
|
||||
}
|
50
internal/definitions/firewall/rule.go
Normal file
50
internal/definitions/firewall/rule.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package firewall
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Rule struct {
|
||||
ID uint64 `json:"id" validate:"required,gt=0"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Match Match `json:"match" validate:"required,dive"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
Counter bool `json:"counter,omitempty"`
|
||||
}
|
||||
|
||||
type ForwardRule struct {
|
||||
Rule
|
||||
Verdict Verdict `json:"verdict" validate:"min=0,max=2"`
|
||||
}
|
||||
|
||||
type Verdict int
|
||||
|
||||
const (
|
||||
Accept Verdict = iota
|
||||
Drop
|
||||
Continue
|
||||
)
|
||||
|
||||
func (t Verdict) String() string {
|
||||
return [...]string{"accept", "drop", "continue"}[t]
|
||||
}
|
||||
|
||||
func (t *Verdict) FromString(input string) Verdict {
|
||||
return map[string]Verdict{
|
||||
"accept": Accept,
|
||||
"drop": Drop,
|
||||
"continue": Continue,
|
||||
}[input]
|
||||
}
|
||||
|
||||
func (t Verdict) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.String())
|
||||
}
|
||||
|
||||
func (t *Verdict) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
err := json.Unmarshal(b, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = t.FromString(s)
|
||||
return nil
|
||||
}
|
42
internal/definitions/firewall/source_nat.go
Normal file
42
internal/definitions/firewall/source_nat.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package firewall
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type SourceNATRule struct {
|
||||
Rule
|
||||
Type SnatType `json:"type" validate:"min=0,max=1"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Service string `json:"service,omitempty"`
|
||||
}
|
||||
|
||||
type SnatType int
|
||||
|
||||
const (
|
||||
Snat SnatType = iota
|
||||
Masquerade
|
||||
)
|
||||
|
||||
func (t SnatType) String() string {
|
||||
return [...]string{"snat", "masquerade"}[t]
|
||||
}
|
||||
|
||||
func (t *SnatType) FromString(input string) SnatType {
|
||||
return map[string]SnatType{
|
||||
"snat": Snat,
|
||||
"masquerade": Masquerade,
|
||||
}[input]
|
||||
}
|
||||
|
||||
func (t SnatType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.String())
|
||||
}
|
||||
|
||||
func (t *SnatType) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
err := json.Unmarshal(b, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = t.FromString(s)
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue