Age | Commit message (Collapse) | Author |
|
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
This socket option needs to be set before the bind call(). Since it's very
commonly used, adding a parameter for it makes sense.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
The SO_ATTACH_FILTER socket option requires special handling as it is not
passing a self-contained structure to the kernel but a pointer to user
memory holding the actual BPF bytecode.
In order to properly support this, first rework the ucode value to C struct
conversion callback machinery to pass an indirect struct base pointer,
allowing conversion callbacks to realloc the struct memory as needed.
Finally introduce custom uv to C conversion for the BPF data which accepts
either a raw bytecode string, an array of opcode arrays or a flat array of
opcode values which are converted into a C array of struct sock_filter
records appended to the reallocated struct memory.
Attaching a BPF program equivalent to the tcpdump expression
`vlan 20 && ether proto 0x1234` would then look like this:
sock.setopt(SOL_SOCKET, SO_ATTACH_FILTER, {
filter: [
[ 0x28, 0, 0, 0x0000000c ],
[ 0x15, 2, 0, 0x00008100 ],
[ 0x15, 1, 0, 0x000088a8 ],
[ 0x15, 0, 6, 0x00009100 ],
[ 0x28, 0, 0, 0x0000000e ],
[ 0x54, 0, 0, 0x00000fff ],
[ 0x15, 0, 3, 0x00000014 ],
[ 0x28, 0, 0, 0x00000010 ],
[ 0x15, 0, 1, 0x00001234 ],
[ 0x6, 0, 0, 0x00040000 ],
[ 0x6, 0, 0, 0x00000000 ],
]
});
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Do not unconditionally pass the `MSG_CMSG_CLOEXEC` flag to `recvmsg()`
invocations as not all protocol specific recvmsg implementations in the
kernel tolerate it; `packet_recvmsg()` for example will immediately
return yield `EINVAL` if any non-whitelisted flag is passed.
- Ensure that the HW address string buffer is zero-terminated when
converting MAC addresses from C to ucode values.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
The `fanout_args` structure is a relatively recent addition to the kernel
so provide a local definition for it, like we already do it for other like
`timeval_old`.
Fixes: #217
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Implement socket.recvmsg(), socket.sendmsg() and support for encoding
and decoding well known control message types.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Handle varying integer sizes for socket option values
- Support interfaces name and index option values
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Treat address string values containing slashes as AF_UNIX addresses
- Default to SOCK_DGRAM for non AF_INET, AF_INET6 sockets
- Gracefully handle EOPNOTSUPP condition after listen() call
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Treat address strings containing slashes as AF_UNIX paths and do not
attempt to resolve them.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Do not attempt to calculate a dynamic length for AF_UNIX socket addresses
but return the total size of `struct sockaddr_un`, like we do it for the
structures of other address families as well.
Fixes incorrect domain socket path truncation.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Remove an accidentially copy-pasted jsdoc comment block.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Optimize the poll() function implementation to re-use passed in socket/flag
tuple arrays as-is in the return value array, which simplifies attaching
state to sockets for user code through subsequent fields in the tuple array.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
If a non-string value which cannot be interpreted as socket address
structure is passed to connect(), the function will leak the internal
address vector when returning the error.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Actually pass NULL to getaddrinfo() when the service argument is omitted,
instead of incorrectly translating it to a string containing "null".
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Fixes: 0662de6 ("socket: add AF_PACKET socket type support")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Add the required infrastructure to support Linux AF_PACKET sockets:
- Add related constants
- Add struct definitions for SOL_PACKET socket options
- Add AF_PACKET family support to sockaddr routines
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- fix `error()` function documentation
- change error message format order to `msg: strerror`
- change `xxx() failed` messages to just `xxx()`
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Introduce a new socket module which provides bindings for the BSD sockets
API to ucode scripts.
Example usage:
import * as socket from 'socket';
let sk = socket.create(socket.AF_INET, socket.SOCK_STREAM);
sk.connect("192.168.1.1", 80);
sk.send("GET / HTTP/1.0\r\n\r\n");
print(sk.recv(4096));
sk.close();
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|