From ecd34ae9a277d96c30a4ee88f6e13437470cd9db Mon Sep 17 00:00:00 2001 From: Qiuwen Lu Date: Thu, 28 May 2020 14:48:56 +0800 Subject: 修正构建NSH外层以太网头部时,未交换源、目的MAC地址的问题。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tunnat/src/tunnel.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tunnat/src/tunnel.cc b/tunnat/src/tunnel.cc index 58ff892..295286f 100644 --- a/tunnat/src/tunnel.cc +++ b/tunnat/src/tunnel.cc @@ -1092,6 +1092,12 @@ int TunNSH::PacketConstruct(const char * pkt, unsigned int pkt_len) struct ether_hdr * eth_hdr = (struct ether_hdr *) pkt; *eth_hdr = eth_hdr_; + /* 交换MAC源、目的地址 */ + struct ether_addr __swap_ether_addr; + ether_addr_copy(ð_hdr->s_addr, &__swap_ether_addr); + ether_addr_copy(ð_hdr->d_addr, ð_hdr->s_addr); + ether_addr_copy(&__swap_ether_addr, ð_hdr->d_addr); + unsigned int offset = 0; pkt += sizeof(struct ether_hdr); offset += sizeof(struct ether_hdr); @@ -1116,6 +1122,12 @@ int TunNSH::PacketForwardModify(const char * pkt, unsigned int pkt_len) return RT_ERR; } + /* 交换MAC源、目的地址 */ + struct ether_addr __swap_ether_addr; + ether_addr_copy(ð_hdr->s_addr, &__swap_ether_addr); + ether_addr_copy(ð_hdr->d_addr, ð_hdr->s_addr); + ether_addr_copy(&__swap_ether_addr, ð_hdr->d_addr); + unsigned int offset = 0; pkt += sizeof(struct ether_hdr); offset += sizeof(struct ether_hdr); -- cgit v1.2.3