-
Notifications
You must be signed in to change notification settings - Fork 47
Factor common RAW AF_PACKET socket pattern #360
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
Conversation
lneto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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