(t *testing.T)
| 1915 | } |
| 1916 | |
| 1917 | func TestAddRuleWithPosition(t *testing.T) { |
| 1918 | want := [][]byte{ |
| 1919 | // batch begin |
| 1920 | []byte("\x00\x00\x00\x0a"), |
| 1921 | // nft add rule ip ipv4table ipv4chain-1 position 2 ip version 6 |
| 1922 | []byte("\x02\x00\x00\x00\x0e\x00\x01\x00\x69\x70\x76\x34\x74\x61\x62\x6c\x65\x00\x00\x00\x10\x00\x02\x00\x69\x70\x76\x34\x63\x68\x61\x69\x6e\x2d\x31\x00\xa8\x00\x04\x80\x34\x00\x01\x80\x0c\x00\x01\x00\x70\x61\x79\x6c\x6f\x61\x64\x00\x24\x00\x02\x80\x08\x00\x01\x00\x00\x00\x00\x01\x08\x00\x02\x00\x00\x00\x00\x01\x08\x00\x03\x00\x00\x00\x00\x00\x08\x00\x04\x00\x00\x00\x00\x01\x44\x00\x01\x80\x0c\x00\x01\x00\x62\x69\x74\x77\x69\x73\x65\x00\x34\x00\x02\x80\x08\x00\x01\x00\x00\x00\x00\x01\x08\x00\x02\x00\x00\x00\x00\x01\x08\x00\x03\x00\x00\x00\x00\x01\x0c\x00\x04\x80\x05\x00\x01\x00\xf0\x00\x00\x00\x0c\x00\x05\x80\x05\x00\x01\x00\x00\x00\x00\x00\x2c\x00\x01\x80\x08\x00\x01\x00\x63\x6d\x70\x00\x20\x00\x02\x80\x08\x00\x01\x00\x00\x00\x00\x01\x08\x00\x02\x00\x00\x00\x00\x00\x0c\x00\x03\x80\x05\x00\x01\x00\x60\x00\x00\x00\x0c\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x02"), |
| 1923 | // batch end |
| 1924 | []byte("\x00\x00\x00\x0a"), |
| 1925 | } |
| 1926 | |
| 1927 | c, err := nftables.New(nftables.WithTestDial( |
| 1928 | func(req []netlink.Message) ([]netlink.Message, error) { |
| 1929 | for idx, msg := range req { |
| 1930 | b, err := msg.MarshalBinary() |
| 1931 | if err != nil { |
| 1932 | t.Fatal(err) |
| 1933 | } |
| 1934 | if len(b) < 16 { |
| 1935 | continue |
| 1936 | } |
| 1937 | b = b[16:] |
| 1938 | if len(want) == 0 { |
| 1939 | t.Errorf("no want entry for message %d: %x", idx, b) |
| 1940 | continue |
| 1941 | } |
| 1942 | if got, want := b, want[0]; !bytes.Equal(got, want) { |
| 1943 | t.Errorf("message %d: %s", idx, linediff(nfdump(got), nfdump(want))) |
| 1944 | } |
| 1945 | want = want[1:] |
| 1946 | } |
| 1947 | return req, nil |
| 1948 | })) |
| 1949 | if err != nil { |
| 1950 | t.Fatal(err) |
| 1951 | } |
| 1952 | |
| 1953 | c.AddRule(&nftables.Rule{ |
| 1954 | Position: 2, |
| 1955 | Table: &nftables.Table{Name: "ipv4table", Family: nftables.TableFamilyIPv4}, |
| 1956 | Chain: &nftables.Chain{ |
| 1957 | Name: "ipv4chain-1", |
| 1958 | Type: nftables.ChainTypeFilter, |
| 1959 | Hooknum: nftables.ChainHookPrerouting, |
| 1960 | Priority: nftables.ChainPriorityRef(0), |
| 1961 | }, |
| 1962 | |
| 1963 | Exprs: []expr.Any{ |
| 1964 | // [ payload load 1b @ network header + 0 => reg 1 ] |
| 1965 | &expr.Payload{ |
| 1966 | DestRegister: 1, |
| 1967 | Base: expr.PayloadBaseNetworkHeader, |
| 1968 | Offset: 0, // Offset for a transport protocol header |
| 1969 | Len: 1, // 1 bytes for port |
| 1970 | }, |
| 1971 | // [ bitwise reg 1 = (reg=1 & 0x000000f0 ) ^ 0x00000000 ] |
| 1972 | &expr.Bitwise{ |
| 1973 | SourceRegister: 1, |
| 1974 | DestRegister: 1, |
nothing calls this directly
no test coverage detected
searching dependent graphs…