2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-04-03 08:22:53 +08:00
|
|
|
/*
|
|
|
|
* Linux IPv6 multicast routing support for BSD pim6sd
|
|
|
|
* Based on net/ipv4/ipmr.c.
|
|
|
|
*
|
|
|
|
* (c) 2004 Mickael Hoerdt, <hoerdt@clarinet.u-strasbg.fr>
|
|
|
|
* LSIIT Laboratory, Strasbourg, France
|
|
|
|
* (c) 2004 Jean-Philippe Andriot, <jean-philippe.andriot@6WIND.com>
|
|
|
|
* 6WIND, Paris, France
|
|
|
|
* Copyright (C)2007,2008 USAGI/WIDE Project
|
|
|
|
* YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
|
|
|
|
*/
|
|
|
|
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2008-04-03 08:22:53 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/inetdevice.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/init.h>
|
2011-02-04 09:59:32 +08:00
|
|
|
#include <linux/compat.h>
|
2018-06-18 10:52:50 +08:00
|
|
|
#include <linux/rhashtable.h>
|
2008-04-03 08:22:53 +08:00
|
|
|
#include <net/protocol.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/raw.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <net/checksum.h>
|
|
|
|
#include <net/netlink.h>
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
#include <net/fib_rules.h>
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
#include <net/ipv6.h>
|
|
|
|
#include <net/ip6_route.h>
|
|
|
|
#include <linux/mroute6.h>
|
2008-04-03 08:22:54 +08:00
|
|
|
#include <linux/pim.h>
|
2008-04-03 08:22:53 +08:00
|
|
|
#include <net/addrconf.h>
|
|
|
|
#include <linux/netfilter_ipv6.h>
|
2011-07-15 23:47:34 +08:00
|
|
|
#include <linux/export.h>
|
2009-01-31 16:51:49 +08:00
|
|
|
#include <net/ip6_checksum.h>
|
2012-12-04 09:13:35 +08:00
|
|
|
#include <linux/netconf.h>
|
2018-12-31 06:24:36 +08:00
|
|
|
#include <net/ip_tunnels.h>
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-12-12 04:10:08 +08:00
|
|
|
#include <linux/nospec.h>
|
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
struct ip6mr_rule {
|
|
|
|
struct fib_rule common;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ip6mr_result {
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
};
|
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
/* Big lock, protecting vif table, mrt cache and mroute socket state.
|
|
|
|
Note that the changes are semaphored via rtnl_lock.
|
|
|
|
*/
|
|
|
|
|
2022-06-23 12:34:49 +08:00
|
|
|
static DEFINE_SPINLOCK(mrt_lock);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2022-06-23 12:34:32 +08:00
|
|
|
static struct net_device *vif_dev_read(const struct vif_device *vif)
|
|
|
|
{
|
2022-06-23 12:34:49 +08:00
|
|
|
return rcu_dereference(vif->dev);
|
2022-06-23 12:34:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
/* Multicast router control variables */
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
/* Special spinlock for queue of unresolved entries */
|
|
|
|
static DEFINE_SPINLOCK(mfc_unres_lock);
|
|
|
|
|
|
|
|
/* We return to original Alan's scheme. Hash table of resolved
|
|
|
|
entries is changed only in process context and protected
|
|
|
|
with weak lock mrt_lock. Queue of unresolved entries is protected
|
|
|
|
with strong spinlock mfc_unres_lock.
|
|
|
|
|
|
|
|
In this case data path is free of exclusive locks at all.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct kmem_cache *mrt_cachep __read_mostly;
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static struct mr_table *ip6mr_new_table(struct net *net, u32 id);
|
|
|
|
static void ip6mr_free_table(struct mr_table *mrt);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static void ip6_mr_forward(struct net *net, struct mr_table *mrt,
|
2018-10-01 16:41:27 +08:00
|
|
|
struct net_device *dev, struct sk_buff *skb,
|
|
|
|
struct mfc6_cache *cache);
|
2022-06-23 12:34:40 +08:00
|
|
|
static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt,
|
2008-12-11 08:30:15 +08:00
|
|
|
mifi_t mifi, int assert);
|
2018-03-01 05:29:32 +08:00
|
|
|
static void mr6_netlink_event(struct mr_table *mrt, struct mfc6_cache *mfc,
|
2012-12-04 09:13:41 +08:00
|
|
|
int cmd);
|
2022-06-23 12:34:40 +08:00
|
|
|
static void mrt6msg_netlink_event(const struct mr_table *mrt, struct sk_buff *pkt);
|
2010-05-11 20:40:56 +08:00
|
|
|
static int ip6mr_rtm_dumproute(struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb);
|
2019-02-18 05:07:52 +08:00
|
|
|
static void mroute_clean_tables(struct mr_table *mrt, int flags);
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-17 05:43:17 +08:00
|
|
|
static void ipmr_expire_process(struct timer_list *t);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
|
2010-06-07 06:34:40 +08:00
|
|
|
#define ip6mr_for_each_table(mrt, net) \
|
2020-02-23 00:57:27 +08:00
|
|
|
list_for_each_entry_rcu(mrt, &net->ipv6.mr6_tables, list, \
|
2020-05-16 15:45:15 +08:00
|
|
|
lockdep_rtnl_is_held() || \
|
|
|
|
list_empty(&net->ipv6.mr6_tables))
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
2018-03-01 05:29:39 +08:00
|
|
|
static struct mr_table *ip6mr_mr_table_iter(struct net *net,
|
|
|
|
struct mr_table *mrt)
|
|
|
|
{
|
|
|
|
struct mr_table *ret;
|
|
|
|
|
|
|
|
if (!mrt)
|
|
|
|
ret = list_entry_rcu(net->ipv6.mr6_tables.next,
|
|
|
|
struct mr_table, list);
|
|
|
|
else
|
|
|
|
ret = list_entry_rcu(mrt->list.next,
|
|
|
|
struct mr_table, list);
|
|
|
|
|
|
|
|
if (&ret->list == &net->ipv6.mr6_tables)
|
|
|
|
return NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static struct mr_table *ip6mr_get_table(struct net *net, u32 id)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
{
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
|
|
|
ip6mr_for_each_table(mrt, net) {
|
|
|
|
if (mrt->id == id)
|
|
|
|
return mrt;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
static int ip6mr_fib_lookup(struct net *net, struct flowi6 *flp6,
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table **mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
{
|
|
|
|
int err;
|
2014-01-13 09:45:22 +08:00
|
|
|
struct ip6mr_result res;
|
|
|
|
struct fib_lookup_arg arg = {
|
|
|
|
.result = &res,
|
|
|
|
.flags = FIB_LOOKUP_NOREF,
|
|
|
|
};
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
2018-10-01 16:41:27 +08:00
|
|
|
/* update flow if oif or iif point to device enslaved to l3mdev */
|
|
|
|
l3mdev_update_flow(net, flowi6_to_flowi(flp6));
|
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
err = fib_rules_lookup(net->ipv6.mr6_rules_ops,
|
|
|
|
flowi6_to_flowi(flp6), 0, &arg);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
*mrt = res.mrt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip6mr_rule_action(struct fib_rule *rule, struct flowi *flp,
|
|
|
|
int flags, struct fib_lookup_arg *arg)
|
|
|
|
{
|
|
|
|
struct ip6mr_result *res = arg->result;
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
|
|
|
switch (rule->action) {
|
|
|
|
case FR_ACT_TO_TBL:
|
|
|
|
break;
|
|
|
|
case FR_ACT_UNREACHABLE:
|
|
|
|
return -ENETUNREACH;
|
|
|
|
case FR_ACT_PROHIBIT:
|
|
|
|
return -EACCES;
|
|
|
|
case FR_ACT_BLACKHOLE:
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-10-01 16:41:27 +08:00
|
|
|
arg->table = fib_rule_get_table(rule, arg);
|
|
|
|
|
|
|
|
mrt = ip6mr_get_table(rule->fr_net, arg->table);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
res->mrt = mrt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip6mr_rule_match(struct fib_rule *rule, struct flowi *flp, int flags)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip6mr_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
|
2018-04-22 00:41:31 +08:00
|
|
|
struct fib_rule_hdr *frh, struct nlattr **tb,
|
|
|
|
struct netlink_ext_ack *extack)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip6mr_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
|
|
|
|
struct nlattr **tb)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip6mr_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
|
|
|
|
struct fib_rule_hdr *frh)
|
|
|
|
{
|
|
|
|
frh->dst_len = 0;
|
|
|
|
frh->src_len = 0;
|
|
|
|
frh->tos = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-05 08:12:11 +08:00
|
|
|
static const struct fib_rules_ops __net_initconst ip6mr_rules_ops_template = {
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
.family = RTNL_FAMILY_IP6MR,
|
|
|
|
.rule_size = sizeof(struct ip6mr_rule),
|
|
|
|
.addr_size = sizeof(struct in6_addr),
|
|
|
|
.action = ip6mr_rule_action,
|
|
|
|
.match = ip6mr_rule_match,
|
|
|
|
.configure = ip6mr_rule_configure,
|
|
|
|
.compare = ip6mr_rule_compare,
|
|
|
|
.fill = ip6mr_rule_fill,
|
|
|
|
.nlgroup = RTNLGRP_IPV6_RULE,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __net_init ip6mr_rules_init(struct net *net)
|
|
|
|
{
|
|
|
|
struct fib_rules_ops *ops;
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
ops = fib_rules_register(&ip6mr_rules_ops_template, net);
|
|
|
|
if (IS_ERR(ops))
|
|
|
|
return PTR_ERR(ops);
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&net->ipv6.mr6_tables);
|
|
|
|
|
|
|
|
mrt = ip6mr_new_table(net, RT6_TABLE_DFLT);
|
2018-06-05 21:02:00 +08:00
|
|
|
if (IS_ERR(mrt)) {
|
|
|
|
err = PTR_ERR(mrt);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = fib_default_rule_add(ops, 0x7fff, RT6_TABLE_DFLT, 0);
|
|
|
|
if (err < 0)
|
|
|
|
goto err2;
|
|
|
|
|
|
|
|
net->ipv6.mr6_rules_ops = ops;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err2:
|
2022-02-08 13:34:51 +08:00
|
|
|
rtnl_lock();
|
2015-03-26 05:45:03 +08:00
|
|
|
ip6mr_free_table(mrt);
|
2022-02-08 13:34:51 +08:00
|
|
|
rtnl_unlock();
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
err1:
|
|
|
|
fib_rules_unregister(ops);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit ip6mr_rules_exit(struct net *net)
|
|
|
|
{
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt, *next;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
2022-02-08 12:50:34 +08:00
|
|
|
ASSERT_RTNL();
|
2010-06-07 07:48:40 +08:00
|
|
|
list_for_each_entry_safe(mrt, next, &net->ipv6.mr6_tables, list) {
|
|
|
|
list_del(&mrt->list);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
ip6mr_free_table(mrt);
|
2010-06-07 07:48:40 +08:00
|
|
|
}
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
fib_rules_unregister(net->ipv6.mr6_rules_ops);
|
|
|
|
}
|
2018-03-26 20:01:34 +08:00
|
|
|
|
2019-10-03 17:49:30 +08:00
|
|
|
static int ip6mr_rules_dump(struct net *net, struct notifier_block *nb,
|
|
|
|
struct netlink_ext_ack *extack)
|
2018-03-26 20:01:34 +08:00
|
|
|
{
|
2019-10-03 17:49:30 +08:00
|
|
|
return fib_rules_dump(net, nb, RTNL_FAMILY_IP6MR, extack);
|
2018-03-26 20:01:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int ip6mr_rules_seq_read(struct net *net)
|
|
|
|
{
|
|
|
|
return fib_rules_seq_read(net, RTNL_FAMILY_IP6MR);
|
|
|
|
}
|
2018-03-26 20:01:35 +08:00
|
|
|
|
|
|
|
bool ip6mr_rule_default(const struct fib_rule *rule)
|
|
|
|
{
|
|
|
|
return fib_rule_matchall(rule) && rule->action == FR_ACT_TO_TBL &&
|
|
|
|
rule->table == RT6_TABLE_DFLT && !rule->l3mdev;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ip6mr_rule_default);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
#else
|
|
|
|
#define ip6mr_for_each_table(mrt, net) \
|
|
|
|
for (mrt = net->ipv6.mrt6; mrt; mrt = NULL)
|
|
|
|
|
2018-03-01 05:29:39 +08:00
|
|
|
static struct mr_table *ip6mr_mr_table_iter(struct net *net,
|
|
|
|
struct mr_table *mrt)
|
|
|
|
{
|
|
|
|
if (!mrt)
|
|
|
|
return net->ipv6.mrt6;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static struct mr_table *ip6mr_get_table(struct net *net, u32 id)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
{
|
|
|
|
return net->ipv6.mrt6;
|
|
|
|
}
|
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
static int ip6mr_fib_lookup(struct net *net, struct flowi6 *flp6,
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table **mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
{
|
|
|
|
*mrt = net->ipv6.mrt6;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __net_init ip6mr_rules_init(struct net *net)
|
|
|
|
{
|
2018-06-05 21:02:00 +08:00
|
|
|
struct mr_table *mrt;
|
|
|
|
|
|
|
|
mrt = ip6mr_new_table(net, RT6_TABLE_DFLT);
|
|
|
|
if (IS_ERR(mrt))
|
|
|
|
return PTR_ERR(mrt);
|
|
|
|
net->ipv6.mrt6 = mrt;
|
|
|
|
return 0;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit ip6mr_rules_exit(struct net *net)
|
|
|
|
{
|
2022-02-08 12:50:34 +08:00
|
|
|
ASSERT_RTNL();
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
ip6mr_free_table(net->ipv6.mrt6);
|
2013-07-23 05:45:53 +08:00
|
|
|
net->ipv6.mrt6 = NULL;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
}
|
2018-03-26 20:01:34 +08:00
|
|
|
|
2019-10-03 17:49:30 +08:00
|
|
|
static int ip6mr_rules_dump(struct net *net, struct notifier_block *nb,
|
|
|
|
struct netlink_ext_ack *extack)
|
2018-03-26 20:01:34 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int ip6mr_rules_seq_read(struct net *net)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
#endif
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
static int ip6mr_hash_cmp(struct rhashtable_compare_arg *arg,
|
|
|
|
const void *ptr)
|
|
|
|
{
|
|
|
|
const struct mfc6_cache_cmp_arg *cmparg = arg->key;
|
|
|
|
struct mfc6_cache *c = (struct mfc6_cache *)ptr;
|
|
|
|
|
|
|
|
return !ipv6_addr_equal(&c->mf6c_mcastgrp, &cmparg->mf6c_mcastgrp) ||
|
|
|
|
!ipv6_addr_equal(&c->mf6c_origin, &cmparg->mf6c_origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rhashtable_params ip6mr_rht_params = {
|
2018-03-01 05:29:34 +08:00
|
|
|
.head_offset = offsetof(struct mr_mfc, mnode),
|
2018-03-01 05:29:31 +08:00
|
|
|
.key_offset = offsetof(struct mfc6_cache, cmparg),
|
|
|
|
.key_len = sizeof(struct mfc6_cache_cmp_arg),
|
|
|
|
.nelem_hint = 3,
|
|
|
|
.obj_cmpfn = ip6mr_hash_cmp,
|
|
|
|
.automatic_shrinking = true,
|
|
|
|
};
|
|
|
|
|
2018-03-01 05:29:33 +08:00
|
|
|
static void ip6mr_new_table_set(struct mr_table *mrt,
|
|
|
|
struct net *net)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
|
|
|
|
list_add_tail_rcu(&mrt->list, &net->ipv6.mr6_tables);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:35 +08:00
|
|
|
static struct mfc6_cache_cmp_arg ip6mr_mr_table_ops_cmparg_any = {
|
|
|
|
.mf6c_origin = IN6ADDR_ANY_INIT,
|
|
|
|
.mf6c_mcastgrp = IN6ADDR_ANY_INIT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mr_table_ops ip6mr_mr_table_ops = {
|
|
|
|
.rht_params = &ip6mr_rht_params,
|
|
|
|
.cmparg_any = &ip6mr_mr_table_ops_cmparg_any,
|
|
|
|
};
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static struct mr_table *ip6mr_new_table(struct net *net, u32 id)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
{
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
|
|
|
mrt = ip6mr_get_table(net, id);
|
2015-03-29 21:00:05 +08:00
|
|
|
if (mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return mrt;
|
|
|
|
|
2018-03-01 05:29:35 +08:00
|
|
|
return mr_table_alloc(net, id, &ip6mr_mr_table_ops,
|
2018-03-01 05:29:33 +08:00
|
|
|
ipmr_expire_process, ip6mr_new_table_set);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static void ip6mr_free_table(struct mr_table *mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
{
|
2015-04-01 02:01:47 +08:00
|
|
|
del_timer_sync(&mrt->ipmr_expire_timer);
|
2019-02-18 05:07:52 +08:00
|
|
|
mroute_clean_tables(mrt, MRT6_FLUSH_MIFS | MRT6_FLUSH_MIFS_STATIC |
|
|
|
|
MRT6_FLUSH_MFC | MRT6_FLUSH_MFC_STATIC);
|
2018-03-01 05:29:32 +08:00
|
|
|
rhltable_destroy(&mrt->mfc_hash);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
kfree(mrt);
|
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2018-03-01 05:29:36 +08:00
|
|
|
/* The /proc interfaces to multicast routing
|
|
|
|
* /proc/ip6_mr_cache /proc/ip6_mr_vif
|
2008-04-03 08:22:53 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
|
2022-06-23 12:34:47 +08:00
|
|
|
__acquires(RCU)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:37 +08:00
|
|
|
struct mr_vif_iter *iter = seq->private;
|
2008-12-11 08:29:48 +08:00
|
|
|
struct net *net = seq_file_net(seq);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
|
|
|
mrt = ip6mr_get_table(net, RT6_TABLE_DFLT);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
|
|
|
|
iter->mrt = mrt;
|
2008-12-11 08:29:48 +08:00
|
|
|
|
2022-06-23 12:34:47 +08:00
|
|
|
rcu_read_lock();
|
2018-03-01 05:29:37 +08:00
|
|
|
return mr_vif_seq_start(seq, pos);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ip6mr_vif_seq_stop(struct seq_file *seq, void *v)
|
2022-06-23 12:34:47 +08:00
|
|
|
__releases(RCU)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2022-06-23 12:34:47 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
2018-03-01 05:29:37 +08:00
|
|
|
struct mr_vif_iter *iter = seq->private;
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt = iter->mrt;
|
2008-12-11 08:29:48 +08:00
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
if (v == SEQ_START_TOKEN) {
|
|
|
|
seq_puts(seq,
|
|
|
|
"Interface BytesIn PktsIn BytesOut PktsOut Flags\n");
|
|
|
|
} else {
|
2018-03-01 05:29:29 +08:00
|
|
|
const struct vif_device *vif = v;
|
2022-06-23 12:34:32 +08:00
|
|
|
const struct net_device *vif_dev;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
vif_dev = vif_dev_read(vif);
|
|
|
|
name = vif_dev ? vif_dev->name : "none";
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
seq_printf(seq,
|
2008-06-02 17:59:02 +08:00
|
|
|
"%2td %-10s %8ld %7ld %8ld %7ld %05X\n",
|
2018-03-01 05:29:32 +08:00
|
|
|
vif - mrt->vif_table,
|
2008-04-03 08:22:53 +08:00
|
|
|
name, vif->bytes_in, vif->pkt_in,
|
|
|
|
vif->bytes_out, vif->pkt_out,
|
|
|
|
vif->flags);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 03:25:02 +08:00
|
|
|
static const struct seq_operations ip6mr_vif_seq_ops = {
|
2008-04-03 08:22:53 +08:00
|
|
|
.start = ip6mr_vif_seq_start,
|
2018-03-01 05:29:37 +08:00
|
|
|
.next = mr_vif_seq_next,
|
2008-04-03 08:22:53 +08:00
|
|
|
.stop = ip6mr_vif_seq_stop,
|
|
|
|
.show = ip6mr_vif_seq_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos)
|
|
|
|
{
|
2008-12-11 08:29:48 +08:00
|
|
|
struct net *net = seq_file_net(seq);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2008-12-11 08:29:48 +08:00
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
mrt = ip6mr_get_table(net, RT6_TABLE_DFLT);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
|
2018-03-01 05:29:36 +08:00
|
|
|
return mr_mfc_seq_start(seq, pos, mrt, &mfc_unres_lock);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (v == SEQ_START_TOKEN) {
|
|
|
|
seq_puts(seq,
|
|
|
|
"Group "
|
|
|
|
"Origin "
|
|
|
|
"Iif Pkts Bytes Wrong Oifs\n");
|
|
|
|
} else {
|
|
|
|
const struct mfc6_cache *mfc = v;
|
2018-03-01 05:29:36 +08:00
|
|
|
const struct mr_mfc_iter *it = seq->private;
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt = it->mrt;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2008-12-04 14:22:16 +08:00
|
|
|
seq_printf(seq, "%pI6 %pI6 %-3hd",
|
2008-10-29 07:09:23 +08:00
|
|
|
&mfc->mf6c_mcastgrp, &mfc->mf6c_origin,
|
2018-03-01 05:29:34 +08:00
|
|
|
mfc->_c.mfc_parent);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
if (it->cache != &mrt->mfc_unres_queue) {
|
2008-12-04 14:21:47 +08:00
|
|
|
seq_printf(seq, " %8lu %8lu %8lu",
|
2018-03-01 05:29:34 +08:00
|
|
|
mfc->_c.mfc_un.res.pkt,
|
|
|
|
mfc->_c.mfc_un.res.bytes,
|
|
|
|
mfc->_c.mfc_un.res.wrong_if);
|
|
|
|
for (n = mfc->_c.mfc_un.res.minvif;
|
|
|
|
n < mfc->_c.mfc_un.res.maxvif; n++) {
|
2018-03-01 05:29:32 +08:00
|
|
|
if (VIF_EXISTS(mrt, n) &&
|
2018-03-01 05:29:34 +08:00
|
|
|
mfc->_c.mfc_un.res.ttls[n] < 255)
|
2008-04-03 08:22:53 +08:00
|
|
|
seq_printf(seq,
|
2018-03-01 05:29:34 +08:00
|
|
|
" %2d:%-3d", n,
|
|
|
|
mfc->_c.mfc_un.res.ttls[n]);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
2008-12-04 14:21:47 +08:00
|
|
|
} else {
|
|
|
|
/* unresolved mfc_caches don't contain
|
|
|
|
* pkt, bytes and wrong_if values
|
|
|
|
*/
|
|
|
|
seq_printf(seq, " %8lu %8lu %8lu", 0ul, 0ul, 0ul);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
seq_putc(seq, '\n');
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:43 +08:00
|
|
|
static const struct seq_operations ipmr_mfc_seq_ops = {
|
2008-04-03 08:22:53 +08:00
|
|
|
.start = ipmr_mfc_seq_start,
|
2018-03-01 05:29:36 +08:00
|
|
|
.next = mr_mfc_seq_next,
|
|
|
|
.stop = mr_mfc_seq_stop,
|
2008-04-03 08:22:53 +08:00
|
|
|
.show = ipmr_mfc_seq_show,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
|
|
|
|
static int pim6_rcv(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct pimreghdr *pim;
|
|
|
|
struct ipv6hdr *encap;
|
|
|
|
struct net_device *reg_dev = NULL;
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = dev_net(skb->dev);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2011-03-13 05:22:43 +08:00
|
|
|
struct flowi6 fl6 = {
|
|
|
|
.flowi6_iif = skb->dev->ifindex,
|
|
|
|
.flowi6_mark = skb->mark,
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
};
|
|
|
|
int reg_vif_num;
|
2008-04-03 08:22:54 +08:00
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
|
|
|
|
goto drop;
|
|
|
|
|
|
|
|
pim = (struct pimreghdr *)skb_transport_header(skb);
|
2016-10-31 20:21:04 +08:00
|
|
|
if (pim->type != ((PIM_VERSION << 4) | PIM_TYPE_REGISTER) ||
|
2008-04-03 08:22:54 +08:00
|
|
|
(pim->flags & PIM_NULL_REGISTER) ||
|
2009-01-28 14:39:59 +08:00
|
|
|
(csum_ipv6_magic(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
|
|
|
|
sizeof(*pim), IPPROTO_PIM,
|
|
|
|
csum_partial((void *)pim, sizeof(*pim), 0)) &&
|
2008-04-27 13:28:58 +08:00
|
|
|
csum_fold(skb_checksum(skb, 0, skb->len, 0))))
|
2008-04-03 08:22:54 +08:00
|
|
|
goto drop;
|
|
|
|
|
|
|
|
/* check if the inner packet is destined to mcast group */
|
|
|
|
encap = (struct ipv6hdr *)(skb_transport_header(skb) +
|
|
|
|
sizeof(*pim));
|
|
|
|
|
|
|
|
if (!ipv6_addr_is_multicast(&encap->daddr) ||
|
|
|
|
encap->payload_len == 0 ||
|
|
|
|
ntohs(encap->payload_len) + sizeof(*pim) > skb->len)
|
|
|
|
goto drop;
|
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
if (ip6mr_fib_lookup(net, &fl6, &mrt) < 0)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
goto drop;
|
|
|
|
|
2022-06-23 12:34:41 +08:00
|
|
|
/* Pairs with WRITE_ONCE() in mif6_add()/mif6_delete() */
|
|
|
|
reg_vif_num = READ_ONCE(mrt->mroute_reg_vif_num);
|
2008-04-03 08:22:54 +08:00
|
|
|
if (reg_vif_num >= 0)
|
2022-06-23 12:34:32 +08:00
|
|
|
reg_dev = vif_dev_read(&mrt->vif_table[reg_vif_num]);
|
2008-04-03 08:22:54 +08:00
|
|
|
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!reg_dev)
|
2008-04-03 08:22:54 +08:00
|
|
|
goto drop;
|
|
|
|
|
|
|
|
skb->mac_header = skb->network_header;
|
|
|
|
skb_pull(skb, (u8 *)encap - skb->data);
|
|
|
|
skb_reset_network_header(skb);
|
2009-01-28 14:39:59 +08:00
|
|
|
skb->protocol = htons(ETH_P_IPV6);
|
2011-03-26 13:10:30 +08:00
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
2010-05-18 13:36:55 +08:00
|
|
|
|
2013-09-02 21:34:58 +08:00
|
|
|
skb_tunnel_rx(skb, reg_dev, dev_net(reg_dev));
|
2010-05-18 13:36:55 +08:00
|
|
|
|
2010-10-01 05:06:55 +08:00
|
|
|
netif_rx(skb);
|
2010-09-20 08:12:11 +08:00
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
return 0;
|
|
|
|
drop:
|
|
|
|
kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-14 20:22:28 +08:00
|
|
|
static const struct inet6_protocol pim6_protocol = {
|
2008-04-03 08:22:54 +08:00
|
|
|
.handler = pim6_rcv,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Service routines creating virtual interfaces: PIMREG */
|
|
|
|
|
2009-09-01 03:50:41 +08:00
|
|
|
static netdev_tx_t reg_vif_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
2008-04-03 08:22:54 +08:00
|
|
|
{
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = dev_net(dev);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2011-03-13 05:22:43 +08:00
|
|
|
struct flowi6 fl6 = {
|
|
|
|
.flowi6_oif = dev->ifindex,
|
ipv4, fib: pass LOOPBACK_IFINDEX instead of 0 to flowi4_iif
As suggested by Julian:
Simply, flowi4_iif must not contain 0, it does not
look logical to ignore all ip rules with specified iif.
because in fib_rule_match() we do:
if (rule->iifindex && (rule->iifindex != fl->flowi_iif))
goto out;
flowi4_iif should be LOOPBACK_IFINDEX by default.
We need to move LOOPBACK_IFINDEX to include/net/flow.h:
1) It is mostly used by flowi_iif
2) Fix the following compile error if we use it in flow.h
by the patches latter:
In file included from include/linux/netfilter.h:277:0,
from include/net/netns/netfilter.h:5,
from include/net/net_namespace.h:21,
from include/linux/netdevice.h:43,
from include/linux/icmpv6.h:12,
from include/linux/ipv6.h:61,
from include/net/ipv6.h:16,
from include/linux/sunrpc/clnt.h:27,
from include/linux/nfs_fs.h:30,
from init/do_mounts.c:32:
include/net/flow.h: In function ‘flowi4_init_output’:
include/net/flow.h:84:32: error: ‘LOOPBACK_IFINDEX’ undeclared (first use in this function)
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Julian Anastasov <ja@ssi.bg>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Cong Wang <cwang@twopensource.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-04-16 07:25:34 +08:00
|
|
|
.flowi6_iif = skb->skb_iif ? : LOOPBACK_IFINDEX,
|
2011-03-13 05:22:43 +08:00
|
|
|
.flowi6_mark = skb->mark,
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
};
|
|
|
|
|
2018-12-31 06:24:36 +08:00
|
|
|
if (!pskb_inet_may_pull(skb))
|
|
|
|
goto tx_err;
|
|
|
|
|
|
|
|
if (ip6mr_fib_lookup(net, &fl6, &mrt) < 0)
|
|
|
|
goto tx_err;
|
2008-12-11 08:30:15 +08:00
|
|
|
|
2008-05-22 05:17:54 +08:00
|
|
|
dev->stats.tx_bytes += skb->len;
|
|
|
|
dev->stats.tx_packets++;
|
2022-06-23 12:34:40 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
ip6mr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num),
|
|
|
|
MRT6MSG_WHOLEPKT);
|
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:54 +08:00
|
|
|
kfree_skb(skb);
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2018-12-31 06:24:36 +08:00
|
|
|
|
|
|
|
tx_err:
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
kfree_skb(skb);
|
|
|
|
return NETDEV_TX_OK;
|
2008-04-03 08:22:54 +08:00
|
|
|
}
|
|
|
|
|
2015-04-02 23:07:03 +08:00
|
|
|
static int reg_vif_get_iflink(const struct net_device *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:28:35 +08:00
|
|
|
static const struct net_device_ops reg_vif_netdev_ops = {
|
|
|
|
.ndo_start_xmit = reg_vif_xmit,
|
2015-04-02 23:07:03 +08:00
|
|
|
.ndo_get_iflink = reg_vif_get_iflink,
|
2008-11-21 12:28:35 +08:00
|
|
|
};
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
static void reg_vif_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
dev->type = ARPHRD_PIMREG;
|
|
|
|
dev->mtu = 1500 - sizeof(struct ipv6hdr) - 8;
|
|
|
|
dev->flags = IFF_NOARP;
|
2008-11-21 12:28:35 +08:00
|
|
|
dev->netdev_ops = ®_vif_netdev_ops;
|
net: Fix inconsistent teardown and release of private netdev state.
Network devices can allocate reasources and private memory using
netdev_ops->ndo_init(). However, the release of these resources
can occur in one of two different places.
Either netdev_ops->ndo_uninit() or netdev->destructor().
The decision of which operation frees the resources depends upon
whether it is necessary for all netdev refs to be released before it
is safe to perform the freeing.
netdev_ops->ndo_uninit() presumably can occur right after the
NETDEV_UNREGISTER notifier completes and the unicast and multicast
address lists are flushed.
netdev->destructor(), on the other hand, does not run until the
netdev references all go away.
Further complicating the situation is that netdev->destructor()
almost universally does also a free_netdev().
This creates a problem for the logic in register_netdevice().
Because all callers of register_netdevice() manage the freeing
of the netdev, and invoke free_netdev(dev) if register_netdevice()
fails.
If netdev_ops->ndo_init() succeeds, but something else fails inside
of register_netdevice(), it does call ndo_ops->ndo_uninit(). But
it is not able to invoke netdev->destructor().
This is because netdev->destructor() will do a free_netdev() and
then the caller of register_netdevice() will do the same.
However, this means that the resources that would normally be released
by netdev->destructor() will not be.
Over the years drivers have added local hacks to deal with this, by
invoking their destructor parts by hand when register_netdevice()
fails.
Many drivers do not try to deal with this, and instead we have leaks.
Let's close this hole by formalizing the distinction between what
private things need to be freed up by netdev->destructor() and whether
the driver needs unregister_netdevice() to perform the free_netdev().
netdev->priv_destructor() performs all actions to free up the private
resources that used to be freed by netdev->destructor(), except for
free_netdev().
netdev->needs_free_netdev is a boolean that indicates whether
free_netdev() should be done at the end of unregister_netdevice().
Now, register_netdevice() can sanely release all resources after
ndo_ops->ndo_init() succeeds, by invoking both ndo_ops->ndo_uninit()
and netdev->priv_destructor().
And at the end of unregister_netdevice(), we invoke
netdev->priv_destructor() and optionally call free_netdev().
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-05-09 00:52:56 +08:00
|
|
|
dev->needs_free_netdev = true;
|
2009-06-14 18:16:13 +08:00
|
|
|
dev->features |= NETIF_F_NETNS_LOCAL;
|
2008-04-03 08:22:54 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static struct net_device *ip6mr_reg_vif(struct net *net, struct mr_table *mrt)
|
2008-04-03 08:22:54 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
char name[IFNAMSIZ];
|
|
|
|
|
|
|
|
if (mrt->id == RT6_TABLE_DFLT)
|
|
|
|
sprintf(name, "pim6reg");
|
|
|
|
else
|
|
|
|
sprintf(name, "pim6reg%u", mrt->id);
|
2008-04-03 08:22:54 +08:00
|
|
|
|
net: set name_assign_type in alloc_netdev()
Extend alloc_netdev{,_mq{,s}}() to take name_assign_type as argument, and convert
all users to pass NET_NAME_UNKNOWN.
Coccinelle patch:
@@
expression sizeof_priv, name, setup, txqs, rxqs, count;
@@
(
-alloc_netdev_mqs(sizeof_priv, name, setup, txqs, rxqs)
+alloc_netdev_mqs(sizeof_priv, name, NET_NAME_UNKNOWN, setup, txqs, rxqs)
|
-alloc_netdev_mq(sizeof_priv, name, setup, count)
+alloc_netdev_mq(sizeof_priv, name, NET_NAME_UNKNOWN, setup, count)
|
-alloc_netdev(sizeof_priv, name, setup)
+alloc_netdev(sizeof_priv, name, NET_NAME_UNKNOWN, setup)
)
v9: move comments here from the wrong commit
Signed-off-by: Tom Gundersen <teg@jklm.no>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-07-14 22:37:24 +08:00
|
|
|
dev = alloc_netdev(0, name, NET_NAME_UNKNOWN, reg_vif_setup);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!dev)
|
2008-04-03 08:22:54 +08:00
|
|
|
return NULL;
|
|
|
|
|
2008-12-11 08:30:15 +08:00
|
|
|
dev_net_set(dev, net);
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
if (register_netdevice(dev)) {
|
|
|
|
free_netdev(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-12-07 01:05:36 +08:00
|
|
|
if (dev_open(dev, NULL))
|
2008-04-03 08:22:54 +08:00
|
|
|
goto failure;
|
|
|
|
|
2008-07-15 11:54:54 +08:00
|
|
|
dev_hold(dev);
|
2008-04-03 08:22:54 +08:00
|
|
|
return dev;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
unregister_netdevice(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-26 20:01:34 +08:00
|
|
|
static int call_ip6mr_vif_entry_notifiers(struct net *net,
|
|
|
|
enum fib_event_type event_type,
|
|
|
|
struct vif_device *vif,
|
2022-06-23 12:34:32 +08:00
|
|
|
struct net_device *vif_dev,
|
2018-03-26 20:01:34 +08:00
|
|
|
mifi_t vif_index, u32 tb_id)
|
|
|
|
{
|
|
|
|
return mr_call_vif_notifiers(net, RTNL_FAMILY_IP6MR, event_type,
|
2022-06-23 12:34:32 +08:00
|
|
|
vif, vif_dev, vif_index, tb_id,
|
2018-03-26 20:01:34 +08:00
|
|
|
&net->ipv6.ipmr_seq);
|
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-26 20:01:34 +08:00
|
|
|
static int call_ip6mr_mfc_entry_notifiers(struct net *net,
|
|
|
|
enum fib_event_type event_type,
|
|
|
|
struct mfc6_cache *mfc, u32 tb_id)
|
|
|
|
{
|
|
|
|
return mr_call_mfc_notifiers(net, RTNL_FAMILY_IP6MR, event_type,
|
|
|
|
&mfc->_c, tb_id, &net->ipv6.ipmr_seq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a VIF entry */
|
2018-03-01 05:29:32 +08:00
|
|
|
static int mif6_delete(struct mr_table *mrt, int vifi, int notify,
|
2017-04-22 01:42:16 +08:00
|
|
|
struct list_head *head)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:29 +08:00
|
|
|
struct vif_device *v;
|
2008-04-03 08:22:53 +08:00
|
|
|
struct net_device *dev;
|
2009-01-28 14:39:59 +08:00
|
|
|
struct inet6_dev *in6_dev;
|
2010-05-11 20:40:53 +08:00
|
|
|
|
|
|
|
if (vifi < 0 || vifi >= mrt->maxvif)
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
v = &mrt->vif_table[vifi];
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2022-06-23 12:34:32 +08:00
|
|
|
dev = rtnl_dereference(v->dev);
|
|
|
|
if (!dev)
|
|
|
|
return -EADDRNOTAVAIL;
|
2018-03-26 20:01:34 +08:00
|
|
|
|
2022-06-23 12:34:32 +08:00
|
|
|
call_ip6mr_vif_entry_notifiers(read_pnet(&mrt->net),
|
|
|
|
FIB_EVENT_VIF_DEL, v, dev,
|
|
|
|
vifi, mrt->id);
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_lock(&mrt_lock);
|
2022-06-23 12:34:32 +08:00
|
|
|
RCU_INIT_POINTER(v->dev, NULL);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
2022-06-23 12:34:40 +08:00
|
|
|
if (vifi == mrt->mroute_reg_vif_num) {
|
|
|
|
/* Pairs with READ_ONCE() in ip6mr_cache_report() and reg_vif_xmit() */
|
|
|
|
WRITE_ONCE(mrt->mroute_reg_vif_num, -1);
|
|
|
|
}
|
2008-04-03 08:22:54 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
if (vifi + 1 == mrt->maxvif) {
|
2008-04-03 08:22:53 +08:00
|
|
|
int tmp;
|
|
|
|
for (tmp = vifi - 1; tmp >= 0; tmp--) {
|
2018-03-01 05:29:32 +08:00
|
|
|
if (VIF_EXISTS(mrt, tmp))
|
2008-04-03 08:22:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2022-06-23 12:34:43 +08:00
|
|
|
WRITE_ONCE(mrt->maxvif, tmp + 1);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_unlock(&mrt_lock);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
dev_set_allmulti(dev, -1);
|
|
|
|
|
2009-01-28 14:39:59 +08:00
|
|
|
in6_dev = __in6_dev_get(dev);
|
2012-12-04 09:13:35 +08:00
|
|
|
if (in6_dev) {
|
2022-02-05 04:15:45 +08:00
|
|
|
atomic_dec(&in6_dev->cnf.mc_forwarding);
|
2017-03-29 05:28:04 +08:00
|
|
|
inet6_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF,
|
2012-12-04 09:13:35 +08:00
|
|
|
NETCONFA_MC_FORWARDING,
|
|
|
|
dev->ifindex, &in6_dev->cnf);
|
|
|
|
}
|
2009-01-28 14:39:59 +08:00
|
|
|
|
2017-04-22 01:42:16 +08:00
|
|
|
if ((v->flags & MIFF_REGISTER) && !notify)
|
2009-10-28 12:48:11 +08:00
|
|
|
unregister_netdevice_queue(dev, head);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2022-06-08 12:39:55 +08:00
|
|
|
netdev_put(dev, &v->dev_tracker);
|
2008-04-03 08:22:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
static inline void ip6mr_cache_free_rcu(struct rcu_head *head)
|
2008-12-11 08:22:34 +08:00
|
|
|
{
|
2018-03-01 05:29:34 +08:00
|
|
|
struct mr_mfc *c = container_of(head, struct mr_mfc, rcu);
|
2018-03-01 05:29:31 +08:00
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
kmem_cache_free(mrt_cachep, (struct mfc6_cache *)c);
|
2008-12-11 08:22:34 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
static inline void ip6mr_cache_free(struct mfc6_cache *c)
|
|
|
|
{
|
2018-03-01 05:29:34 +08:00
|
|
|
call_rcu(&c->_c.rcu, ip6mr_cache_free_rcu);
|
2018-03-01 05:29:31 +08:00
|
|
|
}
|
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
/* Destroy an unresolved cache entry, killing queued skbs
|
|
|
|
and reporting error to netlink readers.
|
|
|
|
*/
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static void ip6mr_destroy_unres(struct mr_table *mrt, struct mfc6_cache *c)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2010-05-11 20:40:53 +08:00
|
|
|
struct net *net = read_pnet(&mrt->net);
|
2008-04-03 08:22:53 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
atomic_dec(&mrt->cache_resolve_queue_len);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
while ((skb = skb_dequeue(&c->_c.mfc_un.unres.unresolved)) != NULL) {
|
2008-04-03 08:22:53 +08:00
|
|
|
if (ipv6_hdr(skb)->version == 0) {
|
networking: make skb_pull & friends return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = {
skb_pull,
__skb_pull,
skb_pull_inline,
__pskb_pull_tail,
__pskb_pull,
pskb_pull
};
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = {
skb_pull,
__skb_pull,
skb_pull_inline,
__pskb_pull_tail,
__pskb_pull,
pskb_pull
};
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:22 +08:00
|
|
|
struct nlmsghdr *nlh = skb_pull(skb,
|
|
|
|
sizeof(struct ipv6hdr));
|
2008-04-03 08:22:53 +08:00
|
|
|
nlh->nlmsg_type = NLMSG_ERROR;
|
2013-03-27 14:47:04 +08:00
|
|
|
nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr));
|
2008-04-03 08:22:53 +08:00
|
|
|
skb_trim(skb, nlh->nlmsg_len);
|
2013-03-27 14:47:04 +08:00
|
|
|
((struct nlmsgerr *)nlmsg_data(nlh))->error = -ETIMEDOUT;
|
2012-09-08 04:12:54 +08:00
|
|
|
rtnl_unicast(skb, net, NETLINK_CB(skb).portid);
|
2008-04-03 08:22:53 +08:00
|
|
|
} else
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
2008-12-11 08:22:34 +08:00
|
|
|
ip6mr_cache_free(c);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-11 20:40:48 +08:00
|
|
|
/* Timer process for all the unresolved queue. */
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static void ipmr_do_expire_process(struct mr_table *mrt)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
unsigned long expires = 10 * HZ;
|
2018-03-01 05:29:34 +08:00
|
|
|
struct mr_mfc *c, *next;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) {
|
2008-04-03 08:22:53 +08:00
|
|
|
if (time_after(c->mfc_un.unres.expires, now)) {
|
|
|
|
/* not yet... */
|
|
|
|
unsigned long interval = c->mfc_un.unres.expires - now;
|
|
|
|
if (interval < expires)
|
|
|
|
expires = interval;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-05-11 20:40:51 +08:00
|
|
|
list_del(&c->list);
|
2018-03-01 05:29:34 +08:00
|
|
|
mr6_netlink_event(mrt, (struct mfc6_cache *)c, RTM_DELROUTE);
|
|
|
|
ip6mr_destroy_unres(mrt, (struct mfc6_cache *)c);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
if (!list_empty(&mrt->mfc_unres_queue))
|
2010-05-11 20:40:53 +08:00
|
|
|
mod_timer(&mrt->ipmr_expire_timer, jiffies + expires);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-17 05:43:17 +08:00
|
|
|
static void ipmr_expire_process(struct timer_list *t)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt = from_timer(mrt, t, ipmr_expire_timer);
|
2010-05-11 20:40:48 +08:00
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
if (!spin_trylock(&mfc_unres_lock)) {
|
2010-05-11 20:40:53 +08:00
|
|
|
mod_timer(&mrt->ipmr_expire_timer, jiffies + 1);
|
2008-04-03 08:22:53 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
if (!list_empty(&mrt->mfc_unres_queue))
|
2010-05-11 20:40:53 +08:00
|
|
|
ipmr_do_expire_process(mrt);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
spin_unlock(&mfc_unres_lock);
|
|
|
|
}
|
|
|
|
|
2022-06-23 12:34:49 +08:00
|
|
|
/* Fill oifs list. It is called under locked mrt_lock. */
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static void ip6mr_update_thresholds(struct mr_table *mrt,
|
2018-03-01 05:29:34 +08:00
|
|
|
struct mr_mfc *cache,
|
2010-05-11 20:40:50 +08:00
|
|
|
unsigned char *ttls)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
int vifi;
|
|
|
|
|
2008-04-10 17:40:10 +08:00
|
|
|
cache->mfc_un.res.minvif = MAXMIFS;
|
2008-04-03 08:22:53 +08:00
|
|
|
cache->mfc_un.res.maxvif = 0;
|
2008-04-10 17:40:10 +08:00
|
|
|
memset(cache->mfc_un.res.ttls, 255, MAXMIFS);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
for (vifi = 0; vifi < mrt->maxvif; vifi++) {
|
2018-03-01 05:29:32 +08:00
|
|
|
if (VIF_EXISTS(mrt, vifi) &&
|
2008-12-11 08:15:08 +08:00
|
|
|
ttls[vifi] && ttls[vifi] < 255) {
|
2008-04-03 08:22:53 +08:00
|
|
|
cache->mfc_un.res.ttls[vifi] = ttls[vifi];
|
|
|
|
if (cache->mfc_un.res.minvif > vifi)
|
|
|
|
cache->mfc_un.res.minvif = vifi;
|
|
|
|
if (cache->mfc_un.res.maxvif <= vifi)
|
|
|
|
cache->mfc_un.res.maxvif = vifi + 1;
|
|
|
|
}
|
|
|
|
}
|
2016-07-27 00:54:52 +08:00
|
|
|
cache->mfc_un.res.lastuse = jiffies;
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static int mif6_add(struct net *net, struct mr_table *mrt,
|
2010-05-11 20:40:53 +08:00
|
|
|
struct mif6ctl *vifc, int mrtsock)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
int vifi = vifc->mif6c_mifi;
|
2018-03-01 05:29:32 +08:00
|
|
|
struct vif_device *v = &mrt->vif_table[vifi];
|
2008-04-03 08:22:53 +08:00
|
|
|
struct net_device *dev;
|
2009-01-28 14:39:59 +08:00
|
|
|
struct inet6_dev *in6_dev;
|
2008-07-15 11:54:23 +08:00
|
|
|
int err;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
/* Is vif busy ? */
|
2018-03-01 05:29:32 +08:00
|
|
|
if (VIF_EXISTS(mrt, vifi))
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EADDRINUSE;
|
|
|
|
|
|
|
|
switch (vifc->mif6c_flags) {
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
case MIFF_REGISTER:
|
|
|
|
/*
|
|
|
|
* Special Purpose VIF in PIM
|
|
|
|
* All the packets will be sent to the daemon
|
|
|
|
*/
|
2010-05-11 20:40:53 +08:00
|
|
|
if (mrt->mroute_reg_vif_num >= 0)
|
2008-04-03 08:22:54 +08:00
|
|
|
return -EADDRINUSE;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
dev = ip6mr_reg_vif(net, mrt);
|
2008-04-03 08:22:54 +08:00
|
|
|
if (!dev)
|
|
|
|
return -ENOBUFS;
|
2008-07-15 11:54:23 +08:00
|
|
|
err = dev_set_allmulti(dev, 1);
|
|
|
|
if (err) {
|
|
|
|
unregister_netdevice(dev);
|
2008-07-15 11:54:54 +08:00
|
|
|
dev_put(dev);
|
2008-07-15 11:54:23 +08:00
|
|
|
return err;
|
|
|
|
}
|
2008-04-03 08:22:54 +08:00
|
|
|
break;
|
|
|
|
#endif
|
2008-04-03 08:22:53 +08:00
|
|
|
case 0:
|
2008-12-11 08:30:15 +08:00
|
|
|
dev = dev_get_by_index(net, vifc->mif6c_pifi);
|
2008-04-03 08:22:53 +08:00
|
|
|
if (!dev)
|
|
|
|
return -EADDRNOTAVAIL;
|
2008-07-15 11:54:23 +08:00
|
|
|
err = dev_set_allmulti(dev, 1);
|
2008-07-15 11:54:54 +08:00
|
|
|
if (err) {
|
|
|
|
dev_put(dev);
|
2008-07-15 11:54:23 +08:00
|
|
|
return err;
|
2008-07-15 11:54:54 +08:00
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-01-28 14:39:59 +08:00
|
|
|
in6_dev = __in6_dev_get(dev);
|
2012-12-04 09:13:35 +08:00
|
|
|
if (in6_dev) {
|
2022-02-05 04:15:45 +08:00
|
|
|
atomic_inc(&in6_dev->cnf.mc_forwarding);
|
2017-03-29 05:28:04 +08:00
|
|
|
inet6_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF,
|
2012-12-04 09:13:35 +08:00
|
|
|
NETCONFA_MC_FORWARDING,
|
|
|
|
dev->ifindex, &in6_dev->cnf);
|
|
|
|
}
|
2009-01-28 14:39:59 +08:00
|
|
|
|
2018-03-01 05:29:29 +08:00
|
|
|
/* Fill in the VIF structures */
|
|
|
|
vif_device_init(v, dev, vifc->vifc_rate_limit, vifc->vifc_threshold,
|
|
|
|
vifc->mif6c_flags | (!mrtsock ? VIFF_STATIC : 0),
|
|
|
|
MIFF_REGISTER);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
/* And finish update writing critical data */
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_lock(&mrt_lock);
|
2022-06-23 12:34:32 +08:00
|
|
|
rcu_assign_pointer(v->dev, dev);
|
2021-12-05 12:22:16 +08:00
|
|
|
netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC);
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
if (v->flags & MIFF_REGISTER)
|
2022-06-23 12:34:40 +08:00
|
|
|
WRITE_ONCE(mrt->mroute_reg_vif_num, vifi);
|
2008-04-03 08:22:54 +08:00
|
|
|
#endif
|
2010-05-11 20:40:53 +08:00
|
|
|
if (vifi + 1 > mrt->maxvif)
|
2022-06-23 12:34:43 +08:00
|
|
|
WRITE_ONCE(mrt->maxvif, vifi + 1);
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_unlock(&mrt_lock);
|
2018-03-26 20:01:34 +08:00
|
|
|
call_ip6mr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD,
|
2022-06-23 12:34:32 +08:00
|
|
|
v, dev, vifi, mrt->id);
|
2008-04-03 08:22:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static struct mfc6_cache *ip6mr_cache_find(struct mr_table *mrt,
|
2011-04-22 12:53:02 +08:00
|
|
|
const struct in6_addr *origin,
|
|
|
|
const struct in6_addr *mcastgrp)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:31 +08:00
|
|
|
struct mfc6_cache_cmp_arg arg = {
|
|
|
|
.mf6c_origin = *origin,
|
|
|
|
.mf6c_mcastgrp = *mcastgrp,
|
|
|
|
};
|
|
|
|
|
2018-03-01 05:29:35 +08:00
|
|
|
return mr_mfc_find(mrt, &arg);
|
2013-01-21 14:00:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for a (*,G) entry */
|
2018-03-01 05:29:32 +08:00
|
|
|
static struct mfc6_cache *ip6mr_cache_find_any(struct mr_table *mrt,
|
2013-01-21 14:00:26 +08:00
|
|
|
struct in6_addr *mcastgrp,
|
|
|
|
mifi_t mifi)
|
|
|
|
{
|
2018-03-01 05:29:31 +08:00
|
|
|
struct mfc6_cache_cmp_arg arg = {
|
|
|
|
.mf6c_origin = in6addr_any,
|
|
|
|
.mf6c_mcastgrp = *mcastgrp,
|
|
|
|
};
|
2013-01-21 14:00:26 +08:00
|
|
|
|
|
|
|
if (ipv6_addr_any(mcastgrp))
|
2018-03-01 05:29:35 +08:00
|
|
|
return mr_mfc_find_any_parent(mrt, mifi);
|
|
|
|
return mr_mfc_find_any(mrt, mifi, &arg);
|
2013-01-21 14:00:26 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
/* Look for a (S,G,iif) entry if parent != -1 */
|
|
|
|
static struct mfc6_cache *
|
2018-03-01 05:29:32 +08:00
|
|
|
ip6mr_cache_find_parent(struct mr_table *mrt,
|
2018-03-01 05:29:31 +08:00
|
|
|
const struct in6_addr *origin,
|
|
|
|
const struct in6_addr *mcastgrp,
|
|
|
|
int parent)
|
|
|
|
{
|
|
|
|
struct mfc6_cache_cmp_arg arg = {
|
|
|
|
.mf6c_origin = *origin,
|
|
|
|
.mf6c_mcastgrp = *mcastgrp,
|
|
|
|
};
|
|
|
|
|
2018-03-01 05:29:35 +08:00
|
|
|
return mr_mfc_find_parent(mrt, &arg, parent);
|
2018-03-01 05:29:31 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:35 +08:00
|
|
|
/* Allocate a multicast cache entry */
|
2010-05-11 20:40:50 +08:00
|
|
|
static struct mfc6_cache *ip6mr_cache_alloc(void)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2008-12-04 14:27:25 +08:00
|
|
|
struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!c)
|
2008-04-03 08:22:53 +08:00
|
|
|
return NULL;
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1;
|
|
|
|
c->_c.mfc_un.res.minvif = MAXMIFS;
|
2018-03-26 20:01:36 +08:00
|
|
|
c->_c.free = ip6mr_cache_free_rcu;
|
|
|
|
refcount_set(&c->_c.mfc_un.res.refcount, 1);
|
2008-04-03 08:22:53 +08:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-05-11 20:40:50 +08:00
|
|
|
static struct mfc6_cache *ip6mr_cache_alloc_unres(void)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2008-12-04 14:27:25 +08:00
|
|
|
struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!c)
|
2008-04-03 08:22:53 +08:00
|
|
|
return NULL;
|
2018-03-01 05:29:34 +08:00
|
|
|
skb_queue_head_init(&c->_c.mfc_un.unres.unresolved);
|
|
|
|
c->_c.mfc_un.unres.expires = jiffies + 10 * HZ;
|
2008-04-03 08:22:53 +08:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A cache entry has gone into a resolved state from queued
|
|
|
|
*/
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static void ip6mr_cache_resolve(struct net *net, struct mr_table *mrt,
|
2010-05-11 20:40:53 +08:00
|
|
|
struct mfc6_cache *uc, struct mfc6_cache *c)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Play the pending entries through our router
|
|
|
|
*/
|
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.unresolved))) {
|
2008-04-03 08:22:53 +08:00
|
|
|
if (ipv6_hdr(skb)->version == 0) {
|
networking: make skb_pull & friends return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = {
skb_pull,
__skb_pull,
skb_pull_inline,
__pskb_pull_tail,
__pskb_pull,
pskb_pull
};
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = {
skb_pull,
__skb_pull,
skb_pull_inline,
__pskb_pull_tail,
__pskb_pull,
pskb_pull
};
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:22 +08:00
|
|
|
struct nlmsghdr *nlh = skb_pull(skb,
|
|
|
|
sizeof(struct ipv6hdr));
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:39 +08:00
|
|
|
if (mr_fill_mroute(mrt, skb, &c->_c,
|
|
|
|
nlmsg_data(nlh)) > 0) {
|
2008-04-05 21:17:39 +08:00
|
|
|
nlh->nlmsg_len = skb_tail_pointer(skb) - (u8 *)nlh;
|
2008-04-03 08:22:53 +08:00
|
|
|
} else {
|
|
|
|
nlh->nlmsg_type = NLMSG_ERROR;
|
2013-03-27 14:47:04 +08:00
|
|
|
nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr));
|
2008-04-03 08:22:53 +08:00
|
|
|
skb_trim(skb, nlh->nlmsg_len);
|
2013-03-27 14:47:04 +08:00
|
|
|
((struct nlmsgerr *)nlmsg_data(nlh))->error = -EMSGSIZE;
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
2012-09-08 04:12:54 +08:00
|
|
|
rtnl_unicast(skb, net, NETLINK_CB(skb).portid);
|
2008-04-03 08:22:53 +08:00
|
|
|
} else
|
2018-10-01 16:41:27 +08:00
|
|
|
ip6_mr_forward(net, mrt, skb->dev, skb, c);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-06-21 04:54:18 +08:00
|
|
|
* Bounce a cache query up to pim6sd and netlink.
|
2008-04-03 08:22:53 +08:00
|
|
|
*
|
2022-06-23 12:34:40 +08:00
|
|
|
* Called under rcu_read_lock()
|
2008-04-03 08:22:53 +08:00
|
|
|
*/
|
|
|
|
|
2022-06-23 12:34:40 +08:00
|
|
|
static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt,
|
2010-05-11 20:40:53 +08:00
|
|
|
mifi_t mifi, int assert)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:30 +08:00
|
|
|
struct sock *mroute6_sk;
|
2008-04-03 08:22:53 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
struct mrt6msg *msg;
|
|
|
|
int ret;
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
2022-02-17 15:46:40 +08:00
|
|
|
if (assert == MRT6MSG_WHOLEPKT || assert == MRT6MSG_WRMIFWHOLE)
|
2008-04-03 08:22:54 +08:00
|
|
|
skb = skb_realloc_headroom(pkt, -skb_network_offset(pkt)
|
|
|
|
+sizeof(*msg));
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
skb = alloc_skb(sizeof(struct ipv6hdr) + sizeof(*msg), GFP_ATOMIC);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
if (!skb)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
|
|
|
/* I suppose that internal messages
|
|
|
|
* do not require checksums */
|
|
|
|
|
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
2022-02-17 15:46:40 +08:00
|
|
|
if (assert == MRT6MSG_WHOLEPKT || assert == MRT6MSG_WRMIFWHOLE) {
|
2008-04-03 08:22:54 +08:00
|
|
|
/* Ugly, but we have no choice with this interface.
|
|
|
|
Duplicate old header, fix length etc.
|
|
|
|
And all this only to mangle msg->im6_msgtype and
|
|
|
|
to set msg->im6_mbz to "mbz" :-)
|
|
|
|
*/
|
|
|
|
skb_push(skb, -skb_network_offset(pkt));
|
|
|
|
|
|
|
|
skb_push(skb, sizeof(*msg));
|
|
|
|
skb_reset_transport_header(skb);
|
|
|
|
msg = (struct mrt6msg *)skb_transport_header(skb);
|
|
|
|
msg->im6_mbz = 0;
|
2022-02-17 15:46:40 +08:00
|
|
|
msg->im6_msgtype = assert;
|
|
|
|
if (assert == MRT6MSG_WRMIFWHOLE)
|
|
|
|
msg->im6_mif = mifi;
|
|
|
|
else
|
2022-06-23 12:34:40 +08:00
|
|
|
msg->im6_mif = READ_ONCE(mrt->mroute_reg_vif_num);
|
2008-04-03 08:22:54 +08:00
|
|
|
msg->im6_pad = 0;
|
2011-11-21 11:39:03 +08:00
|
|
|
msg->im6_src = ipv6_hdr(pkt)->saddr;
|
|
|
|
msg->im6_dst = ipv6_hdr(pkt)->daddr;
|
2008-04-03 08:22:54 +08:00
|
|
|
|
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2008-04-03 08:22:53 +08:00
|
|
|
/*
|
|
|
|
* Copy the IP header
|
|
|
|
*/
|
|
|
|
|
|
|
|
skb_put(skb, sizeof(struct ipv6hdr));
|
|
|
|
skb_reset_network_header(skb);
|
|
|
|
skb_copy_to_linear_data(skb, ipv6_hdr(pkt), sizeof(struct ipv6hdr));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add our header
|
|
|
|
*/
|
|
|
|
skb_put(skb, sizeof(*msg));
|
|
|
|
skb_reset_transport_header(skb);
|
|
|
|
msg = (struct mrt6msg *)skb_transport_header(skb);
|
|
|
|
|
|
|
|
msg->im6_mbz = 0;
|
|
|
|
msg->im6_msgtype = assert;
|
2008-04-10 17:40:10 +08:00
|
|
|
msg->im6_mif = mifi;
|
2008-04-03 08:22:53 +08:00
|
|
|
msg->im6_pad = 0;
|
2011-11-21 11:39:03 +08:00
|
|
|
msg->im6_src = ipv6_hdr(pkt)->saddr;
|
|
|
|
msg->im6_dst = ipv6_hdr(pkt)->daddr;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2009-06-02 13:19:30 +08:00
|
|
|
skb_dst_set(skb, dst_clone(skb_dst(pkt)));
|
2008-04-03 08:22:53 +08:00
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
2008-04-03 08:22:54 +08:00
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
mroute6_sk = rcu_dereference(mrt->mroute_sk);
|
2018-03-01 05:29:30 +08:00
|
|
|
if (!mroute6_sk) {
|
2008-04-03 08:22:53 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-06-21 04:54:18 +08:00
|
|
|
mrt6msg_netlink_event(mrt, skb);
|
|
|
|
|
2018-03-01 05:29:30 +08:00
|
|
|
/* Deliver to user space multicast routing algorithms */
|
|
|
|
ret = sock_queue_rcv_skb(mroute6_sk, skb);
|
2022-06-23 12:34:40 +08:00
|
|
|
|
2008-12-11 08:07:08 +08:00
|
|
|
if (ret < 0) {
|
2012-05-14 05:56:26 +08:00
|
|
|
net_warn_ratelimited("mroute6: pending queue full, dropping entries\n");
|
2008-04-03 08:22:53 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
/* Queue a packet for resolution. It gets locked cache entry! */
|
|
|
|
static int ip6mr_cache_unresolved(struct mr_table *mrt, mifi_t mifi,
|
2018-10-01 16:41:27 +08:00
|
|
|
struct sk_buff *skb, struct net_device *dev)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:34 +08:00
|
|
|
struct mfc6_cache *c;
|
2010-05-11 20:40:51 +08:00
|
|
|
bool found = false;
|
2008-04-03 08:22:53 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
spin_lock_bh(&mfc_unres_lock);
|
2018-03-01 05:29:34 +08:00
|
|
|
list_for_each_entry(c, &mrt->mfc_unres_queue, _c.list) {
|
2010-05-11 20:40:48 +08:00
|
|
|
if (ipv6_addr_equal(&c->mf6c_mcastgrp, &ipv6_hdr(skb)->daddr) &&
|
2010-05-11 20:40:51 +08:00
|
|
|
ipv6_addr_equal(&c->mf6c_origin, &ipv6_hdr(skb)->saddr)) {
|
|
|
|
found = true;
|
2008-04-03 08:22:53 +08:00
|
|
|
break;
|
2010-05-11 20:40:51 +08:00
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2010-05-11 20:40:51 +08:00
|
|
|
if (!found) {
|
2008-04-03 08:22:53 +08:00
|
|
|
/*
|
|
|
|
* Create a new entry if allowable
|
|
|
|
*/
|
|
|
|
|
ipmr: remove hard code cache_resolve_queue_len limit
This is a re-post of previous patch wrote by David Miller[1].
Phil Karn reported[2] that on busy networks with lots of unresolved
multicast routing entries, the creation of new multicast group routes
can be extremely slow and unreliable.
The reason is we hard-coded multicast route entries with unresolved source
addresses(cache_resolve_queue_len) to 10. If some multicast route never
resolves and the unresolved source addresses increased, there will
be no ability to create new multicast route cache.
To resolve this issue, we need either add a sysctl entry to make the
cache_resolve_queue_len configurable, or just remove cache_resolve_queue_len
limit directly, as we already have the socket receive queue limits of mrouted
socket, pointed by David.
>From my side, I'd perfer to remove the cache_resolve_queue_len limit instead
of creating two more(IPv4 and IPv6 version) sysctl entry.
[1] https://lkml.org/lkml/2018/7/22/11
[2] https://lkml.org/lkml/2018/7/21/343
v3: instead of remove cache_resolve_queue_len totally, let's only remove
the hard code limit when allocate the unresolved cache, as Eric Dumazet
suggested, so we don't need to re-count it in other places.
v2: hold the mfc_unres_lock while walking the unresolved list in
queue_count(), as Nikolay Aleksandrov remind.
Reported-by: Phil Karn <karn@ka9q.net>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-09-06 15:36:01 +08:00
|
|
|
c = ip6mr_cache_alloc_unres();
|
|
|
|
if (!c) {
|
2008-04-03 08:22:53 +08:00
|
|
|
spin_unlock_bh(&mfc_unres_lock);
|
|
|
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
/* Fill in the new cache entry */
|
|
|
|
c->_c.mfc_parent = -1;
|
2008-04-03 08:22:53 +08:00
|
|
|
c->mf6c_origin = ipv6_hdr(skb)->saddr;
|
|
|
|
c->mf6c_mcastgrp = ipv6_hdr(skb)->daddr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reflect first query at pim6sd
|
|
|
|
*/
|
2010-05-11 20:40:53 +08:00
|
|
|
err = ip6mr_cache_report(mrt, skb, mifi, MRT6MSG_NOCACHE);
|
2008-12-11 08:30:15 +08:00
|
|
|
if (err < 0) {
|
2008-04-03 08:22:53 +08:00
|
|
|
/* If the report failed throw the cache entry
|
|
|
|
out - Brad Parker
|
|
|
|
*/
|
|
|
|
spin_unlock_bh(&mfc_unres_lock);
|
|
|
|
|
2008-12-11 08:22:34 +08:00
|
|
|
ip6mr_cache_free(c);
|
2008-04-03 08:22:53 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
atomic_inc(&mrt->cache_resolve_queue_len);
|
2018-03-01 05:29:34 +08:00
|
|
|
list_add(&c->_c.list, &mrt->mfc_unres_queue);
|
2012-12-04 09:13:41 +08:00
|
|
|
mr6_netlink_event(mrt, c, RTM_NEWROUTE);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
ipmr_do_expire_process(mrt);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
/* See if we can append the packet */
|
|
|
|
if (c->_c.mfc_un.unres.unresolved.qlen > 3) {
|
2008-04-03 08:22:53 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
err = -ENOBUFS;
|
|
|
|
} else {
|
2018-10-01 16:41:27 +08:00
|
|
|
if (dev) {
|
|
|
|
skb->dev = dev;
|
|
|
|
skb->skb_iif = dev->ifindex;
|
|
|
|
}
|
2018-03-01 05:29:34 +08:00
|
|
|
skb_queue_tail(&c->_c.mfc_un.unres.unresolved, skb);
|
2008-04-03 08:22:53 +08:00
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_bh(&mfc_unres_lock);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MFC6 cache manipulation by user space
|
|
|
|
*/
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static int ip6mr_mfc_delete(struct mr_table *mrt, struct mf6cctl *mfc,
|
2013-01-21 14:00:26 +08:00
|
|
|
int parent)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:31 +08:00
|
|
|
struct mfc6_cache *c;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
/* The entries are added/deleted only under RTNL */
|
|
|
|
rcu_read_lock();
|
|
|
|
c = ip6mr_cache_find_parent(mrt, &mfc->mf6cc_origin.sin6_addr,
|
|
|
|
&mfc->mf6cc_mcastgrp.sin6_addr, parent);
|
|
|
|
rcu_read_unlock();
|
|
|
|
if (!c)
|
|
|
|
return -ENOENT;
|
2018-03-01 05:29:34 +08:00
|
|
|
rhltable_remove(&mrt->mfc_hash, &c->_c.mnode, ip6mr_rht_params);
|
|
|
|
list_del_rcu(&c->_c.list);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-26 20:01:34 +08:00
|
|
|
call_ip6mr_mfc_entry_notifiers(read_pnet(&mrt->net),
|
|
|
|
FIB_EVENT_ENTRY_DEL, c, mrt->id);
|
2018-03-01 05:29:31 +08:00
|
|
|
mr6_netlink_event(mrt, c, RTM_DELROUTE);
|
2018-03-26 20:01:36 +08:00
|
|
|
mr_cache_put(&c->_c);
|
2018-03-01 05:29:31 +08:00
|
|
|
return 0;
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ip6mr_device_event(struct notifier_block *this,
|
|
|
|
unsigned long event, void *ptr)
|
|
|
|
{
|
2013-05-28 09:30:21 +08:00
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = dev_net(dev);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2018-03-01 05:29:29 +08:00
|
|
|
struct vif_device *v;
|
2008-04-03 08:22:53 +08:00
|
|
|
int ct;
|
|
|
|
|
|
|
|
if (event != NETDEV_UNREGISTER)
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
ip6mr_for_each_table(mrt, net) {
|
2018-03-01 05:29:32 +08:00
|
|
|
v = &mrt->vif_table[0];
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
for (ct = 0; ct < mrt->maxvif; ct++, v++) {
|
2022-06-23 12:34:32 +08:00
|
|
|
if (rcu_access_pointer(v->dev) == dev)
|
2017-04-22 01:42:16 +08:00
|
|
|
mif6_delete(mrt, ct, 1, NULL);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
2009-10-28 12:48:11 +08:00
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
2018-03-26 20:01:34 +08:00
|
|
|
static unsigned int ip6mr_seq_read(struct net *net)
|
|
|
|
{
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
return net->ipv6.ipmr_seq + ip6mr_rules_seq_read(net);
|
|
|
|
}
|
|
|
|
|
2019-10-03 17:49:30 +08:00
|
|
|
static int ip6mr_dump(struct net *net, struct notifier_block *nb,
|
|
|
|
struct netlink_ext_ack *extack)
|
2018-03-26 20:01:34 +08:00
|
|
|
{
|
|
|
|
return mr_dump(net, nb, RTNL_FAMILY_IP6MR, ip6mr_rules_dump,
|
2022-06-23 12:34:46 +08:00
|
|
|
ip6mr_mr_table_iter, extack);
|
2018-03-26 20:01:34 +08:00
|
|
|
}
|
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
static struct notifier_block ip6_mr_notifier = {
|
|
|
|
.notifier_call = ip6mr_device_event
|
|
|
|
};
|
|
|
|
|
2018-03-26 20:01:34 +08:00
|
|
|
static const struct fib_notifier_ops ip6mr_notifier_ops_template = {
|
|
|
|
.family = RTNL_FAMILY_IP6MR,
|
|
|
|
.fib_seq_read = ip6mr_seq_read,
|
|
|
|
.fib_dump = ip6mr_dump,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __net_init ip6mr_notifier_init(struct net *net)
|
|
|
|
{
|
|
|
|
struct fib_notifier_ops *ops;
|
|
|
|
|
|
|
|
net->ipv6.ipmr_seq = 0;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-26 20:01:34 +08:00
|
|
|
ops = fib_notifier_ops_register(&ip6mr_notifier_ops_template, net);
|
|
|
|
if (IS_ERR(ops))
|
|
|
|
return PTR_ERR(ops);
|
|
|
|
|
|
|
|
net->ipv6.ip6mr_notifier_ops = ops;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit ip6mr_notifier_exit(struct net *net)
|
|
|
|
{
|
|
|
|
fib_notifier_ops_unregister(net->ipv6.ip6mr_notifier_ops);
|
|
|
|
net->ipv6.ip6mr_notifier_ops = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup for IP multicast routing */
|
2008-12-11 08:15:08 +08:00
|
|
|
static int __net_init ip6mr_net_init(struct net *net)
|
|
|
|
{
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
int err;
|
2010-05-11 20:40:51 +08:00
|
|
|
|
2018-03-26 20:01:34 +08:00
|
|
|
err = ip6mr_notifier_init(net);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
err = ip6mr_rules_init(net);
|
|
|
|
if (err < 0)
|
2018-03-26 20:01:34 +08:00
|
|
|
goto ip6mr_rules_fail;
|
2008-12-11 08:29:48 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
err = -ENOMEM;
|
2018-04-11 01:42:55 +08:00
|
|
|
if (!proc_create_net("ip6_mr_vif", 0, net->proc_net, &ip6mr_vif_seq_ops,
|
|
|
|
sizeof(struct mr_vif_iter)))
|
2008-12-11 08:29:48 +08:00
|
|
|
goto proc_vif_fail;
|
2018-04-11 01:42:55 +08:00
|
|
|
if (!proc_create_net("ip6_mr_cache", 0, net->proc_net, &ipmr_mfc_seq_ops,
|
|
|
|
sizeof(struct mr_mfc_iter)))
|
2008-12-11 08:29:48 +08:00
|
|
|
goto proc_cache_fail;
|
|
|
|
#endif
|
2010-05-11 20:40:53 +08:00
|
|
|
|
2008-12-11 08:24:07 +08:00
|
|
|
return 0;
|
|
|
|
|
2008-12-11 08:29:48 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
proc_cache_fail:
|
2013-02-18 09:34:56 +08:00
|
|
|
remove_proc_entry("ip6_mr_vif", net->proc_net);
|
2008-12-11 08:29:48 +08:00
|
|
|
proc_vif_fail:
|
2022-02-08 12:50:34 +08:00
|
|
|
rtnl_lock();
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
ip6mr_rules_exit(net);
|
2022-02-08 12:50:34 +08:00
|
|
|
rtnl_unlock();
|
2008-12-11 08:29:48 +08:00
|
|
|
#endif
|
2018-03-26 20:01:34 +08:00
|
|
|
ip6mr_rules_fail:
|
|
|
|
ip6mr_notifier_exit(net);
|
2008-12-11 08:15:08 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit ip6mr_net_exit(struct net *net)
|
|
|
|
{
|
2008-12-11 08:29:48 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-02-18 09:34:56 +08:00
|
|
|
remove_proc_entry("ip6_mr_cache", net->proc_net);
|
|
|
|
remove_proc_entry("ip6_mr_vif", net->proc_net);
|
2008-12-11 08:29:48 +08:00
|
|
|
#endif
|
2018-03-26 20:01:34 +08:00
|
|
|
ip6mr_notifier_exit(net);
|
2008-12-11 08:15:08 +08:00
|
|
|
}
|
|
|
|
|
2022-02-08 12:50:34 +08:00
|
|
|
static void __net_exit ip6mr_net_exit_batch(struct list_head *net_list)
|
|
|
|
{
|
|
|
|
struct net *net;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
list_for_each_entry(net, net_list, exit_list)
|
|
|
|
ip6mr_rules_exit(net);
|
|
|
|
rtnl_unlock();
|
|
|
|
}
|
|
|
|
|
2008-12-11 08:15:08 +08:00
|
|
|
static struct pernet_operations ip6mr_net_ops = {
|
|
|
|
.init = ip6mr_net_init,
|
|
|
|
.exit = ip6mr_net_exit,
|
2022-02-08 12:50:34 +08:00
|
|
|
.exit_batch = ip6mr_net_exit_batch,
|
2008-12-11 08:15:08 +08:00
|
|
|
};
|
|
|
|
|
2008-07-03 12:13:30 +08:00
|
|
|
int __init ip6_mr_init(void)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2008-07-03 12:13:30 +08:00
|
|
|
int err;
|
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
mrt_cachep = kmem_cache_create("ip6_mrt_cache",
|
|
|
|
sizeof(struct mfc6_cache),
|
|
|
|
0, SLAB_HWCACHE_ALIGN,
|
|
|
|
NULL);
|
|
|
|
if (!mrt_cachep)
|
2008-07-03 12:13:30 +08:00
|
|
|
return -ENOMEM;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2008-12-11 08:15:08 +08:00
|
|
|
err = register_pernet_subsys(&ip6mr_net_ops);
|
|
|
|
if (err)
|
|
|
|
goto reg_pernet_fail;
|
|
|
|
|
2008-07-03 12:13:30 +08:00
|
|
|
err = register_netdevice_notifier(&ip6_mr_notifier);
|
|
|
|
if (err)
|
|
|
|
goto reg_notif_fail;
|
2009-06-14 18:16:13 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
if (inet6_add_protocol(&pim6_protocol, IPPROTO_PIM) < 0) {
|
2012-05-15 22:11:53 +08:00
|
|
|
pr_err("%s: can't add PIM protocol\n", __func__);
|
2009-06-14 18:16:13 +08:00
|
|
|
err = -EAGAIN;
|
|
|
|
goto add_proto_fail;
|
|
|
|
}
|
|
|
|
#endif
|
2017-12-05 02:19:18 +08:00
|
|
|
err = rtnl_register_module(THIS_MODULE, RTNL_FAMILY_IP6MR, RTM_GETROUTE,
|
|
|
|
NULL, ip6mr_rtm_dumproute, 0);
|
|
|
|
if (err == 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-06-14 18:16:13 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
2017-12-05 02:19:18 +08:00
|
|
|
inet6_del_protocol(&pim6_protocol, IPPROTO_PIM);
|
2009-06-14 18:16:13 +08:00
|
|
|
add_proto_fail:
|
|
|
|
unregister_netdevice_notifier(&ip6_mr_notifier);
|
|
|
|
#endif
|
2008-11-11 08:34:11 +08:00
|
|
|
reg_notif_fail:
|
2008-12-11 08:15:08 +08:00
|
|
|
unregister_pernet_subsys(&ip6mr_net_ops);
|
|
|
|
reg_pernet_fail:
|
2008-11-11 08:34:11 +08:00
|
|
|
kmem_cache_destroy(mrt_cachep);
|
2008-07-03 12:13:30 +08:00
|
|
|
return err;
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2008-07-03 12:13:30 +08:00
|
|
|
void ip6_mr_cleanup(void)
|
|
|
|
{
|
2014-11-19 09:35:39 +08:00
|
|
|
rtnl_unregister(RTNL_FAMILY_IP6MR, RTM_GETROUTE);
|
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
inet6_del_protocol(&pim6_protocol, IPPROTO_PIM);
|
|
|
|
#endif
|
2008-07-03 12:13:30 +08:00
|
|
|
unregister_netdevice_notifier(&ip6_mr_notifier);
|
2008-12-11 08:15:08 +08:00
|
|
|
unregister_pernet_subsys(&ip6mr_net_ops);
|
2008-07-03 12:13:30 +08:00
|
|
|
kmem_cache_destroy(mrt_cachep);
|
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static int ip6mr_mfc_add(struct net *net, struct mr_table *mrt,
|
2013-01-21 14:00:26 +08:00
|
|
|
struct mf6cctl *mfc, int mrtsock, int parent)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2008-04-10 17:40:10 +08:00
|
|
|
unsigned char ttls[MAXMIFS];
|
2018-03-01 05:29:31 +08:00
|
|
|
struct mfc6_cache *uc, *c;
|
2018-03-01 05:29:34 +08:00
|
|
|
struct mr_mfc *_uc;
|
2018-03-01 05:29:31 +08:00
|
|
|
bool found;
|
|
|
|
int i, err;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2010-03-17 14:04:14 +08:00
|
|
|
if (mfc->mf6cc_parent >= MAXMIFS)
|
|
|
|
return -ENFILE;
|
|
|
|
|
2008-04-10 17:40:10 +08:00
|
|
|
memset(ttls, 255, MAXMIFS);
|
|
|
|
for (i = 0; i < MAXMIFS; i++) {
|
2008-04-03 08:22:53 +08:00
|
|
|
if (IF_ISSET(i, &mfc->mf6cc_ifset))
|
|
|
|
ttls[i] = 1;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
/* The entries are added/deleted only under RTNL */
|
|
|
|
rcu_read_lock();
|
|
|
|
c = ip6mr_cache_find_parent(mrt, &mfc->mf6cc_origin.sin6_addr,
|
|
|
|
&mfc->mf6cc_mcastgrp.sin6_addr, parent);
|
|
|
|
rcu_read_unlock();
|
|
|
|
if (c) {
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_lock(&mrt_lock);
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_parent = mfc->mf6cc_parent;
|
|
|
|
ip6mr_update_thresholds(mrt, &c->_c, ttls);
|
2008-04-03 08:22:53 +08:00
|
|
|
if (!mrtsock)
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_flags |= MFC_STATIC;
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_unlock(&mrt_lock);
|
2018-03-26 20:01:34 +08:00
|
|
|
call_ip6mr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_REPLACE,
|
|
|
|
c, mrt->id);
|
2012-12-04 09:13:41 +08:00
|
|
|
mr6_netlink_event(mrt, c, RTM_NEWROUTE);
|
2008-04-03 08:22:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-21 14:00:26 +08:00
|
|
|
if (!ipv6_addr_any(&mfc->mf6cc_mcastgrp.sin6_addr) &&
|
|
|
|
!ipv6_addr_is_multicast(&mfc->mf6cc_mcastgrp.sin6_addr))
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-05-11 20:40:50 +08:00
|
|
|
c = ip6mr_cache_alloc();
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!c)
|
2008-04-03 08:22:53 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
c->mf6c_origin = mfc->mf6cc_origin.sin6_addr;
|
|
|
|
c->mf6c_mcastgrp = mfc->mf6cc_mcastgrp.sin6_addr;
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_parent = mfc->mf6cc_parent;
|
|
|
|
ip6mr_update_thresholds(mrt, &c->_c, ttls);
|
2008-04-03 08:22:53 +08:00
|
|
|
if (!mrtsock)
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_flags |= MFC_STATIC;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
err = rhltable_insert_key(&mrt->mfc_hash, &c->cmparg, &c->_c.mnode,
|
2018-03-01 05:29:31 +08:00
|
|
|
ip6mr_rht_params);
|
|
|
|
if (err) {
|
|
|
|
pr_err("ip6mr: rhtable insert error %d\n", err);
|
|
|
|
ip6mr_cache_free(c);
|
|
|
|
return err;
|
|
|
|
}
|
2018-03-01 05:29:34 +08:00
|
|
|
list_add_tail_rcu(&c->_c.list, &mrt->mfc_cache_list);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
/* Check to see if we resolved a queued list. If so we
|
|
|
|
* need to send on the frames and tidy up.
|
2008-04-03 08:22:53 +08:00
|
|
|
*/
|
2010-05-11 20:40:51 +08:00
|
|
|
found = false;
|
2008-04-03 08:22:53 +08:00
|
|
|
spin_lock_bh(&mfc_unres_lock);
|
2018-03-01 05:29:34 +08:00
|
|
|
list_for_each_entry(_uc, &mrt->mfc_unres_queue, list) {
|
|
|
|
uc = (struct mfc6_cache *)_uc;
|
2010-05-11 20:40:48 +08:00
|
|
|
if (ipv6_addr_equal(&uc->mf6c_origin, &c->mf6c_origin) &&
|
2008-04-03 08:22:53 +08:00
|
|
|
ipv6_addr_equal(&uc->mf6c_mcastgrp, &c->mf6c_mcastgrp)) {
|
2018-03-01 05:29:34 +08:00
|
|
|
list_del(&_uc->list);
|
2010-05-11 20:40:53 +08:00
|
|
|
atomic_dec(&mrt->cache_resolve_queue_len);
|
2010-05-11 20:40:51 +08:00
|
|
|
found = true;
|
2008-04-03 08:22:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-01 05:29:32 +08:00
|
|
|
if (list_empty(&mrt->mfc_unres_queue))
|
2010-05-11 20:40:53 +08:00
|
|
|
del_timer(&mrt->ipmr_expire_timer);
|
2008-04-03 08:22:53 +08:00
|
|
|
spin_unlock_bh(&mfc_unres_lock);
|
|
|
|
|
2010-05-11 20:40:51 +08:00
|
|
|
if (found) {
|
2010-05-11 20:40:53 +08:00
|
|
|
ip6mr_cache_resolve(net, mrt, uc, c);
|
2008-12-11 08:22:34 +08:00
|
|
|
ip6mr_cache_free(uc);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
2018-03-26 20:01:34 +08:00
|
|
|
call_ip6mr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_ADD,
|
|
|
|
c, mrt->id);
|
2012-12-04 09:13:41 +08:00
|
|
|
mr6_netlink_event(mrt, c, RTM_NEWROUTE);
|
2008-04-03 08:22:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the multicast socket, and clear the vif tables etc
|
|
|
|
*/
|
|
|
|
|
2019-02-18 05:07:52 +08:00
|
|
|
static void mroute_clean_tables(struct mr_table *mrt, int flags)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:34 +08:00
|
|
|
struct mr_mfc *c, *tmp;
|
2009-10-28 12:48:11 +08:00
|
|
|
LIST_HEAD(list);
|
2018-03-01 05:29:31 +08:00
|
|
|
int i;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
/* Shut down all active vif entries */
|
2019-02-18 05:07:52 +08:00
|
|
|
if (flags & (MRT6_FLUSH_MIFS | MRT6_FLUSH_MIFS_STATIC)) {
|
|
|
|
for (i = 0; i < mrt->maxvif; i++) {
|
|
|
|
if (((mrt->vif_table[i].flags & VIFF_STATIC) &&
|
|
|
|
!(flags & MRT6_FLUSH_MIFS_STATIC)) ||
|
|
|
|
(!(mrt->vif_table[i].flags & VIFF_STATIC) && !(flags & MRT6_FLUSH_MIFS)))
|
|
|
|
continue;
|
|
|
|
mif6_delete(mrt, i, 0, &list);
|
|
|
|
}
|
|
|
|
unregister_netdevice_many(&list);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
/* Wipe the cache */
|
2019-02-18 05:07:52 +08:00
|
|
|
if (flags & (MRT6_FLUSH_MFC | MRT6_FLUSH_MFC_STATIC)) {
|
|
|
|
list_for_each_entry_safe(c, tmp, &mrt->mfc_cache_list, list) {
|
|
|
|
if (((c->mfc_flags & MFC_STATIC) && !(flags & MRT6_FLUSH_MFC_STATIC)) ||
|
|
|
|
(!(c->mfc_flags & MFC_STATIC) && !(flags & MRT6_FLUSH_MFC)))
|
|
|
|
continue;
|
|
|
|
rhltable_remove(&mrt->mfc_hash, &c->mnode, ip6mr_rht_params);
|
|
|
|
list_del_rcu(&c->list);
|
|
|
|
call_ip6mr_mfc_entry_notifiers(read_pnet(&mrt->net),
|
|
|
|
FIB_EVENT_ENTRY_DEL,
|
|
|
|
(struct mfc6_cache *)c, mrt->id);
|
|
|
|
mr6_netlink_event(mrt, (struct mfc6_cache *)c, RTM_DELROUTE);
|
|
|
|
mr_cache_put(c);
|
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2019-02-18 05:07:52 +08:00
|
|
|
if (flags & MRT6_FLUSH_MFC) {
|
|
|
|
if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
|
|
|
|
spin_lock_bh(&mfc_unres_lock);
|
|
|
|
list_for_each_entry_safe(c, tmp, &mrt->mfc_unres_queue, list) {
|
|
|
|
list_del(&c->list);
|
|
|
|
mr6_netlink_event(mrt, (struct mfc6_cache *)c,
|
|
|
|
RTM_DELROUTE);
|
|
|
|
ip6mr_destroy_unres(mrt, (struct mfc6_cache *)c);
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&mfc_unres_lock);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = sock_net(sk);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
rtnl_lock();
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_lock(&mrt_lock);
|
2018-03-01 05:29:32 +08:00
|
|
|
if (rtnl_dereference(mrt->mroute_sk)) {
|
2008-04-03 08:22:53 +08:00
|
|
|
err = -EADDRINUSE;
|
2018-03-01 05:29:30 +08:00
|
|
|
} else {
|
2018-03-01 05:29:32 +08:00
|
|
|
rcu_assign_pointer(mrt->mroute_sk, sk);
|
2018-03-08 00:43:19 +08:00
|
|
|
sock_set_flag(sk, SOCK_RCU_FREE);
|
2022-02-05 04:15:45 +08:00
|
|
|
atomic_inc(&net->ipv6.devconf_all->mc_forwarding);
|
2016-07-08 11:46:04 +08:00
|
|
|
}
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_unlock(&mrt_lock);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2016-07-08 11:46:04 +08:00
|
|
|
if (!err)
|
2017-03-29 05:28:04 +08:00
|
|
|
inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
|
|
|
|
NETCONFA_MC_FORWARDING,
|
2016-07-08 11:46:04 +08:00
|
|
|
NETCONFA_IFINDEX_ALL,
|
|
|
|
net->ipv6.devconf_all);
|
2008-04-03 08:22:53 +08:00
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ip6mr_sk_done(struct sock *sk)
|
|
|
|
{
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = sock_net(sk);
|
2022-02-06 23:56:00 +08:00
|
|
|
struct ipv6_devconf *devconf;
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2022-02-06 23:56:00 +08:00
|
|
|
int err = -EACCES;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2017-11-09 03:23:46 +08:00
|
|
|
if (sk->sk_type != SOCK_RAW ||
|
|
|
|
inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
|
|
|
|
return err;
|
|
|
|
|
2022-02-06 23:56:00 +08:00
|
|
|
devconf = net->ipv6.devconf_all;
|
|
|
|
if (!devconf || !atomic_read(&devconf->mc_forwarding))
|
2022-02-05 04:15:46 +08:00
|
|
|
return err;
|
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
rtnl_lock();
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
ip6mr_for_each_table(mrt, net) {
|
2018-03-01 05:29:32 +08:00
|
|
|
if (sk == rtnl_dereference(mrt->mroute_sk)) {
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_lock(&mrt_lock);
|
2018-03-01 05:29:32 +08:00
|
|
|
RCU_INIT_POINTER(mrt->mroute_sk, NULL);
|
2018-03-08 00:43:19 +08:00
|
|
|
/* Note that mroute_sk had SOCK_RCU_FREE set,
|
|
|
|
* so the RCU grace period before sk freeing
|
|
|
|
* is guaranteed by sk_destruct()
|
|
|
|
*/
|
2022-02-06 23:56:00 +08:00
|
|
|
atomic_dec(&devconf->mc_forwarding);
|
2022-06-23 12:34:49 +08:00
|
|
|
spin_unlock(&mrt_lock);
|
2017-03-29 05:28:04 +08:00
|
|
|
inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
|
2012-12-04 09:13:35 +08:00
|
|
|
NETCONFA_MC_FORWARDING,
|
|
|
|
NETCONFA_IFINDEX_ALL,
|
|
|
|
net->ipv6.devconf_all);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2019-02-18 05:07:52 +08:00
|
|
|
mroute_clean_tables(mrt, MRT6_FLUSH_MIFS | MRT6_FLUSH_MFC);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:30 +08:00
|
|
|
bool mroute6_is_socket(struct net *net, struct sk_buff *skb)
|
2010-05-11 20:40:53 +08:00
|
|
|
{
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2011-03-13 05:22:43 +08:00
|
|
|
struct flowi6 fl6 = {
|
2014-04-28 15:51:56 +08:00
|
|
|
.flowi6_iif = skb->skb_iif ? : LOOPBACK_IFINDEX,
|
2011-03-13 05:22:43 +08:00
|
|
|
.flowi6_oif = skb->dev->ifindex,
|
|
|
|
.flowi6_mark = skb->mark,
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
};
|
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
if (ip6mr_fib_lookup(net, &fl6, &mrt) < 0)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return NULL;
|
2010-05-11 20:40:53 +08:00
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
return rcu_access_pointer(mrt->mroute_sk);
|
2010-05-11 20:40:53 +08:00
|
|
|
}
|
2018-03-01 05:29:30 +08:00
|
|
|
EXPORT_SYMBOL(mroute6_is_socket);
|
2010-05-11 20:40:53 +08:00
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
/*
|
|
|
|
* Socket options and virtual interface manipulation. The whole
|
|
|
|
* virtual interface system is a complete heap, but unfortunately
|
|
|
|
* that's how BSD mrouted happens to think. Maybe one day with a proper
|
|
|
|
* MOSPF/PIM router set up we can clean this up.
|
|
|
|
*/
|
|
|
|
|
2020-07-23 14:08:59 +08:00
|
|
|
int ip6_mroute_setsockopt(struct sock *sk, int optname, sockptr_t optval,
|
|
|
|
unsigned int optlen)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2013-01-21 14:00:26 +08:00
|
|
|
int ret, parent = 0;
|
2008-04-03 08:22:53 +08:00
|
|
|
struct mif6ctl vif;
|
|
|
|
struct mf6cctl mfc;
|
|
|
|
mifi_t mifi;
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = sock_net(sk);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
2017-02-24 16:29:06 +08:00
|
|
|
if (sk->sk_type != SOCK_RAW ||
|
|
|
|
inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return -ENOENT;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
if (optname != MRT6_INIT) {
|
2018-03-01 05:29:32 +08:00
|
|
|
if (sk != rcu_access_pointer(mrt->mroute_sk) &&
|
2018-03-01 05:29:30 +08:00
|
|
|
!ns_capable(net->user_ns, CAP_NET_ADMIN))
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case MRT6_INIT:
|
|
|
|
if (optlen < sizeof(int))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
return ip6mr_sk_init(mrt, sk);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
case MRT6_DONE:
|
|
|
|
return ip6mr_sk_done(sk);
|
|
|
|
|
|
|
|
case MRT6_ADD_MIF:
|
|
|
|
if (optlen < sizeof(vif))
|
|
|
|
return -EINVAL;
|
2020-07-23 14:08:59 +08:00
|
|
|
if (copy_from_sockptr(&vif, optval, sizeof(vif)))
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EFAULT;
|
2008-04-10 17:40:10 +08:00
|
|
|
if (vif.mif6c_mifi >= MAXMIFS)
|
2008-04-03 08:22:53 +08:00
|
|
|
return -ENFILE;
|
|
|
|
rtnl_lock();
|
2018-03-01 05:29:30 +08:00
|
|
|
ret = mif6_add(net, mrt, &vif,
|
2018-03-01 05:29:32 +08:00
|
|
|
sk == rtnl_dereference(mrt->mroute_sk));
|
2008-04-03 08:22:53 +08:00
|
|
|
rtnl_unlock();
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
case MRT6_DEL_MIF:
|
|
|
|
if (optlen < sizeof(mifi_t))
|
|
|
|
return -EINVAL;
|
2020-07-23 14:08:59 +08:00
|
|
|
if (copy_from_sockptr(&mifi, optval, sizeof(mifi_t)))
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EFAULT;
|
|
|
|
rtnl_lock();
|
2017-04-22 01:42:16 +08:00
|
|
|
ret = mif6_delete(mrt, mifi, 0, NULL);
|
2008-04-03 08:22:53 +08:00
|
|
|
rtnl_unlock();
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manipulate the forwarding caches. These live
|
|
|
|
* in a sort of kernel/user symbiosis.
|
|
|
|
*/
|
|
|
|
case MRT6_ADD_MFC:
|
|
|
|
case MRT6_DEL_MFC:
|
2013-01-21 14:00:26 +08:00
|
|
|
parent = -1;
|
2020-03-13 06:50:22 +08:00
|
|
|
fallthrough;
|
2013-01-21 14:00:26 +08:00
|
|
|
case MRT6_ADD_MFC_PROXY:
|
|
|
|
case MRT6_DEL_MFC_PROXY:
|
2008-04-03 08:22:53 +08:00
|
|
|
if (optlen < sizeof(mfc))
|
|
|
|
return -EINVAL;
|
2020-07-23 14:08:59 +08:00
|
|
|
if (copy_from_sockptr(&mfc, optval, sizeof(mfc)))
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EFAULT;
|
2013-01-21 14:00:26 +08:00
|
|
|
if (parent == 0)
|
|
|
|
parent = mfc.mf6cc_parent;
|
2008-04-03 08:22:53 +08:00
|
|
|
rtnl_lock();
|
2013-01-21 14:00:26 +08:00
|
|
|
if (optname == MRT6_DEL_MFC || optname == MRT6_DEL_MFC_PROXY)
|
|
|
|
ret = ip6mr_mfc_delete(mrt, &mfc, parent);
|
2008-04-03 08:22:53 +08:00
|
|
|
else
|
2013-01-21 14:00:26 +08:00
|
|
|
ret = ip6mr_mfc_add(net, mrt, &mfc,
|
2018-03-01 05:29:30 +08:00
|
|
|
sk ==
|
2018-03-01 05:29:32 +08:00
|
|
|
rtnl_dereference(mrt->mroute_sk),
|
2018-03-01 05:29:30 +08:00
|
|
|
parent);
|
2008-04-03 08:22:53 +08:00
|
|
|
rtnl_unlock();
|
|
|
|
return ret;
|
|
|
|
|
2019-02-18 05:07:52 +08:00
|
|
|
case MRT6_FLUSH:
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
if (optlen != sizeof(flags))
|
|
|
|
return -EINVAL;
|
2020-07-23 14:08:59 +08:00
|
|
|
if (copy_from_sockptr(&flags, optval, sizeof(flags)))
|
2019-02-18 05:07:52 +08:00
|
|
|
return -EFAULT;
|
|
|
|
rtnl_lock();
|
|
|
|
mroute_clean_tables(mrt, flags);
|
|
|
|
rtnl_unlock();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
/*
|
|
|
|
* Control PIM assert (to activate pim will activate assert)
|
|
|
|
*/
|
|
|
|
case MRT6_ASSERT:
|
|
|
|
{
|
|
|
|
int v;
|
2012-11-26 02:26:34 +08:00
|
|
|
|
|
|
|
if (optlen != sizeof(v))
|
|
|
|
return -EINVAL;
|
2020-07-23 14:08:59 +08:00
|
|
|
if (copy_from_sockptr(&v, optval, sizeof(v)))
|
2008-04-03 08:22:54 +08:00
|
|
|
return -EFAULT;
|
2012-11-25 17:35:30 +08:00
|
|
|
mrt->mroute_do_assert = v;
|
2008-04-03 08:22:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
case MRT6_PIM:
|
|
|
|
{
|
2022-04-06 18:04:45 +08:00
|
|
|
bool do_wrmifwhole;
|
2008-04-10 14:41:28 +08:00
|
|
|
int v;
|
2012-11-26 02:26:34 +08:00
|
|
|
|
|
|
|
if (optlen != sizeof(v))
|
|
|
|
return -EINVAL;
|
2020-07-23 14:08:59 +08:00
|
|
|
if (copy_from_sockptr(&v, optval, sizeof(v)))
|
2008-04-03 08:22:54 +08:00
|
|
|
return -EFAULT;
|
2022-02-17 15:46:40 +08:00
|
|
|
|
|
|
|
do_wrmifwhole = (v == MRT6MSG_WRMIFWHOLE);
|
2008-04-03 08:22:54 +08:00
|
|
|
v = !!v;
|
|
|
|
rtnl_lock();
|
|
|
|
ret = 0;
|
2010-05-11 20:40:53 +08:00
|
|
|
if (v != mrt->mroute_do_pim) {
|
|
|
|
mrt->mroute_do_pim = v;
|
|
|
|
mrt->mroute_do_assert = v;
|
2022-02-17 15:46:40 +08:00
|
|
|
mrt->mroute_do_wrvifwhole = do_wrmifwhole;
|
2008-04-03 08:22:54 +08:00
|
|
|
}
|
|
|
|
rtnl_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
|
|
|
|
case MRT6_TABLE:
|
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
if (optlen != sizeof(u32))
|
|
|
|
return -EINVAL;
|
2020-07-23 14:08:59 +08:00
|
|
|
if (copy_from_sockptr(&v, optval, sizeof(v)))
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return -EFAULT;
|
2013-01-24 04:38:34 +08:00
|
|
|
/* "pim6reg%u" should not exceed 16 bytes (IFNAMSIZ) */
|
|
|
|
if (v != RT_TABLE_DEFAULT && v >= 100000000)
|
|
|
|
return -EINVAL;
|
2018-03-01 05:29:32 +08:00
|
|
|
if (sk == rcu_access_pointer(mrt->mroute_sk))
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
ret = 0;
|
2018-06-05 21:02:00 +08:00
|
|
|
mrt = ip6mr_new_table(net, v);
|
|
|
|
if (IS_ERR(mrt))
|
|
|
|
ret = PTR_ERR(mrt);
|
2018-06-05 21:01:59 +08:00
|
|
|
else
|
|
|
|
raw6_sk(sk)->ip6mr_table = v;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
rtnl_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
2008-04-03 08:22:54 +08:00
|
|
|
#endif
|
2008-04-03 08:22:53 +08:00
|
|
|
/*
|
2008-04-23 19:35:13 +08:00
|
|
|
* Spurious command, or MRT6_VERSION which you cannot
|
2008-04-03 08:22:53 +08:00
|
|
|
* set.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Getsock opt support for the multicast routing system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval,
|
|
|
|
int __user *optlen)
|
|
|
|
{
|
|
|
|
int olr;
|
|
|
|
int val;
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = sock_net(sk);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
2017-02-24 16:29:06 +08:00
|
|
|
if (sk->sk_type != SOCK_RAW ||
|
|
|
|
inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return -ENOENT;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case MRT6_VERSION:
|
|
|
|
val = 0x0305;
|
|
|
|
break;
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
case MRT6_PIM:
|
2010-05-11 20:40:53 +08:00
|
|
|
val = mrt->mroute_do_pim;
|
2008-04-03 08:22:54 +08:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case MRT6_ASSERT:
|
2010-05-11 20:40:53 +08:00
|
|
|
val = mrt->mroute_do_assert;
|
2008-04-03 08:22:54 +08:00
|
|
|
break;
|
2008-04-03 08:22:53 +08:00
|
|
|
default:
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_user(olr, optlen))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
olr = min_t(int, olr, sizeof(int));
|
|
|
|
if (olr < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (put_user(olr, optlen))
|
|
|
|
return -EFAULT;
|
|
|
|
if (copy_to_user(optval, &val, olr))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The IP multicast ioctl support routines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
|
|
|
|
{
|
|
|
|
struct sioc_sg_req6 sr;
|
|
|
|
struct sioc_mif_req6 vr;
|
2018-03-01 05:29:29 +08:00
|
|
|
struct vif_device *vif;
|
2008-04-03 08:22:53 +08:00
|
|
|
struct mfc6_cache *c;
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = sock_net(sk);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
|
|
|
mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return -ENOENT;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGETMIFCNT_IN6:
|
|
|
|
if (copy_from_user(&vr, arg, sizeof(vr)))
|
|
|
|
return -EFAULT;
|
2010-05-11 20:40:53 +08:00
|
|
|
if (vr.mifi >= mrt->maxvif)
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EINVAL;
|
2018-12-12 04:10:08 +08:00
|
|
|
vr.mifi = array_index_nospec(vr.mifi, mrt->maxvif);
|
2022-06-23 12:34:42 +08:00
|
|
|
rcu_read_lock();
|
2018-03-01 05:29:32 +08:00
|
|
|
vif = &mrt->vif_table[vr.mifi];
|
|
|
|
if (VIF_EXISTS(mrt, vr.mifi)) {
|
2022-06-23 12:34:42 +08:00
|
|
|
vr.icount = READ_ONCE(vif->pkt_in);
|
|
|
|
vr.ocount = READ_ONCE(vif->pkt_out);
|
|
|
|
vr.ibytes = READ_ONCE(vif->bytes_in);
|
|
|
|
vr.obytes = READ_ONCE(vif->bytes_out);
|
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
if (copy_to_user(arg, &vr, sizeof(vr)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
2022-06-23 12:34:42 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
case SIOCGETSGCNT_IN6:
|
|
|
|
if (copy_from_user(&sr, arg, sizeof(sr)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
rcu_read_lock();
|
2010-05-11 20:40:53 +08:00
|
|
|
c = ip6mr_cache_find(mrt, &sr.src.sin6_addr, &sr.grp.sin6_addr);
|
2008-04-03 08:22:53 +08:00
|
|
|
if (c) {
|
2018-03-01 05:29:34 +08:00
|
|
|
sr.pktcnt = c->_c.mfc_un.res.pkt;
|
|
|
|
sr.bytecnt = c->_c.mfc_un.res.bytes;
|
|
|
|
sr.wrong_if = c->_c.mfc_un.res.wrong_if;
|
2018-03-01 05:29:31 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
if (copy_to_user(arg, &sr, sizeof(sr)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-01 05:29:31 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
default:
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 09:59:32 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
struct compat_sioc_sg_req6 {
|
|
|
|
struct sockaddr_in6 src;
|
|
|
|
struct sockaddr_in6 grp;
|
|
|
|
compat_ulong_t pktcnt;
|
|
|
|
compat_ulong_t bytecnt;
|
|
|
|
compat_ulong_t wrong_if;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_sioc_mif_req6 {
|
|
|
|
mifi_t mifi;
|
|
|
|
compat_ulong_t icount;
|
|
|
|
compat_ulong_t ocount;
|
|
|
|
compat_ulong_t ibytes;
|
|
|
|
compat_ulong_t obytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg)
|
|
|
|
{
|
|
|
|
struct compat_sioc_sg_req6 sr;
|
|
|
|
struct compat_sioc_mif_req6 vr;
|
2018-03-01 05:29:29 +08:00
|
|
|
struct vif_device *vif;
|
2011-02-04 09:59:32 +08:00
|
|
|
struct mfc6_cache *c;
|
|
|
|
struct net *net = sock_net(sk);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2011-02-04 09:59:32 +08:00
|
|
|
|
|
|
|
mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
2011-02-04 09:59:32 +08:00
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGETMIFCNT_IN6:
|
|
|
|
if (copy_from_user(&vr, arg, sizeof(vr)))
|
|
|
|
return -EFAULT;
|
|
|
|
if (vr.mifi >= mrt->maxvif)
|
|
|
|
return -EINVAL;
|
2018-12-12 04:10:08 +08:00
|
|
|
vr.mifi = array_index_nospec(vr.mifi, mrt->maxvif);
|
2022-06-23 12:34:42 +08:00
|
|
|
rcu_read_lock();
|
2018-03-01 05:29:32 +08:00
|
|
|
vif = &mrt->vif_table[vr.mifi];
|
|
|
|
if (VIF_EXISTS(mrt, vr.mifi)) {
|
2022-06-23 12:34:42 +08:00
|
|
|
vr.icount = READ_ONCE(vif->pkt_in);
|
|
|
|
vr.ocount = READ_ONCE(vif->pkt_out);
|
|
|
|
vr.ibytes = READ_ONCE(vif->bytes_in);
|
|
|
|
vr.obytes = READ_ONCE(vif->bytes_out);
|
|
|
|
rcu_read_unlock();
|
2011-02-04 09:59:32 +08:00
|
|
|
|
|
|
|
if (copy_to_user(arg, &vr, sizeof(vr)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
2022-06-23 12:34:42 +08:00
|
|
|
rcu_read_unlock();
|
2011-02-04 09:59:32 +08:00
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
case SIOCGETSGCNT_IN6:
|
|
|
|
if (copy_from_user(&sr, arg, sizeof(sr)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2018-03-01 05:29:31 +08:00
|
|
|
rcu_read_lock();
|
2011-02-04 09:59:32 +08:00
|
|
|
c = ip6mr_cache_find(mrt, &sr.src.sin6_addr, &sr.grp.sin6_addr);
|
|
|
|
if (c) {
|
2018-03-01 05:29:34 +08:00
|
|
|
sr.pktcnt = c->_c.mfc_un.res.pkt;
|
|
|
|
sr.bytecnt = c->_c.mfc_un.res.bytes;
|
|
|
|
sr.wrong_if = c->_c.mfc_un.res.wrong_if;
|
2018-03-01 05:29:31 +08:00
|
|
|
rcu_read_unlock();
|
2011-02-04 09:59:32 +08:00
|
|
|
|
|
|
|
if (copy_to_user(arg, &sr, sizeof(sr)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-01 05:29:31 +08:00
|
|
|
rcu_read_unlock();
|
2011-02-04 09:59:32 +08:00
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
default:
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2015-09-16 09:04:18 +08:00
|
|
|
static inline int ip6mr_forward2_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2019-03-03 15:34:57 +08:00
|
|
|
IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
|
|
|
|
IPSTATS_MIB_OUTFORWDATAGRAMS);
|
|
|
|
IP6_ADD_STATS(net, ip6_dst_idev(skb_dst(skb)),
|
|
|
|
IPSTATS_MIB_OUTOCTETS, skb->len);
|
2015-10-08 05:48:35 +08:00
|
|
|
return dst_output(net, sk, skb);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Processing handlers for ip6mr_forward
|
|
|
|
*/
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static int ip6mr_forward2(struct net *net, struct mr_table *mrt,
|
2018-12-18 07:36:11 +08:00
|
|
|
struct sk_buff *skb, int vifi)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
2018-03-01 05:29:32 +08:00
|
|
|
struct vif_device *vif = &mrt->vif_table[vifi];
|
2022-06-23 12:34:32 +08:00
|
|
|
struct net_device *vif_dev;
|
|
|
|
struct ipv6hdr *ipv6h;
|
2008-04-03 08:22:53 +08:00
|
|
|
struct dst_entry *dst;
|
2011-03-13 05:22:43 +08:00
|
|
|
struct flowi6 fl6;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2022-06-23 12:34:32 +08:00
|
|
|
vif_dev = vif_dev_read(vif);
|
|
|
|
if (!vif_dev)
|
2008-04-03 08:22:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
#ifdef CONFIG_IPV6_PIMSM_V2
|
|
|
|
if (vif->flags & MIFF_REGISTER) {
|
2022-06-23 12:34:42 +08:00
|
|
|
WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1);
|
|
|
|
WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len);
|
2022-06-23 12:34:32 +08:00
|
|
|
vif_dev->stats.tx_bytes += skb->len;
|
|
|
|
vif_dev->stats.tx_packets++;
|
2010-05-11 20:40:53 +08:00
|
|
|
ip6mr_cache_report(mrt, skb, vifi, MRT6MSG_WHOLEPKT);
|
2008-12-15 15:15:49 +08:00
|
|
|
goto out_free;
|
2008-04-03 08:22:54 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-03 08:22:53 +08:00
|
|
|
ipv6h = ipv6_hdr(skb);
|
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
fl6 = (struct flowi6) {
|
|
|
|
.flowi6_oif = vif->link,
|
|
|
|
.daddr = ipv6h->daddr,
|
2008-04-03 08:22:53 +08:00
|
|
|
};
|
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
dst = ip6_route_output(net, NULL, &fl6);
|
2012-02-22 06:10:49 +08:00
|
|
|
if (dst->error) {
|
|
|
|
dst_release(dst);
|
2008-04-03 08:22:53 +08:00
|
|
|
goto out_free;
|
2012-02-22 06:10:49 +08:00
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2009-06-02 13:19:30 +08:00
|
|
|
skb_dst_drop(skb);
|
|
|
|
skb_dst_set(skb, dst);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RFC1584 teaches, that DVMRP/PIM router must deliver packets locally
|
|
|
|
* not only before forwarding, but after forwarding on all output
|
|
|
|
* interfaces. It is clear, if mrouter runs a multicasting
|
|
|
|
* program, it should receive packets not depending to what interface
|
|
|
|
* program is joined.
|
|
|
|
* If we will not make it, the program will have to join on all
|
|
|
|
* interfaces. On the other hand, multihoming host (or router, but
|
|
|
|
* not mrouter) cannot join to more than one interface - it will
|
|
|
|
* result in receiving multiple packets.
|
|
|
|
*/
|
2022-06-23 12:34:32 +08:00
|
|
|
skb->dev = vif_dev;
|
2022-06-23 12:34:42 +08:00
|
|
|
WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1);
|
|
|
|
WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
/* We are about to write */
|
|
|
|
/* XXX: extension headers? */
|
2022-06-23 12:34:32 +08:00
|
|
|
if (skb_cow(skb, sizeof(*ipv6h) + LL_RESERVED_SPACE(vif_dev)))
|
2008-04-03 08:22:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
ipv6h = ipv6_hdr(skb);
|
|
|
|
ipv6h->hop_limit--;
|
|
|
|
|
|
|
|
IP6CB(skb)->flags |= IP6SKB_FORWARDED;
|
|
|
|
|
2015-09-16 09:04:16 +08:00
|
|
|
return NF_HOOK(NFPROTO_IPV6, NF_INET_FORWARD,
|
2022-06-23 12:34:32 +08:00
|
|
|
net, NULL, skb, skb->dev, vif_dev,
|
2008-04-03 08:22:53 +08:00
|
|
|
ip6mr_forward2_finish);
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-23 12:34:49 +08:00
|
|
|
/* Called with rcu_read_lock() */
|
2018-03-01 05:29:32 +08:00
|
|
|
static int ip6mr_find_vif(struct mr_table *mrt, struct net_device *dev)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
int ct;
|
2010-05-11 20:40:53 +08:00
|
|
|
|
2022-06-23 12:34:43 +08:00
|
|
|
/* Pairs with WRITE_ONCE() in mif6_delete()/mif6_add() */
|
|
|
|
for (ct = READ_ONCE(mrt->maxvif) - 1; ct >= 0; ct--) {
|
2022-06-23 12:34:32 +08:00
|
|
|
if (rcu_access_pointer(mrt->vif_table[ct].dev) == dev)
|
2008-04-03 08:22:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ct;
|
|
|
|
}
|
|
|
|
|
2022-06-23 12:34:44 +08:00
|
|
|
/* Called under rcu_read_lock() */
|
2018-03-01 05:29:32 +08:00
|
|
|
static void ip6_mr_forward(struct net *net, struct mr_table *mrt,
|
2018-10-01 16:41:27 +08:00
|
|
|
struct net_device *dev, struct sk_buff *skb,
|
|
|
|
struct mfc6_cache *c)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
int psend = -1;
|
|
|
|
int vif, ct;
|
2018-10-01 16:41:27 +08:00
|
|
|
int true_vifi = ip6mr_find_vif(mrt, dev);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
vif = c->_c.mfc_parent;
|
|
|
|
c->_c.mfc_un.res.pkt++;
|
|
|
|
c->_c.mfc_un.res.bytes += skb->len;
|
|
|
|
c->_c.mfc_un.res.lastuse = jiffies;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
if (ipv6_addr_any(&c->mf6c_origin) && true_vifi >= 0) {
|
2013-01-21 14:00:26 +08:00
|
|
|
struct mfc6_cache *cache_proxy;
|
|
|
|
|
2014-10-29 17:00:26 +08:00
|
|
|
/* For an (*,G) entry, we only check that the incoming
|
2013-01-21 14:00:26 +08:00
|
|
|
* interface is part of the static tree.
|
|
|
|
*/
|
2018-03-01 05:29:35 +08:00
|
|
|
cache_proxy = mr_mfc_find_any_parent(mrt, vif);
|
2013-01-21 14:00:26 +08:00
|
|
|
if (cache_proxy &&
|
2018-03-01 05:29:34 +08:00
|
|
|
cache_proxy->_c.mfc_un.res.ttls[true_vifi] < 255) {
|
2018-03-01 05:29:31 +08:00
|
|
|
rcu_read_unlock();
|
2013-01-21 14:00:26 +08:00
|
|
|
goto forward;
|
2018-03-01 05:29:31 +08:00
|
|
|
}
|
2013-01-21 14:00:26 +08:00
|
|
|
}
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
/*
|
|
|
|
* Wrong interface: drop packet and (maybe) send PIM assert.
|
|
|
|
*/
|
2022-06-23 12:34:32 +08:00
|
|
|
if (rcu_access_pointer(mrt->vif_table[vif].dev) != dev) {
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_un.res.wrong_if++;
|
2008-04-03 08:22:54 +08:00
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
if (true_vifi >= 0 && mrt->mroute_do_assert &&
|
2008-04-03 08:22:54 +08:00
|
|
|
/* pimsm uses asserts, when switching from RPT to SPT,
|
|
|
|
so that we cannot check that packet arrived on an oif.
|
|
|
|
It is bad, but otherwise we would need to move pretty
|
|
|
|
large chunk of pimd to kernel. Ough... --ANK
|
|
|
|
*/
|
2010-05-11 20:40:53 +08:00
|
|
|
(mrt->mroute_do_pim ||
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_un.res.ttls[true_vifi] < 255) &&
|
2008-04-03 08:22:54 +08:00
|
|
|
time_after(jiffies,
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_un.res.last_assert +
|
|
|
|
MFC_ASSERT_THRESH)) {
|
|
|
|
c->_c.mfc_un.res.last_assert = jiffies;
|
2010-05-11 20:40:53 +08:00
|
|
|
ip6mr_cache_report(mrt, skb, true_vifi, MRT6MSG_WRONGMIF);
|
2022-02-17 15:46:40 +08:00
|
|
|
if (mrt->mroute_do_wrvifwhole)
|
|
|
|
ip6mr_cache_report(mrt, skb, true_vifi,
|
|
|
|
MRT6MSG_WRMIFWHOLE);
|
2008-04-03 08:22:54 +08:00
|
|
|
}
|
|
|
|
goto dont_forward;
|
|
|
|
}
|
|
|
|
|
2013-01-21 14:00:26 +08:00
|
|
|
forward:
|
2022-06-23 12:34:42 +08:00
|
|
|
WRITE_ONCE(mrt->vif_table[vif].pkt_in,
|
|
|
|
mrt->vif_table[vif].pkt_in + 1);
|
|
|
|
WRITE_ONCE(mrt->vif_table[vif].bytes_in,
|
|
|
|
mrt->vif_table[vif].bytes_in + skb->len);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Forward the frame
|
|
|
|
*/
|
2018-03-01 05:29:34 +08:00
|
|
|
if (ipv6_addr_any(&c->mf6c_origin) &&
|
|
|
|
ipv6_addr_any(&c->mf6c_mcastgrp)) {
|
2013-01-21 14:00:26 +08:00
|
|
|
if (true_vifi >= 0 &&
|
2018-03-01 05:29:34 +08:00
|
|
|
true_vifi != c->_c.mfc_parent &&
|
2013-01-21 14:00:26 +08:00
|
|
|
ipv6_hdr(skb)->hop_limit >
|
2018-03-01 05:29:34 +08:00
|
|
|
c->_c.mfc_un.res.ttls[c->_c.mfc_parent]) {
|
2013-01-21 14:00:26 +08:00
|
|
|
/* It's an (*,*) entry and the packet is not coming from
|
|
|
|
* the upstream: forward the packet to the upstream
|
|
|
|
* only.
|
|
|
|
*/
|
2018-03-01 05:29:34 +08:00
|
|
|
psend = c->_c.mfc_parent;
|
2013-01-21 14:00:26 +08:00
|
|
|
goto last_forward;
|
|
|
|
}
|
|
|
|
goto dont_forward;
|
|
|
|
}
|
2018-03-01 05:29:34 +08:00
|
|
|
for (ct = c->_c.mfc_un.res.maxvif - 1;
|
|
|
|
ct >= c->_c.mfc_un.res.minvif; ct--) {
|
2013-01-21 14:00:26 +08:00
|
|
|
/* For (*,G) entry, don't forward to the incoming interface */
|
2018-03-01 05:29:34 +08:00
|
|
|
if ((!ipv6_addr_any(&c->mf6c_origin) || ct != true_vifi) &&
|
|
|
|
ipv6_hdr(skb)->hop_limit > c->_c.mfc_un.res.ttls[ct]) {
|
2008-04-03 08:22:53 +08:00
|
|
|
if (psend != -1) {
|
|
|
|
struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
|
|
|
|
if (skb2)
|
2018-12-18 07:36:11 +08:00
|
|
|
ip6mr_forward2(net, mrt, skb2, psend);
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
psend = ct;
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 14:00:26 +08:00
|
|
|
last_forward:
|
2008-04-03 08:22:53 +08:00
|
|
|
if (psend != -1) {
|
2018-12-18 07:36:11 +08:00
|
|
|
ip6mr_forward2(net, mrt, skb, psend);
|
2013-07-21 08:00:31 +08:00
|
|
|
return;
|
2008-04-03 08:22:53 +08:00
|
|
|
}
|
|
|
|
|
2008-04-03 08:22:54 +08:00
|
|
|
dont_forward:
|
2008-04-03 08:22:53 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multicast packets for forwarding arrive here
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ip6_mr_input(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct mfc6_cache *cache;
|
2008-12-11 08:30:15 +08:00
|
|
|
struct net *net = dev_net(skb->dev);
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2011-03-13 05:22:43 +08:00
|
|
|
struct flowi6 fl6 = {
|
|
|
|
.flowi6_iif = skb->dev->ifindex,
|
|
|
|
.flowi6_mark = skb->mark,
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
};
|
|
|
|
int err;
|
2018-10-01 16:41:27 +08:00
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
/* skb->dev passed in is the master dev for vrfs.
|
|
|
|
* Get the proper interface that does have a vif associated with it.
|
|
|
|
*/
|
|
|
|
dev = skb->dev;
|
|
|
|
if (netif_is_l3_master(skb->dev)) {
|
|
|
|
dev = dev_get_by_index_rcu(net, IPCB(skb)->iif);
|
|
|
|
if (!dev) {
|
|
|
|
kfree_skb(skb);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
|
2011-03-13 05:22:43 +08:00
|
|
|
err = ip6mr_fib_lookup(net, &fl6, &mrt);
|
2011-09-28 03:16:08 +08:00
|
|
|
if (err < 0) {
|
|
|
|
kfree_skb(skb);
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return err;
|
2011-09-28 03:16:08 +08:00
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2010-05-11 20:40:53 +08:00
|
|
|
cache = ip6mr_cache_find(mrt,
|
2008-12-11 08:30:15 +08:00
|
|
|
&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!cache) {
|
2018-10-01 16:41:27 +08:00
|
|
|
int vif = ip6mr_find_vif(mrt, dev);
|
2013-01-21 14:00:26 +08:00
|
|
|
|
|
|
|
if (vif >= 0)
|
|
|
|
cache = ip6mr_cache_find_any(mrt,
|
|
|
|
&ipv6_hdr(skb)->daddr,
|
|
|
|
vif);
|
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* No usable cache entry
|
|
|
|
*/
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!cache) {
|
2008-04-03 08:22:53 +08:00
|
|
|
int vif;
|
|
|
|
|
2018-10-01 16:41:27 +08:00
|
|
|
vif = ip6mr_find_vif(mrt, dev);
|
2008-04-03 08:22:53 +08:00
|
|
|
if (vif >= 0) {
|
2018-10-01 16:41:27 +08:00
|
|
|
int err = ip6mr_cache_unresolved(mrt, vif, skb, dev);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
kfree_skb(skb);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-10-01 16:41:27 +08:00
|
|
|
ip6_mr_forward(net, mrt, dev, skb, cache);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-26 05:08:31 +08:00
|
|
|
int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm,
|
2017-01-18 07:51:07 +08:00
|
|
|
u32 portid)
|
2008-04-03 08:22:53 +08:00
|
|
|
{
|
|
|
|
int err;
|
2018-03-01 05:29:32 +08:00
|
|
|
struct mr_table *mrt;
|
2008-04-03 08:22:53 +08:00
|
|
|
struct mfc6_cache *cache;
|
2009-06-02 13:19:30 +08:00
|
|
|
struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
|
2008-04-03 08:22:53 +08:00
|
|
|
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
mrt = ip6mr_get_table(net, RT6_TABLE_DFLT);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!mrt)
|
ipv6: ip6mr: 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 MRT6_TABLE. The table number is
stored in the raw socket data and affects all following ip6mr setsockopt(),
getsockopt() and ioctl() calls. By default, a single table (RT6_TABLE_DFLT)
is created with a default routing rule pointing to it. Newly created pim6reg
devices have the table number appended ("pim6regX"), with the exception of
devices created in the default table, which are named just "pim6reg" 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, SOL_IPV6, MRT6_TABLE, &table, sizeof(table));
- create routing rules directing packets to the new table:
# ip -6 mrule add iif eth0 lookup 123
# ip -6 mrule add oif eth0 lookup 123
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-05-11 20:40:55 +08:00
|
|
|
return -ENOENT;
|
|
|
|
|
2022-06-23 12:34:45 +08:00
|
|
|
rcu_read_lock();
|
2010-05-11 20:40:53 +08:00
|
|
|
cache = ip6mr_cache_find(mrt, &rt->rt6i_src.addr, &rt->rt6i_dst.addr);
|
2013-01-21 14:00:26 +08:00
|
|
|
if (!cache && skb->dev) {
|
|
|
|
int vif = ip6mr_find_vif(mrt, skb->dev);
|
|
|
|
|
|
|
|
if (vif >= 0)
|
|
|
|
cache = ip6mr_cache_find_any(mrt, &rt->rt6i_dst.addr,
|
|
|
|
vif);
|
|
|
|
}
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
if (!cache) {
|
|
|
|
struct sk_buff *skb2;
|
|
|
|
struct ipv6hdr *iph;
|
|
|
|
struct net_device *dev;
|
|
|
|
int vif;
|
|
|
|
|
|
|
|
dev = skb->dev;
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!dev || (vif = ip6mr_find_vif(mrt, dev)) < 0) {
|
2022-06-23 12:34:45 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* really correct? */
|
|
|
|
skb2 = alloc_skb(sizeof(struct ipv6hdr), GFP_ATOMIC);
|
|
|
|
if (!skb2) {
|
2022-06-23 12:34:45 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2016-09-26 05:08:31 +08:00
|
|
|
NETLINK_CB(skb2).portid = portid;
|
2008-04-03 08:22:53 +08:00
|
|
|
skb_reset_transport_header(skb2);
|
|
|
|
|
|
|
|
skb_put(skb2, sizeof(struct ipv6hdr));
|
|
|
|
skb_reset_network_header(skb2);
|
|
|
|
|
|
|
|
iph = ipv6_hdr(skb2);
|
|
|
|
iph->version = 0;
|
|
|
|
iph->priority = 0;
|
|
|
|
iph->flow_lbl[0] = 0;
|
|
|
|
iph->flow_lbl[1] = 0;
|
|
|
|
iph->flow_lbl[2] = 0;
|
|
|
|
iph->payload_len = 0;
|
|
|
|
iph->nexthdr = IPPROTO_NONE;
|
|
|
|
iph->hop_limit = 0;
|
2011-11-21 11:39:03 +08:00
|
|
|
iph->saddr = rt->rt6i_src.addr;
|
|
|
|
iph->daddr = rt->rt6i_dst.addr;
|
2008-04-03 08:22:53 +08:00
|
|
|
|
2018-10-01 16:41:27 +08:00
|
|
|
err = ip6mr_cache_unresolved(mrt, vif, skb2, dev);
|
2022-06-23 12:34:45 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:39 +08:00
|
|
|
err = mr_fill_mroute(mrt, skb, &cache->_c, rtm);
|
2022-06-23 12:34:45 +08:00
|
|
|
rcu_read_unlock();
|
2008-04-03 08:22:53 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static int ip6mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
|
2014-03-20 00:47:51 +08:00
|
|
|
u32 portid, u32 seq, struct mfc6_cache *c, int cmd,
|
|
|
|
int flags)
|
2010-05-11 20:40:56 +08:00
|
|
|
{
|
|
|
|
struct nlmsghdr *nlh;
|
|
|
|
struct rtmsg *rtm;
|
2012-12-04 09:13:39 +08:00
|
|
|
int err;
|
2010-05-11 20:40:56 +08:00
|
|
|
|
2014-03-20 00:47:51 +08:00
|
|
|
nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!nlh)
|
2010-05-11 20:40:56 +08:00
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
rtm = nlmsg_data(nlh);
|
2012-12-04 09:01:49 +08:00
|
|
|
rtm->rtm_family = RTNL_FAMILY_IP6MR;
|
2010-05-11 20:40:56 +08:00
|
|
|
rtm->rtm_dst_len = 128;
|
|
|
|
rtm->rtm_src_len = 128;
|
|
|
|
rtm->rtm_tos = 0;
|
|
|
|
rtm->rtm_table = mrt->id;
|
2012-04-02 08:27:33 +08:00
|
|
|
if (nla_put_u32(skb, RTA_TABLE, mrt->id))
|
|
|
|
goto nla_put_failure;
|
2012-12-04 09:13:39 +08:00
|
|
|
rtm->rtm_type = RTN_MULTICAST;
|
2010-05-11 20:40:56 +08:00
|
|
|
rtm->rtm_scope = RT_SCOPE_UNIVERSE;
|
2018-03-01 05:29:34 +08:00
|
|
|
if (c->_c.mfc_flags & MFC_STATIC)
|
2012-12-04 09:13:38 +08:00
|
|
|
rtm->rtm_protocol = RTPROT_STATIC;
|
|
|
|
else
|
|
|
|
rtm->rtm_protocol = RTPROT_MROUTED;
|
2010-05-11 20:40:56 +08:00
|
|
|
rtm->rtm_flags = 0;
|
|
|
|
|
2015-03-29 22:59:25 +08:00
|
|
|
if (nla_put_in6_addr(skb, RTA_SRC, &c->mf6c_origin) ||
|
|
|
|
nla_put_in6_addr(skb, RTA_DST, &c->mf6c_mcastgrp))
|
2012-04-02 08:27:33 +08:00
|
|
|
goto nla_put_failure;
|
2018-03-01 05:29:39 +08:00
|
|
|
err = mr_fill_mroute(mrt, skb, &c->_c, rtm);
|
2012-12-04 09:13:39 +08:00
|
|
|
/* do not break the dump if cache is unresolved */
|
|
|
|
if (err < 0 && err != -ENOENT)
|
2010-05-11 20:40:56 +08:00
|
|
|
goto nla_put_failure;
|
|
|
|
|
2015-01-17 05:09:00 +08:00
|
|
|
nlmsg_end(skb, nlh);
|
|
|
|
return 0;
|
2010-05-11 20:40:56 +08:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_cancel(skb, nlh);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:39 +08:00
|
|
|
static int _ip6mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
|
|
|
|
u32 portid, u32 seq, struct mr_mfc *c,
|
|
|
|
int cmd, int flags)
|
|
|
|
{
|
|
|
|
return ip6mr_fill_mroute(mrt, skb, portid, seq, (struct mfc6_cache *)c,
|
|
|
|
cmd, flags);
|
|
|
|
}
|
|
|
|
|
2012-12-04 09:13:41 +08:00
|
|
|
static int mr6_msgsize(bool unresolved, int maxvif)
|
|
|
|
{
|
|
|
|
size_t len =
|
|
|
|
NLMSG_ALIGN(sizeof(struct rtmsg))
|
|
|
|
+ nla_total_size(4) /* RTA_TABLE */
|
|
|
|
+ nla_total_size(sizeof(struct in6_addr)) /* RTA_SRC */
|
|
|
|
+ nla_total_size(sizeof(struct in6_addr)) /* RTA_DST */
|
|
|
|
;
|
|
|
|
|
|
|
|
if (!unresolved)
|
|
|
|
len = len
|
|
|
|
+ nla_total_size(4) /* RTA_IIF */
|
|
|
|
+ nla_total_size(0) /* RTA_MULTIPATH */
|
|
|
|
+ maxvif * NLA_ALIGN(sizeof(struct rtnexthop))
|
|
|
|
/* RTA_MFC_STATS */
|
2016-04-22 00:58:27 +08:00
|
|
|
+ nla_total_size_64bit(sizeof(struct rta_mfc_stats))
|
2012-12-04 09:13:41 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:32 +08:00
|
|
|
static void mr6_netlink_event(struct mr_table *mrt, struct mfc6_cache *mfc,
|
2012-12-04 09:13:41 +08:00
|
|
|
int cmd)
|
|
|
|
{
|
|
|
|
struct net *net = read_pnet(&mrt->net);
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int err = -ENOBUFS;
|
|
|
|
|
2018-03-01 05:29:34 +08:00
|
|
|
skb = nlmsg_new(mr6_msgsize(mfc->_c.mfc_parent >= MAXMIFS, mrt->maxvif),
|
2012-12-04 09:13:41 +08:00
|
|
|
GFP_ATOMIC);
|
2015-03-29 21:00:04 +08:00
|
|
|
if (!skb)
|
2012-12-04 09:13:41 +08:00
|
|
|
goto errout;
|
|
|
|
|
2014-03-20 00:47:51 +08:00
|
|
|
err = ip6mr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0);
|
2012-12-04 09:13:41 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
rtnl_notify(skb, net, 0, RTNLGRP_IPV6_MROUTE, NULL, GFP_ATOMIC);
|
|
|
|
return;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
kfree_skb(skb);
|
|
|
|
if (err < 0)
|
|
|
|
rtnl_set_sk_err(net, RTNLGRP_IPV6_MROUTE, err);
|
|
|
|
}
|
|
|
|
|
2017-06-21 04:54:18 +08:00
|
|
|
static size_t mrt6msg_netlink_msgsize(size_t payloadlen)
|
|
|
|
{
|
|
|
|
size_t len =
|
|
|
|
NLMSG_ALIGN(sizeof(struct rtgenmsg))
|
|
|
|
+ nla_total_size(1) /* IP6MRA_CREPORT_MSGTYPE */
|
|
|
|
+ nla_total_size(4) /* IP6MRA_CREPORT_MIF_ID */
|
|
|
|
/* IP6MRA_CREPORT_SRC_ADDR */
|
|
|
|
+ nla_total_size(sizeof(struct in6_addr))
|
|
|
|
/* IP6MRA_CREPORT_DST_ADDR */
|
|
|
|
+ nla_total_size(sizeof(struct in6_addr))
|
|
|
|
/* IP6MRA_CREPORT_PKT */
|
|
|
|
+ nla_total_size(payloadlen)
|
|
|
|
;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2022-06-23 12:34:40 +08:00
|
|
|
static void mrt6msg_netlink_event(const struct mr_table *mrt, struct sk_buff *pkt)
|
2017-06-21 04:54:18 +08:00
|
|
|
{
|
|
|
|
struct net *net = read_pnet(&mrt->net);
|
|
|
|
struct nlmsghdr *nlh;
|
|
|
|
struct rtgenmsg *rtgenm;
|
|
|
|
struct mrt6msg *msg;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct nlattr *nla;
|
|
|
|
int payloadlen;
|
|
|
|
|
|
|
|
payloadlen = pkt->len - sizeof(struct mrt6msg);
|
|
|
|
msg = (struct mrt6msg *)skb_transport_header(pkt);
|
|
|
|
|
|
|
|
skb = nlmsg_new(mrt6msg_netlink_msgsize(payloadlen), GFP_ATOMIC);
|
|
|
|
if (!skb)
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
nlh = nlmsg_put(skb, 0, 0, RTM_NEWCACHEREPORT,
|
|
|
|
sizeof(struct rtgenmsg), 0);
|
|
|
|
if (!nlh)
|
|
|
|
goto errout;
|
|
|
|
rtgenm = nlmsg_data(nlh);
|
|
|
|
rtgenm->rtgen_family = RTNL_FAMILY_IP6MR;
|
|
|
|
if (nla_put_u8(skb, IP6MRA_CREPORT_MSGTYPE, msg->im6_msgtype) ||
|
|
|
|
nla_put_u32(skb, IP6MRA_CREPORT_MIF_ID, msg->im6_mif) ||
|
|
|
|
nla_put_in6_addr(skb, IP6MRA_CREPORT_SRC_ADDR,
|
|
|
|
&msg->im6_src) ||
|
|
|
|
nla_put_in6_addr(skb, IP6MRA_CREPORT_DST_ADDR,
|
|
|
|
&msg->im6_dst))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
nla = nla_reserve(skb, IP6MRA_CREPORT_PKT, payloadlen);
|
|
|
|
if (!nla || skb_copy_bits(pkt, sizeof(struct mrt6msg),
|
|
|
|
nla_data(nla), payloadlen))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
nlmsg_end(skb, nlh);
|
|
|
|
|
|
|
|
rtnl_notify(skb, net, 0, RTNLGRP_IPV6_MROUTE_R, NULL, GFP_ATOMIC);
|
|
|
|
return;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_cancel(skb, nlh);
|
|
|
|
errout:
|
|
|
|
kfree_skb(skb);
|
|
|
|
rtnl_set_sk_err(net, RTNLGRP_IPV6_MROUTE_R, -ENOBUFS);
|
|
|
|
}
|
|
|
|
|
2010-05-11 20:40:56 +08:00
|
|
|
static int ip6mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
2018-10-08 11:16:35 +08:00
|
|
|
const struct nlmsghdr *nlh = cb->nlh;
|
2018-10-16 09:56:42 +08:00
|
|
|
struct fib_dump_filter filter = {};
|
2018-10-16 09:56:47 +08:00
|
|
|
int err;
|
2018-10-08 11:16:35 +08:00
|
|
|
|
|
|
|
if (cb->strict_check) {
|
2018-10-16 09:56:42 +08:00
|
|
|
err = ip_valid_fib_dump_req(sock_net(skb->sk), nlh,
|
2018-10-16 09:56:48 +08:00
|
|
|
&filter, cb);
|
2018-10-08 11:16:35 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-10-16 09:56:47 +08:00
|
|
|
if (filter.table_id) {
|
|
|
|
struct mr_table *mrt;
|
|
|
|
|
|
|
|
mrt = ip6mr_get_table(sock_net(skb->sk), filter.table_id);
|
|
|
|
if (!mrt) {
|
net: don't return invalid table id error when we fall back to PF_UNSPEC
In case we can't find a ->dumpit callback for the requested
(family,type) pair, we fall back to (PF_UNSPEC,type). In effect, we're
in the same situation as if userspace had requested a PF_UNSPEC
dump. For RTM_GETROUTE, that handler is rtnl_dump_all, which calls all
the registered RTM_GETROUTE handlers.
The requested table id may or may not exist for all of those
families. commit ae677bbb4441 ("net: Don't return invalid table id
error when dumping all families") fixed the problem when userspace
explicitly requests a PF_UNSPEC dump, but missed the fallback case.
For example, when we pass ipv6.disable=1 to a kernel with
CONFIG_IP_MROUTE=y and CONFIG_IP_MROUTE_MULTIPLE_TABLES=y,
the (PF_INET6, RTM_GETROUTE) handler isn't registered, so we end up in
rtnl_dump_all, and listing IPv6 routes will unexpectedly print:
# ip -6 r
Error: ipv4: MR table does not exist.
Dump terminated
commit ae677bbb4441 introduced the dump_all_families variable, which
gets set when userspace requests a PF_UNSPEC dump. However, we can't
simply set the family to PF_UNSPEC in rtnetlink_rcv_msg in the
fallback case to get dump_all_families == true, because some messages
types (for example RTM_GETRULE and RTM_GETNEIGH) only register the
PF_UNSPEC handler and use the family to filter in the kernel what is
dumped to userspace. We would then export more entries, that userspace
would have to filter. iproute does that, but other programs may not.
Instead, this patch removes dump_all_families and updates the
RTM_GETROUTE handlers to check if the family that is being dumped is
their own. When it's not, which covers both the intentional PF_UNSPEC
dumps (as dump_all_families did) and the fallback case, ignore the
missing table id error.
Fixes: cb167893f41e ("net: Plumb support for filtering ipv4 and ipv6 multicast route dumps")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-05-20 17:15:46 +08:00
|
|
|
if (rtnl_msg_family(cb->nlh) != RTNL_FAMILY_IP6MR)
|
2018-10-25 03:59:01 +08:00
|
|
|
return skb->len;
|
|
|
|
|
2018-10-16 09:56:47 +08:00
|
|
|
NL_SET_ERR_MSG_MOD(cb->extack, "MR table does not exist");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
err = mr_table_dump(mrt, skb, cb, _ip6mr_fill_mroute,
|
|
|
|
&mfc_unres_lock, &filter);
|
|
|
|
return skb->len ? : err;
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:29:39 +08:00
|
|
|
return mr_rtm_dumproute(skb, cb, ip6mr_mr_table_iter,
|
2018-10-16 09:56:47 +08:00
|
|
|
_ip6mr_fill_mroute, &mfc_unres_lock, &filter);
|
2010-05-11 20:40:56 +08:00
|
|
|
}
|