dn_fib.h 5.2 KB

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