From patchwork Thu Jul 11 08:44:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1130709 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45kqd56t7Qz9sNT for ; Thu, 11 Jul 2019 18:55:05 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 81FF24CC7; Thu, 11 Jul 2019 08:54:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id CB01F4CB0 for ; Thu, 11 Jul 2019 08:44:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 648EDCF for ; Thu, 11 Jul 2019 08:44:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E426E307D844 for ; Thu, 11 Jul 2019 08:44:48 +0000 (UTC) Received: from dceara.remote.csb (ovpn-117-109.ams2.redhat.com [10.36.117.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B16260603 for ; Thu, 11 Jul 2019 08:44:48 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Thu, 11 Jul 2019 10:44:45 +0200 Message-Id: <20190711084430.15842.49840.stgit@dceara.remote.csb> In-Reply-To: <20190711084413.15842.62313.stgit@dceara.remote.csb> References: <20190711084413.15842.62313.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 11 Jul 2019 08:44:48 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v3 1/3] packets: Add IGMPv3 query packet definitions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Signed-off-by: Dumitru Ceara Acked-by: Mark Michelson --- lib/packets.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/packets.h | 19 ++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/lib/packets.c b/lib/packets.c index a8fd61f..ab0b1a3 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -1281,6 +1281,50 @@ packet_set_icmp(struct dp_packet *packet, uint8_t type, uint8_t code) } } +/* Sets the IGMP type to IGMP_HOST_MEMBERSHIP_QUERY and populates the + * v3 query header fields in 'packet'. 'packet' must be a valid IGMPv3 + * query packet with its l4 offset properly populated. + */ +void +packet_set_igmp3_query(struct dp_packet *packet, uint8_t max_resp, + ovs_be32 group, bool srs, uint8_t qrv, uint8_t qqic) +{ + struct igmpv3_query_header *igh = dp_packet_l4(packet); + ovs_be16 orig_type_max_resp = + htons(igh->type << 8 | igh->max_resp); + ovs_be16 new_type_max_resp = + htons(IGMP_HOST_MEMBERSHIP_QUERY << 8 | max_resp); + + if (orig_type_max_resp != new_type_max_resp) { + igh->type = IGMP_HOST_MEMBERSHIP_QUERY; + igh->max_resp = max_resp; + igh->csum = recalc_csum16(igh->csum, orig_type_max_resp, + new_type_max_resp); + } + + ovs_be32 old_group = get_16aligned_be32(&igh->group); + + if (old_group != group) { + put_16aligned_be32(&igh->group, group); + igh->csum = recalc_csum32(igh->csum, old_group, group); + } + + /* See RFC 3376 4.1.6. */ + if (qrv > 7) { + qrv = 0; + } + + ovs_be16 orig_srs_qrv_qqic = htons(igh->srs_qrv << 8 | igh->qqic); + ovs_be16 new_srs_qrv_qqic = htons(srs << 11 | qrv << 8 | qqic); + + if (orig_srs_qrv_qqic != new_srs_qrv_qqic) { + igh->srs_qrv = (srs << 3 | qrv); + igh->qqic = qqic; + igh->csum = recalc_csum16(igh->csum, orig_srs_qrv_qqic, + new_srs_qrv_qqic); + } +} + void packet_set_nd_ext(struct dp_packet *packet, const ovs_16aligned_be32 rso_flags, const uint8_t opt_type) diff --git a/lib/packets.h b/lib/packets.h index d293b35..4124490 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -681,6 +681,7 @@ char *ip_parse_cidr_len(const char *s, int *n, ovs_be32 *ip, #define IP_ECN_ECT_0 0x02 #define IP_ECN_CE 0x03 #define IP_ECN_MASK 0x03 +#define IP_DSCP_CS6 0xc0 #define IP_DSCP_MASK 0xfc static inline int @@ -763,6 +764,20 @@ struct igmpv3_header { }; BUILD_ASSERT_DECL(IGMPV3_HEADER_LEN == sizeof(struct igmpv3_header)); +#define IGMPV3_QUERY_HEADER_LEN 12 +struct igmpv3_query_header { + uint8_t type; + uint8_t max_resp; + ovs_be16 csum; + ovs_16aligned_be32 group; + uint8_t srs_qrv; + uint8_t qqic; + ovs_be16 nsrcs; +}; +BUILD_ASSERT_DECL( + IGMPV3_QUERY_HEADER_LEN == sizeof(struct igmpv3_query_header +)); + #define IGMPV3_RECORD_LEN 8 struct igmpv3_record { uint8_t type; @@ -1543,7 +1558,9 @@ void packet_set_nd(struct dp_packet *, const struct in6_addr *target, void packet_set_nd_ext(struct dp_packet *packet, const ovs_16aligned_be32 rso_flags, const uint8_t opt_type); - +void packet_set_igmp3_query(struct dp_packet *, uint8_t max_resp, + ovs_be32 group, bool srs, uint8_t qrv, + uint8_t qqic); void packet_format_tcp_flags(struct ds *, uint16_t); const char *packet_tcp_flag_to_string(uint32_t flag); void compose_arp__(struct dp_packet *);