New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sock and skb matchArgs selectors #1008
Conversation
02cd33f
to
3b15e91
Compare
for the code LGTM. |
I wouldn't block this PR but MATCH_MAX_ARGS should probably be resolved at some point. One idea would be to use a read-only map and walk it with a proper for loop on newer kernels. Then you could have a map sized as large as needed to fit the args. |
I think the solution was to put the matchargs in a hash and then look up the arg to see if it's there. I'm going to convert all matchArgs over. |
3b15e91
to
ddcb476
Compare
✅ Deploy Preview for tetragon ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
72de723
to
98ff038
Compare
Currently we retrieve port numbers on struct sock and struct sk_buff types in their native endianness (typically network order, but see later). We then convert the endianness to host order (assuming host order is little endian) in golang before printing them out. In order to support the option to match on port numbers in BPF, we should convert them to host order endianness (using bpf_ntohs) at the point that we read them. In addition, while both source and dest ports in sk_buff are in network order, the source port in struct sock is in host order, leading to a bug where the source port was reported incorrectly. This commit converts port numbers to host order in BPF at the point of retrieval, and removes the endianness swap in golang. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
72d80b7
to
b01ed0e
Compare
Both the sock and skb types contain an IPv4 tuple. In preparation for matching on aspects of the tuple (and for IPv6 tuples), extract the tuple as its own type and share it across both sock and skb types. Also, fix reading the protocol on kernels <v5.6 where the protocol field in struct sock is 8 bits of a u32. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
The sock type converts the protocol number to the corresponding string when it outputs the message. The skb type does not do this. Add the protocol string field to the skb type (it currently has an int proto field) and populate it. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
Allow sock and skb argument types to match on source and destination IPv4 address and port, and also on protocol. New operators added: SAddr, DAddr, SPort, DPort, Protocol. Each can match multiple values. See examples/tracingpolicy/tcp-connect.yaml and datagram.yaml for examples. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
Add a sock test that matches on a TCP connection to 127.0.0.1:2112 and a skb test that matches on a UDP connection to 127.0.0.1:53. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
b01ed0e
to
06bed45
Compare
Tetragon can specify arguments of type sock and skb, but doesn't have the ability to match on these (complex) arguments. This series adds selector operators: SAddr, DAddr, SPort, DPort, and Protocol. These can be used to match on either sock or skb types. See commits for details.