ovn: Add lsp-set-dhcpv6-options ovn-nbctl operation.
OVN offers a shortcut to set DHCPv4 options on a logical switch port,
but it did not offer the same for DHCPv6. This commit adds a similar
option for DHCPv6.
@@ -369,6 +369,9 @@ Logical switch port commands:\n\
lsp-set-dhcpv4-options PORT [DHCP_OPTIONS_UUID]\n\
set dhcpv4 options for PORT\n\
lsp-get-dhcpv4-options PORT get the dhcpv4 options for PORT\n\
+ lsp-set-dhcpv6-options PORT [DHCP_OPTIONS_UUID]\n\
+ set dhcpv6 options for PORT\n\
+ lsp-get-dhcpv6-options PORT get the dhcpv6 options for PORT\n\
\n\
Logical router commands:\n\
lr-add [ROUTER] create a logical router named ROUTER\n\
@@ -1244,6 +1247,30 @@ nbctl_lsp_set_dhcpv4_options(struct ctl_context *ctx)
nbrec_logical_switch_port_set_dhcpv4_options(lsp, dhcp_opt);
}
+static void
+nbctl_lsp_set_dhcpv6_options(struct ctl_context *ctx)
+{
+ const char *id = ctx->argv[1];
+ const struct nbrec_logical_switch_port *lsp;
+
+ lsp = lsp_by_name_or_uuid(ctx, id, true);
+ const struct nbrec_dhcp_options *dhcp_opt = NULL;
+ if (ctx->argc == 3) {
+ dhcp_opt = dhcp_options_get(ctx, ctx->argv[2], true);
+ }
+
+ if (dhcp_opt) {
+ struct in6_addr ip;
+ unsigned int plen;
+ char *error = ipv6_parse_cidr(dhcp_opt->cidr, &ip, &plen);
+ if (error) {
+ free(error);
+ ctl_fatal("DHCP options cidr '%s' is not IPv6", dhcp_opt->cidr);
+ }
+ }
+ nbrec_logical_switch_port_set_dhcpv6_options(lsp, dhcp_opt);
+}
+
static void
nbctl_lsp_get_dhcpv4_options(struct ctl_context *ctx)
{
@@ -1258,6 +1285,20 @@ nbctl_lsp_get_dhcpv4_options(struct ctl_context *ctx)
}
}
+static void
+nbctl_lsp_get_dhcpv6_options(struct ctl_context *ctx)
+{
+ const char *id = ctx->argv[1];
+ const struct nbrec_logical_switch_port *lsp;
+
+ lsp = lsp_by_name_or_uuid(ctx, id, true);
+ if (lsp->dhcpv6_options) {
+ ds_put_format(&ctx->output, UUID_FMT " (%s)\n",
+ UUID_ARGS(&lsp->dhcpv6_options->header_.uuid),
+ lsp->dhcpv6_options->cidr);
+ }
+}
+
enum {
DIR_FROM_LPORT,
DIR_TO_LPORT
@@ -3611,6 +3652,10 @@ static const struct ctl_command_syntax nbctl_commands[] = {
nbctl_lsp_set_dhcpv4_options, NULL, "", RW },
{ "lsp-get-dhcpv4-options", 1, 1, "PORT", NULL,
nbctl_lsp_get_dhcpv4_options, NULL, "", RO },
+ { "lsp-set-dhcpv6-options", 1, 2, "PORT [DHCP_OPT_UUID]", NULL,
+ nbctl_lsp_set_dhcpv6_options, NULL, "", RW },
+ { "lsp-get-dhcpv6-options", 1, 1, "PORT", NULL,
+ nbctl_lsp_get_dhcpv6_options, NULL, "", RO },
/* logical router commands. */
{ "lr-add", 0, 1, "[ROUTER]", NULL, nbctl_lr_add, NULL,
