From: Y7n05h Date: Fri, 22 Apr 2022 18:31:55 +0000 (+0800) Subject: change code style X-Git-Tag: auth-4.8.0-alpha0~66^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c06007f4c0818e1d6f744b5572d3524e1bdd13a;p=thirdparty%2Fpdns.git change code style Co-authored-by: Remi Gacogne Signed-off-by: Y7n05h --- diff --git a/contrib/xdp-filter.ebpf.src b/contrib/xdp-filter.ebpf.src index 9b0867eaea..5e4d9d13b8 100644 --- a/contrib/xdp-filter.ebpf.src +++ b/contrib/xdp-filter.ebpf.src @@ -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_md* ctx) { // 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, ð_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 diff --git a/pdns/bpf-filter.cc b/pdns/bpf-filter.cc index 5ff53527a8..331b56692c 100644 --- a/pdns/bpf-filter.cc +++ b/pdns/bpf-filter.cc @@ -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(d_config.d_type)));