* Add a hook */
| 270 | * Add a hook |
| 271 | */ |
| 272 | static int |
| 273 | ng_bpf_newhook(node_p node, hook_p hook, const char *name) |
| 274 | { |
| 275 | hinfo_p hip; |
| 276 | hook_p tmp; |
| 277 | int error; |
| 278 | |
| 279 | /* Create hook private structure */ |
| 280 | hip = malloc(sizeof(*hip), M_NETGRAPH_BPF, M_NOWAIT | M_ZERO); |
| 281 | if (hip == NULL) |
| 282 | return (ENOMEM); |
| 283 | hip->hook = hook; |
| 284 | NG_HOOK_SET_PRIVATE(hook, hip); |
| 285 | |
| 286 | /* Add our reference into other hooks data. */ |
| 287 | NG_NODE_FOREACH_HOOK(node, ng_bpf_addrefs, hook, tmp); |
| 288 | |
| 289 | /* Attach the default BPF program */ |
| 290 | if ((error = ng_bpf_setprog(hook, &ng_bpf_default_prog)) != 0) { |
| 291 | free(hip, M_NETGRAPH_BPF); |
| 292 | NG_HOOK_SET_PRIVATE(hook, NULL); |
| 293 | return (error); |
| 294 | } |
| 295 | |
| 296 | /* Set hook name */ |
| 297 | strlcpy(hip->prog->thisHook, name, sizeof(hip->prog->thisHook)); |
| 298 | return (0); |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Receive a control message |
nothing calls this directly
no test coverage detected