Skip to content

Commit 8f70eab

Browse files
committed
Only set VF L2 address once
1 parent 6f111b8 commit 8f70eab

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

include/dp_iface.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#ifndef __INCLUDE_DP_IFACE_H__
55
#define __INCLUDE_DP_IFACE_H__
66

7+
#include <rte_ether.h>
8+
#include <stdint.h>
79
#include "dp_port.h"
810

911
#ifdef __cplusplus
@@ -23,12 +25,6 @@ int dp_setup_iface(struct dp_port *port, uint32_t vni);
2325
void dp_delete_iface(struct dp_port *port);
2426

2527

26-
static __rte_always_inline
27-
bool dp_arp_cycle_needed(const struct dp_port *port)
28-
{
29-
return port->iface.ready && !port->iface.arp_done;
30-
}
31-
3228
static __rte_always_inline
3329
void dp_fill_ether_hdr(struct rte_ether_hdr *ether_hdr, const struct dp_port *port, uint16_t ether_type)
3430
{

include/dp_port.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdint.h>
88
#include <stdbool.h>
99
#include <net/if.h>
10+
#include <rte_ether.h>
1011
#include <rte_meter.h>
1112
#include <rte_pci.h>
1213
#include <rte_timer.h>
@@ -45,7 +46,7 @@ struct dp_port_iface {
4546
uint32_t nat_ip;
4647
uint16_t nat_port_range[2];
4748
bool ready;
48-
bool arp_done;
49+
bool l2_addr_received;
4950
uint64_t total_flow_rate_cap;
5051
uint64_t public_flow_rate_cap;
5152
uint32_t hostname_len;
@@ -134,6 +135,14 @@ int dp_set_pf_neigh_mac(uint16_t port_id, const struct rte_ether_addr *mac);
134135

135136
int dp_port_meter_config(struct dp_port *port, uint64_t total_flow_rate_cap, uint64_t public_flow_rate_cap);
136137

138+
static __rte_always_inline
139+
bool dp_l2_addr_needed(const struct dp_port *port)
140+
{
141+
return port->iface.ready && !port->iface.l2_addr_received;
142+
}
143+
144+
void dp_l2_addr_set(struct dp_port *port, const struct rte_ether_addr *l2_addr);
145+
137146
static __rte_always_inline
138147
int dp_load_mac(struct dp_port *port)
139148
{

src/dp_periodic_msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void send_to_all_vfs(const struct rte_mbuf *pkt, uint16_t eth_type)
5757
if (eth_type == RTE_ETHER_TYPE_ARP) {
5858
arp_hdr = (struct rte_arp_hdr *)(eth_hdr + 1);
5959
rte_ether_addr_copy(&port->own_mac, &arp_hdr->arp_data.arp_sha);
60-
if (dp_arp_cycle_needed(port))
60+
if (dp_l2_addr_needed(port))
6161
arp_hdr->arp_data.arp_tip = htonl(port->iface.cfg.own_ip);
6262
}
6363

src/dp_port.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static int dp_port_init_ethdev(struct dp_port *port, struct rte_eth_dev_info *de
164164
// guess the inital VM MAC until ARP arrives
165165
if (!port->is_pf) {
166166
rte_ether_addr_copy(&port->own_mac, &port->neigh_mac);
167-
port->iface.arp_done = false;
167+
port->iface.l2_addr_received = false;
168168
}
169169

170170
static_assert(sizeof(port->dev_name) == RTE_ETH_NAME_MAX_LEN, "Incompatible port dev_name size");
@@ -729,3 +729,10 @@ int dp_port_meter_config(struct dp_port *port, uint64_t total_flow_rate_cap, uin
729729

730730
return DP_OK;
731731
}
732+
733+
734+
void dp_l2_addr_set(struct dp_port *port, const struct rte_ether_addr *l2_addr)
735+
{
736+
rte_ether_addr_copy(l2_addr, &port->neigh_mac);
737+
port->iface.l2_addr_received = true;
738+
}

src/nodes/arp_node.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ static __rte_always_inline bool arp_handled(struct rte_mbuf *m)
4242
uint32_t temp_ip;
4343

4444
// ARP reply from VM
45-
if (dp_arp_cycle_needed(port) && sender_ip == htonl(port->iface.cfg.own_ip)) {
46-
rte_ether_addr_copy(&incoming_eth_hdr->src_addr, &port->neigh_mac);
47-
port->iface.arp_done = true;
45+
if (unlikely(dp_l2_addr_needed(port) && sender_ip == htonl(port->iface.cfg.own_ip))) {
46+
dp_l2_addr_set(port, &incoming_eth_hdr->src_addr);
4847
return true;
4948
}
5049

src/nodes/dhcp_node.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ static __rte_always_inline rte_edge_t get_next_index(struct rte_node *node, stru
229229

230230
rte_ether_addr_copy(&incoming_eth_hdr->src_addr, &incoming_eth_hdr->dst_addr);
231231
rte_ether_addr_copy(&port->own_mac, &incoming_eth_hdr->src_addr);
232-
if (response_type == DHCPACK)
233-
rte_ether_addr_copy(&incoming_eth_hdr->dst_addr, &port->neigh_mac);
232+
if (unlikely(response_type == DHCPACK && dp_l2_addr_needed(port)))
233+
dp_l2_addr_set(port, &incoming_eth_hdr->dst_addr);
234234

235235
incoming_ipv4_hdr->src_addr = server_ip;
236236

src/nodes/ipv6_nd_node.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ static __rte_always_inline rte_edge_t get_next_index(__rte_unused struct rte_nod
7676
static_assert(sizeof(nd_msg->target) == sizeof(*gw_ip), "Incompatible IPv6 format in ND message structure");
7777
if (!dp_ipv6_match((const union dp_ipv6 *)nd_msg->target, gw_ip))
7878
return IPV6_ND_NEXT_DROP;
79-
rte_ether_addr_copy(&req_eth_hdr->dst_addr, &port->neigh_mac);
79+
if (unlikely(dp_l2_addr_needed(port)))
80+
dp_l2_addr_set(port, &req_eth_hdr->dst_addr);
8081
dp_copy_ipv6(&port->iface.cfg.own_ipv6, dp_get_dst_ipv6(req_ipv6_hdr));
8182
req_icmp6_hdr->icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
8283
req_icmp6_hdr->icmp6_solicited = 1;

0 commit comments

Comments
 (0)