0001
0002 #ifndef _NET_DN_FIB_H
0003 #define _NET_DN_FIB_H
0004
0005 #include <linux/netlink.h>
0006 #include <linux/refcount.h>
0007 #include <linux/rtnetlink.h>
0008 #include <net/fib_rules.h>
0009
0010 extern const struct nla_policy rtm_dn_policy[];
0011
0012 struct dn_fib_res {
0013 struct fib_rule *r;
0014 struct dn_fib_info *fi;
0015 unsigned char prefixlen;
0016 unsigned char nh_sel;
0017 unsigned char type;
0018 unsigned char scope;
0019 };
0020
0021 struct dn_fib_nh {
0022 struct net_device *nh_dev;
0023 unsigned int nh_flags;
0024 unsigned char nh_scope;
0025 int nh_weight;
0026 int nh_power;
0027 int nh_oif;
0028 __le16 nh_gw;
0029 };
0030
0031 struct dn_fib_info {
0032 struct dn_fib_info *fib_next;
0033 struct dn_fib_info *fib_prev;
0034 refcount_t fib_treeref;
0035 refcount_t fib_clntref;
0036 int fib_dead;
0037 unsigned int fib_flags;
0038 int fib_protocol;
0039 __le16 fib_prefsrc;
0040 __u32 fib_priority;
0041 __u32 fib_metrics[RTAX_MAX];
0042 int fib_nhs;
0043 int fib_power;
0044 struct dn_fib_nh fib_nh[0];
0045 #define dn_fib_dev fib_nh[0].nh_dev
0046 };
0047
0048
0049 #define DN_FIB_RES_RESET(res) ((res).nh_sel = 0)
0050 #define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
0051
0052 #define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res))
0053 #define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw)
0054 #define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev)
0055 #define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
0056
0057 typedef struct {
0058 __le16 datum;
0059 } dn_fib_key_t;
0060
0061 typedef struct {
0062 __le16 datum;
0063 } dn_fib_hash_t;
0064
0065 typedef struct {
0066 __u16 datum;
0067 } dn_fib_idx_t;
0068
0069 struct dn_fib_node {
0070 struct dn_fib_node *fn_next;
0071 struct dn_fib_info *fn_info;
0072 #define DN_FIB_INFO(f) ((f)->fn_info)
0073 dn_fib_key_t fn_key;
0074 u8 fn_type;
0075 u8 fn_scope;
0076 u8 fn_state;
0077 };
0078
0079
0080 struct dn_fib_table {
0081 struct hlist_node hlist;
0082 u32 n;
0083
0084 int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
0085 struct nlattr *attrs[], struct nlmsghdr *n,
0086 struct netlink_skb_parms *req);
0087 int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
0088 struct nlattr *attrs[], struct nlmsghdr *n,
0089 struct netlink_skb_parms *req);
0090 int (*lookup)(struct dn_fib_table *t, const struct flowidn *fld,
0091 struct dn_fib_res *res);
0092 int (*flush)(struct dn_fib_table *t);
0093 int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
0094
0095 unsigned char data[];
0096 };
0097
0098 #ifdef CONFIG_DECNET_ROUTER
0099
0100
0101
0102 void dn_fib_init(void);
0103 void dn_fib_cleanup(void);
0104
0105 int dn_fib_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
0106 struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
0107 struct nlattr *attrs[],
0108 const struct nlmsghdr *nlh, int *errp);
0109 int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
0110 const struct flowidn *fld, struct dn_fib_res *res);
0111 void dn_fib_release_info(struct dn_fib_info *fi);
0112 void dn_fib_flush(void);
0113 void dn_fib_select_multipath(const struct flowidn *fld, struct dn_fib_res *res);
0114
0115
0116
0117
0118 struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
0119 struct dn_fib_table *dn_fib_empty_table(void);
0120 void dn_fib_table_init(void);
0121 void dn_fib_table_cleanup(void);
0122
0123
0124
0125
0126 void dn_fib_rules_init(void);
0127 void dn_fib_rules_cleanup(void);
0128 unsigned int dnet_addr_type(__le16 addr);
0129 int dn_fib_lookup(struct flowidn *fld, struct dn_fib_res *res);
0130
0131 int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
0132
0133 void dn_fib_free_info(struct dn_fib_info *fi);
0134
0135 static inline void dn_fib_info_put(struct dn_fib_info *fi)
0136 {
0137 if (refcount_dec_and_test(&fi->fib_clntref))
0138 dn_fib_free_info(fi);
0139 }
0140
0141 static inline void dn_fib_res_put(struct dn_fib_res *res)
0142 {
0143 if (res->fi)
0144 dn_fib_info_put(res->fi);
0145 if (res->r)
0146 fib_rule_put(res->r);
0147 }
0148
0149 #else
0150
0151 #define dn_fib_init() do { } while(0)
0152 #define dn_fib_cleanup() do { } while(0)
0153
0154 #define dn_fib_lookup(fl, res) (-ESRCH)
0155 #define dn_fib_info_put(fi) do { } while(0)
0156 #define dn_fib_select_multipath(fl, res) do { } while(0)
0157 #define dn_fib_rules_policy(saddr,res,flags) (0)
0158 #define dn_fib_res_put(res) do { } while(0)
0159
0160 #endif
0161
0162 static inline __le16 dnet_make_mask(int n)
0163 {
0164 if (n)
0165 return cpu_to_le16(~((1 << (16 - n)) - 1));
0166 return cpu_to_le16(0);
0167 }
0168
0169 #endif