|
1 diff -r badbd0960f5b config.c |
|
2 --- a/config.c Mon May 09 11:00:36 2011 +0200 |
|
3 +++ b/config.c Wed May 11 16:04:14 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)) == NULL) |
|
27 + conf_err("out of memory"); |
|
28 + memcpy(res->hostname, lin + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so); |
|
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)) == 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); |
|
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 Wed May 11 16:04:14 2011 +0200 |
|
73 @@ -1,3 +1,9 @@ |
|
74 +pound (2.5-1~bpo50+2) lenny-backports; urgency=low |
|
75 + |
|
76 + * patched to deal with backend addresses on dynamic ips |
|
77 + |
|
78 + -- Matthias Förste <foerste@schlittermann.de> Wed, 11 May 2011 15:52:38 +0200 |
|
79 + |
|
80 pound (2.5-1~bpo50+1) lenny-backports; urgency=low |
|
81 |
|
82 * Rebuild for lenny-backports. |
|
83 diff -r badbd0960f5b http.c |
|
84 --- a/http.c Mon May 09 11:00:36 2011 +0200 |
|
85 +++ b/http.c Wed May 11 16:04:14 2011 +0200 |
|
86 @@ -773,6 +773,13 @@ |
|
87 pthread_exit(NULL); |
|
88 break; |
|
89 } |
|
90 + if (backend->dyn_addr && upd_addr(backend->hostname, &backend->addr)) { |
|
91 + logmsg(LOG_WARNING, "(%lx) e503 backend: failed to resolve hostname '%s': %s", pthread_self(), backend->hostname, strerror(errno)); |
|
92 + err_reply(cl, h503, lstn->err503); |
|
93 + free_headers(headers); |
|
94 + clean_all(); |
|
95 + pthread_exit(NULL); |
|
96 + } |
|
97 if((sock = socket(sock_proto, SOCK_STREAM, 0)) < 0) { |
|
98 str_be(buf, MAXBUF - 1, backend); |
|
99 logmsg(LOG_WARNING, "(%lx) e503 backend %s socket create: %s", pthread_self(), buf, strerror(errno)); |
|
100 diff -r badbd0960f5b pound.8 |
|
101 --- a/pound.8 Mon May 09 11:00:36 2011 +0200 |
|
102 +++ b/pound.8 Wed May 11 16:04:14 2011 +0200 |
|
103 @@ -682,6 +682,22 @@ |
|
104 .B Pound |
|
105 uses the same address as the back-end server, but you may use a separate address |
|
106 if you wish. This directive applies only to non Unix-domain servers. |
|
107 +\fBDynamicAddress\fR |
|
108 +If this directive is present then the |
|
109 +.I Address |
|
110 +given for this |
|
111 +.I Backend |
|
112 +is considered a dynamic address. It is resolved whenever a connection attempt |
|
113 +to that |
|
114 +.I Address |
|
115 +is made. |
|
116 +\fBDynamicHAAddress\fR |
|
117 +This is the same as |
|
118 +.I DynamicAddress |
|
119 +except that it applies to the address given in the |
|
120 +.I HAPort |
|
121 +directive if any. |
|
122 + |
|
123 .SH "Emergency" |
|
124 The emergency server will be used once all existing back-ends are "dead". |
|
125 All configuration directives enclosed between |
|
126 diff -r badbd0960f5b pound.h |
|
127 --- a/pound.h Mon May 09 11:00:36 2011 +0200 |
|
128 +++ b/pound.h Wed May 11 16:04:14 2011 +0200 |
|
129 @@ -308,6 +308,10 @@ |
|
130 int alive; /* false if the back-end is dead */ |
|
131 int resurrect; /* this back-end is to be resurrected */ |
|
132 int disabled; /* true if the back-end is disabled */ |
|
133 + int dyn_addr; /* true if the address of the backend may change over time (dynamic ip for example) */ |
|
134 + char *hostname; /* in case of a dynamic address we need to keep the hostname too */ |
|
135 + int dyn_ha_addr; /* like dynaddr but for the ha addr */ |
|
136 + char *ha_hostname; /* in case of a dynamic ha address we need to keep the hostname too */ |
|
137 struct _backend *next; |
|
138 } BACKEND; |
|
139 |
|
140 @@ -571,3 +575,6 @@ |
|
141 * listens to client requests and calls the appropriate functions |
|
142 */ |
|
143 extern void *thr_control(void *); |
|
144 + |
|
145 +/* update address */ |
|
146 +int upd_addr(char *hostname, struct addrinfo *ai); |
|
147 diff -r badbd0960f5b svc.c |
|
148 --- a/svc.c Mon May 09 11:00:36 2011 +0200 |
|
149 +++ b/svc.c Wed May 11 16:04:14 2011 +0200 |
|
150 @@ -904,6 +904,9 @@ |
|
151 default: |
|
152 continue; |
|
153 } |
|
154 + if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) { |
|
155 + logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno)); |
|
156 + } |
|
157 if(connect_nb(sock, &be->ha_addr, be->conn_to) != 0) { |
|
158 kill_be(svc, be, BE_KILL); |
|
159 str_be(buf, MAXBUF - 1, be); |
|
160 @@ -940,6 +943,9 @@ |
|
161 default: |
|
162 continue; |
|
163 } |
|
164 + if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) { |
|
165 + logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno)); |
|
166 + } |
|
167 if(connect_nb(sock, &be->ha_addr, be->conn_to) != 0) { |
|
168 kill_be(svc, be, BE_KILL); |
|
169 str_be(buf, MAXBUF - 1, be); |
|
170 @@ -975,6 +981,9 @@ |
|
171 default: |
|
172 continue; |
|
173 } |
|
174 + if (be->dyn_addr && upd_addr(be->hostname, &be->addr)) { |
|
175 + logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->hostname, strerror(errno)); |
|
176 + } |
|
177 addr = &be->addr; |
|
178 } else { |
|
179 switch(be->ha_addr.ai_family) { |
|
180 @@ -993,6 +1002,9 @@ |
|
181 default: |
|
182 continue; |
|
183 } |
|
184 + if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) { |
|
185 + logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno)); |
|
186 + } |
|
187 addr = &be->ha_addr; |
|
188 } |
|
189 if(connect_nb(sock, addr, be->conn_to) == 0) { |
|
190 @@ -1044,6 +1056,9 @@ |
|
191 default: |
|
192 continue; |
|
193 } |
|
194 + if (be->dyn_addr && upd_addr(be->hostname, &be->addr)) { |
|
195 + logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->hostname, strerror(errno)); |
|
196 + } |
|
197 addr = &be->addr; |
|
198 } else { |
|
199 switch(be->ha_addr.ai_family) { |
|
200 @@ -1062,6 +1077,9 @@ |
|
201 default: |
|
202 continue; |
|
203 } |
|
204 + if (be->dyn_ha_addr && upd_addr(be->ha_hostname, &be->ha_addr)) { |
|
205 + logmsg(LOG_NOTICE, "failed to resolve hostname '%s': %s", be->ha_hostname, strerror(errno)); |
|
206 + } |
|
207 addr = &be->ha_addr; |
|
208 } |
|
209 if(connect_nb(sock, addr, be->conn_to) == 0) { |
|
210 @@ -1671,3 +1689,36 @@ |
|
211 close(ctl); |
|
212 } |
|
213 } |
|
214 + |
|
215 +/* update address */ |
|
216 +int |
|
217 +upd_addr(char *hostname, struct addrinfo *ai) |
|
218 +{ |
|
219 + |
|
220 + int r; |
|
221 + in_port_t port; |
|
222 + |
|
223 + /* get_host will set the port to zero */ |
|
224 + switch(ai->ai_family) { |
|
225 + case AF_INET: |
|
226 + port = ((struct sockaddr_in *)ai->ai_addr)->sin_port; |
|
227 + break; |
|
228 + case AF_INET6: |
|
229 + port = ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port; |
|
230 + break; |
|
231 + } |
|
232 + |
|
233 + r = get_host(hostname, ai); |
|
234 + |
|
235 + switch(ai->ai_family) { |
|
236 + case AF_INET: |
|
237 + ((struct sockaddr_in *)ai->ai_addr)->sin_port = port; |
|
238 + break; |
|
239 + case AF_INET6: |
|
240 + ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port = port; |
|
241 + break; |
|
242 + } |
|
243 + |
|
244 + return r; |
|
245 + |
|
246 +} |