[ovs-dev,v2,1/3] packets: Add IGMPv3 query packet definitions
diff mbox series

Message ID 20190709124900.6460.2100.stgit@dceara.remote.csb
State Superseded
Headers show
Series
  • OVN: Add IGMP support
Related show

Commit Message

Dumitru Ceara July 9, 2019, 12:49 p.m. UTC
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
---
 lib/packets.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 lib/packets.h |   19 ++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletion(-)

Patch
diff mbox series

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 *);