XDP-Newbies Archive mirror
 help / color / mirror / Atom feed
From: Vincent Li <vincent.mc.li@gmail.com>
To: xdp-newbies@vger.kernel.org
Subject: R6 invalid mem access 'inv'
Date: Mon, 14 Jun 2021 09:52:32 -0700 (PDT)	[thread overview]
Message-ID: <d85bbf6-282e-b197-4cd4-7677c4c201@gmail.com> (raw)

Hi,

I am newbie to BPF and I have a consistent "R6 invalid mem access 'inv'" 
error in issue https://github.com/cilium/cilium/issues/16517 when 
attempting to rewrite the skb destination MAC address. I am guessing I 
could be missing something basic and not nessarily related to Cilium. 
This is xdp newbie list, but by any chance, anyone could point out where I 
did wrong, I have tried three variant of patches there and I get same "R6 
invalid mem access 'inv'" error at bpf load and verifier time.

one of the patch is simply to hard code the MAC as below, but still got 
the invalid mem access error

diff --git a/bpf/lib/common.h b/bpf/lib/common.h
index 3e1b11a5f..c6e980776 100644
--- a/bpf/lib/common.h
+++ b/bpf/lib/common.h
@@ -23,6 +23,7 @@
  * #endif
  */
 #define NEEDS_TIMEOUT 1
+#define VTEP_MAC  { .addr = { 0xce, 0x72, 0xa7, 0x03, 0x88, 0x58 } }
 
 #ifndef AF_INET
 #define AF_INET 2
diff --git a/bpf/lib/encap.h b/bpf/lib/encap.h
index dfd87bd82..044579b00 100644
--- a/bpf/lib/encap.h
+++ b/bpf/lib/encap.h
@@ -119,6 +119,7 @@ __encap_with_nodeid(struct __ctx_buff *ctx, __u32 
tunnel_endpoint,
        struct bpf_tunnel_key key = {};
        __u32 node_id;
        int ret;
+       union macaddr vtep_mac = VTEP_MAC;
 
        /* When encapsulating, a packet originating from the local host is
         * being considered as a packet from a remote node as it is being
@@ -137,6 +138,8 @@ __encap_with_nodeid(struct __ctx_buff *ctx, __u32 
tunnel_endpoint,
        ret = ctx_set_tunnel_key(ctx, &key, sizeof(key), 
BPF_F_ZERO_CSUM_TX);
        if (unlikely(ret < 0))
                return DROP_WRITE_ERROR;
+       if (eth_store_daddr(ctx, (__u8 *) &vtep_mac.addr, 0) < 0)
+                return DROP_WRITE_ERROR;
 
        send_trace_notify(ctx, TRACE_TO_OVERLAY, seclabel, 0, 0, 
ENCAP_IFINDEX,
                          0, monitor);
 

                 reply	other threads:[~2021-06-14 16:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d85bbf6-282e-b197-4cd4-7677c4c201@gmail.com \
    --to=vincent.mc.li@gmail.com \
    --cc=xdp-newbies@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).