[NET]: skb_find_text() - Find a text pattern in skb data

Finds a pattern in the skb data according to the specified
textsearch configuration. Use textsearch_next() to retrieve
subsequent occurrences of the pattern. Returns the offset
to the first occurrence or UINT_MAX if no match was found.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Thomas Graf and committed by David S. Miller 3fc7e8a6 677e90ed

+45
+5
include/linux/skbuff.h
··· 27 27 #include <linux/highmem.h> 28 28 #include <linux/poll.h> 29 29 #include <linux/net.h> 30 + #include <linux/textsearch.h> 30 31 #include <net/checksum.h> 31 32 32 33 #define HAVE_ALLOC_SKB /* For the drivers to know */ ··· 339 338 extern unsigned int skb_seq_read(unsigned int consumed, const u8 **data, 340 339 struct skb_seq_state *st); 341 340 extern void skb_abort_seq_read(struct skb_seq_state *st); 341 + 342 + extern unsigned int skb_find_text(struct sk_buff *skb, unsigned int from, 343 + unsigned int to, struct ts_config *config, 344 + struct ts_state *state); 342 345 343 346 /* Internal */ 344 347 #define skb_shinfo(SKB) ((struct skb_shared_info *)((SKB)->end))
+40
net/core/skbuff.c
··· 1614 1614 kunmap_skb_frag(st->frag_data); 1615 1615 } 1616 1616 1617 + #define TS_SKB_CB(state) ((struct skb_seq_state *) &((state)->cb)) 1618 + 1619 + static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text, 1620 + struct ts_config *conf, 1621 + struct ts_state *state) 1622 + { 1623 + return skb_seq_read(offset, text, TS_SKB_CB(state)); 1624 + } 1625 + 1626 + static void skb_ts_finish(struct ts_config *conf, struct ts_state *state) 1627 + { 1628 + skb_abort_seq_read(TS_SKB_CB(state)); 1629 + } 1630 + 1631 + /** 1632 + * skb_find_text - Find a text pattern in skb data 1633 + * @skb: the buffer to look in 1634 + * @from: search offset 1635 + * @to: search limit 1636 + * @config: textsearch configuration 1637 + * @state: uninitialized textsearch state variable 1638 + * 1639 + * Finds a pattern in the skb data according to the specified 1640 + * textsearch configuration. Use textsearch_next() to retrieve 1641 + * subsequent occurrences of the pattern. Returns the offset 1642 + * to the first occurrence or UINT_MAX if no match was found. 1643 + */ 1644 + unsigned int skb_find_text(struct sk_buff *skb, unsigned int from, 1645 + unsigned int to, struct ts_config *config, 1646 + struct ts_state *state) 1647 + { 1648 + config->get_next_block = skb_ts_get_next_block; 1649 + config->finish = skb_ts_finish; 1650 + 1651 + skb_prepare_seq_read(skb, from, to, TS_SKB_CB(state)); 1652 + 1653 + return textsearch_find(config, state); 1654 + } 1655 + 1617 1656 void __init skb_init(void) 1618 1657 { 1619 1658 skbuff_head_cache = kmem_cache_create("skbuff_head_cache", ··· 1694 1655 EXPORT_SYMBOL(skb_prepare_seq_read); 1695 1656 EXPORT_SYMBOL(skb_seq_read); 1696 1657 EXPORT_SYMBOL(skb_abort_seq_read); 1658 + EXPORT_SYMBOL(skb_find_text);