From 8c69ff34c3786d367503b0867d482067fdff7bd0 Mon Sep 17 00:00:00 2001 From: suchangzhi Date: Wed, 10 Jul 2024 17:03:06 +0800 Subject: [PATCH] flow bifurcation: add query kernel arp table --- 0148-query-kernel-arp-table.patch | 71 +++++++++++++++++++++++++++++++ lwip.spec | 6 ++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 0148-query-kernel-arp-table.patch diff --git a/0148-query-kernel-arp-table.patch b/0148-query-kernel-arp-table.patch new file mode 100644 index 0000000..088fba2 --- /dev/null +++ b/0148-query-kernel-arp-table.patch @@ -0,0 +1,71 @@ +diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c +index 579aa08..305db20 100644 +--- a/src/core/ipv4/etharp.c ++++ b/src/core/ipv4/etharp.c +@@ -75,6 +75,8 @@ + * run out instantly if the timeout occurs directly after a request. + */ + #define ARP_MAXPENDING 5 ++#define ARP_TABLE_PATH "/proc/net/arp" ++#define ARP_TABLE_ENTRY_LEN 256 + + /** ARP states */ + enum etharp_state { +@@ -137,6 +139,7 @@ static err_t etharp_raw(struct netif *netif, + const struct eth_addr *hwsrc_addr, const ip4_addr_t *ipsrc_addr, + const struct eth_addr *hwdst_addr, const ip4_addr_t *ipdst_addr, + const u16_t opcode); ++static err_t etharp_query_kernel(struct netif *netif, const ip4_addr_t *ipaddr); + + #if ARP_QUEUEING + /** +@@ -1017,6 +1020,8 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q) + return result; + } + } ++ /* after sending out arp request, query kernel arp table*/ ++ etharp_query_kernel(netif, ipaddr); + + /* packet given? */ + LWIP_ASSERT("q != NULL", q != NULL); +@@ -1224,6 +1229,40 @@ etharp_request_dst(struct netif *netif, const ip4_addr_t *ipaddr, const struct e + ipaddr, ARP_REQUEST); + } + ++static err_t ++etharp_query_kernel(struct netif *netif, const ip4_addr_t *ipaddr) ++{ ++ FILE *arp_table; ++ char line[ARP_TABLE_ENTRY_LEN], ipaddr_tlb[ARP_TABLE_ENTRY_LEN], macaddr_tlb[ARP_TABLE_ENTRY_LEN]; ++ ip4_addr_t ipaddr_tmp; ++ ip4_addr_t mask = { ++ .addr = IPADDR_NONE, ++ }; ++ struct eth_addr ethaddr; ++ ++ arp_table = fopen(ARP_TABLE_PATH, "r"); ++ if (arp_table == NULL) { ++ LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query_kernel: could not open kernel arp table.\n")); ++ return ERR_TIMEOUT; ++ } ++ if (fgets(line, ARP_TABLE_ENTRY_LEN, arp_table) == NULL) { ++ LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query_kernel: could not read header.\n")); ++ return ERR_TIMEOUT; ++ } ++ while (fgets(line, ARP_TABLE_ENTRY_LEN, arp_table) != NULL) { ++ sscanf(line, "%s%*s%*s%s", ipaddr_tlb, macaddr_tlb); ++ ip4addr_aton(ipaddr_tlb, &ipaddr_tmp); ++ if (ip4_addr_net_eq(&ipaddr_tmp, ipaddr, &mask)) { ++ sscanf(macaddr_tlb, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", ++ ðaddr.addr[0], ðaddr.addr[1], ðaddr.addr[2], ++ ðaddr.addr[3], ðaddr.addr[4], ðaddr.addr[5]); ++ etharp_update_arp_entry(netif, ipaddr, ðaddr, ETHARP_FLAG_TRY_HARD); ++ break; ++ } ++ } ++ return ERR_OK; ++} ++ + /** + * Send an ARP request packet asking for ipaddr. + * diff --git a/lwip.spec b/lwip.spec index 643b4f3..af7ba81 100644 --- a/lwip.spec +++ b/lwip.spec @@ -4,7 +4,7 @@ Summary: lwip is a small independent implementation of the TCP/IP protocol suite Name: lwip Version: 2.2.0 -Release: 39 +Release: 40 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -159,6 +159,7 @@ Patch9143: 0144-add-MCAST_MSFILTER-in-setsockopt-for-MLDv2-of-IPv6.patch Patch9144: 0145-cleancode-improving-makefile-readability.patch Patch9145: 0146-cleancode-remove-perf.patch Patch9146: 0147-cleancode-rename-gazelle-files-in-lwip.patch +Patch9147: 0148-query-kernel-arp-table.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -188,6 +189,9 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Wed Jul 10 2024 suchangzhi - 2.2.0-40 +- flow bifurcation: add query kernel arp table + * Tue Jul 9 2024 LemmyHuang - 2.2.0-39 - cleancode: rename gazelle files in lwip -- Gitee