fib_rules.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. };
  24. struct fib_lookup_arg
  25. {
  26. void *lookup_ptr;
  27. void *result;
  28. struct fib_rule *rule;
  29. };
  30. struct fib_rules_ops
  31. {
  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 nlmsghdr *,
  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 nlmsghdr *,
  53. struct fib_rule_hdr *);
  54. u32 (*default_pref)(void);
  55. size_t (*nlmsg_payload)(struct fib_rule *);
  56. int nlgroup;
  57. struct nla_policy *policy;
  58. struct list_head *rules_list;
  59. struct module *owner;
  60. };
  61. #define FRA_GENERIC_POLICY \
  62. [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
  63. [FRA_PRIORITY] = { .type = NLA_U32 }, \
  64. [FRA_FWMARK] = { .type = NLA_U32 }, \
  65. [FRA_FWMASK] = { .type = NLA_U32 }, \
  66. [FRA_TABLE] = { .type = NLA_U32 }, \
  67. [FRA_GOTO] = { .type = NLA_U32 }
  68. static inline void fib_rule_get(struct fib_rule *rule)
  69. {
  70. atomic_inc(&rule->refcnt);
  71. }
  72. static inline void fib_rule_put_rcu(struct rcu_head *head)
  73. {
  74. struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
  75. kfree(rule);
  76. }
  77. static inline void fib_rule_put(struct fib_rule *rule)
  78. {
  79. if (atomic_dec_and_test(&rule->refcnt))
  80. call_rcu(&rule->rcu, fib_rule_put_rcu);
  81. }
  82. static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
  83. {
  84. if (nla[FRA_TABLE])
  85. return nla_get_u32(nla[FRA_TABLE]);
  86. return frh->table;
  87. }
  88. extern int fib_rules_register(struct fib_rules_ops *);
  89. extern int fib_rules_unregister(struct fib_rules_ops *);
  90. extern int fib_rules_lookup(struct fib_rules_ops *,
  91. struct flowi *, int flags,
  92. struct fib_lookup_arg *);
  93. #endif