Helper function bpf_load_hdr_opt
Definition
Copyright (c) 2015 The Libbpf Authors. All rights reserved.
Load header option. Support reading a particular TCP header option for bpf program (BPF_PROG_TYPE_SOCK_OPS).
If flags is 0, it will search the option from the skops->skb_data. The comment in struct bpf_sock_ops has details on what skb_data contains under different skops->op.
The first byte of the searchby_res specifies the kind that it wants to search.
If the searching kind is an experimental kind (i.e. 253 or 254 according to RFC6994). It also needs to specify the "magic" which is either 2 bytes or 4 bytes. It then also needs to specify the size of the magic by using the 2nd byte which is "kind-length" of a TCP header option and the "kind-length" also includes the first 2 bytes "kind" and "kind-length" itself as a normal TCP header option also does.
For example, to search experimental kind 254 with 2 byte magic 0xeB9F, the searchby_res should be [ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
To search for the standard window scale option (3), the searchby_res should be [ 3, 0, 0, .... 0 ]. Note, kind-length must be 0 for regular option.
Searching for No-Op (0) and End-of-Option-List (1) are not supported.
len must be at least 2 bytes which is the minimal size of a header option.
Supported flags:
- BPF_LOAD_HDR_OPT_TCP_SYN to search from the saved_syn packet or the just-received syn packet.
Returns
0 when found, the header option is copied to searchby_res. The return value is the total length copied. On failure, a negative error code is returned:
-EINVAL if a parameter is invalid.
-ENOMSG if the option is not found.
-ENOENT if no syn packet is available when BPF_LOAD_HDR_OPT_TCP_SYN is used.
-ENOSPC if there is not enough space. Only len number of bytes are copied.
-EFAULT on failure to parse the header options in the packet.
-EPERM if the helper cannot be used under the current skops->op.
static long (* const bpf_load_hdr_opt)(struct bpf_sock_ops *skops, void *searchby_res, __u32 len, __u64 flags) = (void *) 142;
Usage
Docs could be improved
This part of the docs is incomplete, contributions are very welcome
Program types
This helper call can be used in the following program types:
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome