fib_rules.h 3.1 KB

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