csocketsnetwork-programmingopenonload

Solarflare ef vi how to sniff TCP packet to a specific port?


{
    in_addr addr;
    EFVI_CHECK(::inet_aton("11.231.75.7", &addr));

    ef_filter_spec filter_spec;
    ef_filter_spec_init(&filter_spec, EF_FILTER_FLAG_NONE);

    ef_filter_spec_set_ip4_local(&filter_spec, IPPROTO_TCP, addr.s_addr, htons(21723));
    ef_vi_filter_add(&res_.vi, res_.dh, &filter_spec, nullptr);
}

{
    // problem is here
    ef_filter_spec filter_spec;
    ef_filter_spec_init(&filter_spec, EF_FILTER_FLAG_NONE);
    
    ef_filter_spec_set_port_sniff(&filter_spec, 0);
    ef_vi_filter_add(&res_.vi, res_.dh, &filter_spec, nullptr);
}

I'm trying to sniff packets sent to a specific netword card at a specific port using Solarflare ef_vi API.

However, when I use ef_filter_spec_set_port_sniff(&filter_spec, 0), it actually sniff all packets received at that netword card. Basically the previous filters are ignored.

When I use ef_filter_spec_set_ip4_local alone, it intercepts the packet instead of sniffing (i.e the packet isn't sent to the kernel).

How can I do this with ef_vi?


Solution

  • what you can do is to interpret all the packets and process only packets matched your port. As far as I know, there is no way to sniff to a specific port using ef_vi APIs.