fib_rules.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. extern int fib_rules_register(struct fib_rules_ops *);
  68. extern int fib_rules_unregister(struct fib_rules_ops *);
  69. extern int fib_rules_lookup(struct fib_rules_ops *,
  70. struct flowi *, int flags,
  71. struct fib_lookup_arg *);
  72. extern int fib_nl_newrule(struct sk_buff *,
  73. struct nlmsghdr *, void *);
  74. extern int fib_nl_delrule(struct sk_buff *,
  75. struct nlmsghdr *, void *);
  76. extern int fib_rules_dump(struct sk_buff *,
  77. struct netlink_callback *, int);
  78. #endif