ng_base.c (180239) | ng_base.c (181803) |
---|---|
1/* 2 * ng_base.c 3 */ 4 5/*- 6 * Copyright (c) 1996-1999 Whistle Communications, Inc. 7 * All rights reserved. 8 * --- 24 unchanged lines hidden (view full) --- 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 36 * OF SUCH DAMAGE. 37 * 38 * Authors: Julian Elischer <julian@freebsd.org> 39 * Archie Cobbs <archie@freebsd.org> 40 * | 1/* 2 * ng_base.c 3 */ 4 5/*- 6 * Copyright (c) 1996-1999 Whistle Communications, Inc. 7 * All rights reserved. 8 * --- 24 unchanged lines hidden (view full) --- 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 36 * OF SUCH DAMAGE. 37 * 38 * Authors: Julian Elischer <julian@freebsd.org> 39 * Archie Cobbs <archie@freebsd.org> 40 * |
41 * $FreeBSD: head/sys/netgraph/ng_base.c 180239 2008-07-04 00:21:38Z rwatson $ | 41 * $FreeBSD: head/sys/netgraph/ng_base.c 181803 2008-08-17 23:27:27Z bz $ |
42 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $ 43 */ 44 45/* 46 * This file implements the base netgraph code. 47 */ 48 49#include <sys/param.h> --- 6 unchanged lines hidden (view full) --- 56#include <sys/limits.h> 57#include <sys/malloc.h> 58#include <sys/mbuf.h> 59#include <sys/queue.h> 60#include <sys/sysctl.h> 61#include <sys/syslog.h> 62#include <sys/refcount.h> 63#include <sys/proc.h> | 42 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $ 43 */ 44 45/* 46 * This file implements the base netgraph code. 47 */ 48 49#include <sys/param.h> --- 6 unchanged lines hidden (view full) --- 56#include <sys/limits.h> 57#include <sys/malloc.h> 58#include <sys/mbuf.h> 59#include <sys/queue.h> 60#include <sys/sysctl.h> 61#include <sys/syslog.h> 62#include <sys/refcount.h> 63#include <sys/proc.h> |
64#include <sys/vimage.h> |
|
64#include <machine/cpu.h> 65 66#include <net/netisr.h> 67 68#include <netgraph/ng_message.h> 69#include <netgraph/netgraph.h> 70#include <netgraph/ng_parse.h> 71 --- 97 unchanged lines hidden (view full) --- 169#define NG_ID_HASH_SIZE 128 /* most systems wont need even this many */ 170static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE]; 171static struct mtx ng_idhash_mtx; 172/* Method to find a node.. used twice so do it here */ 173#define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE)) 174#define NG_IDHASH_FIND(ID, node) \ 175 do { \ 176 mtx_assert(&ng_idhash_mtx, MA_OWNED); \ | 65#include <machine/cpu.h> 66 67#include <net/netisr.h> 68 69#include <netgraph/ng_message.h> 70#include <netgraph/netgraph.h> 71#include <netgraph/ng_parse.h> 72 --- 97 unchanged lines hidden (view full) --- 170#define NG_ID_HASH_SIZE 128 /* most systems wont need even this many */ 171static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE]; 172static struct mtx ng_idhash_mtx; 173/* Method to find a node.. used twice so do it here */ 174#define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE)) 175#define NG_IDHASH_FIND(ID, node) \ 176 do { \ 177 mtx_assert(&ng_idhash_mtx, MA_OWNED); \ |
177 LIST_FOREACH(node, &ng_ID_hash[NG_IDHASH_FN(ID)], \ | 178 LIST_FOREACH(node, &V_ng_ID_hash[NG_IDHASH_FN(ID)], \ |
178 nd_idnodes) { \ 179 if (NG_NODE_IS_VALID(node) \ 180 && (NG_NODE_ID(node) == ID)) { \ 181 break; \ 182 } \ 183 } \ 184 } while (0) 185 --- 447 unchanged lines hidden (view full) --- 633 STAILQ_INIT(&node->nd_input_queue.queue); 634 node->nd_input_queue.q_flags = 0; 635 636 /* Initialize hook list for new node */ 637 LIST_INIT(&node->nd_hooks); 638 639 /* Link us into the name hash. */ 640 mtx_lock(&ng_namehash_mtx); | 179 nd_idnodes) { \ 180 if (NG_NODE_IS_VALID(node) \ 181 && (NG_NODE_ID(node) == ID)) { \ 182 break; \ 183 } \ 184 } \ 185 } while (0) 186 --- 447 unchanged lines hidden (view full) --- 634 STAILQ_INIT(&node->nd_input_queue.queue); 635 node->nd_input_queue.q_flags = 0; 636 637 /* Initialize hook list for new node */ 638 LIST_INIT(&node->nd_hooks); 639 640 /* Link us into the name hash. */ 641 mtx_lock(&ng_namehash_mtx); |
641 LIST_INSERT_HEAD(&ng_name_hash[0], node, nd_nodes); | 642 LIST_INSERT_HEAD(&V_ng_name_hash[0], node, nd_nodes); |
642 mtx_unlock(&ng_namehash_mtx); 643 644 /* get an ID and put us in the hash chain */ 645 mtx_lock(&ng_idhash_mtx); 646 for (;;) { /* wrap protection, even if silly */ 647 node_p node2 = NULL; | 643 mtx_unlock(&ng_namehash_mtx); 644 645 /* get an ID and put us in the hash chain */ 646 mtx_lock(&ng_idhash_mtx); 647 for (;;) { /* wrap protection, even if silly */ 648 node_p node2 = NULL; |
648 node->nd_ID = nextID++; /* 137/second for 1 year before wrap */ | 649 node->nd_ID = V_nextID++; /* 137/second for 1 year before wrap */ |
649 650 /* Is there a problem with the new number? */ 651 NG_IDHASH_FIND(node->nd_ID, node2); /* already taken? */ 652 if ((node->nd_ID != 0) && (node2 == NULL)) { 653 break; 654 } 655 } | 650 651 /* Is there a problem with the new number? */ 652 NG_IDHASH_FIND(node->nd_ID, node2); /* already taken? */ 653 if ((node->nd_ID != 0) && (node2 == NULL)) { 654 break; 655 } 656 } |
656 LIST_INSERT_HEAD(&ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], | 657 LIST_INSERT_HEAD(&V_ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], |
657 node, nd_idnodes); 658 mtx_unlock(&ng_idhash_mtx); 659 660 /* Done */ 661 *nodepp = node; 662 return (0); 663} 664 --- 178 unchanged lines hidden (view full) --- 843 844 /* copy it */ 845 strlcpy(NG_NODE_NAME(node), name, NG_NODESIZ); 846 847 /* Update name hash. */ 848 NG_NAMEHASH(name, hash); 849 mtx_lock(&ng_namehash_mtx); 850 LIST_REMOVE(node, nd_nodes); | 658 node, nd_idnodes); 659 mtx_unlock(&ng_idhash_mtx); 660 661 /* Done */ 662 *nodepp = node; 663 return (0); 664} 665 --- 178 unchanged lines hidden (view full) --- 844 845 /* copy it */ 846 strlcpy(NG_NODE_NAME(node), name, NG_NODESIZ); 847 848 /* Update name hash. */ 849 NG_NAMEHASH(name, hash); 850 mtx_lock(&ng_namehash_mtx); 851 LIST_REMOVE(node, nd_nodes); |
851 LIST_INSERT_HEAD(&ng_name_hash[hash], node, nd_nodes); | 852 LIST_INSERT_HEAD(&V_ng_name_hash[hash], node, nd_nodes); |
852 mtx_unlock(&ng_namehash_mtx); 853 854 return (0); 855} 856 857/* 858 * Find a node by absolute name. The name should NOT end with ':' 859 * The name "." means "this node" and "[xxx]" means "the node --- 20 unchanged lines hidden (view full) --- 880 /* Check for name-by-ID */ 881 if ((temp = ng_decodeidname(name)) != 0) { 882 return (ng_ID2noderef(temp)); 883 } 884 885 /* Find node by name */ 886 NG_NAMEHASH(name, hash); 887 mtx_lock(&ng_namehash_mtx); | 853 mtx_unlock(&ng_namehash_mtx); 854 855 return (0); 856} 857 858/* 859 * Find a node by absolute name. The name should NOT end with ':' 860 * The name "." means "this node" and "[xxx]" means "the node --- 20 unchanged lines hidden (view full) --- 881 /* Check for name-by-ID */ 882 if ((temp = ng_decodeidname(name)) != 0) { 883 return (ng_ID2noderef(temp)); 884 } 885 886 /* Find node by name */ 887 NG_NAMEHASH(name, hash); 888 mtx_lock(&ng_namehash_mtx); |
888 LIST_FOREACH(node, &ng_name_hash[hash], nd_nodes) { | 889 LIST_FOREACH(node, &V_ng_name_hash[hash], nd_nodes) { |
889 if (NG_NODE_IS_VALID(node) && 890 (strcmp(NG_NODE_NAME(node), name) == 0)) { 891 break; 892 } 893 } 894 if (node) 895 NG_NODE_REF(node); 896 mtx_unlock(&ng_namehash_mtx); --- 1672 unchanged lines hidden (view full) --- 2569 const int unnamed = (msg->header.cmd == NGM_LISTNODES); 2570 struct namelist *nl; 2571 node_p node; 2572 int num = 0, i; 2573 2574 mtx_lock(&ng_namehash_mtx); 2575 /* Count number of nodes */ 2576 for (i = 0; i < NG_NAME_HASH_SIZE; i++) { | 890 if (NG_NODE_IS_VALID(node) && 891 (strcmp(NG_NODE_NAME(node), name) == 0)) { 892 break; 893 } 894 } 895 if (node) 896 NG_NODE_REF(node); 897 mtx_unlock(&ng_namehash_mtx); --- 1672 unchanged lines hidden (view full) --- 2570 const int unnamed = (msg->header.cmd == NGM_LISTNODES); 2571 struct namelist *nl; 2572 node_p node; 2573 int num = 0, i; 2574 2575 mtx_lock(&ng_namehash_mtx); 2576 /* Count number of nodes */ 2577 for (i = 0; i < NG_NAME_HASH_SIZE; i++) { |
2577 LIST_FOREACH(node, &ng_name_hash[i], nd_nodes) { | 2578 LIST_FOREACH(node, &V_ng_name_hash[i], nd_nodes) { |
2578 if (NG_NODE_IS_VALID(node) && 2579 (unnamed || NG_NODE_HAS_NAME(node))) { 2580 num++; 2581 } 2582 } 2583 } 2584 mtx_unlock(&ng_namehash_mtx); 2585 --- 5 unchanged lines hidden (view full) --- 2591 break; 2592 } 2593 nl = (struct namelist *) resp->data; 2594 2595 /* Cycle through the linked list of nodes */ 2596 nl->numnames = 0; 2597 mtx_lock(&ng_namehash_mtx); 2598 for (i = 0; i < NG_NAME_HASH_SIZE; i++) { | 2579 if (NG_NODE_IS_VALID(node) && 2580 (unnamed || NG_NODE_HAS_NAME(node))) { 2581 num++; 2582 } 2583 } 2584 } 2585 mtx_unlock(&ng_namehash_mtx); 2586 --- 5 unchanged lines hidden (view full) --- 2592 break; 2593 } 2594 nl = (struct namelist *) resp->data; 2595 2596 /* Cycle through the linked list of nodes */ 2597 nl->numnames = 0; 2598 mtx_lock(&ng_namehash_mtx); 2599 for (i = 0; i < NG_NAME_HASH_SIZE; i++) { |
2599 LIST_FOREACH(node, &ng_name_hash[i], nd_nodes) { | 2600 LIST_FOREACH(node, &V_ng_name_hash[i], nd_nodes) { |
2600 struct nodeinfo *const np = 2601 &nl->nodeinfo[nl->numnames]; 2602 2603 if (NG_NODE_NOT_VALID(node)) 2604 continue; 2605 if (!unnamed && (! NG_NODE_HAS_NAME(node))) 2606 continue; 2607 if (nl->numnames >= num) { --- 1103 unchanged lines hidden --- | 2601 struct nodeinfo *const np = 2602 &nl->nodeinfo[nl->numnames]; 2603 2604 if (NG_NODE_NOT_VALID(node)) 2605 continue; 2606 if (!unnamed && (! NG_NODE_HAS_NAME(node))) 2607 continue; 2608 if (nl->numnames >= num) { --- 1103 unchanged lines hidden --- |