Skip to content

Commit

Permalink
fix unable to receive igmp query
Browse files Browse the repository at this point in the history
Signed-off-by: Ric Li <[email protected]>
  • Loading branch information
ricmli committed Dec 6, 2023
1 parent 1748055 commit 37f7526
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
20 changes: 12 additions & 8 deletions lib/src/mt_cni.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ static int cni_rx_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) {
struct mt_ptp_header* ptp_hdr;
struct rte_arp_hdr* arp_hdr;
struct mt_dhcp_hdr* dhcp_hdr;
struct mt_ipv4_udp* ipv4_hdr;
struct rte_ipv4_hdr* ipv4_hdr;
struct rte_udp_hdr* udp_hdr;
size_t hdr_offset = sizeof(struct rte_ether_hdr);

// mt_mbuf_dump_hdr(port, 0, "cni_rx", m);
Expand Down Expand Up @@ -238,27 +239,30 @@ static int cni_rx_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) {
}
break;
case RTE_ETHER_TYPE_IPV4:
ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ipv4_udp*, hdr_offset);
hdr_offset += sizeof(struct mt_ipv4_udp);
if (ipv4_hdr->ip.next_proto_id == IPPROTO_UDP) {
src_port = ntohs(ipv4_hdr->udp.src_port);
ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr*, hdr_offset);
hdr_offset += ipv4_hdr->ihl * 4; /* may have ip option field */
if (ipv4_hdr->next_proto_id == IPPROTO_UDP) {
udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr*, hdr_offset);
hdr_offset += sizeof(struct rte_udp_hdr);
src_port = ntohs(udp_hdr->src_port);
if (ptp && (src_port == MT_PTP_UDP_EVENT_PORT ||
src_port == MT_PTP_UDP_GEN_PORT)) { /* ptp pkt*/
dbg("%s(%d), ptp msg src_port %u\n", __func__, port, src_port);
ptp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header*, hdr_offset);
mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L4, m->timesync, ipv4_hdr);
mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L4, m->timesync,
(struct mt_ipv4_udp*)ipv4_hdr);
} else if (dhcp && src_port == MT_DHCP_UDP_SERVER_PORT) { /* dhcp pkt */
dhcp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_dhcp_hdr*, hdr_offset);
mt_dhcp_parse(impl, dhcp_hdr, port);
} else {
cni_udp_handle(cni, m);
}
} else if (ipv4_hdr->ip.next_proto_id == IPPROTO_IGMP) {
} else if (ipv4_hdr->next_proto_id == IPPROTO_IGMP) {
struct mcast_mb_query_v3* mb_query =
rte_pktmbuf_mtod_offset(m, struct mcast_mb_query_v3*, hdr_offset);
mt_mcast_parse(impl, mb_query, port);
} else {
/* ipv4 packets other than UDP fallback to kernel */
/* ipv4 packets other than UDP/IGMP fallback to kernel */
cni_burst_to_kernel(cni, m);
}
break;
Expand Down
17 changes: 14 additions & 3 deletions lib/src/mt_mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ static int mcast_inf_remove_mac(struct mt_interface* inf,
return rte_eth_dev_mac_addr_remove(port_id, mcast_mac);
}

/* 224.0.0.1 */
static struct rte_ether_addr mcast_mac_all = {{0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}};

int mt_mcast_init(struct mtl_main_impl* impl) {
int num_ports = mt_num_ports(impl);
int socket = mt_socket_id(impl, MTL_PORT_P);
Expand All @@ -461,6 +464,9 @@ int mt_mcast_init(struct mtl_main_impl* impl) {

/* assign mcast instance */
impl->mcast[i] = mcast;

if (!mt_drv_use_kernel_ctl(impl, i))
mcast_inf_add_mac(mt_if(impl, i), &mcast_mac_all);
}

int ret =
Expand Down Expand Up @@ -503,6 +509,9 @@ int mt_mcast_uinit(struct mtl_main_impl* impl) {
struct mt_mcast_impl* mcast = get_mcast(impl, i);
if (!mcast) continue;

if (!mt_drv_use_kernel_ctl(impl, i))
mcast_inf_remove_mac(mt_if(impl, i), &mcast_mac_all);

/* clear group list */
mcast_group_clear(&mcast->group_list);

Expand Down Expand Up @@ -739,13 +748,15 @@ int mt_mcast_parse(struct mtl_main_impl* impl, struct mcast_mb_query_v3* query,
return -EIO;
}

uint16_t query_checksum = ntohs(query->checksum);
query->checksum = 0;
uint16_t checksum = mcast_msg_checksum(MEMBERSHIP_QUERY, query, 0);
if (checksum != ntohs(query->checksum)) {
err("%s, err checksum %d:%d\n", __func__, ntohs(query->checksum), checksum);
if (checksum != query_checksum) {
err("%s, err checksum %d:%d\n", __func__, query_checksum, checksum);
return -EIO;
}

info("%s, received igmp query\n", __func__);
info_once("%s, received igmp query\n", __func__);
/* stop auto-join if there is query server */
struct mt_mcast_impl* mcast = get_mcast(impl, port);
mcast->has_external_query = true;
Expand Down
1 change: 0 additions & 1 deletion lib/src/mt_mcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ enum mcast_group_record_type {
enum mcast_action_type {
MCAST_JOIN = 0,
MCAST_LEAVE,
MCAST_ON_QUERY,
};

struct mcast_group_record {
Expand Down

0 comments on commit 37f7526

Please sign in to comment.