Skip to content

Commit 468de3a

Browse files
committed
Fix reading of rule type and add l3mdev flag.
When reading rules, makes sure to populate the type field of Rule. Also adds a l3mdev flag to Rule, reads it when listing rules, sets it when updating rules, and makes sure it is taken into account when comparing rules using Equal as introduced in vishvananda#1095.
1 parent 6a8c071 commit 468de3a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

rule.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Rule struct {
2929
UIDRange *RuleUIDRange
3030
Protocol uint8
3131
Type uint8
32+
L3mdev uint8
3233
}
3334

3435
func (r Rule) Equal(x Rule) bool {
@@ -59,7 +60,8 @@ func (r Rule) Equal(x Rule) bool {
5960
r.SuppressPrefixlen == x.SuppressPrefixlen &&
6061
(r.Dport == x.Dport || (r.Dport != nil && x.Dport != nil && r.Dport.Equal(*x.Dport))) &&
6162
(r.Sport == x.Sport || (r.Sport != nil && x.Sport != nil && r.Sport.Equal(*x.Sport))) &&
62-
(r.UIDRange == x.UIDRange || (r.UIDRange != nil && x.UIDRange != nil && r.UIDRange.Equal(*x.UIDRange)))
63+
(r.UIDRange == x.UIDRange || (r.UIDRange != nil && x.UIDRange != nil && r.UIDRange.Equal(*x.UIDRange))) &&
64+
r.L3mdev == x.L3mdev
6365
}
6466

6567
func ptrEqual(a, b *uint32) bool {

rule_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
178178
req.AddData(nl.NewRtAttr(nl.FRA_PROTOCOL, nl.Uint8Attr(rule.Protocol)))
179179
}
180180

181+
if rule.L3mdev > 0 {
182+
req.AddData(nl.NewRtAttr(nl.FRA_L3MDEV, nl.Uint8Attr(rule.L3mdev)))
183+
}
184+
181185
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
182186
return err
183187
}
@@ -239,6 +243,7 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
239243
rule.Invert = msg.Flags&FibRuleInvert > 0
240244
rule.Family = int(msg.Family)
241245
rule.Tos = uint(msg.Tos)
246+
rule.Type = msg.Type
242247

243248
for j := range attrs {
244249
switch attrs[j].Attr.Type {
@@ -291,6 +296,8 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
291296
rule.UIDRange = NewRuleUIDRange(native.Uint32(attrs[j].Value[0:4]), native.Uint32(attrs[j].Value[4:8]))
292297
case nl.FRA_PROTOCOL:
293298
rule.Protocol = uint8(attrs[j].Value[0])
299+
case nl.FRA_L3MDEV:
300+
rule.L3mdev = uint8(attrs[j].Value[0])
294301
}
295302
}
296303

rule_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ func TestRuleEqual(t *testing.T) {
699699
{UIDRange: &RuleUIDRange{Start: 3, End: 5}},
700700
{Protocol: FAMILY_V6},
701701
{Type: unix.RTN_UNREACHABLE},
702+
{L3mdev: 1},
702703
}
703704
for i1 := range cases {
704705
for i2 := range cases {

0 commit comments

Comments
 (0)