Release 4.11 net/ipv4/ip_forward.c
/*
* INET An implementation of the TCP/IP protocol suite for the LINUX
* operating system. INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* The IP forwarding functionality.
*
* Authors: see ip.c
*
* Fixes:
* Many : Split from ip.c , see ip_input.c for
* history.
* Dave Gregorich : NULL ip_rt_put fix for multicast
* routing.
* Jos Vos : Add call_out_firewall before sending,
* use output device for accounting.
* Jos Vos : Call forward firewall after routing
* (always use output device).
* Mike McLagan : Routing by source
*/
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/icmp.h>
#include <linux/netdevice.h>
#include <linux/slab.h>
#include <net/sock.h>
#include <net/ip.h>
#include <net/tcp.h>
#include <net/udp.h>
#include <net/icmp.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/netfilter_ipv4.h>
#include <net/checksum.h>
#include <linux/route.h>
#include <net/route.h>
#include <net/xfrm.h>
static bool ip_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)
{
if (skb->len <= mtu)
return false;
if (unlikely((ip_hdr(skb)->frag_off & htons(IP_DF)) == 0))
return false;
/* original fragment exceeds mtu and DF is set */
if (unlikely(IPCB(skb)->frag_max_size > mtu))
return true;
if (skb->ignore_df)
return false;
if (skb_is_gso(skb) && skb_gso_validate_mtu(skb, mtu))
return false;
return true;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Florian Westphal | 95 | 96.94% | 2 | 66.67% |
Marcelo Ricardo Leitner | 3 | 3.06% | 1 | 33.33% |
Total | 98 | 100.00% | 3 | 100.00% |
static int ip_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
{
struct ip_options *opt = &(IPCB(skb)->opt);
__IP_INC_STATS(net, IPSTATS_MIB_OUTFORWDATAGRAMS);
__IP_ADD_STATS(net, IPSTATS_MIB_OUTOCTETS, skb->len);
if (unlikely(opt->optlen))
ip_forward_options(skb);
return dst_output(net, sk, skb);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 45 | 57.69% | 5 | 31.25% |
Eric W. Biedermann | 10 | 12.82% | 4 | 25.00% |
Vincent Bernat | 9 | 11.54% | 1 | 6.25% |
David S. Miller | 7 | 8.97% | 1 | 6.25% |
Alexey Kuznetsov | 3 | 3.85% | 1 | 6.25% |
Eric Dumazet | 2 | 2.56% | 2 | 12.50% |
Pavel Emelyanov | 1 | 1.28% | 1 | 6.25% |
Hideaki Yoshifuji / 吉藤英明 | 1 | 1.28% | 1 | 6.25% |
Total | 78 | 100.00% | 16 | 100.00% |
int ip_forward(struct sk_buff *skb)
{
u32 mtu;
struct iphdr *iph; /* Our header */
struct rtable *rt; /* Route we use */
struct ip_options *opt = &(IPCB(skb)->opt);
struct net *net;
/* that should never happen */
if (skb->pkt_type != PACKET_HOST)
goto drop;
if (unlikely(skb->sk))
goto drop;
if (skb_warn_if_lro(skb))
goto drop;
if (!xfrm4_policy_check(NULL, XFRM_POLICY_FWD, skb))
goto drop;
if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb))
return NET_RX_SUCCESS;
skb_forward_csum(skb);
net = dev_net(skb->dev);
/*
* According to the RFC, we must first decrease the TTL field. If
* that reaches zero, we must reply an ICMP control message telling
* that the packet's lifetime expired.
*/
if (ip_hdr(skb)->ttl <= 1)
goto too_many_hops;
if (!xfrm4_route_forward(skb))
goto drop;
rt = skb_rtable(skb);
if (opt->is_strictroute && rt->rt_uses_gateway)
goto sr_failed;
IPCB(skb)->flags |= IPSKB_FORWARDED;
mtu = ip_dst_mtu_maybe_forward(&rt->dst, true);
if (ip_exceeds_mtu(skb, mtu)) {
IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS);
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
htonl(mtu));
goto drop;
}
/* We are about to mangle packet. Copy it! */
if (skb_cow(skb, LL_RESERVED_SPACE(rt->dst.dev)+rt->dst.header_len))
goto drop;
iph = ip_hdr(skb);
/* Decrease ttl after skb cow done */
ip_decrease_ttl(iph);
/*
* We now generate an ICMP HOST REDIRECT giving the route
* we calculated.
*/
if (IPCB(skb)->flags & IPSKB_DOREDIRECT && !opt->srr &&
!skb_sec_path(skb))
ip_rt_send_redirect(skb);
skb->priority = rt_tos2priority(iph->tos);
return NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD,
net, NULL, skb, skb->dev, rt->dst.dev,
ip_forward_finish);
sr_failed:
/*
* Strict routing permits no gatewaying
*/
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_SR_FAILED, 0);
goto drop;
too_many_hops:
/* Tell the sender its packet died... */
__IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS);
icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0);
drop:
kfree_skb(skb);
return NET_RX_DROP;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 167 | 43.83% | 12 | 29.27% |
Alexey Kuznetsov | 60 | 15.75% | 4 | 9.76% |
John Heffner | 36 | 9.45% | 1 | 2.44% |
Hannes Frederic Sowa | 24 | 6.30% | 2 | 4.88% |
Eric W. Biedermann | 18 | 4.72% | 2 | 4.88% |
Denis Kirjanov | 12 | 3.15% | 1 | 2.44% |
Sebastian Pöhn | 12 | 3.15% | 1 | 2.44% |
Ben Hutchings | 10 | 2.62% | 1 | 2.44% |
Arnaldo Carvalho de Melo | 6 | 1.57% | 1 | 2.44% |
Linus Torvalds | 5 | 1.31% | 1 | 2.44% |
Wei Dong | 4 | 1.05% | 1 | 2.44% |
Eric Dumazet | 4 | 1.05% | 2 | 4.88% |
Florian Westphal | 3 | 0.79% | 1 | 2.44% |
Herbert Xu | 3 | 0.79% | 1 | 2.44% |
Alexey Dobriyan | 3 | 0.79% | 1 | 2.44% |
Masahide Nakamura | 3 | 0.79% | 1 | 2.44% |
Thomas Graf | 2 | 0.52% | 1 | 2.44% |
David S. Miller | 2 | 0.52% | 1 | 2.44% |
Pavel Emelyanov | 2 | 0.52% | 2 | 4.88% |
Hideaki Yoshifuji / 吉藤英明 | 2 | 0.52% | 1 | 2.44% |
Jan Engelhardt | 1 | 0.26% | 1 | 2.44% |
Patrick McHardy | 1 | 0.26% | 1 | 2.44% |
Julian Anastasov | 1 | 0.26% | 1 | 2.44% |
Total | 381 | 100.00% | 41 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 263 | 42.76% | 15 | 26.79% |
Florian Westphal | 98 | 15.93% | 2 | 3.57% |
Alexey Kuznetsov | 66 | 10.73% | 5 | 8.93% |
John Heffner | 36 | 5.85% | 1 | 1.79% |
Eric W. Biedermann | 28 | 4.55% | 6 | 10.71% |
Hannes Frederic Sowa | 24 | 3.90% | 2 | 3.57% |
Denis Kirjanov | 12 | 1.95% | 1 | 1.79% |
Sebastian Pöhn | 12 | 1.95% | 1 | 1.79% |
Ben Hutchings | 10 | 1.63% | 1 | 1.79% |
Vincent Bernat | 9 | 1.46% | 1 | 1.79% |
David S. Miller | 9 | 1.46% | 1 | 1.79% |
Arnaldo Carvalho de Melo | 6 | 0.98% | 1 | 1.79% |
Eric Dumazet | 6 | 0.98% | 3 | 5.36% |
Linus Torvalds | 5 | 0.81% | 1 | 1.79% |
Wei Dong | 4 | 0.65% | 1 | 1.79% |
Alexey Dobriyan | 3 | 0.49% | 1 | 1.79% |
Herbert Xu | 3 | 0.49% | 1 | 1.79% |
Tejun Heo | 3 | 0.49% | 1 | 1.79% |
Pavel Emelyanov | 3 | 0.49% | 2 | 3.57% |
Masahide Nakamura | 3 | 0.49% | 1 | 1.79% |
Hideaki Yoshifuji / 吉藤英明 | 3 | 0.49% | 2 | 3.57% |
Marcelo Ricardo Leitner | 3 | 0.49% | 1 | 1.79% |
Thomas Graf | 2 | 0.33% | 1 | 1.79% |
Jan Engelhardt | 1 | 0.16% | 1 | 1.79% |
Patrick McHardy | 1 | 0.16% | 1 | 1.79% |
Julian Anastasov | 1 | 0.16% | 1 | 1.79% |
Adrian Bunk | 1 | 0.16% | 1 | 1.79% |
Total | 615 | 100.00% | 56 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.