-
Notifications
You must be signed in to change notification settings - Fork 138
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
Implement expression for matching on source IP? #5
Comments
Hey! Here’s a few pointers:
These are the expressions you’ll need to model with your Go code.
Hope that helps, |
Thank you so much! Would you be open to a PR where I implement an abstraction for building these rules? Something like: builder := nftables.ExprBuilder{Chain: chain}
if err := builder.FilterSourceAddr(srcIP); err != nil {
// ... Errors such as ipv6 address /w ipv4 table family
}
builder.ActionCounter(&counter)
builder.ActionMasquerade()
conn.AddRule(&Rule{ ... Exprs: builder.Expr() ... }) |
Disclaimer: I haven’t thought much about how a good abstraction layer would look like. To me, an important question that I can’t answer yet, is whether the ideal abstraction would implement nft(8)’s config/command line syntax (and how stable those are), or whether something else makes more sense. Intuitively, I’d gravitate towards implementing nft’s syntax: that way, users could just copy their already-existing configuration files. What do you think? |
For the sake of minimizing the learning curve, I agree we should keep the concepts as similar to nft & nft's representation as possible. However, I do think the abstraction needs to be embodied in types; any approach which does string parsing is probably re-inventing the wheel, and loosing the benefits of a type system. Maybe: builder.Table(Table{
Name: ...
Family: ...
Chain: &Chain{
...
Rules: []builder.Rules{
builder.FilterSaddr(saddr),
builder.Masquerade(),
},
},
}).Build() Thoughts? |
I’m not sure about that — neither for nor against, I just can’t tell. Given that, I think the best course of action is to develop your abstraction in a separate repository and see how well it works out in practice. |
I'll give it a try and report back. |
I tried a few things but complexity always crept in to the stage where the APIs were roughly equivalent. The best thing we can do is probably a bunch of examples & maybe a paragraph on using |
Heya,
TL;DR: I'm trying to implement the equivalent of running:
It doesnt look like this library supports source address rules out of the box. I found this which doesnt seem to be terribly different, but I also dont understand (we are throwing bytecode down the netlink socket?)
I tried stracing nft, I tried poking around the nfnl source ... everything seems really hard to follow. Could you give me some direction on how to implement this? happy to write the code, I'm just very lost rn.
Tail end of the strace:
The text was updated successfully, but these errors were encountered: