mirror of https://github.com/vishvananda/netlink
Add class ID parsing to parseU32Data
This patch adds a new switch case that handles the class ID attribute of the U32 filter data listed by FilterList. Without this case block the class ID of the U32 filter is always set to zero. The new test conditions are added to TestFilterAddDel and TestFilterU32BpfAddDel in filter_test.go as well. Signed-off-by: Taku Fukushima <taku@soracom.jp>
This commit is contained in:
parent
aec6f885c2
commit
1b53666767
|
@ -443,6 +443,8 @@ func parseU32Data(filter Filter, data []syscall.NetlinkRouteAttr) (bool, error)
|
||||||
u32.RedirIndex = int(action.Ifindex)
|
u32.RedirIndex = int(action.Ifindex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case nl.TCA_U32_CLASSID:
|
||||||
|
u32.ClassId = native.Uint32(datum.Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return detailed, nil
|
return detailed, nil
|
||||||
|
|
|
@ -51,6 +51,7 @@ func TestFilterAddDel(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("Qdisc is the wrong type")
|
t.Fatal("Qdisc is the wrong type")
|
||||||
}
|
}
|
||||||
|
classId := MakeHandle(1, 1)
|
||||||
filter := &U32{
|
filter := &U32{
|
||||||
FilterAttrs: FilterAttrs{
|
FilterAttrs: FilterAttrs{
|
||||||
LinkIndex: link.Attrs().Index,
|
LinkIndex: link.Attrs().Index,
|
||||||
|
@ -59,6 +60,7 @@ func TestFilterAddDel(t *testing.T) {
|
||||||
Protocol: syscall.ETH_P_IP,
|
Protocol: syscall.ETH_P_IP,
|
||||||
},
|
},
|
||||||
RedirIndex: redir.Attrs().Index,
|
RedirIndex: redir.Attrs().Index,
|
||||||
|
ClassId: classId,
|
||||||
}
|
}
|
||||||
if err := FilterAdd(filter); err != nil {
|
if err := FilterAdd(filter); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -70,6 +72,13 @@ func TestFilterAddDel(t *testing.T) {
|
||||||
if len(filters) != 1 {
|
if len(filters) != 1 {
|
||||||
t.Fatal("Failed to add filter")
|
t.Fatal("Failed to add filter")
|
||||||
}
|
}
|
||||||
|
u32, ok := filters[0].(*U32)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("Filter is the wrong type")
|
||||||
|
}
|
||||||
|
if u32.ClassId != classId {
|
||||||
|
t.Fatalf("ClassId of the filter is the wrong value")
|
||||||
|
}
|
||||||
if err := FilterDel(filter); err != nil {
|
if err := FilterDel(filter); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -296,6 +305,7 @@ func TestFilterU32BpfAddDel(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Skipf("Loading bpf program failed: %s", err)
|
t.Skipf("Loading bpf program failed: %s", err)
|
||||||
}
|
}
|
||||||
|
classId := MakeHandle(1, 1)
|
||||||
filter := &U32{
|
filter := &U32{
|
||||||
FilterAttrs: FilterAttrs{
|
FilterAttrs: FilterAttrs{
|
||||||
LinkIndex: link.Attrs().Index,
|
LinkIndex: link.Attrs().Index,
|
||||||
|
@ -303,7 +313,7 @@ func TestFilterU32BpfAddDel(t *testing.T) {
|
||||||
Priority: 1,
|
Priority: 1,
|
||||||
Protocol: syscall.ETH_P_ALL,
|
Protocol: syscall.ETH_P_ALL,
|
||||||
},
|
},
|
||||||
ClassId: MakeHandle(1, 1),
|
ClassId: classId,
|
||||||
Actions: []Action{
|
Actions: []Action{
|
||||||
&BpfAction{Fd: fd, Name: "simple"},
|
&BpfAction{Fd: fd, Name: "simple"},
|
||||||
&MirredAction{
|
&MirredAction{
|
||||||
|
@ -335,6 +345,9 @@ func TestFilterU32BpfAddDel(t *testing.T) {
|
||||||
if len(u32.Actions) != 2 {
|
if len(u32.Actions) != 2 {
|
||||||
t.Fatalf("Too few Actions in filter")
|
t.Fatalf("Too few Actions in filter")
|
||||||
}
|
}
|
||||||
|
if u32.ClassId != classId {
|
||||||
|
t.Fatalf("ClassId of the filter is the wrong value")
|
||||||
|
}
|
||||||
bpfAction, ok := u32.Actions[0].(*BpfAction)
|
bpfAction, ok := u32.Actions[0].(*BpfAction)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("Action[0] is the wrong type")
|
t.Fatal("Action[0] is the wrong type")
|
||||||
|
|
Loading…
Reference in New Issue