Skip to content

Commit

Permalink
Merge pull request FDio#24 from TetsuyaMurakami/ietf105-hackathon
Browse files Browse the repository at this point in the history
fix the issue to embed TEID into IPv6 address
  • Loading branch information
matsusato3 authored Jul 12, 2019
2 parents 01704c6 + 73a7c24 commit a7cf6c6
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 73 deletions.
4 changes: 2 additions & 2 deletions extras/ietf105/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def test_tmap(self):

c3.vppctl_exec("sr localsid address D3:: behavior end")

c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e")
c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e C1::/64")

c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
c2.set_ipv6_route("eth1", "A1::1", "C::/120")
Expand Down Expand Up @@ -587,7 +587,7 @@ def test_tmap_ipv6(self):

c3.vppctl_exec("sr localsid address D3:: behavior end")

c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e")
c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e C1::/64")

c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
c2.set_ipv6_route("eth1", "A1::1", "C::/120")
Expand Down
29 changes: 27 additions & 2 deletions src/plugins/srv6-mobile/gtp4_e.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,34 @@ static u8 param_str[] = "";
static u8 *
clb_format_srv6_end_m_gtp4_e (u8 * s, va_list * args)
{
s = format (s, "SRv6 End format function unsupported.");
srv6_end_gtp4_param_t *ls_mem = va_arg (*args, void *);

s = format (s, "SRv6 End gtp4.e\n\t");

s = format (s, "Local Prefix: %U/%d\n", format_ip6_address, &ls_mem->local_prefix, ls_mem->local_prefixlen);

return s;
}

static uword
clb_unformat_srv6_end_m_gtp4_e (unformat_input_t * input, va_list * args)
{
if (!unformat (input, "end.m.gtp4.e"))
void **plugin_mem_p = va_arg (*args, void **);
srv6_end_gtp4_param_t *ls_mem;
ip6_address_t local_prefix;
u32 local_prefixlen;

if (!unformat (input, "end.m.gtp4.e %U/%d",
unformat_ip6_address, &local_prefix, &local_prefixlen))
return 0;

ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
clib_memset (ls_mem, 0, sizeof *ls_mem);
*plugin_mem_p = ls_mem;

ls_mem->local_prefix = local_prefix;
ls_mem->local_prefixlen = local_prefixlen;

return 1;
}

Expand All @@ -86,6 +105,12 @@ clb_creation_srv6_end_m_gtp4_e (ip6_sr_localsid_t * localsid)
static int
clb_removal_srv6_end_m_gtp4_e (ip6_sr_localsid_t * localsid)
{
srv6_end_gtp4_param_t *ls_mem;

ls_mem = localsid->plugin_mem;

clib_mem_free(ls_mem);

return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions src/plugins/srv6-mobile/mobile.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ typedef struct srv6_end_gtp6_param_s
u32 sr_prefixlen;
} srv6_end_gtp6_param_t;

typedef struct srv6_end_gtp4_param_s
{
ip6_address_t local_prefix;
u32 local_prefixlen;
} srv6_end_gtp4_param_t;

typedef struct srv6_end_main_v4_s
{

Expand Down
70 changes: 53 additions & 17 deletions src/plugins/srv6-mobile/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
u32 bi0;
vlib_buffer_t *b0;
ip6_sr_localsid_t *ls0;
srv6_end_gtp4_param_t *ls_param;

ip6srv_combo_header_t *ip6srv0;
ip6_address_t src0, dst0;
Expand All @@ -200,6 +201,8 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
pool_elt_at_index (sm2->localsids,
vnet_buffer (b0)->ip.adj_index[VLIB_TX]);

ls_param = (srv6_end_gtp4_param_t *)ls0->plugin_mem;

ip6srv0 = vlib_buffer_get_current (b0);
src0 = ip6srv0->ip.src_address;
dst0 = ip6srv0->ip.dst_address;
Expand Down Expand Up @@ -245,37 +248,70 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,

u32 teid;
u8 *teid8p = (u8 *)&teid;
u16 index;
u16 offset, shift;
u32 index;
u32 offset, shift;

index = ls0->localsid_len;
index += 8;

offset = index / 8;
shift = index % 8;
offset = ls0->localsid_len / 8;
shift = ls0->localsid_len % 8;

if (PREDICT_TRUE(shift == 0)) {
teid8p[0] = dst0.as_u8[offset];
teid8p[1] = dst0.as_u8[offset + 1];
teid8p[2] = dst0.as_u8[offset + 2];
teid8p[3] = dst0.as_u8[offset + 3];
for (index = 0; index < 4; index++) {
hdr0->ip4.dst_address.as_u8[index] = dst0.as_u8[offset + index];
}

teid8p[0] = dst0.as_u8[offset + 5];
teid8p[1] = dst0.as_u8[offset + 6];
teid8p[2] = dst0.as_u8[offset + 7];
teid8p[3] = dst0.as_u8[offset + 8];
} else {
for (index = offset; index < offset + 4; index ++) {
*teid8p = dst0.as_u8[index] << shift;
*teid8p |= dst0.as_u8[index + 1] >> (8 - shift);
for (index = 0; index < 4; index ++) {
hdr0->ip4.dst_address.as_u8[index] = dst0.as_u8[offset + index] << shift;
hdr0->ip4.dst_address.as_u8[index] |= dst0.as_u8[offset + index + 1] >> (8 - shift);
}

for (index = 0; index < 4; index ++) {
*teid8p = dst0.as_u8[offset + 5 + index] << shift;
*teid8p |= dst0.as_u8[offset + 6 + index] >> (8 - shift);
teid8p++;
}
}

hdr0->gtpu.teid = teid;
hdr0->gtpu.length = clib_host_to_net_u16 (len0);

hdr0->udp.src_port = src0.as_u16[6];
offset = ls_param->local_prefixlen / 8;
shift = ls_param->local_prefixlen % 8;

if (PREDICT_TRUE(shift == 0)) {
u8 *pp;

pp = (u8 *) &hdr0->udp.src_port;

for (index = 0; index < 4; index ++) {
hdr0->ip4.src_address.as_u8[index] = src0.as_u8[offset + index];
}

for (index = 0; index < 2; index++) {
pp[index] = src0.as_u8[offset + 4 + index];
}
} else {
u8 *pp;

pp = (u8 *) &hdr0->udp.src_port;
for (index = 0; index < 4; index ++) {
hdr0->ip4.src_address.as_u8[index] = src0.as_u8[offset + index] << shift;
hdr0->ip4.src_address.as_u8[index] |= src0.as_u8[offset + index + 1] >> (8 - shift);
}

for (index = 0; index < 2; index++) {
pp[index] = src0.as_u8[offset + index + 4] << shift;
pp[index] |= src0.as_u8[offset + index + 5] >> (8 - shift);
}
}

hdr0->udp.length = clib_host_to_net_u16 (len0 +
sizeof (udp_header_t) + sizeof (gtpu_header_t));

hdr0->ip4.src_address.as_u32 = src0.as_u32[2];
hdr0->ip4.dst_address.as_u32 = dst0.as_u32[1];
hdr0->ip4.length = clib_host_to_net_u16 (len0 +
sizeof (ip4_gtpu_header_t));

Expand Down
Loading

0 comments on commit a7cf6c6

Please sign in to comment.