net/openvswitch/vport.c
Source file repositories/reference/linux-study-clean/net/openvswitch/vport.c
File Facts
- System
- Linux kernel
- Corpus path
net/openvswitch/vport.c- Extension
.c- Size
- 14607 bytes
- Lines
- 586
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/etherdevice.hlinux/if.hlinux/if_vlan.hlinux/jhash.hlinux/kernel.hlinux/list.hlinux/mutex.hlinux/percpu.hlinux/rcupdate.hlinux/rtnetlink.hlinux/compat.hnet/net_namespace.hlinux/module.hdatapath.hvport.hvport-internal_dev.h
Detected Declarations
function ovs_vport_initfunction ovs_vport_exitfunction __ovs_vport_ops_registerfunction ovs_vport_ops_unregisterfunction vport_privfunction vport_allocfunction configurationfunction configurationfunction ovs_vport_delfunction ovs_vport_get_statsfunction ovs_vport_get_upcall_statsfunction for_each_possible_cpufunction ovs_vport_get_optionsfunction ovs_vport_set_upcall_portidsfunction ovs_vport_get_upcall_portidsfunction skb_get_hashfunction ovs_vport_receivefunction packet_lengthfunction ovs_vport_sendexport __ovs_vport_ops_registerexport ovs_vport_ops_unregisterexport ovs_vport_allocexport ovs_vport_free
Annotated Snippet
if (IS_ERR(vport)) {
module_put(ops->owner);
return vport;
}
bucket = hash_bucket(ovs_dp_get_net(vport->dp),
ovs_vport_name(vport));
hlist_add_head_rcu(&vport->hash_node, bucket);
return vport;
}
/* Unlock to attempt module load and return -EAGAIN if load
* was successful as we need to restart the port addition
* workflow.
*/
ovs_unlock();
request_module("vport-type-%d", parms->type);
ovs_lock();
if (!ovs_vport_lookup(parms))
return ERR_PTR(-EAFNOSUPPORT);
else
return ERR_PTR(-EAGAIN);
}
/**
* ovs_vport_set_options - modify existing vport device (for kernel callers)
*
* @vport: vport to modify.
* @options: New configuration.
*
* Modifies an existing device with the specified configuration (which is
* dependent on device type). ovs_mutex must be held.
*/
int ovs_vport_set_options(struct vport *vport, struct nlattr *options)
{
if (!vport->ops->set_options)
return -EOPNOTSUPP;
return vport->ops->set_options(vport, options);
}
/**
* ovs_vport_del - delete existing vport device
*
* @vport: vport to delete.
*
* Detaches @vport from its datapath and destroys it. ovs_mutex must
* be held.
*/
void ovs_vport_del(struct vport *vport)
{
hlist_del_rcu(&vport->hash_node);
module_put(vport->ops->owner);
vport->ops->destroy(vport);
}
/**
* ovs_vport_get_stats - retrieve device stats
*
* @vport: vport from which to retrieve the stats
* @stats: location to store stats
*
* Retrieves transmit, receive, and error stats for the given device.
*
* Must be called with ovs_mutex or rcu_read_lock.
*/
void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
{
const struct rtnl_link_stats64 *dev_stats;
struct rtnl_link_stats64 temp;
dev_stats = dev_get_stats(vport->dev, &temp);
stats->rx_errors = dev_stats->rx_errors;
stats->tx_errors = dev_stats->tx_errors;
stats->tx_dropped = dev_stats->tx_dropped;
stats->rx_dropped = dev_stats->rx_dropped;
stats->rx_bytes = dev_stats->rx_bytes;
stats->rx_packets = dev_stats->rx_packets;
stats->tx_bytes = dev_stats->tx_bytes;
stats->tx_packets = dev_stats->tx_packets;
}
/**
* ovs_vport_get_upcall_stats - retrieve upcall stats
*
* @vport: vport from which to retrieve the stats.
* @skb: sk_buff where upcall stats should be appended.
*
* Retrieves upcall stats for the given device.
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/if.h`, `linux/if_vlan.h`, `linux/jhash.h`, `linux/kernel.h`, `linux/list.h`, `linux/mutex.h`, `linux/percpu.h`.
- Detected declarations: `function ovs_vport_init`, `function ovs_vport_exit`, `function __ovs_vport_ops_register`, `function ovs_vport_ops_unregister`, `function vport_priv`, `function vport_alloc`, `function configuration`, `function configuration`, `function ovs_vport_del`, `function ovs_vport_get_stats`.
- 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.