Skip to content

Commit

Permalink
vtep: pg_vtep_add_vni_dst
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <[email protected]>
  • Loading branch information
outscale-mgo committed Mar 24, 2020
1 parent 45f2f29 commit b3fc8ff
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/packetgraph/vtep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions src/vtep-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b3fc8ff

Please sign in to comment.