Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
refactored ringbuffer events to use char source[6] and dest[6] to pas…
Browse files Browse the repository at this point in the history
…s icmp event data
  • Loading branch information
r-caamano committed Jan 9, 2024
1 parent f8a4818 commit 1aaf41a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/zfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ static int process_events(void *ctx, void *data, size_t len){
__u8 outer_ttl = evt->source[0];
if(code == 4){
sprintf(message, "%s : %s : %s : %s :%s --> reported next hop mtu:%d > FRAGMENTATION NEEDED IN PATH TO:%s:%d\n", ts, ifname,
(evt->direction == INGRESS) ? "INGRESS" : "EGRESS", protocol,saddr, ntohs(evt->sport), daddr, ntohs(evt->dport));
(evt->direction == INGRESS) ? "INGRESS" : "EGRESS", protocol,saddr, ntohs(evt->source[1]), daddr, ntohs(evt->dport));
if(logging){
res = write_log(log_file_name, message);
}else{
Expand All @@ -1792,8 +1792,7 @@ static int process_events(void *ctx, void *data, size_t len){
}else{
char *code_string = NULL;
char *protocol_string = NULL;
/*evt->sport is use repurposed store encapsulated higher layer protocol*/
if(evt->sport == IPPROTO_TCP){
if(evt->dest[1] == IPPROTO_TCP){
protocol_string = "TCP";
}else{
protocol_string = "UDP";
Expand Down
5 changes: 2 additions & 3 deletions src/zfw_tc_ingress.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ int bpf_sk_splice(struct __sk_buff *skb){
if((inner_iph->protocol == IPPROTO_TCP) || ((inner_iph->protocol == IPPROTO_UDP))){
event.source[0] = iph->ttl;
event.dest[0] = inner_iph->ttl;
event.dest[1] = inner_iph->protocol;
struct bpf_sock_tuple *o_session = (struct bpf_sock_tuple *)(void*)(long)&inner_iph->saddr;
if ((unsigned long)(o_session + 1) > (unsigned long)skb->data_end){
event.error_code = IP_TUPLE_TOO_BIG;
Expand All @@ -755,9 +756,7 @@ int bpf_sk_splice(struct __sk_buff *skb){
event.daddr = o_session->ipv4.daddr;
event.tracking_code = icmph->code;
if(icmph->code == 4){
event.sport = icmph->un.frag.mtu;
}else{
event.sport = inner_iph->protocol;
event.source[1] = icmph->un.frag.mtu;
}
event.dport = o_session->ipv4.dport;
send_event(&event);
Expand Down

0 comments on commit 1aaf41a

Please sign in to comment.