Lines Matching refs:rt
478 static unsigned int mctp_route_mtu(struct mctp_route *rt) in mctp_route_mtu() argument
480 return rt->mtu ?: READ_ONCE(rt->dev->dev->mtu); in mctp_route_mtu()
526 static void mctp_route_release(struct mctp_route *rt) in mctp_route_release() argument
528 if (refcount_dec_and_test(&rt->refs)) { in mctp_route_release()
529 mctp_dev_put(rt->dev); in mctp_route_release()
530 kfree_rcu(rt, rcu); in mctp_route_release()
537 struct mctp_route *rt; in mctp_route_alloc() local
539 rt = kzalloc(sizeof(*rt), GFP_KERNEL); in mctp_route_alloc()
540 if (!rt) in mctp_route_alloc()
543 INIT_LIST_HEAD(&rt->list); in mctp_route_alloc()
544 refcount_set(&rt->refs, 1); in mctp_route_alloc()
545 rt->output = mctp_route_discard; in mctp_route_alloc()
547 return rt; in mctp_route_alloc()
657 static bool mctp_rt_match_eid(struct mctp_route *rt, in mctp_rt_match_eid() argument
660 return READ_ONCE(rt->dev->net) == net && in mctp_rt_match_eid()
661 rt->min <= eid && rt->max >= eid; in mctp_rt_match_eid()
677 struct mctp_route *tmp, *rt = NULL; in mctp_route_lookup() local
683 rt = tmp; in mctp_route_lookup()
689 return rt; in mctp_route_lookup()
695 struct mctp_route *rt; in mctp_route_lookup_null() local
697 list_for_each_entry_rcu(rt, &net->mctp.routes, list) { in mctp_route_lookup_null()
698 if (rt->dev->dev == dev && rt->type == RTN_LOCAL && in mctp_route_lookup_null()
699 refcount_inc_not_zero(&rt->refs)) in mctp_route_lookup_null()
700 return rt; in mctp_route_lookup_null()
706 static int mctp_do_fragment_route(struct mctp_route *rt, struct sk_buff *skb, in mctp_do_fragment_route() argument
773 rc = rt->output(rt, skb2); in mctp_do_fragment_route()
785 int mctp_local_output(struct sock *sk, struct mctp_route *rt, in mctp_local_output() argument
803 if (rt) { in mctp_local_output()
807 if (WARN_ON(!rt->dev)) in mctp_local_output()
812 rt = &tmp_rt; in mctp_local_output()
821 rt->dev = __mctp_dev_get(dev); in mctp_local_output()
824 if (!rt->dev) in mctp_local_output()
830 rt->output = mctp_route_output; in mctp_local_output()
831 rt->mtu = 0; in mctp_local_output()
837 spin_lock_irqsave(&rt->dev->addrs_lock, flags); in mctp_local_output()
838 if (rt->dev->num_addrs == 0) { in mctp_local_output()
842 saddr = rt->dev->addrs[0]; in mctp_local_output()
845 spin_unlock_irqrestore(&rt->dev->addrs_lock, flags); in mctp_local_output()
870 skb->dev = rt->dev->dev; in mctp_local_output()
881 mtu = mctp_route_mtu(rt); in mctp_local_output()
886 rc = rt->output(rt, skb); in mctp_local_output()
888 rc = mctp_do_fragment_route(rt, skb, mtu, tag); in mctp_local_output()
893 mctp_route_release(rt); in mctp_local_output()
907 int (*rtfn)(struct mctp_route *rt, struct sk_buff *skb); in mctp_route_add()
909 struct mctp_route *rt, *ert; in mctp_route_add() local
928 rt = mctp_route_alloc(); in mctp_route_add()
929 if (!rt) in mctp_route_add()
932 rt->min = daddr_start; in mctp_route_add()
933 rt->max = daddr_start + daddr_extent; in mctp_route_add()
934 rt->mtu = mtu; in mctp_route_add()
935 rt->dev = mdev; in mctp_route_add()
936 mctp_dev_hold(rt->dev); in mctp_route_add()
937 rt->type = type; in mctp_route_add()
938 rt->output = rtfn; in mctp_route_add()
943 if (mctp_rt_compare_exact(rt, ert)) { in mctp_route_add()
944 mctp_route_release(rt); in mctp_route_add()
949 list_add_rcu(&rt->list, &net->mctp.routes); in mctp_route_add()
958 struct mctp_route *rt, *tmp; in mctp_route_remove() local
970 list_for_each_entry_safe(rt, tmp, &net->mctp.routes, list) { in mctp_route_remove()
971 if (rt->dev == mdev && in mctp_route_remove()
972 rt->min == daddr_start && rt->max == daddr_end && in mctp_route_remove()
973 rt->type == type) { in mctp_route_remove()
974 list_del_rcu(&rt->list); in mctp_route_remove()
976 mctp_route_release(rt); in mctp_route_remove()
998 struct mctp_route *rt, *tmp; in mctp_route_remove_dev() local
1001 list_for_each_entry_safe(rt, tmp, &net->mctp.routes, list) { in mctp_route_remove_dev()
1002 if (rt->dev == mdev) { in mctp_route_remove_dev()
1003 list_del_rcu(&rt->list); in mctp_route_remove_dev()
1005 mctp_route_release(rt); in mctp_route_remove_dev()
1019 struct mctp_route *rt; in mctp_pkttype_receive() local
1051 rt = mctp_route_lookup(net, cb->net, mh->dest); in mctp_pkttype_receive()
1054 if (!rt && mh->dest == MCTP_ADDR_NULL && skb->pkt_type == PACKET_HOST) in mctp_pkttype_receive()
1055 rt = mctp_route_lookup_null(net, dev); in mctp_pkttype_receive()
1057 if (!rt) in mctp_pkttype_receive()
1060 rt->output(rt, skb); in mctp_pkttype_receive()
1061 mctp_route_release(rt); in mctp_pkttype_receive()
1203 static int mctp_fill_rtinfo(struct sk_buff *skb, struct mctp_route *rt, in mctp_fill_rtinfo() argument
1220 hdr->rtm_dst_len = rt->max - rt->min; in mctp_fill_rtinfo()
1226 hdr->rtm_type = rt->type; in mctp_fill_rtinfo()
1228 if (nla_put_u8(skb, RTA_DST, rt->min)) in mctp_fill_rtinfo()
1235 if (rt->mtu) { in mctp_fill_rtinfo()
1236 if (nla_put_u32(skb, RTAX_MTU, rt->mtu)) in mctp_fill_rtinfo()
1242 if (rt->dev) { in mctp_fill_rtinfo()
1243 if (nla_put_u32(skb, RTA_OIF, rt->dev->dev->ifindex)) in mctp_fill_rtinfo()
1261 struct mctp_route *rt; in mctp_dump_rtinfo() local
1273 list_for_each_entry_rcu(rt, &net->mctp.routes, list) { in mctp_dump_rtinfo()
1276 if (mctp_fill_rtinfo(skb, rt, in mctp_dump_rtinfo()
1305 struct mctp_route *rt; in mctp_routes_net_exit() local
1308 list_for_each_entry_rcu(rt, &net->mctp.routes, list) in mctp_routes_net_exit()
1309 mctp_route_release(rt); in mctp_routes_net_exit()