Lines Matching +full:t +full:- +full:head
1 // SPDX-License-Identifier: GPL-2.0-only
32 return (struct _strp_msg *)((void *)skb->cb +
41 cancel_delayed_work(&strp->msg_timer_work);
43 if (strp->stopped)
46 strp->stopped = 1;
48 if (strp->sk) {
49 struct sock *sk = strp->sk;
52 sk->sk_err = -err;
60 mod_delayed_work(strp_wq, &strp->msg_timer_work, timeo);
67 desc->error = err;
68 kfree_skb(strp->skb_head);
69 strp->skb_head = NULL;
70 strp->cb.abort_parser(strp, err);
75 if (strp->sk) {
76 struct socket *sock = strp->sk->sk_socket;
78 return sock->ops->peek_len(sock);
81 /* If we don't have an associated socket there's nothing to peek.
93 struct strparser *strp = (struct strparser *)desc->arg.data;
95 struct sk_buff *head, *skb;
101 if (strp->paused)
104 head = strp->skb_head;
105 if (head) {
108 /* Getting data with a non-zero offset when a message is
110 * need to clone and pull since we can't deal with
111 * offsets in the skbs for a message expect in the head.
115 STRP_STATS_INCR(strp->stats.mem_fail);
116 desc->error = -ENOMEM;
120 STRP_STATS_INCR(strp->stats.mem_fail);
122 desc->error = -ENOMEM;
129 if (!strp->skb_nextp) {
130 /* We are going to append to the frags_list of head.
133 err = skb_unclone(head, GFP_ATOMIC);
135 STRP_STATS_INCR(strp->stats.mem_fail);
136 desc->error = err;
140 if (unlikely(skb_shinfo(head)->frag_list)) {
141 /* We can't append to an sk_buff that already
142 * has a frag_list. We create a new head, point
143 * the frag_list of that to the old head, and
144 * then are able to use the old head->next for
147 if (WARN_ON(head->next)) {
148 desc->error = -EINVAL;
152 skb = alloc_skb_for_msg(head);
154 STRP_STATS_INCR(strp->stats.mem_fail);
155 desc->error = -ENOMEM;
159 strp->skb_nextp = &head->next;
160 strp->skb_head = skb;
161 head = skb;
163 strp->skb_nextp =
164 &skb_shinfo(head)->frag_list;
173 STRP_STATS_INCR(strp->stats.mem_fail);
174 desc->error = -ENOMEM;
178 cand_len = orig_len - eaten;
180 head = strp->skb_head;
181 if (!head) {
182 head = skb;
183 strp->skb_head = head;
185 strp->skb_nextp = NULL;
186 stm = _strp_msg(head);
188 stm->strp.offset = orig_offset + eaten;
196 STRP_STATS_INCR(strp->stats.mem_fail);
197 desc->error = err;
202 stm = _strp_msg(head);
203 *strp->skb_nextp = skb;
204 strp->skb_nextp = &skb->next;
205 head->data_len += skb->len;
206 head->len += skb->len;
207 head->truesize += skb->truesize;
210 if (!stm->strp.full_len) {
213 len = (*strp->cb.parse_msg)(strp, head);
217 if (!stm->accum_len) {
221 stm->accum_len += cand_len;
223 STRP_STATS_INCR(strp->stats.need_more_hdr);
227 if (len == -ESTRPIPE && stm->accum_len) {
228 len = -ENODATA;
229 strp->unrecov_intr = 1;
231 strp->interrupted = 1;
237 STRP_STATS_INCR(strp->stats.msg_too_big);
238 strp_parser_err(strp, -EMSGSIZE, desc);
240 } else if (len <= (ssize_t)head->len -
241 skb->len - stm->strp.offset) {
245 STRP_STATS_INCR(strp->stats.bad_hdr_len);
246 strp_parser_err(strp, -EPROTO, desc);
250 stm->strp.full_len = len;
253 extra = (ssize_t)(stm->accum_len + cand_len) -
254 stm->strp.full_len;
258 if (stm->strp.full_len - stm->accum_len >
260 /* Don't have the whole message in the socket
261 * buffer. Set strp->need_bytes to wait for
264 * but don't consume yet per strp_read_sock.
267 if (!stm->accum_len) {
272 stm->accum_len += cand_len;
274 strp->need_bytes = stm->strp.full_len -
275 stm->accum_len;
276 STRP_STATS_ADD(strp->stats.bytes, cand_len);
277 desc->count = 0; /* Stop reading socket */
280 stm->accum_len += cand_len;
292 eaten += (cand_len - extra);
295 cancel_delayed_work(&strp->msg_timer_work);
296 strp->skb_head = NULL;
297 strp->need_bytes = 0;
298 STRP_STATS_INCR(strp->stats.msgs);
301 strp->cb.rcv_msg(strp, head);
303 if (unlikely(strp->paused)) {
312 STRP_STATS_ADD(strp->stats.bytes, eaten);
333 struct strparser *strp = (struct strparser *)desc->arg.data;
336 strp->sk->sk_rcvbuf, strp->sk->sk_rcvtimeo);
347 struct socket *sock = strp->sk->sk_socket;
350 if (unlikely(!sock || !sock->ops))
351 return -EBUSY;
353 if (unlikely(!strp->cb.read_sock && !sock->ops->read_sock))
354 return -EBUSY;
361 if (strp->cb.read_sock)
362 strp->cb.read_sock(strp, &desc, strp_recv);
364 sock->ops->read_sock(strp->sk, &desc, strp_recv);
366 desc.error = strp->cb.read_sock_done(strp, desc.error);
374 if (unlikely(strp->stopped) || strp->paused)
384 if (sock_owned_by_user_nocheck(strp->sk)) {
385 queue_work(strp_wq, &strp->work);
389 if (strp->need_bytes) {
390 if (strp_peek_len(strp) < strp->need_bytes)
394 if (strp_read_sock(strp) == -ENOMEM)
395 queue_work(strp_wq, &strp->work);
404 strp->cb.lock(strp);
406 if (unlikely(strp->stopped))
409 if (strp->paused)
412 if (strp_read_sock(strp) == -ENOMEM)
413 queue_work(strp_wq, &strp->work);
416 strp->cb.unlock(strp);
430 STRP_STATS_INCR(strp->stats.msg_timeouts);
431 strp->cb.lock(strp);
432 strp->cb.abort_parser(strp, -ETIMEDOUT);
433 strp->cb.unlock(strp);
438 lock_sock(strp->sk);
443 release_sock(strp->sk);
450 if (!cb || !cb->rcv_msg || !cb->parse_msg)
451 return -EINVAL;
465 if (!cb->lock || !cb->unlock)
466 return -EINVAL;
471 strp->sk = sk;
473 strp->cb.lock = cb->lock ? : strp_sock_lock;
474 strp->cb.unlock = cb->unlock ? : strp_sock_unlock;
475 strp->cb.rcv_msg = cb->rcv_msg;
476 strp->cb.parse_msg = cb->parse_msg;
477 strp->cb.read_sock = cb->read_sock;
478 strp->cb.read_sock_done = cb->read_sock_done ? : default_read_sock_done;
479 strp->cb.abort_parser = cb->abort_parser ? : strp_abort_strp;
481 INIT_DELAYED_WORK(&strp->msg_timer_work, strp_msg_timeout);
482 INIT_WORK(&strp->work, strp_work);
490 strp->paused = 0;
495 queue_work(strp_wq, &strp->work);
504 WARN_ON(!strp->stopped);
506 cancel_delayed_work_sync(&strp->msg_timer_work);
507 cancel_work_sync(&strp->work);
509 if (strp->skb_head) {
510 kfree_skb(strp->skb_head);
511 strp->skb_head = NULL;
518 strp->stopped = 1;
524 queue_work(strp_wq, &strp->work);
535 return -ENOMEM;