resolved: use structured initialization everywhere
This commit is contained in:
parent
a149d4a95e
commit
1ed314087f
|
@ -436,20 +436,22 @@ static int dns_cache_put_positive(
|
||||||
|
|
||||||
dns_cache_make_space(c, 1);
|
dns_cache_make_space(c, 1);
|
||||||
|
|
||||||
i = new0(DnsCacheItem, 1);
|
i = new(DnsCacheItem, 1);
|
||||||
if (!i)
|
if (!i)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
i->type = DNS_CACHE_POSITIVE;
|
*i = (DnsCacheItem) {
|
||||||
i->key = dns_resource_key_ref(rr->key);
|
.type = DNS_CACHE_POSITIVE,
|
||||||
i->rr = dns_resource_record_ref(rr);
|
.key = dns_resource_key_ref(rr->key),
|
||||||
i->until = calculate_until(rr, (uint32_t) -1, timestamp, false);
|
.rr = dns_resource_record_ref(rr),
|
||||||
i->authenticated = authenticated;
|
.until = calculate_until(rr, (uint32_t) -1, timestamp, false),
|
||||||
i->shared_owner = shared_owner;
|
.authenticated = authenticated,
|
||||||
i->ifindex = ifindex;
|
.shared_owner = shared_owner,
|
||||||
i->owner_family = owner_family;
|
.ifindex = ifindex,
|
||||||
i->owner_address = *owner_address;
|
.owner_family = owner_family,
|
||||||
i->prioq_idx = PRIOQ_IDX_NULL;
|
.owner_address = *owner_address,
|
||||||
|
.prioq_idx = PRIOQ_IDX_NULL,
|
||||||
|
};
|
||||||
|
|
||||||
r = dns_cache_link_item(c, i);
|
r = dns_cache_link_item(c, i);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -521,21 +523,23 @@ static int dns_cache_put_negative(
|
||||||
|
|
||||||
dns_cache_make_space(c, 1);
|
dns_cache_make_space(c, 1);
|
||||||
|
|
||||||
i = new0(DnsCacheItem, 1);
|
i = new(DnsCacheItem, 1);
|
||||||
if (!i)
|
if (!i)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
i->type =
|
*i = (DnsCacheItem) {
|
||||||
rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA :
|
.type =
|
||||||
rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE;
|
rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA :
|
||||||
i->until =
|
rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE,
|
||||||
i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC :
|
.until =
|
||||||
calculate_until(soa, nsec_ttl, timestamp, true);
|
i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC :
|
||||||
i->authenticated = authenticated;
|
calculate_until(soa, nsec_ttl, timestamp, true),
|
||||||
i->owner_family = owner_family;
|
.authenticated = authenticated,
|
||||||
i->owner_address = *owner_address;
|
.owner_family = owner_family,
|
||||||
i->prioq_idx = PRIOQ_IDX_NULL;
|
.owner_address = *owner_address,
|
||||||
i->rcode = rcode;
|
.prioq_idx = PRIOQ_IDX_NULL,
|
||||||
|
.rcode = rcode,
|
||||||
|
};
|
||||||
|
|
||||||
if (i->type == DNS_CACHE_NXDOMAIN) {
|
if (i->type == DNS_CACHE_NXDOMAIN) {
|
||||||
/* NXDOMAIN entries should apply equally to all types, so we use ANY as
|
/* NXDOMAIN entries should apply equally to all types, so we use ANY as
|
||||||
|
|
|
@ -75,12 +75,16 @@ int dns_packet_new(
|
||||||
if (!p)
|
if (!p)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
p->size = p->rindex = DNS_PACKET_HEADER_SIZE;
|
*p = (DnsPacket) {
|
||||||
p->allocated = a;
|
.n_ref = 1,
|
||||||
p->max_size = max_size;
|
.protocol = protocol,
|
||||||
p->protocol = protocol;
|
.size = DNS_PACKET_HEADER_SIZE,
|
||||||
p->opt_start = p->opt_size = (size_t) -1;
|
.rindex = DNS_PACKET_HEADER_SIZE,
|
||||||
p->n_ref = 1;
|
.allocated = a,
|
||||||
|
.max_size = max_size,
|
||||||
|
.opt_start = (size_t) -1,
|
||||||
|
.opt_size = (size_t) -1,
|
||||||
|
};
|
||||||
|
|
||||||
*ret = p;
|
*ret = p;
|
||||||
|
|
||||||
|
|
|
@ -21,12 +21,14 @@ static int dns_query_candidate_new(DnsQueryCandidate **ret, DnsQuery *q, DnsScop
|
||||||
assert(q);
|
assert(q);
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
c = new0(DnsQueryCandidate, 1);
|
c = new(DnsQueryCandidate, 1);
|
||||||
if (!c)
|
if (!c)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
c->query = q;
|
*c = (DnsQueryCandidate) {
|
||||||
c->scope = s;
|
.query = q,
|
||||||
|
.scope = s,
|
||||||
|
};
|
||||||
|
|
||||||
LIST_PREPEND(candidates_by_query, q->candidates, c);
|
LIST_PREPEND(candidates_by_query, q->candidates, c);
|
||||||
LIST_PREPEND(candidates_by_scope, s->query_candidates, c);
|
LIST_PREPEND(candidates_by_scope, s->query_candidates, c);
|
||||||
|
@ -413,17 +415,19 @@ int dns_query_new(
|
||||||
if (m->n_dns_queries >= QUERIES_MAX)
|
if (m->n_dns_queries >= QUERIES_MAX)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
q = new0(DnsQuery, 1);
|
q = new(DnsQuery, 1);
|
||||||
if (!q)
|
if (!q)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
q->question_utf8 = dns_question_ref(question_utf8);
|
*q = (DnsQuery) {
|
||||||
q->question_idna = dns_question_ref(question_idna);
|
.question_utf8 = dns_question_ref(question_utf8),
|
||||||
q->ifindex = ifindex;
|
.question_idna = dns_question_ref(question_idna),
|
||||||
q->flags = flags;
|
.ifindex = ifindex,
|
||||||
q->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
|
.flags = flags,
|
||||||
q->answer_protocol = _DNS_PROTOCOL_INVALID;
|
.answer_dnssec_result = _DNSSEC_RESULT_INVALID,
|
||||||
q->answer_family = AF_UNSPEC;
|
.answer_protocol = _DNS_PROTOCOL_INVALID,
|
||||||
|
.answer_family = AF_UNSPEC,
|
||||||
|
};
|
||||||
|
|
||||||
/* First dump UTF8 question */
|
/* First dump UTF8 question */
|
||||||
DNS_QUESTION_FOREACH(key, question_utf8)
|
DNS_QUESTION_FOREACH(key, question_utf8)
|
||||||
|
|
|
@ -97,14 +97,16 @@ DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char
|
||||||
|
|
||||||
assert(name);
|
assert(name);
|
||||||
|
|
||||||
k = new0(DnsResourceKey, 1);
|
k = new(DnsResourceKey, 1);
|
||||||
if (!k)
|
if (!k)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
k->n_ref = 1;
|
*k = (DnsResourceKey) {
|
||||||
k->class = class;
|
.n_ref = 1,
|
||||||
k->type = type;
|
.class = class,
|
||||||
k->_name = name;
|
.type = type,
|
||||||
|
._name = name,
|
||||||
|
};
|
||||||
|
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
@ -372,14 +374,17 @@ bool dns_resource_key_reduce(DnsResourceKey **a, DnsResourceKey **b) {
|
||||||
DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
|
DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
|
||||||
DnsResourceRecord *rr;
|
DnsResourceRecord *rr;
|
||||||
|
|
||||||
rr = new0(DnsResourceRecord, 1);
|
rr = new(DnsResourceRecord, 1);
|
||||||
if (!rr)
|
if (!rr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
rr->n_ref = 1;
|
*rr = (DnsResourceRecord) {
|
||||||
rr->key = dns_resource_key_ref(key);
|
.n_ref = 1,
|
||||||
rr->expiry = USEC_INFINITY;
|
.key = dns_resource_key_ref(key),
|
||||||
rr->n_skip_labels_signer = rr->n_skip_labels_source = (unsigned) -1;
|
.expiry = USEC_INFINITY,
|
||||||
|
.n_skip_labels_signer = (unsigned) -1,
|
||||||
|
.n_skip_labels_source = (unsigned) -1,
|
||||||
|
};
|
||||||
|
|
||||||
return rr;
|
return rr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,16 @@ int dns_search_domain_new(
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = new0(DnsSearchDomain, 1);
|
d = new(DnsSearchDomain, 1);
|
||||||
if (!d)
|
if (!d)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
d->n_ref = 1;
|
*d = (DnsSearchDomain) {
|
||||||
d->manager = m;
|
.n_ref = 1,
|
||||||
d->type = type;
|
.manager = m,
|
||||||
d->name = TAKE_PTR(normalized);
|
.type = type,
|
||||||
|
.name = TAKE_PTR(normalized),
|
||||||
|
};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
|
|
|
@ -194,19 +194,20 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key)
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
t = new0(DnsTransaction, 1);
|
t = new(DnsTransaction, 1);
|
||||||
if (!t)
|
if (!t)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
t->dns_udp_fd = -1;
|
*t = (DnsTransaction) {
|
||||||
t->answer_source = _DNS_TRANSACTION_SOURCE_INVALID;
|
.dns_udp_fd = -1,
|
||||||
t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
|
.answer_source = _DNS_TRANSACTION_SOURCE_INVALID,
|
||||||
t->answer_nsec_ttl = (uint32_t) -1;
|
.answer_dnssec_result = _DNSSEC_RESULT_INVALID,
|
||||||
t->key = dns_resource_key_ref(key);
|
.answer_nsec_ttl = (uint32_t) -1,
|
||||||
t->current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID;
|
.key = dns_resource_key_ref(key),
|
||||||
t->clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID;
|
.current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID,
|
||||||
|
.clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID,
|
||||||
t->id = pick_new_id(s->manager);
|
.id = pick_new_id(s->manager),
|
||||||
|
};
|
||||||
|
|
||||||
r = hashmap_put(s->manager->dns_transactions, UINT_TO_PTR(t->id), t);
|
r = hashmap_put(s->manager->dns_transactions, UINT_TO_PTR(t->id), t);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
|
|
@ -231,13 +231,15 @@ int dns_zone_put(DnsZone *z, DnsScope *s, DnsResourceRecord *rr, bool probe) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
i = new0(DnsZoneItem, 1);
|
i = new(DnsZoneItem, 1);
|
||||||
if (!i)
|
if (!i)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
i->scope = s;
|
*i = (DnsZoneItem) {
|
||||||
i->rr = dns_resource_record_ref(rr);
|
.scope = s,
|
||||||
i->probing_enabled = probe;
|
.rr = dns_resource_record_ref(rr),
|
||||||
|
.probing_enabled = probe,
|
||||||
|
};
|
||||||
|
|
||||||
r = dns_zone_link_item(z, i);
|
r = dns_zone_link_item(z, i);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
|
@ -80,11 +80,13 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
item = new0(EtcHostsItem, 1);
|
item = new(EtcHostsItem, 1);
|
||||||
if (!item)
|
if (!item)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
item->address = address;
|
*item = (EtcHostsItem) {
|
||||||
|
.address = address,
|
||||||
|
};
|
||||||
|
|
||||||
r = hashmap_put(hosts->by_address, &item->address, item);
|
r = hashmap_put(hosts->by_address, &item->address, item);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
|
|
@ -818,14 +818,16 @@ int link_address_new(Link *l, LinkAddress **ret, int family, const union in_addr
|
||||||
assert(l);
|
assert(l);
|
||||||
assert(in_addr);
|
assert(in_addr);
|
||||||
|
|
||||||
a = new0(LinkAddress, 1);
|
a = new(LinkAddress, 1);
|
||||||
if (!a)
|
if (!a)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
a->family = family;
|
*a = (LinkAddress) {
|
||||||
a->in_addr = *in_addr;
|
.family = family,
|
||||||
|
.in_addr = *in_addr,
|
||||||
|
.link = l,
|
||||||
|
};
|
||||||
|
|
||||||
a->link = l;
|
|
||||||
LIST_PREPEND(addresses, l->addresses, a);
|
LIST_PREPEND(addresses, l->addresses, a);
|
||||||
l->n_addresses++;
|
l->n_addresses++;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue