1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/netlink.h>
6 #include <linux/refcount.h>
7 #include <linux/rtnetlink.h>
8 #include <net/fib_rules.h>
10 extern const struct nla_policy rtm_dn_policy[];
14 struct dn_fib_info *fi;
15 unsigned char prefixlen;
22 struct net_device *nh_dev;
23 unsigned int nh_flags;
24 unsigned char nh_scope;
32 struct dn_fib_info *fib_next;
33 struct dn_fib_info *fib_prev;
34 refcount_t fib_treeref;
35 refcount_t fib_clntref;
37 unsigned int fib_flags;
41 __u32 fib_metrics[RTAX_MAX];
44 struct dn_fib_nh fib_nh[0];
45 #define dn_fib_dev fib_nh[0].nh_dev
49 #define DN_FIB_RES_RESET(res) ((res).nh_sel = 0)
50 #define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
52 #define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res))
53 #define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw)
54 #define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev)
55 #define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
70 struct dn_fib_node *fn_next;
71 struct dn_fib_info *fn_info;
72 #define DN_FIB_INFO(f) ((f)->fn_info)
81 struct hlist_node hlist;
84 int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
85 struct nlattr *attrs[], struct nlmsghdr *n,
86 struct netlink_skb_parms *req);
87 int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
88 struct nlattr *attrs[], struct nlmsghdr *n,
89 struct netlink_skb_parms *req);
90 int (*lookup)(struct dn_fib_table *t, const struct flowidn *fld,
91 struct dn_fib_res *res);
92 int (*flush)(struct dn_fib_table *t);
93 int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
98 #ifdef CONFIG_DECNET_ROUTER
102 void dn_fib_init(void);
103 void dn_fib_cleanup(void);
105 int dn_fib_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
106 struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
107 struct nlattr *attrs[],
108 const struct nlmsghdr *nlh, int *errp);
109 int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
110 const struct flowidn *fld, struct dn_fib_res *res);
111 void dn_fib_release_info(struct dn_fib_info *fi);
112 void dn_fib_flush(void);
113 void dn_fib_select_multipath(const struct flowidn *fld, struct dn_fib_res *res);
118 struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
119 struct dn_fib_table *dn_fib_empty_table(void);
120 void dn_fib_table_init(void);
121 void dn_fib_table_cleanup(void);
126 void dn_fib_rules_init(void);
127 void dn_fib_rules_cleanup(void);
128 unsigned int dnet_addr_type(__le16 addr);
129 int dn_fib_lookup(struct flowidn *fld, struct dn_fib_res *res);
131 int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
133 void dn_fib_free_info(struct dn_fib_info *fi);
135 static inline void dn_fib_info_put(struct dn_fib_info *fi)
137 if (refcount_dec_and_test(&fi->fib_clntref))
138 dn_fib_free_info(fi);
141 static inline void dn_fib_res_put(struct dn_fib_res *res)
144 dn_fib_info_put(res->fi);
146 fib_rule_put(res->r);
151 #define dn_fib_init() do { } while(0)
152 #define dn_fib_cleanup() do { } while(0)
154 #define dn_fib_lookup(fl, res) (-ESRCH)
155 #define dn_fib_info_put(fi) do { } while(0)
156 #define dn_fib_select_multipath(fl, res) do { } while(0)
157 #define dn_fib_rules_policy(saddr,res,flags) (0)
158 #define dn_fib_res_put(res) do { } while(0)
160 #endif /* CONFIG_DECNET_ROUTER */
162 static inline __le16 dnet_make_mask(int n)
165 return cpu_to_le16(~((1 << (16 - n)) - 1));
166 return cpu_to_le16(0);
169 #endif /* _NET_DN_FIB_H */