* Receive a control message */
| 345 | * Receive a control message |
| 346 | */ |
| 347 | static int |
| 348 | ng_source_rcvmsg(node_p node, item_p item, hook_p lasthook) |
| 349 | { |
| 350 | sc_p sc = NG_NODE_PRIVATE(node); |
| 351 | struct ng_mesg *msg, *resp = NULL; |
| 352 | int error = 0; |
| 353 | |
| 354 | NGI_GET_MSG(item, msg); |
| 355 | |
| 356 | switch (msg->header.typecookie) { |
| 357 | case NGM_SOURCE_COOKIE: |
| 358 | if (msg->header.flags & NGF_RESP) { |
| 359 | error = EINVAL; |
| 360 | break; |
| 361 | } |
| 362 | switch (msg->header.cmd) { |
| 363 | case NGM_SOURCE_GET_STATS: |
| 364 | case NGM_SOURCE_CLR_STATS: |
| 365 | case NGM_SOURCE_GETCLR_STATS: |
| 366 | { |
| 367 | struct ng_source_stats *stats; |
| 368 | |
| 369 | if (msg->header.cmd != NGM_SOURCE_CLR_STATS) { |
| 370 | NG_MKRESPONSE(resp, msg, |
| 371 | sizeof(*stats), M_NOWAIT); |
| 372 | if (resp == NULL) { |
| 373 | error = ENOMEM; |
| 374 | goto done; |
| 375 | } |
| 376 | sc->stats.queueOctets = sc->queueOctets; |
| 377 | sc->stats.queueFrames = sc->snd_queue.ifq_len; |
| 378 | if ((sc->node->nd_flags & NG_SOURCE_ACTIVE) |
| 379 | && !timevalisset(&sc->stats.endTime)) { |
| 380 | getmicrotime(&sc->stats.elapsedTime); |
| 381 | timevalsub(&sc->stats.elapsedTime, |
| 382 | &sc->stats.startTime); |
| 383 | } |
| 384 | stats = (struct ng_source_stats *)resp->data; |
| 385 | bcopy(&sc->stats, stats, sizeof(* stats)); |
| 386 | } |
| 387 | if (msg->header.cmd != NGM_SOURCE_GET_STATS) |
| 388 | bzero(&sc->stats, sizeof(sc->stats)); |
| 389 | } |
| 390 | break; |
| 391 | case NGM_SOURCE_START: |
| 392 | { |
| 393 | uint64_t packets; |
| 394 | |
| 395 | if (msg->header.arglen != sizeof(uint64_t)) { |
| 396 | error = EINVAL; |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | packets = *(uint64_t *)msg->data; |
| 401 | |
| 402 | error = ng_source_start(sc, packets); |
| 403 | |
| 404 | break; |
nothing calls this directly
no test coverage detected