Loading...
1#ifndef _NET_DN_FIB_H
2#define _NET_DN_FIB_H
3
4#include <linux/netlink.h>
5
6extern const struct nla_policy rtm_dn_policy[];
7
8struct dn_fib_res {
9 struct fib_rule *r;
10 struct dn_fib_info *fi;
11 unsigned char prefixlen;
12 unsigned char nh_sel;
13 unsigned char type;
14 unsigned char scope;
15};
16
17struct dn_fib_nh {
18 struct net_device *nh_dev;
19 unsigned int nh_flags;
20 unsigned char nh_scope;
21 int nh_weight;
22 int nh_power;
23 int nh_oif;
24 __le16 nh_gw;
25};
26
27struct dn_fib_info {
28 struct dn_fib_info *fib_next;
29 struct dn_fib_info *fib_prev;
30 int fib_treeref;
31 atomic_t fib_clntref;
32 int fib_dead;
33 unsigned int fib_flags;
34 int fib_protocol;
35 __le16 fib_prefsrc;
36 __u32 fib_priority;
37 __u32 fib_metrics[RTAX_MAX];
38 int fib_nhs;
39 int fib_power;
40 struct dn_fib_nh fib_nh[0];
41#define dn_fib_dev fib_nh[0].nh_dev
42};
43
44
45#define DN_FIB_RES_RESET(res) ((res).nh_sel = 0)
46#define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
47
48#define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res))
49#define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw)
50#define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev)
51#define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
52
53typedef struct {
54 __le16 datum;
55} dn_fib_key_t;
56
57typedef struct {
58 __le16 datum;
59} dn_fib_hash_t;
60
61typedef struct {
62 __u16 datum;
63} dn_fib_idx_t;
64
65struct dn_fib_node {
66 struct dn_fib_node *fn_next;
67 struct dn_fib_info *fn_info;
68#define DN_FIB_INFO(f) ((f)->fn_info)
69 dn_fib_key_t fn_key;
70 u8 fn_type;
71 u8 fn_scope;
72 u8 fn_state;
73};
74
75
76struct dn_fib_table {
77 struct hlist_node hlist;
78 u32 n;
79
80 int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
81 struct nlattr *attrs[], struct nlmsghdr *n,
82 struct netlink_skb_parms *req);
83 int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
84 struct nlattr *attrs[], struct nlmsghdr *n,
85 struct netlink_skb_parms *req);
86 int (*lookup)(struct dn_fib_table *t, const struct flowidn *fld,
87 struct dn_fib_res *res);
88 int (*flush)(struct dn_fib_table *t);
89 int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
90
91 unsigned char data[0];
92};
93
94#ifdef CONFIG_DECNET_ROUTER
95/*
96 * dn_fib.c
97 */
98void dn_fib_init(void);
99void dn_fib_cleanup(void);
100
101int dn_fib_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
102struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
103 struct nlattr *attrs[],
104 const struct nlmsghdr *nlh, int *errp);
105int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
106 const struct flowidn *fld, struct dn_fib_res *res);
107void dn_fib_release_info(struct dn_fib_info *fi);
108void dn_fib_flush(void);
109void dn_fib_select_multipath(const struct flowidn *fld, struct dn_fib_res *res);
110
111/*
112 * dn_tables.c
113 */
114struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
115struct dn_fib_table *dn_fib_empty_table(void);
116void dn_fib_table_init(void);
117void dn_fib_table_cleanup(void);
118
119/*
120 * dn_rules.c
121 */
122void dn_fib_rules_init(void);
123void dn_fib_rules_cleanup(void);
124unsigned int dnet_addr_type(__le16 addr);
125int dn_fib_lookup(struct flowidn *fld, struct dn_fib_res *res);
126
127int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
128
129void dn_fib_free_info(struct dn_fib_info *fi);
130
131static inline void dn_fib_info_put(struct dn_fib_info *fi)
132{
133 if (atomic_dec_and_test(&fi->fib_clntref))
134 dn_fib_free_info(fi);
135}
136
137static inline void dn_fib_res_put(struct dn_fib_res *res)
138{
139 if (res->fi)
140 dn_fib_info_put(res->fi);
141 if (res->r)
142 fib_rule_put(res->r);
143}
144
145#else /* Endnode */
146
147#define dn_fib_init() do { } while(0)
148#define dn_fib_cleanup() do { } while(0)
149
150#define dn_fib_lookup(fl, res) (-ESRCH)
151#define dn_fib_info_put(fi) do { } while(0)
152#define dn_fib_select_multipath(fl, res) do { } while(0)
153#define dn_fib_rules_policy(saddr,res,flags) (0)
154#define dn_fib_res_put(res) do { } while(0)
155
156#endif /* CONFIG_DECNET_ROUTER */
157
158static inline __le16 dnet_make_mask(int n)
159{
160 if (n)
161 return cpu_to_le16(~((1 << (16 - n)) - 1));
162 return cpu_to_le16(0);
163}
164
165#endif /* _NET_DN_FIB_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _NET_DN_FIB_H
3#define _NET_DN_FIB_H
4
5#include <linux/netlink.h>
6#include <linux/refcount.h>
7
8extern const struct nla_policy rtm_dn_policy[];
9
10struct dn_fib_res {
11 struct fib_rule *r;
12 struct dn_fib_info *fi;
13 unsigned char prefixlen;
14 unsigned char nh_sel;
15 unsigned char type;
16 unsigned char scope;
17};
18
19struct dn_fib_nh {
20 struct net_device *nh_dev;
21 unsigned int nh_flags;
22 unsigned char nh_scope;
23 int nh_weight;
24 int nh_power;
25 int nh_oif;
26 __le16 nh_gw;
27};
28
29struct dn_fib_info {
30 struct dn_fib_info *fib_next;
31 struct dn_fib_info *fib_prev;
32 int fib_treeref;
33 refcount_t fib_clntref;
34 int fib_dead;
35 unsigned int fib_flags;
36 int fib_protocol;
37 __le16 fib_prefsrc;
38 __u32 fib_priority;
39 __u32 fib_metrics[RTAX_MAX];
40 int fib_nhs;
41 int fib_power;
42 struct dn_fib_nh fib_nh[0];
43#define dn_fib_dev fib_nh[0].nh_dev
44};
45
46
47#define DN_FIB_RES_RESET(res) ((res).nh_sel = 0)
48#define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
49
50#define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res))
51#define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw)
52#define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev)
53#define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
54
55typedef struct {
56 __le16 datum;
57} dn_fib_key_t;
58
59typedef struct {
60 __le16 datum;
61} dn_fib_hash_t;
62
63typedef struct {
64 __u16 datum;
65} dn_fib_idx_t;
66
67struct dn_fib_node {
68 struct dn_fib_node *fn_next;
69 struct dn_fib_info *fn_info;
70#define DN_FIB_INFO(f) ((f)->fn_info)
71 dn_fib_key_t fn_key;
72 u8 fn_type;
73 u8 fn_scope;
74 u8 fn_state;
75};
76
77
78struct dn_fib_table {
79 struct hlist_node hlist;
80 u32 n;
81
82 int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
83 struct nlattr *attrs[], struct nlmsghdr *n,
84 struct netlink_skb_parms *req);
85 int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
86 struct nlattr *attrs[], struct nlmsghdr *n,
87 struct netlink_skb_parms *req);
88 int (*lookup)(struct dn_fib_table *t, const struct flowidn *fld,
89 struct dn_fib_res *res);
90 int (*flush)(struct dn_fib_table *t);
91 int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
92
93 unsigned char data[0];
94};
95
96#ifdef CONFIG_DECNET_ROUTER
97/*
98 * dn_fib.c
99 */
100void dn_fib_init(void);
101void dn_fib_cleanup(void);
102
103int dn_fib_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
104struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
105 struct nlattr *attrs[],
106 const struct nlmsghdr *nlh, int *errp);
107int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
108 const struct flowidn *fld, struct dn_fib_res *res);
109void dn_fib_release_info(struct dn_fib_info *fi);
110void dn_fib_flush(void);
111void dn_fib_select_multipath(const struct flowidn *fld, struct dn_fib_res *res);
112
113/*
114 * dn_tables.c
115 */
116struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
117struct dn_fib_table *dn_fib_empty_table(void);
118void dn_fib_table_init(void);
119void dn_fib_table_cleanup(void);
120
121/*
122 * dn_rules.c
123 */
124void dn_fib_rules_init(void);
125void dn_fib_rules_cleanup(void);
126unsigned int dnet_addr_type(__le16 addr);
127int dn_fib_lookup(struct flowidn *fld, struct dn_fib_res *res);
128
129int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
130
131void dn_fib_free_info(struct dn_fib_info *fi);
132
133static inline void dn_fib_info_put(struct dn_fib_info *fi)
134{
135 if (refcount_dec_and_test(&fi->fib_clntref))
136 dn_fib_free_info(fi);
137}
138
139static inline void dn_fib_res_put(struct dn_fib_res *res)
140{
141 if (res->fi)
142 dn_fib_info_put(res->fi);
143 if (res->r)
144 fib_rule_put(res->r);
145}
146
147#else /* Endnode */
148
149#define dn_fib_init() do { } while(0)
150#define dn_fib_cleanup() do { } while(0)
151
152#define dn_fib_lookup(fl, res) (-ESRCH)
153#define dn_fib_info_put(fi) do { } while(0)
154#define dn_fib_select_multipath(fl, res) do { } while(0)
155#define dn_fib_rules_policy(saddr,res,flags) (0)
156#define dn_fib_res_put(res) do { } while(0)
157
158#endif /* CONFIG_DECNET_ROUTER */
159
160static inline __le16 dnet_make_mask(int n)
161{
162 if (n)
163 return cpu_to_le16(~((1 << (16 - n)) - 1));
164 return cpu_to_le16(0);
165}
166
167#endif /* _NET_DN_FIB_H */