Skip to content

Commit

Permalink
Merge pull request #2251 from mlassnig/patch-2245-Detection_of_client…
Browse files Browse the repository at this point in the history
…_location_fails_on_IPv6_only_node

Detection of client location fails on IPv6-only node; Fix #2245
  • Loading branch information
bari12 committed Feb 22, 2019
2 parents 3faadc8 + b2add08 commit 0dcf92a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/rucio/common/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2012-2018 CERN for the benefit of the ATLAS collaboration.
# Copyright 2012-2019 CERN for the benefit of the ATLAS collaboration.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
# Authors:
# - Vincent Garonne <vgaronne@gmail.com>, 2012-2018
# - Thomas Beermann <thomas.beermann@cern.ch>, 2012-2018
# - Mario Lassnig <mario.lassnig@cern.ch>, 2012-2018
# - Mario Lassnig <mario.lassnig@cern.ch>, 2012-2019
# - Cedric Serfon <cedric.serfon@cern.ch>, 2013-2017
# - Ralph Vigne <ralph.vigne@cern.ch>, 2013
# - Joaquin Bogado <jbogado@linti.unlp.edu.ar>, 2015-2018
Expand Down Expand Up @@ -656,8 +656,8 @@ class Color:

def detect_client_location():
"""
Open a UDP socket to a machine on the internet, to get the local IP address
of the requesting client.
Open a UDP socket to a machine on the internet, to get the local IPv4 and IPv6
addresses of the requesting client.
Try to determine the sitename automatically from common environment variables,
in this order: SITE_NAME, ATLAS_SITE_NAME, OSG_SITE_NAME. If none of these exist
Expand All @@ -672,12 +672,21 @@ def detect_client_location():
except Exception:
pass

ip6 = '::'
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.connect(("2001:4860:4860:0:0:0:0:8888", 80))
ip6 = s.getsockname()[0]
except Exception:
pass

site = os.environ.get('SITE_NAME',
os.environ.get('ATLAS_SITE_NAME',
os.environ.get('OSG_SITE_NAME',
'ROAMING')))

return {'ip': ip,
'ip6': ip6,
'fqdn': socket.getfqdn(),
'site': site}

Expand Down

0 comments on commit 0dcf92a

Please sign in to comment.