net/mctp/device.c
Source file repositories/reference/linux-study-clean/net/mctp/device.c
File Facts
- System
- Linux kernel
- Corpus path
net/mctp/device.c- Extension
.c- Size
- 12503 bytes
- Lines
- 563
- 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/if_arp.hlinux/if_link.hlinux/mctp.hlinux/netdevice.hlinux/rcupdate.hlinux/rtnetlink.hnet/addrconf.hnet/netlink.hnet/mctp.hnet/mctpdevice.hnet/sock.h
Detected Declarations
struct mctp_dump_cbfunction mctp_addrinfo_sizefunction mctp_fill_addrinfofunction mctp_dump_dev_addrinfofunction mctp_dump_addrinfofunction mctp_addr_notifyfunction mctp_rtm_newaddrfunction mctp_rtm_deladdrfunction mctp_dev_holdfunction mctp_dev_putfunction mctp_dev_release_keyfunction mctp_dev_set_keyfunction mctp_fill_link_affunction mctp_get_link_af_sizefunction mctp_set_link_affunction mctp_knownfunction mctp_unregisterfunction mctp_registerfunction mctp_dev_notifyfunction mctp_register_netdevicefunction mctp_register_netdevfunction mctp_unregister_netdevfunction mctp_device_initfunction mctp_device_exitexport mctp_register_netdevexport mctp_unregister_netdev
Annotated Snippet
struct mctp_dump_cb {
unsigned long ifindex;
size_t a_idx;
};
/* unlocked: caller must hold rcu_read_lock.
* Returned mctp_dev has its refcount incremented, or NULL if unset.
*/
struct mctp_dev *__mctp_dev_get(const struct net_device *dev)
{
struct mctp_dev *mdev = rcu_dereference(dev->mctp_ptr);
/* RCU guarantees that any mdev is still live.
* Zero refcount implies a pending free, return NULL.
*/
if (mdev)
if (!refcount_inc_not_zero(&mdev->refs))
return NULL;
return mdev;
}
/* Returned mctp_dev does not have refcount incremented. The returned pointer
* remains live while rtnl_lock is held, as that prevents mctp_unregister()
*/
struct mctp_dev *mctp_dev_get_rtnl(const struct net_device *dev)
{
return rtnl_dereference(dev->mctp_ptr);
}
static int mctp_addrinfo_size(void)
{
return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
+ nla_total_size(1) // IFA_LOCAL
+ nla_total_size(1) // IFA_ADDRESS
;
}
/* flag should be NLM_F_MULTI for dump calls */
static int mctp_fill_addrinfo(struct sk_buff *skb,
struct mctp_dev *mdev, mctp_eid_t eid,
int msg_type, u32 portid, u32 seq, int flag)
{
struct ifaddrmsg *hdr;
struct nlmsghdr *nlh;
nlh = nlmsg_put(skb, portid, seq,
msg_type, sizeof(*hdr), flag);
if (!nlh)
return -EMSGSIZE;
hdr = nlmsg_data(nlh);
memset(hdr, 0, sizeof(*hdr));
hdr->ifa_family = AF_MCTP;
hdr->ifa_prefixlen = 0;
hdr->ifa_flags = 0;
hdr->ifa_scope = 0;
hdr->ifa_index = mdev->dev->ifindex;
if (nla_put_u8(skb, IFA_LOCAL, eid))
goto cancel;
if (nla_put_u8(skb, IFA_ADDRESS, eid))
goto cancel;
nlmsg_end(skb, nlh);
return 0;
cancel:
nlmsg_cancel(skb, nlh);
return -EMSGSIZE;
}
static int mctp_dump_dev_addrinfo(struct mctp_dev *mdev, struct sk_buff *skb,
struct netlink_callback *cb)
{
struct mctp_dump_cb *mcb = (void *)cb->ctx;
u32 portid, seq;
int rc = 0;
portid = NETLINK_CB(cb->skb).portid;
seq = cb->nlh->nlmsg_seq;
for (; mcb->a_idx < mdev->num_addrs; mcb->a_idx++) {
rc = mctp_fill_addrinfo(skb, mdev, mdev->addrs[mcb->a_idx],
RTM_NEWADDR, portid, seq, NLM_F_MULTI);
if (rc < 0)
break;
}
return rc;
Annotation
- Immediate include surface: `linux/if_arp.h`, `linux/if_link.h`, `linux/mctp.h`, `linux/netdevice.h`, `linux/rcupdate.h`, `linux/rtnetlink.h`, `net/addrconf.h`, `net/netlink.h`.
- Detected declarations: `struct mctp_dump_cb`, `function mctp_addrinfo_size`, `function mctp_fill_addrinfo`, `function mctp_dump_dev_addrinfo`, `function mctp_dump_addrinfo`, `function mctp_addr_notify`, `function mctp_rtm_newaddr`, `function mctp_rtm_deladdr`, `function mctp_dev_hold`, `function mctp_dev_put`.
- 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.