Skip to content

Commit f0ad086

Browse files
kaberdavem330
authored andcommitted
ipv4: ipmr: support multiple tables
This patch adds support for multiple independant multicast routing instances, named "tables". Userspace multicast routing daemons can bind to a specific table instance by issuing a setsockopt call using a new option MRT_TABLE. The table number is stored in the raw socket data and affects all following ipmr setsockopt(), getsockopt() and ioctl() calls. By default, a single table (RT_TABLE_DEFAULT) is created with a default routing rule pointing to it. Newly created pimreg devices have the table number appended ("pimregX"), with the exception of devices created in the default table, which are named just "pimreg" for compatibility reasons. Packets are directed to a specific table instance using routing rules, similar to how regular routing rules work. Currently iif, oif and mark are supported as keys, source and destination addresses could be supported additionally. Example usage: - bind pimd/xorp/... to a specific table: uint32_t table = 123; setsockopt(fd, IPPROTO_IP, MRT_TABLE, &table, sizeof(table)); - create routing rules directing packets to the new table: # ip mrule add iif eth0 lookup 123 # ip mrule add oif eth0 lookup 123 Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0c12295 commit f0ad086

File tree

6 files changed

+361
-62
lines changed

6 files changed

+361
-62
lines changed

include/linux/fib_rules.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define FIB_RULES_IPV4 AF_INET
2222
#define FIB_RULES_IPV6 AF_INET6
2323
#define FIB_RULES_DECNET AF_DECnet
24+
#define FIB_RULES_IPMR 128
2425

2526
struct fib_rule_hdr {
2627
__u8 family;

include/linux/mroute.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */
2828
#define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */
2929
#define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */
30-
#define MRT_PIM (MRT_BASE+8) /* enable PIM code */
30+
#define MRT_PIM (MRT_BASE+8) /* enable PIM code */
31+
#define MRT_TABLE (MRT_BASE+9) /* Specify mroute table ID */
3132

3233
#define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */
3334
#define SIOCGETSGCNT (SIOCPROTOPRIVATE+1)

include/net/netns/ipv4.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ struct netns_ipv4 {
5959
atomic_t rt_genid;
6060

6161
#ifdef CONFIG_IP_MROUTE
62+
#ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
6263
struct mr_table *mrt;
64+
#else
65+
struct list_head mr_tables;
66+
struct fib_rules_ops *mr_rules_ops;
67+
#endif
6368
#endif
6469
};
6570
#endif

include/net/raw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct raw_sock {
6161
/* inet_sock has to be the first member */
6262
struct inet_sock inet;
6363
struct icmp_filter filter;
64+
u32 ipmr_table;
6465
};
6566

6667
static inline struct raw_sock *raw_sk(const struct sock *sk)

net/ipv4/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ config IP_MROUTE
250250
<file:Documentation/networking/multicast.txt>. If you haven't heard
251251
about it, you don't need it.
252252

253+
config IP_MROUTE_MULTIPLE_TABLES
254+
bool "IP: multicast policy routing"
255+
depends on IP_ADVANCED_ROUTER
256+
select FIB_RULES
257+
help
258+
Normally, a multicast router runs a userspace daemon and decides
259+
what to do with a multicast packet based on the source and
260+
destination addresses. If you say Y here, the multicast router
261+
will also be able to take interfaces and packet marks into
262+
account and run multiple instances of userspace daemons
263+
simultaneously, each one handling a single table.
264+
265+
If unsure, say N.
266+
253267
config IP_PIMSM_V1
254268
bool "IP: PIM-SM version 1 support"
255269
depends on IP_MROUTE

0 commit comments

Comments
 (0)