Skip to content

rule: populate Type field in RuleList and RuleListFiltered#1176

Closed
chent1996 wants to merge 1 commit intovishvananda:mainfrom
chent1996:fix/rule-type-field
Closed

rule: populate Type field in RuleList and RuleListFiltered#1176
chent1996 wants to merge 1 commit intovishvananda:mainfrom
chent1996:fix/rule-type-field

Conversation

@chent1996
Copy link
Contributor

@chent1996 chent1996 commented Mar 25, 2026

Summary

  • Add Type int field to Rule struct to expose the FIB rule action type (e.g. RTN_UNICAST, RTN_BLACKHOLE, RTN_UNREACHABLE)
  • Populate rule.Type from msg.Type during deserialization in RuleListFiltered
  • Support setting msg.Type from rule.Type during rule creation in ruleHandle()
  • Add RT_FILTER_TYPE filtering support for RuleListFiltered

This follows the same pattern used by Route.Type in route handling.

Fixes #1055

Summary by CodeRabbit

  • New Features
    • Rules now support a type attribute.
    • Added filtering capability to exclude rules based on type matching.

The Rule.Type field was missing from the Rule struct, causing
RuleList and RuleListFiltered to always return Type as 0 regardless
of the actual FIB rule action type (e.g. RTN_UNICAST, RTN_BLACKHOLE).

Add Type field to Rule struct, populate it from msg.Type during
deserialization, support setting it during rule creation, and add
RT_FILTER_TYPE filtering support.

Fixes vishvananda#1055
@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d0c086e0-5021-4808-85d5-5fdf63c8aae4

📥 Commits

Reviewing files that changed from the base of the PR and between 72a8cd7 and a3122c7.

📒 Files selected for processing (2)
  • rule.go
  • rule_linux.go

📝 Walkthrough

Walkthrough

The Rule struct gains a new Type field. The rule handling logic is updated to properly serialize this type when creating netlink messages and deserialize it when listing rules. Filter matching now supports type-based filtering.

Changes

Cohort / File(s) Summary
Rule Struct Definition
rule.go
Added exported Type int field to the Rule struct to store rule type information.
Rule Handling and Filtering
rule_linux.go
Updated ruleHandle to set netlink message type from rule.Type when populated. Modified RuleListFiltered to deserialize message type into rule.Type and support RT_FILTER_TYPE filter mask for type-based rule filtering.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A type now flows through rules so fine,
No longer lost to zeros' line,
Each rule remembers what it's for,
And filters know it to the core! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chent1996
Copy link
Contributor Author

Closing as duplicate of #1096 which provides a more comprehensive fix.

@chent1996 chent1996 closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RuleListFiltered and RuleList always return rule.Type=0

1 participant