Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support async message handler, add link selection to relay opts, fix handler fd lookup #8

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
["src/" "test/"]

:dependencies
[[cljs-bean "1.9.0"]]
[[cljs-bean "1.9.0"]
[funcool/promesa "11.0.678"]]

:builds
{:simple-client
Expand Down
2 changes: 2 additions & 0 deletions src/dhcp/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
(def MSG-TYPE-BCAST-LOOKUP (fields/list->lookup MSG-TYPE-LIST [1 3]))

;; https://datatracker.ietf.org/doc/html/rfc3046
;; https://datatracker.ietf.org/doc/html/rfc3527
(def OPTS-RELAY-AGENT-LIST
;; code, name, type
[[0x01 :circuit-id :raw ]
[0x02 :remote-id :raw ]
[0x05 :link-selection :ipv4 ]
[0x06 :subscriber-id :utf8 ]])
(def OPTS-RELAY-AGENT-LOOKUP (tlvs/tlv-list->lookup OPTS-RELAY-AGENT-LIST))

Expand Down
19 changes: 10 additions & 9 deletions src/dhcp/node_server.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

(ns dhcp.node-server
"Framework for creating DHCP server implementations."
(:require [clojure.string :as string]
(:require [promesa.core :as P]
[clojure.string :as string]
[cljs-bean.core :refer [->clj]]
[protocol.socket :as socket]
[dhcp.core :as dhcp]
Expand All @@ -22,16 +23,16 @@
get a response map, and then write/encode the response and send it
via `sock`."
[{:keys [log-msg sock message-handler disable-broadcast] :as cfg} buf rinfo]
(let [msg-map (dhcp/read-dhcp buf)
msg-type (:opt/msg-type msg-map)]
(P/let [msg-map (dhcp/read-dhcp buf)
msg-type (:opt/msg-type msg-map)]
(if (not msg-type)
(log-msg :error (str "Received invalid msg from " rinfo))
(let [resp-addr (if (and (not disable-broadcast)
(dhcp/MSG-TYPE-BCAST-LOOKUP msg-type))
"255.255.255.255"
(:address rinfo))
_ (log-msg :recv msg-map resp-addr)
resp-msg-map (message-handler cfg msg-map)]
(P/let [resp-addr (if (and (not disable-broadcast)
(dhcp/MSG-TYPE-BCAST-LOOKUP msg-type))
"255.255.255.255"
(:address rinfo))
_ (log-msg :recv msg-map resp-addr)
resp-msg-map (message-handler cfg msg-map)]
(if resp-msg-map
(send-message cfg resp-msg-map resp-addr (:port rinfo))
(log-msg :error "No msg-map from message-handler, ignoring"))))))
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/socket.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
(defn setsockopt
"Set `level`/`option`/`value` socket options on `sock`"
[sock level option value]
(let [fd (if (number? sock) sock ^number (.-_handle.fd sock))
(let [fd (if (number? sock) sock ^number (.-fd ^Object (.-_handle sock)))
level-num (if (number? level) level (get PROTOCOLS level))
option-num (if (number? option) option (get-in OPTIONS [level option]))
buf (if (string? value) value (ref/alloc ref/types.int value))
Expand Down
Loading