Skip to content

Change type of Mark / Mask in Rule? #528

@antoninbas

Description

@antoninbas

Rule is defined as follows in rule.go:

type Rule struct {
  // ...
  Mark              int
  Mask              int
  // ...
}

The default value for Mark and Mask is -1 when creating an instance of Rule with NewRule, and this translates in the corresponding attributes being omitted from the generated netlink message:

	if rule.Mark >= 0 {
		b := make([]byte, 4)
		native.PutUint32(b, uint32(rule.Mark))
		req.AddData(nl.NewRtAttr(nl.FRA_FWMARK, b))
	}
	if rule.Mask >= 0 {
		b := make([]byte, 4)
		native.PutUint32(b, uint32(rule.Mask))
		req.AddData(nl.NewRtAttr(nl.FRA_FWMASK, b))
	}

I have a package that uses github.com/vishvananda/netlink as follows:

ipRule := netlink.NewRule()
ipRule.Mark = 1 << 31
ipRule.Mask = 0xffffffff # same as using the default (-1), but writing this makes sense to be explicit
...

When I try to build this code for a 32-bit architecture (in my case arm/v7), I get errors like this:

constant 2147483648 overflows int
constant 4294967295 overflows int

Would it be possible to change the type of Mark and Mask in order to have better support for 32-bit architectures? I would suggest making these fields *int32 values.

(I have limited knowledge of ip rule but I am assuming that 1 << 31 is a legit fwmark value).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions