Lines Matching +full:mctp +full:- +full:handling

1 // SPDX-License-Identifier: GPL-2.0
3 * Management Component Transport Protocol (MCTP) - device implementation.
11 #include <linux/mctp.h>
18 #include <net/mctp.h>
33 struct mctp_dev *mdev = rcu_dereference(dev->mctp_ptr); in __mctp_dev_get()
39 if (!refcount_inc_not_zero(&mdev->refs)) in __mctp_dev_get()
49 return rtnl_dereference(dev->mctp_ptr); in mctp_dev_get_rtnl()
71 return -EMSGSIZE; in mctp_fill_addrinfo()
74 hdr->ifa_family = AF_MCTP; in mctp_fill_addrinfo()
75 hdr->ifa_prefixlen = 0; in mctp_fill_addrinfo()
76 hdr->ifa_flags = 0; in mctp_fill_addrinfo()
77 hdr->ifa_scope = 0; in mctp_fill_addrinfo()
78 hdr->ifa_index = mdev->dev->ifindex; in mctp_fill_addrinfo()
92 return -EMSGSIZE; in mctp_fill_addrinfo()
98 struct mctp_dump_cb *mcb = (void *)cb->ctx; in mctp_dump_dev_addrinfo()
102 portid = NETLINK_CB(cb->skb).portid; in mctp_dump_dev_addrinfo()
103 seq = cb->nlh->nlmsg_seq; in mctp_dump_dev_addrinfo()
104 for (; mcb->a_idx < mdev->num_addrs; mcb->a_idx++) { in mctp_dump_dev_addrinfo()
105 rc = mctp_fill_addrinfo(skb, mdev, mdev->addrs[mcb->a_idx], in mctp_dump_dev_addrinfo()
116 struct mctp_dump_cb *mcb = (void *)cb->ctx; in mctp_dump_addrinfo()
117 struct net *net = sock_net(skb->sk); in mctp_dump_addrinfo()
125 hdr = nlmsg_data(cb->nlh); in mctp_dump_addrinfo()
127 ifindex = hdr->ifa_index; in mctp_dump_addrinfo()
130 for (; mcb->h < NETDEV_HASHENTRIES; mcb->h++, mcb->idx = 0) { in mctp_dump_addrinfo()
132 head = &net->dev_index_head[mcb->h]; in mctp_dump_addrinfo()
134 if (idx >= mcb->idx && in mctp_dump_addrinfo()
135 (ifindex == 0 || ifindex == dev->ifindex)) { in mctp_dump_addrinfo()
149 mcb->a_idx = 0; in mctp_dump_addrinfo()
154 mcb->idx = idx; in mctp_dump_addrinfo()
156 return skb->len; in mctp_dump_addrinfo()
163 struct net *net = dev_net(mdev->dev); in mctp_addr_notify()
165 int rc = -ENOBUFS; in mctp_addr_notify()
172 portid, req_nlh->nlmsg_seq, 0); in mctp_addr_notify()
174 WARN_ON_ONCE(rc == -EMSGSIZE); in mctp_addr_notify()
193 struct net *net = sock_net(skb->sk); in mctp_rtm_newaddr()
215 return -EINVAL; in mctp_rtm_newaddr()
218 dev = __dev_get_by_index(net, ifm->ifa_index); in mctp_rtm_newaddr()
220 return -ENODEV; in mctp_rtm_newaddr()
224 return -ENODEV; in mctp_rtm_newaddr()
226 if (!mctp_address_unicast(addr->s_addr)) in mctp_rtm_newaddr()
227 return -EINVAL; in mctp_rtm_newaddr()
230 if (memchr(mdev->addrs, addr->s_addr, mdev->num_addrs)) in mctp_rtm_newaddr()
231 return -EEXIST; in mctp_rtm_newaddr()
233 tmp_addrs = kmalloc(mdev->num_addrs + 1, GFP_KERNEL); in mctp_rtm_newaddr()
235 return -ENOMEM; in mctp_rtm_newaddr()
236 memcpy(tmp_addrs, mdev->addrs, mdev->num_addrs); in mctp_rtm_newaddr()
237 tmp_addrs[mdev->num_addrs] = addr->s_addr; in mctp_rtm_newaddr()
240 spin_lock_irqsave(&mdev->addrs_lock, flags); in mctp_rtm_newaddr()
241 mdev->num_addrs++; in mctp_rtm_newaddr()
242 swap(mdev->addrs, tmp_addrs); in mctp_rtm_newaddr()
243 spin_unlock_irqrestore(&mdev->addrs_lock, flags); in mctp_rtm_newaddr()
247 mctp_addr_notify(mdev, addr->s_addr, RTM_NEWADDR, skb, nlh); in mctp_rtm_newaddr()
248 mctp_route_add_local(mdev, addr->s_addr); in mctp_rtm_newaddr()
256 struct net *net = sock_net(skb->sk); in mctp_rtm_deladdr()
278 return -EINVAL; in mctp_rtm_deladdr()
281 dev = __dev_get_by_index(net, ifm->ifa_index); in mctp_rtm_deladdr()
283 return -ENODEV; in mctp_rtm_deladdr()
287 return -ENODEV; in mctp_rtm_deladdr()
289 pos = memchr(mdev->addrs, addr->s_addr, mdev->num_addrs); in mctp_rtm_deladdr()
291 return -ENOENT; in mctp_rtm_deladdr()
293 rc = mctp_route_remove_local(mdev, addr->s_addr); in mctp_rtm_deladdr()
294 // we can ignore -ENOENT in the case a route was already removed in mctp_rtm_deladdr()
295 if (rc < 0 && rc != -ENOENT) in mctp_rtm_deladdr()
298 spin_lock_irqsave(&mdev->addrs_lock, flags); in mctp_rtm_deladdr()
299 memmove(pos, pos + 1, mdev->num_addrs - 1 - (pos - mdev->addrs)); in mctp_rtm_deladdr()
300 mdev->num_addrs--; in mctp_rtm_deladdr()
301 spin_unlock_irqrestore(&mdev->addrs_lock, flags); in mctp_rtm_deladdr()
303 mctp_addr_notify(mdev, addr->s_addr, RTM_DELADDR, skb, nlh); in mctp_rtm_deladdr()
310 refcount_inc(&mdev->refs); in mctp_dev_hold()
315 if (mdev && refcount_dec_and_test(&mdev->refs)) { in mctp_dev_put()
316 kfree(mdev->addrs); in mctp_dev_put()
317 dev_put(mdev->dev); in mctp_dev_put()
323 __must_hold(&key->lock) in mctp_dev_release_key()
327 if (dev->ops && dev->ops->release_flow) in mctp_dev_release_key()
328 dev->ops->release_flow(dev, key); in mctp_dev_release_key()
329 key->dev = NULL; in mctp_dev_release_key()
334 __must_hold(&key->lock) in mctp_dev_set_key()
337 key->dev = dev; in mctp_dev_set_key()
348 return ERR_PTR(-ENOMEM); in mctp_add_dev()
350 spin_lock_init(&mdev->addrs_lock); in mctp_add_dev()
352 mdev->net = mctp_default_net(dev_net(dev)); in mctp_add_dev()
355 refcount_set(&mdev->refs, 1); in mctp_add_dev()
356 rcu_assign_pointer(dev->mctp_ptr, mdev); in mctp_add_dev()
359 mdev->dev = dev; in mctp_add_dev()
371 return -ENODATA; in mctp_fill_link_af()
372 if (nla_put_u32(skb, IFLA_MCTP_NET, mdev->net)) in mctp_fill_link_af()
373 return -EMSGSIZE; in mctp_fill_link_af()
374 if (nla_put_u8(skb, IFLA_MCTP_PHYS_BINDING, mdev->binding)) in mctp_fill_link_af()
375 return -EMSGSIZE; in mctp_fill_link_af()
416 WRITE_ONCE(mdev->net, nla_get_u32(tb[IFLA_MCTP_NET])); in mctp_set_link_af()
421 /* Matches netdev types that should have MCTP handling */
425 return dev->type == ARPHRD_MCTP || in mctp_known()
426 dev->type == ARPHRD_LOOPBACK || in mctp_known()
427 dev->type == ARPHRD_NONE; in mctp_known()
438 RCU_INIT_POINTER(mdev->dev->mctp_ptr, NULL); in mctp_unregister()
451 if (rtnl_dereference(dev->mctp_ptr)) in mctp_register()
495 mdev->ops = ops; in mctp_register_netdevice()
496 mdev->binding = binding; in mctp_register_netdevice()