Abolish the rule that a comm_addr has zeroes in all its holes.
Provide comm_addr_equal instead.
We can get rid of a lot of calls to FILLZERO.
In resolver.c we no longer need to copy the fields of ia individually.
We still need to look at the incoming address family since util.c
aborts on unknown AFs and adns (perhaps a new version or something)
might have sent us things we don't understand. (Also reorganise the
loop/switch a little to get `wslot++' out of the `case'.)
We have to move the declaration of iaddr_equal.
Abolish transport_addrs_equal and replace it at call sites with the
new comm_addr_equal.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
memcpy(trimmed,name+1,l-2);
trimmed[l-2]=0;
struct comm_addr ca;
- FILLZERO(ca);
ca.comm=comm;
ca.ia.sin.sin_family=AF_INET;
ca.ia.sin.sin_port=htons(port);
int rslot, wslot, total;
int ca_len=MIN(ans->nrrs,MAX_PEER_ADDRS);
struct comm_addr ca_buf[ca_len];
- FILLZERO(ca_buf);
for (rslot=0, wslot=0, total=0;
rslot<ans->nrrs;
rslot++) {
adns_rr_addr *ra=&ans->rrs.addr[rslot];
struct comm_addr *ca=&ca_buf[wslot];
ca->comm=q->comm;
- /* copy fields individually so we leave holes zeroed: */
switch (ra->addr.sa.sa_family) {
case AF_INET:
assert(ra->len == sizeof(ca->ia.sin));
- ca->ia.sin.sin_family=ra->addr.inet.sin_family;
- ca->ia.sin.sin_addr= ra->addr.inet.sin_addr;
- ca->ia.sin.sin_port= htons(q->port);
- wslot++;
break;
default:
- break;
+ /* silently skip unexpected AFs from adns */
+ continue;
}
+ memcpy(&ca->ia,&ra->addr,ra->len);
+ wslot++;
}
q->answer(q->cst,ca_buf,wslot,total);
free(q);
struct comm_addr {
/* This struct is pure data; in particular comm's clients may
freely copy it. */
- /* Everyone is also guaranteed that all padding is set to zero, ie
- that comm_addrs referring to semantically identical peers will
- compare equal with memcmp. Anyone who constructs a comm_addr
- must start by memsetting it with FILLZERO, or some
- equivalent. */
struct comm_if *comm;
union iaddr ia;
};
comm_addr_to_string_fn *addr_to_string;
};
+bool_t iaddr_equal(const union iaddr *ia, const union iaddr *ib);
+
static inline const char *comm_addr_to_string(const struct comm_addr *ca)
{
return ca->comm->addr_to_string(ca->comm->st, ca);
}
+static inline bool_t comm_addr_equal(const struct comm_addr *a,
+ const struct comm_addr *b)
+{
+ return a->comm==b->comm && iaddr_equal(&a->ia,&b->ia);
+}
+
/* LOG interface */
#define LOG_MESSAGE_BUFLEN 1023
}
}
-static bool_t transport_addrs_equal(const struct comm_addr *a,
- const struct comm_addr *b) {
- return !memcmp(a,b,sizeof(*a));
-}
-
static void transport_peers_expire(struct site *st, transport_peers *peers) {
/* peers must be sorted first */
int previous_peers=peers->npeers;
return 0;
for (search=0; search<peers->npeers; search++)
- if (transport_addrs_equal(&peers->peers[search].addr, ca))
+ if (comm_addr_equal(&peers->peers[search].addr, ca))
return 1;
peers->peers[peers->npeers].addr = *ca;
* Caller must first call transport_peers_expire. */
if (naddrs==1 && peers->npeers>=1 &&
- transport_addrs_equal(&addrs[0], &peers->peers[0].addr)) {
+ comm_addr_equal(&addrs[0], &peers->peers[0].addr)) {
/* optimisation, also avoids debug for trivial updates */
peers->peers[0].last = *tv_now;
return;
if (nfds && (fds->revents & POLLIN)) {
do {
- FILLZERO(from);
fromlen=sizeof(from);
BUF_ASSERT_FREE(st->rbuf);
BUF_ALLOC(st->rbuf,"udp_afterpoll");
memcpy(&from.sin.sin_port,buf_unprepend(st->rbuf,2),2);
}
struct comm_addr ca;
- FILLZERO(ca);
ca.comm=&st->ops;
ca.ia=from;
done=False;
st->ops.release_notify=release_notify;
st->ops.sendmsg=udp_sendmsg;
st->ops.addr_to_string=addr_to_string;
- FILLZERO(st->addr);
st->use_proxy=False;
i=list_elem(args,0);
l=dict_lookup(d,"proxy");
if (l) {
st->use_proxy=True;
- FILLZERO(st->proxy);
st->proxy.sa.sa_family=AF_INET;
i=list_elem(l,0);
if (!i || i->type!=t_string) {
extern int consttime_memeq(const void *s1, const void *s2, size_t n);
const char *iaddr_to_string(const union iaddr *ia);
-bool_t iaddr_equal(const union iaddr *ia, const union iaddr *ib);
int iaddr_socklen(const union iaddr *ia);
#define MINMAX(ae,be,op) ({ \