|
4 | 4 | * Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc. |
5 | 5 | */ |
6 | 6 | #include <linux/bpf.h> |
| 7 | +#include <linux/btf_ids.h> |
7 | 8 | #include <linux/filter.h> |
8 | 9 | #include <linux/types.h> |
9 | 10 | #include <linux/mm.h> |
@@ -709,3 +710,66 @@ struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf) |
709 | 710 |
|
710 | 711 | return nxdpf; |
711 | 712 | } |
| 713 | + |
| 714 | +__diag_push(); |
| 715 | +__diag_ignore_all("-Wmissing-prototypes", |
| 716 | + "Global functions as their definitions will be in vmlinux BTF"); |
| 717 | + |
| 718 | +/** |
| 719 | + * bpf_xdp_metadata_rx_timestamp - Read XDP frame RX timestamp. |
| 720 | + * @ctx: XDP context pointer. |
| 721 | + * @timestamp: Return value pointer. |
| 722 | + * |
| 723 | + * Returns 0 on success or ``-errno`` on error. |
| 724 | + */ |
| 725 | +int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp) |
| 726 | +{ |
| 727 | + return -EOPNOTSUPP; |
| 728 | +} |
| 729 | + |
| 730 | +/** |
| 731 | + * bpf_xdp_metadata_rx_hash - Read XDP frame RX hash. |
| 732 | + * @ctx: XDP context pointer. |
| 733 | + * @hash: Return value pointer. |
| 734 | + * |
| 735 | + * Returns 0 on success or ``-errno`` on error. |
| 736 | + */ |
| 737 | +int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash) |
| 738 | +{ |
| 739 | + return -EOPNOTSUPP; |
| 740 | +} |
| 741 | + |
| 742 | +__diag_pop(); |
| 743 | + |
| 744 | +BTF_SET8_START(xdp_metadata_kfunc_ids) |
| 745 | +#define XDP_METADATA_KFUNC(_, name) BTF_ID_FLAGS(func, name, 0) |
| 746 | +XDP_METADATA_KFUNC_xxx |
| 747 | +#undef XDP_METADATA_KFUNC |
| 748 | +BTF_SET8_END(xdp_metadata_kfunc_ids) |
| 749 | + |
| 750 | +static const struct btf_kfunc_id_set xdp_metadata_kfunc_set = { |
| 751 | + .owner = THIS_MODULE, |
| 752 | + .set = &xdp_metadata_kfunc_ids, |
| 753 | +}; |
| 754 | + |
| 755 | +BTF_ID_LIST(xdp_metadata_kfunc_ids_unsorted) |
| 756 | +#define XDP_METADATA_KFUNC(name, str) BTF_ID(func, str) |
| 757 | +XDP_METADATA_KFUNC_xxx |
| 758 | +#undef XDP_METADATA_KFUNC |
| 759 | + |
| 760 | +u32 bpf_xdp_metadata_kfunc_id(int id) |
| 761 | +{ |
| 762 | + /* xdp_metadata_kfunc_ids is sorted and can't be used */ |
| 763 | + return xdp_metadata_kfunc_ids_unsorted[id]; |
| 764 | +} |
| 765 | + |
| 766 | +bool bpf_dev_bound_kfunc_id(u32 btf_id) |
| 767 | +{ |
| 768 | + return btf_id_set8_contains(&xdp_metadata_kfunc_ids, btf_id); |
| 769 | +} |
| 770 | + |
| 771 | +static int __init xdp_metadata_init(void) |
| 772 | +{ |
| 773 | + return register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &xdp_metadata_kfunc_set); |
| 774 | +} |
| 775 | +late_initcall(xdp_metadata_init); |
0 commit comments