MCPcopy Create free account
hub / github.com/google/nftables / TestCreateListFlowtableWithDevices

Function TestCreateListFlowtableWithDevices

nftables_test.go:4179–4243  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4177}
4178
4179func TestCreateListFlowtableWithDevices(t *testing.T) {
4180 c, newNS := nftest.OpenSystemConn(t, *enableSysTests)
4181 defer nftest.CleanupSystemConn(t, newNS)
4182 c.FlushRuleset()
4183 defer c.FlushRuleset()
4184
4185 filter := &nftables.Table{
4186 Family: nftables.TableFamilyIPv4,
4187 Name: "filter",
4188 }
4189
4190 lo, err := net.InterfaceByName("lo")
4191 if err != nil {
4192 t.Fatalf("net.InterfaceByName() failed: %v", err)
4193 }
4194
4195 flowtable := &nftables.Flowtable{
4196 Table: filter,
4197 Name: "flowtable_test",
4198 Devices: []string{lo.Name},
4199 Hooknum: nftables.FlowtableHookIngress,
4200 Priority: nftables.FlowtablePriorityRef(5),
4201 }
4202
4203 c.AddTable(filter)
4204 c.AddFlowtable(flowtable)
4205
4206 if err := c.Flush(); err != nil {
4207 t.Fatalf("c.Flush() failed: %v", err)
4208 }
4209
4210 flowtables, err := c.ListFlowtables(filter)
4211 if err != nil {
4212 t.Fatalf("c.ListFlowtables() failed: %v", err)
4213 }
4214
4215 if got, want := len(flowtables), 1; got != want {
4216 t.Fatalf("flowtable entry length mismatch: got %d, want %d", got, want)
4217 }
4218
4219 sysFlowtable := flowtables[0]
4220 if got, want := sysFlowtable.Table, flowtable.Table; got != want {
4221 t.Errorf("flowtables table mismatch: got %v, want %v", got, want)
4222 }
4223
4224 if got, want := sysFlowtable.Name, flowtable.Name; got != want {
4225 t.Errorf("flowtables name mismatch: got %s, want %s", got, want)
4226 }
4227
4228 if len(sysFlowtable.Devices) != 1 {
4229 t.Fatalf("expected 1 device in flowtable, got %d", len(sysFlowtable.Devices))
4230 }
4231
4232 if got, want := sysFlowtable.Devices, flowtable.Devices; !reflect.DeepEqual(got, want) {
4233 t.Errorf("flowtables device mismatch: got %v, want %v", got, want)
4234 }
4235
4236 if got, want := *sysFlowtable.Hooknum, *flowtable.Hooknum; got != want {

Callers

nothing calls this directly

Calls 8

OpenSystemConnFunction · 0.92
CleanupSystemConnFunction · 0.92
FlowtablePriorityRefFunction · 0.92
FlushRulesetMethod · 0.80
AddTableMethod · 0.80
AddFlowtableMethod · 0.80
FlushMethod · 0.80
ListFlowtablesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…