Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Remote IP on log file for invalid user or connexion#1653

Open
drmanu011 wants to merge 1 commit intocoturn:masterfrom
drmanu011:patch-1
Open

Add Remote IP on log file for invalid user or connexion#1653
drmanu011 wants to merge 1 commit intocoturn:masterfrom
drmanu011:patch-1

Conversation

@drmanu011
Copy link

Added Remote IP logging on TURN_LOG_FUNC for invalid user, needed for protect turnserver with fail2ban

Are you OK?

Added Remote IP logging on TURN_LOG_FUNC for invalid user, needed for protect turnserver with fail2ban

Are you OK?
@drmanu011 drmanu011 changed the title Update ns_turn_server.c Add Remote IP on log file for invalid user or connexion Mar 14, 2025
@eakraly
Copy link
Collaborator

eakraly commented Mar 30, 2025

Hi @drmanu011

2 comments:

  1. It will probably not help as you may block huge number of clients that are behind NAT and share an IP.
  2. Add a configuration flag so that this behavior is configurable and would not dump client IPs into logs by default

@ggarber ggarber requested a review from Copilot May 25, 2025 15:31
@ggarber ggarber self-assigned this May 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances log messages by adding the remote IP address when logging invalid usernames or missing credentials.

  • Adds remote IP logging to error messages in TURN_LOG_FUNC for invalid user credentials.
  • Implements remote address extraction via addr_to_string and get_remote_addr_from_ioa_socket in two logging locations.

if (!is_secure_string(usname, 1)) {
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "session %018llu: %s: wrong username: %s\n", (unsigned long long)(ss->id),
__FUNCTION__, (char *)usname);
char saddr[129] = "\0";
Copy link

Copilot AI May 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code for obtaining the remote IP is duplicated. Consider extracting the IP retrieval logic into a separate helper function to improve maintainability.

Copilot uses AI. Check for mistakes.
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "session %018llu: %s: Cannot find credentials of user <%s>\n",
(unsigned long long)(ss->id), __FUNCTION__, (char *)usname);
char saddr[129] = "\0";
addr_to_string(get_remote_addr_from_ioa_socket(ss->client_socket), (uint8_t *)saddr);
Copy link

Copilot AI May 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate remote IP extraction code is present here as well. Refactoring this logic into a common helper function could reduce code duplication and ease future maintenance.

Suggested change
addr_to_string(get_remote_addr_from_ioa_socket(ss->client_socket), (uint8_t *)saddr);
extract_remote_ip(ss->client_socket, saddr, sizeof(saddr));

Copilot uses AI. Check for mistakes.
@ggarber
Copy link
Contributor

ggarber commented May 25, 2025

@drmanu011 can you review the feedback received?

@drmanu011
Copy link
Author

Yes, it is easier to use a function rather than duplicating the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants