dn_fib.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 dn_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. u32 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. dn_address 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. u16 datum;
  67. } dn_fib_key_t;
  68. typedef struct {
  69. u16 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. int 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 u16 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. extern int dn_fib_sync_down(dn_address local, struct net_device *dev,
  117. int force);
  118. extern int dn_fib_sync_up(struct net_device *dev);
  119. /*
  120. * dn_tables.c
  121. */
  122. extern struct dn_fib_table *dn_fib_get_table(int n, int creat);
  123. extern struct dn_fib_table *dn_fib_empty_table(void);
  124. extern void dn_fib_table_init(void);
  125. extern void dn_fib_table_cleanup(void);
  126. /*
  127. * dn_rules.c
  128. */
  129. extern void dn_fib_rules_init(void);
  130. extern void dn_fib_rules_cleanup(void);
  131. extern void dn_fib_rule_put(struct dn_fib_rule *);
  132. extern __u16 dn_fib_rules_policy(__u16 saddr, struct dn_fib_res *res, unsigned *flags);
  133. extern unsigned dnet_addr_type(__u16 addr);
  134. extern int dn_fib_lookup(const struct flowi *fl, struct dn_fib_res *res);
  135. /*
  136. * rtnetlink interface
  137. */
  138. extern int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
  139. extern int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
  140. extern int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
  141. extern int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
  142. extern int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
  143. extern int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
  144. extern void dn_fib_free_info(struct dn_fib_info *fi);
  145. static inline void dn_fib_info_put(struct dn_fib_info *fi)
  146. {
  147. if (atomic_dec_and_test(&fi->fib_clntref))
  148. dn_fib_free_info(fi);
  149. }
  150. static inline void dn_fib_res_put(struct dn_fib_res *res)
  151. {
  152. if (res->fi)
  153. dn_fib_info_put(res->fi);
  154. if (res->r)
  155. dn_fib_rule_put(res->r);
  156. }
  157. extern struct dn_fib_table *dn_fib_tables[];
  158. #else /* Endnode */
  159. #define dn_fib_init() do { } while(0)
  160. #define dn_fib_cleanup() do { } while(0)
  161. #define dn_fib_lookup(fl, res) (-ESRCH)
  162. #define dn_fib_info_put(fi) do { } while(0)
  163. #define dn_fib_select_multipath(fl, res) do { } while(0)
  164. #define dn_fib_rules_policy(saddr,res,flags) (0)
  165. #define dn_fib_res_put(res) do { } while(0)
  166. #endif /* CONFIG_DECNET_ROUTER */
  167. static inline u16 dnet_make_mask(int n)
  168. {
  169. if (n)
  170. return htons(~((1<<(16-n))-1));
  171. return 0;
  172. }
  173. #endif /* _NET_DN_FIB_H */