1

I'm experimenting with eBPF map and I have trouble using values retrieved from eBPF maps in the 'if' clause.

I'm also using BCC to experiment with this code!

So, when I run the code, I try to do this :

BPF_ARRAY(test,u64, 12);
u64 key0 = 0;
u64 test = 1234;
test.update(&key0, &test);

and I have checked after running the code that the 1234 has been appropriately inserted.

and when I try to read the value from the eBPF map and make comparison using 'if', it gives me an error such as :

BPF_ARRAY(test,u64, 12);
u64 key0 = 0;
u64 test = 1234;
test.update(&key0, &test);
u64 comparer = 0;
u64 compared = 1234;
u64 replace_value = 1111;
comparer = test.lookup(&key0);
if (comparer == compared)
    test.update(&key0, &replace_value);

and this gives me an error such as :

R3 type=map_value_or_null expected=fp

I think I'm doing legitimate actions, just reading the value from the eBPF map and comparing it with another value in the kernel space but this doesn't seem to work.

Qeole
  • 8,284
  • 1
  • 24
  • 52
Rosè
  • 345
  • 2
  • 13
  • 2
    `compare` should be `comparer` in your example, right? Also, shouldn't it be a pointer to a `u64` (i.e. `u64 *`) instead of just an integer? You should also mention you are working with bcc. – Qeole Nov 21 '19 at 15:45
  • @Qeole Oh I made a typo copying my code to upload here. i edited them and stated I'm working with BCC :) Oh so the problem should be that I'm using an integer instead of a pointer! I will try to fix the code in that regard! Thanks again for helping me out! – Rosè Nov 21 '19 at 15:54
  • 1
    There *is* an issue with your `comparer` variable's type (it should be `u64 *comparer` and then you should check it's not NULL after lookup), but I don't think that's the issue here. What do you do after `test.update`? – pchaigno Nov 21 '19 at 15:58
  • @pchaigno I only do test.update to verify that my if clause did work and I can read a value from the BPF map in the kernel space. I just inserted it there so when I see '1111' in the BPF map from the user space program, that 'if' clause did work! – Rosè Nov 21 '19 at 15:59
  • @pchaigno Oh yeah! It now works! I think after changing my code to pointers, the problem was like you said, that I didn't check if they're NULL values. They work fine now! – Rosè Nov 21 '19 at 16:10

0 Answers0