Commit Graph

279 Commits

Author SHA1 Message Date
Alexander Barton d7ad956a06 Fix connect attempts to further IP addresses of outgoing server links
If a hostname resolves to more than one IP address (round-robin DNS,
IPv4 and IPv6) and an attempt to connect to the first address fails,
ngIRCd should try to connect to the 2nd address, 3rd address etc.

But because of a wrong variable used in the call to New_Server(),
the wrong server structure has been used in further connection attemps
which possibly lead to connection attempts to already connected servers.
2010-10-27 21:59:51 +02:00
Alexander Barton 596bc096b0 Make sourcecode compatible with ansi2knr again
This allows to compile ngIRCd using a pre-ANSI K&R C compiler again:
all source files are automatically converted by the included ansi2knr
program (of GNU automake/autoconf) before compiling them with the
K&R C compiler, but a few coding standards must be met.

Tested on Apple A/UX 3.x.
Regression testing on Linux and Mac OS X.
2010-10-24 21:48:32 +02:00
Alexander Barton 3600dc60fc Output connection status when dumping the internal server state 2010-09-14 00:05:31 +02:00
Florian Westphal ef3dbf96eb remove NGIRCd_SignalRehash
now that the main signal handling is done from the dispatcher
loop we can call NGIRCD_Rehash() directly.

the /REHASH handler can queue the Rehash() function for
execution by sending a SIGHUP.  It will be run when we
return back to the dispatch loop.
2010-09-11 11:36:12 +02:00
Florian Westphal 1fe17e246c Add new 'delayed' signal handlers.
Allows to defer/queue signal processing for execution on the next
event dispatch call, i.e. we can perform any signal action in
normal, non-signal context.

Example uses:
- Reload everything on HUP without writing a global "SIGHUP_received"
  variable
- Dump status of internal Lists on SIGUSR1, etc.
2010-09-11 11:36:12 +02:00
Alexander Barton 6349ec8bb3 Conn_SyncServerStruct(): test all connections; and work case insensitive
Fix synchronization of established connections and configured server
structures after a configuration update:

 - Not only test servers that already have a connection, but also check
   and update configured servers to which a new connection is beeing
   established (SERVER_WAIT state).

 - And do the server name comparision case-insensitive.
2010-09-08 02:02:01 +02:00
Alexander Barton 8d68fe3f86 Check_Servers(): skip servers already beeing connected
Let CheckServers() not only skip servers that already have a
connection, but also skip servers to which a new connection is
already beeing established (SERVER_WAIT state).
2010-09-08 00:45:23 +02:00
Alexander Barton 4f6c19712e Check_Servers(): Code cleanup 2010-09-08 00:42:57 +02:00
Alexander Barton 04e38f17ae Don't reset My_Connections[Idx].lastping when reading data
This fixes PING-PONG lag calculation (which resulted in "0" before).

The "lastping" time is still reset it if a time shift backwards has
been detected to prevent the daemon from miscalculating ping timeouts.
2010-08-19 15:58:55 +02:00
Alexander Barton 6ebb31ab35 Remove Proc_Kill(), use timeout to kill child processes
This avoids a race and potentionally killing the wrong process on
systems that use randomized process IDs; now the child itself is
responsible to exit in a timely manner using SIGALRM.
2010-07-14 10:29:05 +02:00
Alexander Barton cf93881dfb New function Conn_CloseAllSockets() to close all open sockets
This is useful in forked child processes, for example, to make sure that
they don't hold connections open that the main process wants to close.
2010-07-14 10:27:55 +02:00
Alexander Barton 79be1c477e Refactor Resolve_Read() into generic Proc_Read() function 2010-07-11 16:58:30 +02:00
Alexander Barton bf8b646304 New function Conn_GetProcStat()
Get PROC_STAT sub-process structure of a given connection.
2010-07-11 15:15:23 +02:00
Alexander Barton e4ffcd00bd Code cleanup: don't reset penalty time on DNS resolver result
See commit d4632a727fbee6: it's not necessary any more!
2010-07-11 15:12:17 +02:00
Alexander Barton 3d49fa5bff New function Conn_GetFromProc() to get CONN_ID of a subprocess
Get CONN_ID from file descriptor associated to a subprocess structure.
2010-06-29 23:38:39 +02:00
Alexander Barton d4632a727f Don't set a penalty time when doing DNS lookups
The logic isn't as described in the source and intended by this code:
ngIRCd doesn't wait for the asynchronous resolver process until the set
penalty time is over, but until the forked process terminates or the
initial connection timeout (= PongTimeout) triggers.

So don't set the penalty time at all and remove the wrong comment.
2010-06-29 22:55:27 +02:00
Alexander Barton 60f5dd5b29 Update comments: subprocesses not only can be resolver processes 2010-06-29 22:55:27 +02:00
Alexander Barton 89e73ad4b4 Refactoring: Rename CONNECTION.res_stat to .proc_stat
We want to use this process status variable not only for the
resolver subprocesses but other asynchronous tasks as well;
so let's name it more generic.
2010-06-29 22:55:27 +02:00
Alexander Barton 54e67ea9ee New "module" proc.c/proc.h for generic process handling
The new "module" proc.c is used for functions dealing with child
processes. At the moment, it is only used by the asynchronous resolver.

All the functions already implemented habe been migrated from the
resolver code base, and the rest of the ngIRCd source code has been
adepted to the new namespace and calling conventions.

The goal is to develop "generic" process handling functions that can
be used for other purposes as well, e.g. running processes on client
connects etc.
2010-06-29 22:55:27 +02:00
Alexander Barton edfa215481 const'ify Conn_WriteStr() function 2010-06-26 00:44:37 +02:00
Florian Westphal df359835d1 SSL/TLS: fix bogus 'socket closed' error message
When we get there then the ssl handshake has failed, or
we could not create a ssl context because ssl library
initialization failed on startup.

Reflect that in the log message.
2010-05-07 23:25:59 +02:00
Alexander Barton 73fd26e9fa Don't reset counters on RESTART
When ngIRCd restarts, all the connection counters are preserved now,
as well as the command counters for example.

It's unclear if resetting or not resetting is the "correct" behaviour,
but it's quite clear that the behaviour should be consistent for all the
counters ngIRCd uses ...

And initializing "WCounter", the global but temporary write counter,
is not necessarry at all: it is initialized (reset) before its use in
the command parser (see parse.c).
2010-04-25 12:54:13 +02:00
Alexander Barton 1338ade650 Enhace connection statistics counters
This patch enables ngIRCd to count the highest maximum simultaneous
connections and all the connections accepted since startup.

New functions:
- Conn_Count(): get current connections
- Conn_CountMax(): maximum simultaneous connections
- Conn_CountAccepted(): number of connections accepted
2010-04-23 23:25:34 +02:00
Alexander Barton 21140500f1 Conn_Init: code cleanup 2010-04-23 22:23:51 +02:00
Alexander Barton b042363e88 Only include <netinet/in_systm.h> if it exists 2010-04-23 11:04:15 +02:00
Alexander Barton 1caa3fb94b Include netinet/in_systm.h alongside netinet/ip.h
This fixes the following error when compiling on e.g. FreeBSD 6.x:

In file included from conn.c:40:
/usr/include/netinet/ip.h:160: error: syntax error before "n_long"
/usr/include/netinet/ip.h:163: error: syntax error before "n_long"
2010-04-11 16:58:29 +00:00
Alexander Barton 025342fe46 Fix gcc warning "ignoring return value of ..."
This patch fixes two warnings of gcc 4.4.3 when used with eglibc 2.11.1:

ngircd.c: In function ‘NGIRCd_Init’:
ngircd.c:801: warning: ignoring return value of ‘chdir’, declared with
 attribute warn_unused_result
conn.c: In function ‘Simple_Message’:
conn.c:2041: warning: ignoring return value of ‘write’, declared with
 attribute warn_unused_result

The first by checking the return code and an appropriate error message,
the second by "better" ignoring it (which is correct there!) ...
2010-04-09 20:14:11 +02:00
Alexander Barton 6e8cf51bb2 Implement WEBIRC command
The WEBIRC command is used by some Web-to-IRC gateways to set the correct
user name and host name of users instead of their own.

Syntax: WEBIRC <password> <username> <hostname> <ip-address>

The <password> must be set using the new configuration variable "WebircPassword" in the [Global] section of ngircd.conf.

Please note that the <ip-address> is currently not used by ngIRCd (we don't store it in the CLIENT structure, only the resolved hostname).
2010-02-11 00:01:53 +01:00
Alexander Barton a4d7c6f145 setsockopt(): use IPPROTO_IP instead of SOL_IP to set IPTOS_LOWDELAY 2009-12-31 00:57:02 +01:00
Alexander Barton 1b73e68e6e Move NewConnection handling from callbacks to New_Connection() 2009-12-30 23:42:43 +01:00
Alexander Barton 03cde2efd3 Connection functions: add some more documentation comments 2009-12-30 23:35:17 +01:00
Alexander Barton cb6faed61c Clean up conn.{c|h} a little bit 2009-12-30 23:32:47 +01:00
Alexander Barton 536538968c Fix cb_connserver() to handle aborted outgoing connections
A configured server could have been removed while a connection apptempt
is still in progress. So the cb_connserver() callback has to test if the
server configuration record is still valid.
2009-09-12 00:17:42 +02:00
Florian Westphal 4daf780f01 conn.c: fix more sizeof(..dst_addr) misuse
the wrong sizeof() usage fixed in
d76910ce7b
(conn.c: fix resolver server address backlog) was a bit more
widespread, fix all others, too.
2009-09-11 23:31:46 +02:00
Florian Westphal d76910ce7b conn.c: fix resolver server address backlog
if more than one ip address is returned for a single host
name, ngircd is supposed to try other addresses in case
connect() to the first address returned fails for some
reason.

Alexander Barton noticed that this did not work at all,
as the additional results were not stored.
2009-09-11 22:55:32 +02:00
Alexander Barton 8fd0e29d46 Fix "implicit conversion shortens 64-bit value" warning
This patch fixes the following gcc warning in our sources:
"implicit conversion shortens 64-bit value into a 32-bit value"
2009-09-11 22:52:12 +02:00
Alexander Barton e1598e2670 Conn_Close(): remove unused variable "txt" 2009-09-10 11:49:39 +02:00
Florian Westphal 0ef94edad7 add section and rfc number to comment about QUIT error 2009-06-05 01:39:33 +02:00
Florian Westphal 643ae1b48b enforce upper limit on maximum number of handled commands
reported on #ngircd: pasting lots of lines into a channel can kill off
many people on the channel if the read buffer is drained quickly enough
and the client-side TCP can't keep up with the incoming data.

This implements a throttling scheme:
- an irc client may send up to 3 commands per second before a one second
pause is enforced.
- an irc client may send up to 256 bytes per second before a one second
pause is enforced.

After discussion with Alexander Barton, server <-> server links are
treated specially: There is no artificial limit on the number of bytes
sent per second, and up to 10 commands are processed per second before
a pause is enforced.

It may be neccessary to make those limits tuneable to accomondate larger
networks, but for now they are compile time values.
2009-05-25 22:25:18 +02:00
Florian Westphal 9b1c47220f conn.c: fix NumConnections imbalance
New_Server() can call Conn_Close() in its error paths,
but that function decrements the number of current active
connections. Thus we need to increment it earlier.
2009-05-17 21:32:53 +02:00
Florian Westphal 8e2c5816ee SSL/TLS: fix error handling when ssl ctx init for outgoing server link fails 2009-05-17 21:27:27 +02:00
Florian Westphal 627b0b713c security: fix remotely triggerable crash in SSL/TLS code
When a server is running with SSL/TLS support compiled in,
it is trivial to crash the server by sending an MOTD request
via another server in the network.

- ONLY servers without ssl/tls support compiled in are not affected.
  Disabling SSL in the configuration (no ssl listening ports, etc)
  does NOT help.
- servers that are running standalone (i.e., not connected to any
  other servers) are not affected, either.

This affects all ngircd releases since ngircd 13 (earlier versions
have no SSL/TLS support).
2009-05-05 10:21:20 +02:00
David Kingston 9b59f043c8 allow ping timeout quit messages to show the timeout value 2009-04-23 21:39:45 +02:00
Florian Westphal 544b9884f4 remove or translate old comments 2009-04-21 20:58:30 +02:00
Florian Westphal ea041b8838 add const qualifier to pointers where possible 2009-04-21 20:58:23 +02:00
Alexander Barton 54879b432b Display IPv6 addresses as "[<addr>]" when accepting connections.
With this patch ngIRCd displays IPv6 addresses as "[<addr>]:<port>" when
accepting new connections and later, if no successful DNS lookup could
be made (or DNS is disabled altogether).
2009-04-10 13:22:03 +02:00
Alexander Barton 2eb564ccaa Change formatting of some log messages
- Fix formatting of some log messages, mostly punctuation.
- cb_Connect_to_Server(): don't use string concatenation, because it
  is not supported by pre-ANSI C compilers ...
2008-11-20 23:50:26 +01:00
Alexander Barton 4c113d8850 New configuration option "NoIdent" to disable IDENT lookups
The new configuration option "NoIdent" in ngircd.conf can be used to
disable IDENT lookups even when the ngIRCd daemon is compiled with IDENT
lookups enabled.
2008-11-19 19:11:39 +01:00
Alexander Barton 9f067a059d Connection counter: count outgoing connections as well.
This patch lets ngIRCd count outgoing connections as well as incoming
connections (up to now only outgoing connections have been counted). This
change is required because the Conn_Close() function doesn't know whether
it closes an outgoing connection or not and therefore would decrement the
counter below zero when an outgoing connection existed -- which would
trigger an assert() call ...

Please note that this patch changes the (so far undocumented but now fixed)
behaviour of the "MaxConnections" configuration option to account the sum
of the in- and outbound connections!
2008-11-12 01:26:04 +01:00
Florian Westphal ef3327d372 TLS/SSL support: code changes.
This adds the required code to enable ssl/tls support
during compile and run time, respectively.
2008-09-13 15:10:32 +02:00