Skip to content

flower: TCA_FLOWER_FLAGS incorrectly encoded with big-endian instead of native endian #1149

@LikiosSedo

Description

@LikiosSedo

Summary

TCA_FLOWER_FLAGS (skip_hw/skip_sw) are encoded in big-endian via htonl, but netlink attributes are expected in native endian. On little-endian (x86) this flips the bits (e.g., 0x00000001 → 0x01000000), so skip_hw/skip_sw are not applied and tc flower filter add returns EINVAL or the flags are ignored. The tc CLI works because it encodes flags in native endian.

Details

  • Affected: v1.3.1 and current master
  • In filter_linux.go, encode does:
  var flags uint32
  if filter.SkipHw { flags |= nl.TCA_CLS_FLAGS_SKIP_HW }
  if filter.SkipSw { flags |= nl.TCA_CLS_FLAGS_SKIP_SW }
  parent.AddRtAttr(nl.TCA_FLOWER_FLAGS, htonl(flags)) // << big endian
  • htonl in order.go uses binary.BigEndian
  • TCA_FLOWER_FLAGS is NLA_U32 and should use native endian (like other u32 attrs via nl.Uint32Attr)

Reproduce

  1. Create a Flower filter with SkipHw: true or SkipSw: true on x86
  2. netlink.FilterAdd returns EINVAL or the flag is not applied (skip_hw/skip_sw missing)
  3. Adding the same rule via tc CLI succeeds

Fix

- parent.AddRtAttr(nl.TCA_FLOWER_FLAGS, htonl(flags))
+ parent.AddRtAttr(nl.TCA_FLOWER_FLAGS, nl.Uint32Attr(flags))

Impact

With the fix, skip_hw/skip_sw are correctly set, matching tc CLI behavior; avoids EINVAL and ensures flower rules respect offload flags.

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