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
265 const struct j1939_filter *f = jsk->filters; in j1939_sk_match_filter()
266 int nfilter = jsk->nfilters; in j1939_sk_match_filter()
284 static bool j1939_sk_recv_match_one(struct j1939_sock *jsk, in j1939_sk_recv_match_one() argument
287 if (!(jsk->state & J1939_SOCK_BOUND)) in j1939_sk_recv_match_one()
290 if (!j1939_sk_match_dst(jsk, skcb)) in j1939_sk_recv_match_one()
293 if (!j1939_sk_match_filter(jsk, skcb)) in j1939_sk_recv_match_one()
299 static void j1939_sk_recv_one(struct j1939_sock *jsk, struct sk_buff *oskb) in j1939_sk_recv_one() argument
305 if (oskb->sk == &jsk->sk) in j1939_sk_recv_one()
308 if (!j1939_sk_recv_match_one(jsk, oskcb)) in j1939_sk_recv_one()
323 if (sock_queue_rcv_skb(&jsk->sk, skb) < 0) in j1939_sk_recv_one()
329 struct j1939_sock *jsk; in j1939_sk_recv_match() local
333 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_recv_match()
334 match = j1939_sk_recv_match_one(jsk, skcb); in j1939_sk_recv_match()
345 struct j1939_sock *jsk; in j1939_sk_recv() local
348 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_recv()
349 j1939_sk_recv_one(jsk, skb); in j1939_sk_recv()
356 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_sock_destruct() local
373 if (jsk->priv) { in j1939_sk_sock_destruct()
374 j1939_priv_put(jsk->priv); in j1939_sk_sock_destruct()
375 jsk->priv = NULL; in j1939_sk_sock_destruct()
384 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_init() local
390 memset((void *)jsk + sizeof(jsk->sk), 0x0, in j1939_sk_init()
391 sizeof(*jsk) - sizeof(jsk->sk)); in j1939_sk_init()
393 INIT_LIST_HEAD(&jsk->list); in j1939_sk_init()
394 init_waitqueue_head(&jsk->waitq); in j1939_sk_init()
395 jsk->sk.sk_priority = j1939_to_sk_priority(6); in j1939_sk_init()
396 jsk->sk.sk_reuse = 1; /* per default */ in j1939_sk_init()
397 jsk->addr.sa = J1939_NO_ADDR; in j1939_sk_init()
398 jsk->addr.da = J1939_NO_ADDR; in j1939_sk_init()
399 jsk->addr.pgn = J1939_NO_PGN; in j1939_sk_init()
400 jsk->pgn_rx_filter = J1939_NO_PGN; in j1939_sk_init()
401 atomic_set(&jsk->skb_pending, 0); in j1939_sk_init()
402 spin_lock_init(&jsk->sk_session_queue_lock); in j1939_sk_init()
403 INIT_LIST_HEAD(&jsk->sk_session_queue); in j1939_sk_init()
433 struct j1939_sock *jsk = j1939_sk(sock->sk); in j1939_sk_bind() local
445 priv = jsk->priv; in j1939_sk_bind()
450 if (jsk->state & J1939_SOCK_BOUND) { in j1939_sk_bind()
454 if (jsk->ifindex != addr->can_ifindex) { in j1939_sk_bind()
460 j1939_jsk_del(priv, jsk); in j1939_sk_bind()
461 j1939_local_ecu_put(priv, jsk->addr.src_name, jsk->addr.sa); in j1939_sk_bind()
492 jsk->ifindex = addr->can_ifindex; in j1939_sk_bind()
498 jsk->priv = priv; in j1939_sk_bind()
503 jsk->pgn_rx_filter = addr->can_addr.j1939.pgn; in j1939_sk_bind()
504 jsk->addr.src_name = addr->can_addr.j1939.name; in j1939_sk_bind()
505 jsk->addr.sa = addr->can_addr.j1939.addr; in j1939_sk_bind()
508 ret = j1939_local_ecu_get(priv, jsk->addr.src_name, jsk->addr.sa); in j1939_sk_bind()
514 j1939_jsk_add(priv, jsk); in j1939_sk_bind()
526 struct j1939_sock *jsk = j1939_sk(sock->sk); in j1939_sk_connect() local
536 if (!(jsk->state & J1939_SOCK_BOUND)) { in j1939_sk_connect()
542 if (jsk->ifindex != addr->can_ifindex) { in j1939_sk_connect()
549 !sock_flag(&jsk->sk, SOCK_BROADCAST)) { in j1939_sk_connect()
555 jsk->addr.dst_name = addr->can_addr.j1939.name; in j1939_sk_connect()
556 jsk->addr.da = addr->can_addr.j1939.addr; in j1939_sk_connect()
559 jsk->addr.pgn = addr->can_addr.j1939.pgn; in j1939_sk_connect()
561 jsk->state |= J1939_SOCK_CONNECTED; in j1939_sk_connect()
570 const struct j1939_sock *jsk, int peer) in j1939_sk_sock2sockaddr_can() argument
578 addr->can_ifindex = jsk->ifindex; in j1939_sk_sock2sockaddr_can()
579 addr->can_addr.j1939.pgn = jsk->addr.pgn; in j1939_sk_sock2sockaddr_can()
581 addr->can_addr.j1939.name = jsk->addr.dst_name; in j1939_sk_sock2sockaddr_can()
582 addr->can_addr.j1939.addr = jsk->addr.da; in j1939_sk_sock2sockaddr_can()
584 addr->can_addr.j1939.name = jsk->addr.src_name; in j1939_sk_sock2sockaddr_can()
585 addr->can_addr.j1939.addr = jsk->addr.sa; in j1939_sk_sock2sockaddr_can()
594 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_getname() local
599 if (peer && !(jsk->state & J1939_SOCK_CONNECTED)) { in j1939_sk_getname()
604 j1939_sk_sock2sockaddr_can(addr, jsk, peer); in j1939_sk_getname()
616 struct j1939_sock *jsk; in j1939_sk_release() local
622 jsk = j1939_sk(sk); in j1939_sk_release()
624 if (jsk->state & J1939_SOCK_BOUND) { in j1939_sk_release()
625 struct j1939_priv *priv = jsk->priv; in j1939_sk_release()
627 if (wait_event_interruptible(jsk->waitq, in j1939_sk_release()
628 !j1939_sock_pending_get(&jsk->sk))) { in j1939_sk_release()
630 j1939_sk_queue_drop_all(priv, jsk, ESHUTDOWN); in j1939_sk_release()
633 j1939_jsk_del(priv, jsk); in j1939_sk_release()
635 j1939_local_ecu_put(priv, jsk->addr.src_name, in j1939_sk_release()
636 jsk->addr.sa); in j1939_sk_release()
641 kfree(jsk->filters); in j1939_sk_release()
651 static int j1939_sk_setsockopt_flag(struct j1939_sock *jsk, sockptr_t optval, in j1939_sk_setsockopt_flag() argument
660 lock_sock(&jsk->sk); in j1939_sk_setsockopt_flag()
662 jsk->state |= flag; in j1939_sk_setsockopt_flag()
664 jsk->state &= ~flag; in j1939_sk_setsockopt_flag()
665 release_sock(&jsk->sk); in j1939_sk_setsockopt_flag()
673 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_setsockopt() local
705 lock_sock(&jsk->sk); in j1939_sk_setsockopt()
706 ofilters = jsk->filters; in j1939_sk_setsockopt()
707 jsk->filters = filters; in j1939_sk_setsockopt()
708 jsk->nfilters = count; in j1939_sk_setsockopt()
709 release_sock(&jsk->sk); in j1939_sk_setsockopt()
713 return j1939_sk_setsockopt_flag(jsk, optval, optlen, in j1939_sk_setsockopt()
716 ret = j1939_sk_setsockopt_flag(jsk, optval, optlen, in j1939_sk_setsockopt()
721 if (!(jsk->state & J1939_SOCK_ERRQUEUE)) in j1939_sk_setsockopt()
733 lock_sock(&jsk->sk); in j1939_sk_setsockopt()
734 jsk->sk.sk_priority = j1939_to_sk_priority(tmp); in j1939_sk_setsockopt()
735 release_sock(&jsk->sk); in j1939_sk_setsockopt()
746 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_getsockopt() local
760 lock_sock(&jsk->sk); in j1939_sk_getsockopt()
763 tmp = (jsk->state & J1939_SOCK_PROMISC) ? 1 : 0; in j1939_sk_getsockopt()
766 tmp = (jsk->state & J1939_SOCK_ERRQUEUE) ? 1 : 0; in j1939_sk_getsockopt()
769 tmp = j1939_prio(jsk->sk.sk_priority); in j1939_sk_getsockopt()
789 release_sock(&jsk->sk); in j1939_sk_getsockopt()
859 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_alloc_skb() local
886 skcb->addr = jsk->addr; in j1939_sk_alloc_skb()
973 struct j1939_sock *jsk; in __j1939_sk_errqueue() local
980 jsk = j1939_sk(sk); in __j1939_sk_errqueue()
982 if (!(jsk->state & J1939_SOCK_ERRQUEUE)) in __j1939_sk_errqueue()
1074 struct j1939_sock *jsk; in j1939_sk_errqueue() local
1084 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_errqueue()
1085 if (j1939_sk_recv_match_one(jsk, &session->skcb)) in j1939_sk_errqueue()
1086 __j1939_sk_errqueue(session, &jsk->sk, type); in j1939_sk_errqueue()
1093 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_send_loop_abort() local
1095 if (jsk->state & J1939_SOCK_ERRQUEUE) in j1939_sk_send_loop_abort()
1107 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_send_loop() local
1108 struct j1939_session *session = j1939_sk_get_incomplete_session(jsk); in j1939_sk_send_loop()
1154 j1939_sk_queue_drop_all(priv, jsk, in j1939_sk_send_loop()
1201 struct j1939_sock *jsk = j1939_sk(sk); in j1939_sk_sendmsg() local
1208 if (!(jsk->state & J1939_SOCK_BOUND)) { in j1939_sk_sendmsg()
1213 priv = jsk->priv; in j1939_sk_sendmsg()
1214 ifindex = jsk->ifindex; in j1939_sk_sendmsg()
1216 if (!jsk->addr.src_name && jsk->addr.sa == J1939_NO_ADDR) { in j1939_sk_sendmsg()
1255 if (!jsk->addr.dst_name && jsk->addr.da == J1939_NO_ADDR && in j1939_sk_sendmsg()
1273 struct j1939_sock *jsk; in j1939_sk_netdev_event_netdown() local
1277 list_for_each_entry(jsk, &priv->j1939_socks, list) { in j1939_sk_netdev_event_netdown()
1278 jsk->sk.sk_err = error_code; in j1939_sk_netdev_event_netdown()
1279 if (!sock_flag(&jsk->sk, SOCK_DEAD)) in j1939_sk_netdev_event_netdown()
1280 sk_error_report(&jsk->sk); in j1939_sk_netdev_event_netdown()
1282 j1939_sk_queue_drop_all(priv, jsk, error_code); in j1939_sk_netdev_event_netdown()