Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
watal committed Jul 20, 2023
1 parent c6d5b64 commit 161e083
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
28 changes: 15 additions & 13 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023 NTT Communications Corporation
* Copyright (c) 2023 Takeru Hayasaka
* Copyright (c) 2023 Takeru Hayasaka
*/

#define KBUILD_MODNAME "xdp_probe"
Expand All @@ -18,12 +18,13 @@

#include "xdp_map.h"

SEC("xdp")
int xdp_prog(struct xdp_md *ctx) {
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
__u32 probe_key = XDP_PASS;
struct ethhdr *eth = data;
SEC("xdp")
int xdp_prog(struct xdp_md *ctx)
{
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
__u32 probe_key = XDP_PASS;
struct ethhdr *eth = data;

if ((void *)(eth + 1) > data_end)
return XDP_PASS;
Expand Down Expand Up @@ -62,27 +63,28 @@ int xdp_prog(struct xdp_md *ctx) {
key.flags = srh->flags;
key.tag = srh->tag;

for(int i=0; i<MAX_SEGMENTLIST_ENTRIES; i++ )
{
if (!(i < key.lastEntry + 1) )
for (int i = 0; i < MAX_SEGMENTLIST_ENTRIES; i++)
{
if (!(i < key.lastEntry + 1))
break;

if ((void *)(data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr) + sizeof(struct srhhdr) + sizeof(struct in6_addr) * (i + 1) + 1) > data_end)
break;

__builtin_memcpy(&key.segments[i], &srh->segments[i], sizeof(struct in6_addr));
}

value = bpf_map_lookup_elem(&ipfix_probe_map, &key);
if (!value) {
if (!value)
{
bpf_map_update_elem(&ipfix_probe_map, &key, &zero, BPF_NOEXIST);
value = bpf_map_lookup_elem(&ipfix_probe_map, &key);
if (!value)
return XDP_PASS;
}
(*value)++;

return XDP_PASS;
return XDP_PASS;
}

char _license[] SEC("license") = "MIT";
2 changes: 1 addition & 1 deletion src/xdp_consts.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023 NTT Communications Corporation
* Copyright (c) 2023 Takeru Hayasaka
* Copyright (c) 2023 Takeru Hayasaka
*/

#ifndef __XDP_CONSTS_H
Expand Down
5 changes: 3 additions & 2 deletions src/xdp_map.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023 NTT Communications Corporation
* Copyright (c) 2023 Takeru Hayasaka
* Copyright (c) 2023 Takeru Hayasaka
*/

#ifndef __XDP_MAPS_H
Expand All @@ -12,7 +12,8 @@
#include <bpf/bpf_endian.h>
#include "xdp_consts.h"
#include "xdp_struct.h"
struct {
struct
{
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__uint(max_entries, MAX_MAP_ENTRIES);
__type(key, struct probe_data);
Expand Down
11 changes: 6 additions & 5 deletions src/xdp_struct.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023 NTT Communications Corporation
* Copyright (c) 2023 Takeru Hayasaka
* Copyright (c) 2023 Takeru Hayasaka
*/

#ifndef __XDP_STRUCTS_H
Expand All @@ -25,10 +25,11 @@ struct srhhdr
struct in6_addr segments[0];
};

struct probe_data {
__u8 h_dest[ETH_ALEN];
__u8 h_source[ETH_ALEN];
__be16 h_proto;
struct probe_data
{
__u8 h_dest[ETH_ALEN];
__u8 h_source[ETH_ALEN];
__be16 h_proto;
struct in6_addr v6_srcaddr;
struct in6_addr v6_dstaddr;
__u8 nextHdr;
Expand Down

0 comments on commit 161e083

Please sign in to comment.