fib_rules.h 3.0 KB

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