From: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org,
YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Subject: Re: [PATCH 3/3] netfilter: ipv6: add getsockopt to retrieve origdst
Date: Tue, 13 Nov 2012 12:29:36 +0900 [thread overview]
Message-ID: <50A1BEA0.8070504@linux-ipv6.org> (raw)
In-Reply-To: <1352765203-4160-4-git-send-email-pablo@netfilter.org>
pablo@netfilter.org wrote:
> From: Florian Westphal <fw@strlen.de>
> +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;
> + 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
next prev parent reply other threads:[~2012-11-13 3:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-13 0:06 [PATCH 0/3] netfilter updates for net-next pablo
2012-11-13 0:06 ` [PATCH 1/3] ipvs: remove silly double assignment pablo
2012-11-13 0:06 ` [PATCH 2/3] netfilter: nf_nat: use PTR_RET pablo
2012-11-13 0:06 ` [PATCH 3/3] netfilter: ipv6: add getsockopt to retrieve origdst pablo
2012-11-13 3:29 ` YOSHIFUJI Hideaki [this message]
2012-11-13 8:59 ` Florian Westphal
2012-11-13 9:39 ` Pablo Neira Ayuso
2012-11-13 12:40 ` [PATCH 0/3] netfilter updates for net-next Pablo Neira Ayuso
2012-11-13 19:12 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50A1BEA0.8070504@linux-ipv6.org \
--to=yoshfuji@linux-ipv6.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).