summaryrefslogtreecommitdiffstats
path: root/net/strparser/strparser.c
diff options
context:
space:
mode:
authorTom Herbert <tom@herbertland.com>2016-08-28 17:43:19 -0400
committerDavid S. Miller <davem@davemloft.net>2016-08-28 23:32:41 -0400
commit96a59083478d1ea66684c59c073424a9d4e6ac6d (patch)
tree09a988530d4c5e17bf47f16f2c624bc93ac14018 /net/strparser/strparser.c
parent3203558589a597e0a10a66b258fbc5a4a6659ed0 (diff)
kcm: Remove TCP specific references from kcm and strparser
kcm and strparser need to work with any type of stream socket not just TCP. Eliminate references to TCP and call generic proto_ops functions of read_sock and peek_len. Also in strp_init check if the socket support the proto_ops read_sock and peek_len. Signed-off-by: Tom Herbert <tom@herbertland.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/strparser/strparser.c')
-rw-r--r--net/strparser/strparser.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
index 4ecfc10cbe6d..5c7549b5b92c 100644
--- a/net/strparser/strparser.c
+++ b/net/strparser/strparser.c
@@ -26,7 +26,6 @@
26#include <net/strparser.h> 26#include <net/strparser.h>
27#include <net/netns/generic.h> 27#include <net/netns/generic.h>
28#include <net/sock.h> 28#include <net/sock.h>
29#include <net/tcp.h>
30 29
31static struct workqueue_struct *strp_wq; 30static struct workqueue_struct *strp_wq;
32 31
@@ -80,9 +79,16 @@ static void strp_parser_err(struct strparser *strp, int err,
80 strp->cb.abort_parser(strp, err); 79 strp->cb.abort_parser(strp, err);
81} 80}
82 81
82static inline int strp_peek_len(struct strparser *strp)
83{
84 struct socket *sock = strp->sk->sk_socket;
85
86 return sock->ops->peek_len(sock);
87}
88
83/* Lower socket lock held */ 89/* Lower socket lock held */
84static int strp_tcp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, 90static int strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
85 unsigned int orig_offset, size_t orig_len) 91 unsigned int orig_offset, size_t orig_len)
86{ 92{
87 struct strparser *strp = (struct strparser *)desc->arg.data; 93 struct strparser *strp = (struct strparser *)desc->arg.data;
88 struct _strp_rx_msg *rxm; 94 struct _strp_rx_msg *rxm;
@@ -266,12 +272,12 @@ static int strp_tcp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
266 if (extra < 0) { 272 if (extra < 0) {
267 /* Message not complete yet. */ 273 /* Message not complete yet. */
268 if (rxm->strp.full_len - rxm->accum_len > 274 if (rxm->strp.full_len - rxm->accum_len >
269 tcp_inq(strp->sk)) { 275 strp_peek_len(strp)) {
270 /* Don't have the whole messages in the socket 276 /* Don't have the whole messages in the socket
271 * buffer. Set strp->rx_need_bytes to wait for 277 * buffer. Set strp->rx_need_bytes to wait for
272 * the rest of the message. Also, set "early 278 * the rest of the message. Also, set "early
273 * eaten" since we've already buffered the skb 279 * eaten" since we've already buffered the skb
274 * but don't consume yet per tcp_read_sock. 280 * but don't consume yet per strp_read_sock.
275 */ 281 */
276 282
277 if (!rxm->accum_len) { 283 if (!rxm->accum_len) {
@@ -329,16 +335,17 @@ static int default_read_sock_done(struct strparser *strp, int err)
329} 335}
330 336
331/* Called with lock held on lower socket */ 337/* Called with lock held on lower socket */
332static int strp_tcp_read_sock(struct strparser *strp) 338static int strp_read_sock(struct strparser *strp)
333{ 339{
340 struct socket *sock = strp->sk->sk_socket;
334 read_descriptor_t desc; 341 read_descriptor_t desc;
335 342
336 desc.arg.data = strp; 343 desc.arg.data = strp;
337 desc.error = 0; 344 desc.error = 0;
338 desc.count = 1; /* give more than one skb per call */ 345 desc.count = 1; /* give more than one skb per call */
339 346
340 /* sk should be locked here, so okay to do tcp_read_sock */ 347 /* sk should be locked here, so okay to do read_sock */
341 tcp_read_sock(strp->sk, &desc, strp_tcp_recv); 348 sock->ops->read_sock(strp->sk, &desc, strp_recv);
342 349
343 desc.error = strp->cb.read_sock_done(strp, desc.error); 350 desc.error = strp->cb.read_sock_done(strp, desc.error);
344 351
@@ -346,10 +353,8 @@ static int strp_tcp_read_sock(struct strparser *strp)
346} 353}
347 354
348/* Lower sock lock held */ 355/* Lower sock lock held */
349void strp_tcp_data_ready(struct strparser *strp) 356void strp_data_ready(struct strparser *strp)
350{ 357{
351 struct sock *csk = strp->sk;
352
353 if (unlikely(strp->rx_stopped)) 358 if (unlikely(strp->rx_stopped))
354 return; 359 return;
355 360
@@ -360,7 +365,7 @@ void strp_tcp_data_ready(struct strparser *strp)
360 * allows a thread in BH context to safely check if the process 365 * allows a thread in BH context to safely check if the process
361 * lock is held. In this case, if the lock is held, queue work. 366 * lock is held. In this case, if the lock is held, queue work.
362 */ 367 */
363 if (sock_owned_by_user(csk)) { 368 if (sock_owned_by_user(strp->sk)) {
364 queue_work(strp_wq, &strp->rx_work); 369 queue_work(strp_wq, &strp->rx_work);
365 return; 370 return;
366 } 371 }
@@ -369,24 +374,24 @@ void strp_tcp_data_ready(struct strparser *strp)
369 return; 374 return;
370 375
371 if (strp->rx_need_bytes) { 376 if (strp->rx_need_bytes) {
372 if (tcp_inq(csk) >= strp->rx_need_bytes) 377 if (strp_peek_len(strp) >= strp->rx_need_bytes)
373 strp->rx_need_bytes = 0; 378 strp->rx_need_bytes = 0;
374 else 379 else
375 return; 380 return;
376 } 381 }
377 382
378 if (strp_tcp_read_sock(strp) == -ENOMEM) 383 if (strp_read_sock(strp) == -ENOMEM)
379 queue_work(strp_wq, &strp->rx_work); 384 queue_work(strp_wq, &strp->rx_work);
380} 385}
381EXPORT_SYMBOL_GPL(strp_tcp_data_ready); 386EXPORT_SYMBOL_GPL(strp_data_ready);
382 387
383static void do_strp_rx_work(struct strparser *strp) 388static void do_strp_rx_work(struct strparser *strp)
384{ 389{
385 read_descriptor_t rd_desc; 390 read_descriptor_t rd_desc;
386 struct sock *csk = strp->sk; 391 struct sock *csk = strp->sk;
387 392
388 /* We need the read lock to synchronize with strp_tcp_data_ready. We 393 /* We need the read lock to synchronize with strp_data_ready. We
389 * need the socket lock for calling tcp_read_sock. 394 * need the socket lock for calling strp_read_sock.
390 */ 395 */
391 lock_sock(csk); 396 lock_sock(csk);
392 397
@@ -398,7 +403,7 @@ static void do_strp_rx_work(struct strparser *strp)
398 403
399 rd_desc.arg.data = strp; 404 rd_desc.arg.data = strp;
400 405
401 if (strp_tcp_read_sock(strp) == -ENOMEM) 406 if (strp_read_sock(strp) == -ENOMEM)
402 queue_work(strp_wq, &strp->rx_work); 407 queue_work(strp_wq, &strp->rx_work);
403 408
404out: 409out:
@@ -424,9 +429,14 @@ static void strp_rx_msg_timeout(unsigned long arg)
424int strp_init(struct strparser *strp, struct sock *csk, 429int strp_init(struct strparser *strp, struct sock *csk,
425 struct strp_callbacks *cb) 430 struct strp_callbacks *cb)
426{ 431{
432 struct socket *sock = csk->sk_socket;
433
427 if (!cb || !cb->rcv_msg || !cb->parse_msg) 434 if (!cb || !cb->rcv_msg || !cb->parse_msg)
428 return -EINVAL; 435 return -EINVAL;
429 436
437 if (!sock->ops->read_sock || !sock->ops->peek_len)
438 return -EAFNOSUPPORT;
439
430 memset(strp, 0, sizeof(*strp)); 440 memset(strp, 0, sizeof(*strp));
431 441
432 strp->sk = csk; 442 strp->sk = csk;
@@ -456,7 +466,7 @@ void strp_unpause(struct strparser *strp)
456} 466}
457EXPORT_SYMBOL_GPL(strp_unpause); 467EXPORT_SYMBOL_GPL(strp_unpause);
458 468
459/* strp must already be stopped so that strp_tcp_recv will no longer be called. 469/* strp must already be stopped so that strp_recv will no longer be called.
460 * Note that strp_done is not called with the lower socket held. 470 * Note that strp_done is not called with the lower socket held.
461 */ 471 */
462void strp_done(struct strparser *strp) 472void strp_done(struct strparser *strp)