Commit | Line | Data |
---|---|---|
14c0b97d TG |
1 | #ifndef __NET_FIB_RULES_H |
2 | #define __NET_FIB_RULES_H | |
3 | ||
4 | #include <linux/types.h> | |
5a0e3ad6 | 5 | #include <linux/slab.h> |
14c0b97d TG |
6 | #include <linux/netdevice.h> |
7 | #include <linux/fib_rules.h> | |
8 | #include <net/flow.h> | |
9d9e6a58 | 9 | #include <net/rtnetlink.h> |
14c0b97d | 10 | |
fd2c3ef7 | 11 | struct fib_rule { |
14c0b97d TG |
12 | struct list_head list; |
13 | atomic_t refcnt; | |
491deb24 | 14 | int iifindex; |
1b038a5e | 15 | int oifindex; |
b8964ed9 TG |
16 | u32 mark; |
17 | u32 mark_mask; | |
14c0b97d TG |
18 | u32 pref; |
19 | u32 flags; | |
20 | u32 table; | |
7764a45a | 21 | u8 table_prefixlen_min; |
14c0b97d | 22 | u8 action; |
0947c9fe | 23 | u32 target; |
7a2b03c5 | 24 | struct fib_rule __rcu *ctarget; |
491deb24 | 25 | char iifname[IFNAMSIZ]; |
1b038a5e | 26 | char oifname[IFNAMSIZ]; |
14c0b97d | 27 | struct rcu_head rcu; |
51314a17 | 28 | struct net * fr_net; |
14c0b97d TG |
29 | }; |
30 | ||
fd2c3ef7 | 31 | struct fib_lookup_arg { |
14c0b97d TG |
32 | void *lookup_ptr; |
33 | void *result; | |
34 | struct fib_rule *rule; | |
ebc0ffae ED |
35 | int flags; |
36 | #define FIB_LOOKUP_NOREF 1 | |
14c0b97d TG |
37 | }; |
38 | ||
fd2c3ef7 | 39 | struct fib_rules_ops { |
14c0b97d TG |
40 | int family; |
41 | struct list_head list; | |
42 | int rule_size; | |
e1701c68 | 43 | int addr_size; |
0947c9fe TG |
44 | int unresolved_rules; |
45 | int nr_goto_rules; | |
14c0b97d TG |
46 | |
47 | int (*action)(struct fib_rule *, | |
48 | struct flowi *, int, | |
49 | struct fib_lookup_arg *); | |
7764a45a ST |
50 | bool (*suppress)(struct fib_rule *, |
51 | struct fib_lookup_arg *); | |
14c0b97d TG |
52 | int (*match)(struct fib_rule *, |
53 | struct flowi *, int); | |
54 | int (*configure)(struct fib_rule *, | |
55 | struct sk_buff *, | |
14c0b97d TG |
56 | struct fib_rule_hdr *, |
57 | struct nlattr **); | |
7a9bc9b8 | 58 | void (*delete)(struct fib_rule *); |
14c0b97d TG |
59 | int (*compare)(struct fib_rule *, |
60 | struct fib_rule_hdr *, | |
61 | struct nlattr **); | |
62 | int (*fill)(struct fib_rule *, struct sk_buff *, | |
14c0b97d | 63 | struct fib_rule_hdr *); |
868d13ac | 64 | u32 (*default_pref)(struct fib_rules_ops *ops); |
339bf98f | 65 | size_t (*nlmsg_payload)(struct fib_rule *); |
14c0b97d | 66 | |
73417f61 TG |
67 | /* Called after modifications to the rules set, must flush |
68 | * the route cache if one exists. */ | |
ae299fc0 | 69 | void (*flush_cache)(struct fib_rules_ops *ops); |
73417f61 | 70 | |
14c0b97d | 71 | int nlgroup; |
ef7c79ed | 72 | const struct nla_policy *policy; |
76c72d4f | 73 | struct list_head rules_list; |
14c0b97d | 74 | struct module *owner; |
03592383 | 75 | struct net *fro_net; |
e9c5158a | 76 | struct rcu_head rcu; |
14c0b97d TG |
77 | }; |
78 | ||
1f6c9557 | 79 | #define FRA_GENERIC_POLICY \ |
491deb24 | 80 | [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ |
1b038a5e | 81 | [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ |
1f6c9557 TG |
82 | [FRA_PRIORITY] = { .type = NLA_U32 }, \ |
83 | [FRA_FWMARK] = { .type = NLA_U32 }, \ | |
84 | [FRA_FWMASK] = { .type = NLA_U32 }, \ | |
0947c9fe | 85 | [FRA_TABLE] = { .type = NLA_U32 }, \ |
7764a45a | 86 | [FRA_TABLE_PREFIXLEN_MIN] = { .type = NLA_U8 }, \ |
0947c9fe | 87 | [FRA_GOTO] = { .type = NLA_U32 } |
1f6c9557 | 88 | |
14c0b97d TG |
89 | static inline void fib_rule_get(struct fib_rule *rule) |
90 | { | |
91 | atomic_inc(&rule->refcnt); | |
92 | } | |
93 | ||
94 | static inline void fib_rule_put_rcu(struct rcu_head *head) | |
95 | { | |
96 | struct fib_rule *rule = container_of(head, struct fib_rule, rcu); | |
3661a910 | 97 | release_net(rule->fr_net); |
14c0b97d TG |
98 | kfree(rule); |
99 | } | |
100 | ||
101 | static inline void fib_rule_put(struct fib_rule *rule) | |
102 | { | |
103 | if (atomic_dec_and_test(&rule->refcnt)) | |
104 | call_rcu(&rule->rcu, fib_rule_put_rcu); | |
105 | } | |
106 | ||
9e762a4a PM |
107 | static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla) |
108 | { | |
109 | if (nla[FRA_TABLE]) | |
110 | return nla_get_u32(nla[FRA_TABLE]); | |
111 | return frh->table; | |
112 | } | |
113 | ||
3d0c9c4e | 114 | extern struct fib_rules_ops *fib_rules_register(const struct fib_rules_ops *, struct net *); |
9e3a5487 | 115 | extern void fib_rules_unregister(struct fib_rules_ops *); |
14c0b97d TG |
116 | |
117 | extern int fib_rules_lookup(struct fib_rules_ops *, | |
118 | struct flowi *, int flags, | |
119 | struct fib_lookup_arg *); | |
2994c638 DL |
120 | extern int fib_default_rule_add(struct fib_rules_ops *, |
121 | u32 pref, u32 table, | |
122 | u32 flags); | |
d8a566be | 123 | extern u32 fib_default_rule_pref(struct fib_rules_ops *ops); |
14c0b97d | 124 | #endif |