return 0;
}
-void
-cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struct dns_answer *a, uint8_t *rdata, int flush)
+void cache_answer(struct interface *iface, struct sockaddr *from, uint8_t *base,
+ int blen, char *name, struct dns_answer *a, uint8_t *rdata,
+ int flush)
{
struct dns_srv_data *dsd = (struct dns_srv_data *) rdata;
struct cache_record *r;
r->rdlength = dlen;
r->time = now;
r->iface = iface;
+ if (iface->v6)
+ memcpy(&r->from, from, sizeof(struct sockaddr_in6));
+ else
+ memcpy(&r->from, from, sizeof(struct sockaddr_in));
r->refresh = 50;
if (tlen)
uint16_t rdlength;
time_t time;
struct interface *iface;
+ struct sockaddr_storage from;
int refresh;
};
int cache_init(void);
void cache_update(void);
void cache_cleanup(struct interface *iface);
-void cache_answer(struct interface *iface, uint8_t *base, int blen,
- char *name, struct dns_answer *a, uint8_t *rdata, int flush);
+void cache_answer(struct interface *iface, struct sockaddr *from, uint8_t *base,
+ int blen, char *name, struct dns_answer *a, uint8_t *rdata,
+ int flush);
int cache_host_is_known(char *record);
void cache_dump_records(struct blob_buf *buf, const char *name);
void cache_dump_recursive(struct blob_buf *b, const char *name, uint16_t type, struct interface *iface);
return name_buffer;
}
-static int
-parse_answer(struct interface *iface, uint8_t *buffer, int len, uint8_t **b, int *rlen, int cache)
+static int parse_answer(struct interface *iface, struct sockaddr *from,
+ uint8_t *buffer, int len, uint8_t **b, int *rlen,
+ int cache)
{
char *name = dns_consume_name(buffer, len, b, rlen);
struct dns_answer *a;
*b += a->rdlength;
if (cache)
- cache_answer(iface, buffer, len, name, a, rdata, a->class & CLASS_FLUSH);
+ cache_answer(iface, from, buffer, len, name, a, rdata, a->class & CLASS_FLUSH);
return 0;
}
}
void
-dns_handle_packet(struct interface *iface, struct sockaddr *s, uint16_t port, uint8_t *buffer, int len)
+dns_handle_packet(struct interface *iface, struct sockaddr *from, uint16_t port, uint8_t *buffer, int len)
{
struct dns_header *h;
uint8_t *b = buffer;
}
if (!(h->flags & FLAG_RESPONSE))
- parse_question(iface, s, name, q);
+ parse_question(iface, from, name, q);
}
if (!(h->flags & FLAG_RESPONSE))
return;
while (h->answers-- > 0)
- if (parse_answer(iface, buffer, len, &b, &rlen, 1))
+ if (parse_answer(iface, from, buffer, len, &b, &rlen, 1))
return;
while (h->authority-- > 0)
- if (parse_answer(iface, buffer, len, &b, &rlen, 1))
+ if (parse_answer(iface, from, buffer, len, &b, &rlen, 1))
return;
while (h->additional-- > 0)
- if (parse_answer(iface, buffer, len, &b, &rlen, 1))
+ if (parse_answer(iface, from, buffer, len, &b, &rlen, 1))
return;
}