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

Function ng_bpf_newhook

freebsd/netgraph/ng_bpf.c:272–299  ·  view source on GitHub ↗

* Add a hook */

Source from the content-addressed store, hash-verified

270 * Add a hook
271 */
272static int
273ng_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

Callers

nothing calls this directly

Calls 4

mallocFunction · 0.85
ng_bpf_setprogFunction · 0.85
freeFunction · 0.50
strlcpyFunction · 0.50

Tested by

no test coverage detected