summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-resolve/sd-resolve.c178
-rw-r--r--src/libsystemd/sd-resolve/test-resolve.c63
-rw-r--r--src/systemd/sd-resolve.h13
3 files changed, 3 insertions, 251 deletions
diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c
index b0dc822591..888b372c99 100644
--- a/src/libsystemd/sd-resolve/sd-resolve.c
+++ b/src/libsystemd/sd-resolve/sd-resolve.c
@@ -48,9 +48,6 @@ typedef enum {
RESPONSE_ADDRINFO,
REQUEST_NAMEINFO,
RESPONSE_NAMEINFO,
- REQUEST_RES_QUERY,
- REQUEST_RES_SEARCH,
- RESPONSE_RES,
REQUEST_TERMINATE,
RESPONSE_DIED
} QueryType;
@@ -104,12 +101,10 @@ struct sd_resolve_query {
int _h_errno;
struct addrinfo *addrinfo;
char *serv, *host;
- unsigned char *answer;
union {
sd_resolve_getaddrinfo_handler_t getaddrinfo_handler;
sd_resolve_getnameinfo_handler_t getnameinfo_handler;
- sd_resolve_res_handler_t res_handler;
};
void *userdata;
@@ -166,33 +161,16 @@ typedef struct NameInfoResponse {
int _h_errno;
} NameInfoResponse;
-typedef struct ResRequest {
- struct RHeader header;
- int class;
- int type;
- size_t dname_len;
-} ResRequest;
-
-typedef struct ResResponse {
- struct RHeader header;
- int ret;
- int _errno;
- int _h_errno;
-} ResResponse;
-
typedef union Packet {
RHeader rheader;
AddrInfoRequest addrinfo_request;
AddrInfoResponse addrinfo_response;
NameInfoRequest nameinfo_request;
NameInfoResponse nameinfo_response;
- ResRequest res_request;
- ResResponse res_response;
} Packet;
static int getaddrinfo_done(sd_resolve_query* q);
static int getnameinfo_done(sd_resolve_query *q);
-static int res_query_done(sd_resolve_query* q);
static void resolve_query_disconnect(sd_resolve_query *q);
@@ -343,38 +321,6 @@ static int send_nameinfo_reply(
return 0;
}
-static int send_res_reply(int out_fd, unsigned id, const unsigned char *answer, int ret, int _errno, int _h_errno) {
-
- ResResponse resp = {
- .header.type = RESPONSE_RES,
- .header.id = id,
- .ret = ret,
- ._errno = _errno,
- ._h_errno = _h_errno,
- };
-
- struct msghdr mh = {};
- struct iovec iov[2];
- size_t l;
-
- assert(out_fd >= 0);
-
- l = ret > 0 ? (size_t) ret : 0;
-
- resp.header.length = sizeof(ResResponse) + l;
-
- iov[0] = (struct iovec) { .iov_base = &resp, .iov_len = sizeof(ResResponse) };
- iov[1] = (struct iovec) { .iov_base = (void*) answer, .iov_len = l };
-
- mh.msg_iov = iov;
- mh.msg_iovlen = ELEMENTSOF(iov);
-
- if (sendmsg(out_fd, &mh, MSG_NOSIGNAL) < 0)
- return -errno;
-
- return 0;
-}
-
static int handle_request(int out_fd, const Packet *packet, size_t length) {
const RHeader *req;
@@ -437,29 +383,6 @@ static int handle_request(int out_fd, const Packet *packet, size_t length) {
errno, h_errno);
}
- case REQUEST_RES_QUERY:
- case REQUEST_RES_SEARCH: {
- const ResRequest *res_req = &packet->res_request;
- union {
- HEADER header;
- uint8_t space[BUFSIZE];
- } answer;
- const char *dname;
- int ret;
-
- assert(length >= sizeof(ResRequest));
- assert(length == sizeof(ResRequest) + res_req->dname_len);
-
- dname = (const char *) res_req + sizeof(ResRequest);
-
- if (req->type == REQUEST_RES_QUERY)
- ret = res_query(dname, res_req->class, res_req->type, (unsigned char *) &answer, BUFSIZE);
- else
- ret = res_search(dname, res_req->class, res_req->type, (unsigned char *) &answer, BUFSIZE);
-
- return send_res_reply(out_fd, req->id, (unsigned char *) &answer, ret, errno, h_errno);
- }
-
case REQUEST_TERMINATE:
/* Quit */
return -ECONNRESET;
@@ -752,11 +675,6 @@ static int complete_query(sd_resolve *resolve, sd_resolve_query *q) {
r = getnameinfo_done(q);
break;
- case REQUEST_RES_QUERY:
- case REQUEST_RES_SEARCH:
- r = res_query_done(q);
- break;
-
default:
assert_not_reached("Cannot complete unknown query type");
}
@@ -923,28 +841,6 @@ static int handle_response(sd_resolve *resolve, const Packet *packet, size_t len
return complete_query(resolve, q);
}
- case RESPONSE_RES: {
- const ResResponse *res_resp = &packet->res_response;
-
- assert(length >= sizeof(ResResponse));
- assert(q->type == REQUEST_RES_QUERY || q->type == REQUEST_RES_SEARCH);
-
- q->ret = res_resp->ret;
- q->_errno = res_resp->_errno;
- q->_h_errno = res_resp->_h_errno;
-
- if (res_resp->ret >= 0) {
- q->answer = memdup((const char *)resp + sizeof(ResResponse), res_resp->ret);
- if (!q->answer) {
- q->ret = -1;
- q->_errno = ENOMEM;
- q->_h_errno = 0;
- }
- }
-
- return complete_query(resolve, q);
- }
-
default:
return 0;
}
@@ -1181,79 +1077,6 @@ static int getnameinfo_done(sd_resolve_query *q) {
return q->getnameinfo_handler(q, q->ret, q->host, q->serv, q->userdata);
}
-static int resolve_res(
- sd_resolve *resolve,
- sd_resolve_query **_q,
- QueryType qtype,
- const char *dname,
- int class, int type,
- sd_resolve_res_handler_t callback, void *userdata) {
-
- struct msghdr mh = {};
- struct iovec iov[2];
- ResRequest req = {};
- sd_resolve_query *q;
- int r;
-
- assert_return(resolve, -EINVAL);
- assert_return(dname, -EINVAL);
- assert_return(callback, -EINVAL);
- assert_return(!resolve_pid_changed(resolve), -ECHILD);
-
- r = alloc_query(resolve, !_q, &q);
- if (r < 0)
- return r;
-
- q->type = qtype;
- q->res_handler = callback;
- q->userdata = userdata;
-
- req.dname_len = strlen(dname) + 1;
- req.class = class;
- req.type = type;
-
- req.header.id = q->id;
- req.header.type = qtype;
- req.header.length = sizeof(ResRequest) + req.dname_len;
-
- iov[0] = (struct iovec) { .iov_base = &req, .iov_len = sizeof(ResRequest) };
- iov[1] = (struct iovec) { .iov_base = (void*) dname, .iov_len = req.dname_len };
-
- mh.msg_iov = iov;
- mh.msg_iovlen = 2;
-
- if (sendmsg(resolve->fds[REQUEST_SEND_FD], &mh, MSG_NOSIGNAL) < 0) {
- sd_resolve_query_unref(q);
- return -errno;
- }
-
- resolve->n_outstanding++;
-
- if (_q)
- *_q = q;
-
- return 0;
-}
-
-_public_ int sd_resolve_res_query(sd_resolve *resolve, sd_resolve_query** q, const char *dname, int class, int type, sd_resolve_res_handler_t callback, void *userdata) {
- return resolve_res(resolve, q, REQUEST_RES_QUERY, dname, class, type, callback, userdata);
-}
-
-_public_ int sd_resolve_res_search(sd_resolve *resolve, sd_resolve_query** q, const char *dname, int class, int type, sd_resolve_res_handler_t callback, void *userdata) {
- return resolve_res(resolve, q, REQUEST_RES_SEARCH, dname, class, type, callback, userdata);
-}
-
-static int res_query_done(sd_resolve_query* q) {
- assert(q);
- assert(q->done);
- assert(q->res_handler);
-
- errno = q->_errno;
- h_errno = q->_h_errno;
-
- return q->res_handler(q, q->ret, q->answer, q->userdata);
-}
-
_public_ sd_resolve_query* sd_resolve_query_ref(sd_resolve_query *q) {
assert_return(q, NULL);
@@ -1310,7 +1133,6 @@ static void resolve_query_free(sd_resolve_query *q) {
resolve_freeaddrinfo(q->addrinfo);
free(q->host);
free(q->serv);
- free(q->answer);
free(q);
}
diff --git a/src/libsystemd/sd-resolve/test-resolve.c b/src/libsystemd/sd-resolve/test-resolve.c
index 354a4071b7..e8056529f5 100644
--- a/src/libsystemd/sd-resolve/test-resolve.c
+++ b/src/libsystemd/sd-resolve/test-resolve.c
@@ -67,59 +67,8 @@ static int getnameinfo_handler(sd_resolve_query *q, int ret, const char *host, c
return 0;
}
-static int res_handler(sd_resolve_query *q, int ret, unsigned char *answer, void *userdata) {
- int qdcount, ancount, len;
- const unsigned char *pos = answer + sizeof(HEADER);
- unsigned char *end = answer + ret;
- HEADER *head = (HEADER *) answer;
- char name[256];
- assert_se(q);
-
- if (ret < 0) {
- log_error("res_query() error: %s %i", strerror(errno), errno);
- return 0;
- }
-
- if (ret == 0) {
- log_error("No reply for SRV lookup");
- return 0;
- }
-
- qdcount = ntohs(head->qdcount);
- ancount = ntohs(head->ancount);
-
- printf("%d answers for srv lookup:\n", ancount);
-
- /* Ignore the questions */
- while (qdcount-- > 0 && (len = dn_expand(answer, end, pos, name, 255)) >= 0) {
- assert_se(len >= 0);
- pos += len + QFIXEDSZ;
- }
-
- /* Parse the answers */
- while (ancount-- > 0 && (len = dn_expand(answer, end, pos, name, 255)) >= 0) {
- /* Ignore the initial string */
- uint16_t pref, weight, port;
- assert_se(len >= 0);
- pos += len;
- /* Ignore type, ttl, class and dlen */
- pos += 10;
-
- GETSHORT(pref, pos);
- GETSHORT(weight, pos);
- GETSHORT(port, pos);
- len = dn_expand(answer, end, pos, name, 255);
- printf("\tpreference: %2d weight: %2d port: %d host: %s\n",
- pref, weight, port, name);
-
- pos += len;
- }
-
- return 0;
-}
-
int main(int argc, char *argv[]) {
- _cleanup_resolve_query_unref_ sd_resolve_query *q1 = NULL, *q2 = NULL, *q3 = NULL;
+ _cleanup_resolve_query_unref_ sd_resolve_query *q1 = NULL, *q2 = NULL;
_cleanup_resolve_unref_ sd_resolve *resolve = NULL;
int r = 0;
@@ -150,15 +99,9 @@ int main(int argc, char *argv[]) {
if (r < 0)
log_error_errno(r, "sd_resolve_getnameinfo(): %m");
- /* Make a res_query() call */
- r = sd_resolve_res_query(resolve, &q3, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV, res_handler, NULL);
- if (r < 0)
- log_error_errno(r, "sd_resolve_res_query(): %m");
-
- /* Wait until the three queries are completed */
+ /* Wait until the two queries are completed */
while (sd_resolve_query_is_done(q1) == 0 ||
- sd_resolve_query_is_done(q2) == 0 ||
- sd_resolve_query_is_done(q3) == 0) {
+ sd_resolve_query_is_done(q2) == 0) {
r = sd_resolve_wait(resolve, (uint64_t) -1);
if (r < 0) {
diff --git a/src/systemd/sd-resolve.h b/src/systemd/sd-resolve.h
index 36cedcd6b5..80c5852e45 100644
--- a/src/systemd/sd-resolve.h
+++ b/src/systemd/sd-resolve.h
@@ -40,7 +40,6 @@ typedef struct sd_resolve_query sd_resolve_query;
/* A callback on completion */
typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
-typedef int (*sd_resolve_res_handler_t)(sd_resolve_query* q, int ret, unsigned char *answer, void *userdata);
enum {
SD_RESOLVE_GET_HOST = 1ULL,
@@ -99,18 +98,6 @@ int sd_resolve_getaddrinfo(sd_resolve *resolve, sd_resolve_query **q, const char
* if you want to query the hostname (resp. the service name). */
int sd_resolve_getnameinfo(sd_resolve *resolve, sd_resolve_query **q, const struct sockaddr *sa, socklen_t salen, int flags, uint64_t get, sd_resolve_getnameinfo_handler_t callback, void *userdata);
-/* Issue a resolver query on the specified session. The arguments are
- * compatible with those of libc's res_query(3). The function returns a new
- * query object. When the query is completed, you may retrieve the results using
- * sd_resolve_res_done(). */
-int sd_resolve_res_query(sd_resolve *resolve, sd_resolve_query **q, const char *dname, int clazz, int type, sd_resolve_res_handler_t callback, void *userdata);
-
-/* Issue a resolver query on the specified session. The arguments are
- * compatible with those of libc's res_search(3). The function returns a new
- * query object. When the query is completed, you may retrieve the results using
- * sd_resolve_res_done(). */
-int sd_resolve_res_search(sd_resolve *resolve, sd_resolve_query **q, const char *dname, int clazz, int type, sd_resolve_res_handler_t callback, void *userdata);
-
sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
sd_resolve_query *sd_resolve_query_unref(sd_resolve_query* q);