Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label values into traffic in agent side and retrieve the values from traffic in transit side #478

Merged
merged 3 commits into from
May 12, 2021
Merged
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
20 changes: 18 additions & 2 deletions src/xdp/trn_agent_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ static __inline int trn_encapsulate(struct transit_packet *pkt,
/* Readjust the packet size to fit the outer headers */
int gnv_rts_opt_size = sizeof(*pkt->rts_opt);
int gnv_scaled_ep_opt_size = sizeof(*pkt->scaled_ep_opt);
int gnv_pod_label_value_opt_size = sizeof(*pkt->pod_label_value_opt);
int gnv_namespace_label_value_opt_size = sizeof(*pkt->namespace_label_value_opt);

int gnv_opt_size = gnv_rts_opt_size + gnv_scaled_ep_opt_size;
int gnv_opt_size = gnv_rts_opt_size + gnv_scaled_ep_opt_size + gnv_pod_label_value_opt_size + gnv_namespace_label_value_opt_size;
int gnv_hdr_size = sizeof(*pkt->geneve) + gnv_opt_size;
int udp_hdr_size = sizeof(*pkt->udp);
int ip_hdr_size = sizeof(*pkt->ip);
Expand Down Expand Up @@ -199,11 +201,15 @@ static __inline int trn_encapsulate(struct transit_packet *pkt,
pkt->geneve = (void *)pkt->udp + udp_hdr_size;
pkt->rts_opt = (void *)&pkt->geneve->options[0];
pkt->scaled_ep_opt = (void *)pkt->rts_opt + sizeof(*pkt->rts_opt);
pkt->pod_label_value_opt = (void *)pkt->scaled_ep_opt + sizeof(*pkt->scaled_ep_opt);
vinaykul marked this conversation as resolved.
Show resolved Hide resolved
pkt->namespace_label_value_opt = (void *)pkt->pod_label_value_opt + sizeof(*pkt->pod_label_value_opt);

if (pkt->eth + 1 > pkt->data_end || pkt->ip + 1 > pkt->data_end ||
pkt->udp + 1 > pkt->data_end || pkt->geneve + 1 > pkt->data_end ||
pkt->rts_opt + 1 > pkt->data_end ||
pkt->scaled_ep_opt + 1 > pkt->data_end) {
pkt->scaled_ep_opt + 1 > pkt->data_end ||
pkt->pod_label_value_opt + 1 > pkt->data_end ||
pkt->namespace_label_value_opt + 1 > pkt->data_end) {
bpf_debug("[Agent:%ld.0x%x] ABORTED: Bad offset [%d]\n",
pkt->agent_ep_tunid, bpf_ntohl(pkt->agent_ep_ipv4),
__LINE__);
Expand Down Expand Up @@ -260,6 +266,16 @@ static __inline int trn_encapsulate(struct transit_packet *pkt,
__builtin_memset(&pkt->scaled_ep_opt->scaled_ep_data, 0,
sizeof(struct trn_gnv_scaled_ep_data));

pkt->pod_label_value_opt->opt_class = TRN_GNV_OPT_CLASS;
pkt->pod_label_value_opt->type = TRN_GNV_LABEL_VALUE_OPT_TYPE;
vinaykul marked this conversation as resolved.
Show resolved Hide resolved
pkt->pod_label_value_opt->length = sizeof(pkt->pod_label_value_opt->label_value_data) / 4;
pkt->pod_label_value_opt->label_value_data.value = pod_label_value;

pkt->namespace_label_value_opt->opt_class = TRN_GNV_OPT_CLASS;
pkt->namespace_label_value_opt->type = TRN_GNV_LABEL_VALUE_OPT_TYPE;
pkt->namespace_label_value_opt->length = sizeof(pkt->namespace_label_value_opt->label_value_data) / 4;;
pkt->namespace_label_value_opt->label_value_data.value = namespace_label_value;

/* If the source and dest address of the tunneled packet is the
* same, then this host is also a transit switch. Just invoke the
* transit XDP program by a tail call;
Expand Down
18 changes: 18 additions & 0 deletions src/xdp/trn_kern.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define TRN_GNV_OPT_CLASS 0x0111
#define TRN_GNV_RTS_OPT_TYPE 0x48
#define TRN_GNV_SCALED_EP_OPT_TYPE 0x49
#define TRN_GNV_LABEL_VALUE_OPT_TYPE 0x50

/* Scaled endpoint messages type */
#define TRN_SCALED_EP_MODIFY 0x4d // (M: Modify)
Expand All @@ -78,6 +79,21 @@ struct trn_gnv_scaled_ep_opt {
struct trn_gnv_scaled_ep_data scaled_ep_data;
} __attribute__((packed, aligned(4)));

struct trn_gnv_label_value_data {
__u32 value;
} __attribute__((packed, aligned(4)));

struct trn_gnv_label_value_opt {
__be16 opt_class;
__u8 type;
__u8 length : 5;
__u8 r3 : 1;
__u8 r2 : 1;
__u8 r1 : 1;
/* opt data */
struct trn_gnv_label_value_data label_value_data;
} __attribute__((packed, aligned(4)));

struct trn_gnv_rts_data {
__u8 match_flow : 1;
struct remote_endpoint_t host;
Expand Down Expand Up @@ -147,6 +163,8 @@ struct transit_packet {
struct genevehdr *geneve;
struct trn_gnv_rts_opt *rts_opt;
struct trn_gnv_scaled_ep_opt *scaled_ep_opt;
struct trn_gnv_label_value_opt *pod_label_value_opt;
struct trn_gnv_label_value_opt *namespace_label_value_opt;
int gnv_hdr_len;
int gnv_opt_len;

Expand Down
47 changes: 47 additions & 0 deletions src/xdp/trn_transit_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,53 @@ static __inline int trn_process_geneve(struct transit_packet *pkt)
return XDP_ABORTED;
}

pkt->pod_label_value_opt = (void *)pkt->scaled_ep_opt + sizeof(*pkt->scaled_ep_opt);
vinaykul marked this conversation as resolved.
Show resolved Hide resolved

if (pkt->pod_label_value_opt + 1 > pkt->data_end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check the option class like above

Copy link
Collaborator

@w-yue w-yue May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above for option type comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check for both class and type.

bpf_debug("[Scaled_EP:%d:0x%x] ABORTED: Bad offset\n", __LINE__,
bpf_ntohl(pkt->itf_ipv4));
return XDP_ABORTED;
}

if (pkt->pod_label_value_opt->opt_class != TRN_GNV_OPT_CLASS) {
bpf_debug(
"[Scaled_EP:%d:0x%x] ABORTED: Unsupported Geneve option class\n",
__LINE__, bpf_ntohl(pkt->itf_ipv4));
return XDP_ABORTED;
}

if (pkt->pod_label_value_opt->type != TRN_GNV_LABEL_VALUE_OPT_TYPE) {
bpf_debug(
"[Scaled_EP:%d:0x%x] ABORTED: Unsupported Geneve option type\n",
__LINE__, bpf_ntohl(pkt->itf_ipv4));
return XDP_ABORTED;
}

pkt->namespace_label_value_opt = (void *)pkt->pod_label_value_opt + sizeof(*pkt->pod_label_value_opt);
vinaykul marked this conversation as resolved.
Show resolved Hide resolved

if (pkt->namespace_label_value_opt + 1 > pkt->data_end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check the option class like above

Copy link
Collaborator

@w-yue w-yue May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I see option type is not checked or used anywhere in transit xdp. Should we check here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check for both class and type.

bpf_debug("[Scaled_EP:%d:0x%x] ABORTED: Bad offset\n", __LINE__,
bpf_ntohl(pkt->itf_ipv4));
return XDP_ABORTED;
}

if (pkt->namespace_label_value_opt->opt_class != TRN_GNV_OPT_CLASS) {
bpf_debug(
"[Scaled_EP:%d:0x%x] ABORTED: Unsupported Geneve option class\n",
__LINE__, bpf_ntohl(pkt->itf_ipv4));
return XDP_ABORTED;
}

if (pkt->namespace_label_value_opt->type != TRN_GNV_LABEL_VALUE_OPT_TYPE) {
bpf_debug(
"[Scaled_EP:%d:0x%x] ABORTED: Unsupported Geneve option type\n",
__LINE__, bpf_ntohl(pkt->itf_ipv4));
return XDP_ABORTED;
}

// TODO: Handle label based policy from pod_label_value (pkt->pod_label_value_opt->label_value_data.value)
// and namespace_label_value (pkt->namespace_label_value_opt->label_value_data.value)

return trn_process_inner_eth(pkt);
}

Expand Down