Skip to content

Commit 2ee8e5d

Browse files
committed
Add support for alias interfaces
1 parent 31b4b29 commit 2ee8e5d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

userland/lib/pfring_mod.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,13 +893,34 @@ int pfring_mod_get_device_ifindex(pfring *ring, char *device_name, int *if_index
893893

894894
memset(buffer, 0, sizeof(buffer));
895895
strncpy(buffer, device_name, sizeof(buffer) - 1);
896-
896+
897+
/* Device ifindex lookup via PF_RING */
897898
rc = getsockopt(ring->fd, 0, SO_GET_DEVICE_IFINDEX, buffer, &len);
898899

899-
if (rc < 0)
900-
return rc;
900+
if (rc < 0) {
901+
/* Try with a DGRAM socket in case interface is an alias */
902+
int sockfd;
903+
struct ifreq ifr;
904+
905+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
906+
if (sockfd < 0)
907+
return rc;
908+
909+
memset(&ifr, 0, sizeof(ifr));
910+
strncpy(ifr.ifr_name, device_name, sizeof(ifr.ifr_name)-1);
911+
912+
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
913+
close(sockfd);
914+
return rc;
915+
}
916+
917+
*if_index = ifr.ifr_ifindex;
918+
919+
close(sockfd);
920+
} else {
921+
memcpy(if_index, buffer, sizeof(*if_index));
922+
}
901923

902-
memcpy(if_index, buffer, sizeof(*if_index));
903924
return 0;
904925
}
905926

0 commit comments

Comments
 (0)