pound/2.5/dynamic-backends.patch
changeset 35 00eb34bfe348
parent 34 87b508932fa3
equal deleted inserted replaced
34:87b508932fa3 35:00eb34bfe348
     1 diff -r badbd0960f5b config.c
       
     2 --- a/config.c	Mon May 09 11:00:36 2011 +0200
       
     3 +++ b/config.c	Thu May 12 10:36:12 2011 +0200
       
     4 @@ -77,7 +77,7 @@
       
     5  static regex_t  Service, ServiceName, URL, HeadRequire, HeadDeny, BackEnd, Emergency, Priority, HAport, HAportAddr;
       
     6  static regex_t  Redirect, RedirectN, TimeOut, Session, Type, TTL, ID, DynScale;
       
     7  static regex_t  ClientCert, AddHeader, Ciphers, CAlist, VerifyList, CRLlist, NoHTTPS11;
       
     8 -static regex_t  Grace, Include, ConnTO, IgnoreCase, HTTPS, HTTPSCert;
       
     9 +static regex_t  Grace, Include, ConnTO, IgnoreCase, HTTPS, HTTPSCert, DynamicAddress, DynamicHAAddress;
       
    10  
       
    11  static regmatch_t   matches[5];
       
    12  
       
    13 @@ -182,7 +182,7 @@
       
    14      if((res = (BACKEND *)malloc(sizeof(BACKEND))) == NULL)
       
    15          conf_err("BackEnd config: out of memory - aborted");
       
    16      memset(res, 0, sizeof(BACKEND));
       
    17 -    res->be_type = 0;
       
    18 +    res->be_type = res->dyn_addr = res->dyn_ha_addr = 0;
       
    19      res->addr.ai_socktype = SOCK_STREAM;
       
    20      res->to = is_emergency? 120: be_to;
       
    21      res->conn_to = is_emergency? 120: be_connto;
       
    22 @@ -200,6 +200,9 @@
       
    23              lin[strlen(lin) - 1] = '\0';
       
    24          if(!regexec(&Address, lin, 4, matches, 0)) {
       
    25              lin[matches[1].rm_eo] = '\0';
       
    26 +            if((res->hostname = (char *)malloc(matches[1].rm_eo - matches[1].rm_so + 1)) == NULL)
       
    27 +                conf_err("out of memory");
       
    28 +            memcpy(res->hostname, lin + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so + 1);
       
    29              if(get_host(lin + matches[1].rm_so, &res->addr)) {
       
    30                  /* if we can't resolve it assume this is a UNIX domain socket */
       
    31                  res->addr.ai_socktype = SOCK_STREAM;
       
    32 @@ -243,6 +246,7 @@
       
    33              if(is_emergency)
       
    34                  conf_err("HAport is not supported for Emergency back-ends");
       
    35              res->ha_addr = res->addr;
       
    36 +            res->ha_hostname = res->hostname;
       
    37              if((res->ha_addr.ai_addr = (struct sockaddr *)malloc(res->addr.ai_addrlen)) == NULL)
       
    38                  conf_err("out of memory");
       
    39              memcpy(res->ha_addr.ai_addr, res->addr.ai_addr, res->addr.ai_addrlen);
       
    40 @@ -264,6 +268,9 @@
       
    41              if(is_emergency)
       
    42                  conf_err("HAportAddr is not supported for Emergency back-ends");
       
    43              lin[matches[1].rm_eo] = '\0';
       
    44 +            if((res->ha_hostname = (char *)malloc(matches[1].rm_eo - matches[1].rm_so + 1)) == NULL)
       
    45 +                conf_err("out of memory");
       
    46 +            memcpy(res->ha_hostname, lin + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so + 1);
       
    47              if(get_host(lin + matches[1].rm_so, &res->ha_addr)) {
       
    48                  /* if we can't resolve it assume this is a UNIX domain socket */
       
    49                  res->addr.ai_socktype = SOCK_STREAM;
       
    50 @@ -313,6 +320,10 @@
       
    51              SSL_CTX_set_session_id_context(res->ctx, (unsigned char *)lin, strlen(lin));
       
    52              SSL_CTX_set_tmp_rsa_callback(res->ctx, RSA_tmp_callback);
       
    53              SSL_CTX_set_tmp_dh_callback(res->ctx, DH_tmp_callback);
       
    54 +        } else if(!regexec(&DynamicAddress, lin, 4, matches, 0)) {
       
    55 +            res->dyn_addr = 1;
       
    56 +        } else if(!regexec(&DynamicHAAddress, lin, 4, matches, 0)) {
       
    57 +            res->dyn_ha_addr = 1;
       
    58          } else if(!regexec(&End, lin, 4, matches, 0)) {
       
    59              if(!has_addr)
       
    60                  conf_err("BackEnd missing Address - aborted");
       
    61 @@ -1163,6 +1174,8 @@
       
    62      || regcomp(&IgnoreCase, "^[ \t]*IgnoreCase[ \t]+([01])[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
       
    63      || regcomp(&HTTPS, "^[ \t]*HTTPS[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
       
    64      || regcomp(&HTTPSCert, "^[ \t]*HTTPS[ \t]+\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
       
    65 +    || regcomp(&DynamicAddress, "^[ \t]*DynamicAddress[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
       
    66 +    || regcomp(&DynamicHAAddress, "^[ \t]*DynamicHAAddress[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
       
    67      ) {
       
    68          logmsg(LOG_ERR, "bad config Regex - aborted");
       
    69          exit(1);
       
    70 diff -r badbd0960f5b debian/changelog
       
    71 --- a/debian/changelog	Mon May 09 11:00:36 2011 +0200
       
    72 +++ b/debian/changelog	Thu May 12 10:36:12 2011 +0200
       
    73 @@ -1,3 +1,16 @@
       
    74 +pound (2.5-1~bpo50+3) lenny-backports; urgency=low
       
    75 +
       
    76 +  * fixed manpage formatting 
       
    77 +  * fixed unterminated strings 
       
    78 +
       
    79 + -- Matthias Förste <foerste@schlittermann.de>  Thu, 12 May 2011 10:35:36 +0200
       
    80 +
       
    81 +pound (2.5-1~bpo50+2) lenny-backports; urgency=low
       
    82 +
       
    83 +  * patched to deal with backend addresses on dynamic ips
       
    84 +
       
    85 + -- Matthias Förste <foerste@schlittermann.de>  Wed, 11 May 2011 15:52:38 +0200
       
    86 +
       
    87  pound (2.5-1~bpo50+1) lenny-backports; urgency=low
       
    88  
       
    89    * Rebuild for lenny-backports.
       
    90 diff -r badbd0960f5b http.c
       
    91 --- a/http.c	Mon May 09 11:00:36 2011 +0200
       
    92 +++ b/http.c	Thu May 12 10:36:12 2011 +0200
       
    93 @@ -773,6 +773,13 @@
       
    94                  pthread_exit(NULL);
       
    95                  break;
       
    96              }
       
    97 +            if (backend->dyn_addr && upd_addr(backend->hostname, &backend->addr)) {
       
    98 +                logmsg(LOG_WARNING, "(%lx) e503 backend: failed to resolve hostname '%s': %s", pthread_self(), backend->hostname, strerror(errno));
       
    99 +                err_reply(cl, h503, lstn->err503);
       
   100 +                free_headers(headers);
       
   101 +                clean_all();
       
   102 +                pthread_exit(NULL);
       
   103 +            }
       
   104              if((sock = socket(sock_proto, SOCK_STREAM, 0)) < 0) {
       
   105                  str_be(buf, MAXBUF - 1, backend);
       
   106                  logmsg(LOG_WARNING, "(%lx) e503 backend %s socket create: %s", pthread_self(), buf, strerror(errno));
       
   107 diff -r badbd0960f5b pound.8
       
   108 --- a/pound.8	Mon May 09 11:00:36 2011 +0200
       
   109 +++ b/pound.8	Thu May 12 10:36:12 2011 +0200
       
   110 @@ -682,6 +682,24 @@
       
   111  .B Pound
       
   112  uses the same address as the back-end server, but you may use a separate address
       
   113  if you wish. This directive applies only to non Unix-domain servers.
       
   114 +.TP
       
   115 +\fBDynamicAddress\fR
       
   116 +If this directive is present then the
       
   117 +.I Address
       
   118 +given for this
       
   119 +.I Backend
       
   120 +is considered a dynamic address. It is resolved whenever a connection attempt
       
   121 +to that
       
   122 +.I Address
       
   123 +is made.
       
   124 +.TP
       
   125 +\fBDynamicHAAddress\fR
       
   126 +This is the same as
       
   127 +.I DynamicAddress
       
   128 +except that it applies to the address given in the
       
   129 +.I HAPort
       
   130 +directive if any.
       
   131 +
       
   132  .SH "Emergency"
       
   133  The emergency server will be used once all existing back-ends are "dead".
       
   134  All configuration directives enclosed between
       
   135 diff -r badbd0960f5b pound.h
       
   136 --- a/pound.h	Mon May 09 11:00:36 2011 +0200
       
   137 +++ b/pound.h	Thu May 12 10:36:12 2011 +0200
       
   138 @@ -308,6 +308,10 @@
       
   139      int                 alive;      /* false if the back-end is dead */
       
   140      int                 resurrect;  /* this back-end is to be resurrected */
       
   141      int                 disabled;   /* true if the back-end is disabled */
       
   142 +    int                 dyn_addr;     /* true if the address of the backend may change over time (dynamic ip for example) */
       
   143 +    char                *hostname;    /* in case of a dynamic address we need to keep the hostname too */
       
   144 +    int                 dyn_ha_addr;  /* like dynaddr but for the ha addr */
       
   145 +    char                *ha_hostname; /* in case of a dynamic ha address we need to keep the hostname too */
       
   146      struct _backend     *next;
       
   147  }   BACKEND;
       
   148  
       
   149 @@ -571,3 +575,6 @@
       
   150   * listens to client requests and calls the appropriate functions
       
   151   */
       
   152  extern void *thr_control(void *);
       
   153 +
       
   154 +/* update address */
       
   155 +int upd_addr(char *hostname, struct addrinfo *ai);
       
   156 diff -r badbd0960f5b svc.c
       
   157 --- a/svc.c	Mon May 09 11:00:36 2011 +0200
       
   158 +++ b/svc.c	Thu May 12 10:36:12 2011 +0200
       
   159 @@ -904,6 +904,9 @@
       
   160          default:
       
   161              continue;
       
   162          }
       
   163 +        if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) {
       
   164 +            logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno));
       
   165 +        }
       
   166          if(connect_nb(sock, &be->ha_addr, be->conn_to) != 0) {
       
   167              kill_be(svc, be, BE_KILL);
       
   168              str_be(buf, MAXBUF - 1, be);
       
   169 @@ -940,6 +943,9 @@
       
   170          default:
       
   171              continue;
       
   172          }
       
   173 +        if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) {
       
   174 +            logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno));
       
   175 +        }
       
   176          if(connect_nb(sock, &be->ha_addr, be->conn_to) != 0) {
       
   177              kill_be(svc, be, BE_KILL);
       
   178              str_be(buf, MAXBUF - 1, be);
       
   179 @@ -975,6 +981,9 @@
       
   180                  default:
       
   181                      continue;
       
   182                  }
       
   183 +                if (be->dyn_addr && upd_addr(be->hostname, &be->addr)) {
       
   184 +                    logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->hostname, strerror(errno));
       
   185 +                }
       
   186                  addr = &be->addr;
       
   187              } else {
       
   188                  switch(be->ha_addr.ai_family) {
       
   189 @@ -993,6 +1002,9 @@
       
   190                  default:
       
   191                      continue;
       
   192                  }
       
   193 +                if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) {
       
   194 +                    logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno));
       
   195 +                }
       
   196                  addr = &be->ha_addr;
       
   197              }
       
   198              if(connect_nb(sock, addr, be->conn_to) == 0) {
       
   199 @@ -1044,6 +1056,9 @@
       
   200                  default:
       
   201                      continue;
       
   202                  }
       
   203 +                if (be->dyn_addr && upd_addr(be->hostname, &be->addr)) {
       
   204 +                    logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->hostname, strerror(errno));
       
   205 +                }
       
   206                  addr = &be->addr;
       
   207              } else {
       
   208                  switch(be->ha_addr.ai_family) {
       
   209 @@ -1062,6 +1077,9 @@
       
   210                  default:
       
   211                      continue;
       
   212                  }
       
   213 +                if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) {
       
   214 +                    logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno));
       
   215 +                }
       
   216                  addr = &be->ha_addr;
       
   217              }
       
   218              if(connect_nb(sock, addr, be->conn_to) == 0) {
       
   219 @@ -1671,3 +1689,36 @@
       
   220          close(ctl);
       
   221      }
       
   222  }
       
   223 +
       
   224 +/* update address */
       
   225 +int
       
   226 +upd_addr(char *hostname, struct addrinfo *ai)
       
   227 +{
       
   228 +
       
   229 +    int r;
       
   230 +    in_port_t port;
       
   231 +
       
   232 +    /* get_host will set the port to zero */
       
   233 +    switch(ai->ai_family) {
       
   234 +        case AF_INET:
       
   235 +            port = ((struct sockaddr_in *)ai->ai_addr)->sin_port;
       
   236 +            break;
       
   237 +        case AF_INET6:
       
   238 +            port = ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port;
       
   239 +            break;
       
   240 +    }
       
   241 +
       
   242 +    r = get_host(hostname, ai);
       
   243 +
       
   244 +    switch(ai->ai_family) {
       
   245 +        case AF_INET:
       
   246 +            ((struct sockaddr_in *)ai->ai_addr)->sin_port = port;
       
   247 +            break;
       
   248 +        case AF_INET6:
       
   249 +            ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port = port;
       
   250 +            break;
       
   251 +    }
       
   252 +
       
   253 +    return r;
       
   254 +
       
   255 +}