ng_base.c (70917) | ng_base.c (70935) |
---|---|
1/* 2 * ng_base.c 3 * 4 * Copyright (c) 1996-1999 Whistle Communications, Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 22 unchanged lines hidden (view full) --- 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 34 * OF SUCH DAMAGE. 35 * 36 * Authors: Julian Elischer <julian@freebsd.org> 37 * Archie Cobbs <archie@freebsd.org> 38 * | 1/* 2 * ng_base.c 3 * 4 * Copyright (c) 1996-1999 Whistle Communications, Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 22 unchanged lines hidden (view full) --- 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 34 * OF SUCH DAMAGE. 35 * 36 * Authors: Julian Elischer <julian@freebsd.org> 37 * Archie Cobbs <archie@freebsd.org> 38 * |
39 * $FreeBSD: head/sys/netgraph/ng_base.c 70917 2001-01-11 04:13:46Z archie $ | 39 * $FreeBSD: head/sys/netgraph/ng_base.c 70935 2001-01-11 19:27:54Z julian $ |
40 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $ 41 */ 42 43/* 44 * This file implements the base netgraph code. 45 */ 46 47#include <sys/param.h> --- 28 unchanged lines hidden (view full) --- 76static SLIST_HEAD(, ng_hook) ng_allhooks; 77static LIST_HEAD(, ng_hook) ng_freehooks; /* in debug, we never free() them */ 78 79static void ng_dumpitems(void); 80static void ng_dumpnodes(void); 81static void ng_dumphooks(void); 82 83#endif /* NETGRAPH_DEBUG */ | 40 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $ 41 */ 42 43/* 44 * This file implements the base netgraph code. 45 */ 46 47#include <sys/param.h> --- 28 unchanged lines hidden (view full) --- 76static SLIST_HEAD(, ng_hook) ng_allhooks; 77static LIST_HEAD(, ng_hook) ng_freehooks; /* in debug, we never free() them */ 78 79static void ng_dumpitems(void); 80static void ng_dumpnodes(void); 81static void ng_dumphooks(void); 82 83#endif /* NETGRAPH_DEBUG */ |
84/* 85 * DEAD versions of the structures. 86 * In order to avoid races, it is sometimes neccesary to point 87 * at SOMETHING even though theoretically, the current entity is 88 * INVALID. Use these to avoid these races. 89 */ 90struct ng_type ng_deadtype = { 91 NG_ABI_VERSION, 92 "dead", 93 NULL, /* modevent */ 94 NULL, /* constructor */ 95 NULL, /* rcvmsg */ 96 NULL, /* shutdown */ 97 NULL, /* newhook */ 98 NULL, /* findhook */ 99 NULL, /* connect */ 100 NULL, /* rcvdata */ 101 NULL, /* disconnect */ 102 NULL, /* cmdlist */ 103}; |
|
84 | 104 |
105struct ng_node ng_deadnode = { 106 "dead", 107 &ng_deadtype, 108 NG_INVALID, 109 1, /* refs */ 110 0, /* numhooks */ 111 NULL, /* private */ 112 0, /* ID */ 113 LIST_HEAD_INITIALIZER(ng_deadnode.hooks), 114 {}, /* all_nodes list entry */ 115 {}, /* id hashtable list entry */ 116 {}, /* workqueue entry */ 117 { 0, 118 {}, /* should never use! (should hang) */ 119 NULL, 120 &ng_deadnode.nd_input_queue.queue, 121 &ng_deadnode 122 }, 123#ifdef NETGRAPH_DEBUG 124 ND_MAGIC, 125 __FILE__, 126 __LINE__, 127 {NULL} 128#endif /* NETGRAPH_DEBUG */ 129}; 130 131struct ng_hook ng_deadhook = { 132 "dead", 133 NULL, /* private */ 134 HK_INVALID | HK_DEAD, 135 1, /* refs always >= 1 */ 136 &ng_deadhook, /* Peer is self */ 137 &ng_deadnode, /* attached to deadnode */ 138 {}, /* hooks list */ 139#ifdef NETGRAPH_DEBUG 140 HK_MAGIC, 141 __FILE__, 142 __LINE__, 143 {NULL} 144#endif /* NETGRAPH_DEBUG */ 145}; 146 147/* 148 * END DEAD STRUCTURES 149 */ |
|
85/* List nodes with unallocated work */ 86static TAILQ_HEAD(, ng_node) ng_worklist = TAILQ_HEAD_INITIALIZER(ng_worklist); 87static struct mtx ng_worklist_mtx; 88 89/* List of installed types */ 90static LIST_HEAD(, ng_type) ng_typelist; 91static struct mtx ng_typelist_mtx; 92 --- 402 unchanged lines hidden (view full) --- 495 if ((error = ((*type->constructor)(*nodepp)) != 0)) { 496 NG_NODE_UNREF(*nodepp); 497 } 498 } 499 } else { 500 /* 501 * Node has no constructor. We cannot ask for one 502 * to be made. It must be brought into existance by | 150/* List nodes with unallocated work */ 151static TAILQ_HEAD(, ng_node) ng_worklist = TAILQ_HEAD_INITIALIZER(ng_worklist); 152static struct mtx ng_worklist_mtx; 153 154/* List of installed types */ 155static LIST_HEAD(, ng_type) ng_typelist; 156static struct mtx ng_typelist_mtx; 157 --- 402 unchanged lines hidden (view full) --- 560 if ((error = ((*type->constructor)(*nodepp)) != 0)) { 561 NG_NODE_UNREF(*nodepp); 562 } 563 } 564 } else { 565 /* 566 * Node has no constructor. We cannot ask for one 567 * to be made. It must be brought into existance by |
503 * some external agency. The external acency should | 568 * some external agency. The external agency should |
504 * call ng_make_node_common() directly to get the 505 * netgraph part initialised. 506 */ 507 TRAP_ERROR 508 error = EINVAL; 509 } 510 return (error); 511} --- 387 unchanged lines hidden (view full) --- 899 return (ENOMEM); 900 } 901 hook->hk_refs = 1; 902 hook->hk_flags = HK_INVALID; 903 hook->hk_node = node; 904 NG_NODE_REF(node); /* each hook counts as a reference */ 905 906 /* Check if the node type code has something to say about it */ | 569 * call ng_make_node_common() directly to get the 570 * netgraph part initialised. 571 */ 572 TRAP_ERROR 573 error = EINVAL; 574 } 575 return (error); 576} --- 387 unchanged lines hidden (view full) --- 964 return (ENOMEM); 965 } 966 hook->hk_refs = 1; 967 hook->hk_flags = HK_INVALID; 968 hook->hk_node = node; 969 NG_NODE_REF(node); /* each hook counts as a reference */ 970 971 /* Check if the node type code has something to say about it */ |
907 if (node->nd_type->newhook != NULL) 908 if ((error = (*node->nd_type->newhook)(node, hook, name)) != 0) { | 972 if (node->nd_type->newhook != NULL) { 973 if ((error = (*node->nd_type->newhook)(node, hook, name))) { |
909 NG_HOOK_UNREF(hook); /* this frees the hook */ 910 return (error); 911 } | 974 NG_HOOK_UNREF(hook); /* this frees the hook */ 975 return (error); 976 } |
912 | 977 } |
913 /* 914 * The 'type' agrees so far, so go ahead and link it in. 915 * We'll ask again later when we actually connect the hooks. 916 * The reference we have is for this linkage. 917 */ 918 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); 919 node->nd_numhooks++; 920 --- 281 unchanged lines hidden (view full) --- 1202 if (item == NULL) { 1203 printf("failed to free node 0x%x\n", ng_node2ID(here)); 1204 return (ENOMEM); 1205 } 1206 } 1207 return (ng_snd_item(item, 0)); 1208} 1209 | 978 /* 979 * The 'type' agrees so far, so go ahead and link it in. 980 * We'll ask again later when we actually connect the hooks. 981 * The reference we have is for this linkage. 982 */ 983 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); 984 node->nd_numhooks++; 985 --- 281 unchanged lines hidden (view full) --- 1267 if (item == NULL) { 1268 printf("failed to free node 0x%x\n", ng_node2ID(here)); 1269 return (ENOMEM); 1270 } 1271 } 1272 return (ng_snd_item(item, 0)); 1273} 1274 |
1275#define NG_INTERNAL_RMHOOK 0x123456 1276int 1277ng_rmhook_self(hook_p hook) 1278{ 1279 item_p item; 1280 struct ng_mesg *msg; 1281 node_p node = NG_HOOK_NODE(hook); 1282 1283 NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NG_INTERNAL_RMHOOK, 0, M_NOWAIT); 1284 /* 1285 * Try get a queue item to send it with. 1286 * Hopefully since it has a reserve, we can get one. 1287 * If we can't we are screwed anyhow. 1288 * Increase the chances by flushing our queue first. 1289 * We may free an item, (if we were the hog). 1290 * Work in progress is allowed to complete. 1291 * We also pretty much ensure that we come straight 1292 * back in to do the shutdown. It may be a good idea 1293 * to hold a reference actually to stop it from all 1294 * going up in smoke. 1295 */ 1296 item = ng_package_msg_self(node, hook, msg); 1297 if (item == NULL) { /* couldn't allocate item. Freed msg */ 1298 /* try again after flushing our queue */ 1299 panic("Couldn't allocate item to remove hook"); 1300 } 1301 return (ng_snd_item(item, 0)); 1302} 1303 |
|
1210/*********************************************************************** 1211 * Parse and verify a string of the form: <NODE:><PATH> 1212 * 1213 * Such a string can refer to a specific node or a specific hook 1214 * on a specific node, depending on how you look at it. In the 1215 * latter case, the PATH component must not end in a dot. 1216 * 1217 * Both <NODE:> and <PATH> are optional. The <PATH> is a string --- 1008 unchanged lines hidden (view full) --- 2226 error = EINVAL; 2227 break; 2228 } 2229 rmh->ourhook[sizeof(rmh->ourhook) - 1] = '\0'; 2230 if ((hook = ng_findhook(here, rmh->ourhook)) != NULL) 2231 ng_destroy_hook(hook); 2232 break; 2233 } | 1304/*********************************************************************** 1305 * Parse and verify a string of the form: <NODE:><PATH> 1306 * 1307 * Such a string can refer to a specific node or a specific hook 1308 * on a specific node, depending on how you look at it. In the 1309 * latter case, the PATH component must not end in a dot. 1310 * 1311 * Both <NODE:> and <PATH> are optional. The <PATH> is a string --- 1008 unchanged lines hidden (view full) --- 2320 error = EINVAL; 2321 break; 2322 } 2323 rmh->ourhook[sizeof(rmh->ourhook) - 1] = '\0'; 2324 if ((hook = ng_findhook(here, rmh->ourhook)) != NULL) 2325 ng_destroy_hook(hook); 2326 break; 2327 } |
2328 case NG_INTERNAL_RMHOOK: 2329 ng_destroy_hook(lasthook); 2330 break; |
|
2234 case NGM_NODEINFO: 2235 { 2236 struct nodeinfo *ni; 2237 2238 NG_MKRESPONSE(resp, msg, sizeof(*ni), M_NOWAIT); 2239 if (resp == NULL) { 2240 error = ENOMEM; 2241 break; --- 1063 unchanged lines hidden --- | 2331 case NGM_NODEINFO: 2332 { 2333 struct nodeinfo *ni; 2334 2335 NG_MKRESPONSE(resp, msg, sizeof(*ni), M_NOWAIT); 2336 if (resp == NULL) { 2337 error = ENOMEM; 2338 break; --- 1063 unchanged lines hidden --- |