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

Function TestGetRulesQueue

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

Source from the content-addressed store, hash-verified

7649}
7650
7651func TestGetRulesQueue(t *testing.T) {
7652 // Create a new network namespace to test these operations,
7653 // and tear down the namespace at test completion.
7654 c, newNS := nftest.OpenSystemConn(t, *enableSysTests)
7655 defer nftest.CleanupSystemConn(t, newNS)
7656 // Clear all rules at the beginning + end of the test.
7657 c.FlushRuleset()
7658 defer c.FlushRuleset()
7659
7660 table := c.AddTable(&nftables.Table{
7661 Family: nftables.TableFamilyIPv4,
7662 Name: "filter",
7663 })
7664
7665 chain := c.AddChain(&nftables.Chain{
7666 Name: "forward",
7667 Table: table,
7668 Type: nftables.ChainTypeFilter,
7669 Hooknum: nftables.ChainHookForward,
7670 Priority: nftables.ChainPriorityFilter,
7671 })
7672
7673 queueRule := c.AddRule(&nftables.Rule{
7674 Table: table,
7675 Chain: chain,
7676 Exprs: []expr.Any{
7677 &expr.Queue{
7678 Num: 1000,
7679 Flag: expr.QueueFlagBypass,
7680 },
7681 },
7682 })
7683
7684 if err := c.Flush(); err != nil {
7685 t.Errorf("c.Flush() failed: %v", err)
7686 }
7687
7688 rules, err := c.GetRules(table, chain)
7689 if err != nil {
7690 t.Fatal(err)
7691 }
7692
7693 if got, want := len(rules), 1; got != want {
7694 t.Fatalf("unexpected number of rules: got %d, want %d", got, want)
7695 }
7696 if got, want := len(rules[0].Exprs), 1; got != want {
7697 t.Fatalf("unexpected number of exprs: got %d, want %d", got, want)
7698 }
7699 queueExpr, ok := rules[0].Exprs[0].(*expr.Queue)
7700 if !ok {
7701 t.Fatalf("Exprs[0] is type %T, want *expr.Queue", rules[0].Exprs[0])
7702 }
7703 if want := queueRule.Exprs[0]; !reflect.DeepEqual(queueExpr, want) {
7704 t.Errorf("queue expr = %+v, wanted %+v", queueExpr, want)
7705 }
7706}
7707
7708func TestNftablesCompat(t *testing.T) {

Callers

nothing calls this directly

Calls 8

OpenSystemConnFunction · 0.92
CleanupSystemConnFunction · 0.92
FlushRulesetMethod · 0.80
AddTableMethod · 0.80
AddChainMethod · 0.80
AddRuleMethod · 0.80
FlushMethod · 0.80
GetRulesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…