Skip to content

Commit

Permalink
datapath/linux/route: add support for rule protocol
Browse files Browse the repository at this point in the history
Add support for fib rule protocol. Defaults to 0 (unspec) to be
backwards compatible with the old behaviour.

Signed-off-by: Nikolay Aleksandrov <[email protected]>
  • Loading branch information
Nikolay Aleksandrov authored and youngnick committed Mar 25, 2023
1 parent 0557242 commit d0cca9d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/datapath/linux/route/route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit d0cca9d

Please sign in to comment.