Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F119908011
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
15 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/data/templates/dhcp-relay/dhcrelay.conf.j2 b/data/templates/dhcp-relay/dhcrelay.conf.j2
index 11710bd8e..c26c263fd 100644
--- a/data/templates/dhcp-relay/dhcrelay.conf.j2
+++ b/data/templates/dhcp-relay/dhcrelay.conf.j2
@@ -1,6 +1,9 @@
### Autogenerated by dhcp_relay.py ###
{% set max_size = '-A ' ~ relay_options.max_size if relay_options.max_size is vyos_defined %}
{# hop_count and relay_agents_packets is a default option, thus it is always present #}
+{% if interface is vyos_defined %}
OPTIONS="-c {{ relay_options.hop_count }} -a -m {{ relay_options.relay_agents_packets }} {{ max_size }} -i {{ interface | join(' -i ') }} {{ server | join(' ') }}"
-
+{% else %}
+OPTIONS="-c {{ relay_options.hop_count }} -a -m {{ relay_options.relay_agents_packets }} {{ max_size }} -id {{ listen_interface | join(' -id ') }} -iu {{ upstream_interface | join(' -iu ') }} {{ server | join(' ') }}"
+{% endif %}
\ No newline at end of file
diff --git a/interface-definitions/dhcp-relay.xml.in b/interface-definitions/dhcp-relay.xml.in
index 27d0a3e6c..746cc2fb4 100644
--- a/interface-definitions/dhcp-relay.xml.in
+++ b/interface-definitions/dhcp-relay.xml.in
@@ -1,93 +1,140 @@
<?xml version="1.0"?>
<!-- DHCP relay configuration -->
<interfaceDefinition>
<node name="service">
<children>
<node name="dhcp-relay" owner="${vyos_conf_scripts_dir}/dhcp_relay.py">
<properties>
<help>Host Configuration Protocol (DHCP) relay agent</help>
<priority>910</priority>
</properties>
<children>
- #include <include/generic-interface-multi-broadcast.xml.i>
+ <leafNode name="interface">
+ <properties>
+ <help>Interface Name to use [To be deprecated]. Only for backward compatibility. Use listen-interface and upstream-interface instead of this option </help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_interfaces.py --broadcast</script>
+ </completionHelp>
+ <valueHelp>
+ <format>txt</format>
+ <description>Interface name</description>
+ </valueHelp>
+ <constraint>
+ <validator name="interface-name"/>
+ </constraint>
+ <multi/>
+ </properties>
+ </leafNode>
+ <leafNode name="listen-interface">
+ <properties>
+ <help>Interface for DHCP Relay Agent to listen for requests</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_interfaces.py</script>
+ </completionHelp>
+ <valueHelp>
+ <format>txt</format>
+ <description>Interface name</description>
+ </valueHelp>
+ <constraint>
+ <validator name="interface-name"/>
+ </constraint>
+ <multi/>
+ </properties>
+ </leafNode>
+ <leafNode name="upstream-interface">
+ <properties>
+ <help>Interface for DHCP Relay Agent forward requests out</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_interfaces.py</script>
+ </completionHelp>
+ <valueHelp>
+ <format>txt</format>
+ <description>Interface name</description>
+ </valueHelp>
+ <constraint>
+ <validator name="interface-name"/>
+ </constraint>
+ <multi/>
+ </properties>
+ </leafNode>
<node name="relay-options">
<properties>
<help>Relay options</help>
</properties>
<children>
<leafNode name="hop-count">
<properties>
<help>Policy to discard packets that have reached specified hop-count</help>
<valueHelp>
<format>u32:1-255</format>
<description>Hop count</description>
</valueHelp>
<constraint>
<validator name="numeric" argument="--range 1-255"/>
</constraint>
<constraintErrorMessage>hop-count must be a value between 1 and 255</constraintErrorMessage>
</properties>
<defaultValue>10</defaultValue>
</leafNode>
<leafNode name="max-size">
<properties>
<help>Maximum packet size to send to a DHCPv4/BOOTP server</help>
<valueHelp>
<format>u32:64-1400</format>
<description>Maximum packet size</description>
</valueHelp>
<constraint>
<validator name="numeric" argument="--range 64-1400"/>
</constraint>
<constraintErrorMessage>max-size must be a value between 64 and 1400</constraintErrorMessage>
</properties>
<defaultValue>576</defaultValue>
</leafNode>
<leafNode name="relay-agents-packets">
<properties>
<help>Policy to handle incoming DHCPv4 packets which already contain relay agent options</help>
<completionHelp>
<list>append replace forward discard</list>
</completionHelp>
<valueHelp>
<format>append</format>
<description>append own relay options to packet</description>
</valueHelp>
<valueHelp>
<format>replace</format>
<description>replace existing agent option field</description>
</valueHelp>
<valueHelp>
<format>forward</format>
<description>forward packet unchanged</description>
</valueHelp>
<valueHelp>
<format>discard</format>
<description>discard packet (default action if giaddr not set in packet)</description>
</valueHelp>
<constraint>
<regex>(append|replace|forward|discard)</regex>
</constraint>
</properties>
<defaultValue>forward</defaultValue>
</leafNode>
</children>
</node>
<leafNode name="server">
<properties>
<help>DHCP server address</help>
<valueHelp>
<format>ipv4</format>
<description>DHCP server IPv4 address</description>
</valueHelp>
<multi/>
<constraint>
<validator name="ipv4-address"/>
</constraint>
</properties>
</leafNode>
</children>
</node>
</children>
</node>
</interfaceDefinition>
diff --git a/smoketest/scripts/cli/test_service_dhcp-relay.py b/smoketest/scripts/cli/test_service_dhcp-relay.py
index bbfd9e032..92f87c06c 100755
--- a/smoketest/scripts/cli/test_service_dhcp-relay.py
+++ b/smoketest/scripts/cli/test_service_dhcp-relay.py
@@ -1,87 +1,124 @@
#!/usr/bin/env python3
#
# Copyright (C) 2020 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
from base_vyostest_shim import VyOSUnitTestSHIM
from vyos.configsession import ConfigSessionError
from vyos.ifconfig import Section
from vyos.util import process_named_running
from vyos.util import read_file
PROCESS_NAME = 'dhcrelay'
RELAY_CONF = '/run/dhcp-relay/dhcrelay.conf'
base_path = ['service', 'dhcp-relay']
class TestServiceDHCPRelay(VyOSUnitTestSHIM.TestCase):
def tearDown(self):
self.cli_delete(base_path)
self.cli_commit()
def test_relay_default(self):
max_size = '800'
hop_count = '20'
agents_packets = 'append'
servers = ['192.0.2.1', '192.0.2.2']
self.cli_set(base_path + ['interface', 'lo'])
# check validate() - DHCP relay does not support the loopback interface
with self.assertRaises(ConfigSessionError):
self.cli_commit()
self.cli_delete(base_path + ['interface', 'lo'])
# activate DHCP relay on all ethernet interfaces
for tmp in Section.interfaces("ethernet"):
self.cli_set(base_path + ['interface', tmp])
# check validate() - No DHCP relay server(s) configured
with self.assertRaises(ConfigSessionError):
self.cli_commit()
for server in servers:
self.cli_set(base_path + ['server', server])
self.cli_set(base_path + ['relay-options', 'max-size', max_size])
self.cli_set(base_path + ['relay-options', 'hop-count', hop_count])
self.cli_set(base_path + ['relay-options', 'relay-agents-packets', agents_packets])
# commit changes
self.cli_commit()
# Check configured port
config = read_file(RELAY_CONF)
# Test configured relay interfaces
for tmp in Section.interfaces("ethernet"):
self.assertIn(f'-i {tmp}', config)
# Test relay servers
for server in servers:
self.assertIn(f' {server}', config)
# Test max-size
self.assertIn(f'-A {max_size}', config)
# Hop count
self.assertIn(f'-c {hop_count}', config)
# relay-agents-packets
self.assertIn(f'-a -m {agents_packets}', config)
# Check for running process
self.assertTrue(process_named_running(PROCESS_NAME))
+ def test_relay_interfaces(self):
+ max_size = '800'
+ hop_count = '20'
+ agents_packets = 'append'
+ servers = ['192.0.2.1', '192.0.2.2']
+ listen_iface = 'eth0'
+ up_iface = 'eth1'
+
+ self.cli_set(base_path + ['interface', up_iface])
+ self.cli_set(base_path + ['listen-interface', listen_iface])
+ # check validate() - backward interface plus listen_interface
+ with self.assertRaises(ConfigSessionError):
+ self.cli_commit()
+ self.cli_delete(base_path + ['interface'])
+
+ self.cli_set(base_path + ['upstream-interface', up_iface])
+
+ for server in servers:
+ self.cli_set(base_path + ['server', server])
+
+ # commit changes
+ self.cli_commit()
+
+ # Check configured port
+ config = read_file(RELAY_CONF)
+
+ # Test configured relay interfaces
+ self.assertIn(f'-id {listen_iface}', config)
+ self.assertIn(f'-iu {up_iface}', config)
+
+ # Test relay servers
+ for server in servers:
+ self.assertIn(f' {server}', config)
+
+ # Check for running process
+ self.assertTrue(process_named_running(PROCESS_NAME))
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/src/conf_mode/dhcp_relay.py b/src/conf_mode/dhcp_relay.py
index 4de2ca2f3..07ec1c7a3 100755
--- a/src/conf_mode/dhcp_relay.py
+++ b/src/conf_mode/dhcp_relay.py
@@ -1,93 +1,106 @@
#!/usr/bin/env python3
#
# Copyright (C) 2018-2020 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from sys import exit
from vyos.config import Config
from vyos.configdict import dict_merge
from vyos.template import render
+from vyos.base import Warning
from vyos.util import call
from vyos.util import dict_search
from vyos.xml import defaults
from vyos import ConfigError
from vyos import airbag
airbag.enable()
config_file = r'/run/dhcp-relay/dhcrelay.conf'
def get_config(config=None):
if config:
conf = config
else:
conf = Config()
base = ['service', 'dhcp-relay']
if not conf.exists(base):
return None
relay = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True)
# We have gathered the dict representation of the CLI, but there are default
# options which we need to update into the dictionary retrived.
default_values = defaults(base)
relay = dict_merge(default_values, relay)
return relay
def verify(relay):
# bail out early - looks like removal from running config
if not relay:
return None
if 'lo' in (dict_search('interface', relay) or []):
raise ConfigError('DHCP relay does not support the loopback interface.')
if 'server' not in relay :
raise ConfigError('No DHCP relay server(s) configured.\n' \
'At least one DHCP relay server required.')
+ if 'interface' in relay:
+ if 'upstream_interface' in relay or 'listen_interface' in relay:
+ raise ConfigError('<interface> configuration is not compatible with upstream/listen interface')
+ else:
+ Warning('<interface> is going to be deprecated.\n' \
+ 'Please use <listen-interface> and <upstream-interface>')
+
+ if 'upstream_interface' in relay and 'listen_interface' not in relay:
+ raise ConfigError('No listen-interface configured')
+ if 'listen_interface' in relay and 'upstream_interface' not in relay:
+ raise ConfigError('No upstream-interface configured')
+
return None
def generate(relay):
# bail out early - looks like removal from running config
if not relay:
return None
render(config_file, 'dhcp-relay/dhcrelay.conf.j2', relay)
return None
def apply(relay):
# bail out early - looks like removal from running config
service_name = 'isc-dhcp-relay.service'
if not relay:
call(f'systemctl stop {service_name}')
if os.path.exists(config_file):
os.unlink(config_file)
return None
call(f'systemctl restart {service_name}')
return None
if __name__ == '__main__':
try:
c = get_config()
verify(c)
generate(c)
apply(c)
except ConfigError as e:
print(e)
exit(1)
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 26, 10:16 PM (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4989300
Default Alt Text
(15 KB)
Attached To
Mode
rVYOSONEX vyos-1x
Attached
Detach File
Event Timeline
Log In to Comment