dev: bail out if ifindex could not be retrieved
authorDaniel Borkmann <dborkman@redhat.com>
Mon, 17 Jun 2013 20:45:53 +0000 (17 22:45 +0200)
committerDaniel Borkmann <dborkman@redhat.com>
Mon, 17 Jun 2013 20:45:53 +0000 (17 22:45 +0200)
If we fail to find the ifindex of a given device, bail out.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
dev.c

diff --git a/dev.c b/dev.c
index 210487c..6488f4a 100644 (file)
--- a/dev.c
+++ b/dev.c
@@ -9,6 +9,7 @@
 #include "sock.h"
 #include "die.h"
 #include "link.h"
+#include "built_in.h"
 
 int device_ifindex(const char *ifname)
 {
@@ -24,11 +25,10 @@ int device_ifindex(const char *ifname)
        strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
 
        ret = ioctl(sock, SIOCGIFINDEX, &ifr);
-       if (!ret)
-               index = ifr.ifr_ifindex;
-       else
-               index = -1;
+       if (unlikely(ret))
+               panic("Cannot get ifindex from device!\n");
 
+       index = ifr.ifr_ifindex;
        close(sock);
 
        return index;