From b3fc8ff680197f32c407b49a0e3cf26c46d7091e Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Tue, 24 Mar 2020 13:46:13 +0100 Subject: [PATCH] vtep: pg_vtep_add_vni_dst Signed-off-by: Matthias Gatto --- include/packetgraph/vtep.h | 11 ++++++++ src/vtep-impl.h | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/packetgraph/vtep.h b/include/packetgraph/vtep.h index 1a796bfa1..ca412f910 100644 --- a/include/packetgraph/vtep.h +++ b/include/packetgraph/vtep.h @@ -93,6 +93,16 @@ int pg_vtep6_add_vni(struct pg_brick *brick, struct pg_brick *neighbor, uint32_t vni, uint8_t *multicast_ip, struct pg_error **errp); +int pg_vtep4_add_vni_dst(struct pg_brick *brick, uint32_t vni, + struct ether_addr *mac_vm, + struct ether_addr *dmac, uint32_t dip, + struct pg_error **errp); + +int pg_vtep6_add_vni_dst(struct pg_brick *brick, uint32_t vni, + struct ether_addr *mac_vm, + struct ether_addr *dmac, uint8_t *dip, + struct pg_error **errp); + #ifndef __cplusplus /** @@ -148,6 +158,7 @@ inline int pg_vtep_add_vni(struct pg_brick *brick, int pg_vtep_add_mac(struct pg_brick *brick, uint32_t vni, struct ether_addr *mac, struct pg_error **errp); + /** * Like what the function name say * @param brick the brick we are working on diff --git a/src/vtep-impl.h b/src/vtep-impl.h index dec384078..4dab22848 100644 --- a/src/vtep-impl.h +++ b/src/vtep-impl.h @@ -1078,6 +1078,61 @@ int pg_vtep_add_vni_(struct pg_brick *brick, return 0; } +#define pg_vtep_add_vni_dst__(version) CATCAT(pg_vtep, version, _add_vni_dst) +#define pg_vtep_add_vni_dst_ pg_vtep_add_vni_dst__(IP_VERSION) + +int pg_vtep_add_vni_dst_(struct pg_brick *brick, uint32_t vni, + struct ether_addr *mac_vm, + struct ether_addr *dmac, IP_IN_TYPE dip, + struct pg_error **errp) +{ + struct vtep_state *state = pg_brick_get_state(brick, + struct vtep_state); + struct dest_addresses dst = {*dmac, +#if IP_VERSION == 4 + dip, +#else + {.word8 = {0}}, +#endif + state->vtep_tick}; + union pg_mac tmp = {.rte_addr = *mac_vm}; + struct vtep_port *ports = state->ports; + struct vtep_port *good_port = NULL; + struct pg_brick_side *s = &brick->sides[pg_flip_side(state->output)]; + + if (!brick) { + *errp = pg_error_new("brick is NULL"); + return -1; + } + + if (!is_vni_valid(vni)) { + *errp = pg_error_new("Invalid VNI"); + return -1; + } + +#if IP_VERSION != 4 + pg_ip_copy(dip, &dst.ip); +#endif + + for (int i = 0; i < s->nb; ++i) { + if (ports[i].vni == vni) { + good_port = &ports[i]; + break; + } + } + + if (!good_port) { + *errp = pg_error_new("can't find good VNI"); + return -1; + } + + pg_mac_table_elem_set(&good_port->mac_to_dst, tmp, &dst, + sizeof(struct dest_addresses)); + + return 0; +} + + #define pg_vtep_clean_all_mac__(version) \ CATCAT(pg_vtep, version, _clean_all_mac) #define pg_vtep_clean_all_mac_ pg_vtep_clean_all_mac__(IP_VERSION)