mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
sock: pass protocol to sockets
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
#ifndef _RAW_H
|
||||
#define _RAW_H
|
||||
|
||||
void raw_process(netdev_t *netdev, void *buffer, uint32_t peer);
|
||||
socket_t *raw_create_socket(void);
|
||||
typedef struct socket socket_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t netdev; // 1-based index that gets transformed into a minor number
|
||||
uint16_t proto;
|
||||
uint8_t mac[6];
|
||||
} raw_addr_t;
|
||||
|
||||
void raw_process(netdev_t *netdev, void *buffer, mac_t *sender, uint16_t proto, size_t size);
|
||||
socket_t *raw_create_socket(int protocol);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,7 @@ typedef struct {
|
||||
netdev_t *netdev;
|
||||
pollheader_t pollheader;
|
||||
int type;
|
||||
int protocol;
|
||||
int shutdown;
|
||||
int error;
|
||||
bool nonblocking;
|
||||
@@ -363,13 +364,13 @@ static inline size_t sock_countctrl(sockctrl_t *ctrl, size_t len) {
|
||||
}
|
||||
|
||||
void localsock_leavebinding(vnode_t *vnode);
|
||||
int localsock_pair(socket_t **ret1, socket_t **ret2);
|
||||
int localsock_pair_seqpacket(socket_t **ret1, socket_t **ret2);
|
||||
socket_t *localsock_createsocket(void);
|
||||
socket_t *localsock_create_seqpacket_socket(void);
|
||||
socket_t *udp_createsocket();
|
||||
socket_t *tcp_createsocket();
|
||||
socket_t *socket_create(int type);
|
||||
int localsock_pair(socket_t **ret1, socket_t **ret2, int protocol);
|
||||
int localsock_pair_seqpacket(socket_t **ret1, socket_t **ret2, int protocol);
|
||||
socket_t *localsock_createsocket(int protocol);
|
||||
socket_t *localsock_create_seqpacket_socket(int protocol);
|
||||
socket_t *udp_createsocket(int protocol);
|
||||
socket_t *tcp_createsocket(int protocol);
|
||||
socket_t *socket_create(int type, int protocol);
|
||||
int sockfs_newsocket(vnode_t **vnodep, socket_t *socket);
|
||||
void sockfs_init();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -28,7 +28,7 @@ syscallret_t syscall_accept(context_t *, int oldfd, abisockaddr_t *abisockaddr,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
socket_t *client = socket_create(server->type);
|
||||
socket_t *client = socket_create(server->type, server->protocol);
|
||||
if (client == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
goto cleanup;
|
||||
|
||||
@@ -43,7 +43,7 @@ syscallret_t syscall_socket(context_t *, int domain, int type, int protocol) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
socket_t *socket = socket_create(socktype);
|
||||
socket_t *socket = socket_create(socktype, protocol);
|
||||
if (socket == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
return ret;
|
||||
|
||||
@@ -37,9 +37,9 @@ syscallret_t syscall_socketpair(context_t *, int domain, int type, int protocol)
|
||||
|
||||
// create pair
|
||||
if (type == SOCK_SEQPACKET)
|
||||
ret.errno = localsock_pair_seqpacket(&sock1, &sock2);
|
||||
ret.errno = localsock_pair_seqpacket(&sock1, &sock2, protocol);
|
||||
else
|
||||
ret.errno = localsock_pair(&sock1, &sock2);
|
||||
ret.errno = localsock_pair(&sock1, &sock2, protocol);
|
||||
if (ret.errno)
|
||||
return ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user