1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-26 02:46:37 +02:00
Commit Graph

105 Commits

Author SHA1 Message Date
Bram Matthys fd7a715e17 Don't use slow socket closing (w/TLS handshake) for (G)ZLINE.
The whole point of (G)ZLINEs is that it rejects instantly upon
accept, that's what makes them different from KLINE/GLINE.

Commit 89075e532a made it
accidentally use the slow path for this as well.
2023-06-07 15:14:00 +02:00
Bram Matthys 7820676616 SetDeadSocket() in close_connection()
to avoid a crash in todays code which was like:
1) exit_client gets called
2) close_connection() sets client->direction to NULL
3) a bit further it calls remove_dependents()
4) a sendto is attempted and the new code accesses
   client->direction which is unexpected to be NULL

Actually i should probably trace the cause of the sendto_one()
but that is another story ;)
2023-05-28 18:13:34 +02:00
Bram Matthys a7cf24c45d Mention new https://www.unrealircd.org/docs/Proxy_block in release notes
and also for safety when redoing DNS and ident due to IP change,
we now:
ClearIdentLookupSent(client);
ClearIdentLookup(client);
ClearDNSLookup(client);
2023-05-26 14:26:26 +02:00
Bram Matthys c2d465c5dd Move chunk of code from start_of_normal_client_handshake() to
a function called start_dns_and_ident_lookup(). This can then
be easily called from other places as well, like the code k4be
did in src/modules/websocket.c to handle proxies.

Side-effect is that ident lookups would now be done, if we are
configured to do so, for forwarded webirc stuff (not that I
think many people use that feature at the moment...).
2023-05-26 11:24:01 +02:00
Bram Matthys f2015ad865 Fix crash when removing a listen { } block with websocket or rpc
(or changing the port number). Reported by Nini.

Rather complex case: when the listen block is removed, obviously
the config hooks are not called for the (now non-existing) listen
block, and thus the websocket->request_handler and such are not
set to the new address of the websocket handler.
We now use a slightly silly workaround / new hook to fix this
corner case. Ideally there would be an extra layer in-between
like a handler lookup by name, or something like that.
(Or make the websocket module PERM but we don't want that!)
2023-05-19 19:29:46 +02:00
Bram Matthys f804c5ed65 Add detection and set the high connect rate to 1000 per seconds.
https://www.unrealircd.org/docs/FAQ#hi-conn-rate
This finishes https://bugs.unrealircd.org/view.php?id=5532
2023-05-18 13:15:17 +02:00
Bram Matthys 9b9434e442 Delay throttling check until IP is resolved or failed to resolve.
This so you can use throttling exceptions (eg in ELINE) on hostnames.

That is, the above is during normal circumstances. Similar to previous
commit we will turn this feature of during high connection rates.
That is a TODO item.
2023-05-18 11:51:22 +02:00
Bram Matthys 89075e532a Send throttling and some other error messages to SSL/TLS users (encrypted).
This is the start of "be more friendly to TLS users with disconnect
error messages" from https://bugs.unrealircd.org/view.php?id=5532

As that bug explains:
Consider doing the SSL/TLS handshake even for throttling errors and such
when the (reject) connection rate is below a certain amount per second.  If
it is higher than a certain rate, then fall back to the original behavior to
reject the user instantly without handshake or looking at any data.
Rationale: the current/original behavior is there so the ircd can handle
floods, both in terms of traffic and in terms of CPU usage (the SSL/TLS
handshake is quite costly after all).  The downside of the current behavior
is that TLS users don't see the error message, usually.  This feature
request tries to find a middle ground.

Still a TODO item:
* We don't detect high rates yet, so we only do this new behavior atm
  and not yet the old behavior during high connection rates.
* Verify that error messages/behavior hasn't changed (too) much,
  like the throttling and the banning disconnect messages.
2023-05-18 11:17:37 +02:00
Bram Matthys 8cabbcb59b DNS: add negative caching of unresolved hosts (60 seconds)
Mostly to avoid repeated lookups for like clients that reconnect rapidly.
2023-05-06 10:34:26 +02:00
Bram Matthys 4b448f2aaa New option listen::spoof-ip, only valid when using UNIX domain sockets
(so listen::file). This way you can override the IP address that users come
online with when they use the socket (default was and still is `127.0.0.1`).

Add a new guide https://www.unrealircd.org/docs/Running_Tor_hidden_service_with_UnrealIRCd
which uses the new listen::spoof-ip and optionally requires a services account.
2023-04-15 10:37:30 +02:00
Bram Matthys 57c90496e8 JSON-RPC: add rpc.add_timer and rpc.del_timer so you can run a command
every <xyz> msec (minimum: 250).
Can be useful to schedule an rpc.stats call every 1000msec for instance.
Of course timers are destroyed if the client exits.

https://www.unrealircd.org/docs/JSON-RPC:Rpc#rpc.add_timer and
https://www.unrealircd.org/docs/JSON-RPC:Rpc#rpc.del_timer
2023-04-12 10:22:33 +02:00
Bram Matthys 3d8905dd1c Fix "unknown connection(s)" in LUSERS being rather high.
This was a counting bug in src/socket.c. The socket itself was actually
freed though, so it's purely counting that was wrong.

There could still be counting bugs elsewhere, it's always hard to get
this right, for 20 years already :D
2023-03-22 09:31:26 +01:00
Bram Matthys 497a19e7e2 Accept more connections in each listener run. 2023-01-14 20:49:12 +01:00
Bram Matthys d6a3db4ad2 Add listener::mode so for file sockets you can specify the mode permissions.
Valid choices are 0700, 0770 and 0777, see the documentation at
https://www.unrealircd.org/docs/Listen_block

Unrelated: this also documents the ConfigItem_listen struct in struct.h.
2023-01-04 10:06:39 +01:00
Bram Matthys 5e81a6ee67 Add listener->start_handshake function pointer.
This is start_of_normal_client_handshake() by default, but is
start_of_control_client_handshake() for the control channel
(for './unrealircd rehash' and such). Previously that was hardcoded.

It is also used by the RPC code now.
2022-06-19 13:13:33 +00:00
Bram Matthys 2c8fc5e641 Move special handling of control socket to procio_server.c.
Things like setting the client->status to CLIENT_STATUS_CONTROL
and list_add(&client->lclient_node, &control_list);

This does mean that we now add clients earlier to the unknown list,
even ones that are going to be control sockets and clients that are
going to be z-lined etc, but it should be a minimal performance hit
since it are just 1-4 insertions in a circular list.
At the same time it makes the code more cleaner and more maintainable
especially with all the "special cases" and such that are there now
and will only become more and more...
2022-06-19 13:13:33 +00:00
Bram Matthys 29eb89a528 Attach client->local->listener to a client very early, now that it is safe.
This makes other code safer as well since they can assume that if the
client is local (client->local) that the listener (client->local->listener)
is non-NULL and safe to access until the client is completely destroyed.
2022-06-19 13:13:33 +00:00
Bram Matthys 60c83b4ba1 Move connect-flood and max-unknown-connections-per-ip into their own module.
These deal with set::anti-flood::everyone::connect-flood and
set::max-unknown-connections-per-ip respectively.

This adds a new hook HOOKTYPE_ACCEPT, that is mostly meant for internal
usage by UnrealIRCd. Most module coders will want to use the existing
hook HOOKTYPE_HANDSHAKE instead.

This also gets of check_banned() which is now spread over the individual
modules (eg: checking banned is done in tkl on HOOKTYPE_ACCEPT and
HOOKTYPE_IP_CHANGE).
2022-06-19 13:13:33 +00:00
Bram Matthys a09d4a7e88 Add CLIENT_STATUS_RPC and add SetRPC() and IsRPC(). 2022-06-19 13:13:33 +00:00
Ron Nnn 64e411aa34 Add support for linking servers via UNIX domain sockets (#202) 2022-05-06 17:05:54 +02:00
Bram Matthys 5425c8fbb6 Don't fail on versions older than Windows 10 version 1803.
And be a bit more informative on why unrealircdctl fails on those.
2022-01-03 13:31:24 +01:00
Bram Matthys c02eb3f16c Windows code cleanup: WSAStartup() -> init_winsock() 2022-01-03 13:19:22 +01:00
Bram Matthys 39688517b0 Make "./unrealircd rehash" show output on the terminal, same for
"./unrealircd reloadtls" and there is now also a "./unrealircd status"

The output is colorized if the terminal supports it (just like on the
boot screen) and also the exit status is 0 for success and non-0 for
failure. The purpose of all this is that you can easily detect rehash
errors on the command line.

These three commands communicate to UnrealIRCd via the new control
UNIX socket, which is in ~/data/unrealircd.ctl.
This also does a lot of other stuff because we now have an internal
tool called bin/unrealircdctl which is called by ./unrealircd for
some of the commands to communicate to the unrealircd.ctl socket.
Later on more of the existing functionality may be moved to that
tool and we may also provide it on Windows in CLI mode so people
have more of the same functionality as on *NIX.
2022-01-02 20:17:36 +01:00
Bram Matthys dbef19cd7a Add initial implementation of UNIX domain sockets (listen::file).
Various things still need to be done: a lot more testing, ability to
set permissions on the file, #ifdef's because of lack of support
on Windows (currently won't compile), etc.

One thing that I don't intend to change is that I chose not to display
the socket in the host but have clients show up as 'localhost' (and
ip '127.0.0.1'). Doing it this way keeps things easy, otherwise we risk
a lot of breakage for nearly nothing gained, really.

Things can be tested via:
listen {
        file "/tmp/listen";
}

and then with netcat:
nc -U /tmp/listen
USER x x x x
NICK hai
etc...
2022-01-01 18:48:17 +01:00
Bram Matthys 707575bc32 Resolve a number of todo items, most by simply removing them :D 2021-09-25 16:54:29 +02:00
Bram Matthys 4a4d069f11 Get rid of ignore for -Wformat-nonliteral in two entire files,
now it is only in 5 functions in entire UnrealIRCd. Acceptable.
2021-09-25 15:16:45 +02:00
Bram Matthys 847f2fc384 Remove is_ip_valid() as we already have is_valid_ip(), and update
the doxygen docs a bit for that function.
2021-09-25 08:17:47 +02:00
Bram Matthys b94707a51b Change (or delete) old sendto_ops() calls. Function is now gone. 2021-09-23 19:14:10 +02:00
Bram Matthys fcf020b99e It's raining consts... 2021-09-11 09:56:22 +02:00
Bram Matthys 4c2aeab75e Windows compile fixes 2021-08-28 16:35:37 +02:00
k4be 9a8889f161 Remove a static variable that was never read 2021-08-22 21:25:06 +02:00
Bram Matthys 5b90fd0c0d Get rid of old MOTD downloading code and several USE_LIBCURL defines
that are no longer needed.
2021-08-21 14:13:24 +02:00
Bram Matthys edfd0d434f Newlog: convert remaining sendto_ops_and_log() 2021-08-11 19:09:07 +02:00
Bram Matthys 9333d4b264 Newlog: fdlist.c, socket.c 2021-08-11 16:48:26 +02:00
Bram Matthys a4d9ef3947 Get rid of some shorts. Sorry... i hate these :D.
Also get rid of some unused stats struct members.
2021-08-10 14:07:54 +02:00
Bram Matthys 641d514853 Move traffic stats from client->local->sendM/sendK/receiveM/receiveK/sendB/receiveB
into a client->local->traffic struct.
2021-08-10 13:22:59 +02:00
Bram Matthys 420eb2ffb6 Rename client->serv to client->server: this is set if the client is a server,
just like client->user is set if the client is a user.

Rename client->srvptr to client->uplink: this is the uplink that the client
is connected to. If the client is a user then it is set to the server that
the client is connected to, if the client is a server then it is set to the
server that the server is connected to (the.. tadah.. uplink).
For local clients it is always set to &me.
2021-08-10 12:52:46 +02:00
Bram Matthys 90a01ed7f9 Rename client->local->lasttime to client->local->last_msg_received
(Last time any message was received, i.e. the socket was read)
2021-08-10 12:40:07 +02:00
Bram Matthys 73f8976a3a Rename client->local->firsttime to client->local->creationtime
(Time user was created (connected on IRC))
2021-08-10 12:38:07 +02:00
Bram Matthys 4dbc2ac860 Rename client->local->since to client->local->fake_lag, since it is used
for fake lag calculations only (well, except for 1 corner case).

As said, modules should use the new function:
void add_fake_lag(Client *client, long msec)
2021-08-10 12:26:19 +02:00
Bram Matthys 532a9becda Massive renames of SSL/TLS and SSL to TLS. People should know the term by now :D 2021-08-10 09:07:32 +02:00
Bram Matthys bc9525528c Get rid of report_error() and report_baderror() now that the last
function call has been replaced with unreal_log().
2021-08-09 12:20:13 +02:00
Bram Matthys 2d8ae5d43a Move some functions from src/socket.c, that don't belong there,
to src/serv.c and src/misc.c
2021-08-09 12:13:30 +02:00
Bram Matthys 3a9975713a Move connect_server() from src/socket.c to src/modules/server.c (efunc) 2021-08-09 12:10:24 +02:00
Bram Matthys 5b44baab1f ULOG_WARN -> ULOG_WARNING. Better be consistent. This was the only
ULOG_* level that used an abbreviated term.
2021-08-06 08:50:45 +02:00
k4be 15ac841aea Do not show "Read error" quit message on regularly closed connections 2021-07-19 16:53:05 +02:00
Bram Matthys d7fcc90014 Change lost_server_link() prototype and log errors properly for both TLS and non-TLS.
Not really satisfied with the way the TLS socket error is logged yet, but ok..
2021-07-14 14:13:02 +02:00
Bram Matthys 49fe200243 unreal_log(), connect_server and report_error() / report_baderror():
* Converted 90% of the socket and linking errors to use unreal_log()
* Add log_data_socket_error(fd) and $socket_error
* This also makes connect_server() 'void' and removes all of the error
  reporting from the callers (there was 3x code duplication due to that)
* Don't use report_error and report_baderror anymore in socket.c
* More to follow...
2021-07-14 13:33:18 +02:00
Bram Matthys 1068960b9a We now compile with -Wformat-nonliteral by default.
This adds __attribute__((format(printf,X,Y))) to several functions.
It also adds checking only for the non-literal case to some functions
such as unreal_log/unreal_do_log.

This so we can more easily detect format string issues. Especially now with
the recoding of the logger and with possible future mistakes in this area
in UnrealIRCd 6 itself or in third party modules.

The check is currently disabled in these files, which are TODO items:
* src/send.c: still much work to do
* src/socket.c: due to report_error and report_baderror().
  I want to get rid of these functions and integrate them
  in the new logger anyway.
* src/serv.c: only disable for hunt_server()
2021-07-14 11:15:49 +02:00
Bram Matthys 05aeba9ba9 Get rid of Debug(()) function calls. I never use it anyway. 2021-07-12 18:54:38 +02:00