Lines Matching +full:sub +full:- +full:node

2  * Copyright (c) 2001-2003
53 /* default node name */
56 /* my node Id */
86 * We dispatch unsolicieted messages by node cookies and ids.
147 d->cookie = cookie; in ng_register_cookie()
148 d->id = id; in ng_register_cookie()
149 d->func = func; in ng_register_cookie()
150 d->arg = arg; in ng_register_cookie()
151 d->mod = mod; in ng_register_cookie()
182 strcpy(d->hook, hook); in ng_register_hook()
183 d->func = func; in ng_register_hook()
184 d->arg = arg; in ng_register_hook()
185 d->mod = mod; in ng_register_hook()
217 if (m->mod == mod) { in ng_unregister_module()
227 if (d->mod == mod) { in ng_unregister_module()
255 if (d->cookie == mesg->header.typecookie && in csock_handle()
256 (d->id == 0 || d->id == id || id == 0)) in csock_handle()
257 (*d->func)(mesg, path, id, d->arg); in csock_handle()
291 syslog(LOG_DEBUG, "node closed -- exiting"); in csock_read()
317 * Write a message to a node.
326 ng_output_node(const char *node, u_int cookie, u_int opcode, in ng_output_node() argument
331 sprintf(path, "%s:", node); in ng_output_node()
335 ng_output_id(ng_ID_t node, u_int cookie, u_int opcode, in ng_output_id() argument
340 sprintf(path, "[%x]:", node); in ng_output_id()
384 if (setsockopt(csock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) in ng_dialog()
391 if (mesg->header.token == (u_int)token) in ng_dialog()
399 b->mesg = mesg; in ng_dialog()
400 strcpy(b->path, rpath); in ng_dialog()
406 if (setsockopt(csock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) in ng_dialog()
418 ng_dialog_node(const char *node, u_int cookie, u_int opcode, in ng_dialog_node() argument
423 sprintf(path, "%s:", node); in ng_dialog_node()
464 if ((len = NgRecvData(fd, resbuf, resbufsiz + 1, hook)) == -1) { in dsock_input()
487 if (strcmp(hook, d->hook) == 0) in dsock_input()
488 (*d->func)(hook, resbuf, len, d->arg); in dsock_input()
507 csock_handle(b->mesg, b->path); in ng_idle()
513 * Called when the module is loaded. Returning a non-zero value means,
540 if (sysctl(name, 2, &clockinfo, &len, NULL, 0) == -1) in ng_init()
549 * Get the node Id/name/type of a node.
560 id = ((struct nodeinfo *)(void *)resp->data)->id; in ng_node_id()
565 ng_node_id_node(const char *node) in ng_node_id_node() argument
570 if ((resp = ng_dialog_node(node, NGM_GENERIC_COOKIE, NGM_NODEINFO, in ng_node_id_node()
573 id = ((struct nodeinfo *)(void *)resp->data)->id; in ng_node_id_node()
585 strcpy(name, ((struct nodeinfo *)(void *)resp->data)->name); in ng_node_name()
598 strcpy(type, ((struct nodeinfo *)(void *)resp->data)->type); in ng_node_type()
604 * Connect our node to some other node
607 ng_connect_node(const char *node, const char *ourhook, const char *peerhook) in ng_connect_node() argument
611 snprintf(conn.path, NG_PATHSIZ, "%s:", node); in ng_connect_node()
654 return (-1); in ng_connect2_tee_id()
666 * Ensure that a node of type 'type' is connected to 'hook' of 'node'
667 * and return its node id. tee nodes between node and the target node
668 * are skipped. If the type is wrong, or the hook is a dead-end return 0.
672 ng_next_node_id_internal(ng_ID_t node, const char *type, const char *hook, in ng_next_node_id_internal() argument
679 if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, in ng_next_node_id_internal()
684 hooklist = (struct hooklist *)(void *)resp->data; in ng_next_node_id_internal()
686 for (i = 0; i < hooklist->nodeinfo.hooks; i++) in ng_next_node_id_internal()
687 if (strcmp(hooklist->link[i].ourhook, hook) == 0) in ng_next_node_id_internal()
690 if (i == hooklist->nodeinfo.hooks) { in ng_next_node_id_internal()
695 node = hooklist->link[i].nodeinfo.id; in ng_next_node_id_internal()
697 if (skip_tee && strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) { in ng_next_node_id_internal()
698 if (strcmp(hooklist->link[i].peerhook, "left") == 0) in ng_next_node_id_internal()
699 node = ng_next_node_id(node, type, "right"); in ng_next_node_id_internal()
700 else if (strcmp(hooklist->link[i].peerhook, "right") == 0) in ng_next_node_id_internal()
701 node = ng_next_node_id(node, type, "left"); in ng_next_node_id_internal()
703 strcmp(hooklist->link[i].nodeinfo.type, type) != 0) in ng_next_node_id_internal()
704 node = 0; in ng_next_node_id_internal()
707 strcmp(hooklist->link[i].nodeinfo.type, type) != 0) in ng_next_node_id_internal()
708 node = 0; in ng_next_node_id_internal()
712 return (node); in ng_next_node_id_internal()
716 * Ensure that a node of type 'type' is connected to 'hook' of 'node'
717 * and return its node id. tee nodes between node and the target node
718 * are skipped. If the type is wrong, or the hook is a dead-end return 0.
722 ng_next_node_id(ng_ID_t node, const char *type, const char *hook) in ng_next_node_id() argument
724 return (ng_next_node_id_internal(node, type, hook, 1)); in ng_next_node_id()
741 &mkpeer, sizeof(mkpeer)) == -1) in ng_mkpeer_id()
751 &name, sizeof(name)) == -1) in ng_mkpeer_id()
758 * SHutdown node
784 * Disconnect a hook of a node
803 ng_rmhook_tee_id(ng_ID_t node, const char *hook) in ng_rmhook_tee_id() argument
813 /* if we have just shutdown a tee node, which had no other hooks in ng_rmhook_tee_id()
814 * connected, the node id may already be wrong here. */ in ng_rmhook_tee_id()
815 if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, in ng_rmhook_tee_id()
819 hooklist = (struct hooklist *)(void *)resp->data; in ng_rmhook_tee_id()
821 for (i = 0; i < hooklist->nodeinfo.hooks; i++) in ng_rmhook_tee_id()
822 if (strcmp(hooklist->link[i].ourhook, hook) == 0) in ng_rmhook_tee_id()
825 if (i == hooklist->nodeinfo.hooks) { in ng_rmhook_tee_id()
832 if (strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) { in ng_rmhook_tee_id()
833 if (strcmp(hooklist->link[i].peerhook, "left") == 0) { in ng_rmhook_tee_id()
834 next_node = hooklist->link[i].nodeinfo.id; in ng_rmhook_tee_id()
836 } else if (strcmp(hooklist->link[i].peerhook, "right") == 0) { in ng_rmhook_tee_id()
837 next_node = hooklist->link[i].nodeinfo.id; in ng_rmhook_tee_id()
844 ng_rmhook_id(node, hook); in ng_rmhook_tee_id()
847 ng_shutdown_id(node); in ng_rmhook_tee_id()
849 if ((node = next_node) == 0) in ng_rmhook_tee_id()
857 * Get the peer hook of a hook on a given node. Skip any tee nodes in between
860 ng_peer_hook_id(ng_ID_t node, const char *hook, char *peerhook) in ng_peer_hook_id() argument
867 if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, in ng_peer_hook_id()
872 hooklist = (struct hooklist *)(void *)resp->data; in ng_peer_hook_id()
874 for (i = 0; i < hooklist->nodeinfo.hooks; i++) in ng_peer_hook_id()
875 if (strcmp(hooklist->link[i].ourhook, hook) == 0) in ng_peer_hook_id()
878 if (i == hooklist->nodeinfo.hooks) { in ng_peer_hook_id()
880 return (-1); in ng_peer_hook_id()
883 node = hooklist->link[i].nodeinfo.id; in ng_peer_hook_id()
886 if (strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) { in ng_peer_hook_id()
887 if (strcmp(hooklist->link[i].peerhook, "left") == 0) in ng_peer_hook_id()
888 ret = ng_peer_hook_id(node, "right", peerhook); in ng_peer_hook_id()
889 else if (strcmp(hooklist->link[i].peerhook, "right") == 0) in ng_peer_hook_id()
890 ret = ng_peer_hook_id(node, "left", peerhook); in ng_peer_hook_id()
892 strcpy(peerhook, hooklist->link[i].peerhook); in ng_peer_hook_id()
895 strcpy(peerhook, hooklist->link[i].peerhook); in ng_peer_hook_id()
960 "This module implements access to the netgraph sub-system",
975 u_int sub, u_int iidx __unused, enum snmp_op op) in op_ng_config() argument
977 asn_subid_t which = value->var.subs[sub - 1]; in op_ng_config()
992 return (string_get(value, snmp_nodename, -1)); in op_ng_config()
995 value->v.integer = resbufsiz; in op_ng_config()
999 value->v.integer = timeout; in op_ng_config()
1003 value->v.uint32 = debug_level; in op_ng_config()
1022 if ((ret = string_save(value, ctx, -1, &snmp_nodename)) in op_ng_config()
1036 ctx->scratch->int1 = resbufsiz; in op_ng_config()
1037 if (value->v.integer < 1024 || in op_ng_config()
1038 value->v.integer > 0x10000) in op_ng_config()
1040 resbufsiz = value->v.integer; in op_ng_config()
1044 ctx->scratch->int1 = timeout; in op_ng_config()
1045 if (value->v.integer < 10 || in op_ng_config()
1046 value->v.integer > 10000) in op_ng_config()
1048 timeout = value->v.integer; in op_ng_config()
1052 ctx->scratch->int1 = debug_level; in op_ng_config()
1053 debug_level = value->v.uint32; in op_ng_config()
1070 resbufsiz = ctx->scratch->int1; in op_ng_config()
1074 timeout = ctx->scratch->int1; in op_ng_config()
1078 debug_level = ctx->scratch->int1; in op_ng_config()
1103 u_int sub, u_int iidx __unused, enum snmp_op op) in op_ng_stats() argument
1111 value->v.uint32 = stats[value->var.subs[sub - 1] - 1]; in op_ng_stats()
1146 typelist = (struct typelist *)(void *)resp->data; in fetch_types()
1148 for (u = 0; u < typelist->numtypes; u++) { in fetch_types()
1153 strcpy(t->name, typelist->typeinfo[u].type_name); in fetch_types()
1154 t->index.subs[0] = strlen(t->name); in fetch_types()
1155 t->index.len = t->index.subs[0] + 1; in fetch_types()
1156 for (i = 0; i < t->index.subs[0]; i++) in fetch_types()
1157 t->index.subs[i + 1] = t->name[i]; in fetch_types()
1179 return (-1); in ngtype_load()
1199 return (-1); in ngtype_unload()
1204 if ((id = kldfind(mod)) == -1) { in ngtype_unload()
1206 return (-1); in ngtype_unload()
1214 u_int sub, u_int iidx, enum snmp_op op) in op_ng_type() argument
1216 asn_subid_t which = value->var.subs[sub - 1]; in op_ng_type()
1228 if ((t = NEXT_OBJECT_OID(&ngtype_list, &value->var, sub)) == NULL) in op_ng_type()
1230 index_append(&value->var, sub, &t->index); in op_ng_type()
1236 if ((t = FIND_OBJECT_OID(&ngtype_list, &value->var, sub)) == NULL) in op_ng_type()
1241 if (index_decode(&value->var, sub, iidx, &name, &namelen)) in op_ng_type()
1251 t = FIND_OBJECT_OID(&ngtype_list, &value->var, sub); in op_ng_type()
1259 if (!TRUTH_OK(value->v.integer)) { in op_ng_type()
1263 ctx->scratch->int1 = TRUTH_GET(value->v.integer); in op_ng_type()
1264 ctx->scratch->int1 |= (t != NULL) << 1; in op_ng_type()
1265 ctx->scratch->ptr2 = name; in op_ng_type()
1266 ctx->scratch->int2 = namelen; in op_ng_type()
1270 if (ctx->scratch->int1 & 1) { in op_ng_type()
1272 if (ngtype_load(name, namelen) == -1) { in op_ng_type()
1282 if (!(ctx->scratch->int1 & 1)) { in op_ng_type()
1284 if (ngtype_unload(name, namelen) == -1) { in op_ng_type()
1294 if (!(ctx->scratch->int1 & 2)) { in op_ng_type()
1296 if (ctx->scratch->int1 & 1) { in op_ng_type()
1297 /* request to load - unload */ in op_ng_type()
1298 if (ngtype_unload(ctx->scratch->ptr2, in op_ng_type()
1299 ctx->scratch->int2) == -1) in op_ng_type()
1304 if (!(ctx->scratch->int1 & 1)) { in op_ng_type()
1305 /* request to unload - reload */ in op_ng_type()
1306 if (ngtype_load(ctx->scratch->ptr2, in op_ng_type()
1307 ctx->scratch->int2) == -1) in op_ng_type()
1311 free(ctx->scratch->ptr2); in op_ng_type()
1315 free(ctx->scratch->ptr2); in op_ng_type()
1328 value->v.integer = status; in op_ng_type()
1338 * Implement the node table
1341 find_node(const struct asn_oid *oid, u_int sub, struct nodeinfo *info) in find_node() argument
1343 ng_ID_t id = oid->subs[sub]; in find_node()
1348 return (-1); in find_node()
1350 *info = *(struct nodeinfo *)(void *)resp->data; in find_node()
1361 if (i1->id < i2->id) in ncmp()
1362 return (-1); in ncmp()
1363 if (i1->id > i2->id) in ncmp()
1369 find_node_next(const struct asn_oid *oid, u_int sub, struct nodeinfo *info) in find_node_next() argument
1371 u_int idxlen = oid->len - sub; in find_node_next()
1379 return (-1); in find_node_next()
1380 list = (struct namelist *)(void *)resp->data; in find_node_next()
1382 qsort(list->nodeinfo, list->numnames, sizeof(list->nodeinfo[0]), ncmp); in find_node_next()
1385 if (list->numnames == 0) { in find_node_next()
1387 return (-1); in find_node_next()
1389 *info = list->nodeinfo[0]; in find_node_next()
1393 id = oid->subs[sub]; in find_node_next()
1395 for (i = 0; i < list->numnames; i++) in find_node_next()
1396 if (list->nodeinfo[i].id > id) { in find_node_next()
1397 *info = list->nodeinfo[i]; in find_node_next()
1403 return (-1); in find_node_next()
1408 u_int sub, u_int iidx __unused, enum snmp_op op) in op_ng_node() argument
1410 asn_subid_t which = value->var.subs[sub - 1]; in op_ng_node()
1411 u_int idxlen = value->var.len - sub; in op_ng_node()
1417 if (find_node_next(&value->var, sub, &nodeinfo) == -1) in op_ng_node()
1419 value->var.len = sub + 1; in op_ng_node()
1420 value->var.subs[sub] = nodeinfo.id; in op_ng_node()
1426 if (find_node(&value->var, sub, &nodeinfo) == -1) in op_ng_node()
1433 if (find_node(&value->var, sub, &nodeinfo) == -1) in op_ng_node()
1449 value->v.integer = 1; in op_ng_node()
1452 return (string_get(value, nodeinfo.name, -1)); in op_ng_node()
1454 return (string_get(value, nodeinfo.type, -1)); in op_ng_node()
1456 value->v.uint32 = nodeinfo.hooks; in op_ng_node()
1477 return (-1); in find_hook()
1479 list = (struct hooklist *)(void *)resp->data; in find_hook()
1481 for (i = 0; i < list->nodeinfo.hooks; i++) { in find_hook()
1482 if (strlen(list->link[i].ourhook) == hooklen && in find_hook()
1483 strncmp(list->link[i].ourhook, hook, hooklen) == 0) { in find_hook()
1484 *info = list->link[i]; in find_hook()
1490 return (-1); in find_hook()
1499 if (strlen(i1->ourhook) < strlen(i2->ourhook)) in hook_cmp()
1500 return (-1); in hook_cmp()
1501 if (strlen(i1->ourhook) > strlen(i2->ourhook)) in hook_cmp()
1503 return (strcmp(i1->ourhook, i2->ourhook)); in hook_cmp()
1507 find_hook_next(const struct asn_oid *oid, u_int sub, struct nodeinfo *nodeinfo, in find_hook_next() argument
1510 u_int idxlen = oid->len - sub; in find_hook_next()
1520 * Get and sort Node list in find_hook_next()
1524 return (-1); in find_hook_next()
1525 list = (struct namelist *)(void *)resp->data; in find_hook_next()
1527 qsort(list->nodeinfo, list->numnames, sizeof(list->nodeinfo[0]), ncmp); in find_hook_next()
1530 * If we have no index, take the first node and return the in find_hook_next()
1539 * Locate node in find_hook_next()
1541 for (node_index = 0; node_index < list->numnames; node_index++) in find_hook_next()
1542 if (list->nodeinfo[node_index].id >= oid->subs[sub]) in find_hook_next()
1546 * If we have only the node part of the index take, or in find_hook_next()
1547 * there is no node with that Id, take the first hook of that node. in find_hook_next()
1549 if (idxlen == 1 || node_index >= list->numnames || in find_hook_next()
1550 list->nodeinfo[node_index].id > oid->subs[sub]) in find_hook_next()
1554 * We had an exact match on the node id and have (at last part) in find_hook_next()
1555 * of the hook name index. Loop through the hooks of the node in find_hook_next()
1558 if ((resp1 = ng_dialog_id(list->nodeinfo[node_index].id, in find_hook_next()
1561 return (-1); in find_hook_next()
1563 hooks = (struct hooklist *)(void *)resp1->data; in find_hook_next()
1564 if (hooks->nodeinfo.hooks > 0) { in find_hook_next()
1565 qsort(hooks->link, hooks->nodeinfo.hooks, in find_hook_next()
1566 sizeof(hooks->link[0]), hook_cmp); in find_hook_next()
1567 for (i = 0; i < hooks->nodeinfo.hooks; i++) { in find_hook_next()
1568 idx.len = strlen(hooks->link[i].ourhook) + 1; in find_hook_next()
1569 idx.subs[0] = idx.len - 1; in find_hook_next()
1571 idx.subs[j + 1] = hooks->link[i].ourhook[j]; in find_hook_next()
1572 if (index_compare(oid, sub + 1, &idx) < 0) in find_hook_next()
1575 if (i < hooks->nodeinfo.hooks) { in find_hook_next()
1576 *nodeinfo = hooks->nodeinfo; in find_hook_next()
1577 *linkinfo = hooks->link[i]; in find_hook_next()
1585 /* no hook found larger than the index on the index node - take in find_hook_next()
1586 * first hook of next node */ in find_hook_next()
1591 while (node_index < list->numnames) { in find_hook_next()
1592 if ((resp1 = ng_dialog_id(list->nodeinfo[node_index].id, in find_hook_next()
1595 hooks = (struct hooklist *)(void *)resp1->data; in find_hook_next()
1596 if (hooks->nodeinfo.hooks > 0) { in find_hook_next()
1597 qsort(hooks->link, hooks->nodeinfo.hooks, in find_hook_next()
1598 sizeof(hooks->link[0]), hook_cmp); in find_hook_next()
1600 *nodeinfo = hooks->nodeinfo; in find_hook_next()
1601 *linkinfo = hooks->link[0]; in find_hook_next()
1608 /* if we don't have hooks, try next node */ in find_hook_next()
1614 return (-1); in find_hook_next()
1619 u_int sub, u_int iidx, enum snmp_op op) in op_ng_hook() argument
1621 asn_subid_t which = value->var.subs[sub - 1]; in op_ng_hook()
1632 if (find_hook_next(&value->var, sub, &nodeinfo, &linkinfo) == -1) in op_ng_hook()
1635 value->var.len = sub + 1 + 1 + strlen(linkinfo.ourhook); in op_ng_hook()
1636 value->var.subs[sub] = nodeinfo.id; in op_ng_hook()
1637 value->var.subs[sub + 1] = strlen(linkinfo.ourhook); in op_ng_hook()
1639 value->var.subs[sub + i + 2] = in op_ng_hook()
1644 if (index_decode(&value->var, sub, iidx, &lid, in op_ng_hook()
1647 if (find_hook(lid, hook, hooklen, &linkinfo) == -1) { in op_ng_hook()
1655 if (index_decode(&value->var, sub, iidx, &lid, in op_ng_hook()
1658 if (find_hook(lid, hook, hooklen, &linkinfo) == -1) { in op_ng_hook()
1675 value->v.integer = 1; in op_ng_hook()
1678 value->v.uint32 = linkinfo.nodeinfo.id; in op_ng_hook()
1681 return (string_get(value, linkinfo.peerhook, -1)); in op_ng_hook()
1683 return (string_get(value, linkinfo.nodeinfo.type, -1)); in op_ng_hook()