linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] net: bonding: Add support for IPV6 ns/na
@ 2021-12-10 13:08 Sun Shouxin
  2021-12-10 18:03 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Sun Shouxin @ 2021-12-10 13:08 UTC (permalink / raw)
  To: j.vosburgh, vfalico, andy, davem, kuba; +Cc: netdev, linux-kernel, huyd12

Since ipv6 neighbor solicitation and advertisement messages
isn't handled gracefully in bonding6 driver, we can see packet
drop due to inconsistency bewteen mac address in the option
message and source MAC .

Another examples is ipv6 neighbor solicitation and advertisement
messages from VM via tap attached to host brighe, the src mac
mighe be changed through balance-alb mode, but it is not synced
with Link-layer address in the option message.

The patch implements bond6's tx handle for ipv6 neighbor
solicitation and advertisement messages.

			Border-Leaf
			/        \
		       /          \
		    Tunnel1    Tunnel2
		     /              \
	            /                \
		  Leaf-1--Tunnel3--Leaf-2
		    \                /
		     \              /
		      \            /
		       \          /
		       NIC1    NIC2
			\      /
			server

We can see in our lab the Border-Leaf receives occasionally
a NA packet which is assigned to NIC1 mac in ND/NS option
message, but actaully send out via NIC2 mac due to tx-alb,
as a result, it will cause inconsistency between MAC table
and ND Table in Border-Leaf, i.e, NIC1 = Tunnel2 in ND table
and  NIC1 = Tunnel1 in mac table.

And then, Border-Leaf starts to forward packet destinated
to the Server, it will only check the ND table entry in some
switch to encapsulate the destination MAC of the message as
NIC1 MAC, and then send it out from Tunnel2 by ND table.
Then, Leaf-2 receives the packet, it notices the destination
MAC of message is NIC1 MAC and should forword it to Tunne1
by Tunnel3.

However, this traffic forward will be failure due to split
horizon of VxLAN tunnels.

Suggested-by: Hu Yadi <huyd12@chinatelecom.cn>
Signed-off-by: Sun Shouxin <sunshouxin@chinatelecom.cn>
---
 drivers/net/bonding/bond_alb.c | 131 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)

diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 533e476..afa386b 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -22,6 +22,7 @@
 #include <asm/byteorder.h>
 #include <net/bonding.h>
 #include <net/bond_alb.h>
+#include <net/ndisc.h>
 
 static const u8 mac_v6_allmcast[ETH_ALEN + 2] __long_aligned = {
 	0x33, 0x33, 0x00, 0x00, 0x00, 0x01
@@ -1269,6 +1270,119 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
 	return res;
 }
 
+/*determine if the packet is NA or NS*/
+static bool alb_determine_nd(struct icmp6hdr *hdr)
+{
+	if (hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT ||
+	    hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
+		return true;
+	}
+
+	return false;
+}
+
+static void alb_change_nd_option(struct sk_buff *skb, void *data)
+{
+	struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
+	struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
+	struct net_device *dev = skb->dev;
+	struct icmp6hdr *icmp6h = icmp6_hdr(skb);
+	struct ipv6hdr *ip6hdr = ipv6_hdr(skb);
+	u8 *lladdr = NULL;
+	u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
+				offsetof(struct nd_msg, opt));
+
+	while (ndoptlen) {
+		int l;
+
+		switch (nd_opt->nd_opt_type) {
+		case ND_OPT_SOURCE_LL_ADDR:
+		case ND_OPT_TARGET_LL_ADDR:
+		lladdr = ndisc_opt_addr_data(nd_opt, dev);
+		break;
+
+		default:
+		lladdr = NULL;
+		break;
+		}
+
+		l = nd_opt->nd_opt_len << 3;
+
+		if (ndoptlen < l || l == 0)
+			return;
+
+		if (lladdr) {
+			memcpy(lladdr, data, dev->addr_len);
+			icmp6h->icmp6_cksum = 0;
+
+			icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
+							      &ip6hdr->daddr,
+						ntohs(ip6hdr->payload_len),
+						IPPROTO_ICMPV6,
+						csum_partial(icmp6h,
+							     ntohs(ip6hdr->payload_len), 0));
+		}
+		ndoptlen -= l;
+		nd_opt = ((void *)nd_opt) + l;
+	}
+}
+
+static u8 *alb_get_lladdr(struct sk_buff *skb)
+{
+	struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
+	struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
+	struct net_device *dev = skb->dev;
+	u8 *lladdr = NULL;
+	u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
+				offsetof(struct nd_msg, opt));
+
+	while (ndoptlen) {
+		int l;
+
+		switch (nd_opt->nd_opt_type) {
+		case ND_OPT_SOURCE_LL_ADDR:
+		case ND_OPT_TARGET_LL_ADDR:
+			lladdr = ndisc_opt_addr_data(nd_opt, dev);
+			break;
+
+		default:
+			break;
+		}
+
+		l = nd_opt->nd_opt_len << 3;
+
+		if (ndoptlen < l || l == 0)
+			return lladdr;
+
+		if (lladdr)
+			return lladdr;
+
+		ndoptlen -= l;
+		nd_opt = ((void *)nd_opt) + l;
+	}
+
+	return lladdr;
+}
+
+static void alb_set_nd_option(struct sk_buff *skb, struct bonding *bond,
+			      struct slave *tx_slave)
+{
+	struct ipv6hdr *ip6hdr;
+	struct icmp6hdr *hdr = NULL;
+
+	if (skb->protocol == htons(ETH_P_IPV6)) {
+		if (tx_slave && tx_slave !=
+		    rcu_access_pointer(bond->curr_active_slave)) {
+			ip6hdr = ipv6_hdr(skb);
+			if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
+				hdr = icmp6_hdr(skb);
+				if (alb_determine_nd(hdr))
+					alb_change_nd_option(skb, tx_slave->dev->dev_addr);
+			}
+		}
+	}
+}
+
 /************************ exported alb functions ************************/
 
 int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
@@ -1415,6 +1529,7 @@ struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
 	}
 	case ETH_P_IPV6: {
 		const struct ipv6hdr *ip6hdr;
+		struct icmp6hdr *hdr = NULL;
 
 		/* IPv6 doesn't really use broadcast mac address, but leave
 		 * that here just in case.
@@ -1446,6 +1561,21 @@ struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
 			break;
 		}
 
+		if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
+			hdr = icmp6_hdr(skb);
+			if (alb_determine_nd(hdr)) {
+				u8 *lladdr = NULL;
+
+				lladdr = alb_get_lladdr(skb);
+				if (lladdr) {
+					if (!bond_slave_has_mac_rx(bond, lladdr)) {
+						do_tx_balance = false;
+						break;
+					}
+				}
+			}
+		}
+
 		hash_start = (char *)&ip6hdr->daddr;
 		hash_size = sizeof(ip6hdr->daddr);
 		break;
@@ -1489,6 +1619,7 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
 	struct slave *tx_slave = NULL;
 
 	tx_slave = bond_xmit_alb_slave_get(bond, skb);
+	alb_set_nd_option(skb, bond, tx_slave);
 	return bond_do_alb_xmit(skb, bond, tx_slave);
 }
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] net: bonding: Add support for IPV6 ns/na
  2021-12-10 13:08 [PATCH V2] net: bonding: Add support for IPV6 ns/na Sun Shouxin
@ 2021-12-10 18:03 ` kernel test robot
  2021-12-10 18:13 ` kernel test robot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2021-12-10 18:03 UTC (permalink / raw)
  To: Sun Shouxin, j.vosburgh, vfalico, andy, davem, kuba
  Cc: kbuild-all, netdev, linux-kernel, huyd12

Hi Sun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.16-rc4 next-20211208]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Sun-Shouxin/net-bonding-Add-support-for-IPV6-ns-na/20211210-210940
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git c741e49150dbb0c0aebe234389f4aa8b47958fa8
config: nios2-randconfig-r026-20211210 (https://download.01.org/0day-ci/archive/20211211/202112110146.ZZvFe0rG-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/f86d634c3ced7ec9b5af72e4b92bca681be033f7
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Sun-Shouxin/net-bonding-Add-support-for-IPV6-ns-na/20211210-210940
        git checkout f86d634c3ced7ec9b5af72e4b92bca681be033f7
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nios2 SHELL=/bin/bash drivers/net/bonding/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/net/bonding/bond_alb.c: In function 'alb_change_nd_option':
>> drivers/net/bonding/bond_alb.c:1318:47: error: implicit declaration of function 'csum_ipv6_magic'; did you mean 'csum_tcpudp_magic'? [-Werror=implicit-function-declaration]
    1318 |                         icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
         |                                               ^~~~~~~~~~~~~~~
         |                                               csum_tcpudp_magic
   cc1: some warnings being treated as errors


vim +1318 drivers/net/bonding/bond_alb.c

  1283	
  1284	static void alb_change_nd_option(struct sk_buff *skb, void *data)
  1285	{
  1286		struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
  1287		struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
  1288		struct net_device *dev = skb->dev;
  1289		struct icmp6hdr *icmp6h = icmp6_hdr(skb);
  1290		struct ipv6hdr *ip6hdr = ipv6_hdr(skb);
  1291		u8 *lladdr = NULL;
  1292		u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
  1293					offsetof(struct nd_msg, opt));
  1294	
  1295		while (ndoptlen) {
  1296			int l;
  1297	
  1298			switch (nd_opt->nd_opt_type) {
  1299			case ND_OPT_SOURCE_LL_ADDR:
  1300			case ND_OPT_TARGET_LL_ADDR:
  1301			lladdr = ndisc_opt_addr_data(nd_opt, dev);
  1302			break;
  1303	
  1304			default:
  1305			lladdr = NULL;
  1306			break;
  1307			}
  1308	
  1309			l = nd_opt->nd_opt_len << 3;
  1310	
  1311			if (ndoptlen < l || l == 0)
  1312				return;
  1313	
  1314			if (lladdr) {
  1315				memcpy(lladdr, data, dev->addr_len);
  1316				icmp6h->icmp6_cksum = 0;
  1317	
> 1318				icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
  1319								      &ip6hdr->daddr,
  1320							ntohs(ip6hdr->payload_len),
  1321							IPPROTO_ICMPV6,
  1322							csum_partial(icmp6h,
  1323								     ntohs(ip6hdr->payload_len), 0));
  1324			}
  1325			ndoptlen -= l;
  1326			nd_opt = ((void *)nd_opt) + l;
  1327		}
  1328	}
  1329	

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] net: bonding: Add support for IPV6 ns/na
  2021-12-10 13:08 [PATCH V2] net: bonding: Add support for IPV6 ns/na Sun Shouxin
  2021-12-10 18:03 ` kernel test robot
@ 2021-12-10 18:13 ` kernel test robot
  2021-12-14  1:02 ` 回复: " huyd12
  2021-12-14  8:05 ` Eric Dumazet
  3 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2021-12-10 18:13 UTC (permalink / raw)
  To: Sun Shouxin, j.vosburgh, vfalico, andy, davem, kuba
  Cc: llvm, kbuild-all, netdev, linux-kernel, huyd12

Hi Sun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.16-rc4 next-20211208]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Sun-Shouxin/net-bonding-Add-support-for-IPV6-ns-na/20211210-210940
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git c741e49150dbb0c0aebe234389f4aa8b47958fa8
config: hexagon-randconfig-r006-20211210 (https://download.01.org/0day-ci/archive/20211211/202112110234.hkzxELcK-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 097a1cb1d5ebb3a0ec4bcaed8ba3ff6a8e33c00a)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/f86d634c3ced7ec9b5af72e4b92bca681be033f7
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Sun-Shouxin/net-bonding-Add-support-for-IPV6-ns-na/20211210-210940
        git checkout f86d634c3ced7ec9b5af72e4b92bca681be033f7
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/net/bonding/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/net/bonding/bond_alb.c:1318:26: error: implicit declaration of function 'csum_ipv6_magic' [-Werror,-Wimplicit-function-declaration]
                           icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
                                                 ^
   drivers/net/bonding/bond_alb.c:1318:26: note: did you mean 'csum_tcpudp_magic'?
   arch/hexagon/include/asm/checksum.h:21:9: note: 'csum_tcpudp_magic' declared here
   __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
           ^
   arch/hexagon/include/asm/checksum.h:20:27: note: expanded from macro 'csum_tcpudp_magic'
   #define csum_tcpudp_magic csum_tcpudp_magic
                             ^
   1 error generated.


vim +/csum_ipv6_magic +1318 drivers/net/bonding/bond_alb.c

  1283	
  1284	static void alb_change_nd_option(struct sk_buff *skb, void *data)
  1285	{
  1286		struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
  1287		struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
  1288		struct net_device *dev = skb->dev;
  1289		struct icmp6hdr *icmp6h = icmp6_hdr(skb);
  1290		struct ipv6hdr *ip6hdr = ipv6_hdr(skb);
  1291		u8 *lladdr = NULL;
  1292		u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
  1293					offsetof(struct nd_msg, opt));
  1294	
  1295		while (ndoptlen) {
  1296			int l;
  1297	
  1298			switch (nd_opt->nd_opt_type) {
  1299			case ND_OPT_SOURCE_LL_ADDR:
  1300			case ND_OPT_TARGET_LL_ADDR:
  1301			lladdr = ndisc_opt_addr_data(nd_opt, dev);
  1302			break;
  1303	
  1304			default:
  1305			lladdr = NULL;
  1306			break;
  1307			}
  1308	
  1309			l = nd_opt->nd_opt_len << 3;
  1310	
  1311			if (ndoptlen < l || l == 0)
  1312				return;
  1313	
  1314			if (lladdr) {
  1315				memcpy(lladdr, data, dev->addr_len);
  1316				icmp6h->icmp6_cksum = 0;
  1317	
> 1318				icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
  1319								      &ip6hdr->daddr,
  1320							ntohs(ip6hdr->payload_len),
  1321							IPPROTO_ICMPV6,
  1322							csum_partial(icmp6h,
  1323								     ntohs(ip6hdr->payload_len), 0));
  1324			}
  1325			ndoptlen -= l;
  1326			nd_opt = ((void *)nd_opt) + l;
  1327		}
  1328	}
  1329	

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* 回复: [PATCH V2] net: bonding: Add support for IPV6 ns/na
  2021-12-10 13:08 [PATCH V2] net: bonding: Add support for IPV6 ns/na Sun Shouxin
  2021-12-10 18:03 ` kernel test robot
  2021-12-10 18:13 ` kernel test robot
@ 2021-12-14  1:02 ` huyd12
  2021-12-14  1:06   ` Jakub Kicinski
  2021-12-14  8:05 ` Eric Dumazet
  3 siblings, 1 reply; 8+ messages in thread
From: huyd12 @ 2021-12-14  1:02 UTC (permalink / raw)
  To: sunshouxin, j.vosburgh, vfalico, andy, davem, kuba; +Cc: netdev, linux-kernel


Hi,all

Any comments will be appreciated.
thanks a lot.

Yadi


主题: [PATCH V2] net: bonding: Add support for IPV6 ns/na

Since ipv6 neighbor solicitation and advertisement messages isn't handled
gracefully in bonding6 driver, we can see packet drop due to inconsistency
bewteen mac address in the option message and source MAC .

Another examples is ipv6 neighbor solicitation and advertisement messages
from VM via tap attached to host brighe, the src mac mighe be changed
through balance-alb mode, but it is not synced with Link-layer address in
the option message.

The patch implements bond6's tx handle for ipv6 neighbor solicitation and
advertisement messages.

			Border-Leaf
			/        \
		       /          \
		    Tunnel1    Tunnel2
		     /              \
	            /                \
		  Leaf-1--Tunnel3--Leaf-2
		    \                /
		     \              /
		      \            /
		       \          /
		       NIC1    NIC2
			\      /
			server

We can see in our lab the Border-Leaf receives occasionally a NA packet
which is assigned to NIC1 mac in ND/NS option message, but actaully send out
via NIC2 mac due to tx-alb, as a result, it will cause inconsistency between
MAC table and ND Table in Border-Leaf, i.e, NIC1 = Tunnel2 in ND table and
NIC1 = Tunnel1 in mac table.

And then, Border-Leaf starts to forward packet destinated to the Server, it
will only check the ND table entry in some switch to encapsulate the
destination MAC of the message as
NIC1 MAC, and then send it out from Tunnel2 by ND table.
Then, Leaf-2 receives the packet, it notices the destination MAC of message
is NIC1 MAC and should forword it to Tunne1 by Tunnel3.

However, this traffic forward will be failure due to split horizon of VxLAN
tunnels.

Suggested-by: Hu Yadi <huyd12@chinatelecom.cn>
Signed-off-by: Sun Shouxin <sunshouxin@chinatelecom.cn>
---
 drivers/net/bonding/bond_alb.c | 131
+++++++++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)

diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 533e476..afa386b 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -22,6 +22,7 @@
 #include <asm/byteorder.h>
 #include <net/bonding.h>
 #include <net/bond_alb.h>
+#include <net/ndisc.h>
 
 static const u8 mac_v6_allmcast[ETH_ALEN + 2] __long_aligned = {
 	0x33, 0x33, 0x00, 0x00, 0x00, 0x01
@@ -1269,6 +1270,119 @@ static int alb_set_mac_address(struct bonding *bond,
void *addr)
 	return res;
 }
 
+/*determine if the packet is NA or NS*/ static bool 
+alb_determine_nd(struct icmp6hdr *hdr) {
+	if (hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT ||
+	    hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
+		return true;
+	}
+
+	return false;
+}
+
+static void alb_change_nd_option(struct sk_buff *skb, void *data) {
+	struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
+	struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
+	struct net_device *dev = skb->dev;
+	struct icmp6hdr *icmp6h = icmp6_hdr(skb);
+	struct ipv6hdr *ip6hdr = ipv6_hdr(skb);
+	u8 *lladdr = NULL;
+	u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
+				offsetof(struct nd_msg, opt));
+
+	while (ndoptlen) {
+		int l;
+
+		switch (nd_opt->nd_opt_type) {
+		case ND_OPT_SOURCE_LL_ADDR:
+		case ND_OPT_TARGET_LL_ADDR:
+		lladdr = ndisc_opt_addr_data(nd_opt, dev);
+		break;
+
+		default:
+		lladdr = NULL;
+		break;
+		}
+
+		l = nd_opt->nd_opt_len << 3;
+
+		if (ndoptlen < l || l == 0)
+			return;
+
+		if (lladdr) {
+			memcpy(lladdr, data, dev->addr_len);
+			icmp6h->icmp6_cksum = 0;
+
+			icmp6h->icmp6_cksum =
csum_ipv6_magic(&ip6hdr->saddr,
+							
&ip6hdr->daddr,
+						ntohs(ip6hdr->payload_len),
+						IPPROTO_ICMPV6,
+						csum_partial(icmp6h,
+							
ntohs(ip6hdr->payload_len), 0));
+		}
+		ndoptlen -= l;
+		nd_opt = ((void *)nd_opt) + l;
+	}
+}
+
+static u8 *alb_get_lladdr(struct sk_buff *skb) {
+	struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
+	struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
+	struct net_device *dev = skb->dev;
+	u8 *lladdr = NULL;
+	u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
+				offsetof(struct nd_msg, opt));
+
+	while (ndoptlen) {
+		int l;
+
+		switch (nd_opt->nd_opt_type) {
+		case ND_OPT_SOURCE_LL_ADDR:
+		case ND_OPT_TARGET_LL_ADDR:
+			lladdr = ndisc_opt_addr_data(nd_opt, dev);
+			break;
+
+		default:
+			break;
+		}
+
+		l = nd_opt->nd_opt_len << 3;
+
+		if (ndoptlen < l || l == 0)
+			return lladdr;
+
+		if (lladdr)
+			return lladdr;
+
+		ndoptlen -= l;
+		nd_opt = ((void *)nd_opt) + l;
+	}
+
+	return lladdr;
+}
+
+static void alb_set_nd_option(struct sk_buff *skb, struct bonding *bond,
+			      struct slave *tx_slave)
+{
+	struct ipv6hdr *ip6hdr;
+	struct icmp6hdr *hdr = NULL;
+
+	if (skb->protocol == htons(ETH_P_IPV6)) {
+		if (tx_slave && tx_slave !=
+		    rcu_access_pointer(bond->curr_active_slave)) {
+			ip6hdr = ipv6_hdr(skb);
+			if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
+				hdr = icmp6_hdr(skb);
+				if (alb_determine_nd(hdr))
+					alb_change_nd_option(skb,
tx_slave->dev->dev_addr);
+			}
+		}
+	}
+}
+
 /************************ exported alb functions ************************/
 
 int bond_alb_initialize(struct bonding *bond, int rlb_enabled) @@ -1415,6
+1529,7 @@ struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
 	}
 	case ETH_P_IPV6: {
 		const struct ipv6hdr *ip6hdr;
+		struct icmp6hdr *hdr = NULL;
 
 		/* IPv6 doesn't really use broadcast mac address, but leave
 		 * that here just in case.
@@ -1446,6 +1561,21 @@ struct slave *bond_xmit_alb_slave_get(struct bonding
*bond,
 			break;
 		}
 
+		if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
+			hdr = icmp6_hdr(skb);
+			if (alb_determine_nd(hdr)) {
+				u8 *lladdr = NULL;
+
+				lladdr = alb_get_lladdr(skb);
+				if (lladdr) {
+					if (!bond_slave_has_mac_rx(bond,
lladdr)) {
+						do_tx_balance = false;
+						break;
+					}
+				}
+			}
+		}
+
 		hash_start = (char *)&ip6hdr->daddr;
 		hash_size = sizeof(ip6hdr->daddr);
 		break;
@@ -1489,6 +1619,7 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct
net_device *bond_dev)
 	struct slave *tx_slave = NULL;
 
 	tx_slave = bond_xmit_alb_slave_get(bond, skb);
+	alb_set_nd_option(skb, bond, tx_slave);
 	return bond_do_alb_xmit(skb, bond, tx_slave);  }
 
--
1.8.3.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: 回复: [PATCH V2] net: bonding: Add support for IPV6 ns/na
  2021-12-14  1:02 ` 回复: " huyd12
@ 2021-12-14  1:06   ` Jakub Kicinski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2021-12-14  1:06 UTC (permalink / raw)
  To: huyd12; +Cc: sunshouxin, j.vosburgh, vfalico, andy, davem, netdev, linux-kernel

On Tue, 14 Dec 2021 09:02:05 +0800 huyd12@chinatelecom.cn wrote:
> Hi,all
> 
> Any comments will be appreciated.
> thanks a lot.

You'll probably need to fix the build failures and repost.
Some reviewers tend to ignore code with build failures.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] net: bonding: Add support for IPV6 ns/na
  2021-12-10 13:08 [PATCH V2] net: bonding: Add support for IPV6 ns/na Sun Shouxin
                   ` (2 preceding siblings ...)
  2021-12-14  1:02 ` 回复: " huyd12
@ 2021-12-14  8:05 ` Eric Dumazet
  2021-12-20  1:57   ` 孙守鑫
  3 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2021-12-14  8:05 UTC (permalink / raw)
  To: Sun Shouxin, j.vosburgh, vfalico, andy, davem, kuba
  Cc: netdev, linux-kernel, huyd12


On 12/10/21 5:08 AM, Sun Shouxin wrote:
> Since ipv6 neighbor solicitation and advertisement messages
> isn't handled gracefully in bonding6 driver, we can see packet
> drop due to inconsistency bewteen mac address in the option
> message and source MAC .
>
> Another examples is ipv6 neighbor solicitation and advertisement
> messages from VM via tap attached to host brighe, the src mac
> mighe be changed through balance-alb mode, but it is not synced
> with Link-layer address in the option message.
>
> The patch implements bond6's tx handle for ipv6 neighbor
> solicitation and advertisement messages.
>
> 			Border-Leaf
> 			/        \
> 		       /          \
> 		    Tunnel1    Tunnel2
> 		     /              \
> 	            /                \
> 		  Leaf-1--Tunnel3--Leaf-2
> 		    \                /
> 		     \              /
> 		      \            /
> 		       \          /
> 		       NIC1    NIC2
> 			\      /
> 			server
>
> We can see in our lab the Border-Leaf receives occasionally
> a NA packet which is assigned to NIC1 mac in ND/NS option
> message, but actaully send out via NIC2 mac due to tx-alb,
> as a result, it will cause inconsistency between MAC table
> and ND Table in Border-Leaf, i.e, NIC1 = Tunnel2 in ND table
> and  NIC1 = Tunnel1 in mac table.
>
> And then, Border-Leaf starts to forward packet destinated
> to the Server, it will only check the ND table entry in some
> switch to encapsulate the destination MAC of the message as
> NIC1 MAC, and then send it out from Tunnel2 by ND table.
> Then, Leaf-2 receives the packet, it notices the destination
> MAC of message is NIC1 MAC and should forword it to Tunne1
> by Tunnel3.
>
> However, this traffic forward will be failure due to split
> horizon of VxLAN tunnels.
>
> Suggested-by: Hu Yadi <huyd12@chinatelecom.cn>
> Signed-off-by: Sun Shouxin <sunshouxin@chinatelecom.cn>
> ---
>   drivers/net/bonding/bond_alb.c | 131 +++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 131 insertions(+)
>
> diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
> index 533e476..afa386b 100644
> --- a/drivers/net/bonding/bond_alb.c
> +++ b/drivers/net/bonding/bond_alb.c
> @@ -22,6 +22,7 @@
>   #include <asm/byteorder.h>
>   #include <net/bonding.h>
>   #include <net/bond_alb.h>
> +#include <net/ndisc.h>
>   
>   static const u8 mac_v6_allmcast[ETH_ALEN + 2] __long_aligned = {
>   	0x33, 0x33, 0x00, 0x00, 0x00, 0x01
> @@ -1269,6 +1270,119 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
>   	return res;
>   }
>   
> +/*determine if the packet is NA or NS*/
> +static bool alb_determine_nd(struct icmp6hdr *hdr)
> +{
> +	if (hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT ||
> +	    hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
> +static void alb_change_nd_option(struct sk_buff *skb, void *data)
> +{
> +	struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
> +	struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
> +	struct net_device *dev = skb->dev;
> +	struct icmp6hdr *icmp6h = icmp6_hdr(skb);
> +	struct ipv6hdr *ip6hdr = ipv6_hdr(skb);
> +	u8 *lladdr = NULL;
> +	u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
> +				offsetof(struct nd_msg, opt));
> +
> +	while (ndoptlen) {
> +		int l;
> +
> +		switch (nd_opt->nd_opt_type) {
> +		case ND_OPT_SOURCE_LL_ADDR:
> +		case ND_OPT_TARGET_LL_ADDR:
> +		lladdr = ndisc_opt_addr_data(nd_opt, dev);
> +		break;
> +
> +		default:
> +		lladdr = NULL;
> +		break;
> +		}
> +
> +		l = nd_opt->nd_opt_len << 3;
> +
> +		if (ndoptlen < l || l == 0)
> +			return;
> +
> +		if (lladdr) {
> +			memcpy(lladdr, data, dev->addr_len);

I am not sure it is allowed to change skb content without

making sure skb ->head is private.

(Think of tcpdump -i slaveX : we want to see the packet content before 
your change)

I would think skb_cow_head() or something similar is needed.

This is tricky of course, since all cached pointers (icmp6h, ip6hdr, 
msg, nd_opt)

would need to be fetched again, since skb->head/data might be changed

by skb_cow_head().





> +			icmp6h->icmp6_cksum = 0;
> +
> +			icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
> +							      &ip6hdr->daddr,
> +						ntohs(ip6hdr->payload_len),
> +						IPPROTO_ICMPV6,
> +						csum_partial(icmp6h,
> +							     ntohs(ip6hdr->payload_len), 0));
> +		}
> +		ndoptlen -= l;
> +		nd_opt = ((void *)nd_opt) + l;
> +	}
> +}
> +
> +static u8 *alb_get_lladdr(struct sk_buff *skb)
> +{
> +	struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
> +	struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
> +	struct net_device *dev = skb->dev;
> +	u8 *lladdr = NULL;
> +	u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
> +				offsetof(struct nd_msg, opt));
> +
> +	while (ndoptlen) {
> +		int l;
> +
> +		switch (nd_opt->nd_opt_type) {
> +		case ND_OPT_SOURCE_LL_ADDR:
> +		case ND_OPT_TARGET_LL_ADDR:
> +			lladdr = ndisc_opt_addr_data(nd_opt, dev);
> +			break;
> +
> +		default:
> +			break;
> +		}
> +
> +		l = nd_opt->nd_opt_len << 3;
> +
> +		if (ndoptlen < l || l == 0)
> +			return lladdr;

                          return NULL ?

                     (or risk out-of-bound access ?)

> +
> +		if (lladdr)
> +			return lladdr;
> +
> +		ndoptlen -= l;
> +		nd_opt = ((void *)nd_opt) + l;
> +	}
> +
> +	return lladdr;
> +}
> +
> +static void alb_set_nd_option(struct sk_buff *skb, struct bonding *bond,
> +			      struct slave *tx_slave)
> +{
> +	struct ipv6hdr *ip6hdr;
> +	struct icmp6hdr *hdr = NULL;
> +
> +	if (skb->protocol == htons(ETH_P_IPV6)) {
> +		if (tx_slave && tx_slave !=
> +		    rcu_access_pointer(bond->curr_active_slave)) {
> +			ip6hdr = ipv6_hdr(skb);
> +			if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
> +				hdr = icmp6_hdr(skb);
> +				if (alb_determine_nd(hdr))
> +					alb_change_nd_option(skb, tx_slave->dev->dev_addr);
> +			}
> +		}
> +	}
> +}
> +
>   /************************ exported alb functions ************************/
>   
>   int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
> @@ -1415,6 +1529,7 @@ struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
>   	}
>   	case ETH_P_IPV6: {
>   		const struct ipv6hdr *ip6hdr;
> +		struct icmp6hdr *hdr = NULL;
>   
>   		/* IPv6 doesn't really use broadcast mac address, but leave
>   		 * that here just in case.
> @@ -1446,6 +1561,21 @@ struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
>   			break;
>   		}
>   
> +		if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
> +			hdr = icmp6_hdr(skb);
> +			if (alb_determine_nd(hdr)) {
> +				u8 *lladdr = NULL;
> +
> +				lladdr = alb_get_lladdr(skb);
> +				if (lladdr) {
> +					if (!bond_slave_has_mac_rx(bond, lladdr)) {
> +						do_tx_balance = false;
> +						break;
> +					}
> +				}
> +			}
> +		}
> +
>   		hash_start = (char *)&ip6hdr->daddr;
>   		hash_size = sizeof(ip6hdr->daddr);
>   		break;
> @@ -1489,6 +1619,7 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
>   	struct slave *tx_slave = NULL;
>   
>   	tx_slave = bond_xmit_alb_slave_get(bond, skb);
> +	alb_set_nd_option(skb, bond, tx_slave);
>   	return bond_do_alb_xmit(skb, bond, tx_slave);
>   }
>   

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] net: bonding: Add support for IPV6 ns/na
  2021-12-14  8:05 ` Eric Dumazet
@ 2021-12-20  1:57   ` 孙守鑫
  2021-12-20 15:05     ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: 孙守鑫 @ 2021-12-20  1:57 UTC (permalink / raw)
  To: Eric Dumazet, j.vosburgh, vfalico, andy, davem, kuba
  Cc: netdev, linux-kernel, huyd12


在 2021/12/14 16:05, Eric Dumazet 写道:
>
> On 12/10/21 5:08 AM, Sun Shouxin wrote:
>> Since ipv6 neighbor solicitation and advertisement messages
>> isn't handled gracefully in bonding6 driver, we can see packet
>> drop due to inconsistency bewteen mac address in the option
>> message and source MAC .
>>
>> Another examples is ipv6 neighbor solicitation and advertisement
>> messages from VM via tap attached to host brighe, the src mac
>> mighe be changed through balance-alb mode, but it is not synced
>> with Link-layer address in the option message.
>>
>> The patch implements bond6's tx handle for ipv6 neighbor
>> solicitation and advertisement messages.
>>
>>             Border-Leaf
>>             /        \
>>                /          \
>>             Tunnel1    Tunnel2
>>              /              \
>>                 /                \
>>           Leaf-1--Tunnel3--Leaf-2
>>             \                /
>>              \              /
>>               \            /
>>                \          /
>>                NIC1    NIC2
>>             \      /
>>             server
>>
>> We can see in our lab the Border-Leaf receives occasionally
>> a NA packet which is assigned to NIC1 mac in ND/NS option
>> message, but actaully send out via NIC2 mac due to tx-alb,
>> as a result, it will cause inconsistency between MAC table
>> and ND Table in Border-Leaf, i.e, NIC1 = Tunnel2 in ND table
>> and  NIC1 = Tunnel1 in mac table.
>>
>> And then, Border-Leaf starts to forward packet destinated
>> to the Server, it will only check the ND table entry in some
>> switch to encapsulate the destination MAC of the message as
>> NIC1 MAC, and then send it out from Tunnel2 by ND table.
>> Then, Leaf-2 receives the packet, it notices the destination
>> MAC of message is NIC1 MAC and should forword it to Tunne1
>> by Tunnel3.
>>
>> However, this traffic forward will be failure due to split
>> horizon of VxLAN tunnels.
>>
>> Suggested-by: Hu Yadi <huyd12@chinatelecom.cn>
>> Signed-off-by: Sun Shouxin <sunshouxin@chinatelecom.cn>
>> ---
>>   drivers/net/bonding/bond_alb.c | 131 
>> +++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 131 insertions(+)
>>
>> diff --git a/drivers/net/bonding/bond_alb.c 
>> b/drivers/net/bonding/bond_alb.c
>> index 533e476..afa386b 100644
>> --- a/drivers/net/bonding/bond_alb.c
>> +++ b/drivers/net/bonding/bond_alb.c
>> @@ -22,6 +22,7 @@
>>   #include <asm/byteorder.h>
>>   #include <net/bonding.h>
>>   #include <net/bond_alb.h>
>> +#include <net/ndisc.h>
>>     static const u8 mac_v6_allmcast[ETH_ALEN + 2] __long_aligned = {
>>       0x33, 0x33, 0x00, 0x00, 0x00, 0x01
>> @@ -1269,6 +1270,119 @@ static int alb_set_mac_address(struct bonding 
>> *bond, void *addr)
>>       return res;
>>   }
>>   +/*determine if the packet is NA or NS*/
>> +static bool alb_determine_nd(struct icmp6hdr *hdr)
>> +{
>> +    if (hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT ||
>> +        hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
>> +        return true;
>> +    }
>> +
>> +    return false;
>> +}
>> +
>> +static void alb_change_nd_option(struct sk_buff *skb, void *data)
>> +{
>> +    struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
>> +    struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
>> +    struct net_device *dev = skb->dev;
>> +    struct icmp6hdr *icmp6h = icmp6_hdr(skb);
>> +    struct ipv6hdr *ip6hdr = ipv6_hdr(skb);
>> +    u8 *lladdr = NULL;
>> +    u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
>> +                offsetof(struct nd_msg, opt));
>> +
>> +    while (ndoptlen) {
>> +        int l;
>> +
>> +        switch (nd_opt->nd_opt_type) {
>> +        case ND_OPT_SOURCE_LL_ADDR:
>> +        case ND_OPT_TARGET_LL_ADDR:
>> +        lladdr = ndisc_opt_addr_data(nd_opt, dev);
>> +        break;
>> +
>> +        default:
>> +        lladdr = NULL;
>> +        break;
>> +        }
>> +
>> +        l = nd_opt->nd_opt_len << 3;
>> +
>> +        if (ndoptlen < l || l == 0)
>> +            return;
>> +
>> +        if (lladdr) {
>> +            memcpy(lladdr, data, dev->addr_len);
>
> I am not sure it is allowed to change skb content without
>
> making sure skb ->head is private.
>
> (Think of tcpdump -i slaveX : we want to see the packet content before 
> your change)
>
> I would think skb_cow_head() or something similar is needed.
>
> This is tricky of course, since all cached pointers (icmp6h, ip6hdr, 
> msg, nd_opt)
>
> would need to be fetched again, since skb->head/data might be changed
>
> by skb_cow_head().
The tcpdump should show the last packet which sent off from NIC in the end.
could you light me up specific conditions?
>
>
>
>
>
>> +            icmp6h->icmp6_cksum = 0;
>> +
>> +            icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
>> +                                  &ip6hdr->daddr,
>> +                        ntohs(ip6hdr->payload_len),
>> +                        IPPROTO_ICMPV6,
>> +                        csum_partial(icmp6h,
>> +                                 ntohs(ip6hdr->payload_len), 0));
>> +        }
>> +        ndoptlen -= l;
>> +        nd_opt = ((void *)nd_opt) + l;
>> +    }
>> +}
>> +
>> +static u8 *alb_get_lladdr(struct sk_buff *skb)
>> +{
>> +    struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
>> +    struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
>> +    struct net_device *dev = skb->dev;
>> +    u8 *lladdr = NULL;
>> +    u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
>> +                offsetof(struct nd_msg, opt));
>> +
>> +    while (ndoptlen) {
>> +        int l;
>> +
>> +        switch (nd_opt->nd_opt_type) {
>> +        case ND_OPT_SOURCE_LL_ADDR:
>> +        case ND_OPT_TARGET_LL_ADDR:
>> +            lladdr = ndisc_opt_addr_data(nd_opt, dev);
>> +            break;
>> +
>> +        default:
>> +            break;
>> +        }
>> +
>> +        l = nd_opt->nd_opt_len << 3;
>> +
>> +        if (ndoptlen < l || l == 0)
>> +            return lladdr;
>
>                          return NULL ?
>
>                     (or risk out-of-bound access ?)
Thanks your comment, I'll adjust it and send out V4 soon.
>
>> +
>> +        if (lladdr)
>> +            return lladdr;
>> +
>> +        ndoptlen -= l;
>> +        nd_opt = ((void *)nd_opt) + l;
>> +    }
>> +
>> +    return lladdr;
>> +}
>> +
>> +static void alb_set_nd_option(struct sk_buff *skb, struct bonding 
>> *bond,
>> +                  struct slave *tx_slave)
>> +{
>> +    struct ipv6hdr *ip6hdr;
>> +    struct icmp6hdr *hdr = NULL;
>> +
>> +    if (skb->protocol == htons(ETH_P_IPV6)) {
>> +        if (tx_slave && tx_slave !=
>> +            rcu_access_pointer(bond->curr_active_slave)) {
>> +            ip6hdr = ipv6_hdr(skb);
>> +            if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
>> +                hdr = icmp6_hdr(skb);
>> +                if (alb_determine_nd(hdr))
>> +                    alb_change_nd_option(skb, tx_slave->dev->dev_addr);
>> +            }
>> +        }
>> +    }
>> +}
>> +
>>   /************************ exported alb functions 
>> ************************/
>>     int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
>> @@ -1415,6 +1529,7 @@ struct slave *bond_xmit_alb_slave_get(struct 
>> bonding *bond,
>>       }
>>       case ETH_P_IPV6: {
>>           const struct ipv6hdr *ip6hdr;
>> +        struct icmp6hdr *hdr = NULL;
>>             /* IPv6 doesn't really use broadcast mac address, but leave
>>            * that here just in case.
>> @@ -1446,6 +1561,21 @@ struct slave *bond_xmit_alb_slave_get(struct 
>> bonding *bond,
>>               break;
>>           }
>>   +        if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
>> +            hdr = icmp6_hdr(skb);
>> +            if (alb_determine_nd(hdr)) {
>> +                u8 *lladdr = NULL;
>> +
>> +                lladdr = alb_get_lladdr(skb);
>> +                if (lladdr) {
>> +                    if (!bond_slave_has_mac_rx(bond, lladdr)) {
>> +                        do_tx_balance = false;
>> +                        break;
>> +                    }
>> +                }
>> +            }
>> +        }
>> +
>>           hash_start = (char *)&ip6hdr->daddr;
>>           hash_size = sizeof(ip6hdr->daddr);
>>           break;
>> @@ -1489,6 +1619,7 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, 
>> struct net_device *bond_dev)
>>       struct slave *tx_slave = NULL;
>>         tx_slave = bond_xmit_alb_slave_get(bond, skb);
>> +    alb_set_nd_option(skb, bond, tx_slave);
>>       return bond_do_alb_xmit(skb, bond, tx_slave);
>>   }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] net: bonding: Add support for IPV6 ns/na
  2021-12-20  1:57   ` 孙守鑫
@ 2021-12-20 15:05     ` Eric Dumazet
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2021-12-20 15:05 UTC (permalink / raw)
  To: 孙守鑫,
	Eric Dumazet, j.vosburgh, vfalico, andy, davem, kuba
  Cc: netdev, linux-kernel, huyd12


On 12/19/21 5:57 PM, 孙守鑫 wrote:
>
> 在 2021/12/14 16:05, Eric Dumazet 写道:
>>
>> On 12/10/21 5:08 AM, Sun Shouxin wrote:
>>> Since ipv6 neighbor solicitation and advertisement messages
>>> isn't handled gracefully in bonding6 driver, we can see packet
>>> drop due to inconsistency bewteen mac address in the option
>>> message and source MAC .
>>>
>>> Another examples is ipv6 neighbor solicitation and advertisement
>>> messages from VM via tap attached to host brighe, the src mac
>>> mighe be changed through balance-alb mode, but it is not synced
>>> with Link-layer address in the option message.
>>>
>>> The patch implements bond6's tx handle for ipv6 neighbor
>>> solicitation and advertisement messages.
>>>
>>>             Border-Leaf
>>>             /        \
>>>                /          \
>>>             Tunnel1    Tunnel2
>>>              /              \
>>>                 /                \
>>>           Leaf-1--Tunnel3--Leaf-2
>>>             \                /
>>>              \              /
>>>               \            /
>>>                \          /
>>>                NIC1    NIC2
>>>             \      /
>>>             server
>>>
>>> We can see in our lab the Border-Leaf receives occasionally
>>> a NA packet which is assigned to NIC1 mac in ND/NS option
>>> message, but actaully send out via NIC2 mac due to tx-alb,
>>> as a result, it will cause inconsistency between MAC table
>>> and ND Table in Border-Leaf, i.e, NIC1 = Tunnel2 in ND table
>>> and  NIC1 = Tunnel1 in mac table.
>>>
>>> And then, Border-Leaf starts to forward packet destinated
>>> to the Server, it will only check the ND table entry in some
>>> switch to encapsulate the destination MAC of the message as
>>> NIC1 MAC, and then send it out from Tunnel2 by ND table.
>>> Then, Leaf-2 receives the packet, it notices the destination
>>> MAC of message is NIC1 MAC and should forword it to Tunne1
>>> by Tunnel3.
>>>
>>> However, this traffic forward will be failure due to split
>>> horizon of VxLAN tunnels.
>>>
>>> Suggested-by: Hu Yadi <huyd12@chinatelecom.cn>
>>> Signed-off-by: Sun Shouxin <sunshouxin@chinatelecom.cn>
>>> ---
>>>   drivers/net/bonding/bond_alb.c | 131 
>>> +++++++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 131 insertions(+)
>>>
>>> diff --git a/drivers/net/bonding/bond_alb.c 
>>> b/drivers/net/bonding/bond_alb.c
>>> index 533e476..afa386b 100644
>>> --- a/drivers/net/bonding/bond_alb.c
>>> +++ b/drivers/net/bonding/bond_alb.c
>>> @@ -22,6 +22,7 @@
>>>   #include <asm/byteorder.h>
>>>   #include <net/bonding.h>
>>>   #include <net/bond_alb.h>
>>> +#include <net/ndisc.h>
>>>     static const u8 mac_v6_allmcast[ETH_ALEN + 2] __long_aligned = {
>>>       0x33, 0x33, 0x00, 0x00, 0x00, 0x01
>>> @@ -1269,6 +1270,119 @@ static int alb_set_mac_address(struct 
>>> bonding *bond, void *addr)
>>>       return res;
>>>   }
>>>   +/*determine if the packet is NA or NS*/
>>> +static bool alb_determine_nd(struct icmp6hdr *hdr)
>>> +{
>>> +    if (hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT ||
>>> +        hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) {
>>> +        return true;
>>> +    }
>>> +
>>> +    return false;
>>> +}
>>> +
>>> +static void alb_change_nd_option(struct sk_buff *skb, void *data)
>>> +{
>>> +    struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
>>> +    struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
>>> +    struct net_device *dev = skb->dev;
>>> +    struct icmp6hdr *icmp6h = icmp6_hdr(skb);
>>> +    struct ipv6hdr *ip6hdr = ipv6_hdr(skb);
>>> +    u8 *lladdr = NULL;
>>> +    u32 ndoptlen = skb_tail_pointer(skb) - 
>>> (skb_transport_header(skb) +
>>> +                offsetof(struct nd_msg, opt));
>>> +
>>> +    while (ndoptlen) {
>>> +        int l;
>>> +
>>> +        switch (nd_opt->nd_opt_type) {
>>> +        case ND_OPT_SOURCE_LL_ADDR:
>>> +        case ND_OPT_TARGET_LL_ADDR:
>>> +        lladdr = ndisc_opt_addr_data(nd_opt, dev);
>>> +        break;
>>> +
>>> +        default:
>>> +        lladdr = NULL;
>>> +        break;
>>> +        }
>>> +
>>> +        l = nd_opt->nd_opt_len << 3;
>>> +
>>> +        if (ndoptlen < l || l == 0)
>>> +            return;
>>> +
>>> +        if (lladdr) {
>>> +            memcpy(lladdr, data, dev->addr_len);
>>
>> I am not sure it is allowed to change skb content without
>>
>> making sure skb ->head is private.
>>
>> (Think of tcpdump -i slaveX : we want to see the packet content 
>> before your change)
>>
>> I would think skb_cow_head() or something similar is needed.
>>
>> This is tricky of course, since all cached pointers (icmp6h, ip6hdr, 
>> msg, nd_opt)
>>
>> would need to be fetched again, since skb->head/data might be changed
>>
>> by skb_cow_head().
> The tcpdump should show the last packet which sent off from NIC in the 
> end.
> could you light me up specific conditions?


I think I have been clear.

You can not modify skb->head unless it is allowed to.

tcpdump on the slave must show the exact packet being received,

before your modifications in bonding driver.



>>
>>
>>
>>
>>
>>> +            icmp6h->icmp6_cksum = 0;
>>> +
>>> +            icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6hdr->saddr,
>>> +                                  &ip6hdr->daddr,
>>> +                        ntohs(ip6hdr->payload_len),
>>> +                        IPPROTO_ICMPV6,
>>> +                        csum_partial(icmp6h,
>>> + ntohs(ip6hdr->payload_len), 0));
>>> +        }
>>> +        ndoptlen -= l;
>>> +        nd_opt = ((void *)nd_opt) + l;
>>> +    }
>>> +}
>>> +
>>> +static u8 *alb_get_lladdr(struct sk_buff *skb)
>>> +{
>>> +    struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
>>> +    struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)msg->opt;
>>> +    struct net_device *dev = skb->dev;
>>> +    u8 *lladdr = NULL;
>>> +    u32 ndoptlen = skb_tail_pointer(skb) - 
>>> (skb_transport_header(skb) +
>>> +                offsetof(struct nd_msg, opt));
>>> +
>>> +    while (ndoptlen) {
>>> +        int l;
>>> +
>>> +        switch (nd_opt->nd_opt_type) {
>>> +        case ND_OPT_SOURCE_LL_ADDR:
>>> +        case ND_OPT_TARGET_LL_ADDR:
>>> +            lladdr = ndisc_opt_addr_data(nd_opt, dev);
>>> +            break;
>>> +
>>> +        default:
>>> +            break;
>>> +        }
>>> +
>>> +        l = nd_opt->nd_opt_len << 3;
>>> +
>>> +        if (ndoptlen < l || l == 0)
>>> +            return lladdr;
>>
>>                          return NULL ?
>>
>>                     (or risk out-of-bound access ?)
> Thanks your comment, I'll adjust it and send out V4 soon.
>>
>>> +
>>> +        if (lladdr)
>>> +            return lladdr;
>>> +
>>> +        ndoptlen -= l;
>>> +        nd_opt = ((void *)nd_opt) + l;
>>> +    }
>>> +
>>> +    return lladdr;
>>> +}
>>> +
>>> +static void alb_set_nd_option(struct sk_buff *skb, struct bonding 
>>> *bond,
>>> +                  struct slave *tx_slave)
>>> +{
>>> +    struct ipv6hdr *ip6hdr;
>>> +    struct icmp6hdr *hdr = NULL;
>>> +
>>> +    if (skb->protocol == htons(ETH_P_IPV6)) {
>>> +        if (tx_slave && tx_slave !=
>>> +            rcu_access_pointer(bond->curr_active_slave)) {
>>> +            ip6hdr = ipv6_hdr(skb);
>>> +            if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
>>> +                hdr = icmp6_hdr(skb);
>>> +                if (alb_determine_nd(hdr))
>>> +                    alb_change_nd_option(skb, 
>>> tx_slave->dev->dev_addr);
>>> +            }
>>> +        }
>>> +    }
>>> +}
>>> +
>>>   /************************ exported alb functions 
>>> ************************/
>>>     int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
>>> @@ -1415,6 +1529,7 @@ struct slave *bond_xmit_alb_slave_get(struct 
>>> bonding *bond,
>>>       }
>>>       case ETH_P_IPV6: {
>>>           const struct ipv6hdr *ip6hdr;
>>> +        struct icmp6hdr *hdr = NULL;
>>>             /* IPv6 doesn't really use broadcast mac address, but leave
>>>            * that here just in case.
>>> @@ -1446,6 +1561,21 @@ struct slave *bond_xmit_alb_slave_get(struct 
>>> bonding *bond,
>>>               break;
>>>           }
>>>   +        if (ip6hdr->nexthdr == IPPROTO_ICMPV6) {
>>> +            hdr = icmp6_hdr(skb);
>>> +            if (alb_determine_nd(hdr)) {
>>> +                u8 *lladdr = NULL;
>>> +
>>> +                lladdr = alb_get_lladdr(skb);
>>> +                if (lladdr) {
>>> +                    if (!bond_slave_has_mac_rx(bond, lladdr)) {
>>> +                        do_tx_balance = false;
>>> +                        break;
>>> +                    }
>>> +                }
>>> +            }
>>> +        }
>>> +
>>>           hash_start = (char *)&ip6hdr->daddr;
>>>           hash_size = sizeof(ip6hdr->daddr);
>>>           break;
>>> @@ -1489,6 +1619,7 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, 
>>> struct net_device *bond_dev)
>>>       struct slave *tx_slave = NULL;
>>>         tx_slave = bond_xmit_alb_slave_get(bond, skb);
>>> +    alb_set_nd_option(skb, bond, tx_slave);
>>>       return bond_do_alb_xmit(skb, bond, tx_slave);
>>>   }

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-20 15:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-10 13:08 [PATCH V2] net: bonding: Add support for IPV6 ns/na Sun Shouxin
2021-12-10 18:03 ` kernel test robot
2021-12-10 18:13 ` kernel test robot
2021-12-14  1:02 ` 回复: " huyd12
2021-12-14  1:06   ` Jakub Kicinski
2021-12-14  8:05 ` Eric Dumazet
2021-12-20  1:57   ` 孙守鑫
2021-12-20 15:05     ` Eric Dumazet

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).