fib_rules.h 2.5 KB

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