From: Martijn van Oosterhout Subject: AF_PACKET fanout not working on MPLS traffic Date: Mon, 14 Jan 2019 19:40:46 +0100 Message-ID: <20190114184046.GA22481@svana.org> Reply-To: Martijn van Oosterhout Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="h31gzZEtNLTqOjlF" To: netdev@vger.kernel.org Return-path: Received: from svana.org ([113.212.99.187]:56199 "EHLO svana.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbfANTLY (ORCPT ); Mon, 14 Jan 2019 14:11:24 -0500 Received: from kleptog by svana.org with local (Exim 4.84_2) (envelope-from ) id 1gj7AF-0005zu-3K for netdev@vger.kernel.org; Tue, 15 Jan 2019 05:40:49 +1100 Content-Disposition: inline Sender: netdev-owner@vger.kernel.org List-ID: --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi netdev, We're running into an issue where incoming traffic for Suricata is not being distributed across the workers despite AF_PACKET with fanout being used, and it appears to be a kernel issue. Below is a description of the problem and possible solution. Seen on version kernel 4.19, but the code on 4.20 seem largely unchanged. When a packet needs to be distributed by fanout it calls net/packet/af_packet.c:fanout_demux_hash which in turns calls net/core/flow_dissector.c:__skb_get_hash_symmetric which in turn calls net/core/flow_dissector.c:__skb_flow_dissect. However, if you look at the code that parses MPLS traffic it looks like so: --- snip --- net/core/flow_dissector.c:1023 case htons(ETH_P_MPLS_UC): case htons(ETH_P_MPLS_MC): fdret =3D __skb_flow_dissect_mpls(skb, flow_dissector, target_container, data, nhoff, hlen); break; --- snip --- What's going on here is that the dissector goes to extract the MPLS flow information and then stops (it returns either GOOD or BAD here). However because flow_keys_dissector_symmetric does not include FLOW_DISSECTOR_KEY_MPLS no information is extracted at all, with the result that the hash is always the same for every packet. I see a two ways this could be fixed. Option 1: include FLOW_DISSECTOR_KEY_MPLS in flow_keys_dissector_symmetric but that seems a big assumption, we don't do that for VLANs for example. Option 2: Teach the dissector to, in the case where there is an MPLS header that is not for entropy, to skip the MPLS header(s) and continue the dissection on the IP headers that come after the MPLS header. I think option 2 seems to me the right approach, however the dissector (AFAICT) is used extensively from many places in the kernel so I'd like some confirmation before spending too much time on it. It seems like it could lead to an unexpected performance impact on systems using MPLS. Or perhaps there is something else going on I missed. And there is actually another problem: MPLS provides no information about the next header because it assumes the endpoints in the network recognise the MPLS headers. Which means you'd have to make a guess about what the next layer should be. Any ideas? Is this the right approach? Thanks in advance, --=20 Martijn van Oosterhout http://svana.org/kleptog/ > The combine: one man, one day, wheat for half a million loaves of bread. --h31gzZEtNLTqOjlF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIVAwUBXDzXrUvt++dL5i1EAQgF7A/9HpVtkg0YFsL8ftFiZaZuOv8w8w9Db4zh afTbNitZgVzgKxmhUgvi8Y2d0PNBIuXwWr4EIIOIT7Jcp9zcGB6spvSUuoXmME+/ 2YWHxjs9AhnC8DFbDmsXi8CybWQGmuAS+V0i6Yn1LtnXeLOw/Y50zKsEDrYkSRxD KtbiVKh1gJKmI20rXjaDr/dM0x8plwp8F/dyLjjTk5Ld1xmn2DQEDFi56BzZJXDU b0Uh9Y0g5Qj4yGs2g81hOrPHsdxoCytRHxeSgT1t7H9DVC/CYEs/JC5GZirhZV1j qBZF8BVI4OekKy8HJxg2DC3y/IJRH9OspKgLxY73yen2g4TXgRaux69qiYTauFtl vVdGYxyWFMesUJ/j5ts9G+aUpAvprEstAMhI6qWQNWvzCxUajY+DjqC7ROSaB3Cq TM0lg+/qP94jm1cbaiOhaNcO6GmN1B21Z7Ey5d9mkFGRI+I4/JfplR8xuPtH91tP mOSG19/c8i3PRPQVHAFmi33Lpqc0FwUW5Qk+/zet6/kttz6Go90OSXyoj+IGfp26 FjObFFhu0y+7kkGXtDy9CIceFvHNQqT7kB1DdhD/aGqJnw6UrkrGhZeMjy8+Vp9u PPVKo/7ALTnCnbHD96uoFtoD7f1Yok43JcMFHoNP2QA5wvx/VHc+jKN8llS8Z37m Y4Y8f3WsAnk= =puHE -----END PGP SIGNATURE----- --h31gzZEtNLTqOjlF--