* A new Ethernet interface has been attached. * Create a new node for it, etc. */
| 301 | * Create a new node for it, etc. |
| 302 | */ |
| 303 | static void |
| 304 | ng_ether_attach(struct ifnet *ifp) |
| 305 | { |
| 306 | char name[IFNAMSIZ]; |
| 307 | priv_p priv; |
| 308 | node_p node; |
| 309 | |
| 310 | /* |
| 311 | * Do not create / attach an ether node to this ifnet if |
| 312 | * a netgraph node with the same name already exists. |
| 313 | * This should prevent ether nodes to become attached to |
| 314 | * eiface nodes, which may be problematic due to naming |
| 315 | * clashes. |
| 316 | */ |
| 317 | ng_ether_sanitize_ifname(ifp->if_xname, name); |
| 318 | if ((node = ng_name2noderef(NULL, name)) != NULL) { |
| 319 | NG_NODE_UNREF(node); |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | /* Create node */ |
| 324 | KASSERT(!IFP2NG(ifp), ("%s: node already exists?", __func__)); |
| 325 | if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) { |
| 326 | log(LOG_ERR, "%s: can't %s for %s\n", |
| 327 | __func__, "create node", ifp->if_xname); |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | /* Allocate private data */ |
| 332 | priv = malloc(sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO); |
| 333 | if (priv == NULL) { |
| 334 | log(LOG_ERR, "%s: can't %s for %s\n", |
| 335 | __func__, "allocate memory", ifp->if_xname); |
| 336 | NG_NODE_UNREF(node); |
| 337 | return; |
| 338 | } |
| 339 | NG_NODE_SET_PRIVATE(node, priv); |
| 340 | priv->ifp = ifp; |
| 341 | IFP2NG(ifp) = node; |
| 342 | priv->hwassist = ifp->if_hwassist; |
| 343 | |
| 344 | /* Try to give the node the same name as the interface */ |
| 345 | if (ng_name_node(node, name) != 0) |
| 346 | log(LOG_WARNING, "%s: can't name node %s\n", __func__, name); |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * An Ethernet interface is being detached. |
no test coverage detected