Skip to content

Commit

Permalink
[nozzle] cleanup and document nozzle_get_ips (part 1)
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 Dec 15, 2017
1 parent df8d01e commit baa13a8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
32 changes: 28 additions & 4 deletions libnozzle/libnozzle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,22 +1164,46 @@ const char *nozzle_get_name(const nozzle_t nozzle)

int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries)
{
int err = 0;
int err = 0, savederrno = 0;
int found = 0;
char *ip_list = NULL;
int size = 0, offset = 0, len;
struct _ip *ip = nozzle->ip;
struct _ip *ip = NULL;

pthread_mutex_lock(&lib_mutex);
if ((!nozzle) || (!ip_addr_list) || (!entries)) {
errno = EINVAL;
return -1;
}

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

if (!_check(nozzle)) {
errno = EINVAL;
goto out_clean;
}

ip = nozzle->ip;

while (ip) {
found++;
ip = ip->next;
}

if (!found) {
*ip_addr_list = NULL;
*entries = 0;
goto out_clean;
}

size = found * (MAX_IP_CHAR + MAX_PREFIX_CHAR + 2);

ip_list = malloc(size);
if (!ip_list) {
savederrno = errno;
err = -1;
goto out_clean;
}
Expand All @@ -1203,7 +1227,7 @@ int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries)

out_clean:
pthread_mutex_unlock(&lib_mutex);

errno = savederrno;
return err;
}

Expand Down
31 changes: 26 additions & 5 deletions libnozzle/libnozzle.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ nozzle_t nozzle_open(char *devname, size_t devname_size, const char *updownpath)
*
* @return
* 0 on success
* -1 on error and error is set.
* -1 on error and errno is set.
* error_down / error_postdown are set to NULL if execution of external scripts
* is sucessful
* error_down / error_postdown will contain strings recording the execution error.
Expand All @@ -93,7 +93,7 @@ int nozzle_close(nozzle_t nozzle, char **error_down, char **error_postdown);
*
* @return
* 0 on success
* -1 on error and error is set.
* -1 on error and errno is set.
* error_preup / error_up are set to NULL if execution of external scripts
* is sucessful
* error_preup / error_up will contain strings recording the execution error.
Expand All @@ -117,7 +117,7 @@ int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up);
*
* @return
* 0 on success
* -1 on error and error is set.
* -1 on error and errno is set.
* error_down / error_postdown are set to NULL if execution of external scripts
* is sucessful
* error_down / error_postdown will contain strings recording the execution error.
Expand All @@ -143,7 +143,7 @@ int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);
*
* @return
* 0 on success
* -1 on error and error is set.
* -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.
*/
Expand All @@ -165,12 +165,33 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
*
* @return
* 0 on success
* -1 on error and error is set.
* -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 *ip_addr, const char *prefix, char **error_string);

/**
* nozzle_get_ips
* @brief retrive the list of all configured ips for a given interface
*
* TODO: change to use a ip_addr_list struct!
*
* nozzle - pointer to the nozzle struct
*
* ip_addr_list - list of strings containing either an IPv4 or an IPv6 address and their prefixes.
*
* entries - entries recorded.
*
* @return
* 0 on success
* -1 on error and errno is set.
* ip_addr_list is a malloc'ed buffer that the user needs to parse and free after use. ip_addr_list can
* be NULL if entries is 0.
*
*/

int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries);

int nozzle_get_mtu(const nozzle_t nozzle);
Expand Down

0 comments on commit baa13a8

Please sign in to comment.