Skip to content
This repository was archived by the owner on Apr 1, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 247 additions & 3 deletions src/dmn/trn_transit_xdp_usr.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <linux/if.h>
#include <linux/if_packet.h>
#include "extern/linux/err.h"

#include "trn_transitd.h"

static trn_xdp_prog_t trn_prog_tbl[TRAN_MAX_PROG] = {
Expand Down Expand Up @@ -63,13 +64,19 @@ static char * pin_path = "/sys/fs/bpf";
static trn_xdp_map_t trn_xdp_bpfmaps[] = {
{"jmp_table", true, -1, NULL},
{"endpoints_map", true, -1, NULL},
#if turnOn
{"hosted_eps_if", true, -1, NULL},
#endif
{"if_config_map", true, -1, NULL},
{"interfaces_map", true, -1, NULL},
{"xsks_map", true, -1,NULL},
#if connTrack
{"contrack_map", true, -1, NULL},
#endif
#if sgSupport
{"sg_cidr_map", true, -1, NULL},
{"security_group_map", true, -1, NULL},
{"port_range_map", true, -1, NULL},
#endif
#if turnOn
{"hosted_eps_if", true, -1, NULL},
{"oam_queue_map", true, -1, NULL},
{"fwd_flow_cache", true, -1, NULL},
{"rev_flow_cache", true, -1, NULL},
Expand Down Expand Up @@ -374,6 +381,243 @@ static int trn_prog_load(trn_prog_t *prog, int prog_idx)
return 1;
}

#if sgSupport
int trn_update_sg_cidr_get_ctx(void)
{
int fd;

fd = trn_transit_map_get_fd("sg_cidr_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get sg_cidr_map fd");
}

return fd;
}

int trn_update_sg_cidr(int fd, sg_cidr_key_t *sgkey, sg_cidr_t *sg)
{
int err;

if (fd < 0) {
TRN_LOG_ERROR("Invalid sg_cidr_map fd");
return 1;
}

err = bpf_map_update_elem(fd, sgkey, sg, 0);
if (err) {
TRN_LOG_ERROR("Store sg_cidr mapping failed (err:%d).", err);
return 1;
}

return 0;
}

int trn_get_sg_cidr(sg_cidr_key_t *epkey, sg_cidr_t *ep)
{
int fd, err;

fd = trn_transit_map_get_fd("sg_cidr_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get sg_cidr_map fd");
return 1;
}

err = bpf_map_lookup_elem(fd, epkey, ep);
if (err) {
TRN_LOG_ERROR("Querying sg_cidr mapping failed (err:%d).",
err);
return 1;
}
return 0;
}

int trn_delete_sg_cidr(sg_cidr_key_t *epkey)
{
sg_cidr_t ep;
int fd, err;

fd = trn_transit_map_get_fd("sg_cidr_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get sg_cidr_map fd");
return 1;
}

err = bpf_map_lookup_elem(fd, epkey, &ep);

if (err) {
TRN_LOG_ERROR("Querying sg_cidr for delete failed (err:%d).",
err);
return 1;
}

err = bpf_map_delete_elem(fd, epkey);
if (err) {
TRN_LOG_ERROR("Deleting sg_cidr mapping failed (err:%d).",
err);
return 1;
}

return 0;
}
// security_group
int trn_update_sg_get_ctx(void)
{
int fd;

fd = trn_transit_map_get_fd("security_group_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get security_group_map fd");
}

return fd;
}

int trn_update_sg(int fd, security_group_key_t *sgkey, security_group_t *sg)
{
int err;

if (fd < 0) {
TRN_LOG_ERROR("Invalid security_group_map fd");
return 1;
}

err = bpf_map_update_elem(fd, sgkey, sg, 0);
if (err) {
TRN_LOG_ERROR("Store sg_cidr mapping failed (err:%d).", err);
return 1;
}

return 0;
}

int trn_get_sg(security_group_key_t *sgkey, security_group_t *sg)
{
int fd, err;

fd = trn_transit_map_get_fd("security_group_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get security_group_map fd");
return 1;
}

err = bpf_map_lookup_elem(fd, sgkey, sg);
if (err) {
TRN_LOG_ERROR("Querying sg_cidr mapping failed (err:%d).",
err);
return 1;
}
return 0;
}

int trn_delete_sg(security_group_key_t *sgkey)
{
security_group_t sg;
int fd, err;

fd = trn_transit_map_get_fd("security_group_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get security_group_map fd");
return 1;
}

err = bpf_map_lookup_elem(fd, sgkey, &sg);

if (err) {
TRN_LOG_ERROR("Querying security_group for delete failed (err:%d).",
err);
return 1;
}

err = bpf_map_delete_elem(fd, sgkey);
if (err) {
TRN_LOG_ERROR("Deleting security_group mapping failed (err:%d).",
err);
return 1;
}

return 0;
}

//port_range_map
int trn_update_port_range_get_ctx(void)
{
int fd;

fd = trn_transit_map_get_fd("port_range_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get port_range_map fd");
}

return fd;
}

int trn_update_port_range(int fd, port_range_key_t *prkey, port_range_t *pr)
{
int err;

if (fd < 0) {
TRN_LOG_ERROR("Invalid port_range_map fd");
return 1;
}

err = bpf_map_update_elem(fd, prkey, pr, 0);
if (err) {
TRN_LOG_ERROR("Store port_range mapping failed (err:%d).", err);
return 1;
}

return 0;
}

int trn_get_port_range(port_range_key_t *prkey, port_range_t *pr)
{
int fd, err;

fd = trn_transit_map_get_fd("port_range_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get port_range_map fd");
return 1;
}

err = bpf_map_lookup_elem(fd, prkey, pr);
if (err) {
TRN_LOG_ERROR("Querying port_range mapping failed (err:%d).",
err);
return 1;
}
return 0;
}

int trn_delete_port_range(port_range_key_t *prkey)
{
port_range_t pr;
int fd, err;

fd = trn_transit_map_get_fd("port_range_map");
if (fd < 0) {
TRN_LOG_ERROR("Failed to get port_range_map fd");
return 1;
}

err = bpf_map_lookup_elem(fd, prkey, &pr);

if (err) {
TRN_LOG_ERROR("Querying port_range for delete failed (err:%d).",
err);
return 1;
}

err = bpf_map_delete_elem(fd, prkey);
if (err) {
TRN_LOG_ERROR("Deleting port_range mapping failed (err:%d).",
err);
return 1;
}

return 0;
}
#endif

int trn_update_endpoints_get_ctx(void)
{
int fd;
Expand Down
28 changes: 20 additions & 8 deletions src/dmn/trn_transit_xdp_usr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @brief User space APIs and data structures to program transit
* xdp program.
*
* @copyright Copyright (c) 2019-2022 The Authors.
* @copyright Copyright (c) 2019-2023 The Authors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -51,6 +51,8 @@
#include "extern/cJSON.h"

#define turnOn 0
#define sgSupport 1

typedef struct {
int prog_id; // definition in trn_xdp_prog_id_t
char *prog_path; // full path of xdp program
Expand Down Expand Up @@ -99,23 +101,33 @@ typedef struct {
} user_metadata_t;

trn_iface_t *trn_get_itf_context(char *interface);

int trn_update_itf_config(struct tunnel_iface_t *itf);

int trn_update_endpoints_get_ctx(void);

int trn_update_endpoint(int fd, endpoint_key_t *epkey, endpoint_t *ep);

int trn_get_endpoint(endpoint_key_t *epkey, endpoint_t *ep);

int trn_delete_endpoint(endpoint_key_t *epkey);

int trn_transit_xdp_load(char **interfaces, unsigned short ibo_port, bool debug);
#if sgSupport
int trn_update_sg_cidr_get_ctx(void);
int trn_update_sg_cidr(int fd, sg_cidr_key_t *sgkey, sg_cidr_t *sg);
int trn_get_sg_cidr(sg_cidr_key_t *sgkey, sg_cidr_t *sg);
int trn_delete_sg_cidr(sg_cidr_key_t *sgkey);

int trn_update_sg_get_ctx(void);
int trn_update_sg(int fd, security_group_key_t *sgkey, security_group_t *sg);
int trn_get_sg(security_group_key_t *sgkey, security_group_t *sg);
int trn_delete_sg(security_group_key_t *sgkey);

int trn_update_port_range_get_ctx(void);
int trn_update_port_range(int fd, port_range_key_t *prkey, port_range_t *pr);
int trn_get_port_range(port_range_key_t *prkey, port_range_t *pr);
int trn_delete_port_range(port_range_key_t *prkey);
#endif

int trn_transit_xdp_load(char **interfaces, unsigned short ibo_port, bool debug);
int trn_transit_xdp_unload(char **interfaces);

int trn_transit_ebpf_load(int prog_idx);

int trn_transit_ebpf_unload(int prog_idx);

#if turnOn
Expand Down
Loading