blob: c07ac9650ebc00219418dcca80abf828e30dbcd8 [file] [log] [blame]
Thomas Graf14c0b972006-08-04 03:38:38 -07001#ifndef __NET_FIB_RULES_H
2#define __NET_FIB_RULES_H
3
4#include <linux/types.h>
5#include <linux/netdevice.h>
6#include <linux/fib_rules.h>
7#include <net/flow.h>
Thomas Graf9d9e6a52007-03-25 23:20:05 -07008#include <net/rtnetlink.h>
Thomas Graf14c0b972006-08-04 03:38:38 -07009
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000010struct fib_rule {
Thomas Graf14c0b972006-08-04 03:38:38 -070011 struct list_head list;
12 atomic_t refcnt;
Patrick McHardy491deb24b2009-12-03 01:25:54 +000013 int iifindex;
Patrick McHardy1b038a52009-12-03 01:25:56 +000014 int oifindex;
Thomas Grafb8964ed2006-11-09 15:22:18 -080015 u32 mark;
16 u32 mark_mask;
Thomas Graf14c0b972006-08-04 03:38:38 -070017 u32 pref;
18 u32 flags;
19 u32 table;
20 u8 action;
Thomas Graf0947c9fe2007-03-26 17:14:15 -070021 u32 target;
22 struct fib_rule * ctarget;
Patrick McHardy491deb24b2009-12-03 01:25:54 +000023 char iifname[IFNAMSIZ];
Patrick McHardy1b038a52009-12-03 01:25:56 +000024 char oifname[IFNAMSIZ];
Thomas Graf14c0b972006-08-04 03:38:38 -070025 struct rcu_head rcu;
Denis V. Lunev51314a12008-01-20 16:47:09 -080026 struct net * fr_net;
Thomas Graf14c0b972006-08-04 03:38:38 -070027};
28
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000029struct fib_lookup_arg {
Thomas Graf14c0b972006-08-04 03:38:38 -070030 void *lookup_ptr;
31 void *result;
32 struct fib_rule *rule;
33};
34
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000035struct fib_rules_ops {
Thomas Graf14c0b972006-08-04 03:38:38 -070036 int family;
37 struct list_head list;
38 int rule_size;
Thomas Grafe1701c62007-03-24 12:46:02 -070039 int addr_size;
Thomas Graf0947c9fe2007-03-26 17:14:15 -070040 int unresolved_rules;
41 int nr_goto_rules;
Thomas Graf14c0b972006-08-04 03:38:38 -070042
43 int (*action)(struct fib_rule *,
44 struct flowi *, int,
45 struct fib_lookup_arg *);
46 int (*match)(struct fib_rule *,
47 struct flowi *, int);
48 int (*configure)(struct fib_rule *,
49 struct sk_buff *,
Thomas Graf14c0b972006-08-04 03:38:38 -070050 struct fib_rule_hdr *,
51 struct nlattr **);
52 int (*compare)(struct fib_rule *,
53 struct fib_rule_hdr *,
54 struct nlattr **);
55 int (*fill)(struct fib_rule *, struct sk_buff *,
Thomas Graf14c0b972006-08-04 03:38:38 -070056 struct fib_rule_hdr *);
Denis V. Lunev868d13a2008-01-10 03:18:25 -080057 u32 (*default_pref)(struct fib_rules_ops *ops);
Thomas Graf339bf982006-11-10 14:10:15 -080058 size_t (*nlmsg_payload)(struct fib_rule *);
Thomas Graf14c0b972006-08-04 03:38:38 -070059
Thomas Graf73417f62007-03-27 13:56:52 -070060 /* Called after modifications to the rules set, must flush
61 * the route cache if one exists. */
Denis V. Lunevae299fc2008-07-05 19:01:28 -070062 void (*flush_cache)(struct fib_rules_ops *ops);
Thomas Graf73417f62007-03-27 13:56:52 -070063
Thomas Graf14c0b972006-08-04 03:38:38 -070064 int nlgroup;
Patrick McHardyef7c79e2007-06-05 12:38:30 -070065 const struct nla_policy *policy;
Denis V. Lunev76c72d42007-09-16 15:44:27 -070066 struct list_head rules_list;
Thomas Graf14c0b972006-08-04 03:38:38 -070067 struct module *owner;
Denis V. Lunev035923832008-01-20 16:46:01 -080068 struct net *fro_net;
Eric W. Biedermane9c51582009-12-03 12:22:55 -080069 struct rcu_head rcu;
Thomas Graf14c0b972006-08-04 03:38:38 -070070};
71
Thomas Graf1f6c9552006-11-09 15:22:48 -080072#define FRA_GENERIC_POLICY \
Patrick McHardy491deb24b2009-12-03 01:25:54 +000073 [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
Patrick McHardy1b038a52009-12-03 01:25:56 +000074 [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
Thomas Graf1f6c9552006-11-09 15:22:48 -080075 [FRA_PRIORITY] = { .type = NLA_U32 }, \
76 [FRA_FWMARK] = { .type = NLA_U32 }, \
77 [FRA_FWMASK] = { .type = NLA_U32 }, \
Thomas Graf0947c9fe2007-03-26 17:14:15 -070078 [FRA_TABLE] = { .type = NLA_U32 }, \
79 [FRA_GOTO] = { .type = NLA_U32 }
Thomas Graf1f6c9552006-11-09 15:22:48 -080080
Thomas Graf14c0b972006-08-04 03:38:38 -070081static inline void fib_rule_get(struct fib_rule *rule)
82{
83 atomic_inc(&rule->refcnt);
84}
85
86static inline void fib_rule_put_rcu(struct rcu_head *head)
87{
88 struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
Denis V. Lunev3661a912008-04-16 02:01:56 -070089 release_net(rule->fr_net);
Thomas Graf14c0b972006-08-04 03:38:38 -070090 kfree(rule);
91}
92
93static inline void fib_rule_put(struct fib_rule *rule)
94{
95 if (atomic_dec_and_test(&rule->refcnt))
96 call_rcu(&rule->rcu, fib_rule_put_rcu);
97}
98
Patrick McHardy9e762a42006-08-10 23:09:48 -070099static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
100{
101 if (nla[FRA_TABLE])
102 return nla_get_u32(nla[FRA_TABLE]);
103 return frh->table;
104}
105
Eric W. Biedermane9c51582009-12-03 12:22:55 -0800106extern struct fib_rules_ops *fib_rules_register(struct fib_rules_ops *, struct net *);
Denis V. Lunev9e3a5482008-01-20 16:46:41 -0800107extern void fib_rules_unregister(struct fib_rules_ops *);
Daniel Lezcano9eb87f32007-12-07 00:42:52 -0800108extern void fib_rules_cleanup_ops(struct fib_rules_ops *);
Thomas Graf14c0b972006-08-04 03:38:38 -0700109
110extern int fib_rules_lookup(struct fib_rules_ops *,
111 struct flowi *, int flags,
112 struct fib_lookup_arg *);
Denis V. Lunev2994c632007-11-10 22:12:03 -0800113extern int fib_default_rule_add(struct fib_rules_ops *,
114 u32 pref, u32 table,
115 u32 flags);
Thomas Graf14c0b972006-08-04 03:38:38 -0700116#endif