Skip to content

Commit

Permalink
Merge pull request #996 from ywc689/v1.9.8
Browse files Browse the repository at this point in the history
V1.9.8
  • Loading branch information
ywc689 authored Sep 18, 2024
2 parents 6765f6d + b21a018 commit 4c306a4
Show file tree
Hide file tree
Showing 23 changed files with 1,944 additions and 86 deletions.
139 changes: 90 additions & 49 deletions README.md

Large diffs are not rendered by default.

Empty file modified include/sctp/sctp.h
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
From 3e182c106d61863a55e35425e2afefcc222f8f92 Mon Sep 17 00:00:00 2001
From: yuwenchao <[email protected]>
Date: Thu, 1 Aug 2024 17:18:30 +0800
Subject: [PATCH 1/7] kni: use netlink event for multicast (driver part)

Signed-off-by: yuwenchao <[email protected]>
---
kernel/linux/kni/kni_net.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)

diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 779ee34..31e9e39 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -17,6 +17,8 @@
#include <linux/skbuff.h>
#include <linux/kthread.h>
#include <linux/delay.h>
+#include <linux/inetdevice.h>
+#include <net/netlink.h>
#include <linux/rtnetlink.h>

#include <rte_kni_common.h>
@@ -147,6 +149,7 @@
ret_val = wait_event_interruptible_timeout(kni->wq,
kni_fifo_count(kni->resp_q), 3 * HZ);
if (signal_pending(current) || ret_val <= 0) {
+ pr_err("%s: wait_event_interruptible timeout\n", __func__);
ret = -ETIME;
goto fail;
}
@@ -690,6 +693,77 @@ void kni_net_release_fifo_phy(struct kni_dev *kni)
return (ret == 0) ? req.result : ret;
}

+static size_t
+kni_nlmsg_size(void)
+{
+ return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
+ + nla_total_size(4) /* IFA_ADDRESS */
+ + nla_total_size(4) /* IFA_LOCAL */
+ + nla_total_size(4) /* IFA_BROADCAST */
+ + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
+ + nla_total_size(4) /* IFA_FLAGS */
+ + nla_total_size(sizeof(struct ifa_cacheinfo)); /* IFA_CACHEINFO */
+}
+
+static void
+kni_net_set_rx_mode(struct net_device *dev)
+{
+ /*
+ * send event to notify user (DPDK KNI app) that multicast list changed,
+ * so that it can monitor multicast join/leave and set HW mc-addrs to
+ * kni dev accordinglly.
+ *
+ * this event is just an notification, we do not save any mc-addr here
+ * (so attribute space for us). user kni app should get maddrs after
+ * receive this notification.
+ *
+ * I was expecting kernel send some rtnl event for multicast join/leave,
+ * but it doesn't. By checking the call-chain of SIOCADDMULTI (ip maddr,
+ * manages only hardware multicast) and IP_ADD_MEMBERSHIP (ip_mc_join_group,
+ * used to for IPv4 multicast), no rtnl event sent.
+ *
+ * so as workaround, modify kni driver here to send RTM_NEWADDR.
+ * it may not suitalbe to use this event for mcast, but that should works.
+ * hope that won't affect other listener to this event.
+ *
+ * previous solution was using rte_kni_request to pass hw-maddr list to user.
+ * it "works" for times but finally memory corruption found, which is
+ * not easy to address (lock was added and reviewed). That's why we use
+ * netlink event instead.
+ */
+ struct sk_buff *skb;
+ struct net *net = dev_net(dev);
+ struct nlmsghdr *nlh;
+ struct ifaddrmsg *ifm;
+
+ skb = nlmsg_new(kni_nlmsg_size(), GFP_ATOMIC);
+ if (!skb)
+ return;
+
+ /* no other event for us ? */
+ nlh = nlmsg_put(skb, 0, 0, RTM_NEWADDR, sizeof(*ifm), 0);
+ if (!nlh) {
+ kfree_skb(skb);
+ return;
+ }
+
+ /* just send an notification so no other info */
+ ifm = nlmsg_data(nlh);
+ memset(ifm, 0, sizeof(*ifm));
+ ifm->ifa_family = AF_UNSPEC;
+ ifm->ifa_prefixlen = 0;
+ ifm->ifa_flags = 0;
+ ifm->ifa_scope = RT_SCOPE_NOWHERE;
+ ifm->ifa_index = 0;
+
+ nlmsg_end(skb, nlh);
+
+ /* other group ? */
+ pr_debug("%s: rx-mode/multicast-list changed\n", __func__);
+ rtnl_notify(skb, net, 0, RTNLGRP_NOTIFY, NULL, GFP_ATOMIC);
+ return;
+}
+
static void
kni_net_change_rx_flags(struct net_device *netdev, int flags)
{
@@ -791,6 +865,7 @@ void kni_net_release_fifo_phy(struct kni_dev *kni)

ret = kni_net_process_request(netdev, &req);

+ pr_info("%s request returns %d!\n", __func__, ret);
return (ret == 0 ? req.result : ret);
}

@@ -822,6 +897,7 @@ void kni_net_release_fifo_phy(struct kni_dev *kni)
.ndo_change_rx_flags = kni_net_change_rx_flags,
.ndo_start_xmit = kni_net_tx,
.ndo_change_mtu = kni_net_change_mtu,
+ .ndo_set_rx_mode = kni_net_set_rx_mode,
.ndo_tx_timeout = kni_net_tx_timeout,
.ndo_set_mac_address = kni_net_set_mac,
#ifdef HAVE_CHANGE_CARRIER_CB
--
1.8.3.1

Loading

0 comments on commit 4c306a4

Please sign in to comment.