Skip to content

Commit 478e4c2

Browse files
yotamgidavem330
authored andcommitted
net: mroute: Check if rule is a default rule
When the ipmr starts, it adds one default FIB rule that matches all packets and sends them to the DEFAULT (multicast) FIB table. A more complex rule can be added by user to specify that for a specific interface, a packet should be look up at either an arbitrary table or according to the l3mdev of the interface. For drivers willing to offload the ipmr logic into a hardware but don't want to offload all the FIB rules functionality, provide a function that can indicate whether the FIB rule is the default multicast rule, thus only one routing table is needed. This way, a driver can register to the FIB notification chain, get notifications about FIB rules added and trigger some kind of an internal abort mechanism when a non default rule is added by the user. Signed-off-by: Yotam Gigi <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Reviewed-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c7c0bbe commit 478e4c2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/linux/mroute.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/pim.h>
66
#include <linux/rhashtable.h>
77
#include <net/sock.h>
8+
#include <net/fib_rules.h>
89
#include <net/fib_notifier.h>
910
#include <uapi/linux/mroute.h>
1011

@@ -19,6 +20,7 @@ int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
1920
int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
2021
int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
2122
int ip_mr_init(void);
23+
bool ipmr_rule_default(const struct fib_rule *rule);
2224
#else
2325
static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
2426
char __user *optval, unsigned int optlen)
@@ -46,6 +48,11 @@ static inline int ip_mroute_opt(int opt)
4648
{
4749
return 0;
4850
}
51+
52+
static inline bool ipmr_rule_default(const struct fib_rule *rule)
53+
{
54+
return true;
55+
}
4956
#endif
5057

5158
struct vif_device {

net/ipv4/ipmr.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ static unsigned int ipmr_rules_seq_read(struct net *net)
274274
{
275275
return fib_rules_seq_read(net, RTNL_FAMILY_IPMR);
276276
}
277+
278+
bool ipmr_rule_default(const struct fib_rule *rule)
279+
{
280+
return fib_rule_matchall(rule) && rule->table == RT_TABLE_DEFAULT;
281+
}
282+
EXPORT_SYMBOL(ipmr_rule_default);
277283
#else
278284
#define ipmr_for_each_table(mrt, net) \
279285
for (mrt = net->ipv4.mrt; mrt; mrt = NULL)
@@ -318,6 +324,12 @@ static unsigned int ipmr_rules_seq_read(struct net *net)
318324
{
319325
return 0;
320326
}
327+
328+
bool ipmr_rule_default(const struct fib_rule *rule)
329+
{
330+
return true;
331+
}
332+
EXPORT_SYMBOL(ipmr_rule_default);
321333
#endif
322334

323335
static inline int ipmr_hash_cmp(struct rhashtable_compare_arg *arg,

0 commit comments

Comments
 (0)