Skip to content

Helper function bpf_fib_lookup

v4.18

Definition

Copyright (c) 2015 The Libbpf Authors. All rights reserved.

Do FIB lookup in kernel tables using parameters in params. If lookup is successful and result shows packet is to be forwarded, the neighbor tables are searched for the nexthop. If successful (ie., FIB lookup shows forwarding and nexthop is resolved), the nexthop address is returned in ipv4_dst or ipv6_dst based on family, smac is set to mac address of egress device, dmac is set to nexthop mac address, rt_metric is set to metric from route (IPv4/IPv6 only), and ifindex is set to the device index of the nexthop from the FIB lookup.

plen argument is the size of the passed in struct. flags argument can be a combination of one or more of the following values:

BPF_FIB_LOOKUP_DIRECT

    Do a direct table lookup vs full lookup using FIB rules.

BPF_FIB_LOOKUP_TBID

    Used with BPF_FIB_LOOKUP_DIRECT. Use the routing table ID present in params->tbid for the fib lookup.

BPF_FIB_LOOKUP_OUTPUT

    Perform lookup from an egress perspective (default is ingress).

BPF_FIB_LOOKUP_SKIP_NEIGH

    Skip the neighbour table lookup. params->dmac and params->smac will not be set as output. A common use case is to call bpf_redirect_neigh() after doing bpf_fib_lookup().

BPF_FIB_LOOKUP_SRC

    Derive and set source IP addr in params->ipv{4,6}src for the nexthop. If the src addr cannot be derived, BPF_FIB_LKUP_RET_NO_SRC_ADDR is returned. In this case, _params->dmac and params->smac are not set either.

BPF_FIB_LOOKUP_MARK

    Use the mark present in params->mark for the fib lookup. This option should not be used with BPF_FIB_LOOKUP_DIRECT, as it only has meaning for full lookups.

ctx is either struct xdp_md for XDP programs or struct sk_buff tc cls_act programs.

Returns

  • < 0 if any input argument is invalid
  • 0 on success (packet is forwarded, nexthop neighbor exists)
  • 0 one of BPF_FIB_LKUP_RET_ codes explaining why the packet is not forwarded or needs assist from full stack

If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU was exceeded and output params->mtu_result contains the MTU.

static long (* const bpf_fib_lookup)(void *ctx, struct bpf_fib_lookup *params, int plen, __u32 flags) = (void *) 69;

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