Skip to content

Commit 8ae785a

Browse files
MarkZhang81shefty
authored andcommitted
librdmacm: Support DNS in resolve and query addrinfo
Allow rdma_resolve_addrinfo() and rdma_query_addrinfo() to support DNS resolve and query, respectively. A new flags "RAI_DNS" is supported to indicate this is a DNS resolve request. This flag is mutual exclusive with RAI_SA. If both are not set then DNS resolve is performed by default. With this patch a user may resolve both DNS and SA, and it's possible that one thread is querying the resolved addrinfo while another thread is resolving. So protect the route.resolved_ai with id_priv->mut lock. Signed-off-by: Mark Zhang <[email protected]>
1 parent bba3141 commit 8ae785a

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

librdmacm/cma.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,9 @@ static void ucma_process_addrinfo_resolved(struct cma_event *evt)
25912591
{
25922592
struct rdma_addrinfo *rai;
25932593

2594+
if (evt->id_priv->resolved_ai) /* DNS */
2595+
return;
2596+
25942597
rai = ucma_query_ib_service(evt->id_priv);
25952598
if (!rai) {
25962599
evt->event.event = RDMA_CM_EVENT_ADDRINFO_ERROR;
@@ -2756,8 +2759,19 @@ int rdma_get_cm_event(struct rdma_event_channel *channel,
27562759
memcpy(&evt->event.param.arg, resp.param.arg32,
27572760
sizeof(evt->event.param.arg));
27582761
break;
2759-
case RDMA_CM_EVENT_INTERNAL:
2762+
case RDMA_CM_EVENT_INTERNAL: {
2763+
uint64_t resp_arg;
2764+
2765+
memcpy(&resp_arg, resp.param.arg32, sizeof(resp_arg));
2766+
if (resp_arg == RDMA_CM_EVENT_ADDRINFO_RESOLVED) {
2767+
evt->event.event = RDMA_CM_EVENT_ADDRINFO_RESOLVED;
2768+
ucma_process_addrinfo_resolved(evt);
2769+
} else {
2770+
return ERR(EBADE);
2771+
}
2772+
27602773
break;
2774+
}
27612775
default:
27622776
evt->id_priv = (void *) (uintptr_t) resp.uid;
27632777
evt->event.id = &evt->id_priv->id;
@@ -3144,17 +3158,45 @@ static int resolve_ai_sa(struct cma_id_private *id_priv, const char *service)
31443158
return ucma_complete(&id_priv->id);
31453159
}
31463160

3161+
static int resolve_ai_dns(struct cma_id_private *id_priv, const char *node,
3162+
const char *service,
3163+
const struct rdma_addrinfo *hints)
3164+
{
3165+
int ret;
3166+
3167+
ret = rdma_getaddrinfo(node, service, hints, &id_priv->resolved_ai);
3168+
if (ret)
3169+
return ret;
3170+
3171+
ret = __rdma_write_cm_event(&id_priv->id, RDMA_CM_EVENT_INTERNAL, 0,
3172+
(uint64_t)RDMA_CM_EVENT_ADDRINFO_RESOLVED);
3173+
if (ret) {
3174+
rdma_freeaddrinfo(id_priv->resolved_ai);
3175+
id_priv->resolved_ai = NULL;
3176+
return (ret >= 0) ? ERR(ENODATA) : -1;
3177+
}
3178+
3179+
return ucma_complete(&id_priv->id);
3180+
}
3181+
31473182
static int __rdma_resolve_addrinfo(struct cma_id_private *id_priv,
31483183
const char *node, const char *service,
31493184
const struct rdma_addrinfo *hints)
31503185
{
3186+
if (!hints)
3187+
goto resolve_dns;
3188+
3189+
if ((hints->ai_flags & RAI_SA) && (hints->ai_flags & RAI_DNS))
3190+
return ENOTSUP;
3191+
31513192
if (hints->ai_flags & RAI_SA) {
31523193
if (node)
31533194
return ENOTSUP;
31543195
return resolve_ai_sa(id_priv, service);
31553196
}
31563197

3157-
return EINVAL;
3198+
resolve_dns:
3199+
return resolve_ai_dns(id_priv, node, service, hints);
31583200
}
31593201

31603202
int rdma_resolve_addrinfo(struct rdma_cm_id *id, const char *node,
@@ -3164,7 +3206,7 @@ int rdma_resolve_addrinfo(struct rdma_cm_id *id, const char *node,
31643206
struct cma_id_private *id_priv;
31653207
int ret = 0;
31663208

3167-
if (!id || !hints)
3209+
if (!id)
31683210
return ERR(EINVAL);
31693211

31703212
id_priv = container_of(id, struct cma_id_private, id);

librdmacm/rdma_cma.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct rdma_cm_event {
184184
#define RAI_NOROUTE 0x00000004
185185
#define RAI_FAMILY 0x00000008
186186
#define RAI_SA 0x00000010
187+
#define RAI_DNS 0x00000020 /* Mutual-exclusive with RAI_SA */
187188

188189
struct rdma_addrinfo {
189190
int ai_flags;

0 commit comments

Comments
 (0)