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
6 #include <netinet/in.h>
7 #include <arpa/nameser.h>
8 +#include <sys/socket.h>
11 extern int res_query();
13 static int numanswers;
14 static char name[MAXDNAME];
15 static struct ip_address ip;
17 +static struct ip6_address ip6;
21 static stralloc glue = {0};
27 +static int findip6(wanttype)
30 + unsigned short rrtype;
31 + unsigned short rrdlen;
34 + if (numanswers <= 0) return 2;
36 + if (responsepos == responseend) return DNS_SOFT;
38 + i = dn_expand(response.buf,responseend,responsepos,name,MAXDNAME);
39 + if (i < 0) return DNS_SOFT;
42 + i = responseend - responsepos;
43 + if (i < 4 + 3 * 2) return DNS_SOFT;
45 + rrtype = getshort(responsepos);
46 + rrdlen = getshort(responsepos + 8);
49 + if (rrtype == wanttype)
53 + bcopy(&responsepos[0], &ip6.d, 16);
54 + responsepos += rrdlen;
58 + responsepos += rrdlen;
63 static int findmx(wanttype)
71 +static int iaafmt6(s,ip)
73 +struct ip6_address *ip;
78 + static char data[] = "0123456789abcdef";
82 + for (j = 15; j >= 0; j--) {
83 + *s++ = data[ip->d[j] & 0x0f];
85 + *s++ = data[(ip->d[j] >> 4) & 0x0f];
88 + strcpy(s, "ip6.int");
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 */
96 +struct ip6_address *ip;
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;
113 + if (!stralloc_copys(sa,name)) return DNS_MEM;
121 static int dns_ipplus(ia,sa,pref)
124 @@ -268,35 +360,73 @@
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;
133 - if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
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;
143 - switch(resolve(sa,T_A))
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;
154 + while ((r = findip6(T_AAAA)) != 2)
159 + if (r == DNS_SOFT) { err6 = DNS_SOFT; break; }
164 + if (!ipalloc_append(ia,&ix)) { err6 = DNS_MEM; break; }
169 - while ((r = findip(T_A)) != 2)
172 + switch(resolve(sa,T_A))
176 - if (r == DNS_SOFT) return DNS_SOFT;
178 + case DNS_MEM: err4 = DNS_MEM; break;
179 + case DNS_SOFT: err4 = DNS_SOFT; break;
180 + case DNS_HARD: err4 = DNS_HARD; break;
182 + while ((r = findip(T_A)) != 2)
187 + if (r == DNS_SOFT) { err4 = DNS_SOFT; break; }
193 - if (!ipalloc_append(ia,&ix)) return DNS_MEM;
194 + if (!ipalloc_append(ia,&ix)) { err4 = DNS_MEM; break; }
201 + if (err4 != 0 && err6 != 0) {
205 + if (err4 != 0) return err4;
211 if (!stralloc_copy(&glue,sa)) return DNS_MEM;
212 if (!stralloc_0(&glue)) return DNS_MEM;
214 - if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
216 + if (!glue.s[ip_scan(glue.s,&ix.addr.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.addr.ip)])
219 if (!ipalloc_append(ia,&ix)) return DNS_MEM;
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
226 +#include <sys/types.h>
227 +#include <sys/socket.h>
228 #include "substdio.h"
230 #include "stralloc.h"
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));
240 + dnsdoe(dns_ptr6(&sa,&ia.ix[0].addr.ip6));
242 substdio_putflush(subfdout,sa.s,sa.len);
243 substdio_putsflush(subfdout,"\n");
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
249 +#include <sys/types.h>
250 +#include <sys/socket.h>
251 #include "substdio.h"
253 #include "stralloc.h"
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) {
261 + substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].addr.ip));
265 + substdio_put(subfdout,temp,ip6_fmt(temp,&ia.ix[j].addr.ip6));
269 + substdio_puts(subfdout,"Unknown address family = ");
270 + substdio_put(subfdout,temp,fmt_ulong(temp,ia.ix[j].af));
272 substdio_putsflush(subfdout,"\n");
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
279 +#include <sys/types.h>
280 +#include <sys/socket.h>
281 #include "substdio.h"
283 #include "stralloc.h"
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) {
291 + substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].addr.ip));
295 + substdio_put(subfdout,temp,ip6_fmt(temp,&ia.ix[j].addr.ip6));
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
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
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
334 #include "auto_uids.h"
337 +#include "ipalloc.h"
340 char buf[100 + FMT_ULONG];
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
355 if (s[len + 1] != ']') return 0;
360 +int fmt_hexbyte(char *s, unsigned char byte)
362 + static char data[] = "0123456789abcdef";
365 + *s++ = data[(byte >> 4) & 0xf];
366 + *s = data[byte & 0xf];
371 +unsigned int ip6_fmt(s,ip6)
373 +struct ip6_address *ip6;
376 + unsigned int i, j, k;
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;
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
393 struct ip_address { unsigned char d[4]; } ;
395 +struct ip6_address { unsigned char d[16]; } ;
398 extern unsigned int ip_fmt();
400 +extern unsigned int ip6_fmt();
405 extern unsigned int ip_scan();
406 extern unsigned int ip_scanbracket();
408 +#define HOSTNAMELEN 1025
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
421 + struct ip_address ip;
423 + struct ip6_address ip6;
428 -struct ip_mx { struct ip_address ip; int pref; char *fqdn; } ;
430 -struct ip_mx { struct ip_address ip; int pref; } ;
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
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))
452 +struct ip6_address *ip;
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))
463 static stralloc buf = {0};
469 struct sockaddr_in *sin;
471 + struct sockaddr_in6 *sin6;
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;
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);
492 + if (ioctl(s,SIOCGIFFLAGS,x) == 0)
493 + if (ifr->ifr_flags & IFF_UP)
494 + if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
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);
501 if (ioctl(s,SIOCGIFFLAGS,x) == 0)
502 if (ifr->ifr_flags & IFF_UP)
503 if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
508 if (ioctl(s,SIOCGIFFLAGS,x) == 0)
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);
515 + byte_copy(&ix.addr.ip,4,&sin->sin_addr);
516 + if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
519 + else if (ifr->ifr_addr.sa_family == AF_INET6) {
520 + sin6 = (struct sockaddr_in6 *) &ifr->ifr_addr;
522 + byte_copy(&ix.addr.ip6,16,&sin6->sin6_addr);
523 if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; }
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
534 +#include <sys/types.h>
535 +#include <sys/socket.h>
537 #include "substdio.h"
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) {
546 + substdio_put(subfdout,temp,ip_fmt(temp,&ipme.ix[j].addr.ip));
550 + substdio_put(subfdout,temp,ip6_fmt(temp,&ipme.ix[j].addr.ip6));
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
569 -struct ip_address partner;
570 +struct ip_mx partner;
573 # include <sys/stat.h>
578 - if (substdio_put(subfdoutsmall,x,ip_fmt(x,&partner)) == -1) _exit(0);
580 + if (partner.af == AF_INET) {
582 + if (substdio_put(subfdoutsmall,x,ip_fmt(x,&partner.addr.ip)) == -1) _exit(0);
585 + if (substdio_put(subfdoutsmall,x,ip6_fmt(x,&partner.addr.ip6)) == -1) _exit(0);
590 int flagcritical = 0;
601 + return ipme_is(&mxip->addr.ip);
603 + return ipme_is6(&mxip->addr.ip6);
609 +int timeoutconn46(fd, ix, port, timeout)
616 + if (ix->af == AF_INET6)
617 + return timeoutconn6(fd, &ix->addr.ip6, port, timeout);
619 + return timeoutconn(fd, &ix->addr.ip, port, timeout);
628 for (i = 0;i < ip.len;++i)
629 - if (ipme_is(&ip.ix[i].ip))
631 + if (ipme_is46(&ip.ix[i]))
633 + if (ipme_is(&ip.ix[i].addr.ip))
635 if (ip.ix[i].pref < prefme)
636 prefme = ip.ix[i].pref;
638 @@ -750,20 +789,24 @@
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];
656 partner_fqdn = ip.ix[i].fqdn;
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
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
676 +#include "ipalloc.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
684 #include "readwrite.h"
685 #include "auto_qmail.h"
687 +#include "ipalloc.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];
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
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"
707 #include "auto_qmail.h"
710 #include "datetime.h"
712 +#include "ipalloc.h"
715 void die(n) int n; { substdio_flush(subfdout); _exit(n); }
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];
731 - struct ip_address ip;
739 if (r == -1) die_read();
741 + r /= sizeof(tcpto_buf[0]);
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));
762 + substdio_put(subfdout,tmp,ip_fmt(tmp,&tcpto_buf[i].addr.ip));
764 + substdio_put(subfdout,tmp,ip6_fmt(tmp,&tcpto_buf[i].addr.ip6));
766 + substdio_put(subfdout,tmp,ip_fmt(tmp,&tcpto_buf[i].addr.ip));
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");
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
783 return timeoutread(t,fd,buf,len);
786 -char *remoteinfo_get(ipr,rp,ipl,lp,timeout)
787 -struct ip_address *ipr;
789 -struct ip_address *ipl;
792 + struct sockaddr sa;
793 + struct sockaddr_in sa4;
795 + struct sockaddr_in6 sa6;
799 +char *remoteinfo_get(saremote, salocal, timeout)
800 +union sockunion *saremote, *salocal;
805 - struct sockaddr_in sin;
806 + union sockunion sa;
810 + unsigned int len, rp, lp;
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) {
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; }
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; }
850 - byte_zero(&sin,sizeof(sin));
851 - sin.sin_family = AF_INET;
852 - byte_copy(&sin.sin_addr,4,ipl);
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);
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
863 #include <sys/socket.h>
864 #include <sys/param.h>
865 #include <netinet/in.h>
868 #include "stralloc.h"
871 #include "remoteinfo.h"
874 +#include "hassalen.h"
876 void die() { _exit(111); }
878 -struct sockaddr_in salocal;
880 + struct sockaddr sa;
881 + struct sockaddr_in sa4;
883 + struct sockaddr_in6 sa6;
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;
914 + sin.sin_len = sizeof(sin);
916 + memcpy(&sa->sa4, &sin, sizeof(sin));
921 +#define mappedtov4(A)
929 unsigned long timeout;
930 + struct sockaddr_in *v4;
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) {
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)) {
957 if (!stralloc_copys(&localname,"softdnserror")) die();
960 if (!env_unset("TCPLOCALHOST")) die();
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();
973 + if (!stralloc_copys(&localname,"softdnserror")) die();
975 + if (!stralloc_0(&localname)) die();
976 + case_lowers(localname.s);
977 + if (!env_put2("TCPLOCALHOST",localname.s)) die();
980 + if (!env_unset("TCPLOCALHOST")) 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) {
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();
1009 + if (!stralloc_copys(&remotename,"softdnserror")) die();
1011 + if (!stralloc_0(&remotename)) die();
1012 + case_lowers(remotename.s);
1013 + if (!env_put2("TCPREMOTEHOST",remotename.s)) die();
1016 + if (!env_unset("TCPREMOTEHOST")) die();
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();
1029 if (!stralloc_copys(&remotename,"softdnserror")) die();
1030 @@ -112,12 +187,18 @@
1032 if (!env_unset("TCPREMOTEHOST")) die();
1040 if (!env_unset("TCPREMOTEINFO")) die();
1045 - rinfo = remoteinfo_get(&ipremote,remoteport,&iplocal,localport,(int) timeout);
1046 + rinfo = remoteinfo_get(&saremote, &salocal,(int) timeout);
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
1054 +#include <sys/types.h>
1055 +#include <sys/uio.h>
1056 +#include <sys/socket.h>
1057 +#include <unistd.h>
1058 +#include "ipalloc.h"
1065 +#include "ipalloc.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;
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));
1082 if (r < 0) { close(fdlock); return 0; }
1084 + r /= sizeof(tcpto_buf[0]);
1085 if (!r) close(fdlock);
1089 -int tcpto(ip) struct ip_address *ip;
1103 - record = tcpto_buf;
1104 for (i = 0;i < n;++i)
1106 - if (byte_equal(ip->d,4,record))
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)))
1110 + if (byte_equal(&ix->addr.ip, sizeof(ix->addr.ip), &tcpto_buf[i].addr.ip))
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))
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;
1141 - datetime_sec firstwhen;
1143 + datetime_sec firstwhen=0;
1145 datetime_sec lastwhen;
1152 - record = tcpto_buf;
1153 for (i = 0;i < n;++i)
1155 - if (byte_equal(ip->d,4,record))
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)))
1159 + if (byte_equal(&ix->addr.ip, sizeof(ix->addr.ip), &tcpto_buf[i].addr.ip))
1164 + tcpto_buf[i].flag = 0;
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;
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]))
1196 if (!flagerr) { close(fdlock); return; }
1198 - record = tcpto_buf;
1199 for (i = 0;i < n;++i)
1201 - if (!record[4]) break;
1204 + if (tcpto_buf[i].flag == 0) break;
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))
1231 - record = tcpto_buf + (i << 4);
1232 - byte_copy(record,4,ip->d);
1234 - record[8] = when; when >>= 8;
1235 - record[9] = when; when >>= 8;
1236 - record[10] = when; when >>= 8;
1237 - record[11] = when;
1239 - if (seek_set(fdlock,i << 4) == 0)
1240 - if (write(fdlock,record,16) < 16)
1241 + tcpto_buf[i].af = ix->af;
1243 + if (ix->af == AF_INET6)
1244 + byte_copy(&tcpto_buf[i].addr.ip6, 16, &ix->addr.ip6);
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]))
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
1262 -extern int tcpto();
1263 -extern void tcpto_err();
1264 -extern void tcpto_clean();
1265 +#define TCPTO_BUFSIZ 64
1269 + unsigned char flag;
1270 + unsigned long when;
1272 + struct ip_address ip;
1274 + struct ip6_address ip6;
1276 + unsigned char dummy[16];
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);
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
1289 +#include "ipalloc.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
1304 errno = error_timeout; /* note that connect attempt is continuing */
1309 +int timeoutconn6(s,ip,port,timeout)
1311 +struct ip6_address *ip;
1316 + struct sockaddr_in6 sin;
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) {
1334 + if ((errno != error_inprogress) && (errno != error_wouldblock)) return -1;
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)) {
1343 + dummy = sizeof(sin);
1344 + if (getpeername(s,(struct sockaddr *) &sin,&dummy) == -1) {
1352 + errno = error_timeout; /* note that connect attempt is continuing */
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
1360 #define TIMEOUTCONN_H
1362 extern int timeoutconn();
1363 +extern int timeoutconn6();