net/openvswitch/vport-netdev.c
Source file repositories/reference/linux-study-clean/net/openvswitch/vport-netdev.c
File Facts
- System
- Linux kernel
- Corpus path
net/openvswitch/vport-netdev.c- Extension
.c- Size
- 6206 bytes
- Lines
- 255
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/if_arp.hlinux/if_bridge.hlinux/if_vlan.hlinux/kernel.hlinux/llc.hlinux/rtnetlink.hlinux/skbuff.hlinux/openvswitch.hlinux/export.hnet/ip_tunnels.hnet/rtnetlink.hdatapath.hvport.hvport-internal_dev.hvport-netdev.h
Detected Declarations
function netdev_port_receivefunction netdev_frame_hookfunction dp_device_eventfunction vport_netdev_freefunction ovs_netdev_detach_devfunction netdev_destroyfunction ovs_netdev_tunnel_destroyfunction ovs_netdev_initfunction ovs_netdev_exitexport ovs_netdev_linkexport ovs_netdev_tunnel_destroy
Annotated Snippet
ovs_is_internal_dev(vport->dev)) {
err = -EINVAL;
goto error_put;
}
return ovs_netdev_link(vport, false);
error_put:
netdev_put(vport->dev, &vport->dev_tracker);
error_free_vport:
ovs_vport_free(vport);
return ERR_PTR(err);
}
static void vport_netdev_free(struct rcu_head *rcu)
{
struct vport *vport = container_of(rcu, struct vport, rcu);
netdev_put(vport->dev, &vport->dev_tracker);
ovs_vport_free(vport);
}
void ovs_netdev_detach_dev(struct vport *vport)
{
ASSERT_RTNL();
netdev_rx_handler_unregister(vport->dev);
netdev_upper_dev_unlink(vport->dev,
netdev_master_upper_dev_get(vport->dev));
dev_set_promiscuity(vport->dev, -1);
/* paired with smp_mb() in netdev_destroy() */
smp_wmb();
vport->dev->priv_flags &= ~IFF_OVS_DATAPATH;
}
static void netdev_destroy(struct vport *vport)
{
/* When called from ovs_db_notify_wq() after a dp_device_event(), the
* port has already been detached, so we can avoid taking the RTNL by
* checking this first.
*/
if (netif_is_ovs_port(vport->dev)) {
rtnl_lock();
/* Check again while holding the lock to ensure we don't race
* with the netdev notifier and detach twice.
*/
if (netif_is_ovs_port(vport->dev))
ovs_netdev_detach_dev(vport);
rtnl_unlock();
}
/* paired with smp_wmb() in ovs_netdev_detach_dev() */
smp_mb();
call_rcu(&vport->rcu, vport_netdev_free);
}
void ovs_netdev_tunnel_destroy(struct vport *vport)
{
rtnl_lock();
if (netif_is_ovs_port(vport->dev))
ovs_netdev_detach_dev(vport);
/* We can be invoked by both explicit vport deletion and
* underlying netdev deregistration; delete the link only
* if it's not already shutting down.
*/
if (vport->dev->reg_state == NETREG_REGISTERED)
rtnl_delete_link(vport->dev, 0, NULL);
/* We can't put the device reference yet, since it can still be in
* use, but rtnl_unlock()->netdev_run_todo() will block until all
* the references are released, so the RCU call must be before it.
*/
call_rcu(&vport->rcu, vport_netdev_free);
rtnl_unlock();
}
EXPORT_SYMBOL_GPL(ovs_netdev_tunnel_destroy);
/* Returns null if this device is not attached to a datapath. */
struct vport *ovs_netdev_get_vport(struct net_device *dev)
{
if (likely(netif_is_ovs_port(dev)))
return (struct vport *)
rcu_dereference_rtnl(dev->rx_handler_data);
else
return NULL;
}
static struct vport_ops ovs_netdev_vport_ops = {
Annotation
- Immediate include surface: `linux/if_arp.h`, `linux/if_bridge.h`, `linux/if_vlan.h`, `linux/kernel.h`, `linux/llc.h`, `linux/rtnetlink.h`, `linux/skbuff.h`, `linux/openvswitch.h`.
- Detected declarations: `function netdev_port_receive`, `function netdev_frame_hook`, `function dp_device_event`, `function vport_netdev_free`, `function ovs_netdev_detach_dev`, `function netdev_destroy`, `function ovs_netdev_tunnel_destroy`, `function ovs_netdev_init`, `function ovs_netdev_exit`, `export ovs_netdev_link`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.