struct task_base base;
uint8_t src_dst_mac[12];
uint32_t runtime_flags;
- uint32_t tmp_ip;
- uint32_t ip;
};
-static void task_update_config(struct task_swap *task)
-{
- if (unlikely(task->ip != task->tmp_ip))
- task->ip = task->tmp_ip;
-}
-
static void write_src_and_dst_mac(struct task_swap *task, struct rte_mbuf *mbuf)
{
struct ether_hdr *hdr;
static inline int handle_arp_request(struct task_swap *task, struct ether_hdr_arp *hdr_arp, struct ether_addr *s_addr, uint32_t ip)
{
if ((hdr_arp->arp.data.tpa == ip) || (ip == 0)) {
- prepare_arp_reply(hdr_arp, s_addr);
- memcpy(hdr_arp->ether_hdr.d_addr.addr_bytes, hdr_arp->ether_hdr.s_addr.addr_bytes, 6);
- memcpy(hdr_arp->ether_hdr.s_addr.addr_bytes, s_addr, 6);
+ build_arp_reply(hdr_arp, s_addr);
return 0;
} else if (task->runtime_flags & TASK_MULTIPLE_MAC) {
struct ether_addr tmp_s_addr;
create_mac(hdr_arp, &tmp_s_addr);
- prepare_arp_reply(hdr_arp, &tmp_s_addr);
- memcpy(hdr_arp->ether_hdr.d_addr.addr_bytes, hdr_arp->ether_hdr.s_addr.addr_bytes, 6);
- memcpy(hdr_arp->ether_hdr.s_addr.addr_bytes, &tmp_s_addr, 6);
+ build_arp_reply(hdr_arp, &tmp_s_addr);
return 0;
} else {
plogx_dbg("Received ARP on unexpected IP %x, expecting %x\n", rte_be_to_cpu_32(hdr_arp->arp.data.tpa), rte_be_to_cpu_32(ip));
for (uint16_t j = 0; j < n_pkts; ++j) {
hdr = rte_pktmbuf_mtod(mbufs[j], struct ether_hdr *);
switch (hdr->ether_type) {
- case ETYPE_ARP:
- hdr_arp = rte_pktmbuf_mtod(mbufs[j], struct ether_hdr_arp *);
- if (arp_is_gratuitous(hdr_arp)) {
- plog_info("Received gratuitous packet \n");
- out[j] = OUT_DISCARD;
- } else if (hdr_arp->arp.oper == ARP_REQUEST) {
- out[j] = handle_arp_request(task, hdr_arp, (struct ether_addr *)&task->src_dst_mac[6], task->ip);
- } else if (hdr_arp->arp.oper == ARP_REPLY) {
- out[j] = handle_arp_replies(task, hdr_arp);
- } else {
- plog_info("Received unexpected ARP operation %d\n", hdr_arp->arp.oper);
- out[j] = OUT_DISCARD;
- }
- continue;
case ETYPE_MPLSU:
mpls = (struct mpls_hdr *)(hdr + 1);
while (!(mpls->bytes & 0x00010000)) {
}
write_src_and_dst_mac(task, mbufs[j]);
}
- task_update_config(task);
return task->base.tx_pkt(&task->base, mbufs, n_pkts, out);
}
struct ether_addr *src_addr, *dst_addr;
/*
- * Destination MAC can come from
- * - pre-configured mac in case 'dst mac=xx:xx:xx:xx:xx:xx' in config file
- * - src mac from the packet in case 'dst mac=packet' in config file
- * - not written in case 'dst mac=no' in config file
- * - (default - no 'dst mac') src mac from the packet
- * Source MAC can come from
- * - pre-configured mac in case 'src mac=xx:xx:xx:xx:xx:xx' in config file
- * - dst mac from the packet in case 'src mac=packet' in config file
- * - not written in case 'src mac=no' in config file
- * - (default - no 'src mac') if (tx_port) port mac
- * - (default - no 'src mac') if (no tx_port) dst mac from the packet
+ * The destination MAC of the outgoing packet is based on the config file:
+ * - 'dst mac=xx:xx:xx:xx:xx:xx' => the pre-configured mac will be used as dst mac
+ * - 'dst mac=packet' => the src mac of the incoming packet is used as dst mac
+ * - (default - no 'dst mac') => the src mac from the incoming packet is used as dst mac
+ *
+ * The source MAC of the outgoing packet is based on the config file:
+ * - 'src mac=xx:xx:xx:xx:xx:xx' => the pre-configured mac will be used as src mac
+ * - 'src mac=packet' => the dst mac of the incoming packet is used as src mac
+ * - 'src mac=hw' => the mac address of the tx port is used as src mac
+ * An error is returned if there are no physical tx ports
+ * - (default - no 'src mac') => if there is physical tx port, the mac of that port is used as src mac
+ * - (default - no 'src mac') if there are no physical tx ports the dst mac of the incoming packet
*/
if (targ->flags & TASK_ARG_DST_MAC_SET) {
memcpy(&task->src_dst_mac[0], dst_addr, sizeof(*src_addr));
}
+ PROX_PANIC(targ->flags & TASK_ARG_DO_NOT_SET_SRC_MAC, "src mac must be set in swap mode, by definition => src mac=no is not supported\n");
+ PROX_PANIC(targ->flags & TASK_ARG_DO_NOT_SET_DST_MAC, "dst mac must be set in swap mode, by definition => dst mac=no is not supported\n");
+
if (targ->flags & TASK_ARG_SRC_MAC_SET) {
src_addr = &targ->esaddr;
memcpy(&task->src_dst_mac[6], src_addr, sizeof(*dst_addr));
plog_info("\t\tCore %d: src mac set from config file\n", targ->lconf->id);
- } else if (targ->nb_txports) {
- src_addr = &prox_port_cfg[task->base.tx_params_hw.tx_port_queue[0].port].eth_addr;
- memcpy(&task->src_dst_mac[6], src_addr, sizeof(*dst_addr));
- if (targ->flags & TASK_ARG_HW_SRC_MAC){
+ } else {
+ if (targ->flags & TASK_ARG_HW_SRC_MAC)
+ PROX_PANIC(targ->nb_txports == 0, "src mac set to hw but no tx port\n");
+ if (targ->nb_txports) {
+ src_addr = &prox_port_cfg[task->base.tx_params_hw.tx_port_queue[0].port].eth_addr;
+ memcpy(&task->src_dst_mac[6], src_addr, sizeof(*dst_addr));
targ->flags |= TASK_ARG_SRC_MAC_SET;
plog_info("\t\tCore %d: src mac set from port\n", targ->lconf->id);
}
}
task->runtime_flags = targ->flags;
- task->ip = rte_cpu_to_be_32(targ->local_ipv4);
- task->tmp_ip = task->ip;
}
static struct task_init task_init_swap = {
.mode_str = "swap",
.init = init_task_swap,
.handle = handle_swap_bulk,
- .flag_features = TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS|TASK_FEATURE_TXQ_FLAGS_NOMULTSEGS,
+ .flag_features = TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS,
.size = sizeof(struct task_swap),
- .mbuf_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
};
static struct task_init task_init_swap_arp = {
.sub_mode_str = "l3",
.init = init_task_swap,
.handle = handle_swap_bulk,
- .flag_features = TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS|TASK_FEATURE_TXQ_FLAGS_NOMULTSEGS,
+ .flag_features = TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS,
.size = sizeof(struct task_swap),
- .mbuf_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
};
__attribute__((constructor)) static void reg_task_swap(void)