netfilter: netfilter update for 2.6.37
Subsystems (9)
cover netfilter: netfilter update for 2.6.37
Hi Dave,
the following patches contain my netfilter update for 2.6.37, containing:
- xtables and ebtables cleanups from Jan
- NAT cleanups and optimizations from Changli
- a fix for a race condition in netfilter hash random initialization and caching of the original hash value from the lookup for hash insertion from Changli
- smaller ctnetlink fixes and support for user-space connection tracking helpers from Pablo
- ctnetlink expectation deletion event notifications from Pablo
- a patch from Eric to make the LOG targets build the entire log string in a buffer before printing it to save some overhead and avoid having the log message intermixed with unrelated printks
- a TPROXY fix for dealing with TIME_WAIT sockets from Balazs
- a TPROXY fix for locking problems in __inet_inherit_port() from Balazs
- IPv6 TPROXY support from Balazs and Krisztian
- IPVS persistent engine core and SIP persistent engine from Simon
- IPVS IPv6 tunnel mode from Hans Schillstrom
- various IPVS fixes and optimizations from Julian
- IPVS support for local servers and clients from Julian
Please pull from:
git://git.kernel.org:/pub/scm/linux/kernel/git/kaber/nf-next-2.6.git master
Thanks!
PATCH 1/72 netfilter: nf_nat: add nf_nat_csum()
From: Changli Gao <[email protected]>
Add a static function nf_nat_csum() to replace the duplicate code in nf_nat_mangle_udp_packet() and __nf_nat_mangle_tcp_packet().
--- net/ipv4/netfilter/nf_nat_helper.c | 76 +++++++++++++++--------------------- 1 files changed, 31 insertions(+), 45 deletions(-)
net/ipv4/netfilter/nf_nat_helper.c +31 -45
@@ -153,6 +153,35 @@ void nf_nat_set_seq_adjust(struct nf_conn *ct, enum ip_conntrack_info ctinfo, }EXPORT_SYMBOL_GPL (nf_nat_set_seq_adjust); +static void nf_nat_csum (struct sk_buff *skb,struct iphdr *iph,void *data, +int datalen,__sum16 *check,int oldlen) +{ +struct rtable *rt =skb_rtable (skb); + +if (skb->ip_summed !=CHECKSUM_PARTIAL ) { +if (!(rt->rt_flags &RTCF_LOCAL ) && + skb->dev->features &NETIF_F_V4_CSUM ) { + skb->ip_summed =CHECKSUM_PARTIAL ; + skb->csum_start =skb_headroom (skb) + +skb_network_offset (skb) + + iph->ihl *4 ; + skb->csum_offset = (void *)check - data; + *check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, + datalen, iph->protocol,0 ); + }else { + *check =0 ; + *check =csum_tcpudp_magic (iph->saddr, iph->daddr, + datalen, iph->protocol, +csum_partial (data, datalen, +0 )); +if (iph->protocol ==IPPROTO_UDP && !*check) + *check =CSUM_MANGLED_0 ; + } + }else +inet_proto_csum_replace2 (check, skb, +htons (oldlen),htons (datalen),1 ); +} +/* Generic function for mangling variable-length address changes inside * NATed TCP connections (like the PORT XXX,XXX,XXX,XXX,XXX,XXX * command in FTP).
@@ -169,7 +198,6 @@ int __nf_nat_mangle_tcp_packet(struct sk_buff *skb,const char *rep_buffer, unsigned int rep_len, bool adjust) { - struct rtable *rt = skb_rtable(skb); struct iphdr *iph;struct tcphdr *tcph;int oldlen, datalen;
@@ -192,26 +220,7 @@ int __nf_nat_mangle_tcp_packet(struct sk_buff *skb, match_offset, match_len, rep_buffer, rep_len); datalen = skb->len - iph->ihl*4 ; -if (skb->ip_summed !=CHECKSUM_PARTIAL ) { -if (!(rt->rt_flags &RTCF_LOCAL ) && - skb->dev->features &NETIF_F_V4_CSUM ) { - skb->ip_summed =CHECKSUM_PARTIAL ; - skb->csum_start =skb_headroom (skb) + -skb_network_offset (skb) + - iph->ihl *4 ; - skb->csum_offset = offsetof(struct tcphdr , check); - tcph->check = ~tcp_v4_check (datalen, - iph->saddr, iph->daddr,0 ); - }else { - tcph->check =0 ; - tcph->check =tcp_v4_check (datalen, - iph->saddr, iph->daddr, -csum_partial (tcph, - datalen,0 )); - } - }else -inet_proto_csum_replace2 (&tcph->check, skb, -htons (oldlen),htons (datalen),1 ); +nf_nat_csum (skb, iph, tcph, datalen, &tcph->check, oldlen);if (adjust && rep_len != match_len) nf_nat_set_seq_adjust(ct, ctinfo, tcph->seq,
@@ -240,7 +249,6 @@ nf_nat_mangle_udp_packet(struct sk_buff *skb,const char *rep_buffer, unsigned int rep_len) { - struct rtable *rt = skb_rtable(skb); struct iphdr *iph;struct udphdr *udph;int datalen, oldlen;
@@ -274,29 +282,7 @@ nf_nat_mangle_udp_packet(struct sk_buff *skb,if (!udph->check && skb->ip_summed !=CHECKSUM_PARTIAL )return 1 ; -if (skb->ip_summed !=CHECKSUM_PARTIAL ) { -if (!(rt->rt_flags &RTCF_LOCAL ) && - skb->dev->features &NETIF_F_V4_CSUM ) { - skb->ip_summed =CHECKSUM_PARTIAL ; - skb->csum_start =skb_headroom (skb) + -skb_network_offset (skb) + - iph->ihl *4 ; - skb->csum_offset = offsetof(struct udphdr , check); - udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, - datalen,IPPROTO_UDP , -0 ); - }else { - udph->check =0 ; - udph->check =csum_tcpudp_magic (iph->saddr, iph->daddr, - datalen,IPPROTO_UDP , -csum_partial (udph, - datalen,0 )); -if (!udph->check) - udph->check =CSUM_MANGLED_0 ; - } - }else -inet_proto_csum_replace2 (&udph->check, skb, -htons (oldlen),htons (datalen),1 ); +nf_nat_csum (skb, iph, udph, datalen, &udph->check, oldlen);return 1 ; }
Signature · 1 line
1.7.1
PATCH 2/72 netfilter: use NFPROTO_IPV4 instead of AF_INET
In reply to [email protected]From: Changli Gao <[email protected]>
The field family of xt_target should be NFPROTO_IPV4, though NFPROTO_IPV4 and AF_INET are the same.
--- net/netfilter/xt_TPROXY.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/xt_TPROXY.c +1 -1
@@ -76,7 +76,7 @@ static int tproxy_tg_check(const struct xt_tgchk_param *par)static struct xt_target tproxy_tg_reg__read_mostly = { .name ="TPROXY" , - .family =AF_INET , + .family =NFPROTO_IPV4 , .table ="mangle" , .target = tproxy_tg, .targetsize =sizeof (struct xt_tproxy_target_info ),
Signature · 1 line
1.7.1
PATCH 3/72 netfilter: nf_nat_core: don't check if the tuple is used if there is no other choice
In reply to [email protected]From: Changli Gao <[email protected]>
Eliminate nf_nat_used_tuple() to save some CPU cycles when there is no other choice.
--- net/ipv4/netfilter/nf_nat_core.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-)
net/ipv4/netfilter/nf_nat_core.c +11 -5
@@ -262,11 +262,17 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple, proto =__nf_nat_proto_find (orig_tuple->dst.protonum);/* Only bother mapping if it's not already in range and unique */ -if (!(range->flags &IP_NAT_RANGE_PROTO_RANDOM ) && - (!(range->flags &IP_NAT_RANGE_PROTO_SPECIFIED ) || - proto->in_range (tuple, maniptype, &range->min, &range->max)) && - !nf_nat_used_tuple (tuple, ct)) - goto out; +if (!(range->flags &IP_NAT_RANGE_PROTO_RANDOM )) { +if (range->flags &IP_NAT_RANGE_PROTO_SPECIFIED ) { +if (proto->in_range (tuple, maniptype, &range->min, + &range->max) && + (range->min.all == range->max.all || + !nf_nat_used_tuple (tuple, ct))) + goto out; + }else if (!nf_nat_used_tuple (tuple, ct)) { + goto out; + } + }/* Last change: get protocol to try to obtain unique tuple. */ proto->unique_tuple (tuple, range, maniptype, ct);
Signature · 1 line
1.7.1
PATCH 4/72 netfilter: nf_nat: no IP_NAT_RANGE_MAP_IPS flags when alloc_null_binding()
In reply to [email protected]From: Changli Gao <[email protected]>
When alloc_null_binding(), no IP_NAT_RNAGE_MAP_IPS in flags means no IP address translation is needed. It isn't necessary to specify the address explicitly.
--- net/ipv4/netfilter/nf_nat_rule.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-)
net/ipv4/netfilter/nf_nat_rule.c +8 -9
@@ -106,16 +106,15 @@ alloc_null_binding(struct nf_conn *ct, unsigned int hooknum) {/* Force range to this IP; let proto decide mapping for per-proto parts (hence not IP_NAT_RANGE_PROTO_SPECIFIED). -Use reply in case it's already been mangled (eg local packet). */ -__be32 ip - = (HOOK2MANIP (hooknum) ==IP_NAT_MANIP_SRC - ? ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.u3.ip - : ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.u3.ip); -struct nf_nat_range range - = {IP_NAT_RANGE_MAP_IPS , ip, ip, {0 }, {0 } }; - -pr_debug ("Allocating NULL binding for %p (%pI4)\n" , ct, &ip); +struct nf_nat_range range; + + range.flags =0 ; +pr_debug ("Allocating NULL binding for %p (%pI4)\n" , ct, +HOOK2MANIP (hooknum) ==IP_NAT_MANIP_SRC ? + &ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.u3.ip : + &ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.u3.ip); +return nf_nat_setup_info (ct, &range,HOOK2MANIP (hooknum)); }
Signature · 1 line
1.7.1
PATCH 5/72 netfilter: nf_conntrack: fix the hash random initializing race
In reply to [email protected]From: Changli Gao <[email protected]>
nf_conntrack_alloc() isn't called with nf_conntrack_lock locked, so hash random initializing code maybe executed more than once on different CPUs.
--- net/netfilter/nf_conntrack_core.c | 19 +++++++++++++------ 1 files changed, 13 insertions(+), 6 deletions(-)
net/netfilter/nf_conntrack_core.c +13 -6
@@ -65,8 +65,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_max); DEFINE_PER_CPU(struct nf_conn, nf_conntrack_untracked);EXPORT_PER_CPU_SYMBOL (nf_conntrack_untracked); -static int nf_conntrack_hash_rnd_initted; -static unsigned int nf_conntrack_hash_rnd; +static unsigned int nf_conntrack_hash_rnd__read_mostly ;static u_int32_t __hash_conntrack (const struct nf_conntrack_tuple *tuple,u16 zone,unsigned int size,unsigned int rnd)
@@ -574,10 +573,18 @@ struct nf_conn *nf_conntrack_alloc(struct net *net, u16 zone, {struct nf_conn *ct; -if (unlikely (!nf_conntrack_hash_rnd_initted)) { -get_random_bytes (&nf_conntrack_hash_rnd, -sizeof (nf_conntrack_hash_rnd)); - nf_conntrack_hash_rnd_initted =1 ; +if (unlikely (!nf_conntrack_hash_rnd)) { +unsigned int rand; + +/* +* Why not initialize nf_conntrack_rnd in a "init()" function ? +* Because there isn't enough entropy when system initializing, +* and we initialize it as late as possible. +*/ +do { +get_random_bytes (&rand,sizeof (rand)); + }while (!rand); +cmpxchg (&nf_conntrack_hash_rnd,0 , rand); }/* We don't want any race condition at early drop stage */
Signature · 1 line
1.7.1
PATCH 6/72 ipvs: extend connection flags to 32 bits
In reply to [email protected]From: Julian Anastasov <[email protected]>
- the sync protocol supports 16 bits only, so bits 0..15 should be used only for flags that should go to backup server, bits 16 and above should be allocated for flags not sent to backup.
- use IP_VS_CONN_F_DEST_MASK as mask of connection flags in destination that can be changed by user space
- allow IP_VS_CONN_F_ONE_PACKET to be set in destination
--- include/linux/ip_vs.h | 8 ++++++++ include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_conn.c | 16 ++++++++++------ net/netfilter/ipvs/ip_vs_core.c | 11 ++++++----- net/netfilter/ipvs/ip_vs_ctl.c | 5 +++-- 5 files changed, 28 insertions(+), 14 deletions(-)
include/linux/ip_vs.h +8 -0
@@ -70,6 +70,7 @@/* * IPVS Connection Flags +* Only flags 0..15 are sent to backup server */ #define IP_VS_CONN_F_FWD_MASK 0x0007/* mask for the fwd methods */ #define IP_VS_CONN_F_MASQ 0x0000/* masquerading/NAT */
@@ -88,6 +89,13 @@#define IP_VS_CONN_F_TEMPLATE 0x1000/* template, not connection */ #define IP_VS_CONN_F_ONE_PACKET 0x2000/* forward only one packet */ +/* Flags that are not sent to backup server start from bit 16 */ + +/* Connection flags from destination that can be changed by user space */ +#define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \ + IP_VS_CONN_F_ONE_PACKET | \ + 0) +#define IP_VS_SCHEDNAME_MAXLEN 16#define IP_VS_IFNAME_MAXLEN 16
include/net/ip_vs.h +1 -1
@@ -366,6 +366,7 @@ struct ip_vs_conn {union nf_inet_addr caddr;/* client address */ union nf_inet_addr vaddr;/* virtual address */ union nf_inet_addr daddr;/* destination address */ +volatile __u32 flags;/* status flags */ __be16 cport;__be16 vport;__be16 dport;
@@ -378,7 +379,6 @@ struct ip_vs_conn {/* Flags and state transition */ spinlock_t lock;/* lock for state transition */ -volatile __u16 flags;/* status flags */ volatile __u16 state;/* state info */ volatile __u16 old_state;/* old state, to be used for * state transition triggerd
net/netfilter/ipvs/ip_vs_conn.c +10 -6
@@ -505,6 +505,8 @@ static inline int ip_vs_dest_totalconns(struct ip_vs_dest *dest)static inline void ip_vs_bind_dest (struct ip_vs_conn *cp,struct ip_vs_dest *dest) { +unsigned int conn_flags; +/* if dest is NULL, then return directly */ if (!dest)return ;
@@ -512,16 +514,18 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)/* Increase the refcnt counter of the dest */ atomic_inc (&dest->refcnt); + conn_flags =atomic_read (&dest->conn_flags); +if (cp->protocol !=IPPROTO_UDP ) + conn_flags &= ~IP_VS_CONN_F_ONE_PACKET ;/* Bind with the destination and its corresponding transmitter */ -if ((cp->flags &IP_VS_CONN_F_SYNC ) && - (!(cp->flags &IP_VS_CONN_F_TEMPLATE ))) +if (cp->flags &IP_VS_CONN_F_SYNC ) {/* if the connection is not template and is created * by sync, preserve the activity flag. */ - cp->flags |=atomic_read (&dest->conn_flags) & - (~IP_VS_CONN_F_INACTIVE ); -else - cp->flags |=atomic_read (&dest->conn_flags); +if (!(cp->flags &IP_VS_CONN_F_TEMPLATE )) + conn_flags &= ~IP_VS_CONN_F_INACTIVE ; + } + cp->flags |= conn_flags; cp->dest = dest; IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
net/netfilter/ipvs/ip_vs_core.c +6 -5
@@ -194,7 +194,7 @@ ip_vs_sched_persist(struct ip_vs_service *svc,struct ip_vs_dest *dest;struct ip_vs_conn *ct;__be16 dport;/* destination port to forward */ -__be16 flags; +unsigned int flags;union nf_inet_addr snet;/* source network of the client, after masking */
@@ -382,7 +382,8 @@ ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)struct ip_vs_conn *cp =NULL ;struct ip_vs_iphdr iph;struct ip_vs_dest *dest; -__be16 _ports[2 ], *pptr, flags; +__be16 _ports[2 ], *pptr; +unsigned int flags;ip_vs_fill_iphdr (svc->af,skb_network_header (skb), &iph); pptr =skb_header_pointer (skb, iph.len,sizeof (_ports), _ports);
@@ -473,9 +474,9 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,if (sysctl_ip_vs_cache_bypass && svc->fwmark && unicast) {int ret, cs;struct ip_vs_conn *cp; -__u16 flags = (svc->flags &IP_VS_SVC_F_ONEPACKET && - iph.protocol ==IPPROTO_UDP )? -IP_VS_CONN_F_ONE_PACKET :0 ; +unsigned int flags = (svc->flags &IP_VS_SVC_F_ONEPACKET && + iph.protocol ==IPPROTO_UDP )? +IP_VS_CONN_F_ONE_PACKET :0 ;union nf_inet_addr daddr = { .all = {0 ,0 ,0 ,0 } };ip_vs_service_put (svc);
net/netfilter/ipvs/ip_vs_ctl.c +3 -2
@@ -765,7 +765,8 @@ __ip_vs_update_dest(struct ip_vs_service *svc,/* set the weight and the flags */ atomic_set (&dest->weight, udest->weight); - conn_flags = udest->conn_flags |IP_VS_CONN_F_INACTIVE ; + conn_flags = udest->conn_flags &IP_VS_CONN_F_DEST_MASK ; + conn_flags |=IP_VS_CONN_F_INACTIVE ;/* check if local node and update the flags */ #ifdef CONFIG_IP_VS_IPV6
@@ -782,7 +783,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, }/* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */ -if ((conn_flags &IP_VS_CONN_F_FWD_MASK ) !=0 ) { +if ((conn_flags &IP_VS_CONN_F_FWD_MASK ) !=IP_VS_CONN_F_MASQ ) { conn_flags |=IP_VS_CONN_F_NOOUTPUT ; }else {/*
Signature · 1 line
1.7.1
PATCH 7/72 ipvs: netfilter connection tracking changes
In reply to [email protected]From: Julian Anastasov <[email protected]>
Add more code to IPVS to work with Netfilter connection
tracking and fix some problems.
- Allow IPVS to be compiled without connection tracking as in 2.6.35 and before. This can avoid keeping conntracks for all IPVS connections because this costs memory. ip_vs_ftp still depends on connection tracking and NAT as implemented for 2.6.36.
- Add sysctl var "conntrack" to enable connection tracking for all IPVS connections. For loaded IPVS directors it needs tuning of nf_conntrack_max limit.
- Add IP_VS_CONN_F_NFCT connection flag to request the connection to use connection tracking. This allows user space to provide this flag, for example, in dest->conn_flags. This can be useful to request connection tracking per real server instead of forcing it for all connections with the "conntrack" sysctl. This flag is set currently only by ip_vs_ftp and of course by "conntrack" sysctl.
- Add ip_vs_nfct.c file to hold all connection tracking code, by this way main code should not depend of netfilter conntrack support.
- Return back the ip_vs_post_routing handler as in 2.6.35 and use skb->ipvs_property=1 to allow IPVS to work without connection tracking
Connection tracking:
- most of the code is already in 2.6.36-rc
- alter conntrack reply tuple for LVS-NAT connections when first packet from client is forwarded and conntrack state is NEW or RELATED. Additionally, alter reply for RELATED connections from real server, again for packet in original direction.
- add IP_VS_XMIT_TUNNEL to confirm conntrack (without altering reply) for LVS-TUN early because we want to call nf_reset. It is needed because we add IPIP header and the original conntrack should be preserved, not destroyed. The transmitted IPIP packets can reuse same conntrack, so we do not set skb->ipvs_property.
- try to destroy conntrack when the IPVS connection is destroyed. It is not fatal if conntrack disappears before that, it depends on the used timers.
Fix problems from long time:
- add skb->ip_summed = CHECKSUM_NONE for the LVS-TUN transmitters
--- include/linux/ip_vs.h | 2 + include/net/ip_vs.h | 44 ++++++- net/netfilter/ipvs/Kconfig | 13 ++- net/netfilter/ipvs/Makefile | 5 +- net/netfilter/ipvs/ip_vs_conn.c | 13 ++ net/netfilter/ipvs/ip_vs_core.c | 46 ++++++- net/netfilter/ipvs/ip_vs_ctl.c | 12 ++ net/netfilter/ipvs/ip_vs_ftp.c | 146 +------------------- net/netfilter/ipvs/ip_vs_nfct.c | 292 +++++++++++++++++++++++++++++++++++++++ net/netfilter/ipvs/ip_vs_xmit.c | 98 +++++++------- 10 files changed, 475 insertions(+), 196 deletions(-) create mode 100644 net/netfilter/ipvs/ip_vs_nfct.c
include/linux/ip_vs.h +2 -0
@@ -90,10 +90,12 @@#define IP_VS_CONN_F_ONE_PACKET 0x2000/* forward only one packet */ /* Flags that are not sent to backup server start from bit 16 */ +#define IP_VS_CONN_F_NFCT (1 << 16)/* use netfilter conntrack */ /* Connection flags from destination that can be changed by user space */ #define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \ IP_VS_CONN_F_ONE_PACKET | \ + IP_VS_CONN_F_NFCT | \ 0)#define IP_VS_SCHEDNAME_MAXLEN 16
include/net/ip_vs.h +43 -1
64 lines not on this page · raw message
net/netfilter/ipvs/Kconfig +11 -2
@@ -3,7 +3,7 @@ # menuconfig IP_VS tristate "IP virtual server support" - depends on NET && INET && NETFILTER && NF_CONNTRACK + depends on NET && INET && NETFILTER ---help--- IP Virtual Server support will let you build a high-performance virtual server based on cluster of two or more real servers. This
@@ -235,7 +235,8 @@ comment 'IPVS application helper' config IP_VS_FTP tristate "FTP protocol helper" - depends on IP_VS_PROTO_TCP && NF_NAT + depends on IP_VS_PROTO_TCP && NF_CONNTRACK && NF_NAT + select IP_VS_NFCT ---help--- FTP is a protocol that transfers IP address and/or port number in the payload. In the virtual server via Network Address Translation,
@@ -247,4 +248,12 @@ config IP_VS_FTP If you want to compile it in kernel, say Y. To compile it as a module, choose M here. If unsure, say N. +config IP_VS_NFCT + bool "Netfilter connection tracking" + depends on NF_CONNTRACK + ---help--- + The Netfilter connection tracking support allows the IPVS + connection state to be exported to the Netfilter framework + for filtering purposes. + endif # IP_VS
net/netfilter/ipvs/Makefile +4 -1
@@ -9,10 +9,13 @@ ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_UDP) += ip_vs_proto_udp.o ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_AH_ESP) += ip_vs_proto_ah_esp.o ip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_SCTP) += ip_vs_proto_sctp.o +ip_vs-extra_objs-y := +ip_vs-extra_objs-$(CONFIG_IP_VS_NFCT) += ip_vs_nfct.o + ip_vs-objs := ip_vs_conn.o ip_vs_core.o ip_vs_ctl.o ip_vs_sched.o \ ip_vs_xmit.o ip_vs_app.o ip_vs_sync.o \ ip_vs_est.o ip_vs_proto.o \ - $(ip_vs_proto-objs-y) + $(ip_vs_proto-objs-y) $(ip_vs-extra_objs-y) # IPVS core
net/netfilter/ipvs/ip_vs_conn.c +13 -0
@@ -721,6 +721,9 @@ static void ip_vs_conn_expire(unsigned long data)if (cp->control)ip_vs_control_del (cp); +if (cp->flags &IP_VS_CONN_F_NFCT ) +ip_vs_conn_drop_conntrack (cp); +if (unlikely (cp->app !=NULL ))ip_vs_unbind_app (cp);ip_vs_unbind_dest (cp);
@@ -816,6 +819,16 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,if (unlikely (pp &&atomic_read (&pp->appcnt)))ip_vs_bind_app (cp, pp); +/* +* Allow conntrack to be preserved. By default, conntrack +* is created and destroyed for every packet. +* Sometimes keeping conntrack can be useful for +* IP_VS_CONN_F_ONE_PACKET too. +*/ + +if (ip_vs_conntrack_enabled ()) + cp->flags |=IP_VS_CONN_F_NFCT ; +/* Hash it in the ip_vs_conn_tab finally */ ip_vs_conn_hash (cp);
net/netfilter/ipvs/ip_vs_core.c +42 -4
84 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ctl.c +12 -0
@@ -88,6 +88,9 @@ int sysctl_ip_vs_expire_nodest_conn = 0;int sysctl_ip_vs_expire_quiescent_template =0 ;int sysctl_ip_vs_sync_threshold[2 ] = {3 ,50 };int sysctl_ip_vs_nat_icmp_send =0 ; +#ifdef CONFIG_IP_VS_NFCT +int sysctl_ip_vs_conntrack; +#endif #ifdef CONFIG_IP_VS_DEBUG
@@ -1580,6 +1583,15 @@ static struct ctl_table vs_vars[] = { .mode = 0644, .proc_handler = proc_do_defense_mode, }, +#ifdef CONFIG_IP_VS_NFCT + { + .procname = "conntrack", + .data = &sysctl_ip_vs_conntrack, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, +#endif { .procname = "secure_tcp", .data = &sysctl_ip_vs_secure_tcp,
net/netfilter/ipvs/ip_vs_ftp.c +7 -139
188 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_nfct.c new file +292 -0
292 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_xmit.c +49 -49
210 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 8/72 ipvs: make rerouting optional with snat_reroute
In reply to [email protected]From: Julian Anastasov <[email protected]>
Add new sysctl flag "snat_reroute". Recent kernels useip_route_me_harder() to route LVS-NAT responses properly by VIP when there are multiple paths to client. But setups that do not have alternative default routes can skip this routing lookup by using snat_reroute=0.
--- include/net/ip_vs.h | 1 + net/netfilter/ipvs/ip_vs_core.c | 37 +++++++++++++++++++++++++++++-------- net/netfilter/ipvs/ip_vs_ctl.c | 8 ++++++++ 3 files changed, 38 insertions(+), 8 deletions(-)
include/net/ip_vs.h +1 -0
@@ -801,6 +801,7 @@ extern int sysctl_ip_vs_expire_quiescent_template;extern int sysctl_ip_vs_sync_threshold[2 ];extern int sysctl_ip_vs_nat_icmp_send;extern int sysctl_ip_vs_conntrack; +extern int sysctl_ip_vs_snat_reroute;extern struct ip_vs_stats ip_vs_stats;extern const struct ctl_path net_vs_ctl_path[];
net/netfilter/ipvs/ip_vs_core.c +29 -8
@@ -929,20 +929,31 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,ip_send_check (ip_hdr (skb)); } +/* +* nf_iterate does not expect change in the skb->dst->dev. +* It looks like it is not fatal to enable this code for hooks +* where our handlers are at the end of the chain list and +* when all next handlers use skb->dst->dev and not outdev. +* It will definitely route properly the inout NAT traffic +* when multiple paths are used. +*/ +/* For policy routing, packets originating from this * machine itself may be routed differently to packets * passing through. We want this packet to be routed as * if it came from this machine itself. So re-compute * the routing information. */ +if (sysctl_ip_vs_snat_reroute) {#ifdef CONFIG_IP_VS_IPV6 -if (af ==AF_INET6 ) { -if (ip6_route_me_harder (skb) !=0 ) - goto drop; - } else +if (af ==AF_INET6 ) { +if (ip6_route_me_harder (skb) !=0 ) + goto drop; + } else#endif -if (ip_route_me_harder (skb,RTN_LOCAL ) !=0 ) - goto drop; +if (ip_route_me_harder (skb,RTN_LOCAL ) !=0 ) + goto drop; + }IP_VS_DBG_PKT (10 , pp, skb,0 ,"After SNAT" );
@@ -991,8 +1002,13 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,if (unlikely (iph.protocol ==IPPROTO_ICMPV6 )) {int related, verdict =ip_vs_out_icmp_v6 (skb, &related); -if (related) +if (related) { +if (sysctl_ip_vs_snat_reroute && +NF_ACCEPT == verdict && +ip6_route_me_harder (skb)) + verdict =NF_DROP ;return verdict; + }ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); } }else
@@ -1000,8 +1016,13 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,if (unlikely (iph.protocol ==IPPROTO_ICMP )) {int related, verdict =ip_vs_out_icmp (skb, &related); -if (related) +if (related) { +if (sysctl_ip_vs_snat_reroute && +NF_ACCEPT == verdict && +ip_route_me_harder (skb,RTN_LOCAL )) + verdict =NF_DROP ;return verdict; + }ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); }
net/netfilter/ipvs/ip_vs_ctl.c +8 -0
@@ -91,6 +91,7 @@ int sysctl_ip_vs_nat_icmp_send = 0;#ifdef CONFIG_IP_VS_NFCT int sysctl_ip_vs_conntrack;#endif +int sysctl_ip_vs_snat_reroute =1 ;#ifdef CONFIG_IP_VS_DEBUG
@@ -1599,6 +1600,13 @@ static struct ctl_table vs_vars[] = { .mode = 0644, .proc_handler = proc_do_defense_mode, }, + { + .procname = "snat_reroute", + .data = &sysctl_ip_vs_snat_reroute, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, #if 0 { .procname = "timeout_established",
Signature · 1 line
1.7.1
PATCH 9/72 netfilter: save the hash of the tuple in the original direction for latter use
In reply to [email protected]From: Changli Gao <[email protected]>
Since we don't change the tuple in the original direction, we can save it in ct->tuplehash[IP_CT_DIR_REPLY].hnode.pprev for __nf_conntrack_confirm() use.
__hash_conntrack() is split into two steps: hash_conntrack_raw() is used to get the raw hash, and __hash_bucket() is used to get the bucket id.
In SYN-flood case, early_drop() doesn't need to recompute the hash again.
--- net/netfilter/nf_conntrack_core.c | 112 +++++++++++++++++++++++++----------- 1 files changed, 78 insertions(+), 34 deletions(-)
net/netfilter/nf_conntrack_core.c +78 -34
@@ -67,29 +67,40 @@ EXPORT_PER_CPU_SYMBOL(nf_conntrack_untracked);static unsigned int nf_conntrack_hash_rnd__read_mostly ; -static u_int32_t __hash_conntrack (const struct nf_conntrack_tuple *tuple, -u16 zone,unsigned int size,unsigned int rnd) +static u32 hash_conntrack_raw (const struct nf_conntrack_tuple *tuple,u16 zone) {unsigned int n; -u_int32_t h;/* The direction must be ignored, so we hash everything up to the * destination ports (which is a multiple of 4) and treat the last * three bytes manually. */ n = (sizeof (tuple->src) +sizeof (tuple->dst.u3)) /sizeof (u32); - h =jhash2 ((u32 *)tuple, n, - zone ^ rnd ^ (((__force __u16 )tuple->dst.u.all <<16 ) | - tuple->dst.protonum)); +return jhash2 ((u32 *)tuple, n, zone ^ nf_conntrack_hash_rnd ^ + (((__force __u16 )tuple->dst.u.all <<16 ) | + tuple->dst.protonum)); +} + +static u32 __hash_bucket (u32 hash,unsigned int size) +{ +return ((u64 )hash * size) >>32 ; +} + +static u32 hash_bucket (u32 hash,const struct net *net) +{ +return __hash_bucket (hash, net->ct.htable_size); +} -return ((u64 )h * size) >>32 ; +static u_int32_t __hash_conntrack (const struct nf_conntrack_tuple *tuple, +u16 zone,unsigned int size) +{ +return __hash_bucket (hash_conntrack_raw (tuple, zone), size); }static inline u_int32_t hash_conntrack (const struct net *net,u16 zone,const struct nf_conntrack_tuple *tuple) { -return __hash_conntrack (tuple, zone, net->ct.htable_size, - nf_conntrack_hash_rnd); +return __hash_conntrack (tuple, zone, net->ct.htable_size); }bool
@@ -291,20 +302,20 @@ static void death_by_timeout(unsigned long ul_conntrack)* OR * - Caller must lock nf_conntrack_lock before calling this function */ -struct nf_conntrack_tuple_hash * -__nf_conntrack_find (struct net *net,u16 zone, -const struct nf_conntrack_tuple *tuple) +static struct nf_conntrack_tuple_hash * +____nf_conntrack_find (struct net *net,u16 zone, +const struct nf_conntrack_tuple *tuple,u32 hash) {struct nf_conntrack_tuple_hash *h;struct hlist_nulls_node *n; -unsigned int hash =hash_conntrack (net, zone, tuple); +unsigned int bucket =hash_bucket (hash, net);/* Disable BHs the entire time since we normally need to disable them * at least once for the stats anyway. */ local_bh_disable (); begin: -hlist_nulls_for_each_entry_rcu (h, n, &net->ct.hash[hash], hnnode) { +hlist_nulls_for_each_entry_rcu (h, n, &net->ct.hash[bucket], hnnode) {if (nf_ct_tuple_equal (tuple, &h->tuple) &&nf_ct_zone (nf_ct_tuplehash_to_ctrack (h)) == zone) {NF_CT_STAT_INC (net, found);
@@ -318,7 +329,7 @@ begin:* not the expected one, we must restart lookup. * We probably met an item that was moved to another chain. */ -if (get_nulls_value (n) != hash) { +if (get_nulls_value (n) != bucket) {NF_CT_STAT_INC (net, search_restart); goto begin; }
@@ -326,19 +337,27 @@ begin:return NULL ; } + +struct nf_conntrack_tuple_hash * +__nf_conntrack_find (struct net *net,u16 zone, +const struct nf_conntrack_tuple *tuple) +{ +return ____nf_conntrack_find (net, zone, tuple, +hash_conntrack_raw (tuple, zone)); +}EXPORT_SYMBOL_GPL (__nf_conntrack_find);/* Find a connection corresponding to a tuple. */ -struct nf_conntrack_tuple_hash * -nf_conntrack_find_get (struct net *net,u16 zone, -const struct nf_conntrack_tuple *tuple) +static struct nf_conntrack_tuple_hash * +__nf_conntrack_find_get (struct net *net,u16 zone, +const struct nf_conntrack_tuple *tuple,u32 hash) {struct nf_conntrack_tuple_hash *h;struct nf_conn *ct;rcu_read_lock (); begin: - h =__nf_conntrack_find (net, zone, tuple); + h =____nf_conntrack_find (net, zone, tuple, hash);if (h) { ct =nf_ct_tuplehash_to_ctrack (h); if (unlikely(nf_ct_is_dying(ct) ||
@@ -356,6 +375,14 @@ begin:return h; } + +struct nf_conntrack_tuple_hash * +nf_conntrack_find_get (struct net *net,u16 zone, +const struct nf_conntrack_tuple *tuple) +{ +return __nf_conntrack_find_get (net, zone, tuple, +hash_conntrack_raw (tuple, zone)); +}EXPORT_SYMBOL_GPL (nf_conntrack_find_get); static void __nf_conntrack_hash_insert(struct nf_conn *ct,
@@ -408,8 +435,11 @@ __nf_conntrack_confirm(struct sk_buff *skb)return NF_ACCEPT ; zone =nf_ct_zone (ct); - hash =hash_conntrack (net, zone, &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple); - repl_hash =hash_conntrack (net, zone, &ct->tuplehash[IP_CT_DIR_REPLY ].tuple); +/* reuse the hash saved before */ + hash = *(unsigned long *)&ct->tuplehash[IP_CT_DIR_REPLY ].hnnode.pprev; + hash =hash_bucket (hash, net); + repl_hash =hash_conntrack (net, zone, + &ct->tuplehash[IP_CT_DIR_REPLY ].tuple);/* We're not in hash table, and we refuse to set up related connections for unconfirmed conns. But packet copies and
@@ -566,10 +596,11 @@ static noinline int early_drop(struct net *net, unsigned int hash)return dropped; } -struct nf_conn *nf_conntrack_alloc (struct net *net,u16 zone, -const struct nf_conntrack_tuple *orig, -const struct nf_conntrack_tuple *repl, -gfp_t gfp) +static struct nf_conn * +__nf_conntrack_alloc (struct net *net,u16 zone, +const struct nf_conntrack_tuple *orig, +const struct nf_conntrack_tuple *repl, +gfp_t gfp,u32 hash) {struct nf_conn *ct;
@@ -585,6 +616,9 @@ struct nf_conn *nf_conntrack_alloc(struct net *net, u16 zone,get_random_bytes (&rand,sizeof (rand)); }while (!rand);cmpxchg (&nf_conntrack_hash_rnd,0 , rand); + +/* recompute the hash as nf_conntrack_hash_rnd is initialized */ + hash =hash_conntrack_raw (orig, zone); }/* We don't want any race condition at early drop stage */
@@ -592,8 +626,7 @@ struct nf_conn *nf_conntrack_alloc(struct net *net, u16 zone,if (nf_conntrack_max &&unlikely (atomic_read (&net->ct.count) > nf_conntrack_max)) { -unsigned int hash =hash_conntrack (net, zone, orig); -if (!early_drop (net, hash)) { +if (!early_drop (net,hash_bucket (hash, net))) {atomic_dec (&net->ct.count);if (net_ratelimit ()) printk(KERN_WARNING
@@ -623,7 +656,8 @@ struct nf_conn *nf_conntrack_alloc(struct net *net, u16 zone, ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple = *orig; ct->tuplehash[IP_CT_DIR_ORIGINAL ].hnnode.pprev =NULL ; ct->tuplehash[IP_CT_DIR_REPLY ].tuple = *repl; - ct->tuplehash[IP_CT_DIR_REPLY ].hnnode.pprev =NULL ; +/* save hash for reusing when confirming */ + *(unsigned long *)(&ct->tuplehash[IP_CT_DIR_REPLY ].hnnode.pprev) = hash;/* Don't set timer yet: wait for confirmation */ setup_timer (&ct->timeout, death_by_timeout, (unsigned long )ct);write_pnet (&ct->ct_net, net);
@@ -650,6 +684,14 @@ out_free:return ERR_PTR (-ENOMEM );#endif } + +struct nf_conn *nf_conntrack_alloc (struct net *net,u16 zone, +const struct nf_conntrack_tuple *orig, +const struct nf_conntrack_tuple *repl, +gfp_t gfp) +{ +return __nf_conntrack_alloc (net, zone, orig, repl, gfp,0 ); +}EXPORT_SYMBOL_GPL (nf_conntrack_alloc);void nf_conntrack_free (struct nf_conn *ct)
@@ -671,7 +713,7 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,struct nf_conntrack_l3proto *l3proto, struct nf_conntrack_l4proto *l4proto, struct sk_buff *skb, - unsigned int dataoff) + unsigned int dataoff, u32 hash) { struct nf_conn *ct;struct nf_conn_help *help;
@@ -685,7 +727,8 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,return NULL ; } - ct =nf_conntrack_alloc (net, zone, tuple, &repl_tuple,GFP_ATOMIC ); + ct =__nf_conntrack_alloc (net, zone, tuple, &repl_tuple,GFP_ATOMIC , + hash);if (IS_ERR (ct)) {pr_debug ("Can't allocate conntrack.\n" );return (struct nf_conntrack_tuple_hash *)ct;
@@ -762,6 +805,7 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl,struct nf_conntrack_tuple_hash *h;struct nf_conn *ct;u16 zone = tmpl ?nf_ct_zone (tmpl) :NF_CT_DEFAULT_ZONE ; +u32 hash; if (!nf_ct_get_tuple(skb, skb_network_offset(skb), dataoff, l3num, protonum, &tuple, l3proto,
@@ -771,10 +815,11 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl, }/* look for tuple match */ - h =nf_conntrack_find_get (net, zone, &tuple); + hash =hash_conntrack_raw (&tuple, zone); + h =__nf_conntrack_find_get (net, zone, &tuple, hash);if (!h) { h =init_conntrack (net, tmpl, &tuple, l3proto, l4proto, - skb, dataoff); + skb, dataoff, hash);if (!h)return NULL ;if (IS_ERR (h))
@@ -1314,8 +1359,7 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp) ct =nf_ct_tuplehash_to_ctrack (h);hlist_nulls_del_rcu (&h->hnnode); bucket =__hash_conntrack (&h->tuple,nf_ct_zone (ct), - hashsize, - nf_conntrack_hash_rnd); + hashsize);hlist_nulls_add_head_rcu (&h->hnnode, &hash[bucket]); } }
Signature · 1 line
1.7.1
PATCH 10/72 ipvs: changes related to service usecnt
In reply to [email protected]From: Julian Anastasov <[email protected]>
Change the usage of svc usecnt during command execution:
- we check if svc is registered but we do not need to hold usecnt reference while under __ip_vs_mutex, only the packet handling needs it during scheduling
- change __ip_vs_service_get to __ip_vs_service_find and __ip_vs_svc_fwm_get to __ip_vs_svc_fwm_find because now caller will increase svc->usecnt
- put common code that calls update_service in __ip_vs_update_dest
- put common code in ip_vs_unlink_service() and use it to unregister the service
- add comment that svc should not be accessed after ip_vs_del_service anymore
- all IP_VS_WAIT_WHILE calls are now unified: usecnt > 0
- Properly log the app ports
As result, some problems are fixed:
- possible use-after-free of svc in ip_vs_genl_set_cmd after ip_vs_del_service because our usecnt reference does not guarantee that svc is not freed on refcnt==0, eg. when no dests are moved to trash
- possible usecnt leak in do_ip_vs_set_ctl after ip_vs_del_service when the service is not freed now, for example, when some destionations are moved into trash and svc->refcnt remains above 0. It is harmless because svc is not in hash anymore.
--- net/netfilter/ipvs/ip_vs_app.c | 6 +- net/netfilter/ipvs/ip_vs_ctl.c | 250 ++++++++++++++++------------------------ 2 files changed, 102 insertions(+), 154 deletions(-)
net/netfilter/ipvs/ip_vs_app.c +3 -3
@@ -103,8 +103,8 @@ ip_vs_app_inc_new(struct ip_vs_app *app, __u16 proto, __u16 port) goto out;list_add (&inc->a_list, &app->incs_list); -IP_VS_DBG (9 ,"%s application %s:%u registered\n" , - pp->name, inc->name, inc->port); +IP_VS_DBG (9 ,"%s App %s:%u registered\n" , + pp->name, inc->name,ntohs (inc->port));return 0 ;
@@ -130,7 +130,7 @@ ip_vs_app_inc_release(struct ip_vs_app *inc) pp->unregister_app (inc);IP_VS_DBG (9 ,"%s App %s:%u unregistered\n" , - pp->name, inc->name, inc->port); + pp->name, inc->name,ntohs (inc->port));list_del (&inc->a_list);
net/netfilter/ipvs/ip_vs_ctl.c +99 -151
527 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 11/72 netfilter: nf_nat: better error handling of nf_ct_expect_related() in helpers
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch improves the situation in which the expectation table is full for conntrack NAT helpers. Basically, we give up if we don't find a place in the table instead of looping over nf_ct_expect_related() with a different port (we should only do this if it returns -EBUSY, for -EMFILE or -ESHUTDOWN I think that it's better to skip this).
--- net/ipv4/netfilter/nf_nat_amanda.c | 9 +++++- net/ipv4/netfilter/nf_nat_ftp.c | 9 +++++- net/ipv4/netfilter/nf_nat_h323.c | 53 +++++++++++++++++++++++++++++++----- net/ipv4/netfilter/nf_nat_irc.c | 9 +++++- net/ipv4/netfilter/nf_nat_sip.c | 27 +++++++++++++++--- 5 files changed, 93 insertions(+), 14 deletions(-)
net/ipv4/netfilter/nf_nat_amanda.c +8 -1
@@ -44,9 +44,16 @@ static unsigned int help(struct sk_buff *skb,/* Try to get same port: if not, try to change it. */ for (port =ntohs (exp->saved_proto.tcp.port); port !=0 ; port++) { +int ret; + exp->tuple.dst.u.tcp.port =htons (port); -if (nf_ct_expect_related (exp) ==0 ) + ret =nf_ct_expect_related (exp); +if (ret ==0 ) +break ; +else if (ret != -EBUSY ) { + port =0 ;break ; + } }if (port ==0 )
net/ipv4/netfilter/nf_nat_ftp.c +8 -1
@@ -79,9 +79,16 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb,/* Try to get same port: if not, try to change it. */ for (port =ntohs (exp->saved_proto.tcp.port); port !=0 ; port++) { +int ret; + exp->tuple.dst.u.tcp.port =htons (port); -if (nf_ct_expect_related (exp) ==0 ) + ret =nf_ct_expect_related (exp); +if (ret ==0 ) +break ; +else if (ret != -EBUSY ) { + port =0 ;break ; + } }if (port ==0 )
net/ipv4/netfilter/nf_nat_h323.c +46 -7
95 lines not on this page · raw message
net/ipv4/netfilter/nf_nat_irc.c +8 -1
@@ -45,9 +45,16 @@ static unsigned int help(struct sk_buff *skb,/* Try to get same port: if not, try to change it. */ for (port =ntohs (exp->saved_proto.tcp.port); port !=0 ; port++) { +int ret; + exp->tuple.dst.u.tcp.port =htons (port); -if (nf_ct_expect_related (exp) ==0 ) + ret =nf_ct_expect_related (exp); +if (ret ==0 ) +break ; +else if (ret != -EBUSY ) { + port =0 ;break ; + } }if (port ==0 )
net/ipv4/netfilter/nf_nat_sip.c +23 -4
@@ -307,9 +307,16 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff, exp->expectfn = ip_nat_sip_expected;for (; port !=0 ; port++) { +int ret; + exp->tuple.dst.u.udp.port =htons (port); -if (nf_ct_expect_related (exp) ==0 ) + ret =nf_ct_expect_related (exp); +if (ret ==0 ) +break ; +else if (ret != -EBUSY ) { + port =0 ;break ; + } }if (port ==0 )
@@ -480,13 +487,25 @@ static unsigned int ip_nat_sdp_media(struct sk_buff *skb, unsigned int dataoff,/* Try to get same pair of ports: if not, try to change them. */ for (port =ntohs (rtp_exp->tuple.dst.u.udp.port); port !=0 ; port +=2 ) { +int ret; + rtp_exp->tuple.dst.u.udp.port =htons (port); -if (nf_ct_expect_related (rtp_exp) !=0 ) + ret =nf_ct_expect_related (rtp_exp); +if (ret == -EBUSY )continue ; +else if (ret <0 ) { + port =0 ; +break ; + } rtcp_exp->tuple.dst.u.udp.port =htons (port +1 ); -if (nf_ct_expect_related (rtcp_exp) ==0 ) + ret =nf_ct_expect_related (rtcp_exp); +if (ret ==0 )break ; -nf_ct_unexpect_related (rtp_exp); +else if (ret != -EBUSY ) { +nf_ct_unexpect_related (rtp_exp); + port =0 ; +break ; + } }if (port ==0 )
Signature · 1 line
1.7.1
PATCH 12/72 netfilter: ctnetlink: missing validation of CTA_EXPECT_ZONE attribute
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch adds the missing validation of the CTA_EXPECT_ZONE attribute in the ctnetlink code.
--- net/netfilter/nf_conntrack_netlink.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
net/netfilter/nf_conntrack_netlink.c +1 -0
@@ -1733,6 +1733,7 @@ static const struct nla_policy exp_nla_policy[CTA_EXPECT_MAX+1] = { [CTA_EXPECT_TIMEOUT] = { .type = NLA_U32 }, [CTA_EXPECT_ID] = { .type = NLA_U32 }, [CTA_EXPECT_HELP_NAME] = { .type = NLA_NUL_STRING }, + [CTA_EXPECT_ZONE] = { .type = NLA_U16 }, }; static int
Signature · 1 line
1.7.1
PATCH 13/72 netfilter: ctnetlink: allow to specify the expectation flags
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
With this patch, you can specify the expectation flags for user-space created expectations.
--- include/linux/netfilter/nf_conntrack_common.h | 4 ++++ include/linux/netfilter/nfnetlink_conntrack.h | 1 + include/net/netfilter/nf_conntrack_expect.h | 3 --- net/netfilter/nf_conntrack_netlink.c | 8 +++++++- 4 files changed, 12 insertions(+), 4 deletions(-)
include/linux/netfilter/nf_conntrack_common.h +4 -0
@@ -100,6 +100,10 @@ enum ip_conntrack_expect_events { IPEXP_NEW, /* new expectation */ }; +/* expectation flags */ +#define NF_CT_EXPECT_PERMANENT 0x1 +#define NF_CT_EXPECT_INACTIVE 0x2 + #ifdef __KERNEL__ struct ip_conntrack_stat { unsigned int searched;
include/linux/netfilter/nfnetlink_conntrack.h +1 -0
@@ -161,6 +161,7 @@ enum ctattr_expect {CTA_EXPECT_ID ,CTA_EXPECT_HELP_NAME ,CTA_EXPECT_ZONE , +CTA_EXPECT_FLAGS , __CTA_EXPECT_MAX };#define CTA_EXPECT_MAX (__CTA_EXPECT_MAX - 1)
include/net/netfilter/nf_conntrack_expect.h +0 -3
@@ -67,9 +67,6 @@ struct nf_conntrack_expect_policy {#define NF_CT_EXPECT_CLASS_DEFAULT 0 -#define NF_CT_EXPECT_PERMANENT 0x1 -#define NF_CT_EXPECT_INACTIVE 0x2 -int nf_conntrack_expect_init (struct net *net);void nf_conntrack_expect_fini (struct net *net);
net/netfilter/nf_conntrack_netlink.c +7 -1
@@ -1577,6 +1577,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,NLA_PUT_BE32 (skb,CTA_EXPECT_TIMEOUT ,htonl (timeout));NLA_PUT_BE32 (skb,CTA_EXPECT_ID ,htonl ((unsigned long )exp)); +NLA_PUT_BE32 (skb,CTA_EXPECT_FLAGS ,htonl (exp->flags)); helper =rcu_dereference (nfct_help (master)->helper);if (helper)NLA_PUT_STRING (skb,CTA_EXPECT_HELP_NAME , helper->name);
@@ -1734,6 +1735,7 @@ static const struct nla_policy exp_nla_policy[CTA_EXPECT_MAX+1] = { [CTA_EXPECT_ID] = { .type = NLA_U32 }, [CTA_EXPECT_HELP_NAME] = { .type = NLA_NUL_STRING }, [CTA_EXPECT_ZONE] = { .type = NLA_U16 }, + [CTA_EXPECT_FLAGS] = { .type = NLA_U32 }, }; static int
@@ -1933,9 +1935,13 @@ ctnetlink_create_expect(struct net *net, u16 zone, goto out; } +if (cda[CTA_EXPECT_FLAGS ]) + exp->flags =ntohl (nla_get_be32 (cda[CTA_EXPECT_FLAGS ])); +else + exp->flags =0 ; + exp->class =0 ; exp->expectfn =NULL ; - exp->flags =0 ; exp->master = ct; exp->helper =NULL ;memcpy (&exp->tuple, &tuple,sizeof (struct nf_conntrack_tuple ));
Signature · 1 line
1.7.1
PATCH 14/72 netfilter: ctnetlink: add support for user-space expectation helpers
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch adds the basic infrastructure to support user-space expectation helpers via ctnetlink and the netfilter queuing infrastructure NFQUEUE. Basically, this patch:
* adds NF_CT_EXPECT_USERSPACE flag to identify user-space created expectations. I have also added a sanity check in __nf_ct_expect_check() to avoid that kernel-space helpers may create an expectation if the master conntrack has no helper assigned.
* adds some branches to check if the master conntrack helper exists, otherwise we skip the code that refers to kernel-space helper such as the local expectation list and the expectation policy.
* allows to set the timeout for user-space expectations with no helper assigned.
* a list of expectations created from user-space that depends on ctnetlink (if this module is removed, they are deleted).
* includes USERSPACE in the /proc output for expectations that have been created by a user-space helper.
This patch also modifies ctnetlink to skip including the helper name in the Netlink messages if no kernel-space helper is set (since no user-space expectation has not kernel-space kernel assigned).
You can access an example user-space FTP conntrack helper at:
http://people.netfilter.org/pablo/userspace-conntrack-helpers/nf-ftp-helper-userspace-POC.tar.bz
--- include/linux/netfilter/nf_conntrack_common.h | 1 + include/net/netfilter/nf_conntrack_expect.h | 1 + net/netfilter/nf_conntrack_expect.c | 62 +++++++++++++++++++------ net/netfilter/nf_conntrack_netlink.c | 46 ++++++++++++------ 4 files changed, 79 insertions(+), 31 deletions(-)
include/linux/netfilter/nf_conntrack_common.h +1 -0
@@ -103,6 +103,7 @@ enum ip_conntrack_expect_events {/* expectation flags */ #define NF_CT_EXPECT_PERMANENT 0x1#define NF_CT_EXPECT_INACTIVE 0x2 +#define NF_CT_EXPECT_USERSPACE 0x4#ifdef __KERNEL__ struct ip_conntrack_stat {
include/net/netfilter/nf_conntrack_expect.h +1 -0
@@ -85,6 +85,7 @@ nf_ct_find_expectation(struct net *net, u16 zone,void nf_ct_unlink_expect (struct nf_conntrack_expect *exp);void nf_ct_remove_expectations (struct nf_conn *ct);void nf_ct_unexpect_related (struct nf_conntrack_expect *exp); +void nf_ct_remove_userspace_expectations (void );/* Allocate space for an expectation: this is mandatory before calling nf_ct_expect_related. You will have to call put afterwards. */
net/netfilter/nf_conntrack_expect.c +47 -15
117 lines not on this page · raw message
net/netfilter/nf_conntrack_netlink.c +30 -16
77 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 15/72 netfilter: nf_conntrack_sip: Allow ct_sip_get_header() to be called with a null ct argument
In reply to [email protected]From: Simon Horman <[email protected]>
--- net/netfilter/nf_conntrack_sip.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
net/netfilter/nf_conntrack_sip.c +3 -0
@@ -152,6 +152,9 @@ static int parse_addr(const struct nf_conn *ct, const char *cp,const char *end;int ret =0 ; +if (!ct) +return 0 ; +memset (addr,0 ,sizeof (*addr));switch (nf_ct_l3num (ct)) {case AF_INET :
Signature · 1 line
1.7.1
PATCH 16/72 netfilter: nf_conntrack_sip: Add callid parser
In reply to [email protected]From: Simon Horman <[email protected]>
--- include/linux/netfilter/nf_conntrack_sip.h | 1 + net/netfilter/nf_conntrack_sip.c | 39 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 0 deletions(-)
include/linux/netfilter/nf_conntrack_sip.h +1 -0
@@ -89,6 +89,7 @@ enum sip_header_types {SIP_HDR_VIA_TCP ,SIP_HDR_EXPIRES ,SIP_HDR_CONTENT_LENGTH , + SIP_HDR_CALL_ID, }; enum sdp_header_types {
net/netfilter/nf_conntrack_sip.c +39 -0
@@ -130,6 +130,44 @@ static int digits_len(const struct nf_conn *ct, const char *dptr,return len; } +static int iswordc (const char c) +{ +if (isalnum (c) || c =='!' || c =='"' || c =='%' || + (c >='(' && c <='/' ) || c ==':' || c =='<' || c =='>' || + c =='?' || (c >='[' && c <=']' ) || c =='_' || c =='`' || + c =='{' || c =='}' || c =='~' ) +return 1 ; +return 0 ; +} + +static int word_len (const char *dptr,const char *limit) +{ +int len =0 ; +while (dptr < limit &&iswordc (*dptr)) { + dptr++; + len++; + } +return len; +} + +static int callid_len (const struct nf_conn *ct,const char *dptr, +const char *limit,int *shift) +{ +int len, domain_len; + + len =word_len (dptr, limit); + dptr += len; +if (!len || dptr == limit || *dptr !='@' ) +return len; + dptr++; + len++; + + domain_len =word_len (dptr, limit); +if (!domain_len) +return 0 ; +return len + domain_len; +} +/* get media type + port length */ static int media_len (const struct nf_conn *ct,const char *dptr,const char *limit,int *shift)
@@ -299,6 +337,7 @@ static const struct sip_header ct_sip_hdrs[] = { [SIP_HDR_VIA_TCP] = SIP_HDR("Via", "v", "TCP ", epaddr_len), [SIP_HDR_EXPIRES] = SIP_HDR("Expires", NULL, NULL, digits_len), [SIP_HDR_CONTENT_LENGTH] = SIP_HDR("Content-Length", "l", NULL, digits_len), + [SIP_HDR_CALL_ID] = SIP_HDR("Call-Id", "i", NULL, callid_len), };static const char *sip_follow_continuation (const char *dptr,const char *limit)
Signature · 1 line
1.7.1
PATCH 17/72 IPVS: compact ip_vs_sched_persist()
In reply to [email protected]From: Simon Horman <[email protected]>
Compact ip_vs_sched_persist() by setting up parameters and calling functions once.
--- net/netfilter/ipvs/ip_vs_core.c | 160 +++++++++++++-------------------------- 1 files changed, 53 insertions(+), 107 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +51 -105
@@ -193,10 +193,14 @@ ip_vs_sched_persist(struct ip_vs_service *svc,struct ip_vs_iphdr iph;struct ip_vs_dest *dest;struct ip_vs_conn *ct; -__be16 dport;/* destination port to forward */ +int protocol = iph.protocol; +__be16 dport =0 ;/* destination port to forward */ +__be16 vport =0 ;/* virtual service port */ unsigned int flags;union nf_inet_addr snet;/* source network of the client, after masking */ +const union nf_inet_addr fwmark = { .ip =htonl (svc->fwmark) }; +const union nf_inet_addr *vaddr = &iph.daddr;ip_vs_fill_iphdr (svc->af,skb_network_header (skb), &iph);
@@ -227,119 +231,61 @@ ip_vs_sched_persist(struct ip_vs_service *svc,* service, and a template like <caddr, 0, vaddr, vport, daddr, dport> * is created for other persistent services. */ -if (ports[1 ] == svc->port) { -/* Check if a template already exists */ -if (svc->port !=FTPPORT ) - ct =ip_vs_ct_in_get (svc->af, iph.protocol, &snet,0 , - &iph.daddr, ports[1 ]); -else - ct =ip_vs_ct_in_get (svc->af, iph.protocol, &snet,0 , - &iph.daddr,0 ); - -if (!ct || !ip_vs_check_template (ct)) { -/* -* No template found or the dest of the connection -* template is not available. -*/ - dest = svc->scheduler->schedule (svc, skb); -if (dest ==NULL ) { -IP_VS_DBG (1 ,"p-schedule: no dest found.\n" ); -return NULL ; - } - -/* -* Create a template like <protocol,caddr,0, -* vaddr,vport,daddr,dport> for non-ftp service, -* and <protocol,caddr,0,vaddr,0,daddr,0> -* for ftp service. + { +if (ports[1 ] == svc->port) { +/* non-FTP template: +* <protocol, caddr, 0, vaddr, vport, daddr, dport> +* FTP template: +* <protocol, caddr, 0, vaddr, 0, daddr, 0> */ if (svc->port !=FTPPORT ) - ct =ip_vs_conn_new (svc->af, iph.protocol, - &snet,0 , - &iph.daddr, - ports[1 ], - &dest->addr, dest->port, -IP_VS_CONN_F_TEMPLATE , - dest); -else - ct =ip_vs_conn_new (svc->af, iph.protocol, - &snet,0 , - &iph.daddr,0 , - &dest->addr,0 , -IP_VS_CONN_F_TEMPLATE , - dest); -if (ct ==NULL ) -return NULL ; - - ct->timeout = svc->timeout; + vport = ports[1 ]; }else { -/* set destination with the found template */ - dest = ct->dest; +/* Note: persistent fwmark-based services and +* persistent port zero service are handled here. +* fwmark template: +* <IPPROTO_IP,caddr,0,fwmark,0,daddr,0> +* port zero template: +* <protocol,caddr,0,vaddr,0,daddr,0> +*/ +if (svc->fwmark) { + protocol =IPPROTO_IP ; + vaddr = &fwmark; + } } - dport = dest->port; - }else { -/* -* Note: persistent fwmark-based services and persistent -* port zero service are handled here. -* fwmark template: <IPPROTO_IP,caddr,0,fwmark,0,daddr,0> -* port zero template: <protocol,caddr,0,vaddr,0,daddr,0> + } + +/* Check if a template already exists */ + ct =ip_vs_ct_in_get (svc->af, protocol, &snet,0 , vaddr, vport); + +if (!ct || !ip_vs_check_template (ct)) { +/* No template found or the dest of the connection +* template is not available. */ -if (svc->fwmark) { -union nf_inet_addr fwmark = { - .ip =htonl (svc->fwmark) - }; + dest = svc->scheduler->schedule (svc, skb); +if (!dest) { +IP_VS_DBG (1 ,"p-schedule: no dest found.\n" ); +return NULL ; + } - ct =ip_vs_ct_in_get (svc->af,IPPROTO_IP , &snet,0 , - &fwmark,0 ); - }else - ct =ip_vs_ct_in_get (svc->af, iph.protocol, &snet,0 , - &iph.daddr,0 ); +if (ports[1 ] == svc->port && svc->port !=FTPPORT ) + dport = dest->port; -if (!ct || !ip_vs_check_template (ct)) { -/* -* If it is not persistent port zero, return NULL, -* otherwise create a connection template. -*/ -if (svc->port) -return NULL ; +/* Create a template */ + ct =ip_vs_conn_new (svc->af, protocol, &snet,0 ,vaddr, vport, + &dest->addr, dport, +IP_VS_CONN_F_TEMPLATE , dest); +if (ct ==NULL ) +return NULL ; - dest = svc->scheduler->schedule (svc, skb); -if (dest ==NULL ) { -IP_VS_DBG (1 ,"p-schedule: no dest found.\n" ); -return NULL ; - } + ct->timeout = svc->timeout; + }else +/* set destination with the found template */ + dest = ct->dest; -/* -* Create a template according to the service -*/ -if (svc->fwmark) { -union nf_inet_addr fwmark = { - .ip =htonl (svc->fwmark) - }; - - ct =ip_vs_conn_new (svc->af,IPPROTO_IP , - &snet,0 , - &fwmark,0 , - &dest->addr,0 , -IP_VS_CONN_F_TEMPLATE , - dest); - }else - ct =ip_vs_conn_new (svc->af, iph.protocol, - &snet,0 , - &iph.daddr,0 , - &dest->addr,0 , -IP_VS_CONN_F_TEMPLATE , - dest); -if (ct ==NULL ) -return NULL ; - - ct->timeout = svc->timeout; - }else { -/* set destination with the found template */ - dest = ct->dest; - } - dport = ports[1 ]; - } + dport = ports[1 ]; +if (dport == svc->port && dest->port) + dport = dest->port; flags = (svc->flags &IP_VS_SVC_F_ONEPACKET && iph.protocol == IPPROTO_UDP)?
Signature · 1 line
1.7.1
PATCH 18/72 IPVS: Add struct ip_vs_conn_param
In reply to [email protected]From: Simon Horman <[email protected]>
--- include/net/ip_vs.h | 44 ++++++--- net/netfilter/ipvs/ip_vs_conn.c | 171 +++++++++++++++---------------- net/netfilter/ipvs/ip_vs_core.c | 64 ++++++------ net/netfilter/ipvs/ip_vs_ftp.c | 43 +++++---- net/netfilter/ipvs/ip_vs_nfct.c | 12 +- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 47 ++++----- net/netfilter/ipvs/ip_vs_sync.c | 33 +++---- 7 files changed, 211 insertions(+), 203 deletions(-)
include/net/ip_vs.h +30 -14
@@ -357,6 +357,15 @@ struct ip_vs_protocol {extern struct ip_vs_protocol *ip_vs_proto_get (unsigned short proto); +struct ip_vs_conn_param { +const union nf_inet_addr *caddr; +const union nf_inet_addr *vaddr; +__be16 cport; +__be16 vport; +__u16 protocol; +u16 af; +}; +/* * IP_VS structure allocated for each dynamically scheduled connection */
@@ -626,13 +635,23 @@ enum { IP_VS_DIR_LAST, }; -extern struct ip_vs_conn *ip_vs_conn_in_get -(int af,int protocol,const union nf_inet_addr *s_addr,__be16 s_port, -const union nf_inet_addr *d_addr,__be16 d_port); +static inline void ip_vs_conn_fill_param (int af,int protocol, +const union nf_inet_addr *caddr, +__be16 cport, +const union nf_inet_addr *vaddr, +__be16 vport, +struct ip_vs_conn_param *p) +{ + p->af = af; + p->protocol = protocol; + p->caddr = caddr; + p->cport = cport; + p->vaddr = vaddr; + p->vport = vport; +} -extern struct ip_vs_conn *ip_vs_ct_in_get -(int af,int protocol,const union nf_inet_addr *s_addr,__be16 s_port, -const union nf_inet_addr *d_addr,__be16 d_port); +struct ip_vs_conn *ip_vs_conn_in_get (const struct ip_vs_conn_param *p); +struct ip_vs_conn *ip_vs_ct_in_get (const struct ip_vs_conn_param *p); struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,
@@ -640,9 +659,7 @@ struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,unsigned int proto_off, int inverse); -extern struct ip_vs_conn *ip_vs_conn_out_get -(int af,int protocol,const union nf_inet_addr *s_addr,__be16 s_port, -const union nf_inet_addr *d_addr,__be16 d_port); +struct ip_vs_conn *ip_vs_conn_out_get (const struct ip_vs_conn_param *p); struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,
@@ -658,11 +675,10 @@ static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)extern void ip_vs_conn_put (struct ip_vs_conn *cp);extern void ip_vs_conn_fill_cport (struct ip_vs_conn *cp,__be16 cport); -extern struct ip_vs_conn * -ip_vs_conn_new (int af,int proto,const union nf_inet_addr *caddr,__be16 cport, -const union nf_inet_addr *vaddr,__be16 vport, -const union nf_inet_addr *daddr,__be16 dport,unsigned flags, -struct ip_vs_dest *dest); +struct ip_vs_conn *ip_vs_conn_new (const struct ip_vs_conn_param *p, +const union nf_inet_addr *daddr, +__be16 dport,unsigned flags, +struct ip_vs_dest *dest);extern void ip_vs_conn_expire_now (struct ip_vs_conn *cp);extern const char *ip_vs_state_name (__u16 proto,int state);
net/netfilter/ipvs/ip_vs_conn.c +84 -87
284 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_core.c +34 -30
113 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ftp.c +24 -19
58 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_nfct.c +6 -6
@@ -140,6 +140,7 @@ static void ip_vs_nfct_expect_callback(struct nf_conn *ct, {struct nf_conntrack_tuple *orig, new_reply;struct ip_vs_conn *cp; +struct ip_vs_conn_param p;if (exp->tuple.src.l3num !=PF_INET )return ;
@@ -154,9 +155,10 @@ static void ip_vs_nfct_expect_callback(struct nf_conn *ct,/* RS->CLIENT */ orig = &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple; - cp =ip_vs_conn_out_get (exp->tuple.src.l3num, orig->dst.protonum, - &orig->src.u3, orig->src.u.tcp.port, - &orig->dst.u3, orig->dst.u.tcp.port); +ip_vs_conn_fill_param (exp->tuple.src.l3num, orig->dst.protonum, + &orig->src.u3, orig->src.u.tcp.port, + &orig->dst.u3, orig->dst.u.tcp.port, &p); + cp =ip_vs_conn_out_get (&p);if (cp) {/* Change reply CLIENT->RS to CLIENT->VS */ new_reply = ct->tuplehash[IP_CT_DIR_REPLY ].tuple;
@@ -176,9 +178,7 @@ static void ip_vs_nfct_expect_callback(struct nf_conn *ct, }/* CLIENT->VS */ - cp =ip_vs_conn_in_get (exp->tuple.src.l3num, orig->dst.protonum, - &orig->src.u3, orig->src.u.tcp.port, - &orig->dst.u3, orig->dst.u.tcp.port); + cp =ip_vs_conn_in_get (&p);if (cp) {/* Change reply VS->CLIENT to RS->CLIENT */ new_reply = ct->tuplehash[IP_CT_DIR_REPLY ].tuple;
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +19 -28
67 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_sync.c +14 -19
@@ -301,6 +301,7 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)struct ip_vs_conn *cp;struct ip_vs_protocol *pp;struct ip_vs_dest *dest; +struct ip_vs_conn_param param;char *p;int i;
@@ -370,18 +371,17 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen) } } -if (!(flags &IP_VS_CONN_F_TEMPLATE )) - cp =ip_vs_conn_in_get (AF_INET , s->protocol, - (union nf_inet_addr *)&s->caddr, - s->cport, - (union nf_inet_addr *)&s->vaddr, - s->vport); -else - cp =ip_vs_ct_in_get (AF_INET , s->protocol, - (union nf_inet_addr *)&s->caddr, - s->cport, - (union nf_inet_addr *)&s->vaddr, - s->vport); + { +ip_vs_conn_fill_param (AF_INET , s->protocol, + (union nf_inet_addr *)&s->caddr, + s->cport, + (union nf_inet_addr *)&s->vaddr, + s->vport, ¶m); +if (!(flags &IP_VS_CONN_F_TEMPLATE )) + cp =ip_vs_conn_in_get (¶m); +else + cp =ip_vs_ct_in_get (¶m); + }if (!cp) {/* * Find the appropriate destination for the connection.
@@ -406,14 +406,9 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)else flags &= ~IP_VS_CONN_F_INACTIVE ; } - cp =ip_vs_conn_new (AF_INET , s->protocol, - (union nf_inet_addr *)&s->caddr, - s->cport, - (union nf_inet_addr *)&s->vaddr, - s->vport, + cp =ip_vs_conn_new (¶m, (union nf_inet_addr *)&s->daddr, - s->dport, - flags, dest); + s->dport, flags, dest);if (dest)atomic_dec (&dest->refcnt);if (!cp) {
Signature · 1 line
1.7.1
PATCH 19/72 IPVS: Allow null argument to ip_vs_scheduler_put()
In reply to [email protected]From: Simon Horman <[email protected]>
This simplifies caller logic sightly.
--- net/netfilter/ipvs/ip_vs_ctl.c | 13 ++++--------- net/netfilter/ipvs/ip_vs_sched.c | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +4 -9
@@ -1144,7 +1144,7 @@ ip_vs_add_service(struct ip_vs_service_user_kern *u,if (sched ==NULL ) {pr_info ("Scheduler module ip_vs_%s not found\n" , u->sched_name); ret = -ENOENT ; - goto out_mod_dec; + goto out_err; }#ifdef CONFIG_IP_VS_IPV6
@@ -1204,7 +1204,7 @@ ip_vs_add_service(struct ip_vs_service_user_kern *u, *svc_p = svc;return 0 ; - out_err: + out_err:if (svc !=NULL ) {if (svc->scheduler)ip_vs_unbind_scheduler (svc);
@@ -1217,7 +1217,6 @@ ip_vs_add_service(struct ip_vs_service_user_kern *u, }ip_vs_scheduler_put (sched); - out_mod_dec:/* decrease the module use count */ ip_vs_use_count_dec ();
@@ -1300,10 +1299,7 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)#ifdef CONFIG_IP_VS_IPV6 out:#endif - -if (old_sched) -ip_vs_scheduler_put (old_sched); - +ip_vs_scheduler_put (old_sched);return ret; }
@@ -1327,8 +1323,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc)/* Unbind scheduler */ old_sched = svc->scheduler;ip_vs_unbind_scheduler (svc); -if (old_sched) -ip_vs_scheduler_put (old_sched); +ip_vs_scheduler_put (old_sched);/* Unbind app inc */ if (svc->inc) {
net/netfilter/ipvs/ip_vs_sched.c +1 -1
@@ -159,7 +159,7 @@ struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name)void ip_vs_scheduler_put (struct ip_vs_scheduler *scheduler) { -if (scheduler->module) +if (scheduler && scheduler->module)module_put (scheduler->module); }
Signature · 1 line
1.7.1
PATCH 20/72 IPVS: ip_vs_{un,}bind_scheduler NULL arguments
In reply to [email protected]From: Simon Horman <[email protected]>
In general NULL arguments aren't passed by the few callers that exist, so don't test for them.
The exception is to make passing NULL to ip_vs_unbind_scheduler() a noop.
--- net/netfilter/ipvs/ip_vs_ctl.c | 3 +-- net/netfilter/ipvs/ip_vs_sched.c | 23 +++-------------------- 2 files changed, 4 insertions(+), 22 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +1 -2
@@ -1206,8 +1206,7 @@ ip_vs_add_service(struct ip_vs_service_user_kern *u, out_err:if (svc !=NULL ) { -if (svc->scheduler) -ip_vs_unbind_scheduler (svc); +ip_vs_unbind_scheduler (svc);if (svc->inc) {local_bh_disable ();ip_vs_app_inc_put (svc->inc);
net/netfilter/ipvs/ip_vs_sched.c +3 -20
@@ -46,15 +46,6 @@ int ip_vs_bind_scheduler(struct ip_vs_service *svc, {int ret; -if (svc ==NULL ) { -pr_err ("%s(): svc arg NULL\n" , __func__); -return -EINVAL ; - } -if (scheduler ==NULL ) { -pr_err ("%s(): scheduler arg NULL\n" , __func__); -return -EINVAL ; - } - svc->scheduler = scheduler;if (scheduler->init_service) {
@@ -74,18 +65,10 @@ int ip_vs_bind_scheduler(struct ip_vs_service *svc,*/ int ip_vs_unbind_scheduler (struct ip_vs_service *svc) { -struct ip_vs_scheduler *sched; +struct ip_vs_scheduler *sched = svc->scheduler; -if (svc ==NULL ) { -pr_err ("%s(): svc arg NULL\n" , __func__); -return -EINVAL ; - } - - sched = svc->scheduler; -if (sched ==NULL ) { -pr_err ("%s(): svc isn't bound\n" , __func__); -return -EINVAL ; - } +if (!sched) +return 0 ;if (sched->done_service) {if (sched->done_service (svc) !=0 ) {
Signature · 1 line
1.7.1
PATCH 21/72 IPVS: Add struct ip_vs_pe
In reply to [email protected]From: Simon Horman <[email protected]>
--- include/linux/ip_vs.h | 2 + include/net/ip_vs.h | 28 +++++++++++++++- net/netfilter/ipvs/ip_vs_conn.c | 67 ++++++++++++++++++++++++++++++++------ net/netfilter/ipvs/ip_vs_core.c | 36 +++++++++++++++++---- net/netfilter/ipvs/ip_vs_sync.c | 17 +++++++++- 5 files changed, 129 insertions(+), 21 deletions(-)
include/linux/ip_vs.h +2 -0
@@ -99,8 +99,10 @@ 0)#define IP_VS_SCHEDNAME_MAXLEN 16 +#define IP_VS_PENAME_MAXLEN 16#define IP_VS_IFNAME_MAXLEN 16 +#define IP_VS_PEDATA_MAXLEN 255/* * The struct ip_vs_service_user and struct ip_vs_dest_user are
include/net/ip_vs.h +27 -1
@@ -364,6 +364,10 @@ struct ip_vs_conn_param {__be16 vport;__u16 protocol;u16 af; + +const struct ip_vs_pe *pe; +char *pe_data; +__u8 pe_data_len; };/*
@@ -416,6 +420,9 @@ struct ip_vs_conn {void *app_data;/* Application private data */ struct ip_vs_seq in_seq;/* incoming seq. struct */ struct ip_vs_seq out_seq;/* outgoing seq. struct */ + +char *pe_data; +__u8 pe_data_len; };
@@ -486,6 +493,9 @@ struct ip_vs_service {struct ip_vs_scheduler *scheduler;/* bound scheduler object */ rwlock_t sched_lock;/* lock sched_data */ void *sched_data;/* scheduler application data */ + +/* alternate persistence engine */ +struct ip_vs_pe *pe; };
@@ -549,6 +559,20 @@ struct ip_vs_scheduler { const struct sk_buff *skb); }; +/* The persistence engine object */ +struct ip_vs_pe { +struct list_head n_list;/* d-linked list head */ +char *name;/* scheduler name */ +atomic_t refcnt;/* reference counter */ +struct module *module;/* THIS_MODULE/NULL */ + +/* get the connection template, if any */ +int (*fill_param)(struct ip_vs_conn_param *p,struct sk_buff *skb); +bool (*ct_match)(const struct ip_vs_conn_param *p, +struct ip_vs_conn *ct); +u32 (*hashkey_raw)(const struct ip_vs_conn_param *p,u32 initval, +bool inverse); +};/* * The application module object (a.k.a. app incarnation)
@@ -648,6 +672,8 @@ static inline void ip_vs_conn_fill_param(int af, int protocol, p->cport = cport; p->vaddr = vaddr; p->vport = vport; + p->pe =NULL ; + p->pe_data =NULL ; }struct ip_vs_conn *ip_vs_conn_in_get (const struct ip_vs_conn_param *p);
@@ -803,7 +829,7 @@ extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);extern struct ip_vs_scheduler *ip_vs_scheduler_get (const char *sched_name);extern void ip_vs_scheduler_put (struct ip_vs_scheduler *scheduler);extern struct ip_vs_conn * -ip_vs_schedule (struct ip_vs_service *svc,const struct sk_buff *skb); +ip_vs_schedule (struct ip_vs_service *svc,struct sk_buff *skb);extern int ip_vs_leave (struct ip_vs_service *svc,struct sk_buff *skb,struct ip_vs_protocol *pp);
net/netfilter/ipvs/ip_vs_conn.c +56 -11
142 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_core.c +29 -7
@@ -176,6 +176,19 @@ ip_vs_set_state(struct ip_vs_conn *cp, int direction,return pp->state_transition (cp, direction, skb, pp); } +static inline int +ip_vs_conn_fill_param_persist (const struct ip_vs_service *svc, +struct sk_buff *skb,int protocol, +const union nf_inet_addr *caddr,__be16 cport, +const union nf_inet_addr *vaddr,__be16 vport, +struct ip_vs_conn_param *p) +{ +ip_vs_conn_fill_param (svc->af, protocol, caddr, cport, vaddr, vport, p); + p->pe = svc->pe; +if (p->pe && p->pe->fill_param) +return p->pe->fill_param (p, skb); +return 0 ; +}/* * IPVS persistent scheduling function
@@ -186,7 +199,7 @@ ip_vs_set_state(struct ip_vs_conn *cp, int direction,*/ static struct ip_vs_conn *ip_vs_sched_persist (struct ip_vs_service *svc, -const struct sk_buff *skb, +struct sk_buff *skb,__be16 ports[2 ]) {struct ip_vs_conn *cp =NULL ;
@@ -255,8 +268,9 @@ ip_vs_sched_persist(struct ip_vs_service *svc, vaddr = &fwmark; } } -ip_vs_conn_fill_param (svc->af, protocol, &snet,0 , - vaddr, vport, ¶m); +if (ip_vs_conn_fill_param_persist (svc, skb, protocol, &snet,0 , + vaddr, vport, ¶m)) +return NULL ; }/* Check if a template already exists */
@@ -268,22 +282,30 @@ ip_vs_sched_persist(struct ip_vs_service *svc, dest = svc->scheduler->schedule (svc, skb);if (!dest) {IP_VS_DBG (1 ,"p-schedule: no dest found.\n" ); +kfree (param.pe_data);return NULL ; }if (ports[1 ] == svc->port && svc->port !=FTPPORT ) dport = dest->port; -/* Create a template */ +/* Create a template +* This adds param.pe_data to the template, +* and thus param.pe_data will be destroyed +* when the template expires */ ct =ip_vs_conn_new (¶m, &dest->addr, dport,IP_VS_CONN_F_TEMPLATE , dest); -if (ct ==NULL ) +if (ct ==NULL ) { +kfree (param.pe_data);return NULL ; + } ct->timeout = svc->timeout; - }else + }else {/* set destination with the found template */ dest = ct->dest; +kfree (param.pe_data); + } dport = ports[1 ];if (dport == svc->port && dest->port)
@@ -322,7 +344,7 @@ ip_vs_sched_persist(struct ip_vs_service *svc,* Protocols supported: TCP, UDP */ struct ip_vs_conn * -ip_vs_schedule (struct ip_vs_service *svc,const struct sk_buff *skb) +ip_vs_schedule (struct ip_vs_service *svc,struct sk_buff *skb) {struct ip_vs_conn *cp =NULL ;struct ip_vs_iphdr iph;
net/netfilter/ipvs/ip_vs_sync.c +15 -2
@@ -288,6 +288,16 @@ void ip_vs_sync_conn(struct ip_vs_conn *cp)ip_vs_sync_conn (cp->control); } +static inline int +ip_vs_conn_fill_param_sync (int af,int protocol, +const union nf_inet_addr *caddr,__be16 cport, +const union nf_inet_addr *vaddr,__be16 vport, +struct ip_vs_conn_param *p) +{ +/* XXX: Need to take into account persistence engine */ +ip_vs_conn_fill_param (af, protocol, caddr, cport, vaddr, vport, p); +return 0 ; +}/* * Process received multicast message and create the corresponding
@@ -372,11 +382,14 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen) } { -ip_vs_conn_fill_param (AF_INET , s->protocol, +if (ip_vs_conn_fill_param_sync (AF_INET , s->protocol, (union nf_inet_addr *)&s->caddr, s->cport, (union nf_inet_addr *)&s->vaddr, - s->vport, ¶m); + s->vport, ¶m)) { +pr_err ("ip_vs_conn_fill_param_sync failed" ); +return ; + }if (!(flags &IP_VS_CONN_F_TEMPLATE )) cp =ip_vs_conn_in_get (¶m);else
Signature · 1 line
1.7.1
PATCH 22/72 IPVS: Add persistence engine data to /proc/net/ip_vs_conn
In reply to [email protected]From: Simon Horman <[email protected]>
This shouldn't break compatibility with userspace as the new data is at the end of the line.
I have confirmed that this doesn't break ipvsadm, the main (only?) user-space user of this data.
--- include/net/ip_vs.h | 1 + net/netfilter/ipvs/ip_vs_conn.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-)
include/net/ip_vs.h +1 -0
@@ -572,6 +572,7 @@ struct ip_vs_pe { struct ip_vs_conn *ct);u32 (*hashkey_raw)(const struct ip_vs_conn_param *p,u32 initval,bool inverse); +int (*show_pe_data)(const struct ip_vs_conn *cp,char *buf); };/*
net/netfilter/ipvs/ip_vs_conn.c +20 -5
@@ -950,30 +950,45 @@ static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)if (v ==SEQ_START_TOKEN )seq_puts (seq, -"Pro FromIP FPrt ToIP TPrt DestIP DPrt State Expires\n" ); +"Pro FromIP FPrt ToIP TPrt DestIP DPrt State Expires PEName PEData\n" );else {const struct ip_vs_conn *cp = v; +char pe_data[IP_VS_PENAME_MAXLEN +IP_VS_PEDATA_MAXLEN +3 ]; +size_t len =0 ; + +if (cp->dest && cp->dest->svc->pe && + cp->dest->svc->pe->show_pe_data) { + pe_data[0 ] =' ' ; + len =strlen (cp->dest->svc->pe->name); +memcpy (pe_data +1 , cp->dest->svc->pe->name, len); + pe_data[len +1 ] =' ' ; + len +=2 ; + len += cp->dest->svc->pe->show_pe_data (cp, + pe_data + len); + } + pe_data[len] ='\0' ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 ) -seq_printf (seq,"%-3s %pI6 %04X %pI6 %04X %pI6 %04X %-11s %7lu\n" , +seq_printf (seq,"%-3s %pI6 %04X %pI6 %04X " +"%pI6 %04X %-11s %7lu%s\n" ,ip_vs_proto_name (cp->protocol), &cp->caddr.in6,ntohs (cp->cport), &cp->vaddr.in6,ntohs (cp->vport), &cp->daddr.in6,ntohs (cp->dport),ip_vs_state_name (cp->protocol, cp->state), - (cp->timer.expires-jiffies)/HZ ); + (cp->timer.expires-jiffies)/HZ , pe_data); else#endif seq_printf (seq,"%-3s %08X %04X %08X %04X" -" %08X %04X %-11s %7lu\n" , +" %08X %04X %-11s %7lu%s\n" ,ip_vs_proto_name (cp->protocol),ntohl (cp->caddr.ip),ntohs (cp->cport),ntohl (cp->vaddr.ip),ntohs (cp->vport),ntohl (cp->daddr.ip),ntohs (cp->dport),ip_vs_state_name (cp->protocol, cp->state), - (cp->timer.expires-jiffies)/HZ ); + (cp->timer.expires-jiffies)/HZ , pe_data); }return 0 ; }
Signature · 1 line
1.7.1
PATCH 23/72 IPVS: management of persistence engine modules
In reply to [email protected]From: Simon Horman <[email protected]>
This is based heavily on the scheduler management code
--- include/net/ip_vs.h | 6 ++ net/netfilter/ipvs/Makefile | 2 +- net/netfilter/ipvs/ip_vs_pe.c | 147 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 1 deletions(-) create mode 100644 net/netfilter/ipvs/ip_vs_pe.c
include/net/ip_vs.h +6 -0
@@ -796,6 +796,12 @@ extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);extern int ip_vs_app_init (void );extern void ip_vs_app_cleanup (void ); +void ip_vs_bind_pe (struct ip_vs_service *svc,struct ip_vs_pe *pe); +void ip_vs_unbind_pe (struct ip_vs_service *svc); +int register_ip_vs_pe (struct ip_vs_pe *pe); +int unregister_ip_vs_pe (struct ip_vs_pe *pe); +extern struct ip_vs_pe *ip_vs_pe_get (const char *name); +extern void ip_vs_pe_put (struct ip_vs_pe *pe);/* * IPVS protocol functions (from ip_vs_proto.c)
net/netfilter/ipvs/Makefile +1 -1
@@ -14,7 +14,7 @@ ip_vs-extra_objs-$(CONFIG_IP_VS_NFCT) += ip_vs_nfct.o ip_vs-objs := ip_vs_conn.o ip_vs_core.o ip_vs_ctl.o ip_vs_sched.o \ ip_vs_xmit.o ip_vs_app.o ip_vs_sync.o \ - ip_vs_est.o ip_vs_proto.o \ + ip_vs_est.o ip_vs_proto.o ip_vs_pe.o \ $(ip_vs_proto-objs-y) $(ip_vs-extra_objs-y)
net/netfilter/ipvs/ip_vs_pe.c new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 24/72 IPVS: Allow configuration of persistence engines
In reply to [email protected]From: Simon Horman <[email protected]>
Allow the persistence engine of a virtual service to be set, edited and unset.
This feature only works with the netlink user-space interface.
--- include/linux/ip_vs.h | 3 ++ include/net/ip_vs.h | 1 + net/netfilter/ipvs/ip_vs_ctl.c | 57 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-)
include/linux/ip_vs.h +3 -0
@@ -336,6 +336,9 @@ enum {IPVS_SVC_ATTR_NETMASK ,/* persistent netmask */ IPVS_SVC_ATTR_STATS ,/* nested attribute for service stats */ + +IPVS_SVC_ATTR_PE_NAME ,/* name of ct retriever */ + __IPVS_SVC_ATTR_MAX, };
include/net/ip_vs.h +1 -0
@@ -444,6 +444,7 @@ struct ip_vs_service_user_kern {/* virtual service options */ char *sched_name; +char *pe_name;unsigned flags;/* virtual service flags */ unsigned timeout;/* persistent timeout in sec */ u32 netmask;/* persistent netmask */
net/netfilter/ipvs/ip_vs_ctl.c +54 -3
155 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 25/72 IPVS: Fallback if persistence engine fails
In reply to [email protected]From: Simon Horman <[email protected]>
Fall back to normal persistence handling if the persistence engine fails to recognise a packet.
This way, at least the packet will go somewhere.
It is envisaged that iptables could be used to block packets such if this is not desired although nf_conntrack_sip would likely need to be enhanced first.
--- net/netfilter/ipvs/ip_vs_conn.c | 6 +++--- net/netfilter/ipvs/ip_vs_core.c | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +3 -3
@@ -154,7 +154,7 @@ static unsigned int ip_vs_conn_hashkey_param(const struct ip_vs_conn_param *p,const union nf_inet_addr *addr;__be16 port; -if (p->pe && p->pe->hashkey_raw) +if (p->pe_data && p->pe->hashkey_raw)return p->pe->hashkey_raw (p, ip_vs_conn_rnd, inverse) & ip_vs_conn_tab_mask;
@@ -353,7 +353,7 @@ struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p)ct_read_lock (hash);list_for_each_entry (cp, &ip_vs_conn_tab[hash], c_list) { -if (p->pe && p->pe->ct_match) { +if (p->pe_data && p->pe->ct_match) {if (p->pe->ct_match (p, cp)) goto out;continue ;
@@ -956,7 +956,7 @@ static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)char pe_data[IP_VS_PENAME_MAXLEN +IP_VS_PEDATA_MAXLEN +3 ];size_t len =0 ; -if (cp->dest && cp->dest->svc->pe && +if (cp->dest && cp->pe_data && cp->dest->svc->pe->show_pe_data) { pe_data[0 ] =' ' ; len =strlen (cp->dest->svc->pe->name);
net/netfilter/ipvs/ip_vs_core.c +4 -6
@@ -176,7 +176,7 @@ ip_vs_set_state(struct ip_vs_conn *cp, int direction,return pp->state_transition (cp, direction, skb, pp); } -static inline int +static inline void ip_vs_conn_fill_param_persist(const struct ip_vs_service *svc, struct sk_buff *skb, int protocol, const union nf_inet_addr *caddr, __be16 cport,
@@ -186,8 +186,7 @@ ip_vs_conn_fill_param_persist(const struct ip_vs_service *svc,ip_vs_conn_fill_param (svc->af, protocol, caddr, cport, vaddr, vport, p); p->pe = svc->pe;if (p->pe && p->pe->fill_param) -return p->pe->fill_param (p, skb); -return 0 ; + p->pe->fill_param (p, skb); }/*
@@ -268,9 +267,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc, vaddr = &fwmark; } } -if (ip_vs_conn_fill_param_persist (svc, skb, protocol, &snet,0 , - vaddr, vport, ¶m)) -return NULL ; +ip_vs_conn_fill_param_persist (svc, skb, protocol, &snet,0 , + vaddr, vport, ¶m); }/* Check if a template already exists */
Signature · 1 line
1.7.1
PATCH 26/72 IPVS: sip persistence engine
In reply to [email protected]From: Simon Horman <[email protected]>
Add the SIP callid as a key for persistence.
This allows multiple connections from the same IP address to be differentiated on the basis of the callid.
When used in conjunction with the persistence mask, it allows connections from different IP addresses to be aggregated on the basis of the callid.
It is envisaged that a persistence mask of 0.0.0.0 will be a useful setting. That is, ignore the source IP address when checking for persistence.
It is envisaged that this option will be used in conjunction with one-packet scheduling.
This only works with UDP and cannot be made to work with TCP within the current framework.
--- net/netfilter/ipvs/Kconfig | 7 ++ net/netfilter/ipvs/Makefile | 3 + net/netfilter/ipvs/ip_vs_pe_sip.c | 167 +++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 0 deletions(-) create mode 100644 net/netfilter/ipvs/ip_vs_pe_sip.c
net/netfilter/ipvs/Kconfig +7 -0
@@ -256,4 +256,11 @@ config IP_VS_NFCT connection state to be exported to the Netfilter framework for filtering purposes. +config IP_VS_PE_SIP + tristate "SIP persistence engine" + depends on IP_VS_PROTO_UDP + depends on NF_CONNTRACK_SIP + ---help--- + Allow persistence based on the SIP Call-ID + endif # IP_VS
net/netfilter/ipvs/Makefile +3 -0
@@ -35,3 +35,6 @@ obj-$(CONFIG_IP_VS_NQ) += ip_vs_nq.o # IPVS application helpers obj-$(CONFIG_IP_VS_FTP) += ip_vs_ftp.o + +# IPVS connection template retrievers +obj-$(CONFIG_IP_VS_PE_SIP) += ip_vs_pe_sip.o
net/netfilter/ipvs/ip_vs_pe_sip.c new file +167 -0
167 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 27/72 netfilter: nf_nat: make find/put static
In reply to [email protected]From: Stephen Hemminger <[email protected]>
The functions nf_nat_proto_find_get and nf_nat_proto_put are only used internally in nf_nat_core. This might break some out of tree NAT module.
--- include/net/netfilter/nf_nat_protocol.h | 3 --- net/ipv4/netfilter/nf_nat_core.c | 6 ++---- 2 files changed, 2 insertions(+), 7 deletions(-)
include/net/netfilter/nf_nat_protocol.h +0 -3
@@ -45,9 +45,6 @@ struct nf_nat_protocol {extern int nf_nat_protocol_register (const struct nf_nat_protocol *proto);extern void nf_nat_protocol_unregister (const struct nf_nat_protocol *proto); -extern const struct nf_nat_protocol *nf_nat_proto_find_get (u_int8_t protocol); -extern void nf_nat_proto_put (const struct nf_nat_protocol *proto); -/* Built-in protocols. */ extern const struct nf_nat_protocol nf_nat_protocol_tcp;extern const struct nf_nat_protocol nf_nat_protocol_udp;
net/ipv4/netfilter/nf_nat_core.c +2 -4
@@ -47,7 +47,7 @@ __nf_nat_proto_find(u_int8_t protonum)return rcu_dereference (nf_nat_protos[protonum]); } -const struct nf_nat_protocol * +static const struct nf_nat_protocol *nf_nat_proto_find_get (u_int8_t protonum) {const struct nf_nat_protocol *p;
@@ -60,14 +60,12 @@ nf_nat_proto_find_get(u_int8_t protonum)return p; } -EXPORT_SYMBOL_GPL (nf_nat_proto_find_get); -void +static void nf_nat_proto_put (const struct nf_nat_protocol *p) {module_put (p->me); } -EXPORT_SYMBOL_GPL (nf_nat_proto_put);/* We keep an extra hash for each conntrack, for fast searching. */ static inline unsigned int
Signature · 1 line
1.7.1
PATCH 28/72 netfilter: ipt_LOG: add bufferisation to call printk() once
In reply to [email protected]From: Eric Dumazet <[email protected]>
ipt_LOG & ip6t_LOG use lot of calls to printk() and use a lock in a hope several cpus wont mix their output in syslog.
printk() being very expensive [1], its better to call it once, on a prebuilt and complete line. Also, with mixed IPv4 and IPv6 trafic, separate IPv4/IPv6 locks dont avoid garbage.
I used an allocation of a 1024 bytes structure, sort of seq_printf() but with a fixed size limit.
Use a static buffer if dynamic allocation failed.
Emit a once time alert if buffer size happens to be too short.
[1]: printk() has various features like printk_delay()...
--- net/ipv4/netfilter/ipt_LOG.c | 145 +++++++++++++++++++------------------- net/ipv6/netfilter/ip6t_LOG.c | 157 +++++++++++++++++++++-------------------- 2 files changed, 152 insertions(+), 150 deletions(-)
net/ipv4/netfilter/ipt_LOG.c +73 -72
@@ -24,16 +24,15 @@#include <linux/netfilter/x_tables.h> #include <linux/netfilter_ipv4/ipt_LOG.h> #include <net/netfilter/nf_log.h> +#include <net/netfilter/xt_log.h> MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Netfilter Core Team <[email protected]>" );MODULE_DESCRIPTION ("Xtables: IPv4 packet logging to syslog" ); -/* Use lock to serialize, so printks don't overlap */ -static DEFINE_SPINLOCK (log_lock); -/* One level of recursion won't kill us */ -static void dump_packet (const struct nf_loginfo *info, +static void dump_packet (struct sbuff *m, +const struct nf_loginfo *info,const struct sk_buff *skb,unsigned int iphoff) {
@@ -48,32 +47,32 @@ static void dump_packet(const struct nf_loginfo *info, ih =skb_header_pointer (skb, iphoff,sizeof (_iph), &_iph);if (ih ==NULL ) { -printk ("TRUNCATED" ); +sb_add (m,"TRUNCATED" );return ; }/* Important fields: * TOS, len, DF/MF, fragment offset, TTL, src, dst, options. */ /* Max length: 40 "SRC=255.255.255.255 DST=255.255.255.255 " */ -printk ("SRC=%pI4 DST=%pI4 " , +sb_add (m,"SRC=%pI4 DST=%pI4 " , &ih->saddr, &ih->daddr);/* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */ -printk ("LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u " , +sb_add (m,"LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u " ,ntohs (ih->tot_len), ih->tos &IPTOS_TOS_MASK , ih->tos &IPTOS_PREC_MASK , ih->ttl,ntohs (ih->id));/* Max length: 6 "CE DF MF " */ if (ntohs (ih->frag_off) &IP_CE ) -printk ("CE " ); +sb_add (m,"CE " );if (ntohs (ih->frag_off) &IP_DF ) -printk ("DF " ); +sb_add (m,"DF " );if (ntohs (ih->frag_off) &IP_MF ) -printk ("MF " ); +sb_add (m,"MF " );/* Max length: 11 "FRAG:65535 " */ if (ntohs (ih->frag_off) &IP_OFFSET ) -printk ("FRAG:%u " ,ntohs (ih->frag_off) &IP_OFFSET ); +sb_add (m,"FRAG:%u " ,ntohs (ih->frag_off) &IP_OFFSET );if ((logflags &IPT_LOG_IPOPT ) && ih->ihl *4 >sizeof (struct iphdr )) {
@@ -85,15 +84,15 @@ static void dump_packet(const struct nf_loginfo *info, op =skb_header_pointer (skb, iphoff+sizeof (_iph), optsize, _opt);if (op ==NULL ) { -printk ("TRUNCATED" ); +sb_add (m,"TRUNCATED" );return ; }/* Max length: 127 "OPT (" 15*4*2chars ") " */ -printk ("OPT (" ); +sb_add (m,"OPT (" );for (i =0 ; i < optsize; i++) -printk ("%02X" , op[i]); -printk (") " ); +sb_add (m,"%02X" , op[i]); +sb_add (m,") " ); }switch (ih->protocol) {
@@ -102,7 +101,7 @@ static void dump_packet(const struct nf_loginfo *info,const struct tcphdr *th;/* Max length: 10 "PROTO=TCP " */ -printk ("PROTO=TCP " ); +sb_add (m,"PROTO=TCP " );if (ntohs (ih->frag_off) &IP_OFFSET )break ;
@@ -111,41 +110,41 @@ static void dump_packet(const struct nf_loginfo *info, th =skb_header_pointer (skb, iphoff + ih->ihl *4 ,sizeof (_tcph), &_tcph);if (th ==NULL ) { -printk ("INCOMPLETE [%u bytes] " , +sb_add (m,"INCOMPLETE [%u bytes] " , skb->len - iphoff - ih->ihl*4 );break ; }/* Max length: 20 "SPT=65535 DPT=65535 " */ -printk ("SPT=%u DPT=%u " , +sb_add (m,"SPT=%u DPT=%u " ,ntohs (th->source),ntohs (th->dest));/* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */ if (logflags &IPT_LOG_TCPSEQ ) -printk ("SEQ=%u ACK=%u " , +sb_add (m,"SEQ=%u ACK=%u " ,ntohl (th->seq),ntohl (th->ack_seq));/* Max length: 13 "WINDOW=65535 " */ -printk ("WINDOW=%u " ,ntohs (th->window)); +sb_add (m,"WINDOW=%u " ,ntohs (th->window));/* Max length: 9 "RES=0x3F " */ -printk ("RES=0x%02x " , (u8)(ntohl (tcp_flag_word (th) &TCP_RESERVED_BITS ) >>22 )); +sb_add (m,"RES=0x%02x " , (u8)(ntohl (tcp_flag_word (th) &TCP_RESERVED_BITS ) >>22 ));/* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */ if (th->cwr) -printk ("CWR " ); +sb_add (m,"CWR " );if (th->ece) -printk ("ECE " ); +sb_add (m,"ECE " );if (th->urg) -printk ("URG " ); +sb_add (m,"URG " );if (th->ack) -printk ("ACK " ); +sb_add (m,"ACK " );if (th->psh) -printk ("PSH " ); +sb_add (m,"PSH " );if (th->rst) -printk ("RST " ); +sb_add (m,"RST " );if (th->syn) -printk ("SYN " ); +sb_add (m,"SYN " );if (th->fin) -printk ("FIN " ); +sb_add (m,"FIN " );/* Max length: 11 "URGP=65535 " */ -printk ("URGP=%u " ,ntohs (th->urg_ptr)); +sb_add (m,"URGP=%u " ,ntohs (th->urg_ptr));if ((logflags &IPT_LOG_TCPOPT ) && th->doff *4 >sizeof (struct tcphdr )) {
@@ -158,15 +157,15 @@ static void dump_packet(const struct nf_loginfo *info, iphoff+ih->ihl*4 +sizeof (_tcph), optsize, _opt);if (op ==NULL ) { -printk ("TRUNCATED" ); +sb_add (m,"TRUNCATED" );return ; }/* Max length: 127 "OPT (" 15*4*2chars ") " */ -printk ("OPT (" ); +sb_add (m,"OPT (" );for (i =0 ; i < optsize; i++) -printk ("%02X" , op[i]); -printk (") " ); +sb_add (m,"%02X" , op[i]); +sb_add (m,") " ); }break ; }
@@ -177,9 +176,9 @@ static void dump_packet(const struct nf_loginfo *info,if (ih->protocol ==IPPROTO_UDP )/* Max length: 10 "PROTO=UDP " */ -printk ("PROTO=UDP " ); +sb_add (m,"PROTO=UDP " );else /* Max length: 14 "PROTO=UDPLITE " */ -printk ("PROTO=UDPLITE " ); +sb_add (m,"PROTO=UDPLITE " );if (ntohs (ih->frag_off) &IP_OFFSET )break ;
@@ -188,13 +187,13 @@ static void dump_packet(const struct nf_loginfo *info, uh =skb_header_pointer (skb, iphoff+ih->ihl*4 ,sizeof (_udph), &_udph);if (uh ==NULL ) { -printk ("INCOMPLETE [%u bytes] " , +sb_add (m,"INCOMPLETE [%u bytes] " , skb->len - iphoff - ih->ihl*4 );break ; }/* Max length: 20 "SPT=65535 DPT=65535 " */ -printk ("SPT=%u DPT=%u LEN=%u " , +sb_add (m,"SPT=%u DPT=%u LEN=%u " ,ntohs (uh->source),ntohs (uh->dest),ntohs (uh->len));break ;
@@ -221,7 +220,7 @@ static void dump_packet(const struct nf_loginfo *info, [ICMP_ADDRESSREPLY] = 12 };/* Max length: 11 "PROTO=ICMP " */ -printk ("PROTO=ICMP " ); +sb_add (m,"PROTO=ICMP " );if (ntohs (ih->frag_off) &IP_OFFSET )break ;
@@ -230,19 +229,19 @@ static void dump_packet(const struct nf_loginfo *info, ich =skb_header_pointer (skb, iphoff + ih->ihl *4 ,sizeof (_icmph), &_icmph);if (ich ==NULL ) { -printk ("INCOMPLETE [%u bytes] " , +sb_add (m,"INCOMPLETE [%u bytes] " , skb->len - iphoff - ih->ihl*4 );break ; }/* Max length: 18 "TYPE=255 CODE=255 " */ -printk ("TYPE=%u CODE=%u " , ich->type, ich->code); +sb_add (m,"TYPE=%u CODE=%u " , ich->type, ich->code);/* Max length: 25 "INCOMPLETE [65535 bytes] " */ if (ich->type <=NR_ICMP_TYPES && required_len[ich->type] && skb->len-iphoff-ih->ihl*4 < required_len[ich->type]) { -printk ("INCOMPLETE [%u bytes] " , +sb_add (m,"INCOMPLETE [%u bytes] " , skb->len - iphoff - ih->ihl*4 );break ; }
@@ -251,35 +250,35 @@ static void dump_packet(const struct nf_loginfo *info,case ICMP_ECHOREPLY :case ICMP_ECHO :/* Max length: 19 "ID=65535 SEQ=65535 " */ -printk ("ID=%u SEQ=%u " , +sb_add (m,"ID=%u SEQ=%u " ,ntohs (ich->un.echo.id),ntohs (ich->un.echo.sequence));break ;case ICMP_PARAMETERPROB :/* Max length: 14 "PARAMETER=255 " */ -printk ("PARAMETER=%u " , +sb_add (m,"PARAMETER=%u " ,ntohl (ich->un.gateway) >>24 );break ;case ICMP_REDIRECT :/* Max length: 24 "GATEWAY=255.255.255.255 " */ -printk ("GATEWAY=%pI4 " , &ich->un.gateway); +sb_add (m,"GATEWAY=%pI4 " , &ich->un.gateway);/* Fall through */ case ICMP_DEST_UNREACH :case ICMP_SOURCE_QUENCH :case ICMP_TIME_EXCEEDED :/* Max length: 3+maxlen */ if (!iphoff) {/* Only recurse once. */ -printk ("[" ); -dump_packet (info, skb, +sb_add (m,"[" ); +dump_packet (m, info, skb, iphoff + ih->ihl*4 +sizeof (_icmph)); -printk ("] " ); +sb_add (m,"] " ); }/* Max length: 10 "MTU=65535 " */ if (ich->type ==ICMP_DEST_UNREACH && ich->code ==ICMP_FRAG_NEEDED ) -printk ("MTU=%u " ,ntohs (ich->un.frag.mtu)); +sb_add (m,"MTU=%u " ,ntohs (ich->un.frag.mtu)); }break ; }
@@ -292,19 +291,19 @@ static void dump_packet(const struct nf_loginfo *info,break ;/* Max length: 9 "PROTO=AH " */ -printk ("PROTO=AH " ); +sb_add (m,"PROTO=AH " );/* Max length: 25 "INCOMPLETE [65535 bytes] " */ ah =skb_header_pointer (skb, iphoff+ih->ihl*4 ,sizeof (_ahdr), &_ahdr);if (ah ==NULL ) { -printk ("INCOMPLETE [%u bytes] " , +sb_add (m,"INCOMPLETE [%u bytes] " , skb->len - iphoff - ih->ihl*4 );break ; }/* Length: 15 "SPI=0xF1234567 " */ -printk ("SPI=0x%x " ,ntohl (ah->spi)); +sb_add (m,"SPI=0x%x " ,ntohl (ah->spi));break ; }case IPPROTO_ESP : {
@@ -312,7 +311,7 @@ static void dump_packet(const struct nf_loginfo *info,const struct ip_esp_hdr *eh;/* Max length: 10 "PROTO=ESP " */ -printk ("PROTO=ESP " ); +sb_add (m,"PROTO=ESP " );if (ntohs (ih->frag_off) &IP_OFFSET )break ;
@@ -321,25 +320,25 @@ static void dump_packet(const struct nf_loginfo *info, eh =skb_header_pointer (skb, iphoff+ih->ihl*4 ,sizeof (_esph), &_esph);if (eh ==NULL ) { -printk ("INCOMPLETE [%u bytes] " , +sb_add (m,"INCOMPLETE [%u bytes] " , skb->len - iphoff - ih->ihl*4 );break ; }/* Length: 15 "SPI=0xF1234567 " */ -printk ("SPI=0x%x " ,ntohl (eh->spi)); +sb_add (m,"SPI=0x%x " ,ntohl (eh->spi));break ; }/* Max length: 10 "PROTO 255 " */ default : -printk ("PROTO=%u " , ih->protocol); +sb_add (m,"PROTO=%u " , ih->protocol); }/* Max length: 15 "UID=4294967295 " */ if ((logflags &IPT_LOG_UID ) && !iphoff && skb->sk) {read_lock_bh (&skb->sk->sk_callback_lock);if (skb->sk->sk_socket && skb->sk->sk_socket->file) -printk ("UID=%u GID=%u " , +sb_add (m,"UID=%u GID=%u " , skb->sk->sk_socket->file->f_cred->fsuid, skb->sk->sk_socket->file->f_cred->fsgid);read_unlock_bh (&skb->sk->sk_callback_lock);
@@ -347,7 +346,7 @@ static void dump_packet(const struct nf_loginfo *info,/* Max length: 16 "MARK=0xFFFFFFFF " */ if (!iphoff && skb->mark) -printk ("MARK=0x%x " , skb->mark); +sb_add (m,"MARK=0x%x " , skb->mark);/* Proto Max log string length */ /* IP: 40+46+6+11+127 = 230 */
@@ -364,7 +363,8 @@ static void dump_packet(const struct nf_loginfo *info,/* maxlen = 230+ 91 + 230 + 252 = 803 */ } -static void dump_mac_header (const struct nf_loginfo *info, +static void dump_mac_header (struct sbuff *m, +const struct nf_loginfo *info,const struct sk_buff *skb) {struct net_device *dev = skb->dev;
@@ -378,7 +378,7 @@ static void dump_mac_header(const struct nf_loginfo *info,switch (dev->type) {case ARPHRD_ETHER : -printk ("MACSRC=%pM MACDST=%pM MACPROTO=%04x " , +sb_add (m,"MACSRC=%pM MACDST=%pM MACPROTO=%04x " ,eth_hdr (skb)->h_source,eth_hdr (skb)->h_dest,ntohs (eth_hdr (skb)->h_proto));return ;
@@ -387,17 +387,17 @@ static void dump_mac_header(const struct nf_loginfo *info, } fallback: -printk ("MAC=" ); +sb_add (m,"MAC=" );if (dev->hard_header_len && skb->mac_header != skb->network_header) {const unsigned char *p =skb_mac_header (skb);unsigned int i; -printk ("%02x" , *p++); +sb_add (m,"%02x" , *p++);for (i =1 ; i < dev->hard_header_len; i++, p++) -printk (":%02x" , *p); +sb_add (m,":%02x" , *p); } -printk (" " ); +sb_add (m," " ); }static struct nf_loginfo default_loginfo = {
@@ -419,11 +419,12 @@ ipt_log_packet(u_int8_t pf,const struct nf_loginfo *loginfo, const char *prefix) { + struct sbuff *m = sb_open(); +if (!loginfo) loginfo = &default_loginfo; -spin_lock_bh (&log_lock); -printk ("<%d>%sIN=%s OUT=%s " , loginfo->u.log.level, +sb_add (m,"<%d>%sIN=%s OUT=%s " , loginfo->u.log.level, prefix, in ? in->name :"" , out ? out->name :"" );
@@ -434,20 +435,20 @@ ipt_log_packet(u_int8_t pf, physindev = skb->nf_bridge->physindev;if (physindev && in != physindev) -printk ("PHYSIN=%s " , physindev->name); +sb_add (m,"PHYSIN=%s " , physindev->name); physoutdev = skb->nf_bridge->physoutdev;if (physoutdev && out != physoutdev) -printk ("PHYSOUT=%s " , physoutdev->name); +sb_add (m,"PHYSOUT=%s " , physoutdev->name); }#endif /* MAC logging for input path only. */ if (in && !out) -dump_mac_header (loginfo, skb); +dump_mac_header (m, loginfo, skb); + +dump_packet (m, loginfo, skb,0 ); -dump_packet (loginfo, skb,0 ); -printk ("\n" ); -spin_unlock_bh (&log_lock); +sb_close (m); } static unsigned int
net/ipv6/netfilter/ip6t_LOG.c +79 -78
417 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 29/72 netfilter: remove duplicated include
In reply to [email protected]From: Nicolas Kaiser <[email protected]>
Remove duplicated include.
--- net/netfilter/xt_ipvs.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
net/netfilter/xt_ipvs.c +0 -1
@@ -16,7 +16,6 @@#include <linux/ip_vs.h> #include <linux/types.h> #include <linux/netfilter/x_tables.h> -#include <linux/netfilter/x_tables.h> #include <linux/netfilter/xt_ipvs.h> #include <net/netfilter/nf_conntrack.h>
Signature · 1 line
1.7.1
PATCH 30/72 netfilter: unregister nf hooks, matches and targets in the reverse order
In reply to [email protected]From: Changli Gao <[email protected]>
Since we register nf hooks, matches and targets in order, we'd better unregister them in the reverse order.
--- net/netfilter/core.c | 6 ++---- net/netfilter/x_tables.c | 12 ++++-------- 2 files changed, 6 insertions(+), 12 deletions(-)
net/netfilter/core.c +2 -4
@@ -105,10 +105,8 @@ EXPORT_SYMBOL(nf_register_hooks);void nf_unregister_hooks (struct nf_hook_ops *reg,unsigned int n) { -unsigned int i; - -for (i =0 ; i < n; i++) -nf_unregister_hook (®[i]); +while (n-- >0 ) +nf_unregister_hook (®[n]); }EXPORT_SYMBOL (nf_unregister_hooks);
net/netfilter/x_tables.c +4 -8
@@ -116,10 +116,8 @@ EXPORT_SYMBOL(xt_register_targets);void xt_unregister_targets (struct xt_target *target,unsigned int n) { -unsigned int i; - -for (i =0 ; i < n; i++) -xt_unregister_target (&target[i]); +while (n-- >0 ) +xt_unregister_target (&target[n]); }EXPORT_SYMBOL (xt_unregister_targets);
@@ -174,10 +172,8 @@ EXPORT_SYMBOL(xt_register_matches);void xt_unregister_matches (struct xt_match *match,unsigned int n) { -unsigned int i; - -for (i =0 ; i < n; i++) -xt_unregister_match (&match[i]); +while (n-- >0 ) +xt_unregister_match (&match[n]); }EXPORT_SYMBOL (xt_unregister_matches);
Signature · 1 line
1.7.1
PATCH 31/72 netfilter: add missing xt_log.h file
In reply to [email protected]From: Patrick McHardy <[email protected]>
Forgot to add xt_log.h in commit a8defca0 (netfilter: ipt_LOG:
add bufferisation to call printk() once)
--- include/net/netfilter/xt_log.h | 54 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) create mode 100644 include/net/netfilter/xt_log.h
include/net/netfilter/xt_log.h new file +54 -0
@@ -0,0 +1,54 @@ +#define S_SIZE (1024 - (sizeof(unsigned int) + 1)) + +struct sbuff { +unsigned int count; +char buf[S_SIZE +1 ]; +}; +static struct sbuff emergency, *emergency_ptr = &emergency; + +static int sb_add (struct sbuff *m,const char *f, ...) +{ +va_list args; +int len; + +if (likely (m->count <S_SIZE )) { +va_start (args, f); + len =vsnprintf (m->buf + m->count,S_SIZE - m->count, f, args); +va_end (args); +if (likely (m->count + len <S_SIZE )) { + m->count += len; +return 0 ; + } + } + m->count =S_SIZE ; + printk_once(KERN_ERR KBUILD_MODNAME " please increase S_SIZE\n"); +return -1 ; +} + +static struct sbuff *sb_open (void ) +{ +struct sbuff *m =kmalloc (sizeof (*m),GFP_ATOMIC ); + +if (unlikely (!m)) { +local_bh_disable (); +do { + m =xchg (&emergency_ptr,NULL ); + }while (!m); + } + m->count =0 ; +return m; +} + +static void sb_close (struct sbuff *m) +{ + m->buf[m->count] =0 ; +printk ("%s\n" , m->buf); + +if (likely (m != &emergency)) +kfree (m); +else { +xchg (&emergency_ptr, m); +local_bh_enable (); + } +} +
Signature · 1 line
1.7.1
PATCH 32/72 netfilter: xtables: resolve indirect macros 1/3
In reply to [email protected]From: Jan Engelhardt <[email protected]>
Many of the used macros are just there for userspace compatibility. Substitute the in-kernel code to directly use the terminal macro and stuff the defines into #ifndef __KERNEL__ sections.
--- include/linux/netfilter_arp/arp_tables.h | 10 ++++++---- include/linux/netfilter_ipv4/ip_tables.h | 10 ++++++---- include/linux/netfilter_ipv6/ip6_tables.h | 11 ++++++----- net/ipv4/netfilter/arp_tables.c | 10 +++++----- net/ipv4/netfilter/ip_tables.c | 12 ++++++------ net/ipv6/netfilter/ip6_tables.c | 12 ++++++------ 6 files changed, 35 insertions(+), 30 deletions(-)
include/linux/netfilter_arp/arp_tables.h +6 -4
@@ -21,8 +21,10 @@#include <linux/netfilter/x_tables.h> +#ifndef __KERNEL__#define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN#define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN +#endif #define ARPT_DEV_ADDR_LEN_MAX 16
@@ -134,7 +136,7 @@ struct arpt_entry/* The argument to ARPT_SO_GET_INFO */ struct arpt_getinfo {/* Which table: caller fills this in. */ -char name[ARPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* Kernel fills these in. */ /* Which hook entry points are valid: bitmask */
@@ -156,7 +158,7 @@ struct arpt_getinfo {/* The argument to ARPT_SO_SET_REPLACE. */ struct arpt_replace {/* Which table. */ -char name[ARPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* Which hook entry points are valid: bitmask. You can't change this. */
@@ -191,7 +193,7 @@ struct arpt_replace {/* The argument to ARPT_SO_GET_ENTRIES. */ struct arpt_get_entries {/* Which table: user fills this in. */ -char name[ARPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* User fills this in: total entry size. */ unsigned int size;
@@ -230,7 +232,7 @@ struct arpt_standard {struct arpt_error_target {struct arpt_entry_target target; -char errorname[ARPT_FUNCTION_MAXNAMELEN ]; +char errorname[XT_FUNCTION_MAXNAMELEN ]; };struct arpt_error {
include/linux/netfilter_ipv4/ip_tables.h +6 -4
@@ -27,12 +27,14 @@#include <linux/netfilter/x_tables.h> +#ifndef __KERNEL__#define IPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN#define IPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN#define ipt_match xt_match#define ipt_target xt_target#define ipt_table xt_table#define ipt_get_revision xt_get_revision +#endif /* Yes, Virginia, you have to zero the padding. */ struct ipt_ip {
@@ -146,7 +148,7 @@ struct ipt_icmp {/* The argument to IPT_SO_GET_INFO */ struct ipt_getinfo {/* Which table: caller fills this in. */ -char name[IPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* Kernel fills these in. */ /* Which hook entry points are valid: bitmask */
@@ -168,7 +170,7 @@ struct ipt_getinfo {/* The argument to IPT_SO_SET_REPLACE. */ struct ipt_replace {/* Which table. */ -char name[IPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* Which hook entry points are valid: bitmask. You can't change this. */
@@ -202,7 +204,7 @@ struct ipt_replace {/* The argument to IPT_SO_GET_ENTRIES. */ struct ipt_get_entries {/* Which table: user fills this in. */ -char name[IPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* User fills this in: total entry size. */ unsigned int size;
@@ -254,7 +256,7 @@ struct ipt_standard {struct ipt_error_target {struct ipt_entry_target target; -char errorname[IPT_FUNCTION_MAXNAMELEN ]; +char errorname[XT_FUNCTION_MAXNAMELEN ]; };struct ipt_error {
include/linux/netfilter_ipv6/ip6_tables.h +6 -5
@@ -27,13 +27,14 @@#include <linux/netfilter/x_tables.h> +#ifndef __KERNEL__#define IP6T_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN#define IP6T_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN -#define ip6t_match xt_match#define ip6t_target xt_target#define ip6t_table xt_table#define ip6t_get_revision xt_get_revision +#endif /* Yes, Virginia, you have to zero the padding. */ struct ip6t_ip6 {
@@ -117,7 +118,7 @@ struct ip6t_standard {struct ip6t_error_target {struct ip6t_entry_target target; -char errorname[IP6T_FUNCTION_MAXNAMELEN ]; +char errorname[XT_FUNCTION_MAXNAMELEN ]; };struct ip6t_error {
@@ -203,7 +204,7 @@ struct ip6t_icmp {/* The argument to IP6T_SO_GET_INFO */ struct ip6t_getinfo {/* Which table: caller fills this in. */ -char name[IP6T_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* Kernel fills these in. */ /* Which hook entry points are valid: bitmask */
@@ -225,7 +226,7 @@ struct ip6t_getinfo {/* The argument to IP6T_SO_SET_REPLACE. */ struct ip6t_replace {/* Which table. */ -char name[IP6T_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* Which hook entry points are valid: bitmask. You can't change this. */
@@ -259,7 +260,7 @@ struct ip6t_replace {/* The argument to IP6T_SO_GET_ENTRIES. */ struct ip6t_get_entries {/* Which table: user fills this in. */ -char name[IP6T_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];/* User fills this in: total entry size. */ unsigned int size;
net/ipv4/netfilter/arp_tables.c +5 -5
@@ -895,7 +895,7 @@ static int compat_table_info(const struct xt_table_info *info,static int get_info (struct net *net,void __user *user,const int *len,int compat) { -char name[ARPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];struct xt_table *t;int ret;
@@ -908,7 +908,7 @@ static int get_info(struct net *net, void __user *user,if (copy_from_user (name, user,sizeof (name)) !=0 )return -EFAULT ; - name[ARPT_TABLE_MAXNAMELEN -1 ] ='\0' ; + name[XT_TABLE_MAXNAMELEN -1 ] ='\0' ;#ifdef CONFIG_COMPAT if (compat)xt_compat_lock (NFPROTO_ARP );
@@ -1474,7 +1474,7 @@ out_unlock: }struct compat_arpt_replace { -char name[ARPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];u32 valid_hooks;u32 num_entries;u32 size;
@@ -1628,7 +1628,7 @@ static int compat_copy_entries_to_user(unsigned int total_size, }struct compat_arpt_get_entries { -char name[ARPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];compat_uint_t size;struct compat_arpt_entry entrytable[0 ]; };
@@ -1840,7 +1840,7 @@ static struct xt_target arpt_builtin_tg[] __read_mostly = { { .name = ARPT_ERROR_TARGET, .target = arpt_error, - .targetsize = ARPT_FUNCTION_MAXNAMELEN, + .targetsize = XT_FUNCTION_MAXNAMELEN, .family = NFPROTO_ARP, }, };
net/ipv4/netfilter/ip_tables.c +6 -6
@@ -1092,7 +1092,7 @@ static int compat_table_info(const struct xt_table_info *info,static int get_info (struct net *net,void __user *user,const int *len,int compat) { -char name[IPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];struct xt_table *t;int ret;
@@ -1105,7 +1105,7 @@ static int get_info(struct net *net, void __user *user,if (copy_from_user (name, user,sizeof (name)) !=0 )return -EFAULT ; - name[IPT_TABLE_MAXNAMELEN -1 ] ='\0' ; + name[XT_TABLE_MAXNAMELEN -1 ] ='\0' ;#ifdef CONFIG_COMPAT if (compat)xt_compat_lock (AF_INET );
@@ -1400,7 +1400,7 @@ do_add_counters(struct net *net, const void __user *user, #ifdef CONFIG_COMPAT struct compat_ipt_replace { - char name[IPT_TABLE_MAXNAMELEN]; + char name[XT_TABLE_MAXNAMELEN]; u32 valid_hooks; u32 num_entries; u32 size;
@@ -1884,7 +1884,7 @@ compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, }struct compat_ipt_get_entries { -char name[IPT_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];compat_uint_t size;struct compat_ipt_entry entrytable[0 ]; };
@@ -2039,7 +2039,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)case IPT_SO_GET_REVISION_MATCH :case IPT_SO_GET_REVISION_TARGET : { -struct ipt_get_revision rev; +struct xt_get_revision rev;int target;if (*len !=sizeof (rev)) {
@@ -2188,7 +2188,7 @@ static struct xt_target ipt_builtin_tg[] __read_mostly = { { .name = IPT_ERROR_TARGET, .target = ipt_error, - .targetsize = IPT_FUNCTION_MAXNAMELEN, + .targetsize = XT_FUNCTION_MAXNAMELEN, .family = NFPROTO_IPV4, }, };
net/ipv6/netfilter/ip6_tables.c +6 -6
@@ -1105,7 +1105,7 @@ static int compat_table_info(const struct xt_table_info *info,static int get_info (struct net *net,void __user *user,const int *len,int compat) { -char name[IP6T_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];struct xt_table *t;int ret;
@@ -1118,7 +1118,7 @@ static int get_info(struct net *net, void __user *user,if (copy_from_user (name, user,sizeof (name)) !=0 )return -EFAULT ; - name[IP6T_TABLE_MAXNAMELEN -1 ] ='\0' ; + name[XT_TABLE_MAXNAMELEN -1 ] ='\0' ;#ifdef CONFIG_COMPAT if (compat)xt_compat_lock (AF_INET6 );
@@ -1415,7 +1415,7 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len, #ifdef CONFIG_COMPAT struct compat_ip6t_replace { - char name[IP6T_TABLE_MAXNAMELEN]; + char name[XT_TABLE_MAXNAMELEN]; u32 valid_hooks; u32 num_entries; u32 size;
@@ -1899,7 +1899,7 @@ compat_do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user, }struct compat_ip6t_get_entries { -char name[IP6T_TABLE_MAXNAMELEN ]; +char name[XT_TABLE_MAXNAMELEN ];compat_uint_t size;struct compat_ip6t_entry entrytable[0 ]; };
@@ -2054,7 +2054,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)case IP6T_SO_GET_REVISION_MATCH :case IP6T_SO_GET_REVISION_TARGET : { -struct ip6t_get_revision rev; +struct xt_get_revision rev;int target;if (*len !=sizeof (rev)) {
@@ -2203,7 +2203,7 @@ static struct xt_target ip6t_builtin_tg[] __read_mostly = { { .name = IP6T_ERROR_TARGET, .target = ip6t_error, - .targetsize = IP6T_FUNCTION_MAXNAMELEN, + .targetsize = XT_FUNCTION_MAXNAMELEN, .family = NFPROTO_IPV6, }, };
Signature · 1 line
1.7.1
PATCH 33/72 netfilter: xtables: resolve indirect macros 2/3
In reply to [email protected]From: Jan Engelhardt <[email protected]>
--- include/linux/netfilter_arp/arp_tables.h | 15 ++++---- include/linux/netfilter_ipv4/ip_tables.h | 18 ++++----- include/linux/netfilter_ipv6/ip6_tables.h | 20 +++++------ net/ipv4/netfilter/arp_tables.c | 38 ++++++++++---------- net/ipv4/netfilter/ip_tables.c | 54 ++++++++++++++-------------- net/ipv6/netfilter/ip6_tables.c | 54 ++++++++++++++-------------- net/sched/act_ipt.c | 12 +++--- 7 files changed, 103 insertions(+), 108 deletions(-)
include/linux/netfilter_arp/arp_tables.h +7 -8
@@ -24,6 +24,8 @@#ifndef __KERNEL__#define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN#define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN +#define arpt_entry_target xt_entry_target +#define arpt_standard_target xt_standard_target#endif #define ARPT_DEV_ADDR_LEN_MAX 16
@@ -65,9 +67,6 @@ struct arpt_arp {u_int16_t invflags; }; -#define arpt_entry_target xt_entry_target -#define arpt_standard_target xt_standard_target -/* Values for "flag" field in struct arpt_ip (general arp structure). * No flags defined yet. */
@@ -208,7 +207,7 @@ struct arpt_get_entries {#define ARPT_ERROR_TARGET XT_ERROR_TARGET/* Helper functions */ -static __inline__struct arpt_entry_target *arpt_get_target (struct arpt_entry *e) +static __inline__struct xt_entry_target *arpt_get_target (struct arpt_entry *e) {return (void *)e + e->target_offset; }
@@ -227,11 +226,11 @@ static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e/* Standard entry. */ struct arpt_standard {struct arpt_entry entry; -struct arpt_standard_target target; +struct xt_standard_target target; };struct arpt_error_target { -struct arpt_entry_target target; +struct xt_entry_target target;char errorname[XT_FUNCTION_MAXNAMELEN ]; };
@@ -250,7 +249,7 @@ struct arpt_error { { \ .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \ .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \ - sizeof(struct arpt_standard_target)), \ + sizeof(struct xt_standard_target)), \ .target.verdict = -(__verdict) - 1, \ }
@@ -287,7 +286,7 @@ struct compat_arpt_entry {unsigned char elems[0 ]; }; -static inline struct arpt_entry_target * +static inline struct xt_entry_target *compat_arpt_get_target (struct compat_arpt_entry *e) {return (void *)e + e->target_offset;
include/linux/netfilter_ipv4/ip_tables.h +8 -10
@@ -34,6 +34,10 @@#define ipt_target xt_target#define ipt_table xt_table#define ipt_get_revision xt_get_revision +#define ipt_entry_match xt_entry_match +#define ipt_entry_target xt_entry_target +#define ipt_standard_target xt_standard_target +#define ipt_counters xt_counters#endif /* Yes, Virginia, you have to zero the padding. */
@@ -54,12 +58,6 @@ struct ipt_ip {u_int8_t invflags; }; -#define ipt_entry_match xt_entry_match -#define ipt_entry_target xt_entry_target -#define ipt_standard_target xt_standard_target - -#define ipt_counters xt_counters -/* Values for "flag" field in struct ipt_ip (general ip structure). */ #define IPT_F_FRAG 0x01/* Set if rule is a fragment rule */ #define IPT_F_GOTO 0x02/* Set if jump is a goto */
@@ -219,7 +217,7 @@ struct ipt_get_entries {#define IPT_ERROR_TARGET XT_ERROR_TARGET/* Helper functions */ -static __inline__struct ipt_entry_target * +static __inline__struct xt_entry_target *ipt_get_target (struct ipt_entry *e) {return (void *)e + e->target_offset;
@@ -251,11 +249,11 @@ extern void ipt_unregister_table(struct net *net, struct xt_table *table);/* Standard entry. */ struct ipt_standard {struct ipt_entry entry; -struct ipt_standard_target target; +struct xt_standard_target target; };struct ipt_error_target { -struct ipt_entry_target target; +struct xt_entry_target target;char errorname[XT_FUNCTION_MAXNAMELEN ]; };
@@ -309,7 +307,7 @@ struct compat_ipt_entry { };/* Helper functions */ -static inline struct ipt_entry_target * +static inline struct xt_entry_target *compat_ipt_get_target (struct compat_ipt_entry *e) {return (void *)e + e->target_offset;
include/linux/netfilter_ipv6/ip6_tables.h +9 -11
@@ -34,6 +34,10 @@#define ip6t_target xt_target#define ip6t_table xt_table#define ip6t_get_revision xt_get_revision +#define ip6t_entry_match xt_entry_match +#define ip6t_entry_target xt_entry_target +#define ip6t_standard_target xt_standard_target +#define ip6t_counters xt_counters#endif /* Yes, Virginia, you have to zero the padding. */
@@ -63,12 +67,6 @@ struct ip6t_ip6 {u_int8_t invflags; }; -#define ip6t_entry_match xt_entry_match -#define ip6t_entry_target xt_entry_target -#define ip6t_standard_target xt_standard_target - -#define ip6t_counters xt_counters -/* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */ #define IP6T_F_PROTO 0x01/* Set if rule cares about upper protocols */
@@ -113,11 +111,11 @@ struct ip6t_entry {/* Standard entry */ struct ip6t_standard {struct ip6t_entry entry; -struct ip6t_standard_target target; +struct xt_standard_target target; };struct ip6t_error_target { -struct ip6t_entry_target target; +struct xt_entry_target target;char errorname[XT_FUNCTION_MAXNAMELEN ]; };
@@ -136,7 +134,7 @@ struct ip6t_error { { \ .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_standard)), \ .target = XT_TARGET_INIT(IP6T_STANDARD_TARGET, \ - sizeof(struct ip6t_standard_target)), \ + sizeof(struct xt_standard_target)), \ .target.verdict = -(__verdict) - 1, \ }
@@ -275,7 +273,7 @@ struct ip6t_get_entries {#define IP6T_ERROR_TARGET XT_ERROR_TARGET/* Helper functions */ -static __inline__struct ip6t_entry_target * +static __inline__struct xt_entry_target *ip6t_get_target (struct ip6t_entry *e) {return (void *)e + e->target_offset;
@@ -332,7 +330,7 @@ struct compat_ip6t_entry {unsigned char elems[0 ]; }; -static inline struct ip6t_entry_target * +static inline struct xt_entry_target *compat_ip6t_get_target (struct compat_ip6t_entry *e) {return (void *)e + e->target_offset;
net/ipv4/netfilter/arp_tables.c +19 -19
@@ -228,7 +228,7 @@ arpt_error(struct sk_buff *skb, const struct xt_action_param *par)return NF_DROP ; } -static inline const struct arpt_entry_target * +static inline const struct xt_entry_target *arpt_get_target_c (const struct arpt_entry *e) {return arpt_get_target ((struct arpt_entry *)e);
@@ -282,7 +282,7 @@ unsigned int arpt_do_table(struct sk_buff *skb, arp =arp_hdr (skb); do { - const struct arpt_entry_target *t; + const struct xt_entry_target *t; if (!arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) { e = arpt_next_entry(e);
@@ -297,7 +297,7 @@ unsigned int arpt_do_table(struct sk_buff *skb,if (!t->u.kernel.target->target) {int v; - v = ((struct arpt_standard_target *)t)->verdict; + v = ((struct xt_standard_target *)t)->verdict;if (v <0 ) {/* Pop from stack? */ if (v !=ARPT_RETURN ) {
@@ -377,7 +377,7 @@ static int mark_source_chains(const struct xt_table_info *newinfo, e->counters.pcnt = pos;for (;;) { -const struct arpt_standard_target *t +const struct xt_standard_target *t = (void *)arpt_get_target_c (e);int visited = e->comefrom & (1 << hook);
@@ -464,14 +464,14 @@ static int mark_source_chains(const struct xt_table_info *newinfo,static inline int check_entry (const struct arpt_entry *e,const char *name) { -const struct arpt_entry_target *t; +const struct xt_entry_target *t;if (!arp_checkentry (&e->arp)) {duprintf ("arp_tables: arp check failed %p %s.\n" , e, name);return -EINVAL ; } -if (e->target_offset +sizeof (struct arpt_entry_target ) > e->next_offset) +if (e->target_offset +sizeof (struct xt_entry_target ) > e->next_offset)return -EINVAL ; t =arpt_get_target_c (e);
@@ -483,7 +483,7 @@ static inline int check_entry(const struct arpt_entry *e, const char *name)static inline int check_target (struct arpt_entry *e,const char *name) { -struct arpt_entry_target *t =arpt_get_target (e); +struct xt_entry_target *t =arpt_get_target (e);int ret;struct xt_tgchk_param par = { .table = name,
@@ -506,7 +506,7 @@ static inline int check_target(struct arpt_entry *e, const char *name)static inline int find_check_entry (struct arpt_entry *e,const char *name,unsigned int size) { -struct arpt_entry_target *t; +struct xt_entry_target *t;struct xt_target *target;int ret;
@@ -536,7 +536,7 @@ out:static bool check_underflow (const struct arpt_entry *e) { -const struct arpt_entry_target *t; +const struct xt_entry_target *t;unsigned int verdict;if (!unconditional (&e->arp))
@@ -544,7 +544,7 @@ static bool check_underflow(const struct arpt_entry *e) t =arpt_get_target_c (e);if (strcmp (t->u.user.name,XT_STANDARD_TARGET ) !=0 )return false; - verdict = ((struct arpt_standard_target *)t)->verdict; + verdict = ((struct xt_standard_target *)t)->verdict; verdict = -verdict -1 ;return verdict ==NF_DROP || verdict ==NF_ACCEPT ; }
@@ -566,7 +566,7 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e, }if (e->next_offset - <sizeof (struct arpt_entry ) +sizeof (struct arpt_entry_target )) { + <sizeof (struct arpt_entry ) +sizeof (struct xt_entry_target )) {duprintf ("checking: element %p size %u\n" , e, e->next_offset);return -EINVAL ;
@@ -598,7 +598,7 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,static inline void cleanup_entry (struct arpt_entry *e) {struct xt_tgdtor_param par; -struct arpt_entry_target *t; +struct xt_entry_target *t; t =arpt_get_target (e); par.target = t->u.kernel.target;
@@ -794,7 +794,7 @@ static int copy_entries_to_user(unsigned int total_size,/* FIXME: use iterator macros --RR */ /* ... then go back and fix counters and names */ for (off =0 , num =0 ; off < total_size; off += e->next_offset, num++){ -const struct arpt_entry_target *t; +const struct xt_entry_target *t; e = (struct arpt_entry *)(loc_cpu_entry + off); if (copy_to_user(userptr + off
@@ -807,7 +807,7 @@ static int copy_entries_to_user(unsigned int total_size, t =arpt_get_target_c (e);if (copy_to_user (userptr + off + e->target_offset - + offsetof(struct arpt_entry_target , + + offsetof(struct xt_entry_target , u.user.name), t->u.kernel.target->name, strlen(t->u.kernel.target->name)+1) != 0) {
@@ -844,7 +844,7 @@ static int compat_calc_entry(const struct arpt_entry *e,const struct xt_table_info *info, const void *base, struct xt_table_info *newinfo) { - const struct arpt_entry_target *t; + const struct xt_entry_target *t;unsigned int entry_offset;int off, i, ret;
@@ -1204,7 +1204,7 @@ static int do_add_counters(struct net *net, const void __user *user,#ifdef CONFIG_COMPAT static inline void compat_release_entry (struct compat_arpt_entry *e) { -struct arpt_entry_target *t; +struct xt_entry_target *t; t =compat_arpt_get_target (e);module_put (t->u.kernel.target->me);
@@ -1220,7 +1220,7 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,const unsigned int *underflows, const char *name) { - struct arpt_entry_target *t; + struct xt_entry_target *t;struct xt_target *target;unsigned int entry_offset;int ret, off, h;
@@ -1288,7 +1288,7 @@ compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr, unsigned int *size, const char *name, struct xt_table_info *newinfo, unsigned char *base) { - struct arpt_entry_target *t; + struct xt_entry_target *t;struct xt_target *target;struct arpt_entry *de;unsigned int origsize;
@@ -1567,7 +1567,7 @@ static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr, struct xt_counters *counters, unsigned int i) { -struct arpt_entry_target *t; +struct xt_entry_target *t;struct compat_arpt_entry __user *ce;u_int16_t target_offset, next_offset;compat_uint_t origsize;
net/ipv4/netfilter/ip_tables.c +27 -27
210 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +27 -27
210 lines not on this page · raw message
net/sched/act_ipt.c +6 -6
@@ -39,7 +39,7 @@ static struct tcf_hashinfo ipt_hash_info = { .lock = &ipt_lock, }; -static int ipt_init_target (struct ipt_entry_target *t,char *table,unsigned int hook) +static int ipt_init_target (struct xt_entry_target *t,char *table,unsigned int hook) {struct xt_tgchk_param par;struct xt_target *target;
@@ -66,7 +66,7 @@ static int ipt_init_target(struct ipt_entry_target *t, char *table, unsigned intreturn 0 ; } -static void ipt_destroy_target (struct ipt_entry_target *t) +static void ipt_destroy_target (struct xt_entry_target *t) {struct xt_tgdtor_param par = { .target = t->u.kernel.target,
@@ -99,7 +99,7 @@ static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = { [TCA_IPT_TABLE] = { .type = NLA_STRING, .len = IFNAMSIZ }, [TCA_IPT_HOOK] = { .type = NLA_U32 }, [TCA_IPT_INDEX] = { .type = NLA_U32 }, - [TCA_IPT_TARG] = { .len = sizeof(struct ipt_entry_target) }, + [TCA_IPT_TARG] = { .len = sizeof(struct xt_entry_target) }, }; static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est,
@@ -108,7 +108,7 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est,struct nlattr *tb[TCA_IPT_MAX +1 ];struct tcf_ipt *ipt;struct tcf_common *pc; -struct ipt_entry_target *td, *t; +struct xt_entry_target *td, *t;char *tname;int ret =0 , err;u32 hook =0 ;
@@ -126,7 +126,7 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est,if (tb[TCA_IPT_TARG ] ==NULL )return -EINVAL ; - td = (struct ipt_entry_target *)nla_data (tb[TCA_IPT_TARG ]); + td = (struct xt_entry_target *)nla_data (tb[TCA_IPT_TARG ]);if (nla_len (tb[TCA_IPT_TARG ]) < td->u.target_size)return -EINVAL ;
@@ -249,7 +249,7 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, int {unsigned char *b =skb_tail_pointer (skb);struct tcf_ipt *ipt = a->priv; -struct ipt_entry_target *t; +struct xt_entry_target *t;struct tcf_t tm;struct tc_cnt c;
Signature · 1 line
1.7.1
PATCH 34/72 netfilter: xtables: resolve indirect macros 3/3
In reply to [email protected]From: Jan Engelhardt <[email protected]>
--- include/linux/netfilter_arp/arp_tables.h | 33 ++++---------- include/linux/netfilter_ipv4/ip_tables.h | 69 +++++++++++++--------------- include/linux/netfilter_ipv6/ip6_tables.h | 69 ++++++++++------------------ net/ipv4/netfilter/arp_tables.c | 14 +++--- net/ipv4/netfilter/arpt_mangle.c | 2 +- net/ipv4/netfilter/ip_tables.c | 18 ++++---- net/ipv6/netfilter/ip6_tables.c | 18 ++++---- net/sched/act_ipt.c | 2 +- 8 files changed, 94 insertions(+), 131 deletions(-)
include/linux/netfilter_arp/arp_tables.h +10 -23
@@ -26,6 +26,14 @@#define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN#define arpt_entry_target xt_entry_target#define arpt_standard_target xt_standard_target +#define ARPT_CONTINUE XT_CONTINUE +#define ARPT_RETURN XT_RETURN +#define arpt_counters_info xt_counters_info +#define arpt_counters xt_counters +#define ARPT_STANDARD_TARGET XT_STANDARD_TARGET +#define ARPT_ERROR_TARGET XT_ERROR_TARGET +#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ + XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args)#endif #define ARPT_DEV_ADDR_LEN_MAX 16
@@ -126,12 +134,6 @@ struct arpt_entry#define ARPT_SO_GET_REVISION_TARGET (ARPT_BASE_CTL + 3)#define ARPT_SO_GET_MAX (ARPT_SO_GET_REVISION_TARGET) -/* CONTINUE verdict for targets */ -#define ARPT_CONTINUE XT_CONTINUE - -/* For standard target */ -#define ARPT_RETURN XT_RETURN -/* The argument to ARPT_SO_GET_INFO */ struct arpt_getinfo {/* Which table: caller fills this in. */
@@ -185,10 +187,6 @@ struct arpt_replace {struct arpt_entry entries[0 ]; }; -/* The argument to ARPT_SO_ADD_COUNTERS. */ -#define arpt_counters_info xt_counters_info -#define arpt_counters xt_counters -/* The argument to ARPT_SO_GET_ENTRIES. */ struct arpt_get_entries {/* Which table: user fills this in. */
@@ -201,23 +199,12 @@ struct arpt_get_entries {struct arpt_entry entrytable[0 ]; }; -/* Standard return verdict, or do jump. */ -#define ARPT_STANDARD_TARGET XT_STANDARD_TARGET -/* Error verdict. */ -#define ARPT_ERROR_TARGET XT_ERROR_TARGET -/* Helper functions */ static __inline__struct xt_entry_target *arpt_get_target (struct arpt_entry *e) {return (void *)e + e->target_offset; } -#ifndef __KERNEL__ -/* fn returns 0 to continue iteration */ -#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ - XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args) -#endif -/* * Main firewall chains definitions and global var's definitions. */
@@ -248,7 +235,7 @@ struct arpt_error {#define ARPT_STANDARD_INIT (__verdict) \ { \ .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \ - .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \ + .target = XT_TARGET_INIT(XT_STANDARD_TARGET, \ sizeof(struct xt_standard_target)), \ .target.verdict = -(__verdict) - 1, \ }
@@ -256,7 +243,7 @@ struct arpt_error {#define ARPT_ERROR_INIT \ { \ .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_error)), \ - .target = XT_TARGET_INIT(ARPT_ERROR_TARGET, \ + .target = XT_TARGET_INIT(XT_ERROR_TARGET, \ sizeof(struct arpt_error_target)), \ .target.errorname = "ERROR", \ }
include/linux/netfilter_ipv4/ip_tables.h +32 -37
111 lines not on this page · raw message
include/linux/netfilter_ipv6/ip6_tables.h +25 -44
111 lines not on this page · raw message
net/ipv4/netfilter/arp_tables.c +7 -7
@@ -300,7 +300,7 @@ unsigned int arpt_do_table(struct sk_buff *skb, v = ((struct xt_standard_target *)t)->verdict;if (v <0 ) {/* Pop from stack? */ -if (v !=ARPT_RETURN ) { +if (v !=XT_RETURN ) { verdict = (unsigned )(-v) -1 ;break ; }
@@ -332,7 +332,7 @@ unsigned int arpt_do_table(struct sk_buff *skb,/* Target might have changed stuff. */ arp =arp_hdr (skb); -if (verdict ==ARPT_CONTINUE ) +if (verdict ==XT_CONTINUE ) e =arpt_next_entry (e);else /* Verdict */
@@ -392,13 +392,13 @@ static int mark_source_chains(const struct xt_table_info *newinfo,/* Unconditional return/END. */ if ((e->target_offset ==sizeof (struct arpt_entry ) && (strcmp (t->target.u.user.name, -ARPT_STANDARD_TARGET ) ==0 ) && +XT_STANDARD_TARGET ) ==0 ) && t->verdict <0 &&unconditional (&e->arp)) || visited) {unsigned int oldpos, size;if ((strcmp (t->target.u.user.name, -ARPT_STANDARD_TARGET ) ==0 ) && +XT_STANDARD_TARGET ) ==0 ) && t->verdict < -NF_MAX_VERDICT -1 ) { duprintf("mark_source_chains: bad " "negative verdict (%i)\n",
@@ -433,7 +433,7 @@ static int mark_source_chains(const struct xt_table_info *newinfo,int newpos = t->verdict;if (strcmp (t->target.u.user.name, -ARPT_STANDARD_TARGET ) ==0 && +XT_STANDARD_TARGET ) ==0 && newpos >=0 ) {if (newpos > newinfo->size -sizeof (struct arpt_entry )) {
@@ -1828,7 +1828,7 @@ void arpt_unregister_table(struct xt_table *table)/* The built-in targets: standard (NULL) and error. */ static struct xt_target arpt_builtin_tg[]__read_mostly = { { - .name =ARPT_STANDARD_TARGET , + .name =XT_STANDARD_TARGET , .targetsize =sizeof (int ), .family =NFPROTO_ARP , #ifdef CONFIG_COMPAT
@@ -1838,7 +1838,7 @@ static struct xt_target arpt_builtin_tg[] __read_mostly = {#endif }, { - .name = ARPT_ERROR_TARGET, + .name = XT_ERROR_TARGET, .target = arpt_error, .targetsize = XT_FUNCTION_MAXNAMELEN, .family = NFPROTO_ARP,
net/ipv4/netfilter/arpt_mangle.c +1 -1
@@ -63,7 +63,7 @@ static int checkentry(const struct xt_tgchk_param *par)return false;if (mangle->target !=NF_DROP && mangle->target !=NF_ACCEPT && - mangle->target !=ARPT_CONTINUE ) + mangle->target !=XT_CONTINUE )return false;return true; }
net/ipv4/netfilter/ip_tables.c +9 -9
@@ -232,7 +232,7 @@ get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e, {const struct xt_standard_target *t = (void *)ipt_get_target_c (s); -if (strcmp (t->target.u.kernel.target->name,IPT_ERROR_TARGET ) ==0 ) { +if (strcmp (t->target.u.kernel.target->name,XT_ERROR_TARGET ) ==0 ) {/* Head of user chain: ERROR target with chainname */ *chainname = t->target.data; (*rulenum) =0 ;
@@ -241,7 +241,7 @@ get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e,if (s->target_offset ==sizeof (struct ipt_entry ) &&strcmp (t->target.u.kernel.target->name, -IPT_STANDARD_TARGET ) ==0 && +XT_STANDARD_TARGET ) ==0 && t->verdict <0 &&unconditional (&s->ip)) {/* Tail of chains: STANDARD target (return/policy) */
@@ -383,7 +383,7 @@ ipt_do_table(struct sk_buff *skb, v = ((struct xt_standard_target *)t)->verdict;if (v <0 ) {/* Pop from stack? */ -if (v !=IPT_RETURN ) { +if (v !=XT_RETURN ) { verdict = (unsigned )(-v) -1 ;break ; }
@@ -421,7 +421,7 @@ ipt_do_table(struct sk_buff *skb, verdict = t->u.kernel.target->target (skb, &acpar);/* Target might have changed stuff. */ ip =ip_hdr (skb); -if (verdict ==IPT_CONTINUE ) +if (verdict ==XT_CONTINUE ) e =ipt_next_entry (e);else /* Verdict */
@@ -475,13 +475,13 @@ mark_source_chains(const struct xt_table_info *newinfo,/* Unconditional return/END. */ if ((e->target_offset ==sizeof (struct ipt_entry ) && (strcmp (t->target.u.user.name, -IPT_STANDARD_TARGET ) ==0 ) && +XT_STANDARD_TARGET ) ==0 ) && t->verdict <0 &&unconditional (&e->ip)) || visited) {unsigned int oldpos, size;if ((strcmp (t->target.u.user.name, -IPT_STANDARD_TARGET ) ==0 ) && +XT_STANDARD_TARGET ) ==0 ) && t->verdict < -NF_MAX_VERDICT -1 ) { duprintf("mark_source_chains: bad " "negative verdict (%i)\n",
@@ -524,7 +524,7 @@ mark_source_chains(const struct xt_table_info *newinfo,int newpos = t->verdict;if (strcmp (t->target.u.user.name, -IPT_STANDARD_TARGET ) ==0 && +XT_STANDARD_TARGET ) ==0 && newpos >=0 ) {if (newpos > newinfo->size -sizeof (struct ipt_entry )) {
@@ -2176,7 +2176,7 @@ static int icmp_checkentry(const struct xt_mtchk_param *par)static struct xt_target ipt_builtin_tg[]__read_mostly = { { - .name =IPT_STANDARD_TARGET , + .name =XT_STANDARD_TARGET , .targetsize =sizeof (int ), .family =NFPROTO_IPV4 , #ifdef CONFIG_COMPAT
@@ -2186,7 +2186,7 @@ static struct xt_target ipt_builtin_tg[] __read_mostly = {#endif }, { - .name = IPT_ERROR_TARGET, + .name = XT_ERROR_TARGET, .target = ipt_error, .targetsize = XT_FUNCTION_MAXNAMELEN, .family = NFPROTO_IPV4,
net/ipv6/netfilter/ip6_tables.c +9 -9
@@ -262,7 +262,7 @@ get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e, {const struct xt_standard_target *t = (void *)ip6t_get_target_c (s); -if (strcmp (t->target.u.kernel.target->name,IP6T_ERROR_TARGET ) ==0 ) { +if (strcmp (t->target.u.kernel.target->name,XT_ERROR_TARGET ) ==0 ) {/* Head of user chain: ERROR target with chainname */ *chainname = t->target.data; (*rulenum) =0 ;
@@ -271,7 +271,7 @@ get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e,if (s->target_offset ==sizeof (struct ip6t_entry ) &&strcmp (t->target.u.kernel.target->name, -IP6T_STANDARD_TARGET ) ==0 && +XT_STANDARD_TARGET ) ==0 && t->verdict <0 &&unconditional (&s->ipv6)) {/* Tail of chains: STANDARD target (return/policy) */
@@ -406,7 +406,7 @@ ip6t_do_table(struct sk_buff *skb, v = ((struct xt_standard_target *)t)->verdict;if (v <0 ) {/* Pop from stack? */ -if (v !=IP6T_RETURN ) { +if (v !=XT_RETURN ) { verdict = (unsigned )(-v) -1 ;break ; }
@@ -434,7 +434,7 @@ ip6t_do_table(struct sk_buff *skb, acpar.targinfo = t->data; verdict = t->u.kernel.target->target (skb, &acpar); -if (verdict ==IP6T_CONTINUE ) +if (verdict ==XT_CONTINUE ) e =ip6t_next_entry (e);else /* Verdict */
@@ -488,13 +488,13 @@ mark_source_chains(const struct xt_table_info *newinfo,/* Unconditional return/END. */ if ((e->target_offset ==sizeof (struct ip6t_entry ) && (strcmp (t->target.u.user.name, -IP6T_STANDARD_TARGET ) ==0 ) && +XT_STANDARD_TARGET ) ==0 ) && t->verdict <0 &&unconditional (&e->ipv6)) || visited) {unsigned int oldpos, size;if ((strcmp (t->target.u.user.name, -IP6T_STANDARD_TARGET ) ==0 ) && +XT_STANDARD_TARGET ) ==0 ) && t->verdict < -NF_MAX_VERDICT -1 ) { duprintf("mark_source_chains: bad " "negative verdict (%i)\n",
@@ -537,7 +537,7 @@ mark_source_chains(const struct xt_table_info *newinfo,int newpos = t->verdict;if (strcmp (t->target.u.user.name, -IP6T_STANDARD_TARGET ) ==0 && +XT_STANDARD_TARGET ) ==0 && newpos >=0 ) {if (newpos > newinfo->size -sizeof (struct ip6t_entry )) {
@@ -2191,7 +2191,7 @@ static int icmp6_checkentry(const struct xt_mtchk_param *par)/* The built-in targets: standard (NULL) and error. */ static struct xt_target ip6t_builtin_tg[]__read_mostly = { { - .name =IP6T_STANDARD_TARGET , + .name =XT_STANDARD_TARGET , .targetsize =sizeof (int ), .family =NFPROTO_IPV6 , #ifdef CONFIG_COMPAT
@@ -2201,7 +2201,7 @@ static struct xt_target ip6t_builtin_tg[] __read_mostly = {#endif }, { - .name = IP6T_ERROR_TARGET, + .name = XT_ERROR_TARGET, .target = ip6t_error, .targetsize = XT_FUNCTION_MAXNAMELEN, .family = NFPROTO_IPV6,
net/sched/act_ipt.c +1 -1
@@ -230,7 +230,7 @@ static int tcf_ipt(struct sk_buff *skb, struct tc_action *a, result =TC_ACT_SHOT ; ipt->tcf_qstats.drops++;break ; -case IPT_CONTINUE : +case XT_CONTINUE : result =TC_ACT_PIPE ;break ;default :
Signature · 1 line
1.7.1
PATCH 35/72 netfilter: xtables: unify {ip,ip6,arp}t_error_target
In reply to [email protected]From: Jan Engelhardt <[email protected]>
Unification of struct *_error_target was forgotten in v2.6.16-1689-g1e30a01.
--- include/linux/netfilter/x_tables.h | 5 +++++ include/linux/netfilter_arp/arp_tables.h | 10 +++------- include/linux/netfilter_ipv4/ip_tables.h | 10 +++------- include/linux/netfilter_ipv6/ip6_tables.h | 10 +++------- 4 files changed, 14 insertions(+), 21 deletions(-)
include/linux/netfilter/x_tables.h +5 -0
@@ -66,6 +66,11 @@ struct xt_standard_target {int verdict; }; +struct xt_error_target { +struct xt_entry_target target; +char errorname[XT_FUNCTION_MAXNAMELEN ]; +}; +/* The argument to IPT_SO_GET_REVISION_*. Returns highest revision * kernel supports, if >= revision. */ struct xt_get_revision {
include/linux/netfilter_arp/arp_tables.h +3 -7
@@ -26,6 +26,7 @@#define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN#define arpt_entry_target xt_entry_target#define arpt_standard_target xt_standard_target +#define arpt_error_target xt_error_target#define ARPT_CONTINUE XT_CONTINUE#define ARPT_RETURN XT_RETURN#define arpt_counters_info xt_counters_info
@@ -216,14 +217,9 @@ struct arpt_standard {struct xt_standard_target target; }; -struct arpt_error_target { -struct xt_entry_target target; -char errorname[XT_FUNCTION_MAXNAMELEN ]; -}; -struct arpt_error {struct arpt_entry entry; -struct arpt_error_target target; +struct xt_error_target target; };#define ARPT_ENTRY_INIT (__size) \
@@ -244,7 +240,7 @@ struct arpt_error { { \ .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_error)), \ .target = XT_TARGET_INIT(XT_ERROR_TARGET, \ - sizeof(struct arpt_error_target)), \ + sizeof(struct xt_error_target)), \ .target.errorname = "ERROR", \ }
include/linux/netfilter_ipv4/ip_tables.h +3 -7
@@ -37,6 +37,7 @@#define ipt_entry_match xt_entry_match#define ipt_entry_target xt_entry_target#define ipt_standard_target xt_standard_target +#define ipt_error_target xt_error_target#define ipt_counters xt_counters#define IPT_CONTINUE XT_CONTINUE#define IPT_RETURN XT_RETURN
@@ -247,14 +248,9 @@ struct ipt_standard {struct xt_standard_target target; }; -struct ipt_error_target { -struct xt_entry_target target; -char errorname[XT_FUNCTION_MAXNAMELEN ]; -}; -struct ipt_error {struct ipt_entry entry; -struct ipt_error_target target; +struct xt_error_target target; };#define IPT_ENTRY_INIT (__size) \
@@ -275,7 +271,7 @@ struct ipt_error { { \ .entry = IPT_ENTRY_INIT(sizeof(struct ipt_error)), \ .target = XT_TARGET_INIT(XT_ERROR_TARGET, \ - sizeof(struct ipt_error_target)), \ + sizeof(struct xt_error_target)), \ .target.errorname = "ERROR", \ }
include/linux/netfilter_ipv6/ip6_tables.h +3 -7
@@ -37,6 +37,7 @@#define ip6t_entry_match xt_entry_match#define ip6t_entry_target xt_entry_target#define ip6t_standard_target xt_standard_target +#define ip6t_error_target xt_error_target#define ip6t_counters xt_counters#define IP6T_CONTINUE XT_CONTINUE#define IP6T_RETURN XT_RETURN
@@ -137,14 +138,9 @@ struct ip6t_standard {struct xt_standard_target target; }; -struct ip6t_error_target { -struct xt_entry_target target; -char errorname[XT_FUNCTION_MAXNAMELEN ]; -}; -struct ip6t_error {struct ip6t_entry entry; -struct ip6t_error_target target; +struct xt_error_target target; };#define IP6T_ENTRY_INIT (__size) \
@@ -165,7 +161,7 @@ struct ip6t_error { { \ .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_error)), \ .target = XT_TARGET_INIT(XT_ERROR_TARGET, \ - sizeof(struct ip6t_error_target)), \ + sizeof(struct xt_error_target)), \ .target.errorname = "ERROR", \ }
Signature · 1 line
1.7.1
PATCH 36/72 netfilter: xtables: remove unused defines
In reply to [email protected]From: Jan Engelhardt <[email protected]>
--- include/linux/netfilter_arp/arp_tables.h | 4 ---- include/linux/netfilter_ipv4/ip_tables.h | 4 ---- include/linux/netfilter_ipv6/ip6_tables.h | 4 ---- 3 files changed, 0 insertions(+), 12 deletions(-)
include/linux/netfilter_arp/arp_tables.h +0 -4
@@ -255,8 +255,6 @@ extern unsigned int arpt_do_table(struct sk_buff *skb,const struct net_device *out, struct xt_table *table); -#define ARPT_ALIGN (s) XT_ALIGN(s) -#ifdef CONFIG_COMPAT #include <net/compat.h>
@@ -275,8 +273,6 @@ compat_arpt_get_target(struct compat_arpt_entry *e)return (void *)e + e->target_offset; } -#define COMPAT_ARPT_ALIGN (s) COMPAT_XT_ALIGN(s) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _ARPTABLES_H */
include/linux/netfilter_ipv4/ip_tables.h +0 -4
@@ -282,8 +282,6 @@ extern unsigned int ipt_do_table(struct sk_buff *skb,const struct net_device *out, struct xt_table *table); -#define IPT_ALIGN (s) XT_ALIGN(s) -#ifdef CONFIG_COMPAT #include <net/compat.h>
@@ -304,8 +302,6 @@ compat_ipt_get_target(struct compat_ipt_entry *e)return (void *)e + e->target_offset; } -#define COMPAT_IPT_ALIGN (s) COMPAT_XT_ALIGN(s) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _IPTABLES_H */
include/linux/netfilter_ipv6/ip6_tables.h +0 -4
@@ -292,8 +292,6 @@ extern int ip6t_ext_hdr(u8 nexthdr);extern int ipv6_find_hdr (const struct sk_buff *skb,unsigned int *offset,int target,unsigned short *fragoff); -#define IP6T_ALIGN (s) XT_ALIGN(s) -#ifdef CONFIG_COMPAT #include <net/compat.h>
@@ -313,8 +311,6 @@ compat_ip6t_get_target(struct compat_ip6t_entry *e)return (void *)e + e->target_offset; } -#define COMPAT_IP6T_ALIGN (s) COMPAT_XT_ALIGN(s) -#endif /* CONFIG_COMPAT */ #endif /*__KERNEL__*/ #endif /* _IP6_TABLES_H */
Signature · 1 line
1.7.1
PATCH 37/72 IPVS: ip_vs_dbg_callid() is only needed for debugging
In reply to [email protected]From: Simon Horman <[email protected]>
ip_vs_dbg_callid() and IP_VS_DEBUG_CALLID() are only needed it CONFIG_IP_VS_DEBUG is defined.
This resolves the following build warning when CONFIG_IP_VS_DEBUG is not defined.
net/netfilter/ipvs/ip_vs_pe_sip.c:11: warning: 'ip_vs_dbg_callid' defined but not used
--- net/netfilter/ipvs/ip_vs_pe_sip.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_pe_sip.c +2 -0
@@ -8,6 +8,7 @@#include <net/netfilter/nf_conntrack.h> #include <linux/netfilter/nf_conntrack_sip.h> +#ifdef CONFIG_IP_VS_DEBUG static const char *ip_vs_dbg_callid (char *buf,size_t buf_len,const char *callid,size_t callid_len,int *idx)
@@ -22,6 +23,7 @@ static const char *ip_vs_dbg_callid(char *buf, size_t buf_len,#define IP_VS_DEBUG_CALLID (callid, len) \ ip_vs_dbg_callid(ip_vs_dbg_buf, sizeof(ip_vs_dbg_buf), \ callid, len, &ip_vs_dbg_idx) +#endif static int get_callid(const char *dptr, unsigned int dataoff, unsigned int datalen,
Signature · 1 line
1.7.1
PATCH 38/72 netfilter: fix kconfig unmet dependency warning
In reply to [email protected]From: Randy Dunlap <[email protected]>
Fix netfilter kconfig unmet dependencies warning & spell out "compatible" while there.
warning: (IP_NF_TARGET_TTL && NET && INET && NETFILTER && IP_NF_IPTABLES && NETFILTER_ADVANCED || IP6_NF_TARGET_HL && NET && INET && IPV6 && NETFILTER && IP6_NF_IPTABLES && NETFILTER_ADVANCED) selects NETFILTER_XT_TARGET_HL which has unmet direct dependencies ((IP_NF_MANGLE || IP6_NF_MANGLE) && NETFILTER_ADVANCED)
--- net/ipv4/netfilter/Kconfig | 4 ++-- net/ipv6/netfilter/Kconfig | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
net/ipv4/netfilter/Kconfig +2 -2
@@ -324,10 +324,10 @@ config IP_NF_TARGET_ECN config IP_NF_TARGET_TTL tristate '"TTL" target support' - depends on NETFILTER_ADVANCED + depends on NETFILTER_ADVANCED && IP_NF_MANGLE select NETFILTER_XT_TARGET_HL ---help--- - This is a backwards-compat option for the user's convenience + This is a backwards-compatible option for the user's convenience (e.g. when running oldconfig). It selects CONFIG_NETFILTER_XT_TARGET_HL.
net/ipv6/netfilter/Kconfig +2 -2
@@ -132,10 +132,10 @@ config IP6_NF_MATCH_RT # The targets config IP6_NF_TARGET_HL tristate '"HL" hoplimit target support' - depends on NETFILTER_ADVANCED + depends on NETFILTER_ADVANCED && IP6_NF_MANGLE select NETFILTER_XT_TARGET_HL ---help--- - This is a backwards-compat option for the user's convenience + This is a backwards-compatible option for the user's convenience (e.g. when running oldconfig). It selects CONFIG_NETFILTER_XT_TARGET_HL.
Signature · 1 line
1.7.1
PATCH 39/72 netfilter: install missing ebtables headers for userspace
In reply to [email protected]From: Nick Bowler <[email protected]>
The ebt_ip6.h and ebt_nflog.h headers are not not known to Kbuild and therefore not installed by make headers_install. Fix that up.
--- include/linux/netfilter_bridge/Kbuild | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/netfilter_bridge/Kbuild +2 -0
@@ -3,11 +3,13 @@ header-y += ebt_among.h header-y += ebt_arp.h header-y += ebt_arpreply.h header-y += ebt_ip.h +header-y += ebt_ip6.h header-y += ebt_limit.h header-y += ebt_log.h header-y += ebt_mark_m.h header-y += ebt_mark_t.h header-y += ebt_nat.h +header-y += ebt_nflog.h header-y += ebt_pkttype.h header-y += ebt_redirect.h header-y += ebt_stp.h
Signature · 1 line
1.7.1
PATCH 40/72 netfilter: ctnetlink: add expectation deletion events
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch allows to listen to events that inform about expectations destroyed.
--- include/linux/netfilter/nf_conntrack_common.h | 1 + include/net/netfilter/nf_conntrack_expect.h | 8 +++++- net/netfilter/nf_conntrack_expect.c | 6 +++- net/netfilter/nf_conntrack_netlink.c | 30 +++++++++++++++++------- 4 files changed, 33 insertions(+), 12 deletions(-)
include/linux/netfilter/nf_conntrack_common.h +1 -0
@@ -98,6 +98,7 @@ enum ip_conntrack_events {enum ip_conntrack_expect_events {IPEXP_NEW ,/* new expectation */ +IPEXP_DESTROY ,/* destroyed expectation */ };/* expectation flags */
include/net/netfilter/nf_conntrack_expect.h +7 -1
@@ -82,7 +82,13 @@ struct nf_conntrack_expect * nf_ct_find_expectation(struct net *net, u16 zone, const struct nf_conntrack_tuple *tuple); -void nf_ct_unlink_expect (struct nf_conntrack_expect *exp); +void nf_ct_unlink_expect_report (struct nf_conntrack_expect *exp, +u32 pid,int report); +static inline void nf_ct_unlink_expect (struct nf_conntrack_expect *exp) +{ +nf_ct_unlink_expect_report (exp,0 ,0 ); +} +void nf_ct_remove_expectations (struct nf_conn *ct);void nf_ct_unexpect_related (struct nf_conntrack_expect *exp);void nf_ct_remove_userspace_expectations (void );
net/netfilter/nf_conntrack_expect.c +4 -2
@@ -41,7 +41,8 @@ static struct kmem_cache *nf_ct_expect_cachep __read_mostly;static HLIST_HEAD (nf_ct_userspace_expect_list);/* nf_conntrack_expect helper functions */ -void nf_ct_unlink_expect (struct nf_conntrack_expect *exp) +void nf_ct_unlink_expect_report (struct nf_conntrack_expect *exp, +u32 pid,int report) {struct nf_conn_help *master_help =nfct_help (exp->master);struct net *net =nf_ct_exp_net (exp);
@@ -55,11 +56,12 @@ void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)if (!(exp->flags &NF_CT_EXPECT_USERSPACE )) master_help->expecting[exp->class]--; +nf_ct_expect_event_report (IPEXP_DESTROY , exp, pid, report);nf_ct_expect_put (exp);NF_CT_STAT_INC (net, expect_delete); } -EXPORT_SYMBOL_GPL (nf_ct_unlink_expect); +EXPORT_SYMBOL_GPL (nf_ct_unlink_expect_report);static void nf_ct_expectation_timed_out (unsigned long ul_expect) {
net/netfilter/nf_conntrack_netlink.c +21 -9
@@ -1632,17 +1632,20 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)struct nlmsghdr *nlh;struct nfgenmsg *nfmsg;struct sk_buff *skb; -unsigned int type; +unsigned int type, group;int flags =0 ; -if (events & (1 <<IPEXP_NEW )) { +if (events & (1 <<IPEXP_DESTROY )) { + type =IPCTNL_MSG_EXP_DELETE ; + group =NFNLGRP_CONNTRACK_EXP_DESTROY ; + }else if (events & (1 <<IPEXP_NEW )) { type =IPCTNL_MSG_EXP_NEW ; flags =NLM_F_CREATE |NLM_F_EXCL ; + group =NFNLGRP_CONNTRACK_EXP_NEW ; }else return 0 ; -if (!item->report && - !nfnetlink_has_listeners (net,NFNLGRP_CONNTRACK_EXP_NEW )) +if (!item->report && !nfnetlink_has_listeners (net, group))return 0 ; skb =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_ATOMIC );
@@ -1665,8 +1668,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)rcu_read_unlock ();nlmsg_end (skb, nlh); -nfnetlink_send (skb, net, item->pid,NFNLGRP_CONNTRACK_EXP_NEW , - item->report,GFP_ATOMIC ); +nfnetlink_send (skb, net, item->pid, group, item->report,GFP_ATOMIC );return 0 ; nla_put_failure:
@@ -1849,7 +1851,13 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, }/* after list removal, usage count == 1 */ -nf_ct_unexpect_related (exp); +spin_lock_bh (&nf_conntrack_lock); +if (del_timer (&exp->timeout)) { +nf_ct_unlink_expect_report (exp,NETLINK_CB (skb).pid, +nlmsg_report (nlh)); +nf_ct_expect_put (exp); + } +spin_unlock_bh (&nf_conntrack_lock);/* have to put what we 'get' above. * after this line usage count == 0 */ nf_ct_expect_put (exp);
@@ -1866,7 +1874,9 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, m_help =nfct_help (exp->master);if (!strcmp (m_help->helper->name, name) &&del_timer (&exp->timeout)) { -nf_ct_unlink_expect (exp); +nf_ct_unlink_expect_report (exp, +NETLINK_CB (skb).pid, +nlmsg_report (nlh));nf_ct_expect_put (exp); } }
@@ -1880,7 +1890,9 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, &net->ct.expect_hash[i], hnode) {if (del_timer (&exp->timeout)) { -nf_ct_unlink_expect (exp); +nf_ct_unlink_expect_report (exp, +NETLINK_CB (skb).pid, +nlmsg_report (nlh));nf_ct_expect_put (exp); } }
Signature · 1 line
1.7.1
PATCH 41/72 ipvs: IPv6 tunnel mode
In reply to [email protected]From: Hans Schillstrom <[email protected]>
IPv6 encapsulation uses a bad source address for the tunnel. i.e. VIP will be used as local-addr and encap. dst addr. Decapsulation will not accept this.
Example
LVS (eth1 2003::2:0:1/96, VIP 2003::2:0:100)
(eth0 2003::1:0:1/96)
RS (ethX 2003::1:0:5/96)
tcpdump
2003::2:0:100 > 2003::1:0:5: IP6 (hlim 63, next-header TCP (6) payload length: 40) 2003::3:0:10.50991 > 2003::2:0:100.http: Flags [S], cksum 0x7312 (correct), seq 3006460279, win 5760, options [mss 1440,sackOK,TS val 1904932 ecr 0,nop,wscale 3], length 0
In Linux IPv6 impl. you can't have a tunnel with an any cast address receiving packets (I have not tried to interpret RFC 2473) To have receive capabilities the tunnel must have:
- Local address set as multicast addr or an unicast addr
- Remote address set as an unicast addr.
- Loop back addres or Link local address are not allowed.
This causes us to setup a tunnel in the Real Server with the LVS as the remote address, here you can't use the VIP address since it's used inside the tunnel.
Solution
Use outgoing interface IPv6 address (match against the destination). i.e. use ip6_route_output() to look up the route cache and then use ipv6_dev_get_saddr(...) to set the source address of the encapsulated packet.
Additionally, cache the results in new destination
fields: dst_cookie and dst_saddr and properly check the returned dst from ip6_route_output. We now add xfrm_lookup call only for the tunneling method where the source address is a local one.
--- include/net/ip_vs.h | 4 + net/netfilter/ipvs/ip_vs_xmit.c | 171 +++++++++++++++++++++------------------ 2 files changed, 96 insertions(+), 79 deletions(-)
include/net/ip_vs.h +4 -0
@@ -529,6 +529,10 @@ struct ip_vs_dest {spinlock_t dst_lock;/* lock of dst_cache */ struct dst_entry *dst_cache;/* destination cache entry */ u32 dst_rtos;/* RT_TOS(tos) for dst */ +u32 dst_cookie; +#ifdef CONFIG_IP_VS_IPV6 +struct in6_addr dst_saddr; +#endif /* for virtual service */ struct ip_vs_service *svc;/* service it belongs to */
net/netfilter/ipvs/ip_vs_xmit.c +92 -79
363 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 42/72 Fixed race condition at ip_vs.ko module init.
In reply to [email protected]From: Eduardo Blanco <[email protected]>
Lists were initialized after the module was registered. Multiple ipvsadm processes at module load triggered a race condition that resulted in a null pointer dereference in do_ip_vs_get_ctl(). As a result, __ip_vs_mutex was left locked preventing all further ipvsadm commands.
--- net/netfilter/ipvs/ip_vs_ctl.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +10 -9
@@ -3400,6 +3400,16 @@ int __init ip_vs_control_init(void)EnterFunction (2 ); +/* Initialize ip_vs_svc_table, ip_vs_svc_fwm_table, ip_vs_rtable */ +for (idx =0 ; idx <IP_VS_SVC_TAB_SIZE ; idx++) { +INIT_LIST_HEAD (&ip_vs_svc_table[idx]); +INIT_LIST_HEAD (&ip_vs_svc_fwm_table[idx]); + } +for (idx =0 ; idx <IP_VS_RTAB_SIZE ; idx++) { +INIT_LIST_HEAD (&ip_vs_rtable[idx]); + } +smp_wmb (); + ret =nf_register_sockopt (&ip_vs_sockopts);if (ret) {pr_err ("cannot register sockopt.\n" );
@@ -3418,15 +3428,6 @@ int __init ip_vs_control_init(void) sysctl_header =register_sysctl_paths (net_vs_ctl_path, vs_vars); -/* Initialize ip_vs_svc_table, ip_vs_svc_fwm_table, ip_vs_rtable */ -for (idx =0 ; idx <IP_VS_SVC_TAB_SIZE ; idx++) { -INIT_LIST_HEAD (&ip_vs_svc_table[idx]); -INIT_LIST_HEAD (&ip_vs_svc_fwm_table[idx]); - } -for (idx =0 ; idx <IP_VS_RTAB_SIZE ; idx++) { -INIT_LIST_HEAD (&ip_vs_rtable[idx]); - } -ip_vs_new_estimator (&ip_vs_stats);/* Hook the defense timer */
Signature · 1 line
1.7.1
PATCH 43/72 ipvs: fix CHECKSUM_PARTIAL for TCP, UDP
In reply to [email protected]From: Julian Anastasov <[email protected]>
Fix CHECKSUM_PARTIAL handling. Tested for IPv4 TCP,
UDP not tested because it needs network card with HW CSUM support. May be fixes problem where IPVS can not be used in virtual boxes. Problem appears with DNAT to local address when the local stack sends reply in CHECKSUM_PARTIAL mode.
Fix tcp_dnat_handler and udp_dnat_handler to provide
vaddr and daddr in right order (old and new IP) when calling tcp_partial_csum_update/udp_partial_csum_update (CHECKSUM_PARTIAL).
--- net/netfilter/ipvs/ip_vs_proto_tcp.c | 10 +++++----- net/netfilter/ipvs/ip_vs_proto_udp.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_proto_tcp.c +5 -5
@@ -101,15 +101,15 @@ tcp_partial_csum_update(int af, struct tcphdr *tcph,#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) tcph->check = -csum_fold (ip_vs_check_diff16 (oldip->ip6, newip->ip6, + ~csum_fold (ip_vs_check_diff16 (oldip->ip6, newip->ip6,ip_vs_check_diff2 (oldlen, newlen, - ~csum_unfold (tcph->check)))); +csum_unfold (tcph->check)))); else#endif tcph->check = -csum_fold (ip_vs_check_diff4 (oldip->ip, newip->ip, + ~csum_fold (ip_vs_check_diff4 (oldip->ip, newip->ip,ip_vs_check_diff2 (oldlen, newlen, - ~csum_unfold (tcph->check)))); +csum_unfold (tcph->check)))); }
@@ -223,7 +223,7 @@ tcp_dnat_handler(struct sk_buff *skb,* Adjust TCP checksums */ if (skb->ip_summed ==CHECKSUM_PARTIAL ) { -tcp_partial_csum_update (cp->af, tcph, &cp->daddr, &cp->vaddr, +tcp_partial_csum_update (cp->af, tcph, &cp->vaddr, &cp->daddr,htons (oldlen),htons (skb->len - tcphoff)); }else if (!cp->app) {
net/netfilter/ipvs/ip_vs_proto_udp.c +5 -5
@@ -102,15 +102,15 @@ udp_partial_csum_update(int af, struct udphdr *uhdr,#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) uhdr->check = -csum_fold (ip_vs_check_diff16 (oldip->ip6, newip->ip6, + ~csum_fold (ip_vs_check_diff16 (oldip->ip6, newip->ip6,ip_vs_check_diff2 (oldlen, newlen, - ~csum_unfold (uhdr->check)))); +csum_unfold (uhdr->check)))); else#endif uhdr->check = -csum_fold (ip_vs_check_diff4 (oldip->ip, newip->ip, + ~csum_fold (ip_vs_check_diff4 (oldip->ip, newip->ip,ip_vs_check_diff2 (oldlen, newlen, - ~csum_unfold (uhdr->check)))); +csum_unfold (uhdr->check)))); }
@@ -229,7 +229,7 @@ udp_dnat_handler(struct sk_buff *skb,* Adjust UDP checksums */ if (skb->ip_summed ==CHECKSUM_PARTIAL ) { -udp_partial_csum_update (cp->af, udph, &cp->daddr, &cp->vaddr, +udp_partial_csum_update (cp->af, udph, &cp->vaddr, &cp->daddr,htons (oldlen),htons (skb->len - udphoff)); }else if (!cp->app && (udph->check !=0 )) {
Signature · 1 line
1.7.1
PATCH 44/72 ipvs: optimize checksums for apps
In reply to [email protected]From: Julian Anastasov <[email protected]>
Avoid full checksum calculation for apps that can provide
info whether csum was broken after payload mangling. For now only ip_vs_ftp mangles payload and it updates the csum, so the full recalculation is avoided for all packets.
Add CHECKSUM_UNNECESSARY for snat_handler (TCP and UDP).
It is needed to support SNAT from local address for the case when csum is fully recalculated.
--- include/net/ip_vs.h | 12 ++++++++++-- net/netfilter/ipvs/ip_vs_ftp.c | 7 ++++++- net/netfilter/ipvs/ip_vs_proto_tcp.c | 31 +++++++++++++++++++++++++------ net/netfilter/ipvs/ip_vs_proto_udp.c | 31 +++++++++++++++++++++++++------ 4 files changed, 66 insertions(+), 15 deletions(-)
include/net/ip_vs.h +10 -2
@@ -597,11 +597,19 @@ struct ip_vs_app {__be16 port;/* port number in net order */ atomic_t usecnt;/* usage counter */ -/* output hook: return false if can't linearize. diff set for TCP. */ +/* +* output hook: Process packet in inout direction, diff set for TCP. +* Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, +* 2=Mangled but checksum was not updated +*/ int (*pkt_out)(struct ip_vs_app *,struct ip_vs_conn *,struct sk_buff *,int *diff); -/* input hook: return false if can't linearize. diff set for TCP. */ +/* +* input hook: Process packet in outin direction, diff set for TCP. +* Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, +* 2=Mangled but checksum was not updated +*/ int (*pkt_in)(struct ip_vs_app *,struct ip_vs_conn *,struct sk_buff *,int *diff);
net/netfilter/ipvs/ip_vs_ftp.c +6 -1
@@ -242,9 +242,14 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp, ret =nf_nat_mangle_tcp_packet (skb, ct, ctinfo, start-data, end-start, buf, buf_len); -if (ret) +if (ret) {ip_vs_nfct_expect_related (skb, ct, n_cp,IPPROTO_TCP ,0 ,0 ); +if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->ip_summed =CHECKSUM_UNNECESSARY ; +/* csum is updated */ + ret =1 ; + } }/*
net/netfilter/ipvs/ip_vs_proto_tcp.c +25 -6
@@ -120,6 +120,7 @@ tcp_snat_handler(struct sk_buff *skb,struct tcphdr *tcph;unsigned int tcphoff;int oldlen; +int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 )
@@ -134,13 +135,20 @@ tcp_snat_handler(struct sk_buff *skb,return 0 ;if (unlikely (cp->app !=NULL )) { +int ret; +/* Some checks before mangling */ if (pp->csum_check && !pp->csum_check (cp->af, skb, pp))return 0 ;/* Call application helper if needed */ -if (!ip_vs_app_pkt_out (cp, skb)) +if (!(ret =ip_vs_app_pkt_out (cp, skb)))return 0 ; +/* ret=2: csum update is needed after payload mangling */ +if (ret ==1 ) + oldlen = skb->len - tcphoff; +else + payload_csum =1 ; } tcph = (void *)skb_network_header (skb) + tcphoff;
@@ -151,12 +159,13 @@ tcp_snat_handler(struct sk_buff *skb,tcp_partial_csum_update (cp->af, tcph, &cp->daddr, &cp->vaddr,htons (oldlen),htons (skb->len - tcphoff)); - }else if (!cp->app) { + }else if (!payload_csum) {/* Only port and addr are changed, do fast csum update */ tcp_fast_csum_update (cp->af, tcph, &cp->daddr, &cp->vaddr, cp->dport, cp->vport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed =CHECKSUM_NONE ; + skb->ip_summed = (cp->app && pp->csum_check) ? +CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */ tcph->check =0 ;
@@ -174,6 +183,7 @@ tcp_snat_handler(struct sk_buff *skb, skb->len - tcphoff, cp->protocol, skb->csum); + skb->ip_summed =CHECKSUM_UNNECESSARY ; IP_VS_DBG(11, "O-pkt: %s O-csum=%d (+%zd)\n", pp->name, tcph->check,
@@ -190,6 +200,7 @@ tcp_dnat_handler(struct sk_buff *skb,struct tcphdr *tcph;unsigned int tcphoff;int oldlen; +int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 )
@@ -204,6 +215,8 @@ tcp_dnat_handler(struct sk_buff *skb,return 0 ;if (unlikely (cp->app !=NULL )) { +int ret; +/* Some checks before mangling */ if (pp->csum_check && !pp->csum_check (cp->af, skb, pp))return 0 ;
@@ -212,8 +225,13 @@ tcp_dnat_handler(struct sk_buff *skb,* Attempt ip_vs_app call. * It will fix ip_vs_conn and iph ack_seq stuff */ -if (!ip_vs_app_pkt_in (cp, skb)) +if (!(ret =ip_vs_app_pkt_in (cp, skb)))return 0 ; +/* ret=2: csum update is needed after payload mangling */ +if (ret ==1 ) + oldlen = skb->len - tcphoff; +else + payload_csum =1 ; } tcph = (void *)skb_network_header (skb) + tcphoff;
@@ -226,12 +244,13 @@ tcp_dnat_handler(struct sk_buff *skb,tcp_partial_csum_update (cp->af, tcph, &cp->vaddr, &cp->daddr,htons (oldlen),htons (skb->len - tcphoff)); - }else if (!cp->app) { + }else if (!payload_csum) {/* Only port and addr are changed, do fast csum update */ tcp_fast_csum_update (cp->af, tcph, &cp->vaddr, &cp->daddr, cp->vport, cp->dport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed =CHECKSUM_NONE ; + skb->ip_summed = (cp->app && pp->csum_check) ? +CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */ tcph->check =0 ;
net/netfilter/ipvs/ip_vs_proto_udp.c +25 -6
@@ -121,6 +121,7 @@ udp_snat_handler(struct sk_buff *skb,struct udphdr *udph;unsigned int udphoff;int oldlen; +int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 )
@@ -135,6 +136,8 @@ udp_snat_handler(struct sk_buff *skb,return 0 ;if (unlikely (cp->app !=NULL )) { +int ret; +/* Some checks before mangling */ if (pp->csum_check && !pp->csum_check (cp->af, skb, pp))return 0 ;
@@ -142,8 +145,13 @@ udp_snat_handler(struct sk_buff *skb,/* * Call application helper if needed */ -if (!ip_vs_app_pkt_out (cp, skb)) +if (!(ret =ip_vs_app_pkt_out (cp, skb)))return 0 ; +/* ret=2: csum update is needed after payload mangling */ +if (ret ==1 ) + oldlen = skb->len - udphoff; +else + payload_csum =1 ; } udph = (void *)skb_network_header (skb) + udphoff;
@@ -156,12 +164,13 @@ udp_snat_handler(struct sk_buff *skb,udp_partial_csum_update (cp->af, udph, &cp->daddr, &cp->vaddr,htons (oldlen),htons (skb->len - udphoff)); - }else if (!cp->app && (udph->check !=0 )) { + }else if (!payload_csum && (udph->check !=0 )) {/* Only port and addr are changed, do fast csum update */ udp_fast_csum_update (cp->af, udph, &cp->daddr, &cp->vaddr, cp->dport, cp->vport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed =CHECKSUM_NONE ; + skb->ip_summed = (cp->app && pp->csum_check) ? +CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */ udph->check =0 ;
@@ -181,6 +190,7 @@ udp_snat_handler(struct sk_buff *skb, skb->csum);if (udph->check ==0 ) udph->check =CSUM_MANGLED_0 ; + skb->ip_summed =CHECKSUM_UNNECESSARY ;IP_VS_DBG (11 ,"O-pkt: %s O-csum=%d (+%zd)\n" , pp->name, udph->check, (char *)&(udph->check) - (char *)udph);
@@ -196,6 +206,7 @@ udp_dnat_handler(struct sk_buff *skb,struct udphdr *udph;unsigned int udphoff;int oldlen; +int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 )
@@ -210,6 +221,8 @@ udp_dnat_handler(struct sk_buff *skb,return 0 ;if (unlikely (cp->app !=NULL )) { +int ret; +/* Some checks before mangling */ if (pp->csum_check && !pp->csum_check (cp->af, skb, pp))return 0 ;
@@ -218,8 +231,13 @@ udp_dnat_handler(struct sk_buff *skb,* Attempt ip_vs_app call. * It will fix ip_vs_conn */ -if (!ip_vs_app_pkt_in (cp, skb)) +if (!(ret =ip_vs_app_pkt_in (cp, skb)))return 0 ; +/* ret=2: csum update is needed after payload mangling */ +if (ret ==1 ) + oldlen = skb->len - udphoff; +else + payload_csum =1 ; } udph = (void *)skb_network_header (skb) + udphoff;
@@ -232,12 +250,13 @@ udp_dnat_handler(struct sk_buff *skb,udp_partial_csum_update (cp->af, udph, &cp->vaddr, &cp->daddr,htons (oldlen),htons (skb->len - udphoff)); - }else if (!cp->app && (udph->check !=0 )) { + }else if (!payload_csum && (udph->check !=0 )) {/* Only port and addr are changed, do fast csum update */ udp_fast_csum_update (cp->af, udph, &cp->vaddr, &cp->daddr, cp->vport, cp->dport);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->ip_summed =CHECKSUM_NONE ; + skb->ip_summed = (cp->app && pp->csum_check) ? +CHECKSUM_UNNECESSARY :CHECKSUM_NONE ; }else {/* full checksum calculation */ udph->check =0 ;
Signature · 1 line
1.7.1
PATCH 45/72 ipvs: switch to notrack mode
In reply to [email protected]From: Julian Anastasov <[email protected]>
Change skb->ipvs_property semantic. This is preparation
to support ip_vs_out processing in LOCAL_OUT. ipvs_property=1 will be used to avoid expensive lookups for traffic sent by transmitters. Now when conntrack support is not used we call ip_vs_notrack method to avoid problems in OUTPUT and POST_ROUTING hooks instead of exiting POST_ROUTING as before.
--- include/net/ip_vs.h | 20 +++++++++++++++++++- net/netfilter/ipvs/ip_vs_core.c | 39 ++++----------------------------------- net/netfilter/ipvs/ip_vs_xmit.c | 7 +++++-- 3 files changed, 28 insertions(+), 38 deletions(-)
include/net/ip_vs.h +19 -1
@@ -25,7 +25,7 @@#include <linux/ip.h> #include <linux/ipv6.h> /* for struct ipv6hdr */ #include <net/ipv6.h> /* for ipv6_addr_copy */ -#ifdef CONFIG_IP_VS_NFCT +#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netfilter/nf_conntrack.h> #endif
@@ -1021,6 +1021,24 @@ static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)return csum_partial (diff,sizeof (diff), oldsum); } +/* +* Forget current conntrack (unconfirmed) and attach notrack entry +*/ +static inline void ip_vs_notrack (struct sk_buff *skb) +{ +#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) +enum ip_conntrack_info ctinfo; +struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); + +if (!ct || !nf_ct_is_untracked (ct)) { +nf_reset (skb); + skb->nfct = &nf_ct_untracked_get ()->ct_general; + skb->nfctinfo =IP_CT_NEW ; +nf_conntrack_get (skb->nfct); + } +#endif +} +#ifdef CONFIG_IP_VS_NFCT /* * Netfilter connection tracking
net/netfilter/ipvs/ip_vs_core.c +4 -35
@@ -507,23 +507,6 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,return NF_DROP ; } -/* -* It is hooked before NF_IP_PRI_NAT_SRC at the NF_INET_POST_ROUTING -* chain and is used to avoid double NAT and confirmation when we do -* not want to keep the conntrack structure -*/ -static unsigned int ip_vs_post_routing (unsigned int hooknum, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) -{ -if (!skb->ipvs_property) -return NF_ACCEPT ; -/* The packet was sent from IPVS, exit this chain */ -return NF_STOP ; -} -__sum16 ip_vs_checksum_complete (struct sk_buff *skb,int offset) {return csum_fold (skb_checksum (skb, offset, skb->len - offset,0 ));
@@ -682,8 +665,9 @@ static int handle_response_icmp(int af, struct sk_buff *skb,/* do the statistics and put it back */ ip_vs_out_stats (cp, skb); + skb->ipvs_property =1 ;if (!(cp->flags &IP_VS_CONN_F_NFCT )) - skb->ipvs_property =1 ; +ip_vs_notrack (skb);else ip_vs_update_conntrack (skb, cp,0 ); verdict =NF_ACCEPT ;
@@ -929,8 +913,9 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,ip_vs_out_stats (cp, skb);ip_vs_set_state (cp,IP_VS_DIR_OUTPUT , skb, pp); + skb->ipvs_property =1 ;if (!(cp->flags &IP_VS_CONN_F_NFCT )) - skb->ipvs_property =1 ; +ip_vs_notrack (skb);else ip_vs_update_conntrack (skb, cp,0 );ip_vs_conn_put (cp);
@@ -1496,14 +1481,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { .hooknum = NF_INET_FORWARD, .priority = 99, }, -/* Before the netfilter connection tracking, exit from POST_ROUTING */ - { - .hook = ip_vs_post_routing, - .owner = THIS_MODULE, - .pf = PF_INET, - .hooknum = NF_INET_POST_ROUTING, - .priority = NF_IP_PRI_NAT_SRC-1, - },#ifdef CONFIG_IP_VS_IPV6 /* After packet filtering, forward packet through VS/DR, VS/TUN, * or VS/NAT(change destination), so that filtering rules can be
@@ -1532,14 +1509,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { .hooknum = NF_INET_FORWARD, .priority = 99, }, -/* Before the netfilter connection tracking, exit from POST_ROUTING */ - { - .hook = ip_vs_post_routing, - .owner = THIS_MODULE, - .pf = PF_INET6, - .hooknum = NF_INET_POST_ROUTING, - .priority = NF_IP6_PRI_NAT_SRC-1, - },#endif };
net/netfilter/ipvs/ip_vs_xmit.c +5 -2
@@ -217,6 +217,7 @@ ip_vs_dst_reset(struct ip_vs_dest *dest) ({ \ int __ret = NF_ACCEPT; \ \ + (skb)->ipvs_property = 1; \ if (unlikely((cp)->flags & IP_VS_CONN_F_NFCT)) \ __ret = ip_vs_confirm_conntrack(skb, cp); \ if (__ret == NF_ACCEPT) { \
@@ -228,8 +229,9 @@ ip_vs_dst_reset(struct ip_vs_dest *dest)#define IP_VS_XMIT_NAT (pf, skb, cp) \ do { \ + (skb)->ipvs_property = 1; \ if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \ - (skb)->ipvs_property = 1; \ + ip_vs_notrack(skb); \ else \ ip_vs_update_conntrack(skb, cp, 1); \ skb_forward_csum(skb); \
@@ -239,8 +241,9 @@ do { \#define IP_VS_XMIT (pf, skb, cp) \ do { \ + (skb)->ipvs_property = 1; \ if (likely(!((cp)->flags & IP_VS_CONN_F_NFCT))) \ - (skb)->ipvs_property = 1; \ + ip_vs_notrack(skb); \ skb_forward_csum(skb); \ NF_HOOK(pf, NF_INET_LOCAL_OUT, (skb), NULL, \ skb_dst(skb)->dev, dst_output); \
Signature · 1 line
1.7.1
PATCH 46/72 ipvs: do not schedule conns from real servers
In reply to [email protected]From: Julian Anastasov <[email protected]>
This patch is needed to avoid scheduling of
packets from local real server when we add ip_vs_in in LOCAL_OUT hook to support local client.
Currently, when ip_vs_in can not find existing
connection it tries to create new one by calling ip_vs_schedule.
The default indication from ip_vs_schedule was if
connection was scheduled to real server. If real server is not available we try to use the bypass forwarding method or to send ICMP error. But in some cases we do not want to use the bypass feature. So, add flag 'ignored' to indicate if the scheduler ignores this packet.
Make sure we do not create new connections from replies.
We can hit this problem for persistent services and local real server when ip_vs_in is added to LOCAL_OUT hook to handle local clients.
Also, make sure ip_vs_schedule ignores SYN packets
for Active FTP DATA from local real server. The FTP DATA connection should be created on SYN+ACK from client to assign correct connection daddr.
--- include/net/ip_vs.h | 3 +- net/netfilter/ipvs/ip_vs_core.c | 34 +++++++++++++++++++++++++++++++- net/netfilter/ipvs/ip_vs_proto_sctp.c | 6 +++- net/netfilter/ipvs/ip_vs_proto_tcp.c | 7 ++++- net/netfilter/ipvs/ip_vs_proto_udp.c | 6 +++- 5 files changed, 47 insertions(+), 9 deletions(-)
include/net/ip_vs.h +2 -1
@@ -849,7 +849,8 @@ extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);extern struct ip_vs_scheduler *ip_vs_scheduler_get (const char *sched_name);extern void ip_vs_scheduler_put (struct ip_vs_scheduler *scheduler);extern struct ip_vs_conn * -ip_vs_schedule (struct ip_vs_service *svc,struct sk_buff *skb); +ip_vs_schedule (struct ip_vs_service *svc,struct sk_buff *skb, +struct ip_vs_protocol *pp,int *ignored);extern int ip_vs_leave (struct ip_vs_service *svc,struct sk_buff *skb,struct ip_vs_protocol *pp);
net/netfilter/ipvs/ip_vs_core.c +32 -2
@@ -342,7 +342,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,* Protocols supported: TCP, UDP */ struct ip_vs_conn * -ip_vs_schedule (struct ip_vs_service *svc,struct sk_buff *skb) +ip_vs_schedule (struct ip_vs_service *svc,struct sk_buff *skb, +struct ip_vs_protocol *pp,int *ignored) {struct ip_vs_conn *cp =NULL ;struct ip_vs_iphdr iph;
@@ -350,16 +351,43 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb)__be16 _ports[2 ], *pptr;unsigned int flags; + *ignored =1 ;ip_vs_fill_iphdr (svc->af,skb_network_header (skb), &iph); pptr =skb_header_pointer (skb, iph.len,sizeof (_ports), _ports);if (pptr ==NULL )return NULL ;/* +* FTPDATA needs this check when using local real server. +* Never schedule Active FTPDATA connections from real server. +* For LVS-NAT they must be already created. For other methods +* with persistence the connection is created on SYN+ACK. +*/ +if (pptr[0 ] ==FTPDATA ) { +IP_VS_DBG_PKT (12 , pp, skb,0 ,"Not scheduling FTPDATA" ); +return NULL ; + } + +/* +* Do not schedule replies from local real server. It is risky +* for fwmark services but mostly for persistent services. +*/ +if ((!skb->dev || skb->dev->flags &IFF_LOOPBACK ) && + (svc->flags &IP_VS_SVC_F_PERSISTENT || svc->fwmark) && + (cp = pp->conn_in_get (svc->af, skb, pp, &iph, iph.len,1 ))) { +IP_VS_DBG_PKT (12 , pp, skb,0 , +"Not scheduling reply for existing connection" ); +__ip_vs_conn_put (cp); +return NULL ; + } + +/* * Persistent service */ -if (svc->flags &IP_VS_SVC_F_PERSISTENT ) +if (svc->flags &IP_VS_SVC_F_PERSISTENT ) { + *ignored =0 ;return ip_vs_sched_persist (svc, skb, pptr); + }/* * Non-persistent service
@@ -372,6 +400,8 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb)return NULL ; } + *ignored =0 ; + dest = svc->scheduler->schedule (svc, skb);if (dest ==NULL ) {IP_VS_DBG (1 ,"Schedule: no dest found.\n" );
net/netfilter/ipvs/ip_vs_proto_sctp.c +4 -2
@@ -31,6 +31,8 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,if ((sch->type ==SCTP_CID_INIT ) && (svc =ip_vs_service_get (af, skb->mark, iph.protocol, &iph.daddr, sh->dest))) { +int ignored; +if (ip_vs_todrop ()) {/* * It seems that we are very loaded.
@@ -44,8 +46,8 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,* Let the virtual server select a real server for the * incoming connection, and create a connection entry. */ - *cpp =ip_vs_schedule (svc, skb); -if (!*cpp) { + *cpp =ip_vs_schedule (svc, skb, pp, &ignored); +if (!*cpp && !ignored) { *verdict =ip_vs_leave (svc, skb, pp);return 0 ; }
net/netfilter/ipvs/ip_vs_proto_tcp.c +5 -2
@@ -43,9 +43,12 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,return 0 ; } +/* No !th->ack check to allow scheduling on SYN+ACK for Active FTP */ if (th->syn && (svc =ip_vs_service_get (af, skb->mark, iph.protocol, &iph.daddr, th->dest))) { +int ignored; +if (ip_vs_todrop ()) {/* * It seems that we are very loaded.
@@ -60,8 +63,8 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,* Let the virtual server select a real server for the * incoming connection, and create a connection entry. */ - *cpp =ip_vs_schedule (svc, skb); -if (!*cpp) { + *cpp =ip_vs_schedule (svc, skb, pp, &ignored); +if (!*cpp && !ignored) { *verdict =ip_vs_leave (svc, skb, pp);return 0 ; }
net/netfilter/ipvs/ip_vs_proto_udp.c +4 -2
@@ -46,6 +46,8 @@ udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, svc =ip_vs_service_get (af, skb->mark, iph.protocol, &iph.daddr, uh->dest);if (svc) { +int ignored; +if (ip_vs_todrop ()) {/* * It seems that we are very loaded.
@@ -60,8 +62,8 @@ udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,* Let the virtual server select a real server for the * incoming connection, and create a connection entry. */ - *cpp =ip_vs_schedule (svc, skb); -if (!*cpp) { + *cpp =ip_vs_schedule (svc, skb, pp, &ignored); +if (!*cpp && !ignored) { *verdict =ip_vs_leave (svc, skb, pp);return 0 ; }
Signature · 1 line
1.7.1
PATCH 47/72 ipvs: stop ICMP from FORWARD to local
In reply to [email protected]From: Julian Anastasov <[email protected]>
Delivering locally ICMP from FORWARD hook is not supported.
--- net/netfilter/ipvs/ip_vs_core.c | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +19 -2
@@ -48,6 +48,7 @@#ifdef CONFIG_IP_VS_IPV6 #include <net/ipv6.h> #include <linux/netfilter_ipv6.h> +#include <net/ip6_route.h> #endif #include <net/ip_vs.h>
@@ -1191,7 +1192,14 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)if (IPPROTO_TCP == cih->protocol ||IPPROTO_UDP == cih->protocol) offset +=2 *sizeof (__u16); verdict =ip_vs_icmp_xmit (skb, cp, pp, offset); -/* do not touch skb anymore */ +/* LOCALNODE from FORWARD hook is not supported */ +if (verdict ==NF_ACCEPT && hooknum ==NF_INET_FORWARD && +skb_rtable (skb)->rt_flags &RTCF_LOCAL ) { +IP_VS_DBG (1 ,"%s(): " +"local delivery to %pI4 but in FORWARD\n" , + __func__, &skb_rtable (skb)->rt_dst); + verdict =NF_DROP ; + } out:__ip_vs_conn_put (cp);
@@ -1212,6 +1220,7 @@ ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, unsigned int hooknum)struct ip_vs_protocol *pp;unsigned int offset, verdict;union nf_inet_addr snet; +struct rt6_info *rt; *related =1 ;
@@ -1290,7 +1299,15 @@ ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, unsigned int hooknum) IPPROTO_SCTP == cih->nexthdr) offset +=2 *sizeof (__u16); verdict =ip_vs_icmp_xmit_v6 (skb, cp, pp, offset); -/* do not touch skb anymore */ +/* LOCALNODE from FORWARD hook is not supported */ +if (verdict ==NF_ACCEPT && hooknum ==NF_INET_FORWARD && + (rt = (struct rt6_info *)skb_dst (skb)) && + rt->rt6i_dev && rt->rt6i_dev->flags &IFF_LOOPBACK ) { +IP_VS_DBG (1 ,"%s(): " +"local delivery to %pI6 but in FORWARD\n" , + __func__, &rt->rt6i_dst); + verdict =NF_DROP ; + }__ip_vs_conn_put (cp);
Signature · 1 line
1.7.1
PATCH 48/72 ipvs: fix CHECKSUM_PARTIAL for TUN method
In reply to [email protected]From: Julian Anastasov <[email protected]>
The recent change in IP_VS_XMIT_TUNNEL to setCHECKSUM_NONE is not correct. After adding IPIP header skb->csum becomes invalid but the CHECKSUM_PARTIAL case must be supported. So, use skb_forward_csum() which is most suitable for us to allow local clients to send IPIP to remote real server.
--- net/netfilter/ipvs/ip_vs_xmit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +1 -1
@@ -222,7 +222,7 @@ ip_vs_dst_reset(struct ip_vs_dest *dest) __ret =ip_vs_confirm_conntrack (skb, cp); \if (__ret ==NF_ACCEPT ) { \nf_reset (skb); \ - (skb)->ip_summed =CHECKSUM_NONE ; \ +skb_forward_csum (skb); \ } \ __ret; \ })
Signature · 1 line
1.7.1
PATCH 49/72 ipvs: create ip_vs_defrag_user
In reply to [email protected]From: Julian Anastasov <[email protected]>
Create new function ip_vs_defrag_user to return correctIP_DEFRAG_xxx user depending on the hooknum. It will be needed when we add handlers in LOCAL_OUT.
--- net/netfilter/ipvs/ip_vs_core.c | 55 ++++++++++++++++++++++++--------------- 1 files changed, 34 insertions(+), 21 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +34 -21
@@ -543,6 +543,15 @@ __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset)return csum_fold (skb_checksum (skb, offset, skb->len - offset,0 )); } +static inline enum ip_defrag_users ip_vs_defrag_user (unsigned int hooknum) +{ +if (NF_INET_LOCAL_IN == hooknum) +return IP_DEFRAG_VS_IN ; +if (NF_INET_FORWARD == hooknum) +return IP_DEFRAG_VS_FWD ; +return IP_DEFRAG_VS_OUT ; +} +static inline int ip_vs_gather_frags (struct sk_buff *skb,u_int32_t user) {int err =ip_defrag (skb, user);
@@ -714,7 +723,8 @@ out:* Find any that might be relevant, check against existing connections. * Currently handles error types - unreachable, quench, ttl exceeded. */ -static int ip_vs_out_icmp (struct sk_buff *skb,int *related) +static int ip_vs_out_icmp (struct sk_buff *skb,int *related, +unsigned int hooknum) {struct iphdr *iph;struct icmphdr _icmph, *ic;
@@ -729,7 +739,7 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related)/* reassemble IP fragments */ if (ip_hdr (skb)->frag_off &htons (IP_MF |IP_OFFSET )) { -if (ip_vs_gather_frags (skb,IP_DEFRAG_VS_OUT )) +if (ip_vs_gather_frags (skb,ip_vs_defrag_user (hooknum)))return NF_STOLEN ; }
@@ -788,7 +798,8 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related) }#ifdef CONFIG_IP_VS_IPV6 -static int ip_vs_out_icmp_v6 (struct sk_buff *skb,int *related) +static int ip_vs_out_icmp_v6 (struct sk_buff *skb,int *related, +unsigned int hooknum) {struct ipv6hdr *iph;struct icmp6hdr _icmph, *ic;
@@ -804,7 +815,7 @@ static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related)/* reassemble IP fragments */ if (ipv6_hdr (skb)->nexthdr ==IPPROTO_FRAGMENT ) { -if (ip_vs_gather_frags_v6 (skb,IP_DEFRAG_VS_OUT )) +if (ip_vs_gather_frags_v6 (skb,ip_vs_defrag_user (hooknum)))return NF_STOLEN ; }
@@ -986,7 +997,9 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) {if (unlikely (iph.protocol ==IPPROTO_ICMPV6 )) { -int related, verdict =ip_vs_out_icmp_v6 (skb, &related); +int related; +int verdict =ip_vs_out_icmp_v6 (skb, &related, + hooknum);if (related) { if (sysctl_ip_vs_snat_reroute &&
@@ -1000,7 +1013,8 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, } else#endif if (unlikely (iph.protocol ==IPPROTO_ICMP )) { -int related, verdict =ip_vs_out_icmp (skb, &related); +int related; +int verdict =ip_vs_out_icmp (skb, &related, hooknum);if (related) { if (sysctl_ip_vs_snat_reroute &&
@@ -1019,19 +1033,19 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,/* reassemble IP fragments */ #ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) { -if (unlikely (iph.protocol ==IPPROTO_ICMPV6 )) { -int related, verdict =ip_vs_out_icmp_v6 (skb, &related); - -if (related) -return verdict; - -ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); +if (ipv6_hdr (skb)->nexthdr ==IPPROTO_FRAGMENT ) { +if (ip_vs_gather_frags_v6 (skb, +ip_vs_defrag_user (hooknum))) +return NF_STOLEN ; } + +ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); } else#endif if (unlikely (ip_hdr (skb)->frag_off &htons (IP_MF |IP_OFFSET ) && !pp->dont_defrag)) { -if (ip_vs_gather_frags (skb,IP_DEFRAG_VS_OUT )) +if (ip_vs_gather_frags (skb, +ip_vs_defrag_user (hooknum)))return NF_STOLEN ;ip_vs_fill_iphdr (af,skb_network_header (skb), &iph);
@@ -1114,8 +1128,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)/* reassemble IP fragments */ if (ip_hdr (skb)->frag_off &htons (IP_MF |IP_OFFSET )) { -if (ip_vs_gather_frags (skb, hooknum ==NF_INET_LOCAL_IN ? -IP_DEFRAG_VS_IN :IP_DEFRAG_VS_FWD )) +if (ip_vs_gather_frags (skb,ip_vs_defrag_user (hooknum)))return NF_STOLEN ; }
@@ -1226,9 +1239,7 @@ ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, unsigned int hooknum)/* reassemble IP fragments */ if (ipv6_hdr (skb)->nexthdr ==IPPROTO_FRAGMENT ) { -if (ip_vs_gather_frags_v6 (skb, hooknum ==NF_INET_LOCAL_IN ? -IP_DEFRAG_VS_IN : -IP_DEFRAG_VS_FWD )) +if (ip_vs_gather_frags_v6 (skb,ip_vs_defrag_user (hooknum)))return NF_STOLEN ; }
@@ -1349,7 +1360,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) {if (unlikely (iph.protocol ==IPPROTO_ICMPV6 )) { -int related, verdict =ip_vs_in_icmp_v6 (skb, &related, hooknum); +int related; +int verdict =ip_vs_in_icmp_v6 (skb, &related, hooknum);if (related)return verdict;
@@ -1358,7 +1370,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, } else#endif if (unlikely (iph.protocol ==IPPROTO_ICMP )) { -int related, verdict =ip_vs_in_icmp (skb, &related, hooknum); +int related; +int verdict =ip_vs_in_icmp (skb, &related, hooknum);if (related)return verdict;
Signature · 1 line
1.7.1
PATCH 50/72 ipvs: move ip_route_me_harder for ICMP
In reply to [email protected]From: Julian Anastasov <[email protected]>
Currently, ip_route_me_harder after ip_vs_out_icmp
is called even if packet is not related to IPVS connection. Move it into handle_response_icmp. Also, force rerouting if sending to local client because IPv4 stack uses addresses from the route.
--- net/netfilter/ipvs/ip_vs_core.c | 41 ++++++++++++++++++++------------------- 1 files changed, 21 insertions(+), 20 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +21 -20
@@ -702,6 +702,17 @@ static int handle_response_icmp(int af, struct sk_buff *skb,#endif ip_vs_nat_icmp (skb, pp, cp,1 ); +#ifdef CONFIG_IP_VS_IPV6 +if (af ==AF_INET6 ) { +if (sysctl_ip_vs_snat_reroute &&ip6_route_me_harder (skb) !=0 ) + goto out; + } else +#endif +if ((sysctl_ip_vs_snat_reroute || +skb_rtable (skb)->rt_flags &RTCF_LOCAL ) && +ip_route_me_harder (skb,RTN_LOCAL ) !=0 ) + goto out; +/* do the statistics and put it back */ ip_vs_out_stats (cp, skb);
@@ -940,16 +951,16 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,* if it came from this machine itself. So re-compute * the routing information. */ -if (sysctl_ip_vs_snat_reroute) {#ifdef CONFIG_IP_VS_IPV6 -if (af ==AF_INET6 ) { -if (ip6_route_me_harder (skb) !=0 ) - goto drop; - } else +if (af ==AF_INET6 ) { +if (sysctl_ip_vs_snat_reroute &&ip6_route_me_harder (skb) !=0 ) + goto drop; + } else#endif -if (ip_route_me_harder (skb,RTN_LOCAL ) !=0 ) - goto drop; - } +if ((sysctl_ip_vs_snat_reroute || +skb_rtable (skb)->rt_flags &RTCF_LOCAL ) && +ip_route_me_harder (skb,RTN_LOCAL ) !=0 ) + goto drop;IP_VS_DBG_PKT (10 , pp, skb,0 ,"After SNAT" );
@@ -1001,13 +1012,8 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,int verdict =ip_vs_out_icmp_v6 (skb, &related, hooknum); -if (related) { -if (sysctl_ip_vs_snat_reroute && -NF_ACCEPT == verdict && -ip6_route_me_harder (skb)) - verdict =NF_DROP ; +if (related)return verdict; - }ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); } }else
@@ -1016,13 +1022,8 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb,int related;int verdict =ip_vs_out_icmp (skb, &related, hooknum); -if (related) { -if (sysctl_ip_vs_snat_reroute && -NF_ACCEPT == verdict && -ip_route_me_harder (skb,RTN_LOCAL )) - verdict =NF_DROP ; +if (related)return verdict; - }ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); }
Signature · 1 line
1.7.1
PATCH 51/72 ipvs: changes for local real server
In reply to [email protected]From: Julian Anastasov <[email protected]>
This patch deals with local real servers:
- Add support for DNAT to local address (different real server port). It needs ip_vs_out hook in LOCAL_OUT for both families because skb->protocol is not set for locally generated packets and can not be used to set 'af'.
- Skip packets in ip_vs_in marked with skb->ipvs_property because ip_vs_out processing can be executed in LOCAL_OUT but we still have the conn_out_get check in ip_vs_in.
- Ignore packets with inet->nodefrag from local stack
- Require skb_dst(skb) != NULL because we use it to get struct net
- Add support for changing the route to local IPv4 stack after DNAT depending on the source address type. Local client sets output route and the remote client sets input route. It looks like IPv6 does not need such rerouting because the replies use addresses from initial incoming header, not from skb route.
- All transmitters now have strict checks for the destination address type: redirect from non-local address to local real server requires NAT method, local address can not be used as source address when talking to remote real server.
- Now LOCALNODE is not set explicitly as forwarding method in real server to allow the connections to provide correct forwarding method to the backup server. Not sure if this breaks tools that expect to see 'Local' real server type. If needed, this can be supported with new flag IP_VS_DEST_F_LOCAL. Now it should be possible connections in backup that lost their fwmark information during sync to be forwarded properly to their daddr, even if it is local address in the backup server. By this way backup could be used as real server for DR or TUN, for NAT there are some restrictions because tuple collisions in conntracks can create problems for the traffic.
- Call ip_vs_dst_reset when destination is updated in case some real server IP type is changed between local and remote.
--- include/net/ip_vs.h | 1 + net/netfilter/ipvs/ip_vs_core.c | 123 ++++++++++-- net/netfilter/ipvs/ip_vs_ctl.c | 18 +-- net/netfilter/ipvs/ip_vs_xmit.c | 433 +++++++++++++++++++++++++++++++-------- 4 files changed, 458 insertions(+), 117 deletions(-)
include/net/ip_vs.h +1 -0
@@ -409,6 +409,7 @@ struct ip_vs_conn {/* packet transmitter for different forwarding methods. If it mangles the packet, it must return NF_DROP or better NF_STOLEN, otherwise this must be changed to a sk_buff **. +NF_ACCEPT can be returned when destination is local. */ int (*packet_xmit)(struct sk_buff *skb,struct ip_vs_conn *cp,struct ip_vs_protocol *pp);
net/netfilter/ipvs/ip_vs_core.c +107 -16
183 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ctl.c +4 -14
@@ -777,20 +777,6 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, conn_flags = udest->conn_flags &IP_VS_CONN_F_DEST_MASK ; conn_flags |=IP_VS_CONN_F_INACTIVE ; -/* check if local node and update the flags */ -#ifdef CONFIG_IP_VS_IPV6 -if (svc->af ==AF_INET6 ) { -if (__ip_vs_addr_is_local_v6 (&udest->addr.in6)) { - conn_flags = (conn_flags & ~IP_VS_CONN_F_FWD_MASK ) - |IP_VS_CONN_F_LOCALNODE ; - } - } else -#endif -if (inet_addr_type (&init_net, udest->addr.ip) ==RTN_LOCAL ) { - conn_flags = (conn_flags & ~IP_VS_CONN_F_FWD_MASK ) - |IP_VS_CONN_F_LOCALNODE ; - } -/* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */ if ((conn_flags &IP_VS_CONN_F_FWD_MASK ) !=IP_VS_CONN_F_MASQ ) { conn_flags |=IP_VS_CONN_F_NOOUTPUT ;
@@ -824,6 +810,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, dest->u_threshold = udest->u_threshold; dest->l_threshold = udest->l_threshold; +spin_lock (&dest->dst_lock); +ip_vs_dst_reset (dest); +spin_unlock (&dest->dst_lock); +if (add)ip_vs_new_estimator (&dest->stats);
net/netfilter/ipvs/ip_vs_xmit.c +346 -87
759 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 52/72 ipvs: changes for local client
In reply to [email protected]From: Julian Anastasov <[email protected]>
This patch deals with local client processing.
Prefer LOCAL_OUT hook for scheduling connections from
local clients. LOCAL_IN is still supported if the packets are not marked as processed in LOCAL_OUT. The idea to process requests in LOCAL_OUT is to alter conntrack reply before it is confirmed at POST_ROUTING. If the local requests are processed in LOCAL_IN the conntrack can not be updated and matching by state is impossible.
Add the following handlers:
- ip_vs_reply[46] at LOCAL_IN:99 to process replies from remote real servers to local clients. Now when both replies from remote real servers (ip_vs_reply*) and local real servers (ip_vs_local_reply*) are handled it is safe to remove the conn_out_get call from ip_vs_in because it does not support related ICMP packets.
- ip_vs_local_request[46] at LOCAL_OUT:-98 to process requests from local client
Handling in LOCAL_OUT causes some changes:
- as skb->dev, skb->protocol and skb->pkt_type are not defined in LOCAL_OUT make sure we set skb->dev before calling icmpv6_send, prefer skb_dst(skb) for struct net and remove the skb->protocol checks from TUN transmitters.
--- net/netfilter/ipvs/ip_vs_core.c | 266 +++++++++++++++++++++++++++----------- net/netfilter/ipvs/ip_vs_xmit.c | 51 ++++++--- 2 files changed, 225 insertions(+), 92 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +189 -77
@@ -529,9 +529,14 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,* ICMP_PORT_UNREACH is sent here no matter it is TCP/UDP. --WZ */ #ifdef CONFIG_IP_VS_IPV6 -if (svc->af ==AF_INET6 ) +if (svc->af ==AF_INET6 ) { +if (!skb->dev) { +struct net *net =dev_net (skb_dst (skb)->dev); + + skb->dev = net->loopback_dev; + }icmpv6_send (skb,ICMPV6_DEST_UNREACH ,ICMPV6_PORT_UNREACH ,0 ); - else + } else#endif icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_PORT_UNREACH ,0 );
@@ -1065,57 +1070,61 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)*/ cp = pp->conn_out_get (af, skb, pp, &iph, iph.len,0 ); -if (unlikely (!cp)) { -if (sysctl_ip_vs_nat_icmp_send && - (pp->protocol ==IPPROTO_TCP || - pp->protocol ==IPPROTO_UDP || - pp->protocol ==IPPROTO_SCTP )) { -__be16 _ports[2 ], *pptr; - - pptr =skb_header_pointer (skb, iph.len, -sizeof (_ports), _ports); -if (pptr ==NULL ) -return NF_ACCEPT ;/* Not for me */ -if (ip_vs_lookup_real_service (af, iph.protocol, - &iph.saddr, - pptr[0 ])) { -/* -* Notify the real server: there is no -* existing entry if it is not RST -* packet or not TCP packet. -*/ -if ((iph.protocol !=IPPROTO_TCP && - iph.protocol !=IPPROTO_SCTP ) - || ((iph.protocol ==IPPROTO_TCP - && !is_tcp_reset (skb, iph.len)) - || (iph.protocol ==IPPROTO_SCTP - && !is_sctp_abort (skb, - iph.len)))) { +if (likely (cp)) +return handle_response (af, skb, pp, cp, iph.len); +if (sysctl_ip_vs_nat_icmp_send && + (pp->protocol ==IPPROTO_TCP || + pp->protocol ==IPPROTO_UDP || + pp->protocol ==IPPROTO_SCTP )) { +__be16 _ports[2 ], *pptr; + + pptr =skb_header_pointer (skb, iph.len, +sizeof (_ports), _ports); +if (pptr ==NULL ) +return NF_ACCEPT ;/* Not for me */ +if (ip_vs_lookup_real_service (af, iph.protocol, + &iph.saddr, + pptr[0 ])) { +/* +* Notify the real server: there is no +* existing entry if it is not RST +* packet or not TCP packet. +*/ +if ((iph.protocol !=IPPROTO_TCP && + iph.protocol !=IPPROTO_SCTP ) + || ((iph.protocol ==IPPROTO_TCP + && !is_tcp_reset (skb, iph.len)) + || (iph.protocol ==IPPROTO_SCTP + && !is_sctp_abort (skb, + iph.len)))) {#ifdef CONFIG_IP_VS_IPV6 -if (af ==AF_INET6 ) -icmpv6_send (skb, -ICMPV6_DEST_UNREACH , -ICMPV6_PORT_UNREACH , -0 ); - else +if (af ==AF_INET6 ) { +struct net *net = +dev_net (skb_dst (skb)->dev); + +if (!skb->dev) + skb->dev = net->loopback_dev; +icmpv6_send (skb, +ICMPV6_DEST_UNREACH , +ICMPV6_PORT_UNREACH , +0 ); + } else#endif -icmp_send (skb, -ICMP_DEST_UNREACH , -ICMP_PORT_UNREACH ,0 ); -return NF_DROP ; - } +icmp_send (skb, +ICMP_DEST_UNREACH , +ICMP_PORT_UNREACH ,0 ); +return NF_DROP ; } } -IP_VS_DBG_PKT (12 , pp, skb,0 , -"packet continues traversal as normal" ); -return NF_ACCEPT ; } - -return handle_response (af, skb, pp, cp, iph.len); +IP_VS_DBG_PKT (12 , pp, skb,0 , +"ip_vs_out: packet continues traversal as normal" ); +return NF_ACCEPT ; }/* -* It is hooked at the NF_INET_FORWARD chain, used only for VS/NAT. +* It is hooked at the NF_INET_FORWARD and NF_INET_LOCAL_IN chain, +* used only for VS/NAT. * Check if packet is reply for established ip_vs_conn. */ static unsigned int
@@ -1147,7 +1156,8 @@ ip_vs_local_reply4(unsigned int hooknum, struct sk_buff *skb,#ifdef CONFIG_IP_VS_IPV6 /* -* It is hooked at the NF_INET_FORWARD chain, used only for VS/NAT. +* It is hooked at the NF_INET_FORWARD and NF_INET_LOCAL_IN chain, +* used only for VS/NAT. * Check if packet is reply for established ip_vs_conn. */ static unsigned int
@@ -1404,34 +1414,43 @@ ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, unsigned int hooknum)* and send it on its way... */ static unsigned int -ip_vs_in (unsigned int hooknum,struct sk_buff *skb, -const struct net_device *in,const struct net_device *out, -int (*okfn)(struct sk_buff *)) +ip_vs_in (unsigned int hooknum,struct sk_buff *skb,int af) {struct ip_vs_iphdr iph;struct ip_vs_protocol *pp;struct ip_vs_conn *cp; -int ret, restart, af, pkts; +int ret, restart, pkts;/* Already marked as IPVS request or reply? */ if (skb->ipvs_property)return NF_ACCEPT ; - af = (skb->protocol ==htons (ETH_P_IP )) ?AF_INET :AF_INET6 ; - -ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); -/* -* Big tappo: only PACKET_HOST, including loopback for local client -* Don't handle local packets on IPv6 for now +* Big tappo: +* - remote client: only PACKET_HOST +* - route: used for struct net when skb->dev is unset */ -if (unlikely (skb->pkt_type !=PACKET_HOST )) { -IP_VS_DBG_BUF (12 ,"packet type=%d proto=%d daddr=%s ignored\n" , - skb->pkt_type, - iph.protocol, -IP_VS_DBG_ADDR (af, &iph.daddr)); +if (unlikely ((skb->pkt_type !=PACKET_HOST && + hooknum !=NF_INET_LOCAL_OUT ) || + !skb_dst (skb))) { +ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); +IP_VS_DBG_BUF (12 ,"packet type=%d proto=%d daddr=%s" +" ignored in hook %u\n" , + skb->pkt_type, iph.protocol, +IP_VS_DBG_ADDR (af, &iph.daddr), hooknum);return NF_ACCEPT ; } +ip_vs_fill_iphdr (af,skb_network_header (skb), &iph); + +/* Bad... Do not break raw sockets */ +if (unlikely (skb->sk !=NULL && hooknum ==NF_INET_LOCAL_OUT && + af ==AF_INET )) { +struct sock *sk = skb->sk; +struct inet_sock *inet =inet_sk (skb->sk); + +if (inet && sk->sk_family ==PF_INET && inet->nodefrag) +return NF_ACCEPT ; + }#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) {
@@ -1467,11 +1486,6 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,if (unlikely (!cp)) {int v; -/* For local client packets, it could be a response */ - cp = pp->conn_out_get (af, skb, pp, &iph, iph.len,0 ); -if (cp) -return handle_response (af, skb, pp, cp, iph.len); -if (!pp->conn_schedule (af, skb, pp, &v, &cp))return v; }
@@ -1479,7 +1493,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,if (unlikely (!cp)) {/* sorry, all this trouble for a no-hit :) */ IP_VS_DBG_PKT (12 , pp, skb,0 , -"packet continues traversal as normal" ); +"ip_vs_in: packet continues traversal as normal" );return NF_ACCEPT ; }
@@ -1550,6 +1564,72 @@ out:return ret; } +/* +* AF_INET handler in NF_INET_LOCAL_IN chain +* Schedule and forward packets from remote clients +*/ +static unsigned int +ip_vs_remote_request4 (unsigned int hooknum,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +return ip_vs_in (hooknum, skb,AF_INET ); +} + +/* +* AF_INET handler in NF_INET_LOCAL_OUT chain +* Schedule and forward packets from local clients +*/ +static unsigned int +ip_vs_local_request4 (unsigned int hooknum,struct sk_buff *skb, +const struct net_device *in,const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +unsigned int verdict; + +/* Disable BH in LOCAL_OUT until all places are fixed */ +local_bh_disable (); + verdict =ip_vs_in (hooknum, skb,AF_INET ); +local_bh_enable (); +return verdict; +} + +#ifdef CONFIG_IP_VS_IPV6 + +/* +* AF_INET6 handler in NF_INET_LOCAL_IN chain +* Schedule and forward packets from remote clients +*/ +static unsigned int +ip_vs_remote_request6 (unsigned int hooknum,struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +return ip_vs_in (hooknum, skb,AF_INET6 ); +} + +/* +* AF_INET6 handler in NF_INET_LOCAL_OUT chain +* Schedule and forward packets from local clients +*/ +static unsigned int +ip_vs_local_request6 (unsigned int hooknum,struct sk_buff *skb, +const struct net_device *in,const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +unsigned int verdict; + +/* Disable BH in LOCAL_OUT until all places are fixed */ +local_bh_disable (); + verdict =ip_vs_in (hooknum, skb,AF_INET6 ); +local_bh_enable (); +return verdict; +} + +#endif +/* * It is hooked at the NF_INET_FORWARD chain, in order to catch ICMP
@@ -1590,15 +1670,23 @@ ip_vs_forward_icmp_v6(unsigned int hooknum, struct sk_buff *skb,static struct nf_hook_ops ip_vs_ops[]__read_mostly = { +/* After packet filtering, change source only for VS/NAT */ + { + .hook = ip_vs_reply4, + .owner =THIS_MODULE , + .pf =PF_INET , + .hooknum =NF_INET_LOCAL_IN , + .priority =99 , + },/* After packet filtering, forward packet through VS/DR, VS/TUN, * or VS/NAT(change destination), so that filtering rules can be * applied to IPVS. */ { - .hook = ip_vs_in, + .hook = ip_vs_remote_request4, .owner =THIS_MODULE , .pf =PF_INET , - .hooknum =NF_INET_LOCAL_IN , - .priority =100 , + .hooknum =NF_INET_LOCAL_IN , + .priority =101 , },/* Before ip_vs_in, change source only for VS/NAT */ {
@@ -1608,14 +1696,22 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { .hooknum = NF_INET_LOCAL_OUT, .priority = -99, }, +/* After mangle, schedule and forward local requests */ + { + .hook = ip_vs_local_request4, + .owner = THIS_MODULE, + .pf = PF_INET, + .hooknum = NF_INET_LOCAL_OUT, + .priority = -98, + }, /* After packet filtering (but before ip_vs_out_icmp), catch icmp * destined for 0.0.0.0/0, which is for incoming IPVS connections */ { .hook = ip_vs_forward_icmp, .owner = THIS_MODULE, .pf = PF_INET, - .hooknum = NF_INET_FORWARD, - .priority = 99, + .hooknum = NF_INET_FORWARD, + .priority = 99, }, /* After packet filtering, change source only for VS/NAT */ {
@@ -1626,15 +1722,23 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { .priority = 100, }, #ifdef CONFIG_IP_VS_IPV6 + /* After packet filtering, change source only for VS/NAT */ + { + .hook = ip_vs_reply6, + .owner = THIS_MODULE, + .pf = PF_INET6, + .hooknum = NF_INET_LOCAL_IN, + .priority = 99, + }, /* After packet filtering, forward packet through VS/DR, VS/TUN, * or VS/NAT(change destination), so that filtering rules can be * applied to IPVS. */ { - .hook = ip_vs_in, + .hook = ip_vs_remote_request6, .owner = THIS_MODULE, .pf = PF_INET6, - .hooknum = NF_INET_LOCAL_IN, - .priority = 100, + .hooknum = NF_INET_LOCAL_IN, + .priority = 101, }, /* Before ip_vs_in, change source only for VS/NAT */ {
@@ -1644,14 +1748,22 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { .hooknum = NF_INET_LOCAL_OUT, .priority = -99, }, +/* After mangle, schedule and forward local requests */ + { + .hook = ip_vs_local_request6, + .owner = THIS_MODULE, + .pf = PF_INET6, + .hooknum = NF_INET_LOCAL_OUT, + .priority = -98, + }, /* After packet filtering (but before ip_vs_out_icmp), catch icmp * destined for 0.0.0.0/0, which is for incoming IPVS connections */ { .hook = ip_vs_forward_icmp_v6, .owner = THIS_MODULE, .pf = PF_INET6, - .hooknum = NF_INET_FORWARD, - .priority = 99, + .hooknum = NF_INET_FORWARD, + .priority = 99, }, /* After packet filtering, change source only for VS/NAT */ {
net/netfilter/ipvs/ip_vs_xmit.c +36 -15
100 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 53/72 ipvs: inherit forwarding method in backup
In reply to [email protected]From: Julian Anastasov <[email protected]>
Connections in backup server should inherit the
forwarding method from real server. It is a way to fix a problem where the forwarding method in backup connection is damaged by logical OR operation with the real server's connection flags. And the change is needed for setups where the backup server uses different forwarding method for the same real servers.
--- net/netfilter/ipvs/ip_vs_conn.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +2 -0
@@ -563,6 +563,8 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)*/ if (!(cp->flags &IP_VS_CONN_F_TEMPLATE )) conn_flags &= ~IP_VS_CONN_F_INACTIVE ; +/* connections inherit forwarding method from dest */ + cp->flags &= ~IP_VS_CONN_F_FWD_MASK ; } cp->flags |= conn_flags; cp->dest = dest;
Signature · 1 line
1.7.1
PATCH 54/72 ipvs: provide address family for debugging
In reply to [email protected]From: Julian Anastasov <[email protected]>
As skb->protocol is not valid in LOCAL_OUT add
parameter for address family in packet debugging functions. Even if ports are not present in AH and ESP change them to use ip_vs_tcpudp_debug_packet to show at least valid addresses as before. This patch removes the last user of skb->protocol in IPVS.
--- include/net/ip_vs.h | 17 +++++----- net/netfilter/ipvs/ip_vs_core.c | 41 ++++++++++++++---------- net/netfilter/ipvs/ip_vs_proto.c | 8 ++-- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 52 +----------------------------- net/netfilter/ipvs/ip_vs_proto_sctp.c | 2 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 4 +- net/netfilter/ipvs/ip_vs_proto_udp.c | 4 +- net/netfilter/ipvs/ip_vs_xmit.c | 18 ++++++----- 8 files changed, 54 insertions(+), 92 deletions(-)
include/net/ip_vs.h +9 -8
@@ -136,24 +136,24 @@ static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,if (net_ratelimit ()) \ printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ } while (0) -#define IP_VS_DBG_PKT (level, pp, skb, ofs, msg) \ +#define IP_VS_DBG_PKT (level, af, pp, skb, ofs, msg) \ do { \ if (level <= ip_vs_get_debug_level()) \ - pp->debug_packet(pp, skb, ofs, msg); \ + pp->debug_packet(af, pp, skb, ofs, msg); \ } while (0) -#define IP_VS_DBG_RL_PKT (level, pp, skb, ofs, msg) \ +#define IP_VS_DBG_RL_PKT (level, af, pp, skb, ofs, msg) \ do { \ if (level <= ip_vs_get_debug_level() && \ net_ratelimit()) \ - pp->debug_packet(pp, skb, ofs, msg); \ + pp->debug_packet(af, pp, skb, ofs, msg); \ } while (0)#else /* NO DEBUGGING at ALL */ #define IP_VS_DBG_BUF(level, msg...) do {} while (0) #define IP_VS_ERR_BUF(msg...) do {} while (0) #define IP_VS_DBG(level, msg...) do {} while (0) #define IP_VS_DBG_RL(msg...) do {} while (0) -#define IP_VS_DBG_PKT (level, pp, skb, ofs, msg) do {} while (0) -#define IP_VS_DBG_RL_PKT (level, pp, skb, ofs, msg) do {} while (0) +#define IP_VS_DBG_PKT (level, af, pp, skb, ofs, msg) do {} while (0) +#define IP_VS_DBG_RL_PKT (level, af, pp, skb, ofs, msg) do {} while (0)#endif #define IP_VS_BUG () BUG()
@@ -345,7 +345,7 @@ struct ip_vs_protocol {int (*app_conn_bind)(struct ip_vs_conn *cp); -void (*debug_packet)(struct ip_vs_protocol *pp, +void (*debug_packet)(int af,struct ip_vs_protocol *pp,const struct sk_buff *skb,int offset,const char *msg);
@@ -828,7 +828,8 @@ extern int ip_vs_set_state_timeout(int *table, int num, const char *const *names, const char *name, int to);extern void -ip_vs_tcpudp_debug_packet (struct ip_vs_protocol *pp,const struct sk_buff *skb, +ip_vs_tcpudp_debug_packet (int af,struct ip_vs_protocol *pp, +const struct sk_buff *skb,int offset,const char *msg);extern struct ip_vs_protocol ip_vs_protocol_tcp;
net/netfilter/ipvs/ip_vs_core.c +24 -17
120 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_proto.c +4 -4
@@ -172,8 +172,8 @@ ip_vs_tcpudp_debug_packet_v4(struct ip_vs_protocol *pp,else if (ih->frag_off &htons (IP_OFFSET ))sprintf (buf,"%pI4->%pI4 frag" , &ih->saddr, &ih->daddr);else { -__be16 _ports[2 ], *pptr -; +__be16 _ports[2 ], *pptr; + pptr =skb_header_pointer (skb, offset + ih->ihl*4 ,sizeof (_ports), _ports);if (pptr ==NULL )
@@ -223,13 +223,13 @@ ip_vs_tcpudp_debug_packet_v6(struct ip_vs_protocol *pp,void -ip_vs_tcpudp_debug_packet (struct ip_vs_protocol *pp, +ip_vs_tcpudp_debug_packet (int af,struct ip_vs_protocol *pp,const struct sk_buff *skb,int offset,const char *msg) {#ifdef CONFIG_IP_VS_IPV6 -if (skb->protocol ==htons (ETH_P_IPV6 )) +if (af ==AF_INET6 )ip_vs_tcpudp_debug_packet_v6 (pp, skb, offset, msg); else#endif
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +2 -50
70 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_proto_sctp.c +1 -1
@@ -176,7 +176,7 @@ sctp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)if (val != cmp) {/* CRC failure, dump it. */ -IP_VS_DBG_RL_PKT (0 , pp, skb,0 , +IP_VS_DBG_RL_PKT (0 , af, pp, skb,0 ,"Failed checksum for" );return 0 ; }
net/netfilter/ipvs/ip_vs_proto_tcp.c +2 -2
@@ -300,7 +300,7 @@ tcp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp) skb->len - tcphoff, ipv6_hdr(skb)->nexthdr, skb->csum)) { -IP_VS_DBG_RL_PKT (0 , pp, skb,0 , +IP_VS_DBG_RL_PKT (0 , af, pp, skb,0 ,"Failed checksum for" );return 0 ; }
@@ -311,7 +311,7 @@ tcp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp) skb->len - tcphoff, ip_hdr(skb)->protocol, skb->csum)) { -IP_VS_DBG_RL_PKT (0 , pp, skb,0 , +IP_VS_DBG_RL_PKT (0 , af, pp, skb,0 ,"Failed checksum for" );return 0 ; }
net/netfilter/ipvs/ip_vs_proto_udp.c +2 -2
@@ -314,7 +314,7 @@ udp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp) skb->len - udphoff, ipv6_hdr(skb)->nexthdr, skb->csum)) { -IP_VS_DBG_RL_PKT (0 , pp, skb,0 , +IP_VS_DBG_RL_PKT (0 , af, pp, skb,0 ,"Failed checksum for" );return 0 ; }
@@ -325,7 +325,7 @@ udp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp) skb->len - udphoff, ip_hdr(skb)->protocol, skb->csum)) { -IP_VS_DBG_RL_PKT (0 , pp, skb,0 , +IP_VS_DBG_RL_PKT (0 , af, pp, skb,0 ,"Failed checksum for" );return 0 ; }
net/netfilter/ipvs/ip_vs_xmit.c +10 -8
@@ -543,7 +543,8 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { -IP_VS_DBG_RL_PKT (10 , pp, skb,0 ,"ip_vs_nat_xmit(): " +IP_VS_DBG_RL_PKT (10 ,AF_INET , pp, skb,0 , +"ip_vs_nat_xmit(): " "stopping DNAT to local address" ); goto tx_error_put; }
@@ -552,7 +553,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,/* From world but DNAT to loopback address? */ if (local &&ipv4_is_loopback (rt->rt_dst) &&skb_rtable (skb)->fl.iif) { -IP_VS_DBG_RL_PKT (1 , pp, skb,0 ,"ip_vs_nat_xmit(): " +IP_VS_DBG_RL_PKT (1 ,AF_INET , pp, skb,0 ,"ip_vs_nat_xmit(): " "stopping DNAT to loopback address" ); goto tx_error_put; }
@@ -561,7 +562,8 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, mtu =dst_mtu (&rt->dst);if ((skb->len > mtu) && (iph->frag_off &htons (IP_DF ))) {icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu)); -IP_VS_DBG_RL_PKT (0 , pp, skb,0 ,"ip_vs_nat_xmit(): frag needed for" ); +IP_VS_DBG_RL_PKT (0 ,AF_INET , pp, skb,0 , +"ip_vs_nat_xmit(): frag needed for" ); goto tx_error_put; }
@@ -593,7 +595,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, goto tx_error; } -IP_VS_DBG_PKT (10 , pp, skb,0 ,"After DNAT" ); +IP_VS_DBG_PKT (10 ,AF_INET , pp, skb,0 ,"After DNAT" );/* FIXME: when application helper enlarges the packet and the length is larger than the MTU of outgoing device, there will be still
@@ -654,7 +656,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { -IP_VS_DBG_RL_PKT (10 , pp, skb,0 , +IP_VS_DBG_RL_PKT (10 ,AF_INET6 , pp, skb,0 ,"ip_vs_nat_xmit_v6(): " "stopping DNAT to local address" ); goto tx_error_put;
@@ -665,7 +667,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,/* From world but DNAT to loopback address? */ if (local && skb->dev && !(skb->dev->flags &IFF_LOOPBACK ) &&ipv6_addr_type (&rt->rt6i_dst.addr) &IPV6_ADDR_LOOPBACK ) { -IP_VS_DBG_RL_PKT (1 , pp, skb,0 , +IP_VS_DBG_RL_PKT (1 ,AF_INET6 , pp, skb,0 ,"ip_vs_nat_xmit_v6(): " "stopping DNAT to loopback address" ); goto tx_error_put;
@@ -680,7 +682,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, skb->dev = net->loopback_dev; }icmpv6_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu); -IP_VS_DBG_RL_PKT (0 , pp, skb,0 , +IP_VS_DBG_RL_PKT (0 ,AF_INET6 , pp, skb,0 ,"ip_vs_nat_xmit_v6(): frag needed for" ); goto tx_error_put; }
@@ -706,7 +708,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,dst_release (&rt->dst); } -IP_VS_DBG_PKT (10 , pp, skb,0 ,"After DNAT" ); +IP_VS_DBG_PKT (10 ,AF_INET6 , pp, skb,0 ,"After DNAT" );/* FIXME: when application helper enlarges the packet and the length is larger than the MTU of outgoing device, there will be still
Signature · 1 line
1.7.1
PATCH 55/72 tproxy: kick out TIME_WAIT sockets in case a new connection comes in with the same tuple
In reply to [email protected]From: Balazs Scheidler <[email protected]>
Without tproxy redirections an incoming SYN kicks out conflicting TIME_WAIT sockets, in order to handle clients that reuse ports within the TIME_WAIT period.
The same mechanism didn't work in case TProxy is involved in finding the proper socket, as the time_wait processing code looked up the listening socket assuming that the listener addr/port matches those of the established connection.
This is not the case with TProxy as the listener addr/port is possibly changed with the tproxy rule.
--- include/net/netfilter/nf_tproxy_core.h | 6 ++- net/netfilter/nf_tproxy_core.c | 29 ++++++++++---- net/netfilter/xt_TPROXY.c | 68 +++++++++++++++++++++++++++++-- net/netfilter/xt_socket.c | 2 +- 4 files changed, 90 insertions(+), 15 deletions(-)
include/net/netfilter/nf_tproxy_core.h +5 -1
@@ -8,12 +8,16 @@#include <net/inet_sock.h> #include <net/tcp.h> +#define NFT_LOOKUP_ANY 0 +#define NFT_LOOKUP_LISTENER 1 +#define NFT_LOOKUP_ESTABLISHED 2 +/* look up and get a reference to a matching socket */ extern struct sock *nf_tproxy_get_sock_v4 (struct net *net,const u8 protocol,const __be32 saddr,const __be32 daddr,const __be16 sport,const __be16 dport, -const struct net_device *in,bool listening); +const struct net_device *in,int lookup_type);static inline void nf_tproxy_put_sock (struct sock *sk)
net/netfilter/nf_tproxy_core.c +21 -8
@@ -22,21 +22,34 @@ struct sock * nf_tproxy_get_sock_v4(struct net *net, const u8 protocol, const __be32 saddr, const __be32 daddr, const __be16 sport, const __be16 dport, - const struct net_device *in, bool listening_only) + const struct net_device *in, int lookup_type) { struct sock *sk;/* look up socket */ switch (protocol) { case IPPROTO_TCP: - if (listening_only) - sk = __inet_lookup_listener(net, &tcp_hashinfo, - daddr, ntohs(dport), - in->ifindex); - else + switch (lookup_type) { + case NFT_LOOKUP_ANY: sk = __inet_lookup(net, &tcp_hashinfo, saddr, sport, daddr, dport, in->ifindex); + break; + case NFT_LOOKUP_LISTENER: + sk = inet_lookup_listener(net, &tcp_hashinfo, + daddr, dport, + in->ifindex); + break; + case NFT_LOOKUP_ESTABLISHED: + sk = inet_lookup_established(net, &tcp_hashinfo, + saddr, sport, daddr, dport, + in->ifindex); + break; + default: + WARN_ON(1); + sk = NULL; + break; + } break; case IPPROTO_UDP: sk = udp4_lib_lookup(net, saddr, sport, daddr, dport,
@@ -47,8 +60,8 @@ nf_tproxy_get_sock_v4(struct net *net, const u8 protocol, sk =NULL ; } -pr_debug ("tproxy socket lookup: proto %u %08x:%u -> %08x:%u, listener only: %d, sock %p\n" , - protocol,ntohl (saddr),ntohs (sport),ntohl (daddr),ntohs (dport), listening_only, sk); +pr_debug ("tproxy socket lookup: proto %u %08x:%u -> %08x:%u, lookup type: %d, sock %p\n" , + protocol,ntohl (saddr),ntohs (sport),ntohl (daddr),ntohs (dport), lookup_type, sk);return sk; }
net/netfilter/xt_TPROXY.c +63 -5
80 lines not on this page · raw message
net/netfilter/xt_socket.c +1 -1
@@ -142,7 +142,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par,#endif sk =nf_tproxy_get_sock_v4 (dev_net (skb->dev), protocol, - saddr, daddr, sport, dport, par->in, false); + saddr, daddr, sport, dport, par->in,NFT_LOOKUP_ANY );if (sk !=NULL ) {bool wildcard;bool transparent = true;
Signature · 1 line
1.7.1
PATCH 56/72 tproxy: add lookup type checks for UDP in nf_tproxy_get_sock_v4()
In reply to [email protected]From: Balazs Scheidler <[email protected]>
Also, inline this function as the lookup_type is always a literal and inlining removes branches performed at runtime.
--- include/net/netfilter/nf_tproxy_core.h | 116 +++++++++++++++++++++++++++++++- net/netfilter/nf_tproxy_core.c | 48 ------------- 2 files changed, 114 insertions(+), 50 deletions(-)
include/net/netfilter/nf_tproxy_core.h +114 -2
@@ -13,11 +13,123 @@#define NFT_LOOKUP_ESTABLISHED 2/* look up and get a reference to a matching socket */ -extern struct sock * + + +/* This function is used by the 'TPROXY' target and the 'socket' +* match. The following lookups are supported: +* +* Explicit TProxy target rule +* =========================== +* +* This is used when the user wants to intercept a connection matching +* an explicit iptables rule. In this case the sockets are assumed +* matching in preference order: +* +* - match: if there's a fully established connection matching the +* _packet_ tuple, it is returned, assuming the redirection +* already took place and we process a packet belonging to an +* established connection +* +* - match: if there's a listening socket matching the redirection +* (e.g. on-port & on-ip of the connection), it is returned, +* regardless if it was bound to 0.0.0.0 or an explicit +* address. The reasoning is that if there's an explicit rule, it +* does not really matter if the listener is bound to an interface +* or to 0. The user already stated that he wants redirection +* (since he added the rule). +* +* "socket" match based redirection (no specific rule) +* =================================================== +* +* There are connections with dynamic endpoints (e.g. FTP data +* connection) that the user is unable to add explicit rules +* for. These are taken care of by a generic "socket" rule. It is +* assumed that the proxy application is trusted to open such +* connections without explicit iptables rule (except of course the +* generic 'socket' rule). In this case the following sockets are +* matched in preference order: +* +* - match: if there's a fully established connection matching the +* _packet_ tuple +* +* - match: if there's a non-zero bound listener (possibly with a +* non-local address) We don't accept zero-bound listeners, since +* then local services could intercept traffic going through the +* box. +* +* Please note that there's an overlap between what a TPROXY target +* and a socket match will match. Normally if you have both rules the +* "socket" match will be the first one, effectively all packets +* belonging to established connections going through that one. +*/ +static inline struct sock *nf_tproxy_get_sock_v4 (struct net *net,const u8 protocol,const __be32 saddr,const __be32 daddr,const __be16 sport,const __be16 dport, -const struct net_device *in,int lookup_type); +const struct net_device *in,int lookup_type) +{ +struct sock *sk; + +/* look up socket */ +switch (protocol) { +case IPPROTO_TCP : +switch (lookup_type) { +case NFT_LOOKUP_ANY : + sk =__inet_lookup (net, &tcp_hashinfo, + saddr, sport, daddr, dport, + in->ifindex); +break ; +case NFT_LOOKUP_LISTENER : + sk =inet_lookup_listener (net, &tcp_hashinfo, + daddr, dport, + in->ifindex); + +/* NOTE: we return listeners even if bound to +* 0.0.0.0, those are filtered out in +* xt_socket, since xt_TPROXY needs 0 bound +* listeners too */ + +break ; +case NFT_LOOKUP_ESTABLISHED : + sk =inet_lookup_established (net, &tcp_hashinfo, + saddr, sport, daddr, dport, + in->ifindex); +break ; +default : +WARN_ON (1 ); + sk =NULL ; +break ; + } +break ; +case IPPROTO_UDP : + sk =udp4_lib_lookup (net, saddr, sport, daddr, dport, + in->ifindex); +if (sk && lookup_type !=NFT_LOOKUP_ANY ) { +int connected = (sk->sk_state ==TCP_ESTABLISHED ); +int wildcard = (inet_sk (sk)->inet_rcv_saddr ==0 ); + +/* NOTE: we return listeners even if bound to +* 0.0.0.0, those are filtered out in +* xt_socket, since xt_TPROXY needs 0 bound +* listeners too */ +if ((lookup_type ==NFT_LOOKUP_ESTABLISHED && (!connected || wildcard)) || + (lookup_type ==NFT_LOOKUP_LISTENER && connected)) { +sock_put (sk); + sk =NULL ; + } + } +break ; +default : +WARN_ON (1 ); + sk =NULL ; + } + +pr_debug ("tproxy socket lookup: proto %u %08x:%u -> %08x:%u, lookup type: %d, sock %p\n" , + protocol,ntohl (saddr),ntohs (sport),ntohl (daddr),ntohs (dport), lookup_type, sk); + +return sk; +} +static inline void nf_tproxy_put_sock (struct sock *sk)
net/netfilter/nf_tproxy_core.c +0 -48
54 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 57/72 tproxy: fix hash locking issue when using port redirection in __inet_inherit_port()
In reply to [email protected]From: Balazs Scheidler <[email protected]>
When __inet_inherit_port() is called on a tproxy connection the wrong locks are held for the inet_bind_bucket it is added to. __inet_inherit_port() made an implicit assumption that the listener's port number (and thus its bind bucket). Unfortunately, if you're using the TPROXY target to redirect skbs to a transparent proxy that assumption is not true anymore and things break.
This patch adds code to __inet_inherit_port() so that it can handle this case by looking up or creating a new bind bucket for the child socket and updates callers of __inet_inherit_port() to gracefully handle __inet_inherit_port() failing.
Reported by and original patch from Stephen Buck <[email protected]>. See http://marc.info/?t=128169268200001&r=1&w=2 for the original discussion.
--- include/net/inet_hashtables.h | 2 +- net/dccp/ipv4.c | 10 +++++++--- net/dccp/ipv6.c | 10 +++++++--- net/ipv4/inet_hashtables.c | 28 ++++++++++++++++++++++++++-- net/ipv4/tcp_ipv4.c | 10 +++++++--- net/ipv6/tcp_ipv6.c | 12 ++++++++---- 6 files changed, 56 insertions(+), 16 deletions(-)
include/net/inet_hashtables.h +1 -1
@@ -245,7 +245,7 @@ static inline int inet_sk_listen_hashfn(const struct sock *sk) }/* Caller must disable local BH processing. */ -extern void __inet_inherit_port (struct sock *sk,struct sock *child); +extern int __inet_inherit_port (struct sock *sk,struct sock *child);extern void inet_put_port (struct sock *sk);
net/dccp/ipv4.c +7 -3
@@ -392,7 +392,7 @@ struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb, newsk =dccp_create_openreq_child (sk, req, skb);if (newsk ==NULL ) - goto exit; + goto exit_nonewsk;sk_setup_caps (newsk, dst);
@@ -409,16 +409,20 @@ struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb,dccp_sync_mss (newsk,dst_mtu (dst)); +if (__inet_inherit_port (sk, newsk) <0 ) { +sock_put (newsk); + goto exit; + }__inet_hash_nolisten (newsk,NULL ); -__inet_inherit_port (sk, newsk);return newsk; exit_overflow:NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENOVERFLOWS ); +exit_nonewsk: +dst_release (dst); exit:NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENDROPS ); -dst_release (dst);return NULL ; }
net/dccp/ipv6.c +7 -3
@@ -564,7 +564,7 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk, newsk =dccp_create_openreq_child (sk, req, skb);if (newsk ==NULL ) - goto out; + goto out_nonewsk;/* * No need to charge this sock to the relevant IPv6 refcnt debug socks
@@ -632,18 +632,22 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk, newinet->inet_daddr = newinet->inet_saddr =LOOPBACK4_IPV6 ; newinet->inet_rcv_saddr =LOOPBACK4_IPV6 ; +if (__inet_inherit_port (sk, newsk) <0 ) { +sock_put (newsk); + goto out; + }__inet6_hash (newsk,NULL ); -__inet_inherit_port (sk, newsk);return newsk; out_overflow:NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENOVERFLOWS ); +out_nonewsk: +dst_release (dst); out:NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENDROPS );if (opt !=NULL && opt != np->opt)sock_kfree_s (sk, opt, opt->tot_len); -dst_release (dst);return NULL ; }
net/ipv4/inet_hashtables.c +26 -2
@@ -101,19 +101,43 @@ void inet_put_port(struct sock *sk) }EXPORT_SYMBOL (inet_put_port); -void __inet_inherit_port (struct sock *sk,struct sock *child) +int __inet_inherit_port (struct sock *sk,struct sock *child) {struct inet_hashinfo *table = sk->sk_prot->h.hashinfo; -const int bhash =inet_bhashfn (sock_net (sk),inet_sk (child)->inet_num, +unsigned short port =inet_sk (child)->inet_num; +const int bhash =inet_bhashfn (sock_net (sk), port, table->bhash_size);struct inet_bind_hashbucket *head = &table->bhash[bhash];struct inet_bind_bucket *tb;spin_lock (&head->lock); tb =inet_csk (sk)->icsk_bind_hash; +if (tb->port != port) { +/* NOTE: using tproxy and redirecting skbs to a proxy +* on a different listener port breaks the assumption +* that the listener socket's icsk_bind_hash is the same +* as that of the child socket. We have to look up or +* create a new bind bucket for the child here. */ +struct hlist_node *node; +inet_bind_bucket_for_each (tb, node, &head->chain) { +if (net_eq (ib_net (tb),sock_net (sk)) && + tb->port == port) +break ; + } +if (!node) { + tb =inet_bind_bucket_create (table->bind_bucket_cachep, +sock_net (sk), head, port); +if (!tb) { +spin_unlock (&head->lock); +return -ENOMEM ; + } + } + }sk_add_bind_node (child, &tb->owners);inet_csk (child)->icsk_bind_hash = tb;spin_unlock (&head->lock); + +return 0 ; }EXPORT_SYMBOL_GPL (__inet_inherit_port);
net/ipv4/tcp_ipv4.c +7 -3
@@ -1422,7 +1422,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb, newsk =tcp_create_openreq_child (sk, req, skb);if (!newsk) - goto exit; + goto exit_nonewsk; newsk->sk_gso_type =SKB_GSO_TCPV4 ;sk_setup_caps (newsk, dst);
@@ -1469,16 +1469,20 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb, }#endif +if (__inet_inherit_port (sk, newsk) <0 ) { +sock_put (newsk); + goto exit; + }__inet_hash_nolisten (newsk,NULL ); -__inet_inherit_port (sk, newsk);return newsk; exit_overflow:NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENOVERFLOWS ); +exit_nonewsk: +dst_release (dst); exit:NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENDROPS ); -dst_release (dst);return NULL ; }EXPORT_SYMBOL (tcp_v4_syn_recv_sock);
net/ipv6/tcp_ipv6.c +8 -4
@@ -1409,7 +1409,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, newsk =tcp_create_openreq_child (sk, req, skb);if (newsk ==NULL ) - goto out; + goto out_nonewsk;/* * No need to charge this sock to the relevant IPv6 refcnt debug socks
@@ -1497,18 +1497,22 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, }#endif +if (__inet_inherit_port (sk, newsk) <0 ) { +sock_put (newsk); + goto out; + }__inet6_hash (newsk,NULL ); -__inet_inherit_port (sk, newsk);return newsk; out_overflow:NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENOVERFLOWS ); -out: -NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENDROPS ); +out_nonewsk:if (opt && opt != np->opt)sock_kfree_s (sk, opt, opt->tot_len);dst_release (dst); +out: +NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_LISTENDROPS );return NULL ; }
Signature · 1 line
1.7.1
PATCH 58/72 nf_nat: restrict ICMP translation for embedded header
In reply to [email protected]From: Julian Anastasov <[email protected]>
Skip ICMP translation of embedded protocol header
if NAT bits are not set. Needed for IPVS to see the original embedded addresses because for IPVS traffic the IPS_SRC_NAT_BIT and IPS_DST_NAT_BIT bits are not set. It happens when IPVS performs DNAT for client packets after using nf_conntrack_alter_reply to expect replies from real server.
--- net/ipv4/netfilter/nf_nat_core.c | 29 +++++++++++++++-------------- 1 files changed, 15 insertions(+), 14 deletions(-)
net/ipv4/netfilter/nf_nat_core.c +15 -14
@@ -462,6 +462,18 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,return 0 ; } +if (manip ==IP_NAT_MANIP_SRC ) + statusbit =IPS_SRC_NAT ; +else + statusbit =IPS_DST_NAT ; + +/* Invert if this is reply dir. */ +if (dir ==IP_CT_DIR_REPLY ) + statusbit ^=IPS_NAT_MASK ; + +if (!(ct->status & statusbit)) +return 1 ; +pr_debug ("icmp_reply_translation: translating error %p manip %u " "dir %s\n" , skb, manip, dir ==IP_CT_DIR_ORIGINAL ?"ORIG" :"REPLY" );
@@ -496,20 +508,9 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,/* Change outer to look the reply to an incoming packet * (proto 0 means don't invert per-proto part). */ -if (manip ==IP_NAT_MANIP_SRC ) - statusbit =IPS_SRC_NAT ; -else - statusbit =IPS_DST_NAT ; - -/* Invert if this is reply dir. */ -if (dir ==IP_CT_DIR_REPLY ) - statusbit ^=IPS_NAT_MASK ; - -if (ct->status & statusbit) { -nf_ct_invert_tuplepr (&target, &ct->tuplehash[!dir].tuple); -if (!manip_pkt (0 , skb,0 , &target, manip)) -return 0 ; - } +nf_ct_invert_tuplepr (&target, &ct->tuplehash[!dir].tuple); +if (!manip_pkt (0 , skb,0 , &target, manip)) +return 0 ;return 1 ; }
Signature · 1 line
1.7.1
PATCH 59/72 tproxy: split off ipv6 defragmentation to a separate module
In reply to [email protected]From: Balazs Scheidler <[email protected]>
Like with IPv4, TProxy needs IPv6 defragmentation but does not require connection tracking. Since defragmentation was coupled with conntrack, I split off the two, creating an nf_defrag_ipv6 module, similar to the already existing nf_defrag_ipv4.
--- include/net/netfilter/ipv6/nf_defrag_ipv6.h | 6 + net/ipv6/netfilter/Makefile | 5 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 78 +-------------- net/ipv6/netfilter/nf_conntrack_reasm.c | 14 +++- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 131 ++++++++++++++++++++++++ 5 files changed, 156 insertions(+), 78 deletions(-) create mode 100644 include/net/netfilter/ipv6/nf_defrag_ipv6.h create mode 100644 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c
include/net/netfilter/ipv6/nf_defrag_ipv6.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _NF_DEFRAG_IPV6_H +#define _NF_DEFRAG_IPV6_H + +extern void nf_defrag_ipv6_enable (void ); + +#endif /* _NF_DEFRAG_IPV6_H */
net/ipv6/netfilter/Makefile +3 -2
@@ -11,10 +11,11 @@ obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o obj-$(CONFIG_IP6_NF_SECURITY) += ip6table_security.o # objects for l3 independent conntrack -nf_conntrack_ipv6-objs := nf_conntrack_l3proto_ipv6.o nf_conntrack_proto_icmpv6.o nf_conntrack_reasm.o +nf_conntrack_ipv6-objs := nf_conntrack_l3proto_ipv6.o nf_conntrack_proto_icmpv6.o +nf_defrag_ipv6-objs := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o # l3 independent conntrack -obj-$(CONFIG_NF_CONNTRACK_IPV6) += nf_conntrack_ipv6.o +obj-$(CONFIG_NF_CONNTRACK_IPV6) += nf_conntrack_ipv6.o nf_defrag_ipv6.o # matches obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +3 -75
136 lines not on this page · raw message
net/ipv6/netfilter/nf_conntrack_reasm.c +13 -1
@@ -73,7 +73,7 @@ static struct inet_frags nf_frags;static struct netns_frags nf_init_frags; #ifdef CONFIG_SYSCTL -struct ctl_table nf_ct_ipv6_sysctl_table[] = { +struct ctl_table nf_ct_frag6_sysctl_table[] = { { .procname = "nf_conntrack_frag6_timeout", .data = &nf_init_frags.timeout,
@@ -97,6 +97,8 @@ struct ctl_table nf_ct_ipv6_sysctl_table[] = { }, { } }; + +static struct ctl_table_header *nf_ct_frag6_sysctl_header;#endif static unsigned int nf_hashfn (struct inet_frag_queue *q)
@@ -623,11 +625,21 @@ int nf_ct_frag6_init(void)inet_frags_init_net (&nf_init_frags);inet_frags_init (&nf_frags); + nf_ct_frag6_sysctl_header =register_sysctl_paths (nf_net_netfilter_sysctl_path, + nf_ct_frag6_sysctl_table); +if (!nf_ct_frag6_sysctl_header) { +inet_frags_fini (&nf_frags); +return -ENOMEM ; + } +return 0 ; }void nf_ct_frag6_cleanup (void ) { +unregister_sysctl_table (nf_ct_frag6_sysctl_header); + nf_ct_frag6_sysctl_header =NULL ; +inet_frags_fini (&nf_frags); nf_init_frags.low_thresh =0 ;
net/ipv6/netfilter/nf_defrag_ipv6_hooks.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 60/72 tproxy: added const specifiers to udp lookup functions
In reply to [email protected]From: Balazs Scheidler <[email protected]>
The parameters for various UDP lookup functions were non-const, even though they could be const. TProxy has some const references and instead of downcasting it, I added const specifiers along the path.
--- net/ipv6/udp.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
net/ipv6/udp.c +4 -4
@@ -122,8 +122,8 @@ static void udp_v6_rehash(struct sock *sk)static inline int compute_score (struct sock *sk,struct net *net,unsigned short hnum, -struct in6_addr *saddr,__be16 sport, -struct in6_addr *daddr,__be16 dport, +const struct in6_addr *saddr,__be16 sport, +const struct in6_addr *daddr,__be16 dport,int dif) {int score =-1 ;
@@ -239,8 +239,8 @@ exact_match: }static struct sock *__udp6_lib_lookup (struct net *net, -struct in6_addr *saddr,__be16 sport, -struct in6_addr *daddr,__be16 dport, +const struct in6_addr *saddr,__be16 sport, +const struct in6_addr *daddr,__be16 dport,int dif,struct udp_table *udptable) {struct sock *sk, *result;
Signature · 1 line
1.7.1
PATCH 61/72 tproxy: added udp6_lib_lookup function
In reply to [email protected]From: Balazs Scheidler <[email protected]>
Just like with IPv4, we need access to the UDP hash table to look up local sockets, but instead of exporting the global udp_table, export a lookup function.
--- include/net/udp.h | 3 +++ net/ipv6/udp.c | 8 ++++++++ 2 files changed, 11 insertions(+), 0 deletions(-)
include/net/udp.h +3 -0
@@ -183,6 +183,9 @@ extern int udp_lib_setsockopt(struct sock *sk, int level, int optname,extern struct sock *udp4_lib_lookup (struct net *net,__be32 saddr,__be16 sport,__be32 daddr,__be16 dport,int dif); +extern struct sock *udp6_lib_lookup (struct net *net,const struct in6_addr *saddr,__be16 sport, +const struct in6_addr *daddr,__be16 dport, +int dif);/* * SNMP statistics for UDP and UDP-Lite
net/ipv6/udp.c +8 -0
@@ -320,6 +320,14 @@ static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb, udptable); } +struct sock *udp6_lib_lookup (struct net *net,const struct in6_addr *saddr,__be16 sport, +const struct in6_addr *daddr,__be16 dport,int dif) +{ +return __udp6_lib_lookup (net, saddr, sport, daddr, dport, dif, &udp_table); +} +EXPORT_SYMBOL_GPL (udp6_lib_lookup); + +/* * This should be easy, if there is something there we * return it, otherwise we block.
Signature · 1 line
1.7.1
PATCH 62/72 tproxy: added tproxy sockopt interface in the IPV6 layer
In reply to [email protected]From: Balazs Scheidler <[email protected]>
Support for IPV6_RECVORIGDSTADDR sockopt for UDP sockets were contributed by Harry Mason.
--- include/linux/in6.h | 4 ++++ include/linux/ipv6.h | 4 +++- net/ipv6/datagram.c | 19 +++++++++++++++++++ net/ipv6/ipv6_sockglue.c | 23 +++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletions(-)
include/linux/in6.h +4 -0
@@ -268,6 +268,10 @@ struct in6_flowlabel_req {/* RFC5082: Generalized Ttl Security Mechanism */ #define IPV6_MINHOPCOUNT 73 +#define IPV6_ORIGDSTADDR 74 +#define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR +#define IPV6_TRANSPARENT 75 +/* * Multicast Routing: * see include/linux/mroute6.h.
include/linux/ipv6.h +3 -1
@@ -341,7 +341,9 @@ struct ipv6_pinfo { odstopts:1, rxflow:1, rxtclass:1, - rxpmtu:1; + rxpmtu:1, + rxorigdstaddr:1; +/* 2 bits hole */ } bits;__u16 all; } rxopt;
net/ipv6/datagram.c +19 -0
@@ -577,6 +577,25 @@ int datagram_recv_ctl(struct sock *sk, struct msghdr *msg, struct sk_buff *skb)u8 *ptr = nh + opt->dst1;put_cmsg (msg,SOL_IPV6 ,IPV6_2292DSTOPTS , (ptr[1 ]+1 )<<3 , ptr); } +if (np->rxopt.bits.rxorigdstaddr) { +struct sockaddr_in6 sin6; +u16 *ports = (u16 *)skb_transport_header (skb); + +if (skb_transport_offset (skb) +4 <= skb->len) { +/* All current transport protocols have the port numbers in the +* first four bytes of the transport header and this function is +* written with this assumption in mind. +*/ + + sin6.sin6_family =AF_INET6 ; +ipv6_addr_copy (&sin6.sin6_addr, &ipv6_hdr (skb)->daddr); + sin6.sin6_port = ports[1 ]; + sin6.sin6_flowinfo =0 ; + sin6.sin6_scope_id =0 ; + +put_cmsg (msg,SOL_IPV6 ,IPV6_ORIGDSTADDR ,sizeof (sin6), &sin6); + } + }return 0 ; }
net/ipv6/ipv6_sockglue.c +23 -0
@@ -342,6 +342,21 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv =0 ;break ; +case IPV6_TRANSPARENT : +if (optlen <sizeof (int )) + goto e_inval; +/* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */ +inet_sk (sk)->transparent = valbool; + retv =0 ; +break ; + +case IPV6_RECVORIGDSTADDR : +if (optlen <sizeof (int )) + goto e_inval; + np->rxopt.bits.rxorigdstaddr = valbool; + retv =0 ; +break ; +case IPV6_HOPOPTS :case IPV6_RTHDRDSTOPTS :case IPV6_RTHDR :
@@ -1104,6 +1119,14 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,break ; } +case IPV6_TRANSPARENT : + val =inet_sk (sk)->transparent; +break ; + +case IPV6_RECVORIGDSTADDR : + val = np->rxopt.bits.rxorigdstaddr; +break ; +case IPV6_UNICAST_HOPS :case IPV6_MULTICAST_HOPS : {
Signature · 1 line
1.7.1
PATCH 63/72 tproxy: allow non-local binds of IPv6 sockets if IP_TRANSPARENT is enabled
In reply to [email protected]From: Balazs Scheidler <[email protected]>
--- net/ipv6/af_inet6.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
net/ipv6/af_inet6.c +2 -1
@@ -343,7 +343,8 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)*/ v4addr =LOOPBACK4_IPV6 ;if (!(addr_type &IPV6_ADDR_MULTICAST )) { -if (!ipv6_chk_addr (net, &addr->sin6_addr, +if (!inet->transparent && + !ipv6_chk_addr (net, &addr->sin6_addr, dev,0 )) { err = -EADDRNOTAVAIL ; goto out_unlock;
Signature · 1 line
1.7.1
PATCH 64/72 tproxy: added IPv6 socket lookup function to nf_tproxy_core
In reply to [email protected]From: Balazs Scheidler <[email protected]>
--- include/net/netfilter/nf_tproxy_core.h | 72 +++++++++++++++++++++++++++++++- 1 files changed, 71 insertions(+), 1 deletions(-)
include/net/netfilter/nf_tproxy_core.h +71 -1
@@ -5,7 +5,8 @@#include <linux/in.h> #include <linux/skbuff.h> #include <net/sock.h> -#include <net/inet_sock.h> +#include <net/inet_hashtables.h> +#include <net/inet6_hashtables.h> #include <net/tcp.h> #define NFT_LOOKUP_ANY 0
@@ -130,6 +131,75 @@ nf_tproxy_get_sock_v4(struct net *net, const u8 protocol,return sk; } +#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) +static inline struct sock * +nf_tproxy_get_sock_v6 (struct net *net,const u8 protocol, +const struct in6_addr *saddr,const struct in6_addr *daddr, +const __be16 sport,const __be16 dport, +const struct net_device *in,int lookup_type) +{ +struct sock *sk; + +/* look up socket */ +switch (protocol) { +case IPPROTO_TCP : +switch (lookup_type) { +case NFT_LOOKUP_ANY : + sk =inet6_lookup (net, &tcp_hashinfo, + saddr, sport, daddr, dport, + in->ifindex); +break ; +case NFT_LOOKUP_LISTENER : + sk =inet6_lookup_listener (net, &tcp_hashinfo, + daddr,ntohs (dport), + in->ifindex); + +/* NOTE: we return listeners even if bound to +* 0.0.0.0, those are filtered out in +* xt_socket, since xt_TPROXY needs 0 bound +* listeners too */ + +break ; +case NFT_LOOKUP_ESTABLISHED : + sk =__inet6_lookup_established (net, &tcp_hashinfo, + saddr, sport, daddr,ntohs (dport), + in->ifindex); +break ; +default : +WARN_ON (1 ); + sk =NULL ; +break ; + } +break ; +case IPPROTO_UDP : + sk =udp6_lib_lookup (net, saddr, sport, daddr, dport, + in->ifindex); +if (sk && lookup_type !=NFT_LOOKUP_ANY ) { +int connected = (sk->sk_state ==TCP_ESTABLISHED ); +int wildcard =ipv6_addr_any (&inet6_sk (sk)->rcv_saddr); + +/* NOTE: we return listeners even if bound to +* 0.0.0.0, those are filtered out in +* xt_socket, since xt_TPROXY needs 0 bound +* listeners too */ +if ((lookup_type ==NFT_LOOKUP_ESTABLISHED && (!connected || wildcard)) || + (lookup_type ==NFT_LOOKUP_LISTENER && connected)) { +sock_put (sk); + sk =NULL ; + } + } +break ; +default : +WARN_ON (1 ); + sk =NULL ; + } + +pr_debug ("tproxy socket lookup: proto %u %pI6:%u -> %pI6:%u, lookup type: %d, sock %p\n" , + protocol, saddr,ntohs (sport), daddr,ntohs (dport), lookup_type, sk); + +return sk; +} +#endif static inline void nf_tproxy_put_sock (struct sock *sk)
Signature · 1 line
1.7.1
PATCH 65/72 tproxy: added IPv6 support to the TPROXY target
In reply to [email protected]From: Balazs Scheidler <[email protected]>
This requires a new revision as the old target structure was IPv4 specific.
--- include/linux/netfilter/xt_TPROXY.h | 13 ++- net/netfilter/xt_TPROXY.c | 262 ++++++++++++++++++++++++++++++----- 2 files changed, 235 insertions(+), 40 deletions(-)
include/linux/netfilter/xt_TPROXY.h +10 -3
@@ -1,5 +1,5 @@ -#ifndef _XT_TPROXY_H_target -#define _XT_TPROXY_H_target +#ifndef _XT_TPROXY_H +#define _XT_TPROXY_H/* TPROXY target is capable of marking the packet to perform * redirection. We can get rid of that whenever we get support for
@@ -11,4 +11,11 @@ struct xt_tproxy_target_info { __be16 lport; }; -#endif /* _XT_TPROXY_H_target */ +struct xt_tproxy_target_info_v1 { +u_int32_t mark_mask; +u_int32_t mark_value; +union nf_inet_addr laddr; +__be16 lport; +}; + +#endif /* _XT_TPROXY_H */
net/netfilter/xt_TPROXY.c +225 -37
354 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 66/72 tproxy: added IPv6 support to the socket match
In reply to [email protected]From: Balazs Scheidler <[email protected]>
The ICMP extraction bits were contributed by Harry Mason.
--- net/netfilter/xt_socket.c | 165 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 154 insertions(+), 11 deletions(-)
net/netfilter/xt_socket.c +154 -11
@@ -14,6 +14,7 @@#include <linux/skbuff.h> #include <linux/netfilter/x_tables.h> #include <linux/netfilter_ipv4/ip_tables.h> +#include <linux/netfilter_ipv6/ip6_tables.h> #include <net/tcp.h> #include <net/udp.h> #include <net/icmp.h>
@@ -21,6 +22,7 @@#include <net/inet_sock.h> #include <net/netfilter/nf_tproxy_core.h> #include <net/netfilter/ipv4/nf_defrag_ipv4.h> +#include <net/netfilter/ipv6/nf_defrag_ipv6.h> #include <linux/netfilter/xt_socket.h>
@@ -30,7 +32,7 @@#endif static int -extract_icmp_fields(const struct sk_buff *skb, +extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol, __be32 *raddr, __be32 *laddr,
@@ -86,7 +88,6 @@ extract_icmp_fields(const struct sk_buff *skb,return 0 ; } -static bool socket_match (const struct sk_buff *skb,struct xt_action_param *par,const struct xt_socket_mtinfo1 *info)
@@ -115,7 +116,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par, dport = hp->dest; }else if (iph->protocol ==IPPROTO_ICMP ) { -if (extract_icmp_fields (skb, &protocol, &saddr, &daddr, +if (extract_icmp4_fields (skb, &protocol, &saddr, &daddr, &sport, &dport))return false; }else {
@@ -165,32 +166,157 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par, sk =NULL ; } -pr_debug ("proto %u %08x:%u -> %08x:%u (orig %08x:%u) sock %p\n" , - protocol,ntohl (saddr),ntohs (sport), -ntohl (daddr),ntohs (dport), -ntohl (iph->daddr), hp ?ntohs (hp->dest) :0 , sk); +pr_debug ("proto %hhu %pI4:%hu -> %pI4:%hu (orig %pI4:%hu) sock %p\n" , + protocol, &saddr,ntohs (sport), + &daddr,ntohs (dport), + &iph->daddr, hp ?ntohs (hp->dest) :0 , sk);return (sk !=NULL ); }static bool -socket_mt_v0 (const struct sk_buff *skb,struct xt_action_param *par) +socket_mt4_v0 (const struct sk_buff *skb,struct xt_action_param *par) {return socket_match (skb, par,NULL ); }static bool -socket_mt_v1 (const struct sk_buff *skb,struct xt_action_param *par) +socket_mt4_v1 (const struct sk_buff *skb,struct xt_action_param *par) {return socket_match (skb, par, par->matchinfo); } +#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) + +static int +extract_icmp6_fields (const struct sk_buff *skb, +unsigned int outside_hdrlen, +u8 *protocol, +struct in6_addr **raddr, +struct in6_addr **laddr, +__be16 *rport, +__be16 *lport) +{ +struct ipv6hdr *inside_iph, _inside_iph; +struct icmp6hdr *icmph, _icmph; +__be16 *ports, _ports[2 ]; +u8 inside_nexthdr; +int inside_hdrlen; + + icmph =skb_header_pointer (skb, outside_hdrlen, +sizeof (_icmph), &_icmph); +if (icmph ==NULL ) +return 1 ; + +if (icmph->icmp6_type &ICMPV6_INFOMSG_MASK ) +return 1 ; + + inside_iph =skb_header_pointer (skb, outside_hdrlen +sizeof (_icmph),sizeof (_inside_iph), &_inside_iph); +if (inside_iph ==NULL ) +return 1 ; + inside_nexthdr = inside_iph->nexthdr; + + inside_hdrlen =ipv6_skip_exthdr (skb, outside_hdrlen +sizeof (_icmph) +sizeof (_inside_iph), &inside_nexthdr); +if (inside_hdrlen <0 ) +return 1 ;/* hjm: Packet has no/incomplete transport layer headers. */ + +if (inside_nexthdr !=IPPROTO_TCP && + inside_nexthdr !=IPPROTO_UDP ) +return 1 ; + + ports =skb_header_pointer (skb, inside_hdrlen, +sizeof (_ports), &_ports); +if (ports ==NULL ) +return 1 ; + +/* the inside IP packet is the one quoted from our side, thus +* its saddr is the local address */ + *protocol = inside_nexthdr; + *laddr = &inside_iph->saddr; + *lport = ports[0 ]; + *raddr = &inside_iph->daddr; + *rport = ports[1 ]; + +return 0 ; +} + +static bool +socket_mt6_v1 (const struct sk_buff *skb,struct xt_action_param *par) +{ +struct ipv6hdr *iph =ipv6_hdr (skb); +struct udphdr _hdr, *hp =NULL ; +struct sock *sk; +struct in6_addr *daddr, *saddr; +__be16 dport, sport; +int thoff; +u8 tproto; +const struct xt_socket_mtinfo1 *info = (struct xt_socket_mtinfo1 *) par->matchinfo; + + tproto =ipv6_find_hdr (skb, &thoff,-1 ,NULL ); +if (tproto <0 ) { +pr_debug ("unable to find transport header in IPv6 packet, dropping\n" ); +return NF_DROP ; + } + +if (tproto ==IPPROTO_UDP || tproto ==IPPROTO_TCP ) { + hp =skb_header_pointer (skb, thoff, +sizeof (_hdr), &_hdr); +if (hp ==NULL ) +return false; + + saddr = &iph->saddr; + sport = hp->source; + daddr = &iph->daddr; + dport = hp->dest; + + }else if (tproto ==IPPROTO_ICMPV6 ) { +if (extract_icmp6_fields (skb, thoff, &tproto, &saddr, &daddr, + &sport, &dport)) +return false; + }else { +return false; + } + + sk =nf_tproxy_get_sock_v6 (dev_net (skb->dev), tproto, + saddr, daddr, sport, dport, par->in,NFT_LOOKUP_ANY ); +if (sk !=NULL ) { +bool wildcard; +bool transparent = true; + +/* Ignore sockets listening on INADDR_ANY */ + wildcard = (sk->sk_state !=TCP_TIME_WAIT && +ipv6_addr_any (&inet6_sk (sk)->rcv_saddr)); + +/* Ignore non-transparent sockets, +if XT_SOCKET_TRANSPARENT is used */ +if (info && info->flags &XT_SOCKET_TRANSPARENT ) + transparent = ((sk->sk_state !=TCP_TIME_WAIT && +inet_sk (sk)->transparent) || + (sk->sk_state ==TCP_TIME_WAIT && +inet_twsk (sk)->tw_transparent)); + +nf_tproxy_put_sock (sk); + +if (wildcard || !transparent) + sk =NULL ; + } + +pr_debug ("proto %hhu %pI6:%hu -> %pI6:%hu " +"(orig %pI6:%hu) sock %p\n" , + tproto, saddr,ntohs (sport), + daddr,ntohs (dport), + &iph->daddr, hp ?ntohs (hp->dest) :0 , sk); + +return (sk !=NULL ); +} +#endif +static struct xt_match socket_mt_reg[]__read_mostly = { { .name ="socket" , .revision =0 , .family =NFPROTO_IPV4 , - .match = socket_mt_v0, + .match = socket_mt4_v0, .hooks = (1 <<NF_INET_PRE_ROUTING ) | (1 <<NF_INET_LOCAL_IN ), .me =THIS_MODULE ,
@@ -199,17 +325,33 @@ static struct xt_match socket_mt_reg[] __read_mostly = { .name = "socket", .revision = 1, .family = NFPROTO_IPV4, - .match = socket_mt_v1, + .match = socket_mt4_v1, .matchsize = sizeof(struct xt_socket_mtinfo1), .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN), .me = THIS_MODULE, }, +#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) + { + .name = "socket", + .revision = 1, + .family = NFPROTO_IPV6, + .match = socket_mt6_v1, + .matchsize = sizeof(struct xt_socket_mtinfo1), + .hooks = (1 << NF_INET_PRE_ROUTING) | + (1 << NF_INET_LOCAL_IN), + .me = THIS_MODULE, + }, +#endif };static int __init socket_mt_init (void ) {nf_defrag_ipv4_enable (); +#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) +nf_defrag_ipv6_enable (); +#endif +return xt_register_matches (socket_mt_reg,ARRAY_SIZE (socket_mt_reg)); }
@@ -225,3 +367,4 @@ MODULE_LICENSE("GPL");MODULE_AUTHOR ("Krisztian Kovacs, Balazs Scheidler" );MODULE_DESCRIPTION ("x_tables socket match module" );MODULE_ALIAS ("ipt_socket" ); +MODULE_ALIAS ("ip6t_socket" );
Signature · 1 line
1.7.1
PATCH 67/72 tproxy: use the interface primary IP address as a default value for --on-ip
In reply to [email protected]From: Balazs Scheidler <[email protected]>
The REDIRECT target and the older TProxy versions used the primary address of the incoming interface as the default value of the --on-ip parameter. This was unintentionally changed during the initial TProxy submission and caused confusion among users.
Since IPv6 has no notion of primary address, we just select the first address on the list: this way the socket lookup finds wildcard bound sockets properly and we cannot really do better without the user telling us the IPv6 address of the proxy.
This is implemented for both IPv4 and IPv6.
--- net/netfilter/xt_TPROXY.c | 202 +++++++++++++++++++++++++++++---------------- 1 files changed, 132 insertions(+), 70 deletions(-)
net/netfilter/xt_TPROXY.c +132 -70
@@ -16,15 +16,41 @@#include <net/checksum.h> #include <net/udp.h> #include <net/inet_sock.h> - +#include <linux/inetdevice.h> #include <linux/netfilter/x_tables.h> #include <linux/netfilter_ipv4/ip_tables.h> -#include <linux/netfilter_ipv6/ip6_tables.h> -#include <linux/netfilter/xt_TPROXY.h> #include <net/netfilter/ipv4/nf_defrag_ipv4.h> +#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) +#include <net/if_inet6.h> +#include <net/addrconf.h> +#include <linux/netfilter_ipv6/ip6_tables.h> #include <net/netfilter/ipv6/nf_defrag_ipv6.h> +#endif +#include <net/netfilter/nf_tproxy_core.h> +#include <linux/netfilter/xt_TPROXY.h> + +static inline __be32 +tproxy_laddr4 (struct sk_buff *skb,__be32 user_laddr,__be32 daddr) +{ +struct in_device *indev; +__be32 laddr; + +if (user_laddr) +return user_laddr; + + laddr =0 ; +rcu_read_lock (); + indev =__in_dev_get_rcu (skb->dev); +for_primary_ifa (indev) { + laddr = ifa->ifa_local; +break ; + }endfor_ifa (indev); +rcu_read_unlock (); + +return laddr ? laddr : daddr; +}/** * tproxy_handle_time_wait4() - handle IPv4 TCP TIME_WAIT reopen redirections
@@ -75,60 +101,6 @@ tproxy_handle_time_wait4(struct sk_buff *skb, __be32 laddr, __be16 lport,return sk; } -/** -* tproxy_handle_time_wait6() - handle IPv6 TCP TIME_WAIT reopen redirections -* @skb: The skb being processed. -* @tproto: Transport protocol. -* @thoff: Transport protocol header offset. -* @par: Iptables target parameters. -* @sk: The TIME_WAIT TCP socket found by the lookup. -* -* We have to handle SYN packets arriving to TIME_WAIT sockets -* differently: instead of reopening the connection we should rather -* redirect the new connection to the proxy if there's a listener -* socket present. -* -* tproxy_handle_time_wait6() consumes the socket reference passed in. -* -* Returns the listener socket if there's one, the TIME_WAIT socket if -* no such listener is found, or NULL if the TCP header is incomplete. -*/ -static struct sock * -tproxy_handle_time_wait6 (struct sk_buff *skb,int tproto,int thoff, -const struct xt_action_param *par, -struct sock *sk) -{ -const struct ipv6hdr *iph =ipv6_hdr (skb); -struct tcphdr _hdr, *hp; -const struct xt_tproxy_target_info_v1 *tgi = par->targinfo; - - hp =skb_header_pointer (skb, thoff,sizeof (_hdr), &_hdr); -if (hp ==NULL ) { -inet_twsk_put (inet_twsk (sk)); -return NULL ; - } - -if (hp->syn && !hp->rst && !hp->ack && !hp->fin) { -/* SYN to a TIME_WAIT socket, we'd rather redirect it -* to a listener socket if there's one */ -struct sock *sk2; - - sk2 =nf_tproxy_get_sock_v6 (dev_net (skb->dev), tproto, - &iph->saddr, - !ipv6_addr_any (&tgi->laddr.in6) ? &tgi->laddr.in6 : &iph->daddr, - hp->source, - tgi->lport ? tgi->lport : hp->dest, - skb->dev,NFT_LOOKUP_LISTENER ); -if (sk2) { -inet_twsk_deschedule (inet_twsk (sk), &tcp_death_row); -inet_twsk_put (inet_twsk (sk)); - sk = sk2; - } - } - -return sk; -} -static unsigned int tproxy_tg4 (struct sk_buff *skb,__be32 laddr,__be16 lport,u_int32_t mark_mask,u_int32_t mark_value)
@@ -150,6 +122,10 @@ tproxy_tg4(struct sk_buff *skb, __be32 laddr, __be16 lport, hp->source, hp->dest, skb->dev, NFT_LOOKUP_ESTABLISHED); + laddr =tproxy_laddr4 (skb, laddr, iph->daddr); +if (!lport) + lport = hp->dest; +/* UDP has no TCP_TIME_WAIT state, so we never enter here */ if (sk && sk->sk_state ==TCP_TIME_WAIT )/* reopening a TIME_WAIT connection needs special handling */
@@ -158,8 +134,8 @@ tproxy_tg4(struct sk_buff *skb, __be32 laddr, __be16 lport,/* no, there's no established connection, check if * there's a listener on the redirected addr/port */ sk =nf_tproxy_get_sock_v4 (dev_net (skb->dev), iph->protocol, - iph->saddr, laddr ? laddr : iph->daddr, - hp->source, lport ? lport : hp->dest, + iph->saddr, laddr, + hp->source, lport, skb->dev,NFT_LOOKUP_LISTENER );/* NOTE: assign_sock consumes our sk reference */
@@ -174,9 +150,9 @@ tproxy_tg4(struct sk_buff *skb, __be32 laddr, __be16 lport,return NF_ACCEPT ; } -pr_debug ("no socket, dropping: proto %hhu %08x:%hu -> %08x:%hu, mark: %x\n" , - iph->protocol,ntohl (iph->daddr),ntohs (hp->dest), -ntohl (laddr),ntohs (lport), skb->mark); +pr_debug ("no socket, dropping: proto %hhu %pI4:%hu -> %pI4:%hu, mark: %x\n" , + iph->protocol, &iph->saddr,ntohs (hp->source), + &iph->daddr,ntohs (hp->dest), skb->mark);return NF_DROP ; }
@@ -197,6 +173,88 @@ tproxy_tg4_v1(struct sk_buff *skb, const struct xt_action_param *par) }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) + +static inline const struct in6_addr * +tproxy_laddr6 (struct sk_buff *skb,const struct in6_addr *user_laddr, +const struct in6_addr *daddr) +{ +struct inet6_dev *indev; +struct inet6_ifaddr *ifa; +struct in6_addr *laddr; + +if (!ipv6_addr_any (user_laddr)) +return user_laddr; + laddr =NULL ; + +rcu_read_lock (); + indev =__in6_dev_get (skb->dev); +if (indev) +list_for_each_entry (ifa, &indev->addr_list, if_list) { +if (ifa->flags & (IFA_F_TENTATIVE |IFA_F_DEPRECATED )) +continue ; + + laddr = &ifa->addr; +break ; + } +rcu_read_unlock (); + +return laddr ? laddr : daddr; +} + +/** +* tproxy_handle_time_wait6() - handle IPv6 TCP TIME_WAIT reopen redirections +* @skb: The skb being processed. +* @tproto: Transport protocol. +* @thoff: Transport protocol header offset. +* @par: Iptables target parameters. +* @sk: The TIME_WAIT TCP socket found by the lookup. +* +* We have to handle SYN packets arriving to TIME_WAIT sockets +* differently: instead of reopening the connection we should rather +* redirect the new connection to the proxy if there's a listener +* socket present. +* +* tproxy_handle_time_wait6() consumes the socket reference passed in. +* +* Returns the listener socket if there's one, the TIME_WAIT socket if +* no such listener is found, or NULL if the TCP header is incomplete. +*/ +static struct sock * +tproxy_handle_time_wait6 (struct sk_buff *skb,int tproto,int thoff, +const struct xt_action_param *par, +struct sock *sk) +{ +const struct ipv6hdr *iph =ipv6_hdr (skb); +struct tcphdr _hdr, *hp; +const struct xt_tproxy_target_info_v1 *tgi = par->targinfo; + + hp =skb_header_pointer (skb, thoff,sizeof (_hdr), &_hdr); +if (hp ==NULL ) { +inet_twsk_put (inet_twsk (sk)); +return NULL ; + } + +if (hp->syn && !hp->rst && !hp->ack && !hp->fin) { +/* SYN to a TIME_WAIT socket, we'd rather redirect it +* to a listener socket if there's one */ +struct sock *sk2; + + sk2 =nf_tproxy_get_sock_v6 (dev_net (skb->dev), tproto, + &iph->saddr, +tproxy_laddr6 (skb, &tgi->laddr.in6, &iph->daddr), + hp->source, + tgi->lport ? tgi->lport : hp->dest, + skb->dev,NFT_LOOKUP_LISTENER ); +if (sk2) { +inet_twsk_deschedule (inet_twsk (sk), &tcp_death_row); +inet_twsk_put (inet_twsk (sk)); + sk = sk2; + } + } + +return sk; +} +static unsigned int tproxy_tg6_v1 (struct sk_buff *skb,const struct xt_action_param *par) {
@@ -204,6 +262,8 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)const struct xt_tproxy_target_info_v1 *tgi = par->targinfo;struct udphdr _hdr, *hp;struct sock *sk; +const struct in6_addr *laddr; +__be16 lport;int thoff;int tproto;
@@ -228,6 +288,9 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par) hp->source, hp->dest, par->in, NFT_LOOKUP_ESTABLISHED); + laddr =tproxy_laddr6 (skb, &tgi->laddr.in6, &iph->daddr); + lport = tgi->lport ? tgi->lport : hp->dest; +/* UDP has no TCP_TIME_WAIT state, so we never enter here */ if (sk && sk->sk_state ==TCP_TIME_WAIT )/* reopening a TIME_WAIT connection needs special handling */
@@ -236,10 +299,8 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)/* no there's no established connection, check if * there's a listener on the redirected addr/port */ sk =nf_tproxy_get_sock_v6 (dev_net (skb->dev), tproto, - &iph->saddr, - !ipv6_addr_any (&tgi->laddr.in6) ? &tgi->laddr.in6 : &iph->daddr, - hp->source, - tgi->lport ? tgi->lport : hp->dest, + &iph->saddr, laddr, + hp->source, lport, par->in,NFT_LOOKUP_LISTENER );/* NOTE: assign_sock consumes our sk reference */
@@ -249,14 +310,15 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par) skb->mark = (skb->mark & ~tgi->mark_mask) ^ tgi->mark_value;pr_debug ("redirecting: proto %hhu %pI6:%hu -> %pI6:%hu, mark: %x\n" , - tproto, &iph->saddr,ntohs (hp->dest), - &tgi->laddr.in6,ntohs (tgi->lport), skb->mark); + tproto, &iph->saddr,ntohs (hp->source), + laddr,ntohs (lport), skb->mark);return NF_ACCEPT ; }pr_debug ("no socket, dropping: proto %hhu %pI6:%hu -> %pI6:%hu, mark: %x\n" , - tproto, &iph->saddr,ntohs (hp->dest), - &tgi->laddr.in6,ntohs (tgi->lport), skb->mark); + tproto, &iph->saddr,ntohs (hp->source), + &iph->daddr,ntohs (hp->dest), skb->mark); +return NF_DROP ; }
Signature · 1 line
1.7.1
PATCH 68/72 netfilter: ebtables: remove unused definitions
In reply to [email protected]From: Jan Engelhardt <[email protected]>
Userspace does not make use of the inner definitions, so we can remove these from the header now.
v2.6.27-rc8-947-g66bff35 removed the last uses of these structs in the kernel.
--- include/linux/netfilter_bridge/ebtables.h | 52 ----------------------------- 1 files changed, 0 insertions(+), 52 deletions(-)
include/linux/netfilter_bridge/ebtables.h +0 -52
@@ -199,58 +199,6 @@ struct ebt_entry {#define EBT_MATCH 0#define EBT_NOMATCH 1 -struct ebt_match { -struct list_head list; -const char name[EBT_FUNCTION_MAXNAMELEN ]; -bool (*match)(const struct sk_buff *skb,const struct net_device *in, -const struct net_device *out,const struct xt_match *match, -const void *matchinfo,int offset,unsigned int protoff, -bool *hotdrop); -bool (*checkentry)(const char *table,const void *entry, -const struct xt_match *match,void *matchinfo, -unsigned int hook_mask); -void (*destroy)(const struct xt_match *match,void *matchinfo); -unsigned int matchsize; -u_int8_t revision; -u_int8_t family; -struct module *me; -}; - -struct ebt_watcher { -struct list_head list; -const char name[EBT_FUNCTION_MAXNAMELEN ]; -unsigned int (*target)(struct sk_buff *skb, -const struct net_device *in,const struct net_device *out, -unsigned int hook_num,const struct xt_target *target, -const void *targinfo); -bool (*checkentry)(const char *table,const void *entry, -const struct xt_target *target,void *targinfo, -unsigned int hook_mask); -void (*destroy)(const struct xt_target *target,void *targinfo); -unsigned int targetsize; -u_int8_t revision; -u_int8_t family; -struct module *me; -}; - -struct ebt_target { -struct list_head list; -const char name[EBT_FUNCTION_MAXNAMELEN ]; -/* returns one of the standard EBT_* verdicts */ -unsigned int (*target)(struct sk_buff *skb, -const struct net_device *in,const struct net_device *out, -unsigned int hook_num,const struct xt_target *target, -const void *targinfo); -bool (*checkentry)(const char *table,const void *entry, -const struct xt_target *target,void *targinfo, -unsigned int hook_mask); -void (*destroy)(const struct xt_target *target,void *targinfo); -unsigned int targetsize; -u_int8_t revision; -u_int8_t family; -struct module *me; -}; -/* used for jumping from and into user defined chains (udc) */ struct ebt_chainstack {struct ebt_entries *chaininfo;/* pointer to chain data */
Signature · 1 line
1.7.1
PATCH 69/72 netfilter: xtables: add a missing pair of parentheses
In reply to [email protected]From: Jan Engelhardt <[email protected]>
--- include/linux/netfilter/x_tables.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/netfilter/x_tables.h +1 -1
@@ -177,7 +177,7 @@ struct xt_counters_info {/* can only be xt_entry_match, so no use of typeof here */ #define xt_ematch_foreach (pos, entry) \ - for ((pos) = (struct xt_entry_match *)entry->elems; \ + for ((pos) = (struct xt_entry_match *)(entry)->elems; \ (pos) < (struct xt_entry_match *)((char *)(entry) + \ (entry)->target_offset); \ (pos) = (struct xt_entry_match *)((char *)(pos) + \
Signature · 1 line
1.7.1
PATCH 70/72 netfilter: ebtables: replace EBT_ENTRY_ITERATE macro
In reply to [email protected]From: Jan Engelhardt <[email protected]>
The macro is replaced by a list.h-like foreach loop. This makes the
This is similar to v2.6.33-rc8-1212-g72b2b1d.
--- include/linux/netfilter_bridge/ebtables.h | 14 ++++- net/bridge/netfilter/ebtables.c | 93 +++++++++++++++++++---------- 2 files changed, 74 insertions(+), 33 deletions(-)
include/linux/netfilter_bridge/ebtables.h +12 -2
@@ -254,8 +254,15 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb,#endif /* __KERNEL__ */ -/* blatently stolen from ip_tables.h +/* blatantly stolen from ip_tables.h * fn returns 0 to continue iteration */ +#define ebt_entry_foreach (pos, ehead, esize) \ + for ((pos) = (struct ebt_entry *)(ehead); \ + (pos) < (struct ebt_entry *)((char *)(ehead) + (esize)); \ + (pos) = (struct ebt_entry *)((char *)(pos) + \ + ((pos)->bitmask == 0 ? sizeof(struct ebt_entries) : \ + (pos)->next_offset))) + #define EBT_MATCH_ITERATE(e, fn, args...) \ ({ \ unsigned int __i; \
@@ -302,6 +309,7 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, __ret; \ }) +#ifndef __KERNEL__ #define EBT_ENTRY_ITERATE(entries, size, fn, args...) \ ({ \ unsigned int __i; \
@@ -324,5 +332,7 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, } \ __ret; \ }) +#endif /* __KERNEL__ */ + +#endif /* __LINUX_BRIDGE_EFF_H */ -#endif
net/bridge/netfilter/ebtables.c +62 -31
188 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 71/72 netfilter: ebtables: replace EBT_MATCH_ITERATE macro
In reply to [email protected]From: Jan Engelhardt <[email protected]>
--- include/linux/netfilter_bridge/ebtables.h | 9 +++++ net/bridge/netfilter/ebtables.c | 47 ++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 14 deletions(-)
include/linux/netfilter_bridge/ebtables.h +9 -0
@@ -263,6 +263,14 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, ((pos)->bitmask == 0 ? sizeof(struct ebt_entries) : \ (pos)->next_offset))) +#define ebt_ematch_foreach (pos, entry) \ + for ((pos) = (struct ebt_entry_match *)(entry)->elems; \ + (pos) < (struct ebt_entry_match *)((char *)(entry) + \ + (entry)->watchers_offset); \ + (pos) = (struct ebt_entry_match *)((char *)((pos)->data) + \ + (pos)->match_size)) + +#ifndef __KERNEL__ #define EBT_MATCH_ITERATE(e, fn, args...) \ ({ \ unsigned int __i; \
@@ -285,6 +293,7 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, } \ __ret; \ }) +#endif #define EBT_WATCHER_ITERATE(e, fn, args...) \ ({ \
net/bridge/netfilter/ebtables.c +33 -14
125 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 72/72 netfilter: ebtables: replace EBT_WATCHER_ITERATE macro
In reply to [email protected]From: Jan Engelhardt <[email protected]>
--- include/linux/netfilter_bridge/ebtables.h | 9 ++++- net/bridge/netfilter/ebtables.c | 46 ++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 15 deletions(-)
include/linux/netfilter_bridge/ebtables.h +7 -2
@@ -269,6 +269,13 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, (entry)->watchers_offset); \ (pos) = (struct ebt_entry_match *)((char *)((pos)->data) + \ (pos)->match_size)) +#define ebt_ewatcher_foreach (pos, entry) \ + for ((pos) = (struct ebt_entry_watcher *)((entry)->elems + \ + (entry)->watchers_offset); \ + (pos) < (struct ebt_entry_watcher *)((char *)(entry) + \ + (entry)->target_offset); \ + (pos) = (struct ebt_entry_watcher *)((char *)((pos)->data) + \ + (pos)->watcher_size))#ifndef __KERNEL__ #define EBT_MATCH_ITERATE(e, fn, args...) \
@@ -293,7 +300,6 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, } \ __ret; \ }) -#endif #define EBT_WATCHER_ITERATE(e, fn, args...) \ ({ \
@@ -318,7 +324,6 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, __ret; \ }) -#ifndef __KERNEL__ #define EBT_ENTRY_ITERATE(entries, size, fn, args...) \ ({ \ unsigned int __i; \
net/bridge/netfilter/ebtables.c +33 -13
124 lines not on this page · raw message
Signature · 1 line
1.7.1
David Miller
maintainerFrom: [email protected]
Date: Thu, 21 Oct 2010 17:18:47 +0200
Quoted 3 lines
Please pull from:
git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6.gitmaster
Pulled, thanks!
Re: [PATCH 63/72] tproxy: allow non-local binds of IPv6 sockets if IP_TRANSPARENT is enabled
In reply to [email protected]Hello.
Quoted 14 lines · On 2010-10-21, [email protected] wrote:
From: Balazs Scheidler <[email protected]>
Signed-off-by Balazs Scheidler <[email protected]>Signed-off-by KOVACS Krisztian <[email protected]>Signed-off-by Patrick McHardy <[email protected]>--- net/ipv6/af_inet6.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)net/ipv6/af_inet6.c +0
-0
net/ipv6/af_inet6.c int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) · line 350
Quoted 9 lines
net/ipv6/af_inet6.c +2
-1@@ -343,7 +343,8 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)*/ v4addr =LOOPBACK4_IPV6 ;if (!(addr_type &IPV6_ADDR_MULTICAST )) { -if (!ipv6_chk_addr (net, &addr->sin6_addr, +if (!inet->transparent && + !ipv6_chk_addr (net, &addr->sin6_addr, dev,0 )) { err = -EADDRNOTAVAIL ; goto out_unlock;
Sorry, NAK.
http://kerneltrap.org/mailarchive/linux-netdev/2010/7/5/6280572
--yoshfuji