0

If in my python bcc program I store information in a pinned map, how can I access it from a separate python program?

So I have this pinned map from the reference guide:

BPF_TABLE_PINNED("hash", u64, u64, ids, 1024, "/sys/fs/bpf/ids");

I already tried accessing it like a normal table but I get a raise key error. There isn't any documentation but I found this example that I don't really understand https://github.com/iovisor/bcc/blame/master/examples/cpp/UseExternalMap.cc

Qeole
  • 8,284
  • 1
  • 24
  • 52
  • Why do you want to pin the map? Is it just to be able to reference it from a second Python program? – pchaigno Jul 15 '21 at 20:43

1 Answers1

0

If you just want to share a BPF map, you can do that in bcc without explicitly pinning the map. In that case, you need to use BPF_TABLE_SHARED and BPF_TABLE("extern". For example (drawn from the BPF project polycube):

# In first program
BPF_TABLE_SHARED("lru_hash", struct st_k, struct st_v, egress_session_table, NAT_MAP_DIM);

# In second program
BPF_TABLE("extern", struct st_k, struct st_v, egress_session_table,
      NAT_MAP_DIM);
pchaigno
  • 11,313
  • 2
  • 29
  • 54