diff --git a/pkg/datapath/linux/route/route_linux.go b/pkg/datapath/linux/route/route_linux.go index 29fc92f6b6c32..98574881de7c9 100644 --- a/pkg/datapath/linux/route/route_linux.go +++ b/pkg/datapath/linux/route/route_linux.go @@ -320,6 +320,9 @@ type Rule struct { // Table is the routing table to look up if the rule matches Table int + + // Protocol is the routing rule protocol (e.g. proto unspec/kernel) + Protocol uint8 } // String returns the string representation of a Rule (adhering to the Stringer @@ -355,6 +358,8 @@ func (r Rule) String() string { str += fmt.Sprintf(" mark 0x%x mask 0x%x", r.Mark, r.Mask) } + str += fmt.Sprintf(" proto %s", netlink.RouteProtocol(r.Protocol)) + return str } @@ -380,6 +385,10 @@ func lookupRule(spec Rule, family int) (bool, error) { continue } + if spec.Protocol != 0 && r.Protocol != spec.Protocol { + continue + } + if r.Table == spec.Table { return true, nil } @@ -458,6 +467,7 @@ func replaceRule(spec Rule, family int) error { rule.Priority = spec.Priority rule.Src = spec.From rule.Dst = spec.To + rule.Protocol = spec.Protocol return netlink.RuleAdd(rule) } @@ -480,6 +490,7 @@ func deleteRule(spec Rule, family int) error { rule.Src = spec.From rule.Dst = spec.To rule.Family = family + rule.Protocol = spec.Protocol return netlink.RuleDel(rule) }