Skip to content

Commit

Permalink
feat(dns): add an option device to set SO_BINDTODEVICE
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Mar 19, 2024
1 parent 98e842b commit 13b0ff1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ end
nameservers: a list of nameservers to be used. Each nameserver entry can be either a
single hostname string or a table holding both the hostname string and the port number.
mark: a number used to set SO_MARK to socket
device: a string used to set SO_BINDTODEVICE to socket
--]]
function M.query(qname, opts)
if string.byte(qname, 1) == string.byte('.') or #qname > 255 then
Expand Down Expand Up @@ -526,6 +527,10 @@ function M.query(qname, opts)
s:setoption('mark', opts.mark)
end

if opts.device then
s:setoption('bindtodevice', opts.device)
end

answers, err = query(s, id, req, nameserver)
s:close()

Expand Down
4 changes: 4 additions & 0 deletions socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ function M.socket(family, domain, protocol, options)
sock:setoption('mark', options.mark)
end

if options.device then
sock:setoption('bindtodevice', options.device)
end

return setmetatable(o, metatable)
end

Expand Down

0 comments on commit 13b0ff1

Please sign in to comment.