Skip to content

Commit

Permalink
packets: Add IGMPv3 query packet definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Dumitru Ceara <[email protected]>
Acked-by: Mark Michelson <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
dceara authored and blp committed Jul 16, 2019
1 parent 6778f24 commit 1db4445
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
44 changes: 44 additions & 0 deletions lib/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion lib/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 *);
Expand Down

0 comments on commit 1db4445

Please sign in to comment.