/* A query by name reported that 'port_name' is in some datapath
* other than 'dpif', but the caller wants to know about 'dpif'. */
error = ENODEV;
- } else {
+ } else if (dpif_port) {
dpif_port->name = xstrdup(reply.name);
dpif_port->type = xstrdup(netdev_vport_get_netdev_type(&reply));
dpif_port->port_no = reply.port_no;
int error;
error = get_port_by_number(dp, port_no, &port);
- if (!error) {
+ if (!error && dpif_port) {
answer_port_query(port, dpif_port);
}
return error;
int error;
error = get_port_by_name(dp, devname, &port);
- if (!error) {
+ if (!error && dpif_port) {
answer_port_query(port, dpif_port);
}
return error;
/* Removes port numbered 'port_no' from 'dpif'. */
int (*port_del)(struct dpif *dpif, uint32_t port_no);
- /* Queries 'dpif' for a port with the given 'port_no' or 'devname'. Stores
- * information about the port into '*port' if successful.
+ /* Queries 'dpif' for a port with the given 'port_no' or 'devname'.
+ * If 'port' is not null, stores information about the port into
+ * '*port' if successful.
*
- * The caller takes ownership of data in 'port' and must free it with
- * dpif_port_destroy() when it is no longer needed. */
+ * If 'port' is not null, the caller takes ownership of data in
+ * 'port' and must free it with dpif_port_destroy() when it is no
+ * longer needed. */
int (*port_query_by_number)(const struct dpif *dpif, uint32_t port_no,
struct dpif_port *port);
int (*port_query_by_name)(const struct dpif *dpif, const char *devname,
free(dpif_port->type);
}
+/* Checks if port named 'devname' exists in 'dpif'. If so, returns
+ * true; otherwise, returns false. */
+bool
+dpif_port_exists(const struct dpif *dpif, const char *devname)
+{
+ int error = dpif->dpif_class->port_query_by_name(dpif, devname, NULL);
+ if (error != 0 && error != ENODEV) {
+ VLOG_WARN_RL(&error_rl, "%s: failed to query port %s: %s",
+ dpif_name(dpif), devname, strerror(error));
+ }
+
+ return !error;
+}
+
/* Looks up port number 'port_no' in 'dpif'. On success, returns 0 and
* initializes '*port' appropriately; on failure, returns a positive errno
* value.
};
void dpif_port_clone(struct dpif_port *, const struct dpif_port *);
void dpif_port_destroy(struct dpif_port *);
+bool dpif_port_exists(const struct dpif *dpif, const char *devname);
int dpif_port_query_by_number(const struct dpif *, uint32_t port_no,
struct dpif_port *);
int dpif_port_query_by_name(const struct dpif *, const char *devname,