69 lines
1.1 KiB
Go
69 lines
1.1 KiB
Go
package chain
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
type ChainOptions interface {
|
|
String() string
|
|
}
|
|
|
|
type Type int8
|
|
|
|
const (
|
|
TypeNone Type = iota
|
|
TypeFilter
|
|
TypeNat
|
|
TypeRoute
|
|
)
|
|
|
|
func (t Type) String() string {
|
|
switch t {
|
|
case TypeNone:
|
|
return ""
|
|
case TypeFilter:
|
|
return "filter"
|
|
case TypeNat:
|
|
return "inet"
|
|
case TypeRoute:
|
|
return "nat"
|
|
default:
|
|
return fmt.Sprintf("unknown type %d", t)
|
|
}
|
|
}
|
|
|
|
type BaseChainOptions struct {
|
|
Type Type
|
|
Hook Hook
|
|
Priority int32
|
|
Policy Policy
|
|
Device string
|
|
}
|
|
|
|
func (b BaseChainOptions) String() string {
|
|
if b.Type == TypeNone {
|
|
return ""
|
|
}
|
|
|
|
device := ""
|
|
if b.Hook == HookEgress || b.Hook == HookIngress {
|
|
if b.Device != "" {
|
|
device = " device " + b.Device + " "
|
|
}
|
|
}
|
|
|
|
policy := ""
|
|
if b.Type == TypeFilter {
|
|
policy = "policy " + b.Policy.String() + " ; "
|
|
}
|
|
|
|
return "{ type " + b.Type.String() + " hook " + b.Hook.String() + " " + device + " priority " + strconv.Itoa(int(b.Priority)) + " ; " + policy + " }"
|
|
}
|
|
|
|
func NewBaseChainOptions(t Type) BaseChainOptions {
|
|
return BaseChainOptions{
|
|
Type: t,
|
|
}
|
|
}
|