netfilter: Replace printk() with pr_*() and define pr_fmt()
Subsystems (5)
Pablo Neira Ayuso
maintainerPATCH 30/47 netfilter: Replace printk() with pr_*() and define pr_fmt()
From: Arushi Singhal <[email protected]>
Using pr_<loglevel>() is more concise than printk(KERN_<LOGLEVEL>). This patch:
* Replace printks having a log level with the appropriate pr_*() macros.
* Define pr_fmt() to include relevant name.
* Remove redundant prefixes from pr_*() calls.
* Indent the code where possible.
* Remove the useless output messages.
* Remove periods from messages.
--- net/netfilter/nf_conntrack_acct.c | 6 ++++-- net/netfilter/nf_conntrack_ecache.c | 6 ++++-- net/netfilter/nf_conntrack_timestamp.c | 6 ++++-- net/netfilter/nf_nat_core.c | 4 +++- net/netfilter/nf_nat_ftp.c | 7 ++++--- net/netfilter/nf_nat_irc.c | 7 ++++--- net/netfilter/nfnetlink_queue.c | 14 +++++++------- net/netfilter/xt_time.c | 13 +++++++------ 8 files changed, 37 insertions(+), 26 deletions(-)
net/netfilter/nf_conntrack_acct.c +4 -2
@@ -8,6 +8,8 @@* published by the Free Software Foundation. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/netfilter.h> #include <linux/slab.h> #include <linux/kernel.h>
@@ -80,7 +82,7 @@ static int nf_conntrack_acct_init_sysctl(struct net *net) net->ct.acct_sysctl_header =register_net_sysctl (net,"net/netfilter" , table);if (!net->ct.acct_sysctl_header) { -printk (KERN_ERR "nf_conntrack_acct: can't register to sysctl.\n" ); +pr_err ("can't register to sysctl\n" ); goto out_register; }return 0 ;
@@ -125,7 +127,7 @@ int nf_conntrack_acct_init(void) {int ret =nf_ct_extend_register (&acct_extend);if (ret <0 ) -pr_err ("nf_conntrack_acct: Unable to register extension\n" ); +pr_err ("Unable to register extension\n" );return ret; }
net/netfilter/nf_conntrack_ecache.c +4 -2
@@ -11,6 +11,8 @@* published by the Free Software Foundation. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/types.h> #include <linux/netfilter.h> #include <linux/skbuff.h>
@@ -372,7 +374,7 @@ static int nf_conntrack_event_init_sysctl(struct net *net) net->ct.event_sysctl_header =register_net_sysctl (net,"net/netfilter" , table);if (!net->ct.event_sysctl_header) { -printk (KERN_ERR "nf_ct_event: can't register to sysctl.\n" ); +pr_err ("can't register to sysctl\n" ); goto out_register; }return 0 ;
@@ -419,7 +421,7 @@ int nf_conntrack_ecache_init(void) {int ret =nf_ct_extend_register (&event_extend);if (ret <0 ) -pr_err ("nf_ct_event: Unable to register event extension.\n" ); +pr_err ("Unable to register event extension\n" );BUILD_BUG_ON (__IPCT_MAX >=16 );/* ctmask, missed use u16 */
net/netfilter/nf_conntrack_timestamp.c +4 -2
@@ -6,6 +6,8 @@* published by the Free Software Foundation (or any later at your option). */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/netfilter.h> #include <linux/slab.h> #include <linux/kernel.h>
@@ -58,7 +60,7 @@ static int nf_conntrack_tstamp_init_sysctl(struct net *net) net->ct.tstamp_sysctl_header =register_net_sysctl (net,"net/netfilter" , table);if (!net->ct.tstamp_sysctl_header) { -printk (KERN_ERR "nf_ct_tstamp: can't register to sysctl.\n" ); +pr_err ("can't register to sysctl\n" ); goto out_register; }return 0 ;
@@ -104,7 +106,7 @@ int nf_conntrack_tstamp_init(void)int ret; ret =nf_ct_extend_register (&tstamp_extend);if (ret <0 ) -pr_err ("nf_ct_tstamp: Unable to register extension\n" ); +pr_err ("Unable to register extension\n" );return ret; }
net/netfilter/nf_nat_core.c +3 -1
@@ -8,6 +8,8 @@* published by the Free Software Foundation. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/module.h> #include <linux/types.h> #include <linux/timer.h>
@@ -814,7 +816,7 @@ static int __init nf_nat_init(void) ret =nf_ct_extend_register (&nat_extend);if (ret <0 ) {nf_ct_free_hashtable (nf_nat_bysource, nf_nat_htable_size); -printk (KERN_ERR "nf_nat_core: Unable to register extension\n" ); +pr_err ("Unable to register extension\n" );return ret; }
net/netfilter/nf_nat_ftp.c +4 -3
@@ -8,6 +8,8 @@* published by the Free Software Foundation. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/inet.h>
@@ -71,7 +73,7 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb,char buffer[sizeof ("|1||65535|" ) +INET6_ADDRSTRLEN ];unsigned int buflen; -pr_debug ("FTP_NAT: type %i, off %u len %u\n" , type, matchoff, matchlen); +pr_debug ("type %i, off %u len %u\n" , type, matchoff, matchlen);/* Connection will come from wherever this packet goes, hence !dir */ newaddr = ct->tuplehash[!dir].tuple.dst.u3;
@@ -136,8 +138,7 @@ static int __init nf_nat_ftp_init(void)/* Prior to 2.6.11, we had a ports param. No longer, but don't break users. */ static int warn_set (const char *val,const struct kernel_param *kp) { - printk(KERN_INFO KBUILD_MODNAME - ": kernel >= 2.6.10 only uses 'ports' for conntrack modules\n"); +pr_info ("kernel >= 2.6.10 only uses 'ports' for conntrack modules\n" );return 0 ; }module_param_call (ports, warn_set,NULL ,NULL ,0 );
net/netfilter/nf_nat_irc.c +4 -3
@@ -10,6 +10,8 @@* 2 of the License, or (at your option) any later version. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/tcp.h>
@@ -79,7 +81,7 @@ static unsigned int help(struct sk_buff *skb,*/ /* AAA = "us", ie. where server normally talks to. */ snprintf (buffer,sizeof (buffer),"%u %u" ,ntohl (newaddr.ip), port); -pr_debug ("nf_nat_irc: inserting '%s' == %pI4, port %u\n" , +pr_debug ("inserting '%s' == %pI4, port %u\n" , buffer, &newaddr.ip, port); if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo, protoff, matchoff,
@@ -108,8 +110,7 @@ static int __init nf_nat_irc_init(void)/* Prior to 2.6.11, we had a ports param. No longer, but don't break users. */ static int warn_set (const char *val,const struct kernel_param *kp) { - printk(KERN_INFO KBUILD_MODNAME - ": kernel >= 2.6.10 only uses 'ports' for conntrack modules\n"); +pr_info ("kernel >= 2.6.10 only uses 'ports' for conntrack modules\n" );return 0 ; }module_param_call (ports, warn_set,NULL ,NULL ,0 );
net/netfilter/nfnetlink_queue.c +7 -7
@@ -14,6 +14,9 @@* published by the Free Software Foundation. * */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/module.h> #include <linux/skbuff.h> #include <linux/init.h>
@@ -833,11 +836,8 @@ nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff)if (diff >skb_tailroom (e->skb)) { nskb =skb_copy_expand (e->skb,skb_headroom (e->skb), diff,GFP_ATOMIC ); -if (!nskb) { -printk (KERN_WARNING "nf_queue: OOM " -"in mangle, dropping packet\n" ); +if (!nskb)return -ENOMEM ; - }kfree_skb (e->skb); e->skb = nskb; }
@@ -1536,20 +1536,20 @@ static int __init nfnetlink_queue_init(void) status =register_pernet_subsys (&nfnl_queue_net_ops);if (status <0 ) { -pr_err ("nf_queue: failed to register pernet ops\n" ); +pr_err ("failed to register pernet ops\n" ); goto out; }netlink_register_notifier (&nfqnl_rtnl_notifier); status =nfnetlink_subsys_register (&nfqnl_subsys);if (status <0 ) { -pr_err ("nf_queue: failed to create netlink socket\n" ); +pr_err ("failed to create netlink socket\n" ); goto cleanup_netlink_notifier; } status =register_netdevice_notifier (&nfqnl_dev_notifier);if (status <0 ) { -pr_err ("nf_queue: failed to register netdevice notifier\n" ); +pr_err ("failed to register netdevice notifier\n" ); goto cleanup_netlink_subsys; }
net/netfilter/xt_time.c +7 -6
@@ -9,6 +9,9 @@* This file is distributed under the terms of the GNU General Public * License (GPL). Copies of the GPL can be obtained from gnu.org/gpl. */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/ktime.h> #include <linux/module.h> #include <linux/skbuff.h>
@@ -266,13 +269,11 @@ static int __init time_mt_init(void)int minutes = sys_tz.tz_minuteswest;if (minutes <0 )/* east of Greenwich */ - printk(KERN_INFO KBUILD_MODNAME -": kernel timezone is +%02d%02d\n" , - -minutes /60 , -minutes %60 ); +pr_info ("kernel timezone is +%02d%02d\n" , + -minutes /60 , -minutes %60 );else /* west of Greenwich */ - printk(KERN_INFO KBUILD_MODNAME -": kernel timezone is -%02d%02d\n" , - minutes /60 , minutes %60 ); +pr_info ("kernel timezone is -%02d%02d\n" , + minutes /60 , minutes %60 );return xt_register_match (&xt_time_mt_reg); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 31/47 netfilter: ctnetlink: synproxy support
This patch exposes synproxy information per-conntrack. Moreover, send sequence adjustment events once server sends us the SYN,ACK packet, so we can synchronize the sequence adjustment too for packets going as reply from the server, as part of the synproxy logic.
--- include/uapi/linux/netfilter/nf_conntrack_common.h | 1 + include/uapi/linux/netfilter/nfnetlink_conntrack.h | 10 +++ net/ipv4/netfilter/ipt_SYNPROXY.c | 8 +- net/ipv6/netfilter/ip6t_SYNPROXY.c | 8 +- net/netfilter/nf_conntrack_netlink.c | 87 +++++++++++++++++++++- 5 files changed, 109 insertions(+), 5 deletions(-)
include/uapi/linux/netfilter/nf_conntrack_common.h +1 -0
@@ -129,6 +129,7 @@ enum ip_conntrack_events {IPCT_NATSEQADJ =IPCT_SEQADJ ,IPCT_SECMARK ,/* new security mark has been set */ IPCT_LABEL ,/* new connlabel has been set */ +IPCT_SYNPROXY ,/* synproxy has been set */ #ifdef __KERNEL__ __IPCT_MAX #endif
include/uapi/linux/netfilter/nfnetlink_conntrack.h +10 -0
@@ -54,6 +54,7 @@ enum ctattr_type {CTA_MARK_MASK ,CTA_LABELS ,CTA_LABELS_MASK , +CTA_SYNPROXY , __CTA_MAX };#define CTA_MAX (__CTA_MAX - 1)
@@ -190,6 +191,15 @@ enum ctattr_natseq { };#define CTA_NAT_SEQ_MAX (__CTA_NAT_SEQ_MAX - 1) +enum ctattr_synproxy { +CTA_SYNPROXY_UNSPEC , +CTA_SYNPROXY_ISN , +CTA_SYNPROXY_ITS , +CTA_SYNPROXY_TSOFF , + __CTA_SYNPROXY_MAX, +}; +#define CTA_SYNPROXY_MAX (__CTA_SYNPROXY_MAX - 1) +enum ctattr_expect {CTA_EXPECT_UNSPEC ,CTA_EXPECT_MASTER ,
net/ipv4/netfilter/ipt_SYNPROXY.c +7 -1
@@ -16,6 +16,7 @@#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_seqadj.h> #include <net/netfilter/nf_conntrack_synproxy.h> +#include <net/netfilter/nf_conntrack_ecache.h> static struct iphdr * synproxy_build_ip(struct net *net, struct sk_buff *skb, __be32 saddr,
@@ -384,6 +385,8 @@ static unsigned int ipv4_synproxy_hook(void *priv, synproxy->isn =ntohl (th->ack_seq);if (opts.options &XT_SYNPROXY_OPT_TIMESTAMP ) synproxy->its = opts.tsecr; + +nf_conntrack_event_cache (IPCT_SYNPROXY , ct);break ;case TCP_CONNTRACK_SYN_RECV :if (!th->syn || !th->ack)
@@ -392,8 +395,10 @@ static unsigned int ipv4_synproxy_hook(void *priv,if (!synproxy_parse_options (skb, thoff, th, &opts))return NF_DROP ; -if (opts.options &XT_SYNPROXY_OPT_TIMESTAMP ) +if (opts.options &XT_SYNPROXY_OPT_TIMESTAMP ) { synproxy->tsoff = opts.tsval - synproxy->its; +nf_conntrack_event_cache (IPCT_SYNPROXY , ct); + } opts.options &= ~(XT_SYNPROXY_OPT_MSS | XT_SYNPROXY_OPT_WSCALE |
@@ -403,6 +408,7 @@ static unsigned int ipv4_synproxy_hook(void *priv,synproxy_send_server_ack (net, state, skb, th, &opts);nf_ct_seqadj_init (ct, ctinfo, synproxy->isn -ntohl (th->seq)); +nf_conntrack_event_cache (IPCT_SEQADJ , ct);swap (opts.tsval, opts.tsecr);synproxy_send_client_ack (net, skb, th, &opts);
net/ipv6/netfilter/ip6t_SYNPROXY.c +7 -1
@@ -18,6 +18,7 @@#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_seqadj.h> #include <net/netfilter/nf_conntrack_synproxy.h> +#include <net/netfilter/nf_conntrack_ecache.h> static struct ipv6hdr * synproxy_build_ip(struct net *net, struct sk_buff *skb,
@@ -405,6 +406,8 @@ static unsigned int ipv6_synproxy_hook(void *priv, synproxy->isn =ntohl (th->ack_seq);if (opts.options &XT_SYNPROXY_OPT_TIMESTAMP ) synproxy->its = opts.tsecr; + +nf_conntrack_event_cache (IPCT_SYNPROXY , ct);break ;case TCP_CONNTRACK_SYN_RECV :if (!th->syn || !th->ack)
@@ -413,8 +416,10 @@ static unsigned int ipv6_synproxy_hook(void *priv,if (!synproxy_parse_options (skb, thoff, th, &opts))return NF_DROP ; -if (opts.options &XT_SYNPROXY_OPT_TIMESTAMP ) +if (opts.options &XT_SYNPROXY_OPT_TIMESTAMP ) { synproxy->tsoff = opts.tsval - synproxy->its; +nf_conntrack_event_cache (IPCT_SYNPROXY , ct); + } opts.options &= ~(XT_SYNPROXY_OPT_MSS | XT_SYNPROXY_OPT_WSCALE |
@@ -424,6 +429,7 @@ static unsigned int ipv6_synproxy_hook(void *priv,synproxy_send_server_ack (net, state, skb, th, &opts);nf_ct_seqadj_init (ct, ctinfo, synproxy->isn -ntohl (th->seq)); +nf_conntrack_event_cache (IPCT_SEQADJ , ct);swap (opts.tsval, opts.tsecr);synproxy_send_client_ack (net, skb, th, &opts);
net/netfilter/nf_conntrack_netlink.c +84 -3
141 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 32/47 netfilter: ebtables: add support for matching ICMP type and code
In reply to Pablo Neira AyusoFrom: Matthias Schiffer <[email protected]>
We already have ICMPv6 type/code matches. This adds support for IPv4 ICMP matches in the same way.
--- include/uapi/linux/netfilter_bridge/ebt_ip.h | 13 +++++++-- net/bridge/netfilter/ebt_ip.c | 43 +++++++++++++++++++++------- 2 files changed, 43 insertions(+), 13 deletions(-)
include/uapi/linux/netfilter_bridge/ebt_ip.h +10 -3
@@ -24,8 +24,9 @@#define EBT_IP_PROTO 0x08#define EBT_IP_SPORT 0x10#define EBT_IP_DPORT 0x20 +#define EBT_IP_ICMP 0x40#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\ - EBT_IP_SPORT | EBT_IP_DPORT ) + EBT_IP_SPORT | EBT_IP_DPORT | EBT_IP_ICMP)#define EBT_IP_MATCH "ip"/* the same values are used for the invflags */
@@ -38,8 +39,14 @@ struct ebt_ip_info {__u8 protocol;__u8 bitmask;__u8 invflags; -__u16 sport[2 ]; - __u16 dport[2]; +union { +__u16 sport[2 ]; +__u8 icmp_type[2 ]; + }; +union { +__u16 dport[2 ]; +__u8 icmp_code[2 ]; + }; };#endif
net/bridge/netfilter/ebt_ip.c +33 -10
85 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 33/47 netfilter: ebtables: add support for matching IGMP type
In reply to Pablo Neira AyusoFrom: Matthias Schiffer <[email protected]>
We already have ICMPv6 type/code matches (which can be used to distinguish different types of MLD packets). Add support for IPv4 IGMP matches in the same way.
--- include/uapi/linux/netfilter_bridge/ebt_ip.h | 4 +++- net/bridge/netfilter/ebt_ip.c | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-)
include/uapi/linux/netfilter_bridge/ebt_ip.h +3 -1
@@ -25,8 +25,9 @@#define EBT_IP_SPORT 0x10#define EBT_IP_DPORT 0x20#define EBT_IP_ICMP 0x40 +#define EBT_IP_IGMP 0x80#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\ - EBT_IP_SPORT | EBT_IP_DPORT | EBT_IP_ICMP) + EBT_IP_SPORT | EBT_IP_DPORT | EBT_IP_ICMP | EBT_IP_IGMP)#define EBT_IP_MATCH "ip"/* the same values are used for the invflags */
@@ -42,6 +43,7 @@ struct ebt_ip_info {union {__u16 sport[2 ];__u8 icmp_type[2 ]; +__u8 igmp_type[2 ]; };union {__u16 dport[2 ];
net/bridge/netfilter/ebt_ip.c +17 -2
@@ -28,6 +28,9 @@ union pkthdr {u8 type;u8 code; } icmphdr; +struct { +u8 type; + } igmphdr; }; static bool
@@ -57,12 +60,12 @@ ebt_ip_mt(const struct sk_buff *skb, struct xt_action_param *par)if (NF_INVF (info,EBT_IP_PROTO , info->protocol != ih->protocol))return false;if (!(info->bitmask & (EBT_IP_DPORT |EBT_IP_SPORT | -EBT_IP_ICMP ))) +EBT_IP_ICMP |EBT_IP_IGMP )))return true;if (ntohs (ih->frag_off) &IP_OFFSET )return false; -/* min icmp headersize is 4, so sizeof(_pkthdr) is ok. */ +/* min icmp/igmp headersize is 4, so sizeof(_pkthdr) is ok. */ pptr =skb_header_pointer (skb, ih->ihl*4 ,sizeof (_pkthdr), &_pkthdr);if (pptr ==NULL )
@@ -88,6 +91,11 @@ ebt_ip_mt(const struct sk_buff *skb, struct xt_action_param *par) pptr->icmphdr.code < info->icmp_code[0] || pptr->icmphdr.code > info->icmp_code[1]))return false; +if ((info->bitmask &EBT_IP_IGMP ) && +NF_INVF (info,EBT_IP_IGMP , + pptr->igmphdr.type < info->igmp_type[0 ] || + pptr->igmphdr.type > info->igmp_type[1 ])) +return false; }return true; }
@@ -124,6 +132,13 @@ static int ebt_ip_mt_check(const struct xt_mtchk_param *par) info->icmp_code[0] > info->icmp_code[1])return -EINVAL ; } +if (info->bitmask &EBT_IP_IGMP ) { +if ((info->invflags &EBT_IP_PROTO ) || + info->protocol !=IPPROTO_IGMP ) +return -EINVAL ; +if (info->igmp_type[0 ] > info->igmp_type[1 ]) +return -EINVAL ; + }return 0 ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 34/47 netfilter: ebtables: Add support for specifying match revision
In reply to Pablo Neira AyusoFrom: Bernie Harris <[email protected]>
Currently ebtables assumes that the revision number of all match modules is 0, which is an issue when trying to use existing xtables matches with ebtables. The solution is to modify ebtables to allow extensions to specify a revision number, similar to iptables. This gets passed down to the kernel, which is then able to find the match module correctly.
To main binary backwards compatibility, the size of the ebt_entry structures is not changed, only the size of the name field is decreased by 1 byte to make room for the revision field.
--- include/uapi/linux/netfilter_bridge/ebtables.h | 16 +++++++-- net/bridge/netfilter/ebtables.c | 47 ++++++++++++++++---------- 2 files changed, 42 insertions(+), 21 deletions(-)
include/uapi/linux/netfilter_bridge/ebtables.h +13 -3
@@ -20,6 +20,7 @@#define EBT_TABLE_MAXNAMELEN 32#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN +#define EBT_EXTENSION_MAXNAMELEN 31/* verdicts >0 are "branches" */ #define EBT_ACCEPT -1
@@ -120,7 +121,10 @@ struct ebt_entries {struct ebt_entry_match {union { -char name[EBT_FUNCTION_MAXNAMELEN ]; +struct { +char name[EBT_EXTENSION_MAXNAMELEN ]; +uint8_t revision; + };struct xt_match *match; } u;/* size of data */
@@ -130,7 +134,10 @@ struct ebt_entry_match {struct ebt_entry_watcher {union { -char name[EBT_FUNCTION_MAXNAMELEN ]; +struct { +char name[EBT_EXTENSION_MAXNAMELEN ]; +uint8_t revision; + };struct xt_target *watcher; } u;/* size of data */
@@ -140,7 +147,10 @@ struct ebt_entry_watcher {struct ebt_entry_target {union { -char name[EBT_FUNCTION_MAXNAMELEN ]; +struct { +char name[EBT_EXTENSION_MAXNAMELEN ]; +uint8_t revision; + };struct xt_target *target; } u;/* size of data */
net/bridge/netfilter/ebtables.c +29 -18
122 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 35/47 netfilter: ebtables: Add string filter
In reply to Pablo Neira AyusoFrom: Bernie Harris <[email protected]>
This patch is part of a proposal to add a string filter to ebtables, which would be similar to the string filter in iptables. Like iptables, the ebtables filter uses the xt_string module.
--- net/netfilter/xt_string.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/xt_string.c +1 -0
@@ -21,6 +21,7 @@ MODULE_DESCRIPTION("Xtables: string-based matching");MODULE_LICENSE ("GPL" );MODULE_ALIAS ("ipt_string" );MODULE_ALIAS ("ip6t_string" ); +MODULE_ALIAS ("ebt_string" );static bool string_mt (const struct sk_buff *skb,struct xt_action_param *par)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 36/47 netfilter: add flowtable documentation
In reply to Pablo Neira AyusoThis patch adds initial documentation for the Netfilter flowtable infrastructure.
--- Documentation/networking/nf_flowtable.txt | 112 ++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Documentation/networking/nf_flowtable.txt
Documentation/networking/nf_flowtable.txt new file +112 -0
@@ -0,0 +1,112 @@ +Netfilter's flowtable infrastructure +==================================== + +This documentation describes the software flowtable infrastructure available in +Netfilter since Linux kernel 4.16. + +Overview +-------- + +Initial packets follow the classic forwarding path, once the flow enters the +established state according to the conntrack semantics (ie. we have seen traffic +in both directions), then you can decide to offload the flow to the flowtable +from the forward chain via the 'flow offload' action available in nftables. + +Packets that find an entry in the flowtable (ie. flowtable hit) are sent to the +output netdevice via neigh_xmit(), hence, they bypass the classic forwarding +path (the visible effect is that you do not see these packets from any of the +netfilter hooks coming after the ingress). In case of flowtable miss, the packet +follows the classic forward path. + +The flowtable uses a resizable hashtable, lookups are based on the following +7-tuple selectors: source, destination, layer 3 and layer 4 protocols, source +and destination ports and the input interface (useful in case there are several +conntrack zones in place). + +Flowtables are populated via the 'flow offload' nftables action, so the user can +selectively specify what flows are placed into the flow table. Hence, packets +follow the classic forwarding path unless the user explicitly instruct packets +to use this new alternative forwarding path via nftables policy. + +This is represented in Fig.1, which describes the classic forwarding path +including the Netfilter hooks and the flowtable fastpath bypass. + + userspace process + ^ | + | | + _____|____ ____\/___ + / \ / \ + | input | | output | + \__________/ \_________/ + ^ | + | | + _________ __________ --------- _____\/_____ + / \ / \ |Routing | / \ + --> ingress ---> prerouting ---> |decision| | postrouting |--> neigh_xmit + \_________/ \__________/ ---------- \____________/ ^ + | ^ | | ^ | + flowtable | | ____\/___ | | + | | | / \ | | + __\/___ | --------->| forward |------------ | + |-----| | \_________/ | + |-----| | 'flow offload' rule | + |-----| | adds entry to | + |_____| | flowtable | + | | | + / \ | | + /hit\_no_| | + \ ? / | + \ / | + |__yes_________________fastpath bypass ____________________________| + + Fig.1 Netfilter hooks and flowtable interactions + +The flowtable entry also stores the NAT configuration, so all packets are +mangled according to the NAT policy that matches the initial packets that went +through the classic forwarding path. The TTL is decremented before calling +neigh_xmit(). Fragmented traffic is passed up to follow the classic forwarding +path given that the transport selectors are missing, therefore flowtable lookup +is not possible. + +Example configuration +--------------------- + +Enabling the flowtable bypass is relatively easy, you only need to create a +flowtable and add one rule to your forward chain. + + table inet x { + flowtable f { + hook ingress priority 0 devices = { eth0, eth1 }; + } + chain y { + type filter hook forward priority 0; policy accept; + ip protocol tcp flow offload @f + counter packets 0 bytes 0 + } + } + +This example adds the flowtable 'f' to the ingress hook of the eth0 and eth1 +netdevices. You can create as many flowtables as you want in case you need to +perform resource partitioning. The flowtable priority defines the order in which +hooks are run in the pipeline, this is convenient in case you already have a +nftables ingress chain (make sure the flowtable priority is smaller than the +nftables ingress chain hence the flowtable runs before in the pipeline). + +The 'flow offload' action from the forward chain 'y' adds an entry to the +flowtable for the TCP syn-ack packet coming in the reply direction. Once the +flow is offloaded, you will observe that the counter rule in the example above +does not get updated for the packets that are being forwarded through the +forwarding bypass. + +More reading +------------ + +This documentation is based on the LWN.net articles [1][2]. Rafal Milecki also +made a very complete and comprehensive summary called "A state of network +acceleration" that describes how things were before this infrastructure was +mailined [3] and it also makes a rough summary of this work [4]. + +[1] https://lwn.net/Articles/738214/ +[2] https://lwn.net/Articles/742164/ +[3] http://lists.infradead.org/pipermail/lede-dev/2018-January/010830.html +[4] http://lists.infradead.org/pipermail/lede-dev/2018-January/010829.html
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 37/47 netfilter: ebt_stp: Use generic functions for comparisons
In reply to Pablo Neira AyusoFrom: Joe Perches <[email protected]>
Instead of unnecessary const declarations, use the generic functions to save a little object space.
$ size net/bridge/netfilter/ebt_stp.o* text data bss dec hex filename 1250 144 0 1394 572 net/bridge/netfilter/ebt_stp.o.new 1344 144 0 1488 5d0 net/bridge/netfilter/ebt_stp.o.old
--- net/bridge/netfilter/ebt_stp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/bridge/netfilter/ebt_stp.c +2 -4
@@ -153,8 +153,6 @@ ebt_stp_mt(const struct sk_buff *skb, struct xt_action_param *par)static int ebt_stp_mt_check (const struct xt_mtchk_param *par) {const struct ebt_stp_info *info = par->matchinfo; -const u8 bridge_ula[6 ] = {0x01 ,0x80 ,0xc2 ,0x00 ,0x00 ,0x00 }; -const u8 msk[6 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff };const struct ebt_entry *e = par->entryinfo; if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
@@ -162,8 +160,8 @@ static int ebt_stp_mt_check(const struct xt_mtchk_param *par)return -EINVAL ;/* Make sure the match only receives stp frames */ if (!par->nft_compat && - (!ether_addr_equal (e->destmac, bridge_ula) || - !ether_addr_equal (e->destmsk, msk) || + (!ether_addr_equal (e->destmac, eth_stp_addr) || + !is_broadcast_ether_addr (e->destmsk) || !(e->bitmask &EBT_DESTMAC )))return -EINVAL ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 38/47 netfilter: nf_tables: rename struct nf_chain_type
In reply to Pablo Neira AyusoUse nft_ prefix. By when I added chain types, I forgot to use the nftables prefix. Rename enum nft_chain_type to enum nft_chain_types too, otherwise there is an overlap.
--- include/net/netfilter/nf_tables.h | 16 ++++++++-------- net/bridge/netfilter/nf_tables_bridge.c | 2 +- net/ipv4/netfilter/nf_tables_arp.c | 2 +- net/ipv4/netfilter/nf_tables_ipv4.c | 2 +- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 2 +- net/ipv4/netfilter/nft_chain_route_ipv4.c | 2 +- net/ipv6/netfilter/nf_tables_ipv6.c | 2 +- net/ipv6/netfilter/nft_chain_nat_ipv6.c | 2 +- net/ipv6/netfilter/nft_chain_route_ipv6.c | 2 +- net/netfilter/nf_tables_api.c | 18 +++++++++--------- net/netfilter/nf_tables_inet.c | 2 +- net/netfilter/nf_tables_netdev.c | 2 +- 12 files changed, 27 insertions(+), 27 deletions(-)
include/net/netfilter/nf_tables.h +8 -8
@@ -868,7 +868,7 @@ struct nft_chain {char *name; }; -enum nft_chain_type { +enum nft_chain_types {NFT_CHAIN_T_DEFAULT =0 ,NFT_CHAIN_T_ROUTE ,NFT_CHAIN_T_NAT ,
@@ -876,7 +876,7 @@ enum nft_chain_type { };/** -* struct nf_chain_type - nf_tables chain type info +* struct nft_chain_type - nf_tables chain type info * * @name: name of the type * @type: numeric identifier
@@ -885,9 +885,9 @@ enum nft_chain_type {* @hook_mask: mask of valid hooks * @hooks: array of hook functions */ -struct nf_chain_type { +struct nft_chain_type {const char *name; -enum nft_chain_type type; +enum nft_chain_types type;int family;struct module *owner;unsigned int hook_mask;
@@ -895,7 +895,7 @@ struct nf_chain_type { };int nft_chain_validate_dependency (const struct nft_chain *chain, -enum nft_chain_type type); +enum nft_chain_types type);int nft_chain_validate_hooks (const struct nft_chain *chain,unsigned int hook_flags);
@@ -917,7 +917,7 @@ struct nft_stats {*/ struct nft_base_chain {struct nf_hook_ops ops; -const struct nf_chain_type *type; +const struct nft_chain_type *type;u8 policy;u8 flags;struct nft_stats __percpu *stats;
@@ -970,8 +970,8 @@ struct nft_table {char *name; }; -int nft_register_chain_type (const struct nf_chain_type *); -void nft_unregister_chain_type (const struct nf_chain_type *); +int nft_register_chain_type (const struct nft_chain_type *); +void nft_unregister_chain_type (const struct nft_chain_type *);int nft_register_expr (struct nft_expr_type *);void nft_unregister_expr (struct nft_expr_type *);
net/bridge/netfilter/nf_tables_bridge.c +1 -1
@@ -42,7 +42,7 @@ nft_do_chain_bridge(void *priv,return nft_do_chain (&pkt, priv); } -static const struct nf_chain_type filter_bridge = { +static const struct nft_chain_type filter_bridge = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT , .family =NFPROTO_BRIDGE ,
net/ipv4/netfilter/nf_tables_arp.c +1 -1
@@ -27,7 +27,7 @@ nft_do_chain_arp(void *priv,return nft_do_chain (&pkt, priv); } -static const struct nf_chain_type filter_arp = { +static const struct nft_chain_type filter_arp = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT , .family =NFPROTO_ARP ,
net/ipv4/netfilter/nf_tables_ipv4.c +1 -1
@@ -30,7 +30,7 @@ static unsigned int nft_do_chain_ipv4(void *priv,return nft_do_chain (&pkt, priv); } -static const struct nf_chain_type filter_ipv4 = { +static const struct nft_chain_type filter_ipv4 = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT , .family =NFPROTO_IPV4 ,
net/ipv4/netfilter/nft_chain_nat_ipv4.c +1 -1
@@ -67,7 +67,7 @@ static unsigned int nft_nat_ipv4_local_fn(void *priv,return nf_nat_ipv4_local_fn (priv, skb, state, nft_nat_do_chain); } -static const struct nf_chain_type nft_chain_nat_ipv4 = { +static const struct nft_chain_type nft_chain_nat_ipv4 = { .name ="nat" , .type =NFT_CHAIN_T_NAT , .family =NFPROTO_IPV4 ,
net/ipv4/netfilter/nft_chain_route_ipv4.c +1 -1
@@ -58,7 +58,7 @@ static unsigned int nf_route_table_hook(void *priv,return ret; } -static const struct nf_chain_type nft_chain_route_ipv4 = { +static const struct nft_chain_type nft_chain_route_ipv4 = { .name ="route" , .type =NFT_CHAIN_T_ROUTE , .family =NFPROTO_IPV4 ,
net/ipv6/netfilter/nf_tables_ipv6.c +1 -1
@@ -28,7 +28,7 @@ static unsigned int nft_do_chain_ipv6(void *priv,return nft_do_chain (&pkt, priv); } -static const struct nf_chain_type filter_ipv6 = { +static const struct nft_chain_type filter_ipv6 = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT , .family =NFPROTO_IPV6 ,
net/ipv6/netfilter/nft_chain_nat_ipv6.c +1 -1
@@ -65,7 +65,7 @@ static unsigned int nft_nat_ipv6_local_fn(void *priv,return nf_nat_ipv6_local_fn (priv, skb, state, nft_nat_do_chain); } -static const struct nf_chain_type nft_chain_nat_ipv6 = { +static const struct nft_chain_type nft_chain_nat_ipv6 = { .name ="nat" , .type =NFT_CHAIN_T_NAT , .family =NFPROTO_IPV6 ,
net/ipv6/netfilter/nft_chain_route_ipv6.c +1 -1
@@ -60,7 +60,7 @@ static unsigned int nf_route_table_hook(void *priv,return ret; } -static const struct nf_chain_type nft_chain_route_ipv6 = { +static const struct nft_chain_type nft_chain_route_ipv6 = { .name ="route" , .type =NFT_CHAIN_T_ROUTE , .family =NFPROTO_IPV6 ,
net/netfilter/nf_tables_api.c +9 -9
@@ -384,9 +384,9 @@ static inline u64 nf_tables_alloc_handle(struct nft_table *table)return ++table->hgenerator; } -static const struct nf_chain_type *chain_type[NFPROTO_NUMPROTO ][NFT_CHAIN_T_MAX ]; +static const struct nft_chain_type *chain_type[NFPROTO_NUMPROTO ][NFT_CHAIN_T_MAX ]; -static const struct nf_chain_type * +static const struct nft_chain_type *__nf_tables_chain_type_lookup (const struct nlattr *nla,u8 family) {int i;
@@ -399,10 +399,10 @@ __nf_tables_chain_type_lookup(const struct nlattr *nla, u8 family)return NULL ; } -static const struct nf_chain_type * +static const struct nft_chain_type *nf_tables_chain_type_lookup (const struct nlattr *nla,u8 family,bool autoload) { -const struct nf_chain_type *type; +const struct nft_chain_type *type; type =__nf_tables_chain_type_lookup (nla, family);if (type !=NULL )
@@ -859,7 +859,7 @@ static void nf_tables_table_destroy(struct nft_ctx *ctx)kfree (ctx->table); } -int nft_register_chain_type (const struct nf_chain_type *ctype) +int nft_register_chain_type (const struct nft_chain_type *ctype) {int err =0 ;
@@ -878,7 +878,7 @@ int nft_register_chain_type(const struct nf_chain_type *ctype) }EXPORT_SYMBOL_GPL (nft_register_chain_type); -void nft_unregister_chain_type (const struct nf_chain_type *ctype) +void nft_unregister_chain_type (const struct nft_chain_type *ctype) {nfnl_lock (NFNL_SUBSYS_NFTABLES ); chain_type[ctype->family][ctype->type] =NULL ;
@@ -1239,7 +1239,7 @@ static void nf_tables_chain_destroy(struct nft_chain *chain)struct nft_chain_hook {u32 num;s32 priority; -const struct nf_chain_type *type; +const struct nft_chain_type *type;struct net_device *dev; };
@@ -1249,7 +1249,7 @@ static int nft_chain_parse_hook(struct net *net, bool create) {struct nlattr *ha[NFTA_HOOK_MAX +1 ]; -const struct nf_chain_type *type; +const struct nft_chain_type *type;struct net_device *dev;int err;
@@ -6000,7 +6000,7 @@ static const struct nfnetlink_subsystem nf_tables_subsys = { };int nft_chain_validate_dependency (const struct nft_chain *chain, -enum nft_chain_type type) +enum nft_chain_types type) {const struct nft_base_chain *basechain;
net/netfilter/nf_tables_inet.c +1 -1
@@ -38,7 +38,7 @@ static unsigned int nft_do_chain_inet(void *priv, struct sk_buff *skb,return nft_do_chain (&pkt, priv); } -static const struct nf_chain_type filter_inet = { +static const struct nft_chain_type filter_inet = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT , .family =NFPROTO_INET ,
net/netfilter/nf_tables_netdev.c +1 -1
@@ -38,7 +38,7 @@ nft_do_chain_netdev(void *priv, struct sk_buff *skb,return nft_do_chain (&pkt, priv); } -static const struct nf_chain_type nft_filter_chain_netdev = { +static const struct nft_chain_type nft_filter_chain_netdev = { .name ="filter" , .type =NFT_CHAIN_T_DEFAULT , .family =NFPROTO_NETDEV ,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 39/47 netfilter: nf_tables: nft_register_chain_type() returns void
In reply to Pablo Neira AyusoUse WARN_ON() instead since it should not happen that neither family goes over NFPROTO_NUMPROTO nor there is already a chain of this type already registered.
--- include/net/netfilter/nf_tables.h | 2 +- net/bridge/netfilter/nf_tables_bridge.c | 4 +++- net/ipv4/netfilter/nf_tables_arp.c | 4 +++- net/ipv4/netfilter/nf_tables_ipv4.c | 4 +++- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 6 +----- net/ipv4/netfilter/nft_chain_route_ipv4.c | 4 +++- net/ipv6/netfilter/nf_tables_ipv6.c | 4 +++- net/ipv6/netfilter/nft_chain_nat_ipv6.c | 6 +----- net/ipv6/netfilter/nft_chain_route_ipv6.c | 4 +++- net/netfilter/nf_tables_api.c | 14 +++++--------- net/netfilter/nf_tables_inet.c | 4 +++- net/netfilter/nf_tables_netdev.c | 4 +--- 12 files changed, 30 insertions(+), 30 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -970,7 +970,7 @@ struct nft_table {char *name; }; -int nft_register_chain_type (const struct nft_chain_type *); +void nft_register_chain_type (const struct nft_chain_type *);void nft_unregister_chain_type (const struct nft_chain_type *);int nft_register_expr (struct nft_expr_type *);
net/bridge/netfilter/nf_tables_bridge.c +3 -1
@@ -63,7 +63,9 @@ static const struct nft_chain_type filter_bridge = {static int __init nf_tables_bridge_init (void ) { -return nft_register_chain_type (&filter_bridge); +nft_register_chain_type (&filter_bridge); + +return 0 ; } static void __exit nf_tables_bridge_exit(void)
net/ipv4/netfilter/nf_tables_arp.c +3 -1
@@ -42,7 +42,9 @@ static const struct nft_chain_type filter_arp = {static int __init nf_tables_arp_init (void ) { -return nft_register_chain_type (&filter_arp); +nft_register_chain_type (&filter_arp); + +return 0 ; } static void __exit nf_tables_arp_exit(void)
net/ipv4/netfilter/nf_tables_ipv4.c +3 -1
@@ -51,7 +51,9 @@ static const struct nft_chain_type filter_ipv4 = {static int __init nf_tables_ipv4_init (void ) { -return nft_register_chain_type (&filter_ipv4); +nft_register_chain_type (&filter_ipv4); + +return 0 ; } static void __exit nf_tables_ipv4_exit(void)
net/ipv4/netfilter/nft_chain_nat_ipv4.c +1 -5
@@ -86,11 +86,7 @@ static const struct nft_chain_type nft_chain_nat_ipv4 = {static int __init nft_chain_nat_init (void ) { -int err; - - err =nft_register_chain_type (&nft_chain_nat_ipv4); -if (err <0 ) -return err; +nft_register_chain_type (&nft_chain_nat_ipv4);return 0 ; }
net/ipv4/netfilter/nft_chain_route_ipv4.c +3 -1
@@ -71,7 +71,9 @@ static const struct nft_chain_type nft_chain_route_ipv4 = {static int __init nft_chain_route_init (void ) { -return nft_register_chain_type (&nft_chain_route_ipv4); +nft_register_chain_type (&nft_chain_route_ipv4); + +return 0 ; } static void __exit nft_chain_route_exit(void)
net/ipv6/netfilter/nf_tables_ipv6.c +3 -1
@@ -49,7 +49,9 @@ static const struct nft_chain_type filter_ipv6 = {static int __init nf_tables_ipv6_init (void ) { -return nft_register_chain_type (&filter_ipv6); +nft_register_chain_type (&filter_ipv6); + +return 0 ; } static void __exit nf_tables_ipv6_exit(void)
net/ipv6/netfilter/nft_chain_nat_ipv6.c +1 -5
@@ -84,11 +84,7 @@ static const struct nft_chain_type nft_chain_nat_ipv6 = {static int __init nft_chain_nat_ipv6_init (void ) { -int err; - - err =nft_register_chain_type (&nft_chain_nat_ipv6); -if (err <0 ) -return err; +nft_register_chain_type (&nft_chain_nat_ipv6);return 0 ; }
net/ipv6/netfilter/nft_chain_route_ipv6.c +3 -1
@@ -73,7 +73,9 @@ static const struct nft_chain_type nft_chain_route_ipv6 = {static int __init nft_chain_route_init (void ) { -return nft_register_chain_type (&nft_chain_route_ipv6); +nft_register_chain_type (&nft_chain_route_ipv6); + +return 0 ; } static void __exit nft_chain_route_exit(void)
net/netfilter/nf_tables_api.c +5 -9
@@ -859,22 +859,18 @@ static void nf_tables_table_destroy(struct nft_ctx *ctx)kfree (ctx->table); } -int nft_register_chain_type (const struct nft_chain_type *ctype) +void nft_register_chain_type (const struct nft_chain_type *ctype) { -int err =0 ; -if (WARN_ON (ctype->family >=NFPROTO_NUMPROTO )) -return -EINVAL ; +return ;nfnl_lock (NFNL_SUBSYS_NFTABLES ); -if (chain_type[ctype->family][ctype->type] !=NULL ) { - err = -EBUSY ; - goto out; +if (WARN_ON (chain_type[ctype->family][ctype->type] !=NULL )) { +nfnl_unlock (NFNL_SUBSYS_NFTABLES ); +return ; } chain_type[ctype->family][ctype->type] = ctype; -out:nfnl_unlock (NFNL_SUBSYS_NFTABLES ); -return err; }EXPORT_SYMBOL_GPL (nft_register_chain_type);
net/netfilter/nf_tables_inet.c +3 -1
@@ -59,7 +59,9 @@ static const struct nft_chain_type filter_inet = {static int __init nf_tables_inet_init (void ) { -return nft_register_chain_type (&filter_inet); +nft_register_chain_type (&filter_inet); + +return 0 ; } static void __exit nf_tables_inet_exit(void)
net/netfilter/nf_tables_netdev.c +1 -3
@@ -112,9 +112,7 @@ static int __init nf_tables_netdev_init(void) {int ret; - ret =nft_register_chain_type (&nft_filter_chain_netdev); -if (ret) -return ret; +nft_register_chain_type (&nft_filter_chain_netdev); ret =register_netdevice_notifier (&nf_tables_netdev_notifier);if (ret)
Signature · 1 line
2.11.0