1 #ifndef _IP_SET_COUNTER_H
2 #define _IP_SET_COUNTER_H
4 /* Copyright (C) 2015 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
14 ip_set_add_bytes(u64 bytes, struct ip_set_counter *counter)
16 atomic64_add((long long)bytes, &(counter)->bytes);
20 ip_set_add_packets(u64 packets, struct ip_set_counter *counter)
22 atomic64_add((long long)packets, &(counter)->packets);
26 ip_set_get_bytes(const struct ip_set_counter *counter)
28 return (u64)atomic64_read(&(counter)->bytes);
32 ip_set_get_packets(const struct ip_set_counter *counter)
34 return (u64)atomic64_read(&(counter)->packets);
38 ip_set_update_counter(struct ip_set_counter *counter,
39 const struct ip_set_ext *ext,
40 struct ip_set_ext *mext, u32 flags)
42 if (ext->packets != ULLONG_MAX &&
43 !(flags & IPSET_FLAG_SKIP_COUNTER_UPDATE)) {
44 ip_set_add_bytes(ext->bytes, counter);
45 ip_set_add_packets(ext->packets, counter);
47 if (flags & IPSET_FLAG_MATCH_COUNTERS) {
48 mext->packets = ip_set_get_packets(counter);
49 mext->bytes = ip_set_get_bytes(counter);
54 ip_set_put_counter(struct sk_buff *skb, const struct ip_set_counter *counter)
56 return nla_put_net64(skb, IPSET_ATTR_BYTES,
57 cpu_to_be64(ip_set_get_bytes(counter)),
59 nla_put_net64(skb, IPSET_ATTR_PACKETS,
60 cpu_to_be64(ip_set_get_packets(counter)),
65 ip_set_init_counter(struct ip_set_counter *counter,
66 const struct ip_set_ext *ext)
68 if (ext->bytes != ULLONG_MAX)
69 atomic64_set(&(counter)->bytes, (long long)(ext->bytes));
70 if (ext->packets != ULLONG_MAX)
71 atomic64_set(&(counter)->packets, (long long)(ext->packets));
74 #endif /* __KERNEL__ */
75 #endif /* _IP_SET_COUNTER_H */