udpHandlePacket processes the incoming UDP packet and sends a DNS response.
( ctx context.Context, packet []byte, localIP netip.Addr, remoteAddr *net.UDPAddr, conn *net.UDPConn, )
| 133 | |
| 134 | // udpHandlePacket processes the incoming UDP packet and sends a DNS response. |
| 135 | func (p *Proxy) udpHandlePacket( |
| 136 | ctx context.Context, |
| 137 | packet []byte, |
| 138 | localIP netip.Addr, |
| 139 | remoteAddr *net.UDPAddr, |
| 140 | conn *net.UDPConn, |
| 141 | ) { |
| 142 | ctx, cancel := p.reqCtx.New(ctx) |
| 143 | defer cancel() |
| 144 | |
| 145 | p.logger.DebugContext(ctx, "handling new udp packet", "raddr", remoteAddr) |
| 146 | |
| 147 | req := &dns.Msg{} |
| 148 | err := req.Unpack(packet) |
| 149 | if err != nil { |
| 150 | p.logger.ErrorContext(ctx, "unpacking udp packet", slogutil.KeyError, err) |
| 151 | |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | d := p.newDNSContext(ProtoUDP, req, netutil.NetAddrToAddrPort(remoteAddr)) |
| 156 | d.Conn = conn |
| 157 | d.localIP = localIP |
| 158 | |
| 159 | err = p.handleDNSRequest(ctx, d) |
| 160 | if err != nil { |
| 161 | p.logger.DebugContext(ctx, "handling dns request", "proto", d.Proto, slogutil.KeyError, err) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // respondUDP writes a response to the UDP client. d must not be nil. |
| 166 | func (p *Proxy) respondUDP(d *DNSContext) error { |
no test coverage detected