summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>1999-11-01 00:31:14 +0000
committerjulian <julian@FreeBSD.org>1999-11-01 00:31:14 +0000
commit58e6bf41a617bf7506852f363a037d91c91c8251 (patch)
tree4e0da4faadbabb606f78b28d763833318292546b /sys
parentc873ab347f06be8bfb334084760057811165ec63 (diff)
downloadFreeBSD-src-58e6bf41a617bf7506852f363a037d91c91c8251.zip
FreeBSD-src-58e6bf41a617bf7506852f363a037d91c91c8251.tar.gz
Start making the contents of the generic framework opaque to the nodes.
This step: IDs are no-longer the address of the node. Reviewd by: Archie@freebsd.org
Diffstat (limited to 'sys')
-rw-r--r--sys/netgraph/netgraph.h5
-rw-r--r--sys/netgraph/ng_base.c75
-rw-r--r--sys/netgraph/ng_frame_relay.c1
-rw-r--r--sys/netgraph/ng_message.h3
-rw-r--r--sys/netgraph/ng_pppoe.h4
5 files changed, 58 insertions, 30 deletions
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h
index e5e04e6..e37467e 100644
--- a/sys/netgraph/netgraph.h
+++ b/sys/netgraph/netgraph.h
@@ -80,8 +80,10 @@ struct ng_node {
int numhooks; /* number of hooks */
int colour; /* for graph colouring algorithms */
void *private; /* node type dependant node ID */
+ ng_ID_t ID; /* Unique per node */
LIST_HEAD(hooks, ng_hook) hooks; /* linked list of node hooks */
LIST_ENTRY(ng_node) nodes; /* linked list of all nodes */
+ LIST_ENTRY(ng_node) idnodes; /* ID hash collision list */
};
typedef struct ng_node *node_p;
@@ -223,6 +225,7 @@ DECLARE_MODULE(ng_##typename, ng_##typename##_mod, sub, order)
/* Special malloc() type for netgraph structs and ctrl messages */
MALLOC_DECLARE(M_NETGRAPH);
+int ng_bypass(hook_p hook1, hook_p hook2);
void ng_cutlinks(node_p node);
int ng_con_nodes(node_p node,
const char *name, node_p node2, const char *name2);
@@ -235,6 +238,7 @@ int ng_mkpeer(node_p node, const char *name, const char *name2, char *type);
int ng_mod_event(module_t mod, int what, void *arg);
int ng_name_node(node_p node, const char *name);
int ng_newtype(struct ng_type *tp);
+ng_ID_t ng_node2ID(node_p node);
int ng_path2node(node_p here, const char *path, node_p *dest, char **rtnp);
int ng_path_parse(char *addr, char **node, char **path, char **hook);
int ng_queue_data(hook_p hook, struct mbuf *m, meta_p meta);
@@ -248,7 +252,6 @@ int ng_send_msg(node_p here, struct ng_mesg *msg,
const char *address, struct ng_mesg **resp);
void ng_unname(node_p node);
void ng_unref(node_p node);
-int ng_bypass(hook_p hook1, hook_p hook2);
int ng_wait_node(node_p node, char *msg);
#endif /* _NETGRAPH_NETGRAPH_H_ */
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c
index 4234355..48df023 100644
--- a/sys/netgraph/ng_base.c
+++ b/sys/netgraph/ng_base.c
@@ -67,13 +67,18 @@ static LIST_HEAD(, ng_node) nodelist;
/* List of installed types */
static LIST_HEAD(, ng_type) typelist;
+/* Hash releted definitions */
+#define ID_HASH_SIZE 32 /* most systems wont need even this many */
+static LIST_HEAD(, ng_node) ID_hash[ID_HASH_SIZE];
+/* Don't nead to initialise them because it's a LIST */
+
/* Internal functions */
static int ng_add_hook(node_p node, const char *name, hook_p * hookp);
static int ng_connect(hook_p hook1, hook_p hook2);
static void ng_disconnect_hook(hook_p hook);
static int ng_generic_msg(node_p here, struct ng_mesg *msg,
const char *retaddr, struct ng_mesg ** resp);
-static node_p ng_decodeidname(const char *name);
+static ng_ID_t ng_decodeidname(const char *name);
static int ngb_mod_event(module_t mod, int event, void *data);
static void ngintr(void);
@@ -85,6 +90,9 @@ MALLOC_DEFINE(M_NETGRAPH, "netgraph", "netgraph structures and ctrl messages");
#define TRAP_ERROR
#endif
+static ng_ID_t nextID = 1;
+
+
/************************************************************************
Node routines
************************************************************************/
@@ -163,6 +171,10 @@ ng_make_node_common(struct ng_type *type, node_p *nodepp)
/* Initialize hook list for new node */
LIST_INIT(&node->hooks);
+ /* get an ID and put us in the hash chain */
+ node->ID = nextID++; /* 137 per second for 1 year before wrap */
+ LIST_INSERT_HEAD(&ID_hash[node->ID % ID_HASH_SIZE], node, idnodes);
+
/* Done */
*nodepp = node;
return (0);
@@ -231,6 +243,7 @@ ng_unref(node_p node)
if (--node->refs <= 0) {
node->type->refs--;
LIST_REMOVE(node, nodes);
+ LIST_REMOVE(node, idnodes);
FREE(node, M_NETGRAPH);
}
}
@@ -290,6 +303,26 @@ ng_release_node(node_p node)
}
/************************************************************************
+ Node ID handling
+************************************************************************/
+static node_p
+ng_ID2node(ng_ID_t ID)
+{
+ node_p np;
+ LIST_FOREACH(np, &ID_hash[ID % ID_HASH_SIZE], idnodes) {
+ if (np->ID == ID)
+ break;
+ }
+ return(np);
+}
+
+ng_ID_t
+ng_node2ID(node_p node)
+{
+ return (node->ID);
+}
+
+/************************************************************************
Node name handling
************************************************************************/
@@ -310,7 +343,7 @@ ng_name_node(node_p node, const char *name)
TRAP_ERROR;
return (EINVAL);
}
- if (ng_decodeidname(name) != NULL) {
+ if (ng_decodeidname(name) != 0) { /* valid IDs not allowed here */
TRAP_ERROR;
return (EINVAL);
}
@@ -350,21 +383,16 @@ ng_name_node(node_p node, const char *name)
node_p
ng_findname(node_p this, const char *name)
{
- node_p node, temp;
+ node_p node;
+ ng_ID_t temp;
/* "." means "this node" */
if (strcmp(name, ".") == 0)
return(this);
/* Check for name-by-ID */
- if ((temp = ng_decodeidname(name)) != NULL) {
-
- /* Make sure the ID really points to a node */
- LIST_FOREACH(node, &nodelist, nodes) {
- if (node == temp)
- break;
- }
- return (node);
+ if ((temp = ng_decodeidname(name)) != 0) {
+ return (ng_ID2node(temp));
}
/* Find node by name */
@@ -376,16 +404,13 @@ ng_findname(node_p this, const char *name)
}
/*
- * Decode a ID name, eg. "[f03034de]". Returns NULL if the
- * string is not valid, otherwise returns the ID cast to a
- * node pointer.
- *
- * NOTE: the returned pointer is not necessarily valid!
+ * Decode a ID name, eg. "[f03034de]". Returns 0 if the
+ * string is not valid, otherwise returns the value.
*/
-static node_p
+static ng_ID_t
ng_decodeidname(const char *name)
{
- u_int32_t val;
+ ng_ID_t val;
int k, len;
/* Basic checks */
@@ -415,7 +440,7 @@ ng_decodeidname(const char *name)
else
val = (val << 4) | (((ch & 0xdf) - 'A' + 10) & 0xf);
}
- return ((node_p) val);
+ return (val);
}
/*
@@ -895,7 +920,7 @@ ng_path2node(node_p here, const char *address, node_p *destp, char **rtnp)
if (start->name != NULL)
sprintf(*rtnp, "%s:", start->name);
else
- sprintf(*rtnp, "[%lx]:", (u_long) start);
+ sprintf(*rtnp, "[%x]:", ng_node2ID(start));
}
/* Done */
@@ -1067,7 +1092,7 @@ ng_generic_msg(node_p here, struct ng_mesg *msg, const char *retaddr,
if (here->name != NULL)
strncpy(ni->name, here->name, NG_NODELEN);
strncpy(ni->type, here->type->name, NG_TYPELEN);
- ni->id = (u_int32_t) here;
+ ni->id = ng_node2ID(here);
ni->hooks = here->numhooks;
*resp = rp;
break;
@@ -1098,7 +1123,7 @@ ng_generic_msg(node_p here, struct ng_mesg *msg, const char *retaddr,
if (here->name)
strncpy(ni->name, here->name, NG_NODELEN);
strncpy(ni->type, here->type->name, NG_TYPELEN);
- ni->id = (u_int32_t) here;
+ ni->id = ng_node2ID(here);
/* Cycle through the linked list of hooks */
ni->hooks = 0;
@@ -1119,7 +1144,7 @@ ng_generic_msg(node_p here, struct ng_mesg *msg, const char *retaddr,
hook->peer->node->name, NG_NODELEN);
strncpy(link->nodeinfo.type,
hook->peer->node->type->name, NG_TYPELEN);
- link->nodeinfo.id = (u_int32_t) hook->peer->node;
+ link->nodeinfo.id = ng_node2ID(hook->peer->node);
link->nodeinfo.hooks = hook->peer->node->numhooks;
ni->hooks++;
}
@@ -1177,7 +1202,7 @@ ng_generic_msg(node_p here, struct ng_mesg *msg, const char *retaddr,
if (node->name != NULL)
strncpy(np->name, node->name, NG_NODELEN);
strncpy(np->type, node->type->name, NG_TYPELEN);
- np->id = (u_int32_t) node;
+ np->id = ng_node2ID(node);
np->hooks = node->numhooks;
nl->numnames++;
}
@@ -1537,7 +1562,7 @@ ng_queue_msg(node_p here, struct ng_mesg * msg, int len, const char *address)
char *retaddr = NULL;
int error;
- /* Find the target node. Note that this trashes address */
+ /* Find the target node. */
error = ng_path2node(here, address, &dest, &retaddr);
if (error) {
FREE(msg, M_NETGRAPH);
diff --git a/sys/netgraph/ng_frame_relay.c b/sys/netgraph/ng_frame_relay.c
index 97ba1a5..d3b326b 100644
--- a/sys/netgraph/ng_frame_relay.c
+++ b/sys/netgraph/ng_frame_relay.c
@@ -78,7 +78,6 @@ struct ctxinfo { /* one per active hook */
#define MAX_CT 16 /* # of dlci's active at a time (POWER OF 2!) */
struct frmrel_softc {
int unit; /* which card are we? */
- char nodename[NG_NODELEN + 1]; /* store our node name */
int datahooks; /* number of data hooks attached */
node_p node; /* netgraph node */
int addrlen; /* address header length */
diff --git a/sys/netgraph/ng_message.h b/sys/netgraph/ng_message.h
index 8ff46b2..66c7fba 100644
--- a/sys/netgraph/ng_message.h
+++ b/sys/netgraph/ng_message.h
@@ -114,11 +114,12 @@ struct ngm_rmhook {
char ourhook[NG_HOOKLEN + 1]; /* hook name */
};
+#define ng_ID_t unsigned int
/* Structures used in response to NGM_NODEINFO and NGM_LISTHOOKS */
struct nodeinfo {
char name[NG_NODELEN + 1]; /* node name (if any) */
char type[NG_TYPELEN + 1]; /* peer type */
- u_int32_t id; /* unique identifier */
+ ng_ID_t id; /* unique identifier */
u_int32_t hooks; /* number of active hooks */
};
diff --git a/sys/netgraph/ng_pppoe.h b/sys/netgraph/ng_pppoe.h
index 04bec47..53061d1 100644
--- a/sys/netgraph/ng_pppoe.h
+++ b/sys/netgraph/ng_pppoe.h
@@ -82,8 +82,8 @@ enum cmd {
***********************/
/* This structure is returned by the NGM_PPPOE_GET_STATUS command */
struct ngpppoestat {
- u_int packets_in; /* packets in from downstream */
- u_int packets_out; /* packets out towards downstream */
+ u_int packets_in; /* packets in from ethernet */
+ u_int packets_out; /* packets out towards ethernet */
};
/*
OpenPOWER on IntegriCloud