03562e
diff -up libtirpc-1.1.4/man/rpcbind.3t.orig libtirpc-1.1.4/man/rpcbind.3t
03562e
--- libtirpc-1.1.4/man/rpcbind.3t.orig	2018-08-27 10:06:49.000000000 -0400
03562e
+++ libtirpc-1.1.4/man/rpcbind.3t	2022-08-02 11:21:30.134642780 -0400
03562e
@@ -187,6 +187,8 @@ in
03562e
 .El
03562e
 .Sh AVAILABILITY
03562e
 These functions are part of libtirpc.
03562e
+.Sh ENVIRONMENT
03562e
+If RPCB_V2FIRST is defined, rpcbind protocol version tryout algorithm changes from v4,v2,v3 to v2,v4,v3.
03562e
 .Sh SEE ALSO
03562e
 .Xr rpc_clnt_calls 3 ,
03562e
 .Xr rpc_svc_calls 3 ,
03562e
diff -up libtirpc-1.1.4/src/rpcb_clnt.c.orig libtirpc-1.1.4/src/rpcb_clnt.c
03562e
--- libtirpc-1.1.4/src/rpcb_clnt.c.orig	2022-08-02 11:20:42.795833195 -0400
03562e
+++ libtirpc-1.1.4/src/rpcb_clnt.c	2022-08-02 11:21:30.135642797 -0400
03562e
@@ -818,7 +818,8 @@ error:
03562e
  * The algorithm used: If the transports is TCP or UDP, it first tries
03562e
  * version 4 (srv4), then 3 and then fall back to version 2 (portmap).
03562e
  * With this algorithm, we get performance as well as a plan for
03562e
- * obsoleting version 2.
03562e
+ * obsoleting version 2. This behaviour is reverted to old algorithm
03562e
+ * if RPCB_V2FIRST environment var is defined
03562e
  *
03562e
  * For all other transports, the algorithm remains as 4 and then 3.
03562e
  *
03562e
@@ -839,6 +840,10 @@ __rpcb_findaddr_timed(program, version,
03562e
 #ifdef NOTUSED
03562e
 	static bool_t check_rpcbind = TRUE;
03562e
 #endif
03562e
+
03562e
+#ifdef PORTMAP
03562e
+	static bool_t portmap_first = FALSE;
03562e
+#endif
03562e
 	CLIENT *client = NULL;
03562e
 	RPCB parms;
03562e
 	enum clnt_stat clnt_st;
03562e
@@ -895,8 +900,18 @@ __rpcb_findaddr_timed(program, version,
03562e
 		parms.r_addr = (char *) &nullstring[0];
03562e
 	}
03562e
 
03562e
-	/* First try from start_vers(4) and then version 3 (RPCBVERS) */
03562e
+	/* First try from start_vers(4) and then version 3 (RPCBVERS), except
03562e
+	 * if env. var RPCB_V2FIRST is defined */
03562e
+
03562e
+#ifdef PORTMAP
03562e
+	if (getenv(V2FIRST)) {
03562e
+		portmap_first = TRUE;
03562e
+		LIBTIRPC_DEBUG(3, ("__rpcb_findaddr_timed: trying v2-port first\n"));
03562e
+		goto portmap;
03562e
+	}
03562e
+#endif
03562e
 
03562e
+rpcbind:
03562e
 	CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *) &rpcbrmttime);
03562e
 	for (vers = start_vers;  vers >= RPCBVERS; vers--) {
03562e
 		/* Set the version */
03562e
@@ -944,10 +959,17 @@ __rpcb_findaddr_timed(program, version,
03562e
 	}
03562e
 
03562e
 #ifdef PORTMAP 	/* Try version 2 for TCP or UDP */
03562e
+	if (portmap_first)
03562e
+		goto error; /* we tried all versions if reached here */
03562e
+portmap:
03562e
 	if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
03562e
 		address = __try_protocol_version_2(program, version, nconf, host, tp);
03562e
-		if (address == NULL)
03562e
-			goto error;
03562e
+		if (address == NULL) {
03562e
+			if (portmap_first)
03562e
+				goto rpcbind;
03562e
+			else
03562e
+				goto error;
03562e
+		}
03562e
 	}
03562e
 #endif		/* PORTMAP */
03562e
 
03562e
diff -up libtirpc-1.1.4/tirpc/rpc/pmap_prot.h.orig libtirpc-1.1.4/tirpc/rpc/pmap_prot.h
03562e
--- libtirpc-1.1.4/tirpc/rpc/pmap_prot.h.orig	2018-08-27 10:06:49.000000000 -0400
03562e
+++ libtirpc-1.1.4/tirpc/rpc/pmap_prot.h	2022-08-02 11:21:30.135642797 -0400
03562e
@@ -84,6 +84,8 @@
03562e
 #define PMAPPROC_DUMP		((u_long)4)
03562e
 #define PMAPPROC_CALLIT		((u_long)5)
03562e
 
03562e
+#define V2FIRST		"RPCB_V2FIRST"
03562e
+
03562e
 struct pmap {
03562e
 	long unsigned pm_prog;
03562e
 	long unsigned pm_vers;