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