Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.org

Tutorial: Packet - solutions

This directory contains solutions to all the assignments in the basic01, basic02, basic03, and basic04 lessons.

Table of Contents

Solutions

Basic01: loading your first BPF program

This lesson doesn’t contain any assignments except to repeat the steps listed in the lesson readme file.

Basic02: loading a program by name

Assignment 1: Setting up your test lab

No code is needed, just repeat the steps listed in the assignment description.

Assignment 2: Add xdp_abort program

Just add the following section to the xdp_prog_kern.c program and follow the steps listed in the assignment description:

SEC("xdp_abort") int xdp_abort_func(struct xdp_md *ctx) { return XDP_ABORTED; } 

Basic03: counting with BPF maps

The solutions to all three assignments can be found in the following files:

  • The common_kern_user.h file contains the new structure datarec definition.
  • The xdp_prog_kern.c file contains the new xdp_stats_map map definition and the updated xdp_stats_record_action function.

Note that for use in later lessons/assignments the code was moved to the following files: xdp_stats_kern_user.h and xdp_stats_kern.h. So in order to use the xdp_stats_record_action function in later XDP programs, just include the following header files:

#include "../common/xdp_stats_kern_user.h" #include "../common/xdp_stats_kern.h" 

For a user-space application, only the former header is needed.

Basic04: pinning of maps

Assignment 1: (xdp_stats.c) reload map file-descriptor

See the xdp_stats.c program in this directory.

Assignment 2: (xdp_loader.c) reuse pinned map

See the xdp_loader.c program in this directory.