1 // Copyright (c) PLUMgrid, Inc. 2 // Licensed under the Apache License, Version 2.0 (the "License") 3 #include <bcc/proto.h> 4 5 // physical endpoint manager (pem) tables which connects VMs and bridges 6 // <ifindex_in, ifindex_out> 7 BPF_HASH(pem_dest, u32, u32, 256); 8 // <0, tx_pkts> 9 BPF_ARRAY(pem_stats, u32, 1); 10 11 int pem(struct __sk_buff *skb) { 12 u32 ifindex_in, *ifindex_p; 13 u8 *cursor = 0; 14 struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet)); 15 16 ifindex_in = skb->ingress_ifindex; 17 ifindex_p = pem_dest.lookup(&ifindex_in); 18 if (ifindex_p) { 19 #if 1 20 if (ethernet->type == 0x0800 || ethernet->type == 0x0806) { 21 /* accumulate stats */ 22 u32 index = 0; 23 u32 *value = pem_stats.lookup(&index); 24 if (value) 25 lock_xadd(value, 1); 26 } 27 #endif 28 bpf_clone_redirect(skb, *ifindex_p, 0); 29 } 30 31 return 1; 32 } 33