Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conntrack: allow to filter by subnet #627

Merged
merged 1 commit into from
May 9, 2021

Conversation

aojea
Copy link
Contributor

@aojea aojea commented Mar 26, 2021

Add a new conntrack filter to be able to filter by subnet, in
addition to current IP address filter.
This keeps compatibility, since the IP filter is just an IP subnet filter with full mask.

Signed-off-by: Antonio Ojea aojea@redhat.com

@aojea
Copy link
Contributor Author

aojea commented Mar 26, 2021

/assign @dcbw @danwinship

// AddIP adds an IP to the conntrack filter
func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error {
// Convert IP to a subnet with a full mask
iplen := 8 * len(ip)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aojea can you explain a bit more what you're doing here? THere's gotta be something we can do that I can understand in 2 minutes of looking at it. Also, we're not To4() or To16() canonicalizing anything here; does the Contains() down below handle that automatically for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a full mask, I tested locally but indeed is a bit opaque because I think it depends on the golang net IP internal types. I will make it explicit so there is no doubt, if you have an ipv4 it add /32 if you have ipv6 it adds /128

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contains check if an IP belongs to an IP subnet , the IP 192.268.2.1 belongs to the subnet 192.168.2.1/32

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation, new push looks good to me

@aojea aojea force-pushed the conntrack_cidrs branch 2 times, most recently from 57952bd to e9f53c8 Compare March 27, 2021 11:18
conntrack_linux.go Outdated Show resolved Hide resolved
conntrack_test.go Outdated Show resolved Hide resolved
@danwinship
Copy link
Contributor

lgtm

@dcbw
Copy link
Contributor

dcbw commented Apr 5, 2021

LGTM

@aboch
Copy link
Collaborator

aboch commented May 8, 2021

please push again to trigger CI

Add a new conntrack filter to be able to filter by subnet, in
addition to current IP address filter.

Signed-off-by: Antonio Ojea <aojea@redhat.com>
@aboch aboch merged commit a3836f0 into vishvananda:master May 9, 2021
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.

4 participants