summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/common-utils.h3
-rw-r--r--rpc/rpc-transport/rdma/src/name.c19
-rw-r--r--rpc/rpc-transport/socket/src/name.c22
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-pmap.h2
4 files changed, 42 insertions, 4 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index edd198cadc0..b7d4845b138 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -82,7 +82,10 @@ void trap (void);
* nfs port in volume status.
*/
#define GF_NFS3_PORT 2049
+
#define GF_CLIENT_PORT_CEILING 1024
+#define GF_IANA_PRIV_PORTS_START 49152 /* RFC 6335 */
+#define GF_CLNT_INSECURE_PORT_CEILING (GF_IANA_PRIV_PORTS_START - 1)
#define GF_PORT_MAX 65535
#define GF_MINUTE_IN_SECONDS 60
diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c
index d4502e766bf..d5de6f8f5bc 100644
--- a/rpc/rpc-transport/rdma/src/name.c
+++ b/rpc/rpc-transport/rdma/src/name.c
@@ -57,10 +57,17 @@ af_inet_bind_to_port_lt_ceiling (struct rdma_cm_id *cm_id,
int32_t ret = -1;
uint16_t port = ceiling - 1;
gf_boolean_t ports[GF_PORT_MAX];
+ int i = 0;
+loop:
ret = gf_process_reserved_ports (ports, ceiling);
while (port) {
+ if (port == GF_CLIENT_PORT_CEILING) {
+ ret = -1;
+ break;
+ }
+
/* ignore the reserved ports */
if (ports[port] == _gf_true) {
port--;
@@ -80,6 +87,18 @@ af_inet_bind_to_port_lt_ceiling (struct rdma_cm_id *cm_id,
port--;
}
+ /* Incase if all the secure ports are exhausted, we are no more
+ * binding to secure ports, hence instead of getting a random
+ * port, lets define the range to restrict it from getting from
+ * ports reserved for bricks i.e from range of 49152 - 65535
+ * which further may lead to port clash */
+ if (!port) {
+ ceiling = port = GF_CLNT_INSECURE_PORT_CEILING;
+ for (i = 0; i <= ceiling; i++)
+ ports[i] = _gf_false;
+ goto loop;
+ }
+
return ret;
}
diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c
index 12887a72ff1..79e1dfde778 100644
--- a/rpc/rpc-transport/socket/src/name.c
+++ b/rpc/rpc-transport/socket/src/name.c
@@ -45,11 +45,17 @@ af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr,
int32_t ret = -1;
uint16_t port = ceiling - 1;
gf_boolean_t ports[GF_PORT_MAX];
+ int i = 0;
+loop:
ret = gf_process_reserved_ports (ports, ceiling);
- while (port)
- {
+ while (port) {
+ if (port == GF_CLIENT_PORT_CEILING) {
+ ret = -1;
+ break;
+ }
+
/* ignore the reserved ports */
if (ports[port] == _gf_true) {
port--;
@@ -69,6 +75,18 @@ af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr,
port--;
}
+ /* Incase if all the secure ports are exhausted, we are no more
+ * binding to secure ports, hence instead of getting a random
+ * port, lets define the range to restrict it from getting from
+ * ports reserved for bricks i.e from range of 49152 - 65535
+ * which further may lead to port clash */
+ if (!port) {
+ ceiling = port = GF_CLNT_INSECURE_PORT_CEILING;
+ for (i = 0; i <= ceiling; i++)
+ ports[i] = _gf_false;
+ goto loop;
+ }
+
return ret;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.h b/xlators/mgmt/glusterd/src/glusterd-pmap.h
index dc80c41c35b..95ded04208d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.h
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.h
@@ -23,8 +23,6 @@
#include "rpcsvc.h"
-#define GF_IANA_PRIV_PORTS_START 49152 /* RFC 6335 */
-
struct pmap_port_status {
gf_pmap_port_type_t type;
char *brickname;