Skip to content

Commit 76108ce

Browse files
Jan Engelhardtkaber
authored andcommitted
netfilter: Use unsigned types for hooknum and pf vars
and (try to) consistently use u_int8_t for the L3 family. Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: Patrick McHardy <kaber@trash.net>
1 parent be713a4 commit 76108ce

35 files changed

Lines changed: 127 additions & 121 deletions

‎include/linux/netfilter.h‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ struct nf_hook_ops
9292
/* User fills in from here down. */
9393
nf_hookfn *hook;
9494
struct module *owner;
95-
int pf;
96-
int hooknum;
95+
u_int8_t pf;
96+
unsigned int hooknum;
9797
/* Hooks are ordered in ascending priority. */
9898
int priority;
9999
};
@@ -102,7 +102,7 @@ struct nf_sockopt_ops
102102
{
103103
struct list_head list;
104104

105-
int pf;
105+
u_int8_t pf;
106106

107107
/* Non-inclusive ranges: use 0/0/NULL to never get called. */
108108
int set_optmin;
@@ -140,7 +140,7 @@ extern struct ctl_path nf_net_ipv4_netfilter_sysctl_path[];
140140

141141
extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
142142

143-
int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
143+
int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
144144
struct net_device *indev, struct net_device *outdev,
145145
int (*okfn)(struct sk_buff *), int thresh);
146146

@@ -151,7 +151,7 @@ int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
151151
* okfn must be invoked by the caller in this case. Any other return
152152
* value indicates the packet has been consumed by the hook.
153153
*/
154-
static inline int nf_hook_thresh(int pf, unsigned int hook,
154+
static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
155155
struct sk_buff *skb,
156156
struct net_device *indev,
157157
struct net_device *outdev,
@@ -167,7 +167,7 @@ static inline int nf_hook_thresh(int pf, unsigned int hook,
167167
return nf_hook_slow(pf, hook, skb, indev, outdev, okfn, thresh);
168168
}
169169

170-
static inline int nf_hook(int pf, unsigned int hook, struct sk_buff *skb,
170+
static inline int nf_hook(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
171171
struct net_device *indev, struct net_device *outdev,
172172
int (*okfn)(struct sk_buff *))
173173
{
@@ -212,14 +212,14 @@ __ret;})
212212
NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, INT_MIN)
213213

214214
/* Call setsockopt() */
215-
int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt,
215+
int nf_setsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt,
216216
int len);
217-
int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
217+
int nf_getsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt,
218218
int *len);
219219

220-
int compat_nf_setsockopt(struct sock *sk, int pf, int optval,
220+
int compat_nf_setsockopt(struct sock *sk, u_int8_t pf, int optval,
221221
char __user *opt, int len);
222-
int compat_nf_getsockopt(struct sock *sk, int pf, int optval,
222+
int compat_nf_getsockopt(struct sock *sk, u_int8_t pf, int optval,
223223
char __user *opt, int *len);
224224

225225
/* Call this before modifying an existing packet: ensures it is
@@ -292,7 +292,7 @@ extern void nf_unregister_afinfo(const struct nf_afinfo *afinfo);
292292
extern void (*ip_nat_decode_session)(struct sk_buff *, struct flowi *);
293293

294294
static inline void
295-
nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family)
295+
nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
296296
{
297297
#ifdef CONFIG_NF_NAT_NEEDED
298298
void (*decodefn)(struct sk_buff *, struct flowi *);
@@ -315,7 +315,7 @@ extern struct proc_dir_entry *proc_net_netfilter;
315315
#else /* !CONFIG_NETFILTER */
316316
#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
317317
#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb)
318-
static inline int nf_hook_thresh(int pf, unsigned int hook,
318+
static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
319319
struct sk_buff *skb,
320320
struct net_device *indev,
321321
struct net_device *outdev,
@@ -324,15 +324,17 @@ static inline int nf_hook_thresh(int pf, unsigned int hook,
324324
{
325325
return okfn(skb);
326326
}
327-
static inline int nf_hook(int pf, unsigned int hook, struct sk_buff *skb,
327+
static inline int nf_hook(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
328328
struct net_device *indev, struct net_device *outdev,
329329
int (*okfn)(struct sk_buff *))
330330
{
331331
return 1;
332332
}
333333
struct flowi;
334334
static inline void
335-
nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family) {}
335+
nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
336+
{
337+
}
336338
#endif /*CONFIG_NETFILTER*/
337339

338340
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)

‎include/linux/netfilter/x_tables.h‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ struct xt_table
292292
/* Set this to THIS_MODULE if you are a module, otherwise NULL */
293293
struct module *me;
294294

295-
int af; /* address/protocol family */
295+
u_int8_t af; /* address/protocol family */
296296
};
297297

298298
#include <linux/netfilter_ipv4.h>
@@ -346,19 +346,19 @@ extern struct xt_table_info *xt_replace_table(struct xt_table *table,
346346
struct xt_table_info *newinfo,
347347
int *error);
348348

349-
extern struct xt_match *xt_find_match(int af, const char *name, u8 revision);
350-
extern struct xt_target *xt_find_target(int af, const char *name, u8 revision);
351-
extern struct xt_target *xt_request_find_target(int af, const char *name,
349+
extern struct xt_match *xt_find_match(u8 af, const char *name, u8 revision);
350+
extern struct xt_target *xt_find_target(u8 af, const char *name, u8 revision);
351+
extern struct xt_target *xt_request_find_target(u8 af, const char *name,
352352
u8 revision);
353-
extern int xt_find_revision(int af, const char *name, u8 revision, int target,
354-
int *err);
353+
extern int xt_find_revision(u8 af, const char *name, u8 revision,
354+
int target, int *err);
355355

356-
extern struct xt_table *xt_find_table_lock(struct net *net, int af,
356+
extern struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
357357
const char *name);
358358
extern void xt_table_unlock(struct xt_table *t);
359359

360-
extern int xt_proto_init(struct net *net, int af);
361-
extern void xt_proto_fini(struct net *net, int af);
360+
extern int xt_proto_init(struct net *net, u_int8_t af);
361+
extern void xt_proto_fini(struct net *net, u_int8_t af);
362362

363363
extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
364364
extern void xt_free_table_info(struct xt_table_info *info);
@@ -423,12 +423,12 @@ struct compat_xt_counters_info
423423
#define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
424424
& ~(__alignof__(struct compat_xt_counters)-1))
425425

426-
extern void xt_compat_lock(int af);
427-
extern void xt_compat_unlock(int af);
426+
extern void xt_compat_lock(u_int8_t af);
427+
extern void xt_compat_unlock(u_int8_t af);
428428

429-
extern int xt_compat_add_offset(int af, unsigned int offset, short delta);
430-
extern void xt_compat_flush_offsets(int af);
431-
extern short xt_compat_calc_jump(int af, unsigned int offset);
429+
extern int xt_compat_add_offset(u_int8_t af, unsigned int offset, short delta);
430+
extern void xt_compat_flush_offsets(u_int8_t af);
431+
extern short xt_compat_calc_jump(u_int8_t af, unsigned int offset);
432432

433433
extern int xt_compat_match_offset(const struct xt_match *match);
434434
extern int xt_compat_match_from_user(struct xt_entry_match *m,

‎include/net/netfilter/nf_conntrack_core.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/* This header is used to share core functionality between the
2121
standalone connection tracking module, and the compatibility layer's use
2222
of connection tracking. */
23-
extern unsigned int nf_conntrack_in(int pf,
23+
extern unsigned int nf_conntrack_in(u_int8_t pf,
2424
unsigned int hooknum,
2525
struct sk_buff *skb);
2626

‎include/net/netfilter/nf_conntrack_expect.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
8686
/* Allocate space for an expectation: this is mandatory before calling
8787
nf_ct_expect_related. You will have to call put afterwards. */
8888
struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me);
89-
void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, int,
89+
void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
9090
const union nf_inet_addr *,
9191
const union nf_inet_addr *,
9292
u_int8_t, const __be16 *, const __be16 *);

‎include/net/netfilter/nf_conntrack_l4proto.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct nf_conntrack_l4proto
3939
const struct sk_buff *skb,
4040
unsigned int dataoff,
4141
enum ip_conntrack_info ctinfo,
42-
int pf,
42+
u_int8_t pf,
4343
unsigned int hooknum);
4444

4545
/* Called when a new connection for this protocol found;
@@ -52,7 +52,7 @@ struct nf_conntrack_l4proto
5252

5353
int (*error)(struct sk_buff *skb, unsigned int dataoff,
5454
enum ip_conntrack_info *ctinfo,
55-
int pf, unsigned int hooknum);
55+
u_int8_t pf, unsigned int hooknum);
5656

5757
/* Print out the per-protocol part of the tuple. Return like seq_* */
5858
int (*print_tuple)(struct seq_file *s,

‎include/net/netfilter/nf_log.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct nf_loginfo {
2828
} u;
2929
};
3030

31-
typedef void nf_logfn(unsigned int pf,
31+
typedef void nf_logfn(u_int8_t pf,
3232
unsigned int hooknum,
3333
const struct sk_buff *skb,
3434
const struct net_device *in,
@@ -43,12 +43,12 @@ struct nf_logger {
4343
};
4444

4545
/* Function to register/unregister log function. */
46-
int nf_log_register(int pf, const struct nf_logger *logger);
46+
int nf_log_register(u_int8_t pf, const struct nf_logger *logger);
4747
void nf_log_unregister(const struct nf_logger *logger);
48-
void nf_log_unregister_pf(int pf);
48+
void nf_log_unregister_pf(u_int8_t pf);
4949

5050
/* Calls the registered backend logging function */
51-
void nf_log_packet(int pf,
51+
void nf_log_packet(u_int8_t pf,
5252
unsigned int hooknum,
5353
const struct sk_buff *skb,
5454
const struct net_device *in,

‎include/net/netfilter/nf_queue.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct nf_queue_entry {
88
unsigned int id;
99

1010
struct nf_hook_ops *elem;
11-
int pf;
11+
u_int8_t pf;
1212
unsigned int hook;
1313
struct net_device *indev;
1414
struct net_device *outdev;
@@ -24,9 +24,9 @@ struct nf_queue_handler {
2424
char *name;
2525
};
2626

27-
extern int nf_register_queue_handler(int pf,
27+
extern int nf_register_queue_handler(u_int8_t pf,
2828
const struct nf_queue_handler *qh);
29-
extern int nf_unregister_queue_handler(int pf,
29+
extern int nf_unregister_queue_handler(u_int8_t pf,
3030
const struct nf_queue_handler *qh);
3131
extern void nf_unregister_queue_handlers(const struct nf_queue_handler *qh);
3232
extern void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);

‎net/bridge/br_netfilter.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb,
657657
{
658658
struct nf_bridge_info *nf_bridge;
659659
struct net_device *parent;
660-
int pf;
660+
u_int8_t pf;
661661

662662
if (!skb->nf_bridge)
663663
return NF_ACCEPT;
@@ -791,7 +791,7 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb,
791791
{
792792
struct nf_bridge_info *nf_bridge = skb->nf_bridge;
793793
struct net_device *realoutdev = bridge_parent(skb->dev);
794-
int pf;
794+
u_int8_t pf;
795795

796796
#ifdef CONFIG_NETFILTER_DEBUG
797797
/* Be very paranoid. This probably won't happen anymore, but let's

‎net/bridge/netfilter/ebt_log.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ print_ports(const struct sk_buff *skb, uint8_t protocol, int offset)
8484

8585
#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
8686
static void
87-
ebt_log_packet(unsigned int pf, unsigned int hooknum,
87+
ebt_log_packet(u_int8_t pf, unsigned int hooknum,
8888
const struct sk_buff *skb, const struct net_device *in,
8989
const struct net_device *out, const struct nf_loginfo *loginfo,
9090
const char *prefix)

‎net/bridge/netfilter/ebt_ulog.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static void ebt_ulog_packet(unsigned int hooknr, const struct sk_buff *skb,
223223
}
224224

225225
/* this function is registered with the netfilter core */
226-
static void ebt_log_packet(unsigned int pf, unsigned int hooknum,
226+
static void ebt_log_packet(u_int8_t pf, unsigned int hooknum,
227227
const struct sk_buff *skb, const struct net_device *in,
228228
const struct net_device *out, const struct nf_loginfo *li,
229229
const char *prefix)

0 commit comments

Comments
 (0)