dn_fib.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #define dn_fib_mtu fib_metrics[RTAX_MTU-1]
  50. #define dn_fib_window fib_metrics[RTAX_WINDOW-1]
  51. #define dn_fib_rtt fib_metrics[RTAX_RTT-1]
  52. #define dn_fib_advmss fib_metrics[RTAX_ADVMSS-1]
  53. int fib_nhs;
  54. int fib_power;
  55. struct dn_fib_nh fib_nh[0];
  56. #define dn_fib_dev fib_nh[0].nh_dev
  57. };
  58. #define DN_FIB_RES_RESET(res) ((res).nh_sel = 0)
  59. #define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
  60. #define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res))
  61. #define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw)
  62. #define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev)
  63. #define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
  64. typedef struct {
  65. __le16 datum;
  66. } dn_fib_key_t;
  67. typedef struct {
  68. __le16 datum;
  69. } dn_fib_hash_t;
  70. typedef struct {
  71. __u16 datum;
  72. } dn_fib_idx_t;
  73. struct dn_fib_node {
  74. struct dn_fib_node *fn_next;
  75. struct dn_fib_info *fn_info;
  76. #define DN_FIB_INFO(f) ((f)->fn_info)
  77. dn_fib_key_t fn_key;
  78. u8 fn_type;
  79. u8 fn_scope;
  80. u8 fn_state;
  81. };
  82. struct dn_fib_table {
  83. struct hlist_node hlist;
  84. u32 n;
  85. int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
  86. struct dn_kern_rta *rta, struct nlmsghdr *n,
  87. struct netlink_skb_parms *req);
  88. int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
  89. struct dn_kern_rta *rta, struct nlmsghdr *n,
  90. struct netlink_skb_parms *req);
  91. int (*lookup)(struct dn_fib_table *t, const struct flowi *fl,
  92. struct dn_fib_res *res);
  93. int (*flush)(struct dn_fib_table *t);
  94. int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
  95. unsigned char data[0];
  96. };
  97. #ifdef CONFIG_DECNET_ROUTER
  98. /*
  99. * dn_fib.c
  100. */
  101. extern void dn_fib_init(void);
  102. extern void dn_fib_cleanup(void);
  103. extern int dn_fib_ioctl(struct socket *sock, unsigned int cmd,
  104. unsigned long arg);
  105. extern struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
  106. struct dn_kern_rta *rta,
  107. const struct nlmsghdr *nlh, int *errp);
  108. extern int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
  109. const struct flowi *fl,
  110. struct dn_fib_res *res);
  111. extern void dn_fib_release_info(struct dn_fib_info *fi);
  112. extern __le16 dn_fib_get_attr16(struct rtattr *attr, int attrlen, int type);
  113. extern void dn_fib_flush(void);
  114. extern void dn_fib_select_multipath(const struct flowi *fl,
  115. struct dn_fib_res *res);
  116. /*
  117. * dn_tables.c
  118. */
  119. extern struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
  120. extern struct dn_fib_table *dn_fib_empty_table(void);
  121. extern void dn_fib_table_init(void);
  122. extern void dn_fib_table_cleanup(void);
  123. /*
  124. * dn_rules.c
  125. */
  126. extern void dn_fib_rules_init(void);
  127. extern void dn_fib_rules_cleanup(void);
  128. extern unsigned dnet_addr_type(__le16 addr);
  129. extern int dn_fib_lookup(struct flowi *fl, struct dn_fib_res *res);
  130. extern int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
  131. extern void dn_fib_free_info(struct dn_fib_info *fi);
  132. static inline void dn_fib_info_put(struct dn_fib_info *fi)
  133. {
  134. if (atomic_dec_and_test(&fi->fib_clntref))
  135. dn_fib_free_info(fi);
  136. }
  137. static 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. #else /* Endnode */
  145. #define dn_fib_init() do { } while(0)
  146. #define dn_fib_cleanup() do { } while(0)
  147. #define dn_fib_lookup(fl, res) (-ESRCH)
  148. #define dn_fib_info_put(fi) do { } while(0)
  149. #define dn_fib_select_multipath(fl, res) do { } while(0)
  150. #define dn_fib_rules_policy(saddr,res,flags) (0)
  151. #define dn_fib_res_put(res) do { } while(0)
  152. #endif /* CONFIG_DECNET_ROUTER */
  153. static inline __le16 dnet_make_mask(int n)
  154. {
  155. if (n)
  156. return cpu_to_le16(~((1 << (16 - n)) - 1));
  157. return cpu_to_le16(0);
  158. }
  159. #endif /* _NET_DN_FIB_H */