diff --git a/common/common_defines.h b/common/common_defines.h index e35f49a..05cd539 100644 --- a/common/common_defines.h +++ b/common/common_defines.h @@ -94,7 +94,7 @@ struct ingressinfo { #define PORT_AVAILABLE 1024 -int verbose; +static int verbose = 0; #define EXIT_OK 0 /* == EXIT_SUCCESS (stdlib.h) man exit(3) */ #define EXIT_FAIL 1 /* == EXIT_FAILURE (stdlib.h) man exit(3) */ diff --git a/tc_prog/common_kern.h b/tc_prog/common_kern.h index e62feae..5b9a8c7 100644 --- a/tc_prog/common_kern.h +++ b/tc_prog/common_kern.h @@ -90,7 +90,7 @@ unsigned long long load_word(void *skb, #define IS_SRC 1 #define IS_DST 2 -static inline void set_ip_tos(struct __sk_buff *skb, unsigned int off, __u8 tos) +static inline int set_ip_tos(struct __sk_buff *skb, unsigned int off, __u8 tos) { __u8 old_tos = load_byte(skb, off + IP_TOS_OFF); __u8 new_tos; @@ -103,6 +103,7 @@ static inline void set_ip_tos(struct __sk_buff *skb, unsigned int off, __u8 tos) skb, off + IP_CSUM_OFF, htons(old_tos), htons(new_tos), 2); bpf_skb_store_bytes( skb, off + IP_TOS_OFF, &new_tos, sizeof(new_tos), 0); + return TC_ACT_OK; } static inline void set_new_ip( diff --git a/tc_prog/tc_prog_kern.c b/tc_prog/tc_prog_kern.c index 12004ed..5aa8573 100644 --- a/tc_prog/tc_prog_kern.c +++ b/tc_prog/tc_prog_kern.c @@ -5,49 +5,49 @@ #define PORT_MAX 65535 #define ENABLENP -struct bpf_elf_map SEC("maps") ingress_cache = { - .type = BPF_MAP_TYPE_LRU_HASH, - .size_key = sizeof(__be32), - .size_value = sizeof(struct ingressinfo), - .pinning = PIN_GLOBAL_NS, - .max_elem = 1024, -}; +struct { + __uint(type, BPF_MAP_TYPE_LRU_HASH); + __uint(max_entries, 1024); + __type(key, __be32); + __type(value, struct ingressinfo); + __uint(pinning, LIBBPF_PIN_BY_NAME); +} ingress_cache SEC(".maps"); -struct bpf_elf_map SEC("maps") egressip_cache = { - .type = BPF_MAP_TYPE_LRU_HASH, - .size_key = sizeof(__be32), - .size_value = sizeof(__be32), - .pinning = PIN_GLOBAL_NS, - .max_elem = 4096 -}; +struct { + __uint(type, BPF_MAP_TYPE_LRU_HASH); + __uint(max_entries, 4096); + __type(key, __be32); + __type(value, __be32); + __uint(pinning, LIBBPF_PIN_BY_NAME); +} egressip_cache SEC(".maps"); -struct bpf_elf_map SEC("maps") egress_cache = { - .type = BPF_MAP_TYPE_LRU_HASH, - .size_key = sizeof(__be32), - .size_value = sizeof(struct egressinfo), - .pinning = PIN_GLOBAL_NS, - .max_elem = 1024, -}; +struct { + __uint(type, BPF_MAP_TYPE_LRU_HASH); + __uint(max_entries, 1024); + __type(key, __be32); + __type(value, struct egressinfo); + __uint(pinning, LIBBPF_PIN_BY_NAME); +} egress_cache SEC(".maps"); -struct bpf_elf_map SEC("maps") policy_cache = { - .type = BPF_MAP_TYPE_LRU_HASH, - .size_key = sizeof(struct fivetuple), - .size_value = sizeof(struct action), - .pinning = PIN_GLOBAL_NS, - .max_elem = 4096, -}; +struct { + __uint(type, BPF_MAP_TYPE_LRU_HASH); + __uint(max_entries, 4096); + __type(key, struct fivetuple); + __type(value, struct action); + __uint(pinning, LIBBPF_PIN_BY_NAME); +} policy_cache SEC(".maps"); -struct bpf_elf_map SEC("maps") devmap = { - .type = BPF_MAP_TYPE_LRU_HASH, - .size_key = sizeof(int), - .size_value = sizeof(struct devinfo), - .pinning = PIN_GLOBAL_NS, - .max_elem = 8, -}; +struct { + __uint(type, BPF_MAP_TYPE_LRU_HASH); + __uint(max_entries, 8); + __type(key, int); + __type(value, struct devinfo); + __uint(pinning, LIBBPF_PIN_BY_NAME); +} devmap SEC(".maps"); SEC("tc_init_e") int tc_init_e_func(struct __sk_buff *skb) { - int err; + // int err; void *data = (void *)(long)skb->data; void *data_end = (void *)(long)skb->data_end; ////////////////// Check if the packet is a VXLAN packet //////////////////// @@ -95,12 +95,14 @@ int tc_init_e_func(struct __sk_buff *skb) { // Make sure there is elem in the map struct egressinfo tmpnodeegressinfo_; initegressinfo(&tmpnodeegressinfo_, data, skb->ifindex); - err = bpf_map_update_elem(&egress_cache, &outer_iph->daddr, &tmpnodeegressinfo_, BPF_NOEXIST); + // err = + bpf_map_update_elem(&egress_cache, &outer_iph->daddr, &tmpnodeegressinfo_, BPF_NOEXIST); // if(!err) { // bpf_printkm("(tc_init_e)INFO: Updated an nodeegressinfo element"); // } - err = bpf_map_update_elem(&egressip_cache, &inner_iph->daddr, &outer_iph->daddr, BPF_NOEXIST); + // err = + bpf_map_update_elem(&egressip_cache, &inner_iph->daddr, &outer_iph->daddr, BPF_NOEXIST); // if(!err) { // bpf_printkm("(tc_init_e)INFO: Added an podip element. RemoteIP is %x", inner_iph->daddr); // }