| 540 | */ |
| 541 | |
| 542 | static int |
| 543 | ng_attach_cntl(struct socket *so) |
| 544 | { |
| 545 | struct ngsock *priv; |
| 546 | struct ngpcb *pcbp; |
| 547 | node_p node; |
| 548 | int error; |
| 549 | |
| 550 | /* Setup protocol control block */ |
| 551 | if ((error = ng_attach_common(so, NG_CONTROL)) != 0) |
| 552 | return (error); |
| 553 | pcbp = sotongpcb(so); |
| 554 | |
| 555 | /* Make the generic node components */ |
| 556 | if ((error = ng_make_node_common(&typestruct, &node)) != 0) { |
| 557 | ng_detach_common(pcbp, NG_CONTROL); |
| 558 | return (error); |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | * Allocate node private info and hash. We start |
| 563 | * with 16 hash entries, however we may grow later |
| 564 | * in ngs_newhook(). We can't predict how much hooks |
| 565 | * does this node plan to have. |
| 566 | */ |
| 567 | priv = malloc(sizeof(*priv), M_NETGRAPH_SOCK, M_WAITOK | M_ZERO); |
| 568 | priv->hash = hashinit(16, M_NETGRAPH_SOCK, &priv->hmask); |
| 569 | |
| 570 | /* Initialize mutex. */ |
| 571 | mtx_init(&priv->mtx, "ng_socket", NULL, MTX_DEF); |
| 572 | |
| 573 | /* Link the pcb the private data. */ |
| 574 | priv->ctlsock = pcbp; |
| 575 | pcbp->sockdata = priv; |
| 576 | priv->refs++; |
| 577 | priv->node = node; |
| 578 | pcbp->node_id = node->nd_ID; /* hint for netstat(1) */ |
| 579 | |
| 580 | /* Link the node and the private data. */ |
| 581 | NG_NODE_SET_PRIVATE(priv->node, priv); |
| 582 | NG_NODE_REF(priv->node); |
| 583 | priv->refs++; |
| 584 | |
| 585 | return (0); |
| 586 | } |
| 587 | |
| 588 | static int |
| 589 | ng_attach_data(struct socket *so) |
no test coverage detected