This patch adds default_dhcpv4_options and default_dhcpv6_options columns for
Logical_Switch, which should help CMS not to calculate and set dhcpv4_options
and dhcpv6_options columns for lswitch ports on lswitchs one by one, when
most of lswitch ports on the same lswitch are using the DHCPv4_Options and
DHCPv6_Options. Default DHCP(v4 and v6) Options should benefit in case
scalling up and DB synchronization between CMS and OVN NB.
v1 -> v2
add ACL lflows support for lswitch ports using default_dhcpvx_options from
lswitch.
v2 -> v3
update ovn dhcpv4 and dhcpv6 tests for lswitch ports using specific dhcp
options than defualt ones in lswitch.
---
ovn/northd/ovn-northd.c | 144
ovn/ovn-nb.ovsschema| 18 +-
ovn/ovn-nb.xml | 26 +
tests/ovn.at| 74 +++--
4 files changed, 220 insertions(+), 42 deletions(-)
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 0ad9190..3ab11fa 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -1784,14 +1784,27 @@ static bool
build_dhcpv4_action(struct ovn_port *op, ovs_be32 offer_ip,
struct ds *options_action, struct ds *response_action)
{
+char *cidr = NULL;
+struct smap dhcpv4_options = SMAP_INITIALIZER(_options);
if (!op->nbsp->dhcpv4_options) {
-/* CMS has disabled native DHCPv4 for this lport. */
-return false;
+if ((!op->nbsp->use_default_dhcpv4 || *op->nbsp->use_default_dhcpv4)
+&& op->od->nbs->default_dhcpv4_options) {
+/* Use lswitch default DHCPv4 options for this lport. */
+cidr = op->od->nbs->default_dhcpv4_options->cidr;
+smap_clone(_options,
+ >od->nbs->default_dhcpv4_options->options);
+} else {
+/* CMS has disabled native DHCPv4 for this lport. */
+smap_destroy(_options);
+return false;
+}
+} else {
+cidr = op->nbsp->dhcpv4_options->cidr;
+smap_clone(_options, >nbsp->dhcpv4_options->options);
}
ovs_be32 host_ip, mask;
-char *error = ip_parse_masked(op->nbsp->dhcpv4_options->cidr, _ip,
- );
+char *error = ip_parse_masked(cidr, _ip, );
if (error || ((offer_ip ^ host_ip) & mask)) {
/* Either
* - cidr defined is invalid or
@@ -1802,14 +1815,10 @@ build_dhcpv4_action(struct ovn_port *op, ovs_be32
offer_ip,
return false;
}
-const char *server_ip = smap_get(
->nbsp->dhcpv4_options->options, "server_id");
-const char *server_mac = smap_get(
->nbsp->dhcpv4_options->options, "server_mac");
-const char *lease_time = smap_get(
->nbsp->dhcpv4_options->options, "lease_time");
-const char *router = smap_get(
->nbsp->dhcpv4_options->options, "router");
+const char *server_ip = smap_get(_options, "server_id");
+const char *server_mac = smap_get(_options, "server_mac");
+const char *lease_time = smap_get(_options, "lease_time");
+const char *router = smap_get(_options, "router");
if (!(server_ip && server_mac && lease_time && router)) {
/* "server_id", "server_mac", "lease_time" and "router" should be
@@ -1820,8 +1829,8 @@ build_dhcpv4_action(struct ovn_port *op, ovs_be32
offer_ip,
return false;
}
-struct smap dhcpv4_options = SMAP_INITIALIZER(_options);
-smap_clone(_options, >nbsp->dhcpv4_options->options);
+char server_mac_str[ETH_ADDR_STRLEN + 1];
+strcpy(server_mac_str, server_mac);
/* server_mac is not DHCPv4 option, delete it from the smap. */
smap_remove(_options, "server_mac");
@@ -1845,7 +1854,7 @@ build_dhcpv4_action(struct ovn_port *op, ovs_be32
offer_ip,
"ip4.dst = "IP_FMT"; ip4.src = %s; udp.src = 67; "
"udp.dst = 68; outport = inport; flags.loopback = 1; "
"output;",
- server_mac, IP_ARGS(offer_ip), server_ip);
+ server_mac_str, IP_ARGS(offer_ip), server_ip);
smap_destroy(_options);
return true;
@@ -1855,15 +1864,28 @@ static bool
build_dhcpv6_action(struct ovn_port *op, struct in6_addr *offer_ip,
struct ds *options_action, struct ds *response_action)
{
+char *cidr = NULL;
+struct smap dhcpv6_options = SMAP_INITIALIZER(_options);
if (!op->nbsp->dhcpv6_options) {
-/* CMS has disabled native DHCPv6 for this lport. */
-return false;
+if ((!op->nbsp->use_default_dhcpv6 || *op->nbsp->use_default_dhcpv6)
+&& op->od->nbs->default_dhcpv6_options) {
+/* Use lswitch default DHCPv6 options for this lport. */
+cidr = op->od->nbs->default_dhcpv6_options->cidr;
+smap_clone(_options,
+ >od->nbs->default_dhcpv6_options->options);
+} else {
+/* CMS has disabled native DHCPv6