Commit 80fbdb20 authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by David S. Miller

ipv6: datagram: Refactor flowi6 init codes to a new function

Move flowi6 init codes for connected datagram sk to a newly created
function ip6_datagram_flow_key_init().

Notes:
1. fl6_flowlabel is used instead of fl6.flowlabel in __ip6_datagram_connect
2. ipv6_addr_is_multicast(&fl6->daddr) is used instead of
   (addr_type & IPV6_ADDR_MULTICAST) in ip6_datagram_flow_key_init()

This new function will be reused during pmtu update in the later patch.
Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Wei Wang <weiwan@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f1d0540d
...@@ -40,6 +40,30 @@ static bool ipv6_mapped_addr_any(const struct in6_addr *a) ...@@ -40,6 +40,30 @@ static bool ipv6_mapped_addr_any(const struct in6_addr *a)
return ipv6_addr_v4mapped(a) && (a->s6_addr32[3] == 0); return ipv6_addr_v4mapped(a) && (a->s6_addr32[3] == 0);
} }
static void ip6_datagram_flow_key_init(struct flowi6 *fl6, struct sock *sk)
{
struct inet_sock *inet = inet_sk(sk);
struct ipv6_pinfo *np = inet6_sk(sk);
memset(fl6, 0, sizeof(*fl6));
fl6->flowi6_proto = sk->sk_protocol;
fl6->daddr = sk->sk_v6_daddr;
fl6->saddr = np->saddr;
fl6->flowi6_oif = sk->sk_bound_dev_if;
fl6->flowi6_mark = sk->sk_mark;
fl6->fl6_dport = inet->inet_dport;
fl6->fl6_sport = inet->inet_sport;
fl6->flowlabel = np->flow_label;
if (!fl6->flowi6_oif)
fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
if (!fl6->flowi6_oif && ipv6_addr_is_multicast(&fl6->daddr))
fl6->flowi6_oif = np->mcast_oif;
security_sk_classify_flow(sk, flowi6_to_flowi(fl6));
}
static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{ {
struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr;
...@@ -52,6 +76,7 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a ...@@ -52,6 +76,7 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a
struct ipv6_txoptions *opt; struct ipv6_txoptions *opt;
int addr_type; int addr_type;
int err; int err;
__be32 fl6_flowlabel = 0;
if (usin->sin6_family == AF_INET) { if (usin->sin6_family == AF_INET) {
if (__ipv6_only_sock(sk)) if (__ipv6_only_sock(sk))
...@@ -66,11 +91,10 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a ...@@ -66,11 +91,10 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a
if (usin->sin6_family != AF_INET6) if (usin->sin6_family != AF_INET6)
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
memset(&fl6, 0, sizeof(fl6));
if (np->sndflow) { if (np->sndflow) {
fl6.flowlabel = usin->sin6_flowinfo&IPV6_FLOWINFO_MASK; fl6_flowlabel = usin->sin6_flowinfo & IPV6_FLOWINFO_MASK;
if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) { if (fl6_flowlabel & IPV6_FLOWLABEL_MASK) {
flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); flowlabel = fl6_sock_lookup(sk, fl6_flowlabel);
if (!flowlabel) if (!flowlabel)
return -EINVAL; return -EINVAL;
} }
...@@ -145,7 +169,7 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a ...@@ -145,7 +169,7 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a
} }
sk->sk_v6_daddr = *daddr; sk->sk_v6_daddr = *daddr;
np->flow_label = fl6.flowlabel; np->flow_label = fl6_flowlabel;
inet->inet_dport = usin->sin6_port; inet->inet_dport = usin->sin6_port;
...@@ -154,21 +178,7 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a ...@@ -154,21 +178,7 @@ static int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int a
* destination cache for it. * destination cache for it.
*/ */
fl6.flowi6_proto = sk->sk_protocol; ip6_datagram_flow_key_init(&fl6, sk);
fl6.daddr = sk->sk_v6_daddr;
fl6.saddr = np->saddr;
fl6.flowi6_oif = sk->sk_bound_dev_if;
fl6.flowi6_mark = sk->sk_mark;
fl6.fl6_dport = inet->inet_dport;
fl6.fl6_sport = inet->inet_sport;
if (!fl6.flowi6_oif)
fl6.flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
if (!fl6.flowi6_oif && (addr_type&IPV6_ADDR_MULTICAST))
fl6.flowi6_oif = np->mcast_oif;
security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
rcu_read_lock(); rcu_read_lock();
opt = flowlabel ? flowlabel->opt : rcu_dereference(np->opt); opt = flowlabel ? flowlabel->opt : rcu_dereference(np->opt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment