Skip to content

Commit

Permalink
[cleanup] rename ip_addr to ipaddr
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 Jan 30, 2018
1 parent 6dfbdf9 commit 73c5c2e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions libnozzle/internals.h
Expand Up @@ -21,9 +21,9 @@ struct nozzle_lib_config {
#define PREFIX_CHAR_MAX 4

struct nozzle_ip {
char ip_addr[IPADDR_CHAR_MAX];
char ipaddr[IPADDR_CHAR_MAX];
char prefix[PREFIX_CHAR_MAX];
int domain;
int domain; /* AF_INET or AF_INET6 */
struct nozzle_ip *next;
};

Expand Down
64 changes: 32 additions & 32 deletions libnozzle/libnozzle.c
Expand Up @@ -52,12 +52,12 @@ static void _close_cfg(void);
static int _get_mtu(const nozzle_t nozzle);
static int _get_mac(const nozzle_t nozzle, char **ether_addr);
static int _set_down(nozzle_t nozzle, char **error_down, char **error_postdown);
static char *_get_v4_broadcast(const char *ip_addr, const char *prefix);
static char *_get_v4_broadcast(const char *ipaddr, const char *prefix);
static int _set_ip(nozzle_t nozzle, const char *command,
const char *ip_addr, const char *prefix,
const char *ipaddr, const char *prefix,
char **error_string, int secondary);
static int _find_ip(nozzle_t nozzle,
const char *ip_addr, const char *prefix,
const char *ipaddr, const char *prefix,
struct nozzle_ip **ip, struct nozzle_ip **ip_prev);

static int _read_pipe(int fd, char **file, size_t *length)
Expand Down Expand Up @@ -581,7 +581,7 @@ int nozzle_close(nozzle_t nozzle, char **error_down, char **error_postdown)
ip = nozzle->ip;
while (ip) {
ip_next = ip->next;
_set_ip(nozzle, "del", ip->ip_addr, ip->prefix, &error_string, 0);
_set_ip(nozzle, "del", ip->ipaddr, ip->prefix, &error_string, 0);
if (error_string) {
free(error_string);
error_string = NULL;
Expand Down Expand Up @@ -669,7 +669,7 @@ int nozzle_set_mtu(nozzle_t nozzle, const int mtu, char **error_string)
tmp_ip = nozzle->ip;
while(tmp_ip) {
if (tmp_ip->domain == AF_INET6) {
err = _set_ip(nozzle, "add", tmp_ip->ip_addr, tmp_ip->prefix, error_string, 0);
err = _set_ip(nozzle, "add", tmp_ip->ipaddr, tmp_ip->prefix, error_string, 0);
if (err) {
savederrno = errno;
err = -1;
Expand Down Expand Up @@ -910,7 +910,7 @@ int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown)
return err;
}

static char *_get_v4_broadcast(const char *ip_addr, const char *prefix)
static char *_get_v4_broadcast(const char *ipaddr, const char *prefix)
{
int prefix_len;
struct in_addr mask;
Expand All @@ -922,7 +922,7 @@ static char *_get_v4_broadcast(const char *ip_addr, const char *prefix)
if ((prefix_len > 32) || (prefix_len < 0))
return NULL;

if (inet_pton(AF_INET, ip_addr, &address) <= 0)
if (inet_pton(AF_INET, ipaddr, &address) <= 0)
return NULL;

mask.s_addr = htonl(~((1 << (32 - prefix_len)) - 1));
Expand All @@ -934,7 +934,7 @@ static char *_get_v4_broadcast(const char *ip_addr, const char *prefix)
}

static int _set_ip(nozzle_t nozzle, const char *command,
const char *ip_addr, const char *prefix,
const char *ipaddr, const char *prefix,
char **error_string, int secondary)
{
char *broadcast = NULL;
Expand All @@ -946,8 +946,8 @@ static int _set_ip(nozzle_t nozzle, const char *command,
snprintf(proto, sizeof(proto), "inet");
#endif

if (!strchr(ip_addr, ':')) {
broadcast = _get_v4_broadcast(ip_addr, prefix);
if (!strchr(ipaddr, ':')) {
broadcast = _get_v4_broadcast(ipaddr, prefix);
if (!broadcast) {
errno = EINVAL;
return -1;
Expand All @@ -966,20 +966,20 @@ static int _set_ip(nozzle_t nozzle, const char *command,
if (broadcast) {
snprintf(cmdline, sizeof(cmdline)-1,
"ip addr %s %s/%s dev %s broadcast %s",
command, ip_addr, prefix,
command, ipaddr, prefix,
nozzle->nozzlename, broadcast);
} else {
snprintf(cmdline, sizeof(cmdline)-1,
"ip addr %s %s/%s dev %s",
command, ip_addr, prefix,
command, ipaddr, prefix,
nozzle->nozzlename);
}
#endif
#ifdef KNET_BSD
if (!strcmp(command, "add")) {
snprintf(cmdline, sizeof(cmdline)-1,
"ifconfig %s %s %s/%s",
nozzle->nozzlename, proto, ip_addr, prefix);
nozzle->nozzlename, proto, ipaddr, prefix);
if (broadcast) {
snprintf(cmdline + strlen(cmdline),
sizeof(cmdline) - strlen(cmdline) -1,
Expand All @@ -993,7 +993,7 @@ static int _set_ip(nozzle_t nozzle, const char *command,
} else {
snprintf(cmdline, sizeof(cmdline)-1,
"ifconfig %s %s %s/%s delete",
nozzle->nozzlename, proto, ip_addr, prefix);
nozzle->nozzlename, proto, ipaddr, prefix);
}
#endif
if (broadcast) {
Expand All @@ -1003,7 +1003,7 @@ static int _set_ip(nozzle_t nozzle, const char *command,
}

static int _find_ip(nozzle_t nozzle,
const char *ip_addr, const char *prefix,
const char *ipaddr, const char *prefix,
struct nozzle_ip **ip, struct nozzle_ip **ip_prev)
{
struct nozzle_ip *local_ip, *local_ip_prev;
Expand All @@ -1012,7 +1012,7 @@ static int _find_ip(nozzle_t nozzle,
local_ip = local_ip_prev = nozzle->ip;

while(local_ip) {
if ((!strcmp(local_ip->ip_addr, ip_addr)) && (!strcmp(local_ip->prefix, prefix))) {
if ((!strcmp(local_ip->ipaddr, ipaddr)) && (!strcmp(local_ip->prefix, prefix))) {
found = 1;
break;
}
Expand All @@ -1028,14 +1028,14 @@ static int _find_ip(nozzle_t nozzle,
return found;
}

int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char **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;

if ((!nozzle) || (!ip_addr) || (!prefix) || (!error_string)) {
if ((!nozzle) || (!ipaddr) || (!prefix) || (!error_string)) {
errno = EINVAL;
return -1;
}
Expand All @@ -1052,7 +1052,7 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
goto out_clean;
}

found = _find_ip(nozzle, ip_addr, prefix, &ip, &ip_prev);
found = _find_ip(nozzle, ipaddr, prefix, &ip, &ip_prev);
if (found) {
goto out_clean;
}
Expand All @@ -1065,9 +1065,9 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
}

memset(ip, 0, sizeof(struct nozzle_ip));
strncpy(ip->ip_addr, ip_addr, IPADDR_CHAR_MAX);
strncpy(ip->ipaddr, ipaddr, IPADDR_CHAR_MAX);
strncpy(ip->prefix, prefix, PREFIX_CHAR_MAX);
if (!strchr(ip->ip_addr, ':')) {
if (!strchr(ip->ipaddr, ':')) {
ip->domain = AF_INET;
} else {
ip->domain = AF_INET6;
Expand All @@ -1083,7 +1083,7 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
if (nozzle->ip) {
secondary = 1;
}
err = _set_ip(nozzle, "add", ip_addr, prefix, error_string, secondary);
err = _set_ip(nozzle, "add", ipaddr, prefix, error_string, secondary);
savederrno = errno;
}

Expand All @@ -1108,13 +1108,13 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
return err;
}

int nozzle_del_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char **error_string)
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 ((!nozzle) || (!ip_addr) || (!prefix) || (!error_string)) {
if ((!nozzle) || (!ipaddr) || (!prefix) || (!error_string)) {
errno = EINVAL;
return -1;
}
Expand All @@ -1131,12 +1131,12 @@ int nozzle_del_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
goto out_clean;
}

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

err = _set_ip(nozzle, "del", ip_addr, prefix, error_string, 0);
err = _set_ip(nozzle, "del", ipaddr, prefix, error_string, 0);
savederrno = errno;
if (!err) {
if (ip == ip_prev) {
Expand Down Expand Up @@ -1211,15 +1211,15 @@ const char *nozzle_get_name_by_handle(const nozzle_t nozzle)
return name;
}

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

if ((!nozzle) || (!ip_addr_list) || (!entries)) {
if ((!nozzle) || (!ipaddr_list) || (!entries)) {
errno = EINVAL;
return -1;
}
Expand All @@ -1243,7 +1243,7 @@ int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries)
}

if (!found) {
*ip_addr_list = NULL;
*ipaddr_list = NULL;
*entries = 0;
goto out_clean;
}
Expand All @@ -1262,16 +1262,16 @@ int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries)
ip = nozzle->ip;

while (ip) {
len = strlen(ip->ip_addr);
memmove(ip_list + offset, ip->ip_addr, len);
len = strlen(ip->ipaddr);
memmove(ip_list + offset, ip->ipaddr, len);
offset = offset + len + 1;
len = strlen(ip->prefix);
memmove(ip_list + offset, ip->prefix, len);
offset = offset + len + 1;
ip = ip->next;
}

*ip_addr_list = ip_list;
*ipaddr_list = ip_list;
*entries = found;

out_clean:
Expand Down
16 changes: 8 additions & 8 deletions libnozzle/libnozzle.h
Expand Up @@ -131,7 +131,7 @@ int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);
*
* nozzle - pointer to the nozzle struct
*
* ip_addr - string containing either an IPv4 or an IPv6 address.
* ipaddr - string containing either an IPv4 or an IPv6 address.
* Please note that Linux will automatically remove any IPv6 addresses from an interface
* with MTU < 1280. libnozzle will cache those IPs and re-instate them when MTU is > 1280.
* MTU must be set via nozzle_set_mtu for IPv6 to be re-instated.
Expand All @@ -148,15 +148,15 @@ int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);
* error_string will contain a string recording the execution error.
*/

int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char **error_string);
int nozzle_add_ip(nozzle_t nozzle, const char *ipaddr, 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.
* ipaddr - string containing either an IPv4 or an IPv6 address.
*
* prefix - 24, 64 or any valid network prefix for the requested address.
*
Expand All @@ -170,29 +170,29 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
* 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_del_ip(nozzle_t nozzle, const char *ipaddr, 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!
* TODO: change to use a ipaddr_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.
* ipaddr_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
* ipaddr_list is a malloc'ed buffer that the user needs to parse and free after use. ipaddr_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_ips(const nozzle_t nozzle, char **ipaddr_list, int *entries);

/**
* nozzle_get_mtu
Expand Down

0 comments on commit 73c5c2e

Please sign in to comment.