aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/filter.h30
-rw-r--r--include/net/sock.h27
-rw-r--r--net/core/filter.c27
3 files changed, 42 insertions, 42 deletions
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 93a9792e27bc..9bde3ed19fe6 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -50,28 +50,32 @@ static inline unsigned int sk_filter_size(unsigned int proglen)
50#define sk_filter_proglen(fprog) \ 50#define sk_filter_proglen(fprog) \
51 (fprog->len * sizeof(fprog->filter[0])) 51 (fprog->len * sizeof(fprog->filter[0]))
52 52
53extern int sk_filter(struct sock *sk, struct sk_buff *skb); 53int sk_filter(struct sock *sk, struct sk_buff *skb);
54extern unsigned int sk_run_filter(const struct sk_buff *skb, 54unsigned int sk_run_filter(const struct sk_buff *skb,
55 const struct sock_filter *filter); 55 const struct sock_filter *filter);
56 56
57extern int sk_unattached_filter_create(struct sk_filter **pfp, 57int sk_unattached_filter_create(struct sk_filter **pfp,
58 struct sock_fprog *fprog); 58 struct sock_fprog *fprog);
59extern void sk_unattached_filter_destroy(struct sk_filter *fp); 59void sk_unattached_filter_destroy(struct sk_filter *fp);
60 60
61extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk); 61int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
62extern int sk_detach_filter(struct sock *sk); 62int sk_detach_filter(struct sock *sk);
63 63
64extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen); 64int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
65extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len); 65int sk_get_filter(struct sock *sk, struct sock_filter __user *filter,
66extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to); 66 unsigned int len);
67void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
68
69void sk_filter_charge(struct sock *sk, struct sk_filter *fp);
70void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
67 71
68#ifdef CONFIG_BPF_JIT 72#ifdef CONFIG_BPF_JIT
69#include <stdarg.h> 73#include <stdarg.h>
70#include <linux/linkage.h> 74#include <linux/linkage.h>
71#include <linux/printk.h> 75#include <linux/printk.h>
72 76
73extern void bpf_jit_compile(struct sk_filter *fp); 77void bpf_jit_compile(struct sk_filter *fp);
74extern void bpf_jit_free(struct sk_filter *fp); 78void bpf_jit_free(struct sk_filter *fp);
75 79
76static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen, 80static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
77 u32 pass, void *image) 81 u32 pass, void *image)
diff --git a/include/net/sock.h b/include/net/sock.h
index 8d7c431a0660..06a5668f05c9 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1621,33 +1621,6 @@ void sk_common_release(struct sock *sk);
1621/* Initialise core socket variables */ 1621/* Initialise core socket variables */
1622void sock_init_data(struct socket *sock, struct sock *sk); 1622void sock_init_data(struct socket *sock, struct sock *sk);
1623 1623
1624void sk_filter_release_rcu(struct rcu_head *rcu);
1625
1626/**
1627 * sk_filter_release - release a socket filter
1628 * @fp: filter to remove
1629 *
1630 * Remove a filter from a socket and release its resources.
1631 */
1632
1633static inline void sk_filter_release(struct sk_filter *fp)
1634{
1635 if (atomic_dec_and_test(&fp->refcnt))
1636 call_rcu(&fp->rcu, sk_filter_release_rcu);
1637}
1638
1639static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
1640{
1641 atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
1642 sk_filter_release(fp);
1643}
1644
1645static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
1646{
1647 atomic_inc(&fp->refcnt);
1648 atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
1649}
1650
1651/* 1624/*
1652 * Socket reference counting postulates. 1625 * Socket reference counting postulates.
1653 * 1626 *
diff --git a/net/core/filter.c b/net/core/filter.c
index 9730e7fe4770..5b3427aaeca5 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -664,14 +664,37 @@ static void sk_release_orig_filter(struct sk_filter *fp)
664 * sk_filter_release_rcu - Release a socket filter by rcu_head 664 * sk_filter_release_rcu - Release a socket filter by rcu_head
665 * @rcu: rcu_head that contains the sk_filter to free 665 * @rcu: rcu_head that contains the sk_filter to free
666 */ 666 */
667void sk_filter_release_rcu(struct rcu_head *rcu) 667static void sk_filter_release_rcu(struct rcu_head *rcu)
668{ 668{
669 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu); 669 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
670 670
671 sk_release_orig_filter(fp); 671 sk_release_orig_filter(fp);
672 bpf_jit_free(fp); 672 bpf_jit_free(fp);
673} 673}
674EXPORT_SYMBOL(sk_filter_release_rcu); 674
675/**
676 * sk_filter_release - release a socket filter
677 * @fp: filter to remove
678 *
679 * Remove a filter from a socket and release its resources.
680 */
681static void sk_filter_release(struct sk_filter *fp)
682{
683 if (atomic_dec_and_test(&fp->refcnt))
684 call_rcu(&fp->rcu, sk_filter_release_rcu);
685}
686
687void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
688{
689 atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
690 sk_filter_release(fp);
691}
692
693void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
694{
695 atomic_inc(&fp->refcnt);
696 atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
697}
675 698
676static int __sk_prepare_filter(struct sk_filter *fp) 699static int __sk_prepare_filter(struct sk_filter *fp)
677{ 700{