cregit-Linux how code gets into the kernel

Release 4.8 net/ipv4/ip_forward.c

Directory: net/ipv4
 * 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; }


florian westphalflorian westphal9596.94%266.67%
marcelo ricardo leitnermarcelo ricardo leitner33.06%133.33%

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); }


eric w. biedermaneric w. biederman1012.82%425.00%
vincent bernatvincent bernat911.54%16.25%
david s. millerdavid s. miller78.97%16.25%
alexey kuznetsovalexey kuznetsov33.85%16.25%
eric dumazeteric dumazet22.56%212.50%
pavel emelianovpavel emelianov11.28%16.25%
hideaki yoshifujihideaki yoshifuji11.28%16.25%

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 | IPSKB_FRAG_SEGS; 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.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->, 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; }


alexey kuznetsovalexey kuznetsov6015.67%49.52%
john heffnerjohn heffner369.40%12.38%
hannes frederic sowahannes frederic sowa246.27%24.76%
eric w. biedermaneric w. biederman184.70%24.76%
denis kirjanovdenis kirjanov123.13%12.38%
sebastian pohnsebastian pohn123.13%12.38%
ben hutchingsben hutchings102.61%12.38%
arnaldo carvalho de meloarnaldo carvalho de melo61.57%12.38%
linus torvaldslinus torvalds51.31%12.38%
wei dongwei dong41.04%12.38%
eric dumazeteric dumazet41.04%24.76%
masahide nakamuramasahide nakamura30.78%12.38%
alexey dobriyanalexey dobriyan30.78%12.38%
herbert xuherbert xu30.78%12.38%
florian westphalflorian westphal30.78%12.38%
david s. millerdavid s. miller20.52%12.38%
shmulik ladkanishmulik ladkani20.52%12.38%
pavel emelianovpavel emelianov20.52%24.76%
hideaki yoshifujihideaki yoshifuji20.52%12.38%
thomas grafthomas graf20.52%12.38%
patrick mchardypatrick mchardy10.26%12.38%
jan engelhardtjan engelhardt10.26%12.38%
julian anastasovjulian anastasov10.26%12.38%

Overall Contributors

florian westphalflorian westphal9815.88%23.51%
alexey kuznetsovalexey kuznetsov6610.70%58.77%
john heffnerjohn heffner365.83%11.75%
eric w. biedermaneric w. biederman284.54%610.53%
hannes frederic sowahannes frederic sowa243.89%23.51%
denis kirjanovdenis kirjanov121.94%11.75%
sebastian pohnsebastian pohn121.94%11.75%
ben hutchingsben hutchings101.62%11.75%
vincent bernatvincent bernat91.46%11.75%
david s. millerdavid s. miller91.46%11.75%
eric dumazeteric dumazet60.97%35.26%
arnaldo carvalho de meloarnaldo carvalho de melo60.97%11.75%
linus torvaldslinus torvalds50.81%11.75%
wei dongwei dong40.65%11.75%
masahide nakamuramasahide nakamura30.49%11.75%
herbert xuherbert xu30.49%11.75%
alexey dobriyanalexey dobriyan30.49%11.75%
hideaki yoshifujihideaki yoshifuji30.49%23.51%
pavel emelianovpavel emelianov30.49%23.51%
tejun heotejun heo30.49%11.75%
marcelo ricardo leitnermarcelo ricardo leitner30.49%11.75%
shmulik ladkanishmulik ladkani20.32%11.75%
thomas grafthomas graf20.32%11.75%
patrick mchardypatrick mchardy10.16%11.75%
adrian bunkadrian bunk10.16%11.75%
jan engelhardtjan engelhardt10.16%11.75%
julian anastasovjulian anastasov10.16%11.75%
Directory: net/ipv4
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.