2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "stc-monitor-ipt.h"
18 #include "stc-monitor-context.h"
20 static nfacct_rule_jump __get_jump_by_intend(struct nfacct_rule *counter)
22 if (counter->intend == NFACCT_WARN)
23 return NFACCT_JUMP_ACCEPT;
24 else if (counter->intend == NFACCT_BLOCK)
25 return NFACCT_JUMP_REJECT;
26 else if (counter->intend == NFACCT_ALLOW)
27 return NFACCT_JUMP_ACCEPT;
28 else if (counter->intend == NFACCT_TETH_BLOCK)
29 return NFACCT_JUMP_REJECT;
30 else if (counter->intend == NFACCT_TETH_ALLOW)
31 return NFACCT_JUMP_ACCEPT;
33 return NFACCT_JUMP_UNKNOWN;
36 stc_error_e stc_monitor_ipt_add_in(struct nfacct_rule *counter)
39 return STC_ERROR_INVALID_PARAMETER;
41 counter->action = NFACCT_ACTION_INSERT;
42 counter->iotype = NFACCT_COUNTER_IN;
43 counter->jump = __get_jump_by_intend(counter);
44 counter->iptype = NFACCT_TYPE_IPV4;
45 counter->send_limit = 0;
46 counter->rcv_limit = 0;
48 return produce_net_rule(counter);
51 stc_error_e stc_monitor_ipt_add_out(struct nfacct_rule *counter)
54 return STC_ERROR_INVALID_PARAMETER;
56 counter->action = NFACCT_ACTION_INSERT;
57 counter->iotype = NFACCT_COUNTER_OUT;
58 counter->jump = __get_jump_by_intend(counter);
59 counter->iptype = NFACCT_TYPE_IPV4;
60 counter->send_limit = 0;
61 counter->rcv_limit = 0;
63 return produce_net_rule(counter);
66 stc_error_e stc_monitor_ipt_del_in(struct nfacct_rule *counter)
69 return STC_ERROR_INVALID_PARAMETER;
71 counter->action = NFACCT_ACTION_DELETE;
72 counter->iotype = NFACCT_COUNTER_IN;
73 counter->jump = __get_jump_by_intend(counter);
74 counter->iptype = NFACCT_TYPE_IPV4;
75 counter->send_limit = 0;
76 counter->rcv_limit = 0;
78 return produce_net_rule(counter);
81 stc_error_e stc_monitor_ipt_del_out(struct nfacct_rule *counter)
84 return STC_ERROR_INVALID_PARAMETER;
86 counter->action = NFACCT_ACTION_DELETE;
87 counter->iotype = NFACCT_COUNTER_OUT;
88 counter->jump = __get_jump_by_intend(counter);
89 counter->iptype = NFACCT_TYPE_IPV4;
90 counter->send_limit = 0;
91 counter->rcv_limit = 0;
93 return produce_net_rule(counter);
96 stc_error_e stc_monitor_ip6t_add_in(struct nfacct_rule *counter)
99 return STC_ERROR_INVALID_PARAMETER;
101 counter->action = NFACCT_ACTION_INSERT;
102 counter->iotype = NFACCT_COUNTER_IN;
103 counter->jump = __get_jump_by_intend(counter);
104 counter->iptype = NFACCT_TYPE_IPV6;
105 counter->send_limit = 0;
106 counter->rcv_limit = 0;
108 return produce_net_rule(counter);
111 stc_error_e stc_monitor_ip6t_add_out(struct nfacct_rule *counter)
114 return STC_ERROR_INVALID_PARAMETER;
116 counter->action = NFACCT_ACTION_INSERT;
117 counter->iotype = NFACCT_COUNTER_OUT;
118 counter->jump = __get_jump_by_intend(counter);
119 counter->iptype = NFACCT_TYPE_IPV6;
120 counter->send_limit = 0;
121 counter->rcv_limit = 0;
123 return produce_net_rule(counter);
126 stc_error_e stc_monitor_ip6t_del_in(struct nfacct_rule *counter)
129 return STC_ERROR_INVALID_PARAMETER;
131 counter->action = NFACCT_ACTION_DELETE;
132 counter->iotype = NFACCT_COUNTER_IN;
133 counter->jump = __get_jump_by_intend(counter);
134 counter->iptype = NFACCT_TYPE_IPV6;
135 counter->send_limit = 0;
136 counter->rcv_limit = 0;
138 return produce_net_rule(counter);
141 stc_error_e stc_monitor_ip6t_del_out(struct nfacct_rule *counter)
144 return STC_ERROR_INVALID_PARAMETER;
146 counter->action = NFACCT_ACTION_DELETE;
147 counter->iotype = NFACCT_COUNTER_OUT;
148 counter->jump = __get_jump_by_intend(counter);
149 counter->iptype = NFACCT_TYPE_IPV6;
150 counter->send_limit = 0;
151 counter->rcv_limit = 0;
153 return produce_net_rule(counter);
156 stc_error_e stc_monitor_tether_add_in(struct nfacct_rule *counter,
161 if (counter == NULL || ipaddr == NULL)
162 return STC_ERROR_INVALID_PARAMETER;
164 counter->action = NFACCT_ACTION_INSERT;
165 counter->iotype = NFACCT_COUNTER_IN;
166 counter->jump = __get_jump_by_intend(counter);
167 counter->iptype = NFACCT_TYPE_IPV4;
168 counter->send_limit = 0;
169 counter->rcv_limit = 0;
170 counter->src_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
171 counter->src_ip1 = g_strdup(ipaddr);
173 ret = produce_net_rule(counter);
175 FREE(counter->src_ip1);
176 counter->src_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
180 stc_error_e stc_monitor_tether_add_out(struct nfacct_rule *counter,
185 if (counter == NULL || ipaddr == NULL)
186 return STC_ERROR_INVALID_PARAMETER;
188 counter->action = NFACCT_ACTION_INSERT;
189 counter->iotype = NFACCT_COUNTER_OUT;
190 counter->jump = __get_jump_by_intend(counter);
191 counter->iptype = NFACCT_TYPE_IPV4;
192 counter->send_limit = 0;
193 counter->rcv_limit = 0;
194 counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
195 counter->dst_ip1 = g_strdup(ipaddr);
197 ret = produce_net_rule(counter);
199 FREE(counter->dst_ip1);
200 counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
204 stc_error_e stc_monitor_tether_del_in(struct nfacct_rule *counter,
209 if (counter == NULL || ipaddr == NULL)
210 return STC_ERROR_INVALID_PARAMETER;
212 counter->action = NFACCT_ACTION_DELETE;
213 counter->iotype = NFACCT_COUNTER_IN;
214 counter->jump = __get_jump_by_intend(counter);
215 counter->iptype = NFACCT_TYPE_IPV4;
216 counter->send_limit = 0;
217 counter->rcv_limit = 0;
218 counter->src_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
219 counter->src_ip1 = g_strdup(ipaddr);
221 ret = produce_net_rule(counter);
223 FREE(counter->src_ip1);
224 counter->src_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
228 stc_error_e stc_monitor_tether_del_out(struct nfacct_rule *counter,
233 if (counter == NULL || ipaddr == NULL)
234 return STC_ERROR_INVALID_PARAMETER;
236 counter->action = NFACCT_ACTION_DELETE;
237 counter->iotype = NFACCT_COUNTER_OUT;
238 counter->jump = __get_jump_by_intend(counter);
239 counter->iptype = NFACCT_TYPE_IPV4;
240 counter->send_limit = 0;
241 counter->rcv_limit = 0;
242 counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
243 counter->dst_ip1 = g_strdup(ipaddr);
245 ret = produce_net_rule(counter);
247 FREE(counter->dst_ip1);
248 counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_NONE;