• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * (C) 2005-2011 by Pablo Neira Ayuso <pablo@netfilter.org>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  */
9 
10 #include "internal/internal.h"
11 
get_attr_grp_orig_ipv4(const struct nf_conntrack * ct,void * data)12 static void get_attr_grp_orig_ipv4(const struct nf_conntrack *ct, void *data)
13 {
14 	struct nfct_attr_grp_ipv4 *this = data;
15 	this->src = ct->head.orig.src.v4;
16 	this->dst = ct->head.orig.dst.v4;
17 }
18 
get_attr_grp_repl_ipv4(const struct nf_conntrack * ct,void * data)19 static void get_attr_grp_repl_ipv4(const struct nf_conntrack *ct, void *data)
20 {
21 	struct nfct_attr_grp_ipv4 *this = data;
22 	this->src = ct->repl.src.v4;
23 	this->dst = ct->repl.dst.v4;
24 }
25 
get_attr_grp_orig_ipv6(const struct nf_conntrack * ct,void * data)26 static void get_attr_grp_orig_ipv6(const struct nf_conntrack *ct, void *data)
27 {
28 	struct nfct_attr_grp_ipv6 *this = data;
29 	memcpy(this->src, &ct->head.orig.src.v6, sizeof(uint32_t)*4);
30 	memcpy(this->dst, &ct->head.orig.dst.v6, sizeof(uint32_t)*4);
31 }
32 
get_attr_grp_repl_ipv6(const struct nf_conntrack * ct,void * data)33 static void get_attr_grp_repl_ipv6(const struct nf_conntrack *ct, void *data)
34 {
35 	struct nfct_attr_grp_ipv6 *this = data;
36 	memcpy(this->src, &ct->repl.src.v6, sizeof(uint32_t)*4);
37 	memcpy(this->dst, &ct->repl.dst.v6, sizeof(uint32_t)*4);
38 }
39 
get_attr_grp_orig_port(const struct nf_conntrack * ct,void * data)40 static void get_attr_grp_orig_port(const struct nf_conntrack *ct, void *data)
41 {
42 	struct nfct_attr_grp_port *this = data;
43 	this->sport = ct->head.orig.l4src.all;
44 	this->dport = ct->head.orig.l4dst.all;
45 }
46 
get_attr_grp_repl_port(const struct nf_conntrack * ct,void * data)47 static void get_attr_grp_repl_port(const struct nf_conntrack *ct, void *data)
48 {
49 	struct nfct_attr_grp_port *this = data;
50 	this->sport = ct->repl.l4src.all;
51 	this->dport = ct->repl.l4dst.all;
52 }
53 
get_attr_grp_icmp(const struct nf_conntrack * ct,void * data)54 static void get_attr_grp_icmp(const struct nf_conntrack *ct, void *data)
55 {
56 	struct nfct_attr_grp_icmp *this = data;
57 	this->type = ct->head.orig.l4dst.icmp.type;
58 	this->code = ct->head.orig.l4dst.icmp.code;
59 	this->id = ct->head.orig.l4src.icmp.id;
60 }
61 
get_attr_grp_master_ipv4(const struct nf_conntrack * ct,void * data)62 static void get_attr_grp_master_ipv4(const struct nf_conntrack *ct, void *data)
63 {
64 	struct nfct_attr_grp_ipv4 *this = data;
65 	this->src = ct->master.src.v4;
66 	this->dst = ct->master.dst.v4;
67 }
68 
get_attr_grp_master_ipv6(const struct nf_conntrack * ct,void * data)69 static void get_attr_grp_master_ipv6(const struct nf_conntrack *ct, void *data)
70 {
71 	struct nfct_attr_grp_ipv6 *this = data;
72 	memcpy(this->src, &ct->master.src.v6, sizeof(uint32_t)*4);
73 	memcpy(this->dst, &ct->master.dst.v6, sizeof(uint32_t)*4);
74 }
75 
get_attr_grp_master_port(const struct nf_conntrack * ct,void * data)76 static void get_attr_grp_master_port(const struct nf_conntrack *ct, void *data)
77 {
78 	struct nfct_attr_grp_port *this = data;
79 	this->sport = ct->master.l4src.all;
80 	this->dport = ct->master.l4dst.all;
81 }
82 
get_attr_grp_orig_ctrs(const struct nf_conntrack * ct,void * data)83 static void get_attr_grp_orig_ctrs(const struct nf_conntrack *ct, void *data)
84 {
85 	struct nfct_attr_grp_ctrs *this = data;
86 	this->packets = ct->counters[__DIR_ORIG].packets;
87 	this->bytes = ct->counters[__DIR_ORIG].bytes;
88 }
89 
get_attr_grp_repl_ctrs(const struct nf_conntrack * ct,void * data)90 static void get_attr_grp_repl_ctrs(const struct nf_conntrack *ct, void *data)
91 {
92 	struct nfct_attr_grp_ctrs *this = data;
93 	this->packets = ct->counters[__DIR_REPL].packets;
94 	this->bytes = ct->counters[__DIR_REPL].bytes;
95 }
96 
97 static void
get_attr_grp_orig_addr_src(const struct nf_conntrack * ct,void * data)98 get_attr_grp_orig_addr_src(const struct nf_conntrack *ct, void *data)
99 {
100 	union nfct_attr_grp_addr *this = data;
101 	memcpy(&this->addr, &ct->head.orig.src, sizeof(ct->head.orig.src));
102 }
103 
104 static void
get_attr_grp_orig_addr_dst(const struct nf_conntrack * ct,void * data)105 get_attr_grp_orig_addr_dst(const struct nf_conntrack *ct, void *data)
106 {
107 	union nfct_attr_grp_addr *this = data;
108 	memcpy(&this->addr, &ct->head.orig.dst, sizeof(ct->head.orig.dst));
109 }
110 
111 static void
get_attr_grp_repl_addr_src(const struct nf_conntrack * ct,void * data)112 get_attr_grp_repl_addr_src(const struct nf_conntrack *ct, void *data)
113 {
114 	union nfct_attr_grp_addr *this = data;
115 	memcpy(&this->addr, &ct->repl.src, sizeof(ct->repl.src));
116 }
117 
118 static void
get_attr_grp_repl_addr_dst(const struct nf_conntrack * ct,void * data)119 get_attr_grp_repl_addr_dst(const struct nf_conntrack *ct, void *data)
120 {
121 	union nfct_attr_grp_addr *this = data;
122 	memcpy(&this->addr, &ct->repl.dst, sizeof(ct->repl.dst));
123 }
124 
125 const get_attr_grp get_attr_grp_array[ATTR_GRP_MAX] = {
126 	[ATTR_GRP_ORIG_IPV4]		= get_attr_grp_orig_ipv4,
127 	[ATTR_GRP_REPL_IPV4]		= get_attr_grp_repl_ipv4,
128 	[ATTR_GRP_ORIG_IPV6]		= get_attr_grp_orig_ipv6,
129 	[ATTR_GRP_REPL_IPV6]		= get_attr_grp_repl_ipv6,
130 	[ATTR_GRP_ORIG_PORT]		= get_attr_grp_orig_port,
131 	[ATTR_GRP_REPL_PORT]		= get_attr_grp_repl_port,
132 	[ATTR_GRP_ICMP]			= get_attr_grp_icmp,
133 	[ATTR_GRP_MASTER_IPV4]		= get_attr_grp_master_ipv4,
134 	[ATTR_GRP_MASTER_IPV6]		= get_attr_grp_master_ipv6,
135 	[ATTR_GRP_MASTER_PORT]		= get_attr_grp_master_port,
136 	[ATTR_GRP_ORIG_COUNTERS]	= get_attr_grp_orig_ctrs,
137 	[ATTR_GRP_REPL_COUNTERS]	= get_attr_grp_repl_ctrs,
138 	[ATTR_GRP_ORIG_ADDR_SRC]	= get_attr_grp_orig_addr_src,
139 	[ATTR_GRP_ORIG_ADDR_DST]	= get_attr_grp_orig_addr_dst,
140 	[ATTR_GRP_REPL_ADDR_SRC]	= get_attr_grp_repl_addr_src,
141 	[ATTR_GRP_REPL_ADDR_DST]	= get_attr_grp_repl_addr_dst,
142 };
143