Module: Datadog::Core::Utils::Network

Defined in:
lib/datadog/core/utils/network.rb

Overview

Common Network utility functions.

Constant Summary collapse

DEFAULT_IP_HEADERS_NAMES =
%w[
  x-forwarded-for
  x-real-ip
  true-client-ip
  x-client-ip
  x-forwarded
  forwarded
  forwarded-for
  x-cluster-client-ip
  fastly-client-ip
  cf-connecting-ip
  cf-connecting-ipv6
].freeze
CGNAT_IP_RANGE =
IPAddr.new('100.64.0.0/10')

Class Method Summary collapse

Class Method Details

.stripped_ip(ip) ⇒ String?

Parameters:

  • IP (String)

    value.

Returns:

  • (String)

    IP value without the port and the zone indentifier.

  • (nil)

    when no valid IP value found.



44
45
46
47
# File 'lib/datadog/core/utils/network.rb', line 44

def stripped_ip(ip)
  ip = ip_to_ipaddr(ip)
  ip&.to_s
end

.stripped_ip_from_request_headers(headers, ip_headers_to_check: DEFAULT_IP_HEADERS_NAMES) ⇒ String?

Returns a client IP associated with the request if it was

retrieved successfully.

Parameters:

Returns:

  • (String)

    IP value without the port and the zone indentifier.

  • (nil)

    when no valid IP value found.



35
36
37
38
39
# File 'lib/datadog/core/utils/network.rb', line 35

def stripped_ip_from_request_headers(headers, ip_headers_to_check: DEFAULT_IP_HEADERS_NAMES)
  ip = ip_header(headers, ip_headers_to_check)

  ip&.to_s
end