fib_rules.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/netlink.h>
  8. struct fib_rule
  9. {
  10. struct list_head list;
  11. atomic_t refcnt;
  12. int ifindex;
  13. char ifname[IFNAMSIZ];
  14. u32 pref;
  15. u32 flags;
  16. u32 table;
  17. u8 action;
  18. struct rcu_head rcu;
  19. };
  20. struct fib_lookup_arg
  21. {
  22. void *lookup_ptr;
  23. void *result;
  24. struct fib_rule *rule;
  25. };
  26. struct fib_rules_ops
  27. {
  28. int family;
  29. struct list_head list;
  30. int rule_size;
  31. int (*action)(struct fib_rule *,
  32. struct flowi *, int,
  33. struct fib_lookup_arg *);
  34. int (*match)(struct fib_rule *,
  35. struct flowi *, int);
  36. int (*configure)(struct fib_rule *,
  37. struct sk_buff *,
  38. struct nlmsghdr *,
  39. struct fib_rule_hdr *,
  40. struct nlattr **);
  41. int (*compare)(struct fib_rule *,
  42. struct fib_rule_hdr *,
  43. struct nlattr **);
  44. int (*fill)(struct fib_rule *, struct sk_buff *,
  45. struct nlmsghdr *,
  46. struct fib_rule_hdr *);
  47. u32 (*default_pref)(void);
  48. int nlgroup;
  49. struct nla_policy *policy;
  50. struct list_head *rules_list;
  51. struct module *owner;
  52. };
  53. static inline void fib_rule_get(struct fib_rule *rule)
  54. {
  55. atomic_inc(&rule->refcnt);
  56. }
  57. static inline void fib_rule_put_rcu(struct rcu_head *head)
  58. {
  59. struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
  60. kfree(rule);
  61. }
  62. static inline void fib_rule_put(struct fib_rule *rule)
  63. {
  64. if (atomic_dec_and_test(&rule->refcnt))
  65. call_rcu(&rule->rcu, fib_rule_put_rcu);
  66. }
  67. static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
  68. {
  69. if (nla[FRA_TABLE])
  70. return nla_get_u32(nla[FRA_TABLE]);
  71. return frh->table;
  72. }
  73. extern int fib_rules_register(struct fib_rules_ops *);
  74. extern int fib_rules_unregister(struct fib_rules_ops *);
  75. extern int fib_rules_lookup(struct fib_rules_ops *,
  76. struct flowi *, int flags,
  77. struct fib_lookup_arg *);
  78. extern int fib_nl_newrule(struct sk_buff *,
  79. struct nlmsghdr *, void *);
  80. extern int fib_nl_delrule(struct sk_buff *,
  81. struct nlmsghdr *, void *);
  82. extern int fib_rules_dump(struct sk_buff *,
  83. struct netlink_callback *, int);
  84. #endif