Skip to content

Commit 2b21e05

Browse files
author
Jan Engelhardt
committed
netfilter: xtables: compact table hook functions (2/2)
The calls to ip6t_do_table only show minimal differences, so it seems like a good cleanup to merge them to a single one too. Space saving obtained by both patches: 6807725->6807373 ("Total" column from `size -A`.) Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
1 parent 737535c commit 2b21e05

7 files changed

Lines changed: 36 additions & 59 deletions

File tree

‎net/ipv4/netfilter/arptable_filter.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,9 @@ arptable_filter_hook(unsigned int hook, struct sk_buff *skb,
5858
const struct net_device *in, const struct net_device *out,
5959
int (*okfn)(struct sk_buff *))
6060
{
61-
if (hook == NF_ARP_OUT)
62-
return arpt_do_table(skb, hook, in, out,
63-
dev_net(out)->ipv4.arptable_filter);
61+
const struct net *net = dev_net((in != NULL) ? in : out);
6462

65-
/* INPUT/FORWARD: */
66-
return arpt_do_table(skb, hook, in, out,
67-
dev_net(in)->ipv4.arptable_filter);
63+
return arpt_do_table(skb, hook, in, out, net->ipv4.arptable_filter);
6864
}
6965

7066
static struct nf_hook_ops arpt_ops[] __read_mostly = {

‎net/ipv4/netfilter/iptable_filter.c‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,16 @@ iptable_filter_hook(unsigned int hook, struct sk_buff *skb,
6565
const struct net_device *in, const struct net_device *out,
6666
int (*okfn)(struct sk_buff *))
6767
{
68-
if (hook == NF_INET_LOCAL_OUT) {
69-
if (skb->len < sizeof(struct iphdr) ||
70-
ip_hdrlen(skb) < sizeof(struct iphdr))
71-
/* root is playing with raw sockets. */
72-
return NF_ACCEPT;
73-
74-
return ipt_do_table(skb, hook, in, out,
75-
dev_net(out)->ipv4.iptable_filter);
76-
}
68+
const struct net *net;
69+
70+
if (hook == NF_INET_LOCAL_OUT &&
71+
(skb->len < sizeof(struct iphdr) ||
72+
ip_hdrlen(skb) < sizeof(struct iphdr)))
73+
/* root is playing with raw sockets. */
74+
return NF_ACCEPT;
7775

78-
/* LOCAL_IN/FORWARD: */
79-
return ipt_do_table(skb, hook, in, out,
80-
dev_net(in)->ipv4.iptable_filter);
76+
net = dev_net((in != NULL) ? in : out);
77+
return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_filter);
8178
}
8279

8380
static struct nf_hook_ops ipt_ops[] __read_mostly = {

‎net/ipv4/netfilter/iptable_raw.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,16 @@ iptable_raw_hook(unsigned int hook, struct sk_buff *skb,
4949
const struct net_device *in, const struct net_device *out,
5050
int (*okfn)(struct sk_buff *))
5151
{
52-
if (hook == NF_INET_PRE_ROUTING)
53-
return ipt_do_table(skb, hook, in, out,
54-
dev_net(in)->ipv4.iptable_raw);
55-
56-
/* OUTPUT: */
57-
/* root is playing with raw sockets. */
58-
if (skb->len < sizeof(struct iphdr) ||
59-
ip_hdrlen(skb) < sizeof(struct iphdr))
52+
const struct net *net;
53+
54+
if (hook == NF_INET_LOCAL_OUT &&
55+
(skb->len < sizeof(struct iphdr) ||
56+
ip_hdrlen(skb) < sizeof(struct iphdr)))
57+
/* root is playing with raw sockets. */
6058
return NF_ACCEPT;
61-
return ipt_do_table(skb, hook, in, out,
62-
dev_net(out)->ipv4.iptable_raw);
59+
60+
net = dev_net((in != NULL) ? in : out);
61+
return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_raw);
6362
}
6463

6564
/* 'raw' is the very first table. */

‎net/ipv4/netfilter/iptable_security.c‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,16 @@ iptable_security_hook(unsigned int hook, struct sk_buff *skb,
7070
const struct net_device *out,
7171
int (*okfn)(struct sk_buff *))
7272
{
73-
if (hook == NF_INET_LOCAL_OUT) {
74-
if (skb->len < sizeof(struct iphdr) ||
75-
ip_hdrlen(skb) < sizeof(struct iphdr))
76-
/* Somebody is playing with raw sockets. */
77-
return NF_ACCEPT;
78-
79-
return ipt_do_table(skb, hook, in, out,
80-
dev_net(out)->ipv4.iptable_security);
81-
}
82-
83-
/* INPUT/FORWARD: */
84-
return ipt_do_table(skb, hook, in, out,
85-
dev_net(in)->ipv4.iptable_security);
73+
const struct net *net;
74+
75+
if (hook == NF_INET_LOCAL_OUT &&
76+
(skb->len < sizeof(struct iphdr) ||
77+
ip_hdrlen(skb) < sizeof(struct iphdr)))
78+
/* Somebody is playing with raw sockets. */
79+
return NF_ACCEPT;
80+
81+
net = dev_net((in != NULL) ? in : out);
82+
return ipt_do_table(skb, hook, in, out, net->ipv4.iptable_security);
8683
}
8784

8885
static struct nf_hook_ops ipt_ops[] __read_mostly = {

‎net/ipv6/netfilter/ip6table_filter.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,9 @@ ip6table_filter_hook(unsigned int hook, struct sk_buff *skb,
6464
const struct net_device *in, const struct net_device *out,
6565
int (*okfn)(struct sk_buff *))
6666
{
67-
if (hook == NF_INET_LOCAL_OUT)
68-
return ip6t_do_table(skb, hook, in, out,
69-
dev_net(out)->ipv6.ip6table_filter);
67+
const struct net *net = dev_net((in != NULL) ? in : out);
7068

71-
/* INPUT/FORWARD: */
72-
return ip6t_do_table(skb, hook, in, out,
73-
dev_net(in)->ipv6.ip6table_filter);
69+
return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_filter);
7470
}
7571

7672
static struct nf_hook_ops ip6t_ops[] __read_mostly = {

‎net/ipv6/netfilter/ip6table_raw.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ ip6table_raw_hook(unsigned int hook, struct sk_buff *skb,
4848
const struct net_device *in, const struct net_device *out,
4949
int (*okfn)(struct sk_buff *))
5050
{
51-
if (hook == NF_INET_PRE_ROUTING)
52-
return ip6t_do_table(skb, hook, in, out,
53-
dev_net(in)->ipv6.ip6table_raw);
51+
const struct net *net = dev_net((in != NULL) ? in : out);
5452

55-
/* OUTPUT: */
56-
return ip6t_do_table(skb, hook, in, out,
57-
dev_net(out)->ipv6.ip6table_raw);
53+
return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_raw);
5854
}
5955

6056
static struct nf_hook_ops ip6t_ops[] __read_mostly = {

‎net/ipv6/netfilter/ip6table_security.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,9 @@ ip6table_security_hook(unsigned int hook, struct sk_buff *skb,
6969
const struct net_device *out,
7070
int (*okfn)(struct sk_buff *))
7171
{
72-
if (hook == NF_INET_LOCAL_OUT)
73-
return ip6t_do_table(skb, hook, in, out,
74-
dev_net(out)->ipv6.ip6table_security);
72+
const struct net *net = dev_net((in != NULL) ? in : out);
7573

76-
/* INPUT/FORWARD: */
77-
return ip6t_do_table(skb, hook, in, out,
78-
dev_net(in)->ipv6.ip6table_security);
74+
return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_security);
7975
}
8076

8177
static struct nf_hook_ops ip6t_ops[] __read_mostly = {

0 commit comments

Comments
 (0)