-
Notifications
You must be signed in to change notification settings - Fork 730
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
Complete ipv6 support #1204
Complete ipv6 support #1204
Conversation
Add a new ipv6addr struct which contains the 16 bytes of the ip address as 4 uint32_ts. It also has methods for comparisons and subnet checks. Also add new PPM types PT_IPV6ADDR/PT_IPV6NET as well as a general PT_IPADDR/PT_IPNET type. The general types will be used for things like filterchecks where they operate interchangeably on ipv4/ipv6 addresses.
Fully support ipv6 addresses in sinsp_network_interfaces. When storing an ipv6 interface, use the new explicit type ipv6addr instead of 16-byte arrays. Also only save the network portion in a single ipv6 address. Add methods import_ipv6_interface, is_ipv6addr_in_local_machine, infer_ipv6_address, which are used by update_fd to update sinsp_fdinfo structs based on interface information.
Handle PT_IPV6ADDR as a type in string conversions to/from rawvals, both directly and into the lua stack. Generally it's just inet_pton/inet_ntop on the bytes in the ipv6addr struct. Also handle comparisons on PT_IPV6ADDR/PT_IPV6NET, using the equality and netmast comparison operators on the struct. To handle conversion/comparisons for PT_IPADDR/PT_IPNET, use the size of the rawval to determine if it's an ipv4 or ipv6 address and call comparison/converson method again with PT_IPV6ADDR/PT_IPV4ADDR as appropriate. For strings, infer the type based on whether the string has '.' or ':' characters. This required a change to the methods to take the param type/format instead of a filtercheck_field_info, as there are other uses that don't have a filtercheck_field_info.
86301b0
to
4a838c8
Compare
In get_thread_table_int, support SCAP_FD_IPV6 types, grabbing the right part of the sockinfo struct and doing the right conversion for the address family. Add a default column width for ipv6 addresses.
Change all fd.ip/fd.net filterchecks to work on PT_IPADDR types instead. When extracting, add tests for SCAP_FD_IPV6_* types and extract the right part of the sockinfo struct. Comparisons/conversion is already handled by the rawval_to_string changes that handle PT_IPADDR/PT_IPNET types.
Instead of simply handling ipv4 mapped ipv6 addresses, handle any ipv6 address, filling in the right part of the sockinfo struct from the event parameter. Also handle source/dest swapping when determining the client/server endpoints of a connection. Conversions that used to work simply on an ipv6 address as byte array now work on the m_b field of the ipv6addr struct.
The documentation of fd.typechar doesn't distinguish between server sockets and non-server sockets, so simplify things by simply using '4'/'6' to reflect the ipv4/ipv6 type.
In cases where a chisel's filter was specific to ipv4, also allow ipv6.
bc85317
to
d134f3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great set of changes! I just have a minor question, but lgtm.
// (http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses) | ||
// | ||
uint8_t* sip = packed_data + 1; | ||
uint8_t* dip = packed_data + 19; | ||
|
||
if(!(sinsp_utils::is_ipv4_mapped_ipv6(sip) && sinsp_utils::is_ipv4_mapped_ipv6(dip))) | ||
{ | ||
evt->m_fdinfo->m_name = evt->get_param_as_str(1, &parstr, sinsp_evt::PF_SIMPLE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose setting m_fdinfo->m_name
is no longer needed here because we are properly setting the sockinfo, so the flow will be the same as v4 sockets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. The name eventually gets set at line 2486, and both ipv6 and ipv4 follow the same steps of possibly swapping the client/server addresses.
c7e5ba8
to
c8db291
Compare
These were returning pointers to local string values on the stack. Replace with m_tstr, a general purpose string in the object, instead.
2941f8d
to
0ea289b
Compare
Note the 1 new commit that fixes returning some variables from the stack. |
Changes to round out ipv6 support in parsing/filterchecks. The kernel module and libscap already had the necessary components but there were some gaps in filterchecks/event parsing/etc support.
There are corresponding unit tests on the agent side for all of these changes.