-
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
Readme #12
base: main
Are you sure you want to change the base?
Readme #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,78 @@ implemented in pure Go, i.e. does not wrap libnftnl. | |
|
||
This is not an official Google product. | ||
|
||
## Breaking changes | ||
## Alpha status | ||
|
||
This package is in early stages, and only implements a subset of nftables | ||
features. While the developers intend to keep interfaces & function signatures | ||
backwards-compatible, no guarantees are made; bugs or any unexpected | ||
structuring of nftables features may result in breaking changes. | ||
|
||
## Usage | ||
|
||
Issue commands to mutate or read nftables state. Commands that mutate state | ||
(eg: `AddTable`, `AddChain`, `AddSet`, `AddRule`) are queued until `Flush` | ||
is called. | ||
|
||
### Expressions | ||
|
||
The following expressions are implemented for use in rule logic: | ||
|
||
TODO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just link to godoc instead of maintaining a separate list. It will just go stale. |
||
|
||
### Examples | ||
|
||
#### Drop outgoing packets to 1.2.3.4 | ||
|
||
```go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we link to a compiled example in godoc instead? That way, it’ll always be up to date. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An examples directory works, too, but please make them be testable. I don’t mind linking to your blog (in addition). That might be a more pragmatic alternative than wikis, which only make sense for larger projects where there’s enough motivation around to keep them up-to-date. |
||
c := &nftables.Conn{} | ||
|
||
myTable := c.AddTable(&nftables.Table{ | ||
Family: nftables.TableFamilyIPv4, | ||
Name: "myFilter", | ||
}) | ||
|
||
myChain := c.AddChain(&nftables.Chain{ | ||
Name: "myChain", | ||
Table: myTable, | ||
Type: nftables.ChainTypeFilter, | ||
Hooknum: nftables.ChainHookOutput, | ||
Priority: nftables.ChainPriorityFilter, | ||
}) | ||
|
||
c.AddRule(&nftables.Rule{ | ||
Table: myTable, | ||
Chain: myChain, | ||
Exprs: []expr.Any{ | ||
// payload load 4b @ network header + 16 => reg 1 | ||
// (Load the destination IP into register 1) | ||
&expr.Payload{ | ||
DestRegister: 1, | ||
Base: expr.PayloadBaseNetworkHeader, | ||
Offset: 16, | ||
Len: 4, | ||
}, | ||
// cmp eq reg 1 0x01020304 | ||
// (bail if register 1 != 1.2.3.4) | ||
&expr.Cmp{ | ||
Op: expr.CmpOpEq, | ||
Register: 1, | ||
Data: net.ParseIP("1.2.3.4").To4(), | ||
}, | ||
// [ immediate reg 0 drop ] | ||
// (drop the packet) | ||
&expr.Verdict{ | ||
Kind: expr.VerdictDrop, | ||
}, | ||
}, | ||
}) | ||
|
||
if err := c.Flush(); err != nil { | ||
// handle error | ||
} | ||
|
||
``` | ||
|
||
This package is in very early stages, and only contains enough data types and | ||
functions to install very basic nftables rules. It is likely that mistakes with | ||
the data types/API will be identified as more functionality is added. | ||
|
||
## Contributions | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you keep the “Breaking changes” in the heading please? I’d like to have it prominently pointed out.