netfilter updates for net-next
Subsystems (4)
[email protected]
maintainercover netfilter updates for net-next
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following three patches contain updates for your net-next tree, they include:
* Little cleanup for IPVS the use of a strange notation to assign the conntrack object, from Alan Cox.
* getsockopt support to obtain the original IPv6 address after NAT, similar to the one that IPv4 provides, from Florian Westphal.
* Another little cleanup for nf_nat to save a couple of lines by using PTR_RET, from Wu Fengguang.
You can pull these changes from:
git://1984.lsi.us.es/nf-next master
Thanks!
Alan Cox (1):
ipvs: remove silly double assignment
Florian Westphal (1):
netfilter: ipv6: add getsockopt to retrieve origdst
Wu Fengguang (1):
netfilter: nf_nat: use PTR_RET
include/uapi/linux/in6.h | 1 + include/uapi/linux/netfilter_ipv6/ip6_tables.h | 3 ++ net/ipv4/netfilter/iptable_nat.c | 4 +- net/ipv6/netfilter/ip6table_nat.c | 4 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 61 ++++++++++++++++++++++++ net/netfilter/ipvs/ip_vs_nfct.c | 2 +- net/netfilter/ipvs/ip_vs_xmit.c | 8 ++-- 7 files changed, 72 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 1/3 ipvs: remove silly double assignment
From: Alan Cox <[email protected]>
I don't even want to think what the C spec says for this 8)
--- net/netfilter/ipvs/ip_vs_nfct.c | 2 +- net/netfilter/ipvs/ip_vs_xmit.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipvs/ip_vs_nfct.c +1 -1
@@ -82,7 +82,7 @@ void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, int outin) { enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);struct nf_conntrack_tuple new_tuple; if (ct == NULL || nf_ct_is_confirmed(ct) || nf_ct_is_untracked(ct) ||
net/netfilter/ipvs/ip_vs_xmit.c +4 -4
@@ -594,7 +594,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,#if IS_ENABLED (CONFIG_NF_CONNTRACK )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG_RL_PKT(10, AF_INET, pp, skb, 0,
@@ -710,7 +710,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,#if IS_ENABLED (CONFIG_NF_CONNTRACK )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG_RL_PKT(10, AF_INET6, pp, skb, 0,
@@ -1235,7 +1235,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,#if IS_ENABLED (CONFIG_NF_CONNTRACK )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG(10, "%s(): "
@@ -1356,7 +1356,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,#if IS_ENABLED (CONFIG_NF_CONNTRACK )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG(10, "%s(): "
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 2/3 netfilter: nf_nat: use PTR_RET
In reply to [email protected]From: Wu Fengguang <[email protected]>
Use PTR_RET rather than if(IS_ERR(...)) + PTR_ERR
Generated by: coccinelle/api/ptr_ret.cocci
--- net/ipv4/netfilter/iptable_nat.c | 4 +--- net/ipv6/netfilter/ip6table_nat.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
net/ipv4/netfilter/iptable_nat.c +1 -3
@@ -274,9 +274,7 @@ static int __net_init iptable_nat_net_init(struct net *net)return -ENOMEM ; net->ipv4.nat_table =ipt_register_table (net, &nf_nat_ipv4_table, repl);kfree (repl); -if (IS_ERR (net->ipv4.nat_table)) -return PTR_ERR (net->ipv4.nat_table); -return 0 ; +return PTR_RET (net->ipv4.nat_table); } static void __net_exit iptable_nat_net_exit(struct net *net)
net/ipv6/netfilter/ip6table_nat.c +1 -3
@@ -275,9 +275,7 @@ static int __net_init ip6table_nat_net_init(struct net *net)return -ENOMEM ; net->ipv6.ip6table_nat =ip6t_register_table (net, &nf_nat_ipv6_table, repl);kfree (repl); -if (IS_ERR (net->ipv6.ip6table_nat)) -return PTR_ERR (net->ipv6.ip6table_nat); -return 0 ; +return PTR_RET (net->ipv6.ip6table_nat); } static void __net_exit ip6table_nat_net_exit(struct net *net)
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 3/3 netfilter: ipv6: add getsockopt to retrieve origdst
In reply to [email protected]From: Florian Westphal <[email protected]>
userspace can query the original ipv4 destination address of a REDIRECTed connection viagetsockopt(m_sock, SOL_IP, SO_ORIGINAL_DST, &m_server_addr, &addrsize)
but for ipv6 no such option existed.
This adds getsockopt(..., IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, ...).
Without this, userspace needs to parse /proc or use ctnetlink, which appears to be overkill.
This uses option number 80 for IP6T_SO_ORIGINAL_DST, which is spare, to use the same number we use in the IPv4 socket option SO_ORIGINAL_DST.
--- include/uapi/linux/in6.h | 1 + include/uapi/linux/netfilter_ipv6/ip6_tables.h | 3 ++ net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 61 ++++++++++++++++++++++++ 3 files changed, 65 insertions(+)
include/uapi/linux/in6.h +1 -0
@@ -240,6 +240,7 @@ struct in6_flowlabel_req {* * IP6T_SO_GET_REVISION_MATCH 68 * IP6T_SO_GET_REVISION_TARGET 69 +* IP6T_SO_ORIGINAL_DST 80 */ /* RFC5014: Source address selection */
include/uapi/linux/netfilter_ipv6/ip6_tables.h +3 -0
@@ -178,6 +178,9 @@ struct ip6t_error {#define IP6T_SO_GET_REVISION_TARGET (IP6T_BASE_CTL + 5)#define IP6T_SO_GET_MAX IP6T_SO_GET_REVISION_TARGET +/* obtain original address if REDIRECT'd connection */ +#define IP6T_SO_ORIGINAL_DST 80 +/* ICMP matching stuff */ struct ip6t_icmp {__u8 type;/* type to match */
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +61 -0
97 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH 3/3] netfilter: ipv6: add getsockopt to retrieve origdst
Quoted 35 lines · [email protected] wrote:
From: Florian Westphal <[email protected]>
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +34
-0+static int +ipv6_getorigdst (struct sock *sk,int optval,void __user *user,int *len) +{ +const struct inet_sock *inet =inet_sk (sk); +const struct ipv6_pinfo *inet6 =inet6_sk (sk); +const struct nf_conntrack_tuple_hash *h; +struct sockaddr_in6 sin6; +struct nf_conntrack_tuple tuple = { .src.l3num =NFPROTO_IPV6 }; +struct nf_conn *ct; + + tuple.src.u3.in6 = inet6->rcv_saddr; + tuple.src.u.tcp.port = inet->inet_sport; + tuple.dst.u3.in6 = inet6->daddr; + tuple.dst.u.tcp.port = inet->inet_dport; + tuple.dst.protonum = sk->sk_protocol; + +if (sk->sk_protocol !=IPPROTO_TCP && sk->sk_protocol !=IPPROTO_SCTP ) +return -ENOPROTOOPT ; + +if (*len <0 || (unsigned int ) *len <sizeof (sin6)) +return -EINVAL ; + + h =nf_conntrack_find_get (sock_net (sk),NF_CT_DEFAULT_ZONE , &tuple); +if (!h) { +pr_debug ("IP6T_SO_ORIGINAL_DST: Can't find %pI6c/%u-%pI6c/%u.\n" , + &tuple.src.u3.ip6,ntohs (tuple.src.u.tcp.port), + &tuple.dst.u3.ip6,ntohs (tuple.dst.u.tcp.port)); +return -ENOENT ; + } + + ct =nf_ct_tuplehash_to_ctrack (h); + + sin6.sin6_family =AF_INET6 ; + sin6.sin6_port = ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.u.tcp.port;
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = { · line 342
Quoted 10 lines
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +10
-0+ sin6.sin6_flowinfo = inet6->flow_label &IPV6_FLOWINFO_MASK ; +memcpy (&sin6.sin6_addr, + &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.u3.in6, +sizeof (sin6.sin6_addr)); + sin6.sin6_scope_id = sk->sk_bound_dev_if; + +nf_ct_put (ct); +return copy_to_user (user, &sin6,sizeof (sin6)) ? -EFAULT :0 ; +} +
I think we should set sin6_scope_id to sk->sk_bound_dev_if only if the destination is link-local address.
--yoshfuji
Florian Westphal
maintainerRe: [PATCH 3/3] netfilter: ipv6: add getsockopt to retrieve origdst
Quoted 11 lines · YOSHIFUJI Hideaki
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = { · line 342
Quoted 7 lines · [email protected] wrote:
From: Florian Westphal <[email protected]>
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +6
-0+ sin6.sin6_scope_id = sk->sk_bound_dev_if; + +nf_ct_put (ct); +return copy_to_user (user, &sin6,sizeof (sin6)) ? -EFAULT :0 ; +} +I think we should set
sin6_scope_idtosk->sk_bound_dev_ifonly if the destination is link-local address.
Right, I see that getpeer/sockname has this test.
Dave, please either apply the patch as is (I'd submit a fixup) or discard i, I'll then send a V2 with added ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL test to Pablo.
Thanks for reviewing.
Pablo Neira Ayuso
maintainerRe: [PATCH 3/3] netfilter: ipv6: add getsockopt to retrieve origdst
Quoted 13 lines · Florian Westphal
Quoted 11 lines · YOSHIFUJI Hideaki
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = { · line 342
Quoted 7 lines · [email protected] wrote:
From: Florian Westphal <[email protected]>
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +6
-0+ sin6.sin6_scope_id = sk->sk_bound_dev_if; + +nf_ct_put (ct); +return copy_to_user (user, &sin6,sizeof (sin6)) ? -EFAULT :0 ; +} +I think we should set
sin6_scope_idtosk->sk_bound_dev_ifonly if the destination is link-local address.
Quoted 6 lines
Right, I see that getpeer/sockname has this test.
Dave, please either apply the patch as is (I'd submit a fixup) or discard i, I'll then send a V2 with added
ipv6_addr_type(&sin->sin6_addr)&IPV6_ADDR_LINKLOCALtest to Pablo.
Please, send me a follow-up patch, I'll apply and request a new pull request.
Thanks.
Pablo Neira Ayuso
maintainerQuoted 7 lines · On Tue, Nov 13, 2012 at 01:06:40AM +0100, [email protected] wrote:
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following three patches contain updates for your net-next tree, they include:
Quoted 8 lines
* Little cleanup for IPVS the use of a strange notation to assign the conntrack object, from Alan Cox.
* getsockopt support to obtain the original IPv6 address after NAT, similar to the one that IPv4 provides, from Florian Westphal.
* Another little cleanup for
nf_natto save a couple of lines by usingPTR_RET, from Wu Fengguang.
Please, hold on with this pull request. We need a follow-up patch to resolve an issue regarding the getsockopt to obtain original address with IPv6 NAT.
I'll send you a new pull request.
Sorry for the inconvenience.
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Tue, 13 Nov 2012 13:40:02 +0100
Quoted 14 lines · On Tue, Nov 13, 2012 at 01:06:40AM +0100, [email protected] wrote:
Quoted 13 lines
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following three patches contain updates for your net-next tree, they include:
* Little cleanup for IPVS the use of a strange notation to assign the conntrack object, from Alan Cox.
* getsockopt support to obtain the original IPv6 address after NAT, similar to the one that IPv4 provides, from Florian Westphal.
Quoted 8 lines
Quoted 2 lines
* Another little cleanup for
nf_natto save a couple of lines by usingPTR_RET, from Wu Fengguang.Please, hold on with this pull request. We need a follow-up patch to resolve an issue regarding the getsockopt to obtain original address with IPv6 NAT.
I'll send you a new pull request.
Ok.