};
static struct uloop_timeout announce;
-struct uloop_fd *announce_fd;
static int announce_state;
int announce_ttl = 75 * 60;
announce_state++;
case STATE_ANNOUNCE:
- service_announce(announce_fd);
+ service_announce(cur_iface);
uloop_timeout_set(timeout, announce_ttl * 800);
break;
}
}
void
-announce_init(struct uloop_fd *u)
+announce_init(void)
{
announce_state = STATE_PROBE1;
announce.cb = announce_timer;
- announce_fd = u;
uloop_timeout_set(&announce, 100);
}
#define _ANNOUNCE_H__
extern int announce_ttl;
-extern struct uloop_fd *announce_fd;
-extern void announce_init(struct uloop_fd *u);
+extern void announce_init(void);
#endif
}
static struct cache_entry*
-cache_entry(struct uloop_fd *u, char *entry, int hlen, int ttl)
+cache_entry(struct interface *iface, char *entry, int hlen, int ttl)
{
struct cache_entry *s;
char *entry_buf;
avl_insert(&entries, &s->avl);
if (!hlen)
- dns_send_question(cur_iface, entry, TYPE_PTR);
+ dns_send_question(iface, entry, TYPE_PTR);
return s;
}
}
void
-cache_answer(struct uloop_fd *u, uint8_t *base, int blen, char *name, struct dns_answer *a, uint8_t *rdata)
+cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struct dns_answer *a, uint8_t *rdata)
{
struct dns_srv_data *dsd = (struct dns_srv_data *) rdata;
struct cache_record *r;
nlen + 1 < rdlength && !strcmp(rdata_buffer + rdlength - nlen, name))
host_len = rdlength - nlen - 1;
- cache_entry(u, rdata_buffer, host_len, a->ttl);
+ cache_entry(iface, rdata_buffer, host_len, a->ttl);
return;
case TYPE_SRV:
break;
case TYPE_A:
- cache_entry(u, name, strlen(name), a->ttl);
+ cache_entry(iface, name, strlen(name), a->ttl);
if (a->rdlength != 4)
return;
dlen = 4;
break;
case TYPE_AAAA:
- cache_entry(u, name, strlen(name), a->ttl);
+ cache_entry(iface, name, strlen(name), a->ttl);
if (a->rdlength != 16)
return;
dlen = 16;
extern int cache_init(void);
extern void cache_scan(void);
extern void cache_cleanup(void);
-extern void cache_answer(struct uloop_fd *u, uint8_t *base, int blen,
+extern void cache_answer(struct interface *iface, uint8_t *base, int blen,
char *name, struct dns_answer *a, uint8_t *rdata);
extern int cache_host_is_known(char *record);
extern char* cache_lookup_name(const char *key);
}
void
-dns_send_answer(struct uloop_fd *u, const char *answer)
+dns_send_answer(struct interface *iface, const char *answer)
{
uint8_t buffer[256];
struct dns_header h = { 0 };
DBG(1, "A <- %s %s\n", dns_type_string(dns_reply[i].type), answer);
}
- if (interface_send_packet(cur_iface, iov, (dns_answer_cnt * 3) + 1) < 0)
+ if (interface_send_packet(iface, iov, (dns_answer_cnt * 3) + 1) < 0)
fprintf(stderr, "failed to send question\n");
for (i = 0; i < dns_answer_cnt; i++) {
extern void dns_send_question(struct interface *iface, const char *question, int type);
extern void dns_init_answer(void);
extern void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength);
-extern void dns_send_answer(struct uloop_fd *u, const char *answer);
+extern void dns_send_answer(struct interface *iface, const char *answer);
extern char* dns_consume_name(const uint8_t *base, int blen, uint8_t **data, int *len);
extern struct dns_answer* dns_consume_answer(uint8_t **data, int *len);
extern struct dns_question* dns_consume_question(uint8_t **data, int *len);
char *iface_name = "eth0";
static int
-parse_answer(struct uloop_fd *u, uint8_t *buffer, int len, uint8_t **b, int *rlen, int cache)
+parse_answer(struct interface *iface, 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(u, buffer, len, name, a, rdata);
+ cache_answer(iface, buffer, len, name, a, rdata);
return 0;
}
static void
-parse_question(struct uloop_fd *u, char *name, struct dns_question *q)
+parse_question(struct interface *iface, char *name, struct dns_question *q)
{
char *host;
case TYPE_ANY:
host = service_name("local");
if (!strcmp(name, host))
- service_reply(u, NULL);
+ service_reply(iface, NULL);
break;
case TYPE_PTR:
- service_announce_services(u, name);
- service_reply(u, name);
+ service_announce_services(iface, name);
+ service_reply(iface, name);
break;
case TYPE_AAAA:
if (host)
*host = '\0';
if (!strcmp(hostname, name))
- service_reply_a(u, q->type);
+ service_reply_a(iface, q->type);
break;
};
}
static void
read_socket(struct uloop_fd *u, unsigned int events)
{
- uint8_t buffer[8 * 1024];
+ struct interface *iface = container_of(u, struct interface, fd);
+ static uint8_t buffer[8 * 1024];
uint8_t *b = buffer;
struct dns_header *h;
int len, rlen;
}
if (!(h->flags & FLAG_RESPONSE))
- parse_question(announce_fd, name, q);
+ parse_question(iface, name, q);
}
if (!(h->flags & FLAG_RESPONSE))
return;
while (h->answers-- > 0)
- parse_answer(u, buffer, len, &b, &rlen, 1);
+ parse_answer(iface, buffer, len, &b, &rlen, 1);
while (h->authority-- > 0)
- parse_answer(u, buffer, len, &b, &rlen, 0);
+ parse_answer(iface, buffer, len, &b, &rlen, 0);
while (h->additional-- > 0)
- parse_answer(u, buffer, len, &b, &rlen, 1);
+ parse_answer(iface, buffer, len, &b, &rlen, 1);
}
static void
uloop_fd_add(&cur_iface->fd, ULOOP_READ);
sleep(5);
dns_send_question(cur_iface, "_services._dns-sd._udp.local", TYPE_PTR);
- announce_init(&cur_iface->fd);
+ announce_init();
}
}
}
static void
-service_send_ptr(struct uloop_fd *u, struct service *s)
+service_add_ptr(struct service *s)
{
unsigned char buffer[MAX_NAME_LEN];
const char *host = service_name(s->service);
}
static void
-service_send_ptr_c(struct uloop_fd *u, const char *host)
+service_add_ptr_c(const char *host)
{
unsigned char buffer[MAX_NAME_LEN];
int len = dn_comp(host, buffer, MAX_NAME_LEN, NULL, NULL);
}
static void
-service_send_a(struct uloop_fd *u)
+service_send_a(struct interface *iface)
{
unsigned char buffer[MAX_NAME_LEN];
char *host = service_name("local");
int len = dn_comp(host, buffer, MAX_NAME_LEN, NULL, NULL);
struct in_addr in;
- if (!inet_aton(cur_iface->ip, &in)) {
- fprintf(stderr, "%s is not valid\n", cur_iface->ip);
+ if (!inet_aton(iface->ip, &in)) {
+ fprintf(stderr, "%s is not valid\n", iface->ip);
return;
}
}
static void
-service_send_srv(struct uloop_fd *u, struct service *s)
+service_add_srv(struct service *s)
{
unsigned char buffer[MAX_NAME_LEN];
struct dns_srv_data *sd;
}
void
-service_reply_a(struct uloop_fd *u, int type)
+service_reply_a(struct interface *iface, int type)
{
if (type != TYPE_A)
return;
dns_init_answer();
- service_send_a(u);
- dns_send_answer(u, service_name("local"));
+ service_send_a(iface);
+ dns_send_answer(iface, service_name("local"));
}
void
-service_reply(struct uloop_fd *u, const char *match)
+service_reply(struct interface *iface, const char *match)
{
struct service *s;
continue;
dns_init_answer();
- service_send_ptr(u, s);
- dns_send_answer(u, service);
+ service_add_ptr(s);
+ dns_send_answer(iface, service);
dns_init_answer();
- service_send_srv(u, s);
+ service_add_srv(s);
if (s->txt && s->txt_len)
dns_add_answer(TYPE_TXT, (uint8_t *) s->txt, s->txt_len);
- dns_send_answer(u, host);
+ dns_send_answer(iface, host);
}
if (match)
return;
dns_init_answer();
- service_send_a(u);
- dns_send_answer(u, service_name("local"));
+ service_send_a(iface);
+ dns_send_answer(iface, service_name("local"));
}
void
-service_announce_services(struct uloop_fd *u, const char *service)
+service_announce_services(struct interface *iface, const char *service)
{
struct service *s;
int tcp = 1;
continue;
s->t = 0;
dns_init_answer();
- service_send_ptr_c(u, s->service);
+ service_add_ptr_c(s->service);
if (tcp)
- dns_send_answer(u, sdtcp);
+ dns_send_answer(iface, sdtcp);
else
- dns_send_answer(u, sdudp);
- service_reply(u, s->service);
+ dns_send_answer(iface, sdudp);
+ service_reply(iface, s->service);
}
}
void
-service_announce(struct uloop_fd *u)
+service_announce(struct interface *iface)
{
- service_announce_services(u, sdudp);
- service_announce_services(u, sdtcp);
+ service_announce_services(iface, sdudp);
+ service_announce_services(iface, sdtcp);
}
static void
extern char *service_name(const char *domain);
extern void service_init(void);
extern void service_cleanup(void);
-extern void service_announce(struct uloop_fd *u);
-extern void service_announce_services(struct uloop_fd *u, const char *service);
-extern void service_reply(struct uloop_fd *u, const char *match);
-extern void service_reply_a(struct uloop_fd *u, int type);
+extern void service_announce(struct interface *iface);
+extern void service_announce_services(struct interface *iface, const char *service);
+extern void service_reply(struct interface *iface, const char *match);
+extern void service_reply_a(struct interface *iface, int type);
#endif