Skip to content

Commit

Permalink
[nozzle] move find_ip to internals
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 Nov 30, 2018
1 parent 54f5b11 commit ec7075c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
52 changes: 26 additions & 26 deletions libnozzle/internals.c
Expand Up @@ -184,6 +184,32 @@ char *generate_v4_broadcast(const char *ipaddr, const char *prefix)
return strdup(inet_ntoa(broadcast));
}

int find_ip(nozzle_t nozzle,
const char *ipaddr, const char *prefix,
struct nozzle_ip **ip, struct nozzle_ip **ip_prev)
{
struct nozzle_ip *local_ip, *local_ip_prev;
int found = 0;

local_ip = local_ip_prev = nozzle->ip;

while(local_ip) {
if ((!strcmp(local_ip->ipaddr, ipaddr)) && (!strcmp(local_ip->prefix, prefix))) {
found = 1;
break;
}
local_ip_prev = local_ip;
local_ip = local_ip->next;
}

if (found) {
*ip = local_ip;
*ip_prev = local_ip_prev;
}

return found;
}

#if 0
static void _close(nozzle_t nozzle)
{
Expand Down Expand Up @@ -720,32 +746,6 @@ static int _set_ip(nozzle_t nozzle, const char *command,
return _execute_bin_sh(cmdline, error_string);
}

static int _find_ip(nozzle_t nozzle,
const char *ipaddr, const char *prefix,
struct nozzle_ip **ip, struct nozzle_ip **ip_prev)
{
struct nozzle_ip *local_ip, *local_ip_prev;
int found = 0;

local_ip = local_ip_prev = nozzle->ip;

while(local_ip) {
if ((!strcmp(local_ip->ipaddr, ipaddr)) && (!strcmp(local_ip->prefix, prefix))) {
found = 1;
break;
}
local_ip_prev = local_ip;
local_ip = local_ip->next;
}

if (found) {
*ip = local_ip;
*ip_prev = local_ip_prev;
}

return found;
}

int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char **error_string)
{
int err = 0, savederrno = 0;
Expand Down
4 changes: 4 additions & 0 deletions libnozzle/internals.h
Expand Up @@ -63,6 +63,10 @@ struct nozzle_iface {
int execute_bin_sh_command(const char *command, char **error_string);
int run_updown(const nozzle_t nozzle, const char *action, char **error_string);

int find_ip(nozzle_t nozzle,
const char *ipaddr, const char *prefix,
struct nozzle_ip **ip, struct nozzle_ip **ip_prev);

char *generate_v4_broadcast(const char *ipaddr, const char *prefix);

#endif
30 changes: 2 additions & 28 deletions libnozzle/libnozzle.c
Expand Up @@ -187,32 +187,6 @@ static int _set_ip(nozzle_t nozzle, const char *command,
return execute_bin_sh_command(cmdline, error_string);
}

static int _find_ip(nozzle_t nozzle,
const char *ipaddr, const char *prefix,
struct nozzle_ip **ip, struct nozzle_ip **ip_prev)
{
struct nozzle_ip *local_ip, *local_ip_prev;
int found = 0;

local_ip = local_ip_prev = nozzle->ip;

while(local_ip) {
if ((!strcmp(local_ip->ipaddr, ipaddr)) && (!strcmp(local_ip->prefix, prefix))) {
found = 1;
break;
}
local_ip_prev = local_ip;
local_ip = local_ip->next;
}

if (found) {
*ip = local_ip;
*ip_prev = local_ip_prev;
}

return found;
}

/*
* internal helpers below should be completed
*
Expand Down Expand Up @@ -750,7 +724,7 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char
goto out_clean;
}

found = _find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
found = find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
if (found) {
goto out_clean;
}
Expand Down Expand Up @@ -829,7 +803,7 @@ int nozzle_del_ip(nozzle_t nozzle, const char *ipaddr, const char *prefix, char
goto out_clean;
}

found = _find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
found = find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
if (!found) {
goto out_clean;
}
Expand Down

0 comments on commit ec7075c

Please sign in to comment.