* [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support
@ 2015-11-26 14:23 Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 1/7] net: remove unnecessary mroute.h includes Nikolay Aleksandrov
` (8 more replies)
0 siblings, 9 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev; +Cc: davem, Nikolay Aleksandrov
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Hi,
This set continues with the minor cleanups in the first 6 patches and
patch 7 adds the first new feature - MFC manipulation via netlink. It
registers NEWROUTE/DELROUTE for that purpose and uses the same semantics
as the already present netlink dump. The only new attribute that is used
is RTA_PREFSRC to denote an MFC_PROXY entry. Currently the table must
exist before adding an entry, and new tables can be created only via
setsockopt, but that will be changed in the future.
This set was tested with modified iproute2 which supports NEWROUTE/DELROUTE
for RTNL_FAMILY_IPMR.
Cheers,
Nik
Nikolay Aleksandrov (7):
net: remove unnecessary mroute.h includes
net: ipmr: remove unused MFC_NOTIFY flag and make the flags enum
net: ipmr: adjust mroute.h style and drop extern
net: ipmr: move struct mr_table and VIF_EXISTS to mroute.h
net: ipmr: move pimsm_enabled to pim.h and rename
net: ipmr: fix setsockopt error return
net: ipmr: add mfc newroute/delroute netlink support
include/linux/mroute.h | 76 ++++++++++++---------
include/linux/pim.h | 5 ++
net/ipv4/ip_gre.c | 1 -
net/ipv4/ip_output.c | 1 -
net/ipv4/ip_tunnel.c | 1 -
net/ipv4/ip_tunnel_core.c | 1 -
net/ipv4/ip_vti.c | 1 -
net/ipv4/ipip.c | 1 -
net/ipv4/ipmr.c | 168 +++++++++++++++++++++++++++++++++++++---------
net/ipv6/ip6_gre.c | 1 -
10 files changed, 188 insertions(+), 68 deletions(-)
--
2.4.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net-next 1/7] net: remove unnecessary mroute.h includes
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
@ 2015-11-26 14:23 ` Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 2/7] net: ipmr: remove unused MFC_NOTIFY flag and make the flags enum Nikolay Aleksandrov
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev
Cc: davem, Nikolay Aleksandrov, Hideaki YOSHIFUJI, Steffen Klassert,
Herbert Xu
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
It looks like many files are including mroute.h unnecessarily, so remove
the include. Most importantly remove it from ipv6.
CC: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
CC: Steffen Klassert <steffen.klassert@secunet.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
net/ipv4/ip_gre.c | 1 -
net/ipv4/ip_output.c | 1 -
net/ipv4/ip_tunnel.c | 1 -
net/ipv4/ip_tunnel_core.c | 1 -
net/ipv4/ip_vti.c | 1 -
net/ipv4/ipip.c | 1 -
net/ipv6/ip6_gre.c | 1 -
7 files changed, 7 deletions(-)
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 614521437e30..04a48c0159cc 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -24,7 +24,6 @@
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/if_arp.h>
-#include <linux/mroute.h>
#include <linux/if_vlan.h>
#include <linux/init.h>
#include <linux/in6.h>
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 4233cbe47052..e0b94cd843d7 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -76,7 +76,6 @@
#include <linux/igmp.h>
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter_bridge.h>
-#include <linux/mroute.h>
#include <linux/netlink.h>
#include <linux/tcp.h>
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index cbb51f3fac06..0f6e9ee031c4 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -30,7 +30,6 @@
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/if_arp.h>
-#include <linux/mroute.h>
#include <linux/init.h>
#include <linux/in6.h>
#include <linux/inetdevice.h>
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 6cb9009c3d96..1db8418aa62e 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -24,7 +24,6 @@
#include <linux/netdevice.h>
#include <linux/in.h>
#include <linux/if_arp.h>
-#include <linux/mroute.h>
#include <linux/init.h>
#include <linux/in6.h>
#include <linux/inetdevice.h>
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index 4d8f0b698777..02d9c21e2953 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -30,7 +30,6 @@
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/if_arp.h>
-#include <linux/mroute.h>
#include <linux/init.h>
#include <linux/netfilter_ipv4.h>
#include <linux/if_ether.h>
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index f34c31defafe..1f067294cbc5 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -103,7 +103,6 @@
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/if_arp.h>
-#include <linux/mroute.h>
#include <linux/init.h>
#include <linux/netfilter_ipv4.h>
#include <linux/if_ether.h>
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 3c7b9310b33f..938d03ce5e4b 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -24,7 +24,6 @@
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/if_arp.h>
-#include <linux/mroute.h>
#include <linux/init.h>
#include <linux/in6.h>
#include <linux/inetdevice.h>
--
2.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 2/7] net: ipmr: remove unused MFC_NOTIFY flag and make the flags enum
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 1/7] net: remove unnecessary mroute.h includes Nikolay Aleksandrov
@ 2015-11-26 14:23 ` Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 3/7] net: ipmr: adjust mroute.h style and drop extern Nikolay Aleksandrov
` (6 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev; +Cc: davem, Nikolay Aleksandrov
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
MFC_NOTIFY was introduced in kernel 2.1.68 but afaik it hasn't been used
and I couldn't find any users currently so just remove it. Only
MFC_STATIC is left, so move it into an enum, add a description and use
BIT().
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
include/linux/mroute.h | 10 +++++++---
net/ipv4/ipmr.c | 2 --
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/include/linux/mroute.h b/include/linux/mroute.h
index 79aaa9fc1a15..fa66ebc1fed6 100644
--- a/include/linux/mroute.h
+++ b/include/linux/mroute.h
@@ -64,6 +64,13 @@ struct vif_device {
#define VIFF_STATIC 0x8000
+/* mfc_flags:
+ * MFC_STATIC - the entry was added statically (not by a routing daemon)
+ */
+enum {
+ MFC_STATIC = BIT(0),
+};
+
struct mfc_cache {
struct list_head list;
__be32 mfc_mcastgrp; /* Group the entry belongs to */
@@ -89,9 +96,6 @@ struct mfc_cache {
struct rcu_head rcu;
};
-#define MFC_STATIC 1
-#define MFC_NOTIFY 2
-
#define MFC_LINES 64
#ifdef __BIG_ENDIAN
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index a2d248d9c35c..a74e61883b8f 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -2199,8 +2199,6 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb,
}
read_lock(&mrt_lock);
- if (!nowait && (rtm->rtm_flags & RTM_F_NOTIFY))
- cache->mfc_flags |= MFC_NOTIFY;
err = __ipmr_fill_mroute(mrt, skb, cache, rtm);
read_unlock(&mrt_lock);
rcu_read_unlock();
--
2.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 3/7] net: ipmr: adjust mroute.h style and drop extern
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 1/7] net: remove unnecessary mroute.h includes Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 2/7] net: ipmr: remove unused MFC_NOTIFY flag and make the flags enum Nikolay Aleksandrov
@ 2015-11-26 14:23 ` Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 4/7] net: ipmr: move struct mr_table and VIF_EXISTS to mroute.h Nikolay Aleksandrov
` (5 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev; +Cc: davem, Nikolay Aleksandrov
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Remove extra spaces and tabs, adjust function definitions, remove an
unnecessary ifdef (already used below, just move code) and drop extern
from the functions.
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
include/linux/mroute.h | 47 +++++++++++++++++++++--------------------------
1 file changed, 21 insertions(+), 26 deletions(-)
diff --git a/include/linux/mroute.h b/include/linux/mroute.h
index fa66ebc1fed6..7c567a2679ce 100644
--- a/include/linux/mroute.h
+++ b/include/linux/mroute.h
@@ -9,38 +9,28 @@
#ifdef CONFIG_IP_MROUTE
static inline int ip_mroute_opt(int opt)
{
- return (opt >= MRT_BASE) && (opt <= MRT_MAX);
+ return opt >= MRT_BASE && opt <= MRT_MAX;
}
-#else
-static inline int ip_mroute_opt(int opt)
-{
- return 0;
-}
-#endif
-#ifdef CONFIG_IP_MROUTE
-extern int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
-extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
-extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
-extern int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
-extern int ip_mr_init(void);
+int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
+int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
+int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
+int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
+int ip_mr_init(void);
#else
-static inline
-int ip_mroute_setsockopt(struct sock *sock,
- int optname, char __user *optval, unsigned int optlen)
+static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
+ char __user *optval, unsigned int optlen)
{
return -ENOPROTOOPT;
}
-static inline
-int ip_mroute_getsockopt(struct sock *sock,
- int optname, char __user *optval, int __user *optlen)
+static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
+ char __user *optval, int __user *optlen)
{
return -ENOPROTOOPT;
}
-static inline
-int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
+static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
{
return -ENOIOCTLCMD;
}
@@ -49,6 +39,11 @@ static inline int ip_mr_init(void)
{
return 0;
}
+
+static inline int ip_mroute_opt(int opt)
+{
+ return 0;
+}
#endif
struct vif_device {
@@ -96,16 +91,16 @@ struct mfc_cache {
struct rcu_head rcu;
};
-#define MFC_LINES 64
+#define MFC_LINES 64
#ifdef __BIG_ENDIAN
#define MFC_HASH(a,b) (((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1))
#else
#define MFC_HASH(a,b) ((((__force u32)(__be32)a)^(((__force u32)(__be32)b)>>2))&(MFC_LINES-1))
-#endif
+#endif
struct rtmsg;
-extern int ipmr_get_route(struct net *net, struct sk_buff *skb,
- __be32 saddr, __be32 daddr,
- struct rtmsg *rtm, int nowait);
+int ipmr_get_route(struct net *net, struct sk_buff *skb,
+ __be32 saddr, __be32 daddr,
+ struct rtmsg *rtm, int nowait);
#endif
--
2.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 4/7] net: ipmr: move struct mr_table and VIF_EXISTS to mroute.h
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
` (2 preceding siblings ...)
2015-11-26 14:23 ` [PATCH net-next 3/7] net: ipmr: adjust mroute.h style and drop extern Nikolay Aleksandrov
@ 2015-11-26 14:23 ` Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 5/7] net: ipmr: move pimsm_enabled to pim.h and rename Nikolay Aleksandrov
` (4 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev; +Cc: davem, Nikolay Aleksandrov
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Move the definitions of VIF_EXISTS() and struct mr_table to mroute.h
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
include/linux/mroute.h | 21 +++++++++++++++++++--
net/ipv4/ipmr.c | 18 ------------------
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/include/linux/mroute.h b/include/linux/mroute.h
index 7c567a2679ce..bf9b322cb0b0 100644
--- a/include/linux/mroute.h
+++ b/include/linux/mroute.h
@@ -59,6 +59,25 @@ struct vif_device {
#define VIFF_STATIC 0x8000
+#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
+#define MFC_LINES 64
+
+struct mr_table {
+ struct list_head list;
+ possible_net_t net;
+ u32 id;
+ struct sock __rcu *mroute_sk;
+ struct timer_list ipmr_expire_timer;
+ struct list_head mfc_unres_queue;
+ struct list_head mfc_cache_array[MFC_LINES];
+ struct vif_device vif_table[MAXVIFS];
+ int maxvif;
+ atomic_t cache_resolve_queue_len;
+ bool mroute_do_assert;
+ bool mroute_do_pim;
+ int mroute_reg_vif_num;
+};
+
/* mfc_flags:
* MFC_STATIC - the entry was added statically (not by a routing daemon)
*/
@@ -91,8 +110,6 @@ struct mfc_cache {
struct rcu_head rcu;
};
-#define MFC_LINES 64
-
#ifdef __BIG_ENDIAN
#define MFC_HASH(a,b) (((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1))
#else
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index a74e61883b8f..ff3dbbb9f11c 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -67,22 +67,6 @@
#include <net/fib_rules.h>
#include <linux/netconf.h>
-struct mr_table {
- struct list_head list;
- possible_net_t net;
- u32 id;
- struct sock __rcu *mroute_sk;
- struct timer_list ipmr_expire_timer;
- struct list_head mfc_unres_queue;
- struct list_head mfc_cache_array[MFC_LINES];
- struct vif_device vif_table[MAXVIFS];
- int maxvif;
- atomic_t cache_resolve_queue_len;
- bool mroute_do_assert;
- bool mroute_do_pim;
- int mroute_reg_vif_num;
-};
-
struct ipmr_rule {
struct fib_rule common;
};
@@ -104,8 +88,6 @@ static DEFINE_RWLOCK(mrt_lock);
/* Multicast router control variables */
-#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
-
/* Special spinlock for queue of unresolved entries */
static DEFINE_SPINLOCK(mfc_unres_lock);
--
2.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 5/7] net: ipmr: move pimsm_enabled to pim.h and rename
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
` (3 preceding siblings ...)
2015-11-26 14:23 ` [PATCH net-next 4/7] net: ipmr: move struct mr_table and VIF_EXISTS to mroute.h Nikolay Aleksandrov
@ 2015-11-26 14:23 ` Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 6/7] net: ipmr: fix setsockopt error return Nikolay Aleksandrov
` (3 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev; +Cc: davem, Nikolay Aleksandrov
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Move the inline pimsm_enabled() to pim.h and rename it to
ipmr_pimsm_enabled to show it's for the ipv4 ipmr code since pim.h is
used by IPv6 too.
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
include/linux/pim.h | 5 +++++
net/ipv4/ipmr.c | 11 +++--------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/linux/pim.h b/include/linux/pim.h
index 252bf6644c51..e1d756f81348 100644
--- a/include/linux/pim.h
+++ b/include/linux/pim.h
@@ -13,6 +13,11 @@
#define PIM_NULL_REGISTER cpu_to_be32(0x40000000)
+static inline bool ipmr_pimsm_enabled(void)
+{
+ return IS_BUILTIN(CONFIG_IP_PIMSM_V1) || IS_BUILTIN(CONFIG_IP_PIMSM_V2);
+}
+
/* PIMv2 register message header layout (ietf-draft-idmr-pimvsm-v2-00.ps */
struct pimreghdr
{
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index ff3dbbb9f11c..322fdc6ac75b 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -75,11 +75,6 @@ struct ipmr_result {
struct mr_table *mrt;
};
-static inline bool pimsm_enabled(void)
-{
- return IS_BUILTIN(CONFIG_IP_PIMSM_V1) || IS_BUILTIN(CONFIG_IP_PIMSM_V2);
-}
-
/* Big lock, protecting vif table, mrt cache and mroute socket state.
* Note that the changes are semaphored via rtnl_lock.
*/
@@ -751,7 +746,7 @@ static int vif_add(struct net *net, struct mr_table *mrt,
switch (vifc->vifc_flags) {
case VIFF_REGISTER:
- if (!pimsm_enabled())
+ if (!ipmr_pimsm_enabled())
return -EINVAL;
/* Special Purpose VIF in PIM
* All the packets will be sent to the daemon
@@ -1377,7 +1372,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
mrt->mroute_do_assert = val;
break;
case MRT_PIM:
- if (!pimsm_enabled()) {
+ if (!ipmr_pimsm_enabled()) {
ret = -ENOPROTOOPT;
break;
}
@@ -1451,7 +1446,7 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int
val = 0x0305;
break;
case MRT_PIM:
- if (!pimsm_enabled())
+ if (!ipmr_pimsm_enabled())
return -ENOPROTOOPT;
val = mrt->mroute_do_pim;
break;
--
2.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 6/7] net: ipmr: fix setsockopt error return
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
` (4 preceding siblings ...)
2015-11-26 14:23 ` [PATCH net-next 5/7] net: ipmr: move pimsm_enabled to pim.h and rename Nikolay Aleksandrov
@ 2015-11-26 14:23 ` Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 7/7] net: ipmr: add mfc newroute/delroute netlink support Nikolay Aleksandrov
` (2 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev; +Cc: davem, Nikolay Aleksandrov
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
We can have both errors and we'll return the second one, fix it to
return an error at a time as it's normal. I've overlooked this in my
previous set.
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
net/ipv4/ipmr.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 322fdc6ac75b..6c24a16299c7 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1284,12 +1284,14 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
switch (optname) {
case MRT_INIT:
- if (optlen != sizeof(int))
+ if (optlen != sizeof(int)) {
ret = -EINVAL;
- if (rtnl_dereference(mrt->mroute_sk))
+ break;
+ }
+ if (rtnl_dereference(mrt->mroute_sk)) {
ret = -EADDRINUSE;
- if (ret)
break;
+ }
ret = ip_ra_control(sk, 1, mrtsock_destruct);
if (ret == 0) {
--
2.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net-next 7/7] net: ipmr: add mfc newroute/delroute netlink support
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
` (5 preceding siblings ...)
2015-11-26 14:23 ` [PATCH net-next 6/7] net: ipmr: fix setsockopt error return Nikolay Aleksandrov
@ 2015-11-26 14:23 ` Nikolay Aleksandrov
2015-11-26 16:35 ` [PATCH net-next 0/7] net: ipmr: more cleanups and mfc " Andrew Lunn
2015-11-30 20:26 ` David Miller
8 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 14:23 UTC (permalink / raw)
To: netdev; +Cc: davem, Nikolay Aleksandrov
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
This patch adds support to add and remove MFC entries. It uses the
same attributes like the already present dump support in order to be
consistent. There's one new entry - RTA_PREFSRC, it's used to denote an
MFC_PROXY entry (see MRT_ADD_MFC vs MRT_ADD_MFC_PROXY).
The already existing infrastructure is used to create and delete the
entries, the netlink message gets converted internally to a struct mfcctl
which is used with ipmr_mfc_add/delete.
The other used attributes are:
RTA_IIF - used for mfcc_parent (when adding it's required to be valid)
RTA_SRC - used for mfcc_origin
RTA_DST - used for mfcc_mcastgrp
RTA_TABLE - the MRT table id
RTA_MULTIPATH - the "oifs" ttl array
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
net/ipv4/ipmr.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 129 insertions(+)
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 6c24a16299c7..1fa1024e23d0 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -66,6 +66,7 @@
#include <net/netlink.h>
#include <net/fib_rules.h>
#include <linux/netconf.h>
+#include <net/nexthop.h>
struct ipmr_rule {
struct fib_rule common;
@@ -2339,6 +2340,130 @@ done:
return skb->len;
}
+static const struct nla_policy rtm_ipmr_policy[RTA_MAX + 1] = {
+ [RTA_SRC] = { .type = NLA_U32 },
+ [RTA_DST] = { .type = NLA_U32 },
+ [RTA_IIF] = { .type = NLA_U32 },
+ [RTA_TABLE] = { .type = NLA_U32 },
+ [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
+};
+
+static bool ipmr_rtm_validate_proto(unsigned char rtm_protocol)
+{
+ switch (rtm_protocol) {
+ case RTPROT_STATIC:
+ case RTPROT_MROUTED:
+ return true;
+ }
+ return false;
+}
+
+static int ipmr_nla_get_ttls(const struct nlattr *nla, struct mfcctl *mfcc)
+{
+ struct rtnexthop *rtnh = nla_data(nla);
+ int remaining = nla_len(nla), vifi = 0;
+
+ while (rtnh_ok(rtnh, remaining)) {
+ mfcc->mfcc_ttls[vifi] = rtnh->rtnh_hops;
+ if (++vifi == MAXVIFS)
+ break;
+ rtnh = rtnh_next(rtnh, &remaining);
+ }
+
+ return remaining > 0 ? -EINVAL : vifi;
+}
+
+/* returns < 0 on error, 0 for ADD_MFC and 1 for ADD_MFC_PROXY */
+static int rtm_to_ipmr_mfcc(struct net *net, struct nlmsghdr *nlh,
+ struct mfcctl *mfcc, int *mrtsock,
+ struct mr_table **mrtret)
+{
+ struct net_device *dev = NULL;
+ u32 tblid = RT_TABLE_DEFAULT;
+ struct mr_table *mrt;
+ struct nlattr *attr;
+ struct rtmsg *rtm;
+ int ret, rem;
+
+ ret = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipmr_policy);
+ if (ret < 0)
+ goto out;
+ rtm = nlmsg_data(nlh);
+
+ ret = -EINVAL;
+ if (rtm->rtm_family != RTNL_FAMILY_IPMR || rtm->rtm_dst_len != 32 ||
+ rtm->rtm_type != RTN_MULTICAST ||
+ rtm->rtm_scope != RT_SCOPE_UNIVERSE ||
+ !ipmr_rtm_validate_proto(rtm->rtm_protocol))
+ goto out;
+
+ memset(mfcc, 0, sizeof(*mfcc));
+ mfcc->mfcc_parent = -1;
+ ret = 0;
+ nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), rem) {
+ switch (nla_type(attr)) {
+ case RTA_SRC:
+ mfcc->mfcc_origin.s_addr = nla_get_be32(attr);
+ break;
+ case RTA_DST:
+ mfcc->mfcc_mcastgrp.s_addr = nla_get_be32(attr);
+ break;
+ case RTA_IIF:
+ dev = __dev_get_by_index(net, nla_get_u32(attr));
+ if (!dev) {
+ ret = -ENODEV;
+ goto out;
+ }
+ break;
+ case RTA_MULTIPATH:
+ if (ipmr_nla_get_ttls(attr, mfcc) < 0) {
+ ret = -EINVAL;
+ goto out;
+ }
+ break;
+ case RTA_PREFSRC:
+ ret = 1;
+ break;
+ case RTA_TABLE:
+ tblid = nla_get_u32(attr);
+ break;
+ }
+ }
+ mrt = ipmr_get_table(net, tblid);
+ if (!mrt) {
+ ret = -ENOENT;
+ goto out;
+ }
+ *mrtret = mrt;
+ *mrtsock = rtm->rtm_protocol == RTPROT_MROUTED ? 1 : 0;
+ if (dev)
+ mfcc->mfcc_parent = ipmr_find_vif(mrt, dev);
+
+out:
+ return ret;
+}
+
+/* takes care of both newroute and delroute */
+static int ipmr_rtm_route(struct sk_buff *skb, struct nlmsghdr *nlh)
+{
+ struct net *net = sock_net(skb->sk);
+ int ret, mrtsock, parent;
+ struct mr_table *tbl;
+ struct mfcctl mfcc;
+
+ mrtsock = 0;
+ tbl = NULL;
+ ret = rtm_to_ipmr_mfcc(net, nlh, &mfcc, &mrtsock, &tbl);
+ if (ret < 0)
+ return ret;
+
+ parent = ret ? mfcc.mfcc_parent : -1;
+ if (nlh->nlmsg_type == RTM_NEWROUTE)
+ return ipmr_mfc_add(net, tbl, &mfcc, mrtsock, parent);
+ else
+ return ipmr_mfc_delete(tbl, &mfcc, parent);
+}
+
#ifdef CONFIG_PROC_FS
/* The /proc interfaces to multicast routing :
* /proc/net/ip_mr_cache & /proc/net/ip_mr_vif
@@ -2692,6 +2817,10 @@ int __init ip_mr_init(void)
#endif
rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE,
NULL, ipmr_rtm_dumproute, NULL);
+ rtnl_register(RTNL_FAMILY_IPMR, RTM_NEWROUTE,
+ ipmr_rtm_route, NULL, NULL);
+ rtnl_register(RTNL_FAMILY_IPMR, RTM_DELROUTE,
+ ipmr_rtm_route, NULL, NULL);
return 0;
#ifdef CONFIG_IP_PIMSM_V2
--
2.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
` (6 preceding siblings ...)
2015-11-26 14:23 ` [PATCH net-next 7/7] net: ipmr: add mfc newroute/delroute netlink support Nikolay Aleksandrov
@ 2015-11-26 16:35 ` Andrew Lunn
2015-11-26 16:48 ` Nikolay Aleksandrov
2015-11-30 20:26 ` David Miller
8 siblings, 1 reply; 11+ messages in thread
From: Andrew Lunn @ 2015-11-26 16:35 UTC (permalink / raw)
To: Nikolay Aleksandrov; +Cc: netdev, davem, Nikolay Aleksandrov
On Thu, Nov 26, 2015 at 03:23:43PM +0100, Nikolay Aleksandrov wrote:
> From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
>
> Hi,
> This set continues with the minor cleanups in the first 6 patches and
> patch 7 adds the first new feature - MFC manipulation via netlink.
Hi Nikolay
Great to see somebody working on multicast.
Do you have any plans to remove the 32 VIF limit?
I've run out if VIFs on a VPN server with lots of clients. I took the
"quick fix" of recompiling the kernel and userspace with 256 VIFs. But
it would be nice if you could define a netlink API which does not have
this limit and modify the core code to be more dynamic.
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support
2015-11-26 16:35 ` [PATCH net-next 0/7] net: ipmr: more cleanups and mfc " Andrew Lunn
@ 2015-11-26 16:48 ` Nikolay Aleksandrov
0 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2015-11-26 16:48 UTC (permalink / raw)
To: Andrew Lunn, Nikolay Aleksandrov; +Cc: netdev, davem
On 11/26/2015 05:35 PM, Andrew Lunn wrote:
> On Thu, Nov 26, 2015 at 03:23:43PM +0100, Nikolay Aleksandrov wrote:
>> From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
>>
>> Hi,
>> This set continues with the minor cleanups in the first 6 patches and
>> patch 7 adds the first new feature - MFC manipulation via netlink.
>
> Hi Nikolay
>
> Great to see somebody working on multicast.
>
> Do you have any plans to remove the 32 VIF limit?
>
> I've run out if VIFs on a VPN server with lots of clients. I took the
> "quick fix" of recompiling the kernel and userspace with 256 VIFs. But
> it would be nice if you could define a netlink API which does not have
> this limit and modify the core code to be more dynamic.
>
> Andrew
>
Hi Andrew,
I'm glad people are still using it. :-) To answer your question - yes, I plan
to remove that limit, in fact I have a private version where it's done and this
API is the first step, you can see it uses the generic rtnh which supports
ifindex passing, so it'll be a matter of a few small changes to remove it.
The hardest part is keeping current user-space compatible with everything, but
I have the necessary workarounds for that. In the end it should be much more
usable and to some extent without mrtsock application running as well.
Thanks,
Nik
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
` (7 preceding siblings ...)
2015-11-26 16:35 ` [PATCH net-next 0/7] net: ipmr: more cleanups and mfc " Andrew Lunn
@ 2015-11-30 20:26 ` David Miller
8 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2015-11-30 20:26 UTC (permalink / raw)
To: razor; +Cc: netdev, nikolay
From: Nikolay Aleksandrov <razor@blackwall.org>
Date: Thu, 26 Nov 2015 15:23:43 +0100
> This set continues with the minor cleanups in the first 6 patches and
> patch 7 adds the first new feature - MFC manipulation via netlink. It
> registers NEWROUTE/DELROUTE for that purpose and uses the same semantics
> as the already present netlink dump. The only new attribute that is used
> is RTA_PREFSRC to denote an MFC_PROXY entry. Currently the table must
> exist before adding an entry, and new tables can be created only via
> setsockopt, but that will be changed in the future.
> This set was tested with modified iproute2 which supports NEWROUTE/DELROUTE
> for RTNL_FAMILY_IPMR.
Looks great, series applied, thanks!
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2015-11-30 20:26 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 14:23 [PATCH net-next 0/7] net: ipmr: more cleanups and mfc netlink support Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 1/7] net: remove unnecessary mroute.h includes Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 2/7] net: ipmr: remove unused MFC_NOTIFY flag and make the flags enum Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 3/7] net: ipmr: adjust mroute.h style and drop extern Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 4/7] net: ipmr: move struct mr_table and VIF_EXISTS to mroute.h Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 5/7] net: ipmr: move pimsm_enabled to pim.h and rename Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 6/7] net: ipmr: fix setsockopt error return Nikolay Aleksandrov
2015-11-26 14:23 ` [PATCH net-next 7/7] net: ipmr: add mfc newroute/delroute netlink support Nikolay Aleksandrov
2015-11-26 16:35 ` [PATCH net-next 0/7] net: ipmr: more cleanups and mfc " Andrew Lunn
2015-11-26 16:48 ` Nikolay Aleksandrov
2015-11-30 20:26 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).