Skip to content

Commit

Permalink
Merge pull request #22 from hawkv6/empty-sidlist
Browse files Browse the repository at this point in the history
Refactor and fix empty sidlist
  • Loading branch information
jklaiber authored Nov 13, 2023
2 parents e93a529 + af36972 commit c541a44
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 118 deletions.
3 changes: 3 additions & 0 deletions bpf/bpf_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ int client_egress(struct __sk_buff *skb)
if (client_get_sid(skb, ipv6, &sidlist_data) < 0)
goto pass;

if (sidlist_data->sidlist_size == 0)
goto pass;

if (add_srh(skb, data, data_end, sidlist_data) < 0)
goto drop;

Expand Down
2 changes: 1 addition & 1 deletion bpf/bpf_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int server_egress(struct __sk_buff *skb)

handle_srh:
if (server_get_sid(skb, ipv6, &sidlist_data) < 0)
goto drop;
goto pass;

if (add_srh(skb, data, data_end, sidlist_data) < 0) {
bpf_printk("[server-egress] add_srh failed\n");
Expand Down
24 changes: 0 additions & 24 deletions bpf/lib/client_map_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,4 @@ static __always_inline int client_get_sid(struct __sk_buff *skb,
return 0;
}

static __always_inline int
client_get_sid_test(struct __sk_buff *skb, struct ipv6hdr *ipv6,
struct sidlist_data **sidlist_data)
{
__u32 *domain_id = bpf_map_lookup_elem(&client_reverse_map, &ipv6->daddr);
if (!domain_id)
return -1;

struct bpf_elf_map *inner_map =
bpf_map_lookup_elem(&client_outer_map, domain_id);
if (!inner_map)
return -1;

__u16 dstport = 0;
if (parse_ipproto_dstport(skb, ipv6, &dstport) < 0)
return -1;

*sidlist_data = bpf_map_lookup_elem(inner_map, &dstport);
if (!*sidlist_data)
return -1;

return 0;
}

#endif
28 changes: 0 additions & 28 deletions bpf/lib/csum.h

This file was deleted.

65 changes: 0 additions & 65 deletions bpf/lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,71 +111,6 @@ static __always_inline int remove_srh(struct xdp_md *ctx, void *data,
return 0;
}

// static __always_inline int add_srh(struct __sk_buff *skb, void *data,
// void *data_end, struct in6_addr *sids,
// __u8 sidlist_size)
// {
// struct ipv6hdr *ipv6 = data + sizeof(struct ethhdr);
// if (data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr) > data_end)
// return -1;

// int hdr_ext_len =
// (sizeof(struct srh) + sizeof(struct in6_addr) * sidlist_size - 8) / 8;
// struct srh srh = {
// .next_hdr = ipv6->nexthdr,
// .hdr_ext_len = hdr_ext_len,
// .routing_type = SRV6_ROUTING_TYPE,
// .segments_left = sidlist_size - 1,
// .last_entry = sidlist_size - 1,
// };

// // use percpu map to store sidlist temporary
// struct in6_addr *percpu_sidlist;
// __u32 percpu_sidlist_key = 0;
// percpu_sidlist = bpf_map_lookup_elem(&percpu_sidlist_map,
// &percpu_sidlist_key); if (!percpu_sidlist) return -1; memset(percpu_sidlist,
// 0, sizeof(struct in6_addr) * MAX_SEGMENTLIST_ENTRIES);

// // memcpy(percpu_sidlist, sids, sizeof(struct in6_addr) *
// MAX_SEGMENTLIST_ENTRIES); for (int i = 0; i < sidlist_size; i++) { if (!(i <
// sidlist_size)) { break;
// }
// memcpy(&percpu_sidlist[i], &sids[i], sizeof(struct in6_addr));
// }

// // memcpy(&sids[0], &ipv6->daddr, sizeof(struct in6_addr));
// memcpy(&percpu_sidlist[0], &ipv6->daddr, sizeof(struct in6_addr));
// ipv6->payload_len =
// bpf_htons(bpf_ntohs(ipv6->payload_len) + sizeof(struct srh) +
// sizeof(struct in6_addr) * sidlist_size);
// ipv6->nexthdr = SRV6_NEXT_HDR;
// // memcpy(&ipv6->daddr, &sids[sidlist_size - 1], sizeof(struct in6_addr));
// memcpy(&ipv6->daddr, &percpu_sidlist[sidlist_size - 1], sizeof(struct
// in6_addr));

// if (bpf_skb_adjust_room(
// skb, sizeof(struct srh) + sizeof(struct in6_addr) * sidlist_size,
// BPF_ADJ_ROOM_NET, 0) < 0)
// return -1;

// if (bpf_skb_store_bytes(skb, sizeof(struct ethhdr) + sizeof(struct ipv6hdr),
// &srh, sizeof(struct srh), 0) < 0)
// return -1;

// // if (bpf_skb_store_bytes(
// // skb,
// // sizeof(struct ethhdr) + sizeof(struct ipv6hdr) + sizeof(struct srh),
// // sids, sizeof(struct in6_addr) * sidlist_size, 0) < 0)
// // return -1;
// if (bpf_skb_store_bytes(
// skb,
// sizeof(struct ethhdr) + sizeof(struct ipv6hdr) + sizeof(struct srh),
// percpu_sidlist, sizeof(struct in6_addr) * sidlist_size, 0) < 0)
// return -1;

// return 0;
// }

static __always_inline int add_srh(struct __sk_buff *skb, void *data,
void *data_end,
struct sidlist_data *sidlist_data)
Expand Down
Binary file modified pkg/bpf/client/client_bpfeb.o
Binary file not shown.
Binary file modified pkg/bpf/client/client_bpfel.o
Binary file not shown.
Binary file modified pkg/bpf/server/server_bpfeb.o
Binary file not shown.
Binary file modified pkg/bpf/server/server_bpfel.o
Binary file not shown.

0 comments on commit c541a44

Please sign in to comment.