Commit f2ea825f483d5d78754ae813b6db63f8b74e9343

Authored by Jan Engelhardt
Committed by Patrick McHardy
1 parent 5f2b4c9006

[NETFILTER]: nf_nat: use bool type in nf_nat_proto

Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>

Showing 11 changed files with 87 additions and 87 deletions Side-by-side Diff

include/net/netfilter/nf_nat_protocol.h
... ... @@ -15,25 +15,25 @@
15 15  
16 16 /* Translate a packet to the target according to manip type.
17 17 Return true if succeeded. */
18   - int (*manip_pkt)(struct sk_buff *skb,
19   - unsigned int iphdroff,
20   - const struct nf_conntrack_tuple *tuple,
21   - enum nf_nat_manip_type maniptype);
  18 + bool (*manip_pkt)(struct sk_buff *skb,
  19 + unsigned int iphdroff,
  20 + const struct nf_conntrack_tuple *tuple,
  21 + enum nf_nat_manip_type maniptype);
22 22  
23 23 /* Is the manipable part of the tuple between min and max incl? */
24   - int (*in_range)(const struct nf_conntrack_tuple *tuple,
25   - enum nf_nat_manip_type maniptype,
26   - const union nf_conntrack_man_proto *min,
27   - const union nf_conntrack_man_proto *max);
  24 + bool (*in_range)(const struct nf_conntrack_tuple *tuple,
  25 + enum nf_nat_manip_type maniptype,
  26 + const union nf_conntrack_man_proto *min,
  27 + const union nf_conntrack_man_proto *max);
28 28  
29 29 /* Alter the per-proto part of the tuple (depending on
30 30 maniptype), to give a unique tuple in the given range if
31 31 possible; return false if not. Per-protocol part of tuple
32 32 is initialized to the incoming packet. */
33   - int (*unique_tuple)(struct nf_conntrack_tuple *tuple,
34   - const struct nf_nat_range *range,
35   - enum nf_nat_manip_type maniptype,
36   - const struct nf_conn *ct);
  33 + bool (*unique_tuple)(struct nf_conntrack_tuple *tuple,
  34 + const struct nf_nat_range *range,
  35 + enum nf_nat_manip_type maniptype,
  36 + const struct nf_conn *ct);
37 37  
38 38 int (*range_to_nlattr)(struct sk_buff *skb,
39 39 const struct nf_nat_range *range);
40 40  
... ... @@ -59,16 +59,16 @@
59 59 extern void cleanup_protocols(void);
60 60 extern const struct nf_nat_protocol *find_nat_proto(u_int16_t protonum);
61 61  
62   -extern int nf_nat_proto_in_range(const struct nf_conntrack_tuple *tuple,
63   - enum nf_nat_manip_type maniptype,
64   - const union nf_conntrack_man_proto *min,
65   - const union nf_conntrack_man_proto *max);
  62 +extern bool nf_nat_proto_in_range(const struct nf_conntrack_tuple *tuple,
  63 + enum nf_nat_manip_type maniptype,
  64 + const union nf_conntrack_man_proto *min,
  65 + const union nf_conntrack_man_proto *max);
66 66  
67   -extern int nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
68   - const struct nf_nat_range *range,
69   - enum nf_nat_manip_type maniptype,
70   - const struct nf_conn *ct,
71   - u_int16_t *rover);
  67 +extern bool nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
  68 + const struct nf_nat_range *range,
  69 + enum nf_nat_manip_type maniptype,
  70 + const struct nf_conn *ct,
  71 + u_int16_t *rover);
72 72  
73 73 extern int nf_nat_proto_range_to_nlattr(struct sk_buff *skb,
74 74 const struct nf_nat_range *range);
net/ipv4/netfilter/nf_nat_core.c
... ... @@ -349,7 +349,7 @@
349 349 EXPORT_SYMBOL(nf_nat_setup_info);
350 350  
351 351 /* Returns true if succeeded. */
352   -static int
  352 +static bool
353 353 manip_pkt(u_int16_t proto,
354 354 struct sk_buff *skb,
355 355 unsigned int iphdroff,
... ... @@ -360,7 +360,7 @@
360 360 const struct nf_nat_protocol *p;
361 361  
362 362 if (!skb_make_writable(skb, iphdroff + sizeof(*iph)))
363   - return 0;
  363 + return false;
364 364  
365 365 iph = (void *)skb->data + iphdroff;
366 366  
... ... @@ -369,7 +369,7 @@
369 369 /* rcu_read_lock()ed by nf_hook_slow */
370 370 p = __nf_nat_proto_find(proto);
371 371 if (!p->manip_pkt(skb, iphdroff, target, maniptype))
372   - return 0;
  372 + return false;
373 373  
374 374 iph = (void *)skb->data + iphdroff;
375 375  
... ... @@ -380,7 +380,7 @@
380 380 csum_replace4(&iph->check, iph->daddr, target->dst.u3.ip);
381 381 iph->daddr = target->dst.u3.ip;
382 382 }
383   - return 1;
  383 + return true;
384 384 }
385 385  
386 386 /* Do packet manipulations according to nf_nat_setup_info. */
net/ipv4/netfilter/nf_nat_proto_common.c
... ... @@ -17,10 +17,10 @@
17 17 #include <net/netfilter/nf_nat_rule.h>
18 18 #include <net/netfilter/nf_nat_protocol.h>
19 19  
20   -int nf_nat_proto_in_range(const struct nf_conntrack_tuple *tuple,
21   - enum nf_nat_manip_type maniptype,
22   - const union nf_conntrack_man_proto *min,
23   - const union nf_conntrack_man_proto *max)
  20 +bool nf_nat_proto_in_range(const struct nf_conntrack_tuple *tuple,
  21 + enum nf_nat_manip_type maniptype,
  22 + const union nf_conntrack_man_proto *min,
  23 + const union nf_conntrack_man_proto *max)
24 24 {
25 25 __be16 port;
26 26  
... ... @@ -34,11 +34,11 @@
34 34 }
35 35 EXPORT_SYMBOL_GPL(nf_nat_proto_in_range);
36 36  
37   -int nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
38   - const struct nf_nat_range *range,
39   - enum nf_nat_manip_type maniptype,
40   - const struct nf_conn *ct,
41   - u_int16_t *rover)
  37 +bool nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
  38 + const struct nf_nat_range *range,
  39 + enum nf_nat_manip_type maniptype,
  40 + const struct nf_conn *ct,
  41 + u_int16_t *rover)
42 42 {
43 43 unsigned int range_size, min, i;
44 44 __be16 *portptr;
... ... @@ -53,7 +53,7 @@
53 53 if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)) {
54 54 /* If it's dst rewrite, can't change port */
55 55 if (maniptype == IP_NAT_MANIP_DST)
56   - return 0;
  56 + return false;
57 57  
58 58 if (ntohs(*portptr) < 1024) {
59 59 /* Loose convention: >> 512 is credential passing */
60 60  
... ... @@ -83,9 +83,9 @@
83 83 continue;
84 84 if (!(range->flags & IP_NAT_RANGE_PROTO_RANDOM))
85 85 *rover = off;
86   - return 1;
  86 + return true;
87 87 }
88   - return 0;
  88 + return false;
89 89 }
90 90 EXPORT_SYMBOL_GPL(nf_nat_proto_unique_tuple);
91 91  
net/ipv4/netfilter/nf_nat_proto_dccp.c
... ... @@ -22,7 +22,7 @@
22 22  
23 23 static u_int16_t dccp_port_rover;
24 24  
25   -static int
  25 +static bool
26 26 dccp_unique_tuple(struct nf_conntrack_tuple *tuple,
27 27 const struct nf_nat_range *range,
28 28 enum nf_nat_manip_type maniptype,
... ... @@ -32,7 +32,7 @@
32 32 &dccp_port_rover);
33 33 }
34 34  
35   -static int
  35 +static bool
36 36 dccp_manip_pkt(struct sk_buff *skb,
37 37 unsigned int iphdroff,
38 38 const struct nf_conntrack_tuple *tuple,
... ... @@ -49,7 +49,7 @@
49 49 hdrsize = sizeof(struct dccp_hdr);
50 50  
51 51 if (!skb_make_writable(skb, hdroff + hdrsize))
52   - return 0;
  52 + return false;
53 53  
54 54 iph = (struct iphdr *)(skb->data + iphdroff);
55 55 hdr = (struct dccp_hdr *)(skb->data + hdroff);
56 56  
... ... @@ -70,12 +70,12 @@
70 70 *portptr = newport;
71 71  
72 72 if (hdrsize < sizeof(*hdr))
73   - return 1;
  73 + return true;
74 74  
75 75 inet_proto_csum_replace4(&hdr->dccph_checksum, skb, oldip, newip, 1);
76 76 inet_proto_csum_replace2(&hdr->dccph_checksum, skb, oldport, newport,
77 77 0);
78   - return 1;
  78 + return true;
79 79 }
80 80  
81 81 static const struct nf_nat_protocol nf_nat_protocol_dccp = {
net/ipv4/netfilter/nf_nat_proto_gre.c
... ... @@ -37,7 +37,7 @@
37 37 MODULE_DESCRIPTION("Netfilter NAT protocol helper module for GRE");
38 38  
39 39 /* generate unique tuple ... */
40   -static int
  40 +static bool
41 41 gre_unique_tuple(struct nf_conntrack_tuple *tuple,
42 42 const struct nf_nat_range *range,
43 43 enum nf_nat_manip_type maniptype,
... ... @@ -50,7 +50,7 @@
50 50 /* If there is no master conntrack we are not PPTP,
51 51 do not change tuples */
52 52 if (!ct->master)
53   - return 0;
  53 + return false;
54 54  
55 55 if (maniptype == IP_NAT_MANIP_SRC)
56 56 keyptr = &tuple->src.u.gre.key;
57 57  
58 58  
... ... @@ -71,15 +71,15 @@
71 71 for (i = 0; i < range_size; i++, key++) {
72 72 *keyptr = htons(min + key % range_size);
73 73 if (!nf_nat_used_tuple(tuple, ct))
74   - return 1;
  74 + return true;
75 75 }
76 76  
77 77 pr_debug("%p: no NAT mapping\n", ct);
78   - return 0;
  78 + return false;
79 79 }
80 80  
81 81 /* manipulate a GRE packet according to maniptype */
82   -static int
  82 +static bool
83 83 gre_manip_pkt(struct sk_buff *skb, unsigned int iphdroff,
84 84 const struct nf_conntrack_tuple *tuple,
85 85 enum nf_nat_manip_type maniptype)
... ... @@ -92,7 +92,7 @@
92 92 /* pgreh includes two optional 32bit fields which are not required
93 93 * to be there. That's where the magic '8' comes from */
94 94 if (!skb_make_writable(skb, hdroff + sizeof(*pgreh) - 8))
95   - return 0;
  95 + return false;
96 96  
97 97 greh = (void *)skb->data + hdroff;
98 98 pgreh = (struct gre_hdr_pptp *)greh;
... ... @@ -100,7 +100,7 @@
100 100 /* we only have destination manip of a packet, since 'source key'
101 101 * is not present in the packet itself */
102 102 if (maniptype != IP_NAT_MANIP_DST)
103   - return 1;
  103 + return true;
104 104 switch (greh->version) {
105 105 case GRE_VERSION_1701:
106 106 /* We do not currently NAT any GREv0 packets.
107 107  
... ... @@ -112,9 +112,9 @@
112 112 break;
113 113 default:
114 114 pr_debug("can't nat unknown GRE version\n");
115   - return 0;
  115 + return false;
116 116 }
117   - return 1;
  117 + return true;
118 118 }
119 119  
120 120 static const struct nf_nat_protocol gre = {
net/ipv4/netfilter/nf_nat_proto_icmp.c
... ... @@ -17,7 +17,7 @@
17 17 #include <net/netfilter/nf_nat_rule.h>
18 18 #include <net/netfilter/nf_nat_protocol.h>
19 19  
20   -static int
  20 +static bool
21 21 icmp_in_range(const struct nf_conntrack_tuple *tuple,
22 22 enum nf_nat_manip_type maniptype,
23 23 const union nf_conntrack_man_proto *min,
... ... @@ -27,7 +27,7 @@
27 27 ntohs(tuple->src.u.icmp.id) <= ntohs(max->icmp.id);
28 28 }
29 29  
30   -static int
  30 +static bool
31 31 icmp_unique_tuple(struct nf_conntrack_tuple *tuple,
32 32 const struct nf_nat_range *range,
33 33 enum nf_nat_manip_type maniptype,
34 34  
35 35  
... ... @@ -46,12 +46,12 @@
46 46 tuple->src.u.icmp.id = htons(ntohs(range->min.icmp.id) +
47 47 (id % range_size));
48 48 if (!nf_nat_used_tuple(tuple, ct))
49   - return 1;
  49 + return true;
50 50 }
51   - return 0;
  51 + return false;
52 52 }
53 53  
54   -static int
  54 +static bool
55 55 icmp_manip_pkt(struct sk_buff *skb,
56 56 unsigned int iphdroff,
57 57 const struct nf_conntrack_tuple *tuple,
58 58  
... ... @@ -62,13 +62,13 @@
62 62 unsigned int hdroff = iphdroff + iph->ihl*4;
63 63  
64 64 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
65   - return 0;
  65 + return false;
66 66  
67 67 hdr = (struct icmphdr *)(skb->data + hdroff);
68 68 inet_proto_csum_replace2(&hdr->checksum, skb,
69 69 hdr->un.echo.id, tuple->src.u.icmp.id, 0);
70 70 hdr->un.echo.id = tuple->src.u.icmp.id;
71   - return 1;
  71 + return true;
72 72 }
73 73  
74 74 const struct nf_nat_protocol nf_nat_protocol_icmp = {
net/ipv4/netfilter/nf_nat_proto_sctp.c
... ... @@ -16,7 +16,7 @@
16 16  
17 17 static u_int16_t nf_sctp_port_rover;
18 18  
19   -static int
  19 +static bool
20 20 sctp_unique_tuple(struct nf_conntrack_tuple *tuple,
21 21 const struct nf_nat_range *range,
22 22 enum nf_nat_manip_type maniptype,
... ... @@ -26,7 +26,7 @@
26 26 &nf_sctp_port_rover);
27 27 }
28 28  
29   -static int
  29 +static bool
30 30 sctp_manip_pkt(struct sk_buff *skb,
31 31 unsigned int iphdroff,
32 32 const struct nf_conntrack_tuple *tuple,
... ... @@ -39,7 +39,7 @@
39 39 u32 crc32;
40 40  
41 41 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
42   - return 0;
  42 + return false;
43 43  
44 44 iph = (struct iphdr *)(skb->data + iphdroff);
45 45 hdr = (struct sctphdr *)(skb->data + hdroff);
... ... @@ -63,7 +63,7 @@
63 63 crc32 = sctp_end_cksum(crc32);
64 64 hdr->checksum = htonl(crc32);
65 65  
66   - return 1;
  66 + return true;
67 67 }
68 68  
69 69 static const struct nf_nat_protocol nf_nat_protocol_sctp = {
net/ipv4/netfilter/nf_nat_proto_tcp.c
... ... @@ -20,7 +20,7 @@
20 20  
21 21 static u_int16_t tcp_port_rover;
22 22  
23   -static int
  23 +static bool
24 24 tcp_unique_tuple(struct nf_conntrack_tuple *tuple,
25 25 const struct nf_nat_range *range,
26 26 enum nf_nat_manip_type maniptype,
... ... @@ -30,7 +30,7 @@
30 30 &tcp_port_rover);
31 31 }
32 32  
33   -static int
  33 +static bool
34 34 tcp_manip_pkt(struct sk_buff *skb,
35 35 unsigned int iphdroff,
36 36 const struct nf_conntrack_tuple *tuple,
... ... @@ -50,7 +50,7 @@
50 50 hdrsize = sizeof(struct tcphdr);
51 51  
52 52 if (!skb_make_writable(skb, hdroff + hdrsize))
53   - return 0;
  53 + return false;
54 54  
55 55 iph = (struct iphdr *)(skb->data + iphdroff);
56 56 hdr = (struct tcphdr *)(skb->data + hdroff);
57 57  
... ... @@ -73,11 +73,11 @@
73 73 *portptr = newport;
74 74  
75 75 if (hdrsize < sizeof(*hdr))
76   - return 1;
  76 + return true;
77 77  
78 78 inet_proto_csum_replace4(&hdr->check, skb, oldip, newip, 1);
79 79 inet_proto_csum_replace2(&hdr->check, skb, oldport, newport, 0);
80   - return 1;
  80 + return true;
81 81 }
82 82  
83 83 const struct nf_nat_protocol nf_nat_protocol_tcp = {
net/ipv4/netfilter/nf_nat_proto_udp.c
... ... @@ -19,7 +19,7 @@
19 19  
20 20 static u_int16_t udp_port_rover;
21 21  
22   -static int
  22 +static bool
23 23 udp_unique_tuple(struct nf_conntrack_tuple *tuple,
24 24 const struct nf_nat_range *range,
25 25 enum nf_nat_manip_type maniptype,
... ... @@ -29,7 +29,7 @@
29 29 &udp_port_rover);
30 30 }
31 31  
32   -static int
  32 +static bool
33 33 udp_manip_pkt(struct sk_buff *skb,
34 34 unsigned int iphdroff,
35 35 const struct nf_conntrack_tuple *tuple,
... ... @@ -42,7 +42,7 @@
42 42 __be16 *portptr, newport;
43 43  
44 44 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
45   - return 0;
  45 + return false;
46 46  
47 47 iph = (struct iphdr *)(skb->data + iphdroff);
48 48 hdr = (struct udphdr *)(skb->data + hdroff);
... ... @@ -68,7 +68,7 @@
68 68 hdr->check = CSUM_MANGLED_0;
69 69 }
70 70 *portptr = newport;
71   - return 1;
  71 + return true;
72 72 }
73 73  
74 74 const struct nf_nat_protocol nf_nat_protocol_udp = {
net/ipv4/netfilter/nf_nat_proto_udplite.c
... ... @@ -18,7 +18,7 @@
18 18  
19 19 static u_int16_t udplite_port_rover;
20 20  
21   -static int
  21 +static bool
22 22 udplite_unique_tuple(struct nf_conntrack_tuple *tuple,
23 23 const struct nf_nat_range *range,
24 24 enum nf_nat_manip_type maniptype,
... ... @@ -28,7 +28,7 @@
28 28 &udplite_port_rover);
29 29 }
30 30  
31   -static int
  31 +static bool
32 32 udplite_manip_pkt(struct sk_buff *skb,
33 33 unsigned int iphdroff,
34 34 const struct nf_conntrack_tuple *tuple,
... ... @@ -41,7 +41,7 @@
41 41 __be16 *portptr, newport;
42 42  
43 43 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
44   - return 0;
  44 + return false;
45 45  
46 46 iph = (struct iphdr *)(skb->data + iphdroff);
47 47 hdr = (struct udphdr *)(skb->data + hdroff);
... ... @@ -66,7 +66,7 @@
66 66 hdr->check = CSUM_MANGLED_0;
67 67  
68 68 *portptr = newport;
69   - return 1;
  69 + return true;
70 70 }
71 71  
72 72 static const struct nf_nat_protocol nf_nat_protocol_udplite = {
net/ipv4/netfilter/nf_nat_proto_unknown.c
... ... @@ -18,31 +18,31 @@
18 18 #include <net/netfilter/nf_nat_rule.h>
19 19 #include <net/netfilter/nf_nat_protocol.h>
20 20  
21   -static int unknown_in_range(const struct nf_conntrack_tuple *tuple,
22   - enum nf_nat_manip_type manip_type,
23   - const union nf_conntrack_man_proto *min,
24   - const union nf_conntrack_man_proto *max)
  21 +static bool unknown_in_range(const struct nf_conntrack_tuple *tuple,
  22 + enum nf_nat_manip_type manip_type,
  23 + const union nf_conntrack_man_proto *min,
  24 + const union nf_conntrack_man_proto *max)
25 25 {
26   - return 1;
  26 + return true;
27 27 }
28 28  
29   -static int unknown_unique_tuple(struct nf_conntrack_tuple *tuple,
30   - const struct nf_nat_range *range,
31   - enum nf_nat_manip_type maniptype,
32   - const struct nf_conn *ct)
  29 +static bool unknown_unique_tuple(struct nf_conntrack_tuple *tuple,
  30 + const struct nf_nat_range *range,
  31 + enum nf_nat_manip_type maniptype,
  32 + const struct nf_conn *ct)
33 33 {
34 34 /* Sorry: we can't help you; if it's not unique, we can't frob
35 35 anything. */
36   - return 0;
  36 + return false;
37 37 }
38 38  
39   -static int
  39 +static bool
40 40 unknown_manip_pkt(struct sk_buff *skb,
41 41 unsigned int iphdroff,
42 42 const struct nf_conntrack_tuple *tuple,
43 43 enum nf_nat_manip_type maniptype)
44 44 {
45   - return 1;
  45 + return true;
46 46 }
47 47  
48 48 const struct nf_nat_protocol nf_nat_unknown_protocol = {