History

netfilter: inline four headers files into another one.

linux/netfilter/ipset/ip_set.h included four other header files: include/linux/netfilter/ipset/ip_set_comment.h include/linux/netfilter/ipset/ip_set_counter.h include/linux/netfilter/ipset/ip_set_skbinfo.h include/linux/netfilter/ipset/ip_set_timeout.h Of these the first three were not included anywhere else. The last, ip_set_timeout.h, was included in a couple of other places, but defined inline functions which call other inline functions defined in ip_set.h, so ip_set.h had to be included before it. Inlined all four into ip_set.h, and updated the other files that included ip_set_timeout.h.

Jeremy Sowden committed 7 years ago

Commit bd96b4c1 parent 43dd16e7 files · +235 −282Browse files

Unified · Split

7 files
  1. include/linux/netfilter/ipset/ip_set.h +234 −4
  2. include/linux/netfilter/ipset/ip_set_comment.h +0 −73
  3. include/linux/netfilter/ipset/ip_set_counter.h +0 −84
  4. include/linux/netfilter/ipset/ip_set_skbinfo.h +0 −42
  5. include/linux/netfilter/ipset/ip_set_timeout.h +0 −77
  6. net/netfilter/ipset/ip_set_hash_gen.h +1 −1
  7. net/netfilter/xt_set.c +0 −1
include/linux/netfilter/ipset/ip_set.h+234−4
@@ -452,10 +452,240 @@ bitmap_bytes(u32 a, u32 b) · 451 unmodified lines
452 return 4 * ((((b - a + 8) / 8) + 3) / 4);452 return 4 * ((((b - a + 8) / 8) + 3) / 4);
453}453}
454 454
455#include <linux/netfilter/ipset/ip_set_timeout.h>455/* How often should the gc be run by default */
456#include <linux/netfilter/ipset/ip_set_comment.h>456#define IPSET_GC_TIME (3 * 60)
457#include <linux/netfilter/ipset/ip_set_counter.h>457
458#include <linux/netfilter/ipset/ip_set_skbinfo.h>458/* Timeout period depending on the timeout value of the given set */
459#define IPSET_GC_PERIOD(timeout) \
460 ((timeout/3) ? min_t(u32, (timeout)/3, IPSET_GC_TIME) : 1)
461
462/* Entry is set with no timeout value */
463#define IPSET_ELEM_PERMANENT 0
464
465/* Set is defined with timeout support: timeout value may be 0 */
466#define IPSET_NO_TIMEOUT UINT_MAX
467
468/* Max timeout value, see msecs_to_jiffies() in jiffies.h */
469#define IPSET_MAX_TIMEOUT (UINT_MAX >> 1)/MSEC_PER_SEC
470
471#define ip_set_adt_opt_timeout(opt, set) \
472((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)
473
474static inline unsigned int
475ip_set_timeout_uget(struct nlattr *tb)
476{
477 unsigned int timeout = ip_set_get_h32(tb);
478
479 /* Normalize to fit into jiffies */
480 if (timeout > IPSET_MAX_TIMEOUT)
481 timeout = IPSET_MAX_TIMEOUT;
482
483 return timeout;
484}
485
486static inline bool
487ip_set_timeout_expired(const unsigned long *t)
488{
489 return *t != IPSET_ELEM_PERMANENT && time_is_before_jiffies(*t);
490}
491
492static inline void
493ip_set_timeout_set(unsigned long *timeout, u32 value)
494{
495 unsigned long t;
496
497 if (!value) {
498 *timeout = IPSET_ELEM_PERMANENT;
499 return;
500 }
501
502 t = msecs_to_jiffies(value * MSEC_PER_SEC) + jiffies;
503 if (t == IPSET_ELEM_PERMANENT)
504 /* Bingo! :-) */
505 t--;
506 *timeout = t;
507}
508
509static inline u32
510ip_set_timeout_get(const unsigned long *timeout)
511{
512 u32 t;
513
514 if (*timeout == IPSET_ELEM_PERMANENT)
515 return 0;
516
517 t = jiffies_to_msecs(*timeout - jiffies)/MSEC_PER_SEC;
518 /* Zero value in userspace means no timeout */
519 return t == 0 ? 1 : t;
520}
521
522static inline char*
523ip_set_comment_uget(struct nlattr *tb)
524{
525 return nla_data(tb);
526}
527
528/* Called from uadd only, protected by the set spinlock.
529 * The kadt functions don't use the comment extensions in any way.
530 */
531static inline void
532ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,
533 const struct ip_set_ext *ext)
534{
535 struct ip_set_comment_rcu *c = rcu_dereference_protected(comment->c, 1);
536 size_t len = ext->comment ? strlen(ext->comment) : 0;
537
538 if (unlikely(c)) {
539 set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
540 kfree_rcu(c, rcu);
541 rcu_assign_pointer(comment->c, NULL);
542 }
543 if (!len)
544 return;
545 if (unlikely(len > IPSET_MAX_COMMENT_SIZE))
546 len = IPSET_MAX_COMMENT_SIZE;
547 c = kmalloc(sizeof(*c) + len + 1, GFP_ATOMIC);
548 if (unlikely(!c))
549 return;
550 strlcpy(c->str, ext->comment, len + 1);
551 set->ext_size += sizeof(*c) + strlen(c->str) + 1;
552 rcu_assign_pointer(comment->c, c);
553}
554
555/* Used only when dumping a set, protected by rcu_read_lock() */
556static inline int
557ip_set_put_comment(struct sk_buff *skb, const struct ip_set_comment *comment)
558{
559 struct ip_set_comment_rcu *c = rcu_dereference(comment->c);
560
561 if (!c)
562 return 0;
563 return nla_put_string(skb, IPSET_ATTR_COMMENT, c->str);
564}
565
566/* Called from uadd/udel, flush or the garbage collectors protected
567 * by the set spinlock.
568 * Called when the set is destroyed and when there can't be any user
569 * of the set data anymore.
570 */
571static inline void
572ip_set_comment_free(struct ip_set *set, struct ip_set_comment *comment)
573{
574 struct ip_set_comment_rcu *c;
575
576 c = rcu_dereference_protected(comment->c, 1);
577 if (unlikely(!c))
578 return;
579 set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
580 kfree_rcu(c, rcu);
581 rcu_assign_pointer(comment->c, NULL);
582}
583
584static inline void
585ip_set_add_bytes(u64 bytes, struct ip_set_counter *counter)
586{
587 atomic64_add((long long)bytes, &(counter)->bytes);
588}
589
590static inline void
591ip_set_add_packets(u64 packets, struct ip_set_counter *counter)
592{
593 atomic64_add((long long)packets, &(counter)->packets);
594}
595
596static inline u64
597ip_set_get_bytes(const struct ip_set_counter *counter)
598{
599 return (u64)atomic64_read(&(counter)->bytes);
600}
601
602static inline u64
603ip_set_get_packets(const struct ip_set_counter *counter)
604{
605 return (u64)atomic64_read(&(counter)->packets);
606}
607
608static inline bool
609ip_set_match_counter(u64 counter, u64 match, u8 op)
610{
611 switch (op) {
612 case IPSET_COUNTER_NONE:
613 return true;
614 case IPSET_COUNTER_EQ:
615 return counter == match;
616 case IPSET_COUNTER_NE:
617 return counter != match;
618 case IPSET_COUNTER_LT:
619 return counter < match;
620 case IPSET_COUNTER_GT:
621 return counter > match;
622 }
623 return false;
624}
625
626static inline void
627ip_set_update_counter(struct ip_set_counter *counter,
628 const struct ip_set_ext *ext, u32 flags)
629{
630 if (ext->packets != ULLONG_MAX &&
631 !(flags & IPSET_FLAG_SKIP_COUNTER_UPDATE)) {
632 ip_set_add_bytes(ext->bytes, counter);
633 ip_set_add_packets(ext->packets, counter);
634 }
635}
636
637static inline bool
638ip_set_put_counter(struct sk_buff *skb, const struct ip_set_counter *counter)
639{
640 return nla_put_net64(skb, IPSET_ATTR_BYTES,
641 cpu_to_be64(ip_set_get_bytes(counter)),
642 IPSET_ATTR_PAD) ||
643 nla_put_net64(skb, IPSET_ATTR_PACKETS,
644 cpu_to_be64(ip_set_get_packets(counter)),
645 IPSET_ATTR_PAD);
646}
647
648static inline void
649ip_set_init_counter(struct ip_set_counter *counter,
650 const struct ip_set_ext *ext)
651{
652 if (ext->bytes != ULLONG_MAX)
653 atomic64_set(&(counter)->bytes, (long long)(ext->bytes));
654 if (ext->packets != ULLONG_MAX)
655 atomic64_set(&(counter)->packets, (long long)(ext->packets));
656}
657
658static inline void
659ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo,
660 const struct ip_set_ext *ext,
661 struct ip_set_ext *mext, u32 flags)
662{
663 mext->skbinfo = *skbinfo;
664}
665
666static inline bool
667ip_set_put_skbinfo(struct sk_buff *skb, const struct ip_set_skbinfo *skbinfo)
668{
669 /* Send nonzero parameters only */
670 return ((skbinfo->skbmark || skbinfo->skbmarkmask) &&
671 nla_put_net64(skb, IPSET_ATTR_SKBMARK,
672 cpu_to_be64((u64)skbinfo->skbmark << 32 |
673 skbinfo->skbmarkmask),
674 IPSET_ATTR_PAD)) ||
675 (skbinfo->skbprio &&
676 nla_put_net32(skb, IPSET_ATTR_SKBPRIO,
677 cpu_to_be32(skbinfo->skbprio))) ||
678 (skbinfo->skbqueue &&
679 nla_put_net16(skb, IPSET_ATTR_SKBQUEUE,
680 cpu_to_be16(skbinfo->skbqueue)));
681}
682
683static inline void
684ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo,
685 const struct ip_set_ext *ext)
686{
687 *skbinfo = ext->skbinfo;
688}
459 689
460#define IP_SET_INIT_KEXT(skb, opt, set) \690#define IP_SET_INIT_KEXT(skb, opt, set) \
461 { .bytes = (skb)->len, .packets = 1, \691 { .bytes = (skb)->len, .packets = 1, \
include/linux/netfilter/ipset/ip_set_comment.h+0−73
@@ -1,73 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef _IP_SET_COMMENT_H
3#define _IP_SET_COMMENT_H
4
5/* Copyright (C) 2013 Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
6 */
7
8#ifdef __KERNEL__
9
10static inline char*
11ip_set_comment_uget(struct nlattr *tb)
12{
13 return nla_data(tb);
14}
15
16/* Called from uadd only, protected by the set spinlock.
17 * The kadt functions don't use the comment extensions in any way.
18 */
19static inline void
20ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,
21 const struct ip_set_ext *ext)
22{
23 struct ip_set_comment_rcu *c = rcu_dereference_protected(comment->c, 1);
24 size_t len = ext->comment ? strlen(ext->comment) : 0;
25
26 if (unlikely(c)) {
27 set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
28 kfree_rcu(c, rcu);
29 rcu_assign_pointer(comment->c, NULL);
30 }
31 if (!len)
32 return;
33 if (unlikely(len > IPSET_MAX_COMMENT_SIZE))
34 len = IPSET_MAX_COMMENT_SIZE;
35 c = kmalloc(sizeof(*c) + len + 1, GFP_ATOMIC);
36 if (unlikely(!c))
37 return;
38 strlcpy(c->str, ext->comment, len + 1);
39 set->ext_size += sizeof(*c) + strlen(c->str) + 1;
40 rcu_assign_pointer(comment->c, c);
41}
42
43/* Used only when dumping a set, protected by rcu_read_lock() */
44static inline int
45ip_set_put_comment(struct sk_buff *skb, const struct ip_set_comment *comment)
46{
47 struct ip_set_comment_rcu *c = rcu_dereference(comment->c);
48
49 if (!c)
50 return 0;
51 return nla_put_string(skb, IPSET_ATTR_COMMENT, c->str);
52}
53
54/* Called from uadd/udel, flush or the garbage collectors protected
55 * by the set spinlock.
56 * Called when the set is destroyed and when there can't be any user
57 * of the set data anymore.
58 */
59static inline void
60ip_set_comment_free(struct ip_set *set, struct ip_set_comment *comment)
61{
62 struct ip_set_comment_rcu *c;
63
64 c = rcu_dereference_protected(comment->c, 1);
65 if (unlikely(!c))
66 return;
67 set->ext_size -= sizeof(*c) + strlen(c->str) + 1;
68 kfree_rcu(c, rcu);
69 rcu_assign_pointer(comment->c, NULL);
70}
71
72#endif
73#endif
include/linux/netfilter/ipset/ip_set_counter.h+0−84
@@ -1,84 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef _IP_SET_COUNTER_H
3#define _IP_SET_COUNTER_H
4
5/* Copyright (C) 2015 Jozsef Kadlecsik <kadlec@netfilter.org> */
6
7#ifdef __KERNEL__
8
9static inline void
10ip_set_add_bytes(u64 bytes, struct ip_set_counter *counter)
11{
12 atomic64_add((long long)bytes, &(counter)->bytes);
13}
14
15static inline void
16ip_set_add_packets(u64 packets, struct ip_set_counter *counter)
17{
18 atomic64_add((long long)packets, &(counter)->packets);
19}
20
21static inline u64
22ip_set_get_bytes(const struct ip_set_counter *counter)
23{
24 return (u64)atomic64_read(&(counter)->bytes);
25}
26
27static inline u64
28ip_set_get_packets(const struct ip_set_counter *counter)
29{
30 return (u64)atomic64_read(&(counter)->packets);
31}
32
33static inline bool
34ip_set_match_counter(u64 counter, u64 match, u8 op)
35{
36 switch (op) {
37 case IPSET_COUNTER_NONE:
38 return true;
39 case IPSET_COUNTER_EQ:
40 return counter == match;
41 case IPSET_COUNTER_NE:
42 return counter != match;
43 case IPSET_COUNTER_LT:
44 return counter < match;
45 case IPSET_COUNTER_GT:
46 return counter > match;
47 }
48 return false;
49}
50
51static inline void
52ip_set_update_counter(struct ip_set_counter *counter,
53 const struct ip_set_ext *ext, u32 flags)
54{
55 if (ext->packets != ULLONG_MAX &&
56 !(flags & IPSET_FLAG_SKIP_COUNTER_UPDATE)) {
57 ip_set_add_bytes(ext->bytes, counter);
58 ip_set_add_packets(ext->packets, counter);
59 }
60}
61
62static inline bool
63ip_set_put_counter(struct sk_buff *skb, const struct ip_set_counter *counter)
64{
65 return nla_put_net64(skb, IPSET_ATTR_BYTES,
66 cpu_to_be64(ip_set_get_bytes(counter)),
67 IPSET_ATTR_PAD) ||
68 nla_put_net64(skb, IPSET_ATTR_PACKETS,
69 cpu_to_be64(ip_set_get_packets(counter)),
70 IPSET_ATTR_PAD);
71}
72
73static inline void
74ip_set_init_counter(struct ip_set_counter *counter,
75 const struct ip_set_ext *ext)
76{
77 if (ext->bytes != ULLONG_MAX)
78 atomic64_set(&(counter)->bytes, (long long)(ext->bytes));
79 if (ext->packets != ULLONG_MAX)
80 atomic64_set(&(counter)->packets, (long long)(ext->packets));
81}
82
83#endif /* __KERNEL__ */
84#endif /* _IP_SET_COUNTER_H */
include/linux/netfilter/ipset/ip_set_skbinfo.h+0−42
@@ -1,42 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef _IP_SET_SKBINFO_H
3#define _IP_SET_SKBINFO_H
4
5/* Copyright (C) 2015 Jozsef Kadlecsik <kadlec@netfilter.org> */
6
7#ifdef __KERNEL__
8
9static inline void
10ip_set_get_skbinfo(struct ip_set_skbinfo *skbinfo,
11 const struct ip_set_ext *ext,
12 struct ip_set_ext *mext, u32 flags)
13{
14 mext->skbinfo = *skbinfo;
15}
16
17static inline bool
18ip_set_put_skbinfo(struct sk_buff *skb, const struct ip_set_skbinfo *skbinfo)
19{
20 /* Send nonzero parameters only */
21 return ((skbinfo->skbmark || skbinfo->skbmarkmask) &&
22 nla_put_net64(skb, IPSET_ATTR_SKBMARK,
23 cpu_to_be64((u64)skbinfo->skbmark << 32 |
24 skbinfo->skbmarkmask),
25 IPSET_ATTR_PAD)) ||
26 (skbinfo->skbprio &&
27 nla_put_net32(skb, IPSET_ATTR_SKBPRIO,
28 cpu_to_be32(skbinfo->skbprio))) ||
29 (skbinfo->skbqueue &&
30 nla_put_net16(skb, IPSET_ATTR_SKBQUEUE,
31 cpu_to_be16(skbinfo->skbqueue)));
32}
33
34static inline void
35ip_set_init_skbinfo(struct ip_set_skbinfo *skbinfo,
36 const struct ip_set_ext *ext)
37{
38 *skbinfo = ext->skbinfo;
39}
40
41#endif /* __KERNEL__ */
42#endif /* _IP_SET_SKBINFO_H */
include/linux/netfilter/ipset/ip_set_timeout.h+0−77
@@ -1,77 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef _IP_SET_TIMEOUT_H
3#define _IP_SET_TIMEOUT_H
4
5/* Copyright (C) 2003-2013 Jozsef Kadlecsik <kadlec@netfilter.org> */
6
7#ifdef __KERNEL__
8
9/* How often should the gc be run by default */
10#define IPSET_GC_TIME (3 * 60)
11
12/* Timeout period depending on the timeout value of the given set */
13#define IPSET_GC_PERIOD(timeout) \
14 ((timeout/3) ? min_t(u32, (timeout)/3, IPSET_GC_TIME) : 1)
15
16/* Entry is set with no timeout value */
17#define IPSET_ELEM_PERMANENT 0
18
19/* Set is defined with timeout support: timeout value may be 0 */
20#define IPSET_NO_TIMEOUT UINT_MAX
21
22/* Max timeout value, see msecs_to_jiffies() in jiffies.h */
23#define IPSET_MAX_TIMEOUT (UINT_MAX >> 1)/MSEC_PER_SEC
24
25#define ip_set_adt_opt_timeout(opt, set) \
26((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)
27
28static inline unsigned int
29ip_set_timeout_uget(struct nlattr *tb)
30{
31 unsigned int timeout = ip_set_get_h32(tb);
32
33 /* Normalize to fit into jiffies */
34 if (timeout > IPSET_MAX_TIMEOUT)
35 timeout = IPSET_MAX_TIMEOUT;
36
37 return timeout;
38}
39
40static inline bool
41ip_set_timeout_expired(const unsigned long *t)
42{
43 return *t != IPSET_ELEM_PERMANENT && time_is_before_jiffies(*t);
44}
45
46static inline void
47ip_set_timeout_set(unsigned long *timeout, u32 value)
48{
49 unsigned long t;
50
51 if (!value) {
52 *timeout = IPSET_ELEM_PERMANENT;
53 return;
54 }
55
56 t = msecs_to_jiffies(value * MSEC_PER_SEC) + jiffies;
57 if (t == IPSET_ELEM_PERMANENT)
58 /* Bingo! :-) */
59 t--;
60 *timeout = t;
61}
62
63static inline u32
64ip_set_timeout_get(const unsigned long *timeout)
65{
66 u32 t;
67
68 if (*timeout == IPSET_ELEM_PERMANENT)
69 return 0;
70
71 t = jiffies_to_msecs(*timeout - jiffies)/MSEC_PER_SEC;
72 /* Zero value in userspace means no timeout */
73 return t == 0 ? 1 : t;
74}
75
76#endif /* __KERNEL__ */
77#endif /* _IP_SET_TIMEOUT_H */
net/netfilter/ipset/ip_set_hash_gen.h+1−1
@@ -7,7 +7,7 @@ · 6 unmodified lines
7#include <linux/rcupdate.h>7#include <linux/rcupdate.h>
8#include <linux/jhash.h>8#include <linux/jhash.h>
9#include <linux/types.h>9#include <linux/types.h>
10#include <linux/netfilter/ipset/ip_set_timeout.h>10#include <linux/netfilter/ipset/ip_set.h>
11 11
12#define __ipset_dereference_protected(p, c) rcu_dereference_protected(p, c)12#define __ipset_dereference_protected(p, c) rcu_dereference_protected(p, c)
13#define ipset_dereference_protected(p, set) \13#define ipset_dereference_protected(p, set) \
net/netfilter/xt_set.c+0−1
@@ -14,7 +14,6 @@ · 13 unmodified lines
14 14
15#include <linux/netfilter/x_tables.h>15#include <linux/netfilter/x_tables.h>
16#include <linux/netfilter/ipset/ip_set.h>16#include <linux/netfilter/ipset/ip_set.h>
17#include <linux/netfilter/ipset/ip_set_timeout.h>
18#include <uapi/linux/netfilter/xt_set.h>17#include <uapi/linux/netfilter/xt_set.h>
19 18
20MODULE_LICENSE("GPL");19MODULE_LICENSE("GPL");