chiark / gitweb /
src/: Fix internals to carry around address families.
[adns.git] / src / internal.h
index 50733b5eb44515ad8f4450105491d366479ced76..97af49ec620ed7752445a7f11624b19365af9bef 100644 (file)
@@ -124,6 +124,13 @@ typedef struct {
   struct timeval now;
 } parseinfo;
 
   struct timeval now;
 } parseinfo;
 
+union gen_addr {
+  struct in_addr v4;
+  struct in6_addr v6;
+};
+
+struct af_addr { int af; union gen_addr addr; };
+
 union checklabel_state {
   struct { byte ipv[4]; } ptr;
 };
 union checklabel_state {
   struct { byte ipv[4]; } ptr;
 };
@@ -134,7 +141,7 @@ typedef struct {
 
   union {
     struct {
 
   union {
     struct {
-      struct in_addr addr;
+      struct af_addr addr;
     } ptr;
   } tinfo; /* type-specific state for the query itself: zero-init if you
            * don't know better. */
     } ptr;
   } tinfo; /* type-specific state for the query itself: zero-init if you
            * don't know better. */
@@ -148,7 +155,7 @@ typedef struct typeinfo {
   adns_rrtype typekey;
   const char *rrtname;
   const char *fmtname;
   adns_rrtype typekey;
   const char *rrtname;
   const char *fmtname;
-  int rrsz;
+  int fixed_rrsz;
 
   void (*makefinal)(adns_query qu, void *data);
   /* Change memory management of *data.
 
   void (*makefinal)(adns_query qu, void *data);
   /* Change memory management of *data.
@@ -166,7 +173,7 @@ typedef struct typeinfo {
   /* Parse one RR, in dgram of length dglen, starting at cbyte and
    * extending until at most max.
    *
   /* Parse one RR, in dgram of length dglen, starting at cbyte and
    * extending until at most max.
    *
-   * The RR should be stored at *store_r, of length qu->typei->rrsz.
+   * The RR should be stored at *store_r, of length qu->typei->getrrsz().
    *
    * If there is an overrun which might indicate truncation, it should set
    * *rdstart to -1; otherwise it may set it to anything else positive.
    *
    * If there is an overrun which might indicate truncation, it should set
    * *rdstart to -1; otherwise it may set it to anything else positive.
@@ -191,12 +198,17 @@ typedef struct typeinfo {
    * because lablen is zero.
    */
 
    * because lablen is zero.
    */
 
-  void (*postsort)(adns_state ads, void *array, int nrrs,
+  void (*postsort)(adns_state ads, void *array, int nrrs,int rrsz,
                   const struct typeinfo *typei);
   /* Called immediately after the RRs have been sorted, and may rearrange
    * them.  (This is really for the benefit of SRV's bizarre weighting
    * stuff.)  May be 0 to mean nothing needs to be done.
    */
                   const struct typeinfo *typei);
   /* Called immediately after the RRs have been sorted, and may rearrange
    * them.  (This is really for the benefit of SRV's bizarre weighting
    * stuff.)  May be 0 to mean nothing needs to be done.
    */
+
+  int (*getrrsz)(const struct typeinfo *typei, adns_rrtype type);
+  /* Return the output resource-record element size; if this is null, then
+   * the rrsz member can be used.
+   */
 } typeinfo;
 
 adns_status adns__ckl_hostname(adns_state ads, adns_queryflags flags,
 } typeinfo;
 
 adns_status adns__ckl_hostname(adns_state ads, adns_queryflags flags,
@@ -353,11 +365,10 @@ struct adns__state {
   struct sigaction stdsigpipe;
   sigset_t stdsigmask;
   struct pollfd pollfds_buf[MAX_POLLFDS];
   struct sigaction stdsigpipe;
   sigset_t stdsigmask;
   struct pollfd pollfds_buf[MAX_POLLFDS];
-  struct server {
-    struct in_addr addr;
-  } servers[MAXSERVERS];
+  adns_rr_addr servers[MAXSERVERS];
   struct sortlist {
   struct sortlist {
-    struct in_addr base, mask;
+    int af;
+    union gen_addr base, mask;
   } sortlist[MAXSORTLIST];
   char **searchlist;
   unsigned short rand48xsubi[3];
   } sortlist[MAXSORTLIST];
   char **searchlist;
   unsigned short rand48xsubi[3];
@@ -405,6 +416,11 @@ const char *adns__diag_domain(adns_state ads, int serv, adns_query qu,
  * vb before using the return value.
  */
 
  * vb before using the return value.
  */
 
+int adns__getrrsz_default(const typeinfo *typei, adns_rrtype type);
+/* Default function for the `getrrsz' type hook; returns the `fixed_rrsz'
+ * value from the typeinfo entry.
+ */
+
 void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
                 int (*needswap)(void *context, const void *a, const void *b),
                 void *context);
 void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
                 int (*needswap)(void *context, const void *a, const void *b),
                 void *context);
@@ -459,8 +475,8 @@ void adns__query_send(adns_query qu, struct timeval now);
 /* From query.c: */
 
 adns_status adns__internal_submit(adns_state ads, adns_query *query_r,
 /* From query.c: */
 
 adns_status adns__internal_submit(adns_state ads, adns_query *query_r,
-                                 const typeinfo *typei, vbuf *qumsg_vb,
-                                 int id,
+                                 const typeinfo *typei, adns_rrtype type,
+                                 vbuf *qumsg_vb, int id,
                                  adns_queryflags flags, struct timeval now,
                                  qcontext *ctx);
 /* Submits a query (for internal use, called during external submits).
                                  adns_queryflags flags, struct timeval now,
                                  qcontext *ctx);
 /* Submits a query (for internal use, called during external submits).