MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_name_node

Function ng_name_node

freebsd/netgraph/ng_base.c:851–896  ·  view source on GitHub ↗

* Assign a node a name. */

Source from the content-addressed store, hash-verified

849 * Assign a node a name.
850 */
851int
852ng_name_node(node_p node, const char *name)
853{
854 uint32_t hash;
855 node_p node2;
856 int i;
857
858 /* Check the name is valid */
859 for (i = 0; i < NG_NODESIZ; i++) {
860 if (name[i] == '\0' || name[i] == '.' || name[i] == ':')
861 break;
862 }
863 if (i == 0 || name[i] != '\0') {
864 TRAP_ERROR();
865 return (EINVAL);
866 }
867 if (ng_decodeidname(name) != 0) { /* valid IDs not allowed here */
868 TRAP_ERROR();
869 return (EINVAL);
870 }
871
872 NAMEHASH_WLOCK();
873 if (V_ng_named_nodes * 2 > V_ng_name_hmask)
874 ng_name_rehash();
875
876 hash = hash32_str(name, HASHINIT) & V_ng_name_hmask;
877 /* Check the name isn't already being used. */
878 LIST_FOREACH(node2, &V_ng_name_hash[hash], nd_nodes)
879 if (NG_NODE_IS_VALID(node2) &&
880 (strcmp(NG_NODE_NAME(node2), name) == 0)) {
881 NAMEHASH_WUNLOCK();
882 return (EADDRINUSE);
883 }
884
885 if (NG_NODE_HAS_NAME(node))
886 LIST_REMOVE(node, nd_nodes);
887 else
888 V_ng_named_nodes++;
889 /* Copy it. */
890 strlcpy(NG_NODE_NAME(node), name, NG_NODESIZ);
891 /* Update name hash. */
892 LIST_INSERT_HEAD(&V_ng_name_hash[hash], node, nd_nodes);
893 NAMEHASH_WUNLOCK();
894
895 return (0);
896}
897
898/*
899 * Find a node by absolute name. The name should NOT end with ':'

Callers 15

ng_iface_constructorFunction · 0.70
ng_sppp_constructorFunction · 0.70
ng_ipfw_mod_eventFunction · 0.70
ng_eiface_constructorFunction · 0.70
ng_ether_attachFunction · 0.70
ng_gif_attachFunction · 0.70
ng_bindFunction · 0.70
ng_generic_msgFunction · 0.70
ng_h4_openFunction · 0.50
ubt_attachFunction · 0.50

Calls 5

hash32_strFunction · 0.85
strcmpFunction · 0.85
ng_decodeidnameFunction · 0.70
ng_name_rehashFunction · 0.70
strlcpyFunction · 0.50

Tested by

no test coverage detected