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. 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. __be64 tun_id;
  21. struct fib_rule __rcu *ctarget;
  22. struct net *fr_net;
  23. atomic_t refcnt;
  24. u32 pref;
  25. int suppress_ifgroup;
  26. int suppress_prefixlen;
  27. char iifname[IFNAMSIZ];
  28. char oifname[IFNAMSIZ];
  29. struct rcu_head rcu;
  30. };
  31. struct fib_lookup_arg {
  32. void *lookup_ptr;
  33. void *result;
  34. struct fib_rule *rule;
  35. int flags;
  36. #define FIB_LOOKUP_NOREF 1
  37. #define FIB_LOOKUP_IGNORE_LINKSTATE 2
  38. };
  39. struct fib_rules_ops {
  40. int family;
  41. struct list_head list;
  42. int rule_size;
  43. int addr_size;
  44. int unresolved_rules;
  45. int nr_goto_rules;
  46. int (*action)(struct fib_rule *,
  47. struct flowi *, int,
  48. struct fib_lookup_arg *);
  49. bool (*suppress)(struct fib_rule *,
  50. struct fib_lookup_arg *);
  51. int (*match)(struct fib_rule *,
  52. struct flowi *, int);
  53. int (*configure)(struct fib_rule *,
  54. struct sk_buff *,
  55. struct fib_rule_hdr *,
  56. struct nlattr **);
  57. int (*delete)(struct fib_rule *);
  58. int (*compare)(struct fib_rule *,
  59. struct fib_rule_hdr *,
  60. struct nlattr **);
  61. int (*fill)(struct fib_rule *, struct sk_buff *,
  62. struct fib_rule_hdr *);
  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. #endif