fib_rules.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef __NET_FIB_RULES_H
  2. #define __NET_FIB_RULES_H
  3. #include <linux/types.h>
  4. #include <linux/slab.h>
  5. #include <linux/netdevice.h>
  6. #include <linux/fib_rules.h>
  7. #include <net/flow.h>
  8. #include <net/rtnetlink.h>
  9. struct fib_kuid_range {
  10. kuid_t start;
  11. kuid_t end;
  12. };
  13. struct fib_rule {
  14. struct list_head list;
  15. atomic_t refcnt;
  16. int iifindex;
  17. int oifindex;
  18. u32 mark;
  19. u32 mark_mask;
  20. u32 pref;
  21. u32 flags;
  22. u32 table;
  23. u8 action;
  24. u32 target;
  25. struct fib_rule __rcu *ctarget;
  26. char iifname[IFNAMSIZ];
  27. char oifname[IFNAMSIZ];
  28. struct fib_kuid_range uid_range;
  29. struct rcu_head rcu;
  30. struct net * fr_net;
  31. };
  32. struct fib_lookup_arg {
  33. void *lookup_ptr;
  34. void *result;
  35. struct fib_rule *rule;
  36. int flags;
  37. #define FIB_LOOKUP_NOREF 1
  38. };
  39. struct fib_rules_ops {
  40. int family;
  41. struct list_head list;
  42. int rule_size;
  43. int addr_size;
  44. int unresolved_rules;
  45. int nr_goto_rules;
  46. int (*action)(struct fib_rule *,
  47. struct flowi *, int,
  48. struct fib_lookup_arg *);
  49. int (*match)(struct fib_rule *,
  50. struct flowi *, int);
  51. int (*configure)(struct fib_rule *,
  52. struct sk_buff *,
  53. struct fib_rule_hdr *,
  54. struct nlattr **);
  55. int (*compare)(struct fib_rule *,
  56. struct fib_rule_hdr *,
  57. struct nlattr **);
  58. int (*fill)(struct fib_rule *, struct sk_buff *,
  59. struct fib_rule_hdr *);
  60. u32 (*default_pref)(struct fib_rules_ops *ops);
  61. size_t (*nlmsg_payload)(struct fib_rule *);
  62. /* Called after modifications to the rules set, must flush
  63. * the route cache if one exists. */
  64. void (*flush_cache)(struct fib_rules_ops *ops);
  65. int nlgroup;
  66. const struct nla_policy *policy;
  67. struct list_head rules_list;
  68. struct module *owner;
  69. struct net *fro_net;
  70. struct rcu_head rcu;
  71. };
  72. #define FRA_GENERIC_POLICY \
  73. [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
  74. [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
  75. [FRA_PRIORITY] = { .type = NLA_U32 }, \
  76. [FRA_FWMARK] = { .type = NLA_U32 }, \
  77. [FRA_FWMASK] = { .type = NLA_U32 }, \
  78. [FRA_TABLE] = { .type = NLA_U32 }, \
  79. [FRA_GOTO] = { .type = NLA_U32 }, \
  80. [FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) }
  81. static inline void fib_rule_get(struct fib_rule *rule)
  82. {
  83. atomic_inc(&rule->refcnt);
  84. }
  85. static inline void fib_rule_put_rcu(struct rcu_head *head)
  86. {
  87. struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
  88. release_net(rule->fr_net);
  89. kfree(rule);
  90. }
  91. static inline void fib_rule_put(struct fib_rule *rule)
  92. {
  93. if (atomic_dec_and_test(&rule->refcnt))
  94. call_rcu(&rule->rcu, fib_rule_put_rcu);
  95. }
  96. static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
  97. {
  98. if (nla[FRA_TABLE])
  99. return nla_get_u32(nla[FRA_TABLE]);
  100. return frh->table;
  101. }
  102. extern struct fib_rules_ops *fib_rules_register(const struct fib_rules_ops *, struct net *);
  103. extern void fib_rules_unregister(struct fib_rules_ops *);
  104. extern int fib_rules_lookup(struct fib_rules_ops *,
  105. struct flowi *, int flags,
  106. struct fib_lookup_arg *);
  107. extern int fib_default_rule_add(struct fib_rules_ops *,
  108. u32 pref, u32 table,
  109. u32 flags);
  110. extern u32 fib_default_rule_pref(struct fib_rules_ops *ops);
  111. #endif