Commit 414079a6 authored by Kirill Smelkov's avatar Kirill Smelkov

X Fix hostport splitting during gtp_addr calculation

urlparse does not handle raw IPv6 address the way I though it does - extracted
hostname is not the whole address, but only the first part of it:

    In [3]: urllib.parse.urlparse('z://2a11:9ac1:6::5')
    Out[3]: ParseResult(scheme='z', netloc='2a11:9ac1:6::5', path='', params='', query='', fragment='')

    In [4]: _.hostname
    Out[4]: '2a11'

Tests did not noticed this because previouslt we had e.g 4321::1 in the
address, and netaddr thinks 4321 is valid ipv4 address:

    In [6]: netaddr.IPAddress('4321')
    Out[6]: IPAddress('0.0.16.225')

However changing IPv6 addresses to use hex letter trigger the bug with e.g.

       raise AddrFormatError('failed to detect a valid IP ' \
    netaddr.core.AddrFormatError: failed to detect a valid IP address from '2a11'

-> Fix it by avoiding urlparse and doing ip/port splitting ourselves by hand.

/reported-by @lu.xu
parent 3a279a19
......@@ -88,7 +88,7 @@ md5sum = 52da9fe3a569199e35ad89ae1a44c30e
[template-enb]
_update_hash_filename_ = instance-enb.jinja2.cfg
md5sum = d6b3e494db278d2ecc28ea1a9e4a7826
md5sum = ebca620d56ccd5d7fb0967da224ea5db
[template-ors-enb]
_update_hash_filename_ = instance-ors-enb.jinja2.cfg
......@@ -112,7 +112,7 @@ md5sum = dcaac06553a3222b14c0013a13f4a149
[enb.jinja2.cfg]
filename = config/enb.jinja2.cfg
md5sum = d395d9ef1d9631b44f57da271284bf54
md5sum = a0e06192f4f0f2252696a67c5eb902e2
[drb_lte.jinja2.cfg]
filename = config/drb_lte.jinja2.cfg
......
......@@ -99,6 +99,30 @@
15: 75,
20: 100} %}
{{- _[bandwidth] | tojson }}
{%- endmacro %}
{#- jhostport splits address into (host,port) pair. #}
{%- macro jhostport(addr) %}
{%- set _ = namespace() %}
{%- if ':' not in addr %}
{%- set _.host = addr %}
{%- set _.port = None %}
{%- else %}
{%- set head, tail = addr.rsplit(':', 1) %}
{%- if ':' not in head %}
{%- set _.host = head %}
{%- set _.port = tail %}
{%- else %}
{%- if addr.startswith('[') %}
{%- set _.host = addr[1:addr.index(']')] %}
{%- set _.port = tail %}
{%- else %}
{%- set _.host = addr %}
{%- set _.port = None %}
{%- endif %}
{%- endif %}
{%- endif %}
{{- (_.host, _.port) | tojson }}
{%- endmacro -%}
......@@ -163,7 +187,7 @@
{%- set vip = [] %}
{%- for a in vcore %}
{%- set _ = namespace() %}
{%- set _.ip = urllib.parse.urlparse('z://%s' % a).hostname %}
{%- set _.ip = J(jhostport(a))[0] %}
{%- set _.islo = netaddr.IPAddress(_.ip).is_loopback() %}
{%- do vip.append(_) %}
{%- endfor %}
......
......@@ -197,7 +197,6 @@ context =
raw gtp_addr_v4 {{ lan_ipv4 }}
import xbuildout xbuildout
import netaddr netaddr
import urllib urllib
${:extra-context}
[enb-config]
......
......@@ -29,7 +29,6 @@ def j2render(src, out, jcfg):
textctx += 'import nrarfcn_module nrarfcn\n'
textctx += 'import xearfcn_module xlte.earfcn\n'
textctx += 'import xnrarfcn_module xlte.nrarfcn\n'
textctx += 'import urllib urllib\n'
textctx += 'import netaddr netaddr\n'
buildout = None # stub
r = jinja2_template.Recipe(buildout, "recipe", {
......
......@@ -275,11 +275,11 @@ class ENBTestCase4(RFTestCase4):
'gnb_id_bits': 30,
'mme_list': {
'1': {'mme_addr': '1.2.3.4'},
'2': {'mme_addr': '[1234::1]:78'},
'2': {'mme_addr': '[abcd:5::1]:78'},
},
'amf_list': {
'1': {'amf_addr': '4.3.2.1:77'},
'2': {'amf_addr': '4321::1'},
'2': {'amf_addr': 'dcba:5::1'},
},
'plmn_list': {
'1': {'plmn': '31415'},
......@@ -318,8 +318,8 @@ class ENBTestCase4(RFTestCase4):
def test_enb_cfg_basic(t):
assertMatch(t, t.enb_cfg, dict(
enb_id=0x17, gnb_id=0x23, gnb_id_bits=30,
mme_list=[{'mme_addr': '1.2.3.4'}, {'mme_addr': '[1234::1]:78'}],
amf_list=[{'amf_addr': '4.3.2.1:77'}, {'amf_addr': '4321::1'}],
mme_list=[{'mme_addr': '1.2.3.4'}, {'mme_addr': '[abcd:5::1]:78'}],
amf_list=[{'amf_addr': '4.3.2.1:77'}, {'amf_addr': 'dcba:5::1'}],
x2_peers=['44.1.1.1'], xn_peers=['55.1.1.1'],
cell_default={
'plmn_list': [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment