Blame view

include/net/fib_rules.h 4.14 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
14c0b97dd   Thomas Graf   [NET]: Protocol I...
2
3
4
5
  #ifndef __NET_FIB_RULES_H
  #define __NET_FIB_RULES_H
  
  #include <linux/types.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
6
  #include <linux/slab.h>
14c0b97dd   Thomas Graf   [NET]: Protocol I...
7
8
  #include <linux/netdevice.h>
  #include <linux/fib_rules.h>
717d1e993   Reshetova, Elena   net: convert fib_...
9
  #include <linux/refcount.h>
14c0b97dd   Thomas Graf   [NET]: Protocol I...
10
  #include <net/flow.h>
9d9e6a581   Thomas Graf   [NET] rules: Use ...
11
  #include <net/rtnetlink.h>
1b2a44408   Ido Schimmel   net: fib_rules: I...
12
  #include <net/fib_notifier.h>
14c0b97dd   Thomas Graf   [NET]: Protocol I...
13

622ec2c9d   Lorenzo Colitti   net: core: add UI...
14
15
16
17
  struct fib_kuid_range {
  	kuid_t start;
  	kuid_t end;
  };
fd2c3ef76   Eric Dumazet   net: cleanup incl...
18
  struct fib_rule {
14c0b97dd   Thomas Graf   [NET]: Protocol I...
19
  	struct list_head	list;
491deb24b   Patrick McHardy   net 02/05: fib_ru...
20
  	int			iifindex;
1b038a5e6   Patrick McHardy   net 03/05: fib_ru...
21
  	int			oifindex;
b8964ed9f   Thomas Graf   [NET] rules: Prot...
22
23
  	u32			mark;
  	u32			mark_mask;
14c0b97dd   Thomas Graf   [NET]: Protocol I...
24
25
26
  	u32			flags;
  	u32			table;
  	u8			action;
96c63fa73   David Ahern   net: Add l3mdev rule
27
28
  	u8			l3mdev;
  	/* 2 bytes hole, try to use */
0947c9fe5   Thomas Graf   [NET] fib_rules: ...
29
  	u32			target;
e7030878f   Thomas Graf   fib: Add fib rule...
30
  	__be64			tun_id;
7a2b03c51   Eric Dumazet   fib_rules: __rcu ...
31
  	struct fib_rule __rcu	*ctarget;
fba3679d3   Eric Dumazet   fib_rules: reorde...
32
  	struct net		*fr_net;
717d1e993   Reshetova, Elena   net: convert fib_...
33
  	refcount_t		refcnt;
fba3679d3   Eric Dumazet   fib_rules: reorde...
34
35
36
  	u32			pref;
  	int			suppress_ifgroup;
  	int			suppress_prefixlen;
491deb24b   Patrick McHardy   net 02/05: fib_ru...
37
  	char			iifname[IFNAMSIZ];
1b038a5e6   Patrick McHardy   net 03/05: fib_ru...
38
  	char			oifname[IFNAMSIZ];
622ec2c9d   Lorenzo Colitti   net: core: add UI...
39
  	struct fib_kuid_range	uid_range;
14c0b97dd   Thomas Graf   [NET]: Protocol I...
40
41
  	struct rcu_head		rcu;
  };
fd2c3ef76   Eric Dumazet   net: cleanup incl...
42
  struct fib_lookup_arg {
14c0b97dd   Thomas Graf   [NET]: Protocol I...
43
44
45
  	void			*lookup_ptr;
  	void			*result;
  	struct fib_rule		*rule;
96c63fa73   David Ahern   net: Add l3mdev rule
46
  	u32			table;
ebc0ffae5   Eric Dumazet   fib: RCU conversi...
47
  	int			flags;
0eeb075fa   Andy Gospodarek   net: ipv4 sysctl ...
48
49
  #define FIB_LOOKUP_NOREF		1
  #define FIB_LOOKUP_IGNORE_LINKSTATE	2
14c0b97dd   Thomas Graf   [NET]: Protocol I...
50
  };
fd2c3ef76   Eric Dumazet   net: cleanup incl...
51
  struct fib_rules_ops {
14c0b97dd   Thomas Graf   [NET]: Protocol I...
52
53
54
  	int			family;
  	struct list_head	list;
  	int			rule_size;
e1701c68c   Thomas Graf   [NET]: Fix fib_ru...
55
  	int			addr_size;
0947c9fe5   Thomas Graf   [NET] fib_rules: ...
56
57
  	int			unresolved_rules;
  	int			nr_goto_rules;
1b2a44408   Ido Schimmel   net: fib_rules: I...
58
  	unsigned int		fib_rules_seq;
14c0b97dd   Thomas Graf   [NET]: Protocol I...
59
60
61
62
  
  	int			(*action)(struct fib_rule *,
  					  struct flowi *, int,
  					  struct fib_lookup_arg *);
7764a45a8   Stefan Tomanek   fib_rules: add .s...
63
64
  	bool			(*suppress)(struct fib_rule *,
  					    struct fib_lookup_arg *);
14c0b97dd   Thomas Graf   [NET]: Protocol I...
65
66
67
68
  	int			(*match)(struct fib_rule *,
  					 struct flowi *, int);
  	int			(*configure)(struct fib_rule *,
  					     struct sk_buff *,
14c0b97dd   Thomas Graf   [NET]: Protocol I...
69
70
  					     struct fib_rule_hdr *,
  					     struct nlattr **);
0ddcf43d5   Alexander Duyck   ipv4: FIB Local/M...
71
  	int			(*delete)(struct fib_rule *);
14c0b97dd   Thomas Graf   [NET]: Protocol I...
72
73
74
75
  	int			(*compare)(struct fib_rule *,
  					   struct fib_rule_hdr *,
  					   struct nlattr **);
  	int			(*fill)(struct fib_rule *, struct sk_buff *,
14c0b97dd   Thomas Graf   [NET]: Protocol I...
76
  					struct fib_rule_hdr *);
339bf98ff   Thomas Graf   [NETLINK]: Do pre...
77
  	size_t			(*nlmsg_payload)(struct fib_rule *);
14c0b97dd   Thomas Graf   [NET]: Protocol I...
78

73417f617   Thomas Graf   [NET] fib_rules: ...
79
80
  	/* Called after modifications to the rules set, must flush
  	 * the route cache if one exists. */
ae299fc05   Denis V. Lunev   net: add fib_rule...
81
  	void			(*flush_cache)(struct fib_rules_ops *ops);
73417f617   Thomas Graf   [NET] fib_rules: ...
82

14c0b97dd   Thomas Graf   [NET]: Protocol I...
83
  	int			nlgroup;
ef7c79ed6   Patrick McHardy   [NETLINK]: Mark n...
84
  	const struct nla_policy	*policy;
76c72d4f4   Denis V. Lunev   [IPV4/IPV6/DECNET...
85
  	struct list_head	rules_list;
14c0b97dd   Thomas Graf   [NET]: Protocol I...
86
  	struct module		*owner;
035923833   Denis V. Lunev   [FIB]: Add netns ...
87
  	struct net		*fro_net;
e9c5158ac   Eric W. Biederman   net: Allow fib_ru...
88
  	struct rcu_head		rcu;
14c0b97dd   Thomas Graf   [NET]: Protocol I...
89
  };
1b2a44408   Ido Schimmel   net: fib_rules: I...
90
91
92
93
  struct fib_rule_notifier_info {
  	struct fib_notifier_info info; /* must be first */
  	struct fib_rule *rule;
  };
1f6c9557e   Thomas Graf   [NET] rules: Shar...
94
  #define FRA_GENERIC_POLICY \
491deb24b   Patrick McHardy   net 02/05: fib_ru...
95
  	[FRA_IIFNAME]	= { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
1b038a5e6   Patrick McHardy   net 03/05: fib_ru...
96
  	[FRA_OIFNAME]	= { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
1f6c9557e   Thomas Graf   [NET] rules: Shar...
97
98
99
  	[FRA_PRIORITY]	= { .type = NLA_U32 }, \
  	[FRA_FWMARK]	= { .type = NLA_U32 }, \
  	[FRA_FWMASK]	= { .type = NLA_U32 }, \
0947c9fe5   Thomas Graf   [NET] fib_rules: ...
100
  	[FRA_TABLE]     = { .type = NLA_U32 }, \
73f5698e7   Stefan Tomanek   fib_rules: fix su...
101
  	[FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, \
6ef94cfaf   Stefan Tomanek   fib_rules: add ro...
102
  	[FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \
96c63fa73   David Ahern   net: Add l3mdev rule
103
  	[FRA_GOTO]	= { .type = NLA_U32 }, \
622ec2c9d   Lorenzo Colitti   net: core: add UI...
104
105
  	[FRA_L3MDEV]	= { .type = NLA_U8 }, \
  	[FRA_UID_RANGE]	= { .len = sizeof(struct fib_rule_uid_range) }
1f6c9557e   Thomas Graf   [NET] rules: Shar...
106

14c0b97dd   Thomas Graf   [NET]: Protocol I...
107
108
  static inline void fib_rule_get(struct fib_rule *rule)
  {
717d1e993   Reshetova, Elena   net: convert fib_...
109
  	refcount_inc(&rule->refcnt);
14c0b97dd   Thomas Graf   [NET]: Protocol I...
110
  }
14c0b97dd   Thomas Graf   [NET]: Protocol I...
111
112
  static inline void fib_rule_put(struct fib_rule *rule)
  {
717d1e993   Reshetova, Elena   net: convert fib_...
113
  	if (refcount_dec_and_test(&rule->refcnt))
efd7ef1c1   Eric W. Biederman   net: Kill hold_ne...
114
  		kfree_rcu(rule, rcu);
14c0b97dd   Thomas Graf   [NET]: Protocol I...
115
  }
96c63fa73   David Ahern   net: Add l3mdev rule
116
117
118
119
120
121
122
123
124
125
126
127
128
  #ifdef CONFIG_NET_L3_MASTER_DEV
  static inline u32 fib_rule_get_table(struct fib_rule *rule,
  				     struct fib_lookup_arg *arg)
  {
  	return rule->l3mdev ? arg->table : rule->table;
  }
  #else
  static inline u32 fib_rule_get_table(struct fib_rule *rule,
  				     struct fib_lookup_arg *arg)
  {
  	return rule->table;
  }
  #endif
9e762a4a8   Patrick McHardy   [NET]: Introduce ...
129
130
131
132
133
134
  static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
  {
  	if (nla[FRA_TABLE])
  		return nla_get_u32(nla[FRA_TABLE]);
  	return frh->table;
  }
8de6879fa   Joe Perches   fib_rules.h: Remo...
135
136
137
  struct fib_rules_ops *fib_rules_register(const struct fib_rules_ops *,
  					 struct net *);
  void fib_rules_unregister(struct fib_rules_ops *);
14c0b97dd   Thomas Graf   [NET]: Protocol I...
138

8de6879fa   Joe Perches   fib_rules.h: Remo...
139
140
141
142
  int fib_rules_lookup(struct fib_rules_ops *, struct flowi *, int flags,
  		     struct fib_lookup_arg *);
  int fib_default_rule_add(struct fib_rules_ops *, u32 pref, u32 table,
  			 u32 flags);
3c71006d1   Ido Schimmel   ipv4: fib_rules: ...
143
  bool fib_rule_matchall(const struct fib_rule *rule);
1b2a44408   Ido Schimmel   net: fib_rules: I...
144
145
  int fib_rules_dump(struct net *net, struct notifier_block *nb, int family);
  unsigned int fib_rules_seq_read(struct net *net, int family);
96c63fa73   David Ahern   net: Add l3mdev rule
146

c21ef3e34   David Ahern   net: rtnetlink: p...
147
148
149
150
  int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
  		   struct netlink_ext_ack *extack);
  int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
  		   struct netlink_ext_ack *extack);
14c0b97dd   Thomas Graf   [NET]: Protocol I...
151
  #endif