netfilter: conntrack: place print_tuple in procfs part

CONFIG_NF_CONNTRACK_PROCFS is deprecated, no need to use a function
pointer in the trackers for this. Place the printf formatting in
the one place that uses it.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
Florian Westphal 2017-08-12 00:57:06 +02:00 committed by Pablo Neira Ayuso
parent 036c69400a
commit 91950833dd
14 changed files with 56 additions and 116 deletions

View File

@ -37,10 +37,6 @@ struct nf_conntrack_l3proto {
bool (*invert_tuple)(struct nf_conntrack_tuple *inverse, bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
const struct nf_conntrack_tuple *orig); const struct nf_conntrack_tuple *orig);
/* Print out the per-protocol part of the tuple. */
void (*print_tuple)(struct seq_file *s,
const struct nf_conntrack_tuple *);
/* /*
* Called before tracking. * Called before tracking.
* *dataoff: offset of protocol header (TCP, UDP,...) in skb * *dataoff: offset of protocol header (TCP, UDP,...) in skb

View File

@ -61,10 +61,6 @@ struct nf_conntrack_l4proto {
/* called by gc worker if table is full */ /* called by gc worker if table is full */
bool (*can_early_drop)(const struct nf_conn *ct); bool (*can_early_drop)(const struct nf_conn *ct);
/* Print out the per-protocol part of the tuple. Return like seq_* */
void (*print_tuple)(struct seq_file *s,
const struct nf_conntrack_tuple *);
/* Print out the private part of the conntrack. */ /* Print out the private part of the conntrack. */
void (*print_conntrack)(struct seq_file *s, struct nf_conn *); void (*print_conntrack)(struct seq_file *s, struct nf_conn *);

View File

@ -63,13 +63,6 @@ static bool ipv4_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
static void ipv4_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "src=%pI4 dst=%pI4 ",
&tuple->src.u3.ip, &tuple->dst.u3.ip);
}
static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff, static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
unsigned int *dataoff, u_int8_t *protonum) unsigned int *dataoff, u_int8_t *protonum)
{ {
@ -355,7 +348,6 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 __read_mostly = {
.l3proto = PF_INET, .l3proto = PF_INET,
.pkt_to_tuple = ipv4_pkt_to_tuple, .pkt_to_tuple = ipv4_pkt_to_tuple,
.invert_tuple = ipv4_invert_tuple, .invert_tuple = ipv4_invert_tuple,
.print_tuple = ipv4_print_tuple,
.get_l4proto = ipv4_get_l4proto, .get_l4proto = ipv4_get_l4proto,
#if IS_ENABLED(CONFIG_NF_CT_NETLINK) #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
.tuple_to_nlattr = ipv4_tuple_to_nlattr, .tuple_to_nlattr = ipv4_tuple_to_nlattr,

View File

@ -71,16 +71,6 @@ static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
/* Print out the per-protocol part of the tuple. */
static void icmp_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "type=%u code=%u id=%u ",
tuple->dst.u.icmp.type,
tuple->dst.u.icmp.code,
ntohs(tuple->src.u.icmp.id));
}
static unsigned int *icmp_get_timeouts(struct net *net) static unsigned int *icmp_get_timeouts(struct net *net)
{ {
return &icmp_pernet(net)->timeout; return &icmp_pernet(net)->timeout;
@ -364,7 +354,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp __read_mostly =
.l4proto = IPPROTO_ICMP, .l4proto = IPPROTO_ICMP,
.pkt_to_tuple = icmp_pkt_to_tuple, .pkt_to_tuple = icmp_pkt_to_tuple,
.invert_tuple = icmp_invert_tuple, .invert_tuple = icmp_invert_tuple,
.print_tuple = icmp_print_tuple,
.packet = icmp_packet, .packet = icmp_packet,
.get_timeouts = icmp_get_timeouts, .get_timeouts = icmp_get_timeouts,
.new = icmp_new, .new = icmp_new,

View File

@ -67,13 +67,6 @@ static bool ipv6_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
static void ipv6_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "src=%pI6 dst=%pI6 ",
tuple->src.u3.ip6, tuple->dst.u3.ip6);
}
static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff, static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
unsigned int *dataoff, u_int8_t *protonum) unsigned int *dataoff, u_int8_t *protonum)
{ {
@ -350,7 +343,6 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 __read_mostly = {
.l3proto = PF_INET6, .l3proto = PF_INET6,
.pkt_to_tuple = ipv6_pkt_to_tuple, .pkt_to_tuple = ipv6_pkt_to_tuple,
.invert_tuple = ipv6_invert_tuple, .invert_tuple = ipv6_invert_tuple,
.print_tuple = ipv6_print_tuple,
.get_l4proto = ipv6_get_l4proto, .get_l4proto = ipv6_get_l4proto,
#if IS_ENABLED(CONFIG_NF_CT_NETLINK) #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
.tuple_to_nlattr = ipv6_tuple_to_nlattr, .tuple_to_nlattr = ipv6_tuple_to_nlattr,

View File

@ -84,16 +84,6 @@ static bool icmpv6_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
/* Print out the per-protocol part of the tuple. */
static void icmpv6_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "type=%u code=%u id=%u ",
tuple->dst.u.icmp.type,
tuple->dst.u.icmp.code,
ntohs(tuple->src.u.icmp.id));
}
static unsigned int *icmpv6_get_timeouts(struct net *net) static unsigned int *icmpv6_get_timeouts(struct net *net)
{ {
return &icmpv6_pernet(net)->timeout; return &icmpv6_pernet(net)->timeout;
@ -369,7 +359,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 __read_mostly =
.l4proto = IPPROTO_ICMPV6, .l4proto = IPPROTO_ICMPV6,
.pkt_to_tuple = icmpv6_pkt_to_tuple, .pkt_to_tuple = icmpv6_pkt_to_tuple,
.invert_tuple = icmpv6_invert_tuple, .invert_tuple = icmpv6_invert_tuple,
.print_tuple = icmpv6_print_tuple,
.packet = icmpv6_packet, .packet = icmpv6_packet,
.get_timeouts = icmpv6_get_timeouts, .get_timeouts = icmpv6_get_timeouts,
.new = icmpv6_new, .new = icmpv6_new,

View File

@ -49,11 +49,6 @@ static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
static void generic_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
}
static int generic_get_l4proto(const struct sk_buff *skb, unsigned int nhoff, static int generic_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
unsigned int *dataoff, u_int8_t *protonum) unsigned int *dataoff, u_int8_t *protonum)
{ {
@ -66,7 +61,6 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_generic __read_mostly = {
.l3proto = PF_UNSPEC, .l3proto = PF_UNSPEC,
.pkt_to_tuple = generic_pkt_to_tuple, .pkt_to_tuple = generic_pkt_to_tuple,
.invert_tuple = generic_invert_tuple, .invert_tuple = generic_invert_tuple,
.print_tuple = generic_print_tuple,
.get_l4proto = generic_get_l4proto, .get_l4proto = generic_get_l4proto,
}; };
EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_generic); EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_generic);

View File

@ -623,14 +623,6 @@ static bool dccp_can_early_drop(const struct nf_conn *ct)
return false; return false;
} }
static void dccp_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.dccp.port),
ntohs(tuple->dst.u.dccp.port));
}
static void dccp_print_conntrack(struct seq_file *s, struct nf_conn *ct) static void dccp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
{ {
seq_printf(s, "%s ", dccp_state_names[ct->proto.dccp.state]); seq_printf(s, "%s ", dccp_state_names[ct->proto.dccp.state]);
@ -887,7 +879,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4 __read_mostly = {
.get_timeouts = dccp_get_timeouts, .get_timeouts = dccp_get_timeouts,
.error = dccp_error, .error = dccp_error,
.can_early_drop = dccp_can_early_drop, .can_early_drop = dccp_can_early_drop,
.print_tuple = dccp_print_tuple,
.print_conntrack = dccp_print_conntrack, .print_conntrack = dccp_print_conntrack,
#if IS_ENABLED(CONFIG_NF_CT_NETLINK) #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
.to_nlattr = dccp_to_nlattr, .to_nlattr = dccp_to_nlattr,
@ -922,7 +913,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6 __read_mostly = {
.get_timeouts = dccp_get_timeouts, .get_timeouts = dccp_get_timeouts,
.error = dccp_error, .error = dccp_error,
.can_early_drop = dccp_can_early_drop, .can_early_drop = dccp_can_early_drop,
.print_tuple = dccp_print_tuple,
.print_conntrack = dccp_print_conntrack, .print_conntrack = dccp_print_conntrack,
#if IS_ENABLED(CONFIG_NF_CT_NETLINK) #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
.to_nlattr = dccp_to_nlattr, .to_nlattr = dccp_to_nlattr,

View File

@ -62,12 +62,6 @@ static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
/* Print out the per-protocol part of the tuple. */
static void generic_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
}
static unsigned int *generic_get_timeouts(struct net *net) static unsigned int *generic_get_timeouts(struct net *net)
{ {
return &(generic_pernet(net)->timeout); return &(generic_pernet(net)->timeout);
@ -189,7 +183,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly =
.l4proto = 255, .l4proto = 255,
.pkt_to_tuple = generic_pkt_to_tuple, .pkt_to_tuple = generic_pkt_to_tuple,
.invert_tuple = generic_invert_tuple, .invert_tuple = generic_invert_tuple,
.print_tuple = generic_print_tuple,
.packet = generic_packet, .packet = generic_packet,
.get_timeouts = generic_get_timeouts, .get_timeouts = generic_get_timeouts,
.new = generic_new, .new = generic_new,

View File

@ -224,15 +224,6 @@ static bool gre_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
return true; return true;
} }
/* print gre part of tuple */
static void gre_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "srckey=0x%x dstkey=0x%x ",
ntohs(tuple->src.u.gre.key),
ntohs(tuple->dst.u.gre.key));
}
/* print private data for conntrack */ /* print private data for conntrack */
static void gre_print_conntrack(struct seq_file *s, struct nf_conn *ct) static void gre_print_conntrack(struct seq_file *s, struct nf_conn *ct)
{ {
@ -366,7 +357,6 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = {
.l4proto = IPPROTO_GRE, .l4proto = IPPROTO_GRE,
.pkt_to_tuple = gre_pkt_to_tuple, .pkt_to_tuple = gre_pkt_to_tuple,
.invert_tuple = gre_invert_tuple, .invert_tuple = gre_invert_tuple,
.print_tuple = gre_print_tuple,
.print_conntrack = gre_print_conntrack, .print_conntrack = gre_print_conntrack,
.get_timeouts = gre_get_timeouts, .get_timeouts = gre_get_timeouts,
.packet = gre_packet, .packet = gre_packet,

View File

@ -174,15 +174,6 @@ static bool sctp_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
/* Print out the per-protocol part of the tuple. */
static void sctp_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.sctp.port),
ntohs(tuple->dst.u.sctp.port));
}
/* Print out the private part of the conntrack. */ /* Print out the private part of the conntrack. */
static void sctp_print_conntrack(struct seq_file *s, struct nf_conn *ct) static void sctp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
{ {
@ -793,7 +784,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = {
.l4proto = IPPROTO_SCTP, .l4proto = IPPROTO_SCTP,
.pkt_to_tuple = sctp_pkt_to_tuple, .pkt_to_tuple = sctp_pkt_to_tuple,
.invert_tuple = sctp_invert_tuple, .invert_tuple = sctp_invert_tuple,
.print_tuple = sctp_print_tuple,
.print_conntrack = sctp_print_conntrack, .print_conntrack = sctp_print_conntrack,
.packet = sctp_packet, .packet = sctp_packet,
.get_timeouts = sctp_get_timeouts, .get_timeouts = sctp_get_timeouts,
@ -829,7 +819,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = {
.l4proto = IPPROTO_SCTP, .l4proto = IPPROTO_SCTP,
.pkt_to_tuple = sctp_pkt_to_tuple, .pkt_to_tuple = sctp_pkt_to_tuple,
.invert_tuple = sctp_invert_tuple, .invert_tuple = sctp_invert_tuple,
.print_tuple = sctp_print_tuple,
.print_conntrack = sctp_print_conntrack, .print_conntrack = sctp_print_conntrack,
.packet = sctp_packet, .packet = sctp_packet,
.get_timeouts = sctp_get_timeouts, .get_timeouts = sctp_get_timeouts,

View File

@ -301,15 +301,6 @@ static bool tcp_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
/* Print out the per-protocol part of the tuple. */
static void tcp_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.tcp.port),
ntohs(tuple->dst.u.tcp.port));
}
/* Print out the private part of the conntrack. */ /* Print out the private part of the conntrack. */
static void tcp_print_conntrack(struct seq_file *s, struct nf_conn *ct) static void tcp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
{ {
@ -1558,7 +1549,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =
.l4proto = IPPROTO_TCP, .l4proto = IPPROTO_TCP,
.pkt_to_tuple = tcp_pkt_to_tuple, .pkt_to_tuple = tcp_pkt_to_tuple,
.invert_tuple = tcp_invert_tuple, .invert_tuple = tcp_invert_tuple,
.print_tuple = tcp_print_tuple,
.print_conntrack = tcp_print_conntrack, .print_conntrack = tcp_print_conntrack,
.packet = tcp_packet, .packet = tcp_packet,
.get_timeouts = tcp_get_timeouts, .get_timeouts = tcp_get_timeouts,
@ -1595,7 +1585,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly =
.l4proto = IPPROTO_TCP, .l4proto = IPPROTO_TCP,
.pkt_to_tuple = tcp_pkt_to_tuple, .pkt_to_tuple = tcp_pkt_to_tuple,
.invert_tuple = tcp_invert_tuple, .invert_tuple = tcp_invert_tuple,
.print_tuple = tcp_print_tuple,
.print_conntrack = tcp_print_conntrack, .print_conntrack = tcp_print_conntrack,
.packet = tcp_packet, .packet = tcp_packet,
.get_timeouts = tcp_get_timeouts, .get_timeouts = tcp_get_timeouts,

View File

@ -63,15 +63,6 @@ static bool udp_invert_tuple(struct nf_conntrack_tuple *tuple,
return true; return true;
} }
/* Print out the per-protocol part of the tuple. */
static void udp_print_tuple(struct seq_file *s,
const struct nf_conntrack_tuple *tuple)
{
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.udp.port),
ntohs(tuple->dst.u.udp.port));
}
static unsigned int *udp_get_timeouts(struct net *net) static unsigned int *udp_get_timeouts(struct net *net)
{ {
return udp_pernet(net)->timeouts; return udp_pernet(net)->timeouts;
@ -316,7 +307,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly =
.allow_clash = true, .allow_clash = true,
.pkt_to_tuple = udp_pkt_to_tuple, .pkt_to_tuple = udp_pkt_to_tuple,
.invert_tuple = udp_invert_tuple, .invert_tuple = udp_invert_tuple,
.print_tuple = udp_print_tuple,
.packet = udp_packet, .packet = udp_packet,
.get_timeouts = udp_get_timeouts, .get_timeouts = udp_get_timeouts,
.new = udp_new, .new = udp_new,
@ -349,7 +339,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly =
.allow_clash = true, .allow_clash = true,
.pkt_to_tuple = udp_pkt_to_tuple, .pkt_to_tuple = udp_pkt_to_tuple,
.invert_tuple = udp_invert_tuple, .invert_tuple = udp_invert_tuple,
.print_tuple = udp_print_tuple,
.packet = udp_packet, .packet = udp_packet,
.get_timeouts = udp_get_timeouts, .get_timeouts = udp_get_timeouts,
.new = udp_new, .new = udp_new,
@ -382,7 +371,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly =
.allow_clash = true, .allow_clash = true,
.pkt_to_tuple = udp_pkt_to_tuple, .pkt_to_tuple = udp_pkt_to_tuple,
.invert_tuple = udp_invert_tuple, .invert_tuple = udp_invert_tuple,
.print_tuple = udp_print_tuple,
.packet = udp_packet, .packet = udp_packet,
.get_timeouts = udp_get_timeouts, .get_timeouts = udp_get_timeouts,
.new = udp_new, .new = udp_new,
@ -415,7 +403,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly =
.allow_clash = true, .allow_clash = true,
.pkt_to_tuple = udp_pkt_to_tuple, .pkt_to_tuple = udp_pkt_to_tuple,
.invert_tuple = udp_invert_tuple, .invert_tuple = udp_invert_tuple,
.print_tuple = udp_print_tuple,
.packet = udp_packet, .packet = udp_packet,
.get_timeouts = udp_get_timeouts, .get_timeouts = udp_get_timeouts,
.new = udp_new, .new = udp_new,

View File

@ -41,8 +41,62 @@ print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
const struct nf_conntrack_l3proto *l3proto, const struct nf_conntrack_l3proto *l3proto,
const struct nf_conntrack_l4proto *l4proto) const struct nf_conntrack_l4proto *l4proto)
{ {
l3proto->print_tuple(s, tuple); switch (l3proto->l3proto) {
l4proto->print_tuple(s, tuple); case NFPROTO_IPV4:
seq_printf(s, "src=%pI4 dst=%pI4 ",
&tuple->src.u3.ip, &tuple->dst.u3.ip);
break;
case NFPROTO_IPV6:
seq_printf(s, "src=%pI6 dst=%pI6 ",
tuple->src.u3.ip6, tuple->dst.u3.ip6);
break;
default:
break;
}
switch (l4proto->l4proto) {
case IPPROTO_ICMP:
seq_printf(s, "type=%u code=%u id=%u ",
tuple->dst.u.icmp.type,
tuple->dst.u.icmp.code,
ntohs(tuple->src.u.icmp.id));
break;
case IPPROTO_TCP:
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.tcp.port),
ntohs(tuple->dst.u.tcp.port));
break;
case IPPROTO_UDPLITE: /* fallthrough */
case IPPROTO_UDP:
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.udp.port),
ntohs(tuple->dst.u.udp.port));
break;
case IPPROTO_DCCP:
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.dccp.port),
ntohs(tuple->dst.u.dccp.port));
break;
case IPPROTO_SCTP:
seq_printf(s, "sport=%hu dport=%hu ",
ntohs(tuple->src.u.sctp.port),
ntohs(tuple->dst.u.sctp.port));
break;
case IPPROTO_ICMPV6:
seq_printf(s, "type=%u code=%u id=%u ",
tuple->dst.u.icmp.type,
tuple->dst.u.icmp.code,
ntohs(tuple->src.u.icmp.id));
break;
case IPPROTO_GRE:
seq_printf(s, "srckey=0x%x dstkey=0x%x ",
ntohs(tuple->src.u.gre.key),
ntohs(tuple->dst.u.gre.key));
break;
default:
break;
}
} }
EXPORT_SYMBOL_GPL(print_tuple); EXPORT_SYMBOL_GPL(print_tuple);