On Mon, Sep 21, 2026 at 12:32 AM Weiming Shi <[email protected]> wrote:
> Select the reset layout from the protocol callback which consumes the
> packet: the original family for BPF_OK and unsupported redirects, or the
> new family for supported reroute and redirect paths. Preserve the ingress
> interface and L3-slave state from the restored original control block and
> initialize the IPv6 next-header offset when needed. Save and restore the
> marker around nested LWT runs.

What Daniel sketched in v2 was 20 lines. This is still an overkill.

[...]

> +static void bpf_lwt_reset_cb(struct sk_buff *skb, __be16 orig_proto,
> +                          bool use_new_proto)
> +{
> +     __be16 cb_proto = use_new_proto ? skb->protocol : orig_proto;
> +     int iif = skb->skb_iif;
> +     bool l3slave = false;
> +
> +     /* VRF may have replaced skb_iif with the master device index. */
> +     if (orig_proto == htons(ETH_P_IP)) {
> +             iif = IPCB(skb)->iif;
> +             l3slave = ipv4_l3mdev_skb(IPCB(skb)->flags);



When the family doesn't change only IPCB(skb)->opt is stale.
Clear just that like ip_tunnel_xmit() and udp_tunnel_xmit_skb() do.
iif and flags stay as they are and the VRF special casing goes away.
When the family changes do what seg6_do_srh_encap() does.

[...]

> +     use_new_proto = (ret == BPF_LWT_REROUTE &&
> +                      lwt->prog->type != BPF_PROG_TYPE_LWT_OUT) ||
> +                     (ret == BPF_REDIRECT && can_redirect);
> +     if (lwt_ip_encap)
> +             bpf_lwt_reset_cb(skb, orig_proto, use_new_proto);

Not needed. BPF_OK after the prog changed the family is broken no
matter which layout the cb has. bpf_xmit() drops such skb and
bpf_input() hands a v6 packet to ip_forward().
Use skb->protocol.

pw-bot: cr

Reply via email to