Skip to content

Commit 5244ee0

Browse files
LorenzoBianconiKernel Patches Daemon
authored andcommitted
netlink: specs: Add XDP RX checksum capability to XDP metadata specs
Introduce XDP RX checksum capability to XDP metadata specs. XDP RX checksum will be use by devices capable of exposing receive checksum result via bpf_xdp_metadata_rx_checksum(). Moreover, introduce xmo_rx_checksum netdev callback in order allow the eBPF program bounded to the device to retrieve the RX checksum result computed by the hw NIC. Signed-off-by: Lorenzo Bianconi <[email protected]>
1 parent 4a6417f commit 5244ee0

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

Documentation/netlink/specs/netdev.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ definitions:
6161
doc: |
6262
Device is capable of exposing receive packet VLAN tag via
6363
bpf_xdp_metadata_rx_vlan_tag().
64+
-
65+
name: checksum
66+
doc: |
67+
Device is capable of exposing receive checksum result via
68+
bpf_xdp_metadata_rx_checksum().
6469
-
6570
type: flags
6671
name: xsk-flags

include/net/xdp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ void xdp_attachment_setup(struct xdp_attachment_info *info,
552552
NETDEV_XDP_RX_METADATA_VLAN_TAG, \
553553
bpf_xdp_metadata_rx_vlan_tag, \
554554
xmo_rx_vlan_tag) \
555+
XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_CHECKSUM, \
556+
NETDEV_XDP_RX_METADATA_CHECKSUM, \
557+
bpf_xdp_metadata_rx_checksum, \
558+
xmo_rx_checksum)
555559

556560
enum xdp_rx_metadata {
557561
#define XDP_METADATA_KFUNC(name, _, __, ___) name,
@@ -609,12 +613,22 @@ enum xdp_rss_hash_type {
609613
XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
610614
};
611615

616+
enum xdp_checksum {
617+
XDP_CHECKSUM_NONE = CHECKSUM_NONE,
618+
XDP_CHECKSUM_UNNECESSARY = CHECKSUM_UNNECESSARY,
619+
XDP_CHECKSUM_COMPLETE = CHECKSUM_COMPLETE,
620+
XDP_CHECKSUM_PARTIAL = CHECKSUM_PARTIAL,
621+
};
622+
612623
struct xdp_metadata_ops {
613624
int (*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
614625
int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash,
615626
enum xdp_rss_hash_type *rss_type);
616627
int (*xmo_rx_vlan_tag)(const struct xdp_md *ctx, __be16 *vlan_proto,
617628
u16 *vlan_tci);
629+
int (*xmo_rx_checksum)(const struct xdp_md *ctx,
630+
enum xdp_checksum *ip_summed,
631+
u32 *cksum_meta);
618632
};
619633

620634
#ifdef CONFIG_NET

net/core/xdp.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,35 @@ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
962962
return -EOPNOTSUPP;
963963
}
964964

965+
/**
966+
* bpf_xdp_metadata_rx_checksum - Read XDP frame RX checksum.
967+
* @ctx: XDP context pointer.
968+
* @ip_summed: Return value pointer indicating checksum result.
969+
* @cksum_meta: Return value pointer indicating checksum result metadata.
970+
*
971+
* In case of success, ``ip_summed`` is set to the RX checksum result. Possible
972+
* values are:
973+
* ``XDP_CHECKSUM_NONE``
974+
* ``XDP_CHECKSUM_UNNECESSARY``
975+
* ``XDP_CHECKSUM_COMPLETE``
976+
* ``XDP_CHECKSUM_PARTIAL``
977+
*
978+
* In case of success, ``cksum_meta`` contains the hw computed checksum value
979+
* for ``XDP_CHECKSUM_COMPLETE`` or the ``csum_level`` for
980+
* ``XDP_CHECKSUM_UNNECESSARY``. It is set to 0 for ``XDP_CHECKSUM_NONE`` and
981+
* ``XDP_CHECKSUM_PARTIAL``.
982+
*
983+
* Return:
984+
* * Returns 0 on success or ``-errno`` on error.
985+
* * ``-EOPNOTSUPP`` : means device driver does not implement kfunc
986+
* * ``-ENODATA`` : means no RX-timestamp available for this frame
987+
*/
988+
__bpf_kfunc int bpf_xdp_metadata_rx_checksum(const struct xdp_md *ctx,
989+
u8 *ip_summed, u32 *cksum_meta)
990+
{
991+
return -EOPNOTSUPP;
992+
}
993+
965994
__bpf_kfunc_end_defs();
966995

967996
BTF_KFUNCS_START(xdp_metadata_kfunc_ids)

0 commit comments

Comments
 (0)