updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / netqmail / netqmail-tls-1.06-ipv6-20021006.patch
blob5e7c6cbe710f6d8620c0be6f5130b02f69f7064e
1 diff -u netqmail-1.06.save/dns.c netqmail-1.06/dns.c
2 --- netqmail-1.06.save/dns.c 2009-10-12 00:07:49.731681373 +0400
3 +++ netqmail-1.06/dns.c 2009-10-12 00:54:46.291399716 +0400
4 @@ -3,6 +3,7 @@
5 #include <sys/types.h>
6 #include <netinet/in.h>
7 #include <arpa/nameser.h>
8 +#include <sys/socket.h>
9 #include <resolv.h>
10 #include <errno.h>
11 extern int res_query();
12 @@ -27,6 +28,9 @@
13 static int numanswers;
14 static char name[MAXDNAME];
15 static struct ip_address ip;
16 +#ifdef INET6
17 +static struct ip6_address ip6;
18 +#endif
19 unsigned short pref;
21 static stralloc glue = {0};
22 @@ -140,6 +144,43 @@
23 return 0;
26 +#ifdef INET6
27 +static int findip6(wanttype)
28 +int wanttype;
30 + unsigned short rrtype;
31 + unsigned short rrdlen;
32 + int i;
34 + if (numanswers <= 0) return 2;
35 + --numanswers;
36 + if (responsepos == responseend) return DNS_SOFT;
38 + i = dn_expand(response.buf,responseend,responsepos,name,MAXDNAME);
39 + if (i < 0) return DNS_SOFT;
40 + responsepos += i;
42 + i = responseend - responsepos;
43 + if (i < 4 + 3 * 2) return DNS_SOFT;
45 + rrtype = getshort(responsepos);
46 + rrdlen = getshort(responsepos + 8);
47 + responsepos += 10;
49 + if (rrtype == wanttype)
50 + {
51 + if (rrdlen < 16)
52 + return DNS_SOFT;
53 + bcopy(&responsepos[0], &ip6.d, 16);
54 + responsepos += rrdlen;
55 + return 1;
56 + }
58 + responsepos += rrdlen;
59 + return 0;
61 +#endif
63 static int findmx(wanttype)
64 int wanttype;
66 @@ -261,6 +302,57 @@
67 return DNS_HARD;
70 +#ifdef INET6
71 +static int iaafmt6(s,ip)
72 +char *s;
73 +struct ip6_address *ip;
75 + unsigned int i;
76 + int j;
77 + unsigned int len;
78 + static char data[] = "0123456789abcdef";
79 + len = 0;
81 + if (s) {
82 + for (j = 15; j >= 0; j--) {
83 + *s++ = data[ip->d[j] & 0x0f];
84 + *s++ = '.';
85 + *s++ = data[(ip->d[j] >> 4) & 0x0f];
86 + *s++ = '.';
87 + }
88 + strcpy(s, "ip6.int");
89 + }
90 + return 71;
91 + /* 1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.ip6.int */
94 +int dns_ptr6(sa,ip)
95 +stralloc *sa;
96 +struct ip6_address *ip;
98 + int r;
100 + if (!stralloc_ready(sa,iaafmt6((char *) 0,ip))) return DNS_MEM;
101 + sa->len = iaafmt6(sa->s,ip);
102 + switch(resolve(sa,T_PTR))
104 + case DNS_MEM: return DNS_MEM;
105 + case DNS_SOFT: return DNS_SOFT;
106 + case DNS_HARD: return DNS_HARD;
108 + while ((r = findname(T_PTR)) != 2)
110 + if (r == DNS_SOFT) return DNS_SOFT;
111 + if (r == 1)
113 + if (!stralloc_copys(sa,name)) return DNS_MEM;
114 + return 0;
117 + return DNS_HARD;
119 +#endif
121 static int dns_ipplus(ia,sa,pref)
122 ipalloc *ia;
123 stralloc *sa;
124 @@ -268,35 +360,73 @@
126 int r;
127 struct ip_mx ix = {0};
128 + int err4 = 0, err6 = 0;
130 if (!stralloc_copy(&glue,sa)) return DNS_MEM;
131 if (!stralloc_0(&glue)) return DNS_MEM;
132 if (glue.s[0]) {
133 - if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
134 + ix.pref = 0;
135 + ix.af = AF_INET;
136 + if (!glue.s[ip_scan(glue.s,&ix.addr.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.addr.ip)])
138 if (!ipalloc_append(ia,&ix)) return DNS_MEM;
139 return 0;
143 - switch(resolve(sa,T_A))
144 +#ifdef INET6
145 + switch(resolve(sa,T_AAAA))
147 - case DNS_MEM: return DNS_MEM;
148 - case DNS_SOFT: return DNS_SOFT;
149 - case DNS_HARD: return DNS_HARD;
150 + case DNS_MEM: err6 = DNS_MEM; break;
151 + case DNS_SOFT: err6 = DNS_SOFT; break;
152 + case DNS_HARD: err6 = DNS_HARD; break;
153 + default:
154 + while ((r = findip6(T_AAAA)) != 2)
156 + ix.af = AF_INET6;
157 + ix.addr.ip6 = ip6;
158 + ix.pref = pref;
159 + if (r == DNS_SOFT) { err6 = DNS_SOFT; break; }
160 + if (r == 1) {
161 +#ifdef IX_FQDN
162 + ix.fqdn = glue.s;
163 +#endif
164 + if (!ipalloc_append(ia,&ix)) { err6 = DNS_MEM; break; }
167 + break;
169 - while ((r = findip(T_A)) != 2)
170 +#endif
172 + switch(resolve(sa,T_A))
174 - ix.ip = ip;
175 - ix.pref = pref;
176 - if (r == DNS_SOFT) return DNS_SOFT;
177 - if (r == 1) {
178 + case DNS_MEM: err4 = DNS_MEM; break;
179 + case DNS_SOFT: err4 = DNS_SOFT; break;
180 + case DNS_HARD: err4 = DNS_HARD; break;
181 + default:
182 + while ((r = findip(T_A)) != 2)
184 + ix.af = AF_INET;
185 + ix.addr.ip = ip;
186 + ix.pref = pref;
187 + if (r == DNS_SOFT) { err4 = DNS_SOFT; break; }
188 + if (r == 1) {
189 #ifdef IX_FQDN
190 - ix.fqdn = glue.s;
191 + ix.fqdn = glue.s;
192 #endif
193 - if (!ipalloc_append(ia,&ix)) return DNS_MEM;
194 + if (!ipalloc_append(ia,&ix)) { err4 = DNS_MEM; break; }
197 + break;
200 +#ifdef INET6
201 + if (err4 != 0 && err6 != 0) {
202 + return err4;
204 +#else
205 + if (err4 != 0) return err4;
206 +#endif
207 #ifdef IX_FQDN
208 glue.s = 0;
209 #endif
210 @@ -331,8 +461,10 @@
211 if (!stralloc_copy(&glue,sa)) return DNS_MEM;
212 if (!stralloc_0(&glue)) return DNS_MEM;
213 if (glue.s[0]) {
214 - if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
215 + ix.pref = 0;
216 + if (!glue.s[ip_scan(glue.s,&ix.addr.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.addr.ip)])
218 + ix.af = AF_INET;
219 if (!ipalloc_append(ia,&ix)) return DNS_MEM;
220 return 0;
222 diff -u netqmail-1.06.save/dnsfq.c netqmail-1.06/dnsfq.c
223 --- netqmail-1.06.save/dnsfq.c 1998-06-15 14:53:16.000000000 +0400
224 +++ netqmail-1.06/dnsfq.c 2009-10-12 00:24:03.974918125 +0400
225 @@ -1,3 +1,5 @@
226 +#include <sys/types.h>
227 +#include <sys/socket.h>
228 #include "substdio.h"
229 #include "subfd.h"
230 #include "stralloc.h"
231 @@ -25,7 +27,12 @@
233 substdio_putsflush(subfderr,"no IP addresses\n"); _exit(100);
235 - dnsdoe(dns_ptr(&sa,&ia.ix[0].ip));
236 + if (ia.ix[0].af == AF_INET)
237 + dnsdoe(dns_ptr(&sa,&ia.ix[0].addr.ip));
238 +#ifdef INET6
239 + else
240 + dnsdoe(dns_ptr6(&sa,&ia.ix[0].addr.ip6));
241 +#endif
242 substdio_putflush(subfdout,sa.s,sa.len);
243 substdio_putsflush(subfdout,"\n");
244 _exit(0);
245 diff -u netqmail-1.06.save/dnsip.c netqmail-1.06/dnsip.c
246 --- netqmail-1.06.save/dnsip.c 1998-06-15 14:53:16.000000000 +0400
247 +++ netqmail-1.06/dnsip.c 2009-10-12 00:24:03.974918125 +0400
248 @@ -1,3 +1,5 @@
249 +#include <sys/types.h>
250 +#include <sys/socket.h>
251 #include "substdio.h"
252 #include "subfd.h"
253 #include "stralloc.h"
254 @@ -27,7 +29,19 @@
255 dnsdoe(dns_ip(&ia,&sa));
256 for (j = 0;j < ia.len;++j)
258 - substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].ip));
259 + switch(ia.ix[j].af) {
260 + case AF_INET:
261 + substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].addr.ip));
262 + break;
263 +#ifdef INET6
264 + case AF_INET6:
265 + substdio_put(subfdout,temp,ip6_fmt(temp,&ia.ix[j].addr.ip6));
266 + break;
267 +#endif
268 + default:
269 + substdio_puts(subfdout,"Unknown address family = ");
270 + substdio_put(subfdout,temp,fmt_ulong(temp,ia.ix[j].af));
272 substdio_putsflush(subfdout,"\n");
274 _exit(0);
275 diff -u netqmail-1.06.save/dnsmxip.c netqmail-1.06/dnsmxip.c
276 --- netqmail-1.06.save/dnsmxip.c 1998-06-15 14:53:16.000000000 +0400
277 +++ netqmail-1.06/dnsmxip.c 2009-10-12 00:24:03.974918125 +0400
278 @@ -1,3 +1,5 @@
279 +#include <sys/types.h>
280 +#include <sys/socket.h>
281 #include "substdio.h"
282 #include "subfd.h"
283 #include "stralloc.h"
284 @@ -31,7 +33,19 @@
285 dnsdoe(dns_mxip(&ia,&sa,r));
286 for (j = 0;j < ia.len;++j)
288 - substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].ip));
289 + switch(ia.ix[j].af) {
290 + case AF_INET:
291 + substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].addr.ip));
292 + break;
293 +#ifdef INET6
294 + case AF_INET6:
295 + substdio_put(subfdout,temp,ip6_fmt(temp,&ia.ix[j].addr.ip6));
296 + break;
297 +#endif
298 + default:
299 + substdio_puts(subfdout,"Unknown address family = ");
300 + substdio_put(subfdout,temp,fmt_ulong(temp,ia.ix[j].af));
302 substdio_puts(subfdout," ");
303 substdio_put(subfdout,temp,fmt_ulong(temp,(unsigned long) ia.ix[j].pref));
304 substdio_putsflush(subfdout,"\n");
305 diff -u netqmail-1.06.save/error.c netqmail-1.06/error.c
306 --- netqmail-1.06.save/error.c 1998-06-15 14:53:16.000000000 +0400
307 +++ netqmail-1.06/error.c 2009-10-12 00:24:03.974918125 +0400
308 @@ -93,3 +93,10 @@
309 #else
310 -13;
311 #endif
313 +int error_refused =
314 +#ifdef ECONNREFUSED
315 +ECONNREFUSED;
316 +#else
317 +-14;
318 +#endif
319 diff -u netqmail-1.06.save/error.h netqmail-1.06/error.h
320 --- netqmail-1.06.save/error.h 2007-11-30 23:22:54.000000000 +0300
321 +++ netqmail-1.06/error.h 2009-10-12 00:24:03.974918125 +0400
322 @@ -16,6 +16,7 @@
323 extern int error_pipe;
324 extern int error_perm;
325 extern int error_acces;
326 +extern int error_refused;
328 extern char *error_str();
329 extern int error_temp();
330 diff -u netqmail-1.06.save/hier.c netqmail-1.06/hier.c
331 --- netqmail-1.06.save/hier.c 2009-10-12 00:08:52.145008491 +0400
332 +++ netqmail-1.06/hier.c 2009-10-12 00:24:03.978250815 +0400
333 @@ -3,6 +3,8 @@
334 #include "auto_uids.h"
335 #include "fmt.h"
336 #include "fifo.h"
337 +#include "ipalloc.h"
338 +#include "tcpto.h"
340 char buf[100 + FMT_ULONG];
342 @@ -62,7 +64,7 @@
343 dsplit("queue/remote",auto_uids,0700);
345 d(auto_qmail,"queue/lock",auto_uidq,auto_gidq,0750);
346 - z(auto_qmail,"queue/lock/tcpto",1024,auto_uidr,auto_gidq,0644);
347 + z(auto_qmail,"queue/lock/tcpto",sizeof(struct tcpto_buf)*TCPTO_BUFSIZ,auto_uidr,auto_gidq,0644);
348 z(auto_qmail,"queue/lock/sendmutex",0,auto_uids,auto_gidq,0600);
349 p(auto_qmail,"queue/lock/trigger",auto_uids,auto_gidq,0622);
351 diff -u netqmail-1.06.save/ip.c netqmail-1.06/ip.c
352 --- netqmail-1.06.save/ip.c 1998-06-15 14:53:16.000000000 +0400
353 +++ netqmail-1.06/ip.c 2009-10-12 00:24:03.978250815 +0400
354 @@ -51,3 +51,32 @@
355 if (s[len + 1] != ']') return 0;
356 return len + 2;
359 +#ifdef INET6
360 +int fmt_hexbyte(char *s, unsigned char byte)
362 + static char data[] = "0123456789abcdef";
364 + if (s) {
365 + *s++ = data[(byte >> 4) & 0xf];
366 + *s = data[byte & 0xf];
368 + return 2;
371 +unsigned int ip6_fmt(s,ip6)
372 +char *s;
373 +struct ip6_address *ip6;
375 + unsigned int len;
376 + unsigned int i, j, k;
378 + len = 0;
379 + for (j = 0, len = 0, k = 0; j < 8; j++) {
380 + i = fmt_hexbyte(s, ip6->d[k++]); len += i; if (s) s += i;
381 + i = fmt_hexbyte(s, ip6->d[k++]); len += i; if (s) s += i;
382 + i = fmt_str(s,":"); len += i; if (s) s += i;
384 + return len-1;
386 +#endif
387 diff -u netqmail-1.06.save/ip.h netqmail-1.06/ip.h
388 --- netqmail-1.06.save/ip.h 1998-06-15 14:53:16.000000000 +0400
389 +++ netqmail-1.06/ip.h 2009-10-12 00:24:03.978250815 +0400
390 @@ -2,10 +2,20 @@
391 #define IP_H
393 struct ip_address { unsigned char d[4]; } ;
394 +#ifdef INET6
395 +struct ip6_address { unsigned char d[16]; } ;
396 +#endif
398 extern unsigned int ip_fmt();
399 +#ifdef INET6
400 +extern unsigned int ip6_fmt();
401 +#define IPFMT 72
402 +#else
403 #define IPFMT 19
404 +#endif
405 extern unsigned int ip_scan();
406 extern unsigned int ip_scanbracket();
408 +#define HOSTNAMELEN 1025
410 #endif
411 diff -u netqmail-1.06.save/ipalloc.h netqmail-1.06/ipalloc.h
412 --- netqmail-1.06.save/ipalloc.h 2009-10-12 00:07:49.731681373 +0400
413 +++ netqmail-1.06/ipalloc.h 2009-10-12 00:58:20.621378291 +0400
414 @@ -7,11 +7,19 @@
415 # define IX_FQDN 1
416 #endif
418 +struct ip_mx {
419 + unsigned short af;
420 + union {
421 + struct ip_address ip;
422 +#ifdef INET6
423 + struct ip6_address ip6;
424 +#endif
425 + } addr;
426 + int pref;
427 #ifdef IX_FQDN
428 -struct ip_mx { struct ip_address ip; int pref; char *fqdn; } ;
429 -#else
430 -struct ip_mx { struct ip_address ip; int pref; } ;
431 + char *fqdn;
432 #endif
433 + };
435 #include "gen_alloc.h"
437 diff -u netqmail-1.06.save/ipme.c netqmail-1.06/ipme.c
438 --- netqmail-1.06.save/ipme.c 2007-11-30 23:22:54.000000000 +0300
439 +++ netqmail-1.06/ipme.c 2009-10-12 01:43:51.291105297 +0400
440 @@ -24,11 +24,24 @@
441 int i;
442 if (ipme_init() != 1) return -1;
443 for (i = 0;i < ipme.len;++i)
444 - if (byte_equal(&ipme.ix[i].ip,4,ip))
445 + if (ipme.ix[i].af == AF_INET && byte_equal(&ipme.ix[i].addr.ip,4,ip))
446 return 1;
447 return 0;
450 +#ifdef INET6
451 +int ipme_is6(ip)
452 +struct ip6_address *ip;
454 + int i;
455 + if (ipme_init() != 1) return -1;
456 + for (i = 0;i < ipme.len;++i)
457 + if (ipme.ix[i].af == AF_INET6 && byte_equal(&ipme.ix[i].addr.ip6,16,ip))
458 + return 1;
459 + return 0;
461 +#endif
463 static stralloc buf = {0};
465 int ipme_init()
466 @@ -37,6 +50,9 @@
467 char *x;
468 struct ifreq *ifr;
469 struct sockaddr_in *sin;
470 +#ifdef INET6
471 + struct sockaddr_in6 *sin6;
472 +#endif
473 int len;
474 int s;
475 struct ip_mx ix;
476 @@ -49,7 +65,7 @@
477 /* 0.0.0.0 is a special address which always refers to
478 * "this host, this network", according to RFC 1122, Sec. 3.2.1.3a.
480 - byte_copy(&ix.ip,4,"\0\0\0\0");
481 + byte_copy(&ix.addr.ip,4,"\0\0\0\0");
482 if (!ipalloc_append(&ipme,&ix)) { return 0; }
483 if ((s = socket(AF_INET,SOCK_STREAM,0)) == -1) return -1;
485 @@ -76,11 +92,22 @@
486 len = sizeof(*ifr);
487 if (ifr->ifr_addr.sa_family == AF_INET) {
488 sin = (struct sockaddr_in *) &ifr->ifr_addr;
489 - byte_copy(&ix.ip,4,&sin->sin_addr);
490 + byte_copy(&ix.addr.ip,4,&sin->sin_addr);
491 + ix.af = AF_INET;
492 + if (ioctl(s,SIOCGIFFLAGS,x) == 0)
493 + if (ifr->ifr_flags & IFF_UP)
494 + if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
496 +#ifdef INET6
497 + else if (ifr->ifr_addr.sa_family == AF_INET6) {
498 + sin6 = (struct sockaddr_in6 *) &ifr->ifr_addr;
499 + byte_copy(&ix.addr.ip6,16,&sin6->sin6_addr);
500 + ix.af = AF_INET6;
501 if (ioctl(s,SIOCGIFFLAGS,x) == 0)
502 if (ifr->ifr_flags & IFF_UP)
503 if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
505 +#endif
506 #else
507 len = sizeof(*ifr);
508 if (ioctl(s,SIOCGIFFLAGS,x) == 0)
509 @@ -88,10 +115,19 @@
510 if (ioctl(s,SIOCGIFADDR,x) == 0)
511 if (ifr->ifr_addr.sa_family == AF_INET) {
512 sin = (struct sockaddr_in *) &ifr->ifr_addr;
513 - byte_copy(&ix.ip,4,&sin->sin_addr);
514 + ix.af = AF_INET;
515 + byte_copy(&ix.addr.ip,4,&sin->sin_addr);
516 + if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
518 +#ifdef INET6
519 + else if (ifr->ifr_addr.sa_family == AF_INET6) {
520 + sin6 = (struct sockaddr_in6 *) &ifr->ifr_addr;
521 + ix.af = AF_INET6;
522 + byte_copy(&ix.addr.ip6,16,&sin6->sin6_addr);
523 if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
525 #endif
526 +#endif
527 x += len;
529 close(s);
530 diff -u netqmail-1.06.save/ipmeprint.c netqmail-1.06/ipmeprint.c
531 --- netqmail-1.06.save/ipmeprint.c 1998-06-15 14:53:16.000000000 +0400
532 +++ netqmail-1.06/ipmeprint.c 2009-10-12 00:24:03.978250815 +0400
533 @@ -1,3 +1,5 @@
534 +#include <sys/types.h>
535 +#include <sys/socket.h>
536 #include "subfd.h"
537 #include "substdio.h"
538 #include "ip.h"
539 @@ -16,7 +18,19 @@
541 for (j = 0;j < ipme.len;++j)
543 - substdio_put(subfdout,temp,ip_fmt(temp,&ipme.ix[j].ip));
544 + switch(ipme.ix[j].af) {
545 + case AF_INET:
546 + substdio_put(subfdout,temp,ip_fmt(temp,&ipme.ix[j].addr.ip));
547 + break;
548 +#ifdef INET6
549 + case AF_INET6:
550 + substdio_put(subfdout,temp,ip6_fmt(temp,&ipme.ix[j].addr.ip6));
551 + break;
552 +#endif
553 + default:
554 + substdio_puts(subfdout,"Unknown address family = ");
555 + substdio_put(subfdout,temp,fmt_ulong(temp,ipme.ix[j].af));
557 substdio_puts(subfdout,"\n");
559 substdio_flush(subfdout);
560 Общие подкаталоги: netqmail-1.06.save/old-patches и netqmail-1.06/old-patches
561 Общие подкаталоги: netqmail-1.06.save/other-patches и netqmail-1.06/other-patches
562 diff -u netqmail-1.06.save/qmail-remote.c netqmail-1.06/qmail-remote.c
563 --- netqmail-1.06.save/qmail-remote.c 2009-10-12 00:07:49.735014771 +0400
564 +++ netqmail-1.06/qmail-remote.c 2009-10-12 01:02:37.934685921 +0400
565 @@ -46,7 +46,7 @@
567 saa reciplist = {0};
569 -struct ip_address partner;
570 +struct ip_mx partner;
572 #ifdef TLS
573 # include <sys/stat.h>
574 @@ -100,7 +100,15 @@
575 void outhost()
577 char x[IPFMT];
578 - if (substdio_put(subfdoutsmall,x,ip_fmt(x,&partner)) == -1) _exit(0);
579 +#ifdef INET6
580 + if (partner.af == AF_INET) {
581 +#endif
582 + if (substdio_put(subfdoutsmall,x,ip_fmt(x,&partner.addr.ip)) == -1) _exit(0);
583 +#ifdef INET6
584 + } else {
585 + if (substdio_put(subfdoutsmall,x,ip6_fmt(x,&partner.addr.ip6)) == -1) _exit(0);
587 +#endif
590 int flagcritical = 0;
591 @@ -667,6 +675,33 @@
595 +#ifdef INET6
596 +int ipme_is46(mxip)
597 +struct ip_mx *mxip;
599 + switch(mxip->af) {
600 + case AF_INET:
601 + return ipme_is(&mxip->addr.ip);
602 + case AF_INET6:
603 + return ipme_is6(&mxip->addr.ip6);
605 + return 0;
607 +#endif
609 +int timeoutconn46(fd, ix, port, timeout)
610 +int fd;
611 +struct ip_mx *ix;
612 +int port;
613 +int timeout;
615 +#ifdef INET6
616 + if (ix->af == AF_INET6)
617 + return timeoutconn6(fd, &ix->addr.ip6, port, timeout);
618 +#endif
619 + return timeoutconn(fd, &ix->addr.ip, port, timeout);
622 void main(argc,argv)
623 int argc;
624 char **argv;
625 @@ -735,7 +770,11 @@
627 prefme = 100000;
628 for (i = 0;i < ip.len;++i)
629 - if (ipme_is(&ip.ix[i].ip))
630 +#ifdef INET6
631 + if (ipme_is46(&ip.ix[i]))
632 +#else
633 + if (ipme_is(&ip.ix[i].addr.ip))
634 +#endif
635 if (ip.ix[i].pref < prefme)
636 prefme = ip.ix[i].pref;
638 @@ -750,20 +789,24 @@
639 perm_ambigmx();
641 for (i = 0;i < ip.len;++i) if (ip.ix[i].pref < prefme) {
642 - if (tcpto(&ip.ix[i].ip)) continue;
643 + if (tcpto(&ip.ix[i])) continue;
645 - smtpfd = socket(AF_INET,SOCK_STREAM,0);
646 + smtpfd = socket(ip.ix[i].af,SOCK_STREAM,0);
647 if (smtpfd == -1) temp_oserr();
649 - if (timeoutconn(smtpfd,&ip.ix[i].ip,(unsigned int) port,timeoutconnect) == 0) {
650 - tcpto_err(&ip.ix[i].ip,0);
651 - partner = ip.ix[i].ip;
652 + if (timeoutconn46(smtpfd,&ip.ix[i],(unsigned int) port,timeoutconnect) == 0) {
653 + tcpto_err(&ip.ix[i],0);
654 + partner = ip.ix[i];
655 #ifdef TLS
656 partner_fqdn = ip.ix[i].fqdn;
657 #endif
658 smtp(); /* does not return */
660 - tcpto_err(&ip.ix[i].ip,errno == error_timeout);
661 + tcpto_err(&ip.ix[i],errno == error_timeout
662 +#ifdef TCPTO_REFUSED
663 + || errno == error_refused
664 +#endif
665 + );
666 close(smtpfd);
669 diff -u netqmail-1.06.save/qmail-rspawn.c netqmail-1.06/qmail-rspawn.c
670 --- netqmail-1.06.save/qmail-rspawn.c 1998-06-15 14:53:16.000000000 +0400
671 +++ netqmail-1.06/qmail-rspawn.c 2009-10-12 00:24:03.981583955 +0400
672 @@ -4,6 +4,7 @@
673 #include "exit.h"
674 #include "fork.h"
675 #include "error.h"
676 +#include "ipalloc.h"
677 #include "tcpto.h"
679 void initialize(argc,argv)
680 diff -u netqmail-1.06.save/qmail-tcpok.c netqmail-1.06/qmail-tcpok.c
681 --- netqmail-1.06.save/qmail-tcpok.c 1998-06-15 14:53:16.000000000 +0400
682 +++ netqmail-1.06/qmail-tcpok.c 2009-10-12 00:24:03.981583955 +0400
683 @@ -5,10 +5,12 @@
684 #include "readwrite.h"
685 #include "auto_qmail.h"
686 #include "exit.h"
687 +#include "ipalloc.h"
688 +#include "tcpto.h"
690 #define FATAL "qmail-tcpok: fatal: "
692 -char buf[1024]; /* XXX: must match size in tcpto_clean.c, tcpto.c */
693 +struct tcpto_buf buf[TCPTO_BUFSIZ];
694 substdio ss;
696 void main()
697 diff -u netqmail-1.06.save/qmail-tcpto.c netqmail-1.06/qmail-tcpto.c
698 --- netqmail-1.06.save/qmail-tcpto.c 1998-06-15 14:53:16.000000000 +0400
699 +++ netqmail-1.06/qmail-tcpto.c 2009-10-12 00:24:03.991584053 +0400
700 @@ -1,5 +1,7 @@
701 /* XXX: this program knows quite a bit about tcpto's internals */
703 +#include <sys/types.h>
704 +#include <sys/socket.h>
705 #include "substdio.h"
706 #include "subfd.h"
707 #include "auto_qmail.h"
708 @@ -10,6 +12,8 @@
709 #include "exit.h"
710 #include "datetime.h"
711 #include "now.h"
712 +#include "ipalloc.h"
713 +#include "tcpto.h"
715 void die(n) int n; { substdio_flush(subfdout); _exit(n); }
717 @@ -28,7 +32,7 @@
718 void die_lock() { warn("fatal: unable to lock tcpto"); die(111); }
719 void die_read() { warn("fatal: unable to read tcpto"); die(111); }
721 -char tcpto_buf[1024];
722 +struct tcpto_buf tcpto_buf[TCPTO_BUFSIZ];
724 char tmp[FMT_ULONG + IPFMT];
726 @@ -38,8 +42,7 @@
727 int fd;
728 int r;
729 int i;
730 - char *record;
731 - struct ip_address ip;
732 + int af;
733 datetime_sec when;
734 datetime_sec start;
736 @@ -56,29 +59,31 @@
737 close(fdlock);
739 if (r == -1) die_read();
740 - r >>= 4;
741 + r /= sizeof(tcpto_buf[0]);
743 start = now();
745 - record = tcpto_buf;
746 for (i = 0;i < r;++i)
748 - if (record[4] >= 1)
749 + if (tcpto_buf[i].flag >= 1)
751 - byte_copy(&ip,4,record);
752 - when = (unsigned long) (unsigned char) record[11];
753 - when = (when << 8) + (unsigned long) (unsigned char) record[10];
754 - when = (when << 8) + (unsigned long) (unsigned char) record[9];
755 - when = (when << 8) + (unsigned long) (unsigned char) record[8];
756 + af = tcpto_buf[i].af;
757 + when = tcpto_buf[i].when;
759 - substdio_put(subfdout,tmp,ip_fmt(tmp,&ip));
760 +#ifdef INET6
761 + if (af == AF_INET)
762 + substdio_put(subfdout,tmp,ip_fmt(tmp,&tcpto_buf[i].addr.ip));
763 + else
764 + substdio_put(subfdout,tmp,ip6_fmt(tmp,&tcpto_buf[i].addr.ip6));
765 +#else
766 + substdio_put(subfdout,tmp,ip_fmt(tmp,&tcpto_buf[i].addr.ip));
767 +#endif
768 substdio_puts(subfdout," timed out ");
769 substdio_put(subfdout,tmp,fmt_ulong(tmp,(unsigned long) (start - when)));
770 substdio_puts(subfdout," seconds ago; # recent timeouts: ");
771 - substdio_put(subfdout,tmp,fmt_ulong(tmp,(unsigned long) (unsigned char) record[4]));
772 + substdio_put(subfdout,tmp,fmt_ulong(tmp,tcpto_buf[i].flag));
773 substdio_puts(subfdout,"\n");
775 - record += 16;
778 die(0);
779 diff -u netqmail-1.06.save/remoteinfo.c netqmail-1.06/remoteinfo.c
780 --- netqmail-1.06.save/remoteinfo.c 1998-06-15 14:53:16.000000000 +0400
781 +++ netqmail-1.06/remoteinfo.c 2009-10-12 00:24:03.998250615 +0400
782 @@ -23,33 +23,62 @@
783 return timeoutread(t,fd,buf,len);
786 -char *remoteinfo_get(ipr,rp,ipl,lp,timeout)
787 -struct ip_address *ipr;
788 -unsigned long rp;
789 -struct ip_address *ipl;
790 -unsigned long lp;
791 +union sockunion {
792 + struct sockaddr sa;
793 + struct sockaddr_in sa4;
794 +#ifdef INET6
795 + struct sockaddr_in6 sa6;
796 +#endif
799 +char *remoteinfo_get(saremote, salocal, timeout)
800 +union sockunion *saremote, *salocal;
801 int timeout;
803 char *x;
804 int s;
805 - struct sockaddr_in sin;
806 + union sockunion sa;
807 substdio ss;
808 char buf[32];
809 - unsigned int len;
810 + unsigned int len, rp, lp;
811 int numcolons;
812 char ch;
814 t = timeout;
816 - s = socket(AF_INET,SOCK_STREAM,0);
817 + s = socket(saremote->sa.sa_family,SOCK_STREAM,0);
818 + if (s == -1) return 0;
820 + switch(saremote->sa.sa_family) {
821 + case AF_INET:
822 + rp = ntohs(saremote->sa4.sin_port);
823 + lp = ntohs(salocal->sa4.sin_port);
824 + byte_zero(&sa,sizeof(sa));
825 + sa.sa4.sin_family = AF_INET;
826 + byte_copy(&sa.sa4.sin_addr, 4, &salocal->sa4.sin_addr);
827 + sa.sa4.sin_port = 0;
828 + if (bind(s,(struct sockaddr *) &sa.sa,sizeof(sa.sa4)) == -1) { close(s); return 0; }
829 + if (timeoutconn(s,&saremote->sa4.sin_addr,113,timeout) == -1) { close(s); return 0; }
830 + break;
831 +#ifdef INET6
832 + case AF_INET6:
833 + rp = ntohs(saremote->sa6.sin6_port);
834 + lp = ntohs(salocal->sa6.sin6_port);
835 + s = socket(PF_INET6, SOCK_STREAM, 0);
836 if (s == -1) return 0;
837 + byte_zero(&sa,sizeof(sa));
838 + sa.sa6.sin6_family = AF_INET;
839 + byte_copy(&sa.sa6.sin6_addr, 16, &salocal->sa6.sin6_addr);
840 + sa.sa6.sin6_port = 0;
841 + sa.sa6.sin6_flowinfo = 0;
842 + if (bind(s,(struct sockaddr *) &sa.sa,sizeof(sa.sa6)) == -1) { close(s); return 0; }
843 + if (timeoutconn6(s,&saremote->sa6.sin6_addr,113,timeout) == -1) { close(s); return 0; }
844 + break;
845 +#endif
846 + default:
847 + return 0;
850 - byte_zero(&sin,sizeof(sin));
851 - sin.sin_family = AF_INET;
852 - byte_copy(&sin.sin_addr,4,ipl);
853 - sin.sin_port = 0;
854 - if (bind(s,(struct sockaddr *) &sin,sizeof(sin)) == -1) { close(s); return 0; }
855 - if (timeoutconn(s,ipr,113,timeout) == -1) { close(s); return 0; }
856 fcntl(s,F_SETFL,fcntl(s,F_GETFL,0) & ~O_NDELAY);
858 len = 0;
859 diff -u netqmail-1.06.save/tcp-env.c netqmail-1.06/tcp-env.c
860 --- netqmail-1.06.save/tcp-env.c 1998-06-15 14:53:16.000000000 +0400
861 +++ netqmail-1.06/tcp-env.c 2009-10-12 00:24:04.001584040 +0400
862 @@ -2,6 +2,7 @@
863 #include <sys/socket.h>
864 #include <sys/param.h>
865 #include <netinet/in.h>
866 +#include <netdb.h>
867 #include "sig.h"
868 #include "stralloc.h"
869 #include "str.h"
870 @@ -15,20 +16,50 @@
871 #include "remoteinfo.h"
872 #include "exit.h"
873 #include "case.h"
874 +#include "hassalen.h"
876 void die() { _exit(111); }
878 -struct sockaddr_in salocal;
879 +union sockunion {
880 + struct sockaddr sa;
881 + struct sockaddr_in sa4;
882 +#ifdef INET6
883 + struct sockaddr_in6 sa6;
884 +#endif
887 +char temp[HOSTNAMELEN];
889 +union sockunion salocal;
890 unsigned long localport;
891 -struct ip_address iplocal;
892 stralloc localname = {0};
894 -struct sockaddr_in saremote;
895 +union sockunion saremote;
896 unsigned long remoteport;
897 -struct ip_address ipremote;
898 stralloc remotename = {0};
900 -char temp[IPFMT + FMT_ULONG];
901 +#if defined(IN6_IS_ADDR_V4MAPPED) && defined(INET6)
902 +void mappedtov4(union sockunion *sa)
904 + struct sockaddr_in sin;
905 + struct sockaddr_in6 *sin6 = &sa->sa6;
907 + bzero(&sin, sizeof(sin));
908 + if (sin6->sin6_family == AF_INET6 &&
909 + IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr) ) {
910 + memcpy(&sin.sin_addr, sin6->sin6_addr.s6_addr+12, sizeof(sin.sin_addr));
911 + sin.sin_port = sin6->sin6_port;
912 + sin.sin_family = AF_INET;
913 +#ifdef HASSALEN
914 + sin.sin_len = sizeof(sin);
915 +#endif
916 + memcpy(&sa->sa4, &sin, sizeof(sin));
920 +#else
921 +#define mappedtov4(A)
922 +#endif
924 void main(argc,argv)
925 int argc;
926 @@ -39,6 +70,7 @@
927 int opt;
928 int flagremoteinfo;
929 unsigned long timeout;
930 + struct sockaddr_in *v4;
932 sig_pipeignore();
934 @@ -65,17 +97,16 @@
936 dummy = sizeof(salocal);
937 if (getsockname(0,(struct sockaddr *) &salocal,&dummy) == -1) die();
938 + mappedtov4(&salocal);
940 - localport = ntohs(salocal.sin_port);
941 + switch(salocal.sa.sa_family) {
942 + case AF_INET:
943 + localport = ntohs(salocal.sa4.sin_port);
944 temp[fmt_ulong(temp,localport)] = 0;
945 if (!env_put2("TCPLOCALPORT",temp)) die();
947 - byte_copy(&iplocal,4,&salocal.sin_addr);
948 - temp[ip_fmt(temp,&iplocal)] = 0;
949 + temp[ip_fmt(temp, &salocal.sa4.sin_addr)] = 0;
950 if (!env_put2("TCPLOCALIP",temp)) die();
952 - switch(dns_ptr(&localname,&iplocal))
954 + switch(dns_ptr(&localname,&salocal.sa4.sin_addr)) {
955 case DNS_MEM: die();
956 case DNS_SOFT:
957 if (!stralloc_copys(&localname,"softdnserror")) die();
958 @@ -87,20 +118,64 @@
959 default:
960 if (!env_unset("TCPLOCALHOST")) die();
962 + break;
963 +#ifdef INET6
964 + case AF_INET6:
965 + localport = ntohs(salocal.sa6.sin6_port);
966 + temp[fmt_ulong(temp,localport)] = 0;
967 + if (!env_put2("TCPLOCALPORT",temp)) die();
968 + temp[ip6_fmt(temp, &salocal.sa6.sin6_addr)] = 0;
969 + if (!env_put2("TCPLOCALIP",temp)) die();
970 + switch(dns_ptr6(&localname,&salocal.sa6.sin6_addr)) {
971 + case DNS_MEM: die();
972 + case DNS_SOFT:
973 + if (!stralloc_copys(&localname,"softdnserror")) die();
974 + case 0:
975 + if (!stralloc_0(&localname)) die();
976 + case_lowers(localname.s);
977 + if (!env_put2("TCPLOCALHOST",localname.s)) die();
978 + break;
979 + default:
980 + if (!env_unset("TCPLOCALHOST")) die();
982 + break;
983 +#endif
984 + default:
985 + die();
988 dummy = sizeof(saremote);
989 if (getpeername(0,(struct sockaddr *) &saremote,&dummy) == -1) die();
990 + mappedtov4(&saremote);
992 - remoteport = ntohs(saremote.sin_port);
993 + switch(saremote.sa.sa_family) {
994 + case AF_INET:
995 + remoteport = ntohs(saremote.sa4.sin_port);
996 temp[fmt_ulong(temp,remoteport)] = 0;
997 if (!env_put2("TCPREMOTEPORT",temp)) die();
999 - byte_copy(&ipremote,4,&saremote.sin_addr);
1000 - temp[ip_fmt(temp,&ipremote)] = 0;
1001 + temp[ip_fmt(temp, &saremote.sa4.sin_addr)] = 0;
1002 if (!env_put2("TCPREMOTEIP",temp)) die();
1004 - switch(dns_ptr(&remotename,&ipremote))
1006 + switch(dns_ptr(&remotename,&saremote.sa4.sin_addr)) {
1007 + case DNS_MEM: die();
1008 + case DNS_SOFT:
1009 + if (!stralloc_copys(&remotename,"softdnserror")) die();
1010 + case 0:
1011 + if (!stralloc_0(&remotename)) die();
1012 + case_lowers(remotename.s);
1013 + if (!env_put2("TCPREMOTEHOST",remotename.s)) die();
1014 + break;
1015 + default:
1016 + if (!env_unset("TCPREMOTEHOST")) die();
1018 + break;
1019 +#ifdef INET6
1020 + case AF_INET6:
1021 + remoteport = ntohs(saremote.sa6.sin6_port);
1022 + temp[fmt_ulong(temp,remoteport)] = 0;
1023 + if (!env_put2("TCPREMOTEPORT",temp)) die();
1024 + temp[ip6_fmt(temp, &saremote.sa6.sin6_addr)] = 0;
1025 + if (!env_put2("TCPREMOTEIP",temp)) die();
1026 + switch(dns_ptr6(&remotename,&saremote.sa6.sin6_addr)) {
1027 case DNS_MEM: die();
1028 case DNS_SOFT:
1029 if (!stralloc_copys(&remotename,"softdnserror")) die();
1030 @@ -112,12 +187,18 @@
1031 default:
1032 if (!env_unset("TCPREMOTEHOST")) die();
1034 + break;
1035 +#endif
1036 + default:
1037 + die();
1040 if (!env_unset("TCPREMOTEINFO")) die();
1042 if (flagremoteinfo)
1044 char *rinfo;
1045 - rinfo = remoteinfo_get(&ipremote,remoteport,&iplocal,localport,(int) timeout);
1046 + rinfo = remoteinfo_get(&saremote, &salocal,(int) timeout);
1047 if (rinfo)
1048 if (!env_put2("TCPREMOTEINFO",rinfo)) die();
1050 diff -u netqmail-1.06.save/tcpto.c netqmail-1.06/tcpto.c
1051 --- netqmail-1.06.save/tcpto.c 1998-06-15 14:53:16.000000000 +0400
1052 +++ netqmail-1.06/tcpto.c 2009-10-12 01:33:42.307624839 +0400
1053 @@ -1,14 +1,19 @@
1054 +#include <sys/types.h>
1055 +#include <sys/uio.h>
1056 +#include <sys/socket.h>
1057 +#include <unistd.h>
1058 +#include "ipalloc.h"
1059 #include "tcpto.h"
1060 #include "open.h"
1061 #include "lock.h"
1062 #include "seek.h"
1063 #include "now.h"
1064 #include "ip.h"
1065 +#include "ipalloc.h"
1066 #include "byte.h"
1067 #include "datetime.h"
1068 -#include "readwrite.h"
1070 -char tcpto_buf[1024];
1071 +struct tcpto_buf tcpto_buf[TCPTO_BUFSIZ];
1073 static int flagwasthere;
1074 static int fdlock;
1075 @@ -23,19 +28,19 @@
1076 fd = open_read("queue/lock/tcpto");
1077 if (fd == -1) { close(fdlock); return 0; }
1078 if (lock_ex(fdlock) == -1) { close(fdlock); close(fd); return 0; }
1079 - r = read(fd,tcpto_buf,sizeof(tcpto_buf));
1080 + r = read(fd,&tcpto_buf,sizeof(tcpto_buf));
1081 close(fd);
1082 if (r < 0) { close(fdlock); return 0; }
1083 - r >>= 4;
1084 + r /= sizeof(tcpto_buf[0]);
1085 if (!r) close(fdlock);
1086 return r;
1089 -int tcpto(ip) struct ip_address *ip;
1090 +int tcpto(ix)
1091 +struct ip_mx *ix;
1093 int n;
1094 int i;
1095 - char *record;
1096 datetime_sec when;
1098 flagwasthere = 0;
1099 @@ -44,37 +49,35 @@
1100 if (!n) return 0;
1101 close(fdlock);
1103 - record = tcpto_buf;
1104 for (i = 0;i < n;++i)
1106 - if (byte_equal(ip->d,4,record))
1107 +#ifdef INET6
1108 + if (ix->af == tcpto_buf[i].af && (ix->af == AF_INET ? byte_equal(&ix->addr.ip, sizeof(ix->addr.ip), &tcpto_buf[i].addr.ip) : byte_equal(&ix->addr.ip6, sizeof(ix->addr.ip6), &tcpto_buf[i].addr.ip6)))
1109 +#else
1110 + if (byte_equal(&ix->addr.ip, sizeof(ix->addr.ip), &tcpto_buf[i].addr.ip))
1111 +#endif
1113 flagwasthere = 1;
1114 - if (record[4] >= 2)
1115 + if (tcpto_buf[i].flag >= 2)
1117 - when = (unsigned long) (unsigned char) record[11];
1118 - when = (when << 8) + (unsigned long) (unsigned char) record[10];
1119 - when = (when << 8) + (unsigned long) (unsigned char) record[9];
1120 - when = (when << 8) + (unsigned long) (unsigned char) record[8];
1122 + when = tcpto_buf[i].when;
1123 if (now() - when < ((60 + (getpid() & 31)) << 6))
1124 return 1;
1126 return 0;
1128 - record += 16;
1130 return 0;
1133 -void tcpto_err(ip,flagerr) struct ip_address *ip; int flagerr;
1134 +void tcpto_err(ix,flagerr)
1135 +struct ip_mx *ix; int flagerr;
1137 int n;
1138 int i;
1139 - char *record;
1140 datetime_sec when;
1141 - datetime_sec firstwhen;
1142 - int firstpos;
1143 + datetime_sec firstwhen=0;
1144 + int firstpos=-1;
1145 datetime_sec lastwhen;
1147 if (!flagerr)
1148 @@ -84,80 +87,68 @@
1149 n = getbuf();
1150 if (!n) return;
1152 - record = tcpto_buf;
1153 for (i = 0;i < n;++i)
1155 - if (byte_equal(ip->d,4,record))
1156 +#ifdef INET6
1157 + if (ix->af == tcpto_buf[i].af && (ix->af == AF_INET ? byte_equal(&ix->addr.ip, sizeof(ix->addr.ip), &tcpto_buf[i].addr.ip) : byte_equal(&ix->addr.ip6, sizeof(ix->addr.ip6), &tcpto_buf[i].addr.ip6)))
1158 +#else
1159 + if (byte_equal(&ix->addr.ip, sizeof(ix->addr.ip), &tcpto_buf[i].addr.ip))
1160 +#endif
1162 if (!flagerr)
1163 - record[4] = 0;
1164 + tcpto_buf[i].flag = 0;
1165 else
1167 - lastwhen = (unsigned long) (unsigned char) record[11];
1168 - lastwhen = (lastwhen << 8) + (unsigned long) (unsigned char) record[10];
1169 - lastwhen = (lastwhen << 8) + (unsigned long) (unsigned char) record[9];
1170 - lastwhen = (lastwhen << 8) + (unsigned long) (unsigned char) record[8];
1171 + lastwhen = tcpto_buf[i].when;
1172 when = now();
1174 - if (record[4] && (when < 120 + lastwhen)) { close(fdlock); return; }
1175 + if (tcpto_buf[i].flag && (when < 120 + lastwhen)) { close(fdlock); return; }
1177 - if (++record[4] > 10) record[4] = 10;
1178 - record[8] = when; when >>= 8;
1179 - record[9] = when; when >>= 8;
1180 - record[10] = when; when >>= 8;
1181 - record[11] = when;
1182 + if (++tcpto_buf[i].flag > 10) tcpto_buf[i].flag = 10;
1183 + tcpto_buf[i].when = when;
1185 - if (seek_set(fdlock,i << 4) == 0)
1186 - if (write(fdlock,record,16) < 16)
1187 + if (seek_set(fdlock,sizeof(tcpto_buf[0])*i) == 0)
1188 + if (write(fdlock,&tcpto_buf[i],sizeof(tcpto_buf[0])) < sizeof(tcpto_buf[0]))
1189 ; /*XXX*/
1190 close(fdlock);
1191 return;
1193 - record += 16;
1196 if (!flagerr) { close(fdlock); return; }
1198 - record = tcpto_buf;
1199 for (i = 0;i < n;++i)
1201 - if (!record[4]) break;
1202 - record += 16;
1204 + if (tcpto_buf[i].flag == 0) break;
1206 if (i >= n)
1208 firstpos = -1;
1209 - record = tcpto_buf;
1210 for (i = 0;i < n;++i)
1212 - when = (unsigned long) (unsigned char) record[11];
1213 - when = (when << 8) + (unsigned long) (unsigned char) record[10];
1214 - when = (when << 8) + (unsigned long) (unsigned char) record[9];
1215 - when = (when << 8) + (unsigned long) (unsigned char) record[8];
1216 - when += (record[4] << 10);
1217 + when = tcpto_buf[i].when;
1218 + when += (tcpto_buf[i].flag << 10);
1219 if ((firstpos < 0) || (when < firstwhen))
1221 firstpos = i;
1222 firstwhen = when;
1224 - record += 16;
1226 i = firstpos;
1229 if (i >= 0)
1231 - record = tcpto_buf + (i << 4);
1232 - byte_copy(record,4,ip->d);
1233 - when = now();
1234 - record[8] = when; when >>= 8;
1235 - record[9] = when; when >>= 8;
1236 - record[10] = when; when >>= 8;
1237 - record[11] = when;
1238 - record[4] = 1;
1239 - if (seek_set(fdlock,i << 4) == 0)
1240 - if (write(fdlock,record,16) < 16)
1241 + tcpto_buf[i].af = ix->af;
1242 +#ifdef INET6
1243 + if (ix->af == AF_INET6)
1244 + byte_copy(&tcpto_buf[i].addr.ip6, 16, &ix->addr.ip6);
1245 + else
1246 +#endif
1247 + byte_copy(&tcpto_buf[i].addr.ip, 4, &ix->addr.ip);
1248 + tcpto_buf[i].when = now();
1249 + tcpto_buf[i].flag = 1;
1250 + if (seek_set(fdlock,sizeof(tcpto_buf[0])*i) == 0)
1251 + if (write(fdlock,&tcpto_buf[i],sizeof(tcpto_buf[0])) < sizeof(tcpto_buf[0]))
1252 ; /*XXX*/
1255 diff -u netqmail-1.06.save/tcpto.h netqmail-1.06/tcpto.h
1256 --- netqmail-1.06.save/tcpto.h 1998-06-15 14:53:16.000000000 +0400
1257 +++ netqmail-1.06/tcpto.h 2009-10-12 00:24:04.011583902 +0400
1258 @@ -1,8 +1,23 @@
1259 #ifndef TCPTO_H
1260 #define TCPTO_H
1262 -extern int tcpto();
1263 -extern void tcpto_err();
1264 -extern void tcpto_clean();
1265 +#define TCPTO_BUFSIZ 64
1267 +struct tcpto_buf {
1268 + unsigned char af;
1269 + unsigned char flag;
1270 + unsigned long when;
1271 + union {
1272 + struct ip_address ip;
1273 +#ifdef INET6
1274 + struct ip6_address ip6;
1275 +#endif
1276 + unsigned char dummy[16];
1277 + } addr;
1280 +extern int tcpto(struct ip_mx *ix);
1281 +extern void tcpto_err(struct ip_mx *ix, int flagerr);
1282 +extern void tcpto_clean(void);
1284 #endif
1285 diff -u netqmail-1.06.save/tcpto_clean.c netqmail-1.06/tcpto_clean.c
1286 --- netqmail-1.06.save/tcpto_clean.c 1998-06-15 14:53:16.000000000 +0400
1287 +++ netqmail-1.06/tcpto_clean.c 2009-10-12 00:24:04.028250659 +0400
1288 @@ -1,9 +1,10 @@
1289 +#include "ipalloc.h"
1290 #include "tcpto.h"
1291 #include "open.h"
1292 #include "substdio.h"
1293 #include "readwrite.h"
1295 -char tcpto_cleanbuf[1024];
1296 +struct tcpto_buf tcpto_cleanbuf[TCPTO_BUFSIZ];
1298 void tcpto_clean() /* running from queue/mess */
1300 diff -u netqmail-1.06.save/timeoutconn.c netqmail-1.06/timeoutconn.c
1301 --- netqmail-1.06.save/timeoutconn.c 1998-06-15 14:53:16.000000000 +0400
1302 +++ netqmail-1.06/timeoutconn.c 2009-10-12 00:24:04.028250659 +0400
1303 @@ -57,3 +57,52 @@
1304 errno = error_timeout; /* note that connect attempt is continuing */
1305 return -1;
1308 +#ifdef INET6
1309 +int timeoutconn6(s,ip,port,timeout)
1310 +int s;
1311 +struct ip6_address *ip;
1312 +unsigned int port;
1313 +int timeout;
1315 + char ch;
1316 + struct sockaddr_in6 sin;
1317 + char *x;
1318 + fd_set wfds;
1319 + struct timeval tv;
1321 + byte_zero(&sin,sizeof(sin));
1322 + byte_copy(&sin.sin6_addr,16,ip);
1323 + sin.sin6_port = htons(port);;
1324 + sin.sin6_family = AF_INET6;
1326 + if (ndelay_on(s) == -1) return -1;
1328 + /* XXX: could bind s */
1330 + if (connect(s,(struct sockaddr *) &sin,sizeof(sin)) == 0) {
1331 + ndelay_off(s);
1332 + return 0;
1334 + if ((errno != error_inprogress) && (errno != error_wouldblock)) return -1;
1336 + FD_ZERO(&wfds);
1337 + FD_SET(s,&wfds);
1338 + tv.tv_sec = timeout; tv.tv_usec = 0;
1340 + if (select(s + 1,(fd_set *) 0,&wfds,(fd_set *) 0,&tv) == -1) return -1;
1341 + if (FD_ISSET(s,&wfds)) {
1342 + int dummy;
1343 + dummy = sizeof(sin);
1344 + if (getpeername(s,(struct sockaddr *) &sin,&dummy) == -1) {
1345 + read(s,&ch,1);
1346 + return -1;
1348 + ndelay_off(s);
1349 + return 0;
1352 + errno = error_timeout; /* note that connect attempt is continuing */
1353 + return -1;
1355 +#endif
1356 diff -u netqmail-1.06.save/timeoutconn.h netqmail-1.06/timeoutconn.h
1357 --- netqmail-1.06.save/timeoutconn.h 1998-06-15 14:53:16.000000000 +0400
1358 +++ netqmail-1.06/timeoutconn.h 2009-10-12 00:24:04.031583882 +0400
1359 @@ -2,5 +2,6 @@
1360 #define TIMEOUTCONN_H
1362 extern int timeoutconn();
1363 +extern int timeoutconn6();
1365 #endif