netfilter: remove pf argument from conntrack l4 packet function
Subsystems (2)
Florian Westphal
maintainercover netfilter: remove pf argument from conntrack l4 packet function
We currently pass pf to the packet() function of the l4 trackers, but this isn't needed -- its only required for the 'log invalid' check and the l4 protocol is also available in the nf_conn entry.
This series adds helpers for logging invalid packets, similar to nf_ct_helper_log().
I added a __cold annotation, it makes gcc rearrange the callsites as they are then considered unlikely and moved away from hotpath.
After this change, packet() gets passed 5 instead of 6 arguments.
include/net/netfilter/nf_conntrack_l4proto.h | 21 +++++++-- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 19 ++++---- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 15 +++---- net/netfilter/nf_conntrack_core.c | 2 net/netfilter/nf_conntrack_proto.c | 47 ++++++++++++++++++++++ net/netfilter/nf_conntrack_proto_dccp.c | 21 ++------- net/netfilter/nf_conntrack_proto_generic.c | 1 net/netfilter/nf_conntrack_proto_gre.c | 1 net/netfilter/nf_conntrack_proto_sctp.c | 4 - net/netfilter/nf_conntrack_proto_tcp.c | 53 +++++++++---------------- net/netfilter/nf_conntrack_proto_udp.c | 41 ++++++++----------- 11 files changed, 128 insertions(+), 97 deletions(-)
Florian Westphal
maintainerPATCH 1/3 netfilter: conntrack: add and use nf_l4proto_log_invalid
We currently pass down the l4 protocol to the conntrack ->packet() function, but the only user of this is the debug info decision.
Same information can be derived from struct nf_conn.
As a first step, add and use a new log function for this, similar to nf_ct_helper_log().
Add __cold annotation -- invalid packets should be infrequent so gcc can consider all call paths that lead to such a function as unlikely.
--- include/net/netfilter/nf_conntrack_l4proto.h | 10 +++++++ net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 18 ++++++------ net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 14 +++++---- net/netfilter/nf_conntrack_proto.c | 24 ++++++++++++++++ net/netfilter/nf_conntrack_proto_dccp.c | 3 +- net/netfilter/nf_conntrack_proto_sctp.c | 3 +- net/netfilter/nf_conntrack_proto_tcp.c | 22 +++++++------- net/netfilter/nf_conntrack_proto_udp.c | 40 ++++++++++++-------------- 8 files changed, 82 insertions(+), 52 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +10 -0
@@ -152,8 +152,18 @@ extern const struct nla_policy nf_ct_port_nla_policy[];#define LOG_INVALID (net, proto) \ ((net)->ct.sysctl_log_invalid == (proto) || \ (net)->ct.sysctl_log_invalid == IPPROTO_RAW) + +__printf(5, 6) __cold +void nf_l4proto_log_invalid (const struct sk_buff *skb, +struct net *net, +u16 pf,u8 protonum, +const char *fmt, ...);#else static inline int LOG_INVALID (struct net *net,int proto) {return 0 ; } + +static inline __printf(5, 6) __cold +void nf_l4proto_log_invalid(const struct sk_buff *skb, struct net *net, + u16 pf, u8 protonum, const char *fmt, ...) {}#endif /* CONFIG_SYSCTL */ #endif /*_NF_CONNTRACK_PROTOCOL_H*/
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +9 -9
@@ -165,6 +165,12 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,return NF_ACCEPT ; } +static void icmp_error_log (const struct sk_buff *skb,struct net *net, +u8 pf,const char *msg) +{ +nf_l4proto_log_invalid (skb, net, pf,IPPROTO_ICMP ,"%s" , msg); +} +/* Small and modified version of icmp_rcv */ static int icmp_error(struct net *net, struct nf_conn *tmpl,
@@ -177,18 +183,14 @@ icmp_error(struct net *net, struct nf_conn *tmpl,/* Not enough header? */ icmph =skb_header_pointer (skb,ip_hdrlen (skb),sizeof (_ih), &_ih);if (icmph ==NULL ) { -if (LOG_INVALID (net,IPPROTO_ICMP )) -nf_log_packet (net,PF_INET ,0 , skb,NULL ,NULL , -NULL ,"nf_ct_icmp: short packet " ); +icmp_error_log (skb, net, pf,"short packet" );return -NF_ACCEPT ; }/* See ip_conntrack_proto_tcp.c */ if (net->ct.sysctl_checksum && hooknum ==NF_INET_PRE_ROUTING &&nf_ip_checksum (skb, hooknum, dataoff,0 )) { -if (LOG_INVALID (net,IPPROTO_ICMP )) -nf_log_packet (net,PF_INET ,0 , skb,NULL ,NULL ,NULL , -"nf_ct_icmp: bad HW ICMP checksum " ); +icmp_error_log (skb, net, pf,"bad hw icmp checksum" );return -NF_ACCEPT ; }
@@ -199,9 +201,7 @@ icmp_error(struct net *net, struct nf_conn *tmpl,* discarded. */ if (icmph->type >NR_ICMP_TYPES ) { -if (LOG_INVALID (net,IPPROTO_ICMP )) -nf_log_packet (net,PF_INET ,0 , skb,NULL ,NULL ,NULL , -"nf_ct_icmp: invalid ICMP type " ); +icmp_error_log (skb, net, pf,"invalid icmp type" );return -NF_ACCEPT ; }
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +8 -6
@@ -176,6 +176,12 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl,return NF_ACCEPT ; } +static void icmpv6_error_log (const struct sk_buff *skb,struct net *net, +u8 pf,const char *msg) +{ +nf_l4proto_log_invalid (skb, net, pf,IPPROTO_ICMPV6 ,"%s" , msg); +} + static int icmpv6_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb, unsigned int dataoff,
@@ -187,17 +193,13 @@ icmpv6_error(struct net *net, struct nf_conn *tmpl, icmp6h =skb_header_pointer (skb, dataoff,sizeof (_ih), &_ih);if (icmp6h ==NULL ) { -if (LOG_INVALID (net,IPPROTO_ICMPV6 )) -nf_log_packet (net,PF_INET6 ,0 , skb,NULL ,NULL ,NULL , -"nf_ct_icmpv6: short packet " ); +icmpv6_error_log (skb, net, pf,"short packet" );return -NF_ACCEPT ; }if (net->ct.sysctl_checksum && hooknum ==NF_INET_PRE_ROUTING &&nf_ip6_checksum (skb, hooknum, dataoff,IPPROTO_ICMPV6 )) { -if (LOG_INVALID (net,IPPROTO_ICMPV6 )) -nf_log_packet (net,PF_INET6 ,0 , skb,NULL ,NULL ,NULL , -"nf_ct_icmpv6: ICMPv6 checksum failed " ); +icmpv6_error_log (skb, net, pf,"ICMPv6 checksum failed" );return -NF_ACCEPT ; }
net/netfilter/nf_conntrack_proto.c +24 -0
@@ -27,6 +27,7 @@#include <net/netfilter/nf_conntrack_l3proto.h> #include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_core.h> +#include <net/netfilter/nf_log.h> static struct nf_conntrack_l4proto __rcu **nf_ct_protos[NFPROTO_NUMPROTO ]__read_mostly ;struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[NFPROTO_NUMPROTO ]__read_mostly ;
@@ -63,6 +64,29 @@ nf_ct_unregister_sysctl(struct ctl_table_header **header, *header =NULL ; *table =NULL ; } + +__printf(5, 6) +void nf_l4proto_log_invalid(const struct sk_buff *skb, + struct net *net, + u16 pf, u8 protonum, + const char *fmt, ...) +{ + struct va_format vaf; +va_list args; + +if (net->ct.sysctl_log_invalid != protonum || + net->ct.sysctl_log_invalid !=IPPROTO_RAW ) +return ; + +va_start (args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + +nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , +"nf_ct_proto_%d: %pV " , protonum, &vaf); +va_end (args); +} +EXPORT_SYMBOL_GPL (nf_l4proto_log_invalid);#endif const struct nf_conntrack_l4proto *
net/netfilter/nf_conntrack_proto_dccp.c +1 -2
@@ -604,8 +604,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,return NF_ACCEPT ; out_invalid: -if (LOG_INVALID (net,IPPROTO_DCCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL ,"%s" , msg); +nf_l4proto_log_invalid (skb, net, pf,IPPROTO_DCCP ,"%s" , msg);return -NF_ACCEPT ; }
net/netfilter/nf_conntrack_proto_sctp.c +1 -2
@@ -522,8 +522,7 @@ static int sctp_error(struct net *net, struct nf_conn *tpl, struct sk_buff *skb, }return NF_ACCEPT ; out_invalid: -if (LOG_INVALID (net,IPPROTO_SCTP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL ,"%s" , logmsg); +nf_l4proto_log_invalid (skb, net, pf,IPPROTO_SCTP ,"%s" , logmsg);return -NF_ACCEPT ; }
net/netfilter/nf_conntrack_proto_tcp.c +10 -12
@@ -738,6 +738,12 @@ static const u8 tcp_valid_flags[(TCPHDR_FIN|TCPHDR_SYN|TCPHDR_RST|TCPHDR_ACK| [TCPHDR_ACK|TCPHDR_URG] = 1, }; +static void tcp_error_log (const struct sk_buff *skb,struct net *net, +u8 pf,const char *msg) +{ +nf_l4proto_log_invalid (skb, net, pf,IPPROTO_TCP ,"%s" , msg); +} +/* Protect conntrack agaist broken packets. Code taken from ipt_unclean.c. */ static int tcp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
@@ -753,17 +759,13 @@ static int tcp_error(struct net *net, struct nf_conn *tmpl,/* Smaller that minimal TCP header? */ th =skb_header_pointer (skb, dataoff,sizeof (_tcph), &_tcph);if (th ==NULL ) { -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: short packet " ); +tcp_error_log (skb, net, pf,"short packet" );return -NF_ACCEPT ; }/* Not whole TCP header or malformed packet */ if (th->doff*4 <sizeof (struct tcphdr ) || tcplen < th->doff*4 ) { -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: truncated/malformed packet " ); +tcp_error_log (skb, net, pf,"truncated packet" );return -NF_ACCEPT ; }
@@ -774,18 +776,14 @@ static int tcp_error(struct net *net, struct nf_conn *tmpl,/* FIXME: Source route IP option packets --RR */ if (net->ct.sysctl_checksum && hooknum ==NF_INET_PRE_ROUTING &&nf_checksum (skb, hooknum, dataoff,IPPROTO_TCP , pf)) { -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: bad TCP checksum " ); +tcp_error_log (skb, net, pf,"bad checksum" );return -NF_ACCEPT ; }/* Check TCP flags. */ tcpflags = (tcp_flag_byte (th) & ~(TCPHDR_ECE |TCPHDR_CWR |TCPHDR_PSH ));if (!tcp_valid_flags[tcpflags]) { -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: invalid TCP flag combination " ); +tcp_error_log (skb, net, pf,"invalid tcp flag combination" );return -NF_ACCEPT ; }
net/netfilter/nf_conntrack_proto_udp.c +19 -21
@@ -99,6 +99,12 @@ static bool udp_new(struct nf_conn *ct, const struct sk_buff *skb, }#ifdef CONFIG_NF_CT_PROTO_UDPLITE +static void udplite_error_log (const struct sk_buff *skb,struct net *net, +u8 pf,const char *msg) +{ +nf_l4proto_log_invalid (skb, net, pf,IPPROTO_UDPLITE ,"%s" , msg); +} + static int udplite_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb, unsigned int dataoff,
@@ -112,9 +118,7 @@ static int udplite_error(struct net *net, struct nf_conn *tmpl,/* Header is too small? */ hdr =skb_header_pointer (skb, dataoff,sizeof (_hdr), &_hdr);if (!hdr) { -if (LOG_INVALID (net,IPPROTO_UDPLITE )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_udplite: short packet " ); +udplite_error_log (skb, net, pf,"short packet" );return -NF_ACCEPT ; }
@@ -122,17 +126,13 @@ static int udplite_error(struct net *net, struct nf_conn *tmpl,if (cscov ==0 ) { cscov = udplen; }else if (cscov <sizeof (*hdr) || cscov > udplen) { -if (LOG_INVALID (net,IPPROTO_UDPLITE )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_udplite: invalid checksum coverage " ); +udplite_error_log (skb, net, pf,"invalid checksum coverage" );return -NF_ACCEPT ; }/* UDPLITE mandates checksums */ if (!hdr->check) { -if (LOG_INVALID (net,IPPROTO_UDPLITE )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_udplite: checksum missing " ); +udplite_error_log (skb, net, pf,"checksum missing" );return -NF_ACCEPT ; }
@@ -140,9 +140,7 @@ static int udplite_error(struct net *net, struct nf_conn *tmpl,if (net->ct.sysctl_checksum && hooknum ==NF_INET_PRE_ROUTING &&nf_checksum_partial (skb, hooknum, dataoff, cscov,IPPROTO_UDP , pf)) { -if (LOG_INVALID (net,IPPROTO_UDPLITE )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_udplite: bad UDPLite checksum " ); +udplite_error_log (skb, net, pf,"bad checksum" );return -NF_ACCEPT ; }
@@ -150,6 +148,12 @@ static int udplite_error(struct net *net, struct nf_conn *tmpl, }#endif +static void udp_error_log (const struct sk_buff *skb,struct net *net, +u8 pf,const char *msg) +{ +nf_l4proto_log_invalid (skb, net, pf,IPPROTO_UDP ,"%s" , msg); +} + static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb, unsigned int dataoff, u_int8_t pf,
@@ -162,17 +166,13 @@ static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,/* Header is too small? */ hdr =skb_header_pointer (skb, dataoff,sizeof (_hdr), &_hdr);if (hdr ==NULL ) { -if (LOG_INVALID (net,IPPROTO_UDP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_udp: short packet " ); +udp_error_log (skb, net, pf,"short packet" );return -NF_ACCEPT ; }/* Truncated/malformed packets */ if (ntohs (hdr->len) > udplen ||ntohs (hdr->len) <sizeof (*hdr)) { -if (LOG_INVALID (net,IPPROTO_UDP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_udp: truncated/malformed packet " ); +udp_error_log (skb, net, pf,"truncated/malformed packet" );return -NF_ACCEPT ; }
@@ -186,9 +186,7 @@ static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,* FIXME: Source route IP option packets --RR */ if (net->ct.sysctl_checksum && hooknum ==NF_INET_PRE_ROUTING &&nf_checksum (skb, hooknum, dataoff,IPPROTO_UDP , pf)) { -if (LOG_INVALID (net,IPPROTO_UDP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_udp: bad UDP checksum " ); +udp_error_log (skb, net, pf,"bad checksum" );return -NF_ACCEPT ; }
Signature · 1 line
2.13.6
Florian Westphal
maintainerPATCH 2/3 netfilter: conntrack: add and use nf_ct_l4proto_log_invalid
In reply to Florian WestphalWe currently pass down the l4 protocol to the conntrack ->packet() function, but the only user of this is the debug info decision.
Same information can be derived from struct nf_conn. Add a wrapper for the previous patch that extracs the information from nf_conn and passes it to nf_l4proto_log_invalid().
--- include/net/netfilter/nf_conntrack_l4proto.h | 14 ++++++++------ net/netfilter/nf_conntrack_proto.c | 23 +++++++++++++++++++++++ net/netfilter/nf_conntrack_proto_dccp.c | 17 +++++------------ net/netfilter/nf_conntrack_proto_tcp.c | 25 +++++++++---------------- 4 files changed, 45 insertions(+), 34 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +8 -6
@@ -149,21 +149,23 @@ int nf_ct_port_nlattr_tuple_size(void);extern const struct nla_policy nf_ct_port_nla_policy[];#ifdef CONFIG_SYSCTL -#define LOG_INVALID (net, proto) \ - ((net)->ct.sysctl_log_invalid == (proto) || \ - (net)->ct.sysctl_log_invalid == IPPROTO_RAW) - +__printf(3, 4) __cold +void nf_ct_l4proto_log_invalid (const struct sk_buff *skb, +const struct nf_conn *ct, +const char *fmt, ...); __printf(5, 6) __coldvoid nf_l4proto_log_invalid (const struct sk_buff *skb,struct net *net,u16 pf,u8 protonum,const char *fmt, ...);#else -static inline int LOG_INVALID (struct net *net,int proto) {return 0 ; } - static inline __printf(5, 6) __cold void nf_l4proto_log_invalid(const struct sk_buff *skb, struct net *net, u16 pf, u8 protonum, const char *fmt, ...) {} +static inline __printf(3, 4) __cold +void nf_ct_l4proto_log_invalid(const struct sk_buff *skb, + const struct nf_conn *ct, + const char *fmt, ...) { }#endif /* CONFIG_SYSCTL */ #endif /*_NF_CONNTRACK_PROTOCOL_H*/
net/netfilter/nf_conntrack_proto.c +23 -0
@@ -87,6 +87,29 @@ void nf_l4proto_log_invalid(const struct sk_buff *skb,va_end (args); }EXPORT_SYMBOL_GPL (nf_l4proto_log_invalid); + +__printf(3, 4) +void nf_ct_l4proto_log_invalid (const struct sk_buff *skb, +const struct nf_conn *ct, +const char *fmt, ...) +{ +struct va_format vaf; +struct net *net; +va_list args; + + net =nf_ct_net (ct); +if (likely (net->ct.sysctl_log_invalid ==0 )) +return ; + +va_start (args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + +nf_l4proto_log_invalid (skb, net,nf_ct_l3num (ct), +nf_ct_protonum (ct),"%pV" , &vaf); +va_end (args); +} +EXPORT_SYMBOL_GPL (nf_ct_l4proto_log_invalid);#endif const struct nf_conntrack_l4proto *
net/netfilter/nf_conntrack_proto_dccp.c +5 -12
@@ -428,13 +428,13 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,default : dn =dccp_pernet (net);if (dn->dccp_loose ==0 ) { - msg ="nf_ct_dccp: not picking up existing connection " ; + msg ="not picking up existing connection " ; goto out_invalid; }case CT_DCCP_REQUEST :break ;case CT_DCCP_INVALID : - msg ="nf_ct_dccp: invalid state transition " ; + msg ="invalid state transition " ; goto out_invalid; }
@@ -447,9 +447,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,return true; out_invalid: -if (LOG_INVALID (net,IPPROTO_DCCP )) -nf_log_packet (net,nf_ct_l3num (ct),0 , skb,NULL ,NULL , -NULL ,"%s" , msg); +nf_ct_l4proto_log_invalid (skb, ct,"%s" , msg);return false; }
@@ -472,7 +470,6 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,u_int8_t pf, unsigned int *timeouts) { - struct net *net = nf_ct_net(ct); enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);struct dccp_hdr _dh, *dh;u_int8_t type, old_state, new_state;
@@ -534,15 +531,11 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb, ct->proto.dccp.last_pkt = type;spin_unlock_bh (&ct->lock); -if (LOG_INVALID (net,IPPROTO_DCCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_dccp: invalid packet ignored " ); +nf_ct_l4proto_log_invalid (skb, ct,"%s" ,"invalid packet" );return NF_ACCEPT ;case CT_DCCP_INVALID :spin_unlock_bh (&ct->lock); -if (LOG_INVALID (net,IPPROTO_DCCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_dccp: invalid state transition " ); +nf_ct_l4proto_log_invalid (skb, ct,"%s" ,"invalid state transition" );return -NF_ACCEPT ; }
net/netfilter/nf_conntrack_proto_tcp.c +9 -16
@@ -702,9 +702,9 @@ static bool tcp_in_window(const struct nf_conn *ct,if (sender->flags &IP_CT_TCP_FLAG_BE_LIBERAL || tn->tcp_be_liberal) res = true; -if (!res &&LOG_INVALID (net,IPPROTO_TCP )) - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, - "nf_ct_tcp: %s ", +if (!res) { + nf_ct_l4proto_log_invalid(skb, ct, + "%s", before(seq, sender->td_maxend + 1) ? in_recv_win ? before(sack, receiver->td_end + 1) ?
@@ -713,6 +713,7 @@ static bool tcp_in_window(const struct nf_conn *ct, : "ACK is over the upper bound (ACKed data not seen yet)" : "SEQ is under the lower bound (already ACKed data retransmitted)" : "SEQ is over the upper bound (over the window of the receiver)"); + } } pr_debug("tcp_in_window: res=%u sender end=%u maxend=%u maxwin=%u "
@@ -937,10 +938,8 @@ static int tcp_packet(struct nf_conn *ct,IP_CT_EXP_CHALLENGE_ACK ; }spin_unlock_bh (&ct->lock); -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: invalid packet ignored in " -"state %s " , tcp_conntrack_names[old_state]); +nf_ct_l4proto_log_invalid (skb, ct,"invalid packet ignored in " +"state %s " , tcp_conntrack_names[old_state]);return NF_ACCEPT ;case TCP_CONNTRACK_MAX :/* Special case for SYN proxy: when the SYN to the server or
@@ -962,9 +961,7 @@ static int tcp_packet(struct nf_conn *ct,pr_debug ("nf_ct_tcp: Invalid dir=%i index=%u ostate=%u\n" , dir,get_conntrack_index (th), old_state);spin_unlock_bh (&ct->lock); -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: invalid state " ); +nf_ct_l4proto_log_invalid (skb, ct,"invalid state" );return -NF_ACCEPT ;case TCP_CONNTRACK_TIME_WAIT :/* RFC5961 compliance cause stack to send "challenge-ACK"
@@ -979,9 +976,7 @@ static int tcp_packet(struct nf_conn *ct,/* Detected RFC5961 challenge ACK */ ct->proto.tcp.last_flags &= ~IP_CT_EXP_CHALLENGE_ACK ;spin_unlock_bh (&ct->lock); -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: challenge-ACK ignored " ); +nf_ct_l4proto_log_invalid (skb, ct,"challenge-ack ignored" );return NF_ACCEPT ;/* Don't change state */ }break ;
@@ -991,9 +986,7 @@ static int tcp_packet(struct nf_conn *ct, && before(ntohl(th->seq), ct->proto.tcp.seen[!dir].td_maxack)) {/* Invalid RST */ spin_unlock_bh (&ct->lock); -if (LOG_INVALID (net,IPPROTO_TCP )) -nf_log_packet (net, pf,0 , skb,NULL ,NULL , -NULL ,"nf_ct_tcp: invalid RST " ); +nf_ct_l4proto_log_invalid (skb, ct,"invalid rst" );return -NF_ACCEPT ; } if (index == TCP_RST_SET
Signature · 1 line
2.13.6
Florian Westphal
maintainerPATCH 3/3 netfilter: conntrack: remove pf argument from l4 packet functions
In reply to Florian Westphalnot needed/used anymore.
--- include/net/netfilter/nf_conntrack_l4proto.h | 1 - net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 1 - net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 1 - net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_conntrack_proto_dccp.c | 1 - net/netfilter/nf_conntrack_proto_generic.c | 1 - net/netfilter/nf_conntrack_proto_gre.c | 1 - net/netfilter/nf_conntrack_proto_sctp.c | 1 - net/netfilter/nf_conntrack_proto_tcp.c | 6 ++---- net/netfilter/nf_conntrack_proto_udp.c | 1 - 10 files changed, 3 insertions(+), 13 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +0 -1
@@ -42,7 +42,6 @@ struct nf_conntrack_l4proto {const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeouts);/* Called when a new connection for this protocol found;
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +0 -1
@@ -81,7 +81,6 @@ static int icmp_packet(struct nf_conn *ct,const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeout) {/* Do not immediately delete the connection after the first
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +0 -1
@@ -94,7 +94,6 @@ static int icmpv6_packet(struct nf_conn *ct,const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeout) {/* Do not immediately delete the connection after the first
net/netfilter/nf_conntrack_core.c +1 -1
@@ -1419,7 +1419,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,/* Decide what timeout policy we want to apply to this flow. */ timeouts =nf_ct_timeout_lookup (net, ct, l4proto); - ret = l4proto->packet (ct, skb, dataoff, ctinfo, pf, timeouts); + ret = l4proto->packet (ct, skb, dataoff, ctinfo, timeouts);if (ret <=0 ) {/* Invalid: inverse of the return code tells * the netfilter core what to do */
net/netfilter/nf_conntrack_proto_dccp.c +0 -1
@@ -467,7 +467,6 @@ static unsigned int *dccp_get_timeouts(struct net *net)static int dccp_packet (struct nf_conn *ct,const struct sk_buff *skb,unsigned int dataoff,enum ip_conntrack_info ctinfo, -u_int8_t pf,unsigned int *timeouts) {enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);
net/netfilter/nf_conntrack_proto_generic.c +0 -1
@@ -60,7 +60,6 @@ static int generic_packet(struct nf_conn *ct,const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeout) { nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
net/netfilter/nf_conntrack_proto_gre.c +0 -1
@@ -244,7 +244,6 @@ static int gre_packet(struct nf_conn *ct,const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeouts) {/* If we've seen traffic both ways, this is a GRE connection.
net/netfilter/nf_conntrack_proto_sctp.c +0 -1
@@ -306,7 +306,6 @@ static int sctp_packet(struct nf_conn *ct,const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeouts) { enum sctp_conntrack new_state, old_state;
net/netfilter/nf_conntrack_proto_tcp.c +2 -4
@@ -493,8 +493,7 @@ static bool tcp_in_window(const struct nf_conn *ct,unsigned int index, const struct sk_buff *skb, unsigned int dataoff, - const struct tcphdr *tcph, - u_int8_t pf) + const struct tcphdr *tcph) { struct net *net = nf_ct_net(ct);struct nf_tcp_net *tn =tcp_pernet (net);
@@ -801,7 +800,6 @@ static int tcp_packet(struct nf_conn *ct,const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeouts) { struct net *net = nf_ct_net(ct);
@@ -1013,7 +1011,7 @@ static int tcp_packet(struct nf_conn *ct, }if (!tcp_in_window (ct, &ct->proto.tcp, dir, index, - skb, dataoff, th, pf)) { + skb, dataoff, th)) {spin_unlock_bh (&ct->lock);return -NF_ACCEPT ; }
net/netfilter/nf_conntrack_proto_udp.c +0 -1
@@ -73,7 +73,6 @@ static int udp_packet(struct nf_conn *ct,const struct sk_buff *skb, unsigned int dataoff, enum ip_conntrack_info ctinfo, - u_int8_t pf, unsigned int *timeouts) {/* If we've seen traffic both ways, this is some kind of UDP
Signature · 1 line
2.13.6
Pablo Neira Ayuso
maintainerQuoted 3 lines · Florian Westphal
We currently pass pf to the
packet()function of the l4 trackers, but this isn't needed -- its only required for the 'log invalid' check and the l4 protocol is also available in thenf_connentry.
Series applied, thanks.