fib_rules.h 2.8 KB

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