Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177961878
D61768.1795658384.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D61768.1795658384.diff
View Options
diff --git a/usr.sbin/rpcbind/check_bound.c b/usr.sbin/rpcbind/check_bound.c
--- a/usr.sbin/rpcbind/check_bound.c
+++ b/usr.sbin/rpcbind/check_bound.c
@@ -43,6 +43,8 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include <netinet/in.h>
+
#include <rpc/rpc.h>
#include <rpc/svc_dg.h>
@@ -67,6 +69,7 @@
static char nullstring[] = "";
static bool_t check_bound(struct fdlist *, const char *uaddr);
+static bool_t is_wildcard_addr(const struct netbuf *);
/*
* Returns 1 if the given address is bound for the given addr & transport
@@ -103,6 +106,41 @@
return (ans == 0 ? FALSE : TRUE);
}
+/*
+ * Returns TRUE if nb holds an IPv4 or IPv6 wildcard (unspecified) address.
+ *
+ * For a datagram transport, svc_dg_create() sets xp_ltaddr once from
+ * getsockname(). rpcbind's UDP sockets are bound to the wildcard address,
+ * so svc_getrpccallee() returns 0.0.0.0 or :: (not the address the
+ * client sent to). A wildcard says nothing about which local address the
+ * client contacted, and passing it to addrmerge() as the hint makes it
+ * return the first non-loopback interface address. In a multi-FIB
+ * environment this may result in an address that the requester cannot
+ * reach.
+ */
+static bool_t
+is_wildcard_addr(const struct netbuf *nb)
+{
+ const struct sockaddr *sa;
+
+ if (nb == NULL || nb->buf == NULL ||
+ nb->len < sizeof(struct sockaddr_in))
+ return (FALSE);
+ sa = (const struct sockaddr *)nb->buf;
+ switch (sa->sa_family) {
+ case AF_INET:
+ return (((const struct sockaddr_in *)sa)->sin_addr.s_addr ==
+ htonl(INADDR_ANY));
+ case AF_INET6:
+ if (nb->len < sizeof(struct sockaddr_in6))
+ return (FALSE);
+ return (IN6_IS_ADDR_UNSPECIFIED(
+ &((const struct sockaddr_in6 *)sa)->sin6_addr));
+ default:
+ return (FALSE);
+ }
+}
+
int
add_bndlist(const struct netconfig *nconf, struct netbuf *baddr __unused)
{
@@ -155,7 +193,8 @@
mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char *saddr)
{
struct fdlist *fdl;
- struct netbuf *callee;
+ struct netconfig *xprt_nconf;
+ struct netbuf *callee, *dstaddr;
char *c_uaddr, *s_uaddr, *m_uaddr, *allocated_uaddr = NULL;
for (fdl = fdhead; fdl; fdl = fdl->next)
@@ -175,11 +214,33 @@
* If saddr is not NULL, the remote client may have included the
* address by which it contacted us. Use that for the "client" uaddr,
* otherwise use the info from the SVCXPRT.
+ *
+ * Ignore a wildcard local address (UDP on a wildcard-bound socket);
+ * see is_wildcard_addr(). TCP always has a real local address.
+ *
+ * For UDP over IPv4, svc_dg enables IP_RECVDSTADDR on wildcard-bound
+ * sockets and stores each request's destination address in
+ * su_srcaddr. Use it next, as rpcbind did before xp_ltaddr was used.
+ * xp_p2 points at a struct svc_dg_data only for datagram transports,
+ * so check the semantics of the transport the request arrived on.
+ * Do not use fdl->nconf for this: GETADDRLIST calls mergeaddr() with
+ * the netid of each registered entry (e.g. "tcp"), not the transport's.
+ * For IPv6, su_srcaddr.buf is NULL.
*/
callee = svc_getrpccallee(xprt);
- if (callee != NULL && callee->buf != NULL) {
+ dstaddr = NULL;
+ xprt_nconf = rpcbind_get_conf(xprt->xp_netid);
+ if (xprt_nconf != NULL && xprt_nconf->nc_semantics == NC_TPI_CLTS &&
+ xprt->xp_p2 != NULL)
+ dstaddr = &((struct svc_dg_data *)xprt->xp_p2)->su_srcaddr;
+ if (callee != NULL && callee->buf != NULL &&
+ !is_wildcard_addr(callee)) {
c_uaddr = taddr2uaddr(fdl->nconf, callee);
allocated_uaddr = c_uaddr;
+ } else if (dstaddr != NULL && dstaddr->buf != NULL &&
+ dstaddr->len != 0 && !is_wildcard_addr(dstaddr)) {
+ c_uaddr = taddr2uaddr(fdl->nconf, dstaddr);
+ allocated_uaddr = c_uaddr;
} else if (saddr != NULL) {
c_uaddr = saddr;
} else {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 26, 1:59 AM (23 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41872900
Default Alt Text
D61768.1795658384.diff (3 KB)
Attached To
Mode
D61768: rpcbind: fix the contact address for UDP requests in mergeaddr()
Attached
Detach File
Event Timeline