Skip to content

Commit 197c430

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: remove invert_tuple callback
Only used by icmp(v6). Prefer a direct call and remove this function from the l4proto struct. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent df5e162 commit 197c430

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

include/net/netfilter/nf_conntrack_l4proto.h

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

30-
/* Invert the per-proto part of the tuple: ie. turn xmit into reply.
31-
* Only used by icmp, most protocols use a generic version.
32-
*/
33-
bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
34-
const struct nf_conntrack_tuple *orig);
35-
3630
/* Returns verdict for packet, or -1 for invalid. */
3731
int (*packet)(struct nf_conn *ct,
3832
struct sk_buff *skb,
@@ -95,6 +89,11 @@ bool icmpv6_pkt_to_tuple(const struct sk_buff *skb,
9589
struct net *net,
9690
struct nf_conntrack_tuple *tuple);
9791

92+
bool nf_conntrack_invert_icmp_tuple(struct nf_conntrack_tuple *tuple,
93+
const struct nf_conntrack_tuple *orig);
94+
bool nf_conntrack_invert_icmpv6_tuple(struct nf_conntrack_tuple *tuple,
95+
const struct nf_conntrack_tuple *orig);
96+
9897
int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
9998
struct sk_buff *skb,
10099
unsigned int dataoff,

net/netfilter/nf_conntrack_core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,12 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
423423

424424
inverse->dst.protonum = orig->dst.protonum;
425425

426-
if (unlikely(l4proto->invert_tuple))
427-
return l4proto->invert_tuple(inverse, orig);
426+
switch (orig->dst.protonum) {
427+
case IPPROTO_ICMP:
428+
return nf_conntrack_invert_icmp_tuple(inverse, orig);
429+
case IPPROTO_ICMPV6:
430+
return nf_conntrack_invert_icmpv6_tuple(inverse, orig);
431+
}
428432

429433
inverse->src.u.all = orig->dst.u.all;
430434
inverse->dst.u.all = orig->src.u.all;

net/netfilter/nf_conntrack_proto_icmp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ static const u_int8_t invmap[] = {
5454
[ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1
5555
};
5656

57-
static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple,
58-
const struct nf_conntrack_tuple *orig)
57+
bool nf_conntrack_invert_icmp_tuple(struct nf_conntrack_tuple *tuple,
58+
const struct nf_conntrack_tuple *orig)
5959
{
6060
if (orig->dst.u.icmp.type >= sizeof(invmap) ||
6161
!invmap[orig->dst.u.icmp.type])
@@ -347,7 +347,6 @@ static struct nf_proto_net *icmp_get_net_proto(struct net *net)
347347
const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp =
348348
{
349349
.l4proto = IPPROTO_ICMP,
350-
.invert_tuple = icmp_invert_tuple,
351350
#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
352351
.tuple_to_nlattr = icmp_tuple_to_nlattr,
353352
.nlattr_tuple_size = icmp_nlattr_tuple_size,

net/netfilter/nf_conntrack_proto_icmpv6.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ static const u_int8_t noct_valid_new[] = {
6767
[ICMPV6_MLD2_REPORT - 130] = 1
6868
};
6969

70-
static bool icmpv6_invert_tuple(struct nf_conntrack_tuple *tuple,
71-
const struct nf_conntrack_tuple *orig)
70+
bool nf_conntrack_invert_icmpv6_tuple(struct nf_conntrack_tuple *tuple,
71+
const struct nf_conntrack_tuple *orig)
7272
{
7373
int type = orig->dst.u.icmp.type - 128;
7474
if (type < 0 || type >= sizeof(invmap) || !invmap[type])
@@ -358,7 +358,6 @@ static struct nf_proto_net *icmpv6_get_net_proto(struct net *net)
358358
const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
359359
{
360360
.l4proto = IPPROTO_ICMPV6,
361-
.invert_tuple = icmpv6_invert_tuple,
362361
#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
363362
.tuple_to_nlattr = icmpv6_tuple_to_nlattr,
364363
.nlattr_tuple_size = icmpv6_nlattr_tuple_size,

0 commit comments

Comments
 (0)