src/mod/dns.mod/dns.c File Reference

#include "src/mod/module.h"
#include "dns.h"
#include "coredns.c"
Include dependency graph for dns.c:

Go to the source code of this file.

Defines

#define MODULE_NAME   "dns"

Functions

static void dns_event_success (struct resolve *rp, int type)
static void dns_event_failure (struct resolve *rp, int type)
static void eof_dns_socket (int idx)
static void dns_socket (int idx, char *buf, int len)
static void display_dns_socket (int idx, char *buf)
static char * dns_change (ClientData cdata, Tcl_Interp *irp, char *name1, char *name2, int flags)
static void dns_free_cache (void)
static int dns_cache_expmem (void)
static int dns_expmem (void)
static int dns_report (int idx, int details)
static char * dns_close ()
EXPORT_SCOPE char * dns_start ()
char * dns_start (Function *global_funcs)

Variables

static Functionglobal = 0
static int dns_maxsends = 4
static int dns_retrydelay = 3
static int dns_cache = 86400
static int dns_negcache = 600
static char dns_servers [121] = ""
static struct dcc_table DCC_DNS
static tcl_ints dnsints []
static tcl_strings dnsstrings []
static Function dns_table []

Define Documentation

#define MODULE_NAME   "dns"

Definition at line 27 of file dns.c.


Function Documentation

static void display_dns_socket ( int  idx,
char *  buf 
) [static]

Definition at line 107 of file dns.c.

00108 {
00109   strcpy(buf, "dns   (ready)");
00110 }

static int dns_cache_expmem ( void   )  [static]

Definition at line 204 of file dns.c.

References expireresolves, resolve::hostn, and resolve::next.

Referenced by dns_expmem().

00205 {
00206   struct resolve *rp;
00207   int size = 0;
00208 
00209   for (rp = expireresolves; rp; rp = rp->next) {
00210     size += sizeof(struct resolve);
00211     if (rp->hostn)
00212       size += strlen(rp->hostn) + 1;
00213   }
00214   return size;
00215 }

Here is the caller graph for this function:

static char* dns_change ( ClientData  cdata,
Tcl_Interp irp,
char *  name1,
char *  name2,
int  flags 
) [static]

Definition at line 138 of file dns.c.

References EGG_CONST, egg_inet_aton, interp, iptostr, NULL, and Tcl_Free.

Referenced by dns_close(), and dns_start().

00141 {
00142   char buf[121], *p;
00143   unsigned short port;
00144   int i, lc, code;
00145   EGG_CONST char **list, *slist;
00146 
00147   if (flags & (TCL_TRACE_READS | TCL_TRACE_UNSETS)) {
00148     Tcl_DString ds;
00149     
00150     Tcl_DStringInit(&ds);
00151     for (i = 0; i < _res.nscount; i++) {
00152       snprintf(buf, sizeof buf, "%s:%d",
00153                iptostr(_res.nsaddr_list[i].sin_addr.s_addr),
00154                ntohs(_res.nsaddr_list[i].sin_port));
00155       Tcl_DStringAppendElement(&ds, buf);
00156     }
00157     slist = Tcl_DStringValue(&ds);
00158     Tcl_SetVar2(interp, name1, name2, slist, TCL_GLOBAL_ONLY);
00159     Tcl_DStringFree(&ds);
00160   } else { /* TCL_TRACE_WRITES */
00161     slist = Tcl_GetVar2(interp, name1, name2, TCL_GLOBAL_ONLY);
00162     code = Tcl_SplitList(interp, slist, &lc, &list);
00163     if (code == TCL_ERROR)
00164       return "variable must be a list";
00165     /* reinitialize the list */
00166     _res.nscount = 0;
00167     for (i = 0; i < lc; i++) {
00168       if ((p = strchr(list[i], ':'))) {
00169         *p++ = 0;
00170         /* allow non-standard ports */
00171         port = atoi(p);
00172       } else
00173         port = NAMESERVER_PORT; /* port 53 */
00174       /* Ignore invalid addresses */
00175       if (egg_inet_aton(list[i], &_res.nsaddr_list[_res.nscount].sin_addr)) {
00176         _res.nsaddr_list[_res.nscount].sin_port = htons(port);
00177         _res.nsaddr_list[_res.nscount].sin_family = AF_INET;
00178         _res.nscount++;
00179       }
00180     }
00181     Tcl_Free((char *) list);
00182   }
00183   return NULL;
00184 }

Here is the caller graph for this function:

static char* dns_close (  )  [static]

Definition at line 239 of file dns.c.

References dcc, dcc_total, del_hook, dns_change(), dns_check_expires(), dns_forward(), dns_free_cache(), dns_lookup(), HOOK_DNS_HOSTBYIP, HOOK_DNS_IPBYHOST, HOOK_SECONDLY, interp, killsock, lostdcc, MODULE_NAME, module_undepend, NULL, rem_tcl_ints, rem_tcl_strings, and resfd.

00240 {
00241   int i;
00242 
00243   del_hook(HOOK_DNS_HOSTBYIP, (Function) dns_lookup);
00244   del_hook(HOOK_DNS_IPBYHOST, (Function) dns_forward);
00245   del_hook(HOOK_SECONDLY, (Function) dns_check_expires);
00246   rem_tcl_ints(dnsints);
00247   rem_tcl_strings(dnsstrings);
00248   Tcl_UntraceVar(interp, "dns-servers",
00249                  TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
00250                  dns_change, NULL);
00251 
00252   for (i = 0; i < dcc_total; i++) {
00253     if (dcc[i].type == &DCC_DNS && dcc[i].sock == resfd) {
00254       killsock(dcc[i].sock);
00255       lostdcc(i);
00256       break;
00257     }
00258   }
00259 
00260   dns_free_cache();
00261   module_undepend(MODULE_NAME);
00262   return NULL;
00263 }

Here is the call graph for this function:

static void dns_event_failure ( struct resolve rp,
int  type 
) [static]

Definition at line 64 of file dns.c.

References call_hostbyip, call_ipbyhost, debug1, debug2, resolve::hostn, resolve::ip, iptostr, nonull, and UHOSTLEN.

Referenced by dns_forward(), dns_lookup(), and failrp().

00065 {
00066   if (!rp)
00067     return;
00068 
00069   if (type == T_PTR) {
00070     static char s[UHOSTLEN];
00071 
00072     debug1("DNS resolve failed for %s", iptostr(rp->ip));
00073     strcpy(s, iptostr(rp->ip));
00074     call_hostbyip(ntohl(rp->ip), s, 0);
00075   } else if (type == T_A) {
00076     debug1("DNS resolve failed for %s", rp->hostn);
00077     call_ipbyhost(rp->hostn, 0, 0);
00078   } else
00079     debug2("DNS resolve failed for unknown %s / %s", iptostr(rp->ip),
00080            nonull(rp->hostn));
00081   return;
00082 }

Here is the caller graph for this function:

static void dns_event_success ( struct resolve rp,
int  type 
) [static]

Definition at line 50 of file dns.c.

References call_hostbyip, call_ipbyhost, debug2, resolve::hostn, resolve::ip, and iptostr.

Referenced by dns_forward(), dns_lookup(), and passrp().

00051 {
00052   if (!rp)
00053     return;
00054 
00055   if (type == T_PTR) {
00056     debug2("DNS resolved %s to %s", iptostr(rp->ip), rp->hostn);
00057     call_hostbyip(ntohl(rp->ip), rp->hostn, 1);
00058   } else if (type == T_A) {
00059     debug2("DNS resolved %s to %s", rp->hostn, iptostr(rp->ip));
00060     call_ipbyhost(rp->hostn, ntohl(rp->ip), 1);
00061   }
00062 }

Here is the caller graph for this function:

static int dns_expmem ( void   )  [static]

Definition at line 217 of file dns.c.

References dns_cache_expmem().

Referenced by dns_report().

00218 {
00219   return dns_cache_expmem();
00220 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void dns_free_cache ( void   )  [static]

Definition at line 191 of file dns.c.

References expireresolves, resolve::hostn, resolve::next, nfree, and NULL.

Referenced by dns_close().

00192 {
00193   struct resolve *rp, *rpnext;
00194 
00195   for (rp = expireresolves; rp; rp = rpnext) {
00196     rpnext = rp->next;
00197     if (rp->hostn)
00198       nfree(rp->hostn);
00199     nfree(rp);
00200   }
00201   expireresolves = NULL;
00202 }

Here is the caller graph for this function:

static int dns_report ( int  idx,
int  details 
) [static]

Definition at line 222 of file dns.c.

References dns_expmem(), dprintf, and iptostr.

00223 {
00224   if (details) {
00225     int i, size = dns_expmem();
00226 
00227     dprintf(idx, "    Async DNS resolver is active.\n");
00228     dprintf(idx, "    DNS server list:");
00229     for (i = 0; i < _res.nscount; i++)
00230       dprintf(idx, " %s:%d", iptostr(_res.nsaddr_list[i].sin_addr.s_addr),
00231               ntohs(_res.nsaddr_list[i].sin_port));
00232     dprintf(idx, "\n");
00233     dprintf(idx, "    Using %d byte%s of memory\n", size,
00234             (size != 1) ? "s" : "");
00235   }
00236   return 0;
00237 }

Here is the call graph for this function:

static void dns_socket ( int  idx,
char *  buf,
int  len 
) [static]

Definition at line 102 of file dns.c.

References dns_ack().

00103 {
00104   dns_ack();
00105 }

Here is the call graph for this function:

char* dns_start ( Function global_funcs  ) 

Definition at line 276 of file dns.c.

References add_hook, add_tcl_ints, add_tcl_strings, dcc, dns_change(), dns_check_expires(), dns_forward(), dns_lookup(), dns_table, global, HOOK_DNS_HOSTBYIP, HOOK_DNS_IPBYHOST, HOOK_SECONDLY, init_dns_core(), interp, lostdcc, module_depend, MODULE_NAME, module_register, module_undepend, new_dcc, now, NULL, and resfd.

00277 {
00278   int idx;
00279 
00280   global = global_funcs;
00281 
00282   module_register(MODULE_NAME, dns_table, 1, 0);
00283   if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
00284     module_undepend(MODULE_NAME);
00285     return "This module requires Eggdrop 1.6.0 or later.";
00286   }
00287 
00288   idx = new_dcc(&DCC_DNS, 0);
00289   if (idx < 0)
00290     return "NO MORE DCC CONNECTIONS -- Can't create DNS socket.";
00291   if (!init_dns_core()) {
00292     lostdcc(idx);
00293     return "DNS initialisation failed.";
00294   }
00295   dcc[idx].sock = resfd;
00296   dcc[idx].timeval = now;
00297   strcpy(dcc[idx].nick, "(dns)");
00298 
00299   Tcl_TraceVar(interp, "dns-servers",
00300                TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
00301                dns_change, NULL);
00302   add_hook(HOOK_SECONDLY, (Function) dns_check_expires);
00303   add_hook(HOOK_DNS_HOSTBYIP, (Function) dns_lookup);
00304   add_hook(HOOK_DNS_IPBYHOST, (Function) dns_forward);
00305   add_tcl_ints(dnsints);
00306   add_tcl_strings(dnsstrings);
00307   return NULL;
00308 }

Here is the call graph for this function:

EXPORT_SCOPE char* dns_start (  ) 
static void eof_dns_socket ( int  idx  )  [static]

Definition at line 89 of file dns.c.

References dcc, init_dns_network(), killsock, LOG_MISC, lostdcc, now, putlog, and resfd.

00090 {
00091   putlog(LOG_MISC, "*", "DNS Error: socket closed.");
00092   killsock(dcc[idx].sock);
00093   /* Try to reopen socket */
00094   if (init_dns_network()) {
00095     putlog(LOG_MISC, "*", "DNS socket successfully reopened!");
00096     dcc[idx].sock = resfd;
00097     dcc[idx].timeval = now;
00098   } else
00099     lostdcc(idx);
00100 }

Here is the call graph for this function:


Variable Documentation

struct dcc_table DCC_DNS [static]
Initial value:
 {
  "DNS",
   0x00001000  ,
  eof_dns_socket,
  dns_socket,
   0 ,
   0 ,
  display_dns_socket,
   0 ,
   0 ,
   0 
}

Definition at line 112 of file dns.c.

int dns_cache = 86400 [static]

Definition at line 39 of file dns.c.

Referenced by passrp().

int dns_maxsends = 4 [static]

Definition at line 37 of file dns.c.

Referenced by dns_check_expires().

int dns_negcache = 600 [static]

Definition at line 40 of file dns.c.

Referenced by failrp().

int dns_retrydelay = 3 [static]

Definition at line 38 of file dns.c.

Referenced by resendrequest().

char dns_servers[121] = "" [static]

Definition at line 42 of file dns.c.

Function dns_table[] [static]
Initial value:

Definition at line 267 of file dns.c.

Referenced by dns_start().

tcl_ints dnsints[] [static]
Initial value:
 {
  {"dns-maxsends",   &dns_maxsends,   0},
  {"dns-retrydelay", &dns_retrydelay, 0},
  {"dns-cache",      &dns_cache,      0},
  {"dns-negcache",   &dns_negcache,   0},
  { 0 ,              0 ,            0}
}

Definition at line 125 of file dns.c.

tcl_strings dnsstrings[] [static]
Initial value:
 {
  {"dns-servers", dns_servers, 120,           0},
  { 0 ,           0 ,          0,           0}
}

Definition at line 133 of file dns.c.

Function* global = 0 [static]

Definition at line 35 of file dns.c.


Generated on 7 Sep 2016 for Eggdrop by  doxygen 1.6.1