]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
change code style
authorY7n05h <Y7n05h@protonmail.com>
Fri, 22 Apr 2022 18:31:55 +0000 (02:31 +0800)
committerY7n05h <Y7n05h@protonmail.com>
Fri, 22 Apr 2022 18:31:55 +0000 (02:31 +0800)
Co-authored-by: Remi Gacogne <github@coredump.fr>
Signed-off-by: Y7n05h <Y7n05h@protonmail.com>
contrib/xdp-filter.ebpf.src
pdns/bpf-filter.cc

index 9b0867eaeadda9264e7dcb2c48b6c0cfcffc6d21..5e4d9d13b896053fa4426ede295d674c595aaa60 100644 (file)
@@ -332,7 +332,7 @@ static inline enum dns_action udp_dns_reply_v4(struct cursor *c, struct CIDR4 *k
   }
 
   key->cidr = 32;
-  key->addr=bpf_htonl(key->addr);
+  key->addr = bpf_htonl(key->addr);
   value = cidr4filter.lookup(key);
   if (value) {
     __sync_fetch_and_add(&value->counter, 1);
@@ -404,7 +404,7 @@ static inline enum dns_action udp_dns_reply_v6(struct cursor *c, struct CIDR6* k
   return action;
 }
 
-int xdp_dns_filter(struct xdp_md *ctx)
+int xdp_dns_filter(struct xdp_mdctx)
 {
   // store variables
   struct cursor   c;
@@ -419,50 +419,50 @@ int xdp_dns_filter(struct xdp_md *ctx)
 
   // pass the packet if it is not an ethernet one
   if ((eth = parse_eth(&c, &eth_proto))) {
-       // IPv4 packets
-       if (eth_proto == bpf_htons(ETH_P_IP))
-       {
-               if (!(ipv4 = parse_iphdr(&c)) || bpf_htons(ipv4->protocol != IPPROTO_UDP)) {
-                       return XDP_PASS;
-               }
+    // IPv4 packets
+    if (eth_proto == bpf_htons(ETH_P_IP))
+    {
+      if (!(ipv4 = parse_iphdr(&c)) || bpf_htons(ipv4->protocol != IPPROTO_UDP)) {
+        return XDP_PASS;
+      }
+
       struct CIDR4 key;
       key.addr = bpf_htonl(ipv4->saddr);
       // if TC bit must not be set, apply the action
-               if ((r = udp_dns_reply_v4(&c, &key)) != TC) {
-           return r == DROP ? XDP_DROP : XDP_PASS;
-               }
-  
+      if ((r = udp_dns_reply_v4(&c, &key)) != TC) {
+        return r == DROP ? XDP_DROP : XDP_PASS;
+      }
+
       // swap src/dest IP addresses
-               uint32_t swap_ipv4 = ipv4->daddr;
-               ipv4->daddr = ipv4->saddr;
-               ipv4->saddr = swap_ipv4;
-       }
-       // IPv6 packets
-       else if (eth_proto == bpf_htons(ETH_P_IPV6))
-       {
-               ;
-               if (!(ipv6 = parse_ipv6hdr(&c)) || bpf_htons(ipv6->nexthdr != IPPROTO_UDP)) {
-                       return XDP_PASS;
-               } 
+      uint32_t swap_ipv4 = ipv4->daddr;
+      ipv4->daddr = ipv4->saddr;
+      ipv4->saddr = swap_ipv4;
+    }
+    // IPv6 packets
+    else if (eth_proto == bpf_htons(ETH_P_IPV6)) {
+      if (!(ipv6 = parse_ipv6hdr(&c)) || bpf_htons(ipv6->nexthdr != IPPROTO_UDP)) {
+        return XDP_PASS;
+      }
       struct CIDR6 key;
       key.addr = ipv6->saddr;
+
       // if TC bit must not be set, apply the action
-               if ((r = udp_dns_reply_v6(&c, &key)) != TC) {
-                       return r == DROP ? XDP_DROP : XDP_PASS;
-               }
-  
-      // swap src/dest IP addresses
-               struct in6_addr swap_ipv6 = ipv6->daddr;
-               ipv6->daddr = ipv6->saddr;
-               ipv6->saddr = swap_ipv6;
+      if ((r = udp_dns_reply_v6(&c, &key)) != TC) {
+        return r == DROP ? XDP_DROP : XDP_PASS;
+      }
 
-       }
-       // pass all non-IP packets
-       else {
-               return XDP_PASS;
-       }
-  } else {
-       return XDP_PASS;
+      // swap src/dest IP addresses
+      struct in6_addr swap_ipv6 = ipv6->daddr;
+      ipv6->daddr = ipv6->saddr;
+      ipv6->saddr = swap_ipv6;
+    }
+    // pass all non-IP packets
+    else {
+      return XDP_PASS;
+    }
+  }
+  else {
+    return XDP_PASS;
   }
 
   // swap MAC addresses
index 5ff53527a8cad6772cb6d54a715eadd98eaac97e..331b56692cbf289eedb8f4266cdf417da92ea3ef 100644 (file)
@@ -273,28 +273,32 @@ BPFFilter::Map::Map(const BPFFilter::MapConfiguration& config, BPFFilter::MapFor
           while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
             ++d_count;
           }
-        } break;
+          break;
+        }
         case MapType::IPv6: {
           KeyV6 key;
           memset(&key, 0, sizeof(key));
           while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
             ++d_count;
           }
-        } break;
+          break;
+        }
         case MapType::CIDR4: {
           CIDR4 key;
           memset(&key, 0, sizeof(key));
           while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
             ++d_count;
           }
-        } break;
+          break;
+        }
         case MapType::CIDR6: {
           CIDR6 key;
           memset(&key, 0, sizeof(key));
           while (bpf_get_next_key(d_fd.getHandle(), &key, &key) == 0) {
             ++d_count;
           }
-        } break;
+          break;
+        }
         case MapType::QNames: {
           if (format == MapFormat::Legacy) {
             QNameKey key;
@@ -310,7 +314,8 @@ BPFFilter::Map::Map(const BPFFilter::MapConfiguration& config, BPFFilter::MapFor
               ++d_count;
             }
           }
-        } break;
+          break;
+        }
 
         default:
           throw std::runtime_error("Unsupported eBPF map type: " + std::to_string(static_cast<uint8_t>(d_config.d_type)));