From 20eec3e8a4341b866d570837dcbd93d15b3feb26 Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Sat, 17 Jun 2023 14:24:42 +0000 Subject: vyos.utils: T5195: add vyos.utils.network --- python/vyos/utils/__init__.py | 16 ++++++++++++++++ python/vyos/utils/network.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 python/vyos/utils/network.py (limited to 'python') diff --git a/python/vyos/utils/__init__.py b/python/vyos/utils/__init__.py index e69de29bb..0d3998053 100644 --- a/python/vyos/utils/__init__.py +++ b/python/vyos/utils/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2023 VyOS maintainers and contributors +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . + +from vyos.utils import network diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py new file mode 100644 index 000000000..72b7ca6da --- /dev/null +++ b/python/vyos/utils/network.py @@ -0,0 +1,30 @@ +# Copyright 2023 VyOS maintainers and contributors +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . + +import os + + +def get_protocol_by_name(protocol_name): + """Get protocol number by protocol name + + % get_protocol_by_name('tcp') + % 6 + """ + import socket + try: + protocol_number = socket.getprotobyname(protocol_name) + return protocol_number + except socket.error: + return protocol_name -- cgit v1.2.3 From 7b8ef5d6a24fcdb67c8d138eacbc8d17e5324226 Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Sat, 17 Jun 2023 14:52:29 +0000 Subject: T5256: Fix QoS protocol expects protocol number but not name tc filter exepcts protocol number for match instead of protocol name --- python/vyos/qos/base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/vyos/qos/base.py b/python/vyos/qos/base.py index bd1676107..353eb91b3 100644 --- a/python/vyos/qos/base.py +++ b/python/vyos/qos/base.py @@ -20,6 +20,9 @@ from vyos.util import cmd from vyos.util import dict_search from vyos.util import read_file +from vyos.utils.network import get_protocol_by_name + + class QoSBase: _debug = False _direction = ['egress'] @@ -197,7 +200,9 @@ class QoSBase: if tmp: filter_cmd += f' match {tc_af} dport {tmp} 0xffff' tmp = dict_search(f'{af}.protocol', match_config) - if tmp: filter_cmd += f' match {tc_af} protocol {tmp} 0xff' + if tmp: + tmp = get_protocol_by_name(tmp) + filter_cmd += f' match {tc_af} protocol {tmp} 0xff' # Will match against total length of an IPv4 packet and # payload length of an IPv6 packet. -- cgit v1.2.3