dn_fib.h 4.0 KB

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