fib_rules.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. struct net * fr_net;
  24. };
  25. struct fib_lookup_arg
  26. {
  27. void *lookup_ptr;
  28. void *result;
  29. struct fib_rule *rule;
  30. };
  31. struct fib_rules_ops
  32. {
  33. int family;
  34. struct list_head list;
  35. int rule_size;
  36. int addr_size;
  37. int unresolved_rules;
  38. int nr_goto_rules;
  39. int (*action)(struct fib_rule *,
  40. struct flowi *, int,
  41. struct fib_lookup_arg *);
  42. int (*match)(struct fib_rule *,
  43. struct flowi *, int);
  44. int (*configure)(struct fib_rule *,
  45. struct sk_buff *,
  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 fib_rule_hdr *);
  53. u32 (*default_pref)(struct fib_rules_ops *ops);
  54. size_t (*nlmsg_payload)(struct fib_rule *);
  55. /* Called after modifications to the rules set, must flush
  56. * the route cache if one exists. */
  57. void (*flush_cache)(struct fib_rules_ops *ops);
  58. int nlgroup;
  59. const struct nla_policy *policy;
  60. struct list_head rules_list;
  61. struct module *owner;
  62. struct net *fro_net;
  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. release_net(rule->fr_net);
  79. kfree(rule);
  80. }
  81. static inline void fib_rule_put(struct fib_rule *rule)
  82. {
  83. if (atomic_dec_and_test(&rule->refcnt))
  84. call_rcu(&rule->rcu, fib_rule_put_rcu);
  85. }
  86. static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
  87. {
  88. if (nla[FRA_TABLE])
  89. return nla_get_u32(nla[FRA_TABLE]);
  90. return frh->table;
  91. }
  92. extern int fib_rules_register(struct fib_rules_ops *);
  93. extern void fib_rules_unregister(struct fib_rules_ops *);
  94. extern void fib_rules_cleanup_ops(struct fib_rules_ops *);
  95. extern int fib_rules_lookup(struct fib_rules_ops *,
  96. struct flowi *, int flags,
  97. struct fib_lookup_arg *);
  98. extern int fib_default_rule_add(struct fib_rules_ops *,
  99. u32 pref, u32 table,
  100. u32 flags);
  101. #endif