fib_rules.h 2.9 KB

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