From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9FF42A04EF; Mon, 1 Jun 2020 05:13:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 967831D416; Mon, 1 Jun 2020 05:13:24 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 7E8151D416 for ; Mon, 1 Jun 2020 05:13:22 +0200 (CEST) IronPort-SDR: kh+XZZJ9tOQLkWxaBLo1FauRpgAN6iBjSiKyrL/DGGhWWxFN1TxlVjyzLo6S608ydaVmBAm26g XZZAqosBzl4g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2020 20:13:21 -0700 IronPort-SDR: leWTq2pJ8Swv3tBRYAPhAFO2TVqomoHWr14etKRqr7z63HwxxbtXcfa9+FmycALvaFs+AohDGb c8hiHasiOrOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,459,1583222400"; d="scan'208";a="293041427" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga004.fm.intel.com with ESMTP; 31 May 2020 20:13:21 -0700 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 31 May 2020 20:13:20 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 31 May 2020 20:13:21 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.85]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.208]) with mapi id 14.03.0439.000; Mon, 1 Jun 2020 11:13:18 +0800 From: "Tu, Lijuan" To: "Lu, Nannan" , "dts@dpdk.org" CC: "Lu, Nannan" Thread-Topic: [dts] [PATCH V1 1/5] dep: add igmp.py to dep Thread-Index: AQHWMn8ETNnU3o4gM0uPeEwi+5mUfajDICXg Date: Mon, 1 Jun 2020 03:13:17 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BC56606@SHSMSX101.ccr.corp.intel.com> References: <20200525181003.25229-1-nannan.lu@intel.com> In-Reply-To: <20200525181003.25229-1-nannan.lu@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1 1/5] dep: add igmp.py to dep X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" Applied the series, thanks > -----Original Message----- > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Nannan Lu > Sent: Tuesday, May 26, 2020 2:10 AM > To: dts@dpdk.org > Cc: Lu, Nannan > Subject: [dts] [PATCH V1 1/5] dep: add igmp.py to dep >=20 > Add igmp.py to dep so that dts supports > sending igmp packets. >=20 > Signed-off-by: Nannan Lu > --- > dep/igmp.py | 164 > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 164 insertions(+) > create mode 100644 dep/igmp.py >=20 > diff --git a/dep/igmp.py b/dep/igmp.py > new file mode 100644 > index 0000000..5cbf9c0 > --- /dev/null > +++ b/dep/igmp.py > @@ -0,0 +1,164 @@ > +#! /usr/bin/env python > + > +# This file is part of Scapy > +# Scapy is free software: you can redistribute it and/or modify # it > +under the terms of the GNU General Public License as published by # the > +Free Software Foundation, either version 2 of the License, or # any > +later version. > +# > +# Scapy is distributed in the hope that it will be useful, # but > +WITHOUT ANY WARRANTY; without even the implied warranty of # > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU > +General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License # > +along with Scapy. If not, see . > + > +# flake8: noqa: E501 > + > +# scapy.contrib.description =3D Internet Group Management Protocol v1/v2 > +(IGMP/IGMPv2) # scapy.contrib.status =3D loads > + > +from __future__ import print_function > +from scapy.compat import chb, orb > +from scapy.error import warning > +from scapy.fields import ByteEnumField, ByteField, IPField, XShortField > +from scapy.layers.inet import IP, IPOption_Router_Alert from > +scapy.layers.l2 import Ether, getmacbyip from scapy.packet import > +bind_layers, Packet from scapy.utils import atol, checksum > + > + > +def isValidMCAddr(ip): > + """convert dotted quad string to long and check the first octet""" > + FirstOct =3D atol(ip) >> 24 & 0xFF > + return (FirstOct >=3D 224) and (FirstOct <=3D 239) > + > + > +class IGMP(Packet): > + """IGMP Message Class for v1 and v2. > + > +This class is derived from class Packet. You need call "igmpize()" > +so the packet is transformed according the RFC when sent. > +a=3DEther(src=3D"00:01:02:03:04:05") > +b=3DIP(src=3D"1.2.3.4") > +c=3DIGMP(type=3D0x12, gaddr=3D"224.2.3.4") > +x =3D a/b/c > +x[IGMP].igmpize() > +sendp(a/b/c, iface=3D"en0") > + > + Parameters: > + type IGMP type field, 0x11, 0x12, 0x16 or 0x17 > + mrcode Maximum Response time (zero for v1) > + gaddr Multicast Group Address 224.x.x.x/4 > + > +See RFC2236, Section 2. Introduction for definitions of proper > +IGMPv2 message format http://www.faqs.org/rfcs/rfc2236.html > + > + """ > + name =3D "IGMP" > + > + igmptypes =3D {0x11: "Group Membership Query", > + 0x12: "Version 1 - Membership Report", > + 0x16: "Version 2 - Membership Report", > + 0x17: "Leave Group"} > + > + fields_desc =3D [ByteEnumField("type", 0x11, igmptypes), > + ByteField("mrcode", 20), > + XShortField("chksum", None), > + IPField("gaddr", "0.0.0.0")] > + > + def post_build(self, p, pay): > + """Called implicitly before a packet is sent to compute and plac= e IGMP > checksum. > + > + Parameters: > + self The instantiation of an IGMP class > + p The IGMP message in hex in network byte order > + pay Additional payload for the IGMP message > + """ > + p +=3D pay > + if self.chksum is None: > + ck =3D checksum(p) > + p =3D p[:2] + chb(ck >> 8) + chb(ck & 0xff) + p[4:] > + return p > + > + @classmethod > + def dispatch_hook(cls, _pkt=3DNone, *args, **kargs): > + if _pkt and len(_pkt) >=3D 4: > + from scapy.contrib.igmpv3 import IGMPv3 > + if orb(_pkt[0]) in [0x22, 0x30, 0x31, 0x32]: > + return IGMPv3 > + if orb(_pkt[0]) =3D=3D 0x11 and len(_pkt) >=3D 12: > + return IGMPv3 > + return IGMP > + > + def igmpize(self): > + """Called to explicitly fixup the packet according to the IGMP > + RFC > + > + The rules are: > + General: > + 1. the Max Response time is meaningful only in Membership Q= ueries > and should be zero > + IP: > + 1. Send General Group Query to 224.0.0.1 (all systems) > + 2. Send Leave Group to 224.0.0.2 (all routers) > + 3a.Otherwise send the packet to the group address > + 3b.Send reports/joins to the group address > + 4. ttl =3D 1 (RFC 2236, section 2) > + 5. send the packet with the router alert IP option (RFC 2236= , section 2) > + Ether: > + 1. Recalculate destination > + > + Returns: > + True The tuple ether/ip/self passed all check and represe= nts > + a proper IGMP packet. > + False One of more validation checks failed and no fields > + were adjusted. > + > + The function will examine the IGMP message to assure proper form= at. > + Corrections will be attempted if possible. The IP header is then= properly > + adjusted to ensure correct formatting and assignment. The Ethern= et > header > + is then adjusted to the proper IGMP packet format. > + """ > + gaddr =3D self.gaddr if hasattr(self, "gaddr") and self.gaddr el= se "0.0.0.0" > # noqa: E501 > + underlayer =3D self.underlayer > + if self.type not in [0x11, 0x30]: = # General Rule 1 # noqa: > E501 > + self.mrcode =3D 0 > + if isinstance(underlayer, IP): > + if (self.type =3D=3D 0x11): > + if (gaddr =3D=3D "0.0.0.0"): > + underlayer.dst =3D "224.0.0.1" = # IP rule 1 # noqa: > E501 > + elif isValidMCAddr(gaddr): > + underlayer.dst =3D gaddr = # IP rule 3a # noqa: E501 > + else: > + warning("Invalid IGMP Group Address detected !") > + return False > + elif ((self.type =3D=3D 0x17) and isValidMCAddr(gaddr)): > + underlayer.dst =3D "224.0.0.2" = # IP rule 2 # noqa: E501 > + elif ((self.type =3D=3D 0x12) or (self.type =3D=3D 0x16)) an= d > (isValidMCAddr(gaddr)): # noqa: E501 > + underlayer.dst =3D gaddr = # IP rule 3b # noqa: E501 > + else: > + warning("Invalid IGMP Type detected !") > + return False > + if not any(isinstance(x, IPOption_Router_Alert) for x in > underlayer.options): # noqa: E501 > + underlayer.options.append(IPOption_Router_Alert()) > + underlayer.ttl =3D 1 = # IP rule 4 > + _root =3D self.firstlayer() > + if _root.haslayer(Ether): > + # Force recalculate Ether dst > + _root[Ether].dst =3D getmacbyip(underlayer.dst) = # Ether rule 1 # > noqa: E501 > + from scapy.contrib.igmpv3 import IGMPv3 > + if isinstance(self, IGMPv3): > + self.encode_maxrespcode() > + return True > + > + def mysummary(self): > + """Display a summary of the IGMP object.""" > + if isinstance(self.underlayer, IP): > + return > self.underlayer.sprintf("IGMP: %IP.src% > %IP.dst% %IGMP.type% %IGMP.ga > ddr%") # noqa: E501 > + else: > + return self.sprintf("IGMP %IGMP.type% %IGMP.gaddr%") > + > + > +bind_layers(IP, IGMP, frag=3D0, > + proto=3D2, > + ttl=3D1) > -- > 2.17.1