* Constructor for a node */
| 238 | * Constructor for a node |
| 239 | */ |
| 240 | static int |
| 241 | ng_sppp_constructor (node_p node) |
| 242 | { |
| 243 | struct sppp *pp; |
| 244 | struct ifnet *ifp; |
| 245 | priv_p priv; |
| 246 | |
| 247 | /* Allocate node and interface private structures */ |
| 248 | priv = malloc(sizeof(*priv), M_NETGRAPH_SPPP, M_WAITOK | M_ZERO); |
| 249 | |
| 250 | ifp = if_alloc(IFT_PPP); |
| 251 | if (ifp == NULL) { |
| 252 | free (priv, M_NETGRAPH_SPPP); |
| 253 | return (ENOSPC); |
| 254 | } |
| 255 | pp = IFP2SP(ifp); |
| 256 | |
| 257 | /* Link them together */ |
| 258 | ifp->if_softc = priv; |
| 259 | priv->ifp = ifp; |
| 260 | |
| 261 | /* Get an interface unit number */ |
| 262 | ng_sppp_get_unit(&priv->unit); |
| 263 | |
| 264 | /* Link together node and private info */ |
| 265 | NG_NODE_SET_PRIVATE (node, priv); |
| 266 | priv->node = node; |
| 267 | |
| 268 | /* Initialize interface structure */ |
| 269 | if_initname (SP2IFP(pp), NG_SPPP_IFACE_NAME, priv->unit); |
| 270 | ifp->if_start = ng_sppp_start; |
| 271 | ifp->if_ioctl = ng_sppp_ioctl; |
| 272 | ifp->if_flags = (IFF_POINTOPOINT|IFF_MULTICAST); |
| 273 | |
| 274 | /* Give this node the same name as the interface (if possible) */ |
| 275 | if (ng_name_node(node, SP2IFP(pp)->if_xname) != 0) |
| 276 | log (LOG_WARNING, "%s: can't acquire netgraph name\n", |
| 277 | SP2IFP(pp)->if_xname); |
| 278 | |
| 279 | /* Attach the interface */ |
| 280 | sppp_attach (ifp); |
| 281 | if_attach (ifp); |
| 282 | bpfattach (ifp, DLT_NULL, sizeof(u_int32_t)); |
| 283 | |
| 284 | /* Done */ |
| 285 | return (0); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Give our ok for a hook to be added |
nothing calls this directly
no test coverage detected