Push packet reencoding back into the chassis too
This commit is contained in:
parent
2599833904
commit
b15ce583e3
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
;; Simple imperative UDP server harness.
|
;; Simple imperative UDP server harness.
|
||||||
|
|
||||||
|
(require racket/match)
|
||||||
(require racket/udp)
|
(require racket/udp)
|
||||||
(require "dump-bytes.rkt")
|
(require "dump-bytes.rkt")
|
||||||
|
|
||||||
|
@ -21,8 +22,9 @@
|
||||||
(define (start-udp-service
|
(define (start-udp-service
|
||||||
port-number ;; Uint16
|
port-number ;; Uint16
|
||||||
packet-classifier ;; UdpPacket -> Maybe<ClassifiedPacket>
|
packet-classifier ;; UdpPacket -> Maybe<ClassifiedPacket>
|
||||||
bad-packet-handler ;; UdpPacket ServerState -> ListOf<UdpPacket> ServerState
|
bad-packet-handler ;; UdpPacket ServerState -> ListOf<ClassifiedPacket> ServerState
|
||||||
good-packet-handler ;; ClassifiedPacket ServerState -> ListOf<UdpPacket> ServerState
|
good-packet-handler ;; ClassifiedPacket ServerState -> ListOf<ClassifiedPacket> ServerState
|
||||||
|
packet-encoder ;; ClassifiedPacket -> UdpPacket
|
||||||
initial-state ;; ServerState
|
initial-state ;; ServerState
|
||||||
#:packet-size-limit
|
#:packet-size-limit
|
||||||
[packet-size-limit 65536])
|
[packet-size-limit 65536])
|
||||||
|
@ -48,7 +50,8 @@
|
||||||
(else (good-packet-handler classified-packet old-state))))
|
(else (good-packet-handler classified-packet old-state))))
|
||||||
|
|
||||||
(for-each (lambda (p)
|
(for-each (lambda (p)
|
||||||
(udp-send-to s (udp-packet-host p) (udp-packet-port p) (udp-packet-body p)))
|
(match-define (udp-packet body host port) (packet-encoder p))
|
||||||
|
(udp-send-to s host port body))
|
||||||
reply-packets)
|
reply-packets)
|
||||||
new-state)
|
new-state)
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
classify-dns-packet
|
classify-dns-packet
|
||||||
(lambda (packet old-state) (values (log-error packet) old-state))
|
(lambda (packet old-state) (values (log-error packet) old-state))
|
||||||
(lambda (message old-state) (values (handle-request soa-rr zone message) old-state))
|
(lambda (message old-state) (values (handle-request soa-rr zone message) old-state))
|
||||||
|
encode-dns-packet
|
||||||
#f
|
#f
|
||||||
#:packet-size-limit 512))
|
#:packet-size-limit 512))
|
||||||
|
|
||||||
|
@ -79,6 +80,10 @@
|
||||||
(with-handlers ((exn? (lambda (e) #f)))
|
(with-handlers ((exn? (lambda (e) #f)))
|
||||||
(list (packet->dns-message body) host port)))
|
(list (packet->dns-message body) host port)))
|
||||||
|
|
||||||
|
(define (encode-dns-packet data)
|
||||||
|
(match-define (list message host port) data)
|
||||||
|
(udp-packet (dns-message->packet message) host port))
|
||||||
|
|
||||||
;; UdpPacket -> ListOf<UdpPacket>
|
;; UdpPacket -> ListOf<UdpPacket>
|
||||||
(define (log-error packet)
|
(define (log-error packet)
|
||||||
(pretty-print `(bad-packet-received ,packet))
|
(pretty-print `(bad-packet-received ,packet))
|
||||||
|
@ -159,9 +164,7 @@
|
||||||
;; TODO: check opcode and direction in request
|
;; TODO: check opcode and direction in request
|
||||||
;; TODO: think again about multiple questions in one packet
|
;; TODO: think again about multiple questions in one packet
|
||||||
(map (lambda (q)
|
(map (lambda (q)
|
||||||
(udp-packet (dns-message->packet (answer-question q make-reply))
|
(list (answer-question q make-reply) request-host request-port))
|
||||||
request-host
|
|
||||||
request-port))
|
|
||||||
(dns-message-questions request-message)))
|
(dns-message-questions request-message)))
|
||||||
|
|
||||||
(start-server 5555
|
(start-server 5555
|
||||||
|
|
Loading…
Reference in New Issue