* bpf_xdp_adjust_head Part 2

* Fix csum_diff algorithm to use 1's complement arithmetic.

* treat warning as error
This commit is contained in:
Shankar Seal 2021-09-21 12:03:06 -07:00 коммит произвёл GitHub
Родитель c7d2c2fddf
Коммит 91400e41a2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 71 добавлений и 61 удалений

Просмотреть файл

@ -98,7 +98,7 @@ On the attacker machine, do the following:
1. Start performance monitor and add UDPv4 Datagrams/sec
2. Show that 200K packets per second are being received
3. Show & explain code of droppacket.c
4. Compile droppacket.c ```clang -target bpf -O2 -Wall -c droppacket.c -o droppacket.o```
4. Compile droppacket.c ```clang -target bpf -O2 -Werror -c droppacket.c -o droppacket.o```
5. Show eBPF byte code for droppacket.o ```netsh ebpf show disassembly droppacket.o xdp```
6. Show that the verifier checks the code ```netsh ebpf show verification droppacket.o xdp```
7. Launch netsh ```netsh```
@ -108,7 +108,7 @@ On the attacker machine, do the following:
11. Unload program ```delete program <id>``` where <id> is the ID noted above.
12. Show UDP datagrams received drop to back up to ~200K per second
13. Modify droppacket.c to be unsafe - Comment out line 20 & 21
14. Compile droppacket.c ```clang -target bpf -O2 -Wall -c droppacket.c -o droppacket.o```
14. Compile droppacket.c ```clang -target bpf -O2 -Werror -c droppacket.c -o droppacket.o```
15. Show that the verifier rejects the code ```netsh ebpf show verification droppacket.o xdp```
16. Show that loading the program fails ```netsh ebpf add program droppacket.o xdp```

Просмотреть файл

@ -31,7 +31,7 @@ anything.
**Step 2)** Compile optimized code with clang as follows:
```
> clang -target bpf -Wall -O2 -c bpf.c -o bpf.o
> clang -target bpf -Werror -O2 -c bpf.c -o bpf.o
```
This will compile bpf.c (into bpf.o in this example) using bpf as the assembly format,
@ -61,7 +61,7 @@ for this walkthrough we will put the result into a separate .o file,
bpf-d.o in this example:
```
> clang -target bpf -Wall -g -O2 -c bpf.c -o bpf-d.o
> clang -target bpf -Werror -g -O2 -c bpf.c -o bpf-d.o
```
@ -162,7 +162,7 @@ int anotherfunc()
If we now compile the above code as before we can see the new list of sections.
```
> clang -target bpf -Wall -O2 -c bpf2.c -o bpf2.o
> clang -target bpf -Werror -O2 -c bpf2.c -o bpf2.o
> llvm-objdump --triple=bpf -h bpf2.o
@ -619,7 +619,7 @@ Let's compile it and see what it looks like. Here we compile with `-g`
to include source line info:
```
> clang -target bpf -Wall -g -O2 -c helpers.c -o helpers.o
> clang -target bpf -Werror -g -O2 -c helpers.c -o helpers.o
> llvm-objdump --triple bpf -S helpers.o
@ -702,7 +702,7 @@ happens if we didn't compile with `-O2`? The disassembly looks instead
like this:
```
> clang -target bpf -Wall -g -c helpers.c -o helpers.o
> clang -target bpf -Werror -g -c helpers.c -o helpers.o
> llvm-objdump --triple bpf -S helpers.o
@ -821,7 +821,7 @@ using the map parameters specified. We can see the fields encoded
into the `maps` section as follows:
```
> clang -target bpf -Wall -g -O2 -c maponly.c -o maponly.o
> clang -target bpf -Werror -g -O2 -c maponly.c -o maponly.o
> llvm-objdump -s -section maps maponly.o
maponly.o: file format ELF64-BPF

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT
// clang -O2 -Wall -c bindmonitor.c -o bindmonitor_jit.o
// clang -O2 -Werror -c bindmonitor.c -o bindmonitor_jit.o
//
// For bpf code: clang -target bpf -O2 -Wall -c bindmonitor.c -o bindmonitor.o
// For bpf code: clang -target bpf -O2 -Werror -c bindmonitor.c -o bindmonitor.o
// this passes the checker
#include "bpf_helpers.h"

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT
// clang -O2 -Wall -c divide_by_zero.c -o divide_by_zero_jit.o
// clang -O2 -Werror -c divide_by_zero.c -o divide_by_zero_jit.o
//
// For bpf code: clang -target bpf -O2 -Wall -c divide_by_zero.c -o divide_by_zero.o
// For bpf code: clang -target bpf -O2 -Werror -c divide_by_zero.c -o divide_by_zero.o
// this passes the checker
#include "bpf_helpers.h"

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT
// clang -O2 -Wall -c droppacket.c -o dropjit.o
// clang -O2 -Werror -c droppacket.c -o dropjit.o
//
// For bpf code: clang -target bpf -O2 -Wall -c droppacket.c -o droppacket.o
// For bpf code: clang -target bpf -O2 -Werror -c droppacket.c -o droppacket.o
// this passes the checker
#include "bpf_helpers.h"

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT
// clang -O2 -Wall -c droppacket_unsafe.c -o droppacket_unsafe_jit.o
// clang -O2 -Werror -c droppacket_unsafe.c -o droppacket_unsafe_jit.o
//
// For bpf code: clang -target bpf -O2 -Wall -c droppacket_unsafe.c -o droppacket_unsafe.o
// For bpf code: clang -target bpf -O2 -Werror -c droppacket_unsafe.c -o droppacket_unsafe.o
// this passes the checker
#include "bpf_helpers.h"

Просмотреть файл

@ -9,7 +9,7 @@ encapsulate_ipv4_reflect_packet(xdp_md_t* ctx)
int rc = XDP_DROP;
// Adjust XDP context to allocate space for outer IPv4 header.
if (bpf_xdp_adjust_head(ctx, -sizeof(IPV4_HEADER)) < 0)
if (bpf_xdp_adjust_head(ctx, (int)-sizeof(IPV4_HEADER)) < 0)
goto Done;
// The new ethernet header will be at the beginning of the expanded buffer.
@ -38,12 +38,12 @@ encapsulate_ipv4_reflect_packet(xdp_md_t* ctx)
IPV4_HEADER* inner_ipv4_header = (IPV4_HEADER*)next_header;
// Copy over the old ethernet header to the new one.
memcpy(new_ethernet_header, old_ethernet_header, sizeof(ETHERNET_HEADER));
__builtin_memcpy(new_ethernet_header, old_ethernet_header, sizeof(ETHERNET_HEADER));
// Swap the MAC addresses.
swap_mac_addresses(new_ethernet_header);
// Copy over the inner IP header to the encap IP header.
memcpy(outer_ipv4_header, inner_ipv4_header, sizeof(IPV4_HEADER));
__builtin_memcpy(outer_ipv4_header, inner_ipv4_header, sizeof(IPV4_HEADER));
// Swap the IP addresses.
swap_ipv4_addresses(outer_ipv4_header);
// Adjust header fields.
@ -67,7 +67,7 @@ encapsulate_ipv6_reflect_packet(xdp_md_t* ctx)
int rc = XDP_DROP;
// Adjust XDP context to allocate space for outer IPv6 header.
if (bpf_xdp_adjust_head(ctx, -sizeof(IPV6_HEADER)) < 0)
if (bpf_xdp_adjust_head(ctx, (int)-sizeof(IPV6_HEADER)) < 0)
goto Done;
// The new ethernet header will be at the beginning of the expanded buffer.
@ -96,12 +96,12 @@ encapsulate_ipv6_reflect_packet(xdp_md_t* ctx)
IPV6_HEADER* inner_ipv6_header = (IPV6_HEADER*)next_header;
// Copy over the old ethernet header to the new one.
memcpy(new_ethernet_header, old_ethernet_header, sizeof(ETHERNET_HEADER));
__builtin_memcpy(new_ethernet_header, old_ethernet_header, sizeof(ETHERNET_HEADER));
// Swap the MAC addresses.
swap_mac_addresses(new_ethernet_header);
// Copy over the inner IP header to the encap IP header.
memcpy(outer_ipv6_header, inner_ipv6_header, sizeof(IPV6_HEADER));
__builtin_memcpy(outer_ipv6_header, inner_ipv6_header, sizeof(IPV6_HEADER));
// Swap the IP addresses.
swap_ipv6_addresses(outer_ipv6_header);
// Adjust header fields.

Просмотреть файл

@ -92,42 +92,52 @@
<ItemGroup>
<CustomBuild Include="bindmonitor.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Wall -c %(Filename).c -o %(Filename).o</Command>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatOutputAsContent>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>
<CustomBuild Include="bpf.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Wall -c %(Filename).c -o %(Filename).o</Command>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>
<CustomBuild Include="bpf_call.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Wall -c %(Filename).c -o %(Filename).o</Command>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>
<CustomBuild Include="reflect_packet.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Wall -c %(Filename).c -o %(Filename).o</Command>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -I../xdp -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -I../xdp -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -I../xdp -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -I../xdp -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>
<CustomBuild Include="encap_reflect_packet.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -I../xdp -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -I../xdp -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>
@ -143,21 +153,21 @@
</CustomBuild>
<CustomBuild Include="test_sample_ebpf.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Wall -c %(Filename).c -o %(Filename).o</Command>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -I./ext/inc -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -I./ext/inc -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -I./ext/inc -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -I./ext/inc -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>
<CustomBuild Include="droppacket.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Wall -c %(Filename).c -o %(Filename).o</Command>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>
@ -168,8 +178,8 @@
<ItemGroup>
<CustomBuild Include="divide_by_zero.c">
<FileType>CppCode</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatOutputAsContent>
@ -179,10 +189,10 @@
<ItemGroup>
<CustomBuild Include="droppacket_unsafe.c">
<FileType>CppCode</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatOutputAsContent>
</CustomBuild>
@ -190,8 +200,8 @@
<ItemGroup>
<CustomBuild Include="tail_call.c">
<FileType>CppCode</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatOutputAsContent>
@ -201,8 +211,8 @@
<ItemGroup>
<CustomBuild Include="tail_call_bad.c">
<FileType>CppCode</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatOutputAsContent>
@ -212,8 +222,8 @@
<ItemGroup>
<CustomBuild Include="map_in_map.c">
<FileType>CppCode</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatOutputAsContent>
@ -221,8 +231,8 @@
</CustomBuild>
<CustomBuild Include="tail_call_map.c">
<FileType>CppCode</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
<TreatOutputAsContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</TreatOutputAsContent>
@ -230,11 +240,11 @@
</CustomBuild>
<CustomBuild Include="test_utility_helpers.c">
<FileType>CppCode</FileType>
<Command>clang -target bpf -O2 -Wall -c %(Filename).c -o %(Filename).o</Command>
<Command>clang -target bpf -O2 -Werror -c %(Filename).c -o %(Filename).o</Command>
<Outputs>%(Filename).o;%(Outputs)</Outputs>
<TreatOutputAsContent>true</TreatOutputAsContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Wall -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">clang -g -target bpf -O2 -Werror -I../../include -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)%(Filename).o</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)%(Filename).o</Outputs>
</CustomBuild>

Просмотреть файл

@ -9,9 +9,9 @@ inline void
swap_mac_addresses(ETHERNET_HEADER* ethernet_header)
{
mac_address_t mac = {0};
memcpy(mac, ethernet_header->Destination, sizeof(mac_address_t));
memcpy(ethernet_header->Destination, ethernet_header->Source, sizeof(mac_address_t));
memcpy(ethernet_header->Source, mac, sizeof(mac_address_t));
__builtin_memcpy(mac, ethernet_header->Destination, sizeof(mac_address_t));
__builtin_memcpy(ethernet_header->Destination, ethernet_header->Source, sizeof(mac_address_t));
__builtin_memcpy(ethernet_header->Source, mac, sizeof(mac_address_t));
}
inline void
@ -26,9 +26,9 @@ inline void
swap_ipv6_addresses(IPV6_HEADER* ipv6_header)
{
ipv6_address_t address = {0};
memcpy(address, ipv6_header->DestinationAddress, sizeof(ipv6_address_t));
memcpy(ipv6_header->DestinationAddress, ipv6_header->SourceAddress, sizeof(ipv6_address_t));
memcpy(ipv6_header->SourceAddress, address, sizeof(ipv6_address_t));
__builtin_memcpy(address, ipv6_header->DestinationAddress, sizeof(ipv6_address_t));
__builtin_memcpy(ipv6_header->DestinationAddress, ipv6_header->SourceAddress, sizeof(ipv6_address_t));
__builtin_memcpy(ipv6_header->SourceAddress, address, sizeof(ipv6_address_t));
}
inline int