Skip to content

Commit

Permalink
sock: Fix capturing extra packets from other dev
Browse files Browse the repository at this point in the history
Create PF_PACKET socket with proto=0 which does not setup packet handler
and will not capture packets until bind() will be invoked.

Also replaced pf_tx_socket by pf_socket as these funcs became the same,
as proto arg is set to 0.

Suggested-by: Daniel Borkmann <borkmann@iogearbox.net>
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
vkochan authored and tklauser committed May 6, 2015
1 parent d8f6f82 commit 096b043
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 12 deletions.
11 changes: 1 addition & 10 deletions sock.c
Expand Up @@ -25,19 +25,10 @@ int af_socket(int af)
}

int pf_socket(void)
{
int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (unlikely(sock < 0))
panic("Creation of PF socket failed: %s\n", strerror(errno));

return sock;
}

int pf_tx_socket(void)
{
int sock = socket(PF_PACKET, SOCK_RAW, 0);
if (unlikely(sock < 0))
panic("Creation of PF TX socket failed: %s\n", strerror(errno));
panic("Creation of PF socket failed: %s\n", strerror(errno));

return sock;
}
Expand Down
1 change: 0 additions & 1 deletion sock.h
Expand Up @@ -3,7 +3,6 @@

extern int af_socket(int af);
extern int pf_socket(void);
extern int pf_tx_socket(void);
extern void set_nonblocking(int fd);
extern int set_nonblocking_sloppy(int fd);
extern int set_reuseaddr(int fd);
Expand Down
2 changes: 1 addition & 1 deletion trafgen.c
Expand Up @@ -822,7 +822,7 @@ static void main_loop(struct ctx *ctx, char *confname, bool slow,
fflush(stdout);
}

sock = pf_tx_socket();
sock = pf_socket();

if (ctx->qdisc_path == false)
set_sock_qdisc_bypass(sock, ctx->verbose);
Expand Down

0 comments on commit 096b043

Please sign in to comment.