fib_rules.h 2.8 KB

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