opensnitch/daemon/firewall/nftables/exprs/operator.go
Gustavo Iñiguez Goia d9e0c59158
Allow to configure firewall rules from the GUI (#660)
* Allow to configure firewall rules from the GUI (WIP)

New features:
- Configure and list system firewall rules from the GUI (nftables).
- Configure chains' policies.
- Add simple rules to allow incoming ports.
- Add simple rules to exclude apps (ports) from being intercepted.

This feature is only available for nftables. iptables is still supported,
you can add rules to the configuration file and they'll be loaded, but
you can't configure them from the GUI.

More information: #592
2022-05-03 22:05:12 +02:00

33 lines
583 B
Go

package exprs
import (
"github.com/google/nftables/expr"
)
// NewOperator translates a string comparator operator to nftables operator
func NewOperator(operator string) expr.CmpOp {
switch operator {
case "!=":
return expr.CmpOpNeq
case ">":
return expr.CmpOpGt
case ">=":
return expr.CmpOpGte
case "<":
return expr.CmpOpLt
case "<=":
return expr.CmpOpLte
}
return expr.CmpOpEq
}
// NewExprOperator returns a new comparator operator
func NewExprOperator(op expr.CmpOp) *[]expr.Any {
return &[]expr.Any{
&expr.Cmp{
Register: 1,
Op: op,
},
}
}