Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 1 | #ifndef __NET_FIB_RULES_H |
| 2 | #define __NET_FIB_RULES_H |
| 3 | |
| 4 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 5 | #include <linux/slab.h> |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 6 | #include <linux/netdevice.h> |
| 7 | #include <linux/fib_rules.h> |
| 8 | #include <net/flow.h> |
Thomas Graf | 9d9e6a5 | 2007-03-25 23:20:05 -0700 | [diff] [blame] | 9 | #include <net/rtnetlink.h> |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 10 | |
Lorenzo Colitti | 2ec93fe | 2016-11-04 02:23:42 +0900 | [diff] [blame] | 11 | struct fib_kuid_range { |
| 12 | kuid_t start; |
| 13 | kuid_t end; |
| 14 | }; |
| 15 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 16 | struct fib_rule { |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 17 | struct list_head list; |
Patrick McHardy | 491deb24b | 2009-12-03 01:25:54 +0000 | [diff] [blame] | 18 | int iifindex; |
Patrick McHardy | 1b038a5 | 2009-12-03 01:25:56 +0000 | [diff] [blame] | 19 | int oifindex; |
Thomas Graf | b8964ed | 2006-11-09 15:22:18 -0800 | [diff] [blame] | 20 | u32 mark; |
| 21 | u32 mark_mask; |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 22 | u32 flags; |
| 23 | u32 table; |
| 24 | u8 action; |
David Ahern | 96c63fa | 2016-06-08 10:55:39 -0700 | [diff] [blame] | 25 | u8 l3mdev; |
| 26 | /* 2 bytes hole, try to use */ |
Thomas Graf | 0947c9fe | 2007-03-26 17:14:15 -0700 | [diff] [blame] | 27 | u32 target; |
Thomas Graf | e703087 | 2015-07-21 10:44:01 +0200 | [diff] [blame] | 28 | __be64 tun_id; |
Eric Dumazet | 7a2b03c | 2010-10-26 09:24:55 +0000 | [diff] [blame] | 29 | struct fib_rule __rcu *ctarget; |
Eric Dumazet | fba3679 | 2013-08-03 11:50:35 -0700 | [diff] [blame] | 30 | struct net *fr_net; |
| 31 | |
| 32 | atomic_t refcnt; |
| 33 | u32 pref; |
| 34 | int suppress_ifgroup; |
| 35 | int suppress_prefixlen; |
Patrick McHardy | 491deb24b | 2009-12-03 01:25:54 +0000 | [diff] [blame] | 36 | char iifname[IFNAMSIZ]; |
Patrick McHardy | 1b038a5 | 2009-12-03 01:25:56 +0000 | [diff] [blame] | 37 | char oifname[IFNAMSIZ]; |
Lorenzo Colitti | 2ec93fe | 2016-11-04 02:23:42 +0900 | [diff] [blame] | 38 | struct fib_kuid_range uid_range; |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 39 | struct rcu_head rcu; |
| 40 | }; |
| 41 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 42 | struct fib_lookup_arg { |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 43 | void *lookup_ptr; |
| 44 | void *result; |
| 45 | struct fib_rule *rule; |
David Ahern | 96c63fa | 2016-06-08 10:55:39 -0700 | [diff] [blame] | 46 | u32 table; |
Eric Dumazet | ebc0ffa | 2010-10-05 10:41:36 +0000 | [diff] [blame] | 47 | int flags; |
Andy Gospodarek | 0eeb075 | 2015-06-23 13:45:37 -0400 | [diff] [blame] | 48 | #define FIB_LOOKUP_NOREF 1 |
| 49 | #define FIB_LOOKUP_IGNORE_LINKSTATE 2 |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 52 | struct fib_rules_ops { |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 53 | int family; |
| 54 | struct list_head list; |
| 55 | int rule_size; |
Thomas Graf | e1701c6 | 2007-03-24 12:46:02 -0700 | [diff] [blame] | 56 | int addr_size; |
Thomas Graf | 0947c9fe | 2007-03-26 17:14:15 -0700 | [diff] [blame] | 57 | int unresolved_rules; |
| 58 | int nr_goto_rules; |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 59 | |
| 60 | int (*action)(struct fib_rule *, |
| 61 | struct flowi *, int, |
| 62 | struct fib_lookup_arg *); |
Stefan Tomanek | 7764a45 | 2013-08-01 02:17:15 +0200 | [diff] [blame] | 63 | bool (*suppress)(struct fib_rule *, |
| 64 | struct fib_lookup_arg *); |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 65 | int (*match)(struct fib_rule *, |
| 66 | struct flowi *, int); |
| 67 | int (*configure)(struct fib_rule *, |
| 68 | struct sk_buff *, |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 69 | struct fib_rule_hdr *, |
| 70 | struct nlattr **); |
Alexander Duyck | 0ddcf43 | 2015-03-06 13:47:00 -0800 | [diff] [blame] | 71 | int (*delete)(struct fib_rule *); |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 72 | int (*compare)(struct fib_rule *, |
| 73 | struct fib_rule_hdr *, |
| 74 | struct nlattr **); |
| 75 | int (*fill)(struct fib_rule *, struct sk_buff *, |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 76 | struct fib_rule_hdr *); |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 77 | size_t (*nlmsg_payload)(struct fib_rule *); |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 78 | |
Thomas Graf | 73417f6 | 2007-03-27 13:56:52 -0700 | [diff] [blame] | 79 | /* Called after modifications to the rules set, must flush |
| 80 | * the route cache if one exists. */ |
Denis V. Lunev | ae299fc | 2008-07-05 19:01:28 -0700 | [diff] [blame] | 81 | void (*flush_cache)(struct fib_rules_ops *ops); |
Thomas Graf | 73417f6 | 2007-03-27 13:56:52 -0700 | [diff] [blame] | 82 | |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 83 | int nlgroup; |
Patrick McHardy | ef7c79e | 2007-06-05 12:38:30 -0700 | [diff] [blame] | 84 | const struct nla_policy *policy; |
Denis V. Lunev | 76c72d4 | 2007-09-16 15:44:27 -0700 | [diff] [blame] | 85 | struct list_head rules_list; |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 86 | struct module *owner; |
Denis V. Lunev | 03592383 | 2008-01-20 16:46:01 -0800 | [diff] [blame] | 87 | struct net *fro_net; |
Eric W. Biederman | e9c5158 | 2009-12-03 12:22:55 -0800 | [diff] [blame] | 88 | struct rcu_head rcu; |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Thomas Graf | 1f6c955 | 2006-11-09 15:22:48 -0800 | [diff] [blame] | 91 | #define FRA_GENERIC_POLICY \ |
Patrick McHardy | 491deb24b | 2009-12-03 01:25:54 +0000 | [diff] [blame] | 92 | [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ |
Patrick McHardy | 1b038a5 | 2009-12-03 01:25:56 +0000 | [diff] [blame] | 93 | [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ |
Thomas Graf | 1f6c955 | 2006-11-09 15:22:48 -0800 | [diff] [blame] | 94 | [FRA_PRIORITY] = { .type = NLA_U32 }, \ |
| 95 | [FRA_FWMARK] = { .type = NLA_U32 }, \ |
| 96 | [FRA_FWMASK] = { .type = NLA_U32 }, \ |
Thomas Graf | 0947c9fe | 2007-03-26 17:14:15 -0700 | [diff] [blame] | 97 | [FRA_TABLE] = { .type = NLA_U32 }, \ |
Lorenzo Colitti | 3b82497 | 2014-03-31 16:23:51 +0900 | [diff] [blame] | 98 | [FRA_UID_START] = { .type = NLA_U32 }, \ |
| 99 | [FRA_UID_END] = { .type = NLA_U32 }, \ |
Stefan Tomanek | 73f5698 | 2013-08-03 14:14:43 +0200 | [diff] [blame] | 100 | [FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, \ |
Stefan Tomanek | 6ef94cf | 2013-08-02 17:19:56 +0200 | [diff] [blame] | 101 | [FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \ |
David Ahern | 96c63fa | 2016-06-08 10:55:39 -0700 | [diff] [blame] | 102 | [FRA_GOTO] = { .type = NLA_U32 }, \ |
Lorenzo Colitti | 2ec93fe | 2016-11-04 02:23:42 +0900 | [diff] [blame] | 103 | [FRA_L3MDEV] = { .type = NLA_U8 }, \ |
| 104 | [FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) } |
Thomas Graf | 1f6c955 | 2006-11-09 15:22:48 -0800 | [diff] [blame] | 105 | |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 106 | static inline void fib_rule_get(struct fib_rule *rule) |
| 107 | { |
| 108 | atomic_inc(&rule->refcnt); |
| 109 | } |
| 110 | |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 111 | static inline void fib_rule_put(struct fib_rule *rule) |
| 112 | { |
| 113 | if (atomic_dec_and_test(&rule->refcnt)) |
Eric W. Biederman | efd7ef1 | 2015-03-11 23:04:08 -0500 | [diff] [blame] | 114 | kfree_rcu(rule, rcu); |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 115 | } |
| 116 | |
David Ahern | 96c63fa | 2016-06-08 10:55:39 -0700 | [diff] [blame] | 117 | #ifdef CONFIG_NET_L3_MASTER_DEV |
| 118 | static inline u32 fib_rule_get_table(struct fib_rule *rule, |
| 119 | struct fib_lookup_arg *arg) |
| 120 | { |
| 121 | return rule->l3mdev ? arg->table : rule->table; |
| 122 | } |
| 123 | #else |
| 124 | static inline u32 fib_rule_get_table(struct fib_rule *rule, |
| 125 | struct fib_lookup_arg *arg) |
| 126 | { |
| 127 | return rule->table; |
| 128 | } |
| 129 | #endif |
| 130 | |
Patrick McHardy | 9e762a4 | 2006-08-10 23:09:48 -0700 | [diff] [blame] | 131 | static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla) |
| 132 | { |
| 133 | if (nla[FRA_TABLE]) |
| 134 | return nla_get_u32(nla[FRA_TABLE]); |
| 135 | return frh->table; |
| 136 | } |
| 137 | |
Joe Perches | 8de6879 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 138 | struct fib_rules_ops *fib_rules_register(const struct fib_rules_ops *, |
| 139 | struct net *); |
| 140 | void fib_rules_unregister(struct fib_rules_ops *); |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 141 | |
Joe Perches | 8de6879 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 142 | int fib_rules_lookup(struct fib_rules_ops *, struct flowi *, int flags, |
| 143 | struct fib_lookup_arg *); |
| 144 | int fib_default_rule_add(struct fib_rules_ops *, u32 pref, u32 table, |
| 145 | u32 flags); |
David Ahern | 96c63fa | 2016-06-08 10:55:39 -0700 | [diff] [blame] | 146 | |
| 147 | int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh); |
| 148 | int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh); |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 149 | #endif |