diff --git a/filter_linux.go b/filter_linux.go index d9aedca..abe1d9b 100644 --- a/filter_linux.go +++ b/filter_linux.go @@ -443,6 +443,8 @@ func parseU32Data(filter Filter, data []syscall.NetlinkRouteAttr) (bool, error) u32.RedirIndex = int(action.Ifindex) } } + case nl.TCA_U32_CLASSID: + u32.ClassId = native.Uint32(datum.Value) } } return detailed, nil diff --git a/filter_test.go b/filter_test.go index dc4ff39..67d9ee9 100644 --- a/filter_test.go +++ b/filter_test.go @@ -51,6 +51,7 @@ func TestFilterAddDel(t *testing.T) { if !ok { t.Fatal("Qdisc is the wrong type") } + classId := MakeHandle(1, 1) filter := &U32{ FilterAttrs: FilterAttrs{ LinkIndex: link.Attrs().Index, @@ -59,6 +60,7 @@ func TestFilterAddDel(t *testing.T) { Protocol: syscall.ETH_P_IP, }, RedirIndex: redir.Attrs().Index, + ClassId: classId, } if err := FilterAdd(filter); err != nil { t.Fatal(err) @@ -70,6 +72,13 @@ func TestFilterAddDel(t *testing.T) { if len(filters) != 1 { 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 { t.Fatal(err) } @@ -296,6 +305,7 @@ func TestFilterU32BpfAddDel(t *testing.T) { if err != nil { t.Skipf("Loading bpf program failed: %s", err) } + classId := MakeHandle(1, 1) filter := &U32{ FilterAttrs: FilterAttrs{ LinkIndex: link.Attrs().Index, @@ -303,7 +313,7 @@ func TestFilterU32BpfAddDel(t *testing.T) { Priority: 1, Protocol: syscall.ETH_P_ALL, }, - ClassId: MakeHandle(1, 1), + ClassId: classId, Actions: []Action{ &BpfAction{Fd: fd, Name: "simple"}, &MirredAction{ @@ -335,6 +345,9 @@ func TestFilterU32BpfAddDel(t *testing.T) { if len(u32.Actions) != 2 { 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) if !ok { t.Fatal("Action[0] is the wrong type")