From 38a230bb609bfee1103ccb21111171dd56b96b6f Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 1 Apr 2011 21:56:20 +0200 Subject: [PATCH] Switch handling to have a pointer to the target address - change URL struct to contain sockaddr_in6 - change URL-Parsing to add that indirection - change all pointer indirections so the new way fits --- citadel/event_client.c | 4 +-- citadel/event_client.h | 2 +- citadel/modules/smtp/serv_smtpeventclient.c | 39 +++++++++++---------- citadel/modules/smtp/serv_smtpqueue.c | 5 ++- libcitadel/lib/libcitadel.h | 2 +- libcitadel/lib/urlhandling.c | 2 +- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/citadel/event_client.c b/citadel/event_client.c index 4a20ba1ba..dd0fa7c97 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -396,9 +396,9 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r IO->rw_timeout.data = IO; if (IO->IP6) - rc = connect(IO->sock, &IO->Addr, sizeof(struct sockaddr_in6)); + rc = connect(IO->sock, IO->Addr, sizeof(struct sockaddr_in6)); else - rc = connect(IO->sock, (struct sockaddr_in *)&IO->Addr, sizeof(struct sockaddr_in)); + rc = connect(IO->sock, (struct sockaddr_in *)IO->Addr, sizeof(struct sockaddr_in)); if (rc >= 0){ //// freeaddrinfo(res); diff --git a/citadel/event_client.h b/citadel/event_client.h index e98a13a8d..4bd86bd9f 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -42,7 +42,7 @@ struct AsyncIO { /* connection related */ int IP6; - struct sockaddr_in6 Addr; + struct sockaddr_in6 *Addr; int sock; unsigned short dport; diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 2e1dcbbed..7b5ced26f 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -180,10 +180,10 @@ void SetConnectStatus(AsyncIO *IO) buf[0] = '\0'; if (IO->IP6) { - src = &IO->Addr.sin6_addr; + src = &IO->Addr->sin6_addr; } else { - struct sockaddr_in *addr = (struct sockaddr_in *)&IO->Addr; + struct sockaddr_in *addr = (struct sockaddr_in *)IO->Addr; src = &addr->sin_addr.s_addr; } @@ -214,7 +214,7 @@ void SetConnectStatus(AsyncIO *IO) *****************************************************************************/ eNextState mx_connect_relay_ip(AsyncIO *IO) { - + /* SmtpOutMsg *SendMsg = IO->Data; CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__); @@ -235,7 +235,7 @@ eNextState mx_connect_relay_ip(AsyncIO *IO) } else { struct sockaddr_in *addr = (struct sockaddr_in*) &IO->Addr; - /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */ + /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); * / memcpy(&addr->sin_addr,///.s_addr, &SendMsg->pCurrRelay->Addr, sizeof(struct in_addr)); @@ -250,6 +250,7 @@ eNextState mx_connect_relay_ip(AsyncIO *IO) SMTP_C_ConnTimeout, SMTP_C_ReadTimeouts[0], 1); + */ } eNextState get_one_mx_host_ip_done(AsyncIO *IO) @@ -263,20 +264,24 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO) if ((SendMsg->HostLookup.DNSStatus == ARES_SUCCESS) && (hostent != NULL) ) { - IO->IP6 = hostent->h_addrtype == AF_INET6; +/// IO->IP6 = hostent->h_addrtype == AF_INET6; ////IO->HEnt = hostent; + +/// SendMsg->pCurrRelay->Addr + + - memset(&IO->Addr, 0, sizeof(struct in6_addr)); + memset(&SendMsg->pCurrRelay->Addr, 0, sizeof(struct in6_addr)); if (IO->IP6) { - memcpy(&IO->Addr.sin6_addr.s6_addr, + memcpy(&SendMsg->pCurrRelay->Addr.sin6_addr.s6_addr, &hostent->h_addr_list[0], sizeof(struct in6_addr)); - IO->Addr.sin6_family = hostent->h_addrtype; - IO->Addr.sin6_port = htons(IO->dport); + SendMsg->pCurrRelay->Addr.sin6_family = hostent->h_addrtype; + SendMsg->pCurrRelay->Addr.sin6_port = htons(IO->dport); } else { - struct sockaddr_in *addr = (struct sockaddr_in*) &IO->Addr; + struct sockaddr_in *addr = (struct sockaddr_in*) &SendMsg->pCurrRelay->Addr; /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */ // addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]); memcpy(&addr->sin_addr.s_addr, @@ -288,6 +293,7 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO) } ////SendMsg->IO.HEnt = hostent; + SendMsg->IO.Addr = &SendMsg->pCurrRelay->Addr; SetConnectStatus(IO); return InitEventIO(IO, SendMsg, @@ -324,19 +330,16 @@ eNextState get_one_mx_host_ip(AsyncIO *IO) InitC_ares_dns(IO); - if (SendMsg->mx_host != NULL) Hostname = SendMsg->mx_host; - else Hostname = SendMsg->node; - CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__); CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: looking up %s : %d ...\n", SendMsg->n, - Hostname, + SendMsg->pCurrRelay->Host, SendMsg->IO.dport); -// TODO: ns_t_aaaa - if (!QueueQuery(ns_t_a, - Hostname, + + if (!QueueQuery((SendMsg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a, + SendMsg->pCurrRelay->Host, &SendMsg->IO, &SendMsg->HostLookup, get_one_mx_host_ip_done)) @@ -361,6 +364,7 @@ eNextState smtp_resolve_mx_record_done(AsyncIO *IO) QueryCbDone(IO); CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__); + SendMsg->pCurrRelay = SendMsg->Relay; pp = &SendMsg->Relay; while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL)) pp = &(*pp)->Next; @@ -370,7 +374,6 @@ eNextState smtp_resolve_mx_record_done(AsyncIO *IO) { /* ok, we found mx records. */ SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage; - SendMsg->CurrMX = SendMsg->AllMX = IO->DNSQuery->VParsedDNSReply; while (SendMsg->CurrMX) { diff --git a/citadel/modules/smtp/serv_smtpqueue.c b/citadel/modules/smtp/serv_smtpqueue.c index 65cde8f15..5979d6fc5 100644 --- a/citadel/modules/smtp/serv_smtpqueue.c +++ b/citadel/modules/smtp/serv_smtpqueue.c @@ -695,8 +695,11 @@ void smtp_do_procmsg(long msgnum, void *userdata) { StrBufExtract_NextToken(One, All, &Pos, '|'); if (!ParseURL(Url, One, 25)) CtdlLogPrintf(CTDL_DEBUG, "Failed to parse: %s\n", ChrPtr(One)); - else + else { + ///if (!Url->IsIP)) /// todo dupe me fork ipv6 Url = &(*Url)->Next; + + } } FreeStrBuf(&All); FreeStrBuf(&One); diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index b16e3296c..1201a9be7 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -368,7 +368,7 @@ struct ParsedURL { int IPv6; int af; struct hostent *HEnt; - struct in6_addr Addr; + struct sockaddr_in6 Addr; ParsedURL *Next; }; diff --git a/libcitadel/lib/urlhandling.c b/libcitadel/lib/urlhandling.c index a8856fafd..6f7ebb58c 100644 --- a/libcitadel/lib/urlhandling.c +++ b/libcitadel/lib/urlhandling.c @@ -105,7 +105,7 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort) } if (pPort != NULL) url->Port = atol(pPort); - url->IsIP = inet_pton(url->af, url->Host, &url->Addr); + url->IsIP = inet_pton(url->af, url->Host, &url->Addr.sin6_addr); *Url = url; return 1; } -- 2.30.2