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

Function TestObjAPI

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

Source from the content-addressed store, hash-verified

2625}
2626
2627func TestObjAPI(t *testing.T) {
2628 if os.Getenv("TRAVIS") == "true" {
2629 t.SkipNow()
2630 }
2631
2632 // Create a new network namespace to test these operations,
2633 // and tear down the namespace at test completion.
2634 c, newNS := nftest.OpenSystemConn(t, *enableSysTests)
2635 defer nftest.CleanupSystemConn(t, newNS)
2636
2637 // Clear all rules at the beginning + end of the test.
2638 c.FlushRuleset()
2639 defer c.FlushRuleset()
2640
2641 table := c.AddTable(&nftables.Table{
2642 Family: nftables.TableFamilyIPv4,
2643 Name: "filter",
2644 })
2645
2646 tableOther := c.AddTable(&nftables.Table{
2647 Family: nftables.TableFamilyIPv4,
2648 Name: "foo",
2649 })
2650
2651 chain := c.AddChain(&nftables.Chain{
2652 Name: "chain",
2653 Table: table,
2654 Type: nftables.ChainTypeFilter,
2655 Hooknum: nftables.ChainHookPostrouting,
2656 Priority: nftables.ChainPriorityFilter,
2657 })
2658
2659 counter1 := c.AddObj(&nftables.NamedObj{
2660 Table: table,
2661 Name: "fwded1",
2662 Type: nftables.ObjTypeCounter,
2663 Obj: &expr.Counter{
2664 Bytes: 1,
2665 Packets: 1,
2666 },
2667 })
2668
2669 counter2 := c.AddObj(&nftables.NamedObj{
2670 Table: table,
2671 Name: "fwded2",
2672 Type: nftables.ObjTypeCounter,
2673 Obj: &expr.Counter{
2674 Bytes: 1,
2675 Packets: 1,
2676 },
2677 })
2678
2679 c.AddObj(&nftables.NamedObj{
2680 Table: tableOther,
2681 Name: "fwdedOther",
2682 Type: nftables.ObjTypeCounter,
2683 Obj: &expr.Counter{
2684 Bytes: 0,

Callers

nothing calls this directly

Calls 13

OpenSystemConnFunction · 0.92
CleanupSystemConnFunction · 0.92
FlushRulesetMethod · 0.80
AddTableMethod · 0.80
AddChainMethod · 0.80
AddObjMethod · 0.80
AddRuleMethod · 0.80
FlushMethod · 0.80
GetObjectsMethod · 0.80
GetObjectMethod · 0.80
ResetObjectMethod · 0.80
GetObjMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…