/[svn]/hopm/branches/1.1.x/src/firedns.c
ViewVC logotype

Diff of /hopm/branches/1.1.x/src/firedns.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8153 by michael, Wed Apr 5 18:42:47 2017 UTC revision 8154 by michael, Fri Apr 7 18:10:08 2017 UTC
# Line 54  static unsigned int firedns_fdinuse; Line 54  static unsigned int firedns_fdinuse;
54  /* up to FDNS_MAX nameservers; populated by firedns_init() */  /* up to FDNS_MAX nameservers; populated by firedns_init() */
55  static struct in_addr servers4[FDNS_MAX];  static struct in_addr servers4[FDNS_MAX];
56  static struct in6_addr servers6[FDNS_MAX];  static struct in6_addr servers6[FDNS_MAX];
57    
58  /* actual count of nameservers; set by firedns_init() */  /* actual count of nameservers; set by firedns_init() */
59  static int i4;  static unsigned int i4;
60  static int i6;  static unsigned int i6;
61    
62  /*  /*
63   * Linked list of open DNS queries; populated by firedns_add_query(),   * Linked list of open DNS queries; populated by firedns_add_query(),
# Line 68  static list_t *CONNECTIONS; Line 69  static list_t *CONNECTIONS;
69   * List of errors, in order of values used in FDNS_ERR_*, returned by   * List of errors, in order of values used in FDNS_ERR_*, returned by
70   * firedns_strerror   * firedns_strerror
71   */   */
72  static const char *errors[] =  static const char *const errors[] =
73  {  {
74    [FDNS_ERR_NONE] = "Success",    [FDNS_ERR_NONE] = "Success",
75    [FDNS_ERR_FORMAT] = "Format error",    [FDNS_ERR_FORMAT] = "Format error",
# Line 154  firedns_init(void) Line 155  firedns_init(void)
155     * addresses from /etc/firedns.conf (or /etc/resolv.conf)     * addresses from /etc/firedns.conf (or /etc/resolv.conf)
156     */     */
157    FILE *f;    FILE *f;
   int i;  
158    struct in_addr addr4;    struct in_addr addr4;
159    struct in6_addr addr6;    struct in6_addr addr6;
160    char buf[1024];    char buf[1024];
# Line 190  firedns_init(void) Line 190  firedns_init(void)
190    
191        if (strncmp(buf, "nameserver", 10) == 0)        if (strncmp(buf, "nameserver", 10) == 0)
192        {        {
193          i = 10;          unsigned int i = 10;
194    
195          while (buf[i] == ' ' || buf[i] == '\t')          while (buf[i] == ' ' || buf[i] == '\t')
196            ++i;            ++i;
# Line 292  firedns_resolveip4(const char *const nam Line 292  firedns_resolveip4(const char *const nam
292    if (inet_pton(AF_INET, name, &addr) > 0)    if (inet_pton(AF_INET, name, &addr) > 0)
293      return &addr;      return &addr;
294    
295    return (struct in_addr *)firedns_resolveip(FDNS_QRY_A, name);    return firedns_resolveip(FDNS_QRY_A, name);
296  }  }
297    
298  /* immediate AAAA query */  /* immediate AAAA query */
# Line 304  firedns_resolveip6(const char *const nam Line 304  firedns_resolveip6(const char *const nam
304    if (inet_pton(AF_INET6, name, &addr) > 0)    if (inet_pton(AF_INET6, name, &addr) > 0)
305      return &addr;      return &addr;
306    
307    return (struct in6_addr *)firedns_resolveip(FDNS_QRY_AAAA, name);    return firedns_resolveip(FDNS_QRY_AAAA, name);
308  }  }
309    
310  /* resolve a query of a given type */  /* resolve a query of a given type */
311  char *  void *
312  firedns_resolveip(int type, const char *const name)  firedns_resolveip(int type, const char *const name)
313  {  {
314    struct firedns_result *result;    struct firedns_result *result;
315    struct timeval tv;    struct timeval tv;
316    fd_set s;    fd_set s;
317    
318    for (int t = 0; t < FIREDNS_TRIES; ++t)    for (unsigned int t = 0; t < FIREDNS_TRIES; ++t)
319    {    {
320      int fd = firedns_getip(type, name, NULL);      int fd = firedns_getip(type, name, NULL);
   
321      if (fd == -1)      if (fd == -1)
322        return NULL;        return NULL;
323    
# Line 355  firedns_getip(int type, const char *cons Line 354  firedns_getip(int type, const char *cons
354  {  {
355    struct s_connection *s;    struct s_connection *s;
356    node_t *node;    node_t *node;
   int fd;  
357    
358    s = firedns_add_query();    s = firedns_add_query();
359    s->class = 1;    s->class = 1;
# Line 379  firedns_getip(int type, const char *cons Line 377  firedns_getip(int type, const char *cons
377      return -1;      return -1;
378    }    }
379    
380    fd = firedns_doquery(s);    int fd = firedns_doquery(s);
   
381    if (fd == -1)    if (fd == -1)
382    {    {
383      xfree(s);      xfree(s);
# Line 413  firedns_add_query(void) Line 410  firedns_add_query(void)
410  static int  static int
411  firedns_doquery(struct s_connection *s)  firedns_doquery(struct s_connection *s)
412  {  {
   int len;  
413    struct s_header h;    struct s_header h;
414    
415    len = firedns_build_query_payload(s->lookup, s->type, 1, (unsigned char *)&h.payload);    int len = firedns_build_query_payload(s->lookup, s->type, 1, (unsigned char *)&h.payload);
   
416    if (len == -1)    if (len == -1)
417    {    {
418      firedns_errno = FDNS_ERR_FORMAT;      firedns_errno = FDNS_ERR_FORMAT;
# Line 483  firedns_build_query_payload(const char * Line 478  firedns_build_query_payload(const char *
478  static int  static int
479  firedns_send_requests(struct s_header *h, struct s_connection *s, int l)  firedns_send_requests(struct s_header *h, struct s_connection *s, int l)
480  {  {
481    int i, sent_ok = 0;    int sent_ok = 0;
482    struct sockaddr_in addr4;    struct sockaddr_in addr4;
483    struct sockaddr_in6 addr6;    struct sockaddr_in6 addr6;
484    unsigned char payload[sizeof(struct s_header)];    unsigned char payload[sizeof(struct s_header)];
# Line 560  firedns_send_requests(struct s_header *h Line 555  firedns_send_requests(struct s_header *h
555      }      }
556    }    }
557    
558    firedns_empty_header(payload,h,l);    firedns_empty_header(payload, h, l);
559    
560    /* if we've got ipv6 support, an ip v6 socket, and ipv6 servers, send to them */    /* if we've got ipv6 support, an ip v6 socket, and ipv6 servers, send to them */
561    if (i6 > 0 && s->v6 == 1)    if (i6 > 0 && s->v6 == 1)
562    {    {
563      for (i = 0; i < i6; i++)      for (unsigned int i = 0; i < i6; ++i)
564      {      {
565        memset(&addr6, 0, sizeof(addr6));        memset(&addr6, 0, sizeof(addr6));
566        memcpy(&addr6.sin6_addr, &servers6[i], sizeof(addr6.sin6_addr));        memcpy(&addr6.sin6_addr, &servers6[i], sizeof(addr6.sin6_addr));
# Line 578  firedns_send_requests(struct s_header *h Line 573  firedns_send_requests(struct s_header *h
573      }      }
574    }    }
575    
576    for (i = 0; i < i4; i++)    for (unsigned int i = 0; i < i4; ++i)
577    {    {
578      /* send via ipv4-over-ipv6 if we've got an ipv6 socket */      /* send via ipv4-over-ipv6 if we've got an ipv6 socket */
579      if (s->v6 == 1)      if (s->v6 == 1)
# Line 787  firedns_getresult(const int fd) Line 782  firedns_getresult(const int fd)
782  cleanup:  cleanup:
783    list_remove(CONNECTIONS, node);    list_remove(CONNECTIONS, node);
784    node_free(node);    node_free(node);
785    
786    close(c->fd);    close(c->fd);
   firedns_fdinuse--;  
787    xfree(c);    xfree(c);
788      firedns_fdinuse--;
789    
790    return &result;    return &result;
791  }  }
# Line 801  firedns_cycle(void) Line 797  firedns_cycle(void)
797    struct s_connection *p;    struct s_connection *p;
798    struct firedns_result *res, new_result;    struct firedns_result *res, new_result;
799    static struct pollfd *ufds = NULL;    static struct pollfd *ufds = NULL;
800    int fd;    unsigned int size = 0;
   unsigned int size, i;  
801    time_t timenow;    time_t timenow;
802    
803    if (LIST_SIZE(CONNECTIONS) == 0)    if (LIST_SIZE(CONNECTIONS) == 0)
# Line 812  firedns_cycle(void) Line 807  firedns_cycle(void)
807      ufds = xcalloc(sizeof(*ufds) * OptionsItem->dns_fdlimit);      ufds = xcalloc(sizeof(*ufds) * OptionsItem->dns_fdlimit);
808    
809    time(&timenow);    time(&timenow);
   size = 0;  
810    
811    LIST_FOREACH_SAFE(node, node_next, CONNECTIONS->head)    LIST_FOREACH_SAFE(node, node_next, CONNECTIONS->head)
812    {    {
# Line 835  firedns_cycle(void) Line 829  firedns_cycle(void)
829        strlcpy(new_result.lookup, p->lookup, sizeof(new_result.lookup));        strlcpy(new_result.lookup, p->lookup, sizeof(new_result.lookup));
830    
831        close(p->fd);        close(p->fd);
       firedns_fdinuse--;  
832        xfree(p);        xfree(p);
833          firedns_fdinuse--;
834    
835        firedns_errno = FDNS_ERR_TIMEOUT;        firedns_errno = FDNS_ERR_TIMEOUT;
836    
# Line 867  firedns_cycle(void) Line 861  firedns_cycle(void)
861    
862      if (p->fd > 0)      if (p->fd > 0)
863      {      {
864        for (i = 0; i < size; ++i)        for (unsigned int i = 0; i < size; ++i)
865        {        {
866          if ((ufds[i].revents & POLLIN) && ufds[i].fd == p->fd)          if ((ufds[i].revents & POLLIN) && ufds[i].fd == p->fd)
867          {          {
868            fd = p->fd;            res = firedns_getresult(p->fd);
           res = firedns_getresult(fd);  
869    
870            if (res && res->info)            if (res && res->info)
871              dnsbl_result(res);              dnsbl_result(res);

Legend:
Removed from v.8153  
changed lines
  Added in v.8154

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28