rule.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package netlink
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. // Rule represents a netlink rule.
  7. type Rule struct {
  8. Priority int
  9. Family int
  10. Table int
  11. Mark int
  12. Mask int
  13. Tos uint
  14. TunID uint
  15. Goto int
  16. Src *net.IPNet
  17. Dst *net.IPNet
  18. Flow int
  19. IifName string
  20. OifName string
  21. SuppressIfgroup int
  22. SuppressPrefixlen int
  23. Invert bool
  24. Dport *RulePortRange
  25. Sport *RulePortRange
  26. }
  27. func (r Rule) String() string {
  28. return fmt.Sprintf("ip rule %d: from %s table %d", r.Priority, r.Src, r.Table)
  29. }
  30. // NewRule return empty rules.
  31. func NewRule() *Rule {
  32. return &Rule{
  33. SuppressIfgroup: -1,
  34. SuppressPrefixlen: -1,
  35. Priority: -1,
  36. Mark: -1,
  37. Mask: -1,
  38. Goto: -1,
  39. Flow: -1,
  40. }
  41. }
  42. // NewRulePortRange creates rule sport/dport range.
  43. func NewRulePortRange(start, end uint16) *RulePortRange {
  44. return &RulePortRange{Start: start, End: end}
  45. }
  46. // RulePortRange represents rule sport/dport range.
  47. type RulePortRange struct {
  48. Start uint16
  49. End uint16
  50. }