Skip to content
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

XDP declarations are moved from ebpf_nethooks.h. #3793

Merged
merged 18 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ structure which contains an arbitrary amount of data. (Tail calls to
programs can have more than one argument, but hooks put all the info in a
hook-specific context structure passed as one argument.)

The "xdp_test" hook point has the following prototype in `ebpf_nethooks.h`:
The "xdp_test" hook point has the following prototype in `net_ebpf_ext_xdp_hooks.h`:

```c
typedef struct xdp_md
Expand All @@ -517,6 +517,7 @@ A sample eBPF program might look like this:
```c
#include "bpf_helpers.h"
#include "ebpf_nethooks.h"
#include "net_ebpf_ext_xdp_hooks.h"

// Put "xdp_test" in the section name to specify XDP_TEST as the hook.
// The SEC macro below has the same effect as the
Expand Down
54 changes: 0 additions & 54 deletions include/ebpf_nethooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,10 @@
// This file contains APIs for hooks and helpers that are
// exposed by netebpfext.sys for use by eBPF programs.

// XDP_TEST hook. We use "struct xdp_md" for cross-platform compatibility.
typedef struct xdp_md_
{
void* data; ///< Pointer to start of packet data.
void* data_end; ///< Pointer to end of packet data.
uint64_t data_meta; ///< Packet metadata.
uint32_t ingress_ifindex; ///< Ingress interface index.

/* size: 26, cachelines: 1, members: 4 */
/* last cacheline: 26 bytes */
} xdp_md_t;

typedef enum _xdp_action
{
XDP_PASS = 1, ///< Allow the packet to pass.
XDP_DROP, ///< Drop the packet.
XDP_TX ///< Bounce the received packet back out the same NIC it arrived on.
} xdp_action_t;

/**
* @brief Handle an incoming packet as early as possible.
*
* Program type: \ref EBPF_PROGRAM_TYPE_XDP_TEST
*
* @param[in] context Packet metadata.
* @retval XDP_PASS Allow the packet to pass.
* @retval XDP_DROP Drop the packet.
* @retval XDP_TX Bounce the received packet back out the same NIC it arrived on.
*/
typedef xdp_action_t
xdp_hook_t(xdp_md_t* context);

// XDP_TEST helper functions.
#define XDP_EXT_HELPER_FN_BASE 0xFFFF

#ifndef __doxygen
#define EBPF_HELPER(return_type, name, args) typedef return_type(*const name##_t) args
#endif

typedef enum
{
BPF_FUNC_xdp_adjust_head = XDP_EXT_HELPER_FN_BASE + 1,
} ebpf_nethook_helper_id_t;

/**
* @brief Adjust XDP_TEST context data pointer.
*
* @param[in] ctx XDP_TEST context.
* @param[in] delta Number of bytes to move the data pointer by.
*
* @retval 0 The operation was successful.
* @retval <0 A failure occurred.
*/
EBPF_HELPER(int, bpf_xdp_adjust_head, (xdp_md_t * ctx, int delta));
#ifndef __doxygen
#define bpf_xdp_adjust_head ((bpf_xdp_adjust_head_t)BPF_FUNC_xdp_adjust_head)
#endif

// BIND hook

typedef enum _bind_operation
Expand Down
1 change: 1 addition & 0 deletions netebpfext/net_ebpf_ext_program_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ebpf_nethooks.h"
#include "ebpf_program_types.h"
#include "ebpf_shared_framework.h"
#include "net_ebpf_ext_xdp_hooks.h"

#define XDP_EXT_HELPER_FUNCTION_START EBPF_MAX_GENERAL_HELPER_FUNCTION

Expand Down
65 changes: 65 additions & 0 deletions netebpfext/net_ebpf_ext_xdp_hooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) eBPF for Windows contributors
// SPDX-License-Identifier: MIT
#pragma once
#include <stdint.h>

// This file contains APIs for hooks and helpers that are
// exposed by netebpfext.sys for use by eBPF xdp test programs.

// XDP_TEST hook.
typedef struct xdp_md_
{
void* data; ///< Pointer to start of packet data.
void* data_end; ///< Pointer to end of packet data.
uint64_t data_meta; ///< Packet metadata.
uint32_t ingress_ifindex; ///< Ingress interface index.

/* size: 26, cachelines: 1, members: 4 */
/* last cacheline: 26 bytes */
} xdp_md_t;

typedef enum _xdp_action
{
XDP_PASS = 1, ///< Allow the packet to pass.
XDP_DROP, ///< Drop the packet.
XDP_TX ///< Bounce the received packet back out the same NIC it arrived on.
} xdp_action_t;

/**
* @brief Handle an incoming packet as early as possible.
*
* Program type: \ref EBPF_PROGRAM_TYPE_XDP_TEST
*
* @param[in] context Packet metadata.
* @retval XDP_PASS Allow the packet to pass.
* @retval XDP_DROP Drop the packet.
* @retval XDP_TX Bounce the received packet back out the same NIC it arrived on.
*/
typedef xdp_action_t
xdp_hook_t(xdp_md_t* context);

// XDP_TEST helper functions.
#define XDP_EXT_HELPER_FN_BASE 0xFFFF

#ifndef __doxygen
#define EBPF_HELPER(return_type, name, args) typedef return_type(*const name##_t) args
#endif

typedef enum
{
BPF_FUNC_xdp_adjust_head = XDP_EXT_HELPER_FN_BASE + 1,
} ebpf_nethook_helper_id_t;

/**
* @brief Adjust XDP_TEST context data pointer.
*
* @param[in] ctx XDP_TEST context.
* @param[in] delta Number of bytes to move the data pointer by.
*
* @retval 0 The operation was successful.
* @retval <0 A failure occurred.
*/
EBPF_HELPER(int, bpf_xdp_adjust_head, (xdp_md_t * ctx, int delta));
#ifndef __doxygen
#define bpf_xdp_adjust_head ((bpf_xdp_adjust_head_t)BPF_FUNC_xdp_adjust_head)
#endif
Loading
Loading