When the netdev is in another namespace and the operation doesn't support network namespaces, return the correct error.
Signed-off-by: Flavio Leitner <f...@redhat.com> --- lib/netdev-linux.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 120 insertions(+), 14 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index ce8df4c6b..2aee6c226 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -1342,6 +1342,11 @@ netdev_linux_send(struct netdev *netdev_, int qid OVS_UNUSED, int sock = 0; if (!is_tap_netdev(netdev_)) { + if (netdev_linux_netns_is_remote(netdev_linux_cast(netdev_))) { + error = EOPNOTSUPP; + goto free_batch; + } + sock = af_packet_sock(); if (sock < 0) { error = -sock; @@ -1401,6 +1406,10 @@ netdev_linux_set_etheraddr(struct netdev *netdev_, const struct eth_addr mac) int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } if (netdev->cache_valid & VALID_ETHERADDR) { error = netdev->ether_addr_error; @@ -1514,6 +1523,11 @@ netdev_linux_set_mtu(struct netdev *netdev_, int mtu) int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + if (netdev->cache_valid & VALID_MTU) { error = netdev->netdev_mtu_error; if (error || netdev->mtu == mtu) { @@ -1543,9 +1557,14 @@ netdev_linux_get_ifindex(const struct netdev *netdev_) int ifindex, error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } error = get_ifindex(netdev_, &ifindex); - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error ? -error : ifindex; } @@ -2086,6 +2105,11 @@ netdev_linux_get_features(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + netdev_linux_read_features(netdev); if (!netdev->get_features_error) { *current = netdev->current; @@ -2094,8 +2118,9 @@ netdev_linux_get_features(const struct netdev *netdev_, *peer = 0; /* XXX */ } error = netdev->get_features_error; - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2111,6 +2136,12 @@ netdev_linux_set_advertisements(struct netdev *netdev_, ovs_mutex_lock(&netdev->mutex); COVERAGE_INC(netdev_get_ethtool); + + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + memset(&ecmd, 0, sizeof ecmd); error = netdev_linux_do_ethtool(netdev_get_name(netdev_), &ecmd, ETHTOOL_GSET, "ETHTOOL_GSET"); @@ -2188,6 +2219,11 @@ netdev_linux_set_policing(struct netdev *netdev_, : kbits_burst); /* Stick with user-specified value. */ ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto out; + } + if (netdev->cache_valid & VALID_POLICING) { error = netdev->netdev_policing_error; if (error || (netdev->kbits_rate == kbits_rate && @@ -2324,6 +2360,11 @@ netdev_linux_get_qos(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { *typep = netdev->tc->ops->ovs_name; @@ -2331,8 +2372,9 @@ netdev_linux_get_qos(const struct netdev *netdev_, ? netdev->tc->ops->qdisc_get(netdev_, details) : 0); } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2354,6 +2396,11 @@ netdev_linux_set_qos(struct netdev *netdev_, } ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (error) { goto exit; @@ -2387,6 +2434,11 @@ netdev_linux_get_queue(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { struct tc_queue *queue = tc_find_queue(netdev_, queue_id); @@ -2394,8 +2446,9 @@ netdev_linux_get_queue(const struct netdev *netdev_, ? netdev->tc->ops->class_get(netdev_, queue, details) : ENOENT); } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2407,6 +2460,11 @@ netdev_linux_set_queue(struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { error = (queue_id < netdev->tc->ops->n_queues @@ -2414,8 +2472,9 @@ netdev_linux_set_queue(struct netdev *netdev_, ? netdev->tc->ops->class_set(netdev_, queue_id, details) : EINVAL); } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2426,6 +2485,11 @@ netdev_linux_delete_queue(struct netdev *netdev_, unsigned int queue_id) int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { if (netdev->tc->ops->class_delete) { @@ -2437,8 +2501,9 @@ netdev_linux_delete_queue(struct netdev *netdev_, unsigned int queue_id) error = EINVAL; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2451,6 +2516,11 @@ netdev_linux_get_queue_stats(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { if (netdev->tc->ops->class_get_stats) { @@ -2466,8 +2536,9 @@ netdev_linux_get_queue_stats(const struct netdev *netdev_, error = EOPNOTSUPP; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2510,10 +2581,15 @@ struct netdev_linux_queue_state { static int netdev_linux_queue_dump_start(const struct netdev *netdev_, void **statep) { - const struct netdev_linux *netdev = netdev_linux_cast(netdev_); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { if (netdev->tc->ops->class_get) { @@ -2534,8 +2610,9 @@ netdev_linux_queue_dump_start(const struct netdev *netdev_, void **statep) error = EOPNOTSUPP; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2543,11 +2620,16 @@ static int netdev_linux_queue_dump_next(const struct netdev *netdev_, void *state_, unsigned int *queue_idp, struct smap *details) { - const struct netdev_linux *netdev = netdev_linux_cast(netdev_); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct netdev_linux_queue_state *state = state_; int error = EOF; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + while (state->cur_queue < state->n_queues) { unsigned int queue_id = state->queues[state->cur_queue++]; struct tc_queue *queue = tc_find_queue(netdev_, queue_id); @@ -2558,8 +2640,9 @@ netdev_linux_queue_dump_next(const struct netdev *netdev_, void *state_, break; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2582,6 +2665,11 @@ netdev_linux_dump_queue_stats(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { struct queue_dump_state state; @@ -2608,8 +2696,9 @@ netdev_linux_dump_queue_stats(const struct netdev *netdev_, } } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2621,6 +2710,11 @@ netdev_linux_set_in4(struct netdev *netdev_, struct in_addr address, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = do_set_addr(netdev_, SIOCSIFADDR, "SIOCSIFADDR", address); if (!error) { if (address.s_addr != INADDR_ANY) { @@ -2629,8 +2723,8 @@ netdev_linux_set_in4(struct netdev *netdev_, struct in_addr address, } } +exit: ovs_mutex_unlock(&netdev->mutex); - return error; } @@ -2645,9 +2739,15 @@ netdev_linux_get_addr_list(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = netdev_get_addrs(netdev_get_name(netdev_), addr, mask, n_cnt); - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2888,6 +2988,10 @@ netdev_linux_update_flags(struct netdev *netdev_, enum netdev_flags off, ovs_mutex_lock(&netdev->mutex); if (on || off) { /* Changing flags over netlink isn't support yet. */ + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } error = update_flags(netdev, off, on, old_flagsp); } else { /* Try reading flags over netlink, or fall back to ioctl. */ @@ -2897,6 +3001,8 @@ netdev_linux_update_flags(struct netdev *netdev_, enum netdev_flags off, error = update_flags(netdev, off, on, old_flagsp); } } + +exit: ovs_mutex_unlock(&netdev->mutex); return error; } -- 2.13.6 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev