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 Forwarding Information Base. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Authors: A.N.Kuznetsov, <[email protected]> 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 111da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 121da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 131da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 141da177e4SLinus Torvalds */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #ifndef _NET_IP_FIB_H 171da177e4SLinus Torvalds #define _NET_IP_FIB_H 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #include <net/flow.h> 201da177e4SLinus Torvalds #include <linux/seq_file.h> 214895c771SDavid S. Miller #include <linux/rcupdate.h> 22e1ef4bf2SThomas Graf #include <net/fib_rules.h> 238e773277SDavid S. Miller #include <net/inetpeer.h> 24d26b3a7cSEric Dumazet #include <linux/percpu.h> 25b90eb754SJiri Pirko #include <linux/notifier.h> 26*0029c0deSReshetova, Elena #include <linux/refcount.h> 271da177e4SLinus Torvalds 284e902c57SThomas Graf struct fib_config { 294e902c57SThomas Graf u8 fc_dst_len; 304e902c57SThomas Graf u8 fc_tos; 314e902c57SThomas Graf u8 fc_protocol; 324e902c57SThomas Graf u8 fc_scope; 334e902c57SThomas Graf u8 fc_type; 34b52f070cSThomas Graf /* 3 bytes unused */ 354e902c57SThomas Graf u32 fc_table; 366d85c10aSAl Viro __be32 fc_dst; 376d85c10aSAl Viro __be32 fc_gw; 384e902c57SThomas Graf int fc_oif; 394e902c57SThomas Graf u32 fc_flags; 404e902c57SThomas Graf u32 fc_priority; 416d85c10aSAl Viro __be32 fc_prefsrc; 424e902c57SThomas Graf struct nlattr *fc_mx; 434e902c57SThomas Graf struct rtnexthop *fc_mp; 444e902c57SThomas Graf int fc_mx_len; 454e902c57SThomas Graf int fc_mp_len; 464e902c57SThomas Graf u32 fc_flow; 474e902c57SThomas Graf u32 fc_nlflags; 484e902c57SThomas Graf struct nl_info fc_nlinfo; 49571e7226SRoopa Prabhu struct nlattr *fc_encap; 50571e7226SRoopa Prabhu u16 fc_encap_type; 511da177e4SLinus Torvalds }; 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds struct fib_info; 54f2bb4bedSDavid S. Miller struct rtable; 551da177e4SLinus Torvalds 564895c771SDavid S. Miller struct fib_nh_exception { 574895c771SDavid S. Miller struct fib_nh_exception __rcu *fnhe_next; 585aad1de5STimo Teräs int fnhe_genid; 594895c771SDavid S. Miller __be32 fnhe_daddr; 604895c771SDavid S. Miller u32 fnhe_pmtu; 61aee06da6SJulian Anastasov __be32 fnhe_gw; 624895c771SDavid S. Miller unsigned long fnhe_expires; 632ffae99dSTimo Teräs struct rtable __rcu *fnhe_rth_input; 642ffae99dSTimo Teräs struct rtable __rcu *fnhe_rth_output; 654895c771SDavid S. Miller unsigned long fnhe_stamp; 66deed49dfSXin Long struct rcu_head rcu; 674895c771SDavid S. Miller }; 684895c771SDavid S. Miller 694895c771SDavid S. Miller struct fnhe_hash_bucket { 704895c771SDavid S. Miller struct fib_nh_exception __rcu *chain; 714895c771SDavid S. Miller }; 724895c771SDavid S. Miller 73d546c621SEric Dumazet #define FNHE_HASH_SHIFT 11 74d546c621SEric Dumazet #define FNHE_HASH_SIZE (1 << FNHE_HASH_SHIFT) 754895c771SDavid S. Miller #define FNHE_RECLAIM_DEPTH 5 764895c771SDavid S. Miller 771da177e4SLinus Torvalds struct fib_nh { 781da177e4SLinus Torvalds struct net_device *nh_dev; 791da177e4SLinus Torvalds struct hlist_node nh_hash; 801da177e4SLinus Torvalds struct fib_info *nh_parent; 8195c96174SEric Dumazet unsigned int nh_flags; 821da177e4SLinus Torvalds unsigned char nh_scope; 831da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH 841da177e4SLinus Torvalds int nh_weight; 850e884c78SPeter Nørlund atomic_t nh_upper_bound; 861da177e4SLinus Torvalds #endif 87c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID 881da177e4SLinus Torvalds __u32 nh_tclassid; 891da177e4SLinus Torvalds #endif 901da177e4SLinus Torvalds int nh_oif; 91ed49e3caSAl Viro __be32 nh_gw; 921fc050a1SDavid S. Miller __be32 nh_saddr; 93436c3b66SDavid S. Miller int nh_saddr_genid; 94d26b3a7cSEric Dumazet struct rtable __rcu * __percpu *nh_pcpu_rth_output; 9554764bb6SEric Dumazet struct rtable __rcu *nh_rth_input; 96caa41527SEric Dumazet struct fnhe_hash_bucket __rcu *nh_exceptions; 97571e7226SRoopa Prabhu struct lwtunnel_state *nh_lwtstate; 981da177e4SLinus Torvalds }; 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds /* 1011da177e4SLinus Torvalds * This structure contains data shared by many of routes. 1021da177e4SLinus Torvalds */ 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds struct fib_info { 1051da177e4SLinus Torvalds struct hlist_node fib_hash; 1061da177e4SLinus Torvalds struct hlist_node fib_lhash; 1077462bd74SDenis V. Lunev struct net *fib_net; 1081da177e4SLinus Torvalds int fib_treeref; 109*0029c0deSReshetova, Elena refcount_t fib_clntref; 11095c96174SEric Dumazet unsigned int fib_flags; 11137e826c5SDavid S. Miller unsigned char fib_dead; 11237e826c5SDavid S. Miller unsigned char fib_protocol; 11337e826c5SDavid S. Miller unsigned char fib_scope; 114f4ef85bbSEric Dumazet unsigned char fib_type; 115b83738aeSAl Viro __be32 fib_prefsrc; 1165a56a0b3SMark Tomlinson u32 fib_tb_id; 1171da177e4SLinus Torvalds u32 fib_priority; 1183fb07dafSEric Dumazet struct dst_metrics *fib_metrics; 1193fb07dafSEric Dumazet #define fib_mtu fib_metrics->metrics[RTAX_MTU-1] 1203fb07dafSEric Dumazet #define fib_window fib_metrics->metrics[RTAX_WINDOW-1] 1213fb07dafSEric Dumazet #define fib_rtt fib_metrics->metrics[RTAX_RTT-1] 1223fb07dafSEric Dumazet #define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1] 1231da177e4SLinus Torvalds int fib_nhs; 1241da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH 1250e884c78SPeter Nørlund int fib_weight; 1261da177e4SLinus Torvalds #endif 127c9850187SJiri Pirko unsigned int fib_offload_cnt; 128ebc0ffaeSEric Dumazet struct rcu_head rcu; 1291da177e4SLinus Torvalds struct fib_nh fib_nh[0]; 1301da177e4SLinus Torvalds #define fib_dev fib_nh[0].nh_dev 1311da177e4SLinus Torvalds }; 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES 1351da177e4SLinus Torvalds struct fib_rule; 1361da177e4SLinus Torvalds #endif 1371da177e4SLinus Torvalds 1385b470441SDavid S. Miller struct fib_table; 1391da177e4SLinus Torvalds struct fib_result { 1406ffd9034SDavid Ahern __be32 prefix; 1411da177e4SLinus Torvalds unsigned char prefixlen; 1421da177e4SLinus Torvalds unsigned char nh_sel; 1431da177e4SLinus Torvalds unsigned char type; 1441da177e4SLinus Torvalds unsigned char scope; 14585b91b03SDavid S. Miller u32 tclassid; 1461da177e4SLinus Torvalds struct fib_info *fi; 1475b470441SDavid S. Miller struct fib_table *table; 14856315f9eSAlexander Duyck struct hlist_head *fa_head; 1491da177e4SLinus Torvalds }; 1501da177e4SLinus Torvalds 151246955feSRobert Olsson struct fib_result_nl { 15280e856e1SAl Viro __be32 fl_addr; /* To be looked up*/ 1535f300893SThomas Graf u32 fl_mark; 154246955feSRobert Olsson unsigned char fl_tos; 155246955feSRobert Olsson unsigned char fl_scope; 156246955feSRobert Olsson unsigned char tb_id_in; 157246955feSRobert Olsson 158246955feSRobert Olsson unsigned char tb_id; /* Results */ 159246955feSRobert Olsson unsigned char prefixlen; 160246955feSRobert Olsson unsigned char nh_sel; 161246955feSRobert Olsson unsigned char type; 162246955feSRobert Olsson unsigned char scope; 163246955feSRobert Olsson int err; 164246955feSRobert Olsson }; 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH 1671da177e4SLinus Torvalds #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) 1681da177e4SLinus Torvalds #else /* CONFIG_IP_ROUTE_MULTIPATH */ 1691da177e4SLinus Torvalds #define FIB_RES_NH(res) ((res).fi->fib_nh[0]) 1701da177e4SLinus Torvalds #endif /* CONFIG_IP_ROUTE_MULTIPATH */ 1711da177e4SLinus Torvalds 1725b9e12dbSDenis V. Lunev #ifdef CONFIG_IP_MULTIPLE_TABLES 1735b9e12dbSDenis V. Lunev #define FIB_TABLE_HASHSZ 256 1745b9e12dbSDenis V. Lunev #else 1755b9e12dbSDenis V. Lunev #define FIB_TABLE_HASHSZ 2 1765b9e12dbSDenis V. Lunev #endif 1775b9e12dbSDenis V. Lunev 1785c3a0fd7SJoe Perches __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh); 179436c3b66SDavid S. Miller 180c9850187SJiri Pirko static inline void fib_info_offload_inc(struct fib_info *fi) 181c9850187SJiri Pirko { 182c9850187SJiri Pirko fi->fib_offload_cnt++; 183c9850187SJiri Pirko fi->fib_flags |= RTNH_F_OFFLOAD; 184c9850187SJiri Pirko } 185c9850187SJiri Pirko 186c9850187SJiri Pirko static inline void fib_info_offload_dec(struct fib_info *fi) 187c9850187SJiri Pirko { 188c9850187SJiri Pirko if (--fi->fib_offload_cnt == 0) 189c9850187SJiri Pirko fi->fib_flags &= ~RTNH_F_OFFLOAD; 190c9850187SJiri Pirko } 191c9850187SJiri Pirko 192436c3b66SDavid S. Miller #define FIB_RES_SADDR(net, res) \ 193436c3b66SDavid S. Miller ((FIB_RES_NH(res).nh_saddr_genid == \ 194436c3b66SDavid S. Miller atomic_read(&(net)->ipv4.dev_addr_genid)) ? \ 195436c3b66SDavid S. Miller FIB_RES_NH(res).nh_saddr : \ 196436c3b66SDavid S. Miller fib_info_update_nh_saddr((net), &FIB_RES_NH(res))) 1971da177e4SLinus Torvalds #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw) 1981da177e4SLinus Torvalds #define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev) 1991da177e4SLinus Torvalds #define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif) 2001da177e4SLinus Torvalds 201436c3b66SDavid S. Miller #define FIB_RES_PREFSRC(net, res) ((res).fi->fib_prefsrc ? : \ 202436c3b66SDavid S. Miller FIB_RES_SADDR(net, res)) 2031fc050a1SDavid S. Miller 204b90eb754SJiri Pirko struct fib_notifier_info { 205b90eb754SJiri Pirko struct net *net; 206b90eb754SJiri Pirko }; 207b90eb754SJiri Pirko 208b90eb754SJiri Pirko struct fib_entry_notifier_info { 209b90eb754SJiri Pirko struct fib_notifier_info info; /* must be first */ 210b90eb754SJiri Pirko u32 dst; 211b90eb754SJiri Pirko int dst_len; 212b90eb754SJiri Pirko struct fib_info *fi; 213b90eb754SJiri Pirko u8 tos; 214b90eb754SJiri Pirko u8 type; 215b90eb754SJiri Pirko u32 tb_id; 216b90eb754SJiri Pirko }; 217b90eb754SJiri Pirko 2186a003a5fSIdo Schimmel struct fib_rule_notifier_info { 2196a003a5fSIdo Schimmel struct fib_notifier_info info; /* must be first */ 2206a003a5fSIdo Schimmel struct fib_rule *rule; 2216a003a5fSIdo Schimmel }; 2226a003a5fSIdo Schimmel 223982acb97SIdo Schimmel struct fib_nh_notifier_info { 224982acb97SIdo Schimmel struct fib_notifier_info info; /* must be first */ 225982acb97SIdo Schimmel struct fib_nh *fib_nh; 226982acb97SIdo Schimmel }; 227982acb97SIdo Schimmel 228b90eb754SJiri Pirko enum fib_event_type { 2292f3a5272SIdo Schimmel FIB_EVENT_ENTRY_REPLACE, 2302f3a5272SIdo Schimmel FIB_EVENT_ENTRY_APPEND, 231b90eb754SJiri Pirko FIB_EVENT_ENTRY_ADD, 232b90eb754SJiri Pirko FIB_EVENT_ENTRY_DEL, 233b90eb754SJiri Pirko FIB_EVENT_RULE_ADD, 234b90eb754SJiri Pirko FIB_EVENT_RULE_DEL, 235982acb97SIdo Schimmel FIB_EVENT_NH_ADD, 236982acb97SIdo Schimmel FIB_EVENT_NH_DEL, 237b90eb754SJiri Pirko }; 238b90eb754SJiri Pirko 239c3852ef7SIdo Schimmel int register_fib_notifier(struct notifier_block *nb, 240c3852ef7SIdo Schimmel void (*cb)(struct notifier_block *nb)); 241b90eb754SJiri Pirko int unregister_fib_notifier(struct notifier_block *nb); 242c0243892SIdo Schimmel int call_fib_notifier(struct notifier_block *nb, struct net *net, 243c0243892SIdo Schimmel enum fib_event_type event_type, 244c0243892SIdo Schimmel struct fib_notifier_info *info); 245b90eb754SJiri Pirko int call_fib_notifiers(struct net *net, enum fib_event_type event_type, 246b90eb754SJiri Pirko struct fib_notifier_info *info); 247b90eb754SJiri Pirko 248d05f7a7dSIdo Schimmel void fib_notify(struct net *net, struct notifier_block *nb); 249c0243892SIdo Schimmel #ifdef CONFIG_IP_MULTIPLE_TABLES 250d05f7a7dSIdo Schimmel void fib_rules_notify(struct net *net, struct notifier_block *nb); 251c0243892SIdo Schimmel #else 252d05f7a7dSIdo Schimmel static inline void fib_rules_notify(struct net *net, struct notifier_block *nb) 253c0243892SIdo Schimmel { 254c0243892SIdo Schimmel } 255c0243892SIdo Schimmel #endif 256c0243892SIdo Schimmel 2571da177e4SLinus Torvalds struct fib_table { 2581af5a8c4SPatrick McHardy struct hlist_node tb_hlist; 2592dfe55b4SPatrick McHardy u32 tb_id; 26021d8c49eSDavid S. Miller int tb_num_default; 261a7e53531SAlexander Duyck struct rcu_head rcu; 2620ddcf43dSAlexander Duyck unsigned long *tb_data; 2630ddcf43dSAlexander Duyck unsigned long __data[0]; 2641da177e4SLinus Torvalds }; 2651da177e4SLinus Torvalds 2665c3a0fd7SJoe Perches int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, 267ebc0ffaeSEric Dumazet struct fib_result *res, int fib_flags); 2686d8422a1SDavid Ahern int fib_table_insert(struct net *, struct fib_table *, struct fib_config *, 2696d8422a1SDavid Ahern struct netlink_ext_ack *extack); 27078055998SDavid Ahern int fib_table_delete(struct net *, struct fib_table *, struct fib_config *, 27178055998SDavid Ahern struct netlink_ext_ack *extack); 2725c3a0fd7SJoe Perches int fib_table_dump(struct fib_table *table, struct sk_buff *skb, 27316c6cf8bSStephen Hemminger struct netlink_callback *cb); 274b90eb754SJiri Pirko int fib_table_flush(struct net *net, struct fib_table *table); 2750ddcf43dSAlexander Duyck struct fib_table *fib_trie_unmerge(struct fib_table *main_tb); 2763b709334SAlexander Duyck void fib_table_flush_external(struct fib_table *table); 2775c3a0fd7SJoe Perches void fib_free_table(struct fib_table *tb); 2784aa2c466SPavel Emelyanov 2791da177e4SLinus Torvalds #ifndef CONFIG_IP_MULTIPLE_TABLES 2801da177e4SLinus Torvalds 281a5a519b2SAlexander Duyck #define TABLE_LOCAL_INDEX (RT_TABLE_LOCAL & (FIB_TABLE_HASHSZ - 1)) 282a5a519b2SAlexander Duyck #define TABLE_MAIN_INDEX (RT_TABLE_MAIN & (FIB_TABLE_HASHSZ - 1)) 2831da177e4SLinus Torvalds 2848ad4942cSDenis V. Lunev static inline struct fib_table *fib_get_table(struct net *net, u32 id) 2851da177e4SLinus Torvalds { 286a7e53531SAlexander Duyck struct hlist_node *tb_hlist; 28793456b6dSDenis V. Lunev struct hlist_head *ptr; 28893456b6dSDenis V. Lunev 28993456b6dSDenis V. Lunev ptr = id == RT_TABLE_LOCAL ? 290e4aef8aeSDenis V. Lunev &net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX] : 291e4aef8aeSDenis V. Lunev &net->ipv4.fib_table_hash[TABLE_MAIN_INDEX]; 292a7e53531SAlexander Duyck 293a7e53531SAlexander Duyck tb_hlist = rcu_dereference_rtnl(hlist_first_rcu(ptr)); 294a7e53531SAlexander Duyck 295a7e53531SAlexander Duyck return hlist_entry(tb_hlist, struct fib_table, tb_hlist); 2961da177e4SLinus Torvalds } 2971da177e4SLinus Torvalds 2988ad4942cSDenis V. Lunev static inline struct fib_table *fib_new_table(struct net *net, u32 id) 2991da177e4SLinus Torvalds { 3008ad4942cSDenis V. Lunev return fib_get_table(net, id); 3011da177e4SLinus Torvalds } 3021da177e4SLinus Torvalds 30322bd5b9bSDavid S. Miller static inline int fib_lookup(struct net *net, const struct flowi4 *flp, 3040eeb075fSAndy Gospodarek struct fib_result *res, unsigned int flags) 3051da177e4SLinus Torvalds { 306a7e53531SAlexander Duyck struct fib_table *tb; 3070ddcf43dSAlexander Duyck int err = -ENETUNREACH; 30893456b6dSDenis V. Lunev 309345e9b54SAlexander Duyck rcu_read_lock(); 31093456b6dSDenis V. Lunev 311a7e53531SAlexander Duyck tb = fib_get_table(net, RT_TABLE_MAIN); 3120315e382SNikola Forró if (tb) 3130315e382SNikola Forró err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF); 3140315e382SNikola Forró 3150315e382SNikola Forró if (err == -EAGAIN) 3160315e382SNikola Forró err = -ENETUNREACH; 317345e9b54SAlexander Duyck 318345e9b54SAlexander Duyck rcu_read_unlock(); 319345e9b54SAlexander Duyck 320345e9b54SAlexander Duyck return err; 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3233c71006dSIdo Schimmel static inline bool fib4_rule_default(const struct fib_rule *rule) 3243c71006dSIdo Schimmel { 3253c71006dSIdo Schimmel return true; 3263c71006dSIdo Schimmel } 3273c71006dSIdo Schimmel 3281da177e4SLinus Torvalds #else /* CONFIG_IP_MULTIPLE_TABLES */ 3295c3a0fd7SJoe Perches int __net_init fib4_rules_init(struct net *net); 3305c3a0fd7SJoe Perches void __net_exit fib4_rules_exit(struct net *net); 331c3e9a353SPavel Emelyanov 3325c3a0fd7SJoe Perches struct fib_table *fib_new_table(struct net *net, u32 id); 3335c3a0fd7SJoe Perches struct fib_table *fib_get_table(struct net *net, u32 id); 3341da177e4SLinus Torvalds 3350eeb075fSAndy Gospodarek int __fib_lookup(struct net *net, struct flowi4 *flp, 3360eeb075fSAndy Gospodarek struct fib_result *res, unsigned int flags); 337f4530fa5SDavid S. Miller 338f4530fa5SDavid S. Miller static inline int fib_lookup(struct net *net, struct flowi4 *flp, 3390eeb075fSAndy Gospodarek struct fib_result *res, unsigned int flags) 340f4530fa5SDavid S. Miller { 341a7e53531SAlexander Duyck struct fib_table *tb; 3420315e382SNikola Forró int err = -ENETUNREACH; 343a7e53531SAlexander Duyck 3440eeb075fSAndy Gospodarek flags |= FIB_LOOKUP_NOREF; 345a7e53531SAlexander Duyck if (net->ipv4.fib_has_custom_rules) 3460eeb075fSAndy Gospodarek return __fib_lookup(net, flp, res, flags); 347345e9b54SAlexander Duyck 348345e9b54SAlexander Duyck rcu_read_lock(); 349345e9b54SAlexander Duyck 35085b91b03SDavid S. Miller res->tclassid = 0; 351a7e53531SAlexander Duyck 352a7e53531SAlexander Duyck tb = rcu_dereference_rtnl(net->ipv4.fib_main); 3530315e382SNikola Forró if (tb) 3540315e382SNikola Forró err = fib_table_lookup(tb, flp, res, flags); 3550315e382SNikola Forró 3560315e382SNikola Forró if (!err) 3570315e382SNikola Forró goto out; 358a7e53531SAlexander Duyck 359a7e53531SAlexander Duyck tb = rcu_dereference_rtnl(net->ipv4.fib_default); 3600315e382SNikola Forró if (tb) 3610315e382SNikola Forró err = fib_table_lookup(tb, flp, res, flags); 3620315e382SNikola Forró 3630315e382SNikola Forró out: 3640315e382SNikola Forró if (err == -EAGAIN) 3650315e382SNikola Forró err = -ENETUNREACH; 366345e9b54SAlexander Duyck 367345e9b54SAlexander Duyck rcu_read_unlock(); 368345e9b54SAlexander Duyck 369345e9b54SAlexander Duyck return err; 370f4530fa5SDavid S. Miller } 371f4530fa5SDavid S. Miller 3723c71006dSIdo Schimmel bool fib4_rule_default(const struct fib_rule *rule); 3733c71006dSIdo Schimmel 3741da177e4SLinus Torvalds #endif /* CONFIG_IP_MULTIPLE_TABLES */ 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds /* Exported by fib_frontend.c */ 377ef7c79edSPatrick McHardy extern const struct nla_policy rtm_ipv4_policy[]; 3785c3a0fd7SJoe Perches void ip_fib_init(void); 3795c3a0fd7SJoe Perches __be32 fib_compute_spec_dst(struct sk_buff *skb); 3805c3a0fd7SJoe Perches int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, 3815c04c819SMichael Smith u8 tos, int oif, struct net_device *dev, 3829e56e380SDavid S. Miller struct in_device *idev, u32 *itag); 3837a9bc9b8SDavid S. Miller #ifdef CONFIG_IP_ROUTE_CLASSID 384f4530fa5SDavid S. Miller static inline int fib_num_tclassid_users(struct net *net) 385f4530fa5SDavid S. Miller { 386f4530fa5SDavid S. Miller return net->ipv4.fib_num_tclassid_users; 387f4530fa5SDavid S. Miller } 3887a9bc9b8SDavid S. Miller #else 389f4530fa5SDavid S. Miller static inline int fib_num_tclassid_users(struct net *net) 390f4530fa5SDavid S. Miller { 391f4530fa5SDavid S. Miller return 0; 392f4530fa5SDavid S. Miller } 3937a9bc9b8SDavid S. Miller #endif 3940ddcf43dSAlexander Duyck int fib_unmerge(struct net *net); 39514c85021SArnaldo Carvalho de Melo 3961da177e4SLinus Torvalds /* Exported by fib_semantics.c */ 3975c3a0fd7SJoe Perches int ip_fib_check_default(__be32 gw, struct net_device *dev); 3984f823defSJulian Anastasov int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force); 3995a56a0b3SMark Tomlinson int fib_sync_down_addr(struct net_device *dev, __be32 local); 4008a3d0316SAndy Gospodarek int fib_sync_up(struct net_device *dev, unsigned int nh_flags); 4010e884c78SPeter Nørlund 402bf4e0a3dSNikolay Aleksandrov #ifdef CONFIG_IP_ROUTE_MULTIPATH 403bf4e0a3dSNikolay Aleksandrov int fib_multipath_hash(const struct fib_info *fi, const struct flowi4 *fl4, 404bf4e0a3dSNikolay Aleksandrov const struct sk_buff *skb); 405bf4e0a3dSNikolay Aleksandrov #endif 4060e884c78SPeter Nørlund void fib_select_multipath(struct fib_result *res, int hash); 4073ce58d84SDavid Ahern void fib_select_path(struct net *net, struct fib_result *res, 408bf4e0a3dSNikolay Aleksandrov struct flowi4 *fl4, const struct sk_buff *skb); 4091da177e4SLinus Torvalds 4105348ba85SDavid S. Miller /* Exported by fib_trie.c */ 4115c3a0fd7SJoe Perches void fib_trie_init(void); 4120ddcf43dSAlexander Duyck struct fib_table *fib_trie_table(u32 id, struct fib_table *alias); 4131da177e4SLinus Torvalds 414b6bf3ca0SDavid S. Miller static inline void fib_combine_itag(u32 *itag, const struct fib_result *res) 4151da177e4SLinus Torvalds { 416c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID 4171da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES 4181da177e4SLinus Torvalds u32 rtag; 4191da177e4SLinus Torvalds #endif 4201da177e4SLinus Torvalds *itag = FIB_RES_NH(*res).nh_tclassid<<16; 4211da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES 42285b91b03SDavid S. Miller rtag = res->tclassid; 4231da177e4SLinus Torvalds if (*itag == 0) 4241da177e4SLinus Torvalds *itag = (rtag<<16); 4251da177e4SLinus Torvalds *itag |= (rtag>>16); 4261da177e4SLinus Torvalds #endif 4271da177e4SLinus Torvalds #endif 4281da177e4SLinus Torvalds } 4291da177e4SLinus Torvalds 4305c3a0fd7SJoe Perches void free_fib_info(struct fib_info *fi); 4311da177e4SLinus Torvalds 4321c677b3dSIdo Schimmel static inline void fib_info_hold(struct fib_info *fi) 4331c677b3dSIdo Schimmel { 434*0029c0deSReshetova, Elena refcount_inc(&fi->fib_clntref); 4351c677b3dSIdo Schimmel } 4361c677b3dSIdo Schimmel 4371da177e4SLinus Torvalds static inline void fib_info_put(struct fib_info *fi) 4381da177e4SLinus Torvalds { 439*0029c0deSReshetova, Elena if (refcount_dec_and_test(&fi->fib_clntref)) 4401da177e4SLinus Torvalds free_fib_info(fi); 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds 44320380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 4445c3a0fd7SJoe Perches int __net_init fib_proc_init(struct net *net); 4455c3a0fd7SJoe Perches void __net_exit fib_proc_exit(struct net *net); 446cc8274f5SLi Zefan #else 447cc8274f5SLi Zefan static inline int fib_proc_init(struct net *net) 448cc8274f5SLi Zefan { 449cc8274f5SLi Zefan return 0; 450cc8274f5SLi Zefan } 451cc8274f5SLi Zefan static inline void fib_proc_exit(struct net *net) 452cc8274f5SLi Zefan { 453cc8274f5SLi Zefan } 45420380731SArnaldo Carvalho de Melo #endif 45520380731SArnaldo Carvalho de Melo 4561da177e4SLinus Torvalds #endif /* _NET_FIB_H */ 457