Skip to content

Commit

Permalink
Ether and IPv6 was not set appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
ami-GS committed Apr 24, 2024
1 parent eebc505 commit 4eda469
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 19 deletions.
20 changes: 20 additions & 0 deletions src/generated/linux/datapath_raw_xdp_linux.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,26 @@ tracepoint(CLOG_DATAPATH_RAW_XDP_LINUX_C, XdpDeletePortFails , arg2, arg3);\



/*----------------------------------------------------------
// Decoder Ring for XdpSetIpFails
// [ xdp] Failed to set ipv4 %s on %s
// QuicTraceLogVerbose(
XdpSetIpFails,
"[ xdp] Failed to set ipv4 %s on %s",
inet_ntoa(Interface->Ipv4Address),
Interface->IfName);
// arg2 = arg2 = inet_ntoa(Interface->Ipv4Address) = arg2
// arg3 = arg3 = Interface->IfName = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_XdpSetIpFails
#define _clog_4_ARGS_TRACE_XdpSetIpFails(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_DATAPATH_RAW_XDP_LINUX_C, XdpSetIpFails , arg2, arg3);\

#endif




/*----------------------------------------------------------
// Decoder Ring for XdpSetIfnameFails
// [ xdp] Failed to set ifname %s on %s
Expand Down
23 changes: 23 additions & 0 deletions src/generated/linux/datapath_raw_xdp_linux.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,29 @@ TRACEPOINT_EVENT(CLOG_DATAPATH_RAW_XDP_LINUX_C, XdpDeletePortFails,



/*----------------------------------------------------------
// Decoder Ring for XdpSetIpFails
// [ xdp] Failed to set ipv4 %s on %s
// QuicTraceLogVerbose(
XdpSetIpFails,
"[ xdp] Failed to set ipv4 %s on %s",
inet_ntoa(Interface->Ipv4Address),
Interface->IfName);
// arg2 = arg2 = inet_ntoa(Interface->Ipv4Address) = arg2
// arg3 = arg3 = Interface->IfName = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_DATAPATH_RAW_XDP_LINUX_C, XdpSetIpFails,
TP_ARGS(
const char *, arg2,
const char *, arg3),
TP_FIELDS(
ctf_string(arg2, arg2)
ctf_string(arg3, arg3)
)
)



/*----------------------------------------------------------
// Decoder Ring for XdpSetIfnameFails
// [ xdp] Failed to set ifname %s on %s
Expand Down
21 changes: 21 additions & 0 deletions src/manifest/clog.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -12594,6 +12594,22 @@
],
"macroName": "QuicTraceLogVerbose"
},
"XdpSetIpFails": {
"ModuleProperites": {},
"TraceString": "[ xdp] Failed to set ipv4 %s on %s",
"UniqueId": "XdpSetIpFails",
"splitArgs": [
{
"DefinationEncoding": "s",
"MacroVariableName": "arg2"
},
{
"DefinationEncoding": "s",
"MacroVariableName": "arg3"
}
],
"macroName": "QuicTraceLogVerbose"
},
"XdpSetPortFails": {
"ModuleProperites": {},
"TraceString": "[ xdp] Failed to set port %d on %s",
Expand Down Expand Up @@ -17198,6 +17214,11 @@
"TraceID": "XdpSetIfnameFails",
"EncodingString": "[ xdp] Failed to set ifname %s on %s"
},
{
"UniquenessHash": "3920ec7a-fd58-050b-a020-e91a02d8c2d3",
"TraceID": "XdpSetIpFails",
"EncodingString": "[ xdp] Failed to set ipv4 %s on %s"
},
{
"UniquenessHash": "f209f7d4-9287-cfed-6abd-bfcd201e5ee7",
"TraceID": "XdpSetPortFails",
Expand Down
54 changes: 35 additions & 19 deletions src/platform/datapath_raw_xdp_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,22 @@ CxPlatDpRawGetDatapathSize(
return sizeof(XDP_DATAPATH) + (PartitionCount * sizeof(XDP_PARTITION));
}

void ProcessInterfaceAddress(int family, struct ifaddrs *ifa, XDP_INTERFACE *Interface) {
if (family == AF_INET) {
struct sockaddr_in *addr_in = (struct sockaddr_in *)ifa->ifa_addr;
Interface->Ipv4Address = addr_in->sin_addr;
} else if (family == AF_INET6) {
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)ifa->ifa_addr;
if (addr_in6->sin6_scope_id == if_nametoindex(ifa->ifa_name)) {
return;
}
memcpy(&Interface->Ipv6Address, &addr_in6->sin6_addr, sizeof(struct in6_addr));
} else if (family == AF_PACKET) {
struct sockaddr_ll *sall = (struct sockaddr_ll*)ifa->ifa_addr;
memcpy(Interface->PhysicalAddress, sall->sll_addr, sizeof(Interface->PhysicalAddress));
}
}

_IRQL_requires_max_(PASSIVE_LEVEL)
QUIC_STATUS
CxPlatDpRawInitialize(
Expand Down Expand Up @@ -706,19 +722,7 @@ CxPlatDpRawInitialize(

if (strcmp(Interface->IfName, ifa->ifa_name) == 0) {
Initialized = true;
if (family == AF_INET) {
struct sockaddr_in *addr_in = (struct sockaddr_in *)ifa->ifa_addr;
Interface->Ipv4Address = addr_in->sin_addr;
} else if (family == AF_INET6) {
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)ifa->ifa_addr;
if (addr_in6->sin6_scope_id == if_nametoindex(ifa->ifa_name)) {
break;
}
memcpy(&Interface->Ipv6Address, &addr_in6->sin6_addr, sizeof(struct in6_addr));
} else if (family == AF_PACKET) {
struct sockaddr_ll *sall = (struct sockaddr_ll*)ifa->ifa_addr;
memcpy(Interface->PhysicalAddress, sall->sll_addr, sizeof(Interface->PhysicalAddress));
}
ProcessInterfaceAddress(family, ifa, Interface);
break;
}
}
Expand All @@ -736,6 +740,7 @@ CxPlatDpRawInitialize(
CxPlatZeroMemory(Interface, sizeof(*Interface));
memcpy(Interface->IfName, ifa->ifa_name, sizeof(Interface->IfName));
Interface->IfIndex = if_nametoindex(ifa->ifa_name);
ProcessInterfaceAddress(family, ifa, Interface);

if (QUIC_FAILED(CxPlatDpRawInterfaceInitialize(
Xdp, Interface, ClientRecvContextLength))) {
Expand Down Expand Up @@ -953,12 +958,23 @@ CxPlatDpRawPlumbRulesOnSocket(
if (ip_map) {
__u8 ipv_data[16] = {0};
if (IsCreated) {
if (QuicAddrGetFamily(&Socket->LocalAddress) == QUIC_ADDRESS_FAMILY_INET) {
memcpy(ipv_data, &Interface->Ipv4Address.s_addr, 4);
bpf_map_update_elem(bpf_map__fd(ip_map), &IPv4Key, ipv_data, BPF_ANY);
} else {
memcpy(ipv_data, &Interface->Ipv6Address.s6_addr, sizeof(ipv_data));
bpf_map_update_elem(bpf_map__fd(ip_map), &IPv6Key, ipv_data, BPF_ANY);
memcpy(ipv_data, &Interface->Ipv4Address.s_addr, 4);
if (bpf_map_update_elem(bpf_map__fd(ip_map), &IPv4Key, ipv_data, BPF_ANY)) {
QuicTraceLogVerbose(
XdpSetIpFails,
"[ xdp] Failed to set ipv4 %s on %s",
inet_ntoa(Interface->Ipv4Address),
Interface->IfName);
}
memcpy(ipv_data, &Interface->Ipv6Address.s6_addr, sizeof(ipv_data));
if (bpf_map_update_elem(bpf_map__fd(ip_map), &IPv6Key, ipv_data, BPF_ANY)) {
char str_ipv6[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &Interface->Ipv6Address, str_ipv6, sizeof(str_ipv6));
QuicTraceLogVerbose(
XdpSetIpFails,
"[ xdp] Failed to set ipv6 %s on %s",
str_ipv6,
Interface->IfName);
}
} else {
bpf_map_update_elem(bpf_map__fd(ip_map), &IPv4Key, ipv_data, BPF_ANY);
Expand Down

0 comments on commit 4eda469

Please sign in to comment.