Skip to content

Commit

Permalink
[nozzle] cleanup and document nozzle_del_ip
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Aug 3, 2018
1 parent 9502a3d commit 08532d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
23 changes: 17 additions & 6 deletions libnozzle/libnozzle.c
Expand Up @@ -1080,23 +1080,34 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char

int nozzle_del_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char **error_string)
{
int err = 0, found;
int err = 0, savederrno = 0;
int found = 0;
struct _ip *ip = NULL, *ip_prev = NULL;

pthread_mutex_lock(&lib_mutex);
if ((!nozzle) || (!ip_addr) || (!prefix) || (!error_string)) {
errno = EINVAL;
return -1;
}

savederrno = pthread_mutex_lock(&lib_mutex);
if (savederrno) {
errno = savederrno;
return -1;
}

if ((!_check(nozzle)) || (!ip_addr) || (!prefix) || (!error_string)) {
if (!_check(nozzle)) {
errno = EINVAL;
err = -1;
goto out_clean;
}

found = _find_ip(nozzle, ip_addr, prefix, &ip, &ip_prev);
if (!found)
if (!found) {
goto out_clean;
}

err = _set_ip(nozzle, "del", ip_addr, prefix, error_string, 0);

savederrno = errno;
if (!err) {
if (ip == ip_prev) {
nozzle->ip = ip->next;
Expand All @@ -1108,7 +1119,7 @@ int nozzle_del_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char

out_clean:
pthread_mutex_unlock(&lib_mutex);

errno = savederrno;
return err;
}

Expand Down
21 changes: 21 additions & 0 deletions libnozzle/libnozzle.h
Expand Up @@ -149,6 +149,27 @@ int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);
*/

int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char **error_string);

/**
* nozzle_del_ip
* @brief equivalent of ip addr del or ifconfig del <ipaddress/prefix>
*
* nozzle - pointer to the nozzle struct
*
* ip_addr - string containing either an IPv4 or an IPv6 address.
*
* 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 error 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 *ip_addr, const char *prefix, char **error_string);
int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries);

Expand Down

0 comments on commit 08532d0

Please sign in to comment.