1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
* (C) 2009 by Pablo Neira Ayuso <pablo@netfilter.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "conntrackd.h"
#include "origin.h"
static LIST_HEAD(origin_list);
struct origin {
struct list_head head;
unsigned int nl_portid;
int type;
};
/* register a Netlink socket as origin of possible events */
int origin_register(struct nfct_handle *h, int origin_type)
{
struct origin *nlp;
nlp = calloc(sizeof(struct origin), 1);
if (nlp == NULL)
return -1;
nlp->nl_portid = nfnl_portid(nfct_nfnlh(h));
nlp->type = origin_type;
list_add(&nlp->head, &origin_list);
return 0;
}
/* look up for the origin of this Netlink event */
int origin_find(const struct nlmsghdr *nlh)
{
struct origin *this;
list_for_each_entry(this, &origin_list, head) {
if (this->nl_portid == nlh->nlmsg_pid) {
return this->type;
}
}
return CTD_ORIGIN_NOT_ME;
}
int origin_unregister(struct nfct_handle *h)
{
struct origin *this, *tmp;
list_for_each_entry_safe(this, tmp, &origin_list, head) {
if (this->nl_portid == nfnl_portid(nfct_nfnlh(h))) {
list_del(&this->head);
free(this);
return 1;
}
}
return 0;
}
|