Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use a struct as a map key in XDP? #410

Open
samueljaydan opened this issue Mar 26, 2024 · 2 comments
Open

Can I use a struct as a map key in XDP? #410

samueljaydan opened this issue Mar 26, 2024 · 2 comments

Comments

@samueljaydan
Copy link

samueljaydan commented Mar 26, 2024

Is it possible to create a struct as shown below in the XDP part and use it as a key, then write to this map in the packet processor part?

Note: Packet processor is being writing GoLang language.

BPF_MAP_DEF(blacklistmap) = {
    .map_type = BPF_MAP_TYPE_HASH,
    .key_size = sizeof(struct flowblack),
    .value_size = sizeof(int),  // Change value size to sizeof(__u64)
    .max_entries = MAX_RULES,
};
BPF_MAP_ADD(blacklistmap);

struct flowblack {
    __u16 sourceport;
    __u16 destport;
    __u32 saddr;
    __u32 daddr;
};

int xdp_dump(struct xdp_md *ctx) {
// ....
    struct flowblack key = {0};
    key.sourceport = tcp->source;
    key.destport = tcp->dest;
    key.saddr = ip->saddr;
    key.daddr = ip->daddr;
    
    __u64 *rule_idx = bpf_map_lookup_elem(&blacklistmap, &key);
    if (rule_idx) {
        return XDP_DROP;   
    }
// ....
}
@tohojo
Copy link
Member

tohojo commented Apr 4, 2024 via email

@samueljaydan
Copy link
Author

I did, but no succeeded. I've changed the topology using AF_SOCKET. So no need to use it anymore.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants