History

netfilter: ctnetlink: add expectation deletion events

This patch allows to listen to events that inform about expectations destroyed.

Pablo Neira Ayuso committed 16 years ago

Commit ebbf41d1 parent 43f974c4 files · +33 −12Browse files

Unified · Split

4 files
  1. include/linux/netfilter/nf_conntrack_common.h +1 −0
  2. include/net/netfilter/nf_conntrack_expect.h +7 −1
  3. net/netfilter/nf_conntrack_expect.c +4 −2
  4. net/netfilter/nf_conntrack_netlink.c +21 −9
include/linux/netfilter/nf_conntrack_common.h+1−0
@@ -98,6 +98,7 @@ enum ip_conntrack_events { · 97 unmodified lines
9898
9999 enum ip_conntrack_expect_events {
100100 IPEXP_NEW, /* new expectation */
101+ IPEXP_DESTROY, /* destroyed expectation */
101102 };
102103
103104 /* expectation flags */
include/net/netfilter/nf_conntrack_expect.h+7−1
@@ -82,7 +82,13 @@ struct nf_conntrack_expect * · 81 unmodified lines
8282 nf_ct_find_expectation(struct net *net, u16 zone,
8383 const struct nf_conntrack_tuple *tuple);
8484
85−void nf_ct_unlink_expect(struct nf_conntrack_expect *exp);
85+void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
86+ u32 pid, int report);
87+static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
88+{
89+ nf_ct_unlink_expect_report(exp, 0, 0);
90+}
91+
8692 void nf_ct_remove_expectations(struct nf_conn *ct);
8793 void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
8894 void nf_ct_remove_userspace_expectations(void);
net/netfilter/nf_conntrack_expect.c+4−2
@@ -41,7 +41,8 @@ static struct kmem_cache *nf_ct_expect_cachep __read_mostly; · 40 unmodified lines
4141 static HLIST_HEAD(nf_ct_userspace_expect_list);
4242
4343 /* nf_conntrack_expect helper functions */
44−void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
44+void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
45+ u32 pid, int report)
4546 {
4647 struct nf_conn_help *master_help = nfct_help(exp->master);
4748 struct net *net = nf_ct_exp_net(exp);
@@ -55,11 +56,12 @@ void nf_ct_unlink_expect(struct nf_conntrack_expect *exp) · 7 unmodified lines
5556 if (!(exp->flags & NF_CT_EXPECT_USERSPACE))
5657 master_help->expecting[exp->class]--;
5758
59+ nf_ct_expect_event_report(IPEXP_DESTROY, exp, pid, report);
5860 nf_ct_expect_put(exp);
5961
6062 NF_CT_STAT_INC(net, expect_delete);
6163 }
62−EXPORT_SYMBOL_GPL(nf_ct_unlink_expect);
64+EXPORT_SYMBOL_GPL(nf_ct_unlink_expect_report);
6365
6466 static void nf_ct_expectation_timed_out(unsigned long ul_expect)
6567 {
net/netfilter/nf_conntrack_netlink.c+21−9
@@ -1632,17 +1632,20 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item) · 1631 unmodified lines
16321632 struct nlmsghdr *nlh;
16331633 struct nfgenmsg *nfmsg;
16341634 struct sk_buff *skb;
1635− unsigned int type;
1635+ unsigned int type, group;
16361636 int flags = 0;
16371637
1638− if (events & (1 << IPEXP_NEW)) {
1638+ if (events & (1 << IPEXP_DESTROY)) {
1639+ type = IPCTNL_MSG_EXP_DELETE;
1640+ group = NFNLGRP_CONNTRACK_EXP_DESTROY;
1641+ } else if (events & (1 << IPEXP_NEW)) {
16391642 type = IPCTNL_MSG_EXP_NEW;
16401643 flags = NLM_F_CREATE|NLM_F_EXCL;
1644+ group = NFNLGRP_CONNTRACK_EXP_NEW;
16411645 } else
16421646 return 0;
16431647
1644− if (!item->report &&
1645− !nfnetlink_has_listeners(net, NFNLGRP_CONNTRACK_EXP_NEW))
1648+ if (!item->report && !nfnetlink_has_listeners(net, group))
16461649 return 0;
16471650
16481651 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
@@ -1665,8 +1668,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item) · 16 unmodified lines
16651668 rcu_read_unlock();
16661669
16671670 nlmsg_end(skb, nlh);
1668− nfnetlink_send(skb, net, item->pid, NFNLGRP_CONNTRACK_EXP_NEW,
1669− item->report, GFP_ATOMIC);
1671+ nfnetlink_send(skb, net, item->pid, group, item->report, GFP_ATOMIC);
16701672 return 0;
16711673
16721674 nla_put_failure:
@@ -1849,7 +1851,13 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, · 176 unmodified lines
18491851 }
18501852
18511853 /* after list removal, usage count == 1 */
1852− nf_ct_unexpect_related(exp);
1854+ spin_lock_bh(&nf_conntrack_lock);
1855+ if (del_timer(&exp->timeout)) {
1856+ nf_ct_unlink_expect_report(exp, NETLINK_CB(skb).pid,
1857+ nlmsg_report(nlh));
1858+ nf_ct_expect_put(exp);
1859+ }
1860+ spin_unlock_bh(&nf_conntrack_lock);
18531861 /* have to put what we 'get' above.
18541862 * after this line usage count == 0 */
18551863 nf_ct_expect_put(exp);
@@ -1866,7 +1874,9 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, · 10 unmodified lines
18661874 m_help = nfct_help(exp->master);
18671875 if (!strcmp(m_help->helper->name, name) &&
18681876 del_timer(&exp->timeout)) {
1869− nf_ct_unlink_expect(exp);
1877+ nf_ct_unlink_expect_report(exp,
1878+ NETLINK_CB(skb).pid,
1879+ nlmsg_report(nlh));
18701880 nf_ct_expect_put(exp);
18711881 }
18721882 }
@@ -1880,7 +1890,9 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, · 7 unmodified lines
18801890 &net->ct.expect_hash[i],
18811891 hnode) {
18821892 if (del_timer(&exp->timeout)) {
1883− nf_ct_unlink_expect(exp);
1893+ nf_ct_unlink_expect_report(exp,
1894+ NETLINK_CB(skb).pid,
1895+ nlmsg_report(nlh));
18841896 nf_ct_expect_put(exp);
18851897 }
18861898 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t