|
| 1 | +# -*- fill-column: 76; -*- |
| 2 | +#+TITLE: Tutorial: Packet - solutions |
| 3 | +#+OPTIONS: ^:nil |
| 4 | + |
| 5 | +This directory contains solutions to all the assignments in the |
| 6 | +[[file:../basic01-xdp-pass/][basic01]], |
| 7 | +[[file:../basic02-prog-by-name/][basic02]], |
| 8 | +[[file:../basic03-map-counter/][basic03]], and |
| 9 | +[[file:../basic04-pinning-maps/][basic04]] lessons. |
| 10 | + |
| 11 | +* Table of Contents :TOC: |
| 12 | +- [[#solutions][Solutions]] |
| 13 | + - [[#basic01-loading-your-first-bpf-program][Basic01: loading your first BPF program]] |
| 14 | + - [[#basic02-loading-a-program-by-name][Basic02: loading a program by name]] |
| 15 | + - [[#basic03-counting-with-bpf-maps][Basic03: counting with BPF maps]] |
| 16 | + - [[#basic04-pinning-of-maps][Basic04: pinning of maps]] |
| 17 | + |
| 18 | +* Solutions |
| 19 | + |
| 20 | +** Basic01: loading your first BPF program |
| 21 | + |
| 22 | +This lesson doesn't contain any assignments except to repeat the steps listed |
| 23 | +in the lesson readme file. |
| 24 | + |
| 25 | +** Basic02: loading a program by name |
| 26 | + |
| 27 | +*** Assignment 1: Setting up your test lab |
| 28 | + |
| 29 | +No code is needed, just repeat the steps listed in the assignment description. |
| 30 | + |
| 31 | +*** Assignment 2: Add xdp_abort program |
| 32 | + |
| 33 | +Just add the following section to the |
| 34 | +[[file:../basic02-prog-by-name/xdp_prog_kern.c][xdp_prog_kern.c]] program and |
| 35 | +follow the steps listed in the assignment description: |
| 36 | +#+begin_example c |
| 37 | +SEC("xdp_abort") |
| 38 | +int xdp_abort_func(struct xdp_md *ctx) |
| 39 | +{ |
| 40 | + return XDP_ABORTED; |
| 41 | +} |
| 42 | +#+end_example |
| 43 | + |
| 44 | +** Basic03: counting with BPF maps |
| 45 | + |
| 46 | +The solutions to all three assignments can be found in the following files: |
| 47 | + |
| 48 | + * The [[file:../basic04-pinning-maps/common_kern_user.h][common_kern_user.h]] file contains the new structure =datarec= definition. |
| 49 | + * The [[file:../basic04-pinning-maps/xdp_prog_kern.c][xdp_prog_kern.c]] file contains the new =xdp_stats_map= map definition and the updated =xdp_stats_record_action= function. |
| 50 | + |
| 51 | +Note that for use in later lessons/assignments the code was moved to the following files: |
| 52 | +[[file:../common/xdp_stats_kern_user.h][xdp_stats_kern_user.h]] and |
| 53 | +[[file:../common/xdp_stats_kern.h][xdp_stats_kern.h]]. So in order to use the |
| 54 | +=xdp_stats_record_action= function in later XDP programs, just include the |
| 55 | +following header files: |
| 56 | +#+begin_example c |
| 57 | +#include "../common/xdp_stats_kern_user.h" |
| 58 | +#include "../common/xdp_stats_kern.h" |
| 59 | +#+end_example |
| 60 | +For a user-space application, only the former header is needed. |
| 61 | + |
| 62 | +** Basic04: pinning of maps |
| 63 | + |
| 64 | +*** Assignment 1: (xdp_stats.c) reload map file-descriptor |
| 65 | + |
| 66 | +TBD |
| 67 | + |
| 68 | +*** Assignment 2: (xdp_loader.c) reuse pinned map |
| 69 | + |
| 70 | +TBD |
0 commit comments