+ struct ovsrec_port **ports;
+ size_t i, n;
+
+ /* Remove 'port' from the bridge's list of ports. */
+ ports = xmalloc(sizeof *br->ports * br->n_ports);
+ for (i = n = 0; i < br->n_ports; i++) {
+ if (br->ports[i] != port) {
+ ports[n++] = br->ports[i];
+ }
+ }
+ ovsrec_bridge_set_ports(br, ports, n);
+ free(ports);
+
+ /* Delete all of the port's interfaces. */
+ for (i = 0; i < port->n_interfaces; i++) {
+ ovsrec_interface_delete(port->interfaces[i]);
+ }
+
+ /* Delete the port itself. */
+ ovsrec_port_delete(port);
+}
+
+/* Delete 'iface' from 'port' (which must be within 'br'). If 'iface' was
+ * 'port''s only interface, delete 'port' from 'br' also.
+ *
+ * After calling this function, 'iface' must not be referenced again. */
+static void
+del_interface(const struct ovsrec_bridge *br,
+ const struct ovsrec_port *port,
+ const struct ovsrec_interface *iface)
+{
+ if (port->n_interfaces == 1) {
+ del_port(br, port);
+ } else {
+ struct ovsrec_interface **ifaces;
+ size_t i, n;
+
+ ifaces = xmalloc(sizeof *port->interfaces * port->n_interfaces);
+ for (i = n = 0; i < port->n_interfaces; i++) {
+ if (port->interfaces[i] != iface) {
+ ifaces[n++] = port->interfaces[i];
+ }
+ }
+ ovsrec_port_set_interfaces(port, ifaces, n);
+ free(ifaces);
+ ovsrec_interface_delete(iface);
+ }
+}
+
+/* Find and return a port within 'br' named 'port_name'. */
+static const struct ovsrec_port *
+find_port(const struct ovsrec_bridge *br, const char *port_name)
+{
+ size_t i;