Fix: deny the same port for data and control URL
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.c
index 0cf43d2ca3da002ffb7d68aef558316c75b9006a..e3d1be0ccc3446133746ba3db595242204c355ab 100644 (file)
@@ -504,6 +504,12 @@ int consumer_set_network_uri(struct consumer_output *obj,
                if (uri->port == 0) {
                        /* Assign default port. */
                        uri->port = DEFAULT_NETWORK_CONTROL_PORT;
+               } else {
+                       if (obj->dst.net.data_isset && uri->port ==
+                                       obj->dst.net.data.port) {
+                               ret = -LTTNG_ERR_INVALID;
+                               goto error;
+                       }
                }
                DBG3("Consumer control URI set with port %d", uri->port);
                break;
@@ -513,11 +519,18 @@ int consumer_set_network_uri(struct consumer_output *obj,
                if (uri->port == 0) {
                        /* Assign default port. */
                        uri->port = DEFAULT_NETWORK_DATA_PORT;
+               } else {
+                       if (obj->dst.net.control_isset && uri->port ==
+                                       obj->dst.net.control.port) {
+                               ret = -LTTNG_ERR_INVALID;
+                               goto error;
+                       }
                }
                DBG3("Consumer data URI set with port %d", uri->port);
                break;
        default:
                ERR("Set network uri type unknown %d", uri->stype);
+               ret = -LTTNG_ERR_INVALID;
                goto error;
        }
 
@@ -553,6 +566,7 @@ int consumer_set_network_uri(struct consumer_output *obj,
                }
                if (ret < 0) {
                        PERROR("snprintf set consumer uri subdir");
+                       ret = -LTTNG_ERR_NOMEM;
                        goto error;
                }
 
@@ -564,7 +578,7 @@ int consumer_set_network_uri(struct consumer_output *obj,
 equal:
        return 1;
 error:
-       return -1;
+       return ret;
 }
 
 /*
This page took 0.023947 seconds and 4 git commands to generate.