resolved: name TCP and UDP socket calls uniformly
Previously the calls for emitting DNS UDP packets were just called dns_{transacion|scope}_emit(), but the one to establish a DNS TCP connection was called dns_transaction_open_tcp(). Clean this up, and rename them dns_{transaction|scope}_emit_udp() and dns_transaction_open_tcp().
This commit is contained in:
parent
b652d4a209
commit
49cce12d4a
|
@ -279,7 +279,7 @@ static int dns_scope_emit_one(DnsScope *s, int fd, DnsServer *server, DnsPacket
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dns_scope_emit(DnsScope *s, int fd, DnsServer *server, DnsPacket *p) {
|
int dns_scope_emit_udp(DnsScope *s, int fd, DnsServer *server, DnsPacket *p) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
|
@ -405,11 +405,11 @@ static int dns_scope_socket(DnsScope *s, int type, int family, const union in_ad
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dns_scope_udp_dns_socket(DnsScope *s, DnsServer **server) {
|
int dns_scope_socket_udp(DnsScope *s, DnsServer **server) {
|
||||||
return dns_scope_socket(s, SOCK_DGRAM, AF_UNSPEC, NULL, 53, server);
|
return dns_scope_socket(s, SOCK_DGRAM, AF_UNSPEC, NULL, 53, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dns_scope_tcp_socket(DnsScope *s, int family, const union in_addr_union *address, uint16_t port, DnsServer **server) {
|
int dns_scope_socket_tcp(DnsScope *s, int family, const union in_addr_union *address, uint16_t port, DnsServer **server) {
|
||||||
return dns_scope_socket(s, SOCK_STREAM, family, address, port, server);
|
return dns_scope_socket(s, SOCK_STREAM, family, address, port, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -869,7 +869,7 @@ static int on_conflict_dispatch(sd_event_source *es, usec_t usec, void *userdata
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = dns_scope_emit(scope, -1, NULL, p);
|
r = dns_scope_emit_udp(scope, -1, NULL, p);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to send conflict packet: %m");
|
log_debug_errno(r, "Failed to send conflict packet: %m");
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,9 @@ DnsScope* dns_scope_free(DnsScope *s);
|
||||||
void dns_scope_packet_received(DnsScope *s, usec_t rtt);
|
void dns_scope_packet_received(DnsScope *s, usec_t rtt);
|
||||||
void dns_scope_packet_lost(DnsScope *s, usec_t usec);
|
void dns_scope_packet_lost(DnsScope *s, usec_t usec);
|
||||||
|
|
||||||
int dns_scope_emit(DnsScope *s, int fd, DnsServer *server, DnsPacket *p);
|
int dns_scope_emit_udp(DnsScope *s, int fd, DnsServer *server, DnsPacket *p);
|
||||||
int dns_scope_tcp_socket(DnsScope *s, int family, const union in_addr_union *address, uint16_t port, DnsServer **server);
|
int dns_scope_socket_tcp(DnsScope *s, int family, const union in_addr_union *address, uint16_t port, DnsServer **server);
|
||||||
int dns_scope_udp_dns_socket(DnsScope *s, DnsServer **server);
|
int dns_scope_socket_udp(DnsScope *s, DnsServer **server);
|
||||||
|
|
||||||
DnsScopeMatch dns_scope_good_domain(DnsScope *s, int ifindex, uint64_t flags, const char *domain);
|
DnsScopeMatch dns_scope_good_domain(DnsScope *s, int ifindex, uint64_t flags, const char *domain);
|
||||||
int dns_scope_good_key(DnsScope *s, DnsResourceKey *key);
|
int dns_scope_good_key(DnsScope *s, DnsResourceKey *key);
|
||||||
|
|
|
@ -349,13 +349,13 @@ static int dns_transaction_open_tcp(DnsTransaction *t) {
|
||||||
|
|
||||||
switch (t->scope->protocol) {
|
switch (t->scope->protocol) {
|
||||||
case DNS_PROTOCOL_DNS:
|
case DNS_PROTOCOL_DNS:
|
||||||
fd = dns_scope_tcp_socket(t->scope, AF_UNSPEC, NULL, 53, &server);
|
fd = dns_scope_socket_tcp(t->scope, AF_UNSPEC, NULL, 53, &server);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DNS_PROTOCOL_LLMNR:
|
case DNS_PROTOCOL_LLMNR:
|
||||||
/* When we already received a reply to this (but it was truncated), send to its sender address */
|
/* When we already received a reply to this (but it was truncated), send to its sender address */
|
||||||
if (t->received)
|
if (t->received)
|
||||||
fd = dns_scope_tcp_socket(t->scope, t->received->family, &t->received->sender, t->received->sender_port, NULL);
|
fd = dns_scope_socket_tcp(t->scope, t->received->family, &t->received->sender, t->received->sender_port, NULL);
|
||||||
else {
|
else {
|
||||||
union in_addr_union address;
|
union in_addr_union address;
|
||||||
int family = AF_UNSPEC;
|
int family = AF_UNSPEC;
|
||||||
|
@ -372,7 +372,7 @@ static int dns_transaction_open_tcp(DnsTransaction *t) {
|
||||||
if (family != t->scope->family)
|
if (family != t->scope->family)
|
||||||
return -ESRCH;
|
return -ESRCH;
|
||||||
|
|
||||||
fd = dns_scope_tcp_socket(t->scope, family, &address, LLMNR_PORT, NULL);
|
fd = dns_scope_socket_tcp(t->scope, family, &address, LLMNR_PORT, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -717,7 +717,7 @@ static int on_dns_packet(sd_event_source *s, int fd, uint32_t revents, void *use
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dns_transaction_emit(DnsTransaction *t) {
|
static int dns_transaction_emit_udp(DnsTransaction *t) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(t);
|
assert(t);
|
||||||
|
@ -726,7 +726,7 @@ static int dns_transaction_emit(DnsTransaction *t) {
|
||||||
DnsServer *server = NULL;
|
DnsServer *server = NULL;
|
||||||
_cleanup_close_ int fd = -1;
|
_cleanup_close_ int fd = -1;
|
||||||
|
|
||||||
fd = dns_scope_udp_dns_socket(t->scope, &server);
|
fd = dns_scope_socket_udp(t->scope, &server);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
|
@ -739,7 +739,7 @@ static int dns_transaction_emit(DnsTransaction *t) {
|
||||||
t->server = dns_server_ref(server);
|
t->server = dns_server_ref(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = dns_scope_emit(t->scope, t->dns_udp_fd, t->server, t->sent);
|
r = dns_scope_emit_udp(t->scope, t->dns_udp_fd, t->server, t->sent);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -759,17 +759,17 @@ static int on_transaction_timeout(sd_event_source *s, usec_t usec, void *userdat
|
||||||
if (!t->initial_jitter_scheduled || t->initial_jitter_elapsed) {
|
if (!t->initial_jitter_scheduled || t->initial_jitter_elapsed) {
|
||||||
/* Timeout reached? Increase the timeout for the server used */
|
/* Timeout reached? Increase the timeout for the server used */
|
||||||
switch (t->scope->protocol) {
|
switch (t->scope->protocol) {
|
||||||
|
|
||||||
case DNS_PROTOCOL_DNS:
|
case DNS_PROTOCOL_DNS:
|
||||||
assert(t->server);
|
assert(t->server);
|
||||||
|
|
||||||
dns_server_packet_lost(t->server, t->current_features, usec - t->start_usec);
|
dns_server_packet_lost(t->server, t->current_features, usec - t->start_usec);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DNS_PROTOCOL_LLMNR:
|
case DNS_PROTOCOL_LLMNR:
|
||||||
case DNS_PROTOCOL_MDNS:
|
case DNS_PROTOCOL_MDNS:
|
||||||
dns_scope_packet_lost(t->scope, usec - t->start_usec);
|
dns_scope_packet_lost(t->scope, usec - t->start_usec);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert_not_reached("Invalid DNS protocol.");
|
assert_not_reached("Invalid DNS protocol.");
|
||||||
}
|
}
|
||||||
|
@ -795,15 +795,18 @@ static usec_t transaction_get_resend_timeout(DnsTransaction *t) {
|
||||||
assert(t->scope);
|
assert(t->scope);
|
||||||
|
|
||||||
switch (t->scope->protocol) {
|
switch (t->scope->protocol) {
|
||||||
|
|
||||||
case DNS_PROTOCOL_DNS:
|
case DNS_PROTOCOL_DNS:
|
||||||
assert(t->server);
|
assert(t->server);
|
||||||
|
|
||||||
return t->server->resend_timeout;
|
return t->server->resend_timeout;
|
||||||
|
|
||||||
case DNS_PROTOCOL_MDNS:
|
case DNS_PROTOCOL_MDNS:
|
||||||
assert(t->n_attempts > 0);
|
assert(t->n_attempts > 0);
|
||||||
return (1 << (t->n_attempts - 1)) * USEC_PER_SEC;
|
return (1 << (t->n_attempts - 1)) * USEC_PER_SEC;
|
||||||
|
|
||||||
case DNS_PROTOCOL_LLMNR:
|
case DNS_PROTOCOL_LLMNR:
|
||||||
return t->scope->resend_timeout;
|
return t->scope->resend_timeout;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert_not_reached("Invalid DNS protocol.");
|
assert_not_reached("Invalid DNS protocol.");
|
||||||
}
|
}
|
||||||
|
@ -1117,7 +1120,7 @@ int dns_transaction_go(DnsTransaction *t) {
|
||||||
} else {
|
} else {
|
||||||
/* Try via UDP, and if that fails due to large size or lack of
|
/* Try via UDP, and if that fails due to large size or lack of
|
||||||
* support try via TCP */
|
* support try via TCP */
|
||||||
r = dns_transaction_emit(t);
|
r = dns_transaction_emit_udp(t);
|
||||||
if (r == -EMSGSIZE || r == -EAGAIN)
|
if (r == -EMSGSIZE || r == -EAGAIN)
|
||||||
r = dns_transaction_open_tcp(t);
|
r = dns_transaction_open_tcp(t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue