net/openvswitch/vport-internal_dev.c
Source file repositories/reference/linux-study-clean/net/openvswitch/vport-internal_dev.c
File Facts
- System
- Linux kernel
- Corpus path
net/openvswitch/vport-internal_dev.c- Extension
.c- Size
- 5671 bytes
- Lines
- 248
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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_vlan.hlinux/kernel.hlinux/netdevice.hlinux/etherdevice.hlinux/ethtool.hlinux/skbuff.hnet/dst.hnet/xfrm.hnet/rtnetlink.hdatapath.hvport-internal_dev.hvport-netdev.h
Detected Declarations
struct internal_devfunction internal_dev_xmitfunction internal_dev_openfunction internal_dev_stopfunction internal_dev_getinfofunction internal_dev_destructorfunction do_setupfunction internal_dev_destroyfunction internal_dev_recvfunction ovs_is_internal_devfunction ovs_internal_dev_rtnl_link_registerfunction ovs_internal_dev_rtnl_link_unregister
Annotated Snippet
static const struct net_device_ops internal_dev_netdev_ops = {
.ndo_open = internal_dev_open,
.ndo_stop = internal_dev_stop,
.ndo_start_xmit = internal_dev_xmit,
.ndo_set_mac_address = eth_mac_addr,
};
static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
.kind = "openvswitch",
};
static void do_setup(struct net_device *netdev)
{
ether_setup(netdev);
netdev->max_mtu = ETH_MAX_MTU;
netdev->netdev_ops = &internal_dev_netdev_ops;
netdev->priv_flags &= ~IFF_TX_SKB_SHARING;
netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH |
IFF_NO_QUEUE;
netdev->lltx = true;
netdev->needs_free_netdev = true;
netdev->priv_destructor = NULL;
netdev->ethtool_ops = &internal_dev_ethtool_ops;
netdev->rtnl_link_ops = &internal_dev_link_ops;
netdev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE |
NETIF_F_GSO_ENCAP_ALL;
netdev->vlan_features = netdev->features;
netdev->hw_enc_features = netdev->features;
netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
netdev->hw_features = netdev->features;
eth_hw_addr_random(netdev);
}
static struct vport *internal_dev_create(const struct vport_parms *parms)
{
struct vport *vport;
struct internal_dev *internal_dev;
struct net_device *dev;
int err;
vport = ovs_vport_alloc(0, &ovs_internal_vport_ops, parms);
if (IS_ERR(vport)) {
err = PTR_ERR(vport);
goto error;
}
dev = alloc_netdev(sizeof(struct internal_dev),
parms->name, NET_NAME_USER, do_setup);
vport->dev = dev;
if (!vport->dev) {
err = -ENOMEM;
goto error_free_vport;
}
dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
dev_net_set(vport->dev, ovs_dp_get_net(vport->dp));
dev->ifindex = parms->desired_ifindex;
internal_dev = internal_dev_priv(vport->dev);
internal_dev->vport = vport;
/* Restrict bridge port to current netns. */
if (vport->port_no == OVSP_LOCAL)
vport->dev->netns_immutable = true;
rtnl_lock();
err = register_netdevice(vport->dev);
if (err)
goto error_unlock;
vport->dev->priv_destructor = internal_dev_destructor;
dev_set_promiscuity(vport->dev, 1);
rtnl_unlock();
netif_start_queue(vport->dev);
return vport;
error_unlock:
rtnl_unlock();
free_netdev(dev);
error_free_vport:
ovs_vport_free(vport);
error:
return ERR_PTR(err);
Annotation
- Immediate include surface: `linux/if_vlan.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/ethtool.h`, `linux/skbuff.h`, `net/dst.h`, `net/xfrm.h`.
- Detected declarations: `struct internal_dev`, `function internal_dev_xmit`, `function internal_dev_open`, `function internal_dev_stop`, `function internal_dev_getinfo`, `function internal_dev_destructor`, `function do_setup`, `function internal_dev_destroy`, `function internal_dev_recv`, `function ovs_is_internal_dev`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.