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> 2204b1d4e5SIdo Schimmel #include <net/fib_notifier.h> 23e1ef4bf2SThomas Graf #include <net/fib_rules.h> 248e773277SDavid S. Miller #include <net/inetpeer.h> 25d26b3a7cSEric Dumazet #include <linux/percpu.h> 26b90eb754SJiri Pirko #include <linux/notifier.h> 270029c0deSReshetova, Elena #include <linux/refcount.h> 281da177e4SLinus Torvalds 294e902c57SThomas Graf struct fib_config { 304e902c57SThomas Graf u8 fc_dst_len; 314e902c57SThomas Graf u8 fc_tos; 324e902c57SThomas Graf u8 fc_protocol; 334e902c57SThomas Graf u8 fc_scope; 344e902c57SThomas Graf u8 fc_type; 35b52f070cSThomas Graf /* 3 bytes unused */ 364e902c57SThomas Graf u32 fc_table; 376d85c10aSAl Viro __be32 fc_dst; 386d85c10aSAl Viro __be32 fc_gw; 394e902c57SThomas Graf int fc_oif; 404e902c57SThomas Graf u32 fc_flags; 414e902c57SThomas Graf u32 fc_priority; 426d85c10aSAl Viro __be32 fc_prefsrc; 434e902c57SThomas Graf struct nlattr *fc_mx; 444e902c57SThomas Graf struct rtnexthop *fc_mp; 454e902c57SThomas Graf int fc_mx_len; 464e902c57SThomas Graf int fc_mp_len; 474e902c57SThomas Graf u32 fc_flow; 484e902c57SThomas Graf u32 fc_nlflags; 494e902c57SThomas Graf struct nl_info fc_nlinfo; 50571e7226SRoopa Prabhu struct nlattr *fc_encap; 51571e7226SRoopa Prabhu u16 fc_encap_type; 521da177e4SLinus Torvalds }; 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds struct fib_info; 55f2bb4bedSDavid S. Miller struct rtable; 561da177e4SLinus Torvalds 574895c771SDavid S. Miller struct fib_nh_exception { 584895c771SDavid S. Miller struct fib_nh_exception __rcu *fnhe_next; 595aad1de5STimo Teräs int fnhe_genid; 604895c771SDavid S. Miller __be32 fnhe_daddr; 614895c771SDavid S. Miller u32 fnhe_pmtu; 62d52e5a7eSSabrina Dubroca bool fnhe_mtu_locked; 63aee06da6SJulian Anastasov __be32 fnhe_gw; 644895c771SDavid S. Miller unsigned long fnhe_expires; 652ffae99dSTimo Teräs struct rtable __rcu *fnhe_rth_input; 662ffae99dSTimo Teräs struct rtable __rcu *fnhe_rth_output; 674895c771SDavid S. Miller unsigned long fnhe_stamp; 68deed49dfSXin Long struct rcu_head rcu; 694895c771SDavid S. Miller }; 704895c771SDavid S. Miller 714895c771SDavid S. Miller struct fnhe_hash_bucket { 724895c771SDavid S. Miller struct fib_nh_exception __rcu *chain; 734895c771SDavid S. Miller }; 744895c771SDavid S. Miller 75d546c621SEric Dumazet #define FNHE_HASH_SHIFT 11 76d546c621SEric Dumazet #define FNHE_HASH_SIZE (1 << FNHE_HASH_SHIFT) 774895c771SDavid S. Miller #define FNHE_RECLAIM_DEPTH 5 784895c771SDavid S. Miller 791da177e4SLinus Torvalds struct fib_nh { 801da177e4SLinus Torvalds struct net_device *nh_dev; 811da177e4SLinus Torvalds struct hlist_node nh_hash; 821da177e4SLinus Torvalds struct fib_info *nh_parent; 8395c96174SEric Dumazet unsigned int nh_flags; 841da177e4SLinus Torvalds unsigned char nh_scope; 851da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH 861da177e4SLinus Torvalds int nh_weight; 870e884c78SPeter Nørlund atomic_t nh_upper_bound; 881da177e4SLinus Torvalds #endif 89c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID 901da177e4SLinus Torvalds __u32 nh_tclassid; 911da177e4SLinus Torvalds #endif 921da177e4SLinus Torvalds int nh_oif; 93ed49e3caSAl Viro __be32 nh_gw; 941fc050a1SDavid S. Miller __be32 nh_saddr; 95436c3b66SDavid S. Miller int nh_saddr_genid; 96d26b3a7cSEric Dumazet struct rtable __rcu * __percpu *nh_pcpu_rth_output; 9754764bb6SEric Dumazet struct rtable __rcu *nh_rth_input; 98caa41527SEric Dumazet struct fnhe_hash_bucket __rcu *nh_exceptions; 99571e7226SRoopa Prabhu struct lwtunnel_state *nh_lwtstate; 1001da177e4SLinus Torvalds }; 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds /* 1031da177e4SLinus Torvalds * This structure contains data shared by many of routes. 1041da177e4SLinus Torvalds */ 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds struct fib_info { 1071da177e4SLinus Torvalds struct hlist_node fib_hash; 1081da177e4SLinus Torvalds struct hlist_node fib_lhash; 1097462bd74SDenis V. Lunev struct net *fib_net; 1101da177e4SLinus Torvalds int fib_treeref; 1110029c0deSReshetova, Elena refcount_t fib_clntref; 11295c96174SEric Dumazet unsigned int fib_flags; 11337e826c5SDavid S. Miller unsigned char fib_dead; 11437e826c5SDavid S. Miller unsigned char fib_protocol; 11537e826c5SDavid S. Miller unsigned char fib_scope; 116f4ef85bbSEric Dumazet unsigned char fib_type; 117b83738aeSAl Viro __be32 fib_prefsrc; 1185a56a0b3SMark Tomlinson u32 fib_tb_id; 1191da177e4SLinus Torvalds u32 fib_priority; 1203fb07dafSEric Dumazet struct dst_metrics *fib_metrics; 1213fb07dafSEric Dumazet #define fib_mtu fib_metrics->metrics[RTAX_MTU-1] 1223fb07dafSEric Dumazet #define fib_window fib_metrics->metrics[RTAX_WINDOW-1] 1233fb07dafSEric Dumazet #define fib_rtt fib_metrics->metrics[RTAX_RTT-1] 1243fb07dafSEric Dumazet #define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1] 1251da177e4SLinus Torvalds int fib_nhs; 126ebc0ffaeSEric Dumazet struct rcu_head rcu; 1271da177e4SLinus Torvalds struct fib_nh fib_nh[0]; 1281da177e4SLinus Torvalds #define fib_dev fib_nh[0].nh_dev 1291da177e4SLinus Torvalds }; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES 1331da177e4SLinus Torvalds struct fib_rule; 1341da177e4SLinus Torvalds #endif 1351da177e4SLinus Torvalds 1365b470441SDavid S. Miller struct fib_table; 1371da177e4SLinus Torvalds struct fib_result { 1386ffd9034SDavid Ahern __be32 prefix; 1391da177e4SLinus Torvalds unsigned char prefixlen; 1401da177e4SLinus Torvalds unsigned char nh_sel; 1411da177e4SLinus Torvalds unsigned char type; 1421da177e4SLinus Torvalds unsigned char scope; 14385b91b03SDavid S. Miller u32 tclassid; 1441da177e4SLinus Torvalds struct fib_info *fi; 1455b470441SDavid S. Miller struct fib_table *table; 14656315f9eSAlexander Duyck struct hlist_head *fa_head; 1471da177e4SLinus Torvalds }; 1481da177e4SLinus Torvalds 149246955feSRobert Olsson struct fib_result_nl { 15080e856e1SAl Viro __be32 fl_addr; /* To be looked up*/ 1515f300893SThomas Graf u32 fl_mark; 152246955feSRobert Olsson unsigned char fl_tos; 153246955feSRobert Olsson unsigned char fl_scope; 154246955feSRobert Olsson unsigned char tb_id_in; 155246955feSRobert Olsson 156246955feSRobert Olsson unsigned char tb_id; /* Results */ 157246955feSRobert Olsson unsigned char prefixlen; 158246955feSRobert Olsson unsigned char nh_sel; 159246955feSRobert Olsson unsigned char type; 160246955feSRobert Olsson unsigned char scope; 161246955feSRobert Olsson int err; 162246955feSRobert Olsson }; 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH 1651da177e4SLinus Torvalds #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) 1661da177e4SLinus Torvalds #else /* CONFIG_IP_ROUTE_MULTIPATH */ 1671da177e4SLinus Torvalds #define FIB_RES_NH(res) ((res).fi->fib_nh[0]) 1681da177e4SLinus Torvalds #endif /* CONFIG_IP_ROUTE_MULTIPATH */ 1691da177e4SLinus Torvalds 1705b9e12dbSDenis V. Lunev #ifdef CONFIG_IP_MULTIPLE_TABLES 1715b9e12dbSDenis V. Lunev #define FIB_TABLE_HASHSZ 256 1725b9e12dbSDenis V. Lunev #else 1735b9e12dbSDenis V. Lunev #define FIB_TABLE_HASHSZ 2 1745b9e12dbSDenis V. Lunev #endif 1755b9e12dbSDenis V. Lunev 1765c3a0fd7SJoe Perches __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh); 177436c3b66SDavid S. Miller 178436c3b66SDavid S. Miller #define FIB_RES_SADDR(net, res) \ 179436c3b66SDavid S. Miller ((FIB_RES_NH(res).nh_saddr_genid == \ 180436c3b66SDavid S. Miller atomic_read(&(net)->ipv4.dev_addr_genid)) ? \ 181436c3b66SDavid S. Miller FIB_RES_NH(res).nh_saddr : \ 182436c3b66SDavid S. Miller fib_info_update_nh_saddr((net), &FIB_RES_NH(res))) 1831da177e4SLinus Torvalds #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw) 1841da177e4SLinus Torvalds #define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev) 1851da177e4SLinus Torvalds #define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif) 1861da177e4SLinus Torvalds 187436c3b66SDavid S. Miller #define FIB_RES_PREFSRC(net, res) ((res).fi->fib_prefsrc ? : \ 188436c3b66SDavid S. Miller FIB_RES_SADDR(net, res)) 1891fc050a1SDavid S. Miller 190b90eb754SJiri Pirko struct fib_entry_notifier_info { 191b90eb754SJiri Pirko struct fib_notifier_info info; /* must be first */ 192b90eb754SJiri Pirko u32 dst; 193b90eb754SJiri Pirko int dst_len; 194b90eb754SJiri Pirko struct fib_info *fi; 195b90eb754SJiri Pirko u8 tos; 196b90eb754SJiri Pirko u8 type; 197b90eb754SJiri Pirko u32 tb_id; 198b90eb754SJiri Pirko }; 199b90eb754SJiri Pirko 200982acb97SIdo Schimmel struct fib_nh_notifier_info { 201982acb97SIdo Schimmel struct fib_notifier_info info; /* must be first */ 202982acb97SIdo Schimmel struct fib_nh *fib_nh; 203982acb97SIdo Schimmel }; 204982acb97SIdo Schimmel 20504b1d4e5SIdo Schimmel int call_fib4_notifier(struct notifier_block *nb, struct net *net, 206c0243892SIdo Schimmel enum fib_event_type event_type, 207c0243892SIdo Schimmel struct fib_notifier_info *info); 20804b1d4e5SIdo Schimmel int call_fib4_notifiers(struct net *net, enum fib_event_type event_type, 209b90eb754SJiri Pirko struct fib_notifier_info *info); 210b90eb754SJiri Pirko 21104b1d4e5SIdo Schimmel int __net_init fib4_notifier_init(struct net *net); 21204b1d4e5SIdo Schimmel void __net_exit fib4_notifier_exit(struct net *net); 21304b1d4e5SIdo Schimmel 214d05f7a7dSIdo Schimmel void fib_notify(struct net *net, struct notifier_block *nb); 215c0243892SIdo Schimmel 2161da177e4SLinus Torvalds struct fib_table { 2171af5a8c4SPatrick McHardy struct hlist_node tb_hlist; 2182dfe55b4SPatrick McHardy u32 tb_id; 21921d8c49eSDavid S. Miller int tb_num_default; 220a7e53531SAlexander Duyck struct rcu_head rcu; 2210ddcf43dSAlexander Duyck unsigned long *tb_data; 2220ddcf43dSAlexander Duyck unsigned long __data[0]; 2231da177e4SLinus Torvalds }; 2241da177e4SLinus Torvalds 2254724676dSDavid Ahern struct fib_dump_filter { 2264724676dSDavid Ahern u32 table_id; 2274724676dSDavid Ahern /* filter_set is an optimization that an entry is set */ 2284724676dSDavid Ahern bool filter_set; 2294724676dSDavid Ahern unsigned char protocol; 2304724676dSDavid Ahern unsigned char rt_type; 2314724676dSDavid Ahern unsigned int flags; 2324724676dSDavid Ahern struct net_device *dev; 2334724676dSDavid Ahern }; 2344724676dSDavid Ahern 2355c3a0fd7SJoe Perches int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, 236ebc0ffaeSEric Dumazet struct fib_result *res, int fib_flags); 2376d8422a1SDavid Ahern int fib_table_insert(struct net *, struct fib_table *, struct fib_config *, 2386d8422a1SDavid Ahern struct netlink_ext_ack *extack); 23978055998SDavid Ahern int fib_table_delete(struct net *, struct fib_table *, struct fib_config *, 24078055998SDavid Ahern struct netlink_ext_ack *extack); 2415c3a0fd7SJoe Perches int fib_table_dump(struct fib_table *table, struct sk_buff *skb, 24218a8021aSDavid Ahern struct netlink_callback *cb, struct fib_dump_filter *filter); 243b90eb754SJiri Pirko int fib_table_flush(struct net *net, struct fib_table *table); 2440ddcf43dSAlexander Duyck struct fib_table *fib_trie_unmerge(struct fib_table *main_tb); 2453b709334SAlexander Duyck void fib_table_flush_external(struct fib_table *table); 2465c3a0fd7SJoe Perches void fib_free_table(struct fib_table *tb); 2474aa2c466SPavel Emelyanov 2481da177e4SLinus Torvalds #ifndef CONFIG_IP_MULTIPLE_TABLES 2491da177e4SLinus Torvalds 250a5a519b2SAlexander Duyck #define TABLE_LOCAL_INDEX (RT_TABLE_LOCAL & (FIB_TABLE_HASHSZ - 1)) 251a5a519b2SAlexander Duyck #define TABLE_MAIN_INDEX (RT_TABLE_MAIN & (FIB_TABLE_HASHSZ - 1)) 2521da177e4SLinus Torvalds 2538ad4942cSDenis V. Lunev static inline struct fib_table *fib_get_table(struct net *net, u32 id) 2541da177e4SLinus Torvalds { 255a7e53531SAlexander Duyck struct hlist_node *tb_hlist; 25693456b6dSDenis V. Lunev struct hlist_head *ptr; 25793456b6dSDenis V. Lunev 25893456b6dSDenis V. Lunev ptr = id == RT_TABLE_LOCAL ? 259e4aef8aeSDenis V. Lunev &net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX] : 260e4aef8aeSDenis V. Lunev &net->ipv4.fib_table_hash[TABLE_MAIN_INDEX]; 261a7e53531SAlexander Duyck 262a7e53531SAlexander Duyck tb_hlist = rcu_dereference_rtnl(hlist_first_rcu(ptr)); 263a7e53531SAlexander Duyck 264a7e53531SAlexander Duyck return hlist_entry(tb_hlist, struct fib_table, tb_hlist); 2651da177e4SLinus Torvalds } 2661da177e4SLinus Torvalds 2678ad4942cSDenis V. Lunev static inline struct fib_table *fib_new_table(struct net *net, u32 id) 2681da177e4SLinus Torvalds { 2698ad4942cSDenis V. Lunev return fib_get_table(net, id); 2701da177e4SLinus Torvalds } 2711da177e4SLinus Torvalds 27222bd5b9bSDavid S. Miller static inline int fib_lookup(struct net *net, const struct flowi4 *flp, 2730eeb075fSAndy Gospodarek struct fib_result *res, unsigned int flags) 2741da177e4SLinus Torvalds { 275a7e53531SAlexander Duyck struct fib_table *tb; 2760ddcf43dSAlexander Duyck int err = -ENETUNREACH; 27793456b6dSDenis V. Lunev 278345e9b54SAlexander Duyck rcu_read_lock(); 27993456b6dSDenis V. Lunev 280a7e53531SAlexander Duyck tb = fib_get_table(net, RT_TABLE_MAIN); 2810315e382SNikola Forró if (tb) 2820315e382SNikola Forró err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF); 2830315e382SNikola Forró 2840315e382SNikola Forró if (err == -EAGAIN) 2850315e382SNikola Forró err = -ENETUNREACH; 286345e9b54SAlexander Duyck 287345e9b54SAlexander Duyck rcu_read_unlock(); 288345e9b54SAlexander Duyck 289345e9b54SAlexander Duyck return err; 2901da177e4SLinus Torvalds } 2911da177e4SLinus Torvalds 2923c71006dSIdo Schimmel static inline bool fib4_rule_default(const struct fib_rule *rule) 2933c71006dSIdo Schimmel { 2943c71006dSIdo Schimmel return true; 2953c71006dSIdo Schimmel } 2963c71006dSIdo Schimmel 2971b2a4440SIdo Schimmel static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb) 2981b2a4440SIdo Schimmel { 2991b2a4440SIdo Schimmel return 0; 3001b2a4440SIdo Schimmel } 3011b2a4440SIdo Schimmel 3021b2a4440SIdo Schimmel static inline unsigned int fib4_rules_seq_read(struct net *net) 3031b2a4440SIdo Schimmel { 3041b2a4440SIdo Schimmel return 0; 3051b2a4440SIdo Schimmel } 3061b2a4440SIdo Schimmel 307e37b1e97SRoopa Prabhu static inline bool fib4_rules_early_flow_dissect(struct net *net, 308e37b1e97SRoopa Prabhu struct sk_buff *skb, 309e37b1e97SRoopa Prabhu struct flowi4 *fl4, 310e37b1e97SRoopa Prabhu struct flow_keys *flkeys) 311e37b1e97SRoopa Prabhu { 312e37b1e97SRoopa Prabhu return false; 313e37b1e97SRoopa Prabhu } 3141da177e4SLinus Torvalds #else /* CONFIG_IP_MULTIPLE_TABLES */ 3155c3a0fd7SJoe Perches int __net_init fib4_rules_init(struct net *net); 3165c3a0fd7SJoe Perches void __net_exit fib4_rules_exit(struct net *net); 317c3e9a353SPavel Emelyanov 3185c3a0fd7SJoe Perches struct fib_table *fib_new_table(struct net *net, u32 id); 3195c3a0fd7SJoe Perches struct fib_table *fib_get_table(struct net *net, u32 id); 3201da177e4SLinus Torvalds 3210eeb075fSAndy Gospodarek int __fib_lookup(struct net *net, struct flowi4 *flp, 3220eeb075fSAndy Gospodarek struct fib_result *res, unsigned int flags); 323f4530fa5SDavid S. Miller 324f4530fa5SDavid S. Miller static inline int fib_lookup(struct net *net, struct flowi4 *flp, 3250eeb075fSAndy Gospodarek struct fib_result *res, unsigned int flags) 326f4530fa5SDavid S. Miller { 327a7e53531SAlexander Duyck struct fib_table *tb; 3280315e382SNikola Forró int err = -ENETUNREACH; 329a7e53531SAlexander Duyck 3300eeb075fSAndy Gospodarek flags |= FIB_LOOKUP_NOREF; 331a7e53531SAlexander Duyck if (net->ipv4.fib_has_custom_rules) 3320eeb075fSAndy Gospodarek return __fib_lookup(net, flp, res, flags); 333345e9b54SAlexander Duyck 334345e9b54SAlexander Duyck rcu_read_lock(); 335345e9b54SAlexander Duyck 33685b91b03SDavid S. Miller res->tclassid = 0; 337a7e53531SAlexander Duyck 338a7e53531SAlexander Duyck tb = rcu_dereference_rtnl(net->ipv4.fib_main); 3390315e382SNikola Forró if (tb) 3400315e382SNikola Forró err = fib_table_lookup(tb, flp, res, flags); 3410315e382SNikola Forró 3420315e382SNikola Forró if (!err) 3430315e382SNikola Forró goto out; 344a7e53531SAlexander Duyck 345a7e53531SAlexander Duyck tb = rcu_dereference_rtnl(net->ipv4.fib_default); 3460315e382SNikola Forró if (tb) 3470315e382SNikola Forró err = fib_table_lookup(tb, flp, res, flags); 3480315e382SNikola Forró 3490315e382SNikola Forró out: 3500315e382SNikola Forró if (err == -EAGAIN) 3510315e382SNikola Forró err = -ENETUNREACH; 352345e9b54SAlexander Duyck 353345e9b54SAlexander Duyck rcu_read_unlock(); 354345e9b54SAlexander Duyck 355345e9b54SAlexander Duyck return err; 356f4530fa5SDavid S. Miller } 357f4530fa5SDavid S. Miller 3583c71006dSIdo Schimmel bool fib4_rule_default(const struct fib_rule *rule); 3591b2a4440SIdo Schimmel int fib4_rules_dump(struct net *net, struct notifier_block *nb); 3601b2a4440SIdo Schimmel unsigned int fib4_rules_seq_read(struct net *net); 3613c71006dSIdo Schimmel 362e37b1e97SRoopa Prabhu static inline bool fib4_rules_early_flow_dissect(struct net *net, 363e37b1e97SRoopa Prabhu struct sk_buff *skb, 364e37b1e97SRoopa Prabhu struct flowi4 *fl4, 365e37b1e97SRoopa Prabhu struct flow_keys *flkeys) 366e37b1e97SRoopa Prabhu { 367e37b1e97SRoopa Prabhu unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP; 368e37b1e97SRoopa Prabhu 369e37b1e97SRoopa Prabhu if (!net->ipv4.fib_rules_require_fldissect) 370e37b1e97SRoopa Prabhu return false; 371e37b1e97SRoopa Prabhu 372e37b1e97SRoopa Prabhu skb_flow_dissect_flow_keys(skb, flkeys, flag); 373e37b1e97SRoopa Prabhu fl4->fl4_sport = flkeys->ports.src; 374e37b1e97SRoopa Prabhu fl4->fl4_dport = flkeys->ports.dst; 375e37b1e97SRoopa Prabhu fl4->flowi4_proto = flkeys->basic.ip_proto; 376e37b1e97SRoopa Prabhu 377e37b1e97SRoopa Prabhu return true; 378e37b1e97SRoopa Prabhu } 379e37b1e97SRoopa Prabhu 3801da177e4SLinus Torvalds #endif /* CONFIG_IP_MULTIPLE_TABLES */ 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds /* Exported by fib_frontend.c */ 383ef7c79edSPatrick McHardy extern const struct nla_policy rtm_ipv4_policy[]; 3845c3a0fd7SJoe Perches void ip_fib_init(void); 3855c3a0fd7SJoe Perches __be32 fib_compute_spec_dst(struct sk_buff *skb); 38678f2756cSDavid Ahern bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev); 3875c3a0fd7SJoe Perches int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, 3885c04c819SMichael Smith u8 tos, int oif, struct net_device *dev, 3899e56e380SDavid S. Miller struct in_device *idev, u32 *itag); 3907a9bc9b8SDavid S. Miller #ifdef CONFIG_IP_ROUTE_CLASSID 391f4530fa5SDavid S. Miller static inline int fib_num_tclassid_users(struct net *net) 392f4530fa5SDavid S. Miller { 393f4530fa5SDavid S. Miller return net->ipv4.fib_num_tclassid_users; 394f4530fa5SDavid S. Miller } 3957a9bc9b8SDavid S. Miller #else 396f4530fa5SDavid S. Miller static inline int fib_num_tclassid_users(struct net *net) 397f4530fa5SDavid S. Miller { 398f4530fa5SDavid S. Miller return 0; 399f4530fa5SDavid S. Miller } 4007a9bc9b8SDavid S. Miller #endif 4010ddcf43dSAlexander Duyck int fib_unmerge(struct net *net); 40214c85021SArnaldo Carvalho de Melo 4031da177e4SLinus Torvalds /* Exported by fib_semantics.c */ 4045c3a0fd7SJoe Perches int ip_fib_check_default(__be32 gw, struct net_device *dev); 4054f823defSJulian Anastasov int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force); 4065a56a0b3SMark Tomlinson int fib_sync_down_addr(struct net_device *dev, __be32 local); 4078a3d0316SAndy Gospodarek int fib_sync_up(struct net_device *dev, unsigned int nh_flags); 408af7d6cceSSabrina Dubroca void fib_sync_mtu(struct net_device *dev, u32 orig_mtu); 4090e884c78SPeter Nørlund 410bf4e0a3dSNikolay Aleksandrov #ifdef CONFIG_IP_ROUTE_MULTIPATH 4117efc0b6bSDavid Ahern int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, 412e37b1e97SRoopa Prabhu const struct sk_buff *skb, struct flow_keys *flkeys); 413bf4e0a3dSNikolay Aleksandrov #endif 4140e884c78SPeter Nørlund void fib_select_multipath(struct fib_result *res, int hash); 4153ce58d84SDavid Ahern void fib_select_path(struct net *net, struct fib_result *res, 416bf4e0a3dSNikolay Aleksandrov struct flowi4 *fl4, const struct sk_buff *skb); 4171da177e4SLinus Torvalds 4185348ba85SDavid S. Miller /* Exported by fib_trie.c */ 4195c3a0fd7SJoe Perches void fib_trie_init(void); 4200ddcf43dSAlexander Duyck struct fib_table *fib_trie_table(u32 id, struct fib_table *alias); 4211da177e4SLinus Torvalds 422b6bf3ca0SDavid S. Miller static inline void fib_combine_itag(u32 *itag, const struct fib_result *res) 4231da177e4SLinus Torvalds { 424c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID 4251da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES 4261da177e4SLinus Torvalds u32 rtag; 4271da177e4SLinus Torvalds #endif 4281da177e4SLinus Torvalds *itag = FIB_RES_NH(*res).nh_tclassid<<16; 4291da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES 43085b91b03SDavid S. Miller rtag = res->tclassid; 4311da177e4SLinus Torvalds if (*itag == 0) 4321da177e4SLinus Torvalds *itag = (rtag<<16); 4331da177e4SLinus Torvalds *itag |= (rtag>>16); 4341da177e4SLinus Torvalds #endif 4351da177e4SLinus Torvalds #endif 4361da177e4SLinus Torvalds } 4371da177e4SLinus Torvalds 4385c3a0fd7SJoe Perches void free_fib_info(struct fib_info *fi); 4391da177e4SLinus Torvalds 4401c677b3dSIdo Schimmel static inline void fib_info_hold(struct fib_info *fi) 4411c677b3dSIdo Schimmel { 4420029c0deSReshetova, Elena refcount_inc(&fi->fib_clntref); 4431c677b3dSIdo Schimmel } 4441c677b3dSIdo Schimmel 4451da177e4SLinus Torvalds static inline void fib_info_put(struct fib_info *fi) 4461da177e4SLinus Torvalds { 4470029c0deSReshetova, Elena if (refcount_dec_and_test(&fi->fib_clntref)) 4481da177e4SLinus Torvalds free_fib_info(fi); 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds 45120380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 4525c3a0fd7SJoe Perches int __net_init fib_proc_init(struct net *net); 4535c3a0fd7SJoe Perches void __net_exit fib_proc_exit(struct net *net); 454cc8274f5SLi Zefan #else 455cc8274f5SLi Zefan static inline int fib_proc_init(struct net *net) 456cc8274f5SLi Zefan { 457cc8274f5SLi Zefan return 0; 458cc8274f5SLi Zefan } 459cc8274f5SLi Zefan static inline void fib_proc_exit(struct net *net) 460cc8274f5SLi Zefan { 461cc8274f5SLi Zefan } 46220380731SArnaldo Carvalho de Melo #endif 46320380731SArnaldo Carvalho de Melo 46450d889b1SDavid Ahern u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr); 46550d889b1SDavid Ahern 4664724676dSDavid Ahern int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh, 4674724676dSDavid Ahern struct fib_dump_filter *filter, 468*effe6792SDavid Ahern struct netlink_callback *cb); 4691da177e4SLinus Torvalds #endif /* _NET_FIB_H */ 470