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 <linux/config.h> 281da177e4SLinus Torvalds #include <net/dst.h> 291da177e4SLinus Torvalds #include <net/inetpeer.h> 301da177e4SLinus Torvalds #include <net/flow.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> 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #ifndef __KERNEL__ 381da177e4SLinus Torvalds #warning This file is not supposed to be used outside of kernel. 391da177e4SLinus Torvalds #endif 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds #define RTO_ONLINK 0x01 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #define RTO_CONN 0 441da177e4SLinus Torvalds /* RTO_CONN is not used (being alias for 0), but preserved not to break 451da177e4SLinus Torvalds * some modules referring to it. */ 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds #define RT_CONN_FLAGS(sk) (RT_TOS(inet_sk(sk)->tos) | sock_flag(sk, SOCK_LOCALROUTE)) 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds struct fib_nh; 501da177e4SLinus Torvalds struct inet_peer; 511da177e4SLinus Torvalds struct rtable 521da177e4SLinus Torvalds { 531da177e4SLinus Torvalds union 541da177e4SLinus Torvalds { 551da177e4SLinus Torvalds struct dst_entry dst; 561da177e4SLinus Torvalds struct rtable *rt_next; 571da177e4SLinus Torvalds } u; 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds struct in_device *idev; 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds unsigned rt_flags; 621da177e4SLinus Torvalds __u16 rt_type; 631da177e4SLinus Torvalds __u16 rt_multipath_alg; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds __u32 rt_dst; /* Path destination */ 661da177e4SLinus Torvalds __u32 rt_src; /* Path source */ 671da177e4SLinus Torvalds int rt_iif; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* Info on neighbour */ 701da177e4SLinus Torvalds __u32 rt_gateway; 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /* Cache lookup keys */ 731da177e4SLinus Torvalds struct flowi fl; 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds /* Miscellaneous cached information */ 761da177e4SLinus Torvalds __u32 rt_spec_dst; /* RFC1122 specific destination */ 771da177e4SLinus Torvalds struct inet_peer *peer; /* long-living peer info */ 781da177e4SLinus Torvalds }; 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds struct ip_rt_acct 811da177e4SLinus Torvalds { 821da177e4SLinus Torvalds __u32 o_bytes; 831da177e4SLinus Torvalds __u32 o_packets; 841da177e4SLinus Torvalds __u32 i_bytes; 851da177e4SLinus Torvalds __u32 i_packets; 861da177e4SLinus Torvalds }; 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds struct rt_cache_stat 891da177e4SLinus Torvalds { 901da177e4SLinus Torvalds unsigned int in_hit; 911da177e4SLinus Torvalds unsigned int in_slow_tot; 921da177e4SLinus Torvalds unsigned int in_slow_mc; 931da177e4SLinus Torvalds unsigned int in_no_route; 941da177e4SLinus Torvalds unsigned int in_brd; 951da177e4SLinus Torvalds unsigned int in_martian_dst; 961da177e4SLinus Torvalds unsigned int in_martian_src; 971da177e4SLinus Torvalds unsigned int out_hit; 981da177e4SLinus Torvalds unsigned int out_slow_tot; 991da177e4SLinus Torvalds unsigned int out_slow_mc; 1001da177e4SLinus Torvalds unsigned int gc_total; 1011da177e4SLinus Torvalds unsigned int gc_ignored; 1021da177e4SLinus Torvalds unsigned int gc_goal_miss; 1031da177e4SLinus Torvalds unsigned int gc_dst_overflow; 1041da177e4SLinus Torvalds unsigned int in_hlist_search; 1051da177e4SLinus Torvalds unsigned int out_hlist_search; 1061da177e4SLinus Torvalds }; 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds extern struct ip_rt_acct *ip_rt_acct; 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds struct in_device; 1111da177e4SLinus Torvalds extern int ip_rt_init(void); 1121da177e4SLinus Torvalds extern void ip_rt_redirect(u32 old_gw, u32 dst, u32 new_gw, 113cef2685eSIlia Sotnikov u32 src, struct net_device *dev); 1141da177e4SLinus Torvalds extern void ip_rt_advice(struct rtable **rp, int advice); 1151da177e4SLinus Torvalds extern void rt_cache_flush(int how); 1161da177e4SLinus Torvalds extern int __ip_route_output_key(struct rtable **, const struct flowi *flp); 1171da177e4SLinus Torvalds extern int ip_route_output_key(struct rtable **, struct flowi *flp); 1181da177e4SLinus Torvalds extern int ip_route_output_flow(struct rtable **rp, struct flowi *flp, struct sock *sk, int flags); 1191da177e4SLinus Torvalds extern int ip_route_input(struct sk_buff*, u32 dst, u32 src, u8 tos, struct net_device *devin); 1201da177e4SLinus Torvalds extern unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu); 1211da177e4SLinus Torvalds extern void ip_rt_send_redirect(struct sk_buff *skb); 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds extern unsigned inet_addr_type(u32 addr); 1241da177e4SLinus Torvalds extern void ip_rt_multicast_event(struct in_device *); 1251da177e4SLinus Torvalds extern int ip_rt_ioctl(unsigned int cmd, void __user *arg); 1261da177e4SLinus Torvalds extern void ip_rt_get_source(u8 *src, struct rtable *rt); 1271da177e4SLinus Torvalds extern int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb); 1281da177e4SLinus Torvalds 1290ff60a45SJamal Hadi Salim struct in_ifaddr; 1300ff60a45SJamal Hadi Salim extern void fib_add_ifaddr(struct in_ifaddr *); 1310ff60a45SJamal Hadi Salim 1321da177e4SLinus Torvalds static inline void ip_rt_put(struct rtable * rt) 1331da177e4SLinus Torvalds { 1341da177e4SLinus Torvalds if (rt) 1351da177e4SLinus Torvalds dst_release(&rt->u.dst); 1361da177e4SLinus Torvalds } 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3) 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds extern __u8 ip_tos2prio[16]; 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds static inline char rt_tos2priority(u8 tos) 1431da177e4SLinus Torvalds { 1441da177e4SLinus Torvalds return ip_tos2prio[IPTOS_TOS(tos)>>1]; 1451da177e4SLinus Torvalds } 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds static inline int ip_route_connect(struct rtable **rp, u32 dst, 1481da177e4SLinus Torvalds u32 src, u32 tos, int oif, u8 protocol, 1491da177e4SLinus Torvalds u16 sport, u16 dport, struct sock *sk) 1501da177e4SLinus Torvalds { 1511da177e4SLinus Torvalds struct flowi fl = { .oif = oif, 1521da177e4SLinus Torvalds .nl_u = { .ip4_u = { .daddr = dst, 1531da177e4SLinus Torvalds .saddr = src, 1541da177e4SLinus Torvalds .tos = tos } }, 1551da177e4SLinus Torvalds .proto = protocol, 1561da177e4SLinus Torvalds .uli_u = { .ports = 1571da177e4SLinus Torvalds { .sport = sport, 1581da177e4SLinus Torvalds .dport = dport } } }; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds int err; 1611da177e4SLinus Torvalds if (!dst || !src) { 1621da177e4SLinus Torvalds err = __ip_route_output_key(rp, &fl); 1631da177e4SLinus Torvalds if (err) 1641da177e4SLinus Torvalds return err; 1651da177e4SLinus Torvalds fl.fl4_dst = (*rp)->rt_dst; 1661da177e4SLinus Torvalds fl.fl4_src = (*rp)->rt_src; 1671da177e4SLinus Torvalds ip_rt_put(*rp); 1681da177e4SLinus Torvalds *rp = NULL; 1691da177e4SLinus Torvalds } 1701da177e4SLinus Torvalds return ip_route_output_flow(rp, &fl, sk, 0); 1711da177e4SLinus Torvalds } 1721da177e4SLinus Torvalds 1735d39a795SPatrick McHardy static inline int ip_route_newports(struct rtable **rp, u8 protocol, 1745d39a795SPatrick McHardy u16 sport, u16 dport, struct sock *sk) 1751da177e4SLinus Torvalds { 1761da177e4SLinus Torvalds if (sport != (*rp)->fl.fl_ip_sport || 1771da177e4SLinus Torvalds dport != (*rp)->fl.fl_ip_dport) { 1781da177e4SLinus Torvalds struct flowi fl; 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds memcpy(&fl, &(*rp)->fl, sizeof(fl)); 1811da177e4SLinus Torvalds fl.fl_ip_sport = sport; 1821da177e4SLinus Torvalds fl.fl_ip_dport = dport; 1835d39a795SPatrick McHardy fl.proto = protocol; 1841da177e4SLinus Torvalds ip_rt_put(*rp); 1851da177e4SLinus Torvalds *rp = NULL; 1861da177e4SLinus Torvalds return ip_route_output_flow(rp, &fl, sk, 0); 1871da177e4SLinus Torvalds } 1881da177e4SLinus Torvalds return 0; 1891da177e4SLinus Torvalds } 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds extern void rt_bind_peer(struct rtable *rt, int create); 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds static inline struct inet_peer *rt_get_peer(struct rtable *rt) 1941da177e4SLinus Torvalds { 1951da177e4SLinus Torvalds if (rt->peer) 1961da177e4SLinus Torvalds return rt->peer; 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds rt_bind_peer(rt, 0); 1991da177e4SLinus Torvalds return rt->peer; 2001da177e4SLinus Torvalds } 2011da177e4SLinus Torvalds 20220380731SArnaldo Carvalho de Melo extern ctl_table ipv4_route_table[]; 20320380731SArnaldo Carvalho de Melo 2041da177e4SLinus Torvalds #endif /* _ROUTE_H */ 205