174
174
* xmit an sk_buff (used by TCP, SCTP and DCCP)
177
int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
177
int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
178
178
struct ipv6_txoptions *opt)
180
180
struct net *net = sock_net(sk);
181
181
struct ipv6_pinfo *np = inet6_sk(sk);
182
struct in6_addr *first_hop = &fl->fl6_dst;
182
struct in6_addr *first_hop = &fl6->daddr;
183
183
struct dst_entry *dst = skb_dst(skb);
184
184
struct ipv6hdr *hdr;
185
u8 proto = fl->proto;
185
u8 proto = fl6->flowi6_proto;
186
186
int seg_len = skb->len;
905
905
* 2. oif also should be the same.
907
if (ip6_rt_check(&rt->rt6i_dst, &fl->fl6_dst, np->daddr_cache) ||
907
if (ip6_rt_check(&rt->rt6i_dst, &fl6->daddr, np->daddr_cache) ||
908
908
#ifdef CONFIG_IPV6_SUBTREES
909
ip6_rt_check(&rt->rt6i_src, &fl->fl6_src, np->saddr_cache) ||
909
ip6_rt_check(&rt->rt6i_src, &fl6->saddr, np->saddr_cache) ||
911
(fl->oif && fl->oif != dst->dev->ifindex)) {
911
(fl6->flowi6_oif && fl6->flowi6_oif != dst->dev->ifindex)) {
912
912
dst_release(dst);
920
920
static int ip6_dst_lookup_tail(struct sock *sk,
921
struct dst_entry **dst, struct flowi *fl)
921
struct dst_entry **dst, struct flowi6 *fl6)
924
924
struct net *net = sock_net(sk);
926
926
if (*dst == NULL)
927
*dst = ip6_route_output(net, sk, fl);
927
*dst = ip6_route_output(net, sk, fl6);
929
929
if ((err = (*dst)->error))
930
930
goto out_err_release;
932
if (ipv6_addr_any(&fl->fl6_src)) {
932
if (ipv6_addr_any(&fl6->saddr)) {
933
933
err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
935
935
sk ? inet6_sk(sk)->srcprefs : 0,
938
938
goto out_err_release;
965
965
* default router instead
967
967
dst_release(*dst);
968
memcpy(&fl_gw, fl, sizeof(struct flowi));
969
memset(&fl_gw.fl6_dst, 0, sizeof(struct in6_addr));
970
*dst = ip6_route_output(net, sk, &fl_gw);
968
memcpy(&fl_gw6, fl6, sizeof(struct flowi6));
969
memset(&fl_gw6.daddr, 0, sizeof(struct in6_addr));
970
*dst = ip6_route_output(net, sk, &fl_gw6);
971
971
if ((err = (*dst)->error))
972
972
goto out_err_release;
988
988
* ip6_dst_lookup - perform route lookup on flow
989
989
* @sk: socket which provides route info
990
990
* @dst: pointer to dst_entry * for result
991
* @fl: flow to lookup
991
* @fl6: flow to lookup
993
993
* This function performs a route lookup on the given flow.
995
995
* It returns zero on success, or a standard errno code on error.
997
int ip6_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi *fl)
997
int ip6_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi6 *fl6)
1000
return ip6_dst_lookup_tail(sk, dst, fl);
1000
return ip6_dst_lookup_tail(sk, dst, fl6);
1002
1002
EXPORT_SYMBOL_GPL(ip6_dst_lookup);
1005
* ip6_sk_dst_lookup - perform socket cached route lookup on flow
1005
* ip6_dst_lookup_flow - perform route lookup on flow with ipsec
1006
* @sk: socket which provides route info
1007
* @fl6: flow to lookup
1008
* @final_dst: final destination address for ipsec lookup
1009
* @can_sleep: we are in a sleepable context
1011
* This function performs a route lookup on the given flow.
1013
* It returns a valid dst pointer on success, or a pointer encoded
1016
struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
1017
const struct in6_addr *final_dst,
1020
struct dst_entry *dst = NULL;
1023
err = ip6_dst_lookup_tail(sk, &dst, fl6);
1025
return ERR_PTR(err);
1027
ipv6_addr_copy(&fl6->daddr, final_dst);
1029
fl6->flowi6_flags |= FLOWI_FLAG_CAN_SLEEP;
1031
return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
1033
EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
1036
* ip6_sk_dst_lookup_flow - perform socket cached route lookup on flow
1006
1037
* @sk: socket which provides the dst cache and route info
1007
* @dst: pointer to dst_entry * for result
1008
* @fl: flow to lookup
1038
* @fl6: flow to lookup
1039
* @final_dst: final destination address for ipsec lookup
1040
* @can_sleep: we are in a sleepable context
1010
1042
* This function performs a route lookup on the given flow with the
1011
1043
* possibility of using the cached route in the socket if it is valid.
1012
1044
* It will take the socket dst lock when operating on the dst cache.
1013
1045
* As a result, this function can only be used in process context.
1015
* It returns zero on success, or a standard errno code on error.
1047
* It returns a valid dst pointer on success, or a pointer encoded
1017
int ip6_sk_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi *fl)
1050
struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
1051
const struct in6_addr *final_dst,
1021
*dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie);
1022
*dst = ip6_sk_dst_check(sk, *dst, fl);
1025
return ip6_dst_lookup_tail(sk, dst, fl);
1054
struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie);
1057
dst = ip6_sk_dst_check(sk, dst, fl6);
1059
err = ip6_dst_lookup_tail(sk, &dst, fl6);
1061
return ERR_PTR(err);
1063
ipv6_addr_copy(&fl6->daddr, final_dst);
1065
fl6->flowi6_flags |= FLOWI_FLAG_CAN_SLEEP;
1067
return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
1027
EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup);
1069
EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow);
1029
1071
static inline int ip6_ufo_append_data(struct sock *sk,
1030
1072
int getfrag(void *from, char *to, int offset, int len,
1104
1145
int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
1105
1146
int offset, int len, int odd, struct sk_buff *skb),
1106
1147
void *from, int length, int transhdrlen,
1107
int hlimit, int tclass, struct ipv6_txoptions *opt, struct flowi *fl,
1148
int hlimit, int tclass, struct ipv6_txoptions *opt, struct flowi6 *fl6,
1108
1149
struct rt6_info *rt, unsigned int flags, int dontfrag)
1110
1151
struct inet_sock *inet = inet_sk(sk);
1198
1240
if (mtu <= sizeof(struct ipv6hdr) + IPV6_MAXPLEN) {
1199
1241
if (inet->cork.length + length > sizeof(struct ipv6hdr) + IPV6_MAXPLEN - fragheaderlen) {
1200
ipv6_local_error(sk, EMSGSIZE, fl, mtu-exthdrlen);
1242
ipv6_local_error(sk, EMSGSIZE, fl6, mtu-exthdrlen);
1201
1243
return -EMSGSIZE;
1247
/* For UDP, check if TX timestamp is enabled */
1248
if (sk->sk_type == SOCK_DGRAM) {
1249
err = sock_tx_timestamp(sk, &tx_flags);
1206
1255
* Let's try using as much space as possible.
1207
1256
* Use MTU if total length of the message fits into the MTU.