diff options
-rw-r--r-- | include/linux/filter.h | 30 | ||||
-rw-r--r-- | include/net/sock.h | 27 | ||||
-rw-r--r-- | net/core/filter.c | 27 |
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 | ||
53 | extern int sk_filter(struct sock *sk, struct sk_buff *skb); | 53 | int sk_filter(struct sock *sk, struct sk_buff *skb); |
54 | extern unsigned int sk_run_filter(const struct sk_buff *skb, | 54 | unsigned int sk_run_filter(const struct sk_buff *skb, |
55 | const struct sock_filter *filter); | 55 | const struct sock_filter *filter); |
56 | 56 | ||
57 | extern int sk_unattached_filter_create(struct sk_filter **pfp, | 57 | int sk_unattached_filter_create(struct sk_filter **pfp, |
58 | struct sock_fprog *fprog); | 58 | struct sock_fprog *fprog); |
59 | extern void sk_unattached_filter_destroy(struct sk_filter *fp); | 59 | void sk_unattached_filter_destroy(struct sk_filter *fp); |
60 | 60 | ||
61 | extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk); | 61 | int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk); |
62 | extern int sk_detach_filter(struct sock *sk); | 62 | int sk_detach_filter(struct sock *sk); |
63 | 63 | ||
64 | extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen); | 64 | int sk_chk_filter(struct sock_filter *filter, unsigned int flen); |
65 | extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len); | 65 | int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, |
66 | extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to); | 66 | unsigned int len); |
67 | void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to); | ||
68 | |||
69 | void sk_filter_charge(struct sock *sk, struct sk_filter *fp); | ||
70 | void 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 | ||
73 | extern void bpf_jit_compile(struct sk_filter *fp); | 77 | void bpf_jit_compile(struct sk_filter *fp); |
74 | extern void bpf_jit_free(struct sk_filter *fp); | 78 | void bpf_jit_free(struct sk_filter *fp); |
75 | 79 | ||
76 | static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen, | 80 | static 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 */ |
1622 | void sock_init_data(struct socket *sock, struct sock *sk); | 1622 | void sock_init_data(struct socket *sock, struct sock *sk); |
1623 | 1623 | ||
1624 | void 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 | |||
1633 | static 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 | |||
1639 | static 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 | |||
1645 | static 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 | */ |
667 | void sk_filter_release_rcu(struct rcu_head *rcu) | 667 | static 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 | } |
674 | EXPORT_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 | */ | ||
681 | static 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 | |||
687 | void 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 | |||
693 | void 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 | ||
676 | static int __sk_prepare_filter(struct sk_filter *fp) | 699 | static int __sk_prepare_filter(struct sk_filter *fp) |
677 | { | 700 | { |