11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * INET An implementation of the TCP/IP protocol suite for the LINUX 31da177e4SLinus Torvalds * operating system. INET is implemented using the BSD Socket 41da177e4SLinus Torvalds * interface as the means of communication with the user level. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Definitions for the IP router. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Version: @(#)route.h 1.0.4 05/27/93 91da177e4SLinus Torvalds * 1002c30a84SJesper Juhl * Authors: Ross Biro 111da177e4SLinus Torvalds * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 121da177e4SLinus Torvalds * Fixes: 131da177e4SLinus Torvalds * Alan Cox : Reformatted. Added ip_rt_local() 141da177e4SLinus Torvalds * Alan Cox : Support for TCP parameters. 151da177e4SLinus Torvalds * Alexey Kuznetsov: Major changes for new routing code. 161da177e4SLinus Torvalds * Mike McLagan : Routing by source 171da177e4SLinus Torvalds * Robert Olsson : Added rt_cache statistics 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 201da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 211da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 221da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds #ifndef _ROUTE_H 251da177e4SLinus Torvalds #define _ROUTE_H 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #include <net/dst.h> 281da177e4SLinus Torvalds #include <net/inetpeer.h> 291da177e4SLinus Torvalds #include <net/flow.h> 3079876874SKOVACS Krisztian #include <net/inet_sock.h> 311da177e4SLinus Torvalds #include <linux/in_route.h> 321da177e4SLinus Torvalds #include <linux/rtnetlink.h> 331da177e4SLinus Torvalds #include <linux/route.h> 341da177e4SLinus Torvalds #include <linux/ip.h> 351da177e4SLinus Torvalds #include <linux/cache.h> 36beb8d13bSVenkat Yekkirala #include <linux/security.h> 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #define RTO_ONLINK 0x01 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds #define RT_CONN_FLAGS(sk) (RT_TOS(inet_sk(sk)->tos) | sock_flag(sk, SOCK_LOCALROUTE)) 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds struct fib_nh; 431da177e4SLinus Torvalds struct inet_peer; 4462fa8a84SDavid S. Miller struct fib_info; 45fd2c3ef7SEric Dumazet struct rtable { 461da177e4SLinus Torvalds struct dst_entry dst; 471da177e4SLinus Torvalds 485e2b61f7SDavid S. Miller /* Lookup key. */ 495e2b61f7SDavid S. Miller __be32 rt_key_dst; 505e2b61f7SDavid S. Miller __be32 rt_key_src; 51093c2ca4SEric Dumazet 5229e75252SEric Dumazet int rt_genid; 5395c96174SEric Dumazet unsigned int rt_flags; 541da177e4SLinus Torvalds __u16 rt_type; 55475949d8SDavid S. Miller __u8 rt_key_tos; 561da177e4SLinus Torvalds 57f2c3fe24SAl Viro __be32 rt_dst; /* Path destination */ 58f2c3fe24SAl Viro __be32 rt_src; /* Path source */ 591b86a58fSOGAWA Hirofumi int rt_route_iif; 601da177e4SLinus Torvalds int rt_iif; 615e2b61f7SDavid S. Miller int rt_oif; 625e2b61f7SDavid S. Miller __u32 rt_mark; 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds /* Info on neighbour */ 65f2c3fe24SAl Viro __be32 rt_gateway; 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* Miscellaneous cached information */ 68f2c3fe24SAl Viro __be32 rt_spec_dst; /* RFC1122 specific destination */ 696431cbc2SDavid S. Miller u32 rt_peer_genid; 7097bab73fSDavid S. Miller unsigned long _peer; /* long-living peer info */ 7162fa8a84SDavid S. Miller struct fib_info *fi; /* for client ref to shared metrics */ 721da177e4SLinus Torvalds }; 731da177e4SLinus Torvalds 7497bab73fSDavid S. Miller static inline struct inet_peer *rt_peer_ptr(struct rtable *rt) 7597bab73fSDavid S. Miller { 7697bab73fSDavid S. Miller return inetpeer_ptr(rt->_peer); 7797bab73fSDavid S. Miller } 7897bab73fSDavid S. Miller 7997bab73fSDavid S. Miller static inline bool rt_has_peer(struct rtable *rt) 8097bab73fSDavid S. Miller { 8197bab73fSDavid S. Miller return inetpeer_ptr_is_peer(rt->_peer); 8297bab73fSDavid S. Miller } 8397bab73fSDavid S. Miller 8497bab73fSDavid S. Miller static inline void __rt_set_peer(struct rtable *rt, struct inet_peer *peer) 8597bab73fSDavid S. Miller { 8697bab73fSDavid S. Miller __inetpeer_ptr_set_peer(&rt->_peer, peer); 8797bab73fSDavid S. Miller } 8897bab73fSDavid S. Miller 8997bab73fSDavid S. Miller static inline bool rt_set_peer(struct rtable *rt, struct inet_peer *peer) 9097bab73fSDavid S. Miller { 9197bab73fSDavid S. Miller return inetpeer_ptr_set_peer(&rt->_peer, peer); 9297bab73fSDavid S. Miller } 9397bab73fSDavid S. Miller 9497bab73fSDavid S. Miller static inline void rt_init_peer(struct rtable *rt, struct inet_peer_base *base) 9597bab73fSDavid S. Miller { 9697bab73fSDavid S. Miller inetpeer_init_ptr(&rt->_peer, base); 9797bab73fSDavid S. Miller } 9897bab73fSDavid S. Miller 9997bab73fSDavid S. Miller static inline void rt_transfer_peer(struct rtable *rt, struct rtable *ort) 10097bab73fSDavid S. Miller { 10197bab73fSDavid S. Miller rt->_peer = ort->_peer; 10297bab73fSDavid S. Miller if (rt_has_peer(ort)) { 10397bab73fSDavid S. Miller struct inet_peer *peer = rt_peer_ptr(ort); 10497bab73fSDavid S. Miller atomic_inc(&peer->refcnt); 10597bab73fSDavid S. Miller } 10697bab73fSDavid S. Miller } 10797bab73fSDavid S. Miller 108b8400f37SSteffen Klassert static inline bool rt_is_input_route(const struct rtable *rt) 109c7537967SDavid S. Miller { 1101b86a58fSOGAWA Hirofumi return rt->rt_route_iif != 0; 111c7537967SDavid S. Miller } 112c7537967SDavid S. Miller 113b8400f37SSteffen Klassert static inline bool rt_is_output_route(const struct rtable *rt) 114c7537967SDavid S. Miller { 1151b86a58fSOGAWA Hirofumi return rt->rt_route_iif == 0; 116c7537967SDavid S. Miller } 117c7537967SDavid S. Miller 118fd2c3ef7SEric Dumazet struct ip_rt_acct { 1191da177e4SLinus Torvalds __u32 o_bytes; 1201da177e4SLinus Torvalds __u32 o_packets; 1211da177e4SLinus Torvalds __u32 i_bytes; 1221da177e4SLinus Torvalds __u32 i_packets; 1231da177e4SLinus Torvalds }; 1241da177e4SLinus Torvalds 125fd2c3ef7SEric Dumazet struct rt_cache_stat { 1261da177e4SLinus Torvalds unsigned int in_hit; 1271da177e4SLinus Torvalds unsigned int in_slow_tot; 1281da177e4SLinus Torvalds unsigned int in_slow_mc; 1291da177e4SLinus Torvalds unsigned int in_no_route; 1301da177e4SLinus Torvalds unsigned int in_brd; 1311da177e4SLinus Torvalds unsigned int in_martian_dst; 1321da177e4SLinus Torvalds unsigned int in_martian_src; 1331da177e4SLinus Torvalds unsigned int out_hit; 1341da177e4SLinus Torvalds unsigned int out_slow_tot; 1351da177e4SLinus Torvalds unsigned int out_slow_mc; 1361da177e4SLinus Torvalds unsigned int gc_total; 1371da177e4SLinus Torvalds unsigned int gc_ignored; 1381da177e4SLinus Torvalds unsigned int gc_goal_miss; 1391da177e4SLinus Torvalds unsigned int gc_dst_overflow; 1401da177e4SLinus Torvalds unsigned int in_hlist_search; 1411da177e4SLinus Torvalds unsigned int out_hlist_search; 1421da177e4SLinus Torvalds }; 1431da177e4SLinus Torvalds 1447d720c3eSTejun Heo extern struct ip_rt_acct __percpu *ip_rt_acct; 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds struct in_device; 1471da177e4SLinus Torvalds extern int ip_rt_init(void); 148f7655229SAl Viro extern void ip_rt_redirect(__be32 old_gw, __be32 dst, __be32 new_gw, 149f7655229SAl Viro __be32 src, struct net_device *dev); 15076e6ebfbSDenis V. Lunev extern void rt_cache_flush(struct net *net, int how); 1516561a3b1SDavid S. Miller extern void rt_cache_flush_batch(struct net *net); 152813b3b5dSDavid S. Miller extern struct rtable *__ip_route_output_key(struct net *, struct flowi4 *flp); 1539d6ec938SDavid S. Miller extern struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp, 154b23dd4feSDavid S. Miller struct sock *sk); 1552774c131SDavid S. Miller extern struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig); 156407eadd9SEric Dumazet 1579d6ec938SDavid S. Miller static inline struct rtable *ip_route_output_key(struct net *net, struct flowi4 *flp) 1585bfa787fSDavid S. Miller { 1595bfa787fSDavid S. Miller return ip_route_output_flow(net, flp, NULL); 1605bfa787fSDavid S. Miller } 1615bfa787fSDavid S. Miller 16278fbfd8aSDavid S. Miller static inline struct rtable *ip_route_output(struct net *net, __be32 daddr, 16378fbfd8aSDavid S. Miller __be32 saddr, u8 tos, int oif) 16478fbfd8aSDavid S. Miller { 1659d6ec938SDavid S. Miller struct flowi4 fl4 = { 1669d6ec938SDavid S. Miller .flowi4_oif = oif, 167c5d21c4bSRoland Dreier .flowi4_tos = tos, 1689d6ec938SDavid S. Miller .daddr = daddr, 1699d6ec938SDavid S. Miller .saddr = saddr, 17078fbfd8aSDavid S. Miller }; 1719d6ec938SDavid S. Miller return ip_route_output_key(net, &fl4); 17278fbfd8aSDavid S. Miller } 17378fbfd8aSDavid S. Miller 17431e4543dSDavid S. Miller static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi4 *fl4, 17531e4543dSDavid S. Miller struct sock *sk, 17678fbfd8aSDavid S. Miller __be32 daddr, __be32 saddr, 17778fbfd8aSDavid S. Miller __be16 dport, __be16 sport, 17878fbfd8aSDavid S. Miller __u8 proto, __u8 tos, int oif) 17978fbfd8aSDavid S. Miller { 18031e4543dSDavid S. Miller flowi4_init_output(fl4, oif, sk ? sk->sk_mark : 0, tos, 18194b92b88SDavid S. Miller RT_SCOPE_UNIVERSE, proto, 18294b92b88SDavid S. Miller sk ? inet_sk_flowi_flags(sk) : 0, 18394b92b88SDavid S. Miller daddr, saddr, dport, sport); 18478fbfd8aSDavid S. Miller if (sk) 18531e4543dSDavid S. Miller security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); 18631e4543dSDavid S. Miller return ip_route_output_flow(net, fl4, sk); 18778fbfd8aSDavid S. Miller } 18878fbfd8aSDavid S. Miller 189cbb1e85fSDavid S. Miller static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4 *fl4, 19078fbfd8aSDavid S. Miller __be32 daddr, __be32 saddr, 19178fbfd8aSDavid S. Miller __be32 gre_key, __u8 tos, int oif) 19278fbfd8aSDavid S. Miller { 193cbb1e85fSDavid S. Miller memset(fl4, 0, sizeof(*fl4)); 194cbb1e85fSDavid S. Miller fl4->flowi4_oif = oif; 195cbb1e85fSDavid S. Miller fl4->daddr = daddr; 196cbb1e85fSDavid S. Miller fl4->saddr = saddr; 197cbb1e85fSDavid S. Miller fl4->flowi4_tos = tos; 198cbb1e85fSDavid S. Miller fl4->flowi4_proto = IPPROTO_GRE; 199cbb1e85fSDavid S. Miller fl4->fl4_gre_key = gre_key; 200cbb1e85fSDavid S. Miller return ip_route_output_key(net, fl4); 20178fbfd8aSDavid S. Miller } 20278fbfd8aSDavid S. Miller 203407eadd9SEric Dumazet extern int ip_route_input_common(struct sk_buff *skb, __be32 dst, __be32 src, 204c10237e0SDavid S. Miller u8 tos, struct net_device *devin, bool noref); 205407eadd9SEric Dumazet 206407eadd9SEric Dumazet static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, 207407eadd9SEric Dumazet u8 tos, struct net_device *devin) 208407eadd9SEric Dumazet { 209c10237e0SDavid S. Miller return ip_route_input_common(skb, dst, src, tos, devin, false); 210407eadd9SEric Dumazet } 211407eadd9SEric Dumazet 212407eadd9SEric Dumazet static inline int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 src, 213c10237e0SDavid S. Miller u8 tos, struct net_device *devin) 214407eadd9SEric Dumazet { 215c10237e0SDavid S. Miller return ip_route_input_common(skb, dst, src, tos, devin, true); 216407eadd9SEric Dumazet } 217407eadd9SEric Dumazet 21836393395SDavid S. Miller extern void ipv4_update_pmtu(struct sk_buff *skb, struct net *net, u32 mtu, 21936393395SDavid S. Miller int oif, u32 mark, u8 protocol, int flow_flags); 22036393395SDavid S. Miller extern void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu); 2211da177e4SLinus Torvalds extern void ip_rt_send_redirect(struct sk_buff *skb); 2221da177e4SLinus Torvalds 22395c96174SEric Dumazet extern unsigned int inet_addr_type(struct net *net, __be32 addr); 22495c96174SEric Dumazet extern unsigned int inet_dev_addr_type(struct net *net, const struct net_device *dev, __be32 addr); 2251da177e4SLinus Torvalds extern void ip_rt_multicast_event(struct in_device *); 2261bad118aSDenis V. Lunev extern int ip_rt_ioctl(struct net *, unsigned int cmd, void __user *arg); 2278e36360aSDavid S. Miller extern void ip_rt_get_source(u8 *src, struct sk_buff *skb, struct rtable *rt); 2281da177e4SLinus Torvalds extern int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb); 2291da177e4SLinus Torvalds 2300ff60a45SJamal Hadi Salim struct in_ifaddr; 2310ff60a45SJamal Hadi Salim extern void fib_add_ifaddr(struct in_ifaddr *); 232e6abbaa2SJulian Anastasov extern void fib_del_ifaddr(struct in_ifaddr *, struct in_ifaddr *); 2330ff60a45SJamal Hadi Salim 2341da177e4SLinus Torvalds static inline void ip_rt_put(struct rtable * rt) 2351da177e4SLinus Torvalds { 2361da177e4SLinus Torvalds if (rt) 237d8d1f30bSChangli Gao dst_release(&rt->dst); 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3) 2411da177e4SLinus Torvalds 2424839c52bSPhilippe De Muyter extern const __u8 ip_tos2prio[16]; 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds static inline char rt_tos2priority(u8 tos) 2451da177e4SLinus Torvalds { 2461da177e4SLinus Torvalds return ip_tos2prio[IPTOS_TOS(tos)>>1]; 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds 2492d7192d6SDavid S. Miller /* ip_route_connect() and ip_route_newports() work in tandem whilst 2502d7192d6SDavid S. Miller * binding a socket for a new outgoing connection. 2512d7192d6SDavid S. Miller * 2522d7192d6SDavid S. Miller * In order to use IPSEC properly, we must, in the end, have a 2532d7192d6SDavid S. Miller * route that was looked up using all available keys including source 2542d7192d6SDavid S. Miller * and destination ports. 2552d7192d6SDavid S. Miller * 2562d7192d6SDavid S. Miller * However, if a source port needs to be allocated (the user specified 2572d7192d6SDavid S. Miller * a wildcard source port) we need to obtain addressing information 2582d7192d6SDavid S. Miller * in order to perform that allocation. 2592d7192d6SDavid S. Miller * 2602d7192d6SDavid S. Miller * So ip_route_connect() looks up a route using wildcarded source and 2612d7192d6SDavid S. Miller * destination ports in the key, simply so that we can get a pair of 2622d7192d6SDavid S. Miller * addresses to use for port allocation. 2632d7192d6SDavid S. Miller * 2642d7192d6SDavid S. Miller * Later, once the ports are allocated, ip_route_newports() will make 2652d7192d6SDavid S. Miller * another route lookup if needed to make sure we catch any IPSEC 2662d7192d6SDavid S. Miller * rules keyed on the port information. 2672d7192d6SDavid S. Miller * 2682d7192d6SDavid S. Miller * The callers allocate the flow key on their stack, and must pass in 2692d7192d6SDavid S. Miller * the same flowi4 object to both the ip_route_connect() and the 2702d7192d6SDavid S. Miller * ip_route_newports() calls. 2712d7192d6SDavid S. Miller */ 2722d7192d6SDavid S. Miller 2732d7192d6SDavid S. Miller static inline void ip_route_connect_init(struct flowi4 *fl4, __be32 dst, __be32 src, 2742d7192d6SDavid S. Miller u32 tos, int oif, u8 protocol, 275b23dd4feSDavid S. Miller __be16 sport, __be16 dport, 276b23dd4feSDavid S. Miller struct sock *sk, bool can_sleep) 2771da177e4SLinus Torvalds { 2782d7192d6SDavid S. Miller __u8 flow_flags = 0; 27979876874SKOVACS Krisztian 28079876874SKOVACS Krisztian if (inet_sk(sk)->transparent) 28194b92b88SDavid S. Miller flow_flags |= FLOWI_FLAG_ANYSRC; 282a4daad6bSDavid S. Miller if (protocol == IPPROTO_TCP) 28394b92b88SDavid S. Miller flow_flags |= FLOWI_FLAG_PRECOW_METRICS; 2845df65e55SDavid S. Miller if (can_sleep) 28594b92b88SDavid S. Miller flow_flags |= FLOWI_FLAG_CAN_SLEEP; 28694b92b88SDavid S. Miller 2872d7192d6SDavid S. Miller flowi4_init_output(fl4, oif, sk->sk_mark, tos, RT_SCOPE_UNIVERSE, 28894b92b88SDavid S. Miller protocol, flow_flags, dst, src, dport, sport); 2892d7192d6SDavid S. Miller } 2902d7192d6SDavid S. Miller 2912d7192d6SDavid S. Miller static inline struct rtable *ip_route_connect(struct flowi4 *fl4, 2922d7192d6SDavid S. Miller __be32 dst, __be32 src, u32 tos, 2932d7192d6SDavid S. Miller int oif, u8 protocol, 2942d7192d6SDavid S. Miller __be16 sport, __be16 dport, 2952d7192d6SDavid S. Miller struct sock *sk, bool can_sleep) 2962d7192d6SDavid S. Miller { 2972d7192d6SDavid S. Miller struct net *net = sock_net(sk); 2982d7192d6SDavid S. Miller struct rtable *rt; 2992d7192d6SDavid S. Miller 3002d7192d6SDavid S. Miller ip_route_connect_init(fl4, dst, src, tos, oif, protocol, 3012d7192d6SDavid S. Miller sport, dport, sk, can_sleep); 30279876874SKOVACS Krisztian 3031da177e4SLinus Torvalds if (!dst || !src) { 3042d7192d6SDavid S. Miller rt = __ip_route_output_key(net, fl4); 305b23dd4feSDavid S. Miller if (IS_ERR(rt)) 306b23dd4feSDavid S. Miller return rt; 307b23dd4feSDavid S. Miller ip_rt_put(rt); 308e6b45241SJulian Anastasov flowi4_update_output(fl4, oif, tos, fl4->daddr, fl4->saddr); 3091da177e4SLinus Torvalds } 3102d7192d6SDavid S. Miller security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); 3112d7192d6SDavid S. Miller return ip_route_output_flow(net, fl4, sk); 3121da177e4SLinus Torvalds } 3131da177e4SLinus Torvalds 3142d7192d6SDavid S. Miller static inline struct rtable *ip_route_newports(struct flowi4 *fl4, struct rtable *rt, 3152d7192d6SDavid S. Miller __be16 orig_sport, __be16 orig_dport, 3162d7192d6SDavid S. Miller __be16 sport, __be16 dport, 3172d7192d6SDavid S. Miller struct sock *sk) 3181da177e4SLinus Torvalds { 319dca8b089SDavid S. Miller if (sport != orig_sport || dport != orig_dport) { 3202d7192d6SDavid S. Miller fl4->fl4_dport = dport; 3212d7192d6SDavid S. Miller fl4->fl4_sport = sport; 322b23dd4feSDavid S. Miller ip_rt_put(rt); 323e6b45241SJulian Anastasov flowi4_update_output(fl4, sk->sk_bound_dev_if, 324e6b45241SJulian Anastasov RT_CONN_FLAGS(sk), fl4->daddr, 325e6b45241SJulian Anastasov fl4->saddr); 3262d7192d6SDavid S. Miller security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); 3272d7192d6SDavid S. Miller return ip_route_output_flow(sock_net(sk), fl4, sk); 3281da177e4SLinus Torvalds } 329b23dd4feSDavid S. Miller return rt; 3301da177e4SLinus Torvalds } 3311da177e4SLinus Torvalds 332a48eff12SDavid S. Miller extern void rt_bind_peer(struct rtable *rt, __be32 daddr, int create); 3331da177e4SLinus Torvalds 334fbfe95a4SDavid S. Miller static inline struct inet_peer *__rt_get_peer(struct rtable *rt, __be32 daddr, int create) 3351da177e4SLinus Torvalds { 33697bab73fSDavid S. Miller if (rt_has_peer(rt)) 33797bab73fSDavid S. Miller return rt_peer_ptr(rt); 3381da177e4SLinus Torvalds 339fbfe95a4SDavid S. Miller rt_bind_peer(rt, daddr, create); 34055afabaaSDavid S. Miller return (rt_has_peer(rt) ? rt_peer_ptr(rt) : NULL); 3411da177e4SLinus Torvalds } 3421da177e4SLinus Torvalds 343fbfe95a4SDavid S. Miller static inline struct inet_peer *rt_get_peer(struct rtable *rt, __be32 daddr) 344fbfe95a4SDavid S. Miller { 345fbfe95a4SDavid S. Miller return __rt_get_peer(rt, daddr, 0); 346fbfe95a4SDavid S. Miller } 347fbfe95a4SDavid S. Miller 348fbfe95a4SDavid S. Miller static inline struct inet_peer *rt_get_peer_create(struct rtable *rt, __be32 daddr) 349fbfe95a4SDavid S. Miller { 350fbfe95a4SDavid S. Miller return __rt_get_peer(rt, daddr, 1); 351fbfe95a4SDavid S. Miller } 352fbfe95a4SDavid S. Miller 3531668e010SKOVACS Krisztian static inline int inet_iif(const struct sk_buff *skb) 3541668e010SKOVACS Krisztian { 355511c3f92SEric Dumazet return skb_rtable(skb)->rt_iif; 3561668e010SKOVACS Krisztian } 3571668e010SKOVACS Krisztian 358323e126fSDavid S. Miller extern int sysctl_ip_default_ttl; 359323e126fSDavid S. Miller 360323e126fSDavid S. Miller static inline int ip4_dst_hoplimit(const struct dst_entry *dst) 361323e126fSDavid S. Miller { 362323e126fSDavid S. Miller int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT); 363323e126fSDavid S. Miller 364323e126fSDavid S. Miller if (hoplimit == 0) 365323e126fSDavid S. Miller hoplimit = sysctl_ip_default_ttl; 366323e126fSDavid S. Miller return hoplimit; 367323e126fSDavid S. Miller } 368323e126fSDavid S. Miller 3691da177e4SLinus Torvalds #endif /* _ROUTE_H */ 370