blob: bc3c26494c3d2f4b578be0d12f4c20fd8e1b127c [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>
8#include <net/netlink.h>
9
10struct fib_rule
11{
12 struct list_head list;
13 atomic_t refcnt;
14 int ifindex;
15 char ifname[IFNAMSIZ];
Thomas Grafb8964ed2006-11-09 15:22:18 -080016 u32 mark;
17 u32 mark_mask;
Thomas Graf14c0b972006-08-04 03:38:38 -070018 u32 pref;
19 u32 flags;
20 u32 table;
21 u8 action;
22 struct rcu_head rcu;
23};
24
25struct fib_lookup_arg
26{
27 void *lookup_ptr;
28 void *result;
29 struct fib_rule *rule;
30};
31
32struct fib_rules_ops
33{
34 int family;
35 struct list_head list;
36 int rule_size;
37
38 int (*action)(struct fib_rule *,
39 struct flowi *, int,
40 struct fib_lookup_arg *);
41 int (*match)(struct fib_rule *,
42 struct flowi *, int);
43 int (*configure)(struct fib_rule *,
44 struct sk_buff *,
45 struct nlmsghdr *,
46 struct fib_rule_hdr *,
47 struct nlattr **);
48 int (*compare)(struct fib_rule *,
49 struct fib_rule_hdr *,
50 struct nlattr **);
51 int (*fill)(struct fib_rule *, struct sk_buff *,
52 struct nlmsghdr *,
53 struct fib_rule_hdr *);
54 u32 (*default_pref)(void);
Thomas Graf339bf982006-11-10 14:10:15 -080055 size_t (*nlmsg_payload)(struct fib_rule *);
Thomas Graf14c0b972006-08-04 03:38:38 -070056
57 int nlgroup;
58 struct nla_policy *policy;
59 struct list_head *rules_list;
60 struct module *owner;
61};
62
Thomas Graf1f6c9552006-11-09 15:22:48 -080063#define FRA_GENERIC_POLICY \
64 [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
65 [FRA_PRIORITY] = { .type = NLA_U32 }, \
66 [FRA_FWMARK] = { .type = NLA_U32 }, \
67 [FRA_FWMASK] = { .type = NLA_U32 }, \
68 [FRA_TABLE] = { .type = NLA_U32 }
69
Thomas Graf14c0b972006-08-04 03:38:38 -070070static inline void fib_rule_get(struct fib_rule *rule)
71{
72 atomic_inc(&rule->refcnt);
73}
74
75static inline void fib_rule_put_rcu(struct rcu_head *head)
76{
77 struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
78 kfree(rule);
79}
80
81static inline void fib_rule_put(struct fib_rule *rule)
82{
83 if (atomic_dec_and_test(&rule->refcnt))
84 call_rcu(&rule->rcu, fib_rule_put_rcu);
85}
86
Patrick McHardy9e762a42006-08-10 23:09:48 -070087static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
88{
89 if (nla[FRA_TABLE])
90 return nla_get_u32(nla[FRA_TABLE]);
91 return frh->table;
92}
93
Thomas Graf14c0b972006-08-04 03:38:38 -070094extern int fib_rules_register(struct fib_rules_ops *);
95extern int fib_rules_unregister(struct fib_rules_ops *);
96
97extern int fib_rules_lookup(struct fib_rules_ops *,
98 struct flowi *, int flags,
99 struct fib_lookup_arg *);
100
101extern int fib_nl_newrule(struct sk_buff *,
102 struct nlmsghdr *, void *);
103extern int fib_nl_delrule(struct sk_buff *,
104 struct nlmsghdr *, void *);
105extern int fib_rules_dump(struct sk_buff *,
106 struct netlink_callback *, int);
107#endif