fib_rules.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __NET_FIB_RULES_H
  2. #define __NET_FIB_RULES_H
  3. #include <linux/types.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/fib_rules.h>
  6. #include <net/flow.h>
  7. #include <net/rtnetlink.h>
  8. struct fib_rule
  9. {
  10. struct list_head list;
  11. atomic_t refcnt;
  12. int ifindex;
  13. char ifname[IFNAMSIZ];
  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 * ctarget;
  22. struct rcu_head rcu;
  23. };
  24. struct fib_lookup_arg
  25. {
  26. void *lookup_ptr;
  27. void *result;
  28. struct fib_rule *rule;
  29. };
  30. struct fib_rules_ops
  31. {
  32. int family;
  33. struct list_head list;
  34. int rule_size;
  35. int addr_size;
  36. int unresolved_rules;
  37. int nr_goto_rules;
  38. int (*action)(struct fib_rule *,
  39. struct flowi *, int,
  40. struct fib_lookup_arg *);
  41. int (*match)(struct fib_rule *,
  42. struct flowi *, int);
  43. int (*configure)(struct fib_rule *,
  44. struct sk_buff *,
  45. struct nlmsghdr *,
  46. struct fib_rule_hdr *,
  47. struct nlattr **);
  48. int (*compare)(struct fib_rule *,
  49. struct fib_rule_hdr *,
  50. struct nlattr **);
  51. int (*fill)(struct fib_rule *, struct sk_buff *,
  52. struct nlmsghdr *,
  53. struct fib_rule_hdr *);
  54. u32 (*default_pref)(void);
  55. size_t (*nlmsg_payload)(struct fib_rule *);
  56. /* Called after modifications to the rules set, must flush
  57. * the route cache if one exists. */
  58. void (*flush_cache)(void);
  59. int nlgroup;
  60. const struct nla_policy *policy;
  61. struct list_head rules_list;
  62. struct module *owner;
  63. };
  64. #define FRA_GENERIC_POLICY \
  65. [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
  66. [FRA_PRIORITY] = { .type = NLA_U32 }, \
  67. [FRA_FWMARK] = { .type = NLA_U32 }, \
  68. [FRA_FWMASK] = { .type = NLA_U32 }, \
  69. [FRA_TABLE] = { .type = NLA_U32 }, \
  70. [FRA_GOTO] = { .type = NLA_U32 }
  71. static inline void fib_rule_get(struct fib_rule *rule)
  72. {
  73. atomic_inc(&rule->refcnt);
  74. }
  75. static inline void fib_rule_put_rcu(struct rcu_head *head)
  76. {
  77. struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
  78. kfree(rule);
  79. }
  80. static inline void fib_rule_put(struct fib_rule *rule)
  81. {
  82. if (atomic_dec_and_test(&rule->refcnt))
  83. call_rcu(&rule->rcu, fib_rule_put_rcu);
  84. }
  85. static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
  86. {
  87. if (nla[FRA_TABLE])
  88. return nla_get_u32(nla[FRA_TABLE]);
  89. return frh->table;
  90. }
  91. extern int fib_rules_register(struct fib_rules_ops *);
  92. extern int fib_rules_unregister(struct fib_rules_ops *);
  93. extern int fib_rules_lookup(struct fib_rules_ops *,
  94. struct flowi *, int flags,
  95. struct fib_lookup_arg *);
  96. #endif