* We have an item that was possibly queued somewhere. * It should contain all the information needed * to run it on the appropriate node/hook. * If there is apply pointer and we own the last reference, call apply(). */
| 2358 | * If there is apply pointer and we own the last reference, call apply(). |
| 2359 | */ |
| 2360 | static int |
| 2361 | ng_apply_item(node_p node, item_p item, int rw) |
| 2362 | { |
| 2363 | hook_p hook; |
| 2364 | ng_rcvdata_t *rcvdata; |
| 2365 | ng_rcvmsg_t *rcvmsg; |
| 2366 | struct ng_apply_info *apply; |
| 2367 | int error = 0, depth; |
| 2368 | |
| 2369 | /* Node and item are never optional. */ |
| 2370 | KASSERT(node != NULL, ("ng_apply_item: node is NULL")); |
| 2371 | KASSERT(item != NULL, ("ng_apply_item: item is NULL")); |
| 2372 | |
| 2373 | NGI_GET_HOOK(item, hook); /* clears stored hook */ |
| 2374 | #ifdef NETGRAPH_DEBUG |
| 2375 | _ngi_check(item, __FILE__, __LINE__); |
| 2376 | #endif |
| 2377 | |
| 2378 | apply = item->apply; |
| 2379 | depth = item->depth; |
| 2380 | |
| 2381 | switch (item->el_flags & NGQF_TYPE) { |
| 2382 | case NGQF_DATA: |
| 2383 | /* |
| 2384 | * Check things are still ok as when we were queued. |
| 2385 | */ |
| 2386 | KASSERT(hook != NULL, ("ng_apply_item: hook for data is NULL")); |
| 2387 | if (NG_HOOK_NOT_VALID(hook) || |
| 2388 | NG_NODE_NOT_VALID(node)) { |
| 2389 | error = EIO; |
| 2390 | NG_FREE_ITEM(item); |
| 2391 | break; |
| 2392 | } |
| 2393 | /* |
| 2394 | * If no receive method, just silently drop it. |
| 2395 | * Give preference to the hook over-ride method. |
| 2396 | */ |
| 2397 | if ((!(rcvdata = hook->hk_rcvdata)) && |
| 2398 | (!(rcvdata = NG_HOOK_NODE(hook)->nd_type->rcvdata))) { |
| 2399 | error = 0; |
| 2400 | NG_FREE_ITEM(item); |
| 2401 | break; |
| 2402 | } |
| 2403 | error = (*rcvdata)(hook, item); |
| 2404 | break; |
| 2405 | case NGQF_MESG: |
| 2406 | if (hook && NG_HOOK_NOT_VALID(hook)) { |
| 2407 | /* |
| 2408 | * The hook has been zapped then we can't use it. |
| 2409 | * Immediately drop its reference. |
| 2410 | * The message may not need it. |
| 2411 | */ |
| 2412 | NG_HOOK_UNREF(hook); |
| 2413 | hook = NULL; |
| 2414 | } |
| 2415 | /* |
| 2416 | * Similarly, if the node is a zombie there is |
| 2417 | * nothing we can do with it, drop everything. |
no test coverage detected