summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Schulte <moritz@duesseldorf.ccc.de>2002-10-23 01:06:23 +0000
committerMoritz Schulte <moritz@duesseldorf.ccc.de>2002-10-23 01:06:23 +0000
commit9c9949846e9958520994009b7ed2a98367bc6994 (patch)
tree169ae34d854c57036755700e8c643628fbd438ce
parent86257c4e9551141cab13bc26521f99231f47f8fa (diff)
2002-10-23 Moritz Schulte <moritz@duesseldorf.ccc.de>
* netfs.c (netfs_attempt_lookup): Return ENOTDIR instead of EOPNOTSUPP in case the user tries to look something up beneath a port node. (netfs_S_io_read): Correct the netio specific hack, make it apply only for PORT_NODEs. (netfs_attempt_create_file): Clear *np and unlocked &dir->lock. (netfs_attempt_write): Set err to EISDIR if trying to write to a node, which is not a PORT_NODE. (netfs_attempt_read): Set *len to 0, if trying to read from a node, which is not a PORT_NODE, otherwise try to read from socket via socket_recv; update *len to nread after successfull reading. * main.c: Declare ul_node static. * lib.h: Include comments from lib.c. * version.h: Updated. * protocol.c (PROTOCOL_INIT): New macro, used in initializing protocols array. (protocol_socket_open_tcp): Renamed to protocol_socket_open_TCP. (protocol_socket_open_udp): Renamed to protocol_socket_open_UDP. (protocol_find_node): Cleanup. * main.c: Assigned Copyright to FSF. * Makefile: Likewise. * lib.c: Likewise. * lib.h: Likewise. * netfs.c: Likewise. * netio.h: Likewise. (PROTOCOL_NAME_TCP): Defined to "tcp". (PROTOCOL_NAME_UDP): Defined to "udp". Typedef for socket_open_func_t. (OPENONLY_STATE_MODES): Remove definition. Added some comments. * node.c: Likewise. * node.h: Likewise. * protocol.c: Likewise. (protocol_socket_open_std): Added static keyword. (protocol_socket_open_tcp): Likewise. (protocol_socket_open_udp): Likewise. Declared protocol_socket_open_tcp and protocol_socket_open_udp. * protocol.h: Likewise. * protocol.c (protocol_register_protocols): Renamed to protocol_register_default ... * protocol.h: Likewise. * main.c (main): ... and used. * netfs.c (netfs_attempt_mkdir): Call protocol_register to create protocol directories beneath the root directory. (netfs_attempt_rmdir): Cleanup. 2002-10-22 Moritz Schulte <moritz@duesseldorf.ccc.de> * protocol.c (protocol_register): Don't take "id" and "socket_open_func" arguments. (protocol_register): Don't allocate new protocol structure for the node, instead use a pointer to the static protocols structure. (protocol_find_by_name): New function. (protocol_register_protocols): Rewritten to iterate over protocols list. * protocol.h (protocol_register): Likewise. * node.c (node_destroy): Don't free np->nn->protocol. * netio.h (struct protocol): Typedef to protocol_t. * protocol.c (protocols): New array, initialized with protocol information. * netfs.c (netfs_attempt_lookup): Use strcmp instead of STRING_EQUAL. * lib.h: Remove STRING_EQUAL definition.
-rw-r--r--ChangeLog66
-rw-r--r--Makefile3
-rw-r--r--lib.c6
-rw-r--r--lib.h10
-rw-r--r--main.c11
-rw-r--r--netfs.c133
-rw-r--r--netio.h42
-rw-r--r--node.c10
-rw-r--r--node.h3
-rw-r--r--protocol.c98
-rw-r--r--protocol.h10
-rw-r--r--version.h11
12 files changed, 274 insertions, 129 deletions
diff --git a/ChangeLog b/ChangeLog
index 946c4806f..344cd1daf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,68 @@
+2002-10-23 Moritz Schulte <moritz@duesseldorf.ccc.de>
+
+ * netfs.c (netfs_attempt_lookup): Return ENOTDIR instead of
+ EOPNOTSUPP in case the user tries to look something up beneath a
+ port node.
+ (netfs_S_io_read): Correct the netio specific hack, make it apply
+ only for PORT_NODEs.
+ (netfs_attempt_create_file): Clear *np and unlocked &dir->lock.
+ (netfs_attempt_write): Set err to EISDIR if trying to write to a
+ node, which is not a PORT_NODE.
+ (netfs_attempt_read): Set *len to 0, if trying to read from a
+ node, which is not a PORT_NODE, otherwise try to read from socket
+ via socket_recv; update *len to nread after successfull reading.
+ * main.c: Declare ul_node static.
+ * lib.h: Include comments from lib.c.
+ * version.h: Updated.
+ * protocol.c (PROTOCOL_INIT): New macro, used in initializing
+ protocols array.
+ (protocol_socket_open_tcp): Renamed to protocol_socket_open_TCP.
+ (protocol_socket_open_udp): Renamed to protocol_socket_open_UDP.
+ (protocol_find_node): Cleanup.
+ * main.c: Assigned Copyright to FSF.
+ * Makefile: Likewise.
+ * lib.c: Likewise.
+ * lib.h: Likewise.
+ * netfs.c: Likewise.
+ * netio.h: Likewise.
+ (PROTOCOL_NAME_TCP): Defined to "tcp".
+ (PROTOCOL_NAME_UDP): Defined to "udp".
+ Typedef for socket_open_func_t.
+ (OPENONLY_STATE_MODES): Remove definition.
+ Added some comments.
+ * node.c: Likewise.
+ * node.h: Likewise.
+ * protocol.c: Likewise.
+ (protocol_socket_open_std): Added static keyword.
+ (protocol_socket_open_tcp): Likewise.
+ (protocol_socket_open_udp): Likewise.
+ Declared protocol_socket_open_tcp and protocol_socket_open_udp.
+ * protocol.h: Likewise.
+ * protocol.c (protocol_register_protocols): Renamed to
+ protocol_register_default ...
+ * protocol.h: Likewise.
+ * main.c (main): ... and used.
+ * netfs.c (netfs_attempt_mkdir): Call protocol_register to create
+ protocol directories beneath the root directory.
+ (netfs_attempt_rmdir): Cleanup.
+
2002-10-22 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ * protocol.c (protocol_register): Don't take "id" and
+ "socket_open_func" arguments.
+ (protocol_register): Don't allocate new protocol structure for the
+ node, instead use a pointer to the static protocols structure.
+ (protocol_find_by_name): New function.
+ (protocol_register_protocols): Rewritten to iterate over protocols
+ list.
+ * protocol.h (protocol_register): Likewise.
+ * node.c (node_destroy): Don't free np->nn->protocol.
+ * netio.h (struct protocol): Typedef to protocol_t.
+ * protocol.c (protocols): New array, initialized with protocol
+ information.
+ * netfs.c (netfs_attempt_lookup): Use strcmp instead of
+ STRING_EQUAL.
+ * lib.h: Remove STRING_EQUAL definition.
* Makefile (CFLAGS): Added -D_FILE_OFFSET_BITS=64.
2002-10-19 Moritz Schulte <moritz@duesseldorf.ccc.de>
@@ -9,15 +72,12 @@
2002-10-19 Moritz Schulte <moritz@duesseldorf.ccc.de>
* main.c (main): Initialize stat_default.
-
* node.c: New variable: struct stat stat_default.
(node_make_new): Initialize (*node)->nn_stat with stat_default.
-
* node.c (node_make_protocol_node): Remove unnecessary nn_stat
initialization.
(node_make_host_node): Likewise.
(node_make_port_node): Likewise.
-
* main.c: New variable: int fsid ...
(main): ... initialized with getpid ().
diff --git a/Makefile b/Makefile
index 40eb53d5c..13777e341 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
# netio - creates socket ports via the filesystem
-# Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+# Copyright (C) 2001, 02 Free Software Foundation, Inc.
+# Written by Moritz Schulte.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff --git a/lib.c b/lib.c
index 295ad5e8d..d21ee4779 100644
--- a/lib.c
+++ b/lib.c
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -31,7 +32,7 @@
#include "lib.h"
/* Try to alloc SIZE bytes into *MEM. Return ENOMEM if malloc()
- failed. */
+ failed. */
error_t
my_malloc (size_t size, void **mem)
{
@@ -49,6 +50,7 @@ open_socket_server (int no, pf_t *sock)
char *path;
error_t err;
pf_t port;
+
err = asprintf (&path, "%s/%i", _SERVERS_SOCKET, no);
if (err < 0)
return ENOMEM;
diff --git a/lib.h b/lib.h
index b5744cb59..b8e44d124 100644
--- a/lib.h
+++ b/lib.h
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -20,7 +21,10 @@
#include <stdint.h>
#include <hurd/socket.h>
-#define STRING_EQUAL(s1, s2) (! strcmp (s1, s2))
-
+/* Try to alloc SIZE bytes into *MEM. Return ENOMEM if malloc()
+ failed. */
error_t my_malloc (size_t size, void **mem);
+
+/* Open a port to the socket server for the protocol family number NO
+ and store it in *SOCK. Return 0 on success or an error code. */
error_t open_socket_server (int no, pf_t *sock);
diff --git a/main.c b/main.c
index c2fece4d9..d218ab3eb 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -42,7 +43,7 @@ const char *argp_program_bug_address =
const char *doc = "Hurd netio translator v" NETIO_VERSION;
/* The underlying node. */
-mach_port_t ul_node;
+static mach_port_t ul_node;
/* The socket server, PF_INET for us. */
pf_t socket_server;
@@ -79,11 +80,13 @@ main (int argc, char **argv)
error_t err;
extern struct stat stat_default;
+ /* Start the server. */
argp_parse (&netio_argp, argc, argv, 0, 0, 0);
task_get_bootstrap_port (mach_task_self (), &bootstrap_port);
netfs_init ();
ul_node = netfs_startup (bootstrap_port, 0);
+ /* Initialize netio. */
err = node_make_root_node (&netfs_root_node);
if (err)
error (EXIT_FAILURE, err, "cannot create root node");
@@ -141,9 +144,9 @@ main (int argc, char **argv)
if (err)
error (EXIT_FAILURE, err, "open_socket_server");
- err = protocol_register_protocols ();
+ err = protocol_register_default ();
if (err)
- error (EXIT_FAILURE, err, "protocol_register_protocols");
+ error (EXIT_FAILURE, err, "protocol_register_default");
for (;;)
netfs_server_loop ();
diff --git a/netfs.c b/netfs.c
index 149732b8a..e4adf8e0f 100644
--- a/netfs.c
+++ b/netfs.c
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -55,15 +56,16 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
char *name, struct node **node)
{
error_t err;
+
err = fshelp_access (&dir->nn_stat, S_IEXEC, user);
if (err)
goto out;
- if (STRING_EQUAL (name, "."))
+ if (! strcmp (name, "."))
{
*node = dir;
netfs_nref (*node);
}
- else if (STRING_EQUAL (name, ".."))
+ else if (! strcmp (name, ".."))
{
*node = dir->nn->dir;
netfs_nref (*node);
@@ -81,7 +83,8 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
netfs_nref (*node);
}
else
- err = EOPNOTSUPP; /* FIXME? */
+ /* Trying to look something inside beneath a port node. */
+ err = ENOTDIR;
}
out:
@@ -237,6 +240,7 @@ error_t
netfs_attempt_sync (struct iouser *cred, struct node *np,
int wait)
{
+
return EOPNOTSUPP;
}
@@ -272,7 +276,18 @@ error_t
netfs_attempt_mkdir (struct iouser *user, struct node *dir,
char *name, mode_t mode)
{
- return EOPNOTSUPP;
+ error_t err = 0;
+
+ /* Creating of protocol directories is allowed. */
+ if (dir->nn->dir)
+ err = EOPNOTSUPP;
+ else
+ {
+ err = protocol_register (name);
+ if (err == ENOENT)
+ err = EOPNOTSUPP;
+ }
+ return err;
}
/* Attempt to remove directory named NAME in DIR (which is locked) for
@@ -281,10 +296,14 @@ error_t
netfs_attempt_rmdir (struct iouser *user,
struct node *dir, char *name)
{
- /* Let's allow unlinking of protocol directories. */
+ error_t err = 0;
+
+ /* Removing of protocol directories is allowed. */
if (dir->nn->dir)
- return EOPNOTSUPP;
- return protocol_unregister (name);
+ err = EOPNOTSUPP;
+ else
+ err = protocol_unregister (name);
+ return err;
}
/* Create a link in DIR with name NAME to FILE for USER. Note that
@@ -315,6 +334,8 @@ error_t
netfs_attempt_create_file (struct iouser *user, struct node *dir,
char *name, mode_t mode, struct node **np)
{
+ *np = 0;
+ mutex_unlock (&dir->lock);
return EOPNOTSUPP;
}
@@ -333,6 +354,7 @@ netfs_check_open_permissions (struct iouser *user, struct node *np,
int flags, int newnode)
{
error_t err = 0;
+
if (! err && (flags & O_READ))
err = fshelp_access (&np->nn_stat, S_IREAD, user);
if (! err && (flags & O_WRITE))
@@ -350,39 +372,40 @@ netfs_attempt_read (struct iouser *cred, struct node *np,
off_t offset, size_t *len, void *data)
{
error_t err = 0;
+
if (! (np->nn->flags & PORT_NODE))
*len = 0;
- {
- addr_port_t addrport;
- char *bufp = (char *) data;
- mach_msg_type_number_t nread = *len;
- mach_port_t *ports;
- mach_msg_type_number_t nports;
- char *cdata = NULL;
- mach_msg_type_number_t clen = 0;
- int flags = 0;
-
- if (err)
- goto out;
- err = socket_recv (np->nn->sock, &addrport, flags, &bufp, &nread,
- &ports, &nports, &cdata, &clen, &flags,
- nread);
- if (err)
- goto out;
+ else
+ {
+ addr_port_t addrport;
+ char *bufp = (char *) data;
+ mach_msg_type_number_t nread = *len;
+ mach_port_t *ports;
+ mach_msg_type_number_t nports;
+ char *cdata = NULL;
+ mach_msg_type_number_t clen = 0;
+ int flags = 0;
- mach_port_deallocate (mach_task_self (), addrport);
- vm_deallocate (mach_task_self (), (vm_address_t) cdata, clen);
- if (bufp != (char *) data)
- {
- memcpy ((char *) data, bufp, nread);
- vm_deallocate (mach_task_self (), (vm_address_t) bufp, nread);
- }
- }
- out:
+ err = socket_recv (np->nn->sock, &addrport, flags, &bufp, &nread,
+ &ports, &nports, &cdata, &clen, &flags,
+ *len);
+ if (! err)
+ {
+ mach_port_deallocate (mach_task_self (), addrport);
+ vm_deallocate (mach_task_self (), (vm_address_t) cdata, clen);
+ if (bufp != (char *) data)
+ {
+ memcpy ((char *) data, bufp, nread);
+ vm_deallocate (mach_task_self (), (vm_address_t) bufp, nread);
+ }
+ *len = nread;
+ }
+ }
+
return err;
}
-/* Write to the locked file NP for user CRED starting at OFSET and
+/* Write to the locked file NP for user CRED starting at OFFSET and
continuing for up to *LEN bytes from DATA. Set *LEN to the amount
successfully written upon return. */
error_t
@@ -390,14 +413,19 @@ netfs_attempt_write (struct iouser *cred, struct node *np,
off_t offset, size_t *len, void *data)
{
error_t err = 0;
- if (! np->nn->connected)
- err = node_connect_socket (np);
- if (err)
- goto out;
- err = socket_send (np->nn->sock, MACH_PORT_NULL, 0, (char *) data,
- *len, NULL, MACH_MSG_TYPE_COPY_SEND, 0, NULL, 0,
- (int *) len);
- out:
+
+ if (np->nn->flags & PORT_NODE)
+ {
+ if (! np->nn->connected)
+ err = node_connect_socket (np);
+ if (! err)
+ err = socket_send (np->nn->sock, MACH_PORT_NULL, 0, (char *) data,
+ *len, NULL, MACH_MSG_TYPE_COPY_SEND, 0, NULL, 0,
+ (int *) len);
+ }
+ else
+ err = EISDIR;
+
return err;
}
@@ -556,6 +584,7 @@ block_for_reading (socket_t sock)
mach_port_t reply_port;
int type = SELECT_READ;
error_t err;
+
do
{
reply_port = mach_reply_port ();
@@ -587,13 +616,17 @@ netfs_S_io_read (struct protid *user,
node = user->po->np;
- /* This is our special hack. */
- if (! node->nn->connected)
- err = node_connect_socket (node);
- if (err || node->nn->flags & PORT_NODE)
- err = block_for_reading (node->nn->sock);
- if (err)
- return err;
+ /* This is our special hack; applies only to PORT_NODEs. */
+ if (node->nn->flags & PORT_NODE)
+ {
+ err = 0;
+ if (! node->nn->connected)
+ err = node_connect_socket (node);
+ if (! err)
+ err = block_for_reading (node->nn->sock);
+ if (err)
+ return err;
+ }
mutex_lock (&user->po->np->lock);
diff --git a/netio.h b/netio.h
index 6a4f7eaab..cf5e07294 100644
--- a/netio.h
+++ b/netio.h
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -20,20 +21,26 @@
#include <stdint.h>
#include <maptime.h>
-#define NETIO_VERSION "0.2"
-
-#define OPENONLY_STATE_MODES (O_CREAT|O_EXCL|O_NOLINK|O_NOTRANS|O_NONBLOCK)
+#define NETIO_VERSION "0.3cvs"
+/* The supported protocols. */
#define PROTOCOL_ID_TCP 0x00000001
#define PROTOCOL_ID_UDP 0x00000002
+#define PROTOCOL_NAME_TCP "tcp"
+#define PROTOCOL_NAME_UDP "udp"
+
+/* Type for functions, which connect a node socket. */
+typedef error_t (*socket_open_func_t) (struct node *node);
-struct protocol
+/* One of these items per supported protocol. */
+typedef struct protocol
{
- char *name;
int id;
- error_t (*socket_open) (struct node *np);
-};
+ char *name;
+ socket_open_func_t socket_open_func;
+} protocol_t;
+/* The different kinds of nodes managed by netio. */
#define ROOT_NODE 0x00000001
#define PROTOCOL_NODE 0x00000002
#define HOST_NODE 0x00000004
@@ -43,14 +50,17 @@ struct netnode
{
unsigned short int flags; /* Either ROOT_NODE, PROTOCOL_NODE,
HOST_NODE or PORT_NODE. */
- char *host;
- uint16_t port;
- struct protocol *protocol;
- socket_t sock;
- addr_port_t addr;
- unsigned short int connected;
- struct node *entries;
- struct node *dir;
+ char *host; /* The host to connect to. */
+ uint16_t port; /* The port to connect to. */
+ struct protocol *protocol; /* The protocol information. */
+ socket_t sock; /* Our socket port. */
+ addr_port_t addr; /* Our socket address port. */
+ unsigned short int connected; /* non-zero, if the socket is
+ connected. */
+ struct node *entries; /* The entries in this directory, only
+ useful for the root node. */
+ struct node *dir; /* The parent directory. */
};
+/* Used for touching the [acm]times of our nodes. */
extern volatile struct mapped_time_value *netio_maptime;
diff --git a/node.c b/node.c
index 0524d5d43..f440c1c96 100644
--- a/node.c
+++ b/node.c
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -89,7 +90,6 @@ node_destroy (struct node *np)
free (np->nn->host);
else if (np->nn->flags & PROTOCOL_NODE)
{
- free (np->nn->protocol);
*np->prevp = np->next;
if (np->next)
np->next->prevp = np->prevp;
@@ -107,10 +107,11 @@ node_destroy (struct node *np)
/* Create a new protocol node for *PROTOCOL in the directory *DIR.
Return 0 on success or an error code. */
error_t
-node_make_protocol_node (struct node *dir, struct protocol *protocol)
+node_make_protocol_node (struct node *dir, protocol_t *protocol)
{
struct node *node;
error_t err;
+
err = node_make_new (dir, 1, &node);
if (err)
return err;
@@ -201,7 +202,8 @@ error_t
node_connect_socket (struct node *np)
{
error_t err;
- err = (*np->nn->protocol->socket_open) (np);
+
+ err = (*np->nn->protocol->socket_open_func) (np);
if (! err)
np->nn->connected = 1;
return err;
diff --git a/node.h b/node.h
index 3169beef9..c778d6124 100644
--- a/node.h
+++ b/node.h
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2001, 02 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
diff --git a/protocol.c b/protocol.c
index 88dcb5901..adbe06a6f 100644
--- a/protocol.c
+++ b/protocol.c
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2002 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -25,10 +26,22 @@
#include "lib.h"
#include "node.h"
+static error_t protocol_socket_open_TCP (struct node *node);
+static error_t protocol_socket_open_UDP (struct node *node);
+
+#define PROTOCOL_INIT(p) { PROTOCOL_ID_##p, PROTOCOL_NAME_##p, \
+ protocol_socket_open_##p }
+
+static protocol_t protocols[] = { PROTOCOL_INIT (TCP),
+ PROTOCOL_INIT (UDP),
+ { 0, NULL, NULL } };
+
+static error_t protocol_find_by_name (char *name, protocol_t **protocol);
+
/* Connect the node *NODE with style STYLE (SOCK_STREAM or
SOCK_DGRAM). Used by protocol_socket_open_{tcp,udp}. Return 0 on
success or an error code. */
-error_t
+static error_t
protocol_socket_open_std (struct node *node, int style)
{
extern pf_t socket_server;
@@ -66,15 +79,15 @@ protocol_socket_open_std (struct node *node, int style)
}
/* Open a TCP socket for *NODE. Return 0 on success or an error code. */
-error_t
-protocol_socket_open_tcp (struct node *node)
+static error_t
+protocol_socket_open_TCP (struct node *node)
{
return protocol_socket_open_std (node, SOCK_STREAM);
}
/* Open a UDP socket for *NODE. Return 0 on success or an error code. */
-error_t
-protocol_socket_open_udp (struct node *node)
+static error_t
+protocol_socket_open_UDP (struct node *node)
{
return protocol_socket_open_std (node, SOCK_DGRAM);
}
@@ -86,43 +99,37 @@ error_t
protocol_find_node (char *name, struct node **node)
{
struct node *np;
+ error_t err = ENOENT;
+
for (np = netfs_root_node->nn->entries;
np && strcmp (np->nn->protocol->name, name);
np = np->next);
- if (! np)
- return ENOENT;
- *node = np;
- return 0;
+ if (np)
+ {
+ *node = np;
+ err = 0;
+ }
+ return err;
}
/* Register a protocol specified by ID and NAME, creating an according
node. Sockets for that protocol get opened by SOCKET_OPEN_FUNC.
Return 0 on success or an error code. */
error_t
-protocol_register (int id, char *name,
- error_t (*socket_open_func) (struct node *node))
+protocol_register (char *name)
{
error_t err;
- struct protocol *protocol;
- err = my_malloc (sizeof (struct protocol), (void **) &protocol);
+ protocol_t *protocol;
+
+ err = protocol_find_by_name (name, &protocol);
if (err)
- return err;
- protocol->name = strdup (name);
- if (! protocol->name)
- {
- free (protocol);
- return ENOMEM;
- }
+ return EOPNOTSUPP; /* No protocol definition by that name
+ found. */
err = node_make_protocol_node (netfs_root_node, protocol);
if (err)
- {
- free (protocol->name);
- free (protocol);
- return err;
- }
- protocol->id = id;
- protocol->socket_open = socket_open_func;
- return 0;
+ return err;
+
+ return err;
}
/* Unregister the protocol specified by NAME, drop the reference to
@@ -133,6 +140,7 @@ protocol_unregister (char *name)
{
struct node *np;
error_t err;
+
err = protocol_find_node (name, &np);
if (err)
return err;
@@ -143,10 +151,32 @@ protocol_unregister (char *name)
/* Register the protocols - create according nodes. Return 0 on
success or an error code. */
error_t
-protocol_register_protocols (void)
+protocol_register_default (void)
+{
+ protocol_t *p;
+ error_t err = 0;
+
+ for (p = protocols; ! err && p->name; p++)
+ err = protocol_register (p->name);
+
+ return err;
+}
+
+/* Lookup the protocol information for NAME and store them in
+ *PROTOCOL. Return zero on success or ENOENT if the protocol for
+ NAME could not be found. */
+static error_t
+protocol_find_by_name (char *name, protocol_t **protocol)
{
- return (protocol_register (PROTOCOL_ID_TCP, "tcp",
- protocol_socket_open_tcp)
- || protocol_register (PROTOCOL_ID_UDP, "udp",
- protocol_socket_open_udp));
+ protocol_t *p;
+ error_t err = 0;
+
+ for (p = protocols; p->name && strcmp (p->name, name); p++);
+
+ if (p->name)
+ *protocol = p;
+ else
+ err = ENOENT;
+
+ return err;
}
diff --git a/protocol.h b/protocol.h
index 2afae90f9..8a5997c1d 100644
--- a/protocol.h
+++ b/protocol.h
@@ -1,5 +1,6 @@
/* netio - creates socket ports via the filesystem
- Copyright (C) 2002 Moritz Schulte <moritz@duesseldorf.ccc.de>
+ Copyright (C) 2001, 02 Free Software Foundation, Inc.
+ Written by Moritz Schulte.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -16,8 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA */
-error_t protocol_register_protocols (void);
-error_t protocol_register (int id, char *name,
- error_t (*socket_open_func) (struct node *node));
-error_t protocol_unregister (char *name);;
+error_t protocol_register_default (void);
+error_t protocol_register (char *name);
+error_t protocol_unregister (char *name);
error_t protocol_find_node (char *name, struct node **node);
diff --git a/version.h b/version.h
index 54108e57a..8969db313 100644
--- a/version.h
+++ b/version.h
@@ -19,12 +19,11 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#ifndef HURD_VERSION
-#define HURD_VERSION "0.2"
+#define HURD_VERSION "0.3"
#endif
/* The standard way to print versions for --version. */
-#define _SHV_SEP "; "
-#define STANDARD_HURD_VERSION(s, extra...) \
- #s " (GNU Hurd" _SHV_SEP ##extra ") " HURD_VERSION
-
-
+#define STANDARD_HURD_VERSION(s) \
+ #s " (GNU Hurd) " HURD_VERSION
+#define STANDARD_HURD_VERSION_EXTRA(s, extra) \
+ #s " (GNU Hurd; " extra ") " HURD_VERSION