Skip to content

Commit

Permalink
[nozzle] cleanup and document nozzle_set_up
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 24, 2017
1 parent cf20ad6 commit 5cd0eb6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
36 changes: 25 additions & 11 deletions libnozzle/libnozzle.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,46 +751,60 @@ int nozzle_reset_mac(nozzle_t nozzle)

int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up)
{
int err = 0;
int err = 0, savederrno = 0;

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

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

if (!_check(nozzle)) {
errno = EINVAL;
savederrno = EINVAL;
err = -1;
goto out_clean;
}

if ((nozzle->hasupdown) && ((!error_preup) || (!error_up))) {
errno = EINVAL;
savederrno = EINVAL;
err = -1;
goto out_clean;
}

if (nozzle->up)
if (nozzle->up) {
goto out_clean;
}

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

err=ioctl(lib_cfg.sockfd, SIOCGIFFLAGS, &nozzle->ifr);
if (err)
err = ioctl(lib_cfg.sockfd, SIOCGIFFLAGS, &nozzle->ifr);
if (err) {
savederrno = errno;
goto out_clean;
}

_exec_updown(nozzle, "pre-up.d", error_preup);

nozzle->ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
err=ioctl(lib_cfg.sockfd, SIOCSIFFLAGS, &nozzle->ifr);

if (err)
err = ioctl(lib_cfg.sockfd, SIOCSIFFLAGS, &nozzle->ifr);
if (err) {
savederrno = errno;
goto out_clean;
}

_exec_updown(nozzle, "up.d", error_up);

nozzle->up = 1;

out_clean:
pthread_mutex_unlock(&lib_mutex);

errno = savederrno;
return err;
}

Expand Down
28 changes: 25 additions & 3 deletions libnozzle/libnozzle.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ nozzle_t nozzle_open(char *devname, size_t devname_size, const char *updownpath)

int nozzle_close(nozzle_t nozzle, char **error_down, char **error_postdown);

/**
* nozzle_set_up
* @brief equivalent of ifconfig up, executes pre-up.d up.d if configured
*
* nozzle - pointer to the nozzle struct
*
* error_preup - pointers to string to record errors from executing pre-up.d
* when configured. The string is malloc'ed, the caller needs to free those
* buffers.
*
* error_up - pointers to string to record errors from executing up.d
* when configured. The string is malloc'ed, the caller needs to free those
* buffers.
*
* @return
* 0 on success
* -1 on error and error 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.
*/

int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up);
int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);

nozzle_t nozzle_find(char *dev, size_t dev_size);

int nozzle_get_fd(const nozzle_t nozzle);
Expand All @@ -91,9 +116,6 @@ int nozzle_get_mac(const nozzle_t nozzle, char **ether_addr);
int nozzle_set_mac(nozzle_t nozzle, const char *ether_addr);
int nozzle_reset_mac(nozzle_t nozzle);

int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up);
int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);

int nozzle_add_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char **error_string);
int nozzle_del_ip(nozzle_t nozzle, const char *ip_addr, const char *prefix, char **error_string);
int nozzle_get_ips(const nozzle_t nozzle, char **ip_addr_list, int *entries);
Expand Down

0 comments on commit 5cd0eb6

Please sign in to comment.