Permalink
Browse files

link: protect set/get config from doing damages

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information...
fabbione committed Jan 20, 2013
1 parent ce8c32c commit ac9bfd653523c570d80da61204ac95e0cf0b07b4
Showing with 19 additions and 1 deletion.
  1. +1 −0 libknet/internals.h
  2. +18 −1 libknet/link.c
View
@@ -40,6 +40,7 @@ struct knet_link {
/* internals */
uint8_t link_id;
int listener_sock;
+ unsigned int configured:1; /* set to 1 if src/dst have been configured */
unsigned int remoteconnected:1; /* link is enabled for data (peer view) */
unsigned int donnotremoteupdate:1; /* define source of the update */
unsigned int host_info_up_sent:1; /* 0 if we need to notify remote that link is up */
View
@@ -237,7 +237,13 @@ int knet_link_set_config(knet_handle_t knet_h, uint16_t host_id, uint8_t link_id
link = &host->link[link_id];
- /* rememeber to check if link is on traffic before allowing reconfig */
+ if (link->status.enabled != 0) {
+ err =-1;
+ savederrno = EBUSY;
+ log_err(knet_h, KNET_SUB_LINK, "Host %u link %u is currently in use: %s",
+ host_id, link_id, strerror(savederrno));
+ goto exit_unlock;
+ }
memcpy(&link->src_addr, src_addr, sizeof(struct sockaddr_storage));
@@ -290,6 +296,9 @@ int knet_link_set_config(knet_handle_t knet_h, uint16_t host_id, uint8_t link_id
}
exit_unlock:
+ if (!err) {
+ link->configured = 1;
+ }
pthread_rwlock_unlock(&knet_h->list_rwlock);
errno = savederrno;
return err;
@@ -342,6 +351,14 @@ int knet_link_get_config(knet_handle_t knet_h, uint16_t host_id, uint8_t link_id
link = &host->link[link_id];
+ if (!link->configured) {
+ err = -1;
+ savederrno = EINVAL;
+ log_err(knet_h, KNET_SUB_LINK, "host %u link %u is not configured: %s",
+ host_id, link_id, strerror(savederrno));
+ goto exit_unlock;
+ }
+
memcpy(src_addr, &link->src_addr, sizeof(struct sockaddr_storage));
if (link->dynamic == KNET_LINK_DYNIP) {

0 comments on commit ac9bfd6

Please sign in to comment.