fib_rules.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 mark;
  15. u32 mark_mask;
  16. u32 pref;
  17. u32 flags;
  18. u32 table;
  19. u8 action;
  20. struct rcu_head rcu;
  21. };
  22. struct fib_lookup_arg
  23. {
  24. void *lookup_ptr;
  25. void *result;
  26. struct fib_rule *rule;
  27. };
  28. struct fib_rules_ops
  29. {
  30. int family;
  31. struct list_head list;
  32. int rule_size;
  33. int addr_size;
  34. int (*action)(struct fib_rule *,
  35. struct flowi *, int,
  36. struct fib_lookup_arg *);
  37. int (*match)(struct fib_rule *,
  38. struct flowi *, int);
  39. int (*configure)(struct fib_rule *,
  40. struct sk_buff *,
  41. struct nlmsghdr *,
  42. struct fib_rule_hdr *,
  43. struct nlattr **);
  44. int (*compare)(struct fib_rule *,
  45. struct fib_rule_hdr *,
  46. struct nlattr **);
  47. int (*fill)(struct fib_rule *, struct sk_buff *,
  48. struct nlmsghdr *,
  49. struct fib_rule_hdr *);
  50. u32 (*default_pref)(void);
  51. size_t (*nlmsg_payload)(struct fib_rule *);
  52. int nlgroup;
  53. struct nla_policy *policy;
  54. struct list_head *rules_list;
  55. struct module *owner;
  56. };
  57. #define FRA_GENERIC_POLICY \
  58. [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
  59. [FRA_PRIORITY] = { .type = NLA_U32 }, \
  60. [FRA_FWMARK] = { .type = NLA_U32 }, \
  61. [FRA_FWMASK] = { .type = NLA_U32 }, \
  62. [FRA_TABLE] = { .type = NLA_U32 }
  63. static inline void fib_rule_get(struct fib_rule *rule)
  64. {
  65. atomic_inc(&rule->refcnt);
  66. }
  67. static inline void fib_rule_put_rcu(struct rcu_head *head)
  68. {
  69. struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
  70. kfree(rule);
  71. }
  72. static inline void fib_rule_put(struct fib_rule *rule)
  73. {
  74. if (atomic_dec_and_test(&rule->refcnt))
  75. call_rcu(&rule->rcu, fib_rule_put_rcu);
  76. }
  77. static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
  78. {
  79. if (nla[FRA_TABLE])
  80. return nla_get_u32(nla[FRA_TABLE]);
  81. return frh->table;
  82. }
  83. extern int fib_rules_register(struct fib_rules_ops *);
  84. extern int fib_rules_unregister(struct fib_rules_ops *);
  85. extern int fib_rules_lookup(struct fib_rules_ops *,
  86. struct flowi *, int flags,
  87. struct fib_lookup_arg *);
  88. extern int fib_nl_newrule(struct sk_buff *,
  89. struct nlmsghdr *, void *);
  90. extern int fib_nl_delrule(struct sk_buff *,
  91. struct nlmsghdr *, void *);
  92. extern int fib_rules_dump(struct sk_buff *,
  93. struct netlink_callback *, int);
  94. #endif