From: Han Zhou <[email protected]> This patch introduces OVN_IC_Southbound DB schema and the CLI ovn-isbctl that manages the DB.
Signed-off-by: Han Zhou <[email protected]> --- .gitignore | 3 + automake.mk | 38 ++ debian/ovn-common.install | 1 + debian/ovn-common.manpages | 2 + lib/.gitignore | 3 + lib/automake.mk | 17 +- lib/ovn-isb-idl.ann | 9 + lib/ovn-util.c | 13 + lib/ovn-util.h | 1 + ovn-isb.ovsschema | 130 +++++++ ovn-isb.xml | 588 ++++++++++++++++++++++++++++++ utilities/.gitignore | 2 + utilities/automake.mk | 5 + utilities/ovn-isbctl.c | 890 +++++++++++++++++++++++++++++++++++++++++++++ 14 files changed, 1701 insertions(+), 1 deletion(-) create mode 100644 lib/ovn-isb-idl.ann create mode 100644 ovn-isb.ovsschema create mode 100644 ovn-isb.xml create mode 100644 utilities/ovn-isbctl.c diff --git a/.gitignore b/.gitignore index 1994937..66bb101 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,9 @@ /ovn-inb.5 /ovn-inb.gv /ovn-inb.pic +/ovn-isb.5 +/ovn-isb.gv +/ovn-isb.pic /package.m4 /stamp-h1 /_build-gcc diff --git a/automake.mk b/automake.mk index 3bfbf57..85574fc 100644 --- a/automake.mk +++ b/automake.mk @@ -97,6 +97,37 @@ ovn-inb.5: \ $(srcdir)/ovn-inb.xml > [email protected] && \ mv [email protected] $@ +# OVN interconnection southbound E-R diagram +# +# If "python" or "dot" is not available, then we do not add graphical diagram +# to the documentation. +if HAVE_PYTHON +if HAVE_DOT +ovn-isb.gv: ${OVSDIR}/ovsdb/ovsdb-dot.in $(srcdir)/ovn-isb.ovsschema + $(AM_V_GEN)$(OVSDB_DOT) --no-arrows $(srcdir)/ovn-isb.ovsschema > $@ +ovn-isb.pic: ovn-isb.gv ${OVSDIR}/ovsdb/dot2pic + $(AM_V_GEN)(dot -T plain < ovn-isb.gv | $(PYTHON) ${OVSDIR}/ovsdb/dot2pic -f 3) > [email protected] && \ + mv [email protected] $@ +OVN_ISB_PIC = ovn-isb.pic +OVN_ISB_DOT_DIAGRAM_ARG = --er-diagram=$(OVN_ISB_PIC) +CLEANFILES += ovn-isb.gv ovn-isb.pic +endif +endif + +# OVN interconnection southbound schema documentation +EXTRA_DIST += ovn-isb.xml +CLEANFILES += ovn-isb.5 +man_MANS += ovn-isb.5 + +ovn-isb.5: \ + ${OVSDIR}/ovsdb/ovsdb-doc $(srcdir)/ovn-isb.xml $(srcdir)/ovn-isb.ovsschema $(OVN_ISB_PIC) + $(AM_V_GEN)$(OVSDB_DOC) \ + $(OVN_ISB_DOT_DIAGRAM_ARG) \ + --version=$(VERSION) \ + $(srcdir)/ovn-isb.ovsschema \ + $(srcdir)/ovn-isb.xml > [email protected] && \ + mv [email protected] $@ + # Version checking for ovn-nb.ovsschema. ALL_LOCAL += ovn-nb.ovsschema.stamp ovn-nb.ovsschema.stamp: ovn-nb.ovsschema @@ -114,8 +145,15 @@ ovn-inb.ovsschema.stamp: ovn-inb.ovsschema $(srcdir)/build-aux/cksum-schema-check $? $@ CLEANFILES += ovn-inb.ovsschema.stamp +# Version checking for ovn-isb.ovsschema. +ALL_LOCAL += ovn-isb.ovsschema.stamp +ovn-isb.ovsschema.stamp: ovn-isb.ovsschema + $(srcdir)/build-aux/cksum-schema-check $? $@ +CLEANFILES += ovn-isb.ovsschema.stamp + pkgdata_DATA += ovn-nb.ovsschema pkgdata_DATA += ovn-sb.ovsschema pkgdata_DATA += ovn-inb.ovsschema +pkgdata_DATA += ovn-isb.ovsschema CLEANFILES += ovn-sb.ovsschema.stamp diff --git a/debian/ovn-common.install b/debian/ovn-common.install index 9e9bcfb..8f8ab23 100644 --- a/debian/ovn-common.install +++ b/debian/ovn-common.install @@ -1,6 +1,7 @@ usr/bin/ovn-nbctl usr/bin/ovn-sbctl usr/bin/ovn-inbctl +usr/bin/ovn-isbctl usr/bin/ovn-trace usr/bin/ovn-detrace usr/share/openvswitch/scripts/ovn-ctl diff --git a/debian/ovn-common.manpages b/debian/ovn-common.manpages index 94325dd..895da8d 100644 --- a/debian/ovn-common.manpages +++ b/debian/ovn-common.manpages @@ -2,9 +2,11 @@ ovn/ovn-architecture.7 ovn/ovn-nb.5 ovn/ovn-sb.5 ovn/ovn-inb.5 +ovn/ovn-isb.5 ovn/utilities/ovn-ctl.8 ovn/utilities/ovn-nbctl.8 ovn/utilities/ovn-sbctl.8 ovn/utilities/ovn-inbctl.8 +ovn/utilities/ovn-isbctl.8 ovn/utilities/ovn-trace.8 ovn/utilities/ovn-detrace.1 diff --git a/lib/.gitignore b/lib/.gitignore index e5d9bf3..19cc9f5 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -8,4 +8,7 @@ /ovn-inb-idl.c /ovn-inb-idl.h /ovn-inb-idl.ovsidl +/ovn-isb-idl.c +/ovn-isb-idl.h +/ovn-isb-idl.ovsidl /ovn-dirs.c diff --git a/lib/automake.mk b/lib/automake.mk index 83fdbcd..dc62be7 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -31,7 +31,9 @@ nodist_lib_libovn_la_SOURCES = \ lib/ovn-sb-idl.c \ lib/ovn-sb-idl.h \ lib/ovn-inb-idl.c \ - lib/ovn-inb-idl.h + lib/ovn-inb-idl.h \ + lib/ovn-isb-idl.c \ + lib/ovn-isb-idl.h CLEANFILES += $(nodist_lib_libovn_la_SOURCES) @@ -89,3 +91,16 @@ lib/ovn-inb-idl.ovsidl: $(OVN_INB_IDL_FILES) $(AM_V_GEN)$(OVSDB_IDLC) annotate $(OVN_INB_IDL_FILES) > [email protected] && \ mv [email protected] $@ +# ovn-isb IDL +OVSIDL_BUILT += \ + lib/ovn-isb-idl.c \ + lib/ovn-isb-idl.h \ + lib/ovn-isb-idl.ovsidl +EXTRA_DIST += lib/ovn-isb-idl.ann +OVN_ISB_IDL_FILES = \ + $(srcdir)/ovn-isb.ovsschema \ + $(srcdir)/lib/ovn-isb-idl.ann +lib/ovn-isb-idl.ovsidl: $(OVN_ISB_IDL_FILES) + $(AM_V_GEN)$(OVSDB_IDLC) annotate $(OVN_ISB_IDL_FILES) > [email protected] && \ + mv [email protected] $@ + diff --git a/lib/ovn-isb-idl.ann b/lib/ovn-isb-idl.ann new file mode 100644 index 0000000..ea6efad --- /dev/null +++ b/lib/ovn-isb-idl.ann @@ -0,0 +1,9 @@ +# -*- python -*- + +# This code, when invoked by "ovsdb-idlc annotate" (by the build +# process), annotates ovn-isb.ovsschema with additional data that give +# the ovsdb-idl engine information about the types involved, so that +# it can generate more programmer-friendly data structures. + +s["idlPrefix"] = "isbrec_" +s["idlHeader"] = "\"lib/ovn-isb-idl.h\"" diff --git a/lib/ovn-util.c b/lib/ovn-util.c index 23a362c..8d7db44 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -363,6 +363,19 @@ default_inb_db(void) return def; } +const char * +default_isb_db(void) +{ + static char *def; + if (!def) { + def = getenv("OVN_ISB_DB"); + if (!def) { + def = xasprintf("unix:%s/ovnisb_db.sock", ovn_rundir()); + } + } + return def; +} + char * get_abs_unix_ctl_path(void) { diff --git a/lib/ovn-util.h b/lib/ovn-util.h index e31cf51..694c953 100644 --- a/lib/ovn-util.h +++ b/lib/ovn-util.h @@ -73,6 +73,7 @@ char *alloc_nat_zone_key(const struct uuid *key, const char *type); const char *default_nb_db(void); const char *default_sb_db(void); const char *default_inb_db(void); +const char *default_isb_db(void); char *get_abs_unix_ctl_path(void); struct ovsdb_idl_table_class; diff --git a/ovn-isb.ovsschema b/ovn-isb.ovsschema new file mode 100644 index 0000000..ffce8a2 --- /dev/null +++ b/ovn-isb.ovsschema @@ -0,0 +1,130 @@ +{ + "name": "OVN_IC_Southbound", + "version": "1.0.0", + "cksum": "1074410507 6100", + "tables": { + "ISB_Global": { + "columns": { + "external_ids": { + "type": {"key": "string", "value": "string", + "min": 0, "max": "unlimited"}}, + "connections": { + "type": {"key": {"type": "uuid", + "refTable": "Connection"}, + "min": 0, + "max": "unlimited"}}, + "ssl": { + "type": {"key": {"type": "uuid", + "refTable": "SSL"}, + "min": 0, "max": 1}}, + "options": { + "type": {"key": "string", "value": "string", + "min": 0, "max": "unlimited"}}, + "ipsec": {"type": "boolean"}}, + "maxRows": 1, + "isRoot": true}, + "Availability_Zone": { + "columns": { + "name": {"type": "string"}}, + "isRoot": true, + "indexes": [["name"]]}, + "Gateway": { + "columns": { + "name": {"type": "string"}, + "availability_zone": {"type": {"key": {"type": "uuid", + "refTable": "Availability_Zone"}}}, + "hostname": {"type": "string"}, + "encaps": {"type": {"key": {"type": "uuid", + "refTable": "Encap"}, + "min": 1, "max": "unlimited"}}, + "external_ids": { + "type": {"key": "string", "value": "string", + "min": 0, "max": "unlimited"}}}, + "isRoot": true, + "indexes": [["name"]]}, + "Encap": { + "columns": { + "type": {"type": {"key": { + "type": "string", + "enum": ["set", ["geneve", "stt", "vxlan"]]}}}, + "options": {"type": {"key": "string", + "value": "string", + "min": 0, + "max": "unlimited"}}, + "ip": {"type": "string"}, + "gateway_name": {"type": "string"}}, + "indexes": [["type", "ip"]]}, + "Datapath_Binding": { + "columns": { + "transit_switch": {"type": "string"}, + "tunnel_key": { + "type": {"key": {"type": "integer", + "minInteger": 1, + "maxInteger": 16777215}}}, + "external_ids": { + "type": {"key": "string", "value": "string", + "min": 0, "max": "unlimited"}}}, + "indexes": [["tunnel_key"]], + "isRoot": true}, + "Port_Binding": { + "columns": { + "logical_port": {"type": "string"}, + "transit_switch": {"type": "string"}, + "availability_zone": {"type": {"key": {"type": "uuid", + "refTable": "Availability_Zone"}}}, + "tunnel_key": { + "type": {"key": {"type": "integer", + "minInteger": 1, + "maxInteger": 32767}}}, + "gateway": {"type": "string"}, + "encap": {"type": {"key": {"type": "uuid", + "refTable": "Encap", + "refType": "weak"}, + "min": 0, "max": 1}}, + "address": {"type": "string"}, + "external_ids": {"type": {"key": "string", + "value": "string", + "min": 0, + "max": "unlimited"}}}, + "indexes": [["transit_switch", "tunnel_key"], ["logical_port"]], + "isRoot": true}, + "Connection": { + "columns": { + "target": {"type": "string"}, + "max_backoff": {"type": {"key": {"type": "integer", + "minInteger": 1000}, + "min": 0, + "max": 1}}, + "inactivity_probe": {"type": {"key": "integer", + "min": 0, + "max": 1}}, + "other_config": {"type": {"key": "string", + "value": "string", + "min": 0, + "max": "unlimited"}}, + "external_ids": {"type": {"key": "string", + "value": "string", + "min": 0, + "max": "unlimited"}}, + "is_connected": {"type": "boolean", "ephemeral": true}, + "status": {"type": {"key": "string", + "value": "string", + "min": 0, + "max": "unlimited"}, + "ephemeral": true}}, + "indexes": [["target"]]}, + "SSL": { + "columns": { + "private_key": {"type": "string"}, + "certificate": {"type": "string"}, + "ca_cert": {"type": "string"}, + "bootstrap_ca_cert": {"type": "boolean"}, + "ssl_protocols": {"type": "string"}, + "ssl_ciphers": {"type": "string"}, + "external_ids": {"type": {"key": "string", + "value": "string", + "min": 0, + "max": "unlimited"}}}, + "maxRows": 1} + } +} diff --git a/ovn-isb.xml b/ovn-isb.xml new file mode 100644 index 0000000..28a69dd --- /dev/null +++ b/ovn-isb.xml @@ -0,0 +1,588 @@ +<?xml version="1.0" encoding="utf-8"?> +<database name="ovn-isb" title="OVN Interconnection Southbound Database"> + <p> + This database holds configuration and state for interconnecting different + OVN deployments. The content of the database is populated and used by the + <code>ovn-ic</code> program in each OVN deployment, and not supposed to be + directly used by CMS or end user. + </p> + + <p> + The OVN Interconnection Southbound database is shared by + <code>ovn-ic</code> program in each OVN deployment. It contains + interconnection information from all related OVN deployments, and is used + as the intermediate store for each OVN deployment to exchange the + information. The <code>ovn-ic</code> program in each deployment is + responsible for syncing the data between this database and the its own + northbound and southbound databases. + </p> + + <h2>Database Structure</h2> + + <p> + The OVN Interconnection Southbound database contains classes of data with + different properties, as described in the sections below. + </p> + + <h3>Availability Zone Specific Information</h3> + + <p> + These tables contain objects that are availability zone specific. Each object + is owned and populated by one availability zone, and read by other availability + zones. + </p> + + <p> + The <ref table="Availability_Zone"/>, <ref table="Gateway"/>, <ref + table="Encap"/> and <ref table="Port_Binding"/> tables are the availability + zone specific tables. + </p> + + <h3>Global Information</h3> + + <p> + The data that does not belong to any specific availability zone but is + common for all availability zones. + </p> + + <p> + The <ref table="Datapath_Binding"/> table contains the common datapath + binding information. + </p> + + <h3>Common Columns</h3> + <p> + Each of the tables in this database contains a special column, named + <code>external_ids</code>. This column has the same form and purpose each + place it appears. + </p> + + <dl> + <dt><code>external_ids</code>: map of string-string pairs</dt> + <dd> + Key-value pairs for use by <code>ovn-ic</code>. + </dd> + </dl> + <table name="ISB_Global" title="IC Southbound configuration"> + <p> + Interconnection Southbound configuration. This table must have exactly + one row. + </p> + + <group title="Common Columns"> + <column name="external_ids"> + See <em>External IDs</em> at the beginning of this document. + </column> + + <column name="options"> + </column> + </group> + + <group title="Connection Options"> + <column name="connections"> + Database clients to which the Open vSwitch database server should + connect or on which it should listen, along with options for how these + connections should be configured. See the <ref table="Connection"/> + table for more information. + </column> + <column name="ssl"> + Global SSL configuration. + </column> + </group> + <group title="Security Configurations"> + <column name="ipsec"> + Tunnel encryption configuration. If this column is set to be true, all + OVN tunnels will be encrypted with IPsec. XXX + </column> + </group> + </table> + + <table name="Availability_Zone" title="Availability Zone Information"> + <p> + Each row in this table represents an Availability Zone. Each OVN deployment + is considered an availability zone from OVN control plane perspective, with + its own central components, such as northbound and southbound databases and + <code>ovn-northd</code> daemon. + </p> + + <column name="name"> + A name that uniquely identifies the availability zone. + </column> + </table> + + <table name="Gateway" title="Interconnection Gateway Information"> + <p> + Each row in this table represents a interconnection gateway chassis in an + availability zone. + </p> + + <column name="name"> + The name of the gateway. See <ref table="Chassis" column="name"/> column + of the OVN Southbound database's <ref table="Chassis" + db="OVN_Southbound"/> table. + </column> + + <column name="availability_zone"> + The availabilty zone that the gateway belongs to. + </column> + + <column name="hostname"> + The hostname of the gateway. + </column> + + <group title="Common Columns"> + The overall purpose of these columns is described under <code>Common + Columns</code> at the beginning of this document. + + <column name="external_ids"/> + </group> + + <group title="Encapsulation Configuration"> + <p> + OVN uses encapsulation to transmit logical dataplane packets + between gateways. + </p> + + <column name="encaps"> + Points to supported encapsulation configurations to transmit + logical dataplane packets to this gateway. Each entry is a <ref + table="Encap"/> record that describes the configuration. + See <ref table="Chassis" column="encaps"/> column + of the OVN Southbound database's <ref table="Chassis" + db="OVN_Southbound"/> table. + </column> + </group> + + </table> + + <table name="Encap" title="Encapsulation Types"> + <p> + The <ref column="encaps" table="Gateway"/> column in the <ref + table="Gateway"/> table refers to rows in this table to identify + how OVN may transmit logical dataplane packets to this gateway. + </p> + + <column name="type"> + The encapsulation to use to transmit packets to this gateway. + See <ref table="Encap" column="type"/> column + of the OVN Southbound database's <ref table="Encap" + db="OVN_Southbound"/> table. + </column> + + <column name="options"> + Options for configuring the encapsulation, which may be <ref + column="type"/> specific. See <ref table="Encap" column="options"/> + column of the OVN Southbound database's <ref table="Encap" + db="OVN_Southbound"/> table. + </column> + + <column name="ip"> + The IPv4 address of the encapsulation tunnel endpoint. + </column> + + <column name="gateway_name"> + The name of the gateway that created this encap. + </column> + </table> + + <table name="Datapath_Binding" title="Transit Switch Datapath Bindings"> + <p> + Each row in this table represents a logical datapath for a transit + logical switch configured in the OVN Interconnection Northbound + database's <ref table="Transit_Switch" db="OVN_IC_Northbound"/> table. + </p> + + <column name="transit_switch"> + The name of the transit logical switch that is configured in the OVN + Interconnection Northbound database's <ref table="Transit_Switch" + db="OVN_IC_Northbound"/> table. + </column> + + <column name="tunnel_key"> + <p> + The tunnel key value to which the logical datapath is bound. The key + can be generated by any <code>ovn-ic</code> but the same key is shared + by all availability zones so that the logical datapaths can be peered + across them. A tunnel key for transit switch datapath binding must be + globally unique. + </p> + + <p> + For more information about the meanings of a tunnel key, + see <ref table="Datapath_Binding" column="tunnel_key"/> column of the OVN + Southbound database's <ref table="Datapath_Binding" db="OVN_Southbound"/> + table. + </p> + </column> + + <group title="Common Columns"> + The overall purpose of these columns is described under <code>Common + Columns</code> at the beginning of this document. + + <column name="external_ids"/> + </group> + </table> + + <table name="Port_Binding" title="Transit Port Bindings"> + <p> + Each row in this table binds a logical port on the transit switch to a + physical gateway and a tunnel key. Each port on the transit switch + belongs to a specific availability zone. + </p> + + <group title="Core Features"> + <column name="transit_switch"> + The name of the transit switch that the corresponding logical port + belongs to. + </column> + + <column name="logical_port"> + A logical port, taken from <ref table="Logical_Switch_Port" + column="name" db="OVN_Northbound"/> in the OVN_Northbound + database's <ref table="Logical_Switch_Port" db="OVN_Northbound"/> + table. The logical port name must be unique across all availability + zones. + </column> + + <column name="availability_zone"> + The availability zone that the port belongs to. + </column> + + <column name="encap"> + Points to supported encapsulation configurations to transmit + logical dataplane packets to this gateway. Each entry is a <ref + table="Encap"/> record that describes the configuration. + </column> + + <column name="gateway"> + The name of the gateway that this port is physically located. + </column> + + <column name="tunnel_key"> + <p> + A number that represents the logical port in the key (e.g. STT key or + Geneve TLV) field carried within tunnel protocol packets. The key + can be generated by any <code>ovn-ic</code> but the same key is + shared by all availability zones so that the packets can go through + the datapath pipelines of different availability zones. + </p> + <p> + The tunnel ID must be unique within the scope of a logical datapath. + </p> + <p> + For more information about tunnel key, see <ref table="Port_Binding" + column="tunnel_key"/> column of the OVN Southbound database's <ref + table="Port_Binding" db="OVN_Southbound"/> table. + </p> + </column> + + <column name="address"> + <p> + The Ethernet address and IP addresses used by the corresponding logical + router port peering with the transit switch port. It is a string combined + with the value of <ref table="Logical_Router_Port" column="mac"/> + column followed by the values in <ref table="Logical_Router_Port" + column="networks"/> column in <ref table="Logical_Router_Port" + db="OVN_Northbound"/> table. + </p> + </column> + + </group> + + <group title="Common Columns"> + <column name="external_ids"> + <p> + See <em>External IDs</em> at the beginning of this document. + </p> + </column> + </group> + </table> + + <table name="Connection" title="OVSDB client connections."> + <p> + Configuration for a database connection to an Open vSwitch database + (OVSDB) client. + </p> + + <p> + This table primarily configures the Open vSwitch database server + (<code>ovsdb-server</code>). + </p> + + <p> + The Open vSwitch database server can initiate and maintain active + connections to remote clients. It can also listen for database + connections. + </p> + + <group title="Core Features"> + <column name="target"> + <p>Connection methods for clients.</p> + <p> + The following connection methods are currently supported: + </p> + <dl> + <dt><code>ssl:<var>host</var></code>[<code>:<var>port</var></code>]</dt> + <dd> + <p> + The specified SSL <var>port</var> on the given <var>host</var>, + which can either be a DNS name (if built with unbound library) or + an IP address. A valid SSL configuration must be provided when + this form is used, this configuration can be specified via + command-line options or the <ref table="SSL"/> table. + </p> + <p> + If <var>port</var> is not specified, it defaults to 6640. + </p> + <p> + SSL support is an optional feature that is not always + built as part of Open vSwitch. + </p> + </dd> + + <dt><code>tcp:<var>host</var></code>[<code>:<var>port</var></code>]</dt> + <dd> + <p> + The specified TCP <var>port</var> on the given <var>host</var>, + which can either be a DNS name (if built with unbound library) or + an IP address (IPv4 or IPv6). If <var>host</var> is an IPv6 + address, wrap it in square brackets, e.g. <code>tcp:[::1]:6640</code>. + </p> + <p> + If <var>port</var> is not specified, it defaults to 6640. + </p> + </dd> + <dt><code>pssl:</code>[<var>port</var>][<code>:<var>host</var></code>]</dt> + <dd> + <p> + Listens for SSL connections on the specified TCP <var>port</var>. + Specify 0 for <var>port</var> to have the kernel automatically + choose an available port. If <var>host</var>, which can either + be a DNS name (if built with unbound library) or an IP address, + is specified, then connections are restricted to the resolved or + specified local IP address (either IPv4 or IPv6 address). If + <var>host</var> is an IPv6 address, wrap in square brackets, + e.g. <code>pssl:6640:[::1]</code>. If <var>host</var> is not + specified then it listens only on IPv4 (but not IPv6) addresses. + A valid SSL configuration must be provided when this form is used, + this can be specified either via command-line options or the + <ref table="SSL"/> table. + </p> + <p> + If <var>port</var> is not specified, it defaults to 6640. + </p> + <p> + SSL support is an optional feature that is not always built as + part of Open vSwitch. + </p> + </dd> + <dt><code>ptcp:</code>[<var>port</var>][<code>:<var>host</var></code>]</dt> + <dd> + <p> + Listens for connections on the specified TCP <var>port</var>. + Specify 0 for <var>port</var> to have the kernel automatically + choose an available port. If <var>host</var>, which can either + be a DNS name (if built with unbound library) or an IP address, + is specified, then connections are restricted to the resolved or + specified local IP address (either IPv4 or IPv6 address). If + <var>host</var> is an IPv6 address, wrap it in square brackets, + e.g. <code>ptcp:6640:[::1]</code>. If <var>host</var> is not + specified then it listens only on IPv4 addresses. + </p> + <p> + If <var>port</var> is not specified, it defaults to 6640. + </p> + </dd> + </dl> + <p>When multiple clients are configured, the <ref column="target"/> + values must be unique. Duplicate <ref column="target"/> values yield + unspecified results.</p> + </column> + + </group> + + <group title="Client Failure Detection and Handling"> + <column name="max_backoff"> + Maximum number of milliseconds to wait between connection attempts. + Default is implementation-specific. + </column> + + <column name="inactivity_probe"> + Maximum number of milliseconds of idle time on connection to the client + before sending an inactivity probe message. If Open vSwitch does not + communicate with the client for the specified number of seconds, it + will send a probe. If a response is not received for the same + additional amount of time, Open vSwitch assumes the connection has been + broken and attempts to reconnect. Default is implementation-specific. + A value of 0 disables inactivity probes. + </column> + </group> + + <group title="Status"> + <p> + Key-value pair of <ref column="is_connected"/> is always updated. + Other key-value pairs in the status columns may be updated depends + on the <ref column="target"/> type. + </p> + + <p> + When <ref column="target"/> specifies a connection method that + listens for inbound connections (e.g. <code>ptcp:</code> or + <code>punix:</code>), both <ref column="n_connections"/> and + <ref column="is_connected"/> may also be updated while the + remaining key-value pairs are omitted. + </p> + + <p> + On the other hand, when <ref column="target"/> specifies an + outbound connection, all key-value pairs may be updated, except + the above-mentioned two key-value pairs associated with inbound + connection targets. They are omitted. + </p> + + <column name="is_connected"> + <code>true</code> if currently connected to this client, + <code>false</code> otherwise. + </column> + + <column name="status" key="last_error"> + A human-readable description of the last error on the connection + to the manager; i.e. <code>strerror(errno)</code>. This key + will exist only if an error has occurred. + </column> + + <column name="status" key="state" + type='{"type": "string", "enum": ["set", ["VOID", "BACKOFF", "CONNECTING", "ACTIVE", "IDLE"]]}'> + <p> + The state of the connection to the manager: + </p> + <dl> + <dt><code>VOID</code></dt> + <dd>Connection is disabled.</dd> + + <dt><code>BACKOFF</code></dt> + <dd>Attempting to reconnect at an increasing period.</dd> + + <dt><code>CONNECTING</code></dt> + <dd>Attempting to connect.</dd> + + <dt><code>ACTIVE</code></dt> + <dd>Connected, remote host responsive.</dd> + + <dt><code>IDLE</code></dt> + <dd>Connection is idle. Waiting for response to keep-alive.</dd> + </dl> + <p> + These values may change in the future. They are provided only for + human consumption. + </p> + </column> + + <column name="status" key="sec_since_connect" + type='{"type": "integer", "minInteger": 0}'> + The amount of time since this client last successfully connected + to the database (in seconds). Value is empty if client has never + successfully been connected. + </column> + + <column name="status" key="sec_since_disconnect" + type='{"type": "integer", "minInteger": 0}'> + The amount of time since this client last disconnected from the + database (in seconds). Value is empty if client has never + disconnected. + </column> + + <column name="status" key="locks_held"> + Space-separated list of the names of OVSDB locks that the connection + holds. Omitted if the connection does not hold any locks. + </column> + + <column name="status" key="locks_waiting"> + Space-separated list of the names of OVSDB locks that the connection is + currently waiting to acquire. Omitted if the connection is not waiting + for any locks. + </column> + + <column name="status" key="locks_lost"> + Space-separated list of the names of OVSDB locks that the connection + has had stolen by another OVSDB client. Omitted if no locks have been + stolen from this connection. + </column> + + <column name="status" key="n_connections" + type='{"type": "integer", "minInteger": 2}'> + When <ref column="target"/> specifies a connection method that + listens for inbound connections (e.g. <code>ptcp:</code> or + <code>pssl:</code>) and more than one connection is actually active, + the value is the number of active connections. Otherwise, this + key-value pair is omitted. + </column> + + <column name="status" key="bound_port" type='{"type": "integer"}'> + When <ref column="target"/> is <code>ptcp:</code> or + <code>pssl:</code>, this is the TCP port on which the OVSDB server is + listening. (This is particularly useful when <ref + column="target"/> specifies a port of 0, allowing the kernel to + choose any available port.) + </column> + </group> + + <group title="Common Columns"> + The overall purpose of these columns is described under <code>Common + Columns</code> at the beginning of this document. + + <column name="external_ids"/> + <column name="other_config"/> + </group> + </table> + <table name="SSL"> + SSL configuration for ovn-sb database access. + + <column name="private_key"> + Name of a PEM file containing the private key used as the switch's + identity for SSL connections to the controller. + </column> + + <column name="certificate"> + Name of a PEM file containing a certificate, signed by the + certificate authority (CA) used by the controller and manager, + that certifies the switch's private key, identifying a trustworthy + switch. + </column> + + <column name="ca_cert"> + Name of a PEM file containing the CA certificate used to verify + that the switch is connected to a trustworthy controller. + </column> + + <column name="bootstrap_ca_cert"> + If set to <code>true</code>, then Open vSwitch will attempt to + obtain the CA certificate from the controller on its first SSL + connection and save it to the named PEM file. If it is successful, + it will immediately drop the connection and reconnect, and from then + on all SSL connections must be authenticated by a certificate signed + by the CA certificate thus obtained. <em>This option exposes the + SSL connection to a man-in-the-middle attack obtaining the initial + CA certificate.</em> It may still be useful for bootstrapping. + </column> + + <column name="ssl_protocols"> + List of SSL protocols to be enabled for SSL connections. The default + when this option is omitted is <code>TLSv1,TLSv1.1,TLSv1.2</code>. + </column> + + <column name="ssl_ciphers"> + List of ciphers (in OpenSSL cipher string format) to be supported + for SSL connections. The default when this option is omitted is + <code>HIGH:!aNULL:!MD5</code>. + </column> + + <group title="Common Columns"> + The overall purpose of these columns is described under <code>Common + Columns</code> at the beginning of this document. + + <column name="external_ids"/> + </group> + </table> + +</database> diff --git a/utilities/.gitignore b/utilities/.gitignore index 5321110..a8ff6e5 100644 --- a/utilities/.gitignore +++ b/utilities/.gitignore @@ -5,6 +5,8 @@ /ovn-sbctl.8 /ovn-inbctl /ovn-inbctl.8 +/ovn-isbctl +/ovn-isbctl.8 /ovn-appctl /ovn-appctl.8 /ovn-trace diff --git a/utilities/automake.mk b/utilities/automake.mk index 565ce18..efa4324 100644 --- a/utilities/automake.mk +++ b/utilities/automake.mk @@ -71,6 +71,11 @@ bin_PROGRAMS += utilities/ovn-inbctl utilities_ovn_inbctl_SOURCES = utilities/ovn-inbctl.c utilities_ovn_inbctl_LDADD = lib/libovn.la $(OVSDB_LIBDIR)/libovsdb.la $(OVS_LIBDIR)/libopenvswitch.la +# ovn-isbctl +bin_PROGRAMS += utilities/ovn-isbctl +utilities_ovn_isbctl_SOURCES = utilities/ovn-isbctl.c +utilities_ovn_isbctl_LDADD = lib/libovn.la $(OVSDB_LIBDIR)/libovsdb.la $(OVS_LIBDIR)/libopenvswitch.la + # ovn-trace bin_PROGRAMS += utilities/ovn-trace utilities_ovn_trace_SOURCES = utilities/ovn-trace.c diff --git a/utilities/ovn-isbctl.c b/utilities/ovn-isbctl.c new file mode 100644 index 0000000..a6380e8 --- /dev/null +++ b/utilities/ovn-isbctl.c @@ -0,0 +1,890 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <config.h> + +#include <ctype.h> +#include <errno.h> +#include <float.h> +#include <getopt.h> +#include <inttypes.h> +#include <signal.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "colors.h" +#include "command-line.h" +#include "compiler.h" +#include "db-ctl-base.h" +#include "dirs.h" +#include "fatal-signal.h" +#include "openvswitch/dynamic-string.h" +#include "openvswitch/json.h" +#include "openvswitch/ofp-actions.h" +#include "openvswitch/ofp-flow.h" +#include "openvswitch/ofp-print.h" +#include "openvswitch/shash.h" +#include "openvswitch/vconn.h" +#include "openvswitch/vlog.h" +#include "lib/ovn-isb-idl.h" +#include "lib/ovn-util.h" +#include "ovsdb-data.h" +#include "ovsdb-idl.h" +#include "openvswitch/poll-loop.h" +#include "process.h" +#include "sset.h" +#include "stream-ssl.h" +#include "stream.h" +#include "table.h" +#include "timeval.h" +#include "util.h" +#include "svec.h" + +VLOG_DEFINE_THIS_MODULE(isbctl); + +struct isbctl_context; + +/* --db: The database server to contact. */ +static const char *db; + +/* --oneline: Write each command's output as a single line? */ +static bool oneline; + +/* --dry-run: Do not commit any changes. */ +static bool dry_run; + +/* --timeout: Time to wait for a connection to 'db'. */ +static unsigned int timeout; + +/* Format for table output. */ +static struct table_style table_style = TABLE_STYLE_DEFAULT; + +/* The IDL we're using and the current transaction, if any. + * This is for use by isbctl_exit() only, to allow it to clean up. + * Other code should use its context arguments. */ +static struct ovsdb_idl *the_idl; +static struct ovsdb_idl_txn *the_idl_txn; +OVS_NO_RETURN static void isbctl_exit(int status); + +/* --leader-only, --no-leader-only: Only accept the leader in a cluster. */ +static int leader_only = true; + +static void isbctl_cmd_init(void); +OVS_NO_RETURN static void usage(void); +static void parse_options(int argc, char *argv[], struct shash *local_options); +static void run_prerequisites(struct ctl_command[], size_t n_commands, + struct ovsdb_idl *); +static bool do_isbctl(const char *args, struct ctl_command *, size_t n, + struct ovsdb_idl *); + +int +main(int argc, char *argv[]) +{ + struct ovsdb_idl *idl; + struct ctl_command *commands; + struct shash local_options; + unsigned int seqno; + size_t n_commands; + + set_program_name(argv[0]); + fatal_ignore_sigpipe(); + vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN); + vlog_set_levels_from_string_assert("reconnect:warn"); + + isbctl_cmd_init(); + + /* Parse command line. */ + char *args = process_escape_args(argv); + shash_init(&local_options); + parse_options(argc, argv, &local_options); + char *error = ctl_parse_commands(argc - optind, argv + optind, + &local_options, &commands, &n_commands); + if (error) { + ctl_fatal("%s", error); + } + VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG, + "Called as %s", args); + + ctl_timeout_setup(timeout); + + /* Initialize IDL. */ + idl = the_idl = ovsdb_idl_create(db, &isbrec_idl_class, false, true); + ovsdb_idl_set_leader_only(idl, leader_only); + run_prerequisites(commands, n_commands, idl); + + /* Execute the commands. + * + * 'seqno' is the database sequence number for which we last tried to + * execute our transaction. There's no point in trying to commit more than + * once for any given sequence number, because if the transaction fails + * it's because the database changed and we need to obtain an up-to-date + * view of the database before we try the transaction again. */ + seqno = ovsdb_idl_get_seqno(idl); + for (;;) { + ovsdb_idl_run(idl); + if (!ovsdb_idl_is_alive(idl)) { + int retval = ovsdb_idl_get_last_error(idl); + ctl_fatal("%s: database connection failed (%s)", + db, ovs_retval_to_string(retval)); + } + + if (seqno != ovsdb_idl_get_seqno(idl)) { + seqno = ovsdb_idl_get_seqno(idl); + if (do_isbctl(args, commands, n_commands, idl)) { + free(args); + exit(EXIT_SUCCESS); + } + } + + if (seqno == ovsdb_idl_get_seqno(idl)) { + ovsdb_idl_wait(idl); + poll_block(); + } + } +} + +static void +parse_options(int argc, char *argv[], struct shash *local_options) +{ + enum { + OPT_DB = UCHAR_MAX + 1, + OPT_ONELINE, + OPT_NO_SYSLOG, + OPT_DRY_RUN, + OPT_LOCAL, + OPT_COMMANDS, + OPT_OPTIONS, + OPT_BOOTSTRAP_CA_CERT, + VLOG_OPTION_ENUMS, + TABLE_OPTION_ENUMS, + SSL_OPTION_ENUMS, + }; + static const struct option global_long_options[] = { + {"db", required_argument, NULL, OPT_DB}, + {"no-syslog", no_argument, NULL, OPT_NO_SYSLOG}, + {"dry-run", no_argument, NULL, OPT_DRY_RUN}, + {"oneline", no_argument, NULL, OPT_ONELINE}, + {"timeout", required_argument, NULL, 't'}, + {"help", no_argument, NULL, 'h'}, + {"commands", no_argument, NULL, OPT_COMMANDS}, + {"options", no_argument, NULL, OPT_OPTIONS}, + {"leader-only", no_argument, &leader_only, true}, + {"no-leader-only", no_argument, &leader_only, false}, + {"version", no_argument, NULL, 'V'}, + VLOG_LONG_OPTIONS, + STREAM_SSL_LONG_OPTIONS, + {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, + TABLE_LONG_OPTIONS, + {NULL, 0, NULL, 0}, + }; + const int n_global_long_options = ARRAY_SIZE(global_long_options) - 1; + char *tmp, *short_options; + + struct option *options; + size_t allocated_options; + size_t n_options; + size_t i; + + tmp = ovs_cmdl_long_options_to_short_options(global_long_options); + short_options = xasprintf("+%s", tmp); + free(tmp); + + /* We want to parse both global and command-specific options here, but + * getopt_long() isn't too convenient for the job. We copy our global + * options into a dynamic array, then append all of the command-specific + * options. */ + options = xmemdup(global_long_options, sizeof global_long_options); + allocated_options = ARRAY_SIZE(global_long_options); + n_options = n_global_long_options; + ctl_add_cmd_options(&options, &n_options, &allocated_options, OPT_LOCAL); + + for (;;) { + int idx; + int c; + + c = getopt_long(argc, argv, short_options, options, &idx); + if (c == -1) { + break; + } + + switch (c) { + case OPT_DB: + db = optarg; + break; + + case OPT_ONELINE: + oneline = true; + break; + + case OPT_NO_SYSLOG: + vlog_set_levels(&this_module, VLF_SYSLOG, VLL_WARN); + break; + + case OPT_DRY_RUN: + dry_run = true; + break; + + case OPT_LOCAL: + if (shash_find(local_options, options[idx].name)) { + ctl_fatal("'%s' option specified multiple times", + options[idx].name); + } + shash_add_nocopy(local_options, + xasprintf("--%s", options[idx].name), + nullable_xstrdup(optarg)); + break; + + case 'h': + usage(); + + case OPT_COMMANDS: + ctl_print_commands(); + /* fall through */ + + case OPT_OPTIONS: + ctl_print_options(global_long_options); + /* fall through */ + + case 'V': + ovs_print_version(0, 0); + printf("DB Schema %s\n", isbrec_get_db_version()); + exit(EXIT_SUCCESS); + + case 't': + if (!str_to_uint(optarg, 10, &timeout) || !timeout) { + ctl_fatal("value %s on -t or --timeout is invalid", optarg); + } + break; + + VLOG_OPTION_HANDLERS + TABLE_OPTION_HANDLERS(&table_style) + STREAM_SSL_OPTION_HANDLERS + + case OPT_BOOTSTRAP_CA_CERT: + stream_ssl_set_ca_cert_file(optarg, true); + break; + + case '?': + exit(EXIT_FAILURE); + + default: + abort(); + + case 0: + break; + } + } + free(short_options); + + if (!db) { + db = default_isb_db(); + } + + for (i = n_global_long_options; options[i].name; i++) { + free(CONST_CAST(char *, options[i].name)); + } + free(options); +} + +static void +usage(void) +{ + printf("\ +%s: OVN interconnection southbound DB management utility\n\ +\n\ +usage: %s [OPTIONS] COMMAND [ARG...]\n\ +\n\ +General commands:\n\ + show print overview of database contents\n\ +\n\ +Connection commands:\n\ + get-connection print the connections\n\ + del-connection delete the connections\n\ + [--inactivity-probe=MSECS]\n\ + set-connection TARGET... set the list of connections to TARGET...\n\ +\n\ +SSL commands:\n\ + get-ssl print the SSL configuration\n\ + del-ssl delete the SSL configuration\n\ + set-ssl PRIV-KEY CERT CA-CERT [SSL-PROTOS [SSL-CIPHERS]] \ +set the SSL configuration\n\ +\n\ +%s\ +%s\ +\n\ +Options:\n\ + --db=DATABASE connect to DATABASE\n\ + (default: %s)\n\ + --no-leader-only accept any cluster member, not just the leader\n\ + -t, --timeout=SECS wait at most SECS seconds\n\ + --dry-run do not commit changes to database\n\ + --oneline print exactly one line of output per command\n", + program_name, program_name, ctl_get_db_cmd_usage(), + ctl_list_db_tables_usage(), default_isb_db()); + table_usage(); + vlog_usage(); + printf("\ + --no-syslog equivalent to --verbose=isbctl:syslog:warn\n"); + printf("\n\ +Other options:\n\ + -h, --help display this help message\n\ + -V, --version display version information\n"); + stream_usage("database", true, true, true); + exit(EXIT_SUCCESS); +} + + +/* ovs-isbctl specific context. Inherits the 'struct ctl_context' as base. */ +struct isbctl_context { + struct ctl_context base; + + /* A cache of the contents of the database. + * + * A command that needs to use any of this information must first call + * isbctl_context_populate_cache(). A command that changes anything that + * could invalidate the cache must either call + * isbctl_context_invalidate_cache() or manually update the cache to + * maintain its correctness. */ + bool cache_valid; +}; + +/* Casts 'base' into 'struct isbctl_context'. */ +static struct isbctl_context * +isbctl_context_cast(struct ctl_context *base) +{ + return CONTAINER_OF(base, struct isbctl_context, base); +} + +static void +isbctl_context_invalidate_cache(struct ctl_context *ctx) +{ + struct isbctl_context *isbctl_ctx = isbctl_context_cast(ctx); + + if (!isbctl_ctx->cache_valid) { + return; + } + isbctl_ctx->cache_valid = false; +} + +OVS_UNUSED static void +isbctl_context_populate_cache(struct ctl_context *ctx) +{ + struct isbctl_context *isbctl_ctx = isbctl_context_cast(ctx); + + if (isbctl_ctx->cache_valid) { + /* Cache is already populated. */ + return; + } + isbctl_ctx->cache_valid = true; +} + +OVS_UNUSED static void +pre_get_info(struct ctl_context *ctx) +{ + ovsdb_idl_add_column(ctx->idl, &isbrec_availability_zone_col_name); +} + +static struct cmd_show_table cmd_show_tables[] = { + {&isbrec_table_availability_zone, + &isbrec_availability_zone_col_name, + {NULL}, + {NULL, NULL, NULL}}, + + {NULL, NULL, {NULL, NULL, NULL}, {NULL, NULL, NULL}}, +}; + +static void +isbctl_init(struct ctl_context *ctx OVS_UNUSED) +{ +} + +static void +verify_connections(struct ctl_context *ctx) +{ + const struct isbrec_isb_global *isb_global = + isbrec_isb_global_first(ctx->idl); + const struct isbrec_connection *conn; + + isbrec_isb_global_verify_connections(isb_global); + + ISBREC_CONNECTION_FOR_EACH(conn, ctx->idl) { + isbrec_connection_verify_target(conn); + } +} + +static void +pre_connection(struct ctl_context *ctx) +{ + ovsdb_idl_add_column(ctx->idl, &isbrec_isb_global_col_connections); + ovsdb_idl_add_column(ctx->idl, &isbrec_connection_col_target); + ovsdb_idl_add_column(ctx->idl, &isbrec_connection_col_inactivity_probe); +} + +static void +cmd_get_connection(struct ctl_context *ctx) +{ + const struct isbrec_connection *conn; + struct svec targets; + size_t i; + + verify_connections(ctx); + + /* Print the targets in sorted order for reproducibility. */ + svec_init(&targets); + + ISBREC_CONNECTION_FOR_EACH(conn, ctx->idl) { + svec_add(&targets, conn->target); + } + + svec_sort_unique(&targets); + for (i = 0; i < targets.n; i++) { + ds_put_format(&ctx->output, "%s\n", targets.names[i]); + } + svec_destroy(&targets); +} + +static void +delete_connections(struct ctl_context *ctx) +{ + const struct isbrec_isb_global *isb_global = + isbrec_isb_global_first(ctx->idl); + const struct isbrec_connection *conn, *next; + + /* Delete Manager rows pointed to by 'connection_options' column. */ + ISBREC_CONNECTION_FOR_EACH_SAFE(conn, next, ctx->idl) { + isbrec_connection_delete(conn); + } + + /* Delete 'Manager' row refs in 'manager_options' column. */ + isbrec_isb_global_set_connections(isb_global, NULL, 0); +} + +static void +cmd_del_connection(struct ctl_context *ctx) +{ + verify_connections(ctx); + delete_connections(ctx); +} + +static void +insert_connections(struct ctl_context *ctx, char *targets[], size_t n) +{ + const struct isbrec_isb_global *isb_global = + isbrec_isb_global_first(ctx->idl); + struct isbrec_connection **connections; + size_t i, conns=0; + const char *inactivity_probe = shash_find_data(&ctx->options, + "--inactivity-probe"); + + /* Insert each connection in a new row in Connection table. */ + connections = xmalloc(n * sizeof *connections); + for (i = 0; i < n; i++) { + if (stream_verify_name(targets[i]) && + pstream_verify_name(targets[i])) { + VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]); + } + + connections[conns] = isbrec_connection_insert(ctx->txn); + isbrec_connection_set_target(connections[conns], targets[i]); + if (inactivity_probe) { + int64_t msecs = atoll(inactivity_probe); + isbrec_connection_set_inactivity_probe(connections[conns], + &msecs, 1); + } + conns++; + } + + /* Store uuids of new connection rows in 'connection' column. */ + isbrec_isb_global_set_connections(isb_global, connections, conns); + free(connections); +} + +static void +cmd_set_connection(struct ctl_context *ctx) +{ + const size_t n = ctx->argc - 1; + + verify_connections(ctx); + delete_connections(ctx); + insert_connections(ctx, &ctx->argv[1], n); +} + +static void +pre_cmd_get_ssl(struct ctl_context *ctx) +{ + ovsdb_idl_add_column(ctx->idl, &isbrec_isb_global_col_ssl); + + ovsdb_idl_add_column(ctx->idl, &isbrec_ssl_col_private_key); + ovsdb_idl_add_column(ctx->idl, &isbrec_ssl_col_certificate); + ovsdb_idl_add_column(ctx->idl, &isbrec_ssl_col_ca_cert); + ovsdb_idl_add_column(ctx->idl, &isbrec_ssl_col_bootstrap_ca_cert); +} + +static void +cmd_get_ssl(struct ctl_context *ctx) +{ + const struct isbrec_isb_global *isb_global = + isbrec_isb_global_first(ctx->idl); + const struct isbrec_ssl *ssl = isbrec_ssl_first(ctx->idl); + + isbrec_isb_global_verify_ssl(isb_global); + if (ssl) { + isbrec_ssl_verify_private_key(ssl); + isbrec_ssl_verify_certificate(ssl); + isbrec_ssl_verify_ca_cert(ssl); + isbrec_ssl_verify_bootstrap_ca_cert(ssl); + + ds_put_format(&ctx->output, "Private key: %s\n", ssl->private_key); + ds_put_format(&ctx->output, "Certificate: %s\n", ssl->certificate); + ds_put_format(&ctx->output, "CA Certificate: %s\n", ssl->ca_cert); + ds_put_format(&ctx->output, "Bootstrap: %s\n", + ssl->bootstrap_ca_cert ? "true" : "false"); + } +} + +static void +pre_cmd_del_ssl(struct ctl_context *ctx) +{ + ovsdb_idl_add_column(ctx->idl, &isbrec_isb_global_col_ssl); +} + +static void +cmd_del_ssl(struct ctl_context *ctx) +{ + const struct isbrec_isb_global *isb_global = + isbrec_isb_global_first(ctx->idl); + const struct isbrec_ssl *ssl = isbrec_ssl_first(ctx->idl); + + if (ssl) { + isbrec_isb_global_verify_ssl(isb_global); + isbrec_ssl_delete(ssl); + isbrec_isb_global_set_ssl(isb_global, NULL); + } +} + +static void +pre_cmd_set_ssl(struct ctl_context *ctx) +{ + ovsdb_idl_add_column(ctx->idl, &isbrec_isb_global_col_ssl); +} + +static void +cmd_set_ssl(struct ctl_context *ctx) +{ + bool bootstrap = shash_find(&ctx->options, "--bootstrap"); + const struct isbrec_isb_global *isb_global = + isbrec_isb_global_first(ctx->idl); + const struct isbrec_ssl *ssl = isbrec_ssl_first(ctx->idl); + + isbrec_isb_global_verify_ssl(isb_global); + if (ssl) { + isbrec_ssl_delete(ssl); + } + ssl = isbrec_ssl_insert(ctx->txn); + + isbrec_ssl_set_private_key(ssl, ctx->argv[1]); + isbrec_ssl_set_certificate(ssl, ctx->argv[2]); + isbrec_ssl_set_ca_cert(ssl, ctx->argv[3]); + + isbrec_ssl_set_bootstrap_ca_cert(ssl, bootstrap); + + if (ctx->argc == 5) { + isbrec_ssl_set_ssl_protocols(ssl, ctx->argv[4]); + } else if (ctx->argc == 6) { + isbrec_ssl_set_ssl_protocols(ssl, ctx->argv[4]); + isbrec_ssl_set_ssl_ciphers(ssl, ctx->argv[5]); + } + + isbrec_isb_global_set_ssl(isb_global, ssl); +} + + +static const struct ctl_table_class tables[ISBREC_N_TABLES] = { + [ISBREC_TABLE_AVAILABILITY_ZONE].row_ids[0] = + {&isbrec_availability_zone_col_name, NULL, NULL}, +}; + + +static void +isbctl_context_init_command(struct isbctl_context *isbctl_ctx, + struct ctl_command *command) +{ + ctl_context_init_command(&isbctl_ctx->base, command); +} + +static void +isbctl_context_init(struct isbctl_context *isbctl_ctx, + struct ctl_command *command, struct ovsdb_idl *idl, + struct ovsdb_idl_txn *txn, + struct ovsdb_symbol_table *symtab) +{ + ctl_context_init(&isbctl_ctx->base, command, idl, txn, symtab, + isbctl_context_invalidate_cache); + isbctl_ctx->cache_valid = false; +} + +static void +isbctl_context_done_command(struct isbctl_context *isbctl_ctx, + struct ctl_command *command) +{ + ctl_context_done_command(&isbctl_ctx->base, command); +} + +static void +isbctl_context_done(struct isbctl_context *isbctl_ctx, + struct ctl_command *command) +{ + ctl_context_done(&isbctl_ctx->base, command); +} + +static void +run_prerequisites(struct ctl_command *commands, size_t n_commands, + struct ovsdb_idl *idl) +{ + ovsdb_idl_add_table(idl, &isbrec_table_isb_global); + + for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { + if (c->syntax->prerequisites) { + struct isbctl_context isbctl_ctx; + + ds_init(&c->output); + c->table = NULL; + + isbctl_context_init(&isbctl_ctx, c, idl, NULL, NULL); + (c->syntax->prerequisites)(&isbctl_ctx.base); + if (isbctl_ctx.base.error) { + ctl_fatal("%s", isbctl_ctx.base.error); + } + isbctl_context_done(&isbctl_ctx, c); + + ovs_assert(!c->output.string); + ovs_assert(!c->table); + } + } +} + +static bool +do_isbctl(const char *args, struct ctl_command *commands, size_t n_commands, + struct ovsdb_idl *idl) +{ + struct ovsdb_idl_txn *txn; + enum ovsdb_idl_txn_status status; + struct ovsdb_symbol_table *symtab; + struct isbctl_context isbctl_ctx; + struct ctl_command *c; + struct shash_node *node; + + txn = the_idl_txn = ovsdb_idl_txn_create(idl); + if (dry_run) { + ovsdb_idl_txn_set_dry_run(txn); + } + + ovsdb_idl_txn_add_comment(txn, "ovs-isbctl: %s", args); + + const struct isbrec_isb_global *isb = isbrec_isb_global_first(idl); + if (!isb) { + /* XXX add verification that table is empty */ + isbrec_isb_global_insert(txn); + } + + symtab = ovsdb_symbol_table_create(); + for (c = commands; c < &commands[n_commands]; c++) { + ds_init(&c->output); + c->table = NULL; + } + isbctl_context_init(&isbctl_ctx, NULL, idl, txn, symtab); + for (c = commands; c < &commands[n_commands]; c++) { + isbctl_context_init_command(&isbctl_ctx, c); + if (c->syntax->run) { + (c->syntax->run)(&isbctl_ctx.base); + } + if (isbctl_ctx.base.error) { + ctl_fatal("%s", isbctl_ctx.base.error); + } + isbctl_context_done_command(&isbctl_ctx, c); + + if (isbctl_ctx.base.try_again) { + isbctl_context_done(&isbctl_ctx, NULL); + goto try_again; + } + } + isbctl_context_done(&isbctl_ctx, NULL); + + SHASH_FOR_EACH (node, &symtab->sh) { + struct ovsdb_symbol *symbol = node->data; + if (!symbol->created) { + ctl_fatal("row id \"%s\" is referenced but never created (e.g. " + "with \"-- --id=%s create ...\")", + node->name, node->name); + } + if (!symbol->strong_ref) { + if (!symbol->weak_ref) { + VLOG_WARN("row id \"%s\" was created but no reference to it " + "was inserted, so it will not actually appear in " + "the database", node->name); + } else { + VLOG_WARN("row id \"%s\" was created but only a weak " + "reference to it was inserted, so it will not " + "actually appear in the database", node->name); + } + } + } + + status = ovsdb_idl_txn_commit_block(txn); + if (status == TXN_UNCHANGED || status == TXN_SUCCESS) { + for (c = commands; c < &commands[n_commands]; c++) { + if (c->syntax->postprocess) { + isbctl_context_init(&isbctl_ctx, c, idl, txn, symtab); + (c->syntax->postprocess)(&isbctl_ctx.base); + if (isbctl_ctx.base.error) { + ctl_fatal("%s", isbctl_ctx.base.error); + } + isbctl_context_done(&isbctl_ctx, c); + } + } + } + + switch (status) { + case TXN_UNCOMMITTED: + case TXN_INCOMPLETE: + OVS_NOT_REACHED(); + + case TXN_ABORTED: + /* Should not happen--we never call ovsdb_idl_txn_abort(). */ + ctl_fatal("transaction aborted"); + + case TXN_UNCHANGED: + case TXN_SUCCESS: + break; + + case TXN_TRY_AGAIN: + goto try_again; + + case TXN_ERROR: + ctl_fatal("transaction error: %s", ovsdb_idl_txn_get_error(txn)); + + case TXN_NOT_LOCKED: + /* Should not happen--we never call ovsdb_idl_set_lock(). */ + ctl_fatal("database not locked"); + + default: + OVS_NOT_REACHED(); + } + + ovsdb_symbol_table_destroy(symtab); + + for (c = commands; c < &commands[n_commands]; c++) { + struct ds *ds = &c->output; + + if (c->table) { + table_print(c->table, &table_style); + } else if (oneline) { + size_t j; + + ds_chomp(ds, '\n'); + for (j = 0; j < ds->length; j++) { + int ch = ds->string[j]; + switch (ch) { + case '\n': + fputs("\\n", stdout); + break; + + case '\\': + fputs("\\\\", stdout); + break; + + default: + putchar(ch); + } + } + putchar('\n'); + } else { + fputs(ds_cstr(ds), stdout); + } + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + + shash_destroy_free_data(&c->options); + } + free(commands); + ovsdb_idl_txn_destroy(txn); + ovsdb_idl_destroy(idl); + + return true; + +try_again: + /* Our transaction needs to be rerun, or a prerequisite was not met. Free + * resources and return so that the caller can try again. */ + ovsdb_idl_txn_abort(txn); + ovsdb_idl_txn_destroy(txn); + the_idl_txn = NULL; + + ovsdb_symbol_table_destroy(symtab); + for (c = commands; c < &commands[n_commands]; c++) { + ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); + } + return false; +} + +/* Frees the current transaction and the underlying IDL and then calls + * exit(status). + * + * Freeing the transaction and the IDL is not strictly necessary, but it makes + * for a clean memory leak report from valgrind in the normal case. That makes + * it easier to notice real memory leaks. */ +static void +isbctl_exit(int status) +{ + if (the_idl_txn) { + ovsdb_idl_txn_abort(the_idl_txn); + ovsdb_idl_txn_destroy(the_idl_txn); + } + ovsdb_idl_destroy(the_idl); + exit(status); +} + +static const struct ctl_command_syntax isbctl_commands[] = { + { "init", 0, 0, "", NULL, isbctl_init, NULL, "", RW }, + + /* Connection commands. */ + {"get-connection", 0, 0, "", pre_connection, cmd_get_connection, NULL, "", + RO}, + {"del-connection", 0, 0, "", pre_connection, cmd_del_connection, NULL, "", + RW}, + {"set-connection", 1, INT_MAX, "TARGET...", pre_connection, + cmd_set_connection, NULL, "--inactivity-probe=", RW}, + + /* SSL commands. */ + {"get-ssl", 0, 0, "", pre_cmd_get_ssl, cmd_get_ssl, NULL, "", RO}, + {"del-ssl", 0, 0, "", pre_cmd_del_ssl, cmd_del_ssl, NULL, "", RW}, + {"set-ssl", 3, 5, + "PRIVATE-KEY CERTIFICATE CA-CERT [SSL-PROTOS [SSL-CIPHERS]]", + pre_cmd_set_ssl, cmd_set_ssl, NULL, "--bootstrap", RW}, + + {NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, RO}, +}; + +/* Registers isbctl and common db commands. */ +static void +isbctl_cmd_init(void) +{ + ctl_init(&isbrec_idl_class, isbrec_table_classes, tables, + cmd_show_tables, isbctl_exit); + ctl_register_commands(isbctl_commands); +} -- 2.1.0 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
