]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Check that if_nametoindex returns a valid index, thanks to d00mer.
authorRoy Marples <roy@marples.name>
Fri, 23 Mar 2007 10:32:11 +0000 (10:32 +0000)
committerRoy Marples <roy@marples.name>
Fri, 23 Mar 2007 10:32:11 +0000 (10:32 +0000)
ChangeLog
interface.c
socket.c

index 62dd0b1c3a3af291251864353c6a7ffc94d9c2b5..a0b86fe4fe08459365dae9b7e283d8f792ae3e93 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 When we get an invalid length for a DHCP option, try and continue anyway.
 When MTU is less than 576 we now ignore it instead of setting the MTU to 576.
 Build correctly on dietlibc, thanks to d00mer.
+Check that if_nametoindex returns a valid index, thanks to d00mer.
 
 dhcpcd-3.0.16
 RFC 2131 is full of confusion regarding MTU it seems as the effective minimum
index 1d17819e72c6dc9776a71f8951c614552e6f699f..d7122354d2bbc5006be0e192ca729aa120f73a68 100644 (file)
@@ -742,7 +742,12 @@ static int do_address(const char *ifname,
   if (! del)
     nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE;
   nlm.hdr.nlmsg_type = del ? RTM_DELADDR : RTM_NEWADDR;
-  nlm.ifa.ifa_index = if_nametoindex (ifname);
+  if (! (nlm.ifa.ifa_index = if_nametoindex (ifname)))
+    {
+      logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
+             ifname);
+      return -1;
+    }
   nlm.ifa.ifa_family = AF_INET;
 
   nlm.ifa.ifa_prefixlen = inet_ntocidr (netmask);
@@ -763,6 +768,7 @@ static int do_route (const char *ifname,
 {
   char *dstd;
   char *gend;
+  unsigned int ifindex;
   struct
     {
       struct nlmsghdr hdr;
@@ -826,7 +832,15 @@ static int do_route (const char *ifname,
     add_attr_l (&nlm.hdr, sizeof (nlm), RTA_GATEWAY, &gateway.s_addr,
                sizeof (gateway.s_addr));
 
-  add_attr_32 (&nlm.hdr, sizeof (nlm), RTA_OIF, if_nametoindex (ifname));
+
+  if (! (ifindex = if_nametoindex (ifname)))
+    {
+      logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
+             ifname);
+      return -1;
+    }
+
+  add_attr_32 (&nlm.hdr, sizeof (nlm), RTA_OIF, ifindex);
   add_attr_32 (&nlm.hdr, sizeof (nlm), RTA_PRIORITY, metric);
 
   return send_netlink (&nlm.hdr);
index 2ad97906a6364cdcd9e03333a83e6cb590ce991e..a00fda999daa2465d836f0218d359fb5c439f0c1 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -463,7 +463,13 @@ int open_socket (interface_t *iface, bool arp)
     sll.sll_protocol = htons (ETH_P_ARP);
   else
     sll.sll_protocol = htons (ETH_P_IP);
-  sll.sll_ifindex = if_nametoindex (iface->name);
+  if (! (sll.sll_ifindex = if_nametoindex (iface->name)))
+    {
+      logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
+             iface->name);
+      close (fd);
+      return -1;
+    }
 
   if (bind(fd, (struct sockaddr *) &sll, sizeof (struct sockaddr_ll)) == -1)
     {
@@ -494,7 +500,12 @@ int send_packet (const interface_t *iface, const int type,
   memset (&sll, 0, sizeof (struct sockaddr_ll));
   sll.sll_family = AF_PACKET;
   sll.sll_protocol = htons (type);
-  sll.sll_ifindex = if_nametoindex (iface->name);
+  if (! (sll.sll_ifindex = if_nametoindex (iface->name)))
+    {
+      logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
+             iface->name);
+      return -1;
+    }
   sll.sll_halen = ETHER_ADDR_LEN;
   memset(sll.sll_addr, 0xff, sizeof (sll.sll_addr));