Skip to content

Commit

Permalink
refactoring of HIKe/eBPF code
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Lungaroni <[email protected]>
  • Loading branch information
plungaroni committed Sep 6, 2023
1 parent 8413579 commit 24c02b6
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 197 deletions.
68 changes: 1 addition & 67 deletions paolo_adv_usid.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n))
#endif

#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG
//#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG

#define HIKE_PROG_NAME paolo_adv_usid

Expand All @@ -41,9 +41,6 @@ HIKE_PROG(HIKE_PROG_NAME)
struct hdr_cursor *cur;
struct in6_addr *addr;
struct ipv6hdr *ip6h;
// int rc;

hike_pr_debug("init paolo_adv_usid");

if (unlikely(!info))
goto drop;
Expand All @@ -53,8 +50,6 @@ HIKE_PROG(HIKE_PROG_NAME)
*/
cur = pkt_info_cur(info);

hike_pr_debug("pre paolo_adv_usid");

ip6h = (struct ipv6hdr *)cur_header_pointer(ctx, cur, cur->nhoff, sizeof(*ip6h));

if (unlikely(!ip6h))
Expand All @@ -64,63 +59,6 @@ HIKE_PROG(HIKE_PROG_NAME)
/* we let the kernel decide what to do in this situation */
return XDP_PASS;


/* assume that DA.Argument length > 0 */

/* __u32 key = USID_BLOCK_LEN;
__u32 *value;
__u32 blk_octects = 6;
__u32 fnc_octects = 1;
value = bpf_map_lookup_elem(&usid_params, &key);
if (unlikely(!value)) {
hike_pr_err("could not read usid_block_len from map");
goto drop;
}
hike_pr_debug("paolo usid_block_len: %d", *value);
blk_octects = *value;
hike_pr_debug("paolo blk_octects: %d", blk_octects);
key = USID_FUNC_LEN;
value = bpf_map_lookup_elem(&usid_params, &key);
if (unlikely(!value)) {
hike_pr_err("could not read usid_func_len from map");
goto drop;
}
hike_pr_debug("paolo usid_func_len: %d", *value);
fnc_octects = *value;
hike_pr_debug("paolo func_octects: %d", fnc_octects);
*/

/* addr = &ip6h->daddr;
__u32 arg_octects;
int i;
bool arg_zero = true;
arg_octects = 16 - blk_octects - fnc_octects;
for (i = 0; i < arg_octects; ++i) {
if (addr->s6_addr[blk_octects + fnc_octects + i] != 0x00)
arg_zero = false;
}
if (arg_zero)
goto drop;
/* advance DA.Argument */
/* memmove(&ip6h->daddr.s6_addr[blk_octects], &ip6h->daddr.s6_addr[blk_octects + fnc_octects],
16 - blk_octects - fnc_octects);
memset(&addr->s6_addr[16 - fnc_octects], 0x00, fnc_octects);
*/

addr = &ip6h->daddr;

__u32 arg_octects;
Expand All @@ -143,13 +81,9 @@ HIKE_PROG(HIKE_PROG_NAME)

memset(&addr->s6_addr[16 - USID_FUNC_LEN], 0x00, USID_FUNC_LEN);


hike_pr_debug("post paolo_adv_usid, addr");

return HIKE_XDP_VM;

drop:
hike_pr_debug("DROP paolo_adv_usid");
return XDP_ABORTED;
}
EXPORT_HIKE_PROG(HIKE_PROG_NAME);
Expand Down
16 changes: 1 addition & 15 deletions paolo_ip6_dst_filter.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "parse_helpers.h"
#include "paolo_kroute.h"

#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG
//#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG

#define HIKE_PROG_NAME paolo_ip6_dst_filter
#define HIKE_MAPS_NAME ip6_dst
Expand All @@ -36,8 +36,6 @@ HIKE_PROG(HIKE_PROG_NAME)
__be16 key = 0;
//int rc;

hike_pr_debug("init paolo_ip6_dst_filter");

if (unlikely(!info))
goto drop;

Expand All @@ -46,8 +44,6 @@ HIKE_PROG(HIKE_PROG_NAME)
*/
cur = pkt_info_cur(info);

hike_pr_debug("pre paolo_ip6_dst_filter");

ip6h = (struct ipv6hdr *)cur_header_pointer(ctx, cur, cur->nhoff, sizeof(*ip6h));

if (unlikely(!ip6h))
Expand Down Expand Up @@ -78,17 +74,7 @@ HIKE_PROG(HIKE_PROG_NAME)

return HIKE_XDP_VM;


// if (memcmp(&ip6h->daddr, daddr, sizeof(ip6h->daddr)) != 0)
// return HIKE_XDP_VM;
// else
// return XDP_PASS;

hike_pr_debug("post paolo_ip6_dst_filter");


drop:
hike_pr_debug("DROP paolo_ip6_dst_filter");
return XDP_ABORTED;
}
EXPORT_HIKE_PROG(HIKE_PROG_NAME);
Expand Down
9 changes: 1 addition & 8 deletions paolo_kroute.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
#include "parse_helpers.h"
#include "paolo_kroute.h"

#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG
//#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG

HIKE_PROG(paolo_kroute)
{
struct pkt_info *info = hike_pcpu_shmem();
struct hdr_cursor *cur;
int rc;

hike_pr_debug("hike init paolo_kroute");

if (unlikely(!info))
goto drop;

Expand All @@ -33,17 +31,12 @@ HIKE_PROG(paolo_kroute)
*/
cur = pkt_info_cur(info);

hike_pr_debug("hike pre paolo_kroute");

/* lookup with FIB rules */
rc = __paolo_route(ctx, cur, 0);

hike_pr_debug("hike post paolo_kroute; rc: %d", rc);

return rc;

drop:
hike_pr_debug("hike DROP paolo_kroute");
return XDP_ABORTED;
}
EXPORT_HIKE_PROG(paolo_kroute);
Expand Down
19 changes: 5 additions & 14 deletions paolo_seg6_decap.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "parse_helpers.h"
#include "paolo_kroute.h"

#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG
//#define HIKE_PRINT_LEVEL HIKE_PRINT_LEVEL_DEBUG

#define HIKE_PROG_NAME paolo_seg6_decap

Expand All @@ -41,13 +41,13 @@
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n))
#endif

static __always_inline void show_cur_info(const struct hdr_cursor *cur)
/*static __always_inline void show_cur_info(const struct hdr_cursor *cur)
{
hike_pr_debug("dataoff=%d", cur->dataoff);
hike_pr_debug("mhoff=%d", cur->mhoff);
hike_pr_debug("nhoff=%d", cur->nhoff);
hike_pr_debug("thoff=%d", cur->thoff);
}
}*/


HIKE_PROG(HIKE_PROG_NAME)
Expand All @@ -67,8 +67,6 @@ HIKE_PROG(HIKE_PROG_NAME)
struct ethhdr *old_eth, *eth;


hike_pr_debug("init paolo_seg6_decap");

if (unlikely(!info))
goto drop;

Expand All @@ -77,8 +75,6 @@ HIKE_PROG(HIKE_PROG_NAME)
*/
cur = pkt_info_cur(info);

hike_pr_debug("pre paolo_seg6_decap");

ip6h = (struct ipv6hdr *)cur_header_pointer(ctx, cur, cur->nhoff, sizeof(*ip6h));

if (unlikely(!ip6h))
Expand Down Expand Up @@ -161,9 +157,7 @@ HIKE_PROG(HIKE_PROG_NAME)
memcpy(eth, old_eth, sizeof(*eth));
eth->h_proto = bpf_ntohs(protocol);

show_cur_info(cur);
hike_pr_debug("tot_len: %d", tot_len);
hike_pr_debug("srh_len: %d \n", srh_len);
// show_cur_info(cur);


/* reduce the xdp frame */
Expand All @@ -189,14 +183,11 @@ HIKE_PROG(HIKE_PROG_NAME)
/* unset the trasport header offset (not used in L3 context) */
cur_transport_header_unset(cur);

show_cur_info(cur);

hike_pr_debug("post paolo_seg6_decap, OK");
// show_cur_info(cur);

return HIKE_XDP_VM;

drop:
hike_pr_debug("DROP paolo_seg6_decap");
return XDP_ABORTED;
}
EXPORT_HIKE_PROG(HIKE_PROG_NAME);
Expand Down
Loading

0 comments on commit 24c02b6

Please sign in to comment.