Bläddra i källkod

Minor changes. NCDIfConfig: fix open_tuntap return value

ambrop7 14 år sedan
förälder
incheckning
9222a2ef20
3 ändrade filer med 12 tillägg och 11 borttagningar
  1. 1 8
      misc/ipaddr.h
  2. 4 2
      misc/parse_number.h
  3. 7 1
      ncd/NCDIfConfig.c

+ 1 - 8
misc/ipaddr.h

@@ -118,14 +118,7 @@ int ipaddr_parse_ipv4_ifaddr (char *str, struct ipv4_ifaddr *out)
         return 0;
         return 0;
     }
     }
     
     
-    char *prefix = slash + 1;
-    size_t prefix_len = strlen(prefix);
-    
-    if (prefix_len > 2) {
-        return 0;
-    }
-    
-    if (!ipaddr_parse_ipv4_prefix_bin(prefix, prefix_len, &out->prefix)) {
+    if (!ipaddr_parse_ipv4_prefix(slash + 1, &out->prefix)) {
         return 0;
         return 0;
     }
     }
     
     

+ 4 - 2
misc/parse_number.h

@@ -31,8 +31,10 @@
 #include <string.h>
 #include <string.h>
 #include <stddef.h>
 #include <stddef.h>
 
 
-static int parse_unsigned_integer_bin (const char *str, size_t str_len, uintmax_t *out);
-static int parse_unsigned_integer (const char *str, uintmax_t *out);
+#include <misc/debug.h>
+
+static int parse_unsigned_integer_bin (const char *str, size_t str_len, uintmax_t *out) WARN_UNUSED;
+static int parse_unsigned_integer (const char *str, uintmax_t *out) WARN_UNUSED;
 
 
 int parse_unsigned_integer_bin (const char *str, size_t str_len, uintmax_t *out)
 int parse_unsigned_integer_bin (const char *str, size_t str_len, uintmax_t *out)
 {
 {

+ 7 - 1
ncd/NCDIfConfig.c

@@ -83,6 +83,7 @@ int NCDIfConfig_query (const char *ifname)
     memset(&ifr, 0, sizeof(ifr));
     memset(&ifr, 0, sizeof(ifr));
     snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname);
     snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname);
     if (ioctl(s, SIOCGIFFLAGS, &ifr)) {
     if (ioctl(s, SIOCGIFFLAGS, &ifr)) {
+        BLog(BLOG_ERROR, "SIOCGIFFLAGS failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
@@ -105,6 +106,7 @@ fail0:
 int NCDIfConfig_set_up (const char *ifname)
 int NCDIfConfig_set_up (const char *ifname)
 {
 {
     if (strlen(ifname) >= IFNAMSIZ) {
     if (strlen(ifname) >= IFNAMSIZ) {
+        BLog(BLOG_ERROR, "ifname too long");
         return 0;
         return 0;
     }
     }
     
     
@@ -117,6 +119,7 @@ int NCDIfConfig_set_up (const char *ifname)
 int NCDIfConfig_set_down (const char *ifname)
 int NCDIfConfig_set_down (const char *ifname)
 {
 {
     if (strlen(ifname) >= IFNAMSIZ) {
     if (strlen(ifname) >= IFNAMSIZ) {
+        BLog(BLOG_ERROR, "ifname too long");
         return 0;
         return 0;
     }
     }
     
     
@@ -132,6 +135,7 @@ int NCDIfConfig_add_ipv4_addr (const char *ifname, struct ipv4_ifaddr ifaddr)
     ASSERT(ifaddr.prefix <= 32)
     ASSERT(ifaddr.prefix <= 32)
     
     
     if (strlen(ifname) >= IFNAMSIZ) {
     if (strlen(ifname) >= IFNAMSIZ) {
+        BLog(BLOG_ERROR, "ifname too long");
         return 0;
         return 0;
     }
     }
     
     
@@ -149,6 +153,7 @@ int NCDIfConfig_remove_ipv4_addr (const char *ifname, struct ipv4_ifaddr ifaddr)
     ASSERT(ifaddr.prefix <= 32)
     ASSERT(ifaddr.prefix <= 32)
     
     
     if (strlen(ifname) >= IFNAMSIZ) {
     if (strlen(ifname) >= IFNAMSIZ) {
+        BLog(BLOG_ERROR, "ifname too long");
         return 0;
         return 0;
     }
     }
     
     
@@ -239,7 +244,8 @@ fail0:
 static int open_tuntap (const char *ifname, int flags)
 static int open_tuntap (const char *ifname, int flags)
 {
 {
     if (strlen(ifname) >= IFNAMSIZ) {
     if (strlen(ifname) >= IFNAMSIZ) {
-        return 0;
+        BLog(BLOG_ERROR, "ifname too long");
+        return -1;
     }
     }
     
     
     int fd = open(TUN_DEVNODE, O_RDWR);
     int fd = open(TUN_DEVNODE, O_RDWR);