Skip to content

Commit

Permalink
Add support for additional TC BPF filter attributes
Browse files Browse the repository at this point in the history
In order to support BPF_SYSCALL `PROG_GET_FD_BY_ID` -- the ID of the
eBPF must be available.

Add the additional enumerations and handle them when parsing the BPF
filter.
  • Loading branch information
Farid Zakaria authored and aboch committed Jul 1, 2019
1 parent a824196 commit 2e4a68e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
2 changes: 2 additions & 0 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ type BpfFilter struct {
Fd int
Name string
DirectAction bool
Id int
Tag string
}

func (filter *BpfFilter) Type() string {
Expand Down
5 changes: 5 additions & 0 deletions filter_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package netlink
import (
"bytes"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"syscall"
Expand Down Expand Up @@ -627,6 +628,10 @@ func parseBpfData(filter Filter, data []syscall.NetlinkRouteAttr) (bool, error)
if (flags & nl.TCA_BPF_FLAG_ACT_DIRECT) != 0 {
bpf.DirectAction = true
}
case nl.TCA_BPF_ID:
bpf.Id = int(native.Uint32(datum.Value[0:4]))
case nl.TCA_BPF_TAG:
bpf.Tag = hex.EncodeToString(datum.Value[:len(datum.Value)-1])
}
}
return detailed, nil
Expand Down
5 changes: 4 additions & 1 deletion nl/tc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,10 @@ const (
TCA_BPF_FD
TCA_BPF_NAME
TCA_BPF_FLAGS
TCA_BPF_MAX = TCA_BPF_FLAGS
TCA_BPF_FLAGS_GEN
TCA_BPF_TAG
TCA_BPF_ID
TCA_BPF_MAX = TCA_BPF_ID
)

type TcBpf TcGen
Expand Down

0 comments on commit 2e4a68e

Please sign in to comment.