Lines Matching refs:key

76 static bool mctp_key_match(struct mctp_sk_key *key, mctp_eid_t local,  in mctp_key_match()  argument
79 if (!mctp_address_matches(key->local_addr, local)) in mctp_key_match()
82 if (key->peer_addr != peer) in mctp_key_match()
85 if (key->tag != tag) in mctp_key_match()
97 __acquires(&key->lock) in mctp_lookup_key()
99 struct mctp_sk_key *key, *ret; in mctp_lookup_key() local
110 hlist_for_each_entry(key, &net->mctp.keys, hlist) { in mctp_lookup_key()
111 if (!mctp_key_match(key, mh->dest, peer, tag)) in mctp_lookup_key()
114 spin_lock(&key->lock); in mctp_lookup_key()
115 if (key->valid) { in mctp_lookup_key()
116 refcount_inc(&key->refs); in mctp_lookup_key()
117 ret = key; in mctp_lookup_key()
120 spin_unlock(&key->lock); in mctp_lookup_key()
137 struct mctp_sk_key *key; in mctp_key_alloc() local
139 key = kzalloc(sizeof(*key), gfp); in mctp_key_alloc()
140 if (!key) in mctp_key_alloc()
143 key->peer_addr = peer; in mctp_key_alloc()
144 key->local_addr = local; in mctp_key_alloc()
145 key->tag = tag; in mctp_key_alloc()
146 key->sk = &msk->sk; in mctp_key_alloc()
147 key->valid = true; in mctp_key_alloc()
148 spin_lock_init(&key->lock); in mctp_key_alloc()
149 refcount_set(&key->refs, 1); in mctp_key_alloc()
150 sock_hold(key->sk); in mctp_key_alloc()
152 return key; in mctp_key_alloc()
155 void mctp_key_unref(struct mctp_sk_key *key) in mctp_key_unref() argument
159 if (!refcount_dec_and_test(&key->refs)) in mctp_key_unref()
165 spin_lock_irqsave(&key->lock, flags); in mctp_key_unref()
166 mctp_dev_release_key(key->dev, key); in mctp_key_unref()
167 spin_unlock_irqrestore(&key->lock, flags); in mctp_key_unref()
169 sock_put(key->sk); in mctp_key_unref()
170 kfree(key); in mctp_key_unref()
173 static int mctp_key_add(struct mctp_sk_key *key, struct mctp_sock *msk) in mctp_key_add() argument
188 if (mctp_key_match(tmp, key->local_addr, key->peer_addr, in mctp_key_add()
189 key->tag)) { in mctp_key_add()
200 refcount_inc(&key->refs); in mctp_key_add()
201 key->expiry = jiffies + mctp_key_lifetime; in mctp_key_add()
202 timer_reduce(&msk->key_expiry, key->expiry); in mctp_key_add()
204 hlist_add_head(&key->hlist, &net->mctp.keys); in mctp_key_add()
205 hlist_add_head(&key->sklist, &msk->keys); in mctp_key_add()
220 static void __mctp_key_done_in(struct mctp_sk_key *key, struct net *net, in __mctp_key_done_in() argument
222 __releases(&key->lock) in __mctp_key_done_in()
226 trace_mctp_key_release(key, reason); in __mctp_key_done_in()
227 skb = key->reasm_head; in __mctp_key_done_in()
228 key->reasm_head = NULL; in __mctp_key_done_in()
230 if (!key->manual_alloc) { in __mctp_key_done_in()
231 key->reasm_dead = true; in __mctp_key_done_in()
232 key->valid = false; in __mctp_key_done_in()
233 mctp_dev_release_key(key->dev, key); in __mctp_key_done_in()
235 spin_unlock_irqrestore(&key->lock, flags); in __mctp_key_done_in()
237 if (!key->manual_alloc) { in __mctp_key_done_in()
239 if (!hlist_unhashed(&key->hlist)) { in __mctp_key_done_in()
240 hlist_del_init(&key->hlist); in __mctp_key_done_in()
241 hlist_del_init(&key->sklist); in __mctp_key_done_in()
242 mctp_key_unref(key); in __mctp_key_done_in()
248 mctp_key_unref(key); in __mctp_key_done_in()
254 static void mctp_skb_set_flow(struct sk_buff *skb, struct mctp_sk_key *key) in mctp_skb_set_flow() argument
262 refcount_inc(&key->refs); in mctp_skb_set_flow()
263 flow->key = key; in mctp_skb_set_flow()
268 struct mctp_sk_key *key; in mctp_flow_prepare_output() local
275 key = flow->key; in mctp_flow_prepare_output()
277 if (WARN_ON(key->dev && key->dev != dev)) in mctp_flow_prepare_output()
280 mctp_dev_set_key(dev, key); in mctp_flow_prepare_output()
283 static void mctp_skb_set_flow(struct sk_buff *skb, struct mctp_sk_key *key) {} in mctp_skb_set_flow() argument
287 static int mctp_frag_queue(struct mctp_sk_key *key, struct sk_buff *skb) in mctp_frag_queue() argument
295 if (!key->reasm_head) { in mctp_frag_queue()
296 key->reasm_head = skb; in mctp_frag_queue()
297 key->reasm_tailp = &(skb_shinfo(skb)->frag_list); in mctp_frag_queue()
298 key->last_seq = this_seq; in mctp_frag_queue()
302 exp_seq = (key->last_seq + 1) & MCTP_HDR_SEQ_MASK; in mctp_frag_queue()
307 if (key->reasm_head->len + skb->len > mctp_message_maxlen) in mctp_frag_queue()
312 *key->reasm_tailp = skb; in mctp_frag_queue()
313 key->reasm_tailp = &skb->next; in mctp_frag_queue()
315 key->last_seq = this_seq; in mctp_frag_queue()
317 key->reasm_head->data_len += skb->len; in mctp_frag_queue()
318 key->reasm_head->len += skb->len; in mctp_frag_queue()
319 key->reasm_head->truesize += skb->truesize; in mctp_frag_queue()
326 struct mctp_sk_key *key, *any_key = NULL; in mctp_route_input() local
361 key = mctp_lookup_key(net, skb, mh->src, &f); in mctp_route_input()
364 if (key) { in mctp_route_input()
365 msk = container_of(key->sk, struct mctp_sock, sk); in mctp_route_input()
380 if (!key && !msk && (tag & MCTP_HDR_FLAG_TO)) in mctp_route_input()
393 if (key) { in mctp_route_input()
397 __mctp_key_done_in(key, net, f, in mctp_route_input()
399 key = NULL; in mctp_route_input()
408 if (!key) { in mctp_route_input()
409 key = mctp_key_alloc(msk, mh->dest, mh->src, in mctp_route_input()
411 if (!key) { in mctp_route_input()
419 mctp_frag_queue(key, skb); in mctp_route_input()
427 rc = mctp_key_add(key, msk); in mctp_route_input()
429 trace_mctp_key_acquire(key); in mctp_route_input()
435 mctp_key_unref(key); in mctp_route_input()
436 key = NULL; in mctp_route_input()
439 if (key->reasm_head || key->reasm_dead) { in mctp_route_input()
441 __mctp_key_done_in(key, net, f, in mctp_route_input()
444 key = NULL; in mctp_route_input()
446 rc = mctp_frag_queue(key, skb); in mctp_route_input()
450 } else if (key) { in mctp_route_input()
456 if (!key->reasm_head) in mctp_route_input()
459 rc = mctp_frag_queue(key, skb); in mctp_route_input()
465 sock_queue_rcv_skb(key->sk, key->reasm_head); in mctp_route_input()
466 key->reasm_head = NULL; in mctp_route_input()
467 __mctp_key_done_in(key, net, f, MCTP_TRACE_KEY_REPLIED); in mctp_route_input()
468 key = NULL; in mctp_route_input()
478 if (key) { in mctp_route_input()
479 spin_unlock_irqrestore(&key->lock, f); in mctp_route_input()
480 mctp_key_unref(key); in mctp_route_input()
581 static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key, in mctp_reserve_tag() argument
588 key->expiry = jiffies + mctp_key_lifetime; in mctp_reserve_tag()
589 timer_reduce(&msk->key_expiry, key->expiry); in mctp_reserve_tag()
594 hlist_add_head_rcu(&key->hlist, &mns->keys); in mctp_reserve_tag()
595 hlist_add_head_rcu(&key->sklist, &msk->keys); in mctp_reserve_tag()
596 refcount_inc(&key->refs); in mctp_reserve_tag()
608 struct mctp_sk_key *key, *tmp; in mctp_alloc_local_tag() local
617 key = mctp_key_alloc(msk, saddr, daddr, 0, GFP_KERNEL); in mctp_alloc_local_tag()
618 if (!key) in mctp_alloc_local_tag()
655 key->tag = __ffs(tagbits); in mctp_alloc_local_tag()
656 mctp_reserve_tag(net, key, msk); in mctp_alloc_local_tag()
657 trace_mctp_key_acquire(key); in mctp_alloc_local_tag()
659 key->manual_alloc = manual; in mctp_alloc_local_tag()
660 *tagp = key->tag; in mctp_alloc_local_tag()
666 mctp_key_unref(key); in mctp_alloc_local_tag()
670 return key; in mctp_alloc_local_tag()
679 struct mctp_sk_key *key, *tmp; in mctp_lookup_prealloc_tag() local
683 key = NULL; in mctp_lookup_prealloc_tag()
699 key = tmp; in mctp_lookup_prealloc_tag()
700 refcount_inc(&key->refs); in mctp_lookup_prealloc_tag()
708 if (!key) in mctp_lookup_prealloc_tag()
712 *tagp = key->tag; in mctp_lookup_prealloc_tag()
714 return key; in mctp_lookup_prealloc_tag()
868 struct mctp_sk_key *key; in mctp_local_output() local
928 key = mctp_lookup_prealloc_tag(msk, daddr, in mctp_local_output()
931 key = mctp_alloc_local_tag(msk, daddr, saddr, in mctp_local_output()
934 if (IS_ERR(key)) { in mctp_local_output()
935 rc = PTR_ERR(key); in mctp_local_output()
938 mctp_skb_set_flow(skb, key); in mctp_local_output()
940 mctp_key_unref(key); in mctp_local_output()
943 key = NULL; in mctp_local_output()