sock: pass protocol to sockets

This commit is contained in:
Matheus
2026-09-10 16:41:21 -03:00
parent 894d9bdaf9
commit 79752fb5e0
9 changed files with 36 additions and 26 deletions
+8 -8
View File
@@ -1132,12 +1132,12 @@ void localsock_leavebinding(vnode_t *vnode) {
vnode->socketbinding = NULL;
}
int localsock_pair(socket_t **ret1, socket_t **ret2) {
socket_t *socket1 = socket_create(SOCKET_TYPE_LOCAL);
int localsock_pair(socket_t **ret1, socket_t **ret2, int protocol) {
socket_t *socket1 = socket_create(SOCKET_TYPE_LOCAL, protocol);
if (socket1 == NULL)
return ENOMEM;
socket_t *socket2 = socket_create(SOCKET_TYPE_LOCAL);
socket_t *socket2 = socket_create(SOCKET_TYPE_LOCAL, protocol);
if (socket2 == NULL) {
localsock_destroy(socket1);
return ENOMEM;
@@ -1168,8 +1168,8 @@ int localsock_pair(socket_t **ret1, socket_t **ret2) {
return 0;
}
int localsock_pair_seqpacket(socket_t **ret1, socket_t **ret2) {
int error = localsock_pair(ret1, ret2);
int localsock_pair_seqpacket(socket_t **ret1, socket_t **ret2, int protocol) {
int error = localsock_pair(ret1, ret2, protocol);
if (error)
return error;
@@ -1421,7 +1421,7 @@ static socketops_t socketops = {
.setopt = localsock_setopt
};
socket_t *localsock_createsocket(void) {
socket_t *localsock_createsocket(int protocol) {
// XXX possibly move this to a slab?
localsocket_t *socket = alloc(sizeof(localsocket_t));
if (socket == NULL)
@@ -1444,8 +1444,8 @@ socket_t *localsock_createsocket(void) {
return (socket_t *)socket;
}
socket_t *localsock_create_seqpacket_socket(void) {
localsocket_t *localsocket = (localsocket_t *)localsock_createsocket();
socket_t *localsock_create_seqpacket_socket(int protocol) {
localsocket_t *localsocket = (localsocket_t *)localsock_createsocket(protocol);
if (localsocket == NULL)
return NULL;
+4 -3
View File
@@ -2,7 +2,7 @@
#include <kernel/raw.h>
#include <logging.h>
static socket_t *(*createsocket[])() = {
static socket_t *(*createsocket[])(int) = {
udp_createsocket,
localsock_createsocket,
tcp_createsocket,
@@ -10,9 +10,9 @@ static socket_t *(*createsocket[])() = {
raw_create_socket
};
socket_t *socket_create(int type) {
socket_t *socket_create(int type, int protocol) {
__assert(type < sizeof(createsocket) / sizeof(createsocket[0]));
socket_t *socket = createsocket[type]();
socket_t *socket = createsocket[type](protocol);
if (socket == NULL)
return NULL;
@@ -20,6 +20,7 @@ socket_t *socket_create(int type) {
socket->state = SOCKET_STATE_UNBOUND;
MUTEX_INIT(&socket->mutex);
socket->type = type;
socket->protocol = protocol;
socket->nonblocking = false;
return socket;
+1 -1
View File
@@ -1973,7 +1973,7 @@ static socketops_t socketops = {
.getopt = tcp_getopt
};
socket_t *tcp_createsocket() {
socket_t *tcp_createsocket(int protocol) {
tcpsocket_t *socket = alloc(sizeof(tcpsocket_t));
if (socket == NULL)
return NULL;
+1 -1
View File
@@ -382,7 +382,7 @@ static socketops_t socketops = {
.connect = udp_connect
};
socket_t *udp_createsocket() {
socket_t *udp_createsocket(int protocol) {
// XXX possibly move this to a slab?
udpsocket_t *socket = alloc(sizeof(udpsocket_t));
if (socket == NULL)