Skip to content

Commit

Permalink
Bug #411 #651 - don't create tap0 if it already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen committed Apr 25, 2021
1 parent d2254e4 commit 0d6b6bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- fix configure --without-libdnet (#567)
- ensure automake version is at least 1.15 (#553)
- with multiplier option only first file can be sent and hang (#472)
- do not create tap0 if device already exists (#411) (#651)

05/20/2020 Version 4.3.3
- Increase cache buffers size to accomodate VLAN edits (#594)
Expand Down
12 changes: 11 additions & 1 deletion src/common/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,23 @@ sendpacket_t *
sendpacket_open(const char *device, char *errbuf, tcpr_dir_t direction,
sendpacket_type_t sendpacket_type _U_, void *arg _U_)
{
#ifdef HAVE_TUNTAP
char sys_dev_dir[128];
bool device_exists;
#endif
sendpacket_t *sp;
struct stat sdata;

assert(device);
assert(errbuf);

errbuf[0] = '\0';

#ifdef HAVE_TUNTAP
snprintf(sys_dev_dir, sizeof(sys_dev_dir), "/sys/class/net/%s/", device);
device_exists = access(sys_dev_dir, R_OK) == 0;
#endif

/* khial is universal */
if (stat(device, &sdata) == 0) {
if (((sdata.st_mode & S_IFMT) == S_IFCHR)) {
Expand Down Expand Up @@ -515,7 +525,7 @@ sendpacket_open(const char *device, char *errbuf, tcpr_dir_t direction,
}
}
#ifdef HAVE_TUNTAP
} else if (strncmp(device, "tap", 3) == 0) {
} else if (strncmp(device, "tap", 3) == 0 && !device_exists) {
sp = sendpacket_open_tuntap(device, errbuf);
#endif
} else {
Expand Down

1 comment on commit 0d6b6bc

@Zlika
Copy link

@Zlika Zlika commented on 0d6b6bc Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks the replay on a tap device (cf. #828).

Please sign in to comment.