Adding entries to map

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear all,

Hello. We are trying to create a map with multiple entries for destination mac addresses (order of millions). Firstly, we want to know if that can be done in XDP as BPF will not allow loops.

   Here is what we have tried so far.

      /* construct key */
      struct dstmactable_key key = {};
      key.field0 = hd.ethernet.destination;

      /* value */
struct dstmactable_value new_value = { .action = Fallback_action, };
      /* add key / value pair to table*/
      bpf_map_update_elem(&dstmactable, &key, &new_value, BPF_ANY);

We do this for every packet and expectedly, the lookup is a hit for every packet (each packet has the same dest address, although even with random addresses, the result is the same). We wish to add the entries statically before the program starts processing packets as an init() function. Where in the program should we write and call such a function?

Secondly, how can such a table be reset / deleted. If we run the following code (after commenting the addition of the new entries), we get a hit i.e. the HIT variable = 1. On rebooting the machine, it prints HIT = 0. The code is as follows:


accept:
    {
        u8 hit;
        {
/* dstmactable.apply()*/
            {
 /* construct key */
//              struct dstmactable_key new_key = {};
//              new_key.field0 = 41014;
//
//              /* value */
// struct dstmactable_value new_value = { .action = Fallback_action, };
//              /* add key / value pair to table*/
// bpf_map_update_elem(&dstmactable, &new_key, &new_value, BPF_ANY);

                /* construct key */
                struct dstmactable_key key = {};
                key.field0 = hd.ethernet.destination;
                //key.field1 = hd.ethernet.etherType;
                /* value */
                struct dstmactable_value *value = NULL;
                /* perform lookup */
                value = bpf_map_lookup_elem(&dstmactable, &key);
                if (value == NULL) {
                    /* miss; find default action */
                    hit = 0;
                    //printk("Hit = %d, value = NULL\n", hit);
value = bpf_map_lookup_elem(&dstmactable_defaultAction, &ebpf_zero);
                } else {
                    hit = 1;
                    //printk("Hit = %d, value != NULL\n", hit);
                }
                if (value != NULL) {
                    /* run action */
                    switch (value->action) {
                        case Fallback_action:
                        {
//printk("Hit = %d, Fallback action\n", hit);
                                xout.output_action = XDP_TX;
                        }
                        break;
                        case Drop_action:
                        {
//printk("Hit = %d, Drop action\n", hit);
                                xout.output_action = XDP_DROP;
                        }
                        break;
                        default: return XDP_ABORTED;
                    }
                }
                else return XDP_ABORTED;
            }

Please guide us regarding the two queries we have in this regard. We eagerly await your response.

Thank you,
Sincerely,



[Index of Archives]     [Linux Networking Development]     [Fedora Linux Users]     [Linux SCTP]     [DCCP]     [Gimp]     [Yosemite Campsites]

  Powered by Linux