Factor common RAW AF_PACKET socket pattern#360
Conversation
lneto
left a comment
There was a problem hiding this comment.
I would use the very same approach we use on unix.lua; we can leverage the new() function we have there to better modularize our code here..
could you also apply this new lib on the examples that should use it on this PR?
lneto
left a comment
There was a problem hiding this comment.
btw, please use --fixup on your commits or squash it.. let's keep our history as clean as possible
5befca5 to
d32f704
Compare
lib/socket/raw.lua
Outdated
| local function new(method) | ||
| raw[method] = function (proto, ifindex) | ||
| local proto = proto or ETH_P_ALL | ||
| local ifindex = ifindex or 0 | ||
| local s = socket.new(af.PACKET, sock.RAW, proto) | ||
| s:bind(string.pack(">H", proto), ifindex) | ||
| return s | ||
| end | ||
| end | ||
|
|
||
| --- | ||
| -- Creates and binds a raw packet socket for receiving and sending frames. | ||
| -- @param proto (number) EtherType (defaults to ETH_P_ALL). | ||
| -- @param ifindex (number) Interface index. | ||
| -- @return A new raw packet socket bound for RX. | ||
| -- @raise Error if socket.new() or socket.bind() fail. | ||
| -- @see socket.new | ||
| -- @see socket.bind | ||
| new("bind") |
There was a problem hiding this comment.
| local function new(method) | |
| raw[method] = function (proto, ifindex) | |
| local proto = proto or ETH_P_ALL | |
| local ifindex = ifindex or 0 | |
| local s = socket.new(af.PACKET, sock.RAW, proto) | |
| s:bind(string.pack(">H", proto), ifindex) | |
| return s | |
| end | |
| end | |
| --- | |
| -- Creates and binds a raw packet socket for receiving and sending frames. | |
| -- @param proto (number) EtherType (defaults to ETH_P_ALL). | |
| -- @param ifindex (number) Interface index. | |
| -- @return A new raw packet socket bound for RX. | |
| -- @raise Error if socket.new() or socket.bind() fail. | |
| -- @see socket.new | |
| -- @see socket.bind | |
| new("bind") | |
| --- | |
| -- Creates and binds a raw packet socket for receiving and sending frames. | |
| -- @param proto (number) EtherType (defaults to ETH_P_ALL). | |
| -- @param ifindex (number) Interface index. | |
| -- @return A new raw packet socket bound for RX. | |
| -- @raise Error if socket.new() or socket.bind() fail. | |
| -- @see socket.new | |
| -- @see socket.bind | |
| function bind.new(proto, ifindex) | |
| local proto = proto or ETH_P_ALL | |
| local ifindex = ifindex or 0 | |
| local s = socket.new(af.PACKET, sock.RAW, proto) | |
| s:bind(string.pack(">H", proto), ifindex) | |
| return s | |
| end |
if we will have only one method for creating a new raw socket, I'd keep that simpler and avoid the factory..
There was a problem hiding this comment.
resolved in latest push
Move recurring raw socket recieve and send pattern in a common place. Signed-off-by: Ashwani Kumar Kamal <[email protected]>
d32f704 to
8f3f963
Compare
|
Hi @lneto Also I believe we need to call |
Move recurring raw socket receive and send pattern in a common place.
Fixes #358