Skip to content

Commit 44fb87f

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: remove remaining l4proto indirect packet calls
Now that all l4trackers are builtin, no need to use a mix of direct and indirect calls. This removes the last two users: gre and the generic l4 protocol tracker. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent b184356 commit 44fb87f

File tree

4 files changed

+29
-55
lines changed

4 files changed

+29
-55
lines changed

include/net/netfilter/nf_conntrack_l4proto.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ struct nf_conntrack_l4proto {
2727
/* protoinfo nlattr size, closes a hole */
2828
u16 nlattr_size;
2929

30-
/* Returns verdict for packet, or -1 for invalid. */
31-
int (*packet)(struct nf_conn *ct,
32-
struct sk_buff *skb,
33-
unsigned int dataoff,
34-
enum ip_conntrack_info ctinfo,
35-
const struct nf_hook_state *state);
36-
3730
/* Called when a conntrack entry is destroyed */
3831
void (*destroy)(struct nf_conn *ct);
3932

@@ -136,6 +129,11 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,
136129
unsigned int dataoff,
137130
enum ip_conntrack_info ctinfo,
138131
const struct nf_hook_state *state);
132+
int nf_conntrack_gre_packet(struct nf_conn *ct,
133+
struct sk_buff *skb,
134+
unsigned int dataoff,
135+
enum ip_conntrack_info ctinfo,
136+
const struct nf_hook_state *state);
139137

140138
/* Existing built-in generic protocol */
141139
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;

net/netfilter/nf_conntrack_core.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,18 @@ nf_conntrack_handle_icmp(struct nf_conn *tmpl,
15341534
return ret;
15351535
}
15361536

1537+
static int generic_packet(struct nf_conn *ct, struct sk_buff *skb,
1538+
enum ip_conntrack_info ctinfo)
1539+
{
1540+
const unsigned int *timeout = nf_ct_timeout_lookup(ct);
1541+
1542+
if (!timeout)
1543+
timeout = &nf_generic_pernet(nf_ct_net(ct))->timeout;
1544+
1545+
nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
1546+
return NF_ACCEPT;
1547+
}
1548+
15371549
/* Returns verdict for packet, or -1 for invalid. */
15381550
static int nf_conntrack_handle_packet(struct nf_conn *ct,
15391551
struct sk_buff *skb,
@@ -1566,11 +1578,15 @@ static int nf_conntrack_handle_packet(struct nf_conn *ct,
15661578
case IPPROTO_DCCP:
15671579
return nf_conntrack_dccp_packet(ct, skb, dataoff,
15681580
ctinfo, state);
1581+
#endif
1582+
#ifdef CONFIG_NF_CT_PROTO_GRE
1583+
case IPPROTO_GRE:
1584+
return nf_conntrack_gre_packet(ct, skb, dataoff,
1585+
ctinfo, state);
15691586
#endif
15701587
}
15711588

1572-
WARN_ON_ONCE(1);
1573-
return -NF_ACCEPT;
1589+
return generic_packet(ct, skb, ctinfo);
15741590
}
15751591

15761592
unsigned int
@@ -1634,11 +1650,7 @@ nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state)
16341650
goto out;
16351651
}
16361652

1637-
if (l4proto->packet)
1638-
ret = l4proto->packet(ct, skb, dataoff, ctinfo, state);
1639-
else
1640-
ret = nf_conntrack_handle_packet(ct, skb, dataoff, ctinfo, state);
1641-
1653+
ret = nf_conntrack_handle_packet(ct, skb, dataoff, ctinfo, state);
16421654
if (ret <= 0) {
16431655
/* Invalid: inverse of the return code tells
16441656
* the netfilter core what to do */

net/netfilter/nf_conntrack_proto_generic.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,6 @@
1515

1616
static const unsigned int nf_ct_generic_timeout = 600*HZ;
1717

18-
static bool nf_generic_should_process(u8 proto)
19-
{
20-
switch (proto) {
21-
#ifdef CONFIG_NF_CT_PROTO_GRE_MODULE
22-
case IPPROTO_GRE:
23-
return false;
24-
#endif
25-
default:
26-
return true;
27-
}
28-
}
29-
30-
/* Returns verdict for packet, or -1 for invalid. */
31-
static int generic_packet(struct nf_conn *ct,
32-
struct sk_buff *skb,
33-
unsigned int dataoff,
34-
enum ip_conntrack_info ctinfo,
35-
const struct nf_hook_state *state)
36-
{
37-
const unsigned int *timeout = nf_ct_timeout_lookup(ct);
38-
39-
if (!nf_generic_should_process(nf_ct_protonum(ct))) {
40-
pr_warn_once("conntrack: generic helper won't handle protocol %d. Please consider loading the specific helper module.\n",
41-
nf_ct_protonum(ct));
42-
return -NF_ACCEPT;
43-
}
44-
45-
if (!timeout)
46-
timeout = &nf_generic_pernet(nf_ct_net(ct))->timeout;
47-
48-
nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
49-
return NF_ACCEPT;
50-
}
51-
5218
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
5319

5420
#include <linux/netfilter/nfnetlink.h>
@@ -139,7 +105,6 @@ static struct nf_proto_net *generic_get_net_proto(struct net *net)
139105
const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic =
140106
{
141107
.l4proto = 255,
142-
.packet = generic_packet,
143108
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
144109
.ctnl_timeout = {
145110
.nlattr_to_obj = generic_timeout_nlattr_to_obj,

net/netfilter/nf_conntrack_proto_gre.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ static unsigned int *gre_get_timeouts(struct net *net)
213213
}
214214

215215
/* Returns verdict for packet, and may modify conntrack */
216-
static int gre_packet(struct nf_conn *ct,
217-
struct sk_buff *skb,
218-
unsigned int dataoff,
219-
enum ip_conntrack_info ctinfo,
220-
const struct nf_hook_state *state)
216+
int nf_conntrack_gre_packet(struct nf_conn *ct,
217+
struct sk_buff *skb,
218+
unsigned int dataoff,
219+
enum ip_conntrack_info ctinfo,
220+
const struct nf_hook_state *state)
221221
{
222222
if (state->pf != NFPROTO_IPV4)
223223
return -NF_ACCEPT;
@@ -371,7 +371,6 @@ const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre = {
371371
#ifdef CONFIG_NF_CONNTRACK_PROCFS
372372
.print_conntrack = gre_print_conntrack,
373373
#endif
374-
.packet = gre_packet,
375374
.destroy = gre_destroy,
376375
#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
377376
.tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,

0 commit comments

Comments
 (0)