Skip to content

Commit

Permalink
[nozzle] cleanup and document nozzle_(re)set_mac
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 16, 2017
1 parent 6fdc2d2 commit 81b1959
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
27 changes: 21 additions & 6 deletions libnozzle/libnozzle.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,20 @@ int nozzle_get_mac(const nozzle_t nozzle, char **ether_addr)

int nozzle_set_mac(nozzle_t nozzle, const char *ether_addr)
{
int err;
int err = 0, savederrno = 0;

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

if ((!_check(nozzle)) || (!ether_addr)) {
savederrno = pthread_mutex_lock(&lib_mutex);
if (savederrno) {
errno = savederrno;
return -1;
}

if (!_check(nozzle)) {
errno = EINVAL;
err = -1;
goto out_clean;
Expand All @@ -766,26 +775,32 @@ int nozzle_set_mac(nozzle_t nozzle, const char *ether_addr)
strncpy(nozzle->ifname, nozzle->nozzlename, IFNAMSIZ);
#ifdef KNET_LINUX
err = ioctl(lib_cfg.sockfd, SIOCGIFHWADDR, &nozzle->ifr);
if (err)
if (err) {
savederrno = errno;
goto out_clean;
}

memmove(nozzle->ifr.ifr_hwaddr.sa_data, ether_aton(ether_addr), ETH_ALEN);

err = ioctl(lib_cfg.sockfd, SIOCSIFHWADDR, &nozzle->ifr);
savederrno = errno;
#endif
#ifdef KNET_BSD
err = ioctl(lib_cfg.sockfd, SIOCGIFADDR, &nozzle->ifr);
if (err)
if (err) {
savederrno = errno;
goto out_clean;
}

memmove(nozzle->ifr.ifr_addr.sa_data, ether_aton(ether_addr), ETHER_ADDR_LEN);
nozzle->ifr.ifr_addr.sa_len = ETHER_ADDR_LEN;

err = ioctl(lib_cfg.sockfd, SIOCSIFLLADDR, &nozzle->ifr);
savederrno = errno;
#endif
out_clean:
pthread_mutex_unlock(&lib_mutex);

errno = savederrno;
return err;
}

Expand Down
26 changes: 26 additions & 0 deletions libnozzle/libnozzle.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,33 @@ int nozzle_reset_mtu(nozzle_t nozzle, char **error_string);
*/

int nozzle_get_mac(const nozzle_t nozzle, char **ether_addr);

/**
* nozzle_set_mac
* @brief set mac address on a given nozzle interface
*
* nozzle - pointer to the nozzle struct
*
* ether_addr - pointers to string containing the new mac address.
*
* @return
* 0 on success.
* -1 on error and errno is set.
*/

int nozzle_set_mac(nozzle_t nozzle, const char *ether_addr);

/**
* nozzle_reset_mac
* @brief reset mac address on a given nozzle interface to system default
*
* nozzle - pointer to the nozzle struct
*
* @return
* 0 on success.
* -1 on error and errno is set.
*/

int nozzle_reset_mac(nozzle_t nozzle);

nozzle_t nozzle_find(char *dev, size_t dev_size);
Expand Down

0 comments on commit 81b1959

Please sign in to comment.