]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
[libnozzle] remove error_string requirement from many API calls and mark them as...
authorFabio M. Di Nitto <fdinitto@redhat.com>
Tue, 4 Dec 2018 03:04:56 +0000 (04:04 +0100)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Tue, 18 Dec 2018 08:30:22 +0000 (09:30 +0100)
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
libnozzle/libnozzle.c
libnozzle/libnozzle.h
libnozzle/tests/nozzle_test.c

index 40d8253bfc6ae6da9b0d8eef6122712097b84e53..ba9409e4e2604ecab32d43187240fd650e158942 100644 (file)
@@ -59,171 +59,40 @@ static pthread_mutex_t config_mutex = PTHREAD_MUTEX_INITIALIZER;
  * internal helpers
  */
 
-#define IP_ADD 1
-#define IP_DEL 2
-
-static int _set_ip(nozzle_t nozzle, int command,
-                     const char *ipaddr, const char *prefix,
-                     char **error_string, int secondary)
+static void lib_fini(void)
 {
-       int fam;
-       char *broadcast = NULL;
+       if (lib_cfg.head == NULL) {
 #ifdef KNET_LINUX
-       struct rtnl_addr *addr = NULL;
-       struct nl_addr *local_addr = NULL;
-       struct nl_addr *bcast_addr = NULL;
-       struct nl_cache *cache = NULL;
-       int ifindex;
-       int err = 0;
-#endif
-#ifdef KNET_BSD
-       char cmdline[4096];
-       char proto[6];
+               nl_close(lib_cfg.nlsock);
+               nl_socket_free(lib_cfg.nlsock);
 #endif
-
-       if (!strchr(ipaddr, ':')) {
-               fam = AF_INET;
-               broadcast = generate_v4_broadcast(ipaddr, prefix);
-               if (!broadcast) {
-                       errno = EINVAL;
-                       return -1;
-               }
-       } else {
-               fam = AF_INET6;
-       }
-
-#ifdef KNET_LINUX
-       addr = rtnl_addr_alloc();
-       if (!addr) {
-               errno = ENOMEM;
-               return -1;
-       }
-
-       if (rtnl_link_alloc_cache(lib_cfg.nlsock, AF_UNSPEC, &cache) < 0) {
-               errno = ENOMEM;
-               err = -1;
-               goto out;
-       }
-
-       ifindex = rtnl_link_name2i(cache, nozzle->name);
-       if (ifindex == 0) {
-               errno = ENOENT;
-               err = -1;
-               goto out;
+               close(lib_cfg.ioctlfd);
+               lib_init = 0;
        }
+}
 
-       rtnl_addr_set_ifindex(addr, ifindex);
-
-       if (nl_addr_parse(ipaddr, fam, &local_addr) < 0) {
-               errno = EINVAL;
-               err = -1;
-               goto out;
-       }
+static int is_valid_nozzle(const nozzle_t nozzle)
+{
+       nozzle_t temp;
 
-       if (rtnl_addr_set_local(addr, local_addr) < 0) {
-               errno = EINVAL;
-               err = -1;
-               goto out;
+       if (!nozzle) {
+               return 0;
        }
 
-       if (broadcast) {
-               if (nl_addr_parse(broadcast, fam, &bcast_addr) < 0) {
-                       errno = EINVAL;
-                       err = -1;
-                       goto out;
-               }
-
-               if (rtnl_addr_set_broadcast(addr, bcast_addr) < 0) {
-                       errno = EINVAL;
-                       err = -1;
-                       goto out;
-               }
+       if (!lib_init) {
+               return 0;
        }
 
-       rtnl_addr_set_prefixlen(addr, atoi(prefix));
-
-       if (command == IP_ADD) {
-               if (rtnl_addr_add(lib_cfg.nlsock, addr, 0) < 0) {
-                       errno = EINVAL;
-                       err = -1;
-                       goto out;
-               }
-       } else {
-               if (rtnl_addr_delete(lib_cfg.nlsock, addr, 0) < 0) {
-                       errno = EINVAL;
-                       err = -1;
-                       goto out;
-               }
-       }
-out:
-       if (addr) {
-               rtnl_addr_put(addr);
-       }
-       if (local_addr) {
-               nl_addr_put(local_addr);
-       }
-       if (bcast_addr) {
-               nl_addr_put(bcast_addr);
-       }
-       if (cache) {
-               nl_cache_put(cache);
-       }
-       if (broadcast) {
-               free(broadcast);
-       }
-       return err;
-#endif
-#ifdef KNET_BSD
-       memset(cmdline, 0, sizeof(cmdline));
+       temp = lib_cfg.head;
 
-       if (fam == AF_INET) {
-               snprintf(proto, sizeof(proto), "inet");
-       } else {
-               snprintf(proto, sizeof(proto), "inet6");
-       }
+       while (temp != NULL) {
+               if (nozzle == temp)
+                       return 1;
 
-       if (command == IP_ADD) {
-               snprintf(cmdline, sizeof(cmdline)-1,
-                        "ifconfig %s %s %s/%s",
-                        nozzle->name, proto, ipaddr, prefix);
-               if (broadcast) {
-                       snprintf(cmdline + strlen(cmdline),
-                                sizeof(cmdline) - strlen(cmdline) -1,
-                                " broadcast %s", broadcast);
-               }
-               if ((secondary) && (fam == AF_INET)) {
-                       snprintf(cmdline + strlen(cmdline),
-                                sizeof(cmdline) - strlen(cmdline) -1,
-                                " alias");
-               }
-       } else {
-               snprintf(cmdline, sizeof(cmdline)-1,
-                                "ifconfig %s %s %s/%s delete",
-                                nozzle->name, proto, ipaddr, prefix);
-       }
-       if (broadcast) {
-               free(broadcast);
+               temp = temp->next;
        }
-       return execute_bin_sh_command(cmdline, error_string);
-#endif
-}
 
-/*
- * internal helpers below should be completed
- *
- * keep all ioctl work within this file
- */
-
-static void lib_fini(void)
-{
-       if (lib_cfg.head == NULL) {
-#ifdef KNET_LINUX
-               nl_close(lib_cfg.nlsock);
-               nl_socket_free(lib_cfg.nlsock);
-#endif
-               close(lib_cfg.ioctlfd);
-               lib_init = 0;
-       }
+       return 0;
 }
 
 static void destroy_iface(nozzle_t nozzle)
@@ -252,30 +121,6 @@ static void destroy_iface(nozzle_t nozzle)
        return;
 }
 
-static int is_valid_nozzle(const nozzle_t nozzle)
-{
-       nozzle_t temp;
-
-       if (!nozzle) {
-               return 0;
-       }
-
-       if (!lib_init) {
-               return 0;
-       }
-
-       temp = lib_cfg.head;
-
-       while (temp != NULL) {
-               if (nozzle == temp)
-                       return 1;
-
-               temp = temp->next;
-       }
-
-       return 0;
-}
-
 static int get_iface_mtu(const nozzle_t nozzle)
 {
        int err = 0, savederrno = 0;
@@ -401,200 +246,171 @@ out_clean:
        return err;
 }
 
-/*
- * public API
- */
+#define IP_ADD 1
+#define IP_DEL 2
 
-int nozzle_set_mtu(nozzle_t nozzle, const int mtu, char **error_string)
+static int _set_ip(nozzle_t nozzle,
+                  int command,
+                  const char *ipaddr, const char *prefix,
+                  int secondary)
 {
-       int err = 0, savederrno = 0;
-       struct nozzle_ip *tmp_ip;
-       struct ifreq ifr;
+       int fam;
+       char *broadcast = NULL;
+       int err = 0;
+#ifdef KNET_LINUX
+       struct rtnl_addr *addr = NULL;
+       struct nl_addr *local_addr = NULL;
+       struct nl_addr *bcast_addr = NULL;
+       struct nl_cache *cache = NULL;
+       int ifindex;
+#endif
+#ifdef KNET_BSD
+       char cmdline[4096];
+       char proto[6];
+       char *error_string = NULL;
+#endif
 
-       if ((!mtu) || (!error_string)) {
-               errno = EINVAL;
-               return -1;
+       if (!strchr(ipaddr, ':')) {
+               fam = AF_INET;
+               broadcast = generate_v4_broadcast(ipaddr, prefix);
+               if (!broadcast) {
+                       errno = EINVAL;
+                       return -1;
+               }
+       } else {
+               fam = AF_INET6;
        }
 
-       savederrno = pthread_mutex_lock(&config_mutex);
-       if (savederrno) {
-               errno = savederrno;
+#ifdef KNET_LINUX
+       addr = rtnl_addr_alloc();
+       if (!addr) {
+               errno = ENOMEM;
                return -1;
        }
 
-       if (!is_valid_nozzle(nozzle)) {
-               savederrno = EINVAL;
+       if (rtnl_link_alloc_cache(lib_cfg.nlsock, AF_UNSPEC, &cache) < 0) {
+               errno = ENOMEM;
                err = -1;
-               goto out_clean;
-       }
-
-       err = nozzle->current_mtu = get_iface_mtu(nozzle);
-       if (err < 0) {
-               savederrno = errno;
-               goto out_clean;
-       }
-
-       memset(&ifr, 0, sizeof(struct ifreq));
-       strncpy(ifname, nozzle->name, IFNAMSIZ);
-       ifr.ifr_mtu = mtu;
-
-       err = ioctl(lib_cfg.ioctlfd, SIOCSIFMTU, &ifr);
-       if (err) {
-               savederrno = errno;
-               goto out_clean;
+               goto out;
        }
 
-       if ((nozzle->current_mtu < 1280) && (mtu >= 1280)) {
-               tmp_ip = nozzle->ip;
-               while(tmp_ip) {
-                       if (tmp_ip->domain == AF_INET6) {
-                               err = _set_ip(nozzle, IP_ADD, tmp_ip->ipaddr, tmp_ip->prefix, error_string, 0);
-                               if (err) {
-                                       savederrno = errno;
-                                       err = -1;
-                                       goto out_clean;
-                               }
-                       }
-                       tmp_ip = tmp_ip->next;
-               }
+       ifindex = rtnl_link_name2i(cache, nozzle->name);
+       if (ifindex == 0) {
+               errno = ENOENT;
+               err = -1;
+               goto out;
        }
 
-out_clean:
-       pthread_mutex_unlock(&config_mutex);
-       errno = savederrno;
-       return err;
-}
-
-int nozzle_reset_mtu(nozzle_t nozzle, char **error_string)
-{
-       return nozzle_set_mtu(nozzle, nozzle->default_mtu, error_string);
-}
-
-int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char **error_string)
-{
-       int err = 0, savederrno = 0;
-       int found = 0;
-       struct nozzle_ip *ip = NULL, *ip_prev = NULL, *ip_last = NULL;
-       int secondary = 0;
+       rtnl_addr_set_ifindex(addr, ifindex);
 
-       if ((!ipaddr) || (!prefix) || (!error_string)) {
+       if (nl_addr_parse(ipaddr, fam, &local_addr) < 0) {
                errno = EINVAL;
-               return -1;
-       }
-
-       savederrno = pthread_mutex_lock(&config_mutex);
-       if (savederrno) {
-               errno = savederrno;
-               return -1;
-       }
-
-       if (!is_valid_nozzle(nozzle)) {
-               savederrno = EINVAL;
                err = -1;
-               goto out_clean;
-       }
-
-       found = find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
-       if (found) {
-               goto out_clean;
+               goto out;
        }
 
-       ip = malloc(sizeof(struct nozzle_ip));
-       if (!ip) {
-               savederrno = errno;
-               err = -1 ;
-               goto out_clean;
+       if (rtnl_addr_set_local(addr, local_addr) < 0) {
+               errno = EINVAL;
+               err = -1;
+               goto out;
        }
 
-       memset(ip, 0, sizeof(struct nozzle_ip));
-       strncpy(ip->ipaddr, ipaddr, IPADDR_CHAR_MAX);
-       strncpy(ip->prefix, prefix, PREFIX_CHAR_MAX);
-       if (!strchr(ip->ipaddr, ':')) {
-               ip->domain = AF_INET;
-       } else {
-               ip->domain = AF_INET6;
-       }
+       if (broadcast) {
+               if (nl_addr_parse(broadcast, fam, &bcast_addr) < 0) {
+                       errno = EINVAL;
+                       err = -1;
+                       goto out;
+               }
 
-       /*
-        * if user asks for an IPv6 address, but MTU < 1280
-        * store the IP and bring it up later if and when MTU > 1280
-        */
-       if ((ip->domain == AF_INET6) && (get_iface_mtu(nozzle) < 1280)) {
-               err = 0;
-       } else {
-               if (nozzle->ip) {
-                       secondary = 1;
+               if (rtnl_addr_set_broadcast(addr, bcast_addr) < 0) {
+                       errno = EINVAL;
+                       err = -1;
+                       goto out;
                }
-               err = _set_ip(nozzle, IP_ADD, ipaddr, prefix, error_string, secondary);
-               savederrno = errno;
        }
 
-       if (err) {
-               free(ip);
-               goto out_clean;
-       }
+       rtnl_addr_set_prefixlen(addr, atoi(prefix));
 
-       if (nozzle->ip) {
-               ip_last = nozzle->ip;
-               while (ip_last->next != NULL) {
-                       ip_last = ip_last->next;
+       if (command == IP_ADD) {
+               if (rtnl_addr_add(lib_cfg.nlsock, addr, 0) < 0) {
+                       errno = EINVAL;
+                       err = -1;
+                       goto out;
                }
-               ip_last->next = ip;
        } else {
-               nozzle->ip = ip;
-       }
-
-out_clean:
-       pthread_mutex_unlock(&config_mutex);
-       errno = savederrno;
-       return err;
-}
-
-int nozzle_del_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char **error_string)
-{
-       int err = 0, savederrno = 0;
-        int found = 0;
-       struct nozzle_ip *ip = NULL, *ip_prev = NULL;
-
-       if ((!ipaddr) || (!prefix) || (!error_string)) {
-               errno = EINVAL;
-               return -1;
+               if (rtnl_addr_delete(lib_cfg.nlsock, addr, 0) < 0) {
+                       errno = EINVAL;
+                       err = -1;
+                       goto out;
+               }
        }
-
-       savederrno = pthread_mutex_lock(&config_mutex);
-       if (savederrno) {
-               errno = savederrno;
-               return -1;
+out:
+       if (addr) {
+               rtnl_addr_put(addr);
        }
-
-       if (!is_valid_nozzle(nozzle)) {
-               savederrno = EINVAL;
-               err = -1;
-               goto out_clean;
+       if (local_addr) {
+               nl_addr_put(local_addr);
+       }
+       if (bcast_addr) {
+               nl_addr_put(bcast_addr);
+       }
+       if (cache) {
+               nl_cache_put(cache);
+       }
+       if (broadcast) {
+               free(broadcast);
        }
+       return err;
+#endif
+#ifdef KNET_BSD
+       memset(cmdline, 0, sizeof(cmdline));
 
-       found = find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
-       if (!found) {
-               goto out_clean;
+       if (fam == AF_INET) {
+               snprintf(proto, sizeof(proto), "inet");
+       } else {
+               snprintf(proto, sizeof(proto), "inet6");
        }
 
-       err = _set_ip(nozzle, IP_DEL, ipaddr, prefix, error_string, 0);
-       savederrno = errno;
-       if (!err) {
-               if (ip == ip_prev) {
-                       nozzle->ip = ip->next;
-               } else {
-                       ip_prev->next = ip->next;
+       if (command == IP_ADD) {
+               snprintf(cmdline, sizeof(cmdline)-1,
+                        "ifconfig %s %s %s/%s",
+                        nozzle->name, proto, ipaddr, prefix);
+               if (broadcast) {
+                       snprintf(cmdline + strlen(cmdline),
+                                sizeof(cmdline) - strlen(cmdline) -1,
+                                " broadcast %s", broadcast);
                }
-               free(ip);
+               if ((secondary) && (fam == AF_INET)) {
+                       snprintf(cmdline + strlen(cmdline),
+                                sizeof(cmdline) - strlen(cmdline) -1,
+                                " alias");
+               }
+       } else {
+               snprintf(cmdline, sizeof(cmdline)-1,
+                                "ifconfig %s %s %s/%s delete",
+                                nozzle->name, proto, ipaddr, prefix);
+       }
+       if (broadcast) {
+               free(broadcast);
        }
 
-out_clean:
-       pthread_mutex_unlock(&config_mutex);
-       errno = savederrno;
+       /*
+        * temporary workaround as we port libnozzle to BSD ioctl
+        * for IP address management
+        */
+       err = execute_bin_sh_command(cmdline, error_string);
+       if (error_string) {
+               free(error_string);
+               error_string = NULL;
+       }
        return err;
+#endif
 }
 
+/*
+ * public API
+ */
+
 int nozzle_get_ips(const nozzle_t nozzle, char **ipaddr_list, int *entries)
 {
        int err = 0, savederrno = 0;
@@ -1235,3 +1051,193 @@ out_clean:
        errno = savederrno;
        return fd;
 }
+
+int nozzle_set_mtu(nozzle_t nozzle, const int mtu)
+{
+       int err = 0, savederrno = 0;
+       struct nozzle_ip *tmp_ip;
+       struct ifreq ifr;
+
+       if (!mtu) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       savederrno = pthread_mutex_lock(&config_mutex);
+       if (savederrno) {
+               errno = savederrno;
+               return -1;
+       }
+
+       if (!is_valid_nozzle(nozzle)) {
+               savederrno = EINVAL;
+               err = -1;
+               goto out_clean;
+       }
+
+       err = nozzle->current_mtu = get_iface_mtu(nozzle);
+       if (err < 0) {
+               savederrno = errno;
+               goto out_clean;
+       }
+
+       memset(&ifr, 0, sizeof(struct ifreq));
+       strncpy(ifname, nozzle->name, IFNAMSIZ);
+       ifr.ifr_mtu = mtu;
+
+       err = ioctl(lib_cfg.ioctlfd, SIOCSIFMTU, &ifr);
+       if (err) {
+               savederrno = errno;
+               goto out_clean;
+       }
+
+       if ((nozzle->current_mtu < 1280) && (mtu >= 1280)) {
+               tmp_ip = nozzle->ip;
+               while(tmp_ip) {
+                       if (tmp_ip->domain == AF_INET6) {
+                               err = _set_ip(nozzle, IP_ADD, tmp_ip->ipaddr, tmp_ip->prefix, 0);
+                               if (err) {
+                                       savederrno = errno;
+                                       err = -1;
+                                       goto out_clean;
+                               }
+                       }
+                       tmp_ip = tmp_ip->next;
+               }
+       }
+
+out_clean:
+       pthread_mutex_unlock(&config_mutex);
+       errno = savederrno;
+       return err;
+}
+
+int nozzle_reset_mtu(nozzle_t nozzle)
+{
+       return nozzle_set_mtu(nozzle, nozzle->default_mtu);
+}
+
+int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix)
+{
+       int err = 0, savederrno = 0;
+       int found = 0;
+       struct nozzle_ip *ip = NULL, *ip_prev = NULL, *ip_last = NULL;
+       int secondary = 0;
+
+       if ((!ipaddr) || (!prefix)) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       savederrno = pthread_mutex_lock(&config_mutex);
+       if (savederrno) {
+               errno = savederrno;
+               return -1;
+       }
+
+       if (!is_valid_nozzle(nozzle)) {
+               savederrno = EINVAL;
+               err = -1;
+               goto out_clean;
+       }
+
+       found = find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
+       if (found) {
+               goto out_clean;
+       }
+
+       ip = malloc(sizeof(struct nozzle_ip));
+       if (!ip) {
+               savederrno = errno;
+               err = -1 ;
+               goto out_clean;
+       }
+
+       memset(ip, 0, sizeof(struct nozzle_ip));
+       strncpy(ip->ipaddr, ipaddr, IPADDR_CHAR_MAX);
+       strncpy(ip->prefix, prefix, PREFIX_CHAR_MAX);
+       if (!strchr(ip->ipaddr, ':')) {
+               ip->domain = AF_INET;
+       } else {
+               ip->domain = AF_INET6;
+       }
+
+       /*
+        * if user asks for an IPv6 address, but MTU < 1280
+        * store the IP and bring it up later if and when MTU > 1280
+        */
+       if ((ip->domain == AF_INET6) && (get_iface_mtu(nozzle) < 1280)) {
+               err = 0;
+       } else {
+               if (nozzle->ip) {
+                       secondary = 1;
+               }
+               err = _set_ip(nozzle, IP_ADD, ipaddr, prefix, secondary);
+               savederrno = errno;
+       }
+
+       if (err) {
+               free(ip);
+               goto out_clean;
+       }
+
+       if (nozzle->ip) {
+               ip_last = nozzle->ip;
+               while (ip_last->next != NULL) {
+                       ip_last = ip_last->next;
+               }
+               ip_last->next = ip;
+       } else {
+               nozzle->ip = ip;
+       }
+
+out_clean:
+       pthread_mutex_unlock(&config_mutex);
+       errno = savederrno;
+       return err;
+}
+
+int nozzle_del_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix)
+{
+       int err = 0, savederrno = 0;
+        int found = 0;
+       struct nozzle_ip *ip = NULL, *ip_prev = NULL;
+
+       if ((!ipaddr) || (!prefix)) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       savederrno = pthread_mutex_lock(&config_mutex);
+       if (savederrno) {
+               errno = savederrno;
+               return -1;
+       }
+
+       if (!is_valid_nozzle(nozzle)) {
+               savederrno = EINVAL;
+               err = -1;
+               goto out_clean;
+       }
+
+       found = find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
+       if (!found) {
+               goto out_clean;
+       }
+
+       err = _set_ip(nozzle, IP_DEL, ipaddr, prefix, 0);
+       savederrno = errno;
+       if (!err) {
+               if (ip == ip_prev) {
+                       nozzle->ip = ip->next;
+               } else {
+                       ip_prev->next = ip->next;
+               }
+               free(ip);
+       }
+
+out_clean:
+       pthread_mutex_unlock(&config_mutex);
+       errno = savederrno;
+       return err;
+}
index 6c3cb27adbfe45fa2d9d329b46d1085e147a40de..a3a06efafbfdb9e6f2ab79f65fdfd7e7557f509b 100644 (file)
@@ -132,17 +132,12 @@ int nozzle_set_down(nozzle_t nozzle);
  *
  * prefix - 24, 64 or any valid network prefix for the requested address.
  *
- * error_string - pointers to string to record errors from ipaddr2 (Linux) or ifconfig (BSD).
- *                The string is malloc'ed, the caller needs to free this buffer.
- *
  * @return
  * 0 on success
  * -1 on error and errno is set.
- *  error_string is set to NULL on success
- *  error_string will contain a string recording the execution error.
  */
 
-int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char **error_string);
+int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix);
 
 /**
  * nozzle_del_ip
@@ -154,17 +149,12 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char
  *
  * prefix - 24, 64 or any valid network prefix for the requested address.
  *
- * error_string - pointers to string to record errors from ipaddr2 (Linux) or ifconfig (BSD).
- *                The string is malloc'ed, the caller needs to free this buffer.
- *
  * @return
  * 0 on success
  * -1 on error and errno is set.
- *  error_string is set to NULL on success
- *  error_string will contain a string recording the execution error.
  */
 
-int nozzle_del_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char **error_string);
+int nozzle_del_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix);
 
 /**
  * nozzle_get_ips
@@ -209,18 +199,12 @@ int nozzle_get_mtu(const nozzle_t nozzle);
  *
  * mtu - new MTU value
  *
- * error_string - pointer to string to record errors from ipaddr2 (Linux) or ifconfig (BSD)
- *                when re-instanting IPv6 address if MTU is becoming again > 1280.
- *                The string is malloc'ed, the caller needs to free this buffer.
- *
  * @return
  * 0 on success
  * -1 on error and errno is set.
- * error_string is set to NULL on success
- * error_string will contain a string recording the execution error.
  */
 
-int nozzle_set_mtu(nozzle_t nozzle, const int mtu, char **error_string);
+int nozzle_set_mtu(nozzle_t nozzle, const int mtu);
 
 /**
  * nozzle_reset_mtu
@@ -228,18 +212,12 @@ int nozzle_set_mtu(nozzle_t nozzle, const int mtu, char **error_string);
  *
  * nozzle - pointer to the nozzle struct
  *
- * error_string - pointer to string to record errors from ipaddr2 (Linux) or ifconfig (BSD)
- *                when re-instanting IPv6 address if MTU is becoming again > 1280.
- *                The string is malloc'ed, the caller needs to free this buffer.
- *
  * @return
  * 0 on success
  * -1 on error and errno is set.
- * error_string is set to NULL on success
- * error_string will contain a string recording the execution error.
  */
 
-int nozzle_reset_mtu(nozzle_t nozzle, char **error_string);
+int nozzle_reset_mtu(nozzle_t nozzle);
 
 /**
  * nozzle_get_mac
index 2800f48b04b7be84a4b3a8dcbfd37c04881bd172..a9ca16ac66d319f094fe48e192a03bd0ce32e90a 100644 (file)
@@ -275,7 +275,6 @@ static int check_knet_mtu(void)
        size_t size = IFNAMSIZ;
        int err=0;
        nozzle_t nozzle;
-       char *error_string = NULL;
 
        int current_mtu = 0;
        int expected_mtu = 1500;
@@ -304,12 +303,8 @@ static int check_knet_mtu(void)
 
        printf("Setting MTU to 9000\n");
        expected_mtu = 9000;
-       if (nozzle_set_mtu(nozzle, expected_mtu, &error_string) < 0) {
+       if (nozzle_set_mtu(nozzle, expected_mtu) < 0) {
                printf("Unable to set MTU to %d\n", expected_mtu);
-               if (error_string) {
-                       printf("error: %s\n", error_string);
-                       free(error_string);
-               }
                err = -1;
                goto out_clean;
        }
@@ -336,12 +331,8 @@ static int check_knet_mtu(void)
        }
 
        printf("Passing empty struct to set_mtu\n");
-       if (nozzle_set_mtu(NULL, 1500, &error_string) == 0) {
+       if (nozzle_set_mtu(NULL, 1500) == 0) {
                printf("Something is wrong in nozzle_set_mtu sanity checks\n");
-               if (error_string) {
-                       printf("error: %s\n", error_string);
-                       free(error_string);
-               }
                err = -1;
                goto out_clean;
        }
@@ -375,12 +366,7 @@ static int check_knet_mtu_ipv6(void)
 
        printf("Adding ip: %s/64\n", testipv6_1);
 
-       err = nozzle_add_ip(nozzle, testipv6_1, "64", &error_string);
-       if (error_string) {
-               printf("add ipv6 output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv6_1, "64");
        if (err) {
                printf("Unable to assign IP address\n");
                err=-1;
@@ -408,12 +394,8 @@ static int check_knet_mtu_ipv6(void)
        }
 
        printf("Setting MTU to 1200\n");
-       if (nozzle_set_mtu(nozzle, 1200, &error_string) < 0) {
+       if (nozzle_set_mtu(nozzle, 1200) < 0) {
                printf("Unable to set MTU to 1200\n");
-               if (error_string) {
-                       printf("error: %s\n", error_string);
-                       free(error_string);
-               }
                err = -1;
                goto out_clean;
        }
@@ -436,12 +418,7 @@ static int check_knet_mtu_ipv6(void)
        }
 
        printf("Adding ip: %s/64\n", testipv6_2);
-       err = nozzle_add_ip(nozzle, testipv6_2, "64", &error_string);
-       if (error_string) {
-               printf("add ipv6 output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv6_2, "64");
        if (err < 0) {
                printf("Unable to assign IP address\n");
                err=-1;
@@ -469,12 +446,8 @@ static int check_knet_mtu_ipv6(void)
        }
 
        printf("Restoring MTU to default\n");
-       if (nozzle_reset_mtu(nozzle, &error_string) < 0) {
+       if (nozzle_reset_mtu(nozzle) < 0) {
                printf("Unable to reset mtu\n");
-               if (error_string) {
-                       printf("error: %s\n", error_string);
-                       free(error_string);
-               }
                err = -1;
                goto out_clean;
        }
@@ -968,7 +941,6 @@ static int check_knet_close_leak(void)
        size_t size = IFNAMSIZ;
        int err=0;
        nozzle_t nozzle;
-       char *error_string = NULL;
 
        printf("Testing close leak (needs valgrind)\n");
 
@@ -982,12 +954,7 @@ static int check_knet_close_leak(void)
 
        printf("Adding ip: %s/24\n", testipv4_1);
 
-       err = nozzle_add_ip(nozzle, testipv4_1, "24", &error_string);
-       if (error_string) {
-               printf("add ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv4_1, "24");
        if (err < 0) {
                printf("Unable to assign IP address\n");
                err=-1;
@@ -996,12 +963,7 @@ static int check_knet_close_leak(void)
 
        printf("Adding ip: %s/24\n", testipv4_2);
 
-       err = nozzle_add_ip(nozzle, testipv4_2, "24", &error_string);
-       if (error_string) {
-               printf("add ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv4_2, "24");
        if (err < 0) {
                printf("Unable to assign IP address\n");
                err=-1;
@@ -1037,12 +999,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Adding ip: %s/24\n", testipv4_1);
 
-       err = nozzle_add_ip(nozzle, testipv4_1, "24", &error_string);
-       if (error_string) {
-               printf("add ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv4_1, "24");
        if (err < 0) {
                printf("Unable to assign IP address\n");
                err=-1;
@@ -1051,12 +1008,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Adding ip: %s/24\n", testipv4_2);
 
-       err = nozzle_add_ip(nozzle, testipv4_2, "24", &error_string);
-       if (error_string) {
-               printf("add ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv4_2, "24");
        if (err < 0) {
                printf("Unable to assign IP address\n");
                err=-1;
@@ -1065,12 +1017,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Adding duplicate ip: %s/24\n", testipv4_1);
 
-       err = nozzle_add_ip(nozzle, testipv4_1, "24", &error_string);
-       if (error_string) {
-               printf("add ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv4_1, "24");
        if (err < 0) {
                printf("Unable to find IP address in libnozzle db\n");
                err=-1;
@@ -1123,12 +1070,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Deleting ip: %s/24\n", testipv4_1);
 
-       err = nozzle_del_ip(nozzle, testipv4_1, "24", &error_string);
-       if (error_string) {
-               printf("del ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_del_ip(nozzle, testipv4_1, "24");
        if (err < 0) {
                printf("Unable to delete IP address\n");
                err=-1;
@@ -1137,12 +1079,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Deleting ip: %s/24\n", testipv4_2);
 
-       err = nozzle_del_ip(nozzle, testipv4_2, "24", &error_string);
-       if (error_string) {
-               printf("del ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_del_ip(nozzle, testipv4_2, "24");
        if (err < 0) {
                printf("Unable to delete IP address\n");
                err=-1;
@@ -1151,12 +1088,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Deleting again ip: %s/24\n", testipv4_1);
 
-       err = nozzle_del_ip(nozzle, testipv4_1, "24", &error_string);
-       if (error_string) {
-               printf("del ip output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_del_ip(nozzle, testipv4_1, "24");
        if (err < 0) {
                printf("Unable to delete IP address\n");
                err=-1;
@@ -1185,12 +1117,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Adding ip: %s/64\n", testipv6_1);
 
-       err = nozzle_add_ip(nozzle, testipv6_1, "64", &error_string);
-       if (error_string) {
-               printf("add ipv6 output: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_add_ip(nozzle, testipv6_1, "64");
        if (err < 0) {
                printf("Unable to assign IP address\n");
                err=-1;
@@ -1219,12 +1146,7 @@ static int check_knet_set_del_ip(void)
 
        printf("Deleting ip: %s/64\n", testipv6_1);
 
-       err = nozzle_del_ip(nozzle, testipv6_1, "64", &error_string);
-       if (error_string) {
-               printf("Error string: %s\n", error_string);
-               free(error_string);
-               error_string = NULL;
-       }
+       err = nozzle_del_ip(nozzle, testipv6_1, "64");
        if (err) {
                printf("Unable to delete IP address\n");
                err=-1;