dn_fib.h 3.9 KB

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