dn_fib.h 4.6 KB

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