case 0: LogDebug("ConnSSL_Connect: not ready");
return;
case -1:
- Log(LOG_INFO, "SSL connection on socket %d failed", sock);
+ Log(LOG_ERR, "SSL connection on socket %d failed!", sock);
Conn_Close(idx, "Can't connect!", NULL, false);
return;
}
- Log( LOG_INFO, "SSL Connection %d with \"%s:%d\" established.", idx,
+ Log( LOG_INFO, "SSL connection %d with \"%s:%d\" established.", idx,
My_Connections[idx].host, Conf_Server[Conf_GetServer( idx )].port );
server_login(idx);
GLOBAL void
Conn_Init( void )
{
- /* Modul initialisieren: statische Strukturen "ausnullen". */
-
CONN_ID i;
/* Speicher fuer Verbindungs-Pool anfordern */
GLOBAL void
Conn_Exit( void )
{
- /* Modul abmelden: alle noch offenen Connections
- * schliessen und freigeben. */
-
CONN_ID idx;
- LogDebug("Shutting down all connections ..." );
-
Conn_ExitListeners();
- /* Sockets schliessen */
+ LogDebug("Shutting down all connections ..." );
for( idx = 0; idx < Pool_Size; idx++ ) {
if( My_Connections[idx].sock > NONE ) {
Conn_Close( idx, NULL, NGIRCd_SignalRestart ?
#endif
arraylen = array_length(&My_Listeners, sizeof (int));
- Log( LOG_INFO, "Shutting down all listening sockets (%d total)...", arraylen );
+ Log(LOG_INFO,
+ "Shutting down all listening sockets (%d total) ...", arraylen);
fd = array_start(&My_Listeners);
while(arraylen--) {
assert(fd != NULL);
GLOBAL void
-Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
+Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient )
{
/* Close connection. Open pipes of asyncronous resolver
* sub-processes are closed down. */
CLIENT *c;
- char *txt;
+ const char *txt;
double in_k, out_k;
UINT16 port;
#ifdef ZLIB
c = Conn_GetClient( Idx );
#ifdef SSL_SUPPORT
if ( Conn_OPTION_ISSET( &My_Connections[Idx], CONN_SSL )) {
- Log( LOG_INFO, "SSL Connection %d shutting down", Idx );
+ Log(LOG_INFO, "SSL connection %d shutting down ...", Idx);
ConnSSL_Free(&My_Connections[Idx]);
}
#endif
#endif
ng_ipaddr_t new_addr;
char ip_str[NG_INET_ADDRSTRLEN];
- int new_sock, new_sock_len;
+ int new_sock, new_sock_len, identsock;
CLIENT *c;
long cnt;
My_Connections[new_sock].addr = new_addr;
My_Connections[new_sock].client = c;
- Log( LOG_INFO, "Accepted connection %d from %s:%d on socket %d.", new_sock,
- ip_str, ng_ipaddr_getport(&new_addr), Sock);
-
- /* Hostnamen ermitteln */
- strlcpy(My_Connections[new_sock].host, ip_str, sizeof(My_Connections[new_sock].host));
+ /* Set initial hostname to IP address. This becomes overwritten when
+ * the DNS lookup is enabled and succeeds, but is used otherwise. */
+ if (ng_ipaddr_af(&new_addr) != AF_INET)
+ snprintf(My_Connections[new_sock].host,
+ sizeof(My_Connections[new_sock].host), "[%s]", ip_str);
+ else
+ strlcpy(My_Connections[new_sock].host, ip_str,
+ sizeof(My_Connections[new_sock].host));
Client_SetHostname(c, My_Connections[new_sock].host);
+ Log(LOG_INFO, "Accepted connection %d from %s:%d on socket %d.",
+ new_sock, My_Connections[new_sock].host,
+ ng_ipaddr_getport(&new_addr), Sock);
+
+ identsock = new_sock;
+#ifdef IDENTAUTH
+ if (Conf_NoIdent)
+ identsock = -1;
+#endif
if (!Conf_NoDNS)
Resolve_Addr(&My_Connections[new_sock].res_stat, &new_addr,
- My_Connections[new_sock].sock, cb_Read_Resolver_Result);
-
+ identsock, cb_Read_Resolver_Result);
Conn_SetPenalty(new_sock, 4);
return new_sock;
} /* New_Connection */
static CONN_ID
Socket2Index( int Sock )
{
- /* zum Socket passende Connection suchen */
-
assert( Sock >= 0 );
if( Sock >= Pool_Size || My_Connections[Sock].sock != Sock ) {
- /* die Connection wurde vermutlich (wegen eines
- * Fehlers) bereits wieder abgebaut ... */
+ /* the Connection was already closed again, likely due to
+ * an error. */
LogDebug("Socket2Index: can't get connection for socket %d!", Sock);
return NONE;
}
* if this doesn't help either, disconnect client. */
CLIENT *c;
CONN_ID i;
+ char msg[64];
for (i = 0; i < Pool_Size; i++) {
if (My_Connections[i].sock < 0)
LogDebug
("Connection %d: Ping timeout: %d seconds.",
i, Conf_PongTimeout);
- Conn_Close(i, NULL, "Ping timeout",
- true);
+ snprintf(msg, sizeof(msg), "Ping timeout: %d seconds", Conf_PongTimeout);
+ Conn_Close(i, NULL, msg, true);
}
} else if (My_Connections[i].lastdata <
time(NULL) - Conf_PingTimeout) {
len -= sizeof(ng_ipaddr_t);
if (len > sizeof(&Conf_Server[i].dst_addr)) {
len = sizeof(&Conf_Server[i].dst_addr);
- Log(LOG_NOTICE, "Notice: Resolver returned more IP Addresses for host than we can handle,"
- " additional addresses dropped");
+ Log(LOG_NOTICE,
+ "Notice: Resolver returned more IP Addresses for host than we can handle, additional addresses dropped.");
}
memcpy(&Conf_Server[i].dst_addr, &dest_addrs[1], len);
}
GLOBAL bool
Conn_GetCipherInfo(CONN_ID Idx, char *buf, size_t len)
{
+ if (Idx < 0)
+ return false;
+ assert(Idx < (int) array_length(&My_ConnArray, sizeof(CONNECTION)));
return ConnSSL_GetCipherInfo(&My_Connections[Idx], buf, len);
}
GLOBAL bool
Conn_UsesSSL(CONN_ID Idx)
{
+ if (Idx < 0)
+ return false;
+ assert(Idx < (int) array_length(&My_ConnArray, sizeof(CONNECTION)));
return Conn_OPTION_ISSET(&My_Connections[Idx], CONN_SSL);
}
#endif