* Receive a control message */
| 302 | * Receive a control message |
| 303 | */ |
| 304 | static int |
| 305 | ng_bpf_rcvmsg(node_p node, item_p item, hook_p lasthook) |
| 306 | { |
| 307 | struct ng_mesg *msg; |
| 308 | struct ng_mesg *resp = NULL; |
| 309 | int error = 0; |
| 310 | |
| 311 | NGI_GET_MSG(item, msg); |
| 312 | switch (msg->header.typecookie) { |
| 313 | case NGM_BPF_COOKIE: |
| 314 | switch (msg->header.cmd) { |
| 315 | case NGM_BPF_SET_PROGRAM: |
| 316 | { |
| 317 | struct ng_bpf_hookprog *const |
| 318 | hp = (struct ng_bpf_hookprog *)msg->data; |
| 319 | hook_p hook; |
| 320 | |
| 321 | /* Sanity check */ |
| 322 | if (msg->header.arglen < sizeof(*hp) |
| 323 | || msg->header.arglen |
| 324 | != NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) |
| 325 | ERROUT(EINVAL); |
| 326 | |
| 327 | /* Find hook */ |
| 328 | if ((hook = ng_findhook(node, hp->thisHook)) == NULL) |
| 329 | ERROUT(ENOENT); |
| 330 | |
| 331 | /* Set new program */ |
| 332 | if ((error = ng_bpf_setprog(hook, hp)) != 0) |
| 333 | ERROUT(error); |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | case NGM_BPF_GET_PROGRAM: |
| 338 | { |
| 339 | struct ng_bpf_hookprog *hp; |
| 340 | hook_p hook; |
| 341 | |
| 342 | /* Sanity check */ |
| 343 | if (msg->header.arglen == 0) |
| 344 | ERROUT(EINVAL); |
| 345 | msg->data[msg->header.arglen - 1] = '\0'; |
| 346 | |
| 347 | /* Find hook */ |
| 348 | if ((hook = ng_findhook(node, msg->data)) == NULL) |
| 349 | ERROUT(ENOENT); |
| 350 | |
| 351 | /* Build response */ |
| 352 | hp = ((hinfo_p)NG_HOOK_PRIVATE(hook))->prog; |
| 353 | NG_MKRESPONSE(resp, msg, |
| 354 | NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len), M_NOWAIT); |
| 355 | if (resp == NULL) |
| 356 | ERROUT(ENOMEM); |
| 357 | bcopy(hp, resp->data, |
| 358 | NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)); |
| 359 | break; |
| 360 | } |
| 361 |
nothing calls this directly
no test coverage detected