|
9 | 9 | "testing"
|
10 | 10 | "time"
|
11 | 11 |
|
12 |
| - "github.com/vishvananda/netlink/nl" |
13 | 12 | "golang.org/x/sys/unix"
|
| 13 | + |
| 14 | + "github.com/vishvananda/netlink/nl" |
14 | 15 | )
|
15 | 16 |
|
16 | 17 | func TestFilterAddDel(t *testing.T) {
|
@@ -2097,6 +2098,79 @@ func TestFilterIPv6FlowerPedit(t *testing.T) {
|
2097 | 2098 | }
|
2098 | 2099 | }
|
2099 | 2100 |
|
| 2101 | +func TestFilterU32PeditAddDel(t *testing.T) { |
| 2102 | + tearDown := setUpNetlinkTest(t) |
| 2103 | + defer tearDown() |
| 2104 | + |
| 2105 | + qdisc, link := setupLinkForTestWithQdisc(t, "foo") |
| 2106 | + |
| 2107 | + classId := MakeHandle(1, 1) |
| 2108 | + filter := &U32{ |
| 2109 | + FilterAttrs: FilterAttrs{ |
| 2110 | + LinkIndex: link.Attrs().Index, |
| 2111 | + Parent: qdisc.Attrs().Handle, |
| 2112 | + Priority: 1, |
| 2113 | + Protocol: unix.ETH_P_ALL, |
| 2114 | + }, |
| 2115 | + ClassId: classId, |
| 2116 | + } |
| 2117 | + |
| 2118 | + dstIP := net.ParseIP("172.17.0.2") |
| 2119 | + peditAction := NewPeditAction() |
| 2120 | + peditAction.Proto = uint8(nl.IPPROTO_TCP) |
| 2121 | + peditAction.DstIP = dstIP |
| 2122 | + filter.Actions = append(filter.Actions, peditAction) |
| 2123 | + |
| 2124 | + if err := FilterAdd(filter); err != nil { |
| 2125 | + t.Fatal(err) |
| 2126 | + } |
| 2127 | + |
| 2128 | + filters, err := FilterList(link, qdisc.Attrs().Handle) |
| 2129 | + if err != nil { |
| 2130 | + t.Fatal(err) |
| 2131 | + } |
| 2132 | + if len(filters) != 1 { |
| 2133 | + t.Fatal("Failed to add filter") |
| 2134 | + } |
| 2135 | + u32, ok := filters[0].(*U32) |
| 2136 | + if !ok { |
| 2137 | + t.Fatal("Filter is the wrong type") |
| 2138 | + } |
| 2139 | + |
| 2140 | + if len(u32.Actions) != 1 { |
| 2141 | + t.Fatalf("Too few Actions in filter") |
| 2142 | + } |
| 2143 | + |
| 2144 | + pedit, ok := u32.Actions[0].(*PeditAction) |
| 2145 | + if !ok { |
| 2146 | + t.Fatal("action is the wrong type") |
| 2147 | + } |
| 2148 | + if !pedit.DstIP.Equal(dstIP) { |
| 2149 | + t.Fatal("dstIP is wrong") |
| 2150 | + } |
| 2151 | + |
| 2152 | + if err := FilterDel(filter); err != nil { |
| 2153 | + t.Fatal(err) |
| 2154 | + } |
| 2155 | + filters, err = FilterList(link, qdisc.Attrs().Handle) |
| 2156 | + if err != nil { |
| 2157 | + t.Fatal(err) |
| 2158 | + } |
| 2159 | + if len(filters) != 0 { |
| 2160 | + t.Fatal("Failed to remove filter") |
| 2161 | + } |
| 2162 | + |
| 2163 | + if err := QdiscDel(qdisc); err != nil { |
| 2164 | + t.Fatal(err) |
| 2165 | + } |
| 2166 | + qdiscs, err := SafeQdiscList(link) |
| 2167 | + if err != nil { |
| 2168 | + t.Fatal(err) |
| 2169 | + } |
| 2170 | + if len(qdiscs) != 0 { |
| 2171 | + t.Fatal("Failed to remove qdisc") |
| 2172 | + } |
| 2173 | +} |
2100 | 2174 | func TestFilterU32PoliceAddDel(t *testing.T) {
|
2101 | 2175 | tearDown := setUpNetlinkTest(t)
|
2102 | 2176 | defer tearDown()
|
|
0 commit comments