Lines Matching refs:jsk
57 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sock_pending_add() local
59 atomic_inc(&jsk->skb_pending); in j1939_sock_pending_add()
64 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sock_pending_get() local
66 return atomic_read(&jsk->skb_pending); in j1939_sock_pending_get()
71 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sock_pending_del() local
74 if (!atomic_dec_return(&jsk->skb_pending)) in j1939_sock_pending_del()
75 wake_up(&jsk->waitq); /* no pending SKB's */ in j1939_sock_pending_del()
78 static void j1939_jsk_add(struct j1939_priv *priv, struct j1939_sock *jsk) in j1939_jsk_add() argument
80 jsk->state |= J1939_SOCK_BOUND; in j1939_jsk_add()
84 list_add_tail(&jsk->list, &priv->j1939_socks); in j1939_jsk_add()
88 static void j1939_jsk_del(struct j1939_priv *priv, struct j1939_sock *jsk) in j1939_jsk_del() argument
91 list_del_init(&jsk->list); in j1939_jsk_del()
95 jsk->state &= ~J1939_SOCK_BOUND; in j1939_jsk_del()
100 struct j1939_sock *jsk = j1939_sk(session->sk); in j1939_sk_queue_session() local
103 spin_lock_bh(&jsk->sk_session_queue_lock); in j1939_sk_queue_session()
104 empty = list_empty(&jsk->sk_session_queue); in j1939_sk_queue_session()
106 list_add_tail(&session->sk_session_queue_entry, &jsk->sk_session_queue); in j1939_sk_queue_session()
107 spin_unlock_bh(&jsk->sk_session_queue_lock); in j1939_sk_queue_session()
108 j1939_sock_pending_add(&jsk->sk); in j1939_sk_queue_session()
114 j1939_session *j1939_sk_get_incomplete_session(struct j1939_sock *jsk) in j1939_sk_get_incomplete_session() argument
118 spin_lock_bh(&jsk->sk_session_queue_lock); in j1939_sk_get_incomplete_session()
119 if (!list_empty(&jsk->sk_session_queue)) { in j1939_sk_get_incomplete_session()
120 session = list_last_entry(&jsk->sk_session_queue, in j1939_sk_get_incomplete_session()
128 spin_unlock_bh(&jsk->sk_session_queue_lock); in j1939_sk_get_incomplete_session()
134 struct j1939_sock *jsk, int err) in j1939_sk_queue_drop_all() argument
139 spin_lock_bh(&jsk->sk_session_queue_lock); in j1939_sk_queue_drop_all()
140 list_for_each_entry_safe(session, tmp, &jsk->sk_session_queue, in j1939_sk_queue_drop_all()
146 spin_unlock_bh(&jsk->sk_session_queue_lock); in j1939_sk_queue_drop_all()
151 struct j1939_sock *jsk; in j1939_sk_queue_activate_next_locked() local
159 jsk = j1939_sk(session->sk); in j1939_sk_queue_activate_next_locked()
160 lockdep_assert_held(&jsk->sk_session_queue_lock); in j1939_sk_queue_activate_next_locked()
164 first = list_first_entry_or_null(&jsk->sk_session_queue, in j1939_sk_queue_activate_next_locked()
175 first = list_first_entry_or_null(&jsk->sk_session_queue, in j1939_sk_queue_activate_next_locked()
200 struct j1939_sock *jsk; in j1939_sk_queue_activate_next() local
205 jsk = j1939_sk(session->sk); in j1939_sk_queue_activate_next()
207 spin_lock_bh(&jsk->sk_session_queue_lock); in j1939_sk_queue_activate_next()
209 spin_unlock_bh(&jsk->sk_session_queue_lock); in j1939_sk_queue_activate_next()
212 static bool j1939_sk_match_dst(struct j1939_sock *jsk, in j1939_sk_match_dst() argument
215 if ((jsk->state & J1939_SOCK_PROMISC)) in j1939_sk_match_dst()
219 if (jsk->addr.src_name && skcb->addr.dst_name) { in j1939_sk_match_dst()
220 if (jsk->addr.src_name != skcb->addr.dst_name) in j1939_sk_match_dst()
229 if (jsk->addr.sa != skcb->addr.da) in j1939_sk_match_dst()
231 } else if (!sock_flag(&jsk->sk, SOCK_BROADCAST)) { in j1939_sk_match_dst()
240 if (jsk->state & J1939_SOCK_CONNECTED) { in j1939_sk_match_dst()
244 if (jsk->addr.dst_name && skcb->addr.src_name) { in j1939_sk_match_dst()
245 if (jsk->addr.dst_name != skcb->addr.src_name) in j1939_sk_match_dst()
248 if (jsk->addr.da != skcb->addr.sa) in j1939_sk_match_dst()
254 if (j1939_pgn_is_valid(jsk->pgn_rx_filter) && in j1939_sk_match_dst()
255 jsk->pgn_rx_filter != skcb->addr.pgn) in j1939_sk_match_dst()
262 static bool j1939_sk_match_filter(struct j1939_sock *jsk, in j1939_sk_match_filter() argument
268 spin_lock_bh(&jsk->filters_lock); in j1939_sk_match_filter()
270 f = jsk->filters; in j1939_sk_match_filter()
271 nfilter = jsk->nfilters; in j1939_sk_match_filter()
287 spin_unlock_bh(&jsk->filters_lock); in j1939_sk_match_filter()
291 spin_unlock_bh(&jsk->filters_lock); in j1939_sk_match_filter()
295 static bool j1939_sk_recv_match_one(struct j1939_sock *jsk, in j1939_sk_recv_match_one() argument
298 if (!(jsk->state & J1939_SOCK_BOUND)) in j1939_sk_recv_match_one()
301 if (!j1939_sk_match_dst(jsk, skcb)) in j1939_sk_recv_match_one()
304 if (!j1939_sk_match_filter(jsk, skcb)) in j1939_sk_recv_match_one()
310 static void j1939_sk_recv_one(struct j1939_sock *jsk, struct sk_buff *oskb) in j1939_sk_recv_one() argument
316 if (oskb->sk == &jsk->sk) in j1939_sk_recv_one()
319 if (!j1939_sk_recv_match_one(jsk, oskcb)) in j1939_sk_recv_one()
334 if (sock_queue_rcv_skb(&jsk->sk, skb) < 0) in j1939_sk_recv_one()
340 struct j1939_sock *jsk; in j1939_sk_recv_match() local
344 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_recv_match()
345 match = j1939_sk_recv_match_one(jsk, skcb); in j1939_sk_recv_match()
356 struct j1939_sock *jsk; in j1939_sk_recv() local
359 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_recv()
360 j1939_sk_recv_one(jsk, skb); in j1939_sk_recv()
367 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_sock_destruct() local
384 if (jsk->priv) { in j1939_sk_sock_destruct()
385 j1939_priv_put(jsk->priv); in j1939_sk_sock_destruct()
386 jsk->priv = NULL; in j1939_sk_sock_destruct()
395 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_init() local
401 memset((void *)jsk + sizeof(jsk->sk), 0x0, in j1939_sk_init()
402 sizeof(*jsk) - sizeof(jsk->sk)); in j1939_sk_init()
404 INIT_LIST_HEAD(&jsk->list); in j1939_sk_init()
405 init_waitqueue_head(&jsk->waitq); in j1939_sk_init()
406 jsk->sk.sk_priority = j1939_to_sk_priority(6); in j1939_sk_init()
407 jsk->sk.sk_reuse = 1; /* per default */ in j1939_sk_init()
408 jsk->addr.sa = J1939_NO_ADDR; in j1939_sk_init()
409 jsk->addr.da = J1939_NO_ADDR; in j1939_sk_init()
410 jsk->addr.pgn = J1939_NO_PGN; in j1939_sk_init()
411 jsk->pgn_rx_filter = J1939_NO_PGN; in j1939_sk_init()
412 atomic_set(&jsk->skb_pending, 0); in j1939_sk_init()
413 spin_lock_init(&jsk->sk_session_queue_lock); in j1939_sk_init()
414 INIT_LIST_HEAD(&jsk->sk_session_queue); in j1939_sk_init()
415 spin_lock_init(&jsk->filters_lock); in j1939_sk_init()
445 struct j1939_sock *jsk = j1939_sk(sock->sk); in j1939_sk_bind() local
457 priv = jsk->priv; in j1939_sk_bind()
462 if (jsk->state & J1939_SOCK_BOUND) { in j1939_sk_bind()
466 if (jsk->ifindex != addr->can_ifindex) { in j1939_sk_bind()
472 j1939_jsk_del(priv, jsk); in j1939_sk_bind()
473 j1939_local_ecu_put(priv, jsk->addr.src_name, jsk->addr.sa); in j1939_sk_bind()
504 jsk->ifindex = addr->can_ifindex; in j1939_sk_bind()
510 jsk->priv = priv; in j1939_sk_bind()
515 jsk->pgn_rx_filter = addr->can_addr.j1939.pgn; in j1939_sk_bind()
516 jsk->addr.src_name = addr->can_addr.j1939.name; in j1939_sk_bind()
517 jsk->addr.sa = addr->can_addr.j1939.addr; in j1939_sk_bind()
520 ret = j1939_local_ecu_get(priv, jsk->addr.src_name, jsk->addr.sa); in j1939_sk_bind()
526 j1939_jsk_add(priv, jsk); in j1939_sk_bind()
538 struct j1939_sock *jsk = j1939_sk(sock->sk); in j1939_sk_connect() local
548 if (!(jsk->state & J1939_SOCK_BOUND)) { in j1939_sk_connect()
554 if (jsk->ifindex != addr->can_ifindex) { in j1939_sk_connect()
561 !sock_flag(&jsk->sk, SOCK_BROADCAST)) { in j1939_sk_connect()
567 jsk->addr.dst_name = addr->can_addr.j1939.name; in j1939_sk_connect()
568 jsk->addr.da = addr->can_addr.j1939.addr; in j1939_sk_connect()
571 jsk->addr.pgn = addr->can_addr.j1939.pgn; in j1939_sk_connect()
573 jsk->state |= J1939_SOCK_CONNECTED; in j1939_sk_connect()
582 const struct j1939_sock *jsk, int peer) in j1939_sk_sock2sockaddr_can() argument
590 addr->can_ifindex = jsk->ifindex; in j1939_sk_sock2sockaddr_can()
591 addr->can_addr.j1939.pgn = jsk->addr.pgn; in j1939_sk_sock2sockaddr_can()
593 addr->can_addr.j1939.name = jsk->addr.dst_name; in j1939_sk_sock2sockaddr_can()
594 addr->can_addr.j1939.addr = jsk->addr.da; in j1939_sk_sock2sockaddr_can()
596 addr->can_addr.j1939.name = jsk->addr.src_name; in j1939_sk_sock2sockaddr_can()
597 addr->can_addr.j1939.addr = jsk->addr.sa; in j1939_sk_sock2sockaddr_can()
606 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_getname() local
611 if (peer && !(jsk->state & J1939_SOCK_CONNECTED)) { in j1939_sk_getname()
616 j1939_sk_sock2sockaddr_can(addr, jsk, peer); in j1939_sk_getname()
628 struct j1939_sock *jsk; in j1939_sk_release() local
634 jsk = j1939_sk(sk); in j1939_sk_release()
636 if (jsk->state & J1939_SOCK_BOUND) { in j1939_sk_release()
637 struct j1939_priv *priv = jsk->priv; in j1939_sk_release()
639 if (wait_event_interruptible(jsk->waitq, in j1939_sk_release()
640 !j1939_sock_pending_get(&jsk->sk))) { in j1939_sk_release()
642 j1939_sk_queue_drop_all(priv, jsk, ESHUTDOWN); in j1939_sk_release()
645 j1939_jsk_del(priv, jsk); in j1939_sk_release()
647 j1939_local_ecu_put(priv, jsk->addr.src_name, in j1939_sk_release()
648 jsk->addr.sa); in j1939_sk_release()
653 kfree(jsk->filters); in j1939_sk_release()
663 static int j1939_sk_setsockopt_flag(struct j1939_sock *jsk, sockptr_t optval, in j1939_sk_setsockopt_flag() argument
672 lock_sock(&jsk->sk); in j1939_sk_setsockopt_flag()
674 jsk->state |= flag; in j1939_sk_setsockopt_flag()
676 jsk->state &= ~flag; in j1939_sk_setsockopt_flag()
677 release_sock(&jsk->sk); in j1939_sk_setsockopt_flag()
685 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_setsockopt() local
717 lock_sock(&jsk->sk); in j1939_sk_setsockopt()
718 spin_lock_bh(&jsk->filters_lock); in j1939_sk_setsockopt()
719 ofilters = jsk->filters; in j1939_sk_setsockopt()
720 jsk->filters = filters; in j1939_sk_setsockopt()
721 jsk->nfilters = count; in j1939_sk_setsockopt()
722 spin_unlock_bh(&jsk->filters_lock); in j1939_sk_setsockopt()
723 release_sock(&jsk->sk); in j1939_sk_setsockopt()
727 return j1939_sk_setsockopt_flag(jsk, optval, optlen, in j1939_sk_setsockopt()
730 ret = j1939_sk_setsockopt_flag(jsk, optval, optlen, in j1939_sk_setsockopt()
735 if (!(jsk->state & J1939_SOCK_ERRQUEUE)) in j1939_sk_setsockopt()
747 lock_sock(&jsk->sk); in j1939_sk_setsockopt()
748 jsk->sk.sk_priority = j1939_to_sk_priority(tmp); in j1939_sk_setsockopt()
749 release_sock(&jsk->sk); in j1939_sk_setsockopt()
760 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_getsockopt() local
774 lock_sock(&jsk->sk); in j1939_sk_getsockopt()
777 tmp = (jsk->state & J1939_SOCK_PROMISC) ? 1 : 0; in j1939_sk_getsockopt()
780 tmp = (jsk->state & J1939_SOCK_ERRQUEUE) ? 1 : 0; in j1939_sk_getsockopt()
783 tmp = j1939_prio(jsk->sk.sk_priority); in j1939_sk_getsockopt()
803 release_sock(&jsk->sk); in j1939_sk_getsockopt()
873 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_alloc_skb() local
900 skcb->addr = jsk->addr; in j1939_sk_alloc_skb()
987 struct j1939_sock *jsk; in __j1939_sk_errqueue() local
994 jsk = j1939_sk(sk); in __j1939_sk_errqueue()
996 if (!(jsk->state & J1939_SOCK_ERRQUEUE)) in __j1939_sk_errqueue()
1088 struct j1939_sock *jsk; in j1939_sk_errqueue() local
1098 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_errqueue()
1099 if (j1939_sk_recv_match_one(jsk, &session->skcb)) in j1939_sk_errqueue()
1100 __j1939_sk_errqueue(session, &jsk->sk, type); in j1939_sk_errqueue()
1107 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_send_loop_abort() local
1109 if (jsk->state & J1939_SOCK_ERRQUEUE) in j1939_sk_send_loop_abort()
1121 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_send_loop() local
1122 struct j1939_session *session = j1939_sk_get_incomplete_session(jsk); in j1939_sk_send_loop()
1168 j1939_sk_queue_drop_all(priv, jsk, in j1939_sk_send_loop()
1215 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_sendmsg() local
1222 if (!(jsk->state & J1939_SOCK_BOUND)) { in j1939_sk_sendmsg()
1227 priv = jsk->priv; in j1939_sk_sendmsg()
1228 ifindex = jsk->ifindex; in j1939_sk_sendmsg()
1230 if (!jsk->addr.src_name && jsk->addr.sa == J1939_NO_ADDR) { in j1939_sk_sendmsg()
1269 if (!jsk->addr.dst_name && jsk->addr.da == J1939_NO_ADDR && in j1939_sk_sendmsg()
1287 struct j1939_sock *jsk; in j1939_sk_netdev_event_netdown() local
1291 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_netdev_event_netdown()
1292 jsk->sk.sk_err = error_code; in j1939_sk_netdev_event_netdown()
1293 if (!sock_flag(&jsk->sk, SOCK_DEAD)) in j1939_sk_netdev_event_netdown()
1294 sk_error_report(&jsk->sk); in j1939_sk_netdev_event_netdown()
1296 j1939_sk_queue_drop_all(priv, jsk, error_code); in j1939_sk_netdev_event_netdown()