Lines Matching +full:use +full:- +full:rtm
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * ROUTE - implementation of the IP router.
34 * Alan Cox : Use __u32 properly
48 * Andi Kleen : Load-limit warning messages.
110 ((oldflp4)->flowi4_tos & (IPTOS_RT_MASK | RTO_ONLINK))
222 seq_printf(seq, "%-127s\n", in rt_cache_seq_show()
243 for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) { in rt_cpu_seq_start()
285 0, /* st->in_hit */ in rt_cpu_seq_show()
286 st->in_slow_tot, in rt_cpu_seq_show()
287 st->in_slow_mc, in rt_cpu_seq_show()
288 st->in_no_route, in rt_cpu_seq_show()
289 st->in_brd, in rt_cpu_seq_show()
290 st->in_martian_dst, in rt_cpu_seq_show()
291 st->in_martian_src, in rt_cpu_seq_show()
293 0, /* st->out_hit */ in rt_cpu_seq_show()
294 st->out_slow_tot, in rt_cpu_seq_show()
295 st->out_slow_mc, in rt_cpu_seq_show()
297 0, /* st->gc_total */ in rt_cpu_seq_show()
298 0, /* st->gc_ignored */ in rt_cpu_seq_show()
299 0, /* st->gc_goal_miss */ in rt_cpu_seq_show()
300 0, /* st->gc_dst_overflow */ in rt_cpu_seq_show()
301 0, /* st->in_hlist_search */ in rt_cpu_seq_show()
302 0 /* st->out_hlist_search */ in rt_cpu_seq_show()
322 return -ENOMEM; in rt_acct_proc_show()
344 pde = proc_create_seq("rt_cache", 0444, net->proc_net, in ip_rt_do_proc_init()
349 pde = proc_create_seq("rt_cache", 0444, net->proc_net_stat, in ip_rt_do_proc_init()
355 pde = proc_create_single("rt_acct", 0, net->proc_net, in ip_rt_do_proc_init()
364 remove_proc_entry("rt_cache", net->proc_net_stat); in ip_rt_do_proc_init()
367 remove_proc_entry("rt_cache", net->proc_net); in ip_rt_do_proc_init()
369 return -ENOMEM; in ip_rt_do_proc_init()
374 remove_proc_entry("rt_cache", net->proc_net_stat); in ip_rt_do_proc_exit()
375 remove_proc_entry("rt_cache", net->proc_net); in ip_rt_do_proc_exit()
377 remove_proc_entry("rt_acct", net->proc_net); in ip_rt_do_proc_exit()
403 res = rth->rt_genid != rt_genid_ipv4(dev_net_rcu(rth->dst.dev)); in rt_is_expired()
419 struct net_device *dev = dst->dev; in ipv4_neigh_lookup()
424 if (likely(rt->rt_gw_family == AF_INET)) { in ipv4_neigh_lookup()
425 n = ip_neigh_gw4(dev, rt->rt_gw4); in ipv4_neigh_lookup()
426 } else if (rt->rt_gw_family == AF_INET6) { in ipv4_neigh_lookup()
427 n = ip_neigh_gw6(dev, &rt->rt_gw6); in ipv4_neigh_lookup()
431 pkey = skb ? ip_hdr(skb)->daddr : *((__be32 *) daddr); in ipv4_neigh_lookup()
435 if (!IS_ERR(n) && !refcount_inc_not_zero(&n->refcnt)) in ipv4_neigh_lookup()
446 struct net_device *dev = dst->dev; in ipv4_confirm_neigh()
449 if (rt->rt_gw_family == AF_INET) { in ipv4_confirm_neigh()
450 pkey = (const __be32 *)&rt->rt_gw4; in ipv4_confirm_neigh()
451 } else if (rt->rt_gw_family == AF_INET6) { in ipv4_confirm_neigh()
452 return __ipv6_confirm_neigh_stub(dev, &rt->rt_gw6); in ipv4_confirm_neigh()
454 (rt->rt_flags & in ipv4_confirm_neigh()
485 delta = get_random_u32_below(now - old); in ip_idents_reserve()
488 * supports -fno-strict-overflow before reporting it that was a bug in ip_idents_reserve()
489 * in UBSAN, and it has been fixed in GCC-8. in ip_idents_reserve()
491 return atomic_add_return(segs + delta, p_id) - segs; in ip_idents_reserve()
499 if (unlikely(siphash_key_is_zero(&net->ipv4.ip_id_key))) in __ip_select_ident()
500 get_random_bytes(&net->ipv4.ip_id_key, in __ip_select_ident()
501 sizeof(net->ipv4.ip_id_key)); in __ip_select_ident()
503 hash = siphash_3u32((__force u32)iph->daddr, in __ip_select_ident()
504 (__force u32)iph->saddr, in __ip_select_ident()
505 iph->protocol, in __ip_select_ident()
506 &net->ipv4.ip_id_key); in __ip_select_ident()
508 iph->id = htons(id); in __ip_select_ident()
516 fl4->flowi4_tos = tos & IPTOS_RT_MASK; in ip_rt_fix_tos()
518 fl4->flowi4_scope = RT_SCOPE_LINK; in ip_rt_fix_tos()
529 oif = sk->sk_bound_dev_if; in __build_flow_key()
530 mark = READ_ONCE(sk->sk_mark); in __build_flow_key()
534 sk->sk_protocol; in __build_flow_key()
538 prot, flow_flags, iph->daddr, iph->saddr, 0, 0, in __build_flow_key()
545 const struct net *net = dev_net(skb->dev); in build_skb_flow_key()
547 int oif = skb->dev->ifindex; in build_skb_flow_key()
548 u8 prot = iph->protocol; in build_skb_flow_key()
549 u32 mark = skb->mark; in build_skb_flow_key()
550 __u8 tos = iph->tos; in build_skb_flow_key()
559 __be32 daddr = inet->inet_daddr; in build_sk_flow_key()
562 inet_opt = rcu_dereference(inet->inet_opt); in build_sk_flow_key()
563 if (inet_opt && inet_opt->opt.srr) in build_sk_flow_key()
564 daddr = inet_opt->opt.faddr; in build_sk_flow_key()
565 flowi4_init_output(fl4, sk->sk_bound_dev_if, READ_ONCE(sk->sk_mark), in build_sk_flow_key()
569 IPPROTO_RAW : sk->sk_protocol, in build_sk_flow_key()
571 daddr, inet->inet_saddr, 0, 0, sk->sk_uid); in build_sk_flow_key()
590 rt = rcu_dereference(fnhe->fnhe_rth_input); in fnhe_flush_routes()
592 RCU_INIT_POINTER(fnhe->fnhe_rth_input, NULL); in fnhe_flush_routes()
593 dst_dev_put(&rt->dst); in fnhe_flush_routes()
594 dst_release(&rt->dst); in fnhe_flush_routes()
596 rt = rcu_dereference(fnhe->fnhe_rth_output); in fnhe_flush_routes()
598 RCU_INIT_POINTER(fnhe->fnhe_rth_output, NULL); in fnhe_flush_routes()
599 dst_dev_put(&rt->dst); in fnhe_flush_routes()
600 dst_release(&rt->dst); in fnhe_flush_routes()
609 for (fnhe_p = &hash->chain; ; fnhe_p = &fnhe->fnhe_next) { in fnhe_remove_oldest()
615 time_before(fnhe->fnhe_stamp, oldest->fnhe_stamp)) { in fnhe_remove_oldest()
621 *oldest_p = oldest->fnhe_next; in fnhe_remove_oldest()
637 rt->rt_pmtu = fnhe->fnhe_pmtu; in fill_route_from_fnhe()
638 rt->rt_mtu_locked = fnhe->fnhe_mtu_locked; in fill_route_from_fnhe()
639 rt->dst.expires = fnhe->fnhe_expires; in fill_route_from_fnhe()
641 if (fnhe->fnhe_gw) { in fill_route_from_fnhe()
642 rt->rt_flags |= RTCF_REDIRECTED; in fill_route_from_fnhe()
643 rt->rt_uses_gateway = 1; in fill_route_from_fnhe()
644 rt->rt_gw_family = AF_INET; in fill_route_from_fnhe()
645 rt->rt_gw4 = fnhe->fnhe_gw; in fill_route_from_fnhe()
660 genid = fnhe_genid(dev_net(nhc->nhc_dev)); in update_or_create_fnhe()
665 hash = rcu_dereference(nhc->nhc_exceptions); in update_or_create_fnhe()
670 rcu_assign_pointer(nhc->nhc_exceptions, hash); in update_or_create_fnhe()
676 for (fnhe = rcu_dereference(hash->chain); fnhe; in update_or_create_fnhe()
677 fnhe = rcu_dereference(fnhe->fnhe_next)) { in update_or_create_fnhe()
678 if (fnhe->fnhe_daddr == daddr) in update_or_create_fnhe()
684 if (fnhe->fnhe_genid != genid) in update_or_create_fnhe()
685 fnhe->fnhe_genid = genid; in update_or_create_fnhe()
687 fnhe->fnhe_gw = gw; in update_or_create_fnhe()
689 fnhe->fnhe_pmtu = pmtu; in update_or_create_fnhe()
690 fnhe->fnhe_mtu_locked = lock; in update_or_create_fnhe()
692 fnhe->fnhe_expires = max(1UL, expires); in update_or_create_fnhe()
694 rt = rcu_dereference(fnhe->fnhe_rth_input); in update_or_create_fnhe()
697 rt = rcu_dereference(fnhe->fnhe_rth_output); in update_or_create_fnhe()
707 depth--; in update_or_create_fnhe()
714 fnhe->fnhe_next = hash->chain; in update_or_create_fnhe()
716 fnhe->fnhe_genid = genid; in update_or_create_fnhe()
717 fnhe->fnhe_daddr = daddr; in update_or_create_fnhe()
718 fnhe->fnhe_gw = gw; in update_or_create_fnhe()
719 fnhe->fnhe_pmtu = pmtu; in update_or_create_fnhe()
720 fnhe->fnhe_mtu_locked = lock; in update_or_create_fnhe()
721 fnhe->fnhe_expires = max(1UL, expires); in update_or_create_fnhe()
723 rcu_assign_pointer(hash->chain, fnhe); in update_or_create_fnhe()
729 rt = rcu_dereference(nhc->nhc_rth_input); in update_or_create_fnhe()
731 rt->dst.obsolete = DST_OBSOLETE_KILL; in update_or_create_fnhe()
736 prt = per_cpu_ptr(nhc->nhc_pcpu_rth_output, i); in update_or_create_fnhe()
739 rt->dst.obsolete = DST_OBSOLETE_KILL; in update_or_create_fnhe()
743 fnhe->fnhe_stamp = jiffies; in update_or_create_fnhe()
752 __be32 new_gw = icmp_hdr(skb)->un.gateway; in __ip_do_redirect()
753 __be32 old_gw = ip_hdr(skb)->saddr; in __ip_do_redirect()
754 struct net_device *dev = skb->dev; in __ip_do_redirect()
760 switch (icmp_hdr(skb)->code & 7) { in __ip_do_redirect()
771 if (rt->rt_gw_family != AF_INET || rt->rt_gw4 != old_gw) in __ip_do_redirect()
794 n = __ipv4_neigh_lookup(rt->dst.dev, (__force u32)new_gw); in __ip_do_redirect()
796 n = neigh_create(&arp_tbl, &new_gw, rt->dst.dev); in __ip_do_redirect()
798 if (!(READ_ONCE(n->nud_state) & NUD_VALID)) { in __ip_do_redirect()
806 update_or_create_fnhe(nhc, fl4->daddr, new_gw, in __ip_do_redirect()
811 rt->dst.obsolete = DST_OBSOLETE_KILL; in __ip_do_redirect()
821 const struct iphdr *iph = (const struct iphdr *) skb->data; in __ip_do_redirect()
822 __be32 daddr = iph->daddr; in __ip_do_redirect()
823 __be32 saddr = iph->saddr; in __ip_do_redirect()
826 " Advised path = %pI4 -> %pI4\n", in __ip_do_redirect()
827 &old_gw, dev->name, &new_gw, in __ip_do_redirect()
838 const struct iphdr *iph = (const struct iphdr *) skb->data; in ip_do_redirect()
839 struct net *net = dev_net(skb->dev); in ip_do_redirect()
840 int oif = skb->dev->ifindex; in ip_do_redirect()
841 u8 prot = iph->protocol; in ip_do_redirect()
842 u32 mark = skb->mark; in ip_do_redirect()
843 __u8 tos = iph->tos; in ip_do_redirect()
856 if ((dst->obsolete > 0) || in ipv4_negative_advice()
857 (rt->rt_flags & RTCF_REDIRECTED) || in ipv4_negative_advice()
858 rt->dst.expires) in ipv4_negative_advice()
888 in_dev = __in_dev_get_rcu(rt->dst.dev); in ip_rt_send_redirect()
894 vif = l3mdev_master_ifindex_rcu(rt->dst.dev); in ip_rt_send_redirect()
896 net = dev_net(rt->dst.dev); in ip_rt_send_redirect()
897 peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif); in ip_rt_send_redirect()
901 rt_nexthop(rt, ip_hdr(skb)->daddr)); in ip_rt_send_redirect()
908 if (time_after(jiffies, peer->rate_last + ip_rt_redirect_silence)) { in ip_rt_send_redirect()
909 peer->rate_tokens = 0; in ip_rt_send_redirect()
910 peer->n_redirects = 0; in ip_rt_send_redirect()
916 if (peer->n_redirects >= ip_rt_redirect_number) { in ip_rt_send_redirect()
917 peer->rate_last = jiffies; in ip_rt_send_redirect()
924 if (peer->n_redirects == 0 || in ip_rt_send_redirect()
926 (peer->rate_last + in ip_rt_send_redirect()
927 (ip_rt_redirect_load << peer->n_redirects)))) { in ip_rt_send_redirect()
928 __be32 gw = rt_nexthop(rt, ip_hdr(skb)->daddr); in ip_rt_send_redirect()
931 peer->rate_last = jiffies; in ip_rt_send_redirect()
932 ++peer->n_redirects; in ip_rt_send_redirect()
934 peer->n_redirects == ip_rt_redirect_number) in ip_rt_send_redirect()
936 &ip_hdr(skb)->saddr, inet_iif(skb), in ip_rt_send_redirect()
937 &ip_hdr(skb)->daddr, &gw); in ip_rt_send_redirect()
946 struct net_device *dev = skb->dev; in ip_error()
955 if (netif_is_l3_master(skb->dev)) { in ip_error()
956 dev = __dev_get_by_index(dev_net(skb->dev), IPCB(skb)->iif); in ip_error()
967 net = dev_net(rt->dst.dev); in ip_error()
969 switch (rt->dst.error) { in ip_error()
983 switch (rt->dst.error) { in ip_error()
1001 peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, in ip_error()
1002 l3mdev_master_ifindex_rcu(skb->dev)); in ip_error()
1006 peer->rate_tokens += now - peer->rate_last; in ip_error()
1007 if (peer->rate_tokens > ip_rt_error_burst) in ip_error()
1008 peer->rate_tokens = ip_rt_error_burst; in ip_error()
1009 peer->rate_last = now; in ip_error()
1010 if (peer->rate_tokens >= ip_rt_error_cost) in ip_error()
1011 peer->rate_tokens -= ip_rt_error_cost; in ip_error()
1026 struct dst_entry *dst = &rt->dst; in __ip_rt_update_pmtu()
1040 net = dev_net_rcu(dst->dev); in __ip_rt_update_pmtu()
1041 if (mtu < net->ipv4.ip_rt_min_pmtu) { in __ip_rt_update_pmtu()
1043 mtu = min(old_mtu, net->ipv4.ip_rt_min_pmtu); in __ip_rt_update_pmtu()
1046 if (rt->rt_pmtu == mtu && !lock && in __ip_rt_update_pmtu()
1047 time_before(jiffies, dst->expires - net->ipv4.ip_rt_mtu_expires / 2)) in __ip_rt_update_pmtu()
1060 update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock, in __ip_rt_update_pmtu()
1061 jiffies + net->ipv4.ip_rt_mtu_expires); in __ip_rt_update_pmtu()
1067 update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock, in __ip_rt_update_pmtu()
1068 jiffies + net->ipv4.ip_rt_mtu_expires); in __ip_rt_update_pmtu()
1084 if (skb && netif_is_any_bridge_port(skb->dev)) in ip_rt_update_pmtu()
1093 const struct iphdr *iph = (const struct iphdr *)skb->data; in ipv4_update_pmtu()
1096 u32 mark = IP4_REPLY_MARK(net, skb->mark); in ipv4_update_pmtu()
1098 __build_flow_key(net, &fl4, NULL, iph, oif, iph->tos, protocol, mark, in ipv4_update_pmtu()
1110 const struct iphdr *iph = (const struct iphdr *)skb->data; in __ipv4_sk_update_pmtu()
1117 fl4.flowi4_mark = IP4_REPLY_MARK(sock_net(sk), skb->mark); in __ipv4_sk_update_pmtu()
1128 const struct iphdr *iph = (const struct iphdr *)skb->data; in ipv4_sk_update_pmtu()
1150 if (odst->obsolete && !odst->ops->check(odst, 0)) { in ipv4_sk_update_pmtu()
1158 __ip_rt_update_pmtu((struct rtable *)xfrm_dst_path(&rt->dst), &fl4, mtu); in ipv4_sk_update_pmtu()
1160 if (!dst_check(&rt->dst, 0)) { in ipv4_sk_update_pmtu()
1162 dst_release(&rt->dst); in ipv4_sk_update_pmtu()
1172 sk_dst_set(sk, &rt->dst); in ipv4_sk_update_pmtu()
1183 const struct iphdr *iph = (const struct iphdr *)skb->data; in ipv4_redirect()
1187 __build_flow_key(net, &fl4, NULL, iph, oif, iph->tos, protocol, 0, 0); in ipv4_redirect()
1198 const struct iphdr *iph = (const struct iphdr *)skb->data; in ipv4_sk_redirect()
1217 /* All IPV4 dsts are created with ->obsolete set to the value in ipv4_dst_check()
1225 if (dst->obsolete != DST_OBSOLETE_FORCE_CHK || rt_is_expired(rt)) in ipv4_dst_check()
1241 ip_hdr(skb)->version != 4 || ip_hdr(skb)->ihl < 5) in ipv4_send_dest_unreach()
1245 if (ip_hdr(skb)->ihl > 5) { in ipv4_send_dest_unreach()
1246 if (!pskb_network_may_pull(skb, ip_hdr(skb)->ihl * 4)) in ipv4_send_dest_unreach()
1248 opt.optlen = ip_hdr(skb)->ihl * 4 - sizeof(struct iphdr); in ipv4_send_dest_unreach()
1251 dev = skb->dev ? skb->dev : skb_rtable(skb)->dst.dev; in ipv4_send_dest_unreach()
1269 dst_set_expires(&rt->dst, 0); in ipv4_link_failure()
1274 pr_debug("%s: %pI4 -> %pI4, %s\n", in ip_rt_bug()
1275 __func__, &ip_hdr(skb)->saddr, &ip_hdr(skb)->daddr, in ip_rt_bug()
1276 skb->dev ? skb->dev->name : "?"); in ip_rt_bug()
1296 src = ip_hdr(skb)->saddr; in ip_rt_get_source()
1301 .daddr = iph->daddr, in ip_rt_get_source()
1302 .saddr = iph->saddr, in ip_rt_get_source()
1303 .flowi4_tos = iph->tos & IPTOS_RT_MASK, in ip_rt_get_source()
1304 .flowi4_oif = rt->dst.dev->ifindex, in ip_rt_get_source()
1305 .flowi4_iif = skb->dev->ifindex, in ip_rt_get_source()
1306 .flowi4_mark = skb->mark, in ip_rt_get_source()
1310 if (fib_lookup(dev_net(rt->dst.dev), &fl4, &res, 0) == 0) in ip_rt_get_source()
1311 src = fib_result_prefsrc(dev_net(rt->dst.dev), &res); in ip_rt_get_source()
1313 src = inet_select_addr(rt->dst.dev, in ip_rt_get_source()
1314 rt_nexthop(rt, iph->daddr), in ip_rt_get_source()
1324 if (!(rt->dst.tclassid & 0xFFFF)) in set_class_tag()
1325 rt->dst.tclassid |= tag & 0xFFFF; in set_class_tag()
1326 if (!(rt->dst.tclassid & 0xFFFF0000)) in set_class_tag()
1327 rt->dst.tclassid |= tag & 0xFFFF0000; in set_class_tag()
1338 net = dev_net_rcu(dst->dev); in ipv4_default_advmss()
1339 advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, in ipv4_default_advmss()
1340 net->ipv4.ip_rt_min_advmss); in ipv4_default_advmss()
1343 return min(advmss, IPV4_MAX_PMTU - header_size); in ipv4_default_advmss()
1360 hash = rcu_dereference_protected(nhc->nhc_exceptions, in ip_del_fnhe()
1364 fnhe_p = &hash->chain; in ip_del_fnhe()
1367 if (fnhe->fnhe_daddr == daddr) { in ip_del_fnhe()
1369 fnhe->fnhe_next, lockdep_is_held(&fnhe_lock))); in ip_del_fnhe()
1373 fnhe->fnhe_daddr = 0; in ip_del_fnhe()
1378 fnhe_p = &fnhe->fnhe_next; in ip_del_fnhe()
1379 fnhe = rcu_dereference_protected(fnhe->fnhe_next, in ip_del_fnhe()
1389 struct fnhe_hash_bucket *hash = rcu_dereference(nhc->nhc_exceptions); in find_exception()
1399 fnhe = rcu_dereference(fnhe->fnhe_next)) { in find_exception()
1400 if (fnhe->fnhe_daddr == daddr) { in find_exception()
1401 if (fnhe->fnhe_expires && in find_exception()
1402 time_after(jiffies, fnhe->fnhe_expires)) { in find_exception()
1413 * 1. mtu on route is locked - use it
1420 struct fib_nh_common *nhc = res->nhc; in ip_mtu_from_fib_result()
1421 struct net_device *dev = nhc->nhc_dev; in ip_mtu_from_fib_result()
1422 struct fib_info *fi = res->fi; in ip_mtu_from_fib_result()
1425 if (READ_ONCE(dev_net(dev)->ipv4.sysctl_ip_fwd_use_pmtu) || in ip_mtu_from_fib_result()
1426 fi->fib_metrics->metrics[RTAX_LOCK - 1] & (1 << RTAX_MTU)) in ip_mtu_from_fib_result()
1427 mtu = fi->fib_mtu; in ip_mtu_from_fib_result()
1433 if (fnhe && !time_after_eq(jiffies, fnhe->fnhe_expires)) in ip_mtu_from_fib_result()
1434 mtu = fnhe->fnhe_pmtu; in ip_mtu_from_fib_result()
1438 mtu = min(READ_ONCE(dev->mtu), IP_MAX_MTU); in ip_mtu_from_fib_result()
1440 return mtu - lwtunnel_headroom(nhc->nhc_lwtstate, mtu); in ip_mtu_from_fib_result()
1450 if (daddr == fnhe->fnhe_daddr) { in rt_bind_exception()
1453 int genid = fnhe_genid(dev_net(rt->dst.dev)); in rt_bind_exception()
1456 porig = &fnhe->fnhe_rth_input; in rt_bind_exception()
1458 porig = &fnhe->fnhe_rth_output; in rt_bind_exception()
1461 if (fnhe->fnhe_genid != genid) { in rt_bind_exception()
1462 fnhe->fnhe_genid = genid; in rt_bind_exception()
1463 fnhe->fnhe_gw = 0; in rt_bind_exception()
1464 fnhe->fnhe_pmtu = 0; in rt_bind_exception()
1465 fnhe->fnhe_expires = 0; in rt_bind_exception()
1466 fnhe->fnhe_mtu_locked = false; in rt_bind_exception()
1471 if (!rt->rt_gw4) { in rt_bind_exception()
1472 rt->rt_gw4 = daddr; in rt_bind_exception()
1473 rt->rt_gw_family = AF_INET; in rt_bind_exception()
1477 dst_hold(&rt->dst); in rt_bind_exception()
1480 dst_dev_put(&orig->dst); in rt_bind_exception()
1481 dst_release(&orig->dst); in rt_bind_exception()
1486 fnhe->fnhe_stamp = jiffies; in rt_bind_exception()
1499 p = (struct rtable **)&nhc->nhc_rth_input; in rt_cache_route()
1501 p = (struct rtable **)raw_cpu_ptr(nhc->nhc_pcpu_rth_output); in rt_cache_route()
1508 dst_hold(&rt->dst); in rt_cache_route()
1513 dst_release(&orig->dst); in rt_cache_route()
1516 dst_release(&rt->dst); in rt_cache_route()
1535 rt->dst.rt_uncached_list = ul; in rt_add_uncached_list()
1537 spin_lock_bh(&ul->lock); in rt_add_uncached_list()
1538 list_add_tail(&rt->dst.rt_uncached, &ul->head); in rt_add_uncached_list()
1539 spin_unlock_bh(&ul->lock); in rt_add_uncached_list()
1544 if (!list_empty(&rt->dst.rt_uncached)) { in rt_del_uncached_list()
1545 struct uncached_list *ul = rt->dst.rt_uncached_list; in rt_del_uncached_list()
1547 spin_lock_bh(&ul->lock); in rt_del_uncached_list()
1548 list_del_init(&rt->dst.rt_uncached); in rt_del_uncached_list()
1549 spin_unlock_bh(&ul->lock); in rt_del_uncached_list()
1569 if (list_empty(&ul->head)) in rt_flush_dev()
1572 spin_lock_bh(&ul->lock); in rt_flush_dev()
1573 list_for_each_entry_safe(rt, safe, &ul->head, dst.rt_uncached) { in rt_flush_dev()
1574 if (rt->dst.dev != dev) in rt_flush_dev()
1576 rt->dst.dev = blackhole_netdev; in rt_flush_dev()
1578 &rt->dst.dev_tracker, GFP_ATOMIC); in rt_flush_dev()
1579 list_move(&rt->dst.rt_uncached, &ul->quarantine); in rt_flush_dev()
1581 spin_unlock_bh(&ul->lock); in rt_flush_dev()
1588 rt->dst.obsolete == DST_OBSOLETE_FORCE_CHK && in rt_cache_valid()
1603 if (nhc->nhc_gw_family && nhc->nhc_scope == RT_SCOPE_LINK) { in rt_set_nexthop()
1604 rt->rt_uses_gateway = 1; in rt_set_nexthop()
1605 rt->rt_gw_family = nhc->nhc_gw_family; in rt_set_nexthop()
1607 if (likely(nhc->nhc_gw_family == AF_INET)) in rt_set_nexthop()
1608 rt->rt_gw4 = nhc->nhc_gw.ipv4; in rt_set_nexthop()
1610 rt->rt_gw6 = nhc->nhc_gw.ipv6; in rt_set_nexthop()
1613 ip_dst_init_metrics(&rt->dst, fi->fib_metrics); in rt_set_nexthop()
1616 if (nhc->nhc_family == AF_INET) { in rt_set_nexthop()
1620 rt->dst.tclassid = nh->nh_tclassid; in rt_set_nexthop()
1623 rt->dst.lwtstate = lwtstate_get(nhc->nhc_lwtstate); in rt_set_nexthop()
1634 if (!rt->rt_gw4) { in rt_set_nexthop()
1635 rt->rt_gw_family = AF_INET; in rt_set_nexthop()
1636 rt->rt_gw4 = daddr; in rt_set_nexthop()
1645 set_class_tag(rt, res->tclassid); in rt_set_nexthop()
1661 rt->rt_genid = rt_genid_ipv4(dev_net(dev)); in rt_dst_alloc()
1662 rt->rt_flags = flags; in rt_dst_alloc()
1663 rt->rt_type = type; in rt_dst_alloc()
1664 rt->rt_is_input = 0; in rt_dst_alloc()
1665 rt->rt_iif = 0; in rt_dst_alloc()
1666 rt->rt_pmtu = 0; in rt_dst_alloc()
1667 rt->rt_mtu_locked = 0; in rt_dst_alloc()
1668 rt->rt_uses_gateway = 0; in rt_dst_alloc()
1669 rt->rt_gw_family = 0; in rt_dst_alloc()
1670 rt->rt_gw4 = 0; in rt_dst_alloc()
1672 rt->dst.output = ip_output; in rt_dst_alloc()
1674 rt->dst.input = ip_local_deliver; in rt_dst_alloc()
1686 rt->dst.flags); in rt_dst_clone()
1689 new_rt->rt_genid = rt_genid_ipv4(dev_net(dev)); in rt_dst_clone()
1690 new_rt->rt_flags = rt->rt_flags; in rt_dst_clone()
1691 new_rt->rt_type = rt->rt_type; in rt_dst_clone()
1692 new_rt->rt_is_input = rt->rt_is_input; in rt_dst_clone()
1693 new_rt->rt_iif = rt->rt_iif; in rt_dst_clone()
1694 new_rt->rt_pmtu = rt->rt_pmtu; in rt_dst_clone()
1695 new_rt->rt_mtu_locked = rt->rt_mtu_locked; in rt_dst_clone()
1696 new_rt->rt_gw_family = rt->rt_gw_family; in rt_dst_clone()
1697 if (rt->rt_gw_family == AF_INET) in rt_dst_clone()
1698 new_rt->rt_gw4 = rt->rt_gw4; in rt_dst_clone()
1699 else if (rt->rt_gw_family == AF_INET6) in rt_dst_clone()
1700 new_rt->rt_gw6 = rt->rt_gw6; in rt_dst_clone()
1702 new_rt->dst.input = rt->dst.input; in rt_dst_clone()
1703 new_rt->dst.output = rt->dst.output; in rt_dst_clone()
1704 new_rt->dst.error = rt->dst.error; in rt_dst_clone()
1705 new_rt->dst.lastuse = jiffies; in rt_dst_clone()
1706 new_rt->dst.lwtstate = lwtstate_get(rt->dst.lwtstate); in rt_dst_clone()
1721 return -EINVAL; in ip_mc_validate_source()
1724 skb->protocol != htons(ETH_P_IP)) in ip_mc_validate_source()
1725 return -EINVAL; in ip_mc_validate_source()
1728 return -EINVAL; in ip_mc_validate_source()
1732 ip_hdr(skb)->protocol != IPPROTO_IGMP) in ip_mc_validate_source()
1733 return -EINVAL; in ip_mc_validate_source()
1761 IPCB(skb)->flags |= IPSKB_NOPOLICY; in ip_route_input_mc()
1763 rth = rt_dst_alloc(dev_net(dev)->loopback_dev, flags, RTN_MULTICAST, in ip_route_input_mc()
1766 return -ENOBUFS; in ip_route_input_mc()
1769 rth->dst.tclassid = itag; in ip_route_input_mc()
1771 rth->dst.output = ip_rt_bug; in ip_route_input_mc()
1772 rth->rt_is_input= 1; in ip_route_input_mc()
1776 rth->dst.input = ip_mr_input; in ip_route_input_mc()
1781 skb_dst_set(skb, &rth->dst); in ip_route_input_mc()
1800 &daddr, &saddr, dev->name); in ip_handle_martian_source()
1801 if (dev->hard_header_len && skb_mac_header_was_set(skb)) { in ip_handle_martian_source()
1805 dev->hard_header_len, false); in ip_handle_martian_source()
1818 struct net_device *dev = nhc->nhc_dev; in __mkroute_input()
1830 return -EINVAL; in __mkroute_input()
1834 in_dev->dev, in_dev, &itag); in __mkroute_input()
1836 ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr, in __mkroute_input()
1842 do_cache = res->fi && !itag; in __mkroute_input()
1844 skb->protocol == htons(ETH_P_IP)) { in __mkroute_input()
1847 gw = nhc->nhc_gw_family == AF_INET ? nhc->nhc_gw.ipv4 : 0; in __mkroute_input()
1850 IPCB(skb)->flags |= IPSKB_DOREDIRECT; in __mkroute_input()
1853 if (skb->protocol != htons(ETH_P_IP)) { in __mkroute_input()
1863 err = -EINVAL; in __mkroute_input()
1869 IPCB(skb)->flags |= IPSKB_NOPOLICY; in __mkroute_input()
1874 rth = rcu_dereference(fnhe->fnhe_rth_input); in __mkroute_input()
1876 rth = rcu_dereference(nhc->nhc_rth_input); in __mkroute_input()
1878 skb_dst_set_noref(skb, &rth->dst); in __mkroute_input()
1883 rth = rt_dst_alloc(out_dev->dev, 0, res->type, in __mkroute_input()
1886 err = -ENOBUFS; in __mkroute_input()
1890 rth->rt_is_input = 1; in __mkroute_input()
1893 rth->dst.input = ip_forward; in __mkroute_input()
1895 rt_set_nexthop(rth, daddr, res, fnhe, res->fi, res->type, itag, in __mkroute_input()
1897 lwtunnel_set_redirect(&rth->dst); in __mkroute_input()
1898 skb_dst_set(skb, &rth->dst); in __mkroute_input()
1919 if (likely(outer_iph->protocol != IPPROTO_ICMP)) in ip_multipath_l3_keys()
1922 if (unlikely((outer_iph->frag_off & htons(IP_OFFSET)) != 0)) in ip_multipath_l3_keys()
1925 icmph = skb_header_pointer(skb, outer_iph->ihl * 4, sizeof(_icmph), in ip_multipath_l3_keys()
1930 if (!icmp_is_err(icmph->type)) in ip_multipath_l3_keys()
1934 outer_iph->ihl * 4 + sizeof(_icmph), in ip_multipath_l3_keys()
1941 hash_keys->addrs.v4addrs.src = key_iph->saddr; in ip_multipath_l3_keys()
1942 hash_keys->addrs.v4addrs.dst = key_iph->daddr; in ip_multipath_l3_keys()
1949 u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields); in fib_multipath_custom_hash_outer()
1978 u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields); in fib_multipath_custom_hash_inner()
2038 u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields); in fib_multipath_custom_hash_fl4()
2047 hash_keys.addrs.v4addrs.src = fl4->saddr; in fib_multipath_custom_hash_fl4()
2049 hash_keys.addrs.v4addrs.dst = fl4->daddr; in fib_multipath_custom_hash_fl4()
2051 hash_keys.basic.ip_proto = fl4->flowi4_proto; in fib_multipath_custom_hash_fl4()
2053 hash_keys.ports.src = fl4->fl4_sport; in fib_multipath_custom_hash_fl4()
2055 hash_keys.ports.dst = fl4->fl4_dport; in fib_multipath_custom_hash_fl4()
2064 u32 multipath_hash = fl4 ? fl4->flowi4_multipath_hash : 0; in fib_multipath_hash()
2068 switch (READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_policy)) { in fib_multipath_hash()
2075 hash_keys.addrs.v4addrs.src = fl4->saddr; in fib_multipath_hash()
2076 hash_keys.addrs.v4addrs.dst = fl4->daddr; in fib_multipath_hash()
2086 /* short-circuit if we already have L4 hash present */ in fib_multipath_hash()
2087 if (skb->l4_hash) in fib_multipath_hash()
2098 hash_keys.addrs.v4addrs.src = flkeys->addrs.v4addrs.src; in fib_multipath_hash()
2099 hash_keys.addrs.v4addrs.dst = flkeys->addrs.v4addrs.dst; in fib_multipath_hash()
2100 hash_keys.ports.src = flkeys->ports.src; in fib_multipath_hash()
2101 hash_keys.ports.dst = flkeys->ports.dst; in fib_multipath_hash()
2102 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in fib_multipath_hash()
2106 hash_keys.addrs.v4addrs.src = fl4->saddr; in fib_multipath_hash()
2107 hash_keys.addrs.v4addrs.dst = fl4->daddr; in fib_multipath_hash()
2108 hash_keys.ports.src = fl4->fl4_sport; in fib_multipath_hash()
2109 hash_keys.ports.dst = fl4->fl4_dport; in fib_multipath_hash()
2110 hash_keys.basic.ip_proto = fl4->flowi4_proto; in fib_multipath_hash()
2140 hash_keys.addrs.v4addrs.src = fl4->saddr; in fib_multipath_hash()
2141 hash_keys.addrs.v4addrs.dst = fl4->daddr; in fib_multipath_hash()
2167 if (res->fi && fib_info_num_path(res->fi) > 1) { in ip_mkroute_input()
2168 int h = fib_multipath_hash(res->fi->fib_net, NULL, skb, hkeys); in ip_mkroute_input()
2171 IPCB(skb)->flags |= IPSKB_MULTIPATH; in ip_mkroute_input()
2179 /* Implements all the saddr-related checks as ip_route_input_slow(),
2190 int err = -EINVAL; in ip_route_use_hint()
2194 return -EINVAL; in ip_route_use_hint()
2205 if (rt->rt_type != RTN_LOCAL) in ip_route_use_hint()
2226 struct fib_nh_common *nhc = res->fi ? res->nhc : NULL; in ip_rt_get_dev()
2230 dev = l3mdev_master_dev_rcu(nhc->nhc_dev); in ip_rt_get_dev()
2232 return dev ? : net->loopback_dev; in ip_rt_get_dev()
2256 int err = -EINVAL; in ip_route_input_slow()
2273 if (tun_info && !(tun_info->mode & IP_TUNNEL_INFO_TX)) in ip_route_input_slow()
2274 fl4.flowi4_tun_key.tun_id = tun_info->key.tun_id; in ip_route_input_slow()
2282 res->fi = NULL; in ip_route_input_slow()
2283 res->table = NULL; in ip_route_input_slow()
2288 * I even do not know to fix it or not. Waiting for complains :-) in ip_route_input_slow()
2312 fl4.flowi4_iif = dev->ifindex; in ip_route_input_slow()
2313 fl4.flowi4_mark = skb->mark; in ip_route_input_slow()
2333 err = -EHOSTUNREACH; in ip_route_input_slow()
2337 if (res->type == RTN_BROADCAST) { in ip_route_input_slow()
2346 if (res->type == RTN_LOCAL) { in ip_route_input_slow()
2355 err = -EHOSTUNREACH; in ip_route_input_slow()
2358 if (res->type != RTN_UNICAST) in ip_route_input_slow()
2366 if (skb->protocol != htons(ETH_P_IP)) in ip_route_input_slow()
2376 res->type = RTN_BROADCAST; in ip_route_input_slow()
2381 IPCB(skb)->flags |= IPSKB_NOPOLICY; in ip_route_input_slow()
2383 do_cache &= res->fi && !itag; in ip_route_input_slow()
2387 rth = rcu_dereference(nhc->nhc_rth_input); in ip_route_input_slow()
2389 skb_dst_set_noref(skb, &rth->dst); in ip_route_input_slow()
2396 flags | RTCF_LOCAL, res->type, false); in ip_route_input_slow()
2400 rth->dst.output= ip_rt_bug; in ip_route_input_slow()
2402 rth->dst.tclassid = itag; in ip_route_input_slow()
2404 rth->rt_is_input = 1; in ip_route_input_slow()
2407 if (res->type == RTN_UNREACHABLE) { in ip_route_input_slow()
2408 rth->dst.input= ip_error; in ip_route_input_slow()
2409 rth->dst.error= -err; in ip_route_input_slow()
2410 rth->rt_flags &= ~RTCF_LOCAL; in ip_route_input_slow()
2416 rth->dst.lwtstate = lwtstate_get(nhc->nhc_lwtstate); in ip_route_input_slow()
2417 if (lwtunnel_input_redirect(rth->dst.lwtstate)) { in ip_route_input_slow()
2418 WARN_ON(rth->dst.input == lwtunnel_input); in ip_route_input_slow()
2419 rth->dst.lwtstate->orig_input = rth->dst.input; in ip_route_input_slow()
2420 rth->dst.input = lwtunnel_input; in ip_route_input_slow()
2426 skb_dst_set(skb, &rth->dst); in ip_route_input_slow()
2432 res->type = RTN_UNREACHABLE; in ip_route_input_slow()
2433 res->fi = NULL; in ip_route_input_slow()
2434 res->table = NULL; in ip_route_input_slow()
2445 &daddr, &saddr, dev->name); in ip_route_input_slow()
2449 err = -EINVAL; in ip_route_input_slow()
2453 err = -ENOBUFS; in ip_route_input_slow()
2467 * hardware multicast filters :-( As result the host on multicasting in ip_route_input_rcu()
2479 int err = -EINVAL; in ip_route_input_rcu()
2484 ip_hdr(skb)->protocol); in ip_route_input_rcu()
2490 l3_in_dev = __in_dev_get_rcu(skb->dev); in ip_route_input_rcu()
2493 ip_hdr(skb)->protocol); in ip_route_input_rcu()
2533 struct fib_info *fi = res->fi; in __mkroute_output()
2536 u16 type = res->type; in __mkroute_output()
2542 return ERR_PTR(-EINVAL); in __mkroute_output()
2545 if (ipv4_is_loopback(fl4->saddr) && in __mkroute_output()
2546 !(dev_out->flags & IFF_LOOPBACK) && in __mkroute_output()
2548 return ERR_PTR(-EINVAL); in __mkroute_output()
2550 if (ipv4_is_lbcast(fl4->daddr)) in __mkroute_output()
2552 else if (ipv4_is_multicast(fl4->daddr)) in __mkroute_output()
2554 else if (ipv4_is_zeronet(fl4->daddr)) in __mkroute_output()
2555 return ERR_PTR(-EINVAL); in __mkroute_output()
2557 if (dev_out->flags & IFF_LOOPBACK) in __mkroute_output()
2566 if (!ip_check_mc_rcu(in_dev, fl4->daddr, fl4->saddr, in __mkroute_output()
2567 fl4->flowi4_proto)) in __mkroute_output()
2571 /* If multicast route do not exist use in __mkroute_output()
2575 if (fi && res->prefixlen < 4) in __mkroute_output()
2578 (orig_oif != dev_out->ifindex)) { in __mkroute_output()
2597 fnhe = find_exception(nhc, fl4->daddr); in __mkroute_output()
2601 prth = &fnhe->fnhe_rth_output; in __mkroute_output()
2603 if (unlikely(fl4->flowi4_flags & in __mkroute_output()
2605 !(nhc->nhc_gw_family && in __mkroute_output()
2606 nhc->nhc_scope == RT_SCOPE_LINK))) { in __mkroute_output()
2610 prth = raw_cpu_ptr(nhc->nhc_pcpu_rth_output); in __mkroute_output()
2613 if (rt_cache_valid(rth) && dst_hold_safe(&rth->dst)) in __mkroute_output()
2621 return ERR_PTR(-ENOBUFS); in __mkroute_output()
2623 rth->rt_iif = orig_oif; in __mkroute_output()
2629 !(dev_out->flags & IFF_LOOPBACK)) { in __mkroute_output()
2630 rth->dst.output = ip_mc_output; in __mkroute_output()
2636 !ipv4_is_local_multicast(fl4->daddr)) { in __mkroute_output()
2637 rth->dst.input = ip_mr_input; in __mkroute_output()
2638 rth->dst.output = ip_mc_output; in __mkroute_output()
2644 rt_set_nexthop(rth, fl4->daddr, res, fnhe, fi, type, 0, do_cache); in __mkroute_output()
2645 lwtunnel_set_redirect(&rth->dst); in __mkroute_output()
2665 fl4->flowi4_iif = LOOPBACK_IFINDEX; in ip_route_output_key_hash()
2681 int orig_oif = fl4->flowi4_oif; in ip_route_output_key_hash_rcu()
2686 if (fl4->saddr) { in ip_route_output_key_hash_rcu()
2687 if (ipv4_is_multicast(fl4->saddr) || in ip_route_output_key_hash_rcu()
2688 ipv4_is_lbcast(fl4->saddr) || in ip_route_output_key_hash_rcu()
2689 ipv4_is_zeronet(fl4->saddr)) { in ip_route_output_key_hash_rcu()
2690 rth = ERR_PTR(-EINVAL); in ip_route_output_key_hash_rcu()
2694 rth = ERR_PTR(-ENETUNREACH); in ip_route_output_key_hash_rcu()
2696 /* I removed check for oif == dev_out->oif here. in ip_route_output_key_hash_rcu()
2701 * of another iface. --ANK in ip_route_output_key_hash_rcu()
2704 if (fl4->flowi4_oif == 0 && in ip_route_output_key_hash_rcu()
2705 (ipv4_is_multicast(fl4->daddr) || in ip_route_output_key_hash_rcu()
2706 ipv4_is_lbcast(fl4->daddr))) { in ip_route_output_key_hash_rcu()
2708 dev_out = __ip_dev_find(net, fl4->saddr, false); in ip_route_output_key_hash_rcu()
2727 fl4->flowi4_oif = dev_out->ifindex; in ip_route_output_key_hash_rcu()
2731 if (!(fl4->flowi4_flags & FLOWI_FLAG_ANYSRC)) { in ip_route_output_key_hash_rcu()
2733 if (!__ip_dev_find(net, fl4->saddr, false)) in ip_route_output_key_hash_rcu()
2739 if (fl4->flowi4_oif) { in ip_route_output_key_hash_rcu()
2740 dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif); in ip_route_output_key_hash_rcu()
2741 rth = ERR_PTR(-ENODEV); in ip_route_output_key_hash_rcu()
2746 if (!(dev_out->flags & IFF_UP) || !__in_dev_get_rcu(dev_out)) { in ip_route_output_key_hash_rcu()
2747 rth = ERR_PTR(-ENETUNREACH); in ip_route_output_key_hash_rcu()
2750 if (ipv4_is_local_multicast(fl4->daddr) || in ip_route_output_key_hash_rcu()
2751 ipv4_is_lbcast(fl4->daddr) || in ip_route_output_key_hash_rcu()
2752 fl4->flowi4_proto == IPPROTO_IGMP) { in ip_route_output_key_hash_rcu()
2753 if (!fl4->saddr) in ip_route_output_key_hash_rcu()
2754 fl4->saddr = inet_select_addr(dev_out, 0, in ip_route_output_key_hash_rcu()
2758 if (!fl4->saddr) { in ip_route_output_key_hash_rcu()
2759 if (ipv4_is_multicast(fl4->daddr)) in ip_route_output_key_hash_rcu()
2760 fl4->saddr = inet_select_addr(dev_out, 0, in ip_route_output_key_hash_rcu()
2761 fl4->flowi4_scope); in ip_route_output_key_hash_rcu()
2762 else if (!fl4->daddr) in ip_route_output_key_hash_rcu()
2763 fl4->saddr = inet_select_addr(dev_out, 0, in ip_route_output_key_hash_rcu()
2768 if (!fl4->daddr) { in ip_route_output_key_hash_rcu()
2769 fl4->daddr = fl4->saddr; in ip_route_output_key_hash_rcu()
2770 if (!fl4->daddr) in ip_route_output_key_hash_rcu()
2771 fl4->daddr = fl4->saddr = htonl(INADDR_LOOPBACK); in ip_route_output_key_hash_rcu()
2772 dev_out = net->loopback_dev; in ip_route_output_key_hash_rcu()
2773 fl4->flowi4_oif = LOOPBACK_IFINDEX; in ip_route_output_key_hash_rcu()
2774 res->type = RTN_LOCAL; in ip_route_output_key_hash_rcu()
2781 res->fi = NULL; in ip_route_output_key_hash_rcu()
2782 res->table = NULL; in ip_route_output_key_hash_rcu()
2783 if (fl4->flowi4_oif && in ip_route_output_key_hash_rcu()
2784 (ipv4_is_multicast(fl4->daddr) || !fl4->flowi4_l3mdev)) { in ip_route_output_key_hash_rcu()
2796 * and ifaddr state. --ANK in ip_route_output_key_hash_rcu()
2803 if (fl4->saddr == 0) in ip_route_output_key_hash_rcu()
2804 fl4->saddr = inet_select_addr(dev_out, 0, in ip_route_output_key_hash_rcu()
2806 res->type = RTN_UNICAST; in ip_route_output_key_hash_rcu()
2813 if (res->type == RTN_LOCAL) { in ip_route_output_key_hash_rcu()
2814 if (!fl4->saddr) { in ip_route_output_key_hash_rcu()
2815 if (res->fi->fib_prefsrc) in ip_route_output_key_hash_rcu()
2816 fl4->saddr = res->fi->fib_prefsrc; in ip_route_output_key_hash_rcu()
2818 fl4->saddr = fl4->daddr; in ip_route_output_key_hash_rcu()
2823 net->loopback_dev; in ip_route_output_key_hash_rcu()
2830 fl4->flowi4_oif = dev_out->ifindex; in ip_route_output_key_hash_rcu()
2864 struct dst_entry *new = &rt->dst; in ipv4_blackhole_route()
2866 new->__use = 1; in ipv4_blackhole_route()
2867 new->input = dst_discard; in ipv4_blackhole_route()
2868 new->output = dst_discard_out; in ipv4_blackhole_route()
2870 new->dev = net->loopback_dev; in ipv4_blackhole_route()
2871 netdev_hold(new->dev, &new->dev_tracker, GFP_ATOMIC); in ipv4_blackhole_route()
2873 rt->rt_is_input = ort->rt_is_input; in ipv4_blackhole_route()
2874 rt->rt_iif = ort->rt_iif; in ipv4_blackhole_route()
2875 rt->rt_pmtu = ort->rt_pmtu; in ipv4_blackhole_route()
2876 rt->rt_mtu_locked = ort->rt_mtu_locked; in ipv4_blackhole_route()
2878 rt->rt_genid = rt_genid_ipv4(net); in ipv4_blackhole_route()
2879 rt->rt_flags = ort->rt_flags; in ipv4_blackhole_route()
2880 rt->rt_type = ort->rt_type; in ipv4_blackhole_route()
2881 rt->rt_uses_gateway = ort->rt_uses_gateway; in ipv4_blackhole_route()
2882 rt->rt_gw_family = ort->rt_gw_family; in ipv4_blackhole_route()
2883 if (rt->rt_gw_family == AF_INET) in ipv4_blackhole_route()
2884 rt->rt_gw4 = ort->rt_gw4; in ipv4_blackhole_route()
2885 else if (rt->rt_gw_family == AF_INET6) in ipv4_blackhole_route()
2886 rt->rt_gw6 = ort->rt_gw6; in ipv4_blackhole_route()
2891 return rt ? &rt->dst : ERR_PTR(-ENOMEM); in ipv4_blackhole_route()
2902 if (flp4->flowi4_proto) { in ip_route_output_flow()
2903 flp4->flowi4_oif = rt->dst.dev->ifindex; in ip_route_output_flow()
2904 rt = (struct rtable *)xfrm_lookup_route(net, &rt->dst, in ip_route_output_flow()
2927 dst_cache = (struct dst_cache *)&info->dst_cache; in ip_route_output_tunnel()
2935 fl4.flowi4_mark = skb->mark; in ip_route_output_tunnel()
2937 fl4.daddr = info->key.u.ipv4.dst; in ip_route_output_tunnel()
2938 fl4.saddr = info->key.u.ipv4.src; in ip_route_output_tunnel()
2939 tos = info->key.tos; in ip_route_output_tunnel()
2945 return ERR_PTR(-ENETUNREACH); in ip_route_output_tunnel()
2947 if (rt->dst.dev == dev) { /* is this necessary? */ in ip_route_output_tunnel()
2950 return ERR_PTR(-ELOOP); in ip_route_output_tunnel()
2954 dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); in ip_route_output_tunnel()
2975 return -EMSGSIZE; in rt_fill_info()
2978 r->rtm_family = AF_INET; in rt_fill_info()
2979 r->rtm_dst_len = 32; in rt_fill_info()
2980 r->rtm_src_len = 0; in rt_fill_info()
2981 r->rtm_tos = inet_dscp_to_dsfield(dscp); in rt_fill_info()
2982 r->rtm_table = table_id < 256 ? table_id : RT_TABLE_COMPAT; in rt_fill_info()
2985 r->rtm_type = rt->rt_type; in rt_fill_info()
2986 r->rtm_scope = RT_SCOPE_UNIVERSE; in rt_fill_info()
2987 r->rtm_protocol = RTPROT_UNSPEC; in rt_fill_info()
2988 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED; in rt_fill_info()
2989 if (rt->rt_flags & RTCF_NOTIFY) in rt_fill_info()
2990 r->rtm_flags |= RTM_F_NOTIFY; in rt_fill_info()
2991 if (IPCB(skb)->flags & IPSKB_DOREDIRECT) in rt_fill_info()
2992 r->rtm_flags |= RTCF_DOREDIRECT; in rt_fill_info()
2997 r->rtm_src_len = 32; in rt_fill_info()
3001 if (rt->dst.dev && in rt_fill_info()
3002 nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex)) in rt_fill_info()
3004 if (rt->dst.lwtstate && in rt_fill_info()
3005 lwtunnel_fill_encap(skb, rt->dst.lwtstate, RTA_ENCAP, RTA_ENCAP_TYPE) < 0) in rt_fill_info()
3008 if (rt->dst.tclassid && in rt_fill_info()
3009 nla_put_u32(skb, RTA_FLOW, rt->dst.tclassid)) in rt_fill_info()
3013 fl4->saddr != src) { in rt_fill_info()
3014 if (nla_put_in_addr(skb, RTA_PREFSRC, fl4->saddr)) in rt_fill_info()
3017 if (rt->rt_uses_gateway) { in rt_fill_info()
3018 if (rt->rt_gw_family == AF_INET && in rt_fill_info()
3019 nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gw4)) { in rt_fill_info()
3021 } else if (rt->rt_gw_family == AF_INET6) { in rt_fill_info()
3031 via->rtvia_family = AF_INET6; in rt_fill_info()
3032 memcpy(via->rtvia_addr, &rt->rt_gw6, alen); in rt_fill_info()
3036 expires = rt->dst.expires; in rt_fill_info()
3041 expires -= now; in rt_fill_info()
3046 memcpy(metrics, dst_metrics_ptr(&rt->dst), sizeof(metrics)); in rt_fill_info()
3047 if (rt->rt_pmtu && expires) in rt_fill_info()
3048 metrics[RTAX_MTU - 1] = rt->rt_pmtu; in rt_fill_info()
3049 if (rt->rt_mtu_locked && expires) in rt_fill_info()
3050 metrics[RTAX_LOCK - 1] |= BIT(RTAX_MTU); in rt_fill_info()
3055 if (fl4->flowi4_mark && in rt_fill_info()
3056 nla_put_u32(skb, RTA_MARK, fl4->flowi4_mark)) in rt_fill_info()
3059 if (!uid_eq(fl4->flowi4_uid, INVALID_UID) && in rt_fill_info()
3062 fl4->flowi4_uid))) in rt_fill_info()
3071 fl4->saddr, fl4->daddr, in rt_fill_info()
3081 if (nla_put_u32(skb, RTA_IIF, fl4->flowi4_iif)) in rt_fill_info()
3086 error = rt->dst.error; in rt_fill_info()
3088 if (rtnl_put_cacheinfo(skb, &rt->dst, 0, expires, error) < 0) in rt_fill_info()
3096 return -EMSGSIZE; in rt_fill_info()
3110 fnhe = rcu_dereference(fnhe->fnhe_next)) { in fnhe_dump_bucket()
3117 if (fnhe->fnhe_genid != genid) in fnhe_dump_bucket()
3120 if (fnhe->fnhe_expires && in fnhe_dump_bucket()
3121 time_after(jiffies, fnhe->fnhe_expires)) in fnhe_dump_bucket()
3124 rt = rcu_dereference(fnhe->fnhe_rth_input); in fnhe_dump_bucket()
3126 rt = rcu_dereference(fnhe->fnhe_rth_output); in fnhe_dump_bucket()
3130 err = rt_fill_info(net, fnhe->fnhe_daddr, 0, rt, in fnhe_dump_bucket()
3132 NETLINK_CB(cb->skb).portid, in fnhe_dump_bucket()
3133 cb->nlh->nlmsg_seq, flags); in fnhe_dump_bucket()
3148 struct net *net = sock_net(cb->skb->sk); in fib_dump_info_fnhe()
3156 if (nhc->nhc_flags & RTNH_F_DEAD) in fib_dump_info_fnhe()
3160 bucket = rcu_dereference(nhc->nhc_exceptions); in fib_dump_info_fnhe()
3190 skb->protocol = htons(ETH_P_IP); in inet_rtm_getroute_build_skb()
3192 iph->protocol = ip_proto; in inet_rtm_getroute_build_skb()
3193 iph->saddr = src; in inet_rtm_getroute_build_skb()
3194 iph->daddr = dst; in inet_rtm_getroute_build_skb()
3195 iph->version = 0x4; in inet_rtm_getroute_build_skb()
3196 iph->frag_off = 0; in inet_rtm_getroute_build_skb()
3197 iph->ihl = 0x5; in inet_rtm_getroute_build_skb()
3198 skb_set_transport_header(skb, skb->len); in inet_rtm_getroute_build_skb()
3200 switch (iph->protocol) { in inet_rtm_getroute_build_skb()
3205 udph->source = sport; in inet_rtm_getroute_build_skb()
3206 udph->dest = dport; in inet_rtm_getroute_build_skb()
3207 udph->len = htons(sizeof(struct udphdr)); in inet_rtm_getroute_build_skb()
3208 udph->check = 0; in inet_rtm_getroute_build_skb()
3215 tcph->source = sport; in inet_rtm_getroute_build_skb()
3216 tcph->dest = dport; in inet_rtm_getroute_build_skb()
3217 tcph->doff = sizeof(struct tcphdr) / 4; in inet_rtm_getroute_build_skb()
3218 tcph->rst = 1; in inet_rtm_getroute_build_skb()
3219 tcph->check = ~tcp_v4_check(sizeof(struct tcphdr), in inet_rtm_getroute_build_skb()
3227 icmph->type = ICMP_ECHO; in inet_rtm_getroute_build_skb()
3228 icmph->code = 0; in inet_rtm_getroute_build_skb()
3240 struct rtmsg *rtm; in inet_rtm_valid_getroute_req() local
3243 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*rtm))) { in inet_rtm_valid_getroute_req()
3246 return -EINVAL; in inet_rtm_valid_getroute_req()
3250 return nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX, in inet_rtm_valid_getroute_req()
3253 rtm = nlmsg_data(nlh); in inet_rtm_valid_getroute_req()
3254 if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) || in inet_rtm_valid_getroute_req()
3255 (rtm->rtm_dst_len && rtm->rtm_dst_len != 32) || in inet_rtm_valid_getroute_req()
3256 rtm->rtm_table || rtm->rtm_protocol || in inet_rtm_valid_getroute_req()
3257 rtm->rtm_scope || rtm->rtm_type) { in inet_rtm_valid_getroute_req()
3259 return -EINVAL; in inet_rtm_valid_getroute_req()
3262 if (rtm->rtm_flags & ~(RTM_F_NOTIFY | in inet_rtm_valid_getroute_req()
3266 return -EINVAL; in inet_rtm_valid_getroute_req()
3269 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX, in inet_rtm_valid_getroute_req()
3274 if ((tb[RTA_SRC] && !rtm->rtm_src_len) || in inet_rtm_valid_getroute_req()
3275 (tb[RTA_DST] && !rtm->rtm_dst_len)) { in inet_rtm_valid_getroute_req()
3277 return -EINVAL; in inet_rtm_valid_getroute_req()
3297 return -EINVAL; in inet_rtm_valid_getroute_req()
3307 struct net *net = sock_net(in_skb->sk); in inet_rtm_getroute()
3315 struct rtmsg *rtm; in inet_rtm_getroute() local
3328 rtm = nlmsg_data(nlh); in inet_rtm_getroute()
3353 return -ENOBUFS; in inet_rtm_getroute()
3357 fl4.flowi4_tos = rtm->rtm_tos & IPTOS_RT_MASK; in inet_rtm_getroute()
3374 err = -ENODEV; in inet_rtm_getroute()
3379 skb->dev = dev; in inet_rtm_getroute()
3380 skb->mark = mark; in inet_rtm_getroute()
3382 rtm->rtm_tos & IPTOS_RT_MASK, dev, in inet_rtm_getroute()
3386 if (err == 0 && rt->dst.error) in inet_rtm_getroute()
3387 err = -rt->dst.error; in inet_rtm_getroute()
3390 skb->dev = net->loopback_dev; in inet_rtm_getroute()
3396 skb_dst_set(skb, &rt->dst); in inet_rtm_getroute()
3402 if (rtm->rtm_flags & RTM_F_NOTIFY) in inet_rtm_getroute()
3403 rt->rt_flags |= RTCF_NOTIFY; in inet_rtm_getroute()
3405 if (rtm->rtm_flags & RTM_F_LOOKUP_TABLE) in inet_rtm_getroute()
3406 table_id = res.table ? res.table->tb_id : 0; in inet_rtm_getroute()
3414 if (rtm->rtm_flags & RTM_F_FIB_MATCH) { in inet_rtm_getroute()
3420 err = -EHOSTUNREACH; in inet_rtm_getroute()
3428 fri.type = rt->rt_type; in inet_rtm_getroute()
3436 u8 slen = 32 - fri.dst_len; in inet_rtm_getroute()
3438 if (fa->fa_slen == slen && in inet_rtm_getroute()
3439 fa->tb_id == fri.tb_id && in inet_rtm_getroute()
3440 fa->fa_dscp == fri.dscp && in inet_rtm_getroute()
3441 fa->fa_info == res.fi && in inet_rtm_getroute()
3442 fa->fa_type == fri.type) { in inet_rtm_getroute()
3443 fri.offload = READ_ONCE(fa->offload); in inet_rtm_getroute()
3444 fri.trap = READ_ONCE(fa->trap); in inet_rtm_getroute()
3446 READ_ONCE(fa->offload_failed); in inet_rtm_getroute()
3452 nlh->nlmsg_seq, RTM_NEWROUTE, &fri, 0); in inet_rtm_getroute()
3456 nlh->nlmsg_seq, 0); in inet_rtm_getroute()
3475 rt_cache_flush(dev_net(in_dev->dev)); in ip_rt_multicast_event()
3487 struct net *net = (struct net *)__ctl->extra1; in ipv4_sysctl_rtcache_flush()
3495 return -EINVAL; in ipv4_sysctl_rtcache_flush()
3514 /* Deprecated. Use gc_min_interval_ms */
3635 /* Don't export non-whitelisted sysctls to unprivileged users */ in sysctl_route_net_init()
3636 if (net->user_ns != &init_user_ns) { in sysctl_route_net_init()
3646 for (i = 1; i < ARRAY_SIZE(ipv4_route_netns_table) - 1; i++) in sysctl_route_net_init()
3647 tbl[i].data += (void *)net - (void *)&init_net; in sysctl_route_net_init()
3651 net->ipv4.route_hdr = register_net_sysctl_sz(net, "net/ipv4/route", in sysctl_route_net_init()
3653 if (!net->ipv4.route_hdr) in sysctl_route_net_init()
3661 return -ENOMEM; in sysctl_route_net_init()
3668 tbl = net->ipv4.route_hdr->ctl_table_arg; in sysctl_route_net_exit()
3669 unregister_net_sysctl_table(net->ipv4.route_hdr); in sysctl_route_net_exit()
3683 net->ipv4.ip_rt_min_pmtu = DEFAULT_MIN_PMTU; in netns_ip_rt_init()
3684 net->ipv4.ip_rt_mtu_expires = DEFAULT_MTU_EXPIRES; in netns_ip_rt_init()
3685 net->ipv4.ip_rt_min_advmss = DEFAULT_MIN_ADVMSS; in netns_ip_rt_init()
3695 atomic_set(&net->ipv4.rt_genid, 0); in rt_genid_init()
3696 atomic_set(&net->fnhe_genid, 0); in rt_genid_init()
3697 atomic_set(&net->ipv4.dev_addr_genid, get_random_u32()); in rt_genid_init()
3710 return -ENOMEM; in ipv4_inetpeer_init()
3712 net->ipv4.peers = bp; in ipv4_inetpeer_init()
3718 struct inet_peer_base *bp = net->ipv4.peers; in ipv4_inetpeer_exit()
3720 net->ipv4.peers = NULL; in ipv4_inetpeer_exit()
3739 /* For modern hosts, this will use 2 MB of memory */ in ip_rt_init()
3759 INIT_LIST_HEAD(&ul->head); in ip_rt_init()
3760 INIT_LIST_HEAD(&ul->quarantine); in ip_rt_init()
3761 spin_lock_init(&ul->lock); in ip_rt_init()