github.com/vishvananda/netlink@v1.3.0/rule.go (about) 1 package netlink 2 3 import ( 4 "fmt" 5 "net" 6 ) 7 8 // Rule represents a netlink rule. 9 type Rule struct { 10 Priority int 11 Family int 12 Table int 13 Mark uint32 14 Mask *uint32 15 Tos uint 16 TunID uint 17 Goto int 18 Src *net.IPNet 19 Dst *net.IPNet 20 Flow int 21 IifName string 22 OifName string 23 SuppressIfgroup int 24 SuppressPrefixlen int 25 Invert bool 26 Dport *RulePortRange 27 Sport *RulePortRange 28 IPProto int 29 UIDRange *RuleUIDRange 30 Protocol uint8 31 Type uint8 32 } 33 34 func (r Rule) String() string { 35 from := "all" 36 if r.Src != nil && r.Src.String() != "<nil>" { 37 from = r.Src.String() 38 } 39 40 to := "all" 41 if r.Dst != nil && r.Dst.String() != "<nil>" { 42 to = r.Dst.String() 43 } 44 45 return fmt.Sprintf("ip rule %d: from %s to %s table %d %s", 46 r.Priority, from, to, r.Table, r.typeString()) 47 } 48 49 // NewRule return empty rules. 50 func NewRule() *Rule { 51 return &Rule{ 52 SuppressIfgroup: -1, 53 SuppressPrefixlen: -1, 54 Priority: -1, 55 Mark: 0, 56 Mask: nil, 57 Goto: -1, 58 Flow: -1, 59 } 60 } 61 62 // NewRulePortRange creates rule sport/dport range. 63 func NewRulePortRange(start, end uint16) *RulePortRange { 64 return &RulePortRange{Start: start, End: end} 65 } 66 67 // RulePortRange represents rule sport/dport range. 68 type RulePortRange struct { 69 Start uint16 70 End uint16 71 } 72 73 // NewRuleUIDRange creates rule uid range. 74 func NewRuleUIDRange(start, end uint32) *RuleUIDRange { 75 return &RuleUIDRange{Start: start, End: end} 76 } 77 78 // RuleUIDRange represents rule uid range. 79 type RuleUIDRange struct { 80 Start uint32 81 End uint32 82 }