Skip to content

Commit

Permalink
Moved ether addresses directly to port structure
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueCZ committed Nov 15, 2023
1 parent 5ece1e1 commit ec30bf5
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 36 deletions.
3 changes: 1 addition & 2 deletions include/dp_firewall.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ struct dp_fwall_rule {
TAILQ_ENTRY(dp_fwall_rule) next_rule;
};

// forward-declaration due to 'struct dp_fwall_rule' being part of 'struct dp_grpc_responder'
// forward-declaration due to 'struct dp_fwall_rule' being part of these structures
struct dp_grpc_responder;
// dtto for 'struct vm_entry' which is part of 'struct dp_port'
struct dp_port;

void dp_init_firewall_rules(struct dp_port *port);
Expand Down
14 changes: 7 additions & 7 deletions include/dp_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ extern "C" {

#define VM_IFACE_ID_MAX_LEN 64

struct macip_entry {
struct rte_ether_addr own_mac;
struct rte_ether_addr neigh_mac;
struct dp_port_ips {
uint32_t own_ip;
uint32_t neigh_ip;
uint8_t depth;
Expand All @@ -28,9 +26,9 @@ struct macip_entry {
char pxe_str[VM_MACHINE_PXE_MAX_LEN];
};

struct vm_entry {
struct dp_port_vm {
struct dp_fwall_head fwall_head;
struct macip_entry info;
struct dp_port_ips info;
uint32_t vni;
char machineid[VM_IFACE_ID_MAX_LEN];
uint8_t ul_ipv6[16];
Expand All @@ -49,7 +47,9 @@ struct dp_port {
uint8_t peer_pf_hairpin_tx_rx_queue_offset;
uint16_t peer_pf_port_id;
bool attached;
struct vm_entry vm;
struct rte_ether_addr own_mac;
struct rte_ether_addr neigh_mac;
struct dp_port_vm vm;
struct rte_flow *default_jump_flow;
struct rte_flow *default_capture_flow;
bool captured;
Expand Down Expand Up @@ -81,7 +81,7 @@ int dp_stop_port(struct dp_port *port);
static __rte_always_inline
int dp_load_mac(struct dp_port *port)
{
return rte_eth_macaddr_get(port->port_id, &port->vm.info.own_mac);
return rte_eth_macaddr_get(port->port_id, &port->own_mac);
}

static __rte_always_inline
Expand Down
6 changes: 3 additions & 3 deletions include/dp_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ bool dp_arp_cycle_needed(const struct dp_port *port)
static struct rte_ether_addr nul_mac = {0};

return port->vm.ready
&& rte_is_same_ether_addr(&port->vm.info.neigh_mac, &nul_mac);
&& rte_is_same_ether_addr(&port->neigh_mac, &nul_mac);
}

static __rte_always_inline
void dp_fill_ether_hdr(struct rte_ether_hdr *ether_hdr, const struct dp_port *port, uint16_t ether_type)
{
rte_ether_addr_copy(&port->vm.info.neigh_mac, &ether_hdr->dst_addr);
rte_ether_addr_copy(&port->vm.info.own_mac, &ether_hdr->src_addr);
rte_ether_addr_copy(&port->neigh_mac, &ether_hdr->dst_addr);
rte_ether_addr_copy(&port->own_mac, &ether_hdr->src_addr);
ether_hdr->ether_type = htons(ether_type);
}

Expand Down
6 changes: 2 additions & 4 deletions src/dp_periodic_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void send_to_all_vfs(const struct rte_mbuf *pkt, uint16_t eth_type)
struct dp_dpdk_layer *dp_layer = get_dpdk_layer();
const struct dp_ports *ports = dp_get_ports();
struct rte_mbuf *clone_buf;
const struct rte_ether_addr *mac;
int ret;

DP_FOREACH_PORT(ports, port) {
Expand All @@ -37,12 +36,11 @@ void send_to_all_vfs(const struct rte_mbuf *pkt, uint16_t eth_type)
clone_buf->port = port->port_id;
eth_hdr = rte_pktmbuf_mtod(clone_buf, struct rte_ether_hdr *);

mac = &port->vm.info.own_mac;
rte_ether_addr_copy(mac, &eth_hdr->src_addr);
rte_ether_addr_copy(&port->own_mac, &eth_hdr->src_addr);

if (eth_type == RTE_ETHER_TYPE_ARP) {
arp_hdr = (struct rte_arp_hdr *)(eth_hdr + 1);
rte_ether_addr_copy(mac, &arp_hdr->arp_data.arp_sha);
rte_ether_addr_copy(&port->own_mac, &arp_hdr->arp_data.arp_sha);
if (dp_arp_cycle_needed(port))
arp_hdr->arp_data.arp_tip = htonl(port->vm.info.own_ip);
}
Expand Down
4 changes: 2 additions & 2 deletions src/dp_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ static int dp_port_init_ethdev(struct dp_port *port, struct rte_eth_dev_info *de
rte_eth_dev_get_name_by_port(port->port_id, port->dev_name);

if (port->is_pf) {
if (DP_FAILED(dp_get_pf_neigh_mac(dev_info->if_index, &pf_neigh_mac, &port->vm.info.own_mac)))
if (DP_FAILED(dp_get_pf_neigh_mac(dev_info->if_index, &pf_neigh_mac, &port->own_mac)))
return DP_ERROR;
rte_ether_addr_copy(&pf_neigh_mac, &port->vm.info.neigh_mac);
rte_ether_addr_copy(&pf_neigh_mac, &port->neigh_mac);
}

return DP_OK;
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/arp_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static __rte_always_inline bool arp_handled(struct rte_mbuf *m)

// ARP reply from VM
if (dp_arp_cycle_needed(port) && sender_ip == htonl(port->vm.info.own_ip)) {
rte_ether_addr_copy(&incoming_eth_hdr->src_addr, &port->vm.info.neigh_mac);
rte_ether_addr_copy(&incoming_eth_hdr->src_addr, &port->neigh_mac);
return true;
}

Expand All @@ -50,9 +50,9 @@ static __rte_always_inline bool arp_handled(struct rte_mbuf *m)

// respond back to origin address from this address (reuse the packet)
rte_ether_addr_copy(&incoming_arp_hdr->arp_data.arp_sha, &incoming_eth_hdr->dst_addr);
rte_ether_addr_copy(&port->vm.info.own_mac, &incoming_eth_hdr->src_addr);
rte_ether_addr_copy(&port->own_mac, &incoming_eth_hdr->src_addr);
rte_ether_addr_copy(&incoming_arp_hdr->arp_data.arp_sha, &tmp_addr);
rte_ether_addr_copy(&port->vm.info.own_mac, &incoming_arp_hdr->arp_data.arp_sha);
rte_ether_addr_copy(&port->own_mac, &incoming_arp_hdr->arp_data.arp_sha);
rte_ether_addr_copy(&tmp_addr, &incoming_arp_hdr->arp_data.arp_tha);
temp_ip = incoming_arp_hdr->arp_data.arp_sip;
incoming_arp_hdr->arp_data.arp_sip = incoming_arp_hdr->arp_data.arp_tip;
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/dhcp_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ static __rte_always_inline rte_edge_t get_next_index(struct rte_node *node, stru
m->l4_len = sizeof(struct rte_udp_hdr);

rte_ether_addr_copy(&incoming_eth_hdr->src_addr, &incoming_eth_hdr->dst_addr);
rte_ether_addr_copy(&port->vm.info.own_mac, &incoming_eth_hdr->src_addr);
rte_ether_addr_copy(&port->own_mac, &incoming_eth_hdr->src_addr);
if (response_type == DHCPACK)
rte_ether_addr_copy(&incoming_eth_hdr->dst_addr, &port->vm.info.neigh_mac);
rte_ether_addr_copy(&incoming_eth_hdr->dst_addr, &port->neigh_mac);

incoming_ipv4_hdr->src_addr = server_ip;

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/dhcpv6_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static __rte_always_inline rte_edge_t get_next_index(struct rte_node *node, stru

// switch the packet's direction
rte_ether_addr_copy(&req_eth_hdr->src_addr, &req_eth_hdr->dst_addr);
rte_ether_addr_copy(&dp_get_in_port(m)->vm.info.own_mac, &req_eth_hdr->src_addr);
rte_ether_addr_copy(&dp_get_in_port(m)->own_mac, &req_eth_hdr->src_addr);

rte_memcpy(req_ipv6_hdr->dst_addr, req_ipv6_hdr->src_addr, sizeof(req_ipv6_hdr->dst_addr));
rte_memcpy(req_ipv6_hdr->src_addr, own_ip6, sizeof(req_ipv6_hdr->src_addr));
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/ipv6_nd_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static __rte_always_inline rte_edge_t get_next_index(__rte_unused struct rte_nod
struct dp_port *port = dp_get_in_port(m);

rte_ether_addr_copy(&req_eth_hdr->src_addr, &req_eth_hdr->dst_addr);
rte_ether_addr_copy(&port->vm.info.own_mac, &req_eth_hdr->src_addr);
rte_ether_addr_copy(&port->own_mac, &req_eth_hdr->src_addr);

if (!memcmp(req_ipv6_hdr->src_addr, dp_unspecified_ipv6, sizeof(req_ipv6_hdr->src_addr)))
rte_memcpy(req_ipv6_hdr->dst_addr, dp_multicast_ipv6, sizeof(req_ipv6_hdr->dst_addr));
Expand All @@ -48,7 +48,7 @@ static __rte_always_inline rte_edge_t get_next_index(__rte_unused struct rte_nod
nd_msg = (struct nd_msg *)(req_ipv6_hdr + 1);
if (memcmp(&nd_msg->target, rt_ip, sizeof(nd_msg->target)))
return IPV6_ND_NEXT_DROP;
rte_ether_addr_copy(&req_eth_hdr->dst_addr, &port->vm.info.neigh_mac);
rte_ether_addr_copy(&req_eth_hdr->dst_addr, &port->neigh_mac);
rte_memcpy(port->vm.info.vm_ipv6, req_ipv6_hdr->dst_addr, sizeof(port->vm.info.vm_ipv6));
req_icmp6_hdr->icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
req_icmp6_hdr->icmp6_solicited = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/rte_flow/dp_rte_flow_capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void dp_configure_pkt_capture_action(uint8_t *encaped_mirror_hdr,
const struct dp_port *outgoing_port = dp_get_pf0();
const struct dp_capture_hdr_config *capture_hdr_config = dp_get_capture_hdr_config();

rte_ether_addr_copy(&outgoing_port->vm.info.neigh_mac, &encap_eth_hdr->dst_addr);
rte_ether_addr_copy(&outgoing_port->vm.info.own_mac, &encap_eth_hdr->src_addr);
rte_ether_addr_copy(&outgoing_port->neigh_mac, &encap_eth_hdr->dst_addr);
rte_ether_addr_copy(&outgoing_port->own_mac, &encap_eth_hdr->src_addr);
encap_eth_hdr->ether_type = htons(RTE_ETHER_TYPE_IPV6);

rte_memcpy(new_ipv6_hdr->src_addr, dp_conf_get_underlay_ip(), sizeof(new_ipv6_hdr->src_addr));
Expand Down
16 changes: 8 additions & 8 deletions src/rte_flow/dp_rte_flow_traffic_forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ static __rte_always_inline void dp_create_ipip_encap_header(uint8_t raw_hdr[DP_I
struct rte_ether_hdr *encap_eth_hdr = (struct rte_ether_hdr *)raw_hdr;
struct rte_ipv6_hdr *encap_ipv6_hdr = (struct rte_ipv6_hdr *)(&raw_hdr[sizeof(struct rte_ether_hdr)]);

rte_ether_addr_copy(&outgoing_port->vm.info.neigh_mac, &encap_eth_hdr->dst_addr);
rte_ether_addr_copy(&outgoing_port->vm.info.own_mac, &encap_eth_hdr->src_addr);
rte_ether_addr_copy(&outgoing_port->neigh_mac, &encap_eth_hdr->dst_addr);
rte_ether_addr_copy(&outgoing_port->own_mac, &encap_eth_hdr->src_addr);
encap_eth_hdr->ether_type = htons(RTE_ETHER_TYPE_IPV6);

encap_ipv6_hdr->vtc_flow = htonl(DP_IP6_VTC_FLOW);
Expand Down Expand Up @@ -379,8 +379,8 @@ int dp_offload_handle_tunnel_decap_traffic(struct dp_flow *df,
df->conntrack->incoming_flow_offloaded_flag.pf0 = true;

// prepare the new ethernet header to replace the IPIP one
rte_ether_addr_copy(&outgoing_port->vm.info.neigh_mac, &new_eth_hdr.dst_addr);
rte_ether_addr_copy(&outgoing_port->vm.info.own_mac, &new_eth_hdr.src_addr);
rte_ether_addr_copy(&outgoing_port->neigh_mac, &new_eth_hdr.dst_addr);
rte_ether_addr_copy(&outgoing_port->own_mac, &new_eth_hdr.src_addr);
new_eth_hdr.ether_type = htons(df->l3_type);

// restore the actual incoming pkt's ipv6 dst addr
Expand Down Expand Up @@ -544,8 +544,8 @@ int dp_offload_handle_local_traffic(struct dp_flow *df,
dp_set_end_flow_item(&pattern[pattern_cnt++]);

// set proper ethernet addresses
dp_set_dst_mac_set_action(&actions[action_cnt++], &set_dst_mac, &outgoing_port->vm.info.neigh_mac);
dp_set_src_mac_set_action(&actions[action_cnt++], &set_src_mac, &outgoing_port->vm.info.own_mac);
dp_set_dst_mac_set_action(&actions[action_cnt++], &set_dst_mac, &outgoing_port->neigh_mac);
dp_set_src_mac_set_action(&actions[action_cnt++], &set_src_mac, &outgoing_port->own_mac);

// replace IPv4 address in overlay if VIP/NAT enabled
if (df->flags.nat == DP_NAT_CHG_DST_IP) {
Expand Down Expand Up @@ -632,8 +632,8 @@ int dp_offload_handle_in_network_traffic(struct dp_flow *df,
// in network traffic has to be set via the other pf port via hairpin
real_outgoing_port = incoming_port == dp_get_pf0() ? dp_get_pf1() : incoming_port;
df->nxt_hop = real_outgoing_port->port_id;
dp_set_src_mac_set_action(&actions[action_cnt++], &set_src_mac, &real_outgoing_port->vm.info.own_mac);
dp_set_dst_mac_set_action(&actions[action_cnt++], &set_dst_mac, &real_outgoing_port->vm.info.neigh_mac);
dp_set_src_mac_set_action(&actions[action_cnt++], &set_src_mac, &real_outgoing_port->own_mac);
dp_set_dst_mac_set_action(&actions[action_cnt++], &set_dst_mac, &real_outgoing_port->neigh_mac);

// set the right underlay address
dp_set_ipv6_set_dst_action(&actions[action_cnt++], &set_ipv6, df->tun_info.ul_dst_addr6);
Expand Down

0 comments on commit ec30bf5

Please sign in to comment.