tools/testing/selftests/bpf/progs/xsk_xdp_progs.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/xsk_xdp_progs.c
Extension
.c
Size
2992 bytes
Lines
126
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret == -EOPNOTSUPP) {
			/* Set adjust_value to -EOPNOTSUPP to indicate to userspace that this case
			 * is unsupported
			 */
			adjust_value = -EOPNOTSUPP;
			return bpf_redirect_map(&xsk, 0, XDP_DROP);
		}

		return XDP_DROP;
	}

	curr_buff_len = bpf_xdp_get_buff_len(xdp);
	if (curr_buff_len != buff_len + adjust_value)
		return XDP_DROP;

	if (curr_buff_len > buff_len) {
		__u32 *pkt_data = (void *)(long)xdp->data;
		__u32 len, words_to_end, seq_num;

		len = curr_buff_len - PKT_HDR_ALIGN;
		words_to_end = len / sizeof(*pkt_data) - 1;
		seq_num = words_to_end;

		/* Convert sequence number to network byte order. Store this in the last 4 bytes of
		 * the packet. Use 'adjust_value' to determine the position at the end of the
		 * packet for storing the sequence number.
		 */
		seq_num = __constant_htonl(words_to_end);
		bpf_xdp_store_bytes(xdp, curr_buff_len - sizeof(seq_num), &seq_num,
				    sizeof(seq_num));
	}

	return bpf_redirect_map(&xsk, 0, XDP_DROP);
}

char _license[] SEC("license") = "GPL";

Annotation

Implementation Notes