Skip to contentSkip to conversation

ipmr: ip6mr: APIs to support adding more than MAXVIFS/MAXMIFS

RFC PATCH In review Stephen Suryaputra 3 participants 5 messages Sep 17, 2021 – Sep 21, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ipmr: ip6mr: APIs to support adding more than MAXVIFS/MAXMIFS

MAXVIFS and MAXMIFS are too small (32) for certain applications. But they are defined in user header files So, use a different definition CONFIG_IP_MROUTE_EXT_MAXVIFS that is configurable and different ioctl requests (MRT_xyz_EXT and MRT6_xyz_EXT) as well as a different structure for adding MFC (mfcctl_ext).

CONFIG_IP_MROUTE_EXT_MAXVIFS is bounded by the IF_SETSIZE (256) in mroute6.h.

This patch is extending the following RFC:
http://patchwork.ozlabs.org/project/netdev/patch/[email protected]/

---
 include/linux/mroute_base.h  |  11 +---
 include/uapi/linux/mroute.h  |  14 ++++-
 include/uapi/linux/mroute6.h |   5 +-
 net/ipv4/Kconfig             |  11 ++++
 net/ipv4/ipmr.c              | 115 +++++++++++++++++++++++++++++------
 net/ipv4/ipmr_base.c         |   2 +-
 net/ipv6/ip6mr.c             |  52 +++++++++++-----
 7 files changed, 163 insertions(+), 47 deletions(-)
include/linux/mroute_base.h +2 -9
index 8071148f29a6..85f3a8864044 100644
@@ -89,13 +89,6 @@ static inline int mr_call_vif_notifiers(struct net *net,
 	return call_fib_notifiers(net, event_type, &info.info);
 }
 
-#ifndef MAXVIFS
-/* This one is nasty; value is defined in uapi using different symbols for
- * mroute and morute6 but both map into same 32.
- */
-#define MAXVIFS	32
-#endif
-
 #define VIF_EXISTS(_mrt, _idx) (!!((_mrt)->vif_table[_idx].dev))
 
 /* mfc_flags:
@@ -145,7 +138,7 @@ struct mr_mfc {
 			unsigned long pkt;
 			unsigned long wrong_if;
 			unsigned long lastuse;
-			unsigned char ttls[MAXVIFS];
+			unsigned char ttls[CONFIG_IP_MROUTE_EXT_MAXVIFS];
 			refcount_t refcount;
 		} res;
 	} mfc_un;
@@ -246,7 +239,7 @@ struct mr_table {
 	struct sock __rcu	*mroute_sk;
 	struct timer_list	ipmr_expire_timer;
 	struct list_head	mfc_unres_queue;
-	struct vif_device	vif_table[MAXVIFS];
+	struct vif_device	vif_table[CONFIG_IP_MROUTE_EXT_MAXVIFS];
 	struct rhltable		mfc_hash;
 	struct list_head	mfc_cache_list;
 	int			maxvif;
include/uapi/linux/mroute.h +13 -1
index 1a42f5f9b31b..b28f46565a43 100644
@@ -29,7 +29,10 @@
 #define MRT_ADD_MFC_PROXY	(MRT_BASE+10)	/* Add a (*,*|G) mfc entry	*/
 #define MRT_DEL_MFC_PROXY	(MRT_BASE+11)	/* Del a (*,*|G) mfc entry	*/
 #define MRT_FLUSH	(MRT_BASE+12)	/* Flush all mfc entries and/or vifs	*/
-#define MRT_MAX		(MRT_BASE+12)
+#define MRT_ADD_VIF_EXT	(MRT_BASE+13)	/* Add a virtual interface		*/
+#define MRT_ADD_MFC_EXT	(MRT_BASE+14)	/* Add a multicast forwarding entry	*/
+#define MRT_ADD_MFC_PROXY_EXT	(MRT_BASE+15)	/* Add a (*,*|G) mfc entry	*/
+#define MRT_MAX		(MRT_BASE+15)
 
 #define SIOCGETVIFCNT	SIOCPROTOPRIVATE	/* IP protocol privates */
 #define SIOCGETSGCNT	(SIOCPROTOPRIVATE+1)
@@ -88,6 +91,15 @@ struct mfcctl {
 	int	     mfcc_expire;
 };
 
+struct mfcctl_ext {
+	/* Need to be the same as mfcctl */
+	struct in_addr mfcc_origin;		/* Origin of mcast	*/
+	struct in_addr mfcc_mcastgrp;		/* Group in question	*/
+	vifi_t	mfcc_parent;			/* Where it arrived	*/
+	unsigned char mfcc_ttls[];		/* Where it is going	*/
+	/* Don't put anything here as mfcc_ttls should grow into here */
+};
+
 /*  Group count retrieval for mrouted */
 struct sioc_sg_req {
 	struct in_addr src;
include/uapi/linux/mroute6.h +4 -1
index a1fd6173e2db..1d15af3e0011 100644
@@ -32,7 +32,10 @@
 #define MRT6_ADD_MFC_PROXY	(MRT6_BASE+10)	/* Add a (*,*|G) mfc entry	*/
 #define MRT6_DEL_MFC_PROXY	(MRT6_BASE+11)	/* Del a (*,*|G) mfc entry	*/
 #define MRT6_FLUSH	(MRT6_BASE+12)	/* Flush all mfc entries and/or vifs	*/
-#define MRT6_MAX	(MRT6_BASE+12)
+#define MRT6_ADD_MIF_EXT	(MRT6_BASE+13)	/* Add a virtual interface		*/
+#define MRT6_ADD_MFC_EXT	(MRT6_BASE+14)	/* Add a multicast forwarding entry	*/
+#define MRT6_ADD_MFC_PROXY_EXT	(MRT6_BASE+15)	/* Add a (*,*|G) mfc entry	*/
+#define MRT6_MAX	(MRT6_BASE+15)
 
 #define SIOCGETMIFCNT_IN6	SIOCPROTOPRIVATE	/* IP protocol privates */
 #define SIOCGETSGCNT_IN6	(SIOCPROTOPRIVATE+1)
net/ipv4/Kconfig +11 -0
index 87983e70f03f..34ff677a4dca 100644
@@ -243,6 +243,17 @@ config IP_MROUTE_MULTIPLE_TABLES
 
 	  If unsure, say N.
 
+config IP_MROUTE_EXT_MAXVIFS
+	int "IP: extended maximum multicast routing vif"
+	depends on IP_MROUTE || IPV6_MROUTE
+	range 32 256
+	default 32
+	help
+	  Maximum multicast routing vif is set at 32 and it is defined in the
+	  user API header file, so it is fixed. There are cases where more
+	  vifs are needed. This config is used to get more vifs. The default
+	  is set to be the same as MAXVIFS (32).
+
 config IP_PIMSM_V1
 	bool "IP: PIM-SM version 1 support"
 	depends on IP_MROUTE
net/ipv4/ipmr.c +96 -19

220 lines not on this page · raw message

net/ipv4/ipmr_base.c +1 -1
index aa8738a91210..ce109643ce7b 100644
@@ -215,7 +215,7 @@ int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
 	int ct;
 
 	/* If cache is unresolved, don't try to parse IIF and OIF */
-	if (c->mfc_parent >= MAXVIFS) {
+	if (c->mfc_parent >= CONFIG_IP_MROUTE_EXT_MAXVIFS) {
 		rtm->rtm_flags |= RTNH_F_UNRESOLVED;
 		return -ENOENT;
 	}
net/ipv6/ip6mr.c +36 -16

123 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/a569861a106aab4e715ba5e5ed82db0c20c2ca92 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags…

Hi Stephen,

[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Stephen-Suryaputra/ipmr-ip6mr-APIs-to-support-adding-more-than-MAXVIFS-MAXMIFS/20210918-064706
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git af54faab84f754ebd42ecdda871f8d71940ae40b
config: um-x86_64_defconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/a569861a106aab4e715ba5e5ed82db0c20c2ca92
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Stephen-Suryaputra/ipmr-ip6mr-APIs-to-support-adding-more-than-MAXVIFS-MAXMIFS/20210918-064706 git checkout a569861a106aab4e715ba5e5ed82db0c20c2ca92
# save the attached .config to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=um SUBARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from include/linux/mroute.h:10,

                    from net/ipv4/raw.c:51:
>> include/linux/mroute_base.h:141:23: error: 'CONFIG_IP_MROUTE_EXT_MAXVIFS' undeclared here (not in a function)
     141 |    unsigned char ttls[CONFIG_IP_MROUTE_EXT_MAXVIFS];
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
   In file included from include/linux/mroute.h:10,
                    from net/ipv4/route.c:83:
>> include/linux/mroute_base.h:141:23: error: 'CONFIG_IP_MROUTE_EXT_MAXVIFS' undeclared here (not in a function)
     141 |    unsigned char ttls[CONFIG_IP_MROUTE_EXT_MAXVIFS];
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   net/ipv4/route.c: In function 'ip_rt_send_redirect':
   net/ipv4/route.c:877:6: warning: variable 'log_martians' set but not used [-Wunused-but-set-variable]
     877 |  int log_martians;
         |      ^~~~~~~~~~~~

vim +/CONFIG_IP_MROUTE_EXT_MAXVIFS +141 include/linux/mroute_base.h

102
103 /**
104 * struct mr_mfc - common multicast routing entries
105 * @mnode: rhashtable list
106 * @mfc_parent: source interface (iif)
107 * @mfc_flags: entry flags
108 * @expires: unresolved entry expire time
109 * @unresolved: unresolved cached skbs
110 * @last_assert: time of last assert
111 * @minvif: minimum VIF id
112 * @maxvif: maximum VIF id
113 * @bytes: bytes that have passed for this entry
114 * @pkt: packets that have passed for this entry
115 * @wrong_if: number of wrong source interface hits
116 * @lastuse: time of last use of the group (traffic or update)
117 * @ttls: OIF TTL threshold array
118 * @refcount: reference count for this entry
119 * @list: global entry list
120 * @rcu: used for entry destruction
121 * @free: Operation used for freeing an entry under RCU
122 */
123 struct mr_mfc {
124 struct rhlist_head mnode;
125 unsigned short mfc_parent;
126 int mfc_flags;
127
128 union {
129 struct {
130 unsigned long expires;
131 struct sk_buff_head unresolved;
132 } unres;
133 struct {
134 unsigned long last_assert;
135 int minvif;
136 int maxvif;
137 unsigned long bytes;
138 unsigned long pkt;
139 unsigned long wrong_if;
140 unsigned long lastuse;

 > 141				unsigned char ttls[CONFIG_IP_MROUTE_EXT_MAXVIFS];

142 refcount_t refcount;
143 } res;
144 } mfc_un;
145 struct list_head list;
146 struct rcu_head rcu;
147 void (*free)(struct rcu_head *head);
148 };
149

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Stephen Suryaputra
Quoted 11 lines · Stephen Suryaputra

MAXVIFS and MAXMIFS are too small (32) for certain applications. But they are defined in user header files So, use a different definition CONFIG_IP_MROUTE_EXT_MAXVIFS that is configurable and different ioctl requests (MRT_xyz_EXT and MRT6_xyz_EXT) as well as a different structure for adding MFC (mfcctl_ext).

CONFIG_IP_MROUTE_EXT_MAXVIFS is bounded by the IF_SETSIZE (256) in mroute6.h.

This patch is extending the following RFC:
http://patchwork.ozlabs.org/project/netdev/patch/[email protected]/

Quoting the above URL:

Quoted 2 lines

My goal is an API that works with just a recompile of existing applications, and an ABI that continues to work for old applications.

Does this really work? Does the distribution version of mrouted use the kernel UAPI headers of the running kernel? Can i upgrade to a newer kernel, with newer headers, and it automagically pulls in a new mrouted built using the new kernel headers? I think not. ethtool has its own copy of the kernel headers. mrouted uses /usr/include/linux/mroute.h which is provided by linux-libc-dev:amd64. That is not tied to the running kernel. What about quagga?

So in effect, you have to ask the running kernel, what value is it using for MAXVIFS? Which means it is much more than just a recompile. So i doubt think you can achieve this goal.

Given that, i really think you should spend the time to do a proper solution. Add a netlink based API, which does not have the 32 limit. Make the kernel implementation be based on a linked list. Have the ioctl interface simply return the first 32 entries and ignore anything above that.

Andrew

#4 lore raw
In reply to Stephen Suryaputra
Quoted 6 lines

That particular goal by Eric isn't exactly my goal. I extended his approach to be more inline with the latest feedback he got. My application is written for an embedded router and for it /usr/include/linux/mroute.h is coming from the include/uapi/linux/mroute.h. So, the new structure mfcctl_ext can be used by the application.

Hi Stephan

That however is not the general case. Any new API you add needs to support the general case, not just work for you. This needs to work for Debian, Redhat, OpenWRT, Yocto etc, where often a copy of the kernel headers are used.

Quoted 5 lines

This proposal doesn't change any existing ones such as MRT_ADD_MFC, MRT_ADD_VIF, MRT6_ADD_MFC and MRT6_ADD_MIF as they are still using the unchanged MAXVIFS. So, if the applications such as quagga still use the existing mroute.h it should still be working with the 32 vifs limitation.

Agreed, you have not broken the existing code. But you have also not added something which is a good way forward for quagga, mrouted etc, to support arbitrary number of VIFS. I doubt the community will allow this sort of band aid, which works for you, but not many others. They will want a proper generic solution.

Andrew

#3 lore raw
In reply to Andrew Lunn
Quoted 18 lines · Andrew Lunn
Quoted 11 lines · Stephen Suryaputra

MAXVIFS and MAXMIFS are too small (32) for certain applications. But they are defined in user header files So, use a different definition CONFIG_IP_MROUTE_EXT_MAXVIFS that is configurable and different ioctl requests (MRT_xyz_EXT and MRT6_xyz_EXT) as well as a different structure for adding MFC (mfcctl_ext).

CONFIG_IP_MROUTE_EXT_MAXVIFS is bounded by the IF_SETSIZE (256) in mroute6.h.

This patch is extending the following RFC:
http://patchwork.ozlabs.org/project/netdev/patch/[email protected]/

Quoting the above URL:

Quoted 2 lines

My goal is an API that works with just a recompile of existing applications, and an ABI that continues to work for old applications.

Quoted 8 lines

Does this really work? Does the distribution version of mrouted use the kernel UAPI headers of the running kernel? Can i upgrade to a newer kernel, with newer headers, and it automagically pulls in a new mrouted built using the new kernel headers? I think not. ethtool has its own copy of the kernel headers. mrouted uses /usr/include/linux/mroute.h which is provided by linux-libc-dev:amd64. That is not tied to the running kernel. What about quagga?

That particular goal by Eric isn't exactly my goal. I extended his approach to be more inline with the latest feedback he got. My application is written for an embedded router and for it /usr/include/linux/mroute.h is coming from the include/uapi/linux/mroute.h. So, the new structure mfcctl_ext can be used by the application.

Quoted 10 lines

So in effect, you have to ask the running kernel, what value is it using for MAXVIFS? Which means it is much more than just a recompile. So i doubt think you can achieve this goal.

Given that, i really think you should spend the time to do a proper solution. Add a netlink based API, which does not have the 32 limit. Make the kernel implementation be based on a linked list. Have the ioctl interface simply return the first 32 entries and ignore anything above that.

This proposal doesn't change any existing ones such as MRT_ADD_MFC, MRT_ADD_VIF, MRT6_ADD_MFC and MRT6_ADD_MIF as they are still using the unchanged MAXVIFS. So, if the applications such as quagga still use the existing mroute.h it should still be working with the 32 vifs limitation.

To use more than 32 vifs, then MRT_ADD_MFC_EXT, etc can be used. But for that the applications need to be modified and be using the updated mroute.h and mroute6.h.

Regards,
Stephen.