Commit b27b6ce2 authored by Joanne Hugé's avatar Joanne Hugé

filter packet on ether type

parent b730271d
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <immintrin.h> #include <immintrin.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <linux/filter.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h> #include <linux/if_packet.h>
#include <math.h> #include <math.h>
#include <netdb.h> #include <netdb.h>
...@@ -709,6 +711,19 @@ int start(TRXEcpriState * s) { ...@@ -709,6 +711,19 @@ int start(TRXEcpriState * s) {
log_debug("TRX_ECPRI", "raw socket setup"); log_debug("TRX_ECPRI", "raw socket setup");
/* From the example above: tcpdump -i em1 port 22 -dd */
struct sock_filter code[] = {
{ 0x28, 0, 0, 0x0000000c },
{ 0x15, 0, 1, 0x0000aefe },
{ 0x06, 0, 0, 0x00040000 },
{ 0x06, 0, 0, 0x00000000 },
};
struct sock_fprog bpf = {
.len = 4,
.filter = code,
};
//set_latency_target(); //set_latency_target();
tx_seq_id = 0; tx_seq_id = 0;
...@@ -779,7 +794,16 @@ int start(TRXEcpriState * s) { ...@@ -779,7 +794,16 @@ int start(TRXEcpriState * s) {
return 1; return 1;
} }
// Only receive incoming packets, don't capture packets we are sending // Only receive incoming packets, don't capture packets we are sending
setsockopt(recv_sockfd, SOL_PACKET, PACKET_IGNORE_OUTGOING, &(int){1}, sizeof(int)); if(setsockopt(recv_sockfd, SOL_PACKET, PACKET_IGNORE_OUTGOING, &(int){1}, sizeof(int))) {
perror("setsockopt PACKET_IGNORE_OUTGOING: ");
return 1;
}
// Filter on MAC ADDRESS
if (setsockopt(recv_sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf))) {
perror("setsockopt SO_ATTACH_FILTER: ");
return 1;
}
connect_sk_addr.sll_ifindex = if_index; connect_sk_addr.sll_ifindex = if_index;
connect_sk_addr.sll_halen = ETH_ALEN; connect_sk_addr.sll_halen = ETH_ALEN;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment