2008-04-03 04:22:53 +04: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 @ 6 WIND . com >
* 6 WIND , Paris , France
* Copyright ( C ) 2007 , 2008 USAGI / WIDE Project
* YOSHIFUJI Hideaki < yoshfuji @ linux - ipv6 . org >
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version
* 2 of the License , or ( at your option ) any later version .
*
*/
2016-12-24 22:46:01 +03:00
# include <linux/uaccess.h>
2008-04-03 04:22:53 +04: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 04:59:32 +03:00
# include <linux/compat.h>
2018-06-18 05:52:50 +03:00
# include <linux/rhashtable.h>
2008-04-03 04:22:53 +04: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 16:40:55 +04:00
# include <net/fib_rules.h>
2008-04-03 04:22:53 +04:00
# include <net/ipv6.h>
# include <net/ip6_route.h>
# include <linux/mroute6.h>
2008-04-03 04:22:54 +04:00
# include <linux/pim.h>
2008-04-03 04:22:53 +04:00
# include <net/addrconf.h>
# include <linux/netfilter_ipv6.h>
2011-07-15 19:47:34 +04:00
# include <linux/export.h>
2009-01-31 11:51:49 +03:00
# include <net/ip6_checksum.h>
2012-12-04 05:13:35 +04:00
# include <linux/netconf.h>
2008-04-03 04:22:53 +04:00
2018-12-11 23:10:08 +03: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 16:40:55 +04:00
struct ip6mr_rule {
struct fib_rule common ;
} ;
struct ip6mr_result {
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
} ;
2008-04-03 04:22:53 +04:00
/* Big lock, protecting vif table, mrt cache and mroute socket state.
Note that the changes are semaphored via rtnl_lock .
*/
static DEFINE_RWLOCK ( mrt_lock ) ;
2018-03-01 00:29:32 +03:00
/* Multicast router control variables */
2008-04-03 04:22:53 +04: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 00:29:32 +03: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 16:40:55 +04:00
2018-03-01 00:29:32 +03:00
static void ip6_mr_forward ( struct net * net , struct mr_table * mrt ,
2018-10-01 11:41:27 +03:00
struct net_device * dev , struct sk_buff * skb ,
struct mfc6_cache * cache ) ;
2018-03-01 00:29:32 +03:00
static int ip6mr_cache_report ( struct mr_table * mrt , struct sk_buff * pkt ,
2008-12-11 03:30:15 +03:00
mifi_t mifi , int assert ) ;
2018-03-01 00:29:32 +03:00
static void mr6_netlink_event ( struct mr_table * mrt , struct mfc6_cache * mfc ,
2012-12-04 05:13:41 +04:00
int cmd ) ;
2018-03-01 00:29:32 +03:00
static void mrt6msg_netlink_event ( struct mr_table * mrt , struct sk_buff * pkt ) ;
2010-05-11 16:40:56 +04:00
static int ip6mr_rtm_dumproute ( struct sk_buff * skb ,
struct netlink_callback * cb ) ;
2018-03-01 00:29:32 +03:00
static void mroute_clean_tables ( struct mr_table * mrt , bool all ) ;
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 00:43:17 +03: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 16:40:55 +04:00
# ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
2010-06-07 02:34:40 +04:00
# define ip6mr_for_each_table(mrt, 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 16:40:55 +04:00
list_for_each_entry_rcu ( mrt , & net - > ipv6 . mr6_tables , list )
2018-03-01 00:29:39 +03: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 00:29:32 +03: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 16:40:55 +04:00
{
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
ip6mr_for_each_table ( mrt , net ) {
if ( mrt - > id = = id )
return mrt ;
}
return NULL ;
}
2011-03-13 00:22:43 +03:00
static int ip6mr_fib_lookup ( struct net * net , struct flowi6 * flp6 ,
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
{
int err ;
2014-01-13 05:45:22 +04: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 16:40:55 +04:00
2018-10-01 11:41:27 +03:00
/* update flow if oif or iif point to device enslaved to l3mdev */
l3mdev_update_flow ( net , flowi6_to_flowi ( flp6 ) ) ;
2011-03-13 00:22:43 +03: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 16:40:55 +04: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 00:29:32 +03: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 16:40:55 +04: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 11:41:27 +03:00
arg - > table = fib_rule_get_table ( rule , arg ) ;
mrt = ip6mr_get_table ( rule - > fr_net , arg - > table ) ;
2015-03-29 16:00:04 +03: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 16:40:55 +04: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 const struct nla_policy ip6mr_rule_policy [ FRA_MAX + 1 ] = {
FRA_GENERIC_POLICY ,
} ;
static int ip6mr_rule_configure ( struct fib_rule * rule , struct sk_buff * skb ,
2018-04-21 19:41:31 +03: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 16:40:55 +04: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 04:12:11 +04: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 16:40:55 +04: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 ,
. policy = ip6mr_rule_policy ,
. owner = THIS_MODULE ,
} ;
static int __net_init ip6mr_rules_init ( struct net * net )
{
struct fib_rules_ops * ops ;
2018-03-01 00:29:32 +03: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 16:40:55 +04: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 16:02:00 +03: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 16:40:55 +04: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 :
2015-03-26 00:45:03 +03:00
ip6mr_free_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 16:40:55 +04:00
err1 :
fib_rules_unregister ( ops ) ;
return err ;
}
static void __net_exit ip6mr_rules_exit ( struct net * net )
{
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
2013-07-23 01:45:53 +04:00
rtnl_lock ( ) ;
2010-06-07 03:48:40 +04: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 16:40:55 +04:00
ip6mr_free_table ( mrt ) ;
2010-06-07 03:48:40 +04: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 16:40:55 +04:00
fib_rules_unregister ( net - > ipv6 . mr6_rules_ops ) ;
2015-03-31 21:01:46 +03: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 16:40:55 +04:00
}
2018-03-26 15:01:34 +03:00
static int ip6mr_rules_dump ( struct net * net , struct notifier_block * nb )
{
return fib_rules_dump ( net , nb , RTNL_FAMILY_IP6MR ) ;
}
static unsigned int ip6mr_rules_seq_read ( struct net * net )
{
return fib_rules_seq_read ( net , RTNL_FAMILY_IP6MR ) ;
}
2018-03-26 15:01:35 +03: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 16:40:55 +04:00
# else
# define ip6mr_for_each_table(mrt, net) \
for ( mrt = net - > ipv6 . mrt6 ; mrt ; mrt = NULL )
2018-03-01 00:29:39 +03: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 00:29:32 +03: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 16:40:55 +04:00
{
return net - > ipv6 . mrt6 ;
}
2011-03-13 00:22:43 +03:00
static int ip6mr_fib_lookup ( struct net * net , struct flowi6 * flp6 ,
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
{
* mrt = net - > ipv6 . mrt6 ;
return 0 ;
}
static int __net_init ip6mr_rules_init ( struct net * net )
{
2018-06-05 16:02:00 +03: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 16:40:55 +04:00
}
static void __net_exit ip6mr_rules_exit ( struct net * net )
{
2013-07-23 01:45:53 +04: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 16:40:55 +04:00
ip6mr_free_table ( net - > ipv6 . mrt6 ) ;
2013-07-23 01:45:53 +04:00
net - > ipv6 . mrt6 = NULL ;
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 16:40:55 +04:00
}
2018-03-26 15:01:34 +03:00
static int ip6mr_rules_dump ( struct net * net , struct notifier_block * nb )
{
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 16:40:55 +04:00
# endif
2018-03-01 00:29:31 +03: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 00:29:34 +03:00
. head_offset = offsetof ( struct mr_mfc , mnode ) ,
2018-03-01 00:29:31 +03:00
. key_offset = offsetof ( struct mfc6_cache , cmparg ) ,
. key_len = sizeof ( struct mfc6_cache_cmp_arg ) ,
. nelem_hint = 3 ,
. locks_mul = 1 ,
. obj_cmpfn = ip6mr_hash_cmp ,
. automatic_shrinking = true ,
} ;
2018-03-01 00:29:33 +03: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 00:29:35 +03: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 00:29:32 +03: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 16:40:55 +04:00
{
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
mrt = ip6mr_get_table ( net , id ) ;
2015-03-29 16:00:05 +03: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 16:40:55 +04:00
return mrt ;
2018-03-01 00:29:35 +03:00
return mr_table_alloc ( net , id , & ip6mr_mr_table_ops ,
2018-03-01 00:29:33 +03: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 16:40:55 +04:00
}
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
{
2015-03-31 21:01:47 +03:00
del_timer_sync ( & mrt - > ipmr_expire_timer ) ;
2015-11-20 15:54:20 +03:00
mroute_clean_tables ( mrt , true ) ;
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
kfree ( mrt ) ;
}
2008-04-03 04:22:53 +04:00
# ifdef CONFIG_PROC_FS
2018-03-01 00:29:36 +03:00
/* The /proc interfaces to multicast routing
* / proc / ip6_mr_cache / proc / ip6_mr_vif
2008-04-03 04:22:53 +04:00
*/
static void * ip6mr_vif_seq_start ( struct seq_file * seq , loff_t * pos )
__acquires ( mrt_lock )
{
2018-03-01 00:29:37 +03:00
struct mr_vif_iter * iter = seq - > private ;
2008-12-11 03:29:48 +03:00
struct net * net = seq_file_net ( seq ) ;
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
mrt = ip6mr_get_table ( net , RT6_TABLE_DFLT ) ;
2015-03-29 16:00:04 +03: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 16:40:55 +04:00
return ERR_PTR ( - ENOENT ) ;
iter - > mrt = mrt ;
2008-12-11 03:29:48 +03:00
2008-04-03 04:22:53 +04:00
read_lock ( & mrt_lock ) ;
2018-03-01 00:29:37 +03:00
return mr_vif_seq_start ( seq , pos ) ;
2008-04-03 04:22:53 +04:00
}
static void ip6mr_vif_seq_stop ( struct seq_file * seq , void * v )
__releases ( mrt_lock )
{
read_unlock ( & mrt_lock ) ;
}
static int ip6mr_vif_seq_show ( struct seq_file * seq , void * v )
{
2018-03-01 00:29:37 +03:00
struct mr_vif_iter * iter = seq - > private ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt = iter - > mrt ;
2008-12-11 03:29:48 +03:00
2008-04-03 04:22:53 +04:00
if ( v = = SEQ_START_TOKEN ) {
seq_puts ( seq ,
" Interface BytesIn PktsIn BytesOut PktsOut Flags \n " ) ;
} else {
2018-03-01 00:29:29 +03:00
const struct vif_device * vif = v ;
2008-04-03 04:22:53 +04:00
const char * name = vif - > dev ? vif - > dev - > name : " none " ;
seq_printf ( seq ,
2008-06-02 13:59:02 +04:00
" %2td %-10s %8ld %7ld %8ld %7ld %05X \n " ,
2018-03-01 00:29:32 +03:00
vif - mrt - > vif_table ,
2008-04-03 04:22:53 +04:00
name , vif - > bytes_in , vif - > pkt_in ,
vif - > bytes_out , vif - > pkt_out ,
vif - > flags ) ;
}
return 0 ;
}
2009-09-01 23:25:02 +04:00
static const struct seq_operations ip6mr_vif_seq_ops = {
2008-04-03 04:22:53 +04:00
. start = ip6mr_vif_seq_start ,
2018-03-01 00:29:37 +03:00
. next = mr_vif_seq_next ,
2008-04-03 04:22:53 +04: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 03:29:48 +03:00
struct net * net = seq_file_net ( seq ) ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2008-12-11 03:29:48 +03: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 16:40:55 +04:00
mrt = ip6mr_get_table ( net , RT6_TABLE_DFLT ) ;
2015-03-29 16:00:04 +03: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 16:40:55 +04:00
return ERR_PTR ( - ENOENT ) ;
2018-03-01 00:29:36 +03:00
return mr_mfc_seq_start ( seq , pos , mrt , & mfc_unres_lock ) ;
2008-04-03 04:22:53 +04: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 00:29:36 +03:00
const struct mr_mfc_iter * it = seq - > private ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt = it - > mrt ;
2008-04-03 04:22:53 +04:00
2008-12-04 09:22:16 +03:00
seq_printf ( seq , " %pI6 %pI6 %-3hd " ,
2008-10-29 02:09:23 +03:00
& mfc - > mf6c_mcastgrp , & mfc - > mf6c_origin ,
2018-03-01 00:29:34 +03:00
mfc - > _c . mfc_parent ) ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:32 +03:00
if ( it - > cache ! = & mrt - > mfc_unres_queue ) {
2008-12-04 09:21:47 +03:00
seq_printf ( seq , " %8lu %8lu %8lu " ,
2018-03-01 00:29:34 +03: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 00:29:32 +03:00
if ( VIF_EXISTS ( mrt , n ) & &
2018-03-01 00:29:34 +03:00
mfc - > _c . mfc_un . res . ttls [ n ] < 255 )
2008-04-03 04:22:53 +04:00
seq_printf ( seq ,
2018-03-01 00:29:34 +03:00
" %2d:%-3d " , n ,
mfc - > _c . mfc_un . res . ttls [ n ] ) ;
2008-04-03 04:22:53 +04:00
}
2008-12-04 09:21:47 +03: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 04:22:53 +04:00
}
seq_putc ( seq , ' \n ' ) ;
}
return 0 ;
}
2009-09-23 03:43:43 +04:00
static const struct seq_operations ipmr_mfc_seq_ops = {
2008-04-03 04:22:53 +04:00
. start = ipmr_mfc_seq_start ,
2018-03-01 00:29:36 +03:00
. next = mr_mfc_seq_next ,
. stop = mr_mfc_seq_stop ,
2008-04-03 04:22:53 +04:00
. show = ipmr_mfc_seq_show ,
} ;
# endif
2008-04-03 04:22:54 +04: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 03:30:15 +03:00
struct net * net = dev_net ( skb - > dev ) ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2011-03-13 00:22:43 +03: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 16:40:55 +04:00
} ;
int reg_vif_num ;
2008-04-03 04:22:54 +04:00
if ( ! pskb_may_pull ( skb , sizeof ( * pim ) + sizeof ( * encap ) ) )
goto drop ;
pim = ( struct pimreghdr * ) skb_transport_header ( skb ) ;
2016-10-31 15:21:04 +03:00
if ( pim - > type ! = ( ( PIM_VERSION < < 4 ) | PIM_TYPE_REGISTER ) | |
2008-04-03 04:22:54 +04:00
( pim - > flags & PIM_NULL_REGISTER ) | |
2009-01-28 09:39:59 +03: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 09:28:58 +04:00
csum_fold ( skb_checksum ( skb , 0 , skb - > len , 0 ) ) ) )
2008-04-03 04:22:54 +04: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 00:22:43 +03: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 16:40:55 +04:00
goto drop ;
reg_vif_num = mrt - > mroute_reg_vif_num ;
2008-04-03 04:22:54 +04:00
read_lock ( & mrt_lock ) ;
if ( reg_vif_num > = 0 )
2018-03-01 00:29:32 +03:00
reg_dev = mrt - > vif_table [ reg_vif_num ] . dev ;
2008-04-03 04:22:54 +04:00
if ( reg_dev )
dev_hold ( reg_dev ) ;
read_unlock ( & mrt_lock ) ;
2015-03-29 16:00:04 +03:00
if ( ! reg_dev )
2008-04-03 04:22:54 +04:00
goto drop ;
skb - > mac_header = skb - > network_header ;
skb_pull ( skb , ( u8 * ) encap - skb - > data ) ;
skb_reset_network_header ( skb ) ;
2009-01-28 09:39:59 +03:00
skb - > protocol = htons ( ETH_P_IPV6 ) ;
2011-03-26 08:10:30 +03:00
skb - > ip_summed = CHECKSUM_NONE ;
2010-05-18 09:36:55 +04:00
2013-09-02 17:34:58 +04:00
skb_tunnel_rx ( skb , reg_dev , dev_net ( reg_dev ) ) ;
2010-05-18 09:36:55 +04:00
2010-10-01 01:06:55 +04:00
netif_rx ( skb ) ;
2010-09-20 04:12:11 +04:00
2008-04-03 04:22:54 +04:00
dev_put ( reg_dev ) ;
return 0 ;
drop :
kfree_skb ( skb ) ;
return 0 ;
}
2009-09-14 16:22:28 +04:00
static const struct inet6_protocol pim6_protocol = {
2008-04-03 04:22:54 +04:00
. handler = pim6_rcv ,
} ;
/* Service routines creating virtual interfaces: PIMREG */
2009-08-31 23:50:41 +04:00
static netdev_tx_t reg_vif_xmit ( struct sk_buff * skb ,
struct net_device * dev )
2008-04-03 04:22:54 +04:00
{
2008-12-11 03:30:15 +03:00
struct net * net = dev_net ( dev ) ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2011-03-13 00:22:43 +03: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 03:25:34 +04:00
. flowi6_iif = skb - > skb_iif ? : LOOPBACK_IFINDEX ,
2011-03-13 00:22:43 +03: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 16:40:55 +04:00
} ;
int err ;
2011-03-13 00:22:43 +03:00
err = ip6mr_fib_lookup ( net , & fl6 , & mrt ) ;
2011-09-23 17:11:01 +04: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 16:40:55 +04:00
return err ;
2011-09-23 17:11:01 +04:00
}
2008-12-11 03:30:15 +03:00
2008-04-03 04:22:54 +04:00
read_lock ( & mrt_lock ) ;
2008-05-22 01:17:54 +04:00
dev - > stats . tx_bytes + = skb - > len ;
dev - > stats . tx_packets + + ;
2010-05-11 16:40:53 +04:00
ip6mr_cache_report ( mrt , skb , mrt - > mroute_reg_vif_num , MRT6MSG_WHOLEPKT ) ;
2008-04-03 04:22:54 +04:00
read_unlock ( & mrt_lock ) ;
kfree_skb ( skb ) ;
2009-06-23 10:03:08 +04:00
return NETDEV_TX_OK ;
2008-04-03 04:22:54 +04:00
}
2015-04-02 18:07:03 +03:00
static int reg_vif_get_iflink ( const struct net_device * dev )
{
return 0 ;
}
2008-11-21 07:28:35 +03:00
static const struct net_device_ops reg_vif_netdev_ops = {
. ndo_start_xmit = reg_vif_xmit ,
2015-04-02 18:07:03 +03:00
. ndo_get_iflink = reg_vif_get_iflink ,
2008-11-21 07:28:35 +03:00
} ;
2008-04-03 04:22:54 +04: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 07:28:35 +03:00
dev - > netdev_ops = & reg_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-08 19:52:56 +03:00
dev - > needs_free_netdev = true ;
2009-06-14 14:16:13 +04:00
dev - > features | = NETIF_F_NETNS_LOCAL ;
2008-04-03 04:22:54 +04:00
}
2018-03-01 00:29:32 +03:00
static struct net_device * ip6mr_reg_vif ( struct net * net , struct mr_table * mrt )
2008-04-03 04:22:54 +04: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 16:40:55 +04:00
char name [ IFNAMSIZ ] ;
if ( mrt - > id = = RT6_TABLE_DFLT )
sprintf ( name , " pim6reg " ) ;
else
sprintf ( name , " pim6reg%u " , mrt - > id ) ;
2008-04-03 04:22:54 +04: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 18:37:24 +04:00
dev = alloc_netdev ( 0 , name , NET_NAME_UNKNOWN , reg_vif_setup ) ;
2015-03-29 16:00:04 +03:00
if ( ! dev )
2008-04-03 04:22:54 +04:00
return NULL ;
2008-12-11 03:30:15 +03:00
dev_net_set ( dev , net ) ;
2008-04-03 04:22:54 +04:00
if ( register_netdevice ( dev ) ) {
free_netdev ( dev ) ;
return NULL ;
}
if ( dev_open ( dev ) )
goto failure ;
2008-07-15 07:54:54 +04:00
dev_hold ( dev ) ;
2008-04-03 04:22:54 +04:00
return dev ;
failure :
unregister_netdevice ( dev ) ;
return NULL ;
}
# endif
2018-03-26 15:01:34 +03:00
static int call_ip6mr_vif_entry_notifiers ( struct net * net ,
enum fib_event_type event_type ,
struct vif_device * vif ,
mifi_t vif_index , u32 tb_id )
{
return mr_call_vif_notifiers ( net , RTNL_FAMILY_IP6MR , event_type ,
vif , vif_index , tb_id ,
& net - > ipv6 . ipmr_seq ) ;
}
2008-04-03 04:22:53 +04:00
2018-03-26 15:01:34 +03: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 00:29:32 +03:00
static int mif6_delete ( struct mr_table * mrt , int vifi , int notify ,
2017-04-21 20:42:16 +03:00
struct list_head * head )
2008-04-03 04:22:53 +04:00
{
2018-03-01 00:29:29 +03:00
struct vif_device * v ;
2008-04-03 04:22:53 +04:00
struct net_device * dev ;
2009-01-28 09:39:59 +03:00
struct inet6_dev * in6_dev ;
2010-05-11 16:40:53 +04:00
if ( vifi < 0 | | vifi > = mrt - > maxvif )
2008-04-03 04:22:53 +04:00
return - EADDRNOTAVAIL ;
2018-03-01 00:29:32 +03:00
v = & mrt - > vif_table [ vifi ] ;
2008-04-03 04:22:53 +04:00
2018-03-26 15:01:34 +03:00
if ( VIF_EXISTS ( mrt , vifi ) )
call_ip6mr_vif_entry_notifiers ( read_pnet ( & mrt - > net ) ,
FIB_EVENT_VIF_DEL , v , vifi ,
mrt - > id ) ;
2008-04-03 04:22:53 +04:00
write_lock_bh ( & mrt_lock ) ;
dev = v - > dev ;
v - > dev = NULL ;
if ( ! dev ) {
write_unlock_bh ( & mrt_lock ) ;
return - EADDRNOTAVAIL ;
}
2008-04-03 04:22:54 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
2010-05-11 16:40:53 +04:00
if ( vifi = = mrt - > mroute_reg_vif_num )
mrt - > mroute_reg_vif_num = - 1 ;
2008-04-03 04:22:54 +04:00
# endif
2010-05-11 16:40:53 +04:00
if ( vifi + 1 = = mrt - > maxvif ) {
2008-04-03 04:22:53 +04:00
int tmp ;
for ( tmp = vifi - 1 ; tmp > = 0 ; tmp - - ) {
2018-03-01 00:29:32 +03:00
if ( VIF_EXISTS ( mrt , tmp ) )
2008-04-03 04:22:53 +04:00
break ;
}
2010-05-11 16:40:53 +04:00
mrt - > maxvif = tmp + 1 ;
2008-04-03 04:22:53 +04:00
}
write_unlock_bh ( & mrt_lock ) ;
dev_set_allmulti ( dev , - 1 ) ;
2009-01-28 09:39:59 +03:00
in6_dev = __in6_dev_get ( dev ) ;
2012-12-04 05:13:35 +04:00
if ( in6_dev ) {
2009-01-28 09:39:59 +03:00
in6_dev - > cnf . mc_forwarding - - ;
2017-03-29 00:28:04 +03:00
inet6_netconf_notify_devconf ( dev_net ( dev ) , RTM_NEWNETCONF ,
2012-12-04 05:13:35 +04:00
NETCONFA_MC_FORWARDING ,
dev - > ifindex , & in6_dev - > cnf ) ;
}
2009-01-28 09:39:59 +03:00
2017-04-21 20:42:16 +03:00
if ( ( v - > flags & MIFF_REGISTER ) & & ! notify )
2009-10-28 07:48:11 +03:00
unregister_netdevice_queue ( dev , head ) ;
2008-04-03 04:22:53 +04:00
dev_put ( dev ) ;
return 0 ;
}
2018-03-01 00:29:31 +03:00
static inline void ip6mr_cache_free_rcu ( struct rcu_head * head )
2008-12-11 03:22:34 +03:00
{
2018-03-01 00:29:34 +03:00
struct mr_mfc * c = container_of ( head , struct mr_mfc , rcu ) ;
2018-03-01 00:29:31 +03:00
2018-03-01 00:29:34 +03:00
kmem_cache_free ( mrt_cachep , ( struct mfc6_cache * ) c ) ;
2008-12-11 03:22:34 +03:00
}
2018-03-01 00:29:31 +03:00
static inline void ip6mr_cache_free ( struct mfc6_cache * c )
{
2018-03-01 00:29:34 +03:00
call_rcu ( & c - > _c . rcu , ip6mr_cache_free_rcu ) ;
2018-03-01 00:29:31 +03:00
}
2008-04-03 04:22:53 +04:00
/* Destroy an unresolved cache entry, killing queued skbs
and reporting error to netlink readers .
*/
2018-03-01 00:29:32 +03:00
static void ip6mr_destroy_unres ( struct mr_table * mrt , struct mfc6_cache * c )
2008-04-03 04:22:53 +04:00
{
2010-05-11 16:40:53 +04:00
struct net * net = read_pnet ( & mrt - > net ) ;
2008-04-03 04:22:53 +04:00
struct sk_buff * skb ;
2010-05-11 16:40:53 +04:00
atomic_dec ( & mrt - > cache_resolve_queue_len ) ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:34 +03:00
while ( ( skb = skb_dequeue ( & c - > _c . mfc_un . unres . unresolved ) ) ! = NULL ) {
2008-04-03 04:22:53 +04: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 15:29:22 +03:00
struct nlmsghdr * nlh = skb_pull ( skb ,
sizeof ( struct ipv6hdr ) ) ;
2008-04-03 04:22:53 +04:00
nlh - > nlmsg_type = NLMSG_ERROR ;
2013-03-27 10:47:04 +04:00
nlh - > nlmsg_len = nlmsg_msg_size ( sizeof ( struct nlmsgerr ) ) ;
2008-04-03 04:22:53 +04:00
skb_trim ( skb , nlh - > nlmsg_len ) ;
2013-03-27 10:47:04 +04:00
( ( struct nlmsgerr * ) nlmsg_data ( nlh ) ) - > error = - ETIMEDOUT ;
2012-09-08 00:12:54 +04:00
rtnl_unicast ( skb , net , NETLINK_CB ( skb ) . portid ) ;
2008-04-03 04:22:53 +04:00
} else
kfree_skb ( skb ) ;
}
2008-12-11 03:22:34 +03:00
ip6mr_cache_free ( c ) ;
2008-04-03 04:22:53 +04:00
}
2010-05-11 16:40:48 +04:00
/* Timer process for all the unresolved queue. */
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:32 +03:00
static void ipmr_do_expire_process ( struct mr_table * mrt )
2008-04-03 04:22:53 +04:00
{
unsigned long now = jiffies ;
unsigned long expires = 10 * HZ ;
2018-03-01 00:29:34 +03:00
struct mr_mfc * c , * next ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:32 +03:00
list_for_each_entry_safe ( c , next , & mrt - > mfc_unres_queue , list ) {
2008-04-03 04:22:53 +04: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 16:40:51 +04:00
list_del ( & c - > list ) ;
2018-03-01 00:29:34 +03:00
mr6_netlink_event ( mrt , ( struct mfc6_cache * ) c , RTM_DELROUTE ) ;
ip6mr_destroy_unres ( mrt , ( struct mfc6_cache * ) c ) ;
2008-04-03 04:22:53 +04:00
}
2018-03-01 00:29:32 +03:00
if ( ! list_empty ( & mrt - > mfc_unres_queue ) )
2010-05-11 16:40:53 +04:00
mod_timer ( & mrt - > ipmr_expire_timer , jiffies + expires ) ;
2008-04-03 04:22:53 +04: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 00:43:17 +03:00
static void ipmr_expire_process ( struct timer_list * t )
2008-04-03 04:22:53 +04:00
{
2018-03-01 00:29:32 +03:00
struct mr_table * mrt = from_timer ( mrt , t , ipmr_expire_timer ) ;
2010-05-11 16:40:48 +04:00
2008-04-03 04:22:53 +04:00
if ( ! spin_trylock ( & mfc_unres_lock ) ) {
2010-05-11 16:40:53 +04:00
mod_timer ( & mrt - > ipmr_expire_timer , jiffies + 1 ) ;
2008-04-03 04:22:53 +04:00
return ;
}
2018-03-01 00:29:32 +03:00
if ( ! list_empty ( & mrt - > mfc_unres_queue ) )
2010-05-11 16:40:53 +04:00
ipmr_do_expire_process ( mrt ) ;
2008-04-03 04:22:53 +04:00
spin_unlock ( & mfc_unres_lock ) ;
}
/* Fill oifs list. It is called under write locked mrt_lock. */
2018-03-01 00:29:32 +03:00
static void ip6mr_update_thresholds ( struct mr_table * mrt ,
2018-03-01 00:29:34 +03:00
struct mr_mfc * cache ,
2010-05-11 16:40:50 +04:00
unsigned char * ttls )
2008-04-03 04:22:53 +04:00
{
int vifi ;
2008-04-10 13:40:10 +04:00
cache - > mfc_un . res . minvif = MAXMIFS ;
2008-04-03 04:22:53 +04:00
cache - > mfc_un . res . maxvif = 0 ;
2008-04-10 13:40:10 +04:00
memset ( cache - > mfc_un . res . ttls , 255 , MAXMIFS ) ;
2008-04-03 04:22:53 +04:00
2010-05-11 16:40:53 +04:00
for ( vifi = 0 ; vifi < mrt - > maxvif ; vifi + + ) {
2018-03-01 00:29:32 +03:00
if ( VIF_EXISTS ( mrt , vifi ) & &
2008-12-11 03:15:08 +03:00
ttls [ vifi ] & & ttls [ vifi ] < 255 ) {
2008-04-03 04:22:53 +04: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-26 19:54:52 +03:00
cache - > mfc_un . res . lastuse = jiffies ;
2008-04-03 04:22:53 +04:00
}
2018-03-01 00:29:32 +03:00
static int mif6_add ( struct net * net , struct mr_table * mrt ,
2010-05-11 16:40:53 +04:00
struct mif6ctl * vifc , int mrtsock )
2008-04-03 04:22:53 +04:00
{
int vifi = vifc - > mif6c_mifi ;
2018-03-01 00:29:32 +03:00
struct vif_device * v = & mrt - > vif_table [ vifi ] ;
2008-04-03 04:22:53 +04:00
struct net_device * dev ;
2009-01-28 09:39:59 +03:00
struct inet6_dev * in6_dev ;
2008-07-15 07:54:23 +04:00
int err ;
2008-04-03 04:22:53 +04:00
/* Is vif busy ? */
2018-03-01 00:29:32 +03:00
if ( VIF_EXISTS ( mrt , vifi ) )
2008-04-03 04:22:53 +04:00
return - EADDRINUSE ;
switch ( vifc - > mif6c_flags ) {
2008-04-03 04:22:54 +04: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 16:40:53 +04:00
if ( mrt - > mroute_reg_vif_num > = 0 )
2008-04-03 04:22:54 +04: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 16:40:55 +04:00
dev = ip6mr_reg_vif ( net , mrt ) ;
2008-04-03 04:22:54 +04:00
if ( ! dev )
return - ENOBUFS ;
2008-07-15 07:54:23 +04:00
err = dev_set_allmulti ( dev , 1 ) ;
if ( err ) {
unregister_netdevice ( dev ) ;
2008-07-15 07:54:54 +04:00
dev_put ( dev ) ;
2008-07-15 07:54:23 +04:00
return err ;
}
2008-04-03 04:22:54 +04:00
break ;
# endif
2008-04-03 04:22:53 +04:00
case 0 :
2008-12-11 03:30:15 +03:00
dev = dev_get_by_index ( net , vifc - > mif6c_pifi ) ;
2008-04-03 04:22:53 +04:00
if ( ! dev )
return - EADDRNOTAVAIL ;
2008-07-15 07:54:23 +04:00
err = dev_set_allmulti ( dev , 1 ) ;
2008-07-15 07:54:54 +04:00
if ( err ) {
dev_put ( dev ) ;
2008-07-15 07:54:23 +04:00
return err ;
2008-07-15 07:54:54 +04:00
}
2008-04-03 04:22:53 +04:00
break ;
default :
return - EINVAL ;
}
2009-01-28 09:39:59 +03:00
in6_dev = __in6_dev_get ( dev ) ;
2012-12-04 05:13:35 +04:00
if ( in6_dev ) {
2009-01-28 09:39:59 +03:00
in6_dev - > cnf . mc_forwarding + + ;
2017-03-29 00:28:04 +03:00
inet6_netconf_notify_devconf ( dev_net ( dev ) , RTM_NEWNETCONF ,
2012-12-04 05:13:35 +04:00
NETCONFA_MC_FORWARDING ,
dev - > ifindex , & in6_dev - > cnf ) ;
}
2009-01-28 09:39:59 +03:00
2018-03-01 00:29:29 +03: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 04:22:53 +04:00
/* And finish update writing critical data */
write_lock_bh ( & mrt_lock ) ;
v - > dev = dev ;
2008-04-03 04:22:54 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
if ( v - > flags & MIFF_REGISTER )
2010-05-11 16:40:53 +04:00
mrt - > mroute_reg_vif_num = vifi ;
2008-04-03 04:22:54 +04:00
# endif
2010-05-11 16:40:53 +04:00
if ( vifi + 1 > mrt - > maxvif )
mrt - > maxvif = vifi + 1 ;
2008-04-03 04:22:53 +04:00
write_unlock_bh ( & mrt_lock ) ;
2018-03-26 15:01:34 +03:00
call_ip6mr_vif_entry_notifiers ( net , FIB_EVENT_VIF_ADD ,
v , vifi , mrt - > id ) ;
2008-04-03 04:22:53 +04:00
return 0 ;
}
2018-03-01 00:29:32 +03:00
static struct mfc6_cache * ip6mr_cache_find ( struct mr_table * mrt ,
2011-04-22 08:53:02 +04:00
const struct in6_addr * origin ,
const struct in6_addr * mcastgrp )
2008-04-03 04:22:53 +04:00
{
2018-03-01 00:29:31 +03:00
struct mfc6_cache_cmp_arg arg = {
. mf6c_origin = * origin ,
. mf6c_mcastgrp = * mcastgrp ,
} ;
2018-03-01 00:29:35 +03:00
return mr_mfc_find ( mrt , & arg ) ;
2013-01-21 10:00:26 +04:00
}
/* Look for a (*,G) entry */
2018-03-01 00:29:32 +03:00
static struct mfc6_cache * ip6mr_cache_find_any ( struct mr_table * mrt ,
2013-01-21 10:00:26 +04:00
struct in6_addr * mcastgrp ,
mifi_t mifi )
{
2018-03-01 00:29:31 +03:00
struct mfc6_cache_cmp_arg arg = {
. mf6c_origin = in6addr_any ,
. mf6c_mcastgrp = * mcastgrp ,
} ;
2013-01-21 10:00:26 +04:00
if ( ipv6_addr_any ( mcastgrp ) )
2018-03-01 00:29:35 +03:00
return mr_mfc_find_any_parent ( mrt , mifi ) ;
return mr_mfc_find_any ( mrt , mifi , & arg ) ;
2013-01-21 10:00:26 +04:00
}
2018-03-01 00:29:31 +03:00
/* Look for a (S,G,iif) entry if parent != -1 */
static struct mfc6_cache *
2018-03-01 00:29:32 +03:00
ip6mr_cache_find_parent ( struct mr_table * mrt ,
2018-03-01 00:29:31 +03: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 00:29:35 +03:00
return mr_mfc_find_parent ( mrt , & arg , parent ) ;
2018-03-01 00:29:31 +03:00
}
2018-03-01 00:29:35 +03:00
/* Allocate a multicast cache entry */
2010-05-11 16:40:50 +04:00
static struct mfc6_cache * ip6mr_cache_alloc ( void )
2008-04-03 04:22:53 +04:00
{
2008-12-04 09:27:25 +03:00
struct mfc6_cache * c = kmem_cache_zalloc ( mrt_cachep , GFP_KERNEL ) ;
2015-03-29 16:00:04 +03:00
if ( ! c )
2008-04-03 04:22:53 +04:00
return NULL ;
2018-03-01 00:29:34 +03:00
c - > _c . mfc_un . res . last_assert = jiffies - MFC_ASSERT_THRESH - 1 ;
c - > _c . mfc_un . res . minvif = MAXMIFS ;
2018-03-26 15:01:36 +03:00
c - > _c . free = ip6mr_cache_free_rcu ;
refcount_set ( & c - > _c . mfc_un . res . refcount , 1 ) ;
2008-04-03 04:22:53 +04:00
return c ;
}
2010-05-11 16:40:50 +04:00
static struct mfc6_cache * ip6mr_cache_alloc_unres ( void )
2008-04-03 04:22:53 +04:00
{
2008-12-04 09:27:25 +03:00
struct mfc6_cache * c = kmem_cache_zalloc ( mrt_cachep , GFP_ATOMIC ) ;
2015-03-29 16:00:04 +03:00
if ( ! c )
2008-04-03 04:22:53 +04:00
return NULL ;
2018-03-01 00:29:34 +03:00
skb_queue_head_init ( & c - > _c . mfc_un . unres . unresolved ) ;
c - > _c . mfc_un . unres . expires = jiffies + 10 * HZ ;
2008-04-03 04:22:53 +04:00
return c ;
}
/*
* A cache entry has gone into a resolved state from queued
*/
2018-03-01 00:29:32 +03:00
static void ip6mr_cache_resolve ( struct net * net , struct mr_table * mrt ,
2010-05-11 16:40:53 +04:00
struct mfc6_cache * uc , struct mfc6_cache * c )
2008-04-03 04:22:53 +04:00
{
struct sk_buff * skb ;
/*
* Play the pending entries through our router
*/
2018-03-01 00:29:34 +03:00
while ( ( skb = __skb_dequeue ( & uc - > _c . mfc_un . unres . unresolved ) ) ) {
2008-04-03 04:22:53 +04: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 15:29:22 +03:00
struct nlmsghdr * nlh = skb_pull ( skb ,
sizeof ( struct ipv6hdr ) ) ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:39 +03:00
if ( mr_fill_mroute ( mrt , skb , & c - > _c ,
nlmsg_data ( nlh ) ) > 0 ) {
2008-04-05 17:17:39 +04:00
nlh - > nlmsg_len = skb_tail_pointer ( skb ) - ( u8 * ) nlh ;
2008-04-03 04:22:53 +04:00
} else {
nlh - > nlmsg_type = NLMSG_ERROR ;
2013-03-27 10:47:04 +04:00
nlh - > nlmsg_len = nlmsg_msg_size ( sizeof ( struct nlmsgerr ) ) ;
2008-04-03 04:22:53 +04:00
skb_trim ( skb , nlh - > nlmsg_len ) ;
2013-03-27 10:47:04 +04:00
( ( struct nlmsgerr * ) nlmsg_data ( nlh ) ) - > error = - EMSGSIZE ;
2008-04-03 04:22:53 +04:00
}
2012-09-08 00:12:54 +04:00
rtnl_unicast ( skb , net , NETLINK_CB ( skb ) . portid ) ;
2008-04-03 04:22:53 +04:00
} else
2018-10-01 11:41:27 +03:00
ip6_mr_forward ( net , mrt , skb - > dev , skb , c ) ;
2008-04-03 04:22:53 +04:00
}
}
/*
2017-06-20 23:54:18 +03:00
* Bounce a cache query up to pim6sd and netlink .
2008-04-03 04:22:53 +04:00
*
* Called under mrt_lock .
*/
2018-03-01 00:29:32 +03:00
static int ip6mr_cache_report ( struct mr_table * mrt , struct sk_buff * pkt ,
2010-05-11 16:40:53 +04:00
mifi_t mifi , int assert )
2008-04-03 04:22:53 +04:00
{
2018-03-01 00:29:30 +03:00
struct sock * mroute6_sk ;
2008-04-03 04:22:53 +04:00
struct sk_buff * skb ;
struct mrt6msg * msg ;
int ret ;
2008-04-03 04:22:54 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
if ( assert = = MRT6MSG_WHOLEPKT )
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 04:22:53 +04:00
if ( ! skb )
return - ENOBUFS ;
/* I suppose that internal messages
* do not require checksums */
skb - > ip_summed = CHECKSUM_UNNECESSARY ;
2008-04-03 04:22:54 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
if ( assert = = MRT6MSG_WHOLEPKT ) {
/* 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 ;
msg - > im6_msgtype = MRT6MSG_WHOLEPKT ;
2010-05-11 16:40:53 +04:00
msg - > im6_mif = mrt - > mroute_reg_vif_num ;
2008-04-03 04:22:54 +04:00
msg - > im6_pad = 0 ;
2011-11-21 07:39:03 +04:00
msg - > im6_src = ipv6_hdr ( pkt ) - > saddr ;
msg - > im6_dst = ipv6_hdr ( pkt ) - > daddr ;
2008-04-03 04:22:54 +04:00
skb - > ip_summed = CHECKSUM_UNNECESSARY ;
} else
# endif
{
2008-04-03 04:22:53 +04: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 13:40:10 +04:00
msg - > im6_mif = mifi ;
2008-04-03 04:22:53 +04:00
msg - > im6_pad = 0 ;
2011-11-21 07:39:03 +04:00
msg - > im6_src = ipv6_hdr ( pkt ) - > saddr ;
msg - > im6_dst = ipv6_hdr ( pkt ) - > daddr ;
2008-04-03 04:22:53 +04:00
2009-06-02 09:19:30 +04:00
skb_dst_set ( skb , dst_clone ( skb_dst ( pkt ) ) ) ;
2008-04-03 04:22:53 +04:00
skb - > ip_summed = CHECKSUM_UNNECESSARY ;
2008-04-03 04:22:54 +04:00
}
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:30 +03:00
rcu_read_lock ( ) ;
2018-03-01 00:29:32 +03:00
mroute6_sk = rcu_dereference ( mrt - > mroute_sk ) ;
2018-03-01 00:29:30 +03:00
if ( ! mroute6_sk ) {
rcu_read_unlock ( ) ;
2008-04-03 04:22:53 +04:00
kfree_skb ( skb ) ;
return - EINVAL ;
}
2017-06-20 23:54:18 +03:00
mrt6msg_netlink_event ( mrt , skb ) ;
2018-03-01 00:29:30 +03:00
/* Deliver to user space multicast routing algorithms */
ret = sock_queue_rcv_skb ( mroute6_sk , skb ) ;
rcu_read_unlock ( ) ;
2008-12-11 03:07:08 +03:00
if ( ret < 0 ) {
2012-05-14 01:56:26 +04:00
net_warn_ratelimited ( " mroute6: pending queue full, dropping entries \n " ) ;
2008-04-03 04:22:53 +04:00
kfree_skb ( skb ) ;
}
return ret ;
}
2018-03-01 00:29:34 +03: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 11:41:27 +03:00
struct sk_buff * skb , struct net_device * dev )
2008-04-03 04:22:53 +04:00
{
2018-03-01 00:29:34 +03:00
struct mfc6_cache * c ;
2010-05-11 16:40:51 +04:00
bool found = false ;
2008-04-03 04:22:53 +04:00
int err ;
spin_lock_bh ( & mfc_unres_lock ) ;
2018-03-01 00:29:34 +03:00
list_for_each_entry ( c , & mrt - > mfc_unres_queue , _c . list ) {
2010-05-11 16:40:48 +04:00
if ( ipv6_addr_equal ( & c - > mf6c_mcastgrp , & ipv6_hdr ( skb ) - > daddr ) & &
2010-05-11 16:40:51 +04:00
ipv6_addr_equal ( & c - > mf6c_origin , & ipv6_hdr ( skb ) - > saddr ) ) {
found = true ;
2008-04-03 04:22:53 +04:00
break ;
2010-05-11 16:40:51 +04:00
}
2008-04-03 04:22:53 +04:00
}
2010-05-11 16:40:51 +04:00
if ( ! found ) {
2008-04-03 04:22:53 +04:00
/*
* Create a new entry if allowable
*/
2010-05-11 16:40:53 +04:00
if ( atomic_read ( & mrt - > cache_resolve_queue_len ) > = 10 | |
2010-05-11 16:40:50 +04:00
( c = ip6mr_cache_alloc_unres ( ) ) = = NULL ) {
2008-04-03 04:22:53 +04:00
spin_unlock_bh ( & mfc_unres_lock ) ;
kfree_skb ( skb ) ;
return - ENOBUFS ;
}
2018-03-01 00:29:34 +03:00
/* Fill in the new cache entry */
c - > _c . mfc_parent = - 1 ;
2008-04-03 04:22:53 +04:00
c - > mf6c_origin = ipv6_hdr ( skb ) - > saddr ;
c - > mf6c_mcastgrp = ipv6_hdr ( skb ) - > daddr ;
/*
* Reflect first query at pim6sd
*/
2010-05-11 16:40:53 +04:00
err = ip6mr_cache_report ( mrt , skb , mifi , MRT6MSG_NOCACHE ) ;
2008-12-11 03:30:15 +03:00
if ( err < 0 ) {
2008-04-03 04:22:53 +04:00
/* If the report failed throw the cache entry
out - Brad Parker
*/
spin_unlock_bh ( & mfc_unres_lock ) ;
2008-12-11 03:22:34 +03:00
ip6mr_cache_free ( c ) ;
2008-04-03 04:22:53 +04:00
kfree_skb ( skb ) ;
return err ;
}
2010-05-11 16:40:53 +04:00
atomic_inc ( & mrt - > cache_resolve_queue_len ) ;
2018-03-01 00:29:34 +03:00
list_add ( & c - > _c . list , & mrt - > mfc_unres_queue ) ;
2012-12-04 05:13:41 +04:00
mr6_netlink_event ( mrt , c , RTM_NEWROUTE ) ;
2008-04-03 04:22:53 +04:00
2010-05-11 16:40:53 +04:00
ipmr_do_expire_process ( mrt ) ;
2008-04-03 04:22:53 +04:00
}
2018-03-01 00:29:34 +03:00
/* See if we can append the packet */
if ( c - > _c . mfc_un . unres . unresolved . qlen > 3 ) {
2008-04-03 04:22:53 +04:00
kfree_skb ( skb ) ;
err = - ENOBUFS ;
} else {
2018-10-01 11:41:27 +03:00
if ( dev ) {
skb - > dev = dev ;
skb - > skb_iif = dev - > ifindex ;
}
2018-03-01 00:29:34 +03:00
skb_queue_tail ( & c - > _c . mfc_un . unres . unresolved , skb ) ;
2008-04-03 04:22:53 +04:00
err = 0 ;
}
spin_unlock_bh ( & mfc_unres_lock ) ;
return err ;
}
/*
* MFC6 cache manipulation by user space
*/
2018-03-01 00:29:32 +03:00
static int ip6mr_mfc_delete ( struct mr_table * mrt , struct mf6cctl * mfc ,
2013-01-21 10:00:26 +04:00
int parent )
2008-04-03 04:22:53 +04:00
{
2018-03-01 00:29:31 +03:00
struct mfc6_cache * c ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:31 +03: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 00:29:34 +03:00
rhltable_remove ( & mrt - > mfc_hash , & c - > _c . mnode , ip6mr_rht_params ) ;
list_del_rcu ( & c - > _c . list ) ;
2008-04-03 04:22:53 +04:00
2018-03-26 15:01:34 +03:00
call_ip6mr_mfc_entry_notifiers ( read_pnet ( & mrt - > net ) ,
FIB_EVENT_ENTRY_DEL , c , mrt - > id ) ;
2018-03-01 00:29:31 +03:00
mr6_netlink_event ( mrt , c , RTM_DELROUTE ) ;
2018-03-26 15:01:36 +03:00
mr_cache_put ( & c - > _c ) ;
2018-03-01 00:29:31 +03:00
return 0 ;
2008-04-03 04:22:53 +04:00
}
static int ip6mr_device_event ( struct notifier_block * this ,
unsigned long event , void * ptr )
{
2013-05-28 05:30:21 +04:00
struct net_device * dev = netdev_notifier_info_to_dev ( ptr ) ;
2008-12-11 03:30:15 +03:00
struct net * net = dev_net ( dev ) ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2018-03-01 00:29:29 +03:00
struct vif_device * v ;
2008-04-03 04:22:53 +04: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 16:40:55 +04:00
ip6mr_for_each_table ( mrt , net ) {
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
for ( ct = 0 ; ct < mrt - > maxvif ; ct + + , v + + ) {
if ( v - > dev = = dev )
2017-04-21 20:42:16 +03: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 16:40:55 +04:00
}
2008-04-03 04:22:53 +04:00
}
2009-10-28 07:48:11 +03:00
2008-04-03 04:22:53 +04:00
return NOTIFY_DONE ;
}
2018-03-26 15:01:34 +03:00
static unsigned int ip6mr_seq_read ( struct net * net )
{
ASSERT_RTNL ( ) ;
return net - > ipv6 . ipmr_seq + ip6mr_rules_seq_read ( net ) ;
}
static int ip6mr_dump ( struct net * net , struct notifier_block * nb )
{
return mr_dump ( net , nb , RTNL_FAMILY_IP6MR , ip6mr_rules_dump ,
ip6mr_mr_table_iter , & mrt_lock ) ;
}
2008-04-03 04:22:53 +04:00
static struct notifier_block ip6_mr_notifier = {
. notifier_call = ip6mr_device_event
} ;
2018-03-26 15:01:34 +03: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 04:22:53 +04:00
2018-03-26 15:01:34 +03: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 03:15:08 +03: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 16:40:55 +04:00
int err ;
2010-05-11 16:40:51 +04:00
2018-03-26 15:01:34 +03: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 16:40:55 +04:00
err = ip6mr_rules_init ( net ) ;
if ( err < 0 )
2018-03-26 15:01:34 +03:00
goto ip6mr_rules_fail ;
2008-12-11 03:29:48 +03:00
# ifdef CONFIG_PROC_FS
err = - ENOMEM ;
2018-04-10 20:42:55 +03:00
if ( ! proc_create_net ( " ip6_mr_vif " , 0 , net - > proc_net , & ip6mr_vif_seq_ops ,
sizeof ( struct mr_vif_iter ) ) )
2008-12-11 03:29:48 +03:00
goto proc_vif_fail ;
2018-04-10 20:42:55 +03:00
if ( ! proc_create_net ( " ip6_mr_cache " , 0 , net - > proc_net , & ipmr_mfc_seq_ops ,
sizeof ( struct mr_mfc_iter ) ) )
2008-12-11 03:29:48 +03:00
goto proc_cache_fail ;
# endif
2010-05-11 16:40:53 +04:00
2008-12-11 03:24:07 +03:00
return 0 ;
2008-12-11 03:29:48 +03:00
# ifdef CONFIG_PROC_FS
proc_cache_fail :
2013-02-18 05:34:56 +04:00
remove_proc_entry ( " ip6_mr_vif " , net - > proc_net ) ;
2008-12-11 03:29:48 +03:00
proc_vif_fail :
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 16:40:55 +04:00
ip6mr_rules_exit ( net ) ;
2008-12-11 03:29:48 +03:00
# endif
2018-03-26 15:01:34 +03:00
ip6mr_rules_fail :
ip6mr_notifier_exit ( net ) ;
2008-12-11 03:15:08 +03:00
return err ;
}
static void __net_exit ip6mr_net_exit ( struct net * net )
{
2008-12-11 03:29:48 +03:00
# ifdef CONFIG_PROC_FS
2013-02-18 05:34:56 +04:00
remove_proc_entry ( " ip6_mr_cache " , net - > proc_net ) ;
remove_proc_entry ( " ip6_mr_vif " , net - > proc_net ) ;
2008-12-11 03:29:48 +03:00
# endif
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 16:40:55 +04:00
ip6mr_rules_exit ( net ) ;
2018-03-26 15:01:34 +03:00
ip6mr_notifier_exit ( net ) ;
2008-12-11 03:15:08 +03:00
}
static struct pernet_operations ip6mr_net_ops = {
. init = ip6mr_net_init ,
. exit = ip6mr_net_exit ,
} ;
2008-07-03 08:13:30 +04:00
int __init ip6_mr_init ( void )
2008-04-03 04:22:53 +04:00
{
2008-07-03 08:13:30 +04:00
int err ;
2008-04-03 04:22:53 +04:00
mrt_cachep = kmem_cache_create ( " ip6_mrt_cache " ,
sizeof ( struct mfc6_cache ) ,
0 , SLAB_HWCACHE_ALIGN ,
NULL ) ;
if ( ! mrt_cachep )
2008-07-03 08:13:30 +04:00
return - ENOMEM ;
2008-04-03 04:22:53 +04:00
2008-12-11 03:15:08 +03:00
err = register_pernet_subsys ( & ip6mr_net_ops ) ;
if ( err )
goto reg_pernet_fail ;
2008-07-03 08:13:30 +04:00
err = register_netdevice_notifier ( & ip6_mr_notifier ) ;
if ( err )
goto reg_notif_fail ;
2009-06-14 14:16:13 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
if ( inet6_add_protocol ( & pim6_protocol , IPPROTO_PIM ) < 0 ) {
2012-05-15 18:11:53 +04:00
pr_err ( " %s: can't add PIM protocol \n " , __func__ ) ;
2009-06-14 14:16:13 +04:00
err = - EAGAIN ;
goto add_proto_fail ;
}
# endif
2017-12-04 21:19:18 +03: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 14:16:13 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
2017-12-04 21:19:18 +03:00
inet6_del_protocol ( & pim6_protocol , IPPROTO_PIM ) ;
2009-06-14 14:16:13 +04:00
add_proto_fail :
unregister_netdevice_notifier ( & ip6_mr_notifier ) ;
# endif
2008-11-11 03:34:11 +03:00
reg_notif_fail :
2008-12-11 03:15:08 +03:00
unregister_pernet_subsys ( & ip6mr_net_ops ) ;
reg_pernet_fail :
2008-11-11 03:34:11 +03:00
kmem_cache_destroy ( mrt_cachep ) ;
2008-07-03 08:13:30 +04:00
return err ;
2008-04-03 04:22:53 +04:00
}
2008-07-03 08:13:30 +04:00
void ip6_mr_cleanup ( void )
{
2014-11-19 04:35:39 +03:00
rtnl_unregister ( RTNL_FAMILY_IP6MR , RTM_GETROUTE ) ;
# ifdef CONFIG_IPV6_PIMSM_V2
inet6_del_protocol ( & pim6_protocol , IPPROTO_PIM ) ;
# endif
2008-07-03 08:13:30 +04:00
unregister_netdevice_notifier ( & ip6_mr_notifier ) ;
2008-12-11 03:15:08 +03:00
unregister_pernet_subsys ( & ip6mr_net_ops ) ;
2008-07-03 08:13:30 +04:00
kmem_cache_destroy ( mrt_cachep ) ;
}
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:32 +03:00
static int ip6mr_mfc_add ( struct net * net , struct mr_table * mrt ,
2013-01-21 10:00:26 +04:00
struct mf6cctl * mfc , int mrtsock , int parent )
2008-04-03 04:22:53 +04:00
{
2008-04-10 13:40:10 +04:00
unsigned char ttls [ MAXMIFS ] ;
2018-03-01 00:29:31 +03:00
struct mfc6_cache * uc , * c ;
2018-03-01 00:29:34 +03:00
struct mr_mfc * _uc ;
2018-03-01 00:29:31 +03:00
bool found ;
int i , err ;
2008-04-03 04:22:53 +04:00
2010-03-17 09:04:14 +03:00
if ( mfc - > mf6cc_parent > = MAXMIFS )
return - ENFILE ;
2008-04-10 13:40:10 +04:00
memset ( ttls , 255 , MAXMIFS ) ;
for ( i = 0 ; i < MAXMIFS ; i + + ) {
2008-04-03 04:22:53 +04:00
if ( IF_ISSET ( i , & mfc - > mf6cc_ifset ) )
ttls [ i ] = 1 ;
}
2018-03-01 00:29:31 +03: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 ) {
2008-04-03 04:22:53 +04:00
write_lock_bh ( & mrt_lock ) ;
2018-03-01 00:29:34 +03:00
c - > _c . mfc_parent = mfc - > mf6cc_parent ;
ip6mr_update_thresholds ( mrt , & c - > _c , ttls ) ;
2008-04-03 04:22:53 +04:00
if ( ! mrtsock )
2018-03-01 00:29:34 +03:00
c - > _c . mfc_flags | = MFC_STATIC ;
2008-04-03 04:22:53 +04:00
write_unlock_bh ( & mrt_lock ) ;
2018-03-26 15:01:34 +03:00
call_ip6mr_mfc_entry_notifiers ( net , FIB_EVENT_ENTRY_REPLACE ,
c , mrt - > id ) ;
2012-12-04 05:13:41 +04:00
mr6_netlink_event ( mrt , c , RTM_NEWROUTE ) ;
2008-04-03 04:22:53 +04:00
return 0 ;
}
2013-01-21 10:00:26 +04:00
if ( ! ipv6_addr_any ( & mfc - > mf6cc_mcastgrp . sin6_addr ) & &
! ipv6_addr_is_multicast ( & mfc - > mf6cc_mcastgrp . sin6_addr ) )
2008-04-03 04:22:53 +04:00
return - EINVAL ;
2010-05-11 16:40:50 +04:00
c = ip6mr_cache_alloc ( ) ;
2015-03-29 16:00:04 +03:00
if ( ! c )
2008-04-03 04:22:53 +04:00
return - ENOMEM ;
c - > mf6c_origin = mfc - > mf6cc_origin . sin6_addr ;
c - > mf6c_mcastgrp = mfc - > mf6cc_mcastgrp . sin6_addr ;
2018-03-01 00:29:34 +03:00
c - > _c . mfc_parent = mfc - > mf6cc_parent ;
ip6mr_update_thresholds ( mrt , & c - > _c , ttls ) ;
2008-04-03 04:22:53 +04:00
if ( ! mrtsock )
2018-03-01 00:29:34 +03:00
c - > _c . mfc_flags | = MFC_STATIC ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:34 +03:00
err = rhltable_insert_key ( & mrt - > mfc_hash , & c - > cmparg , & c - > _c . mnode ,
2018-03-01 00:29:31 +03:00
ip6mr_rht_params ) ;
if ( err ) {
pr_err ( " ip6mr: rhtable insert error %d \n " , err ) ;
ip6mr_cache_free ( c ) ;
return err ;
}
2018-03-01 00:29:34 +03:00
list_add_tail_rcu ( & c - > _c . list , & mrt - > mfc_cache_list ) ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:31 +03: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 04:22:53 +04:00
*/
2010-05-11 16:40:51 +04:00
found = false ;
2008-04-03 04:22:53 +04:00
spin_lock_bh ( & mfc_unres_lock ) ;
2018-03-01 00:29:34 +03:00
list_for_each_entry ( _uc , & mrt - > mfc_unres_queue , list ) {
uc = ( struct mfc6_cache * ) _uc ;
2010-05-11 16:40:48 +04:00
if ( ipv6_addr_equal ( & uc - > mf6c_origin , & c - > mf6c_origin ) & &
2008-04-03 04:22:53 +04:00
ipv6_addr_equal ( & uc - > mf6c_mcastgrp , & c - > mf6c_mcastgrp ) ) {
2018-03-01 00:29:34 +03:00
list_del ( & _uc - > list ) ;
2010-05-11 16:40:53 +04:00
atomic_dec ( & mrt - > cache_resolve_queue_len ) ;
2010-05-11 16:40:51 +04:00
found = true ;
2008-04-03 04:22:53 +04:00
break ;
}
}
2018-03-01 00:29:32 +03:00
if ( list_empty ( & mrt - > mfc_unres_queue ) )
2010-05-11 16:40:53 +04:00
del_timer ( & mrt - > ipmr_expire_timer ) ;
2008-04-03 04:22:53 +04:00
spin_unlock_bh ( & mfc_unres_lock ) ;
2010-05-11 16:40:51 +04:00
if ( found ) {
2010-05-11 16:40:53 +04:00
ip6mr_cache_resolve ( net , mrt , uc , c ) ;
2008-12-11 03:22:34 +03:00
ip6mr_cache_free ( uc ) ;
2008-04-03 04:22:53 +04:00
}
2018-03-26 15:01:34 +03:00
call_ip6mr_mfc_entry_notifiers ( net , FIB_EVENT_ENTRY_ADD ,
c , mrt - > id ) ;
2012-12-04 05:13:41 +04:00
mr6_netlink_event ( mrt , c , RTM_NEWROUTE ) ;
2008-04-03 04:22:53 +04:00
return 0 ;
}
/*
* Close the multicast socket , and clear the vif tables etc
*/
2018-03-01 00:29:32 +03:00
static void mroute_clean_tables ( struct mr_table * mrt , bool all )
2008-04-03 04:22:53 +04:00
{
2018-03-01 00:29:34 +03:00
struct mr_mfc * c , * tmp ;
2009-10-28 07:48:11 +03:00
LIST_HEAD ( list ) ;
2018-03-01 00:29:31 +03:00
int i ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:31 +03:00
/* Shut down all active vif entries */
2010-05-11 16:40:53 +04:00
for ( i = 0 ; i < mrt - > maxvif ; i + + ) {
2018-03-01 00:29:32 +03:00
if ( ! all & & ( mrt - > vif_table [ i ] . flags & VIFF_STATIC ) )
2015-11-20 15:54:20 +03:00
continue ;
2017-04-21 20:42:16 +03:00
mif6_delete ( mrt , i , 0 , & list ) ;
2008-04-03 04:22:53 +04:00
}
2009-10-28 07:48:11 +03:00
unregister_netdevice_many ( & list ) ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:31 +03:00
/* Wipe the cache */
2018-03-01 00:29:32 +03:00
list_for_each_entry_safe ( c , tmp , & mrt - > mfc_cache_list , list ) {
2018-03-01 00:29:31 +03:00
if ( ! all & & ( c - > mfc_flags & MFC_STATIC ) )
continue ;
2018-03-01 00:29:32 +03:00
rhltable_remove ( & mrt - > mfc_hash , & c - > mnode , ip6mr_rht_params ) ;
2018-03-01 00:29:31 +03:00
list_del_rcu ( & c - > list ) ;
2018-03-01 00:29:34 +03:00
mr6_netlink_event ( mrt , ( struct mfc6_cache * ) c , RTM_DELROUTE ) ;
2018-03-26 15:01:36 +03:00
mr_cache_put ( c ) ;
2008-04-03 04:22:53 +04:00
}
2010-05-11 16:40:53 +04:00
if ( atomic_read ( & mrt - > cache_resolve_queue_len ) ! = 0 ) {
2008-04-03 04:22:53 +04:00
spin_lock_bh ( & mfc_unres_lock ) ;
2018-03-01 00:29:32 +03:00
list_for_each_entry_safe ( c , tmp , & mrt - > mfc_unres_queue , list ) {
2010-05-11 16:40:51 +04:00
list_del ( & c - > list ) ;
2018-03-26 15:01:34 +03:00
call_ip6mr_mfc_entry_notifiers ( read_pnet ( & mrt - > net ) ,
FIB_EVENT_ENTRY_DEL ,
( struct mfc6_cache * ) c ,
mrt - > id ) ;
2018-03-01 00:29:34 +03:00
mr6_netlink_event ( mrt , ( struct mfc6_cache * ) c ,
RTM_DELROUTE ) ;
ip6mr_destroy_unres ( mrt , ( struct mfc6_cache * ) c ) ;
2008-04-03 04:22:53 +04:00
}
spin_unlock_bh ( & mfc_unres_lock ) ;
}
}
2018-03-01 00:29:32 +03:00
static int ip6mr_sk_init ( struct mr_table * mrt , struct sock * sk )
2008-04-03 04:22:53 +04:00
{
int err = 0 ;
2008-12-11 03:30:15 +03:00
struct net * net = sock_net ( sk ) ;
2008-04-03 04:22:53 +04:00
rtnl_lock ( ) ;
write_lock_bh ( & mrt_lock ) ;
2018-03-01 00:29:32 +03:00
if ( rtnl_dereference ( mrt - > mroute_sk ) ) {
2008-04-03 04:22:53 +04:00
err = - EADDRINUSE ;
2018-03-01 00:29:30 +03:00
} else {
2018-03-01 00:29:32 +03:00
rcu_assign_pointer ( mrt - > mroute_sk , sk ) ;
2018-03-07 19:43:19 +03:00
sock_set_flag ( sk , SOCK_RCU_FREE ) ;
2018-03-01 00:29:30 +03:00
net - > ipv6 . devconf_all - > mc_forwarding + + ;
2016-07-08 06:46:04 +03:00
}
2008-04-03 04:22:53 +04:00
write_unlock_bh ( & mrt_lock ) ;
2016-07-08 06:46:04 +03:00
if ( ! err )
2017-03-29 00:28:04 +03:00
inet6_netconf_notify_devconf ( net , RTM_NEWNETCONF ,
NETCONFA_MC_FORWARDING ,
2016-07-08 06:46:04 +03:00
NETCONFA_IFINDEX_ALL ,
net - > ipv6 . devconf_all ) ;
2008-04-03 04:22:53 +04:00
rtnl_unlock ( ) ;
return err ;
}
int ip6mr_sk_done ( struct sock * 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 16:40:55 +04:00
int err = - EACCES ;
2008-12-11 03:30:15 +03:00
struct net * net = sock_net ( sk ) ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2008-04-03 04:22:53 +04:00
2017-11-08 22:23:46 +03:00
if ( sk - > sk_type ! = SOCK_RAW | |
inet_sk ( sk ) - > inet_num ! = IPPROTO_ICMPV6 )
return err ;
2008-04-03 04:22:53 +04: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 16:40:55 +04:00
ip6mr_for_each_table ( mrt , net ) {
2018-03-01 00:29:32 +03:00
if ( sk = = rtnl_dereference ( 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 16:40:55 +04:00
write_lock_bh ( & mrt_lock ) ;
2018-03-01 00:29:32 +03:00
RCU_INIT_POINTER ( mrt - > mroute_sk , NULL ) ;
2018-03-07 19:43:19 +03:00
/* Note that mroute_sk had SOCK_RCU_FREE set,
* so the RCU grace period before sk freeing
* is guaranteed by sk_destruct ( )
*/
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 16:40:55 +04:00
net - > ipv6 . devconf_all - > mc_forwarding - - ;
2016-07-08 06:46:04 +03:00
write_unlock_bh ( & mrt_lock ) ;
2017-03-29 00:28:04 +03:00
inet6_netconf_notify_devconf ( net , RTM_NEWNETCONF ,
2012-12-04 05:13:35 +04:00
NETCONFA_MC_FORWARDING ,
NETCONFA_IFINDEX_ALL ,
net - > ipv6 . devconf_all ) ;
2008-04-03 04:22:53 +04:00
2015-11-20 15:54:20 +03:00
mroute_clean_tables ( mrt , false ) ;
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 16:40:55 +04:00
err = 0 ;
break ;
}
}
2008-04-03 04:22:53 +04:00
rtnl_unlock ( ) ;
return err ;
}
2018-03-01 00:29:30 +03:00
bool mroute6_is_socket ( struct net * net , struct sk_buff * skb )
2010-05-11 16:40:53 +04:00
{
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2011-03-13 00:22:43 +03:00
struct flowi6 fl6 = {
2014-04-28 11:51:56 +04:00
. flowi6_iif = skb - > skb_iif ? : LOOPBACK_IFINDEX ,
2011-03-13 00:22:43 +03: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 16:40:55 +04:00
} ;
2011-03-13 00:22:43 +03: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 16:40:55 +04:00
return NULL ;
2010-05-11 16:40:53 +04:00
2018-03-01 00:29:32 +03:00
return rcu_access_pointer ( mrt - > mroute_sk ) ;
2010-05-11 16:40:53 +04:00
}
2018-03-01 00:29:30 +03:00
EXPORT_SYMBOL ( mroute6_is_socket ) ;
2010-05-11 16:40:53 +04:00
2008-04-03 04:22:53 +04: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 .
*/
2009-10-01 03:12:20 +04:00
int ip6_mroute_setsockopt ( struct sock * sk , int optname , char __user * optval , unsigned int optlen )
2008-04-03 04:22:53 +04:00
{
2013-01-21 10:00:26 +04:00
int ret , parent = 0 ;
2008-04-03 04:22:53 +04:00
struct mif6ctl vif ;
struct mf6cctl mfc ;
mifi_t mifi ;
2008-12-11 03:30:15 +03:00
struct net * net = sock_net ( sk ) ;
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
2017-02-24 11:29:06 +03: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 16:40:55 +04:00
mrt = ip6mr_get_table ( net , raw6_sk ( sk ) - > ip6mr_table ? : RT6_TABLE_DFLT ) ;
2015-03-29 16:00:04 +03: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 16:40:55 +04:00
return - ENOENT ;
2008-04-03 04:22:53 +04:00
if ( optname ! = MRT6_INIT ) {
2018-03-01 00:29:32 +03:00
if ( sk ! = rcu_access_pointer ( mrt - > mroute_sk ) & &
2018-03-01 00:29:30 +03:00
! ns_capable ( net - > user_ns , CAP_NET_ADMIN ) )
2008-04-03 04:22:53 +04:00
return - EACCES ;
}
switch ( optname ) {
case MRT6_INIT :
if ( optlen < sizeof ( int ) )
return - EINVAL ;
2010-05-11 16:40:53 +04:00
return ip6mr_sk_init ( mrt , sk ) ;
2008-04-03 04:22:53 +04:00
case MRT6_DONE :
return ip6mr_sk_done ( sk ) ;
case MRT6_ADD_MIF :
if ( optlen < sizeof ( vif ) )
return - EINVAL ;
if ( copy_from_user ( & vif , optval , sizeof ( vif ) ) )
return - EFAULT ;
2008-04-10 13:40:10 +04:00
if ( vif . mif6c_mifi > = MAXMIFS )
2008-04-03 04:22:53 +04:00
return - ENFILE ;
rtnl_lock ( ) ;
2018-03-01 00:29:30 +03:00
ret = mif6_add ( net , mrt , & vif ,
2018-03-01 00:29:32 +03:00
sk = = rtnl_dereference ( mrt - > mroute_sk ) ) ;
2008-04-03 04:22:53 +04:00
rtnl_unlock ( ) ;
return ret ;
case MRT6_DEL_MIF :
if ( optlen < sizeof ( mifi_t ) )
return - EINVAL ;
if ( copy_from_user ( & mifi , optval , sizeof ( mifi_t ) ) )
return - EFAULT ;
rtnl_lock ( ) ;
2017-04-21 20:42:16 +03:00
ret = mif6_delete ( mrt , mifi , 0 , NULL ) ;
2008-04-03 04:22:53 +04: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 10:00:26 +04:00
parent = - 1 ;
2017-10-17 00:36:52 +03:00
/* fall through */
2013-01-21 10:00:26 +04:00
case MRT6_ADD_MFC_PROXY :
case MRT6_DEL_MFC_PROXY :
2008-04-03 04:22:53 +04:00
if ( optlen < sizeof ( mfc ) )
return - EINVAL ;
if ( copy_from_user ( & mfc , optval , sizeof ( mfc ) ) )
return - EFAULT ;
2013-01-21 10:00:26 +04:00
if ( parent = = 0 )
parent = mfc . mf6cc_parent ;
2008-04-03 04:22:53 +04:00
rtnl_lock ( ) ;
2013-01-21 10:00:26 +04:00
if ( optname = = MRT6_DEL_MFC | | optname = = MRT6_DEL_MFC_PROXY )
ret = ip6mr_mfc_delete ( mrt , & mfc , parent ) ;
2008-04-03 04:22:53 +04:00
else
2013-01-21 10:00:26 +04:00
ret = ip6mr_mfc_add ( net , mrt , & mfc ,
2018-03-01 00:29:30 +03:00
sk = =
2018-03-01 00:29:32 +03:00
rtnl_dereference ( mrt - > mroute_sk ) ,
2018-03-01 00:29:30 +03:00
parent ) ;
2008-04-03 04:22:53 +04:00
rtnl_unlock ( ) ;
return ret ;
2008-04-03 04:22:54 +04:00
/*
* Control PIM assert ( to activate pim will activate assert )
*/
case MRT6_ASSERT :
{
int v ;
2012-11-25 22:26:34 +04:00
if ( optlen ! = sizeof ( v ) )
return - EINVAL ;
2008-04-03 04:22:54 +04:00
if ( get_user ( v , ( int __user * ) optval ) )
return - EFAULT ;
2012-11-25 13:35:30 +04:00
mrt - > mroute_do_assert = v ;
2008-04-03 04:22:54 +04:00
return 0 ;
}
# ifdef CONFIG_IPV6_PIMSM_V2
case MRT6_PIM :
{
2008-04-10 10:41:28 +04:00
int v ;
2012-11-25 22:26:34 +04:00
if ( optlen ! = sizeof ( v ) )
return - EINVAL ;
2008-04-03 04:22:54 +04:00
if ( get_user ( v , ( int __user * ) optval ) )
return - EFAULT ;
v = ! ! v ;
rtnl_lock ( ) ;
ret = 0 ;
2010-05-11 16:40:53 +04:00
if ( v ! = mrt - > mroute_do_pim ) {
mrt - > mroute_do_pim = v ;
mrt - > mroute_do_assert = v ;
2008-04-03 04:22:54 +04: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 16:40:55 +04:00
# endif
# ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
case MRT6_TABLE :
{
u32 v ;
if ( optlen ! = sizeof ( u32 ) )
return - EINVAL ;
if ( get_user ( v , ( u32 __user * ) optval ) )
return - EFAULT ;
2013-01-24 00:38:34 +04:00
/* "pim6reg%u" should not exceed 16 bytes (IFNAMSIZ) */
if ( v ! = RT_TABLE_DEFAULT & & v > = 100000000 )
return - EINVAL ;
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
return - EBUSY ;
rtnl_lock ( ) ;
ret = 0 ;
2018-06-05 16:02:00 +03:00
mrt = ip6mr_new_table ( net , v ) ;
if ( IS_ERR ( mrt ) )
ret = PTR_ERR ( mrt ) ;
2018-06-05 16:01:59 +03: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 16:40:55 +04:00
rtnl_unlock ( ) ;
return ret ;
}
2008-04-03 04:22:54 +04:00
# endif
2008-04-03 04:22:53 +04:00
/*
2008-04-23 15:35:13 +04:00
* Spurious command , or MRT6_VERSION which you cannot
2008-04-03 04:22:53 +04: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 03:30:15 +03:00
struct net * net = sock_net ( sk ) ;
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
2017-02-24 11:29:06 +03: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 16:40:55 +04:00
mrt = ip6mr_get_table ( net , raw6_sk ( sk ) - > ip6mr_table ? : RT6_TABLE_DFLT ) ;
2015-03-29 16:00:04 +03: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 16:40:55 +04:00
return - ENOENT ;
2008-04-03 04:22:53 +04:00
switch ( optname ) {
case MRT6_VERSION :
val = 0x0305 ;
break ;
2008-04-03 04:22:54 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
case MRT6_PIM :
2010-05-11 16:40:53 +04:00
val = mrt - > mroute_do_pim ;
2008-04-03 04:22:54 +04:00
break ;
# endif
case MRT6_ASSERT :
2010-05-11 16:40:53 +04:00
val = mrt - > mroute_do_assert ;
2008-04-03 04:22:54 +04:00
break ;
2008-04-03 04:22:53 +04: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 00:29:29 +03:00
struct vif_device * vif ;
2008-04-03 04:22:53 +04:00
struct mfc6_cache * c ;
2008-12-11 03:30:15 +03:00
struct net * net = sock_net ( sk ) ;
2018-03-01 00:29:32 +03: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 16:40:55 +04:00
mrt = ip6mr_get_table ( net , raw6_sk ( sk ) - > ip6mr_table ? : RT6_TABLE_DFLT ) ;
2015-03-29 16:00:04 +03: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 16:40:55 +04:00
return - ENOENT ;
2008-04-03 04:22:53 +04:00
switch ( cmd ) {
case SIOCGETMIFCNT_IN6 :
if ( copy_from_user ( & vr , arg , sizeof ( vr ) ) )
return - EFAULT ;
2010-05-11 16:40:53 +04:00
if ( vr . mifi > = mrt - > maxvif )
2008-04-03 04:22:53 +04:00
return - EINVAL ;
2018-12-11 23:10:08 +03:00
vr . mifi = array_index_nospec ( vr . mifi , mrt - > maxvif ) ;
2008-04-03 04:22:53 +04:00
read_lock ( & mrt_lock ) ;
2018-03-01 00:29:32 +03:00
vif = & mrt - > vif_table [ vr . mifi ] ;
if ( VIF_EXISTS ( mrt , vr . mifi ) ) {
2008-04-03 04:22:53 +04:00
vr . icount = vif - > pkt_in ;
vr . ocount = vif - > pkt_out ;
vr . ibytes = vif - > bytes_in ;
vr . obytes = vif - > bytes_out ;
read_unlock ( & mrt_lock ) ;
if ( copy_to_user ( arg , & vr , sizeof ( vr ) ) )
return - EFAULT ;
return 0 ;
}
read_unlock ( & mrt_lock ) ;
return - EADDRNOTAVAIL ;
case SIOCGETSGCNT_IN6 :
if ( copy_from_user ( & sr , arg , sizeof ( sr ) ) )
return - EFAULT ;
2018-03-01 00:29:31 +03:00
rcu_read_lock ( ) ;
2010-05-11 16:40:53 +04:00
c = ip6mr_cache_find ( mrt , & sr . src . sin6_addr , & sr . grp . sin6_addr ) ;
2008-04-03 04:22:53 +04:00
if ( c ) {
2018-03-01 00:29:34 +03: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 00:29:31 +03:00
rcu_read_unlock ( ) ;
2008-04-03 04:22:53 +04:00
if ( copy_to_user ( arg , & sr , sizeof ( sr ) ) )
return - EFAULT ;
return 0 ;
}
2018-03-01 00:29:31 +03:00
rcu_read_unlock ( ) ;
2008-04-03 04:22:53 +04:00
return - EADDRNOTAVAIL ;
default :
return - ENOIOCTLCMD ;
}
}
2011-02-04 04:59:32 +03: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 00:29:29 +03:00
struct vif_device * vif ;
2011-02-04 04:59:32 +03:00
struct mfc6_cache * c ;
struct net * net = sock_net ( sk ) ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2011-02-04 04:59:32 +03:00
mrt = ip6mr_get_table ( net , raw6_sk ( sk ) - > ip6mr_table ? : RT6_TABLE_DFLT ) ;
2015-03-29 16:00:04 +03:00
if ( ! mrt )
2011-02-04 04:59:32 +03: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-11 23:10:08 +03:00
vr . mifi = array_index_nospec ( vr . mifi , mrt - > maxvif ) ;
2011-02-04 04:59:32 +03:00
read_lock ( & mrt_lock ) ;
2018-03-01 00:29:32 +03:00
vif = & mrt - > vif_table [ vr . mifi ] ;
if ( VIF_EXISTS ( mrt , vr . mifi ) ) {
2011-02-04 04:59:32 +03:00
vr . icount = vif - > pkt_in ;
vr . ocount = vif - > pkt_out ;
vr . ibytes = vif - > bytes_in ;
vr . obytes = vif - > bytes_out ;
read_unlock ( & mrt_lock ) ;
if ( copy_to_user ( arg , & vr , sizeof ( vr ) ) )
return - EFAULT ;
return 0 ;
}
read_unlock ( & mrt_lock ) ;
return - EADDRNOTAVAIL ;
case SIOCGETSGCNT_IN6 :
if ( copy_from_user ( & sr , arg , sizeof ( sr ) ) )
return - EFAULT ;
2018-03-01 00:29:31 +03:00
rcu_read_lock ( ) ;
2011-02-04 04:59:32 +03:00
c = ip6mr_cache_find ( mrt , & sr . src . sin6_addr , & sr . grp . sin6_addr ) ;
if ( c ) {
2018-03-01 00:29:34 +03: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 00:29:31 +03:00
rcu_read_unlock ( ) ;
2011-02-04 04:59:32 +03:00
if ( copy_to_user ( arg , & sr , sizeof ( sr ) ) )
return - EFAULT ;
return 0 ;
}
2018-03-01 00:29:31 +03:00
rcu_read_unlock ( ) ;
2011-02-04 04:59:32 +03:00
return - EADDRNOTAVAIL ;
default :
return - ENOIOCTLCMD ;
}
}
# endif
2008-04-03 04:22:53 +04:00
2015-09-16 04:04:18 +03:00
static inline int ip6mr_forward2_finish ( struct net * net , struct sock * sk , struct sk_buff * skb )
2008-04-03 04:22:53 +04:00
{
2016-04-28 02:44:40 +03: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 00:48:35 +03:00
return dst_output ( net , sk , skb ) ;
2008-04-03 04:22:53 +04:00
}
/*
* Processing handlers for ip6mr_forward
*/
2018-03-01 00:29:32 +03:00
static int ip6mr_forward2 ( struct net * net , struct mr_table * mrt ,
2010-05-11 16:40:53 +04:00
struct sk_buff * skb , struct mfc6_cache * c , int vifi )
2008-04-03 04:22:53 +04:00
{
struct ipv6hdr * ipv6h ;
2018-03-01 00:29:32 +03:00
struct vif_device * vif = & mrt - > vif_table [ vifi ] ;
2008-04-03 04:22:53 +04:00
struct net_device * dev ;
struct dst_entry * dst ;
2011-03-13 00:22:43 +03:00
struct flowi6 fl6 ;
2008-04-03 04:22:53 +04:00
2015-03-29 16:00:04 +03:00
if ( ! vif - > dev )
2008-04-03 04:22:53 +04:00
goto out_free ;
2008-04-03 04:22:54 +04:00
# ifdef CONFIG_IPV6_PIMSM_V2
if ( vif - > flags & MIFF_REGISTER ) {
vif - > pkt_out + + ;
vif - > bytes_out + = skb - > len ;
2008-05-22 01:17:54 +04:00
vif - > dev - > stats . tx_bytes + = skb - > len ;
vif - > dev - > stats . tx_packets + + ;
2010-05-11 16:40:53 +04:00
ip6mr_cache_report ( mrt , skb , vifi , MRT6MSG_WHOLEPKT ) ;
2008-12-15 10:15:49 +03:00
goto out_free ;
2008-04-03 04:22:54 +04:00
}
# endif
2008-04-03 04:22:53 +04:00
ipv6h = ipv6_hdr ( skb ) ;
2011-03-13 00:22:43 +03:00
fl6 = ( struct flowi6 ) {
. flowi6_oif = vif - > link ,
. daddr = ipv6h - > daddr ,
2008-04-03 04:22:53 +04:00
} ;
2011-03-13 00:22:43 +03:00
dst = ip6_route_output ( net , NULL , & fl6 ) ;
2012-02-22 02:10:49 +04:00
if ( dst - > error ) {
dst_release ( dst ) ;
2008-04-03 04:22:53 +04:00
goto out_free ;
2012-02-22 02:10:49 +04:00
}
2008-04-03 04:22:53 +04:00
2009-06-02 09:19:30 +04:00
skb_dst_drop ( skb ) ;
skb_dst_set ( skb , dst ) ;
2008-04-03 04:22:53 +04: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 .
*/
dev = vif - > dev ;
skb - > dev = dev ;
vif - > pkt_out + + ;
vif - > bytes_out + = skb - > len ;
/* We are about to write */
/* XXX: extension headers? */
if ( skb_cow ( skb , sizeof ( * ipv6h ) + LL_RESERVED_SPACE ( dev ) ) )
goto out_free ;
ipv6h = ipv6_hdr ( skb ) ;
ipv6h - > hop_limit - - ;
IP6CB ( skb ) - > flags | = IP6SKB_FORWARDED ;
2015-09-16 04:04:16 +03:00
return NF_HOOK ( NFPROTO_IPV6 , NF_INET_FORWARD ,
net , NULL , skb , skb - > dev , dev ,
2008-04-03 04:22:53 +04:00
ip6mr_forward2_finish ) ;
out_free :
kfree_skb ( skb ) ;
return 0 ;
}
2018-03-01 00:29:32 +03:00
static int ip6mr_find_vif ( struct mr_table * mrt , struct net_device * dev )
2008-04-03 04:22:53 +04:00
{
int ct ;
2010-05-11 16:40:53 +04:00
for ( ct = mrt - > maxvif - 1 ; ct > = 0 ; ct - - ) {
2018-03-01 00:29:32 +03:00
if ( mrt - > vif_table [ ct ] . dev = = dev )
2008-04-03 04:22:53 +04:00
break ;
}
return ct ;
}
2018-03-01 00:29:32 +03:00
static void ip6_mr_forward ( struct net * net , struct mr_table * mrt ,
2018-10-01 11:41:27 +03:00
struct net_device * dev , struct sk_buff * skb ,
struct mfc6_cache * c )
2008-04-03 04:22:53 +04:00
{
int psend = - 1 ;
int vif , ct ;
2018-10-01 11:41:27 +03:00
int true_vifi = ip6mr_find_vif ( mrt , dev ) ;
2008-04-03 04:22:53 +04:00
2018-03-01 00:29:34 +03: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 04:22:53 +04:00
2018-03-01 00:29:34 +03:00
if ( ipv6_addr_any ( & c - > mf6c_origin ) & & true_vifi > = 0 ) {
2013-01-21 10:00:26 +04:00
struct mfc6_cache * cache_proxy ;
2014-10-29 12:00:26 +03:00
/* For an (*,G) entry, we only check that the incoming
2013-01-21 10:00:26 +04:00
* interface is part of the static tree .
*/
2018-03-01 00:29:31 +03:00
rcu_read_lock ( ) ;
2018-03-01 00:29:35 +03:00
cache_proxy = mr_mfc_find_any_parent ( mrt , vif ) ;
2013-01-21 10:00:26 +04:00
if ( cache_proxy & &
2018-03-01 00:29:34 +03:00
cache_proxy - > _c . mfc_un . res . ttls [ true_vifi ] < 255 ) {
2018-03-01 00:29:31 +03:00
rcu_read_unlock ( ) ;
2013-01-21 10:00:26 +04:00
goto forward ;
2018-03-01 00:29:31 +03:00
}
rcu_read_unlock ( ) ;
2013-01-21 10:00:26 +04:00
}
2008-04-03 04:22:54 +04:00
/*
* Wrong interface : drop packet and ( maybe ) send PIM assert .
*/
2018-10-01 11:41:27 +03:00
if ( mrt - > vif_table [ vif ] . dev ! = dev ) {
2018-03-01 00:29:34 +03:00
c - > _c . mfc_un . res . wrong_if + + ;
2008-04-03 04:22:54 +04:00
2010-05-11 16:40:53 +04:00
if ( true_vifi > = 0 & & mrt - > mroute_do_assert & &
2008-04-03 04:22:54 +04: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 16:40:53 +04:00
( mrt - > mroute_do_pim | |
2018-03-01 00:29:34 +03:00
c - > _c . mfc_un . res . ttls [ true_vifi ] < 255 ) & &
2008-04-03 04:22:54 +04:00
time_after ( jiffies ,
2018-03-01 00:29:34 +03:00
c - > _c . mfc_un . res . last_assert +
MFC_ASSERT_THRESH ) ) {
c - > _c . mfc_un . res . last_assert = jiffies ;
2010-05-11 16:40:53 +04:00
ip6mr_cache_report ( mrt , skb , true_vifi , MRT6MSG_WRONGMIF ) ;
2008-04-03 04:22:54 +04:00
}
goto dont_forward ;
}
2013-01-21 10:00:26 +04:00
forward :
2018-03-01 00:29:32 +03:00
mrt - > vif_table [ vif ] . pkt_in + + ;
mrt - > vif_table [ vif ] . bytes_in + = skb - > len ;
2008-04-03 04:22:53 +04:00
/*
* Forward the frame
*/
2018-03-01 00:29:34 +03:00
if ( ipv6_addr_any ( & c - > mf6c_origin ) & &
ipv6_addr_any ( & c - > mf6c_mcastgrp ) ) {
2013-01-21 10:00:26 +04:00
if ( true_vifi > = 0 & &
2018-03-01 00:29:34 +03:00
true_vifi ! = c - > _c . mfc_parent & &
2013-01-21 10:00:26 +04:00
ipv6_hdr ( skb ) - > hop_limit >
2018-03-01 00:29:34 +03:00
c - > _c . mfc_un . res . ttls [ c - > _c . mfc_parent ] ) {
2013-01-21 10:00:26 +04:00
/* It's an (*,*) entry and the packet is not coming from
* the upstream : forward the packet to the upstream
* only .
*/
2018-03-01 00:29:34 +03:00
psend = c - > _c . mfc_parent ;
2013-01-21 10:00:26 +04:00
goto last_forward ;
}
goto dont_forward ;
}
2018-03-01 00:29:34 +03:00
for ( ct = c - > _c . mfc_un . res . maxvif - 1 ;
ct > = c - > _c . mfc_un . res . minvif ; ct - - ) {
2013-01-21 10:00:26 +04:00
/* For (*,G) entry, don't forward to the incoming interface */
2018-03-01 00:29:34 +03: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 04:22:53 +04:00
if ( psend ! = - 1 ) {
struct sk_buff * skb2 = skb_clone ( skb , GFP_ATOMIC ) ;
if ( skb2 )
2018-03-01 00:29:34 +03:00
ip6mr_forward2 ( net , mrt , skb2 ,
c , psend ) ;
2008-04-03 04:22:53 +04:00
}
psend = ct ;
}
}
2013-01-21 10:00:26 +04:00
last_forward :
2008-04-03 04:22:53 +04:00
if ( psend ! = - 1 ) {
2018-03-01 00:29:34 +03:00
ip6mr_forward2 ( net , mrt , skb , c , psend ) ;
2013-07-21 04:00:31 +04:00
return ;
2008-04-03 04:22:53 +04:00
}
2008-04-03 04:22:54 +04:00
dont_forward :
2008-04-03 04:22:53 +04: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 03:30:15 +03:00
struct net * net = dev_net ( skb - > dev ) ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2011-03-13 00:22:43 +03: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 16:40:55 +04:00
} ;
int err ;
2018-10-01 11:41:27 +03: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 16:40:55 +04:00
2011-03-13 00:22:43 +03:00
err = ip6mr_fib_lookup ( net , & fl6 , & mrt ) ;
2011-09-27 23:16:08 +04: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 16:40:55 +04:00
return err ;
2011-09-27 23:16:08 +04:00
}
2008-04-03 04:22:53 +04:00
read_lock ( & mrt_lock ) ;
2010-05-11 16:40:53 +04:00
cache = ip6mr_cache_find ( mrt ,
2008-12-11 03:30:15 +03:00
& ipv6_hdr ( skb ) - > saddr , & ipv6_hdr ( skb ) - > daddr ) ;
2015-03-29 16:00:04 +03:00
if ( ! cache ) {
2018-10-01 11:41:27 +03:00
int vif = ip6mr_find_vif ( mrt , dev ) ;
2013-01-21 10:00:26 +04:00
if ( vif > = 0 )
cache = ip6mr_cache_find_any ( mrt ,
& ipv6_hdr ( skb ) - > daddr ,
vif ) ;
}
2008-04-03 04:22:53 +04:00
/*
* No usable cache entry
*/
2015-03-29 16:00:04 +03:00
if ( ! cache ) {
2008-04-03 04:22:53 +04:00
int vif ;
2018-10-01 11:41:27 +03:00
vif = ip6mr_find_vif ( mrt , dev ) ;
2008-04-03 04:22:53 +04:00
if ( vif > = 0 ) {
2018-10-01 11:41:27 +03:00
int err = ip6mr_cache_unresolved ( mrt , vif , skb , dev ) ;
2008-04-03 04:22:53 +04:00
read_unlock ( & mrt_lock ) ;
return err ;
}
read_unlock ( & mrt_lock ) ;
kfree_skb ( skb ) ;
return - ENODEV ;
}
2018-10-01 11:41:27 +03:00
ip6_mr_forward ( net , mrt , dev , skb , cache ) ;
2008-04-03 04:22:53 +04:00
read_unlock ( & mrt_lock ) ;
return 0 ;
}
2016-09-26 00:08:31 +03:00
int ip6mr_get_route ( struct net * net , struct sk_buff * skb , struct rtmsg * rtm ,
2017-01-18 02:51:07 +03:00
u32 portid )
2008-04-03 04:22:53 +04:00
{
int err ;
2018-03-01 00:29:32 +03:00
struct mr_table * mrt ;
2008-04-03 04:22:53 +04:00
struct mfc6_cache * cache ;
2009-06-02 09:19:30 +04:00
struct rt6_info * rt = ( struct rt6_info * ) skb_dst ( skb ) ;
2008-04-03 04:22:53 +04: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 16:40:55 +04:00
mrt = ip6mr_get_table ( net , RT6_TABLE_DFLT ) ;
2015-03-29 16:00:04 +03: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 16:40:55 +04:00
return - ENOENT ;
2008-04-03 04:22:53 +04:00
read_lock ( & mrt_lock ) ;
2010-05-11 16:40:53 +04:00
cache = ip6mr_cache_find ( mrt , & rt - > rt6i_src . addr , & rt - > rt6i_dst . addr ) ;
2013-01-21 10:00:26 +04: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 04:22:53 +04:00
if ( ! cache ) {
struct sk_buff * skb2 ;
struct ipv6hdr * iph ;
struct net_device * dev ;
int vif ;
dev = skb - > dev ;
2015-03-29 16:00:04 +03:00
if ( ! dev | | ( vif = ip6mr_find_vif ( mrt , dev ) ) < 0 ) {
2008-04-03 04:22:53 +04:00
read_unlock ( & mrt_lock ) ;
return - ENODEV ;
}
/* really correct? */
skb2 = alloc_skb ( sizeof ( struct ipv6hdr ) , GFP_ATOMIC ) ;
if ( ! skb2 ) {
read_unlock ( & mrt_lock ) ;
return - ENOMEM ;
}
2016-09-26 00:08:31 +03:00
NETLINK_CB ( skb2 ) . portid = portid ;
2008-04-03 04:22:53 +04: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 07:39:03 +04:00
iph - > saddr = rt - > rt6i_src . addr ;
iph - > daddr = rt - > rt6i_dst . addr ;
2008-04-03 04:22:53 +04:00
2018-10-01 11:41:27 +03:00
err = ip6mr_cache_unresolved ( mrt , vif , skb2 , dev ) ;
2008-04-03 04:22:53 +04:00
read_unlock ( & mrt_lock ) ;
return err ;
}
2018-03-01 00:29:39 +03:00
err = mr_fill_mroute ( mrt , skb , & cache - > _c , rtm ) ;
2008-04-03 04:22:53 +04:00
read_unlock ( & mrt_lock ) ;
return err ;
}
2018-03-01 00:29:32 +03:00
static int ip6mr_fill_mroute ( struct mr_table * mrt , struct sk_buff * skb ,
2014-03-19 20:47:51 +04:00
u32 portid , u32 seq , struct mfc6_cache * c , int cmd ,
int flags )
2010-05-11 16:40:56 +04:00
{
struct nlmsghdr * nlh ;
struct rtmsg * rtm ;
2012-12-04 05:13:39 +04:00
int err ;
2010-05-11 16:40:56 +04:00
2014-03-19 20:47:51 +04:00
nlh = nlmsg_put ( skb , portid , seq , cmd , sizeof ( * rtm ) , flags ) ;
2015-03-29 16:00:04 +03:00
if ( ! nlh )
2010-05-11 16:40:56 +04:00
return - EMSGSIZE ;
rtm = nlmsg_data ( nlh ) ;
2012-12-04 05:01:49 +04:00
rtm - > rtm_family = RTNL_FAMILY_IP6MR ;
2010-05-11 16:40:56 +04:00
rtm - > rtm_dst_len = 128 ;
rtm - > rtm_src_len = 128 ;
rtm - > rtm_tos = 0 ;
rtm - > rtm_table = mrt - > id ;
2012-04-02 04:27:33 +04:00
if ( nla_put_u32 ( skb , RTA_TABLE , mrt - > id ) )
goto nla_put_failure ;
2012-12-04 05:13:39 +04:00
rtm - > rtm_type = RTN_MULTICAST ;
2010-05-11 16:40:56 +04:00
rtm - > rtm_scope = RT_SCOPE_UNIVERSE ;
2018-03-01 00:29:34 +03:00
if ( c - > _c . mfc_flags & MFC_STATIC )
2012-12-04 05:13:38 +04:00
rtm - > rtm_protocol = RTPROT_STATIC ;
else
rtm - > rtm_protocol = RTPROT_MROUTED ;
2010-05-11 16:40:56 +04:00
rtm - > rtm_flags = 0 ;
2015-03-29 17:59:25 +03: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 04:27:33 +04:00
goto nla_put_failure ;
2018-03-01 00:29:39 +03:00
err = mr_fill_mroute ( mrt , skb , & c - > _c , rtm ) ;
2012-12-04 05:13:39 +04:00
/* do not break the dump if cache is unresolved */
if ( err < 0 & & err ! = - ENOENT )
2010-05-11 16:40:56 +04:00
goto nla_put_failure ;
2015-01-17 00:09:00 +03:00
nlmsg_end ( skb , nlh ) ;
return 0 ;
2010-05-11 16:40:56 +04:00
nla_put_failure :
nlmsg_cancel ( skb , nlh ) ;
return - EMSGSIZE ;
}
2018-03-01 00:29:39 +03: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 05:13:41 +04: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-21 19:58:27 +03:00
+ nla_total_size_64bit ( sizeof ( struct rta_mfc_stats ) )
2012-12-04 05:13:41 +04:00
;
return len ;
}
2018-03-01 00:29:32 +03:00
static void mr6_netlink_event ( struct mr_table * mrt , struct mfc6_cache * mfc ,
2012-12-04 05:13:41 +04:00
int cmd )
{
struct net * net = read_pnet ( & mrt - > net ) ;
struct sk_buff * skb ;
int err = - ENOBUFS ;
2018-03-01 00:29:34 +03:00
skb = nlmsg_new ( mr6_msgsize ( mfc - > _c . mfc_parent > = MAXMIFS , mrt - > maxvif ) ,
2012-12-04 05:13:41 +04:00
GFP_ATOMIC ) ;
2015-03-29 16:00:04 +03:00
if ( ! skb )
2012-12-04 05:13:41 +04:00
goto errout ;
2014-03-19 20:47:51 +04:00
err = ip6mr_fill_mroute ( mrt , skb , 0 , 0 , mfc , cmd , 0 ) ;
2012-12-04 05:13:41 +04: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-20 23:54:18 +03: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 ;
}
2018-03-01 00:29:32 +03:00
static void mrt6msg_netlink_event ( struct mr_table * mrt , struct sk_buff * pkt )
2017-06-20 23:54:18 +03: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 16:40:56 +04:00
static int ip6mr_rtm_dumproute ( struct sk_buff * skb , struct netlink_callback * cb )
{
2018-10-08 06:16:35 +03:00
const struct nlmsghdr * nlh = cb - > nlh ;
2018-10-16 04:56:42 +03:00
struct fib_dump_filter filter = { } ;
2018-10-16 04:56:47 +03:00
int err ;
2018-10-08 06:16:35 +03:00
if ( cb - > strict_check ) {
2018-10-16 04:56:42 +03:00
err = ip_valid_fib_dump_req ( sock_net ( skb - > sk ) , nlh ,
2018-10-16 04:56:48 +03:00
& filter , cb ) ;
2018-10-08 06:16:35 +03:00
if ( err < 0 )
return err ;
}
2018-10-16 04:56:47 +03:00
if ( filter . table_id ) {
struct mr_table * mrt ;
mrt = ip6mr_get_table ( sock_net ( skb - > sk ) , filter . table_id ) ;
if ( ! mrt ) {
2018-10-24 22:59:01 +03:00
if ( filter . dump_all_families )
return skb - > len ;
2018-10-16 04:56:47 +03: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 00:29:39 +03:00
return mr_rtm_dumproute ( skb , cb , ip6mr_mr_table_iter ,
2018-10-16 04:56:47 +03:00
_ip6mr_fill_mroute , & mfc_unres_lock , & filter ) ;
2010-05-11 16:40:56 +04:00
}