Skip to content

Commit

Permalink
[cleanup] rename struct _ip to struct nozzle_ip and cleanup related d…
Browse files Browse the repository at this point in the history
…efines

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Dec 16, 2017
1 parent 5247399 commit 6578b48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
19 changes: 10 additions & 9 deletions libnozzle/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ struct nozzle_lib_config {
int sockfd;
};

#define MAX_IP_CHAR 128
#define MAX_PREFIX_CHAR 4
#define MAX_MAC_CHAR 18
#define IPADDR_CHAR_MAX 128
#define PREFIX_CHAR_MAX 4

struct _ip {
char ip_addr[MAX_IP_CHAR];
char prefix[MAX_PREFIX_CHAR];
struct nozzle_ip {
char ip_addr[IPADDR_CHAR_MAX];
char prefix[PREFIX_CHAR_MAX];
int domain;
struct _ip *next;
struct nozzle_ip *next;
};

#define MACADDR_CHAR_MAX 18

struct nozzle_iface {
struct ifreq ifr;
int fd;
char nozzlename[IFNAMSIZ];
char default_mac[MAX_MAC_CHAR];
char default_mac[MACADDR_CHAR_MAX];
int default_mtu;
int current_mtu;
char updownpath[PATH_MAX - 11 - 1 - IFNAMSIZ]; /* 11 = post-down.d 1 = / */
int hasupdown;
int up;
struct _ip *ip;
struct nozzle_ip *ip;
struct nozzle_iface *next;
};
#define ifname ifr.ifr_name
Expand Down
30 changes: 15 additions & 15 deletions libnozzle/libnozzle.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static int _set_ip(nozzle_t nozzle, const char *command,
char **error_string, int secondary);
static int _find_ip(nozzle_t nozzle,
const char *ip_addr, const char *prefix,
struct _ip **ip, struct _ip **ip_prev);
struct nozzle_ip **ip, struct nozzle_ip **ip_prev);

static int _read_pipe(int fd, char **file, size_t *length)
{
Expand Down Expand Up @@ -267,14 +267,14 @@ static int _get_mtu(const nozzle_t nozzle)
static int _get_mac(const nozzle_t nozzle, char **ether_addr)
{
int err = 0, savederrno = 0;
char mac[MAX_MAC_CHAR];
char mac[MACADDR_CHAR_MAX];
#ifdef KNET_BSD
struct ifaddrs *ifap = NULL;
struct ifaddrs *ifa;
int found = 0;
#endif

memset(&mac, 0, MAX_MAC_CHAR);
memset(&mac, 0, MACADDR_CHAR_MAX);
memset(&nozzle->ifr, 0, sizeof(struct ifreq));
strncpy(nozzle->ifname, nozzle->nozzlename, IFNAMSIZ);

Expand Down Expand Up @@ -550,7 +550,7 @@ int nozzle_close(nozzle_t nozzle, char **error_down, char **error_postdown)
int err = 0, savederrno = 0;
nozzle_t temp = lib_cfg.head;
nozzle_t prev = lib_cfg.head;
struct _ip *ip, *ip_next;
struct nozzle_ip *ip, *ip_next;
char *error_string = NULL;

savederrno = pthread_mutex_lock(&lib_mutex);
Expand Down Expand Up @@ -632,7 +632,7 @@ int nozzle_get_mtu(const nozzle_t nozzle)
int nozzle_set_mtu(nozzle_t nozzle, const int mtu, char **error_string)
{
int err = 0, savederrno = 0;
struct _ip *tmp_ip;
struct nozzle_ip *tmp_ip;

if ((!nozzle) || (!mtu) || (!error_string)) {
errno = EINVAL;
Expand Down Expand Up @@ -1004,9 +1004,9 @@ static int _set_ip(nozzle_t nozzle, const char *command,

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

local_ip = local_ip_prev = nozzle->ip;
Expand All @@ -1032,7 +1032,7 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
{
int err = 0, savederrno = 0;
int found = 0;
struct _ip *ip = NULL, *ip_prev = NULL, *ip_last = NULL;
struct nozzle_ip *ip = NULL, *ip_prev = NULL, *ip_last = NULL;
int secondary = 0;

if ((!nozzle) || (!ip_addr) || (!prefix) || (!error_string)) {
Expand All @@ -1057,16 +1057,16 @@ int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
goto out_clean;
}

ip = malloc(sizeof(struct _ip));
ip = malloc(sizeof(struct nozzle_ip));
if (!ip) {
savederrno = errno;
err = -1 ;
goto out_clean;
}

memset(ip, 0, sizeof(struct _ip));
strncpy(ip->ip_addr, ip_addr, MAX_IP_CHAR);
strncpy(ip->prefix, prefix, MAX_PREFIX_CHAR);
memset(ip, 0, sizeof(struct nozzle_ip));
strncpy(ip->ip_addr, ip_addr, IPADDR_CHAR_MAX);
strncpy(ip->prefix, prefix, PREFIX_CHAR_MAX);
if (!strchr(ip->ip_addr, ':')) {
ip->domain = AF_INET;
} else {
Expand Down Expand Up @@ -1112,7 +1112,7 @@ int nozzle_del_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char
{
int err = 0, savederrno = 0;
int found = 0;
struct _ip *ip = NULL, *ip_prev = NULL;
struct nozzle_ip *ip = NULL, *ip_prev = NULL;

if ((!nozzle) || (!ip_addr) || (!prefix) || (!error_string)) {
errno = EINVAL;
Expand Down Expand Up @@ -1217,7 +1217,7 @@ int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries)
int found = 0;
char *ip_list = NULL;
int size = 0, offset = 0, len;
struct _ip *ip = NULL;
struct nozzle_ip *ip = NULL;

if ((!nozzle) || (!ip_addr_list) || (!entries)) {
errno = EINVAL;
Expand Down Expand Up @@ -1248,7 +1248,7 @@ int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries)
goto out_clean;
}

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

ip_list = malloc(size);
if (!ip_list) {
Expand Down

0 comments on commit 6578b48

Please sign in to comment.